From ccc48ed8c2ab0c934e820131746442462ddd8f93 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 16 Mar 2022 18:26:47 +0200 Subject: [PATCH] Export instances created through geometry nodes --- blender/io_mspgl/export_scene.py | 4 +++- blender/io_mspgl/scene.py | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/blender/io_mspgl/export_scene.py b/blender/io_mspgl/export_scene.py index ac3bf0be..861286ff 100644 --- a/blender/io_mspgl/export_scene.py +++ b/blender/io_mspgl/export_scene.py @@ -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") diff --git a/blender/io_mspgl/scene.py b/blender/io_mspgl/scene.py index 7a0fa2f0..4cb6be5b 100644 --- a/blender/io_mspgl/scene.py +++ b/blender/io_mspgl/scene.py @@ -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) -- 2.45.2