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:
authorJulien Duroure <julien.duroure@gmail.com>2020-09-05 16:33:18 +0300
committerJulien Duroure <julien.duroure@gmail.com>2020-09-05 16:33:18 +0300
commit3a5aaa9b9999a0eada72076ba5b5bacc653e4528 (patch)
treee170b508072974a151c34ea4ea0fba70000a752a /io_scene_gltf2/blender/exp/gltf2_blender_get.py
parent109632093bd5f3c7754cf6d66cfe66579d734cb3 (diff)
glTF exporter: materials: export factors from MULTIPLY nodes
Diffstat (limited to 'io_scene_gltf2/blender/exp/gltf2_blender_get.py')
-rwxr-xr-xio_scene_gltf2/blender/exp/gltf2_blender_get.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_get.py b/io_scene_gltf2/blender/exp/gltf2_blender_get.py
index 4f66aa6a..27f4ae18 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_get.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_get.py
@@ -218,3 +218,67 @@ def get_node(data_path):
return None
return node_name[:(index)]
+
+
+def get_factor_from_socket(socket, kind):
+ """
+ For baseColorFactor, metallicFactor, etc.
+ Get a constant value from a socket, or a constant value
+ from a MULTIPLY node just before the socket.
+ kind is either 'RGB' or 'VALUE'.
+ """
+ fac = __get_const_from_socket(socket, kind)
+ if fac is not None:
+ return fac
+
+ node = __previous_node(socket)
+ if node is not None:
+ x1, x2 = None, None
+ if kind == 'RGB':
+ if node.type == 'MIX_RGB' and node.blend_type == 'MULTIPLY':
+ # TODO: handle factor in inputs[0]?
+ x1 = __get_const_from_socket(node.inputs[1], kind)
+ x2 = __get_const_from_socket(node.inputs[2], kind)
+ if kind == 'VALUE':
+ if node.type == 'MATH' and node.operation == 'MULTIPLY':
+ x1 = __get_const_from_socket(node.inputs[0], kind)
+ x2 = __get_const_from_socket(node.inputs[1], kind)
+ if x1 is not None and x2 is None: return x1
+ if x2 is not None and x1 is None: return x2
+
+ return None
+
+
+def __get_const_from_socket(socket, kind):
+ if not socket.is_linked:
+ if kind == 'RGB':
+ if socket.type != 'RGBA': return None
+ return list(socket.default_value)[:3]
+ if kind == 'VALUE':
+ if socket.type != 'VALUE': return None
+ return socket.default_value
+
+ # Handle connection to a constant RGB/Value node
+ prev_node = __previous_node(socket)
+ if prev_node is not None:
+ if kind == 'RGB' and prev_node.type == 'RGB':
+ return list(prev_node.outputs[0].default_value)[:3]
+ if kind == 'VALUE' and prev_node.type == 'VALUE':
+ return prev_node.outputs[0].default_value
+
+ return None
+
+
+def __previous_node(socket):
+ while True:
+ if not socket.is_linked:
+ return None
+
+ node = socket.links[0].from_node
+
+ # Skip over reroute nodes
+ if node.type == 'REROUTE':
+ socket = node.inputs[0]
+ continue
+
+ return node