From: Mikko Rasa Date: Tue, 31 Jul 2012 23:07:55 +0000 (+0300) Subject: Support exporting textures with objects X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b0fe4fa54e881e7dc2495a1078b7ffe6076d4744;p=libs%2Fgl.git Support exporting textures with objects --- diff --git a/blender/io_mesh_mspgl/__init__.py b/blender/io_mesh_mspgl/__init__.py index 37eec088..0b7b31df 100644 --- a/blender/io_mesh_mspgl/__init__.py +++ b/blender/io_mesh_mspgl/__init__.py @@ -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): diff --git a/blender/io_mesh_mspgl/export_mspgl.py b/blender/io_mesh_mspgl/export_mspgl.py index f888dc45..0e96c424 100644 --- a/blender/io_mesh_mspgl/export_mspgl.py +++ b/blender/io_mesh_mspgl/export_mspgl.py @@ -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()