glTF exporter: fix crash managing shader node groups

Happen when multiple link on the same socket
This commit is contained in:
Julien Duroure
2024-09-26 15:21:35 +02:00
parent 124bae5a4d
commit 3cfeebe7c7
2 changed files with 9 additions and 5 deletions

View File

@@ -5,7 +5,7 @@
bl_info = {
'name': 'glTF 2.0 format',
'author': 'Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
"version": (4, 3, 35),
"version": (4, 3, 36),
'blender': (4, 2, 0),
'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0',

View File

@@ -890,6 +890,9 @@ def get_texture_transform_from_mapping_node(mapping_node, export_settings):
def check_if_is_linked_to_active_output(shader_socket, group_path):
# Here, group_path must be copyed, because if there are muliply link that enter/exit a group node
# This will modify it, and we don't want to modify the original group_path (from the parameter) inside the loop
for link in shader_socket.links:
# If we are entering a node group
@@ -897,10 +900,11 @@ def check_if_is_linked_to_active_output(shader_socket, group_path):
socket_name = link.to_socket.name
sockets = [n for n in link.to_node.node_tree.nodes if n.type == "GROUP_INPUT"][0].outputs
socket = [s for s in sockets if s.name == socket_name][0]
group_path.append(link.to_node)
new_group_path = group_path.copy()
new_group_path.append(link.to_node)
# TODOSNode : Why checking outputs[0] ? What about alpha for texture node, that is outputs[1] ????
# recursive until find an output material node
ret = check_if_is_linked_to_active_output(socket, group_path)
ret = check_if_is_linked_to_active_output(socket, new_group_path)
if ret is True:
return True
continue
@@ -910,10 +914,10 @@ def check_if_is_linked_to_active_output(shader_socket, group_path):
socket_name = link.to_socket.name
sockets = group_path[-1].outputs
socket = [s for s in sockets if s.name == socket_name][0]
group_path = group_path[:-1]
new_group_path = group_path[:-1]
# TODOSNode : Why checking outputs[0] ? What about alpha for texture node, that is outputs[1] ????
# recursive until find an output material node
ret = check_if_is_linked_to_active_output(socket, group_path)
ret = check_if_is_linked_to_active_output(socket, new_group_path)
if ret is True:
return True
continue