]> git.tdb.fi Git - libs/gl.git/commitdiff
Display overall progress when exporting scenes
authorMikko Rasa <tdb@tdb.fi>
Mon, 15 Sep 2014 08:24:11 +0000 (11:24 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 15 Sep 2014 08:24:11 +0000 (11:24 +0300)
blender/io_mspgl/export_mesh.py
blender/io_mspgl/export_object.py
blender/io_mspgl/export_scene.py
blender/io_mspgl/util.py

index e429d7ae35ccd3c9daf4350e5decaf6e395084cb..e9724f27f3d94166469099df98b70cfed1c09b87 100644 (file)
@@ -191,7 +191,7 @@ class MeshExporter:
 
                return strips, loose
 
-       def export(self, context, out_file, objs=None):
+       def export(self, context, out_file, objs=None, progress=None):
                if self.compound:
                        if objs is None:
                                objs = context.selected_objects
@@ -216,7 +216,8 @@ class MeshExporter:
                from .mesh import Mesh
                from .util import Progress
 
-               progress = Progress(context)
+               if not progress:
+                       progress = Progress(context)
                progress.set_task("Preparing", 0.0, 0.0)
 
                mesh = None
@@ -229,7 +230,8 @@ class MeshExporter:
                        else:
                                mesh.splice(Mesh(bmesh))
 
-               progress.set_task("Smoothing", 0.05, 0.35)
+               if progress:
+                       progress.set_task("Smoothing", 0.05, 0.35)
                if self.smoothing=="NONE":
                        mesh.flatten_faces()
                mesh.split_smooth(progress)
@@ -280,7 +282,8 @@ class MeshExporter:
                                        texunits.insert(0, unit)
 
                        for i, u in texunits:
-                               progress.set_task("Splitting UVs", 0.35+0.3*i/len(texunits), 0.35+0.3*(i+1)/len(texunits))
+                               if progress:
+                                       progress.set_task("Splitting UVs", 0.35+0.3*i/len(texunits), 0.35+0.3*(i+1)/len(texunits))
                                mesh.split_uv(i, progress)
                                if self.tbn_vecs and u.name==self.tbn_uvtex:
                                        mesh.compute_uv()
@@ -291,10 +294,12 @@ class MeshExporter:
                strips = []
                loose = mesh.faces
                if self.use_strips:
-                       progress.set_task("Creating strips", 0.65, 0.95)
+                       if progress:
+                               progress.set_task("Creating strips", 0.65, 0.95)
                        strips, loose = self.stripify(mesh, progress)
 
-               progress.set_task("Writing file", 0.95, 1.0)
+               if progress:
+                       progress.set_task("Writing file", 0.95, 1.0)
 
                from .outfile import open_output
                out_file = open_output(out_file)
@@ -371,7 +376,8 @@ class MeshExporter:
                                out_file.write("indices", l.vertices[0].index, l.vertices[1].index)
                        out_file.end()
 
-               progress.set_task("Done", 1.0, 1.0)
+               if progress:
+                       progress.set_task("Done", 1.0, 1.0)
 
                for m in bmeshes:
                        bpy.data.meshes.remove(m)
index d89afd05df667fb7c26d648a167bde38cc7ff8f8..a8af6d1f9b6a87e2334fa4deeafe74062c66821c 100644 (file)
@@ -17,7 +17,7 @@ class ObjectExporter:
                self.external_tech = True
                self.shared_tech = True
 
-       def export(self, context, out_file, objs=None):
+       def export(self, context, out_file, objs=None, progress=None):
                if objs is None:
                        obj = context.active_object
                else:
@@ -35,11 +35,11 @@ class ObjectExporter:
                        path, base = os.path.split(out_file.filename)
                        base, ext = os.path.splitext(base)
                        mesh_out = open_output(os.path.join(path, base+".mesh"))
-                       mesh = mesh_export.export(context, mesh_out, objs)
+                       mesh = mesh_export.export(context, mesh_out, objs, progress)
                        out_file.write("mesh", '"{}.mesh"'.format(base))
                else:
                        out_file.begin("mesh")
-                       mesh = mesh_export.export(context, out_file, objs)
+                       mesh = mesh_export.export(context, out_file, objs, progress)
                        out_file.end()
 
                if self.external_tech and obj.technique:
index 8f224fea8d418d183c70394e87b4176cfd748e07..03a02ed47903cd57d7c7e94a656b8f099664162f 100644 (file)
@@ -22,13 +22,17 @@ class SceneExporter:
                object_export.compound = True
                object_export.external_tech = self.external_tech
 
+               from .util import Progress
+               progress = Progress(context)
                if self.resource_collection:
                        res_out = open_output(os.path.join(path, base+"_resources.mdc"))
 
                        # TODO Export techniques as separate items in the collection
-                       for o in objs:
+                       for i, o in enumerate(objs):
                                res_out.begin("object", '"{}.object"'.format(o.name))
-                               object_export.export(context, res_out, [o])
+                               progress.push_task(o.name, i/len(objs), (i+1)/len(objs))
+                               object_export.export(context, res_out, [o], progress)
+                               progress.pop_task()
                                res_out.end()
                else:
                        object_export.separate_tech = True
@@ -37,7 +41,9 @@ class SceneExporter:
                                os.makedirs(res_dir)
                        for o in objs:
                                obj_out = open_output(os.path.join(res_dir, o.name+".object"))
-                               object_export.export(context, obj_out, [o])
+                               progress.push_task(o.name, i/len(objs), (i+1)/len(objs))
+                               object_export.export(context, obj_out, [o], progress)
+                               progress.pop_task()
 
                for o in objs:
                        out_file.begin("object", '"{}.object"'.format(o.name))
index 000190fe05e2cb80510121c90afd945378dd3ba6..850f1ddbb71dd754005d80a1e568fb01dc9f9819 100644 (file)
@@ -4,13 +4,28 @@ class Progress:
                self.start = 0.0
                self.delta = 1.0
                self.last = 0.0
+               self.stack = []
                self.window_manager = context.window_manager
                self.window_manager.progress_begin(0.0, 1.0)
 
+       def push_task(self, task, low, high):
+               self.stack.append((task, low, high-low))
+               self.set_task("init", 0.0, 0.0)
+
+       def pop_task(self):
+               self.set_task("finish", 1.0, 1.0)
+               self.stack.pop()
+
        def set_task(self, task, low, high):
+               if self.stack:
+                       task = self.stack[-1][0]+": "+task
+                       low = self.stack[-1][1]+self.stack[-1][2]*low
+                       high = self.stack[-1][1]+self.stack[-1][2]*high
+
                self.task = task
                self.start = low
                self.delta = high-low
+
                self.set_progress(0)
 
        def set_progress(self, value):