Advertisement
Guest User

thewidow IK Script

a guest
Mar 21st, 2015
1,093
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.04 KB | None | 0 0
  1. import vs
  2.  
  3. #==================================================================================================
  4. def AddValidObjectToList( objectList, obj ):
  5. if ( obj != None ): objectList.append( obj )
  6.  
  7.  
  8. #==================================================================================================
  9. def HideControlGroups( rig, rootGroup, *groupNames ):
  10. for name in groupNames:
  11. group = rootGroup.FindChildByName( name, False )
  12. if ( group != None ):
  13. rig.HideControlGroup( group )
  14.  
  15.  
  16. #==================================================================================================
  17. # Create the reverse foot control and operators for the foot on the specified side
  18. #==================================================================================================
  19. def CreateReverseFoot( controlName, sideName, gameModel, animSet, shot, helperControlGroup, footControlGroup ) :
  20.  
  21. # Cannot create foot controls without heel position, so check for that first
  22. heelAttachName = "pvt_heel_" + sideName
  23. if ( gameModel.FindAttachment( heelAttachName ) == 0 ):
  24. print "Could not create foot control " + controlName + ", model is missing heel attachment point: " + heelAttachName;
  25. return None
  26.  
  27. footRollDefault = 0.5
  28. rotationAxis = vs.Vector( 1, 0, 0 )
  29.  
  30. # Construct the name of the dag nodes of the foot and toe for the specified side
  31. footName = "rig_foot_" + sideName
  32. toeName = "rig_toe_" + sideName
  33.  
  34. # Get the world space position and orientation of the foot and toe
  35. footPos = sfm.GetPosition( footName )
  36. footRot = sfm.GetRotation( footName )
  37. toePos = sfm.GetPosition( toeName )
  38.  
  39. # Setup the reverse foot hierarchy such that the foot is the parent of all the foot transforms, the
  40. # reverse heel is the parent of the heel, so it can be used for rotations around the ball of the
  41. # foot that will move the heel, the heel is the parent of the foot IK handle so that it can perform
  42. # rotations around the heel and move the foot IK handle, resulting in moving all the foot bones.
  43. # root
  44. # + rig_foot_R
  45. # + rig_knee_R
  46. # + rig_reverseHeel_R
  47. # + rig_heel_R
  48. # + rig_footIK_R
  49.  
  50.  
  51. # Construct the reverse heel joint this will be used to rotate the heel around the toe, and as
  52. # such is positioned at the toe, but using the rotation of the foot which will be its parent,
  53. # so that it has no local rotation once parented to the foot.
  54. reverseHeelName = "rig_reverseHeel_" + sideName
  55. reverseHeelDag = sfm.CreateRigHandle( reverseHeelName, pos=toePos, rot=footRot, rotControl=False )
  56. sfmUtils.Parent( reverseHeelName, footName, vs.REPARENT_LOGS_OVERWRITE )
  57.  
  58.  
  59.  
  60. # Construct the heel joint, this will be used to rotate the foot around the back of the heel so it
  61. # is created at the heel location (offset from the foot) and also given the rotation of its parent.
  62. heelName = "rig_heel_" + sideName
  63. vecHeelPos = gameModel.ComputeAttachmentPosition( heelAttachName )
  64. heelPos = [ vecHeelPos.x, vecHeelPos.y, vecHeelPos.z ]
  65. heelRot = sfm.GetRotation( reverseHeelName )
  66. heelDag = sfm.CreateRigHandle( heelName, pos=heelPos, rot=heelRot, posControl=True, rotControl=False )
  67. sfmUtils.Parent( heelName, reverseHeelName, vs.REPARENT_LOGS_OVERWRITE )
  68.  
  69. # Create the ik handle which will be used as the target for the ik chain for the leg
  70. ikHandleName = "rig_footIK_" + sideName
  71. ikHandleDag = sfmUtils.CreateHandleAt( ikHandleName, footName )
  72. sfmUtils.Parent( ikHandleName, heelName, vs.REPARENT_LOGS_OVERWRITE )
  73.  
  74. # Create an orient constraint which causes the toe's orientation to match the foot's orientation
  75. footRollControlName = controlName + "_" + sideName
  76. toeOrientTarget = sfm.OrientConstraint( footName, toeName, mo=True, controls=False )
  77. footRollControl, footRollValue = sfmUtils.CreateControlledValue( footRollControlName, "value", vs.AT_FLOAT, footRollDefault, animSet, shot )
  78.  
  79. # Create the expressions to re-map the footroll slider value for use in the constraint and rotation operators
  80. toeOrientExprName = "expr_toeOrientEnable_" + sideName
  81. toeOrientExpr = sfmUtils.CreateExpression( toeOrientExprName, "inrange( footRoll, 0.5001, 1.0 )", animSet )
  82. toeOrientExpr.SetValue( "footRoll", footRollDefault )
  83.  
  84. toeRotateExprName = "expr_toeRotation_" + sideName
  85. toeRotateExpr = sfmUtils.CreateExpression( toeRotateExprName, "max( 0, (footRoll - 0.5) ) * 140", animSet )
  86. toeRotateExpr.SetValue( "footRoll", footRollDefault )
  87.  
  88. heelRotateExprName = "expr_heelRotation_" + sideName
  89. heelRotateExpr = sfmUtils.CreateExpression( heelRotateExprName, "max( 0, (0.5 - footRoll) ) * -100", animSet )
  90. heelRotateExpr.SetValue( "footRoll", footRollDefault )
  91.  
  92. # Create a connection from the footroll value to all of the expressions that require it
  93. footRollConnName = "conn_footRoll_" + sideName
  94. footRollConn = sfmUtils.CreateConnection( footRollConnName, footRollValue, "value", animSet )
  95. footRollConn.AddOutput( toeOrientExpr, "footRoll" )
  96. footRollConn.AddOutput( toeRotateExpr, "footRoll" )
  97. footRollConn.AddOutput( heelRotateExpr, "footRoll" )
  98.  
  99. # Create the connection from the toe orientation enable expression to the target weight of the
  100. # toe orientation constraint, this will turn the constraint on an off based on the footRoll value
  101. toeOrientConnName = "conn_toeOrientExpr_" + sideName;
  102. toeOrientConn = sfmUtils.CreateConnection( toeOrientConnName, toeOrientExpr, "result", animSet )
  103. toeOrientConn.AddOutput( toeOrientTarget, "targetWeight" )
  104.  
  105. # Create a rotation constraint to drive the toe rotation and connect its input to the
  106. # toe rotation expression and connect its output to the reverse heel dag's orientation
  107. toeRotateConstraintName = "rotationConstraint_toe_" + sideName
  108. toeRotateConstraint = sfmUtils.CreateRotationConstraint( toeRotateConstraintName, rotationAxis, reverseHeelDag, animSet )
  109.  
  110. toeRotateExprConnName = "conn_toeRotateExpr_" + sideName
  111. toeRotateExprConn = sfmUtils.CreateConnection( toeRotateExprConnName, toeRotateExpr, "result", animSet )
  112. toeRotateExprConn.AddOutput( toeRotateConstraint, "rotations", 0 );
  113.  
  114. # Create a rotation constraint to drive the heel rotation and connect its input to the
  115. # heel rotation expression and connect its output to the heel dag's orientation
  116. heelRotateConstraintName = "rotationConstraint_heel_" + sideName
  117. heelRotateConstraint = sfmUtils.CreateRotationConstraint( heelRotateConstraintName, rotationAxis, heelDag, animSet )
  118.  
  119. heelRotateExprConnName = "conn_heelRotateExpr_" + sideName
  120. heelRotateExprConn = sfmUtils.CreateConnection( heelRotateExprConnName, heelRotateExpr, "result", animSet )
  121. heelRotateExprConn.AddOutput( heelRotateConstraint, "rotations", 0 )
  122.  
  123. if ( helperControlGroup != None ):
  124. sfmUtils.AddDagControlsToGroup( helperControlGroup, reverseHeelDag, ikHandleDag, heelDag )
  125.  
  126. if ( footControlGroup != None ):
  127. footControlGroup.AddControl( footRollControl )
  128.  
  129. return ikHandleDag
  130.  
  131.  
  132. #==================================================================================================
  133. # Compute the direction from boneA to boneB
  134. #==================================================================================================
  135. def ComputeVectorBetweenBones( boneA, boneB, scaleFactor ):
  136.  
  137. vPosA = vs.Vector( 0, 0, 0 )
  138. boneA.GetAbsPosition( vPosA )
  139.  
  140. vPosB = vs.Vector( 0, 0, 0 )
  141. boneB.GetAbsPosition( vPosB )
  142.  
  143. vDir = vs.Vector( 0, 0, 0 )
  144. vs.mathlib.VectorSubtract( vPosB, vPosA, vDir )
  145. vDir.NormalizeInPlace()
  146.  
  147. vScaledDir = vs.Vector( 0, 0, 0 )
  148. vs.mathlib.VectorScale( vDir, scaleFactor, vScaledDir )
  149.  
  150. return vScaledDir
  151.  
  152.  
  153. #==================================================================================================
  154. # Build a simple ik rig for the currently selected animation set
  155. #==================================================================================================
  156. def BuildRig():
  157.  
  158. # Get the currently selected animation set and shot
  159. shot = sfm.GetCurrentShot()
  160. animSet = sfm.GetCurrentAnimationSet()
  161. gameModel = animSet.gameModel
  162. rootGroup = animSet.GetRootControlGroup()
  163.  
  164. # Start the biped rig to which all of the controls and constraints will be added
  165. rig = sfm.BeginRig( "rig_biped_" + animSet.GetName() );
  166. if ( rig == None ):
  167. return
  168.  
  169. # Change the operation mode to passthrough so changes chan be made temporarily
  170. sfm.SetOperationMode( "Pass" )
  171.  
  172. # Move everything into the reference pose
  173. sfm.SelectAll()
  174. sfm.SetReferencePose()
  175.  
  176. #==============================================================================================
  177. # Find the dag nodes for all of the bones in the model which will be used by the script
  178. #==============================================================================================
  179. boneRoot = sfmUtils.FindFirstDag( [ "RootTransform" ], True )
  180. bonePelvis = sfmUtils.FindFirstDag( [ "root hips", "Bip01_Pelvis", "bip_pelvis" ], True )
  181. boneSpine0 = sfmUtils.FindFirstDag( [ "spine lower", "Bip01_Spine", "bip_spine_0" ], True )
  182. boneSpine1 = sfmUtils.FindFirstDag( [ "spine upper", "Bip01_Spine1", "bip_spine_1" ], True )
  183. boneNeck = sfmUtils.FindFirstDag( [ "head neck lower", "Bip01_Neck", "bip_neck_0", "bip_neck", "ValveBiped.Bip01_Neck1" ], True )
  184. boneHead = sfmUtils.FindFirstDag( [ "head neck upper", "Bip01_Head", "bip_head", "ValveBiped.Bip01_Head1" ], True )
  185.  
  186. boneUpperLegR = sfmUtils.FindFirstDag( [ "leg right thigh", "Bip01_R_Thigh", "bip_hip_R" ], True )
  187. boneLowerLegR = sfmUtils.FindFirstDag( [ "leg right knee", "Bip01_R_Calf", "bip_knee_R" ], True )
  188. boneFootR = sfmUtils.FindFirstDag( [ "leg right foot", "Bip01_R_Foot", "bip_foot_R" ], True )
  189. boneToeR = sfmUtils.FindFirstDag( [ "leg right toe base", "Bip01_R_Toe0", "bip_toe_R" ], True )
  190. boneCollarR = sfmUtils.FindFirstDag( [ "arm right shoulder 1", "Bip01_R_Clavicle", "bip_collar_R" ], True )
  191. boneUpperArmR = sfmUtils.FindFirstDag( [ "arm right shoulder 2", "Bip01_R_UpperArm", "bip_upperArm_R" ], True )
  192. boneLowerArmR = sfmUtils.FindFirstDag( [ "arm right elbow", "Bip01_R_Forearm", "bip_lowerArm_R" ], True )
  193. boneHandR = sfmUtils.FindFirstDag( [ "arm right wrist", "Bip01_R_Hand", "bip_hand_R" ], True )
  194.  
  195. boneUpperLegL = sfmUtils.FindFirstDag( [ "leg left thigh", "Bip01_L_Thigh", "bip_hip_L" ], True )
  196. boneLowerLegL = sfmUtils.FindFirstDag( [ "leg left knee", "Bip01_L_Calf", "bip_knee_L" ], True )
  197. boneFootL = sfmUtils.FindFirstDag( [ "leg left foot", "Bip01_L_Foot", "bip_foot_L" ], True )
  198. boneToeL = sfmUtils.FindFirstDag( [ "leg left toe base", "Bip01_L_Toe0", "bip_toe_L" ], True )
  199. boneCollarL = sfmUtils.FindFirstDag( [ "arm left shoulder 1", "Bip01_L_Clavicle", "bip_collar_L" ], True )
  200. boneUpperArmL = sfmUtils.FindFirstDag( [ "arm left shoulder 2", "Bip01_L_UpperArm", "bip_upperArm_L" ], True )
  201. boneLowerArmL = sfmUtils.FindFirstDag( [ "arm left elbow", "Bip01_L_Forearm", "bip_lowerArm_L" ], True )
  202. boneHandL = sfmUtils.FindFirstDag( [ "arm left wrist", "Bip01_L_Hand", "bip_hand_L" ], True )
  203.  
  204. boneCollarR2 = sfmUtils.FindFirstDag( [ "arm back right shoulder 1" ], True )
  205. boneUpperArmR2 = sfmUtils.FindFirstDag( [ "arm back right shoulder 2" ], True )
  206. boneLowerArmR2 = sfmUtils.FindFirstDag( [ "arm back right elbow" ], True )
  207. boneHandR2 = sfmUtils.FindFirstDag( [ "arm back right wrist" ], True )
  208.  
  209. boneCollarL2 = sfmUtils.FindFirstDag( [ "arm back left shoulder 1" ], True )
  210. boneUpperArmL2 = sfmUtils.FindFirstDag( [ "arm back left shoulder 2" ], True )
  211. boneLowerArmL2 = sfmUtils.FindFirstDag( [ "arm back left elbow" ], True )
  212. boneHandL2 = sfmUtils.FindFirstDag( [ "arm back left wrist" ], True )
  213.  
  214.  
  215. #==============================================================================================
  216. # Create the rig handles and constrain them to existing bones
  217. #==============================================================================================
  218. rigRoot = sfmUtils.CreateConstrainedHandle( "rig_root", boneRoot, bCreateControls=False )
  219. rigPelvis = sfmUtils.CreateConstrainedHandle( "rig_pelvis", bonePelvis, bCreateControls=False )
  220. rigSpine0 = sfmUtils.CreateConstrainedHandle( "rig_spine_0", boneSpine0, bCreateControls=False )
  221. rigSpine1 = sfmUtils.CreateConstrainedHandle( "rig_spine_1", boneSpine1, bCreateControls=False )
  222. rigNeck = sfmUtils.CreateConstrainedHandle( "rig_neck", boneNeck, bCreateControls=False )
  223. rigHead = sfmUtils.CreateConstrainedHandle( "rig_head", boneHead, bCreateControls=False )
  224.  
  225. rigFootR = sfmUtils.CreateConstrainedHandle( "rig_foot_R", boneFootR, bCreateControls=False )
  226. rigToeR = sfmUtils.CreateConstrainedHandle( "rig_toe_R", boneToeR, bCreateControls=False )
  227. rigCollarR = sfmUtils.CreateConstrainedHandle( "rig_collar_R", boneCollarR, bCreateControls=False )
  228. rigHandR = sfmUtils.CreateConstrainedHandle( "rig_hand_R", boneHandR, bCreateControls=False )
  229. rigFootL = sfmUtils.CreateConstrainedHandle( "rig_foot_L", boneFootL, bCreateControls=False )
  230. rigToeL = sfmUtils.CreateConstrainedHandle( "rig_toe_L", boneToeL, bCreateControls=False )
  231. rigCollarL = sfmUtils.CreateConstrainedHandle( "rig_collar_L", boneCollarL, bCreateControls=False )
  232. rigHandL = sfmUtils.CreateConstrainedHandle( "rig_hand_L", boneHandL, bCreateControls=False )
  233.  
  234. rigCollarR2 = sfmUtils.CreateConstrainedHandle( "rig_collar_R 2", boneCollarR2, bCreateControls=False )
  235. rigHandR2 = sfmUtils.CreateConstrainedHandle( "rig_hand_R 2", boneHandR2, bCreateControls=False )
  236.  
  237. rigCollarL2 = sfmUtils.CreateConstrainedHandle( "rig_collar_L 2", boneCollarL2, bCreateControls=False )
  238. rigHandL2 = sfmUtils.CreateConstrainedHandle( "rig_hand_L 2", boneHandL2, bCreateControls=False )
  239.  
  240.  
  241.  
  242. # Use the direction from the heel to the toe to compute the knee offsets,
  243. # this makes the knee offset indpendent of the inital orientation of the model.
  244. vKneeOffsetR = ComputeVectorBetweenBones( boneFootR, boneToeR, 10 )
  245. vKneeOffsetL = ComputeVectorBetweenBones( boneFootL, boneToeL, 10 )
  246.  
  247.  
  248. rigKneeR = sfmUtils.CreateOffsetHandle( "rig_knee_R", boneLowerLegR, vKneeOffsetR, bCreateControls=False )
  249. rigKneeL = sfmUtils.CreateOffsetHandle( "rig_knee_L", boneLowerLegL, vKneeOffsetL, bCreateControls=False )
  250. rigElbowR = sfmUtils.CreateOffsetHandle( "rig_elbow_R", boneLowerArmR, -vKneeOffsetR, bCreateControls=False )
  251. rigElbowL = sfmUtils.CreateOffsetHandle( "rig_elbow_L", boneLowerArmL, -vKneeOffsetL, bCreateControls=False )
  252.  
  253. rigElbowR2 = sfmUtils.CreateOffsetHandle( "rig_elbow_R 2", boneLowerArmR2, -vKneeOffsetR, bCreateControls=False )
  254. rigElbowL2 = sfmUtils.CreateOffsetHandle( "rig_elbow_L 2", boneLowerArmL2, -vKneeOffsetR, bCreateControls=False )
  255.  
  256. # Create a helper handle which will remain constrained to the each foot position that can be used for parenting.
  257. rigFootHelperR = sfmUtils.CreateConstrainedHandle( "rig_footHelper_R", boneFootR, bCreateControls=False )
  258. rigFootHelperL = sfmUtils.CreateConstrainedHandle( "rig_footHelper_L", boneFootL, bCreateControls=False )
  259.  
  260. # Create a list of all of the rig dags
  261. allRigHandles = [ rigRoot, rigPelvis, rigSpine0, rigSpine1, rigNeck, rigHead,
  262. rigCollarR, rigElbowR, rigHandR, rigKneeR, rigFootR, rigToeR,
  263. rigCollarL, rigElbowL, rigHandL, rigKneeL, rigFootL, rigToeL,
  264. rigCollarR2, rigCollarL2, rigHandR2, rigHandL2, rigElbowR2,
  265. rigElbowL2];
  266.  
  267.  
  268. #==============================================================================================
  269. # Generate the world space logs for the rig handles and remove the constraints
  270. #==============================================================================================
  271. sfm.ClearSelection()
  272. sfmUtils.SelectDagList( allRigHandles )
  273. sfm.GenerateSamples()
  274. sfm.RemoveConstraints()
  275.  
  276.  
  277. #==============================================================================================
  278. # Build the rig handle hierarchy
  279. #==============================================================================================
  280. sfmUtils.ParentMaintainWorld( rigPelvis, rigRoot )
  281. sfmUtils.ParentMaintainWorld( rigSpine0, rigPelvis )
  282. sfmUtils.ParentMaintainWorld( rigSpine1, rigSpine0 )
  283. sfmUtils.ParentMaintainWorld( rigNeck, rigSpine1 )
  284. sfmUtils.ParentMaintainWorld( rigHead, rigNeck )
  285.  
  286. sfmUtils.ParentMaintainWorld( rigFootHelperR, rigRoot )
  287. sfmUtils.ParentMaintainWorld( rigFootHelperL, rigRoot )
  288. sfmUtils.ParentMaintainWorld( rigFootR, rigRoot )
  289. sfmUtils.ParentMaintainWorld( rigFootL, rigRoot )
  290. sfmUtils.ParentMaintainWorld( rigKneeR, rigFootR )
  291. sfmUtils.ParentMaintainWorld( rigKneeL, rigFootL )
  292. sfmUtils.ParentMaintainWorld( rigToeR, rigFootHelperR )
  293. sfmUtils.ParentMaintainWorld( rigToeL, rigFootHelperL )
  294.  
  295. sfmUtils.ParentMaintainWorld( rigCollarR, rigSpine1 )
  296. sfmUtils.ParentMaintainWorld( rigElbowR, rigCollarR )
  297. sfmUtils.ParentMaintainWorld( rigHandR, rigRoot )
  298. sfmUtils.ParentMaintainWorld( rigCollarL, rigSpine1 )
  299. sfmUtils.ParentMaintainWorld( rigElbowL, rigCollarL )
  300. sfmUtils.ParentMaintainWorld( rigHandL, rigRoot )
  301.  
  302. sfmUtils.ParentMaintainWorld( rigCollarR2, rigSpine1 )
  303. sfmUtils.ParentMaintainWorld( rigCollarL2, rigSpine1 )
  304. sfmUtils.ParentMaintainWorld( rigHandR2, rigRoot )
  305. sfmUtils.ParentMaintainWorld( rigHandL2, rigRoot )
  306. sfmUtils.ParentMaintainWorld( rigElbowR2, rigCollarR2 )
  307. sfmUtils.ParentMaintainWorld( rigElbowL2, rigCollarL2 )
  308.  
  309. # Create the hips control, this allows a pelvis rotation that does not effect the spine,
  310. # it is only used for rotation so a position control is not created. Additionally add the
  311. # new control to the selection so the that set default call operates on it too.
  312. rigHips = sfmUtils.CreateHandleAt( "rig_hips", rigPelvis, False, True )
  313. sfmUtils.Parent( rigHips, rigPelvis, vs.REPARENT_LOGS_OVERWRITE )
  314. sfm.SelectDag( rigHips )
  315.  
  316. # Set the defaults of the rig transforms to the current locations. Defaults are stored in local
  317. # space, so while the parent operation tries to preserve default values it is cleaner to just
  318. # set them once the final hierarchy is constructed.
  319. sfm.SetDefault()
  320.  
  321.  
  322. #==============================================================================================
  323. # Create the reverse foot controls for both the left and right foot
  324. #==============================================================================================
  325. rigLegsGroup = rootGroup.CreateControlGroup( "RigLegs" )
  326. rigHelpersGroup = rootGroup.CreateControlGroup( "RigHelpers" )
  327. rigHelpersGroup.SetVisible( False )
  328. rigHelpersGroup.SetSnappable( False )
  329.  
  330. footIKTargetR = rigFootR
  331. footIkTargetL = rigFootL
  332.  
  333. if ( gameModel != None ) :
  334. footRollIkTargetR = CreateReverseFoot( "rig_footRoll", "R", gameModel, animSet, shot, rigHelpersGroup, rigLegsGroup )
  335. footRollIkTargetL = CreateReverseFoot( "rig_footRoll", "L", gameModel, animSet, shot, rigHelpersGroup, rigLegsGroup )
  336. if ( footRollIkTargetR != None ) :
  337. footIKTargetR = footRollIkTargetR
  338. if ( footRollIkTargetL != None ) :
  339. footIkTargetL = footRollIkTargetL
  340.  
  341.  
  342. #==============================================================================================
  343. # Create constraints to drive the bone transforms using the rig handles
  344. #==============================================================================================
  345.  
  346. # The following bones are simply constrained directly to a rig handle
  347. sfmUtils.CreatePointOrientConstraint( rigRoot, boneRoot )
  348. sfmUtils.CreatePointOrientConstraint( rigHips, bonePelvis )
  349. sfmUtils.CreatePointOrientConstraint( rigSpine0, boneSpine0 )
  350. sfmUtils.CreatePointOrientConstraint( rigSpine1, boneSpine1 )
  351. sfmUtils.CreatePointOrientConstraint( rigNeck, boneNeck )
  352. sfmUtils.CreatePointOrientConstraint( rigHead, boneHead )
  353. sfmUtils.CreatePointOrientConstraint( rigCollarR, boneCollarR )
  354. sfmUtils.CreatePointOrientConstraint( rigCollarL, boneCollarL )
  355. sfmUtils.CreatePointOrientConstraint( rigToeR, boneToeR )
  356. sfmUtils.CreatePointOrientConstraint( rigToeL, boneToeL )
  357.  
  358. sfmUtils.CreatePointOrientConstraint( rigCollarR2, boneCollarR2 )
  359. sfmUtils.CreatePointOrientConstraint( rigCollarL2, boneCollarL2 )
  360.  
  361. # Create ik constraints for the arms and legs that will control the rotation of the hip / knee and
  362. # upper arm / elbow joints based on the position of the foot and hand respectively.
  363. sfmUtils.BuildArmLeg( rigKneeR, footIKTargetR, boneUpperLegR, boneFootR, True )
  364. sfmUtils.BuildArmLeg( rigKneeL, footIkTargetL, boneUpperLegL, boneFootL, True )
  365. sfmUtils.BuildArmLeg( rigElbowR, rigHandR, boneUpperArmR, boneHandR, True )
  366. sfmUtils.BuildArmLeg( rigElbowL, rigHandL, boneUpperArmL, boneHandL, True )
  367.  
  368. sfmUtils.BuildArmLeg( rigElbowL2, rigHandL2, boneUpperArmL2, boneHandL2, True )
  369. sfmUtils.BuildArmLeg( rigElbowR2, rigHandR2, boneUpperArmR2, boneHandR2, True )
  370.  
  371.  
  372. #==============================================================================================
  373. # Create handles for the important attachment points
  374. #==============================================================================================
  375. attachmentGroup = rootGroup.CreateControlGroup( "Attachments" )
  376. attachmentGroup.SetVisible( False )
  377.  
  378. sfmUtils.CreateAttachmentHandleInGroup( "pvt_heel_R", attachmentGroup )
  379. sfmUtils.CreateAttachmentHandleInGroup( "pvt_toe_R", attachmentGroup )
  380. sfmUtils.CreateAttachmentHandleInGroup( "pvt_outerFoot_R", attachmentGroup )
  381. sfmUtils.CreateAttachmentHandleInGroup( "pvt_innerFoot_R", attachmentGroup )
  382.  
  383. sfmUtils.CreateAttachmentHandleInGroup( "pvt_heel_L", attachmentGroup )
  384. sfmUtils.CreateAttachmentHandleInGroup( "pvt_toe_L", attachmentGroup )
  385. sfmUtils.CreateAttachmentHandleInGroup( "pvt_outerFoot_L", attachmentGroup )
  386. sfmUtils.CreateAttachmentHandleInGroup( "pvt_innerFoot_L", attachmentGroup )
  387.  
  388.  
  389.  
  390. #==============================================================================================
  391. # Re-organize the selection groups
  392. #==============================================================================================
  393. rigBodyGroup = rootGroup.CreateControlGroup( "RigBody" )
  394. rigArmsGroup = rootGroup.CreateControlGroup( "RigArms" )
  395.  
  396. RightArmGroup = rootGroup.CreateControlGroup( "RightArm" )
  397. LeftArmGroup = rootGroup.CreateControlGroup( "LeftArm" )
  398. RightLegGroup = rootGroup.CreateControlGroup( "RightLeg" )
  399. LeftLegGroup = rootGroup.CreateControlGroup( "LeftLeg" )
  400.  
  401. sfmUtils.AddDagControlsToGroup( rigBodyGroup, rigRoot, rigPelvis, rigHips, rigSpine0, rigSpine1, rigNeck, rigHead )
  402.  
  403. rigArmsGroup.AddChild( RightArmGroup )
  404. rigArmsGroup.AddChild( LeftArmGroup )
  405. sfmUtils.AddDagControlsToGroup( RightArmGroup, rigHandR, rigElbowR, rigCollarR, rigHandR2, rigElbowR2, rigCollarR2 )
  406. sfmUtils.AddDagControlsToGroup( LeftArmGroup, rigHandL, rigElbowL, rigCollarL, rigHandL2, rigElbowL2, rigCollarL2 )
  407.  
  408. rigLegsGroup.AddChild( RightLegGroup )
  409. rigLegsGroup.AddChild( LeftLegGroup )
  410. sfmUtils.AddDagControlsToGroup( RightLegGroup, rigKneeR, rigFootR, rigToeR )
  411. sfmUtils.AddDagControlsToGroup( LeftLegGroup, rigKneeL, rigFootL, rigToeL )
  412.  
  413. sfmUtils.MoveControlGroup( "rig_footRoll_L", rigLegsGroup, LeftLegGroup )
  414. sfmUtils.MoveControlGroup( "rig_footRoll_R", rigLegsGroup, RightLegGroup )
  415.  
  416.  
  417.  
  418. sfmUtils.AddDagControlsToGroup( rigHelpersGroup, rigFootHelperR, rigFootHelperL )
  419.  
  420. # Set the control group visiblity, this is done through the rig so it can track which
  421. # groups it hid, so they can be set back to being visible when the rig is detached.
  422. HideControlGroups( rig, rootGroup, "Body", "Arms", "Legs", "Unknown", "Other", "Root" )
  423.  
  424. #Re-order the groups
  425. fingersGroup = rootGroup.FindChildByName( "Fingers", False )
  426. rootGroup.MoveChildToBottom( rigBodyGroup )
  427. rootGroup.MoveChildToBottom( rigLegsGroup )
  428. rootGroup.MoveChildToBottom( rigArmsGroup )
  429. rootGroup.MoveChildToBottom( fingersGroup )
  430.  
  431. rightFingersGroup = rootGroup.FindChildByName( "RightFingers", True )
  432. if ( rightFingersGroup != None ):
  433. RightArmGroup.AddChild( rightFingersGroup )
  434. rightFingersGroup.SetSelectable( False )
  435.  
  436. leftFingersGroup = rootGroup.FindChildByName( "LeftFingers", True )
  437. if ( leftFingersGroup != None ):
  438. LeftArmGroup.AddChild( leftFingersGroup )
  439. leftFingersGroup.SetSelectable( False )
  440.  
  441.  
  442. #==============================================================================================
  443. # Set the selection groups colors
  444. #==============================================================================================
  445. topLevelColor = vs.Color( 0, 128, 255, 255 )
  446. RightColor = vs.Color( 255, 0, 0, 255 )
  447. LeftColor = vs.Color( 0, 255, 0, 255 )
  448.  
  449. rigBodyGroup.SetGroupColor( topLevelColor, False )
  450. rigArmsGroup.SetGroupColor( topLevelColor, False )
  451. rigLegsGroup.SetGroupColor( topLevelColor, False )
  452. attachmentGroup.SetGroupColor( topLevelColor, False )
  453. rigHelpersGroup.SetGroupColor( topLevelColor, False )
  454.  
  455. RightArmGroup.SetGroupColor( RightColor, False )
  456. LeftArmGroup.SetGroupColor( LeftColor, False )
  457. RightLegGroup.SetGroupColor( RightColor, False )
  458. LeftLegGroup.SetGroupColor( LeftColor, False )
  459.  
  460.  
  461. # End the rig definition
  462. sfm.EndRig()
  463. return
  464.  
  465. #==================================================================================================
  466. # Script entry
  467. #==================================================================================================
  468.  
  469. # Construct the rig for the selected animation set
  470. BuildRig();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement