From: Mikko Rasa Date: Sat, 16 Oct 2021 09:29:32 +0000 (+0300) Subject: Refactor scene export to use inline scenes instead of a wrapper scene X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=5b19e93f2eb5db3c97a17d63250716c26a01b53f;p=libs%2Fgl.git Refactor scene export to use inline scenes instead of a wrapper scene --- diff --git a/blender/io_mspgl/export.py b/blender/io_mspgl/export.py index cf4312d2..6db2c81c 100644 --- a/blender/io_mspgl/export.py +++ b/blender/io_mspgl/export.py @@ -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) diff --git a/blender/io_mspgl/export_scene.py b/blender/io_mspgl/export_scene.py index 0fb12dd3..1a1bbab0 100644 --- a/blender/io_mspgl/export_scene.py +++ b/blender/io_mspgl/export_scene.py @@ -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: