NodesGraphModelInterface Manual

Table of Contents

About

maxon::nodes::NodesGraphModelInterface is an implementation of maxon::GraphModelInterface and presents the node system (NodeSystemInterface Manual) as a graph model.

Note
If possible, one should work with the more generic maxon::GraphModelInterface, see GraphModelInterface Manual.

Access

The maxon::nodes::NodesGraphModelRef is obtained from the NodeMaterial:

See NodeMaterial Manual.

// This example obtains the NodesGraphModelRef from the given NodeMaterial.
// access node space
const maxon::Id nodeSpaceID = GetActiveNodeSpaceId();
if (nodeMaterial->HasSpace(nodeSpaceID) == false)
return maxon::IllegalArgumentError(MAXON_SOURCE_LOCATION);
const maxon::nodes::NodesGraphModelRef& graph = nodeMaterial->GetGraph(nodeSpaceID) iferr_return;

Use

The node graph model gives access to the stored node system:

See NodeSystemInterface Manual.

// This example obtains the NodeSystem from the given NodeMaterial.
const maxon::nodes::NodesGraphModelRef& graph = nodeMaterial->GetGraph(nodeSpaceID) iferr_return;
const maxon::nodes::NodeSystem& system = graph.GetNodeSystem();

A new nodes graph can be created with the class maxon::nodes::NodesGraphModelClass().

// This example creates a new NodesGraphModelRef.
maxon::nodes::MutableRoot root = maxon::nodes::CoreNodesNodeSystemClass().CreateNodeSystem() iferr_return;
const maxon::AssetRepositoryRef& repository = maxon::AssetInterface::GetBuiltinRepository();
const auto nodesGraphModelClass = maxon::nodes::NodesGraphModelClass();
maxon::nodes::NodesGraphModelRef nodesGraphModel = nodesGraphModelClass.Create() iferr_return;
nodesGraphModel.Init(sys, repository, filter, true) iferr_return;

A view on a node graph is a new node graph that presents only a subset of the original node graph.

A node system can contain multiple children under the root node:

// This example obtains a node graph from a node material and inserts a new node.
// get graph
const maxon::nodes::NodesGraphModelRef& nodeGraph = nodeMaterial->GetGraph(nodeSpaceID) iferr_return;
if (nodeGraph.IsReadOnly())
return maxon::IllegalStateError(MAXON_SOURCE_LOCATION);
// start a new change list if we want to apply the changes also to a different graph
nodeGraph.StartNewChangeList() iferr_return;
// start transaction
maxon::GraphTransaction transaction = nodeGraph.BeginTransaction() iferr_return;
// prepare for adding a new node
const maxon::Id nodeAssetId { "net.maxonexample.noderenderer.usernode" };
const maxon::AssetRepositoryRef& repository = maxon::AssetInterface::GetBuiltinRepository();
maxon::nodes::NodeTemplate nodeTemplate = maxon::nodes::NodesLib::LoadTemplate(repository, nodeAssetId) iferr_return;
// add new node
// leave the 'childId' parameter empty to create a UUID
maxon::GraphNode userGraphNode = nodeGraph.AddChild(maxon::Id(), nodeTemplate) iferr_return;
// set node name
userGraphNode.SetValue<decltype(maxon::NODE::BASE::NAME)>("My user node"_s) iferr_return;
// commit transaction
transaction.Commit() iferr_return;
// this change list contains the latest changes
const maxon::ChangeList& list = nodeGraph.GetChangeList();

Nodes can be organized in group nodes:

Nodes are based on assets from the asset repository:

A maxon::nodes::NodeSystemManagerInterface manages a node system and its views:

maxon::nodes::NodeSystemManagerInterface::FILTER::INCLUDE_INNER
@ INCLUDE_INNER
Includes inner nodes in the view.
maxon::GraphNodeFunctions::SetValue
Result< Bool > SetValue(const InternedId &attr, ForwardingDataPtr &&value, Bool checkAndInvalidate=true) const
Definition: graph.h:1746
maxon::GraphTransaction::Commit
Result< void > Commit(const DataDictionary &userData=GetPtrSizedZeroRef< DataDictionary >(), Bool validate=true)
maxon::nodes::NodeSystemInterface::FINALIZE_FLAGS::NONE
@ NONE
Don't do any finalizations at all.
maxon::AssetInterface::GetBuiltinRepository
static const MAXON_METHOD AssetRepositoryRef & GetBuiltinRepository()
GetActiveNodeSpaceId
maxon::Id GetActiveNodeSpaceId()
maxon::Id
Definition: apibaseid.h:250
iferr_return
#define iferr_return
Definition: resultbase.h:1465
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:66
maxon::NO_VALUE
static const NO_VALUE_TYPE NO_VALUE
Definition: optional.h:17
maxon::nodes::NodesLib::LoadTemplate
static MAXON_METHOD Result< NodeTemplate > LoadTemplate(const AssetRepositoryRef &repo, const Id &assetId)
maxon::nodes::MutableRoot::EndModification
Result< NodeSystem > EndModification(Opt< ChangeList & > list={}, NodeSystem::FINALIZE_FLAGS finalize=NodeSystem::FINALIZE_FLAGS::CLEANUP)
maxon::nodes::MutableRoot
Definition: nodesystem.h:2141
NodeMaterial::HasSpace
Bool HasSpace(const maxon::Id &spaceId) const
Definition: c4d_basematerial.h:403
NodeMaterial::GetGraph
maxon::Result< const maxon::nodes::NodesGraphModelRef & > GetGraph(const maxon::Id &spaceId) const
Definition: c4d_basematerial.h:475
maxon::nodes::NodeSystemManagerInterface::FILTER::INCLUDE_HIDDEN
@ INCLUDE_HIDDEN
Includes hidden nodes in the view.
maxon::GraphTransaction
Definition: graph.h:1076
maxon::GraphNode
Definition: graph.h:2210