/*----------------------------------Updated 4-10-07----- FB Universal Slider -v0.8- by Chris "Funky Bunnies" Whitaker -------------------------------------------------------- || www.FunkyBunnies3d.com || ======================================================== -Concept: This was originally just a test-script, but basically it moves an object or component along a path to 1 or 2 other objects according to pivot. It's especially useful for aligning objects and bones or precisely moving objects for modeling or animation. -to Use: Select object/component that you want to slide Click either "Load Obj" or "Load Object" button Select Min/Max object/component Click Load Min/Load Max move slider to interpolate between Min and Max targets -applicable Min/Max selections: Vertex CV EP Curve Point Subdivision mesh point Lattice Point Particle Joint Transform node (Poly Mesh, NURBS curve, surface, SubD, Locator, etc.) -applicable Object selections: Vertex CV EP Subdivision mesh point Lattice Point Joint Transform node (Poly Mesh, NURBS curve, surface, SubD, Locator, etc.) ======================================== BUTTONS ---------------------------------------- Bake - Bake transformation into object Load Obj - same as Load Object Load Object - Loads object to be slide-ibject Load Min - Loads minimum target for slide Load Max - Loads maximum for slide Reset - Sets slider to 0 Hold Position - Use initial position of slide-object to calculate slide Snap to Path - Use ONLY min and max targets to calculate slide Edit -Reset Settings - Clears settings and resets them at starting value ========================================== ------------------------- *Note on sliding joints:| Joints are done a bit differently, instead of moving the whole hierarchy, the pivot is moved independently. After the slider is changed, the joint will reorient to default settings as to avoid incorrect rotational angle. ---------------------------------------------------------------------------------- ======================================================== -Known Bugs/ Limitations in functionality: -Only works on one object -Unexpected results may occur when using targets in a heirarchy or components of another target -annoying slider that you HAVE to use (for now) -no control for object center instead of pivot - it'll make the GUI look cluttered and is not that useful If you run into any other problems or have suggestions, feel free to contact me ========================================================================== // Contact Me: Chris@FunkyBunnies3d.com // ========================================================================== ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// This command runs the script*/ FBslider(); global proc FBslider(){ if (`window -exists FBslide` == true ) deleteUI FBslide; window -title "FB Universal Slider v.0.8" -wh 300 190 -menuBar on -mxb 0 -s 0 FBslide; menu -label "Edit" -tearOff 0; menuItem -label "Reset Settings" -c "FBslider()"; menu -label "About" -tearOff 0; menuItem -label "About the script" -c "FBSLinfoWin()"; menuItem -label "Visit my website" -c "showHelp -absolute \"http:\//www.FunkyBunnies3d.com\""; string $monkeys = `formLayout`; columnLayout -rs 5; rowLayout -nc 2 -ct1 "left" -cat 2 "left" 150; floatSliderGrp -l "-1" -el "1" -field 1 -pre 3 -cw4 25 40 150 25 -minValue -1 -maxValue 1 -value 0 -dc "FBSLslide(0);" -cc "FBSLslide(1);" Slide; button -l "Bake" -align "center" -c "FBSLloadObj(1); radioButtonGrp -e -select 1 Slidetype; floatSliderGrp -e -v 0 Slide; FBSLslide(1);"; setParent..; rowLayout -nc 3 -cat 1 "left" 20 -cw3 120 90 60; button -l "Load Min" -align "center" -ann "Load minimum target" -c "FBSLloadmin()"; button -l "Load Obj" -align "center" -c "FBSLloadObj(0)" -ann "Load object to slide"; button -l " Load Max" -align "center" -ann "Load maximum target" -c "FBSLloadmax()"; setParent..; rowLayout -nc 3 -cat 1 "left" 10 -cw3 110 90 100; textField -w 80 -ed 0 -tx "-none loaded-" -ann "Min Target" Mintxt; textField -w 70 -ed 0 -tx "-none loaded-" -ann "Object" Objtxt; textField -w 80 -ed 0 -tx "-none loaded-" -ann "Max Target" Maxtxt; setParent..; rowLayout -nc 2 -cat 1 "left" 15 -cw2 165 160; radioButtonGrp -numberOfRadioButtons 2 -cw3 40 100 100 -select 1 -cc "FBSLslide(1)" -label "" -labelArray2 "Hold Position" "Snap to path" -ann "Slide type" Slidetype; setParent..; setParent..; setParent..; button -l "Load Object" -ann "Load object to slide" -align "center" -w 105 -h 30 -c "FBSLloadObj(0)" Loadobjbut; button -l "Reset" -ann "Reset to zero" -align "center" -w 105 -h 30 -c "floatSliderGrp -e -v 0 Slide; radioButtonGrp -e -select 1 Slidetype; FBSLslide(1);" Resetbut; button -l "Close" -ann "Close window" -align "center" -w 105 -h 30 -c "deleteUI FBslide" Cancelbut; formLayout -edit -attachNone Loadobjbut "top" -attachForm Loadobjbut "left" 4 -attachForm Loadobjbut "bottom" 4 -attachPosition Loadobjbut "right" 2 33 -an Resetbut "top" -af Resetbut "bottom" 4 -ap Resetbut "right" 1 66 -ap Resetbut "left" 1 33 -attachNone Cancelbut "top" -attachPosition Cancelbut "left" 2 66 -attachForm Cancelbut "bottom" 4 -attachForm Cancelbut "right" 4 $monkeys; showWindow FBslide; } ///////////////////////////////////////////// END GUI MADNESS HERE/////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// global proc FBSLloadmin() { string $pos[] = `ls -sl -fl`; if (`objectType $pos[0]` != "transform" &&`objectType $pos[0]` != "joint") { $pos = `filterExpand -sm 9 -sm 10 -sm 12 -sm 22 -sm 28 -sm 30 -sm 31 -sm 36 -sm 46 -sm 47 -sm 39`; if ($pos[0]=="") error "Invalid selection type. Does not compute!"; } if (`size $pos` >1) warning "Only first item used for this operation"; textField -e -tx ($pos[0]) Mintxt; if (`textField -q -tx Objtxt` != "-none loaded-") FBSLslide(1); } global proc FBSLloadmax() { string $pos[] = `ls -sl -fl`; if (`objectType $pos[0]` != "transform" &&`objectType $pos[0]` != "joint") { $pos = `filterExpand -sm 9 -sm 10 -sm 12 -sm 22 -sm 28 -sm 30 -sm 31 -sm 36 -sm 46 -sm 47 -sm 39`; if ($pos[0]=="") error "Invalid selection type. Does not compute."; } if (`size $pos` >1) warning "Only first item used for this operation"; textField -e -tx ($pos[0]) Maxtxt; if (`textField -q -tx Objtxt` != "-none loaded-") FBSLslide(1); } global proc FBSLloadObj(int $bake) { string $selected[]; if ($bake == 0 ) { $selected = `ls -sl -fl`; if (`size $selected` >1) warning "Only first item used for this operation"; } else { $selected[0] = `textField -q -tx Objtxt`; } global float $PT0[]; if (`objectType $selected[0]` == "transform" ||`objectType $selected[0]` == "joint") { $PT0 = `xform -q -ws -piv $selected[0]`; } else { $selected = `filterExpand -sm 28 -sm 30 -sm 31 -sm 36 -sm 46`; if ($selected[0]=="") error "Invalid selection type. Does not compute!"; $PT0= `pointPosition $selected[0]`; } textField -e -tx ($selected[0]) Objtxt; //if not -none loaded- then-> if (`textField -q -tx Mintxt` != "-none loaded-" || `textField -q -tx Maxtxt` != "-none loaded-") FBSLslide(1); } global proc FBSLslide(int $undoable) { if (`textField -q -tx Objtxt` == "-none loaded-") { if ($undoable==1) error "You haven't loaded an object to slide, fool."; floatSliderGrp -e -v 0 Slide; } else if (`textField -q -tx Mintxt` == "-none loaded-" && `textField -q -tx Maxtxt` == "-none loaded-") { if ($undoable==1) error "You haven't loaded a Min or Max target yet"; floatSliderGrp -e -v 0 Slide; } else{ if (`textField -q -tx Mintxt` != "-none loaded-" && `textField -q -tx Objtxt` != "-none loaded-" && `textField -q -tx Maxtxt` != "-none loaded-"){} else if (`textField -q -tx Mintxt` != "-none loaded-" && `textField -q -tx Objtxt` != "-none loaded-") { if ($undoable==1) warning "no Max target loaded"; if (`floatSliderGrp -q -v Slide` >0) floatSliderGrp -e -v 0 Slide; } else if (`textField -q -tx Maxtxt` != "-none loaded-" && `textField -q -tx Objtxt` != "-none loaded-") { if ($undoable==1) warning "no Min target loaded"; if (`floatSliderGrp -q -v Slide` <0) floatSliderGrp -e -v 0 Slide; } undoInfo -swf ($undoable); string $selected = `textField -q -tx Objtxt`; string $tempmin = `textField -q -tx Mintxt`; string $tempmax = `textField -q -tx Maxtxt`; //if slide object renamed if ($selected == "-none loaded-"){} else if (!`objExists ($selected)`) { textField -e -fn "obliqueLabelFont" Objtxt; if ($undoable == 1 ) error "Sliding object was renamed or deleted"; } else textField -e -fn "plainLabelFont" Objtxt; //if Min target renamed if ($tempmin == "-none loaded-"){} else if (!`objExists ($tempmin)`) { textField -e -fn "obliqueLabelFont" Mintxt; error "Min target was renamed or deleted"; } else textField -e -fn "plainLabelFont" Mintxt; //if Max target renamed if ($tempmax == "-none loaded-"){} else if (!`objExists ($tempmax)`) { textField -e -fn "obliqueLabelFont" Maxtxt; error "Max target was renamed or deleted"; } else textField -e -fn "plainLabelFont" Maxtxt; if (`radioButtonGrp -q -select Slidetype` == 2) { FBSLSlidepath($undoable); } else { global float $PT0[]; float $PT1[]; float $PT2[]; //if no min target, don't do anything if ($tempmin == "-none loaded-"){} else if (`objectType ($tempmin)` == "transform" ||`objectType ($tempmin)` == "joint") { $PT1 = `xform -q -ws -piv $tempmin`; } else { $PT1= `pointPosition $tempmin`; } //if no max target, don't do anything if ($tempmax == "-none loaded-"){} else if (`objectType $tempmax` == "transform" ||`objectType $tempmax` == "joint") { $PT2 = `xform -q -ws -piv $tempmax`; } else { $PT2= `pointPosition $tempmax`; } float $newpositionX; float $newpositionY; float $newpositionZ; //if Slider is negative, run with PointB, if positive run with PointA if (`floatSliderGrp -q -v Slide`<0) { //newPos = Xz + Change*(Xz - Xb) $newpositionX = (($PT0[0]) +`floatSliderGrp -q -v Slide`*(($PT0[0]) - ($PT1[0]))); $newpositionY = (($PT0[1]) +`floatSliderGrp -q -v Slide`*(($PT0[1]) - ($PT1[1]))); $newpositionZ = (($PT0[2]) +`floatSliderGrp -q -v Slide`*(($PT0[2]) - ($PT1[2]))); //move to final position if (`objectType $selected` == "joint") { move -a -ws ($newpositionX) ($newpositionY) ($newpositionZ) ($selected+".rotatePivot") ($selected+".scalePivot"); //on slider change, reorient joint to default settings if ($undoable == 1) { joint -e -oj xyz -secondaryAxisOrient yup -zso ($selected); string $cursel[] = `ls -sl`; string $parent[] = `pickWalk -d up $selected`; if (`objectType $parent[0]` == "joint") joint -e -oj xyz -secondaryAxisOrient yup -zso ($parent[0]); select -r $cursel; } } else move -a -rpr ($newpositionX) ($newpositionY) ($newpositionZ) `textField -q -tx Objtxt`; } else { //newPos = Xz + Change*(Xa - Xz) $newpositionX = (($PT0[0]) +`floatSliderGrp -q -v Slide`*(($PT2[0]) - ($PT0[0]))); $newpositionY = (($PT0[1]) +`floatSliderGrp -q -v Slide`*(($PT2[1]) - ($PT0[1]))); $newpositionZ = (($PT0[2]) +`floatSliderGrp -q -v Slide`*(($PT2[2]) - ($PT0[2]))); //move to final position if (`objectType $selected` == "joint") { move -ws ($newpositionX) ($newpositionY) ($newpositionZ) ($selected+".rotatePivot") ($selected+".scalePivot"); //on slider change, reorient joint to default settings if ($undoable == 1) { joint -e -oj xyz -secondaryAxisOrient yup -zso ($selected); string $cursel[] = `ls -sl`; string $parent[] = `pickWalk -d up $selected`; if (`objectType $parent[0]` == "joint") joint -e -oj xyz -secondaryAxisOrient yup -zso ($parent[0]); select -r $cursel; } } else move -a -rpr ($newpositionX) ($newpositionY) ($newpositionZ) `textField -q -tx Objtxt`; } } //reset undo undoInfo -swf 1; } } global proc FBSLSlidepath(int $undoable) { string $selected = `textField -q -tx Objtxt`; string $tempmin = `textField -q -tx Mintxt`; string $tempmax = `textField -q -tx Maxtxt`; float $PT1[]; float $PT2[]; //if no Min target, set Min = Max if ($tempmin == "-none loaded-"){$tempmin = $tempmax;} //then find position as normal if (`objectType $tempmin` == "transform" ||`objectType $tempmin` == "joint") { $PT1 = `xform -q -ws -piv $tempmin`; } else { $PT1= `pointPosition $tempmin`; } //if no Max target, set Max = Min if ($tempmax == "-none loaded-"){ $tempmax = $tempmin;} //then find position as normal if (`objectType $tempmax` == "transform" ||`objectType $tempmax` == "joint") { $PT2 = `xform -q -ws -piv $tempmax`; } else { $PT2= `pointPosition $tempmax`; } float $newpositionX; float $newpositionY; float $newpositionZ; $newpositionX = .5*($PT1[0]+$PT2[0])+(`floatSliderGrp -q -v Slide`*(.5*($PT2[0]-$PT1[0]))); $newpositionY = .5*($PT1[1]+$PT2[1])+(`floatSliderGrp -q -v Slide`*(.5*($PT2[1]-$PT1[1]))); $newpositionZ = .5*($PT1[2]+$PT2[2])+(`floatSliderGrp -q -v Slide`*(.5*($PT2[2]-$PT1[2]))); if (`objectType $selected` == "joint") { move -ws ($newpositionX) ($newpositionY) ($newpositionZ) ($selected+".rotatePivot") ($selected+".scalePivot"); //on slider change, reorient joint to default settings if ($undoable == 1) { joint -e -oj xyz -secondaryAxisOrient yup -zso $selected; string $cursel[] = `ls -sl`; string $parent[] = `pickWalk -d up $selected`; if (`objectType $parent[0]` == "joint") joint -e -oj xyz -secondaryAxisOrient yup -zso ($parent[0]); select -r $cursel; } } else move -a -rpr ($newpositionX) ($newpositionY) ($newpositionZ) `textField -q -tx Objtxt`; undoInfo -swf 1; } global proc FBSLinfoWin() { if (`window -exists FBslinfoWin`) { deleteUI FBslinfoWin; } window -rtf 1 -s 0 -tbm 0 -t "About the script" FBslinfoWin; columnLayout -rs 5; frameLayout -bs "in" -li 45 -h 150 -w 236 -l "FB Universal Slider v.0.8" -mw 5; string $infoform = `formLayout`; text -l " Written by Chris \"Funky Bunnies\" Whitaker \n \n This script is more a test than anything else. \n Easily slide between 2 objects or components. \n \n Use: Select and load each object/point and \n use the slider to interpolate between targets."; string $FBemail = `button -l "Chris@FunkyBunnies3d.com" -w 150 -al "center" -c "showHelp -absolute \"mailto:Chris@FunkyBunnies3d.com\""`; formLayout -e -af $FBemail "bottom" 10 -af $FBemail "left" 20 -af $FBemail "right" 20 $infoform; setParent..; setParent..; rowLayout -w 250 -cat 1 "left" 70 -cal 1 "center"; button -l "Close" -w 100 -al "center" -ann "Close window" -c "deleteUI FBslinfoWin;"; showWindow FBslinfoWin; }