Wednesday, December 12, 2007

Getting started with MEL

Starting off with programming, be it MEL, HTML, Python, Java, whatever can be somewhat intimidating.But i'm finally finding format that works for me. For days I've been puttering around meaning to put together a MEL script to automate a leg setup that takes a simple joint chain and creates a IK/FK leg with a no-flip knee and a floating box that allows you to choose between left and right, as well as whether the leg would stretch or not.
I've been doing so much puttering that after 3 days, I was still looking at the same 50 lines of code that made up the floating box. Knowing i had over 500 more lines of code to write; of course i didn't want to start, its like looking at a blank canvas knowing you need to create an A+ masterpiece, it won't come.
So just like we were taught to sketch out drawings and paintings, i started to 'sketch' out the code.

All I really do (especially since its a macroscript that just automates function) is write down every part of the process that i need to script to make this thing happen, much like an outline for a term paper:
//Create the IK/FK switch
//Duplicate and rename the joint chains
//Create orient costraint-change interpolation style to 2
//Set driven key for ik/fk blend
//Return driver to 0
//Create the reverse foot
//Create groups and move pivots
//Set driven key for foot actions
//peel heel
//stand tip
//twist heel
//twist toe
//toe tap
//Create an if/else statement for stretchyness
//Find the end joint where the ikHandle is located.
//Find the start joint being affected by the ik handle
//Create a vector array to store the world space coordinates of the joints


Now all i have to do is go and fill in the arguments to carry out the actions, which is simple with a small macroscript like this. If you lose track or don't know what you're looking for you can always go into maya, do the process, open the script editor and just copy and paste.

//Change pole vector on RPsolver to [.1 0 0]
select ikHandle ($legSide + "LegIk")
setAttr "ikHandle1.poleVectorX" .1;
setAttr "ikHandle1.poleVectorY" 0;
setAttr "ikHandle1.poleVectorZ" 0;

//Change twist attr to 90
setAttr "LegIk.twist" 90;

//Create plus/minus average node
shadingNode -asUtility plusMinusAverage;

//connect knee attr to +/- input 1D[0]
select -r ($legSide + "footControl")

connectAttr -force "footControl.knee" plusMinusAverage.input1D[0];

//connect offset attr to +/- input 1D[1]
connectAttr -force "footControl.offset" plusMinusAverage.input1D[1];

//connect output 1D to IK twist attr
connectAttr -force plusMinusAverage.output1D | "LegIk.twist"

//change offset to 90, lock and hide
setAttr "footControl.offset" 90;
setAttr -lock true -keyable false "footControl.offset";

I'll post the entire script when I'm done, but i gotta quit procrastinating for now.

No comments: