Skip to content

Commit 1d8b894

Browse files
author
Sightskeye
committed
Fix: Support Emission link input blender 4
1 parent e77fde3 commit 1d8b894

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

OmniscientImporter/cameraProjection/cameraProjectionMaterial.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import bpy
22
from bpy.types import PropertyGroup
33
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
55
from .projection_shader_group import create_projection_shader_group
66
from ..ui.utils import find_collection_and_shot_index_by_camera
77

@@ -192,13 +192,16 @@ def ensure_bsdf_connection(material, latest_mix_rgb_visibility_node):
192192
except IndexError as e:
193193
print(f"Failed to create link: {latest_mix_rgb_visibility_node.name} [0] -> {principled_bsdf_node.name} [0]. Error: {e}")
194194

195-
# Create a new link from the latest mix node to the Emission input of the BSDF node
196195
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+
202205
# Create a new link from the mix_rgb_emission_node to the Emission input of the BSDF node
203206
mix_rgb_emission_node = find_node(nodes, 'MIX_RGB', 'MixRGBEmissionNode')
204207
if mix_rgb_emission_node:

OmniscientImporter/cameraProjection/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,8 @@ def hide_specific_nodes(node_tree, node_types):
6666
def find_node(nodes, node_type, node_name=None):
6767
if node_name:
6868
return next((node for node in nodes if node.type == node_type and node.name == node_name), None)
69-
return next((node for node in nodes if node.type == node_type), None)
69+
return next((node for node in nodes if node.type == node_type), None)
70+
71+
def is_blender_4():
72+
from bpy.app import version
73+
return version >= (4, 0, 0)

0 commit comments

Comments
 (0)