Skip to content

Commit ba0daf1

Browse files
committed
Cinema 4D 2024.0.0 Release
- Added an example that demonstrates accessing node materials and their graph contents in a scene. scripts\05_modules\nodesaccess_nodematerial_2024.py - Added an example that demonstrates creating new node materials and adding graphs to them. scripts\05_modules\create_nodematerial_2024.py - Added an example that demonstrates setting up a Redshift node material composed out of multiple nodes.. scripts\05_modules\create_redshift_nodematerial_2024.py - Added an example that demonstrates setting up a Standard renderer node material composed out of multiple nodes. scripts\05_modules\reate_standard_nodematerial_2023_1.py
1 parent b1ea3fc commit ba0daf1

8 files changed

+287
-186
lines changed

plugins/py-ies_meta_r12/py-ies-meta_loader.pyp renamed to plugins/py-ies_meta_r12/py-ies-meta-loader.pyp

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ import c4d
2222
# SceneLoader are registered earlier than Cinema 4D Resource parser.
2323
# To have all the constant defined in fies_loader.h, you need to manually parse them
2424
import os
25-
import symbol_parser
26-
symbol_parser.parse_and_export_in_caller(os.path.join(os.path.dirname(__file__), "res"))
25+
import mxutils
26+
27+
mxutils.ImportSymbols(os.path.join(os.path.dirname(__file__), "res"))
2728

2829
PLUGIN_ID = 1059408
2930

plugins/readme.md

+1-8
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,7 @@ A data class for creating scene saver plugins (custom scene file format exporter
141141

142142
Exporter, exporting all IES Meta information from the current document to a txt files.
143143
Iterates all objects present in the cache of each objects in the scene to retrieve IES light.
144-
145-
## SceneLoaderData
146-
A data class for creating custom scene file format importer.
147-
148-
### py-ies_meta_loader
149-
150-
Importer, creating IES light from a file exported with the ies_meta_exporter.
151-
144+
152145
## BitmapLoaderData
153146
A data class for creating bitmap loader plugins (custom bitmap file format importer).
154147

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#coding: utf-8
2+
"""Demonstrates accessing node materials and their graph contents in a scene.
3+
4+
Topics:
5+
* Accessing node materials in a document.
6+
* Testing for and accessing graphs for node spaces in a node material.
7+
* Iterating over nodes in a graph.
8+
"""
9+
__author__ = "Ferdinand Hoppe"
10+
__copyright__ = "Copyright (C) 2023 MAXON Computer GmbH"
11+
__date__ = "01/09/2023"
12+
__license__ = "Apache-2.0 License"
13+
__version__ = "2024.0.0"
14+
15+
16+
import c4d
17+
import maxon
18+
19+
doc: c4d.documents.BaseDocument # The active document.
20+
21+
def main():
22+
"""
23+
"""
24+
# Node materials are instances of the classic API material type #BaseMaterial. The node data
25+
# is attached to them as a #NodeMaterial. We can retrieve a #NodeMaterial instance for each
26+
# #BaseMaterial instance, whether or not this material actually is a node material or not.
27+
# Because of that, we must iterate over all material in a document to find node materials and
28+
# retrieve the #NodeMaterial for each of them.
29+
30+
# For each #material in the currently active document get its #nodeMaterial reference.
31+
material: c4d.BaseMaterial
32+
for material in doc.GetMaterials():
33+
nodeMaterial: c4d.NodeMaterial = material.GetNodeMaterialReference()
34+
35+
# To test if a material has a graph for a specific space, we must use the method #HasSpace.
36+
# To support 3rd party render engines, you must ask them for their node space ID.
37+
for nid in ("net.maxon.nodespace.standard", # Standard Renderer
38+
"com.redshift3d.redshift4c4d.class.nodespace"): # Redshift Renderer
39+
if not nodeMaterial.HasSpace(nid):
40+
continue
41+
42+
# This material has a graph for the space #nid, we retrieve it.
43+
graph: maxon.GraphModelInterface = nodeMaterial.GetGraph(nid)
44+
if graph.IsNullValue():
45+
raise RuntimeError("Found malformed empty graph associated with node space.")
46+
47+
# Now we iterate over all items in the graph.
48+
print (f"\nThe material '{material.GetName()}' has a graph in the node space '{nid}'.")
49+
root: maxon.GraphNode = graph.GetRoot()
50+
51+
# Iterate over the direct children of the graph root.
52+
node: maxon.GraphNode
53+
for node in root.GetChildren():
54+
print (f"\tDirect child of graph root: {node.GetId()}")
55+
56+
print ("\t" + "-" * 60)
57+
# Iterate over all nodes in the graph, i.e., unpack things like nodes nested in groups.
58+
# With the mask argument we could also include ports in this iteration.
59+
for node in root.GetInnerNodes(mask=maxon.NODE_KIND.NODE, includeThis=False):
60+
print (f"\tNode in the graph: {node}")
61+
62+
c4d.EventAdd()
63+
64+
65+
if __name__ == "__main__":
66+
main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#coding: utf-8
2+
"""Demonstrates creating new node materials and adding graphs to them.
3+
4+
See the `create_redshift_nodematerial` and `create_standard_nodematerial` examples in this directory
5+
for also populating a graph with nodes and connecting them.
6+
7+
Topics:
8+
* Creating node materials.
9+
* Adding and removing graphs to them.
10+
"""
11+
__author__ = "Ferdinand Hoppe"
12+
__copyright__ = "Copyright (C) 2023 MAXON Computer GmbH"
13+
__date__ = "01/09/2023"
14+
__license__ = "Apache-2.0 License"
15+
__version__ = "2024.0.0"
16+
17+
import c4d
18+
import maxon
19+
20+
doc: c4d.documents.BaseDocument # The active document.
21+
22+
def main():
23+
"""
24+
"""
25+
# Node materials are instances of the classic API material type #BaseMaterial. The node data
26+
# is attached to them as a #NodeMaterial. We can retrieve a #NodeMaterial instance for each
27+
# #BaseMaterial instance, whether or not this material actually is a node material or not.
28+
29+
# Instantiate a classic API material.
30+
material: c4d.BaseMaterial = c4d.BaseMaterial(c4d.Mmaterial)
31+
if not material:
32+
raise MemoryError(f"{material = }")
33+
doc.InsertMaterial(material)
34+
35+
# Get the node material for it and add a graph for the currently active material space to it.
36+
nodeMaterial: c4d.NodeMaterial = material.GetNodeMaterialReference()
37+
graph: maxon.GraphModelInterface = nodeMaterial.CreateDefaultGraph(c4d.GetActiveNodeSpaceId())
38+
if graph.IsNullValue():
39+
raise RuntimeError("Could not add graph to material.")
40+
41+
# The method #CreateDefaultGraph we used above does not create an empty graph, but the setup
42+
# the respective node space considers to be its default setup. For Redshift this is for example
43+
# an RS Standard Material node connected to an Output end node.
44+
print ("Nodes in CreateDefaultGraph setup:")
45+
for node in graph.GetRoot().GetInnerNodes(mask=maxon.NODE_KIND.NODE, includeThis=False):
46+
print (f"{node}")
47+
48+
# Remove the graph we just created.
49+
nodeMaterial.RemoveGraph(c4d.GetActiveNodeSpaceId())
50+
51+
# We can also create an empty graph which contains no nodes at all with.
52+
graph: maxon.GraphModelInterface = nodeMaterial.CreateEmptyGraph(c4d.GetActiveNodeSpaceId())
53+
if graph.IsNullValue():
54+
raise RuntimeError("Could not add graph to material.")
55+
56+
print ("Nodes in CreateEmptyGraph setup:")
57+
for node in graph.GetRoot().GetInnerNodes(mask=maxon.NODE_KIND.NODE, includeThis=False):
58+
print (f"{node}")
59+
60+
# Remove the graph again.
61+
nodeMaterial.RemoveGraph(c4d.GetActiveNodeSpaceId())
62+
63+
# Finally, we should be aware that node material can hold graphs for multiple node spaces and
64+
# therefore can be used with multiple render engines. To do this, we can simply add multiple
65+
# graphs for specific nodes spaces.
66+
67+
# Add a default graph for both the Redshift and Standard material node space, check the "Basic"
68+
# tab of the material, it will list a graph for both spaces. When you switch between render
69+
# engines, the material will have its own graph for each engine. To support 3rd party render
70+
# engines, you must ask their vendor for their node space ID.
71+
nodeMaterial.CreateDefaultGraph("com.redshift3d.redshift4c4d.class.nodespace")
72+
nodeMaterial.CreateDefaultGraph("net.maxon.nodespace.standard")
73+
74+
75+
if __name__ == "__main__":
76+
main()

scripts/05_modules/node/create_nodematerial_r26.py

-117
This file was deleted.

0 commit comments

Comments
 (0)