3 def is_same_object(obj1, obj2):
4 if obj1.data.name!=obj2.data.name:
6 if any(m1.name!=m2.name for m1, m2 in zip(obj1.material_slots, obj2.material_slots)):
12 def __init__(self, obj, prototype):
14 self.matrix_world = obj.matrix_world
15 self.rotation_mode = obj.rotation_mode
16 self.prototype = prototype.name
19 def __init__(self, scene, obj_filter=None):
20 self.name = scene.name
21 self.export_disposition = scene.export_disposition
22 self.background_set = None
23 self.camera = scene.camera
26 self.blended_instances = []
28 self.ambient_light = mathutils.Color((0.0, 0.0, 0.0))
29 self.exposure = scene.view_settings.exposure
31 self.use_hdr = scene.use_hdr
32 self.use_ao = scene.eevee.use_gtao
33 self.ao_distance = scene.eevee.gtao_distance
34 self.ao_samples = scene.ao_samples
36 out_node = next((n for n in scene.world.node_tree.nodes if n.type=='OUTPUT_WORLD'), None)
38 from .util import get_linked_node_and_socket
40 surface_node, _ = get_linked_node_and_socket(scene.world.node_tree, out_node.inputs["Surface"])
41 if surface_node and surface_node.type=='BACKGROUND':
42 c = surface_node.inputs["Color"].default_value
43 s = surface_node.inputs["Strength"].default_value
44 self.ambient_light = mathutils.Color(c[:3])*s
46 objects = scene.objects[:]
47 objects.sort(key=lambda o:o.name)
49 objects = list(filter(obj_filter, objects))
53 if o.name in processed:
57 clones = [c for c in objects if is_same_object(o, c)]
58 self.prototypes.append(o)
59 instance_list = self.instances
60 if o.material_slots and o.material_slots[0].material and o.material_slots[0].material.blend_method=='BLEND':
61 instance_list = self.blended_instances
63 instance_list.append(Instance(c, o))
70 if self.background_set:
71 result = self.background_set.get_chain()
75 def get_all_collections(collection):
77 for c in collection.children:
78 result += get_all_collections(c)
81 def create_scene_from_current(context, *, selected_only=False, visible_only=True):
85 obj_filters.append(lambda o: o.select_get())
89 for c in get_all_collections(context.view_layer.layer_collection):
90 if not c.hide_viewport and not c.collection.hide_viewport:
91 visible_names.update(o.name for o in c.collection.objects)
92 obj_filters.append(lambda o: o.name in visible_names)
95 if len(obj_filters)==1:
96 obj_filter = obj_filters[0]
98 obj_filter = lambda o: all(f(o) for f in obj_filters)
100 return Scene(context.scene, obj_filter)
102 def create_scene(scene, *, visible_only=True):
106 visible_names = set()
107 for c in get_all_collections(scene.collection):
108 if not c.hide_viewport:
109 visible_names.update(o.name for o in c.objects)
110 obj_filter = lambda o: o.name in visible_names
112 return Scene(scene, obj_filter)
114 def create_scene_chain(scene, cache, *, visible_only=True):
122 if scene.name in cache:
123 converted = cache[scene.name]
125 converted = create_scene(scene, visible_only=visible_only)
126 cache[scene.name] = converted
131 prev.background_set = converted
134 scene = scene.background_set