From: Mikko Rasa Date: Mon, 3 Sep 2007 14:26:50 +0000 (+0000) Subject: Add script for exporting meshes from Blender X-Git-Tag: 0.9~45 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=79b9a1c86ecf81753934669d531679f29c6ab6e1;p=libs%2Fgl.git Add script for exporting meshes from Blender --- diff --git a/mesh_export.py b/mesh_export.py new file mode 100644 index 00000000..0e63d336 --- /dev/null +++ b/mesh_export.py @@ -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()