例: タコリグの作成

 
 
 

この例では、タコリグをビルドします。 このタコリグを構成する内容は、次のとおりです。

ガイドヌルのコレクションは、エレメントを配置する各コマンドに渡されます。

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

var Octopus = new Object();

/*
	MAKE MODEL AND GLOBAL SRT ICON
*/
Octopus.Model = ActiveSceneRoot.AddModel();
Octopus.Model.Name = "Octopus"
Octopus.GlobalSRT = makeRigIcon(Octopus.Model, 4, 
									 0,0,0, 			//position
									 1,1,1,   			//icon length,width,height
									 893, 			//color
									 "GlobalSRT"		 //name
						);

//Make the main octopus controller
Octopus.BodyCtrl = makeRigIcon(Octopus.GlobalSRT, 2, 
									 0,4.5,0, 			//position
									 5,1.4,5,   			//icon length,width,height
									 253, 			//color
									 "BodyCtrl"			 //name
						);
						
//Make the tentacle control (manipulate to settle the tentacles)
Octopus.TentacleCtrl = makeRigIcon(Octopus.BodyCtrl, 2, 
									 0,4.5,0, 			//position
									 2.5,1,2.5,   		//icon length,width,height
									 49, 			//color
									 "TentacleCtrl"			 //name
						);

Octopus.TentacleCtrl.Kinematics.AddConstraint("Pose",Octopus.BodyCtrl,true);																			
			
/*
	MAKE THE HEAD
*/
guidecoll = CreateGuideColl(guidepos, guidename, Array(0,1,2));  
						
Octopus.Head = MakeHead(Octopus.BodyCtrl, //head parent
						guidecoll, //guide collection
						"Octo",					 //object name prefix
						1,					//spine head and neck
						0,					//head type (ignored unless creating box shadow)
						3,					 //number of vertebrae
						1,					 //stretch spine
						null, //spine sliders
						null, //ear guide collection
						0,					 //shadow type
						null); //shadow parent
						
DeleteObj( guidecoll );

/*
	MAKE THE TENTACLES
*/

guidecoll = CreateGuideColl(guidepos, guidename, Array(3,4,5,6,7)); 
 
	var lXfm = XSIMath.CreateTransform();
	lXfm.SetIdentity();
	lXfm.SetRotationFromXYZAnglesValues(0,2*3.1415/8,0);
	
	Octopus.Tentacles = new Array();
	
	for(i=0;i<8;i++)
	{
		OffsetGuideColl(guidecoll, lXfm);
		Octopus.Tentacles[i] = MakeTail(Octopus.BodyCtrl, //head parent
								guidecoll,				 //guide collection
								6,					 //number of bones
								0,					 //shadow type
								null);				 //shadow parent
				
		 Octopus.Tentacles[i].Root.Kinematics.AddConstraint("Pose",Octopus.TentacleCtrl,true);																				
	}

DeleteObj( guidecoll );
Translate(Octopus.BodyCtrl, 0, 2, 0, siRelative, siView, siObj, siXYZ, null, null, null, null, null, null, null, null, null, 0);

//----------------------------------------------
// Build 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 2
	guidepos[i].Set(0,5,0);					guidename[i++] = "SpineBase";
	guidepos[i].Set(0,7,0);					guidename[i++] = "SpineBaseDepth";
	guidepos[i].Set(0,9,0);					guidename[i++] = "SpineEndDepth";

	//3 to 7
	guidepos[i].Set(1,5,0);					guidename[i++] = "TentacleBase";
	guidepos[i].Set(3,5,0);					guidename[i++] = "Tentacle1";
	guidepos[i].Set(5,5,0);					guidename[i++] = "Tentacle2";
	guidepos[i].Set(7,5,0);					guidename[i++] = "Tentacle3";
	guidepos[i].Set(9,5,0);					guidename[i++] = "TentacleTip";
	
}

//-------------------------------------------------------
// 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;
}

function OffsetGuideColl( in_GuideColl, in_OffsetXfo)
{
	var GuideXfm, idx;
	for(idx=0; idx<in_GuideColl.count; idx++)
	{
		GuideXfm = in_GuideColl(idx).Kinematics.Global.Transform;
		GuideXfm.Mul(GuideXfm,in_OffsetXfo);
		in_GuideColl(idx).Kinematics.Global.Transform = GuideXfm;
	}
}