Files
test2/source/blender/python/intern/bpy_inline_shader_nodes.hh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

14 lines
235 B
C++
Raw Normal View History

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
2025-09-11 06:08:30 +02:00
/* SPDX-FileCopyrightText: 2025 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup pythonintern
*/
#pragma once
#include <Python.h>
[[nodiscard]] PyObject *BPyInit_inline_shader_nodes_type();