def apply_transform(obj:Object, location:bool=True, rotation:bool=True, scale:bool=True): loc, rot, scale = obj.matrix_world.decompose() obj.matrix_world = Matrix.Identity(4) m = obj.data s_mat_x = Matrix.Scale(scale.x, 4, Vector((1, 0, 0))) s_mat_y = Matrix.Scale(scale.y, 4, Vector((0, 1, 0))) s_mat_z = Matrix.Scale(scale.z, 4, Vector((0, 0, 1))) if scale: m.transform(s_mat_x * s_mat_y * s_mat_z) else: obj.scale = scale if rotation: m.transform(rot.to_matrix().to_4x4()) else: obj.rotation_euler = rot.to_euler() if location: m.transform(Matrix.Translation(loc)) else: obj.location = loc
def apply_transform(obj: Object): """ efficiently apply object transformation """ # select(obj, active=True, only=True) # bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) loc, rot, scale = obj.matrix_world.decompose() obj.matrix_world = Matrix.Identity(4) m = obj.data s_mat_x = Matrix.Scale(scale.x, 4, Vector((1, 0, 0))) s_mat_y = Matrix.Scale(scale.y, 4, Vector((0, 1, 0))) s_mat_z = Matrix.Scale(scale.z, 4, Vector((0, 0, 1))) m.transform(s_mat_x * s_mat_y * s_mat_z) m.transform(rot.to_matrix().to_4x4()) m.transform(Matrix.Translation(loc))
def apply_transform(obj:Object, location:bool=True, rotation:bool=True, scale:bool=True): """ apply object transformation to mesh """ loc, rot, scale = obj.matrix_world.decompose() obj.matrix_world = Matrix.Identity(4) m = obj.data s_mat_x = Matrix.Scale(scale.x, 4, Vector((1, 0, 0))) s_mat_y = Matrix.Scale(scale.y, 4, Vector((0, 1, 0))) s_mat_z = Matrix.Scale(scale.z, 4, Vector((0, 0, 1))) if scale: m.transform(mathutils_mult(s_mat_x, s_mat_y, s_mat_z)) else: obj.scale = scale if rotation: m.transform(rot.to_matrix().to_4x4()) else: obj.rotation_euler = rot.to_euler() if location: m.transform(Matrix.Translation(loc)) else: obj.location = loc
def ob_copy_to_faces(ob: Object) -> None: mats = mesh.face_pos() if mats: ob.matrix_world = mats.pop() collection = bpy.context.collection space_data = bpy.context.space_data use_local_view = bool(space_data.local_view) for mat in mats: ob_copy = ob.copy() collection.objects.link(ob_copy) ob_copy.matrix_world = mat ob_copy.select_set(True) if use_local_view: ob_copy.local_view_set(space_data, True)
def apply_transform(obj:Object, location:bool=True, rotation:bool=True, scale:bool=True): """ apply object transformation to mesh """ loc, rot, scl = obj.matrix_world.decompose() obj.matrix_world = Matrix.Identity(4) m = obj.data s_mat_x = Matrix.Scale(scl.x, 4, Vector((1, 0, 0))) s_mat_y = Matrix.Scale(scl.y, 4, Vector((0, 1, 0))) s_mat_z = Matrix.Scale(scl.z, 4, Vector((0, 0, 1))) if scale: m.transform(mathutils_mult(s_mat_x, s_mat_y, s_mat_z)) else: obj.scale = scl if rotation: m.transform(rot.to_matrix().to_4x4()) else: obj.rotation_euler = rot.to_euler() if location: m.transform(Matrix.Translation(loc)) else: obj.location = loc