Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def set_transform_from_matrix(obj, bone_name, matrix, *, space='POSE', undo_copy_scale=False, ignore_locks=False, no_loc=False, no_rot=False, no_scale=False, keyflags=None):
- "Apply the matrix to the transformation of the bone, taking locked channels, mode and certain constraints into account, and optionally keyframe it."
- bone = obj.pose.bones[bone_name]
- def restore_channels(prop, old_vec, locks, extra_lock):
- if extra_lock or (not ignore_locks and all(locks)):
- setattr(bone, prop, old_vec)
- else:
- if not ignore_locks and any(locks):
- new_vec = Vector(getattr(bone, prop))
- for i, lock in enumerate(locks):
- if lock:
- new_vec[i] = old_vec[i]
- setattr(bone, prop, new_vec)
- # Save the old values of the properties
- old_loc = Vector(bone.location)
- old_rot_euler = Vector(bone.rotation_euler)
- old_rot_quat = Vector(bone.rotation_quaternion)
- old_rot_axis = Vector(bone.rotation_axis_angle)
- old_scale = Vector(bone.scale)
- # Compute and assign the local matrix
- if space != 'LOCAL':
- matrix = obj.convert_space(pose_bone=bone, matrix=matrix, from_space=space, to_space='LOCAL')
- if undo_copy_scale:
- matrix = undo_copy_scale_constraints(obj, bone, matrix)
- bone.matrix_basis = matrix
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement