]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/scene.py
Export instances created through geometry nodes
[libs/gl.git] / blender / io_mspgl / scene.py
index 7a0fa2f037d290108e8e3d951d8a7617874208c5..4cb6be5baf63a45d521511a42d28d86de0c86c43 100644 (file)
@@ -1,4 +1,5 @@
 import itertools
+import bpy
 import mathutils
 
 def is_same_object(obj1, obj2):
@@ -11,10 +12,16 @@ def is_same_object(obj1, obj2):
 
 class Instance:
        def __init__(self, obj, prototype):
-               self.name = obj.name
-               self.matrix_world = obj.matrix_world
-               self.rotation_mode = obj.rotation_mode
-               self.prototype = prototype
+               if type(obj)==bpy.types.DepsgraphObjectInstance:
+                       self.name = None
+                       self.matrix_world = mathutils.Matrix(obj.matrix_world)
+                       self.rotation_mode = prototype.rotation_mode
+                       self.prototype = bpy.data.objects[prototype.name]
+               else:
+                       self.name = obj.name
+                       self.matrix_world = obj.matrix_world
+                       self.rotation_mode = obj.rotation_mode
+                       self.prototype = prototype
 
 class Scene:
        def __init__(self, scene, obj_filter=None):
@@ -65,6 +72,10 @@ class Scene:
                                if o.data.use_shadow:
                                        self.use_shadow = True
 
+               for i in scene.view_layers[0].depsgraph.object_instances:
+                       if i.is_instance and i.object.type=='MESH':
+                               self.add_instance(Instance(i, i.object))
+
                proto_map = {}
                for i in itertools.chain(self.instances, self.blended_instances):
                        p = proto_map.get(i.prototype)