////////////////////////// // // Maya script file // ////////////////////////// // // Author : Lluís Llobera // (lluisllobera@hotmail.com) // // Creation date : 3/VI/2004 // UPDATE 1.1 : 17/III/2005 // // Main procedure : type "llCycleMachine" in the Command Line or Script Editor // ////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// // // This script will create a window to work on two-legged cycles, following Kyle Balda's // walk cycle method. It consists of four rows of numbered buttons, which will allow // the user to quickly change the current time (updating or not as he does so). // The buttons are colored for easily identifying each leg, plus the button representing // the current time is always white. // // UPDATE 1.1 : Now there's a "frame start" input field to allow the animators to // start their cycles at a number different from 0. // // // Enjoy!! // //////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////// // llCMAdjustWindowSize // /////////////////////////////////////////// // // Button width slider has changed and triggered this proc. // Changes the width of the buttons and then of the window // // <-- llCycleMachineExecute // /////////////////////////////////////////// global proc llCMAdjustWindowSize (float $CYCLE) { int $BUTTONWIDTH = `intSliderGrp -q -v llCMWButtonWidth` ; int $CURRENTHEIGHT = `window -q -h llCycleMachineWindow` ; int $MAXWIDTH = 340 ; // KEEP IT EVEN !!!! for ($I = 1 ; $I <= $CYCLE ; $I++) eval ("rowColumnLayout -e -cw " + $I + " " + $BUTTONWIDTH + " llCMWNumbersLayout") ; if ((($CYCLE * $BUTTONWIDTH) + 30) < $MAXWIDTH) { eval ("window -e -w " + $MAXWIDTH + " llCycleMachineWindow") ; evalEcho ("columnLayout -e -cat \"left\" " + (($MAXWIDTH / 2) - (($CYCLE*$BUTTONWIDTH)/2)-15) + " llCMWNumbersOffsetLayout") ; } else { eval ("window -e -w " + (($CYCLE * $BUTTONWIDTH) + 30) + " llCycleMachineWindow") ; eval ("columnLayout -e -cat \"left\" 0 llCMWNumbersOffsetLayout") ; } ; window -e -rtf 0 -s 1 -h $CURRENTHEIGHT llCycleMachineWindow ; eval ("columnLayout -e -cat \"left\" " + (`window -q -w llCycleMachineWindow` / 2 - 150) + " llCMWCBLayout") ; } ; // global proc llCMAdjustWindowSize /////////////////////////////////////////// // llCMTimeChanged // /////////////////////////////////////////// // // Current time has changed. // This proc is usually triggered by a scriptJob. // Checks if the current time is represented in any of the buttons. // If it is, then the button becomes white and its command is appended ";". // Checks if any button has the appended ";" - if so, restores its color // like it should be. // // <-- llCycleMachineExecute // <-- llCMChangeButtonColor // /////////////////////////////////////////// global proc llCMTimeChanged (int $CYCLE , float $STARTFRAME) { string $CHILDREN[] = `rowColumnLayout -q -ca llCMWNumbersLayout` ; float $COLOR1R = `floatFieldGrp -q -v1 llCMWColor1` ; float $COLOR1G = `floatFieldGrp -q -v2 llCMWColor1` ; float $COLOR1B = `floatFieldGrp -q -v3 llCMWColor1` ; float $COLOR2R = `floatFieldGrp -q -v1 llCMWColor2` ; float $COLOR2G = `floatFieldGrp -q -v2 llCMWColor2` ; float $COLOR2B = `floatFieldGrp -q -v3 llCMWColor2` ; float $CURRENTTIME = (`currentTime -q` - $STARTFRAME) ; // see if current time is in cycle machine float $I ; int $J = 0 ; float $MIN = (0 - $CYCLE) ; float $MAX = ($CYCLE * 3) -1 ; string $COMMAND ; string $FIRSTLETTER ; for ($I = $MIN ; $I <= $MAX ; $I++) { $COMMAND = eval ("button -q -c " + $CHILDREN[$J]) ; $FIRSTLETTER = `substring $COMMAND 1 1` ; if ($I == $CURRENTTIME) // button representing current time FOUND { // change button color eval ("button -e -bgc 1 1 1 " + $CHILDREN[$J]) ; // change button command eval ("button -e -c \";" + $COMMAND + "\" " + $CHILDREN[$J]) ; // change button visibility (for refresh) eval ("button -e -vis 0 " + $CHILDREN[$J]) ; eval ("button -e -vis 1 " + $CHILDREN[$J]) ; } else if ($FIRSTLETTER == ";") // found button was last current time { // change button color if (($I >= ($MIN) && ($I < 0)) || (($I >= $CYCLE) && ($I < ($CYCLE*2)))) eval ("button -e -bgc " + $COLOR1R + " " + $COLOR1G + " " + $COLOR1B + " " + $CHILDREN[$J]) ; if (($I >= 0) && ($I < ($CYCLE)) || (($I >= ($CYCLE*2)) && ($I <= ($MAX)))) eval ("button -e -bgc " + $COLOR2R + " " + $COLOR2G + " " + $COLOR2B + " " + $CHILDREN[$J]) ; // change button command $COMMAND = eval ("substring \"" + $COMMAND + "\" 2 " + (`size $COMMAND`)) ; eval ("button -e -c \"" + $COMMAND + "\" " + $CHILDREN[$J]) ; // change button visibility (for refresh) eval ("button -e -vis 0 " + $CHILDREN[$J]) ; eval ("button -e -vis 1 " + $CHILDREN[$J]) ; } ; // if ($FIRSTLETTER == ";") $J ++ ; } ; // for } ; // global proc llCMTimeChanged /////////////////////////////////////////// // llCMChangeButtonColor // /////////////////////////////////////////// // // Creates a colorEditor window, then changes the color // of the necessary buttons. // // // <-- llCycleMachineExecute // /////////////////////////////////////////// global proc llCMChangeButtonColor (int $BUTTON , float $CYCLE , float $STARTFRAME) { float $COLORR = eval ("floatFieldGrp -q -v1 llCMWColor" + $BUTTON) ; float $COLORG = eval ("floatFieldGrp -q -v2 llCMWColor" + $BUTTON) ; float $COLORB = eval ("floatFieldGrp -q -v3 llCMWColor" + $BUTTON) ; vector $CURRENTCOLOR = <<$COLORR,$COLORG,$COLORB>> ; string $RESULT = eval ("colorEditor -rgb " + $CURRENTCOLOR) ; string $COLORBUFFER[] ; tokenize ($RESULT, $COLORBUFFER) ; string $CHILDREN[] = `rowColumnLayout -q -ca llCMWNumbersLayout` ; if ($COLORBUFFER[3] == 1) { // change Color button eval ("button -e -bgc " + $COLORBUFFER[0] + " " + $COLORBUFFER[1] + " " + $COLORBUFFER[2] + " llCMWButtonColor" + $BUTTON) ; eval ("button -e -vis 0 llCMWButtonColor" + $BUTTON) ; eval ("button -e -vis 1 llCMWButtonColor" + $BUTTON) ; eval ("floatFieldGrp -e -v1 " + $COLORBUFFER[0] + " llCMWColor" + $BUTTON) ; eval ("floatFieldGrp -e -v2 " + $COLORBUFFER[1] + " llCMWColor" + $BUTTON) ; eval ("floatFieldGrp -e -v3 " + $COLORBUFFER[2] + " llCMWColor" + $BUTTON) ; // change rest of buttons int $J = 0 ; float $MIN = (0 - $CYCLE) ; float $MAX = ($CYCLE * 3) -1 ; for ($I = $MIN ; $I <= $MAX ; $I++) { $CHANGE = 0 ; if ($BUTTON == 1) if (($I >= ($MIN) && ($I < 0)) || (($I >= $CYCLE ) && ($I < ($CYCLE*2)))) $CHANGE = 1 ; if ($BUTTON == 2) if (($I >= 0) && ($I < $CYCLE) || (($I >= ($CYCLE*2)) && ($I <= ($MAX)))) $CHANGE = 1 ; if ($CHANGE) { eval ("button -e -bgc " + $COLORBUFFER[0] + " " + $COLORBUFFER[1] + " " + $COLORBUFFER[2] + " " + $CHILDREN[$J]) ; eval ("button -e -vis 0 " + $CHILDREN[$J]) ; eval ("button -e -vis 1 " + $CHILDREN[$J]) ; } ; // if ($CHANGE) $J ++ ; } ; // for } ; // if ($COLORBUFFER[3] == 1) llCMTimeChanged ($CYCLE , $STARTFRAME) ; } ; // global proc llCMChangeButtonColor /////////////////////////////////////////// // llCMButtonPressed // /////////////////////////////////////////// // // When a time button is pressed, the currentTime // changes, updating or not depending on the checkBoxGrp value. // // // <-- llCycleMachineExecute // /////////////////////////////////////////// global proc llCMButtonPressed (float $TIME , int $CHECK) { // if $CHECK is 2 then the button has been pressed, // otherwise this proc is called from the popupMenu // in the button and therefore the checkBox // should be ignored int $UPDATE = $CHECK ; if ($UPDATE == 2) $UPDATE = `checkBoxGrp -q -v1 llCMUpdateTimeCB`; eval ("currentTime -u " + $UPDATE + " " + $TIME) ; } ; // global proc llCMButtonPressed /////////////////////////////////////////// // llCMCreateButtons // /////////////////////////////////////////// // // Creates the numbered time buttons. // // // <-- llCycleMachineExecute // /////////////////////////////////////////// global proc llCMCreateButtons (float $CYCLE , float $STARTFRAME , int $BUTTONWIDTH) { float $I ; float $MIN = (0 - $CYCLE) ; float $MAX = ($CYCLE * 3) -1 ; string $COLORS[] = {"1 0.5 0.5" , "0.5 1 1"} ; string $CURRENTCOLOR ; for (($I = $MIN + $STARTFRAME) ; $I <= ($MAX + $STARTFRAME) ; $I++) { if (($I >= ($MIN + $STARTFRAME) && ($I < (0 + $STARTFRAME))) || (($I >= ($CYCLE + $STARTFRAME)) && ($I < (($CYCLE*2) + $STARTFRAME)))) $CURRENTCOLOR = $COLORS[0] ; else $CURRENTCOLOR = $COLORS[1] ; eval ("button -w 20 -l (" + $I + ") -bgc " + $CURRENTCOLOR + "-c (\"llCMButtonPressed(" + $I + ",2)\")") ; popupMenu ; menuItem -l ("Go to " + $I + ", update") -c ("llCMButtonPressed(" + $I + ",1)") ; menuItem -l ("Go to " + $I + ", don't update") -c ("llCMButtonPressed(" + $I + ",0)") ; } ; for ($I = 1 ; $I <= $CYCLE ; $I++) eval ("rowColumnLayout -e -cw " + $I + " " + $BUTTONWIDTH + " llCMWNumbersLayout") ; } ; // global proc llCMCreateButtons /////////////////////////////////////////// // llCycleMachineExecute // /////////////////////////////////////////// // // Creates the main window and the color-changing scriptJob. // // // <-- llCycleMachine // --> llCMCreateButtons // --> llCMButtonPressed // --> llCMChangeButtonColor // /////////////////////////////////////////// global proc llCycleMachineExecute (float $CYCLE , float $STARTFRAME) { int $BUTTONWIDTH = 40 ; string $VERSION = "1.1" ; if (`window -ex llCycleMachineWindow`) deleteUI llCycleMachineWindow ; window -title ("llCycleMachineWindow v" + $VERSION) llCycleMachineWindow ; columnLayout -adj 1 -rs 5 -co "both" 10 ; columnLayout llCMWNumbersOffsetLayout ; rowColumnLayout -nc $CYCLE llCMWNumbersLayout ; llCMCreateButtons ($CYCLE , $STARTFRAME , $BUTTONWIDTH) ; setParent .. ; setParent .. ; columnLayout llCMWCBLayout ; rowColumnLayout -nc 4 -cw 1 100 -cat 2 "left" 10 -cw 2 55 -cat 3 "left" 10 -cw 3 75 -cat 4 "left" 1 -cw 4 60 ; checkBoxGrp -l "Update Time" -v1 1 -cw 1 70 llCMUpdateTimeCB ; button -l "Color 1" -w 50 -bgc 1 0.5 0.5 -c ("llCMChangeButtonColor(1," + $CYCLE + "," + $STARTFRAME + ")") llCMWButtonColor1 ; button -l "Color 2" -w 50 -bgc 0.5 1 1 -c ("llCMChangeButtonColor(2," + $CYCLE + "," + $STARTFRAME + ")") llCMWButtonColor2 ; intSliderGrp -w 60 -adj 1 -v $BUTTONWIDTH -min 20 -max 60 -cc ("llCMAdjustWindowSize (" + $CYCLE + ")") llCMWButtonWidth ; // the following two floatFields are always unmanaged (invisible) // and bear the RGB values for color1 and color2 floatFieldGrp -numberOfFields 3 -pre 4 -m 0 -v1 1 -v2 0.5 -v3 0.5 llCMWColor1 ; floatFieldGrp -numberOfFields 3 -pre 4 -m 0 -v1 0.5 -v2 1 -v3 1 llCMWColor2 ; // adjust window size window -e -rtf 1 llCycleMachineWindow ; llCMAdjustWindowSize ($CYCLE) ; showWindow llCycleMachineWindow ; // create scriptJob scriptJob -p llCycleMachineWindow -event timeChanged ("llCMTimeChanged (" + $CYCLE + " , " + $STARTFRAME + ")") ; // color current time button llCMTimeChanged ($CYCLE , $STARTFRAME) ; } ; // global proc llCycleMachineExecute /////////////////////////////////////////// // llCycleMachineParse // /////////////////////////////////////////// // // Gets the values from the set-up window and goes on // to create the cycle window if no errors were found. // // // <-- llCycleMachine // --> llCycleMachineExecute // /////////////////////////////////////////// global proc llCycleMachineParse () { int $ERROR = 0 ; float $CYCLE = `intFieldGrp -q -v1 llCMCycleInput` ; float $STARTFRAME = `intFieldGrp -q -v1 llCMStartFrame` ; if ($CYCLE < 1) $ERROR = 1 ; switch ($ERROR) { case 0 : playbackOptions -min (0 + $STARTFRAME) -max ((($CYCLE*2)-1) + $STARTFRAME) -ast ((-$CYCLE) + $STARTFRAME) -aet ((($CYCLE*3)-1) + $STARTFRAME) ; llCycleMachineExecute $CYCLE $STARTFRAME ; deleteUI llCycleMachineStartWindow ; break ; case 1 : error ("Specify a frame cycle number greater than 0.") ; break ; } ; // switch ($ERROR) } ; // global proc llCycleMachineParse /////////////////////////////////////////// // llCycleMachine // /////////////////////////////////////////// // // MAIN PROC // // // --> llCycleMachineParse // /////////////////////////////////////////// global proc llCycleMachine () { int $WIDTH = 175 ; int $HEIGHT = 107 ; if (`window -ex llCycleMachineStartWindow`) deleteUI llCycleMachineStartWindow ; window -tlb 0 -s 1 llCycleMachineStartWindow ; columnLayout -rs 1 -cw 160 -cat "left" 10 ; separator -style "none" -h 5 ; intFieldGrp -cw 1 100 -cw 2 40 -l "Frames per step :" -v1 10 llCMCycleInput ; intFieldGrp -cw 1 100 -cw 2 40 -l "Start Frame :" -v1 0 llCMStartFrame ; columnLayout -rs 3 -adj 1 -cat "both" 40 ; button -l "GO" -w 81 -c llCycleMachineParse ; window -e -w $WIDTH -h $HEIGHT llCycleMachineStartWindow ; window -e -s 0 llCycleMachineStartWindow ; showWindow llCycleMachineStartWindow ; } ; // global proc llCycleMachine //////////////////////////////////////////////////////////////////////////////////////////////////// // // EoS llCycleMachine // ////////////////////////////////////////////////////////////////////////////////////////////////////