- clones = [c for c in objects if is_same_object(o, c)]
- self.prototypes.append(o)
- for c in clones:
- self.instances.append(Instance(c, o))
- processed.add(c.name)
+ 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)
+ 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
+ instance_list = self.instances
+ if obj.material_slots and obj.material_slots[0].material:
+ mat = obj.material_slots[0].material
+ if mat.blend_method=='BLEND':
+ instance_list = self.blended_instances
+ if mat.image_based_lighting:
+ self.use_ibl = True
+ instance_list.append(instance)
+
+ def get_chain(self):
+ result = []
+ if self.background_set:
+ result = self.background_set.get_chain()
+ result.append(self)
+ return result