1 def is_same_object(obj1, obj2):
2 if obj1.data.name!=obj2.data.name:
4 if any(m1.name!=m2.name for m1, m2 in zip(obj1.material_slots, obj2.material_slots)):
10 def __init__(self, obj, prototype):
12 self.matrix_world = obj.matrix_world
13 self.rotation_mode = obj.rotation_mode
14 self.prototype = prototype.name
17 def __init__(self, scene, obj_filter=None):
18 self.name = scene.name
19 self.scene_type = scene.scene_type
23 objects = [o for o in scene.objects if o.type=='MESH']
24 objects.sort(key=lambda o:o.name)
26 objects = list(filter(obj_filter, objects))
30 if o.name in processed:
33 clones = [c for c in objects if is_same_object(o, c)]
34 self.prototypes.append(o)
36 self.instances.append(Instance(c, o))
39 def get_all_collections(collection):
41 for c in collection.children:
42 result += get_all_collections(c)
45 def create_scene_from_current(context, *, selected_only=False, visible_only=True):
49 obj_filters.append(lambda o: o.select_get())
53 for c in get_all_collections(context.view_layer.layer_collection):
54 if not c.hide_viewport and not c.collection.hide_viewport:
55 visible_names.update(o.name for o in c.collection.objects)
56 obj_filters.append(lambda o: o.name in visible_names)
59 if len(obj_filters)==1:
60 obj_filter = obj_filters[0]
62 obj_filter = lambda o: all(f(o) for f in obj_filters)
64 return Scene(context.scene, obj_filter)