]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/export.py
Redesign progress and error reporting in the Blender exporter
[libs/gl.git] / blender / io_mspgl / export.py
index 6db2c81c6cbb9f718ebec222227182e9e8d7e96b..190069c4f3caa961ed3512ec191b9366f7238be4 100644 (file)
@@ -2,20 +2,19 @@ import os
 import itertools
 
 class DataExporter:
-       def export_to_file(self, context, out_fn, *, collection=False, shared_resources=False):
-               from .util import Progress
-               progress = Progress(context)
-
-               objects = context.selected_objects
+       def export_to_file(self, ctx, out_fn, *, collection=False, shared_resources=False):
+               objects = context.context.selected_objects
 
                resources = {}
                material_atlases = {}
 
-               dummy_res = self.export_resources(context, objects, resources, material_atlases, progress)
+               task = ctx.task("Exporting resources", 1.0)
+               dummy_res = self.export_resources(task, objects, resources, material_atlases)
 
                path, base = os.path.split(out_fn)
                base, ext = os.path.splitext(base)
 
+               task = ctx.task("Writing files", 1.0)
                refs = dummy_res.collect_references()
                if not shared_resources:
                        numbers = {}
@@ -34,7 +33,7 @@ class DataExporter:
                        for r in refs:
                                r.write_to_file(os.path.join(path, r.name))
 
-       def export_resources(self, context, objects, resources, material_atlases, progress):
+       def export_resources(self, ctx, objects, resources, material_atlases):
                if material_atlases is None:
                        material_atlases = {}
 
@@ -46,8 +45,9 @@ class DataExporter:
                from .datafile import Resource
                dummy_res = Resource("dummy", "dummy")
 
-               for i, obj in enumerate(objects):
-                       progress.push_task_slice(obj.name, i, len(objects))
+               ctx.set_slices(len(objects))
+               for obj in objects:
+                       task = ctx.next_slice(obj)
                        res_name = None
                        res = None
                        if obj.type=='MESH':
@@ -56,8 +56,8 @@ class DataExporter:
                                        if not object_exporter:
                                                from .export_object import ObjectExporter
                                                object_exporter = ObjectExporter()
-                                       object_exporter.export_object_resources(context, obj, resources, material_atlases, progress)
-                                       res = object_exporter.export_object(obj, resources, progress)
+                                       object_exporter.export_object_resources(task, obj, resources, material_atlases)
+                                       res = object_exporter.export_object(obj, resources)
                        elif obj.type=='CAMERA':
                                res_name = obj.name+".camera"
                                if res_name not in resources:
@@ -71,7 +71,7 @@ class DataExporter:
                                        if not armature_exporter:
                                                from .export_armature import ArmatureExporter
                                                armature_exporter = ArmatureExporter()
-                                       res = armature_exporter.export_armature(context, obj)
+                                       res = armature_exporter.export_armature(obj)
                        elif obj.type=='LIGHT':
                                res_name = obj.name+".light"
                                if res_name not in resources:
@@ -84,27 +84,26 @@ class DataExporter:
                                resources[res_name] = res
                                dummy_res.create_reference_statement("ref", res)
 
-                       progress.pop_task()
-
                return dummy_res
 
 class ProjectExporter:
-       def export_to_directory(self, context, out_dir):
-               from .util import Progress
-               progress = Progress(context)
-
+       def export_to_directory(self, ctx, out_dir):
                from .scene import create_scene_chain
 
+               task = ctx.task("Preparing scenes", 0.0)
+               task.set_slices(len(ctx.context.blend_data.scenes))
+
                scenes = {}
                sequences = []
-               for s in context.blend_data.scenes:
+               for s in ctx.context.blend_data.scenes:
+                       subtask = task.next_slice(s)
                        if s.export_disposition=='IGNORE':
                                continue
 
                        if s.export_disposition=='SEQUENCE':
                                scene = create_scene_chain(s, scenes)
                                sequences.append(scene)
-                       elif s.name not in scenes:
+                       elif s.export_disposition!='IGNORE' and s.name not in scenes:
                                scene = create_scene(s)
                                if s.export_disposition=='SCENE':
                                        scenes[scene.name] = scene
@@ -132,9 +131,13 @@ class ProjectExporter:
                scene_exporter = SceneExporter()
                data_exporter = DataExporter()
 
+               task = ctx.task("Exporting resources", 1.0)
                resources = {}
-               dummy_res = data_exporter.export_resources(context, all_objects, resources, None, progress)
+               dummy_res = data_exporter.export_resources(task, all_objects, resources, None)
+
+               task = ctx.task("Exporting scenes", 1.0)
                for s in ordered_scenes:
+                       subtask = task.task(s, 0.5)
                        scene_name = s.name+".scene"
                        if scene_name not in resources:
                                scene_res = scene_exporter.export_scene(s, resources)
@@ -142,6 +145,7 @@ class ProjectExporter:
                                dummy_res.create_reference_statement("ref", scene_res)
 
                for s in sequences:
+                       subtask = task.task(s, 0.5)
                        seq_name = s.name+".seq"
                        if seq_name not in resources:
                                scene_exporter.export_sequence_resources(s, resources)
@@ -149,6 +153,7 @@ class ProjectExporter:
                                resources[seq_name] = seq_res
                                dummy_res.create_reference_statement("ref", seq_res)
 
+               task = ctx.task("Writing files", 1.0)
                refs = dummy_res.collect_references()
                for r in refs:
                        r.write_to_file(os.path.join(out_dir, r.name))