]> git.tdb.fi Git - libs/gl.git/commitdiff
Minor refactoring of the Blender exporter
authorMikko Rasa <tdb@tdb.fi>
Wed, 5 May 2021 11:22:53 +0000 (14:22 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 5 May 2021 12:29:42 +0000 (15:29 +0300)
blender/io_mspgl/export_light.py
blender/io_mspgl/material.py
blender/io_mspgl/util.py

index 432705589bcd8b972c2684dbc762e7c37e05f424..4da2ba29a717c6b7bf6ac9417d4157b4ddc12302 100644 (file)
@@ -15,8 +15,7 @@ class LightExporter:
                        pos = obj.matrix_world@mathutils.Vector((0.0, 0.0, 0.0, 1.0))
 
                light_res.statements.append(Statement("position", *tuple(pos)))
-               c = light.color
-               e = light.energy
-               light_res.statements.append(Statement("color", c.r*e, c.g*e, c.b*e))
+               c = light.color*light.energy
+               light_res.statements.append(Statement("color", *tuple(c)))
 
                return light_res
index 2613edac67478dae4d4ef57a1c537bc6af487bd8..aba58e5518d4ebf9477da591ccb2a0e776cad249 100644 (file)
@@ -1,14 +1,8 @@
 import os
 
-def get_linked_node_and_socket(node_tree, socket):
-       for l in node_tree.links:
-               if socket==l.to_socket:
-                       return (l.from_node, l.from_socket)
-               elif socket==l.from_socket:
-                       return (l.to_node, l.to_socket)
-       return (None, None)
-
 def check_group(node_tree, group, func):
+       from .util import get_linked_node_and_socket
+
        output = group.node_tree.nodes["Group Output"]
        from_node, _ = get_linked_node_and_socket(group.node_tree, output.inputs[0])
        if from_node:
@@ -23,6 +17,8 @@ def check_invert_green(node_tree, node):
        elif node.type!='COMBRGB':
                return (None, None)
 
+       from .util import get_linked_node_and_socket
+
        green, g_sock = get_linked_node_and_socket(node_tree, node.inputs["G"])
        if not green or green.type!='MATH' or green.operation!='SUBTRACT':
                return (None, None)
@@ -55,6 +51,8 @@ class MaterialProperty:
                                self.value = input_socket.default_value
 
                if self.tex_keyword:
+                       from .util import get_linked_node_and_socket
+
                        from_node, _ = get_linked_node_and_socket(node_tree, input_socket)
                        alpha_from = None
                        if from_node:
@@ -104,15 +102,12 @@ class Material:
                elif self.render_mode=='CUSTOM' and not self.shader:
                        raise Exception("Invalid configuration on material {}: No shader for custom rendering".format(self.name))
 
-               out_node = None
-               for n in material.node_tree.nodes:
-                       if n.type=='OUTPUT_MATERIAL':
-                               out_node = n
-                               break
-
+               out_node = next((n for n in material.node_tree.nodes if n.type=='OUTPUT_MATERIAL'), None)
                if not out_node:
                        raise Exception("No output node found on material {}".format(self.name))
 
+               from .util import get_linked_node_and_socket
+
                surface_node, _ = get_linked_node_and_socket(material.node_tree, out_node.inputs["Surface"])
                if not surface_node:
                        if self.render_mode=='BUILTIN':
index 3b2f718bdb4aebf4399870ad6227b4554e78c347..e77e544751abe7b9bcdbfe8ad968ec451b86b2ca 100644 (file)
@@ -77,3 +77,11 @@ def make_unique(values):
                        result.append(i)
                        seen.add(i)
        return result
+
+def get_linked_node_and_socket(node_tree, socket):
+       for l in node_tree.links:
+               if socket==l.to_socket:
+                       return (l.from_node, l.from_socket)
+               elif socket==l.from_socket:
+                       return (l.to_node, l.to_socket)
+       return (None, None)