Core Nodes Implementation
A core node is a basic node of Cinema 4D 's node material system. It represents a basic functionality that can be used in a node material.
The relevant interfaces needed to implement custom core nodes are found in the corenodes.framework .
A simple custom core node is implemented as follows:
// This example shows #include " maxon/micronodes.h "// core node class class MaximumComponentCoreNode { public : // input port "colora" MAXON_PORT_INPUT ( maxon::ColorA , colora);
// input port "colorb" MAXON_PORT_INPUT ( maxon::ColorA , colorb);
// output port "result" MAXON_PORT_OUTPUT ( maxon::ColorA , result);
// access input port color const maxon::ColorA & inputColorA = ports.colora(); const maxon::ColorA & inputColorB = ports.colorb();
// invert color maxon::ColorA resultColor; resultColor. r = maxon::Max (inputColorA. r , inputColorB. r ); resultColor. g = maxon::Max (inputColorA. g , inputColorB. g ); resultColor. b = maxon::Max (inputColorA. b , inputColorB. b ); resultColor. a = maxon::Max (inputColorA. a , inputColorB. a );
// store in result port ports.result.Update(resultColor);
// we choose pure registration, because the node has no lazy evaluation (and is evaluated from left to right). MAXON_CORENODE_REGISTER_PURE (MaximumComponentCoreNode, "net.maxonexample.corenodes.examplenode" );
The description of the core node must be created with the Resource Editor.The new data type must have the ID of the core node.
The data type properties are:
The core node needs a new attribute:
The name of the node is set with net.maxon.node.base.
Port descriptions are created with new attributes:
The description of the core node must be loaded and handled properly:
// This example loads and handles the description database containing the core node description. static maxon::BaseArray<maxon::GenericData> g_coreNodeDescriptions;// the ID of the database storing the core node's description static maxon::Id g_corenodesDatabaseId = maxon::Id { "net.maxonexample.corenodes" };
// function to process the description // static maxon::Result<void> HandleCoreNodeDescriptions(const maxon::Id& databaseId) //{ // iferr_scope; // // const maxon::Id catData = maxon::DATADESCRIPTION_CATEGORY_DATA; // const maxon::LanguageRef language = maxon::LanguageRef(); // // maxon::BaseArray<maxon::IdAndVersion> ids = maxon::DataDescriptionDefinitionDatabaseInterface::GetRegisteredDescriptions(g_corenodesDatabaseId, catData, language) iferr_return; // for (const maxon::IdAndVersion& id : ids) // { // maxon::DataDescription description = maxon::DataDescriptionDatabaseInterface::LoadDescription(maxon::DATADESCRIPTION_CATEGORY_DATA, maxon::LanguageRef(), id.first) iferr_return; // // maxon::DataDictionary info = description.GetInfo(); // // maxon::Id builderId = info.Get(maxon::DESCRIPTION::DATA::INFO::PROCESSOR, maxon::Id()); // if (builderId.IsPopulated()) // { // const maxon::DescriptionProcessor& processor = maxon::DescriptionProcessors::Get(builderId); // if (processor) // { // maxon::GenericData d = processor.Process(id.first, description) iferr_return; // g_coreNodeDescriptions.Append(std::move(d)) iferr_return; // } // } // } // // return maxon::OK; //}
// load description static maxon::Result<void> HandleInitializeModule() { iferr_scope_handler { err.CritStop(); return err; };
// get plugin "res" folder maxon::Url pluginDir = maxon::Application::GetUrl ( maxon::APPLICATION_URLTYPE::CURRENT_MODULE_RESOURCE_DIR ) iferr_return ;
// get "nodes" folder within the "res" folder const maxon::Url coreNodesResourceUrl = pluginDir.Append( "nodes" _s) iferr_return ;
// register database maxon::DataDescriptionDefinitionDatabaseInterface::RegisterDatabaseWithUrl (g_corenodesDatabaseId, coreNodesResourceUrl) iferr_return ;
// handle the core node description //HandleCoreNodeDescriptions(g_corenodesDatabaseId) iferr_return; // commented out due to duplication in DB registration occurred because of the line above
return maxon::OK ; }// free description static void HandleFreeModule() { g_coreNodeDescriptions. 重置 (); } MAXON_INITIALIZATION (HandleInitializeModule, HandleFreeModule);
This is an extended version of the typical procedure to load MAXON API descriptions. See Loading Data Descriptions .