Asset Manager



  • I'm looking into developing my own content browser of sorts. An interface into a a version control system we have at our studio. I was looking into the Url api, and I remembered that you guys have that whole preset:// thing going with lib4d assets. Is it possible using the C++ that I could resolve my own custom URL/URIs to assets and images in C4D, or is the preset:// thing custom logic internal to only the built in content browser.



  • Hello,

    as always, please use the Q&A system to mark your post as a question.

    You can register a custom URL scheme. This scheme defines how a data connection is created for the given URL.

    The Url schemes is defined by implementing IoHandlerInterface; the connection by implementing IoConnectionInterface.

    This is a simple example of such implementations:

    #include "maxon/ioconnection.h"
    #include "maxon/iohandler.h"
    
    
    class MyIOImpl : public maxon::Component<MyIOImpl, maxon::IoConnectionInterface>
    {
      MAXON_COMPONENT(NORMAL, maxon::IoConnectionBaseClass);
    
    public:
      maxon::ResultOk<void> Init(const maxon::Url& name)
      {
        _url = name;
    
        return maxon::OK;
      }
    
      maxon::Result<maxon::Url> ResolveMyScheme()
      {
        iferr_scope;
    
        // resolve custom scheme
        maxon::String resolvedPath { "file:///c:/assets/" };
        resolvedPath.Append(_url.GetPath()) iferr_return;
    
        return maxon::Url { resolvedPath };
      }
    
      MAXON_METHOD const maxon::Url& GetUrl() const
      {
        return _url;
      }
    
      MAXON_METHOD maxon::Result<maxon::OutputStreamRef> OpenOutputStream(maxon::OPENSTREAMFLAGS flags)
      {
        iferr_scope;
    
        return ResolveMyScheme().OpenOutputStream();
      }
    
      MAXON_METHOD maxon::Result<maxon::InputStreamRef> OpenInputStream(maxon::OPENSTREAMFLAGS flags)
      {
        iferr_scope;
        return ResolveMyScheme().OpenInputStream();
      }
    
      MAXON_METHOD maxon::Result<maxon::InOutputStreamRef> OpenInOutputStream(maxon::OPENSTREAMFLAGS flags)
      {
        iferr_scope;
        return ResolveMyScheme().OpenInOutputStream();
      }
    
      MAXON_METHOD maxon::Result<maxon::IOATTRIBUTES> IoGetAttributes() const
      {
        return maxon::IOATTRIBUTES::GROUP_R | maxon::IOATTRIBUTES::GROUP_W | maxon::IOATTRIBUTES::OWNER_R | maxon::IOATTRIBUTES::OWNER_W | maxon::IOATTRIBUTES::PUBLIC_R | maxon::IOATTRIBUTES::PUBLIC_W;
      }
    
      MAXON_METHOD maxon::Result<maxon::UniversalDateTime> IoGetTime(maxon::IOTIMEMODE mode) const
      {
        return maxon::UniversalDateTime::GetNow();
      }
    
    private:
      maxon::Url _url;
    };
    
    MAXON_COMPONENT_CLASS_REGISTER(MyIOImpl, "net.maxon.class.iocustom");
    
    static maxon::Id g_myAssetScheme { "myassets" };
    
    class MyHandlerImpl : public maxon::Component<MyHandlerImpl, maxon::IoHandlerInterface>
    {
      MAXON_COMPONENT(NORMAL, maxon::IoHandlerObjectBaseClass);
    
    public:
      MAXON_METHOD const maxon::Id& GetUrlScheme() const
      {
        return g_myAssetScheme;
      }
    
      MAXON_METHOD maxon::Result<maxon::IoConnectionRef> OpenConnection(const maxon::Url& name) const
      {
        return MyIOImpl::CreateInit(name);
      }
    
      MAXON_METHOD maxon::Result<maxon::Url> Normalize(const maxon::Url& url, maxon::NORMALIZEFLAGS flags) const
      {
        return url;
      }
    
      MAXON_METHOD maxon::Result<maxon::Url> IoNormalize(const maxon::Url& url, maxon::NORMALIZEFLAGS flags) const
      {
        return url;
      }
    };
    
    MAXON_COMPONENT_OBJECT_REGISTER(MyHandlerImpl, maxon::IoHandlers, "net.maxon.iohandler.custom");
    

    This is how this scheme would be used:

    const maxon::Url myUrl { "myassets:///test.txt"_s };
    
    
    // open input stream and get file size
    const maxon::InputStreamRef inputStream = myUrl.OpenInputStream() iferr_return;
    const maxon::Int length = inputStream.GetStreamLength() iferr_return;
    maxon::BaseArray<maxon::Char> data;
    data.Resize(length) iferr_return;
    inputStream.Read(data) iferr_return;
    
    // convert to string
    const maxon::String text { data };
    DiagnosticOutput("File Content: @", text);
    

    best wishes,
    Sebastian



  • Hello,

    as always, please use the Q&A system to mark your post as a question.

    You can register a custom URL scheme. This scheme defines how a data connection is created for the given URL.

    The Url schemes is defined by implementing IoHandlerInterface; the connection by implementing IoConnectionInterface.

    This is a simple example of such implementations:

    #include "maxon/ioconnection.h"
    #include "maxon/iohandler.h"
    
    
    class MyIOImpl : public maxon::Component<MyIOImpl, maxon::IoConnectionInterface>
    {
      MAXON_COMPONENT(NORMAL, maxon::IoConnectionBaseClass);
    
    public:
      maxon::ResultOk<void> Init(const maxon::Url& name)
      {
        _url = name;
    
        return maxon::OK;
      }
    
      maxon::Result<maxon::Url> ResolveMyScheme()
      {
        iferr_scope;
    
        // resolve custom scheme
        maxon::String resolvedPath { "file:///c:/assets/" };
        resolvedPath.Append(_url.GetPath()) iferr_return;
    
        return maxon::Url { resolvedPath };
      }
    
      MAXON_METHOD const maxon::Url& GetUrl() const
      {
        return _url;
      }
    
      MAXON_METHOD maxon::Result<maxon::OutputStreamRef> OpenOutputStream(maxon::OPENSTREAMFLAGS flags)
      {
        iferr_scope;
    
        return ResolveMyScheme().OpenOutputStream();
      }
    
      MAXON_METHOD maxon::Result<maxon::InputStreamRef> OpenInputStream(maxon::OPENSTREAMFLAGS flags)
      {
        iferr_scope;
        return ResolveMyScheme().OpenInputStream();
      }
    
      MAXON_METHOD maxon::Result<maxon::InOutputStreamRef> OpenInOutputStream(maxon::OPENSTREAMFLAGS flags)
      {
        iferr_scope;
        return ResolveMyScheme().OpenInOutputStream();
      }
    
      MAXON_METHOD maxon::Result<maxon::IOATTRIBUTES> IoGetAttributes() const
      {
        return maxon::IOATTRIBUTES::GROUP_R | maxon::IOATTRIBUTES::GROUP_W | maxon::IOATTRIBUTES::OWNER_R | maxon::IOATTRIBUTES::OWNER_W | maxon::IOATTRIBUTES::PUBLIC_R | maxon::IOATTRIBUTES::PUBLIC_W;
      }
    
      MAXON_METHOD maxon::Result<maxon::UniversalDateTime> IoGetTime(maxon::IOTIMEMODE mode) const
      {
        return maxon::UniversalDateTime::GetNow();
      }
    
    private:
      maxon::Url _url;
    };
    
    MAXON_COMPONENT_CLASS_REGISTER(MyIOImpl, "net.maxon.class.iocustom");
    
    static maxon::Id g_myAssetScheme { "myassets" };
    
    class MyHandlerImpl : public maxon::Component<MyHandlerImpl, maxon::IoHandlerInterface>
    {
      MAXON_COMPONENT(NORMAL, maxon::IoHandlerObjectBaseClass);
    
    public:
      MAXON_METHOD const maxon::Id& GetUrlScheme() const
      {
        return g_myAssetScheme;
      }
    
      MAXON_METHOD maxon::Result<maxon::IoConnectionRef> OpenConnection(const maxon::Url& name) const
      {
        return MyIOImpl::CreateInit(name);
      }
    
      MAXON_METHOD maxon::Result<maxon::Url> Normalize(const maxon::Url& url, maxon::NORMALIZEFLAGS flags) const
      {
        return url;
      }
    
      MAXON_METHOD maxon::Result<maxon::Url> IoNormalize(const maxon::Url& url, maxon::NORMALIZEFLAGS flags) const
      {
        return url;
      }
    };
    
    MAXON_COMPONENT_OBJECT_REGISTER(MyHandlerImpl, maxon::IoHandlers, "net.maxon.iohandler.custom");
    

    This is how this scheme would be used:

    const maxon::Url myUrl { "myassets:///test.txt"_s };
    
    
    // open input stream and get file size
    const maxon::InputStreamRef inputStream = myUrl.OpenInputStream() iferr_return;
    const maxon::Int length = inputStream.GetStreamLength() iferr_return;
    maxon::BaseArray<maxon::Char> data;
    data.Resize(length) iferr_return;
    inputStream.Read(data) iferr_return;
    
    // convert to string
    const maxon::String text { data };
    DiagnosticOutput("File Content: @", text);
    

    best wishes,
    Sebastian



  • Update: the previous version of the code had some ill-formatted statements. You can actually define the scheme as part of the Url, without setting it using SetScheme():

    const maxon::Url myUrl { "myassets:///test.txt"_s };
    

    Thus, the path is resolved just by adding the path to the target folder:

    maxon::String resolvedPath { "file:///c:/assets/" };
    resolvedPath.Append(_url.GetPath()) iferr_return;
    

    best wishes,
    Sebastian


Log in to reply