]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mesh_mspgl/export_mspgl.py
Support exporting textures with objects
[libs/gl.git] / blender / io_mesh_mspgl / export_mspgl.py
index f888dc4528d9981250e9b6ea950d35244ac7b4ee..0e96c4249631ebc17844f1e3267beab1469c49f7 100644 (file)
@@ -75,6 +75,7 @@ class Exporter:
                self.compound = False
                self.object = False
                self.material_tex = False
+               self.textures = "REF"
                self.smoothing = "MSPGL"
 
        def stripify(self, mesh, progress = None):
@@ -385,6 +386,38 @@ class Exporter:
                                        out_file.write("specular", spec.r, spec.g, spec.b, 1.0)
                                        out_file.write("shininess", mat.specular_hardness);
                                        out_file.end()
+
+                               if self.textures!="NONE":
+                                       for slot in mesh.materials[0].texture_slots:
+                                               if not slot:
+                                                       continue
+
+                                               tex = slot.texture
+                                               if tex.type!="IMAGE":
+                                                       continue
+
+                                               if slot.uv_layer:
+                                                       for u in mesh.uv_layers:
+                                                               if u.name==slot.uv_layer:
+                                                                       index = u.unit
+                                               else:
+                                                       index = mesh.uv_layers[0].unit
+
+                                               out_file.begin("texunit", index)
+                                               if self.textures=="INLINE":
+                                                       out_file.begin("texture2d")
+                                                       out_file.write("min_filter", "LINEAR")
+                                                       out_file.write("storage", "RGBA", tex.image.size[0], tex.image.size[1])
+                                                       texdata = '"'
+                                                       for p in tex.image.pixels:
+                                                               texdata += "\\x%02X"%int(p*255)
+                                                       texdata += '"'
+                                                       out_file.write("raw_data", texdata)
+                                                       out_file.end()
+                                               else:
+                                                       out_file.write("texture", '"%s"'%tex.image.name)
+                                               out_file.end()
+
                        out_file.end()
                        out_file.end()