Advertisement
Guest User

rig_biped_tali.py

a guest
Jan 1st, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 26.02 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( [ "pelvis",      "ValveBiped.Bip01_Pelvis",      "Bip01_Pelvis",     "bip_pelvis" ], True )
  181.     boneSpine0    = sfmUtils.FindFirstDag( [ "spine",       "ValveBiped.Bip01_Spine",       "Bip01_Spine",      "bip_spine_0" ], True )
  182.     boneSpine1    = sfmUtils.FindFirstDag( [ "spine",       "ValveBiped.Bip01_Spine1",      "Bip01_Spine1",     "bip_spine_1" ], False )
  183.     boneSpine2    = sfmUtils.FindFirstDag( [ "spine1",      "ValveBiped.Bip01_Spine2",      "Bip01_Spine2",     "bip_spine_2" ], True )
  184.     boneSpine3    = sfmUtils.FindFirstDag( [ "spine2",      "ValveBiped.Bip01_Spine3",      "Bip01_Spine3",     "bip_spine_3",  "ValveBiped.Bip01_Spine4" ], True )
  185.     boneNeck      = sfmUtils.FindFirstDag( [ "neck",        "ValveBiped.Bip01_Neck",        "Bip01_Neck",       "bip_neck_0",   "bip_neck", "ValveBiped.Bip01_Neck1" ], True )
  186.     boneHead      = sfmUtils.FindFirstDag( [ "head",        "ValveBiped.Bip01_Head",        "Bip01_Head",       "bip_head",     "ValveBiped.Bip01_Head1" ], True )
  187.    
  188.     boneUpperLegR = sfmUtils.FindFirstDag( [ "R_thigh",     "ValveBiped.Bip01_R_Thigh",    "Bip01_R_Thigh",    "bip_hip_R" ], True )
  189.     boneLowerLegR = sfmUtils.FindFirstDag( [ "R_shin",      "ValveBiped.Bip01_R_Calf",     "Bip01_R_Calf",     "bip_knee_R" ], True )
  190.     boneFootR     = sfmUtils.FindFirstDag( [ "R_foot",      "ValveBiped.Bip01_R_Foot",     "Bip01_R_Foot",     "bip_foot_R" ], True )
  191.     boneToeR      = sfmUtils.FindFirstDag( [ "R_toe",       "ValveBiped.Bip01_R_Toe0",     "Bip01_R_Toe0",     "bip_toe_R" ], True )
  192.     boneCollarR   = sfmUtils.FindFirstDag( [ "R_shoulder",  "ValveBiped.Bip01_R_Clavicle", "Bip01_R_Clavicle", "bip_collar_R" ], True )  
  193.     boneUpperArmR = sfmUtils.FindFirstDag( [ "R_arm",       "ValveBiped.Bip01_R_UpperArm", "Bip01_R_UpperArm", "bip_upperArm_R" ], True )
  194.     boneLowerArmR = sfmUtils.FindFirstDag( [ "R_forearm",   "ValveBiped.Bip01_R_Forearm",  "Bip01_R_Forearm",  "bip_lowerArm_R" ], True )
  195.     boneHandR     = sfmUtils.FindFirstDag( [ "ValveBiped.Bip01_R_Hand",     "Bip01_R_Hand",     "bip_hand_R" ], True )
  196.    
  197.     boneUpperLegL = sfmUtils.FindFirstDag( [ "L_thigh",     "ValveBiped.Bip01_L_Thigh",    "Bip01_L_Thigh",    "bip_hip_L" ], True )
  198.     boneLowerLegL = sfmUtils.FindFirstDag( [ "L_shin",      "ValveBiped.Bip01_L_Calf",     "Bip01_L_Calf",     "bip_knee_L" ], True )
  199.     boneFootL     = sfmUtils.FindFirstDag( [ "L_foot",      "ValveBiped.Bip01_L_Foot",     "Bip01_L_Foot",     "bip_foot_L" ], True )
  200.     boneToeL      = sfmUtils.FindFirstDag( [ "L_toe",       "ValveBiped.Bip01_L_Toe0",     "Bip01_L_Toe0",     "bip_toe_L" ], True )
  201.     boneCollarL   = sfmUtils.FindFirstDag( [ "L_shoulder",  "ValveBiped.Bip01_L_Clavicle", "Bip01_L_Clavicle", "bip_collar_L" ], True )        
  202.     boneUpperArmL = sfmUtils.FindFirstDag( [ "L_arm",       "ValveBiped.Bip01_L_UpperArm", "Bip01_L_UpperArm", "bip_upperArm_L" ], True )
  203.     boneLowerArmL = sfmUtils.FindFirstDag( [ "L_forearm",   "ValveBiped.Bip01_L_Forearm",  "Bip01_L_Forearm",  "bip_lowerArm_L" ], True )
  204.     boneHandL     = sfmUtils.FindFirstDag( [ "ValveBiped.Bip01_L_Hand",     "Bip01_L_Hand",     "bip_hand_L" ], True )
  205.    
  206.  
  207.     #==============================================================================================
  208.     # Create the rig handles and constrain them to existing bones
  209.     #==============================================================================================
  210.     rigRoot    = sfmUtils.CreateConstrainedHandle( "rig_root",     boneRoot,    bCreateControls=False )
  211.     rigPelvis  = sfmUtils.CreateConstrainedHandle( "rig_pelvis",   bonePelvis,  bCreateControls=False )
  212.     rigSpine0  = sfmUtils.CreateConstrainedHandle( "rig_spine_0",  boneSpine0,  bCreateControls=False )
  213.     rigSpine1  = sfmUtils.CreateConstrainedHandle( "rig_spine_1",  boneSpine1,  bCreateControls=False )
  214.     rigSpine2  = sfmUtils.CreateConstrainedHandle( "rig_spine_2",  boneSpine2,  bCreateControls=False )
  215.     rigChest   = sfmUtils.CreateConstrainedHandle( "rig_chest",    boneSpine3,  bCreateControls=False )
  216.     rigNeck    = sfmUtils.CreateConstrainedHandle( "rig_neck",     boneNeck,    bCreateControls=False )
  217.     rigHead    = sfmUtils.CreateConstrainedHandle( "rig_head",     boneHead,    bCreateControls=False )
  218.    
  219.     rigFootR   = sfmUtils.CreateConstrainedHandle( "rig_foot_R",   boneFootR,   bCreateControls=False )
  220.     rigToeR    = sfmUtils.CreateConstrainedHandle( "rig_toe_R",    boneToeR,    bCreateControls=False )
  221.     rigCollarR = sfmUtils.CreateConstrainedHandle( "rig_collar_R", boneCollarR, bCreateControls=False )
  222.     rigHandR   = sfmUtils.CreateConstrainedHandle( "rig_hand_R",   boneHandR,   bCreateControls=False )
  223.     rigFootL   = sfmUtils.CreateConstrainedHandle( "rig_foot_L",   boneFootL,   bCreateControls=False )
  224.     rigToeL    = sfmUtils.CreateConstrainedHandle( "rig_toe_L",    boneToeL,    bCreateControls=False )
  225.     rigCollarL = sfmUtils.CreateConstrainedHandle( "rig_collar_L", boneCollarL, bCreateControls=False )
  226.     rigHandL   = sfmUtils.CreateConstrainedHandle( "rig_hand_L",   boneHandL,   bCreateControls=False )
  227.        
  228.    
  229.     # Use the direction from the heel to the toe to compute the knee offsets,
  230.     # this makes the knee offset indpendent of the inital orientation of the model.
  231.     vKneeOffsetR = ComputeVectorBetweenBones( boneFootR, boneToeR, 10 )
  232.     vKneeOffsetL = ComputeVectorBetweenBones( boneFootL, boneToeL, 10 )
  233.    
  234.    
  235.     rigKneeR   = sfmUtils.CreateOffsetHandle( "rig_knee_R",  boneLowerLegR, vKneeOffsetR,  bCreateControls=False )  
  236.     rigKneeL   = sfmUtils.CreateOffsetHandle( "rig_knee_L",  boneLowerLegL, vKneeOffsetL,  bCreateControls=False )
  237.     rigElbowR  = sfmUtils.CreateOffsetHandle( "rig_elbow_R", boneLowerArmR, -vKneeOffsetR,  bCreateControls=False )
  238.     rigElbowL  = sfmUtils.CreateOffsetHandle( "rig_elbow_L", boneLowerArmL, -vKneeOffsetL,  bCreateControls=False )
  239.    
  240.     # Create a helper handle which will remain constrained to the each foot position that can be used for parenting.
  241.     rigFootHelperR = sfmUtils.CreateConstrainedHandle( "rig_footHelper_R", boneFootR, bCreateControls=False )
  242.     rigFootHelperL = sfmUtils.CreateConstrainedHandle( "rig_footHelper_L", boneFootL, bCreateControls=False )
  243.    
  244.     # Create a list of all of the rig dags
  245.     allRigHandles = [ rigRoot, rigPelvis, rigSpine0, rigSpine1, rigSpine2, rigChest, rigNeck, rigHead,
  246.                       rigCollarR, rigElbowR, rigHandR, rigKneeR, rigFootR, rigToeR,
  247.                       rigCollarL, rigElbowL, rigHandL, rigKneeL, rigFootL, rigToeL ];
  248.    
  249.    
  250.     #==============================================================================================
  251.     # Generate the world space logs for the rig handles and remove the constraints
  252.     #==============================================================================================
  253.     sfm.ClearSelection()
  254.     sfmUtils.SelectDagList( allRigHandles )
  255.     sfm.GenerateSamples()
  256.     sfm.RemoveConstraints()    
  257.    
  258.    
  259.     #==============================================================================================
  260.     # Build the rig handle hierarchy
  261.     #==============================================================================================
  262.     sfmUtils.ParentMaintainWorld( rigPelvis,        rigRoot )
  263.     sfmUtils.ParentMaintainWorld( rigSpine0,        rigPelvis )
  264.     sfmUtils.ParentMaintainWorld( rigSpine1,        rigSpine0 )
  265.     sfmUtils.ParentMaintainWorld( rigSpine2,        rigSpine1 )
  266.     sfmUtils.ParentMaintainWorld( rigChest,         rigSpine2 )
  267.     sfmUtils.ParentMaintainWorld( rigNeck,          rigChest )
  268.     sfmUtils.ParentMaintainWorld( rigHead,          rigNeck )
  269.    
  270.     sfmUtils.ParentMaintainWorld( rigFootHelperR,   rigRoot )
  271.     sfmUtils.ParentMaintainWorld( rigFootHelperL,   rigRoot )
  272.     sfmUtils.ParentMaintainWorld( rigFootR,         rigRoot )
  273.     sfmUtils.ParentMaintainWorld( rigFootL,         rigRoot )
  274.     sfmUtils.ParentMaintainWorld( rigKneeR,         rigFootR )
  275.     sfmUtils.ParentMaintainWorld( rigKneeL,         rigFootL )
  276.     sfmUtils.ParentMaintainWorld( rigToeR,          rigFootHelperR )
  277.     sfmUtils.ParentMaintainWorld( rigToeL,          rigFootHelperL )
  278.    
  279.     sfmUtils.ParentMaintainWorld( rigCollarR,       rigChest )
  280.     sfmUtils.ParentMaintainWorld( rigElbowR,        rigCollarR )
  281.     sfmUtils.ParentMaintainWorld( rigHandR,     rigRoot )
  282.     sfmUtils.ParentMaintainWorld( rigCollarL,       rigChest )
  283.     sfmUtils.ParentMaintainWorld( rigElbowL,        rigCollarL )
  284.     sfmUtils.ParentMaintainWorld( rigHandL,     rigRoot )
  285.    
  286.     # Create the hips control, this allows a pelvis rotation that does not effect the spine,
  287.     # it is only used for rotation so a position control is not created. Additionally add the
  288.     # new control to the selection so the that set default call operates on it too.
  289.     rigHips = sfmUtils.CreateHandleAt( "rig_hips", rigPelvis, False, True )
  290.     sfmUtils.Parent( rigHips, rigPelvis, vs.REPARENT_LOGS_OVERWRITE )
  291.     sfm.SelectDag( rigHips )
  292.  
  293.     # Set the defaults of the rig transforms to the current locations. Defaults are stored in local
  294.     # space, so while the parent operation tries to preserve default values it is cleaner to just
  295.     # set them once the final hierarchy is constructed.
  296.     sfm.SetDefault()
  297.    
  298.    
  299.     #==============================================================================================
  300.     # Create the reverse foot controls for both the left and right foot
  301.     #==============================================================================================
  302.     rigLegsGroup = rootGroup.CreateControlGroup( "RigLegs" )
  303.     rigHelpersGroup = rootGroup.CreateControlGroup( "RigHelpers" )
  304.     rigHelpersGroup.SetVisible( False )
  305.     rigHelpersGroup.SetSnappable( False )
  306.    
  307.     footIKTargetR = rigFootR
  308.     footIkTargetL = rigFootL
  309.    
  310.     if ( gameModel != None ) :
  311.         footRollIkTargetR = CreateReverseFoot( "rig_footRoll", "R", gameModel, animSet, shot, rigHelpersGroup, rigLegsGroup )
  312.         footRollIkTargetL = CreateReverseFoot( "rig_footRoll", "L", gameModel, animSet, shot, rigHelpersGroup, rigLegsGroup )
  313.         if ( footRollIkTargetR != None ) :
  314.             footIKTargetR = footRollIkTargetR
  315.         if ( footRollIkTargetL != None ) :
  316.             footIkTargetL = footRollIkTargetL
  317.    
  318.    
  319.     #==============================================================================================
  320.     # Create constraints to drive the bone transforms using the rig handles
  321.     #==============================================================================================
  322.    
  323.     # The following bones are simply constrained directly to a rig handle
  324.     sfmUtils.CreatePointOrientConstraint( rigRoot,      boneRoot        )
  325.     sfmUtils.CreatePointOrientConstraint( rigHips,      bonePelvis      )
  326.     sfmUtils.CreatePointOrientConstraint( rigSpine0,    boneSpine0      )
  327.     sfmUtils.CreatePointOrientConstraint( rigSpine1,    boneSpine1      )
  328.     sfmUtils.CreatePointOrientConstraint( rigSpine2,    boneSpine2      )
  329.     sfmUtils.CreatePointOrientConstraint( rigChest,     boneSpine3      )
  330.     sfmUtils.CreatePointOrientConstraint( rigNeck,      boneNeck        )
  331.     sfmUtils.CreatePointOrientConstraint( rigHead,      boneHead        )
  332.     sfmUtils.CreatePointOrientConstraint( rigCollarR,   boneCollarR     )
  333.     sfmUtils.CreatePointOrientConstraint( rigCollarL,   boneCollarL     )
  334.     sfmUtils.CreatePointOrientConstraint( rigToeR,      boneToeR        )
  335.     sfmUtils.CreatePointOrientConstraint( rigToeL,      boneToeL        )
  336.    
  337.     # Create ik constraints for the arms and legs that will control the rotation of the hip / knee and
  338.     # upper arm / elbow joints based on the position of the foot and hand respectively.
  339.     sfmUtils.BuildArmLeg( rigKneeR,  footIKTargetR, boneUpperLegR,  boneFootR, True )
  340.     sfmUtils.BuildArmLeg( rigKneeL,  footIkTargetL, boneUpperLegL,  boneFootL, True )
  341.     sfmUtils.BuildArmLeg( rigElbowR, rigHandR,      boneUpperArmR,  boneHandR, True )
  342.     sfmUtils.BuildArmLeg( rigElbowL, rigHandL,      boneUpperArmL,  boneHandL, True )
  343.    
  344.    
  345.     #==============================================================================================
  346.     # Create handles for the important attachment points
  347.     #==============================================================================================    
  348.     attachmentGroup = rootGroup.CreateControlGroup( "Attachments" )  
  349.     attachmentGroup.SetVisible( False )
  350.    
  351.     sfmUtils.CreateAttachmentHandleInGroup( "pvt_heel_R",       attachmentGroup )
  352.     sfmUtils.CreateAttachmentHandleInGroup( "pvt_toe_R",        attachmentGroup )
  353.     sfmUtils.CreateAttachmentHandleInGroup( "pvt_outerFoot_R",  attachmentGroup )
  354.     sfmUtils.CreateAttachmentHandleInGroup( "pvt_innerFoot_R",  attachmentGroup )
  355.    
  356.     sfmUtils.CreateAttachmentHandleInGroup( "pvt_heel_L",       attachmentGroup )
  357.     sfmUtils.CreateAttachmentHandleInGroup( "pvt_toe_L",        attachmentGroup )
  358.     sfmUtils.CreateAttachmentHandleInGroup( "pvt_outerFoot_L",  attachmentGroup )
  359.     sfmUtils.CreateAttachmentHandleInGroup( "pvt_innerFoot_L",  attachmentGroup )
  360.    
  361.    
  362.    
  363.     #==============================================================================================
  364.     # Re-organize the selection groups
  365.     #==============================================================================================  
  366.     rigBodyGroup = rootGroup.CreateControlGroup( "RigBody" )
  367.     rigArmsGroup = rootGroup.CreateControlGroup( "RigArms" )
  368.    
  369.     RightArmGroup = rootGroup.CreateControlGroup( "RightArm" )
  370.     LeftArmGroup = rootGroup.CreateControlGroup( "LeftArm" )
  371.     RightLegGroup = rootGroup.CreateControlGroup( "RightLeg" )
  372.     LeftLegGroup = rootGroup.CreateControlGroup( "LeftLeg" )  
  373.    
  374.     sfmUtils.AddDagControlsToGroup( rigBodyGroup, rigRoot, rigPelvis, rigHips, rigSpine0, rigSpine1, rigSpine2, rigChest, rigNeck, rigHead )  
  375.      
  376.     rigArmsGroup.AddChild( RightArmGroup )
  377.     rigArmsGroup.AddChild( LeftArmGroup )
  378.     sfmUtils.AddDagControlsToGroup( RightArmGroup,  rigHandR, rigElbowR, rigCollarR )
  379.     sfmUtils.AddDagControlsToGroup( LeftArmGroup, rigHandL, rigElbowL, rigCollarL )
  380.    
  381.     rigLegsGroup.AddChild( RightLegGroup )
  382.     rigLegsGroup.AddChild( LeftLegGroup )
  383.     sfmUtils.AddDagControlsToGroup( RightLegGroup, rigKneeR, rigFootR, rigToeR )
  384.     sfmUtils.AddDagControlsToGroup( LeftLegGroup, rigKneeL, rigFootL, rigToeL )
  385.    
  386.     sfmUtils.MoveControlGroup( "rig_footRoll_L", rigLegsGroup, LeftLegGroup )
  387.     sfmUtils.MoveControlGroup( "rig_footRoll_R", rigLegsGroup, RightLegGroup )
  388.    
  389.  
  390.  
  391.     sfmUtils.AddDagControlsToGroup( rigHelpersGroup, rigFootHelperR, rigFootHelperL )
  392.  
  393.     # Set the control group visiblity, this is done through the rig so it can track which
  394.     # groups it hid, so they can be set back to being visible when the rig is detached.
  395.     HideControlGroups( rig, rootGroup, "Body", "Arms", "Legs", "Unknown", "Other", "Root" )      
  396.        
  397.     #Re-order the groups
  398.     fingersGroup = rootGroup.FindChildByName( "Fingers", False )
  399.     rootGroup.MoveChildToBottom( rigBodyGroup )
  400.     rootGroup.MoveChildToBottom( rigLegsGroup )    
  401.     rootGroup.MoveChildToBottom( rigArmsGroup )      
  402.     rootGroup.MoveChildToBottom( fingersGroup )  
  403.        
  404.     rightFingersGroup = rootGroup.FindChildByName( "RightFingers", True )
  405.     if ( rightFingersGroup != None ):
  406.         RightArmGroup.AddChild( rightFingersGroup )
  407.         rightFingersGroup.SetSelectable( False )
  408.                                
  409.     leftFingersGroup = rootGroup.FindChildByName( "LeftFingers", True )
  410.     if ( leftFingersGroup != None ):
  411.         LeftArmGroup.AddChild( leftFingersGroup )
  412.         leftFingersGroup.SetSelectable( False )
  413.        
  414.  
  415.     #==============================================================================================
  416.     # Set the selection groups colors
  417.     #==============================================================================================
  418.     topLevelColor = vs.Color( 0, 128, 255, 255 )
  419.     RightColor = vs.Color( 255, 0, 0, 255 )
  420.     LeftColor = vs.Color( 0, 255, 0, 255 )
  421.    
  422.     rigBodyGroup.SetGroupColor( topLevelColor, False )
  423.     rigArmsGroup.SetGroupColor( topLevelColor, False )
  424.     rigLegsGroup.SetGroupColor( topLevelColor, False )
  425.     attachmentGroup.SetGroupColor( topLevelColor, False )
  426.     rigHelpersGroup.SetGroupColor( topLevelColor, False )
  427.    
  428.     RightArmGroup.SetGroupColor( RightColor, False )
  429.     LeftArmGroup.SetGroupColor( LeftColor, False )
  430.     RightLegGroup.SetGroupColor( RightColor, False )
  431.     LeftLegGroup.SetGroupColor( LeftColor, False )
  432.    
  433.    
  434.     # End the rig definition
  435.     sfm.EndRig()
  436.     return
  437.    
  438. #==================================================================================================
  439. # Script entry
  440. #==================================================================================================
  441.  
  442. # Construct the rig for the selected animation set
  443. BuildRig();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement