]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/export.py
Refactor scene export to use inline scenes instead of a wrapper scene
[libs/gl.git] / blender / io_mspgl / export.py
index 37813d081a0d1bebf2cf5407431b59dce6de4589..6db2c81c6cbb9f718ebec222227182e9e8d7e96b 100644 (file)
@@ -2,11 +2,7 @@ import os
 import itertools
 
 class DataExporter:
-       def __init__(self):
-               self.collection = False
-               self.shared_resources = True
-
-       def export_to_file(self, context, out_fn):
+       def export_to_file(self, context, out_fn, *, collection=False, shared_resources=False):
                from .util import Progress
                progress = Progress(context)
 
@@ -21,7 +17,7 @@ class DataExporter:
                base, ext = os.path.splitext(base)
 
                refs = dummy_res.collect_references()
-               if not self.shared_resources:
+               if not shared_resources:
                        numbers = {}
                        for r in refs:
                                res_ext = os.path.splitext(r.name)[1]
@@ -32,7 +28,7 @@ class DataExporter:
                                        r.name = base+res_ext
                                numbers[res_ext] = n+1
 
-               if self.collection:
+               if collection:
                        dummy_res.write_collection(out_fn, exclude_self=True)
                else:
                        for r in refs:
@@ -120,6 +116,15 @@ class ProjectExporter:
                        if s.camera:
                                all_objects.append(s.camera)
 
+               scene_queue = list(scenes.values())
+               ordered_scenes = []
+               while scene_queue:
+                       s = scene_queue.pop(0)
+                       if not s.background_set or s.background_set in ordered_scenes:
+                               ordered_scenes.append(s)
+                       else:
+                               scene_queue.append(s)
+
                from .util import make_unique
                all_objects = make_unique(all_objects)
 
@@ -129,7 +134,7 @@ class ProjectExporter:
 
                resources = {}
                dummy_res = data_exporter.export_resources(context, all_objects, resources, None, progress)
-               for s in scenes.values():
+               for s in ordered_scenes:
                        scene_name = s.name+".scene"
                        if scene_name not in resources:
                                scene_res = scene_exporter.export_scene(s, resources)