From: Mikko Rasa Date: Mon, 15 Sep 2014 08:24:11 +0000 (+0300) Subject: Display overall progress when exporting scenes X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=328ac951d8df830e1c9ee469b4ab073e9163606d;p=libs%2Fgl.git Display overall progress when exporting scenes --- diff --git a/blender/io_mspgl/export_mesh.py b/blender/io_mspgl/export_mesh.py index e429d7ae..e9724f27 100644 --- a/blender/io_mspgl/export_mesh.py +++ b/blender/io_mspgl/export_mesh.py @@ -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) diff --git a/blender/io_mspgl/export_object.py b/blender/io_mspgl/export_object.py index d89afd05..a8af6d1f 100644 --- a/blender/io_mspgl/export_object.py +++ b/blender/io_mspgl/export_object.py @@ -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: diff --git a/blender/io_mspgl/export_scene.py b/blender/io_mspgl/export_scene.py index 8f224fea..03a02ed4 100644 --- a/blender/io_mspgl/export_scene.py +++ b/blender/io_mspgl/export_scene.py @@ -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)) diff --git a/blender/io_mspgl/util.py b/blender/io_mspgl/util.py index 000190fe..850f1ddb 100644 --- a/blender/io_mspgl/util.py +++ b/blender/io_mspgl/util.py @@ -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):