Making custom rigs

From Valve Developer Community
< SFM
Jump to: navigation, search
Underlinked - Logo.png
This article needs more links to other articles to help integrate it into the encyclopedia. Please help improve this article by adding links that are relevant to the context within the existing text.
January 2024
Warning.pngWarning:Be aware that the SFM team may change the script bindings and thus break all external scripts at any time.

Creating a IK rig for a custom model is fairly easy to accomplish by modifying the rig_biped_simple script included with the SFM. We will run through the creation of a new rig script for Atlas from Portal 2 as an example (model name is ballbot.mdl), assuming that Portal 2 content has been added to SFM through the guide located at [1].

The rig_biped_simple script is located at Steam/steamapps/common/SourceFilmmaker/game/platform/scripts/sfm/animset/rig_biped_simple.py Start by making a copy of this script called rig_biped_atlas.py

Open up the new copy of the script and scroll down to the comment #Find the dag nodes for all of the bones in the model which will be used by the script.

Under this you will find a number of variables which store references to the bones in your model that will be used in the rig script. Depending on your model, you may have bones that are named differently to the ones provided.

The most important bones that are required are the root, pelvis, upper leg, lower leg, foot, collar, elbow and hand bones. Other bones can be added or removed to the rig as required by adding them to the list of variables.

For sake of this example, we will replace the existing bones with ones from the atlas model. Open up the Model Viewer from the SFM SDK, load player/ballbot/ballbot.mdl then open the Bones tab.

By searching through the bone list with Highlight Bone selected, we can find the correct bone names that we will using as our replacements in the script. Some example bones are listed below.

  boneRoot      = sfmUtils.FindFirstDag( [ "RootTransform" ],     True )
  bonePelvis    = sfmUtils.FindFirstDag( [ "root" ],              True )
  boneSpine0    = sfmUtils.FindFirstDag( [ "spine1" ],            True )
  boneHead      = sfmUtils.FindFirstDag( [ "Body_ball" ],         True )
  boneUpperLegR = sfmUtils.FindFirstDag( [ "R_thigh" ],           True )
  boneLowerLegR = sfmUtils.FindFirstDag( [ "R_knee" ],            True )
  boneFootR     = sfmUtils.FindFirstDag( [ "R_foot" ],            True )
  boneToeR      = sfmUtils.FindFirstDag( [ "R_toe" ],             True ) 
  boneCollarR   = sfmUtils.FindFirstDag( [ "R_clavPlate_joint" ], True )   
  boneUpperArmR = sfmUtils.FindFirstDag( [ "bicep_R" ],           True ) 
  boneLowerArmR = sfmUtils.FindFirstDag( [ "elbow_R" ],           True )
  boneHandR     = sfmUtils.FindFirstDag( [ "wrist_R" ],           True )
  boneUpperLegL = sfmUtils.FindFirstDag( [ "L_thigh" ],           True )
  boneLowerLegL = sfmUtils.FindFirstDag( [ "L_knee" ],            True )
  boneFootL     = sfmUtils.FindFirstDag( [ "L_foot" ],            True )
  boneToeL      = sfmUtils.FindFirstDag( [ "L_toe" ],             True ) 
  boneCollarL   = sfmUtils.FindFirstDag( [ "L_clavPlate_joint" ], True )   
  boneUpperArmL = sfmUtils.FindFirstDag( [ "bicep_L" ],           True ) 
  boneLowerArmL = sfmUtils.FindFirstDag( [ "elbow_L" ],           True )
  boneHandL     = sfmUtils.FindFirstDag( [ "wrist_L" ],           True )

Some things to note is that we are using RootTransform as the root bone, whilst the actual root bone is being used as the pelvis bone. This is because the Atlas model does not possess a pelvis bone that can be used without moving parts of the mesh independently. This method will allow us to transform the pelvis whilst keeping the hands and legs in place.

Now that the correct bones have been added to the script, changes must be made to the rig objects that will be used to control them. Depending on your model, you may need to comment out or add new rig objects in a variety of places.

Find the line #Create the rig handles and constrain them to existing bones and comment out or add and new rig objects. For Atlas, comment out these lines as we do not have corresponding bones to use.

   #rigSpine1  = sfmUtils.CreateConstrainedHandle( "rig_spine_1",  boneSpine1,  bCreateControls=False )
   #rigSpine2  = sfmUtils.CreateConstrainedHandle( "rig_spine_2",  boneSpine2,  bCreateControls=False )
   #rigChest   = sfmUtils.CreateConstrainedHandle( "rig_chest",    boneSpine3,  bCreateControls=False )
   #rigNeck    = sfmUtils.CreateConstrainedHandle( "rig_neck",     boneNeck,    bCreateControls=False )

Find the variable allRigHandles and remove the rig objects named above

Find the comment #Build the rig handle hierarchy and comment out the same rig objects.

Find the comment #Create constraints to drive the bone transforms using the rig handles and repeat.

Remember that if you are creating this script for an alternate model, to add or remove rig elements according to your needs.

In order to add the fingers to the rig, we need edit the file Steam/steamapps/common/SourceFilmmaker/game/platform/cfg/sfm_defaultanimationgroups.txt

Find the group "Fingers" and add the following bones to the left and right finger groups respectively.

Left Fingers:

   "control"		"thumb0_L"
   "control"		"thumb1_L"	
   "control"		"thumb2_L"	
   "control"		"index0_L"	
   "control"		"index1_L"	
   "control"		"index2_L"	
   "control"		"mid_0_L"	
   "control"		"mid_1_L"	
   "control"		"mid_2_L"	
   "control"		"ring_0_L"	
   "control"		"ring_1_L"	
   "control"		"ring_2_L"	

Right Fingers:

   "control"		"thumb0_R"
   "control"		"thumb1_R"	
   "control"		"thumb2_R"	
   "control"		"index0_R"	
   "control"		"index1_R"	
   "control"		"index2_R"	
   "control"		"mid_0_R"	
   "control"		"mid_1_R"	
   "control"		"mid_2_R"	
   "control"		"ring_0_R"	
   "control"		"ring_1_R"	
   "control"		"ring_2_R"	

All done! Test it out by opening up SFM and creating a new animset for ballbot.mdl

Right click the new animset and select Rig->rig_biped_atlas. Congratulations! You now have a model with working IK controls for the hands and feet. The rig_foot and rig_hand controls will control your IK targets whilst the rig_knee and rig_elbow controls will control the direction the limb will bend towards. The rig_pelvis control will move the central body whilst leaving the hands and feet locked in place.

If you just want to jump straight in, here [[2]] are rig scripts for both of the Portal 2 co-op bots as well as an updated sfm_defaultanimationgroups file. Just extract the zip file to your Steam/common/SourceFilmmaker directory.