SHARE
TWEET

Untitled

a guest Jan 14th, 2020 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 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):
  2.     "Apply the matrix to the transformation of the bone, taking locked channels, mode and certain constraints into account, and optionally keyframe it."
  3.     bone = obj.pose.bones[bone_name]
  4.  
  5.     def restore_channels(prop, old_vec, locks, extra_lock):
  6.         if extra_lock or (not ignore_locks and all(locks)):
  7.             setattr(bone, prop, old_vec)
  8.         else:
  9.             if not ignore_locks and any(locks):
  10.                 new_vec = Vector(getattr(bone, prop))
  11.  
  12.                 for i, lock in enumerate(locks):
  13.                     if lock:
  14.                         new_vec[i] = old_vec[i]
  15.  
  16.                 setattr(bone, prop, new_vec)
  17.  
  18.     # Save the old values of the properties
  19.     old_loc = Vector(bone.location)
  20.     old_rot_euler = Vector(bone.rotation_euler)
  21.     old_rot_quat = Vector(bone.rotation_quaternion)
  22.     old_rot_axis = Vector(bone.rotation_axis_angle)
  23.     old_scale = Vector(bone.scale)
  24.  
  25.     # Compute and assign the local matrix
  26.     if space != 'LOCAL':
  27.         matrix = obj.convert_space(pose_bone=bone, matrix=matrix, from_space=space, to_space='LOCAL')
  28.  
  29.     if undo_copy_scale:
  30.         matrix = undo_copy_scale_constraints(obj, bone, matrix)
  31.  
  32.     bone.matrix_basis = matrix
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top