]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/export_material.py
Fix exporting of materials without any textures
[libs/gl.git] / blender / io_mspgl / export_material.py
index 41ed287bd3ab1c154ad146c2d760053ff9340455..4d2fe0749c71456fba465256a6e16ee8a5d28f06 100644 (file)
@@ -40,7 +40,7 @@ class MaterialExporter:
                material = Material(material)
 
                if self.use_textures:
-                       for p in material.properties.values():
+                       for p in material.properties:
                                if p.texture:
                                        tex_name = p.texture.image.name+".tex2d"
                                        if tex_name not in resources:
@@ -64,40 +64,40 @@ class MaterialExporter:
                from .datafile import Resource, Statement
                mat_res = Resource(material.name+".mat", "material")
 
-               if material.type!="pbr":
+               if material.type!="pbr" and material.type!="unlit":
                        raise Exception("Can't export unknown material type "+material.type)
 
                st = Statement(material.type)
-               for kw, p in material.properties.items():
-                       ss = self.create_property_statement(mat_res, p, kw, resources)
+               for p in material.properties:
+                       ss = self.create_property_statement(mat_res, p, resources)
                        if ss:
                                st.sub.append(ss)
                if self.use_textures:
-                       first_tex = (p.texture for p in material.properties.values() if p.texture).__next__()
-                       if first_tex and not first_tex.default_filter:
+                       textures = [p.texture for p in material.properties if p.texture]
+                       if textures and not textures[0].default_filter:
                                from .export_texture import SamplerExporter
                                sampler_export = SamplerExporter()
-                               st.sub.append(mat_res.create_reference_statement("sampler", resources[sampler_export.get_sampler_name(first_tex)]))
+                               st.sub.append(mat_res.create_reference_statement("sampler", resources[sampler_export.get_sampler_name(textures[0])]))
                mat_res.statements.append(st)
 
                return mat_res
 
-       def create_property_statement(self, mat_res, prop, keyword, resources):
+       def create_property_statement(self, mat_res, prop, resources):
                from .datafile import Statement
                if self.use_textures and prop.texture:
                        tex_res = resources[prop.texture.image.name+".tex2d"]
                        from .util import basename
                        fn = basename(prop.texture.image.filepath)
                        if prop.texture.default_filter and fn:
-                               return Statement(keyword+"_map", fn)
+                               return Statement(prop.tex_keyword, fn)
                        else:
-                               return mat_res.create_reference_statement(keyword+"_map", tex_res)
-               elif prop.value is None:
+                               return mat_res.create_reference_statement(prop.tex_keyword, tex_res)
+               elif not prop.keyword:
                        return
                elif type(prop.value)==tuple:
-                       return Statement(keyword, *prop.value)
+                       return Statement(prop.keyword, *prop.value)
                else:
-                       return Statement(keyword, prop.value)
+                       return Statement(prop.keyword, prop.value)
 
 
 class MaterialMapExporter: