]> git.tdb.fi Git - libs/gl.git/commitdiff
Switch to the scene an object is on when exporting it
authorMikko Rasa <tdb@tdb.fi>
Tue, 30 Jul 2024 15:25:02 +0000 (18:25 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 30 Jul 2024 15:25:02 +0000 (18:25 +0300)
I couldn't find any other way to get a suitable depsgraph for evaluating
the object for mesh export.

blender/io_mspgl/export.py

index b724eddd4f8c071953cad9dc1c7c9cb38a24cc59..e065a3f2f4ba56c98f8a5aee14484d1782be5f24 100644 (file)
@@ -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