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.