- proto_map = {}
- for i in itertools.chain(self.instances, self.blended_instances):
- p = proto_map.get(i.prototype)
- if p:
- i.prototype = p
- else:
- found = False
- for p in proto_map.values():
- if is_same_object(i.prototype, p):
- proto_map[i.prototype] = p
- i.prototype = p
- found = True
- break
-
- if not found:
- proto_map[i.prototype] = i.prototype
- self.prototypes.append(i.prototype)
-
- def add_instance(self, instance):
- obj = instance.prototype
+ for i in scene.view_layers[0].depsgraph.object_instances:
+ if i.is_instance and i.object.type=='MESH':
+ self.add_instance(i, bpy.data.objects[i.object.name], proto_map)
+
+ def add_instance(self, obj, proto_obj, proto_map):
+ prototype = proto_map.get(proto_obj)
+ if not prototype:
+ for p in proto_map.values():
+ if is_same_object(proto_obj, p.object):
+ prototype = p
+ break
+
+ if not prototype:
+ prototype = ObjectPrototype(proto_obj)
+ self.prototypes.append(prototype)
+
+ proto_map[proto_obj] = prototype
+