]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/export_mesh.py
Add an exporter setting to export all selected objects or meshes at once
[libs/gl.git] / blender / io_mspgl / export_mesh.py
index 0bf7b83af6fb6be4581f0dcfcbebd04674ddc17b..974685b3d1fa8cf0ae579bea292dd7676a8e47a3 100644 (file)
@@ -1,4 +1,5 @@
 import itertools
+import os
 import bpy
 import mathutils
 
@@ -7,6 +8,7 @@ class MeshExporter:
                self.show_progress = True
                self.use_strips = True
                self.use_degen_tris = False
+               self.export_all = False
 
        def join_strips(self, strips):
                big_strip = []
@@ -26,15 +28,26 @@ class MeshExporter:
                return big_strip
 
        def export_to_file(self, context, out_fn):
-               obj = context.active_object
+               if self.export_all:
+                       objs = [o for o in context.selected_objects if o.type=="MESH"]
+               else:
+                       objs = [context.active_object]
 
                from .util import Progress
 
+               path, base = os.path.split(out_fn)
+               base, ext = os.path.splitext(base)
+
                progress = Progress(self.show_progress and context)
-               progress.push_task("", 0.0, 0.95)
-               resource = self.export_mesh(context, obj, progress)
+               for i, obj in enumerate(objs):
+                       if self.export_all:
+                               out_fn = os.path.join(path, obj.data.name+ext)
 
-               resource.write_to_file(out_fn)
+                       progress.push_task_slice(obj.data.name, i, len(objs))
+                       resource = self.export_mesh(context, obj, progress)
+
+                       resource.write_to_file(out_fn)
+                       progress.pop_task()
 
        def export_mesh(self, context, mesh_or_obj, progress):
                from .mesh import Mesh, create_mesh_from_object