Friday, November 28, 2014

Stretchy Arm using node editor with global scale, no scripting required!

Few days back I got an email from a friend asking me for a method to stretch the arm with global scaling without using any scripting.
Here is a quick way to do it:

1/ I created a basic IK arm rig, nothing fancy.


2/ I used the Distance tool(Create-Measure Tools-Distance Tool) to measure the distance between shoulder and wrist. Snap the start and end locator to shoulder joint and wrist joint respectively. Point constraint the l_armDistStart_loc to the l_shoulder_bn and l_armDistEnd_loc to the l_arm_ctrl.


A distance node is created and you can find the distance value in the shape node of the distance node.

3/Open the node editor, and add the Global_ctrl to it; create a multiply divide node and rename it to GlobalArmScaleMult_nd.  Connect the Global_ctrl.scaleY to GlobalArmScaleMult_nd.input1X and the operation is meant to be Multiply. 
As my arm is slightly bend in the default pose, I need to straighten it before it starts stretching, that is the total distance I need to note before I apply stretching. Copy the distance value and paste it in GlobalArmScaleMult_nd.input2X. 



4/Add distance shape node to the node editor and create another multiply divide node; rename this node to l_armStretchDiv_nd. Here we will divide the distance value with outputX value of the GlobalArmScaleMult_nd.

5/As this is an arm, we aren't going to squash it. We need to keep the scale value 1 if the distance between Shoulder and wrist gets less. To do this, we will add a condition node. Create a condition node and link the outputX value of the l_armStretchDiv_nd to the first term; check if it is greater than or equal to one which means the distance has increased(the control has been stretched). If true, hook the value of  l_armStretchDiv_nd .outputX else leave the value to 1.

6/We are almost there, all you need to do it connect the outputX value of the condition node to the l_shoulder_bn.scaleX and l_elbow_bn.scaleX.

Tadaaa!! All done :D






Monday, September 22, 2014

Switch multiple textures in Maya using layered texture



This is a really cool technique I found in Maya to switch between multiple textures. Whenever I have googled about switching textures, all I could find is using psd layers or an image sequence. What if I don’t have Photoshop or any editing software but three or four texture file to switch between into a model or rig?
Here is how you go about:
Select your model and apply a lambert shader or any other material you would like.

Open your hypershade and add a layered texture from create menu.  Add three different images to individual file textures and then connect the out color to the layeredTexture input color. Your shading network would look like this:




Create an attribute in your global control which would be used to make texture selection. I have quickly added a texture attribute with integer value from min 0 and max 2. 0 is for texture 1, 1 is for texture 2 and 2 is for texture 3. You can have any other values or use enum type which is even more readable for the animator.
Here comes the real deal!
You use SDK to switch between textures and animate the Alpha values of the individual texture file added in the layered texture.
Basically, when you want to select the first texture, you zero out the alpha values of texture 2 and 3 in the layered texture and keep the alpha value 1 for the 1st texture.
You do the same for all other switches.
I could not SDK the alpha value using the SDK dialogue box, maya gave me an error “No object matches name: layeredTexture1.alpha”. So I wrote a small code in MEL to do this job-
   
for($i=0; $i<3; $i++)
{
    setAttr "pCube1.Texture" $i;
   
    if($i==0)
    {
        setAttr "layeredTexture1.inputs[0].alpha" 1;
        setAttr "layeredTexture1.inputs[1].alpha" 0;
        setAttr "layeredTexture1.inputs[2].alpha" 0;
    }
   
    else if($i==1)
    {
        setAttr "layeredTexture1.inputs[0].alpha" 0;
        setAttr "layeredTexture1.inputs[1].alpha" 1;
        setAttr "layeredTexture1.inputs[2].alpha" 0;
    }
    else if($i==2)
    {
        setAttr "layeredTexture1.inputs[0].alpha" 0;
        setAttr "layeredTexture1.inputs[1].alpha" 0;
        setAttr "layeredTexture1.inputs[2].alpha" 1;
    }
    setDrivenKeyframe -currentDriver "pCube1.Texture" "layeredTexture1.inputs[0].alpha";
    setDrivenKeyframe -currentDriver "pCube1.Texture" "layeredTexture1.inputs[1].alpha";
    setDrivenKeyframe -currentDriver "pCube1.Texture" "layeredTexture1.inputs[2].alpha";
   
}


 Cheers!

Wednesday, September 17, 2014

Train Rigging in Maya


Flying trains, train on hills and there are million other ways you would like to move your train. It would become really difficult to animate it manually and then attach it to a motion path. We riggers have to make the life of animators easy, because we are the saviors!!
Create a joint for every bogie and the engine as well, something like this:

 

Now create a straight path using CV curve tool, go to the options and select 3cubic. Now you can use as many CVs as you like in the curve depending on the requirement. I have used 15; you can always go back and rebuild the curve.  


Apply IK spline Handle to the joints switching off auto create curve and auto parent curve, only root on curve should be selected. Select your first joint, then the end joint and the curve we just created.
Select the IK spline handle that has just been created and increase the offset value, you will see that the train starts moving on the path curve.

 



Create clusters for each CV point on the curve with Relative off.


Create your controls for the path; I would suggest one for each cluster and then parent constraint the cluster to the controls. Now you can move the
se controls in any position and make the shape of your path in which the train will move.




You can hook the offset attribute of IK spline handle to the global control of the train using connection editor or SDK. Hide the clusters as you don’t need to see them and also template the path. You don’t want the animators to mistakenly move any of these.
 

Woohoo!! You have the train moving. You can add many other things like the train bogies rotating side to side while the train moves or cartoony smoke coming out as the train moves.