|
1 | 1 | import bpy |
2 | 2 | from bpy.types import PropertyGroup |
3 | 3 | from bpy.props import StringProperty |
4 | | -from .utils import get_or_create_node, create_link, add_driver, hide_specific_nodes, find_node |
| 4 | +from .utils import get_or_create_node, create_link, add_driver, hide_specific_nodes, find_node, is_blender_4 |
5 | 5 | from .projection_shader_group import create_projection_shader_group |
6 | 6 | from ..ui.utils import find_collection_and_shot_index_by_camera |
7 | 7 |
|
@@ -192,13 +192,16 @@ def ensure_bsdf_connection(material, latest_mix_rgb_visibility_node): |
192 | 192 | except IndexError as e: |
193 | 193 | print(f"Failed to create link: {latest_mix_rgb_visibility_node.name} [0] -> {principled_bsdf_node.name} [0]. Error: {e}") |
194 | 194 |
|
195 | | - # Create a new link from the latest mix node to the Emission input of the BSDF node |
196 | 195 | try: |
197 | | - emission_input_index = 19 |
198 | | - links.new(latest_mix_rgb_visibility_node.outputs[0], principled_bsdf_node.inputs[emission_input_index]) |
199 | | - except IndexError as e: |
200 | | - print(f"Failed to create link: {latest_mix_rgb_visibility_node.name} [0] -> {principled_bsdf_node.name} [{emission_input_index}]. Error: {e}") |
201 | | - |
| 196 | + emission_input_name = "Emission Color" if is_blender_4() else "Emission" |
| 197 | + emission_input = principled_bsdf_node.inputs.get(emission_input_name) |
| 198 | + if emission_input is not None: |
| 199 | + links.new(latest_mix_rgb_visibility_node.outputs[0], emission_input) |
| 200 | + else: |
| 201 | + print(f"{emission_input_name} input not found in {principled_bsdf_node.name}") |
| 202 | + except Exception as e: |
| 203 | + print(f"Failed to create link: {latest_mix_rgb_visibility_node.name} [0] -> {principled_bsdf_node.name} [{emission_input_name}]. Error: {e}") |
| 204 | + |
202 | 205 | # Create a new link from the mix_rgb_emission_node to the Emission input of the BSDF node |
203 | 206 | mix_rgb_emission_node = find_node(nodes, 'MIX_RGB', 'MixRGBEmissionNode') |
204 | 207 | if mix_rgb_emission_node: |
|
0 commit comments