]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/export.py
Add a Blender operator to export the entire project at once
[libs/gl.git] / blender / io_mspgl / export.py
index f36cc4df6c1d774d8b66d6604f3ab2ac9440ca3e..37813d081a0d1bebf2cf5407431b59dce6de4589 100644 (file)
@@ -1,4 +1,5 @@
 import os
+import itertools
 
 class DataExporter:
        def __init__(self):
@@ -44,6 +45,7 @@ class DataExporter:
                object_exporter = None
                camera_exporter = None
                armature_exporter = None
+               light_exporter = None
 
                from .datafile import Resource
                dummy_res = Resource("dummy", "dummy")
@@ -74,6 +76,13 @@ class DataExporter:
                                                from .export_armature import ArmatureExporter
                                                armature_exporter = ArmatureExporter()
                                        res = armature_exporter.export_armature(context, obj)
+                       elif obj.type=='LIGHT':
+                               res_name = obj.name+".light"
+                               if res_name not in resources:
+                                       if not light_exporter:
+                                               from .export_light import LightExporter
+                                               light_exporter = LightExporter()
+                                       res = light_exporter.export_light(obj)
 
                        if res:
                                resources[res_name] = res
@@ -82,3 +91,59 @@ class DataExporter:
                        progress.pop_task()
 
                return dummy_res
+
+class ProjectExporter:
+       def export_to_directory(self, context, out_dir):
+               from .util import Progress
+               progress = Progress(context)
+
+               from .scene import create_scene_chain
+
+               scenes = {}
+               sequences = []
+               for s in context.blend_data.scenes:
+                       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:
+                               scene = create_scene(s)
+                               if s.export_disposition=='SCENE':
+                                       scenes[scene.name] = scene
+
+               all_objects = []
+               for s in scenes.values():
+                       all_objects += s.prototypes
+                       all_objects += s.lights
+                       if s.camera:
+                               all_objects.append(s.camera)
+
+               from .util import make_unique
+               all_objects = make_unique(all_objects)
+
+               from .export_scene import SceneExporter
+               scene_exporter = SceneExporter()
+               data_exporter = DataExporter()
+
+               resources = {}
+               dummy_res = data_exporter.export_resources(context, all_objects, resources, None, progress)
+               for s in scenes.values():
+                       scene_name = s.name+".scene"
+                       if scene_name not in resources:
+                               scene_res = scene_exporter.export_scene(s, resources)
+                               resources[scene_name] = scene_res
+                               dummy_res.create_reference_statement("ref", scene_res)
+
+               for s in sequences:
+                       seq_name = s.name+".seq"
+                       if seq_name not in resources:
+                               scene_exporter.export_sequence_resources(s, resources)
+                               seq_res = scene_exporter.export_sequence(s, resources)
+                               resources[seq_name] = seq_res
+                               dummy_res.create_reference_statement("ref", seq_res)
+
+               refs = dummy_res.collect_references()
+               for r in refs:
+                       r.write_to_file(os.path.join(out_dir, r.name))