Example: Anatomy of a Custom Rig Script

 
 
 

This example builds a simple biped using the Character Development Kit's rigging kit commands. You'll notice that the commands have the same options you have in the interface—for example, you can choose a quaternion spine for the torso, define forearm and bicep divisions, control the location of the leg's up vector, etc.

Each command reads from an array of positioned "guide" nulls (see the end of the script). You can either set up your own guide objects, or use the guides available in the Softimage's default guides (see Identifying Guide Objects in the Default Guides).

Each command also returns a list of objects created, which helps you determine the name of object the rig component should be parented to. In this script, however, the script writer knew the names of the objects each command creates (this is easy to figure out by consulting the CDK Object Reference or the Commands and Scripting Reference). You can also use return values to add components to envelopes or hidden groups, etc. For more information about using return values, refer to Working with Return Values.

// build list of guide object positions and names
BuildGuideArrays();

var Biped = new Object();

// make the model and the globalSRT icon
Biped.Model = ActiveSceneRoot.AddModel();
Biped.GlobalSRT = makeRigIcon(Biped.Model, 4, 
									 0,0,0, 				//position
									 1,1,1, 				//icon length,width,height
									 893, 						//color
									 "GlobalSRT"			 //name
						);

// make the torso
guidecoll = CreateGuideColl(guidepos, guidename, Array(0,1,2,3,4,5,6,7,8,9));  
Biped.Torso = makeTorso(Biped.GlobalSRT , 										//parent object
										4, 				//nb of torso divisions
									 	false, 			//use fixed length spine
										guidecoll, 		//torso guides: 
										0,			 //use square icons for torso controls
										1,			 //spine head and neck
										null,		 //spine parameter sliders
										0,			 //no shadow
										null,		 //no shadow parent
										0);			 //don't use negative scaling
DeleteObj( guidecoll );
// make the arms. first the left arm, then the right arm
// left arm
guidecoll = CreateGuideColl(guidepos, guidename, Array(6,10,11));  

Biped.LArm = MakeArm(Biped.Torso.LEff,  //parent object
					guidecoll,				//guide objects
					"L",				//arm object prefix
					Biped.Torso.LEff,				//object to pos. constrain arm root to
					0,					//#forearm divs
					0,					//#bicep divs
					0,					//no shadow
					null,				//no shadow parent
					null,				//hand root
					0);					//don't use negative scale

DeleteObj( guidecoll );

// right arm 
guidecoll = CreateGuideColl(guidepos, guidename, Array(9,12,13));  

Biped.LArm = MakeArm(Biped.Torso.REff,  //parent object
					guidecoll,				//guide objects
					"R",				//arm object prefix
					Biped.Torso.REff,				//object to pos. constrain arm root to
					0,					//#forearm divs
					0,					//#bicep divs
					0,					//no shadow
					null,				//no shadow parent
					null,				//hand root
					0);					//don't use negative scale

DeleteObj( guidecoll );

// make the head
guidecoll = CreateGuideColl(guidepos, guidename, Array(14,15,16));  

Biped.Head = MakeHead(				Biped.Torso.Spine.TopVertebra, 
					 	guidecoll, 
					 	"",
					 	1,				//use spine-type head and neck 
					 	0, 				//box shadow head type 
					 	2,				//number of neck spine divisions
					 	1,				//neck stretches to meet head controller
					 	null,			//neck sliders
					 	null,			//no ears (guide collection for ears) 

						0,				//no shadow
						null);				//no shadow parent
DeleteObj( guidecoll );


// make the legs, first the left then the right
//left leg
guidecoll = CreateGuideColl(guidepos, guidename, Array(4,17,18));  
Biped.LeftLeg = MakeLeg( 					Biped.Model, 				//rig model
							Biped.Torso.HipBone,//leg parent
							"L", 				//object name prefix
							guidecoll, 				//1)top of leg, 2)knee, 3)ankle
							1, 					//place leg upvector behind leg
							0, 					//#thigh divisions
							0,					 //no shadow
							null);					 //no shadow parent
DeleteObj( guidecoll );

//right leg
guidecoll = CreateGuideColl(guidepos, guidename, Array(7,19,20));  
Biped.RightLeg = MakeLeg( 					Biped.Model, 				//rig model
							Biped.Torso.HipBone,//leg parent
							"R", 				//object name prefix
							guidecoll, 				//1)top of leg, 2)knee, 3)ankle
							1, 					//place leg upvector behind leg
							0, 					//#thigh divisions
							0,					 //no shadow
							null);					 //no shadow parent
DeleteObj( guidecoll );

// make the feet, first the left, then the right
//left foot
guidecoll = CreateGuideColl(guidepos, guidename, Array(21,22,23,18,24,25,26));  

Biped.LeftFoot = MakeFoot(					Biped.Model, 			//rig model
						Biped.GlobalSRT,			//parent of foot controls
						"L", 				//short object name prefix
						"Left", 				//long object name prefix
						guidecoll, 				//foot guide objects
						null, 					//foot sliders
						0, 					//create extenstion icon (used for dog leg)
						0,					//no shadow
						null);					//no shadow parent

//attach the leg to the foot
Biped.LeftLeg.Eff.AddChild(Biped.LeftFoot.Root);
Biped.LeftLeg.Eff.Kinematics.AddConstraint("Position", Biped.LeftFoot.BaseGuide , false);
						
DeleteObj( guidecoll );
//right foot
guidecoll = CreateGuideColl(guidepos, guidename, Array(27,28,29,20,30,31,32));  

Biped.RightFoot = MakeFoot(					Biped.Model, 			//rig model
						Biped.GlobalSRT,			//parent of foot controls
						"R", 				//short object name prefix
						"Right", 				//long object name prefix
						guidecoll, 				//foot guide objects
						null, 					//foot sliders
						0, 					//create extenstion icon (used for dog leg)
						0,					//no shadow
						null);					//no shadow parent

//attach the leg to the foot
Biped.RightLeg.Eff.AddChild(Biped.RightFoot.Root);
Biped.RightLeg.Eff.Kinematics.AddConstraint("Position", Biped.RightFoot.BaseGuide , false);
						
DeleteObj( guidecoll );

//----------------------------------------------
// Builds an array of guide positions and names
//----------------------------------------------
function BuildGuideArrays()
{

	guidepos  = new Array();
	guidename = new Array();

	for (i=0;i<33;i++)
	{ 
		guidepos[i] = XSIMath.CreateVector3(); 
	}

	i=0;
	
	//0 to 3
	guidepos[i].Set(0,18,-0.5);						guidename[i++] = "SpineBase";
	guidepos[i].Set(0,20,-0.5);						guidename[i++] = "SpineBaseDepth";
	guidepos[i].Set(0,22,-0.5);						guidename[i++] = "SpineEndDepth";
	guidepos[i].Set(0,24,-0.5);						guidename[i++] = "SpineEnd";

	//4 to 6
	guidepos[i].Set(1.75,16,0);						guidename[i++] = "LeftLegStart";
	guidepos[i].Set(2,24,0);						guidename[i++] = "LeftShoulderStart";
	guidepos[i].Set(4,24,0);						guidename[i++] = "LeftShoulderEnd";

	//7 to 9
	guidepos[i].Set(-1.75,16,0);					guidename[i++] = "RightLegStart";
	guidepos[i].Set(-2,24,0);						guidename[i++] = "RightShoulderStart";
	guidepos[i].Set(-4,24,0);						guidename[i++] = "RightShoulderEnd";

	//10 to 11
	guidepos[i].Set(8,24,-1);						guidename[i++] = "LeftElbow";
	guidepos[i].Set(12,24,0);						guidename[i++] = "LeftHand";

	//12 to 13
	guidepos[i].Set(-8,24,1);						guidename[i++] = "RightElbow";
	guidepos[i].Set(-12,24,0);						guidename[i++] = "RightHand";
		
	//14 to 16
	guidepos[i].Set(0,24,-0.5);						guidename[i++] = "NeckBase";
	guidepos[i].Set(0,25,-0.5);						guidename[i++] = "Neck";
	guidepos[i].Set(0,26,-0.5);						guidename[i++] = "Head";
	
	//17 to 18
	guidepos[i].Set(1.75,9,0.5);					guidename[i++] = "LeftKnee";
	guidepos[i].Set(1.75,2,0);						guidename[i++] = "LeftAnkle";

	//19 to 20
	guidepos[i].Set(-1.75,9,0.5);						guidename[i++] = "RightKnee";
	guidepos[i].Set(-1.75,2,0);						guidename[i++] = "RightAnkle";

	//21 to 26
	guidepos[i].Set(1.75,0,0);						guidename[i++] = "LMiddlePivot";
	guidepos[i].Set(1.65,0,0);						guidename[i++] = "LRightPivot";
	guidepos[i].Set(1.85,0,0);						guidename[i++] = "LLeftPivot";
	guidepos[i].Set(1.75,1,1);						guidename[i++] = "LLeftFoot";
	guidepos[i].Set(1.75,0.5,2);					guidename[i++] = "LLeftToe";
	guidepos[i].Set(1.75,0.5,3);					guidename[i++] = "LLeftToe2";
	
	//27 to 32
	guidepos[i].Set(-1.75,0,0);						guidename[i++] = "RMiddlePivot";
	guidepos[i].Set(-1.85,0,0);						guidename[i++] = "RRightPivot";
	guidepos[i].Set(-1.65,0,0);						guidename[i++] = "RLeftPivot";
	guidepos[i].Set(-1.75,1,1);						guidename[i++] = "RLeftFoot";
	guidepos[i].Set(-1.75,0.5,2);						guidename[i++] = "RLeftToe";
	guidepos[i].Set(-1.75,0.5,3);						guidename[i++] = "RLeftToe2";
	
}

//-------------------------------------------------------
// From array of positions and names created in BuildGuideArrays(),
// create a collection of guide nulls
//-------------------------------------------------------
function CreateGuideColl( in_aGuidePositions, in_aGuideNames, in_Indices)
{

	var lXfm = XSIMath.CreateTransform();
	var guidecoll = new ActiveXObject("XSI.Collection");
	
	var idx;
	for(idx=0; idx<in_Indices.length; idx++)
	{
//		logmessage(in_Indices[idx] + "  " + in_aGuideNames[in_Indices[idx]]);
		guidecoll.Add( GetPrim("Null", in_aGuideNames[in_Indices[idx]]) ); 
		lXfm.SetTranslation(in_aGuidePositions[in_Indices[idx]]);
		guidecoll(idx).Kinematics.Global.Transform = lXfm;
	}
	
	return guidecoll;
}