/* NAME: dbJoystickRig.mel VERSION: 1.2 CATEGORY: Rigging FUNCTION: A script that takes 2 or 4 attributes and creates a joystick rig controller from them. USAGE: 1. Copy the dbJoystickRig.mel into your Maya Scripts directory (Usually found in "My Documents\maya\\scripts\"). 2. In the Maya Script Editor, type in "source dbJoystickRig.mel; dbJoystickRig;" AUTHOR: David Bokser E-MAIL: me@davidbokser.com WEBSITE: www.davidbokser.com VERSION HISTORY: May 25, 2006 - V1.2 - Added the ability to do a vertical stick with 2 attributes May 24, 2006 - V1.1 - Added the ability to create vertical and half vertical boxes, with either a direct connection of set driven key connection - Added the ability to create half standard controllers in the positive or negative direction. May 10, 2006 - V1.0 - Initial release */ /* // Creates the User Interface window. */ global proc dbJoystickRig() { if (`window -q -ex joystickWindow`) deleteUI -window joystickWindow; window -title "Joystick UI Creator" -w 306 -h 198 -menuBar true joystickWindow; menu -label "Help" -helpMenu true; menuItem -label "About Application..." -c ("confirmDialog -title \"About\" -messageAlign \"center\" -message \"Joystick Rig Creator\\nV 1.2\\n\\nWritten by \\nDavid Bokser\\nme@davidbokser.com\\n\\nCopyright 2006, All Rights Reserved\" -button \"Cool\" -dismissString \"Ok\";"); columnLayout; text "Type of Controller:"; rowColumnLayout -nc 2 -cw 1 150 -cw 2 150; radioCollection joystickTypeCol; radioButton -sl -label "Standard Joystick" -align "left" -w 150 -onCommand ("columnLayout -e -vis 1 standardCL; columnLayout -e -vis 0 halfStandardCL; columnLayout -e -vis 0 verticalCL; window -e -h 310 joystickWindow;") standardButton; radioButton -label "Half Standard Joystick" -align "left" -w 150 -onCommand ("columnLayout -e -vis 1 halfStandardCL; columnLayout -e -vis 0 verticalCL; columnLayout -e -vis 0 standardCL; window -e -h 266 joystickWindow;") halfStandardButton; radioButton -label "Vertical Joystick" -align "left" -w 150 -onCommand ("columnLayout -e -vis 1 verticalCL; columnLayout -e -vis 0 halfStandardCL; columnLayout -e -vis 0 standardCL; window -e -h 298 joystickWindow; if(`radioCollection -q -sl attrNumCol` == \"attrNum2\"){rowColumnLayout -e -cw 1 100 -cw 2 46 -cw 3 100 -cw 4 46 vertRCL; textField -e -vis 1 tx_vatt2; button -e -vis 1 vertBut2; button -e -label \"high\" vertBut1;} columnLayout -e -vis 1 numAttrCL;") verticalButton; radioButton -label "Half Vertical Joystick" -align "left" -w 150 -onCommand ("columnLayout -e -vis 1 verticalCL; columnLayout -e -vis 0 halfStandardCL; columnLayout -e -vis 0 standardCL; window -e -h 266 joystickWindow; columnLayout -e -vis 0 numAttrCL; rowColumnLayout -e -cw 1 150 -cw 2 50 vertRCL; textField -e -vis 0 tx_vatt2; button -e -vis 0 vertBut2; button -e -label \"set\" vertBut1;" ) halfButton; setParent ..; textField -w 297 -tx "Insert Controller Name Here" tx_ctrlName; separator -h 10 -w 297; // Standard Layout columnLayout standardCL; text -align "left" -l "Insert the 4 attributes you want for your joystick controller in the \nform of \"node.attribute\". for example, if your blendshape is \ncalled \"blendShape1\" and your attribute is called \"angryL\", \nthen type in \"blendShape1.angryL\""; rowColumnLayout -nc 4 -cw 2 46 -cw 4 46; textField -w 148 tx_att1; popupMenu; menuItem -label "Select Object" -c ("string $temp = `textField -q -tx tx_att1`; $temp = `match \"^[^\\.]*\" $temp`; select -r $temp;"); button -label "set" -c ("string $objects[] = `ls -sl`; string $channels[] = `channelBox -q -sma mainChannelBox`; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_att1; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_hatt1; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_vatt1;") ; textField -w 148 tx_att2; popupMenu; menuItem -label "Select Object" -c ("string $temp = `textField -q -tx tx_att2`; $temp = `match \"^[^\\.]*\" $temp`; select -r $temp;"); button -label "set" -c ("string $objects[] = `ls -sl`; string $channels[] = `channelBox -q -sma mainChannelBox`; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_att2; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_hatt2;") ; textField -w 148 -vis 0 tx_att6; popupMenu; menuItem -label "Select Object" -c ("string $temp = `textField -q -tx tx_att6`; $temp = `match \"^[^\\.]*\" $temp`; select -r $temp;"); button -label "set" -c ("string $objects[] = `ls -sl`; string $channels[] = `channelBox -q -sma mainChannelBox`; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_att6;") -vis 0 stanBut1; textField -w 148 -vis 0 tx_att5; popupMenu; menuItem -label "Select Object" -c ("string $temp = `textField -q -tx tx_att5`; $temp = `match \"^[^\\.]*\" $temp`; select -r $temp;"); button -label "set" -c ("string $objects[] = `ls -sl`; string $channels[] = `channelBox -q -sma mainChannelBox`; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_att5;") -vis 0 stanBut2; textField -w 148 tx_att4; popupMenu; menuItem -label "Select Object" -c ("string $temp = `textField -q -tx tx_att4`; $temp = `match \"^[^\\.]*\" $temp`; select -r $temp;"); button -label "set" -c ("string $objects[] = `ls -sl`; string $channels[] = `channelBox -q -sma mainChannelBox`; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_att4;") ; textField -w 148 tx_att3; popupMenu; menuItem -label "Select Object" -c ("string $temp = `textField -q -tx tx_att3`; $temp = `match \"^[^\\.]*\" $temp`; select -r $temp;"); button -label "set" -c ("string $objects[] = `ls -sl`; string $channels[] = `channelBox -q -sma mainChannelBox`; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_att3;") ; setParent ..; columnLayout numAttrCL; text "Number of Attributes:"; rowColumnLayout -nc 2 -cw 1 40 -cw 2 160; radioCollection attrNumCol1; radioButton -label "4" -onCommand ("window -e -h 310 joystickWindow;textField -e -vis 0 tx_att5; button -e -vis 0 stanBut1;textField -e -vis 0 tx_att6; button -e -vis 0 stanBut2;") -sl attrNum4; radioButton -label "6" -onCommand ("window -e -h 310 joystickWindow;textField -e -vis 1 tx_att5; button -e -vis 1 stanBut1;textField -e -vis 1 tx_att6; button -e -vis 1 stanBut2;") attrNum6; setParent ..; setParent ..; setParent ..; // Half Standard Layout columnLayout -vis 0 halfStandardCL; text -align "left" -l "Insert the 2 attributes you want for your joystick controller in the \nform of \"node.attribute\". for example, if your blendshape is \ncalled \"blendShape1\" and your attribute is called \"angryL\", \nthen type in \"blendShape1.angryL\""; rowColumnLayout -nc 4 -cw 2 46 -cw 4 46; textField -w 148 tx_hatt1; popupMenu; menuItem -label "Select Object" -c ("string $temp = `textField -q -tx tx_hatt1`; $temp = `match \"^[^\\.]*\" $temp`; select $temp;"); button -label "set" -c ("string $objects[] = `ls -sl`; string $channels[] = `channelBox -q -sma mainChannelBox`; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_hatt1; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_att1; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_vatt1;") ; textField -w 148 tx_hatt2; popupMenu; menuItem -label "Select Object" -c ("string $temp = `textField -q -tx tx_hatt2`; $temp = `match \"^[^\\.]*\" $temp`; select $temp;"); button -label "set" -c ("string $objects[] = `ls -sl`; string $channels[] = `channelBox -q -sma mainChannelBox`; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_hatt2; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_att2;") ; setParent ..; text "Direction:"; rowColumnLayout -nc 2 -cw 1 80 -cw 2 160; radioCollection dirTypeCol; radioButton -label "Positive" -sl dirType1; radioButton -label "Negative" dirType2; setParent ..; setParent ..; // Vertical Layout columnLayout -vis 0 verticalCL; text -align "left" -l "Insert the attribute you want for your joystick controller in the \nform of \"node.attribute\". for example, if your blendshape is \ncalled \"blendShape1\" and your attribute is called \"angryL\", \nthen type in \"blendShape1.angryL\""; rowColumnLayout -nc 4 -cw 1 150 -cw 2 50 vertRCL; textField -w 148 tx_vatt1; popupMenu; menuItem -label "Select Object" -c ("string $temp = `textField -q -tx tx_vatt1`; $temp = `match \"^[^\\.]*\" $temp`; select $temp;"); button -label "set" -c ("string $objects[] = `ls -sl`; string $channels[] = `channelBox -q -sma mainChannelBox`; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_vatt1; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_hatt1; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_att1;") vertBut1; textField -w 148 -vis 0 tx_vatt2; popupMenu; menuItem -label "Select Object" -c ("string $temp = `textField -q -tx tx_vatt2`; $temp = `match \"^[^\\.]*\" $temp`; select $temp;"); button -vis 0 -label "low" -c ("string $objects[] = `ls -sl`; string $channels[] = `channelBox -q -sma mainChannelBox`; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_hatt2; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_att2; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_vatt2;") vertBut2; setParent ..; columnLayout numAttrCL; text "Number of Attributes:"; rowColumnLayout -nc 2 -cw 1 40 -cw 2 160; radioCollection attrNumCol; radioButton -label "1" -onCommand ("rowColumnLayout -e -cw 1 150 -cw 2 50 vertRCL; textField -e -vis 0 tx_vatt2; button -e -vis 0 vertBut2; button -e -label \"set\" vertBut1;") -sl attrNum1; radioButton -label "2" -onCommand ("rowColumnLayout -e -cw 1 100 -cw 2 46 -cw 3 100 -cw 4 46 vertRCL; textField -e -vis 1 tx_vatt2; button -e -vis 1 vertBut2; button -e -label \"high\" vertBut1;") attrNum2; setParent ..; setParent ..; text "Connection Type:"; rowColumnLayout -nc 2 -cw 1 120 -cw 2 160; radioCollection keyTypeCol; radioButton -label "Direct Connection" -sl conType1; radioButton -label "SDK" conType2; setParent ..; setParent ..; separator -h 10 -w 297; button -w 297 -l "Create Joystick Controller" createButton; button -e -c "interpretJoystickController()" createButton; showWindow; window -e -h 310 -w 306 joystickWindow; } global proc interpretJoystickController() { string $joystickType = `radioCollection -q -sl joystickTypeCol`; int $type; int $conType; int $dirType = 0; int $attrNum = 1; int $attrNum1 = 1; string $conTypeSl = `radioCollection -q -sl keyTypeCol`; string $dirTypeSl = `radioCollection -q -sl dirTypeCol`; string $attrNumSl = `radioCollection -q -sl attrNumCol`; string $attrNumSl1 = `radioCollection -q -sl attrNumCol1`; string $att1 = ""; string $att2 = ""; string $att3 = ""; string $att4 = ""; string $att5 = ""; string $att6 = ""; if($attrNumSl == "attrNum2") $attrNum = 2; if($joystickType == "standardButton") { $att1 = `textField -q -tx tx_att1`; $att2 = `textField -q -tx tx_att2`; $att3 = `textField -q -tx tx_att3`; $att4 = `textField -q -tx tx_att4`; $att5 = `textField -q -tx tx_att5`; $att6 = `textField -q -tx tx_att6`; $type = 1; $conType = 0; if($attrNumSl1 == "attrNum6") $attrNum = 2; else $attrNum = 1; } else if($joystickType == "halfStandardButton") { $att1 = `textField -q -tx tx_hatt1`; $att2 = `textField -q -tx tx_hatt2`; $type = 4; } else { $att1 = `textField -q -tx tx_vatt1`; if($attrNum == 2) $att2 = `textField -q -tx tx_vatt2`; if($joystickType == "verticalButton") $type = 2; else $type = 3; } if($conTypeSl == "conType1") $conType = 1; else if($conTypeSl == "conType2") $conType = 2; if($dirTypeSl == "dirType1") $dirType = 1; else if($dirTypeSl == "dirType2") $dirType = 2; createJoystickController `textField -q -tx tx_ctrlName` $type $conType $dirType $attrNum $att1 $att2 $att3 $att4 $att5 $att6; } global proc dbJoystickRigAttach() { if (`window -q -ex joystickWindow`) deleteUI -window joystickWindow; window -title "Joystick UI Creator" -w 306 -h 198 joystickWindow; columnLayout; text -align "left" -l "Insert the 4 attributes you want for your joystick controller in the \nform of \"node.attribute\". for example, if your blendshape is \ncalled \"blendShape1\" and your attribute is called \"angryL\", \nthen type in \"blendShape1.angryL\""; rowColumnLayout -nc 4 -cw 2 46 -cw 4 46; textField -w 148 tx_att1; button -label "set" -c ("string $objects[] = `ls -sl`; string $channels[] = `channelBox -q -sma mainChannelBox`; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_att1;") ; textField -w 148 tx_att2; button -label "set" -c ("string $objects[] = `ls -sl`; string $channels[] = `channelBox -q -sma mainChannelBox`; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_att2;") ; textField -w 148 tx_att4; button -label "set" -c ("string $objects[] = `ls -sl`; string $channels[] = `channelBox -q -sma mainChannelBox`; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_att4;") ; textField -w 148 tx_att3; button -label "set" -c ("string $objects[] = `ls -sl`; string $channels[] = `channelBox -q -sma mainChannelBox`; textField -e -text ($objects[0] + \".\" + $channels[0]) tx_att3;") ; setParent ..; textFieldButtonGrp -w 297 -tx "Controller Name" -buttonLabel "Set" -bc ("string $controllerName[] = `ls -sl -l`; textFieldButtonGrp -e -text $controllerName[0] tx_ctrlName;") tx_ctrlName; button -w 297 -l "Create Joystick Controller" createButton; button -e -c "reAttachJoystickController `textFieldButtonGrp -q -tx tx_ctrlName` `textField -q -tx tx_att1` `textField -q -tx tx_att2` `textField -q -tx tx_att3` `textField -q -tx tx_att4`" createButton; showWindow; } /* // creates the Joystick Controller // takes in the name of the controller as well as 4 of the attributes that it will use in the // joystick control. // // Type 1 = Standard // Type 2 = Vertical // Type 3 = Half Vertical // Type 4 = Half Standard // // conType 1 = Direct Connection // conType 2 = SDK */ global proc createJoystickController (string $name, int $type, int $conType, int $dirType, int $attrNum, string $at1, string $at2, string $at3, string $at4, string $at5, string $at6) { string $ctrlName[] = {}; if(`objExists ($name + "_controller_box")`) error "object already exists. Change the name"; // call the createControllerSplines function and get the names of the constrollers back if($type == 4) { if($dirType == 1) $ctrlName = createControllerSplines($name, 4); else if ($dirType == 2) $ctrlName = createControllerSplines($name, 5); } else $ctrlName = createControllerSplines($name, $type); // Joystick Box if($type == 1) { // call all the createExpression functions if($at1 != "") createExpression1 $ctrlName[1] $at1; if($at2 != "") createExpression2 $ctrlName[1] $at2; if($at3 != "") createExpression3 $ctrlName[1] $at3; if($at4 != "") createExpression4 $ctrlName[1] $at4; if($attrNum == 2) { if($at5 != "") createExpression5 $ctrlName[1] $at5; if($at6 != "") createExpression6 $ctrlName[1] $at6; } } // Half Joystick Box else if($type == 4) { if ($dirType == 1) { if($at1 != "") createExpression1 $ctrlName[1] $at1; if($at2 != "") createExpression2 $ctrlName[1] $at2; } else if ($dirType == 2) { if($at1 != "") createExpression3 $ctrlName[1] $at2; if($at2 != "") createExpression4 $ctrlName[1] $at1; } } // Vertical Box else if($type == 2) { if($attrNum == 1) { if($at1 != "") { if($conType == 1) { connectAttr -f ($name + "_lever.ty") $at1; } else { setDrivenKeyframe -cd ($name + "_lever.ty") -driverValue 0 -value 0 $at1; setDrivenKeyframe -cd ($name + "_lever.ty") -driverValue 1 -value 1 $at1; setDrivenKeyframe -cd ($name + "_lever.ty") -driverValue -1 -value -1 $at1; } } } else if($attrNum == 2) { if($at1 != "") { if($conType == 1) { string $reverse = `shadingNode -asUtility multiplyDivide`; setAttr ($reverse + ".input2X") -1; string $greater = `shadingNode -asUtility condition`; setAttr ($greater + ".operation") 3; setAttr ($greater + ".colorIfFalseR") 0; string $less = `shadingNode -asUtility condition`; setAttr ($less + ".operation") 5; setAttr ($less + ".colorIfFalseR") 0; connectAttr -f ($name + "_lever.ty") ($greater + ".firstTerm"); connectAttr -f ($name + "_lever.ty") ($less + ".firstTerm"); connectAttr -f ($name + "_lever.ty") ($greater + ".colorIfTrueR"); connectAttr -f ($name + "_lever.ty") ($less + ".colorIfTrueR"); connectAttr -f ($less + ".outColorR") ($reverse + ".input1X"); connectAttr -f ($reverse + ".outputX") $at2; connectAttr -f ($greater + ".outColorR") $at1; } else { setDrivenKeyframe -cd ($name + "_lever.ty") -driverValue 0 -value 0 $at1; setDrivenKeyframe -cd ($name + "_lever.ty") -driverValue 0 -value 0 $at2; setDrivenKeyframe -cd ($name + "_lever.ty") -driverValue 1 -value 1 $at1; setDrivenKeyframe -cd ($name + "_lever.ty") -driverValue -1 -value 1 $at2; } } } } // Half Vertical Box else if($type == 3) { if($at1 != "") { if($conType == 1) { connectAttr -f ($name + "_lever.ty") $at1; } else { setDrivenKeyframe -cd ($name + "_lever.ty") -driverValue 0 -value 0 $at1; setDrivenKeyframe -cd ($name + "_lever.ty") -driverValue 1 -value 1 $at1; } } } else { error "Incorrect Type"; } } global proc reAttachJoystickController (string $name, string $at1, string $at2, string $at3, string $at4) { // call all the createExpression functions if($at1 != "") createExpression1 $name $at1; if($at2 != "") createExpression2 $name $at2; if($at3 != "") createExpression3 $name $at3; if($at4 != "") createExpression4 $name $at4; } /* // Creates the controller splines for the joystick. // Takes in the name of the controller and prefixes it to the splines. */ global proc string[] createControllerSplines (string $name, int $type) { // create the controller box string $controller = $name + "_controller_box"; if($type == 1) { // standard curve -d 1.25 -p -1.25 -1.25 0 -p -1.25 1.25 0 -p 1.25 1.25 0 -p 1.25 -1.25 0 -p -1.25 -1.25 0 -k 0 -k 1.25 -k 2 -k 3 -k 4 -n $controller; } else if ($type == 2) { // vertical curve -d 1.25 -p -.25 -1.25 0 -p -.25 1.25 0 -p .25 1.25 0 -p .25 -1.25 0 -p -.25 -1.25 0 -k 0 -k 1.25 -k 2 -k 3 -k 4 -n $controller; } else if ($type == 3) { // half vertical curve -d 1.25 -p -.25 -.25 0 -p -.25 1.25 0 -p .25 1.25 0 -p .25 -.25 0 -p -.25 -.25 0 -k 0 -k 1.25 -k 2 -k 3 -k 4 -n $controller; } else if ($type == 4) { // half standard positive curve -d 1.25 -p -1.25 -.25 0 -p -1.25 1.25 0 -p 1.25 1.25 0 -p 1.25 -.25 0 -p -1.25 -.25 0 -k 0 -k 1.25 -k 2 -k 3 -k 4 -n $controller; } else if($type == 5) { // half standard negative curve -d 1.25 -p -1.25 -1.25 0 -p -1.25 .25 0 -p 1.25 .25 0 -p 1.25 -1.25 0 -p -1.25 -1.25 0 -k 0 -k 1.25 -k 2 -k 3 -k 4 -n $controller; } else { error "Incorrect type"; } // create the lever string $lever = $name + "_lever"; circle -c 0 0 0 -nr 0 0 1 -sw 360 -r 0.25 -d 3 -ut 0 -tol 0.01 -s 8 -ch 1 -n $lever; setAttr -lock true ($controller + ".sx"); setAttr -lock true ($controller + ".sy"); setAttr -lock true ($controller + ".sz"); setAttr -keyable false ($controller + ".sx"); setAttr -keyable false ($controller + ".sy"); setAttr -keyable false ($controller + ".sz"); // lock transforms if($type == 1) { transformLimits -ty -1 1 -ety 1 1 $lever; transformLimits -tx -1 1 -etx 1 1 $lever; } else if ($type == 2) { transformLimits -ty -1 1 -ety 1 1 $lever; setAttr -lock true ($lever + ".tx"); setAttr -keyable false ($lever + ".tx"); } else if ($type == 3) { transformLimits -ty 0 1 -ety 1 1 $lever; setAttr -lock true ($lever + ".tx"); setAttr -keyable false ($lever + ".tx"); } else if($type == 4) { transformLimits -ty 0 1 -ety 1 1 $lever; transformLimits -tx -1 1 -etx 1 1 $lever; } else if($type == 5) { transformLimits -ty -1 0 -ety 1 1 $lever; transformLimits -tx -1 1 -etx 1 1 $lever; } setAttr -lock true ($lever + ".tz"); setAttr -lock true ($lever + ".rx"); setAttr -lock true ($lever + ".ry"); setAttr -lock true ($lever + ".rz"); setAttr -lock true ($lever + ".sx"); setAttr -lock true ($lever + ".sy"); setAttr -lock true ($lever + ".sz"); setAttr -keyable false ($lever + ".tz"); setAttr -keyable false ($lever + ".rx"); setAttr -keyable false ($lever + ".ry"); setAttr -keyable false ($lever + ".rz"); setAttr -keyable false ($lever + ".sx"); setAttr -keyable false ($lever + ".sy"); setAttr -keyable false ($lever + ".sz"); // Parent the lever to the controller parent $lever $controller; select $lever; // returns the names of the controllers string $names[] = {$controller, $lever}; return $names; } /* // Creates the expression for the *UPPER LEFT* quadrant of the controller // Takes in the name of the lever, the name of the lever and attribute. */ global proc createExpression1 (string $lever, string $at1) { string $exp = "if (" + $lever + ".translateX >= 0 && " + $lever + ".translateY >= 0)\r\n"; $exp += " " + $at1 + " = (1-" + $lever + ".translateX) * " + $lever + ".translateY;\r\n"; $exp += "else if (" + $lever + ".translateX < 0 && " + $lever + ".translateY >= 0)\r\n"; $exp += " " + $at1 + " = " + $lever + ".translateY;\r\n"; $exp += "else\r\n"; $exp += " " + $at1 + " = 0;\n"; expression -s $exp; } /* // Creates the expression for the *UPPER RIGHT* quadrant of the controller // Takes in the name of the lever, the name of the lever and attribute. */ global proc createExpression2 (string $lever, string $at2) { string $exp = "if (" + $lever + ".translateX <= 0 && " + $lever + ".translateY >= 0)\r\n"; $exp += " " + $at2 + " = (" + $lever + ".translateX +1) * " + $lever + ".translateY;\r\n"; $exp += "else if (" + $lever + ".translateX > 0 && " + $lever + ".translateY >= 0)\r\n"; $exp += " " + $at2 + " = " + $lever + ".translateY;\r\n"; $exp += "else\r\n" ; $exp += " " + $at2 + " = 0;\n"; // create the expression expression -s $exp; } /* // Creates the expression for the *BOTTOM RIGHT* quadrant of the controller // Takes in the name of the lever, the name of the lever and attribute. */ global proc createExpression3 (string $lever, string $at3) { string $exp = "if (" + $lever + ".translateX <= 0 && " + $lever + ".translateY < 0)\r\n"; $exp += " " + $at3 + "= (" + $lever + ".translateX +1) * (" + $lever + ".translateY * -1);\r\n"; $exp += "else if (" + $lever + ".translateX > 0 && " + $lever + ".translateY < 0)\r\n"; $exp += " " + $at3 + "= " + $lever + ".translateY * -1;\r\n"; $exp += "else\r\n"; $exp += " " + $at3 + " = 0;\n"; // create the expression expression -s $exp; } /* // Creates the expression for the *BOTTOM LEFT* quadrant of the controller // Takes in the name of the lever, the name of the lever and attribute. */ global proc createExpression4 (string $lever, string $at4) { string $exp = "if (" + $lever + ".translateX >= 0 && " + $lever + ".translateY <= 0)\r\n"; $exp += " " + $at4 + "= (1-" + $lever + ".translateX) * (" + $lever + ".translateY * -1);\r\n"; $exp += "else if (" + $lever + ".translateX < 0 && " + $lever + ".translateY <= 0)\r\n"; $exp += " " + $at4 + "= (" + $lever + ".translateY * -1);\r\n"; $exp += "else\r\n"; $exp += " " + $at4 + "= 0;\n"; // create the expression expression -s $exp; } // Expression for CENTER LEFT QUADRANT global proc createExpression5 (string $lever, string $at5) { string $exp = "if (" + $lever + ".translateX >= 0 && " + $lever + ".translateY >= 0)\r\n"; $exp += " " + $at5 + "= " + $lever + ".translateX - " + $lever + ".translateY;\r\n"; $exp += "else if (" + $lever + ".translateX >= 0 && " + $lever + ".translateY < 0)\r\n"; $exp += " " + $at5 + "= " + $lever + ".translateX + " + $lever + ".translateY;\r\n"; $exp += "else\r\n"; $exp += " " + $at5 + "= 0;\n"; // create the expression expression -s $exp; } // Expression for CENTER RIGHT QUADRANT global proc createExpression6 (string $lever, string $at6) { string $exp = "if (" + $lever + ".translateX <= 0 && " + $lever + ".translateY >= 0)\r\n"; $exp += " " + $at6 + "= (" + $lever + ".translateX * -1) - " + $lever + ".translateY;\r\n"; $exp += "else if (" + $lever + ".translateX <= 0 && " + $lever + ".translateY < 0)\r\n"; $exp += " " + $at6 + "= (" + $lever + ".translateX * -1) + " + $lever + ".translateY;\r\n"; $exp += "else\r\n"; $exp += " " + $at6 + "= 0;\n"; // create the expression expression -s $exp; } // Expression for TOP CENTER QUADRANT global proc createExpression7 (string $lever, string $at) { string $exp = "if (" + $lever + ".translateX >= 0 && " + $lever + ".translateY >= 0)\r\n"; $exp += " " + $at + "= (1 - " + $lever + ".translateX) * " + $lever + ".translateY;\r\n"; $exp += "else if (" + $lever + ".translateX <= 0 && " + $lever + ".translateY >= 0)\r\n"; $exp += " " + $at + "= (1 + " + $lever + ".translateX) * " + $lever + ".translateY;\r\n"; $exp += "else\r\n"; $exp += " " + $at + "= 0;\n"; // create the expression expression -s $exp; } // Expression for BOTTOM CENTER QUADRANT global proc createExpression8 (string $lever, string $at) { string $exp = "if (" + $lever + ".translateX >= 0 && " + $lever + ".translateY < 0)\r\n"; $exp += " " + $at + "= (1 - " + $lever + ".translateX) * -1 * " + $lever + ".translateY;\r\n"; $exp += "else if (" + $lever + ".translateX <= 0 && " + $lever + ".translateY < 0)\r\n"; $exp += " " + $at + "= (1 + " + $lever + ".translateX) * -1 * " + $lever + ".translateY;\r\n"; $exp += "else\r\n"; $exp += " " + $at + "= 0;\n"; // create the expression expression -s $exp; }