]> git.tdb.fi Git - libs/gl.git/commitdiff
Support exporting textures with objects
authorMikko Rasa <tdb@tdb.fi>
Tue, 31 Jul 2012 23:07:55 +0000 (02:07 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 31 Jul 2012 23:07:55 +0000 (02:07 +0300)
blender/io_mesh_mspgl/__init__.py
blender/io_mesh_mspgl/export_mspgl.py

index 37eec0889853a1c5942abfd67c0d51c403eb0840..0b7b31dfe31d6d28120cc2cae01b79cce32192a5 100644 (file)
@@ -56,6 +56,10 @@ class ExportMspGLObject(bpy.types.Operator, ExportMspGLBase):
 
        filename_ext = ".object"
 
+       textures = bpy.props.EnumProperty(name="Textures", description="Export textures", default="REF",
+               items=(("NONE", "None", "Ignore textures"),
+                       ("REF", "Referenced", "Reference external data"),
+                       ("INLINE", "Inline", "Embed textures in the object")))
        material_tex = bpy.props.BoolProperty(name="Material texture", description="Generate a texture based on material colors", default=False)
 
        def prepare_exporter(self, exporter):
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()