Wednesday 23 February 2011

Today we dine in MEL

So today I hit a checkpoint with my script, and HAVE A VIDEO!

VIDEO;
Awesome, so what does it do, why is it a checkpoint etc. at the moment, all it does is move things along different axis, at random points between a user input time range. it mimics speed by changing the space between the keyframes. i'll figure out how to alter the distance automaticaly later on. It's a checkpoint because the sliders now work, the object select button works and the range is input by the user, plus the GUI looks perty, it will be rearranged to look better and the sections more logical. but other than that not a bad start.

GUI;






CODE;

proc sc_gui()

{
if (`window -exists "sc_gui"`) deleteUI "sc_gui";
window -w 150 -h 300 -t "Randomizer" -maximizeButton false -minimizeButton false sc_gui;
columnLayout;
separator;
separator;
textFieldButtonGrp -label "Object:"
-text ""
-buttonLabel "<<<"
-cw3 50 165 10
-ct3 "left" "both" "left"
-buttonCommand "sc_getObj()" selObj;
textFieldGrp -l "Start:"
-cw2 50 165 start;
textFieldGrp -l "Finish:"
-cw2 50 165 finish;
separator;
separator;
separator -style "double" -w 260;
separator;
separator;
checkBoxGrp -l "Random: "
-cw2 50 165;
separator;
separator;
floatSliderGrp -l "x "
-cw2 40 165 -min -10 -max 10 tranX;
floatSliderGrp -l "y "
-cw2 40 165 -min -10 -max 10 tranY;
floatSliderGrp -l "z "
-cw2 40 165 -min -10 -max 10 tranZ;
separator;
separator;
separator -style "double" -w 260;
separator;
separator;
button -l "Frame" -c sc_frameCount;
showWindow "sc_gui";
separator;
separator;
}
proc sc_getObj()
{
string $sel[] = (`ls -sl`);
string $firstObj = $sel[0];
textFieldButtonGrp -edit -text $firstObj selObj;
print $firstObj;
}
proc sc_frameCount()
{
int $start = (`textFieldGrp -query -text start`);
int $end = (`textFieldGrp -query -text finish`);
int $min = 1;
int $max = 10;
string $sel[] = (`select`);
string $Ty = "ty";
$currentFrame = $start;
for ($currentFrame > $start; $currentFrame < $end;)
{
int $randGen = rand($min,$max);
string $selObj = (`textFieldButtonGrp -query -text selObj`);
float $randMoveX = (`floatSliderGrp -query -value tranX`);
float $randMoveY = (`floatSliderGrp -query -value tranY`);
float $randMoveZ = (`floatSliderGrp -query -value tranZ`);
string $objAttrX = $selObj + ".translateX";
string $objAttrY = $selObj + ".translateY";
string $objAttrZ = $selObj + ".translateZ";
int $objAttrGetX = `getAttr $objAttrX`;
int $objAttrGetY = `getAttr $objAttrY`;
int $objAttrGetZ = `getAttr $objAttrZ`;
int $finalMoveX = ($objAttrGetX + $randMoveX);
int $finalMoveY = ($objAttrGetY + $randMoveY);
int $finalMoveZ = ($objAttrGetZ + $randMoveZ);
$currentFrame = ($currentFrame + $randGen);
currentTime -edit $currentFrame;
setAttr $objAttrX $finalMoveX;
setAttr $objAttrY $finalMoveY;
setAttr $objAttrZ $finalMoveZ;
print ($currentFrame + "\n");
print ($randMoveX + "\n");
print ($randMoveY + "\n");
print ($randMoveZ + "\n");
setKeyframe `textFieldButtonGrp -query -text selObj`;
}
}
sc_gui()

No comments:

Post a Comment