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.

Thursday, 1 March 2012

Stretchy Ribbon Spine

Here is a test of a Mel script I wrote for a Stretchy Ribbon Spine. I created two buttons for it. The first one creates a system of locator's which can be moved to line up with the characters spine and the next creates the spine itself based on the orientation and positional information of the locators and zeros the rotational values on the joints.

  

I've still got allot to learn about organizing my scripts properly and have been reading everything I can get my hands on regarding the best methods/standard procedures..... but gees it's fun.