Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'io_scene_gltf2/blender/exp/gltf2_blender_get.py')
-rwxr-xr-xio_scene_gltf2/blender/exp/gltf2_blender_get.py32
1 files changed, 20 insertions, 12 deletions
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_get.py b/io_scene_gltf2/blender/exp/gltf2_blender_get.py
index 940f6f0a..e38906e6 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_get.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_get.py
@@ -32,6 +32,21 @@ def get_object_from_datapath(blender_object, data_path: str):
return prop
+def get_node_socket(blender_material, type, name):
+ """
+ For a given material input name, retrieve the corresponding node tree socket for a given node type.
+
+ :param blender_material: a blender material for which to get the socket
+ :return: a blender NodeSocket for a given type
+ """
+ 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]
+ return None
+
+
def get_socket(blender_material: bpy.types.Material, name: str):
"""
For a given material input name, retrieve the corresponding node tree socket.
@@ -46,13 +61,9 @@ def get_socket(blender_material: bpy.types.Material, name: str):
if name == "Emissive":
# Check for a dedicated Emission node first, it must supersede the newer built-in one
# because the newer one is always present in all Principled BSDF materials.
- 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]
+ emissive_socket = get_node_socket(blender_material, bpy.types.ShaderNodeEmission, "Color")
+ if emissive_socket:
+ return emissive_socket
# If a dedicated Emission node was not found, fall back to the Principled BSDF Emission socket.
name = "Emission"
type = bpy.types.ShaderNodeBsdfPrincipled
@@ -61,11 +72,8 @@ def get_socket(blender_material: bpy.types.Material, name: str):
name = "Color"
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]
+
+ return get_node_socket(blender_material, type, name)
return None