NodeMaterial Manual

Table of Contents

About

A NodeMaterial represents a material containing node system. It can contain a separate node system for each available node space.

Access

A node material is accessed by checking if a given material uses nodes. Then the material can be cast into NodeMaterial.

// This example checks if the given material is node based and casts it into NodeMaterial.
// get active material
BaseMaterial* const material = doc->GetActiveMaterial();
if (material == nullptr)
return maxon::IllegalArgumentError(MAXON_SOURCE_LOCATION);
// check if node based
if (material->IsNodeBased() == false)
return maxon::IllegalArgumentError(MAXON_SOURCE_LOCATION);
// get node material
NodeMaterial* const nodeMaterial = static_cast<NodeMaterial*>(material);
Bool IsNodeBased() const
Definition: c4d_basematerial.h:28
Definition: c4d_basematerial.h:391
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
const char * doc
Definition: pyerrors.h:226

Use

A node material can contain multiple node system; one system for each node space.

// 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;
maxon::Id GetActiveNodeSpaceId()
maxon::Result< const maxon::nodes::NodesGraphModelRef & > GetGraph(const maxon::Id &spaceId) const
Definition: c4d_basematerial.h:475
Bool HasSpace(const maxon::Id &spaceId) const
Definition: c4d_basematerial.h:403
Definition: apibaseid.h:253
#define iferr_return
Definition: resultbase.h:1519
// This example gets the material end node of the given NodeMaterial and
// stores all input ports of that node in an array.
const maxon::Id nodeSpaceID = GetActiveNodeSpaceId();
// get end node path
maxon::NodePath path;
nodeMaterial->GetMaterialNodePath(nodeSpaceID, path) iferr_return;
if (path.IsEmpty())
return maxon::OK;
// get graph and node
const maxon::nodes::NodesGraphModelRef& graph = nodeMaterial->GetGraph(nodeSpaceID) iferr_return;
const maxon::GraphNode node = graph.GetNode(path);
// get input ports
const maxon::GraphNode inputPorts = node.GetPortList(maxon::PORT_DIR::INPUT) iferr_return;
// store ports in base array
inputPorts.GetChildren(ports) iferr_return;
maxon::Result< void > GetMaterialNodePath(const maxon::Id &spaceId, maxon::NodePath &result) const
Definition: c4d_basematerial.h:411
Definition: basearray.h:412
Result< Bool > GetChildren(const ValueReceiver< const GraphNode & > &callback, NODE_KIND mask=NODE_KIND::ALL_MASK) const
Definition: graph.h:1160
Definition: graph.h:1950
return OK
Definition: apibase.h:2690
@ INPUT
Input direction, i.e., an input port or an incoming connection.
Definition: node.h:10

The node system does not store animation data. The animation data for a given node is stored in a BaseList2D object and its CTrack animation tracks.

// This example accesses the BaseList2D object that stores the animation data for the given GraphNode.
// get BaseList2D representation
const BaseList2D* const baseList = nodeMaterial->GetBaseListForNode(nodeSpaceID, path) iferr_return;
BaseList2D* const listElementNonConst = const_cast<BaseList2D*>(baseList);
// check all input ports
for (const maxon::GraphNode& port : ports)
{
// get DescID
DescID paramterID;
nodeMaterial->GetDescIDForNodePort(nodeSpaceID, node, port, paramterID) iferr_return;
const CTrack* const track = listElementNonConst->FindCTrack(paramterID);
if (track != nullptr)
{
const maxon::String name = track->GetName();
DiagnosticOutput("Track name: @", name);
}
}
const char const char * name
Definition: abstract.h:195
Definition: c4d_baselist.h:2208
String GetName() const
Definition: c4d_baselist.h:2381
CTrack * FindCTrack(const DescID &id)
Definition: c4d_canimation.h:671
Definition: lib_description.h:330
maxon::Result< const BaseList2D * > GetBaseListForNode(const maxon::Id &spaceId, const maxon::NodePath &nodePath)
Definition: c4d_basematerial.h:427
maxon::Result< void > GetDescIDForNodePort(const maxon::Id &spaceId, const maxon::GraphNode &node, const maxon::GraphNode &port, DescID &result) const
Definition: c4d_basematerial.h:437
Definition: string.h:1235
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:176

Further functions are: