Advertisement
yaotungyu

abandoned hatt distance rnd

Jun 14th, 2021
1,115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.09 KB | None | 0 0
  1. ns = cmds.ls("Hattie*:Geo_Grp")[0].split(":")[0]
  2. angle_calc_joints= {':{side}_Arm_ShoulderSecondaryA_Bind_Jnt':'start',
  3.                     ':{side}_Arm_ShoulderSecondaryF_Bind_Jnt':'middle',
  4.                     ':{side}_Arm_ElbowSecondaryF_Bind_Jnt':'end'}
  5.  
  6. dist_start_joints = [              
  7.     ':{side}_Cuff_Part_Bind_Jnt',
  8.     ':{side}_Cuff02_Part_Bind_Jnt',
  9.     ':{side}_Cuff03_Part_Bind_Jnt',
  10.     ':{side}_Cuff04_Part_Bind_Jnt'
  11.     ]
  12. dist_end_joint = ':{side}_Arm_ShoulderSecondaryD_Bind_Jnt'
  13. cuff_center_joint = ':{side}_CuffElbowTwist_Part_Bind_Jnt'
  14.  
  15.  
  16. loc_offset_dict = {u'{ns}__L_Cuff02_cuff_dist_end_pt.r': (-13.710952036971118,
  17.                                         -0.1653287205299997,
  18.                                         -2.002178735393707),
  19.  u'{ns}__L_Cuff02_cuff_dist_end_pt.t': (0.8669128896274074,
  20.                                         0.5791167822250358,
  21.                                         6.082250686357249),
  22.  u'{ns}__L_Cuff03_cuff_dist_end_pt.r': (-5.53661791560965,
  23.                                         1.2498842488794155,
  24.                                         15.317549823010165),
  25.  u'{ns}__L_Cuff03_cuff_dist_end_pt.t': (5.428926926507209,
  26.                                         0.4935049443176567,
  27.                                         0.5076109457532234),
  28.  u'{ns}__L_Cuff04_cuff_dist_end_pt.r': (6.719219366751352,
  29.                                         0.14837106877796996,
  30.                                         1.7967444886748256),
  31.  u'{ns}__L_Cuff04_cuff_dist_end_pt.t': (0.800522067964657,
  32.                                         -0.288305247764999,
  33.                                         -4.804874309085163),
  34.  u'{ns}__L_Cuff_cuff_dist_end_pt.r': (-4.720192471964436,
  35.                                       -0.4797406481189684,
  36.                                       -18.611451547690617),
  37.  u'{ns}__L_Cuff_cuff_dist_end_pt.t': (-4.78674468822242,
  38.                                       0.7691870091930397,
  39.                                       1.4424614781989653),
  40.  u'{ns}__R_Cuff02_cuff_dist_end_pt.r': (-13.710952036971118,
  41.                                         0.1653287205299997,
  42.                                         2.002178735393707),
  43.  u'{ns}__R_Cuff02_cuff_dist_end_pt.t': (-0.8669128896274003,
  44.                                         0.5791167822250323,
  45.                                         6.0822506863572485),
  46.  u'{ns}__R_Cuff03_cuff_dist_end_pt.r': (-5.53661791560965,
  47.                                         -1.2498842488794164,
  48.                                         -15.317549823010188),
  49.  u'{ns}__R_Cuff03_cuff_dist_end_pt.t': (-5.428926926507209,
  50.                                         0.493504944317646,
  51.                                         0.507610945753224),
  52.  u'{ns}__R_Cuff04_cuff_dist_end_pt.r': (6.719219366751352,
  53.                                         -0.14837106877797157,
  54.                                         -1.7967444886748256),
  55.  u'{ns}__R_Cuff04_cuff_dist_end_pt.t': (-0.8005220679646428,
  56.                                         -0.28830524776500965,
  57.                                         -4.8048743090851636),
  58.  u'{ns}__R_Cuff_cuff_dist_end_pt.r': (-4.720192471964439,
  59.                                       0.47974064811896816,
  60.                                       18.611451547690592),
  61.  u'{ns}__R_Cuff_cuff_dist_end_pt.t': (4.786744688222427,
  62.                                       0.7691870091930255,
  63.                                       1.4424614781989658)}
  64.  
  65. #replace dictionary keys with prpoer namespace
  66. for k in loc_offset_dict:
  67.     loc_offset_dict[k.format(ns=ns)] = loc_offset_dict.pop(k)
  68.  
  69.  
  70. for side in ['L','R']:
  71.     #create locator on upper arm
  72.     endJoint_loc = cmds.spaceLocator(n=ns+'__'+side+'_cuff_dist_end_pt')[0]
  73.    
  74.     #create an attr for controlling how much auto offset to apply
  75.     if not cmds.objExists(ns+':'+side+'_CuffElbowTwist_Main_Ctrl.autoY_offset'):
  76.         cmds.addAttr(ns+':'+side+'_CuffElbowTwist_Main_Ctrl',longName='autoY_offset',at='float',k=1)
  77.    
  78.     #create locator on center of cuff
  79.     collar_center_loc = cmds.spaceLocator(n=ns+'__'+side+'_cuff_center')[0]
  80.     for jnt in dist_start_joints:
  81.         print jnt.format(side=side)
  82.         #get cuff parts string from joint name
  83.         cuff_part = jnt.split('_')[1]
  84.        
  85.         #create distance nodes
  86.         cmds.createNode('distanceDimShape')
  87.         dist_node_name = ns+'_'+side+'_'+cuff_part+'_distancer'
  88.         dist_dim = cmds.rename(cmds.listRelatives(p=1)[0],dist_node_name)
  89.        
  90.         #create offset loc for default position of cuff joints
  91.         #locs are parented to the center cuff loc
  92.         startJoint_loc = cmds.spaceLocator(n=ns+'__'+side+'_'+cuff_part+'_cuff_dist_end_pt')[0]
  93.         cmds.parent(startJoint_loc,collar_center_loc)
  94.        
  95.         #apply pre-defined transform values to the locators
  96.         for tr in ['t','r']:
  97.             val_get = loc_offset_dict[startJoint_loc+'.'+tr]
  98.             cmds.setAttr(startJoint_loc+'.'+tr,val_get[0],val_get[1],val_get[2])
  99.        
  100.         #create a second set of cuff locators in world space for world location
  101.         startJoint_world_loc = cmds.spaceLocator(n=ns+'__'+side+'_'+cuff_part+'_cuff_dist_end_pt_world')[0]
  102.         cmds.parentConstraint(startJoint_loc,startJoint_world_loc)
  103.        
  104.         #connect the upper arm loc and the world cuff loc to the distance node
  105.         cmds.connectAttr(startJoint_world_loc+'.t',dist_dim+'.startPoint')
  106.         cmds.connectAttr(endJoint_loc +'.t',dist_dim+'.endPoint')
  107.        
  108.         #define the expression for autooffset
  109.         expn_struct = ns+':{side}_{part}_Main_Cns.ty = {distancer}*{yoffset}'.format(
  110.             side=side,
  111.             part=cuff_part,
  112.             distancer=dist_dim+'.distance',
  113.             yoffset=ns+':'+side+'_CuffElbowTwist_Main_Ctrl.autoY_offset'
  114.             )
  115.         #create expressions
  116.         #cmds.expression(s=expn_struct,n='expn_autoY_'+cuff_part)
  117.     cmds.parentConstraint(ns+cuff_center_joint.format(side=side),collar_center_loc)            
  118.     cmds.parentConstraint(ns+dist_end_joint.format(side=side),endJoint_loc)    
  119.    
  120.    
  121.  
  122.    
  123.  
  124.  
  125.        
  126.        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement