]> git.tdb.fi Git - libs/gl.git/commitdiff
Refactor scene export to use inline scenes instead of a wrapper scene
authorMikko Rasa <tdb@tdb.fi>
Sat, 16 Oct 2021 09:29:32 +0000 (12:29 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 16 Oct 2021 16:03:00 +0000 (19:03 +0300)
blender/io_mspgl/export.py
blender/io_mspgl/export_scene.py

index cf4312d2631993aeb37d7e4d9fd925c70952ff1f..6db2c81c6cbb9f718ebec222227182e9e8d7e96b 100644 (file)
@@ -116,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)
 
@@ -125,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)
index 0fb12dd37de74268723e51ce077370585d19055a..1a1bbab062859d794e23361a16cb03d927b40829 100644 (file)
@@ -37,9 +37,26 @@ class SceneExporter:
                from .datafile import Resource, Statement, Token
                scene_res = Resource(scene.name+".scene", "scene")
 
-               scene_res.statements.append(Statement("type", Token("simple")))
+               if scene.background_set:
+                       scene_res.statements.append(Statement("type", Token("ordered")))
+                       if scene.background_set:
+                               scene_res.statements.append(scene_res.create_reference_statement("scene", resources[scene.background_set.name+".scene"]))
+
+                       st = Statement("scene")
+                       st.sub.append(Statement("type", Token("simple")))
+                       self.add_instances(scene_res, st.sub, scene.instances, resources)
+                       scene_res.statements.append(st)
+               else:
+                       scene_res.statements.append(Statement("type", Token("simple")))
+
+                       self.add_instances(scene_res, scene_res.statements, scene.instances, resources)
+
+               return scene_res
+
+       def add_instances(self, scene_res, statements, instances, resources):
+               from .datafile import Statement
 
-               for i in scene.instances:
+               for i in instances:
                        obj_res = resources[i.prototype+".object"]
                        st = scene_res.create_reference_statement("object", obj_res, i.name)
 
@@ -59,23 +76,11 @@ class SceneExporter:
                        ss.sub.append(Statement("scale", *tuple(scale)))
 
                        st.sub.append(ss)
-                       scene_res.statements.append(st)
-
-               return scene_res
+                       statements.append(st)
 
        def export_sequence_resources(self, scene, resources):
                from .datafile import Resource, Statement, Token
 
-               if scene.background_set:
-                       wrapper_name = scene.name+".wrapper.scene"
-                       if wrapper_name not in resources:
-                               wrapper_res = Resource(wrapper_name, "scene")
-                               wrapper_res.statements.append(Statement("type", Token("ordered")))
-                               for s in scene.get_chain():
-                                       wrapper_res.statements.append(wrapper_res.create_reference_statement("scene", resources[s.name+".scene"]))
-
-                               resources[wrapper_name] = wrapper_res
-
                lights = []
                s = scene
                while s:
@@ -108,10 +113,6 @@ class SceneExporter:
                if scene.use_hdr:
                        seq_res.statements.append(Statement("hdr", True))
 
-               content = scene
-               if scene.background_set:
-                       content = resources[scene.name+".wrapper.scene"]
-
                ss = Statement("clear")
                ss.sub.append(Statement("color", 0.0, 0.0, 0.0, 0.0))
                ss.sub.append(Statement("depth", 1.0))
@@ -120,7 +121,7 @@ class SceneExporter:
                ss = Statement("step", "", "content")
                ss.sub.append(Statement("depth_test", Token("LEQUAL")))
                ss.sub.append(seq_res.create_reference_statement("lighting", resources[scene.name+".lightn"]))
-               ss.sub.append(seq_res.create_reference_statement("scene", content))
+               ss.sub.append(seq_res.create_reference_statement("scene", resources[scene.name+".scene"]))
                seq_res.statements.append(ss)
 
                if scene.use_ao: