glTF exporter: take care of active output node

This commit is contained in:
Julien Duroure 2020-11-30 18:47:05 +01:00
parent 5f2cb885ab
commit 5088c8d9d7
Notes: blender-bot 2023-02-14 18:51:12 +01:00
Referenced by issue #78926, Materials export blank if unconnected Principled BSDF node is anywhere in a "Background" material during gltf 2.0 export
3 changed files with 15 additions and 2 deletions

View File

@ -15,7 +15,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": (1, 5, 3),
"version": (1, 5, 4),
'blender': (2, 91, 0),
'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0',

View File

@ -38,7 +38,7 @@ def detect_shadeless_material(blender_material, export_settings):
info = {}
for node in blender_material.node_tree.nodes:
if node.type == 'OUTPUT_MATERIAL':
if node.type == 'OUTPUT_MATERIAL' and node.is_active_output:
socket = node.inputs[0]
break
else:

View File

@ -60,6 +60,7 @@ def get_socket(blender_material: bpy.types.Material, name: str):
type = bpy.types.ShaderNodeEmission
name = "Color"
nodes = [n for n in blender_material.node_tree.nodes if isinstance(n, type) and not n.mute]
nodes = [node for node in nodes if check_if_is_linked_to_active_output(node.outputs[0])]
inputs = sum([[input for input in node.inputs if input.name == name] for node in nodes], [])
if inputs:
return inputs[0]
@ -72,6 +73,7 @@ def get_socket(blender_material: bpy.types.Material, name: str):
else:
type = bpy.types.ShaderNodeBsdfPrincipled
nodes = [n for n in blender_material.node_tree.nodes if isinstance(n, type) and not n.mute]
nodes = [node for node in nodes if check_if_is_linked_to_active_output(node.outputs[0])]
inputs = sum([[input for input in node.inputs if input.name == name] for node in nodes], [])
if inputs:
return inputs[0]
@ -98,6 +100,17 @@ def get_socket_old(blender_material: bpy.types.Material, name: str):
return None
def check_if_is_linked_to_active_output(shader_socket):
for link in shader_socket.links:
if isinstance(link.to_node, bpy.types.ShaderNodeOutputMaterial) and link.to_node.is_active_output is True:
return True
if len(link.to_node.outputs) > 0: # ignore non active output, not having output sockets
ret = check_if_is_linked_to_active_output(link.to_node.outputs[0]) # recursive until find an output material node
if ret is True:
return True
return False
def find_shader_image_from_shader_socket(shader_socket, max_hops=10):
"""Find any ShaderNodeTexImage in the path from the socket."""