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);

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;
// 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
// store ports in base array
inputPorts.GetChildren(ports) iferr_return;

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);
}
}

Further functions are:

NodeMaterial::GetBaseListForNode
maxon::Result< const BaseList2D * > GetBaseListForNode(const maxon::Id &spaceId, const maxon::NodePath &nodePath)
Definition: c4d_basematerial.h:427
BaseList2D
Definition: c4d_baselist.h:2174
maxon::GraphNodeFunctions::GetChildren
Result< Bool > GetChildren(const ValueReceiver< const GraphNode & > &callback, NODE_KIND mask=NODE_KIND::ALL_MASK) const
Definition: graph.h:1303
DescID
Definition: lib_description.h:328
maxon::PORT_DIR::INPUT
@ INPUT
Input direction, i.e., an input port or an incoming connection.
BaseList2D::IsNodeBased
Bool IsNodeBased() const
maxon::String
Definition: string.h:1225
BaseDocument::GetActiveMaterial
BaseMaterial * GetActiveMaterial(void)
maxon::OK
return OK
Definition: apibase.h:2620
GetActiveNodeSpaceId
maxon::Id GetActiveNodeSpaceId()
NodeMaterial::GetDescIDForNodePort
maxon::Result< void > GetDescIDForNodePort(const maxon::Id &spaceId, const maxon::GraphNode &node, const maxon::GraphNode &port, DescID &result) const
Definition: c4d_basematerial.h:437
maxon::Id
Definition: apibaseid.h:250
maxon::GraphNodeFunctions::GetPortList
Result< typename SFINAEHelper< GraphNode, BASE >::type > GetPortList(PORT_DIR dir) const
Definition: graph.h:1358
iferr_return
#define iferr_return
Definition: resultbase.h:1465
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
BaseList2D::FindCTrack
CTrack * FindCTrack(const DescID &id)
maxon::BaseArray
Definition: basearray.h:411
DiagnosticOutput
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:176
CTrack
Definition: c4d_canimation.h:659
NodeMaterial::HasSpace
Bool HasSpace(const maxon::Id &spaceId) const
Definition: c4d_basematerial.h:403
NodeMaterial::GetMaterialNodePath
maxon::Result< void > GetMaterialNodePath(const maxon::Id &spaceId, maxon::NodePath &result) const
Definition: c4d_basematerial.h:411
NodeMaterial::GetGraph
maxon::Result< const maxon::nodes::NodesGraphModelRef & > GetGraph(const maxon::Id &spaceId) const
Definition: c4d_basematerial.h:475
NodeMaterial
Definition: c4d_basematerial.h:390
BaseList2D::GetName
String GetName() const
Definition: c4d_baselist.h:2348
BaseMaterial
Definition: c4d_basematerial.h:27
maxon::GraphNode
Definition: graph.h:2312