]> git.tdb.fi Git - libs/gl.git/commitdiff
Add script for exporting meshes from Blender
authorMikko Rasa <tdb@tdb.fi>
Mon, 3 Sep 2007 14:26:50 +0000 (14:26 +0000)
committerMikko Rasa <tdb@tdb.fi>
Mon, 3 Sep 2007 14:26:50 +0000 (14:26 +0000)
mesh_export.py [new file with mode: 0644]

diff --git a/mesh_export.py b/mesh_export.py
new file mode 100644 (file)
index 0000000..0e63d33
--- /dev/null
@@ -0,0 +1,52 @@
+#!BPY
+# $Id$
+
+"""
+Name: 'MSP GL Mesh (.mesh)...'
+Blender: 244
+Group: 'Export'
+"""
+
+import sys
+import Blender
+
+class Exporter:
+       def __init__(self, fn):
+               self.filename=fn
+               if fn==None:
+                       self.out_file=sys.stdout
+               else:
+                       self.out_file=file(fn, "w")
+
+       def export(self):
+               scene=Blender.Scene.GetCurrent()
+
+               obj=scene.getActiveObject()
+               if obj.getType()!="Mesh":
+                       raise Exception, "Can only export Mesh data"
+
+               mesh=obj.getData(mesh=True)
+
+               self.out_file.write("vertices NORMAL3,VERTEX3\n{\n")
+               for v in mesh.verts:
+                       self.out_file.write("\tnormal3 %g %g %g;\n"%tuple(v.no))
+                       self.out_file.write("\tvertex3 %g %g %g;\n"%tuple(v.co))
+               self.out_file.write("};\n")
+               self.out_file.write("batch TRIANGLES\n{\n")
+               for f in mesh.faces:
+                       for i in range(2, len(f.verts)):
+                               self.out_file.write("\tindices %u %u %u;\n"%(f.verts[0].index, f.verts[i-1].index, f.verts[i].index))
+               self.out_file.write("};\n")
+
+class FrontEnd:
+       def run(self):
+               #self.export(None)
+               Blender.Window.FileSelector(self.export, "Export MSP GL mesh", Blender.sys.makename(ext='.mesh'))
+       
+       def export(self, fn):
+               exp=Exporter(fn)
+               exp.export()
+
+if __name__=="__main__":
+       fe=FrontEnd()
+       fe.run()