MAYA_MODULE_PATH=%MAYA_MODULE_PATH%;C:\Users\Krish\Documents\maya\scripts\ml_tools-master;C:\Users\Krish\Documents\maya\scripts\KR_Tools;
// Picker Maya Script
// abxPicker.mel
//
// Version 2.5.2
// Created by J. Adam Burke adam@adamburke.net
// Modified : 28 Dec 2012
// DESCRIPTION:
// abxPicker provides artists, animators, and character TDs with an intuitive interface
// for creating and using custom character control interfaces. Using drag and drop, you
// can create, position, resize, and edit buttons to select character controls.
// USAGE:
// Source script "abxPicker.mel" and run "abxPicker();"
// assign to shelf or hotkey as preferred
// ©2013 J. Adam Burke
// http://www.adamburke.net
// BUG FIXES in 2.5.2
// hardcoded namespace use on zooms fixed
// fixed pose command to work with referencing and namespacing
// fixed crash on zoom-in/out due to deleting a pop-up menu running a command to delete itself
global proc abxPicker(){
if (`window -q -ex abxPickerWindow`){
showWindow abxPickerWindow;
}
else{
string $parent = `window -t "abxPicker 2.5.2" -tlb 0 -ret abxPickerWindow`;
$panelName = "abxPickerLyt";
setParent $parent;
formLayout abxPickerWindowLyt;
$panelName = `formLayout $panelName`;
formLayout -e -af $panelName "left" 0 -af $panelName "right"0 -af $panelName "top" 0 -af $panelName "bottom" 0 abxPickerWindowLyt;
//tabLayout -e -tabLabel $panelName "Picker" $parent;
//--------------Toolbar Layout-----------------------
rowLayout -nc 6 -adj 3 -co6 0 0 2 0 0 0 -cw6 23 23 67 23 23 23 -ct6 "both" "both" "both" "both" "both" "both" -cl6 "center" "center" "right" "center" "center" "center" abxPickerToolbar;
iconTextButton -ann "New Picker Sheet" -image "fileNew.xpm" -w 23 -h 23 -command "layout -e -visible false abxPickerCharTabs;layout -e -visible true abxPickerNewForm";
iconTextButton -ann "Save Picker Sheet" -di "fileNew.xpm" -image "fileSave.xpm" -vis false -w 23 -h 23 -command "abxPickerWriteNode `tabLayout -q -st (eval(\"tabLayout -q -st abxPickerCharTabs\"))`;iconTextButton -e -vis false abxPickerSave;" abxPickerSave;
textField -ann "Character Menu" -editable false -text "None" abxPickerCharText;
popupMenu -b 1 abxPickerCharMenu;
iconTextButton -ann "Redraw Picker Sheet" -image "autoload.xpm" -w 23 -h 23 -command "abxPickerRefresh 0";
iconTextButton -ann "Dock Toggle" -image "channelLayers.png" -w 23 -h 23 -command "abxPickerDockToggle";
iconTextButton -ann "Help" -style "iconOnly" -w 23 -h 23 -image "pickOtherComp.xpm" -label "?" -command "abxPickerHelp";
setParent..;
//--------------Picker Tab Layout--------------------
tabLayout -tabsVisible false -imw 0 -imh 0 abxPickerCharTabs;
abxPickerRefresh 0;
setParent..;
//--------------Bottom Toolbar Layout-----------------
columnLayout -parent $panelName -cal "center" -cat "both" 0 -adj true abxPickerColLyt;
rowLayout -cw 1 17 -cw 2 17 -cw 3 17 -cw 4 17 -cw 5 20 -cw 6 20 -cw 7 20 -cw 8 20 -cw 9 40 -nc 9 -adj 8;
iconTextButton -style "iconOnly" -ann "Drag and Drop: Red" -dtg "0:0:.7:.4:.4" -w 16 -h 16 -bgc .7 .4 .4 -dgc "abxPickerCtrlNew";
//iconTextButton -style "textOnly" -l "+" -ann "Zoom In" -w 16 -h 16 -c "abxPickerZoom \"in\";abxPickerRefresh;";
//iconTextButton -style "textOnly" -l "-" -ann "Zoom In" -w 16 -h 16 -c "abxPickerZoom \"out\";abxPickerRefresh;";
iconTextButton -style "iconOnly" -ann "Drag and Drop: Green" -dtg "0:0:.4:.7:.4" -w 16 -h 16 -bgc .4 .7 .4 -dgc "abxPickerCtrlNew";
iconTextButton -style "iconOnly" -ann "Drag and Drop: Blue" -dtg "0:0:.4:.5:.7" -w 16 -h 16 -bgc .4 .5 .7 -dgc "abxPickerCtrlNew";
iconTextButton -style "iconOnly" -ann "Drag and Drop: Yellow" -dtg "0:0:.7:.7:.4" -w 16 -h 16 -bgc .7 .7 .4 -dgc "abxPickerCtrlNew";
iconTextButton -style "textOnly" -ann "Command: Select Current" -label "Sl" -w 19 -h 16 -bgc .5 .5 .5 -dgc "abxPickerCtrlCommand" -c "/*select*/";
iconTextButton -style "textOnly" -ann "Command: Select Current and Translate" -label "T" -w 19 -h 16 -bgc .5 .5 .5 -dgc "abxPickerCtrlCommand" -c "/*selectT*/";
iconTextButton -style "textOnly" -ann "Command: Select Current and Rotate" -label "R" -w 19 -h 16 -bgc .5 .5 .5 -dgc "abxPickerCtrlCommand" -c "/*selectR*/";
iconTextButton -style "textOnly" -l "More..." -w 16 -h 16 -c "abxPickerBuildToolbox" ;
columnLayout -w 40 -dpc "abxPickerCtrlTrash";
iconTextButton -mw 0 -mh 0 -ann "Trash: Drag ctrls here to Delete" -style "iconOnly" -image "smallTrash.xpm" -w 40 -h 17 -dpc "abxPickerCtrlTrash" abxPickerTrashBtn;
setParent..;
setParent..;
//--------------New Picker Layout -------------------
columnLayout -visible false -rs 2 -cat "both" 3 -adj true -parent $panelName abxPickerNewForm;
radioCollection;
rowLayout -adj 1 -nc 1 -cw 1 50 -cat 1 "both" 1 -cal 1 "center";
radioButton -l "Use Reference Prefix or Namespace" -onc "textField -e -en 0 -text \"\" abxPickerCharNameTxt;" abxPickerUsePrefixRB;
setParent..;
rowLayout -adj 2 -nc 2 -cw2 50 50 -ct2 "both" "both" -cl2 "center" "center" -co2 1 1;
radioButton -sl -l "Name" -onc "textField -e -en 1 abxPickerCharNameTxt;" abxPickerUseNameRB;
textField -w 10 -text "Character" abxPickerCharNameTxt;
setParent..;
//textFieldGrp -adj 2 -cw 1 50 -cw 2 10 -label "Name" -text "Character" abxPickerCharNameTxt;
textFieldGrp -adj 2 -cw 1 50 -cw 2 10 -label "Tab" -text "Main" abxPickerSubNameTxt;
textFieldButtonGrp -adj 2 -cw 1 50 -cw 2 10 -cw 3 60 -label "Image" -text "" -buttonLabel "B.." -bc "abxPickerBrowsePath `fileDialog2 -ds 2 -cap \"Choose Background Image\" -fm 1` \"\";" abxPickerImagePath;
colorSliderGrp -adj 3 -cw 1 50 -cw 2 30 -cw 3 30 -label "Color" -rgb .4 .4 .4 abxPickerBGColor;
rowLayout -adj 1 -nc 3 -cw3 10 50 50 -ct3 "both" "both" "both" -cl3 "center" "center" "center" -co3 5 5 5;
button -visible false;
button -label "OK" -c "abxPickerNewSheet;layout -e -visible true abxPickerCharTabs;layout -e -visible false abxPickerNewForm" ;
button -label "Cancel" -c "layout -e -visible true abxPickerCharTabs;layout -e -visible false abxPickerNewForm";
setParent..;
//text -al "center" -label "Tip: Leave \"Name\" field blank\n when using referencing with\n rename prefixes or namespaces";
formLayout -e
-af abxPickerToolbar "top" 0
-af abxPickerToolbar "left" 0
-af abxPickerToolbar "right" 0
-aof abxPickerToolbar "bottom" -24
-af abxPickerCharTabs "top" 24
-af abxPickerCharTabs "left" 0
-af abxPickerCharTabs "right" 0
-ap abxPickerCharTabs "bottom" 18 100
-af abxPickerNewForm "top" 24
-af abxPickerNewForm "left" 0
-af abxPickerNewForm "right" 0
-ap abxPickerNewForm "bottom" 20 100
-aof abxPickerColLyt "top" -17
-af abxPickerColLyt "left" 1
-af abxPickerColLyt "right" 1
-ap abxPickerColLyt "bottom" 1 100
$panelName;
// create script job to refresh picker window on scene loads
string $listArray[] = `scriptJob -lj`;
string $tokenBuffer[];
int $foundJob = 0;
int $jobNum =0;
for ($i=0;$i<size($listArray);$i++){
// if the script jobs are found Kill them
if (`gmatch $listArray[$i] "*abxPickerScriptJob*"`){
tokenize $listArray[$i] ":" $tokenBuffer;
$JobNum = $tokenBuffer[0];
//scriptJob -k (int($JobNum));
$foundJob = 1;
}
}
// if no script jobs were found then start new ones
if ($foundJob == 0) {
int $jobNum = `scriptJob -e "SceneOpened" "abxPickerScriptJob"`;
}
//return $panelName;
//dockControl -label "abxToybox" -fl 1 -area "left" -epo true
// -content $parent
// -allowedArea "left"
// -allowedArea "right" abxToyboxDock;
showWindow $parent;
// mac loses the drag-drop events if the buttons aren't
if (`about -os` == "mac")
abxPickerRefresh 1;
}
}
global proc abxPickerDockToggle () {
// check if parent picker window exists
if (`layout -ex abxPickerLyt`){
$parentLayout = `layout -q -parent abxPickerLyt`;
if ($parentLayout == "abxPickerWindow|abxPickerWindowLyt"){
formLayout -parent DisplayLayerUITabLayout abxPickerTabLyt;
layout -e -parent abxPickerTabLyt abxPickerLyt;
formLayout -e
-af abxPickerLyt "left" 0
-af abxPickerLyt "right"0
-af abxPickerLyt "top" 0
-af abxPickerLyt "bottom" 0
abxPickerTabLyt;
tabLayout -e -st abxPickerTabLyt DisplayLayerUITabLayout;
tabLayout -e -tl abxPickerTabLyt "Picker" DisplayLayerUITabLayout;
deleteUI abxPickerWindow;
}
else if ($parentLayout == "MayaWindow|MainChannelsLayersLayout|ChannelsLayersPaneLayout|LayerEditorForm|DisplayLayerUITabLayout|abxPickerTabLyt"){
if (!`layout -q -ex abxPickerWindowLyt`){
window -t abxPicker -tlb 0 abxPickerWindow;
formLayout abxPickerWindowLyt;
}
layout -e -parent abxPickerWindowLyt abxPickerLyt;
formLayout -e
-af abxPickerLyt "left" 0
-af abxPickerLyt "right"0
-af abxPickerLyt "top" 0
-af abxPickerLyt "bottom" 0
abxPickerWindowLyt;
deleteUI abxPickerTabLyt;
showWindow abxPickerWindow;
if (`about -os` == "mac")
abxPickerRefresh 1;
}
}
// get window children layouts
// parent children window layout to the DisplayLayerUITabLayout
}
global proc abxPickerZoom (string $mode){
// get visible picker node
$currentChar = `tabLayout -q -st abxPickerCharTabs`;
string $currentSubTabLayout = `tabLayout -q -st $currentChar`;
//if namespace is in use we need to substitute
string $currentNodeLyt = $currentSubTabLayout;
//$currentNodeLyt = substituteAllString($currentSubTabLayout,"_",":");
int $subStrEnd = (size($currentNodeLyt)-6);
string $currentNode = (substring($currentNodeLyt, 1,$subStrEnd)+"_PIKR");
if (!`objExists $currentNode`){
$currentNodeLyt = substituteAllString($currentSubTabLayout,"_",":");
int $subStrEnd = (size($currentNodeLyt)-6);
$currentNode = (substring($currentNodeLyt, 1,$subStrEnd)+"_PIKR");
}
//print ("CurrentNode="+$currentNode+"\n");
if (`attributeExists "pickerScale" $currentNode`){
float $scaleFactor = `getAttr ($currentNode + ".pickerScale")`;
if ($mode == "in"){
$scaleFactor = $scaleFactor + 0.25;
setAttr ($currentNode + ".pickerScale") $scaleFactor;
}
else if ($mode == "out"){
$scaleFactor = $scaleFactor - 0.25;
if ($scaleFactor > 0){
setAttr ($currentNode + ".pickerScale") $scaleFactor;
}
}
// get the current layout and resize the controls
//string $buttons[] = `tabLayout -q -ca $currentSubTabLayout`;
//int $i = 0;
//for ($i=0;$i<size($buttons);$i++){
// formLayout -e
//}
}
else {
warning ("abxPicker Version 1.0 Node detected. Please update or re-save PIKR layout\n");
}
}
global proc string[] abxPickerCtrlDrag(string $dragControl, int $x, int $y, int $mods){
string $msg[] = {"move", $x, $y, $mods};
return $msg;
}
global proc string[] abxPickerCtrlNew(string $dragControl, int $x, int $y, int $mods){
string $msg[] = {"new", $x, $y, $mods};
return $msg;
}
global proc string[] abxPickerCtrlColor(string $dragControl, int $x, int $y, int $mods){
string $msg[] = {"color", $x, $y, $mods};
return $msg;
}
global proc string[] abxPickerCtrlImage(string $dragControl, int $x, int $y, int $mods){
string $msg[] = {"image", $x, $y, $mods};
return $msg;
}
global proc string[] abxPickerCtrlCommand(string $dragControl, int $x, int $y, int $mods){
string $msg[] = {"command", $x, $y, $mods};
return $msg;
}
global proc string[] abxPickerCtrlScript(string $dragControl, int $x, int $y, int $mods){
$textControl = `iconTextButton -q -dtg $dragControl`;
iconTextButton -e -c `scrollField -q -text $textControl` $dragControl;
string $msg[] = {"command", $x, $y, $mods};
return $msg;
}
global proc string[] abxPickerCtrlLabel(string $dragControl, int $x, int $y, int $mods){
string $msg[] = {"label", $x, $y, $mods};
return $msg;
}
global proc int abxPickerCtrlTrash(string $dragControl, string $dropControl, string $msgs[], int $x, int $y, int $type){
print ("drag="+$dragControl+" drop="+$dropControl+" xy="+$x+":"+$y+" type="+$type+"\n");
if ($msgs[0] == "move")
print ("Removing "+$dragControl+"\n");
// probably have to wait for this callback to end before deleting the control in 2011 otherwise it crashes
//eval("deleteUI -control "+$dragControl);
iconTextButton -e -vis true abxPickerSave;
string $formName = `control -q -p $dragControl`;
print ($formName);
//formLayout -e -ap $dragControl "top" 0 0 -ap $dragControl "left" 0 0 -ap $dragControl "bottom" 1 0 -ap$dragControl "right" 1 0 $formName;
//iconTextButton -e -dtg ("0:0:1:1:0") -w 1 -h 1 $dragControl;
control -e -enable 0 -visible 0 $dragControl;
return 2;
}
//-----------------------------------------------------------------------
// form layout drop callback: handles various objects drop events
global proc abxPickerCtrlDrop(string $dragControl, string $dropControl, string $msgs[], int $x, int $y, int $type){
iconTextButton -e -vis true abxPickerSave;
string $op = $msgs[0];
int $mods = $msgs[3];
int $startX = $msgs[1];
int $startY = $msgs[2];
int $inherit = 1;
int $modifiers = `getModifiers`;
if ($modifiers % 2)
$mods = 1;
if ($modifiers / 4 % 2)
$mods = 2;
if ($modifiers / 8 % 2)
$mods = 3;
if ($modifiers / 16 % 2)
$mods = 4;
string $ctrlData = `iconTextButton -q -dtg $dragControl`;
string $tokenBuffer[];
tokenize $ctrlData ":" $tokenBuffer;
//if (`about -os` == "mac"){
// if ($mods == 1) $mods = 2;
//}
if ($op == "move"){
switch ($mods){
case 0:
//print ("XPos="+$x+" YPos="+$y+"\n");
int $ctrlWidth = `control -q -w $dragControl`;
int $ctrlHeight = `control -q -h $dragControl`;
int $ctrlLeftPos = ($x-$startX);
int $ctrlTopPos = ($y-$startY);
int $ctrlRightPos = (-1*(($x-$startX)+$ctrlWidth));
int $ctrlBottomPos = (-1*(($y-$startY)+$ctrlHeight));
iconTextButton -e -dtg ($ctrlLeftPos+":"+$ctrlTopPos+":"+$tokenBuffer[2]+":"+$tokenBuffer[3]+":"+$tokenBuffer[4]) $dragControl;
//print ("Button "+$dragControl+" Pos:"+$ctrlLeftPos+":"+$ctrlTopPos+":"+$ctrlRightPos+":"+$ctrlBottomPos+"\n");
formLayout -e
-ap $dragControl "left" $ctrlLeftPos 0
-ap $dragControl "top" $ctrlTopPos 0
-ap $dragControl "right" $ctrlRightPos 0
-ap $dragControl "bottom" $ctrlBottomPos 0
$dropControl;
break;
// duplicate button
case 1:
$op = "new";
break;
//resize bottom right corner
case 2:
//print ("XPos="+$x+" YPos="+$y+"\n");
int $ctrlLeftPos = $tokenBuffer[0];
int $ctrlTopPos = $tokenBuffer[1];
int $ctrlRightPos = (-1*$x);
int $ctrlBottomPos = (-1*$y);
//print ($x+" "+$ctrlLeftPos+" "+$y+" "+$ctrlTopPos+"\n");
if ($x < $ctrlLeftPos+8)
$ctrlRightPos = (-1*($ctrlLeftPos+8));
if ($y < $ctrlTopPos+8)
$ctrlBottomPos = (-1*($ctrlTopPos+8));
//print ("Button "+$dragControl+"Pos:"+$ctrlLeftPos+":"+$ctrlTopPos+":"+$ctrlRightPos+":"+$ctrlBottomPos+"\n");
iconTextButton -e -w (($ctrlRightPos*-1)-$ctrlLeftPos) -h (($ctrlBottomPos*-1)-$ctrlTopPos) $dragControl;
formLayout -e
-ap $dragControl "right" $ctrlRightPos 0
-ap $dragControl "bottom" $ctrlBottomPos 0
$dropControl;
break;
}
}
if ($op == "color"){
string $colorControl = abxDropOnButton($dropControl,$x,$y);
if ($colorControl != ""){
if (float($tokenBuffer[2]) < 0) eval("iconTextButton -e -ebg 0 "+$colorControl);
else eval("iconTextButton -e -bgc "+$tokenBuffer[2]+" "+$tokenBuffer[3]+" "+$tokenBuffer[4]+" "+$colorControl);
string $colorControlLabel = `iconTextButton -q -dtg $colorControl`;
string $colorTBuffer[];
tokenize $colorControlLabel ":" $colorTBuffer;
iconTextButton -e -dtg ($colorTBuffer[0]+":"+$colorTBuffer[1]+":"+$tokenBuffer[2]+":"+$tokenBuffer[3]+":"+$tokenBuffer[4]) $colorControl;
}
else {
$inherit = 0;
$op = "new";
}
}
if ($op == "command"){
string $colorControl = abxDropOnButton($dropControl,$x,$y);
if ($colorControl != ""){
string $command = `iconTextButton -q -c $dragControl`;
if ($command == "/*select*/"){
$slNodes = `ls -sl`;
$cmd = "\"";
for ($each in $slNodes)
$cmd = $cmd + " " + $each;
iconTextButton -e -c ("global string $pickrPrefix=\"\";abxPickerSelect "+$cmd+"\"") $colorControl;
print ("Command Changed\n");
}
else if ($command == "/*selectT*/"){
$slNodes = `ls -sl`;
$cmd = "\"";
for ($each in $slNodes)
$cmd = $cmd + " " + $each;
iconTextButton -e -c ("global string $pickrPrefix=\"\";abxPickerSelect "+$cmd+"\";setToolTo moveSuperContext") $colorControl;
print ("Command Changed\n");
}
else if ($command == "/*selectR*/"){
$slNodes = `ls -sl`;
$cmd = "\"";
for ($each in $slNodes)
$cmd = $cmd + " " + $each;
iconTextButton -e -c ("global string $pickrPrefix=\"\";abxPickerSelect "+$cmd+"\";setToolTo RotateSuperContext") $colorControl;
print ("Command Changed\n");
}
else if ($command == "/*key*/"){
$slNodes = `ls -sl`;
$cmd = "\"";
for ($each in $slNodes)
$cmd = $cmd + " " + $each;
iconTextButton -e -c ("global string $pickrPrefix=\"\";abxPickerKey "+$cmd+"\"") $colorControl;
print ("Command Changed\n");
}
else if ($command == "/*selectS*/"){
$slNodes = `ls -sl`;
$cmd = "\"";
for ($each in $slNodes)
$cmd = $cmd + " " + $each;
iconTextButton -e -c ("global string $pickrPrefix=\"\";abxPickerSelect "+$cmd+"\";setToolTo scaleSuperContext") $colorControl;
print ("Command Changed\n");
}
else if ($command == "/*selectM*/"){
$slNodes = `ls -sl`;
$cmd = "\"";
for ($each in $slNodes)
$cmd = $cmd + " " + $each;
iconTextButton -e -c ("global string $pickrPrefix=\"\";abxPickerSelect "+$cmd+"\";setToolTo ShowManips") $colorControl;
print ("Command Changed\n");
}
else if ($command == "/*toggle*/"){
string $slNodes[] = `ls -sl`;
string $selectedChnl[] = `channelBox -q -sma mainChannelBox`;
if(size($selectedChnl) != 0 && size($slNodes) != 0){
$cmd = "\"";
for ($each in $slNodes){
$cmd = $cmd + " " + $each;
}
$attrs = "\"";
for ($each in $selectedChnl){
$attrs = $attrs + " " + $each;
}
iconTextButton -e -c ("global string $pickrPrefix=\"\";abxPickerToggle "+$cmd+"\" "+$attrs+"\"") $colorControl;
}
}
else if ($command == "/*pose*/"){
string $slNodes[] = `ls -sl`;
string $nodes = "";
string $vals = "";
global string $pickrPrefix;
for ($each in $slNodes){
string $keyableAttrs[] = `listAnimatable $each`;
for ($every in $keyableAttrs){
$val = `getAttr ($every)`;
if ($vals != "") $vals += ",";
$vals += $val;
// if node dag name already has picker prefix then remove it
while (`gmatch $every ("*"+$pickrPrefix+"*")`){
string $regularExpr = ($pickrPrefix);
string $newName = `substitute $regularExpr $every ""`;
$every = $newName;
}
if ($nodes != "") $nodes += ",";
$nodes += $every;
//$cmd = ($cmd+"setAttr "+$every+" "+$val+";");
}
print ("abxPickerPose \""+$nodes+"\" \""+$vals+"\";\n");
iconTextButton -e -c ("global string $pickrPrefix=\""+$pickrPrefix+"\";abxPickerPose \""+$nodes+"\" \""+$vals+"\";") $colorControl;
}
}
else if ($command == "/*isolate*/"){
$slNodes = `ls -sl`;
$cmd = "";
for ($each in $slNodes)
$cmd = $cmd + " " + $each;
iconTextButton -e -c ("global string $pickrPrefix=\"\";abxPickerIsolate \""+$cmd+"\";") $colorControl;
print ("Command Changed\n");
}
else {
iconTextButton -e -c ("global string $pickrPrefix=\"\";"+$command) $colorControl;
}
}
}
if ($op == "label"){
string $colorControl = abxDropOnButton($dropControl,$x,$y);
if ($colorControl != ""){
string $label = `iconTextButton -q -l $dragControl`;
iconTextButton -e -l $label $colorControl;
iconTextButton -e -style "textOnly" $colorControl;
}
}
if ($op == "image"){
string $colorControl = abxDropOnButton($dropControl,$x,$y);
if ($colorControl != ""){
string $image = `iconTextButton -q -image $dragControl`;
iconTextButton -e -image $image -style "iconOnly" $colorControl;
}
else {
$op = "new";
}
}
if ($op == "new"){
setParent $dropControl;
int $ctrlWidth = 16;
int $ctrlHeight = 16;
string $image = `iconTextButton -q -image $dragControl`;
string $data = `iconTextButton -q -dtg $dragControl`;
string $label = "";
if ($inherit == 1){
$ctrlWidth = `control -q -w $dragControl`;
$ctrlHeight = `control -q -h $dragControl`;
$label = `iconTextButton -q -l $dragControl`;
}
string $tokenBuffer[];
tokenize $data ":" $tokenBuffer;
$slNodes = `ls -sl`;
$cmd = "\"";
for ($each in $slNodes)
$cmd = $cmd + " " + $each;
$newCtrl = abxPickerNewButton(($x-($ctrlWidth/2)),($y-($ctrlHeight/2)),$ctrlWidth,$ctrlHeight,$tokenBuffer[2],$tokenBuffer[3],$tokenBuffer[4],$image,("global string $pickrPrefix=\"\";abxPickerSelect "+$cmd+"\""),$label);
control -e -h $ctrlHeight -w $ctrlWidth $newCtrl;
int $newCtrlWidth = `control -q -w $newCtrl`;
int $newCtrlHeight = `control -q -h $newCtrl`;
//print ("Button "+$newCtrl+"Pos:"+$ctrlHeight+":"+$ctrlWidth+" From:"+$dragControl+"\n");
formLayout -e
-ap $newCtrl "left" ($x-($ctrlWidth/2)) 0
-ap $newCtrl "top" ($y-($ctrlHeight/2)) 0
-ap $newCtrl "right" (-1*(($x-($ctrlWidth/2))+$ctrlWidth)) 0
-ap $newCtrl "bottom" (-1*(($y-($ctrlHeight/2))+$ctrlHeight)) 0
$dropControl;
}
}
//------------------------------------------------------------------------
// returns the name of the button if any the drop was over
global proc string abxDropOnButton(string $picker, int $x, int $y) {
int $buttonCount = `layout -q -nch $picker`;
string $uiName[] = `layout -q -ca $picker`;
string $pickerData = `layout -q -dtg $picker`;
for ($i=1;$i<$buttonCount;$i++){
string $data = `iconTextButton -q -dtg $uiName[$i]`;
int $width = `control -q -width $uiName[$i]`;
int $height = `control -q -height $uiName[$i]`;
string $dataBuffer[];
tokenize $data ":" $dataBuffer;
int $leftPos = $dataBuffer[0];
int $topPos = $dataBuffer[1];
float $red = $dataBuffer[2];
float $blue = $dataBuffer[3];
float $green = $dataBuffer[4];
if ($x>=$leftPos && $y>=$topPos && $x<=($leftPos+$width) && $y<=($topPos+$height)){
//print ($x+":"+$y+":::"+$leftPos+","+$topPos+","+($leftPos+$width)+","+($topPos+$height)+"\n");
//print ($uiName[$i]+"\n");
// flashes UI Color;
//iconTextButton -e -bgc 1 1 1 $uiName[$i];
//iconTextButton -e -bgc $red $green $blue $uiName[$i];
return $uiName[$i];
}
}
return "";
}
//------------------------------------------------------------------------
//sets the position of the button using attach position commands to the form layout
global proc abxPickerSetPos(string $parent, string $control, int $x, int $y,int $width, int $height){
int $rightPos = ($x + $width)*-1;
int $bottomPos = ($y + $height)*-1;
int $parentWidth = `layout -q -w $parent`;
int $parentHeight = `layout -q -h $parent`;
//print ("Button Pos:"+$rightPos+":"+$bottomPos+":"+$parentWidth+":"+$parentHeight+"\n");
formLayout -e
-ap $control "left" $x 0
-ap $control "top" $y 0
-ap $control "right" $rightPos 0
-ap $control "bottom" $bottomPos 0
$parent;
}
//--------------------------------------------------------------------------
// creates a new button and encodes the position/color data into the label
global proc string abxPickerNewButton(int $ctrlX, int $ctrlY, int $ctrlWidth, int $ctrlHeight, float $bgr, float $bgg, float $bgb, string $image,string $command, string $label){
// stores position and color data so it can be queried
$data = ($ctrlX+":"+$ctrlY+":"+$bgr+":"+$bgg+":"+$bgb);
string $newCtrl;
//string $newCtrl = `iconTextButton -mh 0 -mw 0 -style "iconOnly" -l $label -dtg $data -w $ctrlWidth -h $ctrlHeight -bgc $bgr $bgg $bgb -dgc "abxPickerCtrlDrag" -image $image -c $command`;
if ($image== ""){
if ($bgr>=0){
$newCtrl = `iconTextButton -mh 0 -mw 0 -style "textOnly" -l $label -dtg $data -w $ctrlWidth -h $ctrlHeight -bgc $bgr $bgg $bgb -dgc "abxPickerCtrlDrag" -c $command`;
}
else {
$newCtrl = `iconTextButton -mh 0 -mw 0 -style "textOnly" -l $label -dtg $data -w $ctrlWidth -h $ctrlHeight -dgc "abxPickerCtrlDrag" -c $command`;
}
}
else {
if ($bgr>=0){
$newCtrl = `iconTextButton -mh 0 -mw 0 -style "iconOnly" -image $image -dtg $data -w $ctrlWidth -h $ctrlHeight -bgc $bgr $bgg $bgb -dgc "abxPickerCtrlDrag" -c $command`;
}
else {
$newCtrl = `iconTextButton -mh 0 -mw 0 -style "iconOnly" -image $image -dtg $data -w $ctrlWidth -h $ctrlHeight -dgc "abxPickerCtrlDrag" -c $command`;
}
}
//popupMenu -button 3 -parent $newCtrl;
//menuItem -label "Label...";
//menuItem -label "Color...";
//menuItem -label "Image...";
//menuItem -label "Command...";
//menuItem -label "Dimensions...";
//menuItem -d true;
//menuItem -label "Delete";
return $newCtrl;
}
// because image controls don't auto detect their dimensions in 2011 this will get the image size by creating a symbol button
global proc int[] abxPickerGetImageSize (string $imagePath){
window abxImageTempWindow;
columnLayout;
symbolButton -vis 1 -image $imagePath tempSB;
showWindow abxImageTempWindow;
window -e -tlc -2000 -2000 abxImageTempWindow;
int $ih = `symbolButton -q -height tempSB`;
int $iw = `symbolButton -q -width tempSB`;
deleteUI -window abxImageTempWindow;
//print ("Height:"+$ih+" Width:"+$iw+"\n");
return {$iw,$ih};
}
//########################////
//-------------------------------------------------------------------------
// shows the new form and creates a blank layout and node
global proc abxPickerNewSheet () {
global string $pickrPrefix;
string $characterName = `textField -q -text abxPickerCharNameTxt`;
string $characterName2 = "";
if ($characterName != "")
$characterName2 = ($characterName + "_");
string $subCharName = `textFieldGrp -q -text abxPickerSubNameTxt`;
string $bgImage = `textFieldButtonGrp -q -text abxPickerImagePath`;
$bgImage = `workspace -en $bgImage`;
float $bgColor[] = `colorSliderGrp -q -rgb abxPickerBGColor`;
string $bgPic;
if (!`tabLayout -q -ex ($characterName+"PkrLyt")`){
tabLayout -parent abxPickerCharTabs ($characterName+"PkrLyt");
//menuItem -parent "abxPickerCharMenu" -label $characterName -c ("tabLayout -e -st "+$characterName+"PkrLyt abxPickerCharTabs;textField -e -text "+$characterName+" abxPickerCharText");
}
if ($characterName == "")
formLayout -parent ($characterName+"PkrLyt") -dtg (" |"+$subCharName+"|"+$bgColor[0]+"|"+$bgColor[1]+"|"+$bgColor[1]) -bgc $bgColor[0] $bgColor[1] $bgColor[2] -dpc "abxPickerCtrlDrop" ($characterName2+$subCharName+"PkrLyt");
else
formLayout -parent ($characterName+"PkrLyt") -dtg ($characterName2+"|"+$subCharName+"|"+$bgColor[0]+"|"+$bgColor[1]+"|"+$bgColor[1]) -bgc $bgColor[0] $bgColor[1] $bgColor[2] -dpc "abxPickerCtrlDrop" ($characterName2+$subCharName+"PkrLyt");
if (`filetest -f $bgImage`){
int $imageDim[] = `abxPickerGetImageSize $bgImage`;
setParent ($characterName2+$subCharName+"PkrLyt");
if (`about -os` == "mac")
$bgPic = `symbolButton -parent ($characterName2+$subCharName+"PkrLyt") -image $bgImage -w $imageDim[0] -h $imageDim[1]`;
else
$bgPic = `image -parent ($characterName2+$subCharName+"PkrLyt") -image $bgImage -w $imageDim[0] -h $imageDim[1]`;
}
else {
if (`about -os` == "mac")
$bgPic = `symbolButton -visible false -bgc $bgColor[0] $bgColor[1] $bgColor[2]`;
else
$bgPic = `image -visible false -bgc $bgColor[0] $bgColor[1] $bgColor[2]`;
}
popupMenu -button 3 -parent ($characterName2+$subCharName+"PkrLyt");
menuItem -label "BG Image..." -c abxPickerSetBGImage;
menuItem -label "Zoom In" -c "abxPickerZoom \"in\";evalDeferred(\"abxPickerRefresh 0\");" ;
menuItem -label "Zoom Out" -c "abxPickerZoom \"out\";evalDeferred(\"abxPickerRefresh 0\");";
tabLayout -e -tabLabel ($characterName2+$subCharName+"PkrLyt") $subCharName ($characterName+"PkrLyt");
formLayout -e
-af $bgPic "top" 0
-af $bgPic "left" 0
-an $bgPic "right"
-an $bgPic "bottom"
($characterName2+$subCharName+"PkrLyt");
setParent ..;
$pickrPrefix = "";
if ($characterName == ""){
abxPickerNewNode ($characterName2+$subCharName+"_PIKR") $bgImage ($bgColor[0]+":"+$bgColor[1]+":"+$bgColor[1]) 1 0 1;
}
else{
abxPickerNewNode ($characterName2+$subCharName+"_PIKR") $bgImage ($bgColor[0]+":"+$bgColor[1]+":"+$bgColor[1]) 0 0 1;
}
if ($characterName != "")
menuItem -parent "abxPickerCharMenu" -label $characterName -c ("abxPickerMenuCmd \""+$characterName+"\"");
else
menuItem -parent "abxPickerCharMenu" -label "*Prefix*" -c ("abxPickerMenuCmd \""+$characterName+"\"");
abxPickerMenuCmd $characterName;
//textField -e -text $characterName abxPickerCharText;
//tabLayout -e -st ($characterName2+$subCharName+"PkrLyt") ($characterName+"PkrLyt");
//tabLayout -e -st ($characterName+"PkrLyt") abxPickerCharTabs;
}
//-------------------------------------------------------------------------
// deletes all current picker layouts and redraws them from the saved nodes
global proc abxPickerRefresh (int $force) {
string $pickerNodes[] = `ls "*_PIKR"`;
string $loadedSheets[];
string $lastChar;
string $lastTab = "";
string $charName;
string $charName2;
string $subName;
string $tokenBuffer[];
$pickerNodes = stringArrayCatenate($pickerNodes,`ls "*:*_PIKR"`);
string $loseUnsaved = "Discard Changes";
if (`iconTextButton -q -vis abxPickerSave` == 1 && $force == 0){
$loseUnsaved = `confirmDialog -title "abxPicker: Unsaved Layout Edits" -message "Changes to abxPicker layouts have not been saved!" -button "Discard Changes" -button "Save Changes" -button "Abort Refresh" -dismissString "Abort Refresh" -cancelButton "Abort Refresh"`;
}
if ($loseUnsaved == "Save Changes"){
abxPickerWriteNode `tabLayout -q -st (eval("tabLayout -q -st abxPickerCharTabs"))`;
iconTextButton -e -vis false abxPickerSave;
}
if ($loseUnsaved != "Abort Refresh"){
if (size($pickerNodes) > 0){
if (`tabLayout -q -ex abxPickerCharTabs`){
$loadedSheets = `tabLayout -q -ca abxPickerCharTabs`;
$lastChar = `textField -q -text abxPickerCharText`;
if ($lastChar != "None" && $lastChar != "*Prefix*"){
$lastTab = `tabLayout -q -st ($lastChar+"PkrLyt")`;
}
}
}
// hides all pickersheets, deletes picker sheets and character menu items.
tabLayout -e -visible false abxPickerCharTabs;
textField -e -text "None" abxPickerCharText;
for ($each in $loadedSheets)
deleteUI -layout $each;
popupMenu -e -dai abxPickerCharMenu;
if (size($pickerNodes) > 0){
setParent abxPickerCharTabs;
for ($each in $pickerNodes){
$charName="";
tokenize $each ":" $tokenBuffer;
if (size($tokenBuffer) < 2){
tokenize $each "_" $tokenBuffer;
if (size($tokenBuffer) >= 3){
$charName = ($tokenBuffer[0]);
for ($i=1;$i<size($tokenBuffer)-2;$i++)
$charName = ($charName + $tokenBuffer[$i]);
}
}
else{
$charName = $tokenBuffer[0];
}
if (!`tabLayout -q -ex ($charName+"PkrLyt")`){
tabLayout -parent abxPickerCharTabs ($charName+"PkrLyt");
if ($charName != "")
menuItem -parent "abxPickerCharMenu" -label $charName -c ("abxPickerMenuCmd \""+$charName+"\"");
else
menuItem -parent "abxPickerCharMenu" -label "*Prefix*" -c ("abxPickerMenuCmd \""+$charName+"\"");
}
abxPickerMenuCmd $charName;
}
}
tabLayout -e -visible true abxPickerCharTabs;
if (`tabLayout -exists ($lastChar+"PkrLyt")`){
tabLayout -e -st ($lastChar+"PkrLyt") abxPickerCharTabs;
textField -e -text $lastChar abxPickerCharText;
if ($lastTab != "" && $lastChar != "None"){
tabLayout -e -st $lastTab ($lastChar+"PkrLyt");
}
}
iconTextButton -e -vis 0 abxPickerSave;
}
}
//----------------------------------------------------------------------
// creates a new node and adds the custom attrs to store the picker data
global proc int abxPickerNewNode (string $nodeName, string $bgImage, string $bgColor, int $charPrefix, int $mirrorPicker,float $pickerScale){
if (objExists($nodeName)){
warning "Character and Sub Character already exists. Aborting";
return 0;
}
createNode -name $nodeName "geometryVarGroup";
addAttr -longName "bgImage" -dt "string";
setAttr ($nodeName+".bgImage") -type "string" $bgImage;
addAttr -longName "bgColor" -dt "string";
setAttr ($nodeName+".bgColor") -type "string" $bgColor;
addAttr -longName "count" -at "long";
addAttr -longName "data" -dt "stringArray";
addAttr -longName "width" -dt "Int32Array";
addAttr -longName "height" -dt "Int32Array";
addAttr -longName "overlay" -dt "stringArray";
addAttr -longName "command" -dt "stringArray";
addAttr -longName "image" -dt "stringArray";
addAttr -longName "label" -dt "stringArray";
addAttr -longName "charPrefix" -at bool;
setAttr ($nodeName+".charPrefix") $charPrefix;
addAttr -longName "mirrorPicker" -at bool;
setAttr ($nodeName+".mirrorPicker") $mirrorPicker;
addAttr -longName "pickerScale" -at "float";
setAttr ($nodeName+".pickerScale") $pickerScale;
return 1;
}
//-----------------------------------------------------------------------
// reads the picker data from a node and draws the picker
global proc abxPickerReadNode (string $node) {
// declarations
string $tokenBuffer[];
string $tokenBuffer2[];
string $tokenBufferNS[];
string $bgColorBuffer[];
string $bgPic;
string $charName = "";
string $charName2 = "";
string $subName = "";
// global prefix variable for passing to abxPickerSelect
global string $pickrPrefix;
// load the node into memory
int $mirrorPicker = 0;
float $pickerScale = 1;
if (`attributeExists mirroPicker $node`)
$mirrorPicker = `getAttr ($node+".mirrorPicker")`;
if (`attributeExists pickerScale $node`)
$pickerScale = `getAttr ($node+".pickerScale")`;
int $count = `getAttr ($node+".count")`;
string $bgImage = `getAttr ($node+".bgImage")`;
$bgImage = `workspace -en $bgImage`;
string $bgColor = `getAttr ($node+".bgColor")`;
string $data[] = `getAttr ($node+".data")`;
int $width[] = `getAttr ($node+".width")`;
int $height[] =`getAttr ($node+".height")`;
string $overlay[] = `getAttr ($node+".overlay")`;
string $command[] = `getAttr ($node+".command")`;
string $image[] = `getAttr ($node+".image")`;
if (!attributeExists("label",$node))
addAttr -longName "label" -dt "stringArray" $node;
string $label[] = `getAttr ($node+".label")`;
int $charPrefix = `getAttr ($node+".charPrefix")`;
tokenize $node ":" $tokenBufferNS;
if (size($tokenBufferNS)<2){
tokenize $node "_" $tokenBuffer;
if (size($tokenBuffer) >= 3){
$charName = ($tokenBuffer[0]);
$charName2 = ($tokenBuffer[0]+"_");
for ($i=1;$i<size($tokenBuffer)-2;$i++){
$charName = ($charName + $tokenBuffer[$i]);
}
$subName = $tokenBuffer[size($tokenBuffer)-2];
}
else if (size($tokenBuffer) == 2){
$charName = "";
$charName2 = "";
$subName = $tokenBuffer[0];
}
}
else{
$charName = $tokenBufferNS[0];
$charName2 = ($tokenBufferNS[0]+"_");
tokenize $tokenBufferNS[1] "_" $tokenBuffer2;
$subName = $tokenBuffer2[size($tokenBuffer2)-2];
}
tokenize $bgColor ":" $bgColorBuffer;
float $bgr = $bgColorBuffer[0];
float $bgg = $bgColorBuffer[1];
float $bgb = $bgColorBuffer[2];
if (!`tabLayout -q -ex ($charName+"PkrLyt")`){
tabLayout -parent abxPickerCharTabs ($charName+"PkrLyt");
}
if ($charName != ""){
if (size($tokenBufferNS) < 2)
formLayout -parent ($charName+"PkrLyt") -dtg ($charName2+"|"+$subName+"|"+$bgColor) -bgc $bgr $bgg $bgb -dpc "abxPickerCtrlDrop" ($charName2+$subName+"PkrLyt");
else
formLayout -parent ($charName+"PkrLyt") -dtg ($charName+":|"+$subName+"|"+$bgColor) -bgc $bgr $bgg $bgb -dpc "abxPickerCtrlDrop" ($charName2+$subName+"PkrLyt");
}
else{
formLayout -parent ($charName+"PkrLyt") -dtg (" |"+$subName+"|"+$bgColor) -bgc $bgr $bgg $bgb -dpc "abxPickerCtrlDrop" ($charName2+$subName+"PkrLyt");
}
if (`filetest -f $bgImage`){
int $imageDim[] = `abxPickerGetImageSize $bgImage`;
setParent ($charName2+$subName+"PkrLyt");
if (`about -os`=="mac")
$bgPic = `symbolButton -parent ($charName2+$subName+"PkrLyt") -enable 0 -image $bgImage -w ($imageDim[0]*$pickerScale) -h ($imageDim[1]*$pickerScale)`;
else
$bgPic = `image -parent ($charName2+$subName+"PkrLyt") -enable 0 -image $bgImage -w ($imageDim[0]*$pickerScale) -h ($imageDim[1]*$pickerScale)`;
}
else{
if (`about -os`=="mac")
$bgPic = `symbolButton -parent ($charName2+$subName+"PkrLyt") -visible 0 -bgc $bgr $bgg $bgb`;
else
$bgPic = `image -parent ($charName2+$subName+"PkrLyt") -visible 0 -bgc $bgr $bgg $bgb`;
//print ("Image NOT Found "+$bgImage+"\n");
}
popupMenu -button 3 -parent ($charName2+$subName+"PkrLyt");
menuItem -label "BG Image..." -c abxPickerSetBGImage;
menuItem -label "Zoom In" -c "abxPickerZoom \"in\";evalDeferred(\"abxPickerRefresh 0\");" ;
menuItem -label "Zoom Out" -c "abxPickerZoom \"out\";evalDeferred(\"abxPickerRefresh 0\");";
tabLayout -e -tabLabel ($charName2+$subName+"PkrLyt") $subName ($charName+"PkrLyt");
formLayout -e
-af $bgPic "top" 0
-af $bgPic "left" 0
-an $bgPic "right"
-an $bgPic "bottom"
($charName2+$subName+"PkrLyt");
// if namespaces are used prefix with colon else use underscore
if (size($tokenBufferNS)>1)
$pickrPrefix = ($charName+":");
else
$pickrPrefix = $charName2;
for ($i=0;$i<$count;$i++){
tokenize $data[$i] ":" $tokenBuffer;
if (size($tokenBuffer)==5){
int $xPos = int($tokenBuffer[0]) * $pickerScale;
int $yPos = int($tokenBuffer[1]) * $pickerScale;
float $bgr = $tokenBuffer[2];
float $bgg = $tokenBuffer[3];
float $bgb = $tokenBuffer[4];
string $control;
// if prefix flag is true
if ($charPrefix == 1){
// if the data node has a rename prefix
if ($charName2!=""){
// create the button that sets the pickrPrefix
$control = `abxPickerNewButton $xPos $yPos ($width[$i]*$pickerScale) ($height[$i]*$pickerScale) $bgr $bgg $bgb $image[$i] ("global string $pickrPrefix=\""+$pickrPrefix+"\";"+$command[$i]) $label[$i]`;
}
else{
$control = `abxPickerNewButton $xPos $yPos ($width[$i]*$pickerScale) ($height[$i]*$pickerScale) $bgr $bgg $bgb $image[$i] ("global string $pickrPrefix=\"\";"+$command[$i]) $label[$i]`;
}
}
else {
$control = `abxPickerNewButton $xPos $yPos ($width[$i]*$pickerScale) ($height[$i]*$pickerScale) $bgr $bgg $bgb $image[$i] ("global string $pickrPrefix=\"\";"+$command[$i]) $label[$i]`;
}
abxPickerSetPos ($charName2+$subName+"PkrLyt") $control $xPos $yPos ($width[$i]*$pickerScale) ($height[$i]*$pickerScale) ;
}
}
textField -e -text $charName abxPickerCharText;
// formLayout -e -visible true ($charName2+$subName+"PkrLyt");
}
//------------------------------------------------------------------
// writes the picker data to a transform node
global proc abxPickerWriteNode (string $picker) {
int $buttonCount = `layout -q -nch $picker`;
string $uiName[] = `layout -q -ca $picker`;
string $bgImage = "";
if (`about -os` == "mac")
$bgImage = `symbolButton -q -image $uiName[0]`;
else
$bgImage = `image -q -image $uiName[0]`;
string $pickerData = `layout -q -dtg $picker`;
string $nodeName = "";
string $pickerDataBuffer[];
tokenize $pickerData "|" $pickerDataBuffer;
if ($pickerDataBuffer[0] == " ")
$nodeName = ($pickerDataBuffer[1]+"_PIKR");
else
$nodeName = ($pickerDataBuffer[0]+$pickerDataBuffer[1]+"_PIKR");
if (!objExists($nodeName))
abxPickerNewNode ($nodeName) "" "" 0 0 1;
print ("Saving "+$nodeName+"\n");
setAttr ($nodeName+".bgImage") -type "string" $bgImage;
setAttr ($nodeName+".bgColor") -type "string" ($pickerDataBuffer[2]+":"+$pickerDataBuffer[3]+":"+$pickerDataBuffer[4]);
setAttr ($nodeName+".count") ($buttonCount-1);
// adds attributes to nodes for newer version of abxPicker
if (!`attributeExists mirrorPicker $nodeName`){
addAttr -longName "mirrorPicker" -at "bool" $nodeName;
setAttr ($nodeName+".mirrorPicker") 0;
}
if (!`attributeExists pickerScale $nodeName`){
addAttr -longName "pickerScale" -at "float" $nodeName;
setAttr ($nodeName+".pickerScale") 1.0;
}
int $mirrorPicker = `getAttr ($nodeName+".mirrorPicker")`;
float $pickerScale = `getAttr ($nodeName+".pickerScale")`;
string $data[];
int $width[];
int $height[];
string $overlay[];
string $image[];
string $command[];
string $label[];
// assumes first child is the background image ($i=0) and ignores it
for ($i=1;$i<$buttonCount;$i++){
// if it hasnt been disabled
if (`control -q -en $uiName[$i]` == 1){
// parse the data for reverse scaling the left and top position of controls
string $tokenBuffer[];
string $unscaledData = `iconTextButton -q -dtg $uiName[$i]`;
tokenize $unscaledData ":" $tokenBuffer;
int $xPos = int((float($tokenBuffer[0])+0.5) / $pickerScale);
int $yPos = int((float($tokenBuffer[1])+0.5) / $pickerScale);
string $scaledData = "";
for ($j=0;$j<size($tokenBuffer);$j++){
if ($j == 0){
$scaledData = ($xPos);
}
else if ($j == 1) {
$scaledData = ($scaledData+":"+$yPos);
}
else {
$scaledData = ($scaledData+":"+$tokenBuffer[$j]);
}
}
int $unscaledWidth = int(float(`control -q -width $uiName[$i]`)+0.5);
int $unscaledHeight = int(float(`control -q -height $uiName[$i]`)+0.5);
// $data[size($data)] = `iconTextButton -q -dtg $uiName[$i]`;
$data[size($data)] = $scaledData;
$width[size($width)] = ($unscaledWidth / $pickerScale);
$height[size($height)] = ($unscaledHeight / $pickerScale);
$overlay[size($overlay)] = `iconTextButton -q -imageOverlayLabel $uiName[$i]`;
$image[size($image)] = `iconTextButton -q -image1 $uiName[$i]`;
$command[size($command)] = `iconTextButton -q -command $uiName[$i]`;
$label[size($label)] = `iconTextButton -q -label $uiName[$i]`;
}
}
// set buttonCount to size of array
$buttonCount = size($data)+1;
int $charPrefix = `getAttr ($nodeName+".charPrefix")`;
// build setAttr
string $setAttrCmd = ("setAttr "+$nodeName+".data -type stringArray "+($buttonCount-1));
for ($each in $data)
$setAttrCmd = ($setAttrCmd + " \"" + $each + "\"");
eval ($setAttrCmd);
string $setAttrCmd = ("setAttr "+$nodeName+".overlay -type stringArray "+($buttonCount-1));
for ($each in $overlay)
$setAttrCmd = ($setAttrCmd + " \"" + $each + "\"");
eval ($setAttrCmd);
string $setAttrCmd = ("setAttr "+$nodeName+".image -type stringArray "+($buttonCount-1));
for ($each in $image)
$setAttrCmd = ($setAttrCmd + " \"" + $each + "\"");
eval ($setAttrCmd);
// writes the command data, removes prefix code
string $setAttrCmd = ("setAttr "+$nodeName+".command -type stringArray "+($buttonCount-1));
for ($each in $command) {
//if ($charPrefix == 1){
string $tokenBuffer[];
tokenize $each ";" $tokenBuffer;
string $newCommand = "";
$newCommand = $tokenBuffer[1];
for ($i=2;$i<size($tokenBuffer);$i++){
$newCommand = ($newCommand + ";" + $tokenBuffer[$i]);
}
$setAttrCmd = ($setAttrCmd + " \"" + encodeString($newCommand) + "\"");
//}
//else {
// $setAttrCmd = ($setAttrCmd + " \"" + encodeString($each) + "\"");
//}
}
eval ($setAttrCmd);
string $setAttrCmd = ("setAttr "+$nodeName+".width -type Int32Array "+($buttonCount-1));
for ($each in $width)
$setAttrCmd = ($setAttrCmd + " " + $each);
eval ($setAttrCmd);
string $setAttrCmd = ("setAttr "+$nodeName+".height -type Int32Array "+($buttonCount-1));
for ($each in $height)
$setAttrCmd = ($setAttrCmd + " " + $each);
eval ($setAttrCmd);
if (!attributeExists("label",$nodeName))
addAttr -longName "label" -dt "stringArray" nodeName;
string $setAttrCmd = ("setAttr "+$nodeName+".label -type stringArray "+($buttonCount-1));
for ($each in $label)
$setAttrCmd = ($setAttrCmd + " \"" + encodeString($each) + "\"");
eval ($setAttrCmd);
}
//------------------------------------------------------------------------
// called when clicking the buttons, allows for additive/toggle selection
global proc abxPickerSelect (string $selList){
string $selListBuffer[];
global string $pickrPrefix;
tokenize $selList " " $selListBuffer;
if ($pickrPrefix != ""){
for ($i=0;$i<size($selListBuffer);$i++){
string $pathPipeBuffer[];
tokenize $selListBuffer[$i] "|" $pathPipeBuffer;
if (size($pathPipeBuffer) > 1){
string $rebuiltPathName = "";
for ($j=0;$j<size($pathPipeBuffer);$j++){
if ($j == 0){
$rebuiltPathName = ($pickrPrefix+$pathPipeBuffer[$j]);
}
else {
$rebuiltPathName = ($rebuiltPathName + "|" +$pickrPrefix+$pathPipeBuffer[$j]);
}
}
$selListBuffer[$i] = $rebuiltPathName;
}
else {
$selListBuffer[$i] = ($pickrPrefix+$selListBuffer[$i]);
}
}
}
int $mods = `getModifiers`;
string $cmd = "select ";
// shift
if (($mods / 1) %2) {
$cmd += "-add ";
//select -add $selListBuffer;
}
// ctrl
else if (($mods / 4) %2) {
$cmd += "-toggle ";
//select -toggle $selListBuffer;
}
// nothing
else{
//print $selListBuffer;
//select $selListBuffer;
}
for ($each in $selListBuffer){
$cmd +=($each+" ");
}
evalEcho($cmd);
setFocus MayaWindow;
}
//------------------------------------------------------------------------
// called when toggling boolean values such as visibility
global proc abxPickerToggle (string $selList, string $attrList){
global string $pickrPrefix;
string $tokenBufferNodes[];
string $tokenBufferAttrs[];
tokenize $selList " " $tokenBufferNodes;
tokenize $attrList " " $tokenBufferAttrs;
for ($each in $tokenBufferNodes){
for ($every in $tokenBufferAttrs){
if ($pickrPrefix != ""){
$oldVal = `getAttr ($pickrPrefix+$each+"."+$every)`;
if ($oldVal == 1)
setAttr ($pickrPrefix+$each+"."+$every) 0;
else if ($oldVal == 0)
setAttr ($pickrPrefix+$each+"."+$every) 1;
}
else{
$oldVal = `getAttr ($each+"."+$every)`;
if ($oldVal == 1)
setAttr ($each+"."+$every) 0;
else if ($oldVal == 0)
setAttr ($each+"."+$every) 1;
}
}
}
}
//------------------------------------------------------------------------
// called when clicking the buttons, allows for additive/toggle selection
global proc abxPickerKey (string $selList){
string $selListBuffer[];
global string $pickrPrefix;
tokenize $selList " " $selListBuffer;
if ($pickrPrefix != ""){
for ($i=0;$i<size($selListBuffer);$i++){
$selListBuffer[$i] = ($pickrPrefix+$selListBuffer[$i]);
}
}
setKeyframe $selListBuffer;
}
//-------------------------------------------------------------------------
// called when toggling isolate object funtion
global proc abxPickerIsolate (string $selList) {
select $selList;
global string $abxPickerIsoList;
// find all model views
string $modelViews[];
$editors = `lsUI -editors`;
for ($each in $editors) {
if (`modelEditor -q -exists $each`){
$modelViews[size($modelViews)] = $each;
}
}
if ($selList != $abxPickerIsoList){
for ($each in $modelViews){
isolateSelect -state 1 $each;
}
$abxPickerIsoList = $selList;
}
else {
for ($each in $modelViews){
isolateSelect -state 0 $each;
}
$abxPickerIsoList = "";
}
}
//-------------------------------------------------------------------------
// called when setting pose funtion
global proc abxPickerPose (string $nodes, string $vals){
string $nodeAttrPath[] = stringToStringArray($nodes,",");
string $attrVal[] = stringToStringArray($vals,",");
global string $pickrPrefix;
string $seperator = "_";
string $cmds = "";
int $i = 0;
for ($i=0;$i<size($nodeAttrPath);$i++){
string $nodeDagPath[] = stringToStringArray($nodeAttrPath[$i],"|");
string $prefixNodeDagPath = "";
if ($pickrPrefix != ""){
for ($each in $nodeDagPath){
if ($each != ""){
$prefixNodeDagPath += ("|"+$pickrPrefix+$each);
}
}
}
else{
$prefixNodeDagPath = $nodeAttrPath[$i];
}
$cmds += ("setAttr "+$prefixNodeDagPath+" "+$attrVal[$i]+";\n");
}
evalEcho $cmds;
}
//-------------------------------------------------------------------------
// creates the control preset window
global proc abxPickerBuildToolbox() {
if (`window -ex abxPickerToolWindow` != true) {
window -w 156 -h 311 -t "Buttons" -tlb 0 abxPickerToolWindow;
formLayout abxPickerToolForm;
tabLayout abxPickerToolTabs;
columnLayout -parent abxPickerToolTabs -rs 0 abxPickerToolColor ;
//columnLayout -rs 2;
rowLayout -nc 12;
iconTextButton -style "iconOnly" -dtg "0:0:.5:0:0" -w 16 -h 16 -bgc .5 0 0 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.5:.25:0" -w 16 -h 16 -bgc .5 .25 0 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.5:.5:0" -w 16 -h 16 -bgc .5 .5 0 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.25:.5:0" -w 16 -h 16 -bgc .25 .5 0 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:0:.5:0" -w 16 -h 16 -bgc 0 .5 0 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:0:.5:.25" -w 16 -h 16 -bgc 0 .5 .25 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:0:.5:.5" -w 16 -h 16 -bgc 0 .5 .5 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:0:.25:.5" -w 16 -h 16 -bgc 0 .25 .5 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:0:0:.5" -w 16 -h 16 -bgc 0 0 .5 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.25:0:.5" -w 16 -h 16 -bgc .25 0 .5 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.5:0:.5" -w 16 -h 16 -bgc .5 0 .5 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.5:0:.25" -w 16 -h 16 -bgc .5 0 .25 -dgc "abxPickerCtrlColor";
setParent..;
rowLayout -nc 12;
iconTextButton -style "iconOnly" -dtg "0:0:.75:0:0" -w 16 -h 16 -bgc .75 0 0 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.38:.5:0" -w 16 -h 16 -bgc .75 .38 0 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.75:.75:0" -w 16 -h 16 -bgc .75 .75 0 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.38:.75:0" -w 16 -h 16 -bgc .38 .75 0 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:0:.75:0" -w 16 -h 16 -bgc 0 .75 0 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:0:.75:.38" -w 16 -h 16 -bgc 0 .75 .38 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:0:.75:.75" -w 16 -h 16 -bgc 0 .75 .75 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:0:..38:.75" -w 16 -h 16 -bgc 0 .38 .75 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:0:0:.75" -w 16 -h 16 -bgc 0 0 .75 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.38:0:.75" -w 16 -h 16 -bgc .38 0 .75 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.75:0:.75" -w 16 -h 16 -bgc .75 0 .75 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.75:0:..38" -w 16 -h 16 -bgc .75 0 .38 -dgc "abxPickerCtrlColor";
setParent..;
rowLayout -nc 12;
iconTextButton -style "iconOnly" -dtg "0:0:1:0:0" -w 16 -h 16 -bgc 1 0 0 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:1:.5:0" -w 16 -h 16 -bgc 1 .5 0 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:1:1:0" -w 16 -h 16 -bgc 1 1 0 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.5:1:0" -w 16 -h 16 -bgc .5 1 0 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:0:1:0" -w 16 -h 16 -bgc 0 1 0 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:0:1:.5" -w 16 -h 16 -bgc 0 1 .5 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:0:1:1" -w 16 -h 16 -bgc 0 1 1 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:0:.5:1" -w 16 -h 16 -bgc 0 .5 1 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:0:0:1" -w 16 -h 16 -bgc 0 0 1 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.5:0:1" -w 16 -h 16 -bgc .5 0 1 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:1:0:1" -w 16 -h 16 -bgc 1 0 1 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:1:0:.5" -w 16 -h 16 -bgc 1 0 .5 -dgc "abxPickerCtrlColor";
setParent..;
rowLayout -nc 12;
iconTextButton -style "iconOnly" -dtg "0:0:1:.5:.5" -w 16 -h 16 -bgc 1 .5 .5 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:1:.75:.5" -w 16 -h 16 -bgc 1 .75 .5 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:1:1:.5" -w 16 -h 16 -bgc 1 1 .5 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.75:1:.5" -w 16 -h 16 -bgc .75 1 .5 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.5:1:.5" -w 16 -h 16 -bgc .5 1 .5 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.5:1:.75" -w 16 -h 16 -bgc .5 1 .75 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.5:1:1" -w 16 -h 16 -bgc .5 1 1 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.5:.75:1" -w 16 -h 16 -bgc .5 .75 1 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.5:.5:1" -w 16 -h 16 -bgc .5 .5 1 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.75:.5:1" -w 16 -h 16 -bgc .75 .5 1 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:1:.5:1" -w 16 -h 16 -bgc 1 .5 1 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:1:.5:.75" -w 16 -h 16 -bgc 1 .5 .75 -dgc "abxPickerCtrlColor";
setParent..;
rowLayout -nc 12;
iconTextButton -style "iconOnly" -dtg "0:0:.7:.4:.4" -w 16 -h 16 -bgc .7 .4 .4 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.7:.5:.4" -w 16 -h 16 -bgc .7 .5 .4 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.7:.7:.4" -w 16 -h 16 -bgc .7 .7 .4 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.5:.7:.4" -w 16 -h 16 -bgc .5 .7 .4 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.4:.7:.4" -w 16 -h 16 -bgc .4 .7 .4 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.4:.7:.5" -w 16 -h 16 -bgc .4 .7 .5 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.4:.7:.7" -w 16 -h 16 -bgc .4 .7 .7 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.4:.5:.7" -w 16 -h 16 -bgc .4 .5 .7 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.4:.4:.7" -w 16 -h 16 -bgc .4 .4 .7 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.5:.4:.7" -w 16 -h 16 -bgc .5 .4 .7 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.7:.4:.7" -w 16 -h 16 -bgc .7 .4 .7 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.7:.4:.5" -w 16 -h 16 -bgc .7 .4 .5 -dgc "abxPickerCtrlColor";
setParent..;
rowLayout -nc 7;
iconTextButton -style "textOnly" -l "T" -dtg "0:0:-1:.0:.0" -w 16 -h 16 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.0:.0:.0" -w 16 -h 16 -bgc .0 .0 .0 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.2:.2:.2" -w 16 -h 16 -bgc .2 .2 .2 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.4:.4:.4" -w 16 -h 16 -bgc .4 .4 .4 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.6:.6:.6" -w 16 -h 16 -bgc .6 .6 .6 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:.8:.8:.8" -w 16 -h 16 -bgc .8 .8 .8 -dgc "abxPickerCtrlColor";
iconTextButton -style "iconOnly" -dtg "0:0:1:1:1" -w 16 -h 16 -bgc 1 1 1 -dgc "abxPickerCtrlColor";
setParent..;
rowLayout -nc 2 -co2 3 3 -cw2 60 60;
iconTextButton -style "textOnly" -ann "Drag from here to drop custom color" -bgc .95 .95 .95 -label "Custom" -w 56 -h 30 -dgc "abxPickerCtrlColor" abxPickerClrCustom;
colorSliderGrp -cw 1 30 -cw 2 120
-cc ("float $custColor[] = `colorSliderGrp -q -rgb abxPickerClrCustomGrp`;"
+"iconTextButton -e -bgc $custColor[0] $custColor[1] $custColor[2] abxPickerClrCustom;"
+"iconTextButton -e -dtg (\"0:0:\"+$custColor[0]+\":\"+$custColor[1]+\":\"+$custColor[2]) abxPickerClrCustom;")
-rgb 1 1 1 abxPickerClrCustomGrp;
//textField -text "Custom" -cc "iconTextButton -e -c `textField -q -text abxPickerClrTxt` abxPickerClrCustom" abxPickerClrTxt;
setParent..;
setParent..;
setParent..;
columnLayout -parent abxPickerToolTabs abxPickerToolImages;
//rowLayout -nc 2 -co2 3 3 -cw2 32 32;
//columnLayout -rs 4;
//rowLayout -nc 2 -co2 6 6 -cw2 36 36;
//iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -image "fileOpen.xpm" -dgc "abxPickerCtrlImage";
//textField -w 120 abxPickerCustomImageField;
//setParent..;
//setParent..;
rowLayout -nc 8 ;
iconTextButton -style "textOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -dgc "abxPickerCtrlLabel";
iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -image "autoKeyframeOff.png" -dgc "abxPickerCtrlImage";
iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -image "blackbox.png" -dgc "abxPickerCtrlImage";
iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -image "Camera.png" -dgc "abxPickerCtrlImage";
iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -image "channelBoxUseManips.png" -dgc "abxPickerCtrlImage";
iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -image "circle.png" -dgc "abxPickerCtrlImage";
iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -image "square.png" -dgc "abxPickerCtrlImage";
iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -image "dot.png" -dgc "abxPickerCtrlImage";
setParent..;
rowLayout -nc 8 ;
iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -image "defaultHand.png" -dgc "abxPickerCtrlImage";
iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -image "autoKeyframeOn.png" -dgc "abxPickerCtrlImage";
iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -image "fleur.png" -dgc "abxPickerCtrlImage";
iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -image "light.png" -dgc "abxPickerCtrlImage";
iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -image "menuIconAdd.png" -dgc "abxPickerCtrlImage";
iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -image "timeStop.png" -dgc "abxPickerCtrlImage";
iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -image "tumbleCursor.png" -dgc "abxPickerCtrlImage";
iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -image "srt_M.png" -dgc "abxPickerCtrlImage";
setParent..;
rowLayout -nc 8 ;
iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -image "render_blinn.png" -dgc "abxPickerCtrlImage";
iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -image "render_lambert.png" -dgc "abxPickerCtrlImage";
iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -image "render_shadingMap.png" -dgc "abxPickerCtrlImage";
iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -image "render_useBackground.png" -dgc "abxPickerCtrlImage";
iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -image "pickHandlesObj.png" -dgc "abxPickerCtrlImage";
iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -image "pickPivotComp.png" -dgc "abxPickerCtrlImage";
iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -image "pickPointComp.png" -dgc "abxPickerCtrlImage";
iconTextButton -style "iconOnly" -w 32 -h 32 -dtg "0:0:-1:.9:.9" -bgc .95 .95 .95 -image "pickPointComp2.png" -dgc "abxPickerCtrlImage";
setParent..;
rowLayout -nc 3 -adj 2 -co3 3 6 6 -cw3 36 205 27 ;
iconTextButton -style "iconOnly" -bgc .95 .95 .95 -label "Custom" -w 32 -h 30 -dgc "abxPickerCtrlImage" abxPickerImgCustom;
textField -text "Custom" -w 200 -aie 1 -ec "iconTextButton -e -image `textField -q -text abxPickerImgTxt` abxPickerImgCustom" abxPickerImgTxt;
symbolButton -image "fileOpen.png"
-c ("string $multipleFilters = \"PNG (*.png);;JPEG (*.jpg);;Bitmap (*.bmp);;XPM (*.xpm);;All Files (*.*)\";"
+"string $imagePath[] = `fileDialog2 -ds 2 -fileFilter $multipleFilters -selectFileFilter \"PNG\" -cap \"Choose Background Image\" -fm 1`;"
+"if ($imagePath[0]!=\"\") { textField -e -text $imagePath[0] abxPickerImgTxt;"
+"iconTextButton -e -image $imagePath[0] abxPickerImgCustom;}");
//symbolButton -image "factoryIcon.png" -command "python(\"import maya.app.general.resourceBrowser as resourceBrowser;resBrowser = resourceBrowser.resourceBrowser();path = resBrowser.run();del resBrowser;\")";
//symbolButton -image "factoryIcon.png" -command "python(\"import maya.app.general.resourceBrowse as resourceBrowser\");python(\"import maya.app.general.resourceBrowse\")";
setParent..;
setParent..;
setParent..;
columnLayout -parent abxPickerToolTabs abxPickerToolcmd;
//rowLayout -nc 2 -co2 3 3 -cw2 60 60;
rowLayout -nc 4 ;
iconTextButton -style "textOnly" -ann "Select and Use Move Tool" -bgc .95 .95 .95 -label "Move" -w 56 -h 30 -dgc "abxPickerCtrlCommand" -c "/*selectT*/";
iconTextButton -style "textOnly" -ann "Select and Use Rotate Tool" -bgc .95 .95 .95 -label "Rotate" -w 56 -h 30 -dgc "abxPickerCtrlCommand" -c "/*selectR*/";
iconTextButton -style "textOnly" -ann "Select and Use Scale Tool" -bgc .95 .95 .95 -label "Scale" -w 56 -h 30 -dgc "abxPickerCtrlCommand" -c "/*selectS*/";
iconTextButton -style "textOnly" -ann "Select and Show Manip" -bgc .95 .95 .95 -label "Manip" -w 56 -h 30 -dgc "abxPickerCtrlCommand" -c "/*selectM*/";
setParent..;
rowLayout -nc 4 ;
iconTextButton -style "textOnly" -ann "Select Object" -bgc .95 .95 .95 -label "Select" -w 56 -h 30 -dgc "abxPickerCtrlCommand" -c "/*select*/";
iconTextButton -style "textOnly" -ann "Key Selected Object" -bgc .95 .95 .95 -label "Key" -w 56 -h 30 -dgc "abxPickerCtrlCommand" -c "/*key*/";
iconTextButton -style "textOnly" -ann "Toggle Selected Attr On|Off (select attr in channelbox)" -bgc .95 .95 .95 -label "Toggle" -w 56 -h 30 -dgc "abxPickerCtrlCommand" -c "/*toggle*/";
iconTextButton -style "textOnly" -ann "Store Attr Values for Pose" -bgc .95 .95 .95 -label "Pose" -w 56 -h 30 -dgc "abxPickerCtrlCommand" -c "/*pose*/";
setParent..;
rowLayout -nc 1 ;
iconTextButton -visible 0 -style "textOnly" -ann "Isolate" -bgc .95 .95 .95 -label "Isolate" -w 56 -h 30 -dgc "abxPickerCtrlCommand" -c "/*isolate*/";
setParent..;
rowLayout -nc 2 -co2 3 3 -cw2 60 60;
iconTextButton -style "textOnly" -ann "Drag from here to drop custom command" -bgc .95 .95 .95 -label "Custom" -w 56 -h 30 -dgc "abxPickerCtrlCommand" abxPickerCmdCustom;
textField -text "Custom" -w 150 -aie 1 -ec "iconTextButton -e -c `textField -q -text abxPickerCmdTxt` abxPickerCmdCustom" abxPickerCmdTxt;
setParent..;
setParent..;
columnLayout -parent abxPickerToolTabs abxPickerToolLabel;
//rowLayout -nc 2 -co2 3 3 -cw2 60 60;
rowLayout -nc 4 ;
iconTextButton -style "textOnly" -bgc .95 .95 .95 -label "God" -w 56 -h 20 -dgc "abxPickerCtrlLabel";
iconTextButton -style "textOnly" -bgc .95 .95 .95 -label "Mvr" -w 56 -h 20 -dgc "abxPickerCtrlLabel";
iconTextButton -style "textOnly" -bgc .95 .95 .95 -label "Dir" -w 56 -h 20 -dgc "abxPickerCtrlLabel";
iconTextButton -style "textOnly" -bgc .95 .95 .95 -label "IK" -w 56 -h 20 -dgc "abxPickerCtrlLabel";
setParent..;
rowLayout -nc 4 ;
iconTextButton -style "textOnly" -bgc .95 .95 .95 -label "Key" -w 56 -h 20 -dgc "abxPickerCtrlLabel";
iconTextButton -style "textOnly" -bgc .95 .95 .95 -label "KeyAll" -w 56 -h 20 -dgc "abxPickerCtrlLabel";
iconTextButton -style "textOnly" -bgc .95 .95 .95 -label "SelAll" -w 56 -h 20 -dgc "abxPickerCtrlLabel";
iconTextButton -style "textOnly" -bgc .95 .95 .95 -label "FK" -w 56 -h 20 -dgc "abxPickerCtrlLabel";
setParent..;
rowLayout -nc 4 ;
iconTextButton -style "textOnly" -bgc .95 .95 .95 -label "" -w 56 -h 20 -dgc "abxPickerCtrlLabel";
iconTextButton -style "textOnly" -bgc .95 .95 .95 -label "Vis" -w 56 -h 20 -dgc "abxPickerCtrlLabel";
iconTextButton -style "textOnly" -bgc .95 .95 .95 -label "Lf" -w 56 -h 20 -dgc "abxPickerCtrlLabel";
iconTextButton -style "textOnly" -bgc .95 .95 .95 -label "Rt" -w 56 -h 20 -dgc "abxPickerCtrlLabel";
setParent..;
rowLayout -nc 4 ;
iconTextButton -style "textOnly" -bgc .95 .95 .95 -label "Root" -w 56 -h 20 -dgc "abxPickerCtrlLabel";
iconTextButton -style "textOnly" -bgc .95 .95 .95 -label "Hide" -w 56 -h 20 -dgc "abxPickerCtrlLabel";
iconTextButton -style "textOnly" -bgc .95 .95 .95 -label "Show" -w 56 -h 20 -dgc "abxPickerCtrlLabel";
iconTextButton -style "textOnly" -bgc .95 .95 .95 -label "Body" -w 56 -h 20 -dgc "abxPickerCtrlLabel";
setParent..;
rowLayout -nc 2 -co2 3 3 -cw2 60 60;
iconTextButton -style "textOnly" -ann "Drag from here to drop custom label" -bgc .95 .95 .95 -label "Custom" -w 56 -h 30 -dgc "abxPickerCtrlLabel" abxPickerLblCustom;
textField -text "Custom" -w 150 -aie 1 -ec "iconTextButton -e -label `textField -q -text abxPickerLblTxt` abxPickerLblCustom" abxPickerLblTxt;
setParent..;
setParent..;
formLayout -parent abxPickerToolTabs abxPickerToolScript;
iconTextButton -style "textOnly" -bgc .95 .95 .95 - ann "Drag from here to drop custom script" -label "MEL Script" -w 56 -h 30 -dtg "abxPickerScrptTxt" -dgc "abxPickerCtrlScript" abxPickerScrptCustom;
scrollField -text "Add Custom Command Here." -ec "iconTextButton -e -c `scrollField -q -text abxPickerScrptTxt` abxPickerScrptCustom" abxPickerScrptTxt;
formLayout -e -af abxPickerScrptCustom "left" 3 -af abxPickerScrptCustom "top" 3 abxPickerToolScript;
formLayout -e -af abxPickerScrptTxt "left" 3 -ac abxPickerScrptTxt "top" 3 abxPickerScrptCustom -af abxPickerScrptTxt "bottom" 3 -af abxPickerScrptTxt "right" 3 abxPickerToolScript;
//cmdScrollFieldExecuter -h 100 abxPickerCmdTxt;
tabLayout -e -tabLabel "abxPickerToolColor" "Color" abxPickerToolTabs;
tabLayout -e -tabLabel "abxPickerToolImages" "Image" abxPickerToolTabs;
tabLayout -e -tabLabel "abxPickerToolcmd" "Command" abxPickerToolTabs;
tabLayout -e -tabLabel "abxPickerToolLabel" "Label" abxPickerToolTabs;
tabLayout -e -tabLabel "abxPickerToolScript" "Script" abxPickerToolTabs;
tabLayout -e -visible true abxPickerToolTabs;
formLayout -e
-af abxPickerToolTabs "top" 2
-af abxPickerToolTabs "left" 2
-af abxPickerToolTabs "right" 0
-af abxPickerToolTabs "bottom" 0
abxPickerToolForm;
showWindow abxPickerToolWindow;
}
else {
showWindow abxPickerToolWindow;
}
}
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
//-------------------------------------------------------------------------
// creates the control preset window
global proc abxPickerPropertyToolbox(string $control) {
if (`window -ex abxPickerPropWindow` != true) {
window -w 156 -h 311 -t "Buttons" -tlb 0 abxPickerPropWindow;
formLayout abxPickerPropForm;
formLayout -e
-af abxPickerToolTabs "top" 2
-af abxPickerToolTabs "left" 2
-af abxPickerToolTabs "right" 0
-af abxPickerToolTabs "bottom" 0
abxPickerToolForm;
showWindow abxPickerPropWindow;
}
else {
showWindow abxPickerPropWindow;
}
}
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
global proc abxPickerSetBGImage () {
string $multipleFilters = "PNG (*.png);;JPEG (*.jpg);;Bitmap (*.bmp);;XPM (*.xpm);;All Files (*.*)";
string $imagePath[] = `fileDialog2 -ds 2 -fileFilter $multipleFilters -selectFileFilter "PNG" -cap "Choose Background Image" -fm 1`;
if ($imagePath[0] != ""){
// set image of current tab
// get visible picker node
$currentChar = `tabLayout -q -st abxPickerCharTabs`;
string $currentSubTabLayout = `tabLayout -q -st $currentChar`;
string $currentNodeLyt = $currentSubTabLayout;
int $subStrEnd = (size($currentNodeLyt)-6);
string $currentNode = (substring($currentNodeLyt, 1,$subStrEnd)+"_PIKR");
string $pickerNodes[] = `layout -q -ca $currentSubTabLayout`;
string $imageControl = $pickerNodes[0];
int $imgDim[] = `abxPickerGetImageSize $imagePath[0]`;
float $pickerScale = 1;
if (`attributeExists pickerScale $currentNode`)
$pickerScale = `getAttr ($currentNode+".pickerScale")`;
if (`about -os` == "mac")
symbolButton -e -visible 1 -w ($imgDim[0]*$pickerScale) -h ($imgDim[1]*$pickerScale) -image $imagePath[0] $imageControl;
else
image -e -visible 1 -w ($imgDim[0]*$pickerScale) -h ($imgDim[1]*$pickerScale) -image $imagePath[0] $imageControl;
// set bg attribute of current tabs picker
setAttr -type "string" ($currentNode+".bgImage") $imagePath[0];
}
}
global proc abxPickerMenuCmd (string $character){
string $pickerNodes[];
string $pickerNodesAlt[];
if ($character != ""){
$pickerNodes = `ls ($character+"_*_PIKR")`;
$pickerNodes = stringArrayCatenate($pickerNodes,`ls ($character+":*_PIKR")`);
}
else{
// if a charname prefix is used, find only nameless nodes
$pickerNodesAlt = `ls "*_PIKR"`;
int $i = 0;
string $tokenBuffer[];
for ($each in $pickerNodesAlt){
tokenize $each "_" $tokenBuffer;
if (size($tokenBuffer)<3){
$pickerNodes[$i] = $each;
$i++;
}
}
}
for ($node in $pickerNodes){
string $charName = "";
string $charName2 = "";
string $tokenBuffer[];
string $tokenBuffer2[];
string $subName="";
tokenize $node ":" $tokenBuffer;
// if there is no namespaces in use
if (size($tokenBuffer) < 2){
// break apart underscores
tokenize $node "_" $tokenBuffer;
// if it has a character name
if (size($tokenBuffer) >= 3){
$charName = ($tokenBuffer[0]);
$charName2 = ($tokenBuffer[0]+"_");
for ($i=1;$i<size($tokenBuffer)-2;$i++){
$charName = ($charName + $tokenBuffer[$i]);
}
}
$subName = $tokenBuffer[size($tokenBuffer)-2];
}
// if there is a namespace
else{
$charName = $tokenBuffer[0];
$charName2 = ($tokenBuffer[0]+"_");
tokenize $tokenBuffer[1] "_" $tokenBuffer2;
$subName = $tokenBuffer2[size($tokenBuffer2)-2];
}
// if the Character tab and subchar tab doesn't exist load the node
if (!`tabLayout -q -ex ($charName+"PkrLyt")`){
if (!`formLayout -q -ex ($charName2+$subName+"PkrLyt")`)
abxPickerReadNode $node;
}
// if the character tab exists but the subchar tab doesn't load the node
else{
if (!`formLayout -q -ex ($charName2+$subName+"PkrLyt")`)
abxPickerReadNode $node;
}
tabLayout -e -st ($charName+"PkrLyt") abxPickerCharTabs;
if ($charName != "")
textField -e -text $charName abxPickerCharText;
else
textField -e -text "*Prefix*" abxPickerCharText;
}
}
global proc abxPickerBrowsePath (string $sampleImageName[], string $fileType) {
textFieldButtonGrp -e -text $sampleImageName[0] abxPickerImagePath;
}
global proc abxPickerScriptJob () {
if (`window -q -ex abxPickerWindow`)
abxPickerRefresh 0;
}
global proc abxPickerHelp() {
if (!`window -q -ex abxPickerHelpWin`){
//windowPref -r abxPickerHelpWin;
window -s 1 -tlb 0 -t "abxPicker Help (Version 2.5.2)" -h 400 -w 450 abxPickerHelpWin;
columnLayout -rs 1 -adj 1 -w 400 -cat "both" 0;
text -al "left" -label (
" abxPicker is a Character Control Interface that allows you to\n"
+" create a schematic layout of your character's animation controls\n"
+" for simplified selection and animation.\n");
scrollLayout -cr true -w 400 -h 270 abxPickerHelpScrl;
columnLayout -rs 1 -adj 1 -w 400 -cat "both" 0;
text -al "left" -font "boldLabelFont" -label "\n Making a New Interface a.k.a. \"Sheet\"\n";
text -al "left" -label (
" 1. Press the \"New Picker Sheet\" button in the upper left corner.\n"
+" 2. Enter a Name for your character\n"
+" 3. Enter a SubSet Name such as \"Body\" or \"Hands\" or \"Face\"\n"
+" 4. Browse for a background image or leave blank and choose a color\n"
+" 5. Press \"OK\" and your new picker sheet is shown. Also notice a \n"
+" PIKR node is now visible in your outliner. This node stores the \n"
+" data for your interface and can be exported/imported to other scenes \n\n");
text -al "left" -font "boldLabelFont" -label " Create and Layout Buttons\n";
text -al "left" -label (
" 1. Select a control or object in maya's viewport that you want to \n"
+" create a button for \n"
+" 2. Middle-Mouse-Button drag and drop one of the colored buttons in the \n"
+" lower left corner onto the picker sheet. This creates a new button that \n"
+" will select the current object \n"
+" 3. Reposition the button by MMB draging it to a new position \n"
+" 4. Resize button by Ctrl+MMB draging. Where you release will define \n"
+" the lower right corner of the button\n"
+" 5. Duplicate buttons by Shift+MMB draging an existing button\n"
+" 6. Continue to create and layout buttons for your character \n"
+" 7. Remove buttons by MMB drag and drop to the trash can \n"
+" 8. Be sure to save your changes by clicking the \"Save Picker Sheet\"\n"
+" Button in the upper left corner \n\n");
text -al "left" -font "boldLabelFont" -label " Edit Button Color, Commands, add Labels \n";
text -al "left" -label (
" 1. Press \"More...\" to show the button pallete \n"
+" 2. Change colors by MMB draging and droping over existing buttons \n"
+" 3. Change the command by selecting a new object in the viewport and \n"
+" then MMB drag and drop over existing buttons. Move, Rotate, Scale, \n"
+" and Manip will select the object and automatically switch tools.\n"
+" Key command will key all keyable attributes on selected objects.\n"
+" Toggle will toggle selected channels in channel editor between \n"
+" values of 0 and 1 (useful for visibility buttons or other)\n"
+" 4. Change Labels by MMB drag and drop over existing buttons. Create \n"
+" your own labelsby entering text into the \"custom\" field, press enter,\n"
+" and then MMB drag the button \n\n");
text -al "left" -font "boldLabelFont" -label " Using the Picker to Pick Things\n";
text -al "left" -label (
" 1. Left Click the Character Menu located in the top middle of the Picker\n"
+" window to choose the character you wish to work with\n"
+" 2. Left click buttons to select the corresponding object/control\n"
+" 3. Shift + Left click to add objects to the selection list \n"
+" 4. Ctrl + Left click to remove objects from the selection list\n\n");
text -al "left" -font "boldLabelFont" -label " Working with Referencing/Pipeline \n";
text -al "left" -label (
" If your developing character's in a pipeline using referencing you'll \n"
+" probably want the character's name to be unspecified until that scene is \n"
+" referenced. abxPicker supports rename prefixes or namespaces that\n"
+" specify the character's name. To set this up do the following\n"
+" 1. In your character scene file, create a new picker sheet and select.\n"
+" Use Reference Prefix or Namespace. \n"
+" 2. You'll notice that the character name is listed in the character menu as \n"
+" *prefix* Go about making the rest of your character picker normally.\n"
+" and thats it. When you reference the scene the prefix will be the name.\n\n");
text -al "left" -font "boldLabelFont" -label " Renaming a Picker Sheet \n";
text -al "left" -label (
" If you would like to rename a character simply alter the name of the PIKR \n"
+" node in the format <charname>_<tabname>_PIKR. \n"
+" If you would like to convert a picker sheet to use reference prefixes simply\n"
+" remove the character name from the PIKR node like this <tabname_PIKR>\n"
+" then open the attribute editor for that node and expand the Extra\n"
+" Attributes and enable the \"Char Prefix\".\n");
setParent..;
setParent..;
rowLayout -nc 2 -cw2 300 200;
text -label " abxPicker.mel ©2012 J. Adam Burke\n http://www.adamburke.net\n Version 2.5 (2012)";
button -w 60 -label "OK" -c "deleteUI -window abxPickerHelpWin";
scrollLayout -e -h 270 abxPickerHelpScrl;
showWindow abxPickerHelpWin;
}
else{showWindow abxPickerHelpWin;}
}
# -= ml_worldBake.py =-
# __ by Morgan Loomis
# ____ ___ / / http://morganloomis.com
# / __ `__ \/ / Revision 15
# / / / / / / / 2018-07-18
# /_/ /_/ /_/_/ _________
# /_________/
#
# ______________
# - -/__ License __/- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
# Copyright 2018 Morgan Loomis
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
# Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# ___________________
# - -/__ Installation __/- - - - - - - - - - - - - - - - - - - - - - - - - -
#
# Copy this file into your maya scripts directory, for example:
# C:/Documents and Settings/user/My Documents/maya/scripts/ml_worldBake.py
#
# Run the tool in a python shell or shelf button by importing the module,
# and then calling the primary function:
#
# import ml_worldBake
# ml_worldBake.ui()
#
#
# __________________
# - -/__ Description __/- - - - - - - - - - - - - - - - - - - - - - - - - - -
#
# Temporarily bake animation to locators in world (or custom) space. Use this
# tool to preserve the worldspace position of animation when you need to make
# positional changes to an object's parent.
#
# ____________
# - -/__ Usage __/- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
# Run the tool, select the objects, then press the "To Locators" button. When
# you're ready to bake back, select the locators and press the "From Locators"
# button. Checking "Bake on Ones" will bake every frame, otherwise the keytimes
# will be derived from the original animation.
#
# _________
# - -/__ Ui __/- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
# [Bake Selection To Locators] : Bake selected object to locators specified space.
# [Bake Selected Locators Back To Objects] : Bake from selected locators back to their source objects.
# [Re-Parent Animated] : Parent all selected nodes to the last selection.
# [Un-Parent Animated] : Parent all selected to world.
# [Bake Selected] : Bake from the first selected object directly to the second.
# [Bake Selected With Offset] : Bake from the first selected object directly to the second, maintaining offset.
#
# ___________________
# - -/__ Requirements __/- - - - - - - - - - - - - - - - - - - - - - - - - -
#
# This script requires the ml_utilities module, which can be downloaded here:
# https://raw.githubusercontent.com/morganloomis/ml_tools/master/ml_utilities.py
#
# __________
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /_ Enjoy! _/- - -
__author__ = 'Morgan Loomis'
__license__ = 'MIT'
__revision__ = 15
__category__ = 'animation'
from functools import partial
import maya.cmds as mc
from maya import OpenMaya
try:
import ml_utilities as utl
utl.upToDateCheck(32)
except ImportError:
result = mc.confirmDialog( title='Module Not Found',
message='This tool requires the ml_utilities module. Once downloaded you will need to restart Maya.',
button=['Download Module','Cancel'],
defaultButton='Cancel', cancelButton='Cancel', dismissString='Cancel' )
if result == 'Download Module':
mc.showHelp('http://morganloomis.com/tool/ml_utilities/',absolute=True)
def ui():
'''
User interface for world bake
'''
with utl.MlUi('ml_worldBake', 'World Bake', width=400, height=175, info='''Select objects, bake to locators in world, camera, or custom space.
When you're ready to bake back, select locators
and bake "from locators" to re-apply your animation.''') as win:
mc.checkBoxGrp('ml_worldBake_bakeOnOnes_checkBox',label='Bake on Ones',
annotation='Bake every frame. If deselected, the tool will preserve keytimes.')
tabs = mc.tabLayout()
tab1 = mc.columnLayout(adj=True)
mc.radioButtonGrp('ml_worldBake_space_radioButton', label='Bake To Space', numberOfRadioButtons=3,
labelArray3=('World','Camera','Last Selected'), select=1,
annotation='The locators will be parented to world, the current camera, or the last selection.')
mc.checkBoxGrp('ml_worldBake_constrain_checkBox',label='Maintain Constraints',
annotation='Constrain source nodes to the created locators, after baking.')
win.ButtonWithPopup(label='Bake Selection To Locators', command=toLocators, annotation='Bake selected object to locators specified space.',
readUI_toArgs={'bakeOnOnes':'ml_worldBake_bakeOnOnes_checkBox',
'spaceInt':'ml_worldBake_space_radioButton',
'constrainSource':'ml_worldBake_constrain_checkBox'},
name=win.name)#this last arg is temp..
mc.setParent('..')
tab2 = mc.columnLayout(adj=True)
win.ButtonWithPopup(label='Bake Selected Locators Back To Objects', command=fromLocators, annotation='Bake from selected locators back to their source objects.',
readUI_toArgs={'bakeOnOnes':'ml_worldBake_bakeOnOnes_checkBox'}, name=win.name)#this last arg is temp..
mc.setParent('..')
tab3 = mc.columnLayout(adj=True)
win.ButtonWithPopup(label='Re-Parent Animated', command=reparent, annotation='Parent all selected nodes to the last selection.',
readUI_toArgs={'bakeOnOnes':'ml_worldBake_bakeOnOnes_checkBox'}, name=win.name)
win.ButtonWithPopup(label='Un-Parent Animated', command=unparent, annotation='Parent all selected to world.',
readUI_toArgs={'bakeOnOnes':'ml_worldBake_bakeOnOnes_checkBox'}, name=win.name)
mc.separator()
mc.checkBoxGrp('ml_worldBake_maintainOffset_checkBox',label='Maintain Offset',
annotation='Maintain the offset between nodes, rather than snapping.')
win.ButtonWithPopup(label='Bake Selected', command=utl.matchBake, annotation='Bake from the first selected object directly to the second.',
readUI_toArgs={'bakeOnOnes':'ml_worldBake_bakeOnOnes_checkBox',
'maintainOffset':'ml_worldBake_maintainOffset_checkBox'}, name=win.name)
mc.tabLayout( tabs, edit=True, tabLabel=((tab1, 'Bake To Locators'), (tab2, 'Bake From Locators'), (tab3, 'Bake Selection')) )
# win.ButtonWithPopup(label='Bake Selected With Offset', command=matchBake, annotation='Bake from the first selected object directly to the second, maintaining offset.',
# readUI_toArgs={'bakeOnOnes':'ml_worldBake_bakeOnOnes_checkBox'}, name=win.name)#this last arg is temp..
def toLocators(bakeOnOnes=False, space='world', spaceInt=None, constrainSource=False):
'''
Creates locators, and bakes their position to selection.
Creates connections to the source objects, so they can
be found later to bake back.
'''
if spaceInt and 0 <= spaceInt <= 2:
space = ['world', 'camera', 'last'][spaceInt]
sel = mc.ls(sl=True)
parent = None
if space == 'camera':
parent = utl.getCurrentCamera()
elif space == 'last':
parent = sel[-1]
sel = sel[:-1]
mc.select(sel)
matchBakeLocators(parent=parent, bakeOnOnes=bakeOnOnes, constrainSource=constrainSource)
def fromLocators(bakeOnOnes=False):
'''
Traces connections from selected locators to their source nodes, and
bakes their position back.
Arguments:
bakeOnOnes :: Bool :: Preserve the original keytimes from the locator.
'''
#get neccesary nodes
objs = mc.ls(sl=True)
if not objs:
OpenMaya.MGlobal.displayWarning('Select a previously baked locator.')
return
source = list()
destination = list()
for src in objs:
try:
dest = mc.listConnections(src+'.ml_bakeSource',destination=False)[0]
if dest:
source.append(src)
destination.append(dest)
except StandardError:
pass
if not destination:
OpenMaya.MGlobal.displayWarning('Select a previously baked locator.')
return
#delete constraints on destination nodes
for each in destination:
constraints = mc.listConnections(each, source=True, destination=False, type='constraint')
if constraints:
try:
mc.delete(constraints)
except StandardError:
pass
utl.matchBake(source, destination, bakeOnOnes=bakeOnOnes)
for each in source:
mc.delete(each)
def matchBakeLocators(parent=None, bakeOnOnes=False, constrainSource=False):
#get neccesary nodes
objs = mc.ls(sl=True)
if not objs:
OpenMaya.MGlobal.displayWarning('Select an Object')
return
locs = list()
cutIndex = dict()
noKeys = list()
noKeysLoc = list()
for obj in objs:
name = mc.ls(obj, shortNames=True)[0]
if ':' in name:
name = obj.rpartition(':')[-1]
locator = mc.spaceLocator(name='worldBake_'+name+'_#')[0]
mc.setAttr(locator+'.rotateOrder', 3)
mc.addAttr(locator, longName='ml_bakeSource', attributeType='message')
mc.connectAttr('.'.join((obj,'message')), '.'.join((locator,'ml_bakeSource')))
mc.addAttr(locator, longName='ml_bakeSourceName', dataType='string')
mc.setAttr('.'.join((locator,'ml_bakeSourceName')), name, type='string')
if parent:
locator = mc.parent(locator, parent)[0]
locs.append(locator)
#should look through all trans and rot
if not mc.keyframe(obj, query=True, name=True):
noKeys.append(obj)
noKeysLoc.append(locator)
utl.matchBake(objs, locs, bakeOnOnes=bakeOnOnes)
if not bakeOnOnes and noKeys:
utl.matchBake(noKeys, noKeysLoc, bakeOnOnes=True)
if constrainSource:
mc.cutKey(objs)
for loc, obj in zip(locs, objs):
mc.parentConstraint(loc, obj)
def reparent(bakeOnOnes=False):
objs = mc.ls(sl=True)
if not objs or len(objs) < 2:
OpenMaya.MGlobal.displayWarning('Select one or more nodes, followed by the new parent.')
return
parentBake(objs[:-1], objs[-1], bakeOnOnes=bakeOnOnes)
def unparent(bakeOnOnes=False):
objs = mc.ls(sl=True)
if not objs:
OpenMaya.MGlobal.displayWarning('Select one or more nodes to unparent.')
return
parentBake(objs, bakeOnOnes=bakeOnOnes)
def parentBake(objs, parent=None, bakeOnOnes=False):
#check objects can be parented
parentReferenced = mc.referenceQuery(parent, isNodeReferenced=True) if parent else False
culledObjs = []
for each in objs:
eachParent = mc.listRelatives(each, parent=True)
if mc.referenceQuery(each, isNodeReferenced=True):
if parentReferenced:
OpenMaya.MGlobal.displayWarning("Child and parent are both referenced, skipping: {} > {}".format(each, parent))
continue
if eachParent and mc.referenceQuery(eachParent[0], isNodeReferenced=True):
OpenMaya.MGlobal.displayWarning("Node is referenced and can't be reparented, skipping: {}".format(each))
continue
if not parent and not eachParent:
OpenMaya.MGlobal.displayWarning("Node is already child of the world, skipping: {}".format(each))
continue
culledObjs.append(each)
if not culledObjs:
OpenMaya.MGlobal.displayWarning("No nodes could be reparented.")
return
source = []
destination = []
for each in culledObjs:
source.append(mc.duplicate(each, parentOnly=True)[0])
mc.copyKey(each)
mc.pasteKey(source[-1], option='replaceCompletely')
try:
if parent:
destination.append(mc.parent(each, parent)[0])
else:
destination.append(mc.parent(each, world=True)[0])
except RuntimeError as err:
mc.delete(source)
raise err
utl.matchBake(source=source, destination=destination, bakeOnOnes=bakeOnOnes)
mc.delete(source)
def mm_matchLocators(*args):
matchBakeLocators()
def mm_matchLocatorsOnes(*args):
matchBakeLocators(bakeOnOnes=True)
def mm_fromLocators(*args):
fromLocators()
def mm_reparent(*args):
reparent()
def mm_unparent(*args):
unparent()
def markingMenu():
menuKwargs = {'enable':True,
'subMenu':False,
'enableCommandRepeat':True,
'optionBox':False,
'boldFont':True}
mc.menuItem(radialPosition='N', label='Bake To Locators', command=mm_matchLocators, **menuKwargs)
mc.menuItem(radialPosition='NW', label='Bake To Locators (Ones)', command=mm_matchLocatorsOnes, **menuKwargs)
mc.menuItem(radialPosition='W', label='Bake From Locators', command=mm_fromLocators, **menuKwargs)
mc.menuItem(radialPosition='E', label='Re-Parent', command=mm_reparent, **menuKwargs)
mc.menuItem(radialPosition='S', label='Un-Parent', command=mm_unparent, **menuKwargs)
mc.menuItem(label='World Bake UI', command=ui, **menuKwargs)
if __name__ == '__main__':
#matchBakeLocators(constrainSource=True)
ui()
# ______________________
# - -/__ Revision History __/- - - - - - - - - - - - - - - - - - - - - - - -
#
# Revision 1: : First publish
#
# Revision 6: : Updated to use ml_utilities. Changed from direct constraint to constrained duplicate node.
#
# Revision 7: 2011-05-13 : fixed a bug with transferring certain types of tangents.
#
# Revision 8: 2011-05-14 : fixed error baking things with transforms locked or hidden
#
# Revision 9: 2012-06-13 : fixing duplicate name bug, adding more error checking.
#
# Revision 10: 2012-11-15 : Converting UI to tabs, adding camera and explicit options.
#
# Revision 11: 2014-03-01 : adding category
#
# Revision 12: 2015-05-14 : Baking broken out and moved to ml_utilities
#
# Revision 13: 2018-02-17 : Updating license to MIT.
#
# Revision 14: 2018-06-27 : parenting options and marking menu
#
# Revision 15: 2018-07-18 : marking menu
//snap
global proc kr_snap() {
//geting the list of selected objects
string $sel[] = `ls -sl`;
string $sel1= $sel[0];
string $sel2= $sel[1];
select -clear;
//selecting the objects in reverse order
select $sel2;
select -add $sel1;
//Snaping
parentConstraint -weight 1;
//select -d $sel[1];
select -clear;
//select -d $sel[1];
select $sel1;
delete -constraints;
}
//some old script
/*
global proc kr_sceneready() {
//Geting panel ID
string $panelid = `getPanel -wf`;
print $panelid;
//Hiding stuff
modelEditor -e -allObjects 0 $panelid;
modelEditor -e -controllers true $panelid;
toggleNurbsCurvesOption;
togglePolygonsOption;
modelEditor -e -locators true $panelid;
}
*/
//***********************************************//
// //
// Overlapper release 1.1.2 //
// Tool for creating overlapping action //
// copyright Dmitrii Kolpakov 2018 //
// //
//***********************************************//
global proc OverlapperRelease()
{
optionVar -intValue animBlendingOpt 1;
if ((`window -ex OverlapperPanel`)==true)
deleteUI OverlapperPanel;
CleanUpProc;
string $window = `window -title "Overlapper 1.1.2"
-toolbox 1
-s 1
-menuBar 1
-widthHeight 172 133
OverlapperPanel`;
menu -l "Advanced" -to 0 aboutMenu;
menuItem -l "Debug mode" -cb 0 -ann "Don't delete Overlapping offset controls. Expert mode. Be careful" debMode;
menuItem -l "Bake on anim layer" -cb 0 -ann "Each new overlapping animation will be baked on new animation layer" onLayerMode;
menuItem -l "Adaptive scale" -cb 1 -ann "Overlap Scale parameter automaticly changes for distance between selected controls" adScaleMode;
menuItem -l "Create selection set" -cb 1 -ann "Create selection set of overlapped controls for last overlapper session" ovCrSelSet;
menuItem -l "Delete redundant" -cb 0 -ann "Delete all redundant keys on ovelapped controls" DelRed;
menuItem -l "CleanUp" -ann "Delete all Oveplapper stuff" -c CleanUpProc;
menu -l "Help" -to 0 helpMenu;
menuItem -l "Intro" -c hIntro;
menuItem -l "Tutorial" -c hTutorial;
columnLayout;
rowColumnLayout -nc 2 ;
text -label " Softness " -align "center" -ann "More animation velocity, less softness";
floatField -v 3 -w 10 -precision 2 timeShift;
text -label " Scale " -align "center" -ann "More Scale, more overlap apmlitude";
floatField -v 1.0 -w 10 -precision 2 globalScale;
rowColumnLayout -nc 1;
rowColumnLayout -nc 1;
checkBox -ann "Add wind animation on overlapped controls" -label " Wind" -v 0 -h 18 WindCheckBox;
setParent..;
setParent..;
rowColumnLayout -nc 2;
text -label " Scale" -align "center" -ann "More Scale, more wind apmlitude";
floatField -v 1 -w 48 -bgc 0.45 0.52 0.57 -precision 2 windScale;
text -label " Speed " -align "center" -ann "More Speed, more wind frequence";
floatField -v 1 -w 20 -precision 2 -bgc 0.45 0.52 0.57 windSpeed;
setParent..; setParent..; setParent..;
rowColumnLayout -nc 1;
string $theLayout =`frameLayout -cc OverlapperPanelBig -ec OverlapperPanelSmall -collapsable 1 - collapse 1 -l "Options"`;
checkBox -l "Don't use first controls" -v 0 -ann "Don't use first controls in selected sequence of controls" firstCtrl;
checkBox -l "Add translate" -v 0 -ann "Add translate overlap for selected controls" IKmode;
checkBox -l "Hierarchy" -v 0 -ann "Add all controls below the hierarchy. Works with Advanced Skeleton rigs" HierarchyCheckBox;
checkBox -l "Cycle" -v 0 -ann "Create seamless overlapping action for cycle animation. The first and the last keys on timeline must be the same" CycleCheckBox;
setParent..;
button -w 160 -label "Overlap" -bgc 0.85 0.85 0.85 -command "OverlapperStarter";
showWindow $window;
window -edit -widthHeight 163 163 OverlapperPanel;
}
global proc OverlapperPanelBig()
{window -edit -widthHeight 163 163 OverlapperPanel;}
global proc OverlapperPanelSmall()
{window -edit -widthHeight 163 236 OverlapperPanel;}
proc hIntro()
{launch -web "https://vimeo.com/286860063";}
proc hTutorial()
{launch -web "https://vimeo.com/287771379";}
global proc CleanUpProc()
{
if(`objExists "*_OverlapJoint*"`) {delete "*_OverlapJoint*";}
if(`objExists "*:*_OverlapJoint*"`) {delete "*:*_OverlapJoint*";}
if(`objExists "*:*:*_OverlapJoint*"`) {delete "*:*:*_OverlapJoint*";}
if(`objExists "*overlapOffsetLocator*"`) {delete "*overlapOffsetLocator*";}
if(`objExists "overlapResultLocatorOut*"`) {delete "overlapResultLocatorOut*";}
if(`objExists "TEMP_Offset_locator*"`) {delete ("TEMP_Offset_locator*");}
if(`objExists "*overlapOffsetIKLocator*"`) {delete "*overlapOffsetIKLocator*";}
if(`objExists "OverlapperSet"`) {delete "OverlapperSet";}
if(`objExists "OverlapperWorkSet"`) {delete "OverlapperWorkSet";}
progressWindow -endProgress;
}
global proc OverlapperStarter()
{
float $startTime = `timerX`;
if(`objExists "OverlapperWorkSet"`){delete "OverlapperWorkSet";}
//time range
global string $gPlayBackSlider;
global string $FirstSelectedCtrl;
global int $timeStart, $timeEnd;
global int $timeStartGlobal, $timeEndGlobal;
float $RangeStart, $Range[];
float $totalTime;
$Range = `timeControl -q -ra $gPlayBackSlider`;
$RangeStart = $Range[1] - $Range[0];
int $RangeStartInt = $RangeStart;
if($RangeStartInt == 1)
{$timeStartGlobal = `playbackOptions -q -min`; $timeEndGlobal = `playbackOptions -q -max`;}
else
{$timeStartGlobal = $Range[0]; $timeEndGlobal = $Range[1];}
string $ctrlsAmount[] = `ls -sl`;
$FirstSelectedCtrl = $ctrlsAmount[0];
// MANY CONTROLS
if(`size($ctrlsAmount)`>1)
{
// some ctrls with hierarchy
if (`checkBox -q -v HierarchyCheckBox`==1)
{
for ($SelCtrl in $ctrlsAmount)
{
select -r $SelCtrl; progressWindow -endProgress; OverlapperWithHierarchy; CycleFinal;
}
}
// some ctrls without hierarchy
else
{
Overlapper; CycleFinal;
}
}
// ONE CONTROLS
else {
// with hierarchy
if (`checkBox -q -v HierarchyCheckBox`==1)
{
progressWindow -endProgress; OverlapperWithHierarchy; CycleFinal;
}
// without hierarchy
else
{
confirmDialog -b "Ok" -t "Oooops.." -m "For correct work you should select more than one control \n or switch on Hierarchy mode in Options \n\nIf you want overlap one control: \n 1. select two neighboring controls \n 2. check `Don't use first control` in Options ";
}
}
$totalTime = `timerX -startTime $startTime`;
print ("Total Overlapper Time: "+$totalTime+" seconds"+"\n");
}
////////////////// Hierarchy work //////////////////////
proc OverlapperWithHierarchy()
{
string $ArraySecondGuys[];
string $parentArray[];
string $nodesArray[];
string $Chain[];
string $lastElement;
string $allSceneNurbes[];
string $currentShapeType;
string $CtrlByHierarchy[];
string $TypeOfObject;
int $ClearElemwnts;
clear ($allSceneNurbes);
// find type of selection
string $currentCtrls[] = `ls -sl`;
select -r $currentCtrls[0];
pickWalk -d down;
string $currentShape[] = `ls -sl`;
$currentShapeType = `objectType $currentShape[0]`;
select -r $currentCtrls; select -hi;
$currentCtrls = `ls -sl`;
if( `objExists "*Root_M"`||`objExists "*:Root_M"`||`objExists "*DeformationSystem"`||`objExists "*:DeformationSystem"`||`objExists "*MotionSystem"`||`objExists "*:MotionSystem"`||`objExists "*FitSkeleton"`||`objExists "*:FitSkeleton"`)
{$currentShapeType = "nurbsCurve";}
$allSceneNurbes = `listTransforms ("-type "+$currentShapeType)`;
string $Stuff[] = stringArrayRemove($allSceneNurbes, $currentCtrls);
$CtrlByHierarchy = stringArrayRemove($Stuff, $currentCtrls);
select -r $CtrlByHierarchy;
int $amountOfAllCtrls = `size($CtrlByHierarchy)`;
string $LastCtrlInHierarchy = $CtrlByHierarchy[(`size($CtrlByHierarchy)`)-1];
clear ($Chain);
for ($i=0; $i<$amountOfAllCtrls; ++$i )
{
select -r $CtrlByHierarchy[$i];
select -hi;
string $currentCtrls[] = `ls -sl`;
string $Stuff[] = stringArrayRemove($allSceneNurbes, $currentCtrls);
string $CurrentCtrlByHierarchy[] = stringArrayRemove($Stuff, $currentCtrls);
if ($CtrlByHierarchy[$i+1]==$CurrentCtrlByHierarchy[1]&&$CurrentCtrlByHierarchy[0]!=$LastCtrlInHierarchy)
{
stringArrayInsertAtIndex(100, $Chain, $CurrentCtrlByHierarchy[0]);
select -r $CurrentCtrlByHierarchy[0];
}
else
{
stringArrayInsertAtIndex(100, $Chain, $CurrentCtrlByHierarchy[0]);
select -r $Chain;
Overlapper;
string $CtrlByHierarchy[] = stringArrayRemove($Chain, $CtrlByHierarchy); clear ($Chain);
}
int $amountOfAllCtrls = `size($CtrlByHierarchy)`;
}
}
///////////// Overlapper /////////////
proc Overlapper()
{
cycleCheck -e 1;
global int $timeStartGlobal, $timeEndGlobal;
global int $timeStart, $timeEnd;
$timeStart = $timeStartGlobal;
$timeEnd = $timeEndGlobal;
int $ClearElemwnts;
float $OverTimeShift = `floatField -q -v timeShift`;
float $OverGlobalScale = `floatField -q -v globalScale`;
if($OverGlobalScale<=0){$OverGlobalScale=0.001;}
float $windScaleValue = `floatField -q -v windScale`;
float $windSpeedValue = `floatField -q -v windSpeed`;
int $deBugMode = `menuItem -query -cb debMode`;
int $onLayerSwitch = `menuItem -query -cb onLayerMode`;
int $adptScale = `menuItem -query -cb adScaleMode`;
int $OvSelectionSet = `menuItem -query -cb ovCrSelSet`;
int $TRANSLATEmode = `checkBox -q -v IKmode`;
int $DoNotUseFirstCtrl = `checkBox -q -v firstCtrl`;
int $WindSwitch = `checkBox -q -v WindCheckBox`;
int $CycleCheckBox = `checkBox -q -v CycleCheckBox`;
float $timeShift = $OverTimeShift;
float $overlapIntensity = $OverGlobalScale;
float $scaleModulator = 5;
string $overlapJointsArray[];
float $overlapJointsLenghtArray[];
float $averageLenghtJoints;
global float $sumLenghtJoints;
string $ControlName[];
float $cycleLenghts;
string $SelectedControlsClearNameSpaces[];
string $SelectedControls[];
global string $eulerFilterCurves[];
global string $FirstSelectedCtrl;
int $TRmode;
int $w;
string $CurentWindControl;
clear ($overlapJointsArray);
clear ($overlapJointsLenghtArray);
clear ($SelectedControls);
clear ($SelectedControlsClearNameSpaces);
//time range
float $currentTime =`currentTime -query`;
//set frame
currentTime - e $timeStart;
$SelectedControls = `ls -sl`;
int $iLoop = `size($SelectedControls)`;
$DividedName = `tokenize $SelectedControls[0] ":" $ControlName`;
if ($DividedName>1)
{
for ($i=0; $i<$iLoop; ++$i)
{
$DividedNameCurve = `tokenize $SelectedControls[$i] ":" $ControlName`;
$ClearNameCtrl = $ControlName[($DividedNameCurve-1)];
stringArrayInsertAtIndex(100, $SelectedControlsClearNameSpaces, $ClearNameCtrl);
}
}
else {$SelectedControlsClearNameSpaces=$SelectedControls;}
select -cl;
//progressBar
int $amount = 0;
float $prAmount = 100/$iLoop;
progressWindow
-title "progress..."
-progress $amount
-status "Progress: 0%"
-isInterruptable true;
// create locators for Joints
for ($i=0; $i<$iLoop; ++$i)
{
spaceLocator -n ("TEMP_Offset_locator"+$i);
select -r $SelectedControls[$i] ("TEMP_Offset_locator"+$i);
parentConstraint -weight 1;
}
select -cl;
// create Joints
for ($i=0; $i<$iLoop; ++$i )
{
float $WorldTr[] = `xform -q -ws -t ("TEMP_Offset_locator"+$i)`;
joint -rad 1 -n ($SelectedControls[$i]+"_OverlapJoint") -p $WorldTr[0] $WorldTr[1] $WorldTr[2];
if ($i>0)
{
joint -e -zso -oj xyz -sao yup ($SelectedControls[$i-1]+"_OverlapJoint");
}
stringArrayInsertAtIndex( 100, $overlapJointsArray, ($SelectedControls[$i]+"_OverlapJoint") );
}
delete ("TEMP_Offset_locator*");
int $overlapJointsAnmount = `size($SelectedControls)`;
select -r ($overlapJointsArray[$overlapJointsAnmount-1]);
duplicate -rr;
string $LastOrientJoints[] = `ls -sl`;
move -r -ls -wd 2 0 0 ;
float $WorldLastTr[] = `xform -q -ws -t $LastOrientJoints[0]`;
select -r ($SelectedControls[$i-1]+"_OverlapJoint");
joint -rad 1 -n ($SelectedControls[$i-1]+"LastOrientJoint") -p $WorldLastTr[0] $WorldLastTr[1] $WorldLastTr[2];
joint -e -zso -oj xyz -sao yup ($SelectedControls[$i-1]+"_OverlapJoint");
delete $LastOrientJoints;
$LastOrientJoints = `ls -sl`;
stringArrayInsertAtIndex( 100, $overlapJointsArray, $LastOrientJoints[0]);
select -r $overlapJointsArray;
joint -e -oj xyz -secondaryAxisOrient zup -ch -zso;
clear ($overlapJointsLenghtArray);
//joints lengths
for ($i=1; $i<($iLoop+1); ++$i )
{
float $DistanceBetween = `getAttr ($overlapJointsArray[$i]+".translateX")`;
floatArrayInsertAtIndex( 100, $overlapJointsLenghtArray, $DistanceBetween);
}
//average
int $JointsLentghtsAmount = `size($overlapJointsLenghtArray)`;
$sumLenghtJoints = 0;
for ($i=0; $i<($JointsLentghtsAmount); ++$i )
{
$sumLenghtJoints = $sumLenghtJoints + $overlapJointsLenghtArray[$i];
}
$averageLenghtJoints = ($sumLenghtJoints-2)/$JointsLentghtsAmount;
setAttr ($SelectedControls[$i-1]+"LastOrientJoint.translateX") $averageLenghtJoints;
// constrain joint to controls
for ($i=0; $i<$iLoop; ++$i)
{
select -r $SelectedControls[$i] ($SelectedControls[$i]+"_OverlapJoint");
pointConstraint -weight 1 -mo;
orientConstraint -weight 1 -mo;
}
// bake jonts
select -r $overlapJointsArray;
bakeResults
-simulation 0
-t ($timeStart+":"+$timeEnd)
-sampleBy 1
-disableImplicitControl 1
-preserveOutsideKeys 1
-sparseAnimCurveBake 0
-bakeOnOverrideLayer 0
-minimizeRotation 0
$overlapJointsArray;
delete -constraints;
// Cycling (copy curves, add time)
if ($CycleCheckBox == 1)
{
if ($DoNotUseFirstCtrl==1)
{
for ($i=1; $i<($iLoop); ++$i )
{
selectKey -r -k -t ($timeStart+":"+$timeEnd) ($SelectedControlsClearNameSpaces[$i]+"_OverlapJoint_translateX")
($SelectedControlsClearNameSpaces[$i]+"_OverlapJoint_translateY")
($SelectedControlsClearNameSpaces[$i]+"_OverlapJoint_translateZ")
($SelectedControlsClearNameSpaces[$i]+"_OverlapJoint_rotateX")
($SelectedControlsClearNameSpaces[$i]+"_OverlapJoint_rotateY")
($SelectedControlsClearNameSpaces[$i]+"_OverlapJoint_rotateZ");
copyKey;
pasteKey -time $timeEnd -float $timeEnd -option insert -copies 2 -connect 0 -timeOffset 0 -floatOffset 0 -valueOffset 0;
select -cl ;
}
}
else
{
for ($i=0; $i<($iLoop-1); ++$i )
{
selectKey -r -k -t ($timeStart+":"+$timeEnd) ($SelectedControlsClearNameSpaces[$i]+"_OverlapJoint_translateX")
($SelectedControlsClearNameSpaces[$i]+"_OverlapJoint_translateY")
($SelectedControlsClearNameSpaces[$i]+"_OverlapJoint_translateZ")
($SelectedControlsClearNameSpaces[$i]+"_OverlapJoint_rotateX")
($SelectedControlsClearNameSpaces[$i]+"_OverlapJoint_rotateY")
($SelectedControlsClearNameSpaces[$i]+"_OverlapJoint_rotateZ");
copyKey;
pasteKey -time $timeEnd -float $timeEnd -option insert -copies 2 -connect 0 -timeOffset 0 -floatOffset 0 -valueOffset 0;
select -cl ;
}
}
$cycleLenghts = $timeEnd-$timeStart;
$timeEnd = $timeEnd+2*$cycleLenghts;
}
if($DoNotUseFirstCtrl==1) {$TRmode=1;} else {$TRmode=0;}
// Overlaping
for ($i=$TRmode; $i<$iLoop; ++$i )
{
//progressBar
$amount += $prAmount;
progressWindow -edit
-progress $amount
-status ("Progress: "+$amount+"%");
//create locator
spaceLocator -n ("overlapOffsetLocator"+$i);
select -r $overlapJointsArray[$i] ("overlapOffsetLocator"+$i);
string $temps[] = `pointConstraint -offset 0 0 0 -weight 1`;
delete $temps;
$temps = `orientConstraint -offset 0 0 0 -weight 1`;
delete $temps;
//create IK locator
spaceLocator -n ("overlapOffsetIKLocator"+$i);
select -r $overlapJointsArray[$i] ("overlapOffsetIKLocator"+$i);
$temps = `pointConstraint -offset 0 0 0 -weight 1`;
delete $temps;
$temps = `orientConstraint -offset 0 0 0 -weight 1`;
delete $temps;
select -r ("overlapOffsetLocator"+$i);
if ($adptScale==1){$scaleModulator = $averageLenghtJoints;}
$overlapIntensityMult = $averageLenghtJoints/$overlapIntensity*5;
move -r -os -ls $overlapIntensityMult 0 0 ;
select -r $overlapJointsArray[$i] ("overlapOffsetLocator"+$i);
parentConstraint -mo -weight 1;
select -r $overlapJointsArray[$i] ("overlapOffsetIKLocator"+$i);
parentConstraint -mo -weight 1;
bakeResults -simulation 0
-t ($timeStart+":"+$timeEnd)
-sampleBy 1
-disableImplicitControl 1
-preserveOutsideKeys 1
-sparseAnimCurveBake 0
-bakeOnOverrideLayer 0
-minimizeRotation 0
-controlPoints 0
-at "tx"
-at "ty"
-at "tz"
-at "rx"
-at "ry"
-at "rz"
-shape 0
("overlapOffsetLocator"+$i) ("overlapOffsetIKLocator"+$i);
filterCurve ("overlapOffsetLocator"+$i+"_rotateX")("overlapOffsetLocator"+$i+"_rotateY")("overlapOffsetLocator"+$i+"_rotateZ");
spaceLocator -n ("overlapOffsetLocatorWind"+$i);
parent ("overlapOffsetLocatorWind"+$i) ("overlapOffsetLocator"+$i);
makeIdentity -apply false -t 1 -r 1 -s 1;
float $timeShiftNeg = -1*$timeShift;
float $timeShiftCurrent = $timeShift+1;
keyframe -e -iub true -r -o over -tc $timeShift ("overlapOffsetLocator"+$i+"_translateX");
keyframe -e -iub true -r -o over -tc $timeShift ("overlapOffsetLocator"+$i+"_translateY");
keyframe -e -iub true -r -o over -tc $timeShift ("overlapOffsetLocator"+$i+"_translateZ");
keyframe -e -iub true -r -o over -tc $timeShift ("overlapOffsetIKLocator"+$i+"_translateX");
keyframe -e -iub true -r -o over -tc $timeShift ("overlapOffsetIKLocator"+$i+"_translateY");
keyframe -e -iub true -r -o over -tc $timeShift ("overlapOffsetIKLocator"+$i+"_translateZ");
keyframe -e -iub true -r -o over -tc ($timeShift*$OverGlobalScale) ("overlapOffsetLocator"+$i+"_rotateX");
keyframe -e -iub true -r -o over -tc ($timeShift*$OverGlobalScale) ("overlapOffsetLocator"+$i+"_rotateY");
keyframe -e -iub true -r -o over -tc ($timeShift*$OverGlobalScale) ("overlapOffsetLocator"+$i+"_rotateZ");
selectKey -add -k -t $timeShiftCurrent ("overlapOffsetLocator"+$i+"_translateX");
selectKey -add -k -t $timeShiftCurrent ("overlapOffsetLocator"+$i+"_translateY");
selectKey -add -k -t $timeShiftCurrent ("overlapOffsetLocator"+$i+"_translateZ");
selectKey -add -k -t $timeShiftCurrent ("overlapOffsetIKLocator"+$i+"_translateX");
selectKey -add -k -t $timeShiftCurrent ("overlapOffsetIKLocator"+$i+"_translateY");
selectKey -add -k -t $timeShiftCurrent ("overlapOffsetIKLocator"+$i+"_translateZ");
selectKey -add -k -t ($timeShiftCurrent*$OverGlobalScale) ("overlapOffsetLocator"+$i+"_rotateX");
selectKey -add -k -t ($timeShiftCurrent*$OverGlobalScale) ("overlapOffsetLocator"+$i+"_rotateY");
selectKey -add -k -t ($timeShiftCurrent*$OverGlobalScale) ("overlapOffsetLocator"+$i+"_rotateZ");
keyframe -animation keys -option over -relative -timeChange $timeShiftNeg;
spaceLocator -n ("overlapInLocator_first_"+$i);
spaceLocator -n ("overlapInLocator_second_"+$i);
spaceLocator -n ("overlapResultLocator_"+$i);
parent ("overlapInLocator_first_"+$i) ($SelectedControls[$i]+"_OverlapJoint");
parent ("overlapInLocator_second_"+$i) ($SelectedControls[$i]+"_OverlapJoint");
parent ("overlapResultLocator_"+$i) ($SelectedControls[$i]+"_OverlapJoint");
select -r ("overlapInLocator_first_"+$i) ("overlapInLocator_second_"+$i) ("overlapResultLocator_"+$i);
makeIdentity -apply false -t 1 -r 1 -s 1;
select -r("overlapInLocator_second_"+$i);
move -r -os -ls $overlapIntensityMult 0 0 ;
select -r ("overlapInLocator_first_"+$i);
group -n ("overlapInLocator_first_"+$i+"grp");
// IK mode
if($TRANSLATEmode==1)
{
select -r ("overlapOffsetIKLocator"+$i) ("overlapInLocator_first_"+$i+"grp");
pointConstraint -mo -weight 1;
}
select -r ("overlapOffsetLocatorWind"+$i) ("overlapInLocator_second_"+$i);
parentConstraint -mo -weight 1;
select -r ("overlapInLocator_second_"+$i) ("overlapInLocator_first_"+$i+"grp");
aimConstraint -mo -weight 1 -aimVector 1 0 0 -upVector 0 1 0 -worldUpType "object" -worldUpObject ("overlapInLocator_second_"+$i);
select -r ("overlapInLocator_second_"+$i) ("overlapInLocator_first_"+$i);
orientConstraint -mo -skip y -skip z -weight 1;
select -r ("overlapInLocator_first_"+$i) ("overlapResultLocator_"+$i);
parentConstraint -mo -weight 1;
///Wind
if($DoNotUseFirstCtrl==1) {$w=$i-1;} else {$w=$i;}
if($w<1&&$WindSwitch==1)
{
string $CurentWindControl;
if($DoNotUseFirstCtrl==1) {$CurentWindControl = "overlapOffsetLocatorWind1";}
else {$CurentWindControl = "overlapOffsetLocatorWind0";}
select -r $CurentWindControl;
float $windMultiply = 0.07*$overlapIntensityMult*$windScaleValue ;
float $speedMultiply = 20/$windSpeedValue;
setKeyframe -attribute "translateY" -attribute "translateZ" -t $timeStart $CurentWindControl;
bakeResults
-simulation 0
-t ($timeStart+":"+($timeEnd+$speedMultiply))
-sampleBy $speedMultiply
-disableImplicitControl 1
-preserveOutsideKeys 1
-sparseAnimCurveBake 0
-bakeOnOverrideLayer 0
-minimizeRotation 0
-at "ty"
-at "tz"
$CurentWindControl;
string $listAnimAttrs[] = `listAttr -k $CurentWindControl`;
for ($attr in $listAnimAttrs)
{
// array of animated atributes
string $animCurve[] = `listConnections -type "animCurve" ($CurentWindControl+"."+$attr)`;
for ($animCurveCurrent in $animCurve)
{
// array of keys
float $animCurveCurrentKeysTimeArray[] = `keyframe -time ($timeStart+":"+$timeEnd) -query -timeChange $animCurveCurrent`;
// array of values
for ($animCurveCurrentKeysTime in $animCurveCurrentKeysTimeArray)
{
float $animCurveCurrentKeysTimeArray[] = `keyframe -time $animCurveCurrentKeysTime -query -valueChange $animCurveCurrent`;
//Randomazer
float $RandomizerValue = `rand -1 1`;
float $animCurveCurrentKeysValueArrayAddRandom = $animCurveCurrentKeysTimeArray[0]+$windMultiply*$RandomizerValue;
keyframe -e -iub true -r -o over -vc $animCurveCurrentKeysValueArrayAddRandom -t $animCurveCurrentKeysTime $animCurveCurrent;
}
}
}
keyframe -e -iub true -r -o over -tc ($speedMultiply/2) ($CurentWindControl+"_translateY");
selectKey -add -k -t (($speedMultiply/2)+1) ($CurentWindControl+"_translateY");
keyframe -animation keys -option over -relative -timeChange ($speedMultiply/-2);
if ($CycleCheckBox == 1)
{
selectKey -add -k -t $timeStart ($CurentWindControl+"_translateY");
selectKey -add -k -t $timeStart ($CurentWindControl+"_translateZ");
pasteKey -time $timeEnd -float $timeEnd -option insert -copies 1 -connect 0 -timeOffset 0 -floatOffset 0 -valueOffset 0 ($CurentWindControl+"_translateY");
pasteKey -time $timeEnd -float $timeEnd-option insert -copies 1 -connect 0 -timeOffset 0 -floatOffset 0 -valueOffset 0 ($CurentWindControl+"_translateZ");
}
}
bakeResults -simulation 0
-t ($timeStart+":"+$timeEnd)
-sampleBy 1
-disableImplicitControl 1
-preserveOutsideKeys 1
-sparseAnimCurveBake 0
-bakeOnOverrideLayer 0
-minimizeRotation 0
-controlPoints 0
-shape 1
("overlapResultLocator_"+$i);
if($deBugMode==0) {delete ("overlapInLocator_first_"+$i) ("overlapInLocator_first_"+$i+"grp") ("overlapOffsetLocator"+$i) ("overlapInLocator_second_"+$i);}
spaceLocator -n ("overlapResultLocatorOut_"+$i);
if(`objExists "OverlapperOverlapResultLocatorSet"`) {sets -edit -forceElement OverlapperOverlapResultLocatorSet ("overlapResultLocatorOut_"+$i);}
else {$createSetResult = `sets -name "OverlapperOverlapResultLocatorSet"`;}
select -r ("overlapResultLocator_"+$i) ("overlapResultLocatorOut_"+$i);
parentConstraint -weight 1;
bakeResults -simulation 0
-t ($timeStart+":"+$timeEnd)
-sampleBy 1
-disableImplicitControl 1
-preserveOutsideKeys 1
-sparseAnimCurveBake 0
-bakeOnOverrideLayer 0
-minimizeRotation 0
-controlPoints 0
-shape 1
("overlapResultLocatorOut_"+$i);
if($deBugMode==0) {delete ("overlapResultLocator_"+$i);}
select -r ("overlapResultLocatorOut_"+$i) ($SelectedControls[$i]+"_OverlapJoint");
parentConstraint -weight 1 -mo;
}
// constrain controls back to joint
if ($DoNotUseFirstCtrl==1)
{
for ($i=0; $i<$iLoop; ++$i )
{
//orient constraint
if (`getAttr -keyable ($SelectedControls[$i]+".rx")`==1&&`getAttr -lock ($SelectedControls[$i]+".rx")`==0&&
`getAttr -keyable ($SelectedControls[$i]+".ry")`==1&&`getAttr -lock ($SelectedControls[$i]+".ry")`==0&&
`getAttr -keyable ($SelectedControls[$i]+".rx")`==1&&`getAttr -lock ($SelectedControls[$i]+".rx")`==0)
{select -r ($SelectedControls[$i]+"_OverlapJoint") $SelectedControls[$i]; orientConstraint -mo -weight 1;}
//point constraint
if (`getAttr -keyable ($SelectedControls[$i]+".tx")`==1&&`getAttr -lock ($SelectedControls[$i]+".tx")`==0&&
`getAttr -keyable ($SelectedControls[$i]+".ty")`==1&&`getAttr -lock ($SelectedControls[$i]+".ty")`==0&&
`getAttr -keyable ($SelectedControls[$i]+".tx")`==1&&`getAttr -lock ($SelectedControls[$i]+".tx")`==0&&$TRANSLATEmode==1)
{select -r ($SelectedControls[$i]+"_OverlapJoint") $SelectedControls[$i]; pointConstraint -mo -weight 1;}
}
}
else
{
for ($i=0; $i<$iLoop; ++$i )
{
//orient constraint
if (`getAttr -keyable ($SelectedControls[$i]+".rx")`==1&&`getAttr -lock ($SelectedControls[$i]+".rx")`==0&&
`getAttr -keyable ($SelectedControls[$i]+".ry")`==1&&`getAttr -lock ($SelectedControls[$i]+".ry")`==0&&
`getAttr -keyable ($SelectedControls[$i]+".rx")`==1&&`getAttr -lock ($SelectedControls[$i]+".rx")`==0)
{select -r ($SelectedControls[$i]+"_OverlapJoint") $SelectedControls[$i]; orientConstraint -mo -weight 1;}
//point constraint
if (`getAttr -keyable ($SelectedControls[$i]+".tx")`==1&&`getAttr -lock ($SelectedControls[$i]+".tx")`==0&&
`getAttr -keyable ($SelectedControls[$i]+".ty")`==1&&`getAttr -lock ($SelectedControls[$i]+".ty")`==0&&
`getAttr -keyable ($SelectedControls[$i]+".tx")`==1&&`getAttr -lock ($SelectedControls[$i]+".tx")`==0&&$TRANSLATEmode==1)
{select -r ($SelectedControls[$i]+"_OverlapJoint") $SelectedControls[$i]; pointConstraint -mo -weight 1;}
}
}
if ($CycleCheckBox == 1)
{
$cycleLenghts = $timeEndGlobal-$timeStartGlobal;
select -r OverlapperOverlapResultLocatorSet;
string $EulerArrays[] = `ls -sl`;
for ($obj in $EulerArrays)
{
keyframe -e -iub true -r -o over -tc (-2*$cycleLenghts) ($obj+"_translateX");
keyframe -e -iub true -r -o over -tc (-2*$cycleLenghts) ($obj+"_translateY");
keyframe -e -iub true -r -o over -tc (-2*$cycleLenghts) ($obj+"_translateZ");
keyframe -e -iub true -r -o over -tc (-2*$cycleLenghts) ($obj+"_rotateX");
keyframe -e -iub true -r -o over -tc (-2*$cycleLenghts) ($obj+"_rotateY");
keyframe -e -iub true -r -o over -tc (-2*$cycleLenghts) ($obj+"_rotateZ");
}
}
select -r $SelectedControls;
if ($DoNotUseFirstCtrl==1&&`size($SelectedControls)`>1) {select -d $FirstSelectedCtrl;}
$SelectedControls = `ls -sl`;
if($TRANSLATEmode==1)
{
bakeResults
-simulation 0
-t ($timeStartGlobal+":"+$timeEndGlobal)
-sampleBy 1
-disableImplicitControl 1
-preserveOutsideKeys 1
-sparseAnimCurveBake 0
-bakeOnOverrideLayer $onLayerSwitch
-minimizeRotation 0
-controlPoints 0
-shape 0
-at "tx"
-at "ty"
-at "tz"
-at "rx"
-at "ry"
-at "rz"
$SelectedControls;
}
else
{
bakeResults
-simulation 0
-t ($timeStartGlobal+":"+$timeEndGlobal)
-sampleBy 1
-disableImplicitControl 1
-preserveOutsideKeys 1
-sparseAnimCurveBake 0
-bakeOnOverrideLayer $onLayerSwitch
-minimizeRotation 0
-controlPoints 0
-shape 0
-at "rx"
-at "ry"
-at "rz"
$SelectedControls;
}
//create selection set
if($OvSelectionSet==1)
{
if(`objExists "OverlapperSet*"`) {sets -edit -forceElement OverlapperSet $SelectedControls;}
else {$createSetResult = `sets -name "OverlapperSet"`;}
}
if(`objExists "OverlapperWorkSet*"`) {sets -edit -forceElement OverlapperWorkSet $SelectedControls;}
else {$createSetResult = `sets -name "OverlapperWorkSet"`;}
// finalization
if($deBugMode==0)
{
delete $overlapJointsArray;
if(`objExists "overlapResultLocatorOut*"`) {delete "overlapResultLocatorOut*";}
if(`objExists "*overlapOffsetIKLocator*"`) {delete "*overlapOffsetIKLocator*";}
}
currentTime - e $currentTime;
select -r $SelectedControls;
cycleCheck -e on;
progressWindow -endProgress;
// select ovelapped controls set
if(`objExists "OverlapperSet"`) {select -r OverlapperSet;}
}
// Finalizing
global proc CycleFinal()
{
global int $prefsOption;
string $SelectedControlsClearNameSpaces[];
string $SelectedControls[];
global string $eulerFilterCurves[];
string $ControlName[];
float $cycleLenghts;
float $totalTime;
float $startTime;
int $DelRedMode;
global int $timeStartGlobal, $timeEndGlobal;
global int $timeStart, $timeEnd;
$timeStart = $timeStartGlobal;
$timeEnd = $timeEndGlobal;
$DelRedMode = `menuItem -query -cb DelRed`;
$TRANSLATEmode = `checkBox -q -v IKmode`;
// euler all anim curves
clear ($eulerFilterCurves);
select -r OverlapperWorkSet;
string $EulerArrays[] = `ls -sl`;
for ($obj in $EulerArrays)
{
$listAnimAttrs = `listAttr -k $obj`;
for ($attr in $listAnimAttrs)
{
$animCurve = `listConnections -type "animCurve" ($obj+"."+$attr)`;
int $ClearElemwnts = `size($animCurve)`; appendStringArray($eulerFilterCurves, $animCurve, $ClearElemwnts);
}
}
filterCurve $eulerFilterCurves;
// simplifier
if ($DelRedMode == 1)
{
select -r OverlapperWorkSet;
$SelectedControls = `ls -sl`;
if ($TRANSLATEmode == 1) {selectKey -r -at rx -at ry -at rz -at tx -at ty -at tz -k;}
else {selectKey -r -at rx -at ry -at rz -k;}
string $selectedCurves[] = `keyframe -selected -q -name`;
string $redundantTime = $timeStartGlobal+":"+$timeEndGlobal;
//delete redundant
for ($currentAnimCurve in $selectedCurves)
{
float $allKeys[] = `keyframe -t $redundantTime -q -timeChange $currentAnimCurve`;
$valArray = `keyframe -t $redundantTime -q -valueChange $currentAnimCurve`;
$keysSize = `size($allKeys)`;
for ($s=1; $s<$keysSize-1; ++$s )
{if ($valArray[$s] == $valArray[$s-1]&&$valArray[$s] == $valArray[$s+1]) {cutKey -time $allKeys[$s] -clear $currentAnimCurve;}}
}
}
delete "OverlapperWorkSet";
}
OverlapperRelease;
global proc kr_selgeoonly() {
selectMode -object; selectType -handle 0 -ikHandle 0 -joint 0 -nurbsCurve 0 -cos 0 -stroke 0 -nurbsSurface 1 -polymesh 1 -subdiv 1 -plane 1 -lattice 0 -cluster 0 -sculpt 0 -nonlinear 0 -particleShape 0 -emitter 0 -field 0 -spring 0 -rigidBody 0 -fluid 0 -hairSystem 0 -follicle 0 -nCloth 0 -nRigid 0 -dynamicConstraint 0 -rigidConstraint 0 -collisionModel 0 -light 0 -camera 0 -texture 0 -ikEndEffector 0 -locator 0 -dimension 0;selectType -byName gpuCache 1;
}
global proc kr_selcurvesonly() {
selectMode -object; selectType -handle 0 -ikHandle 0 -joint 0 -nurbsCurve 1 -cos 1 -stroke 1 -nurbsSurface 0 -polymesh 0 -subdiv 0 -plane 0 -lattice 0 -cluster 0 -sculpt 0 -nonlinear 0 -particleShape 0 -emitter 0 -field 0 -spring 0 -rigidBody 0 -fluid 0 -hairSystem 0 -follicle 0 -nCloth 0 -nRigid 0 -dynamicConstraint 0 -rigidConstraint 0 -collisionModel 0 -light 0 -camera 0 -texture 0 -ikEndEffector 0 -locator 1 -dimension 0;selectType -byName gpuCache 0;
}
global proc kr_keymarker() {
//Create KEYS marker
spaceLocator -p 0 0 0;
select -r locator1 ;
rename "locator1" "KEYS";
select KEYS ;
currentTime -101 ;
setKeyframe -breakdown 0 |KEYS.rotate;
currentTime -100 ;
setKeyframe -breakdown 0 |KEYS.rotate;
selectKey -add -k -t -100 KEYS_rotateX ;
selectKey -add -k -t -100 KEYS_rotateY ;
selectKey -add -k -t -100 KEYS_rotateZ ;
keyframe -e -iub true -r -o over -vc 0.180662 -t -100 KEYS_rotateX ;
keyframe -e -iub true -r -o over -vc 0.180662 -t -100 KEYS_rotateY ;
keyframe -e -iub true -r -o over -vc 0.180662 -t -100 KEYS_rotateZ ;
performChangeAnimCurveColor 1 graphEditor1OutlineEd;
}
global proc kr_bakeChan() {
//get selected object names
string $selectedObjt[] = `ls -sl`;
//Get frame range
string $FrameRange = `playbackOptions -q -ast` +":"+ `playbackOptions -q -aet`;
//get selected channelBox attributes
string $selAttr[] = `channelBox -q -sma mainChannelBox`;
//Run bake on each objects
for( $a=0; $a < size($selectedObjt); ++$a )
{
//Baking selected channels
for( $i=0; $i < size($selAttr); ++$i )
{
print $selAttr[$i];
bakeResults -simulation true -t $FrameRange -sampleBy 1 -oversamplingRate 1 -disableImplicitControl true -preserveOutsideKeys true -sparseAnimCurveBake false -removeBakedAttributeFromLayer false -removeBakedAnimFromLayer false -bakeOnOverrideLayer false -minimizeRotation true -at $selAttr[$i] $selectedObjt[$a];
}
}
}
global proc kr_bake() {
//Get frame range
string $FrameRange = `playbackOptions -q -ast` +":"+ `playbackOptions -q -aet`;
//get selected object names
string $selectedObjt[] = `ls -sl`;
//Run bake on each objects
for( $a=0; $a < size($selectedObjt); ++$a )
{
bakeResults -simulation true -t $FrameRange -sampleBy 1 -oversamplingRate 1 -disableImplicitControl true -preserveOutsideKeys true -sparseAnimCurveBake false -removeBakedAttributeFromLayer false -removeBakedAnimFromLayer false -bakeOnOverrideLayer false -minimizeRotation true -controlPoints false -shape true {$selectedObjt[$a]};
}
}
/*
/////////////////////////////////////////////////////////////
ackToggleTranslateMode 1.1
6/1/05
Aaron Koressel
www.aaronkoressel.com
Toggles between local translation and world translation.
CHANGELOG:
7/29/07 1.1
Changed one of the modes to local instead of object.
Local represents the exact channel that is being animated so
it is far more relevant than object translation.
//////////////////////////////////////////////////////////////
*/
global proc ackToggleTranslateMode() {
int $transX = `manipMoveContext -q -mode Move`;
// 0 = Object, 1 = Local, 2 = World, 3 = Normal, 4 = Rotation Axis
if ($transX == 2) {
manipMoveContext -e -mode 1 Move;
} else {
manipMoveContext -e -mode 2 Move;
};
}
//////////////////////////////////////////////////////////
// ackZeroOutKeys 1.0
// 6/2/05
// Aaron Koressel
//
// Zeroes out the values of selected keys in the
// graph editor.
//////////////////////////////////////////////////////////
global proc ackZeroOutKeys() {
//Don't do anything if no keys are selected
$keyCount = `keyframe -an keys -q -kc`;
if ($keyCount != 0) {
keyframe -valueChange 0;
}
}
//////////////////////////////////////////////////////////
// ackToggleRotateMode 1.0
// 6/1/05
// Aaron Koressel
//
// Toggles the rotation tool between local rotation
// and gimbal rotation.
//////////////////////////////////////////////////////////
global proc ackToggleRotateMode() {
int $rotX = `manipRotateContext -q -mode Rotate`;
// 0 = Local, 1 = Global, 2 = Gimbal
if ($rotX == 0) {
manipRotateContext -e -mode 2 Rotate;
} else {
manipRotateContext -e -mode 0 Rotate;
};
}
# making proxy/ sliced/ cut-out rig script made by Truong Cg Artist
# gumroad.com/TruongCgArtist
# thank you Trong Hoan for supporting me during the process of making this script
# facebook.com/dauphairigging
import maya.cmds as cmds
from math import pow, sqrt
import maya.OpenMaya as OpenMaya
import pymel.core as pm
import re
bodyMesh = None
reducePercent = 50
bodyMeshTF = "body_mesh_text_field"
trsUI_ID = "Proxy_Making_script_by_Truong"
mainControl = None
mainControl_tf = "Main_control_text_field"
def autoRenamingDuplicateObjects():
# find and auto fix the all items that have same name
# this function is from Erwan Leroy erwanleroy.com/maya-python-renaming-duplicate-objects
# Find all objects that have the same shortname as another
# We can indentify them because they have | in the name
duplicates = [f for f in cmds.ls() if '|' in f]
# Sort them by hierarchy so that we don't rename a parent before a child.
duplicates.sort(key=lambda obj: obj.count('|'), reverse=True)
# if we have duplicates, rename them
if duplicates:
for name in duplicates:
# extract the base name
m = re.compile("[^|]*$").search(name)
shortname = m.group(0)
# extract the numeric suffix
m2 = re.compile(".*[^0-9]").match(shortname)
if m2:
stripSuffix = m2.group(0)
else:
stripSuffix = shortname
# rename, adding '#' as the suffix, which tells maya to find the next available number
newname = cmds.rename(name, (stripSuffix + "#"))
print("renamed %s to %s" % (name, newname))
return "Renamed %s objects with duplicated name." % len(duplicates)
else:
return "No Duplicates"
# function to calculate distance between to objects
def getDistance(objA, objB):
gObjA = cmds.xform(objA, q=True, t=True, ws=True)
gObjB = cmds.xform(objB, q=True, t=True, ws=True)
return sqrt(pow(gObjA[0] - gObjB[0], 2) + pow(gObjA[1] - gObjB[1], 2) + pow(gObjA[2] - gObjB[2], 2))
# get direction vector, then normalize. This code is from Paul from Techart
def placeNodeAtOffset(objA, objB, percent, node):
pt1 = cmds.xform(objA, q=True, rp=True, ws=True)
pt2 = cmds.xform(objB, q=True, rp=True, ws=True)
distance = getDistance(objA, objB)
offset = percent*distance
V1 = OpenMaya.MVector(*pt1)
V2 = OpenMaya.MVector(*pt2)
V3 = (V1 - V2).normal()
V4 = V2 + V3*offset
cmds.move(V4.x, V4.y, V4.z, node)
def getClosestVert(bodyMesh, currentJoint):
geo = pm.PyNode(bodyMesh) # user input (from UI) needed!
fPG = pm.PyNode(currentJoint) # convert to PyNode
pos = fPG.getRotatePivot(space='world')
nodeDagPath = OpenMaya.MObject()
try:
selectionList = OpenMaya.MSelectionList()
selectionList.add(geo.name())
nodeDagPath = OpenMaya.MDagPath()
selectionList.getDagPath(0, nodeDagPath)
except:
raise RuntimeError('OpenMaya.MDagPath() failed on %s' % geo.name())
mfnMesh = OpenMaya.MFnMesh(nodeDagPath)
pointA = OpenMaya.MPoint(pos.x, pos.y, pos.z)
pointB = OpenMaya.MPoint()
space = OpenMaya.MSpace.kWorld
util = OpenMaya.MScriptUtil()
util.createFromInt(0)
idPointer = util.asIntPtr()
mfnMesh.getClosestPoint(pointA, pointB, space, idPointer)
idx = OpenMaya.MScriptUtil(idPointer).asInt()
faceVerts = [geo.vtx[i] for i in geo.f[idx].getVertices()]
closestVert = None
minLength = None
for v in faceVerts:
thisLength = (pos - v.getPosition(space='world')).length()
if minLength is None or thisLength < minLength:
minLength = thisLength
closestVert = v
return str(closestVert)
# function to get the farthest child joint distance >> use this for the length of cylinder (if have child joint)
def getCylinderHeight(currentJoint):
childJoint = findCorrectChildJnt(currentJoint)
cylinderHeight = getDistance(childJoint, currentJoint)
return cylinderHeight
# function to get farthest point to joint (in any direction) >> use this for cylinder radios later
def getCylinderRadios(currentJoint):
global bodyMesh
# find child jnt
childJoint = findCorrectChildJnt(currentJoint)
locList = []
if childJoint:
percentList = [0.0, 0.25, 0.5, 0.75, 1.0]
maxDistance = 0.0
for p in percentList:
loc = cmds.spaceLocator()
locList.append(loc[0])
placeNodeAtOffset(currentJoint, childJoint, p, loc[0])
closestVer = getClosestVert(bodyMesh, loc[0])
distance = getDistance(loc[0], closestVer)
if distance >= maxDistance:
maxDistance = distance
radius = maxDistance*165/100
cmds.delete(locList)
else:
radius = 0.0
return radius
# having problem with 11 and 1 in numbering joints
def searchSimilarJoints(currentJoint):
allJoint = cmds.ls(type="joint")
currentJointNameLength = len(currentJoint)
for lastIndex in range(currentJointNameLength):
if lastIndex != 0:
tripOffName = currentJoint[0:-lastIndex]
# what if it finds up to "horse"? 3 is a safe number ... for now
if lastIndex > 3:
return None
break
similarObjList = cmds.ls(tripOffName + "*", type="joint")
if similarObjList:
maxRange = len(similarObjList)
currentJntIndex = similarObjList.index(currentJoint)
if currentJntIndex < maxRange:
nextJoint = similarObjList[currentJntIndex + 1]
if nextJoint:
return nextJoint
else:
return None
break
# Need a better way to find correct child joint
def pathLength(joint):
fullPath = cmds.ls(joint, long=1)[0]
fullPathList = fullPath.split("|")
pathLength = len(fullPathList)-1
return pathLength
def minLength(joint_list):
min = 999999
for jnt in joint_list:
length = pathLength(jnt)
if length <= min:
min = length
return min
def findCorrectChildJnt(currentJnt):
childrenJointList = cmds.listRelatives(currentJnt, children=1, allDescendents=1, type="joint")
if childrenJointList:
firstLevelChildJointLength = minLength(childrenJointList)
firstLevelChildJntList=[]
for child in childrenJointList:
if pathLength(child) == firstLevelChildJointLength:
firstLevelChildJntList.append(child)
return firstLevelChildJntList[0] # assume the first one is the right child, will fail if this is not the case
else:
return None
# searchSimilarJoints(currentJnt)
# Create cylinders + get orientation (aim constraint to joint child) + get radius and length above
# >> move cylinder up 1/2 length >> freeze transform
# then parent constraint the cylinder to joint. Stop there for further adjustments from user
def createCylinders(mesh):
if not (cmds.objExists("CutMesh_Grp")):
cmds.group(em=True, name="CutMesh_Grp")
autoRenamingDuplicateObjects()
# get joint list from selected model
jointList = cmds.skinCluster(mesh, q=True, inf=True)
# still cannot get tail joint with ribbon setup
for jnt in jointList:
# need check if there is child joint
checkHavingChildJntList = cmds.listRelatives(jnt, children=True, allDescendents=1, type="joint")
if checkHavingChildJntList:
cylinderRadius = getCylinderRadios(jnt)
cylinderHeight = getCylinderHeight(jnt)
polyCyl = cmds.polyCylinder(height=cylinderHeight, radius=cylinderRadius, name=jnt+"_cut")
# move up 1/2 height
cmds.xform(polyCyl, t=[0, cylinderHeight/2, 0], r=True)
# move pivot to 0 0 0
cmds.xform(polyCyl, pivots=[0, 0, 0], ws=True)
# freeze transform
cmds.makeIdentity(polyCyl, apply=True)
# parent constraint to the current joint
parentCon = cmds.parentConstraint(jnt, polyCyl, mo=0)
cmds.delete(parentCon)
# aim constraint to orient, then delete this constraint >>> This one will fail
childJoints = findCorrectChildJnt(jnt)
# usually the correct orient is the fist child joint. This is a temporary solution
aimCon = cmds.aimConstraint(childJoints, polyCyl, mo=0, aim=[0, 1, 0])
cmds.delete(aimCon)
cmds.parent(polyCyl[0], "CutMesh_Grp")
def createLoftMeshes(mesh):
if not (cmds.objExists("CutMesh_Grp")):
cmds.group(em=True, name="CutMesh_Grp")
autoRenamingDuplicateObjects()
# get joint list from selected model
jointList = cmds.skinCluster(mesh, q=True, inf=True)
if not (cmds.objExists("Curves_Grp")):
cmds.group(em=True, name="Curves_Grp")
for jnt in jointList:
# need check if there is child joint
checkHavingChildJntList = cmds.listRelatives(jnt, children=True, allDescendents=1, type="joint")
if checkHavingChildJntList:
# find child jnt
childJoint = findCorrectChildJnt(jnt)
curveList = []
percentList = [0.0, 0.25, 0.5, 0.75, 1.0]
# create 5 curves and move them along 0, 25%, 50%, 75%, 100% in the vector between 2 joints above
for p in percentList:
c = cmds.circle()
curveList.append(c[0])
placeNodeAtOffset(jnt, childJoint, p, c[0])
# get distance of each curve to mesh surface for this curve's radius (update after create)
closestVer = getClosestVert(mesh, c[0])
radius = getDistance(c[0], closestVer)*165/100
cmds.setAttr(c[1]+".radius", radius)
if p == percentList[0]:
# for the last curve, aim to the parent joint
aimCon = cmds.aimConstraint(jnt, c[0], mo=0, aim=[0, 0, 1])
cmds.delete(aimCon)
else:
# aim constraint the curve to the next joint, then delete the constraint
aimCon = cmds.aimConstraint(childJoint, c[0], mo=0, aim=[0, 0, -1])
cmds.delete(aimCon)
cmds.parent(c[0], "Curves_Grp")
# store first curve pivot
firstCurvePivot = cmds.xform(curveList[-1], q=True, rp=True, ws=True)
# store original Rotation
oldRotation = cmds.xform(curveList[-1], q=True, rotation=True, ws=True)
# this is for matching orientation of the pivot of proxy mesh & first curve/ jnt
pivotGrp = cmds.group(em=True, world=True)
# constraint to snap the pivotGrp to the first Curve
firstCurveConstraint = cmds.parentConstraint(curveList[-1], pivotGrp, mo=0)
cmds.delete(firstCurveConstraint)
# parent all 5 curves under pivotGrp
cmds.parent(curveList, pivotGrp)
# zero out rotation, so the loft mesh will be straight up
cmds.xform(pivotGrp, ws=True, rotation=[90, 0, 0])
# loft 5 curves to make a loft mesh
cmds.select(curveList, r=True)
loftAction=cmds.loft(polygon=1, name=jnt+"_cut")
# flip normal
cmds.polyNormal(loftAction[0], normalMode=0)
# close hole
cmds.polyCloseBorder(loftAction[0])
# match the pivot of loft mesh to the first curve
cmds.xform(loftAction[0], rp=firstCurvePivot, ws=1)
# parent loftMesh under pivotGrp
cmds.parent(loftAction[0], pivotGrp)
# delete history the loft mesh
cmds.delete(loftAction[0], ch=True)
# get back the rotation for pivotGrp
cmds.xform(pivotGrp, rotation=oldRotation, ws=True)
# parent loft meshes to Loft_Meshes_Grp
cmds.parent(loftAction[0], "CutMesh_Grp")
# delete pivot grp
cmds.delete(pivotGrp)
# delete Curves Grp
cmds.delete("Curves_Grp")
def renameCut(mesh, side):
newSide = None
meshName = list(mesh.split(side))[0]
if side == "_R_":
newSide = "_L_"
if side == "_L_":
newSide = "_R_"
newName = meshName + newSide + "cut"
return newName
def mirrorScale(mesh, newMeshName):
if cmds.objExists(newMeshName):
cmds.delete(newMeshName)
cmds.duplicate(mesh, name=newMeshName)
cmds.select(clear=True)
tempGrp = cmds.group(empty=1)
cmds.parent(newMeshName, tempGrp)
cmds.xform(tempGrp, scale=[-1, 1, 1])
if cmds.objExists("CutMesh_Grp"):
cmds.parent(newMeshName, "CutMesh_Grp")
else:
raise Exception("There is no CutMesh_Grp")
cmds.delete(tempGrp)
def mirrorSelectedCut():
cut_mesh_list = cmds.ls(sl=1)
for mesh in cut_mesh_list:
if "_R_" in mesh:
newMeshName = renameCut(mesh, "_R_")
mirrorScale(mesh, newMeshName)
if "_L_" in mesh:
newMeshName = renameCut(mesh, "_L_")
mirrorScale(mesh, newMeshName)
else:
print("This is a middle mesh")
cmds.select(mesh, r=1)
def setReducePercent(percent):
global reducePercent
reducePercent = percent
def reduceMainMesh():
global bodyMesh
# get joint list from main model
jointList = cmds.skinCluster(bodyMesh, q=True, inf=True)
newOriginal = cmds.duplicate(bodyMesh, rr=1)[0]
cmds.hide(bodyMesh)
cmds.polyReduce(newOriginal, keepQuadsWeight=1, percentage=reducePercent, triangulate=0, ch=0)
cmds.skinCluster(newOriginal, jointList, tsb=1, sm=0)
bodyMesh = newOriginal
return bodyMesh
# loop through cylinder mesh in Cylinders_Grp >> duplicate mesh >> boolean the mesh
def makeBooleans():
global bodyMesh
if not (cmds.objExists("CutMesh_Grp")):
raise Exception("Please create cylinder meshes first!")
if not (cmds.objExists("Proxy_Grp")):
cmds.group(em=True, name="Proxy_Grp")
cutMesh_list = cmds.listRelatives("CutMesh_Grp", children=True)
for cutMesh in cutMesh_list:
dupMesh = cmds.duplicate(bodyMesh, rr=True, name=bodyMesh+'_for_'+cutMesh)[0]
proxy = cmds.polyBoolOp(cutMesh, dupMesh, operation=3, name=cutMesh+"_proxy")
cmds.delete(proxy[0], ch=True)
cmds.parent(proxy[0], "Proxy_Grp")
if cmds.objExists(dupMesh):
cmds.delete(dupMesh)
cmds.refresh()
def setMainControl():
global mainControl
mainControl = cmds.ls(sl=True)[-1]
load_selected_as(mainControl, mainControl_tf)
# constraint to joint by names
def constraintProxy():
if not (cmds.objExists("Proxy_Grp")):
raise Exception("Please create proxy meshes first!")
proxy_list = cmds.listRelatives("Proxy_Grp", children=True)
for proxy in proxy_list:
jntName = proxy.split("_cut_proxy")[0]
cmds.parentConstraint(jntName, proxy, mo=True)
if mainControl:
cmds.scaleConstraint(mainControl, proxy, mo=True)
def parentProxy():
if not (cmds.objExists("Proxy_Grp")):
raise Exception("Please create proxy meshes first!")
proxy_list = cmds.listRelatives("Proxy_Grp", children=True)
for proxy in proxy_list:
jntName = proxy.split("_cut_proxy")[0]
cmds.parent(proxy, jntName)
def load_selected_as(sel, text_field):
text_field = cmds.textField(text_field, e=True, tx=str(sel))
def chooseBodyMesh():
global bodyMesh
bodyMeshList= cmds.ls(sl=True)
if not bodyMeshList:
raise Exception("Please select something")
if len(bodyMeshList)>1:
raise Exception("Please choose 1 mesh only!")
bodyMesh = bodyMeshList[0]
bodyMeshShape = cmds.listRelatives(bodyMesh, s=True, ni=True, f=True)
bodyMeshNodeType = cmds.nodeType(bodyMeshShape)
if bodyMeshNodeType != "mesh":
raise Exception("Please select mesh type object!")
load_selected_as(bodyMesh, bodyMeshTF)
cmds.select(clear=True)
return bodyMesh
def show_UI(winID):
if cmds.window(winID, exists=True):
cmds.deleteUI(winID)
cmds.window(winID)
create_UI(winID)
cmds.showWindow(winID)
def create_UI(winID):
cmds.window(winID, e=True, width=250, height=410)
main_lo = cmds.columnLayout(p=winID)
cmds.text("\n Select Character Mesh then hit the button: \n")
cmds.button(label="Mesh*", width=250, command='chooseBodyMesh()')
cmds.textField(bodyMeshTF, width=250, ed=False)
cmds.separator(height=10, p=main_lo)
cyl_loft_row_lo = cmds.rowLayout(p=main_lo, nc=3)
cmds.button(label="Create Cylinders", width=114, command='createCylinders(bodyMesh)', p=cyl_loft_row_lo)
cmds.text(" or ", p=cyl_loft_row_lo)
cmds.button(label="Create Loft Meshes", width=114, command='createLoftMeshes(bodyMesh)', p=cyl_loft_row_lo)
cmds.button(label="Mirror Selected Meshes", command='mirrorSelectedCut()', width=250, p=main_lo)
cmds.text("\n Please adjust further to cover your character,", p=main_lo)
cmds.text(" Delete unused cylinders/ loft meshes, then: \n", p=main_lo)
cmds.separator(height=10, p=main_lo, width=250)
reduce_lo = cmds.rowLayout(p=main_lo, nc=3)
cmds.text(label=" Reduce Main Mesh** (%):")
percent = cmds.intField()
cmds.intField(percent, e=True, changeCommand=setReducePercent, w=50)
reduce_btn = cmds.button(label="Reduce", c='reduceMainMesh()', w=50)
cmds.text("** Optional/ Fix failed Boolean Operation", p=main_lo)
cmds.separator(height=10, p=main_lo, width=250)
cmds.separator(height=10, p=main_lo)
cmds.button(label="Create Proxy Meshes", width=250, command='makeBooleans()', p=main_lo)
cmds.separator(height=10, p=main_lo)
set_main_row_lo = cmds.rowLayout(p=main_lo, nc=3)
cmds.text(" Load Main Control:")
cmds.textField(mainControl_tf, ed=False)
set_main_btn = cmds.button(label=">>", c='setMainControl()', width=25)
parent_options_row_lo = cmds.rowLayout(p=main_lo, nc=3)
cmds.button(label="Constraint To Joints", width=114, command='constraintProxy()', p=parent_options_row_lo)
cmds.text(" or ", p=parent_options_row_lo)
cmds.button(label="Parent Under Joints", width=114, command='parentProxy()', p=parent_options_row_lo)
cmds.separator(height=10, p=main_lo)
hide_show_row_lo = cmds.rowLayout(p=main_lo, nc=2)
cmds.button(label="Hide Original Mesh", width=123, command='cmds.hide(bodyMesh)', p=hide_show_row_lo)
cmds.button(label="Show Original Mesh", width=123, command='cmds.showHidden(bodyMesh)', p=hide_show_row_lo)
cmds.text("\n * Click again if you close the tool mid way \n", p=main_lo)
show_UI(trsUI_ID)