Wednesday, 21 March 2012

Learning Mel - Early Days

I love how using Mel saves me countless hours. When I think of all that time I could have saved  in the past before I knew how to do this :)
For example – setting up an Ik Fk blend for rotation and scale is a easy as...


    string $ArmNm[] = {"shld01", "elbA01", "elbB01"};
    for ($jntSw=1; $jntSw<4; $jntSw++)

    {
   orientConstraint
       -n ($prefix + "_" + $partName + "_" + ($ArmNm[($jntSw-1)]) + "_jntOri")
           ($prefix + "_" + $partName + "_" + ($ArmNm[($jntSw-1)]) + "_ik")
           ($prefix + "_" + $partName + "_" + ($ArmNm[($jntSw-1)]) + "_fk")
           ($prefix + "_" + $partName + "_" + ($ArmNm[($jntSw-1)]) + "_jntBnd");
   createNode blendColors
       -n  ($prefix + "_" + $partName + "_" + ($ArmNm[($jntSw-1)]) + "_jSBld");
   connectAttr    
           ($prefix + "_" + $partName + "_" + ($ArmNm[($jntSw-1)]) + "_ik.scaleX")
           ($prefix + "_" + $partName + "_" + ($ArmNm[($jntSw-1)]) + "_jSBld.color1R");
   connectAttr      
           ($prefix + "_" + $partName + "_" + ($ArmNm[($jntSw-1)]) + "_fk.scaleX")
           ($prefix + "_" + $partName + "_" + ($ArmNm[($jntSw-1)]) + "_jSBld.color2R");
   connectAttr
           ($prefix + "_" + $partName + "_" + ($ArmNm[($jntSw-1)]) + "_jSBld.outputR")
           ($prefix + "_" + $partName + "_" + ($ArmNm[($jntSw-1)]) + "_jntBnd.scaleX");
    }


In the example above I've given procedure arguments for $prefix (character Name), $partName (body part like "arm") and I've used the string array ($ArmNm[]) to capture the elements within $partName - in this case the shoulder joint and the two elbow joints.

 A `for loop` cycles through 3 times (<4) and matches the $armNm array containing the elements within the $partName, (-1 because arrays start with 0 in Mel), to the newly created blend nodes for scale blending and orient constraints for rotational blending. These are then connected to the bind joints.

No comments:

Post a Comment