From 3aae342f8d4d1e9b60bc83472fa27e1a0ab0bb91 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 30 Jul 2024 18:25:02 +0300 Subject: [PATCH] Switch to the scene an object is on when exporting it I couldn't find any other way to get a suitable depsgraph for evaluating the object for mesh export. --- blender/io_mspgl/export.py | 95 +++++++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 37 deletions(-) diff --git a/blender/io_mspgl/export.py b/blender/io_mspgl/export.py index b724eddd..e065a3f2 100644 --- a/blender/io_mspgl/export.py +++ b/blender/io_mspgl/export.py @@ -40,44 +40,65 @@ class DataExporter: from .datafile import Resource dummy_res = Resource("dummy", "dummy") + orig_scene = ctx.context.window.scene + ctx.set_slices(len(objects)) - for obj in objects: - task = ctx.next_slice(obj) - res_name = None - res = None - if obj.type=='MESH': - res_name = obj.name+".object" - if res_name not in resources: - if not object_exporter: - from .export_object import ObjectExporter - object_exporter = ObjectExporter() - object_exporter.export_object_resources(task, obj, resources) - res = object_exporter.export_object(obj, resources) - elif obj.type=='CAMERA': - res_name = obj.name+".camera" - if res_name not in resources: - if not camera_exporter: - from .export_camera import CameraExporter - camera_exporter = CameraExporter() - res = camera_exporter.export_camera(obj) - elif obj.type=='ARMATURE': - res_name = obj.name+".arma" - if res_name not in resources: - if not armature_exporter: - from .export_armature import ArmatureExporter - armature_exporter = ArmatureExporter() - res = armature_exporter.export_armature(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 - dummy_res.create_reference_statement("ref", res) + for s in ctx.context.blend_data.scenes: + scene_objects = set(s.collection.all_objects) + + first = True + remaining_objects = [] + for obj in objects: + if not obj in scene_objects: + remaining_objects.append(obj) + continue + + if first: + ctx.context.window.scene = s + first = False + + task = ctx.next_slice(obj) + res_name = None + res = None + if obj.type=='MESH': + res_name = obj.name+".object" + if res_name not in resources: + if not object_exporter: + from .export_object import ObjectExporter + object_exporter = ObjectExporter() + object_exporter.export_object_resources(task, obj, resources) + res = object_exporter.export_object(obj, resources) + elif obj.type=='CAMERA': + res_name = obj.name+".camera" + if res_name not in resources: + if not camera_exporter: + from .export_camera import CameraExporter + camera_exporter = CameraExporter() + res = camera_exporter.export_camera(obj) + elif obj.type=='ARMATURE': + res_name = obj.name+".arma" + if res_name not in resources: + if not armature_exporter: + from .export_armature import ArmatureExporter + armature_exporter = ArmatureExporter() + res = armature_exporter.export_armature(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 + dummy_res.create_reference_statement("ref", res) + + if not remaining_objects: + break + objects = remaining_objects + + ctx.context.window.scene = orig_scene return dummy_res -- 2.45.2