Shader Nodes: add Python API for inlined shader nodes
This makes the shader node inlining from #141936 available to external renderers which use the Python API. Existing external renderer add-ons need to be updated to get the inlined node tree from a material like below instead of using the original node tree of the material directly. The main contribution are these three methods: `Material.inline_shader_nodes()`, `Light.inline_shader_nodes()` and `World.inline_shader_nodes()`. In theory, there could be an inlining API for node trees more generally, but some aspects of the inlining are specific to shader nodes currently. For example the detection of output nodes and implicit input handling. Furthermore, having the method on e.g. `Material` instead of on the node tree might be more future proof for the case when we want to store input properties of the material on the `Material` which are then passed into the shader node tree. Example from API docs: ```python import bpy # The materials should be retrieved from the evaluated object to make sure that # e.g. edits of Geometry Nodes are applied. depsgraph = bpy.context.view_layer.depsgraph ob = bpy.context.active_object ob_eval = depsgraph.id_eval_get(ob) material_eval = ob_eval.material_slots[0].material # Compute the inlined shader nodes. # Important: Do not loose the reference to this object while accessing the inlined # node tree. Otherwise there will be a crash due to a dangling pointer. inline_shader_nodes = material_eval.inline_shader_nodes() # Get the actual inlined `bpy.types.NodeTree`. tree = inline_shader_nodes.node_tree for node in tree.nodes: print(node.name) ``` Pull Request: https://projects.blender.org/blender/blender/pulls/145811
This commit is contained in:
@@ -2189,6 +2189,24 @@ def write_rst_geometry_set(basepath):
|
||||
EXAMPLE_SET_USED.add("bpy.types.GeometrySet")
|
||||
|
||||
|
||||
def write_rst_inline_shader_nodes(basepath):
|
||||
"""
|
||||
Write the RST files for ``bpy.types.InlineShaderNodes``.
|
||||
"""
|
||||
if 'bpy.types.InlineShaderNodes' in EXCLUDE_MODULES:
|
||||
return
|
||||
|
||||
# Write the index.
|
||||
filepath = os.path.join(basepath, "bpy.types.InlineShaderNodes.rst")
|
||||
with open(filepath, "w", encoding="utf-8") as fh:
|
||||
fw = fh.write
|
||||
fw(title_string("InlineShaderNodes", "="))
|
||||
write_example_ref("", fw, "bpy.types.InlineShaderNodes")
|
||||
pyclass2sphinx(fw, "bpy.types", "InlineShaderNodes", bpy.types.InlineShaderNodes, False)
|
||||
|
||||
EXAMPLE_SET_USED.add("bpy.types.InlineShaderNodes")
|
||||
|
||||
|
||||
def write_rst_msgbus(basepath):
|
||||
"""
|
||||
Write the RST files of ``bpy.msgbus`` module
|
||||
@@ -2541,6 +2559,7 @@ def rna2sphinx(basepath):
|
||||
write_rst_ops_index(basepath) # `bpy.ops`.
|
||||
write_rst_msgbus(basepath) # `bpy.msgbus`.
|
||||
write_rst_geometry_set(basepath) # `bpy.types.GeometrySet`.
|
||||
write_rst_inline_shader_nodes(basepath) # `bpy.types.InlineShaderNodes`.
|
||||
pyrna2sphinx(basepath) # `bpy.types.*` & `bpy.ops.*`.
|
||||
write_rst_data(basepath) # `bpy.data`.
|
||||
write_rst_importable_modules(basepath)
|
||||
|
||||
Reference in New Issue
Block a user