Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login
    1. Maxon Developers Forum
    2. krfft
    3. Topics
    K
    • Profile
    • Following 0
    • Followers 0
    • Topics 4
    • Posts 10
    • Best 0
    • Controversial 0
    • Groups 0

    Topics created by krfft

    • K

      Override material tag in take

      Cinema 4D SDK
      • r25 c++ • • krfft
      13
      0
      Votes
      13
      Posts
      1.8k
      Views

      ferdinandF

      Hey @krfft,

      thanks for posting your detailed results.

      Cheers,
      Ferdinand

    • K

      Loading Materials from AssetDescriptions into a Scene

      Cinema 4D SDK
      • c++ r25 • • krfft
      3
      0
      Votes
      3
      Posts
      660
      Views

      ferdinandF

      Hello @krfft,

      here the promised code. It is an extension of the Search Assets example which can be found in the Asset API Handbook.

      I hope this helps and cheers,
      Ferdinand

      The result:
      1.gif

      The code:

      static Int32 g_max_materials = 10; /// ------------------------------------------------------------------------------------------------ /// Loads in the first ten material assets into the active document which can be found in the user /// prefs repository. /// /// I did remove most of the comment fluff here, assuming you are already familiar with the rest. /// ------------------------------------------------------------------------------------------------ maxon::Result<void> LoadAssets() { iferr_scope; // Get the active document and do some setup stuff to search for all materials in the user prefs // repository. See FindAssets() example function in the Assets API exmaples for details. BaseDocument* doc = GetActiveDocument(); if (doc == nullptr) return maxon::UnexpectedError(MAXON_SOURCE_LOCATION, "No active document."_s); const maxon::AssetRepositoryRef& repository = maxon::AssetInterface::GetUserPrefsRepository(); const maxon::AssetType assetType = maxon::AssetTypes::File(); const maxon::Id assetFindId = {}; const maxon::Id assetVersion = {}; maxon::BaseArray<maxon::AssetDescription> results; repository.FindAssets( assetType, assetFindId, assetVersion, maxon::ASSET_FIND_MODE::LATEST, results) iferr_return; // Iterate over the results until we have found ten materials. maxon::Int counter = 0; for (maxon::AssetDescription assetDescription : results) { if (counter == g_max_materials) break; maxon::AssetMetaData metadata = assetDescription.GetMetaData(); maxon::Id subTypeId = metadata.Get(maxon::ASSETMETADATA::SubType) iferr_return; // This is a material asset. if (subTypeId == maxon::ASSETMETADATA::SubType_ENUM_Material) { // With a valid url. maxon::Url url = assetDescription.GetUrl() iferr_return; if (url.IsEmpty()) continue; // The url of the asset is in case of material assets a c4d file. So, we merge that asset // document with the active document. ApplicationOutput("@| Type: @, Url: @", counter, subTypeId, url); maxon::String* error = {}; maxon::Bool didMerge = MergeDocument( doc, MaxonConvert(url), SCENEFILTER::MATERIALS, nullptr, error); ApplicationOutput("@: Merged: @, Error: @", counter, didMerge, error); if (didMerge) counter++; } } return maxon::OK; }
    • K

      Getting materials from Asset browser

      Cinema 4D SDK
      • • • krfft
      2
      0
      Votes
      2
      Posts
      477
      Views

      ferdinandF

      Hello @krfft,

      thank you for reaching out to us. And please excuse the delay, but we did decide to wait with our answer for the all new and shiny R25 release. The new R25 C++ documentation does include the first part for an Asset API Handbook which contains most of the basics, i.e., how to iterate over stuff, how to create some basic asset types and so on, other topics will be dealt with at a later point.

      Some, but not all examples given there will translate directly to S24, because some parts of the Asset API have changed, as the Asset Browser is still under development. Below you will find a code snippet for finding the first ten materials in the user preferences repository which should also run under S24. Please feel free to ask follopw up questions if you have any.

      Cheers,
      Ferdinand

      // This code will iterate over the ten first materials that are contained in the user preferences // repository, which will contain the builtin assets of Cinema 4D as well as user databases. // The maximum number of material assets to find so that we do not saturate the console with // possibly thousands of materials that could be stored in the asset browser of a user. static Int32 g_max_object_to_find = 10; maxon::Result<void> FindAssets() { // An error scope handling which is more verbose than a simple "iferr_scope;". If one of the // calls below returns an error, the function will be exited through this block. iferr_scope_handler { ApplicationOutput("Stopped FindAssets() execution with the error: @", err); return err; }; // Get the user preferences repository. For retrieving specific user database repositories, see // CreateRepositories() in asset_api_basics_databases.cpp. const maxon::AssetRepositoryRef& repository = maxon::AssetInterface::GetUserPrefsRepository(); // Now we are preparing some arguments for the call to find assets. // The asset type we are looking for. Asset types are declared in the maxxon::AssetTypes // namespace. const maxon::AssetType assetType = maxon::AssetTypes::File(); // The id of the asset we are looking for, passing an empty id will return assets with any id. const maxon::Id assetFindId = {}; // The version of the asset we are looking for, passing an empty id will return assets with any // version. const maxon::Id assetVersion = {}; // A maxon::BaseArray where we will store all found asset descriptions. maxon::BaseArray<maxon::AssetDescription> results; // There are multiple methods attached to AssetRepositoryInterface to find assets in an // repository. We use here FindAsset() which allows us to define the verion types we want // to retrieve. In this case we pass ASSET_FIND_MODE::LATEST to only find the latest version of // each asset. But we could for example also pass ASSET_FIND_MODE::ALL to find all version of an // asset. repository.FindAssets(assetType, assetFindId, assetVersion, maxon::ASSET_FIND_MODE::LATEST, results) iferr_return; ApplicationOutput("Total number of file-type assets found: @", results.GetCount()); maxon::Int counter = 0; // Iterate over the results and print out some data for the first ten material assets. for (maxon::AssetDescription assetDescription : results) { // Exit when we encountered ten object assets. if (counter == g_max_object_to_find) break; // We retrieve the subtype of the subtype asset. See the topic Asset API - Metadata for more // details on asset metadata. maxon::AssetMetaData metadata = assetDescription.GetMetaData(); maxon::Id subTypeId = metadata.Get(maxon::ASSETMETADATA::SubType) iferr_return; // This asset is of subtype material. if (subTypeId == maxon::ASSETMETADATA::SubType_ENUM_Material) { // Now we collect some data to print out. // The id of the asset itself. maxon::Id assetId = assetDescription.GetId(); // Rather pointless here, because we know the repository in this case already, but an // AssetDescription has a the id of the repository attached it is contained in. maxon::Id repositoryId = assetDescription.GetRepositoryId(); // The storage Url of the asset. const maxon::Url& assetUrl = assetDescription.GetUrl() iferr_return; // The name of the asset. maxon::String assetName = assetDescription.GetMetaString(maxon::OBJECT::BASE::NAME, maxon::LanguageRef()) iferr_return; ApplicationOutput("Found object asset with the id: @", assetId); ApplicationOutput("\tRepository: @", repositoryId); ApplicationOutput("\tLocation: @", assetUrl); ApplicationOutput("\tName: @", assetName); counter++; } } return maxon::OK; }
    • K

      Baking textures for PBR object

      Cinema 4D SDK
      • • • krfft
      2
      0
      Votes
      2
      Posts
      822
      Views

      r_giganteR

      Hi krftt thanks for reaching out us.

      With regard to your question, if the intent is to bake the final appearance of a PBR material on a texture, I confirm that there are no means to achieve this considering that the baked data will also be camera-dependent.

      If, on the contrary, your goal is to sample the shader used in any of the reflection layers used in a PBR material you can consider BaseShader::Sample() and, given a ChannelData, retrieve the color at a specific point - see this thread.

      To browse through the different channel you can use something like:

      # check for an active material mat = doc.GetActiveMaterial() if mat is None: return # retrieve the reflection layers count layersCount = mat.GetReflectionLayerCount() # loop through the layers for i in xrange(layersCount): # get the ReflectionLayer instance and the related data ID reflLayer = mat.GetReflectionLayerIndex(i) reflLayerData = reflLayer.GetDataID() # check for the instance to be the one currently active in the Attribute Manager if reflLayer.GetFlags() & (c4d.REFLECTION_FLAG_TAB): # retrieve the color color = mat[reflLayerData + c4d.REFLECTION_LAYER_COLOR_COLOR] # try to retrieve the shader colorShader = mat[reflLayerData + c4d.REFLECTION_LAYER_COLOR_TEXTURE] # do something with the data retrieved if colorShader is None: print "Selected layer is ", reflLayer.GetName(), "and uses color: ", color else: print "Selected layer is ", reflLayer.GetName(), "and uses shader: ", colorShader.GetName()

      Best, Riccardo