]> git.tdb.fi Git - libs/gl.git/commitdiff
Export instances created through geometry nodes
authorMikko Rasa <tdb@tdb.fi>
Wed, 16 Mar 2022 16:26:47 +0000 (18:26 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 16 Mar 2022 16:26:47 +0000 (18:26 +0200)
blender/io_mspgl/export_scene.py
blender/io_mspgl/scene.py

index ac3bf0be184e31999e285eeb54c3a29c16c1dcfd..861286ff4f2a2e54631093004e1a4ced14b8141e 100644 (file)
@@ -69,7 +69,9 @@ class SceneExporter:
 
                for i in instances:
                        obj_res = resources[i.prototype.name+".object"]
-                       st = scene_res.create_reference_statement("object", obj_res, i.name)
+                       st = scene_res.create_reference_statement("object", obj_res)
+                       if i.name:
+                               st.append(i.name)
 
                        ss = Statement("transform")
 
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)