Changeset View
Changeset View
Standalone View
Standalone View
release/scripts/startup/bl_operators/object.py
| Show First 20 Lines • Show All 590 Lines • ▼ Show 20 Lines | def _main(context): | ||||
| trans = matrix.to_translation() | trans = matrix.to_translation() | ||||
| rot = matrix.to_3x3() # also contains scale | rot = matrix.to_3x3() # also contains scale | ||||
| return [(rot @ b) + trans for b in base_tri] | return [(rot @ b) + trans for b in base_tri] | ||||
| linked = defaultdict(list) | linked = defaultdict(list) | ||||
| for obj in context.selected_objects: | for obj in context.selected_objects: | ||||
| if obj.type == 'MESH': | if obj.type == 'MESH': | ||||
| linked[obj.data].append(obj) | linked[obj.data].append(obj) | ||||
| elif obj.type == 'EMPTY' and obj.instance_type == 'COLLECTION' and obj.instance_collection: | |||||
| linked[obj.instance_collection].append(obj) | |||||
| for data, objects in linked.items(): | for data, objects in linked.items(): | ||||
| face_verts = [axis for obj in objects | face_verts = [axis for obj in objects | ||||
| for v in matrix_to_quad(obj.matrix_world) | for v in matrix_to_quad(obj.matrix_world) | ||||
| for axis in v] | for axis in v] | ||||
| nbr_verts = len(face_verts) // 3 | nbr_verts = len(face_verts) // 3 | ||||
| nbr_faces = nbr_verts // 4 | nbr_faces = nbr_verts // 4 | ||||
| Show All 9 Lines | def _main(context): | ||||
| mesh.loops.foreach_set("vertex_index", faces) | mesh.loops.foreach_set("vertex_index", faces) | ||||
| mesh.polygons.foreach_set("loop_start", range(0, nbr_faces * 4, 4)) | mesh.polygons.foreach_set("loop_start", range(0, nbr_faces * 4, 4)) | ||||
| mesh.polygons.foreach_set("loop_total", (4,) * nbr_faces) | mesh.polygons.foreach_set("loop_total", (4,) * nbr_faces) | ||||
| mesh.update() # generates edge data | mesh.update() # generates edge data | ||||
| ob_new = bpy.data.objects.new(mesh.name, mesh) | ob_new = bpy.data.objects.new(mesh.name, mesh) | ||||
| context.collection.objects.link(ob_new) | context.collection.objects.link(ob_new) | ||||
| if type(data) is bpy.types.Collection: | |||||
| ob_inst = bpy.data.objects.new(data.name, None) | |||||
| ob_inst.instance_type = 'COLLECTION' | |||||
| ob_inst.instance_collection = data | |||||
| else: | |||||
| ob_inst = bpy.data.objects.new(data.name, data) | ob_inst = bpy.data.objects.new(data.name, data) | ||||
| context.collection.objects.link(ob_inst) | context.collection.objects.link(ob_inst) | ||||
| ob_new.instance_type = 'FACES' | ob_new.instance_type = 'FACES' | ||||
| ob_inst.parent = ob_new | ob_inst.parent = ob_new | ||||
| ob_new.use_instance_faces_scale = True | ob_new.use_instance_faces_scale = True | ||||
| ob_new.instance_faces_scale = 1.0 / SCALE_FAC | ob_new.instance_faces_scale = 1.0 / SCALE_FAC | ||||
| ob_inst.select_set(True) | ob_inst.select_set(True) | ||||
| ▲ Show 20 Lines • Show All 393 Lines • Show Last 20 Lines | |||||