]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/material.py
Recognize textures through an RGB to BW node in Blender
[libs/gl.git] / blender / io_mspgl / material.py
index d25286055056034a68d936976d18b4755ceb0685..5e06fd8aa061ef83ca9540b1d97163657d0011be 100644 (file)
@@ -32,6 +32,8 @@ class MaterialProperty:
                        if from_node:
                                if from_node.type=='NORMAL_MAP':
                                        from_node, _ = get_linked_node_and_socket(node_tree, from_node.inputs["Color"])
+                               elif from_node.type=='RGBTOBW':
+                                       from_node, _ = get_linked_node_and_socket(node_tree, from_node.inputs["Color"])
 
                                if alpha_socket:
                                        alpha_from, _ = get_linked_node_and_socket(node_tree, alpha_socket)
@@ -92,6 +94,12 @@ class Material:
                        roughness.set_from_input(material.node_tree, surface_node.inputs["Roughness"])
                        normal.set_from_input(material.node_tree, surface_node.inputs["Normal"])
                        emission.set_from_input(material.node_tree, surface_node.inputs["Emission"])
+               elif surface_node.type=='EMISSION':
+                       self.type = "unlit"
+
+                       color = self.create_property("color", "texture", (1.0, 1.0, 1.0, 1.0))
+
+                       color.set_from_input(material.node_tree, surface_node.inputs["Color"])
                else:
                        raise Exception("Unsupported surface node type "+surface_node.type)
 
@@ -116,24 +124,24 @@ class Material:
                return prop
 
 
-class MaterialMap:
+class MaterialAtlas:
        def __init__(self, materials):
                self.render_mode = materials[0].render_mode
                if self.render_mode=='EXTERNAL':
-                       raise Exception("Material map with external render mode does not make sense")
+                       raise Exception("Material atlas with external render mode does not make sense")
 
                self.shader = materials[0].shader
                if self.shader:
-                       self.name = "material_map_"+os.path.splitext(self.shader)[0]
+                       self.name = "material_atlas_"+os.path.splitext(self.shader)[0]
                else:
-                       self.name = "material_map"
+                       self.name = "material_atlas"
                self.materials = materials
                self.material_names = [m.name for m in self.materials]
                for m in self.materials:
                        if m.render_mode!=self.render_mode:
-                               raise Exception("Conflicting render modes in MaterialMap constructor")
+                               raise Exception("Conflicting render modes in MaterialAtlas constructor")
                        if self.render_mode=='CUSTOM' and m.shader!=self.shader:
-                               raise Exception("Conflicting shaders in MaterialMap constructor")
+                               raise Exception("Conflicting shaders in MaterialAtlas constructor")
 
                count = len(self.materials)
                size = 1
@@ -150,7 +158,7 @@ class MaterialMap:
                self.base_color_data = ""
                for m in map(Material, self.materials):
                        if any(p.texture for p in m.properties):
-                               raise Exception("Texturing is incompatible with material map")
+                               raise Exception("Texturing is incompatible with material atlas")
                        base_color = [int(cm(c)*255) for c in m.base_color.value]
                        self.base_color_data += "\\x{:02X}\\x{:02X}\\x{:02X}\\xFF".format(*base_color)
                self.base_color_data += "\\x00\\x00\\x00\\x00"*(self.size[0]*self.size[1]-count)
@@ -161,16 +169,16 @@ class MaterialMap:
                y = index//self.size[0]
                return ((x+0.5)/self.size[0], (y+0.5)/self.size[1])
 
-def create_material_map(context, material):
-       if not material.material_map:
-               raise Exception("Material is not part of a material map")
+def create_material_atlas(context, material):
+       if not material.material_atlas:
+               raise Exception("Material is not part of a material atlas")
 
        shader = material.shader
        materials = []
        for m in context.blend_data.materials:
-               if m.material_map and m.shader==shader:
+               if m.material_atlas and m.shader==shader:
                        materials.append(m)
 
-       mat_map = MaterialMap(materials)
+       mat_map = MaterialAtlas(materials)
 
        return mat_map