]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/material.py
Add a tint property for PBR materials
[libs/gl.git] / blender / io_mspgl / material.py
index ccbf0083f143988af633523c2b4ec2b30e10d55c..3e2bce001943d4c26090129dcd9650153abae9a1 100644 (file)
@@ -19,6 +19,7 @@ class PropertyNode:
 
                checks = [self.check_group,
                        self.check_scale,
+                       self.check_tint,
                        self.check_gray,
                        self.check_extract,
                        self.check_normal,
@@ -63,6 +64,17 @@ class PropertyNode:
                                        self.data = self.node.inputs[i].default_value
                                        return self.set_input_from_linked(self.node.inputs[1-i])
 
+       def check_tint(self):
+               if self.node.type!='MIX_RGB':
+                       return
+
+               if self.node.blend_type=='MULTIPLY':
+                       for i in range(2):
+                               if not self.node.inputs[1+i].is_linked:
+                                       self.type = 'TINT'
+                                       self.data = self.node.inputs[1+i].default_value[:]
+                                       return self.set_input_from_linked(self.node.inputs[2-i])
+
        def check_gray(self):
                if self.node.type=='RGBTOBW':
                        self.type = 'GRAY'
@@ -152,6 +164,7 @@ class MaterialProperty:
                self.texture = None
                self.tex_channels = None
                self.scale = 1.0
+               self.tint = None
 
        def set_from_input(self, node_tree, input_socket, alpha_socket=None):
                if self.keyword:
@@ -183,6 +196,8 @@ class MaterialProperty:
                                                channels = ['~'+c if c in n.data else c for c in channels]
                                        elif n.type=='SCALE':
                                                self.scale = n.data
+                                       elif n.type=='TINT':
+                                               self.tint = n.data
                                        elif n.type=='TEXTURE':
                                                self.texture = n.node
                                        n = n.input
@@ -253,12 +268,15 @@ class Material:
                        self.type = "pbr"
 
                        base_color = self.create_property("base_color", (0.8, 0.8, 0.8, 1.0))
+                       tint = self.create_property("tint", (1.0, 1.0, 1.0, 1.0))
                        metalness = self.create_property("metalness", 0.0)
                        roughness = self.create_property("roughness", 0.5)
                        normal = self.create_property("normal_map")
                        emission = self.create_property("emission", (0.0, 0.0, 0.0))
 
                        base_color.set_from_input(material.node_tree, from_node.inputs["Base Color"], from_node.inputs["Alpha"])
+                       if base_color.tint:
+                               tint.value = base_color.tint
                        metalness.set_from_input(material.node_tree, from_node.inputs["Metallic"])
                        roughness.set_from_input(material.node_tree, from_node.inputs["Roughness"])
                        normal.set_from_input(material.node_tree, from_node.inputs["Normal"])