]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/material.py
Fix normal map property name in material exporter
[libs/gl.git] / blender / io_mspgl / material.py
index e97561b795f5ffd6ffa5ec915c0e8c15cfc5fe1d..93f177908b4b6ede25de2a24b2e1f7d8fc1d5246 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)
@@ -84,7 +86,7 @@ class Material:
                        base_color = self.create_property("base_color", (0.8, 0.8, 0.8, 1.0))
                        metalness = self.create_property("metalness", 0.0)
                        roughness = self.create_property("roughness", 0.5)
-                       normal = self.create_property("normal")
+                       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, surface_node.inputs["Base Color"], surface_node.inputs["Alpha"])
@@ -122,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
@@ -156,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)
@@ -167,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