Advanced Twist Control

Alright, here is a confusing concept for the beginners. Though the theory of the advanced twist is slightly complicated to comprehend, the result is just smooth. Anyways, here is my script.

Mel Window:


Script:

global proc rk_advanceTwistControl()

{
if(`window -exists rk_advanceTwistControlUI`)
deleteUI rk_advanceTwistControlUI;

window -title " Advanced Twist Controls " -maximizeButton 0 rk_advanceTwistControlUI;
menuBarLayout myMenubar;
menu -label "\nHelp";
menu -label "\nEdit" myResetmenu ;
menuItem -label "Reset" -command rk_advanceTwistControl myMenuitem;
formLayout myformLayout;
//-----------------------------------------------------------------------------------
text -label " Joints " jointsText;
textScrollList -height 50 my_jointsTSL;

//-----------------------------------------------------------------------------------
text -label " IK Spline Handle" ikHandleText;
textScrollList -height 25 my_ikHandleTSL;

//-----------------------------------------------------------------------------------

text -label " Control Objects" myControlsText;
textScrollList -height 50 my_ConObjectsTSL;

//-----------------------------------------------------------------------------------

button -label " Joints " -command jointProcedure joints_button;
button -label " IK Spline Handle " -command ikHandleProcedure IKSpline_button;
button -label " Control Objects " -command controlsProcedure conObjects_button;

//-----------------------------------------------------------------------------------------

button -label " Go " -command go go_button;

//---------------------------------------------------------------
text -label " Rakesh K Karkera " myName;
text -label " tylerdurtan@gmail.com " myid;

formLayout -edit

-attachForm jointsText left 5
-attachForm jointsText top 5
-attachPosition jointsText right 0 30

-attachForm my_jointsTSL left 5
-attachControl my_jointsTSL top 2 jointsText
-attachPosition my_jointsTSL right 0 30
//-----------------------------------------------------------------------------------
-attachControl ikHandleText left 5 jointsText
-attachForm ikHandleText top 5
-attachPosition ikHandleText right 0 60

-attachControl my_ikHandleTSL left 5 my_jointsTSL
-attachControl my_ikHandleTSL top 2 ikHandleText
-attachPosition my_ikHandleTSL right 0 61
//-----------------------------------------------------------------------------------

-attachControl myControlsText left 5 ikHandleText
-attachForm myControlsText top 5
-attachPosition myControlsText right 0 90

-attachControl my_ConObjectsTSL left 6 my_ikHandleTSL
-attachControl my_ConObjectsTSL top 2 myControlsText
-attachPosition my_ConObjectsTSL right 0 98

//---------------------------------------------------------------------------------
-attachForm joints_button left 9
-attachControl joints_button top 15 my_jointsTSL
-attachPosition joints_button right 0 28

-attachControl IKSpline_button left 25 joints_button
-attachControl IKSpline_button top 40 my_ikHandleTSL
-attachPosition IKSpline_button right 0 59


-attachControl conObjects_button left 28 IKSpline_button
-attachControl conObjects_button top 15 my_ConObjectsTSL
-attachPosition conObjects_button right 0 97
//-------------------------------------------------------------------------------------
-attachForm go_button left 30
-attachControl go_button top 20 IKSpline_button
-attachForm go_button right 30

//--------------------------------------------------------------------------------------

-attachPosition myName left 0 38
-attachControl myName top 30 go_button
-attachPosition myName right 0 95


-attachPosition myid left 1 36
-attachControl myid top 0 myName
-attachPosition myid right 0 95

//----------------------------------------------------------------------------
myformLayout;

showWindow rk_advanceTwistControlUI;

}

global proc jointProcedure()

{
textScrollList -edit -removeAll my_jointsTSL;
string $selectedJoints[]= `ls -sl -head 2 ` ;

for( $eachJoint in $selectedJoints)


{
textScrollList -edit -append $eachJoint my_jointsTSL;
}

}

global proc ikHandleProcedure()

{

textScrollList -edit -removeAll my_ikHandleTSL;

string $selectedIK[]=`ls -sl -head 1`;

textScrollList -edit -append $selectedIK[0] my_ikHandleTSL;
}

global proc controlsProcedure()
{
textScrollList -edit -removeAll my_ConObjectsTSL;

string $selectedControls[]=`ls -sl -head 2`;
string $selectedJoints[]= `textScrollList -q -allItems my_jointsTSL`;

int $i;
for($i=0; $i<=1; $i++)
{
textScrollList -edit -append $selectedControls[$i] my_ConObjectsTSL;

select -r $selectedControls[$i];
move 0 0 0 ;
rotate 0 0 0 ;
group -relative -name ($selectedControls[$i]+"_grp" );

string $grouped[]=`ls -sl`;

parentConstraint $selectedJoints[$i] $grouped[0];
select -r ($grouped[0]+"_parentConstraint1");
delete;
}
}
global proc go()

{
string $selectedikHandle[]= `textScrollList -q -allItems my_ikHandleTSL`;

string $selectedconObjects[]= `textScrollList -q -allItems my_ConObjectsTSL`;

setAttr ($selectedikHandle[0]+".dTwistControlEnable") 1;

setAttr ($selectedikHandle[0]+".dWorldUpType") 4;

string $wrldUpObject = $selectedconObjects[0];
string $wrldUpObject2 = $selectedconObjects[1];
string $splnIKHandle = $selectedikHandle[0];
connectAttr -f ($wrldUpObject + ".worldMatrix") ($splnIKHandle+".dWorldUpMatrix");
connectAttr -f ($wrldUpObject2 + ".worldMatrix") ($splnIKHandle+".dWorldUpMatrixEnd");
}

Where To Use: Advance twist is commonly used in the spine of a bi-ped rig. After attaching the ikSpline handle to the spine, attaching the controls to its advance twist gives a very smooth rotation action in a certain direction.

How To Use: After creating the skeleton and attaching the ikSpline handle to the bi-ped character, create two control curves as shown in picture 1 below. In my case i have just created two nurbs circles but u can create your fancy curves. Remember to keep them near the origin as shown in the picture.


Then attach the joints, ikSpline handle and conrols to the Mel Window by selecting and hitting on their respective buttons as shown below in picture 2.


Finally click on 'GO'. The advanced twist is thus activated and by rotating the controls in the X- Axis direction we can see a smooth rotation down the spine as shown in picture below.

No comments:

Post a Comment