// ========================= // Weight tools // ========================= // Initializing global variables. global string $weightToolsVersion; $weightToolsVersion = "4.0g06"; global string $weightToolsDefaultPath; $weightToolsDefaultPath = `workspace -q -rd` + "scenes/weights"; //====================================================================== // open explorer in weights directory //====================================================================== global proc openWeightsDir () { string $lastPlaceTmp = `textFieldButtonGrp -q -label weightToolsTextFieldTFBG`; string $lastPlace = toNativePath( $lastPlaceTmp ); system ("start explorer /n,/e, " + $lastPlace); } // ==================================== // Save preferences // ==================================== global proc weightToolsSavePrefs () { string $lastPlaceTmp = `textFieldButtonGrp -q -label weightToolsTextFieldTFBG`; optionVar -stringValue lastPlaceStatus $lastPlaceTmp; string $bookMarkTmp = `menuItem -q -label weightToolsBookmark1`; optionVar -stringValue weightToolsBookmark1Status $bookMarkTmp; string $bookMarkTmp = `menuItem -q -label weightToolsBookmark2`; optionVar -stringValue weightToolsBookmark2Status $bookMarkTmp; string $bookMarkTmp = `menuItem -q -label weightToolsBookmark3`; optionVar -stringValue weightToolsBookmark3Status $bookMarkTmp; string $bookMarkTmp = `menuItem -q -label weightToolsBookmark4`; optionVar -stringValue weightToolsBookmark4Status $bookMarkTmp; string $bookMarkTmp = `menuItem -q -label weightToolsBookmark5`; optionVar -stringValue weightToolsBookmark5Status $bookMarkTmp; print ( "===> Your weightTools preferences have been saved!!!" ); } // ==================================== // Replace current bookmark // ==================================== global proc weightToolsReplaceBookmark () { if ( `menuItem -q -rb weightToolsBookmark1` ) menuItem -e -l `textFieldButtonGrp -q -label weightToolsTextFieldTFBG` weightToolsBookmark1; else if ( `menuItem -q -rb weightToolsBookmark2` ) menuItem -e -l `textFieldButtonGrp -q -label weightToolsTextFieldTFBG` weightToolsBookmark2; else if ( `menuItem -q -rb weightToolsBookmark3` ) menuItem -e -l `textFieldButtonGrp -q -label weightToolsTextFieldTFBG` weightToolsBookmark3; else if ( `menuItem -q -rb weightToolsBookmark4` ) menuItem -e -l `textFieldButtonGrp -q -label weightToolsTextFieldTFBG` weightToolsBookmark4; else if ( `menuItem -q -rb weightToolsBookmark5` ) menuItem -e -l `textFieldButtonGrp -q -label weightToolsTextFieldTFBG` weightToolsBookmark5; } // ==================================== // Clear current bookmark // ==================================== global proc weightToolsClearSelectedBookmark () { if ( `menuItem -q -rb weightToolsBookmark1` ) menuItem -e -l "Empty" weightToolsBookmark1; else if ( `menuItem -q -rb weightToolsBookmark2` ) menuItem -e -l "Empty" weightToolsBookmark2; else if ( `menuItem -q -rb weightToolsBookmark3` ) menuItem -e -l "Empty" weightToolsBookmark3; else if ( `menuItem -q -rb weightToolsBookmark4` ) menuItem -e -l "Empty" weightToolsBookmark4; else if ( `menuItem -q -rb weightToolsBookmark5` ) menuItem -e -l "Empty" weightToolsBookmark5; } //============================ // Update weights directory //============================ global proc weightToolsUpdateDirectory() { string $updatedDirectory = `textFieldButtonGrp -q -text weightToolsTextFieldTFBG`; string $workspace = ( `textFieldButtonGrp -q -label weightToolsTextFieldTFBG` + "/" + $updatedDirectory ); // NT textFieldButtonGrp -e -label $workspace -ann $workspace weightToolsTextFieldTFBG; textFieldButtonGrp -e -text "" weightToolsTextFieldTFBG; sysFile -makeDir $workspace ; } // ========================= // Save weights by number // ========================= global proc saveWeightsByNumber( string $filePath ) { string $geoSelect[] = `ls -sn -sl`; string $geoTypeGeneral[] = `ls -sl -dag -s -showType`; string $geoType = $geoTypeGeneral[1]; // -------------------------- // 1- Select all the points // -------------------------- // For nurbs... if ( $geoType == "nurbsSurface") { int $numU = size(`ls -fl ($geoSelect[0] + ".cv[*][0]")`); int $numV = size(`ls -fl ($geoSelect[0] + ".cv[0][*]")`); select -r ( $geoSelect[0] + ".cv[0:" + $numU + "][0:" + $numV + "]" ); } // For polygons... else if ( $geoType == "mesh") { int $numberOfVtxs[] = `polyEvaluate -v $geoSelect`; int $pointNumber = $numberOfVtxs[0]; select -r ( $geoSelect[0] + ".vtx[0:" + $pointNumber + "]" ); } // -------------------------- // 2- Get skin cluster name // -------------------------- string $skincl = `findRelatedSkinCluster($geoSelect[0])`; //print ( "\n$skincl= " + $skincl ); /* now get the selected object components... 28 means CV's 31 means poly vertices 36 means SubD Points 46 means lattice points ... and then expand it into a nice list */ string $expandedSel[0] = `filterExpand -ex 1 -sm 28 -sm 31 -sm 46 -sm 36 $geoSelect[0]`; /* At this point the string array expandedSel[] has stuff like this in it... nurbsSphere1.cv[4][5] for NURBS pSphere1.vtx[361] for polys ffd1Lattice.pt[1][2][3] for lattices ... so we can just use each of those for the stuff below! */ // --------------------------- // 3- Output the weights file // --------------------------- // If the procedure was called without a filePath argument (e.g. ""), it means the UI window is up, // so read from the text field path. if ( $filePath == "" ) $filePath = `textFieldButtonGrp -q -label weightToolsTextFieldTFBG`; string $fileName = ( $filePath + "/" + $geoSelect[0] + "_pointNumWeights.mel" ); int $fileId = `fopen $fileName "w"`; if ( $fileId == 0 ) error -sl 1 ( "weightTools: Error Opening File " + $fileName ); waitCursor -state on; // Get the list of influencing joints. string $listOfJointsTmp[] = `skinCluster -q -inf $skincl`; // Strip any "|" sign off joint's name. int $i; for ($i=0;$i<`size $listOfJointsTmp`;$i++) { string $buffer[]; int $numTokens = `tokenize $listOfJointsTmp[$i] "|" $buffer`; //print ($buffer[`size $buffer`-1]); $listOfJointsTmp[$i] = $buffer[`size $buffer`-1]; } string $listOfJoints = "List of joints: " + stringArrayToString( $listOfJointsTmp, " " ); fprint $fileId ($listOfJoints + " ;\n"); // Now go through every points and write down the weights info. string $selectedPoint; for ($selectedPoint in $expandedSel) { // Find the joint(s) influencing the point. string $cmd = "skinPercent -q -t " + $skincl + " " + $selectedPoint; string $skinJoints[] = eval($cmd); // Strip any "|" sign off joint's name. for ($i=0;$i<`size $skinJoints`;$i++) { string $buffer[]; int $numTokens = `tokenize $skinJoints[$i] "|" $buffer`; //print ($buffer[`size $buffer`-1]); $skinJoints[$i] = $buffer[`size $buffer`-1]; } string $cmd = "skinPercent -q -v " + $skincl + " " + $selectedPoint; // And what are their skinPercent weights? string $weights[] = eval($cmd); string $output = "skinPercent "; for ($j=0;$j<`size $skinJoints`;$j++) { $output = $output + "-tv " + $skinJoints[$j] + " " + $weights[$j] + " "; } // Note here that we print "$skincl" as a variable. At execution time, "$skincl" will be replaced by the relevant skin cluster name. $output = $output + "$skincl " + $selectedPoint + ";\n"; fprint $fileId $output; //print ("$output = " + $output + "\n"); } fclose $fileId; waitCursor -state off; print ("-----> saveWeights by Point Number successful for \"" + $geoSelect[0] + "\"! <-----\n"); } // ============================= // Save weights by position // ============================= global proc saveWeightsByPosition( string $filePath, string $spaceChoice ) { string $geoSelect[] = `ls -sn -sl`; string $geoTypeGeneral[] = `ls -sl -dag -s -showType`; string $geoType = $geoTypeGeneral[1]; // -------------------------- // 1- Select all the points // -------------------------- // For nurbs... if ( $geoType == "nurbsSurface") { int $numU = size(`ls -fl ($geoSelect[0] + ".cv[*][0]")`); int $numV = size(`ls -fl ($geoSelect[0] + ".cv[0][*]")`); select -r ( $geoSelect[0] + ".cv[0:" + $numU + "][0:" + $numV + "]" ); } // For polygons... else if ( $geoType == "mesh") { int $numberOfVtxs[] = `polyEvaluate -v $geoSelect`; int $pointNumber = $numberOfVtxs[0]; select -r ( $geoSelect[0] + ".vtx[0:" + $pointNumber + "]" ); } // -------------------------- // 2- Get skin cluster name // -------------------------- string $skincl = `findRelatedSkinCluster($geoSelect[0])`; //print ( "\n$skincl= " + $skincl ); /* now get the selected object components... 28 means CV's 31 means poly vertices 36 means SubD Points 46 means lattice points ... and then expand it into a nice list */ string $expandedSel[0] = `filterExpand -ex 1 -sm 28 -sm 31 -sm 46 -sm 36 $geoSelect[0]`; /* At this point the string array expandedSel[] has stuff like this in it... nurbsSphere1.cv[4][5] for NURBS pSphere1.vtx[361] for polys ffd1Lattice.pt[1][2][3] for lattices ... so we can just use each of those for the stuff below! */ // --------------------------- // 3- Output the weights file // --------------------------- // If the procedure was called without a filePath argument (e.g. ""), it means the UI window is up, // so read from the text field path. if ( $filePath == "" ) $filePath = `textFieldButtonGrp -q -label weightToolsTextFieldTFBG`; if ( $spaceChoice == "" ) { if ( `radioButton -q -sl weightToolsGlobalRB` ) $spaceChoice = "worldSpace"; else $spaceChoice = "localSpace"; } string $fileName = ( $filePath + "/" + $geoSelect[0] + "_pointPosWeights.mel" ); int $fileId = `fopen $fileName "w"`; if ( $fileId == 0 ) error -sl 1 ( "weightTools: Error Opening File " + $fileName ); waitCursor -state on; // Get the list of influencing joints. string $listOfJointsTmp[] = `skinCluster -q -inf $skincl`; // Strip any "|" sign off joint's name. int $i; for ($i=0;$i<`size $listOfJointsTmp`;$i++) { string $buffer[]; int $numTokens = `tokenize $listOfJointsTmp[$i] "|" $buffer`; //print ($buffer[`size $buffer`-1]); $listOfJointsTmp[$i] = $buffer[`size $buffer`-1]; } string $listOfJoints = "List of joints: " + stringArrayToString( $listOfJointsTmp, " " ); fprint $fileId ($listOfJoints + " ;\n"); // Now go through every points and write down the weights info. string $selectedPoint; for ($selectedPoint in $expandedSel) { // Find the joint(s) influencing the point. string $cmd = "skinPercent -q -t " + $skincl + " " + $selectedPoint; string $skinJoints[] = eval($cmd); // Strip any "|" sign off joint's name. for ($i=0;$i<`size $skinJoints`;$i++) { string $buffer[]; int $numTokens = `tokenize $skinJoints[$i] "|" $buffer`; //print ($buffer[`size $buffer`-1]); $skinJoints[$i] = $buffer[`size $buffer`-1]; } string $cmd = "skinPercent -q -v " + $skincl + " " + $selectedPoint; // And what are their skinPercent weights? string $weights[] = eval($cmd); if ( $spaceChoice == "worldSpace" ) $pos = `pointPosition -w $selectedPoint`; else $pos = `pointPosition -l $selectedPoint`; // Write point name... fprint $fileId ( $selectedPoint + "\n" ); // ... and point position. fprint $fileId ( $pos[0] + " " + $pos[1] + " " + $pos[2] + "\n" ); // print pos string $output = ""; for ($j=0;$j<`size $skinJoints`;$j++) { $output = $output + "-tv " + $skinJoints[$j] + " " + $weights[$j] + " "; } // Write weights info. fprint $fileId ( $output + "\n" ); } fclose $fileId; waitCursor -state off; print ("-----> saveWeights by Point Position successful for \"" + $geoSelect[0] + "\"! <-----\n"); } // ========================= // Load weights by number // ========================= global proc loadWeightsByNumber() { string $selection[] = `ls -sn -sl`; string $summaryLoad[]; string $badOnes[]; string $missingFiles[]; string $filePath = `textFieldButtonGrp -q -label weightToolsTextFieldTFBG`; string $fileName; string $skinCluster; string $loadMethod = " by Point Number"; waitCursor -state on; // Go through everything selected and attempt to load the weights. for ($i=0;$i<(`size $selection`);$i++) { if ( (`findRelatedSkinCluster($selection[$i])`) != "" ) { // Infer file name based on gemetry name. $skinCluster = `findRelatedSkinCluster($selection[$i])`; $fileName = ($filePath + "/" + $selection[$i] + "_pointNumWeights.mel"); int $fileId = `fopen $fileName "r"`; if ( $fileId != 0 ) { doLoadWeightsByNumber( $fileName, $skinCluster, $selection[$i], ($i+1), (`size $selection`) ); $summaryLoad = stringArrayCatenate ( { $selection[$i] }, $summaryLoad); } else { //warning ("---> There's no weight file for \"" + $selection[$i] + "\"! <---"); $missingFiles = stringArrayCatenate ( { $selection[$i] }, $missingFiles); } } else //if ( (`findRelatedSkinCluster($selection[$i])`) == "" && (!`checkBox -q -v bindJointsCB`) ) { //warning ("---> \"" + $selection[$i] + "\" is NOT a skin, so weights won't be loaded!!! <---"); $badOnes = stringArrayCatenate ( { $selection[$i] }, $badOnes); } } waitCursor -state off; // Display a window with the summary of what happened. outputSummaryWindow( $loadMethod, $summaryLoad, $badOnes, $missingFiles ); select -r $selection; print "---> weightTools: Done! Please refer to Summary Window for details <---"; } // =================================== // Do load weights by number // =================================== global proc doLoadWeightsByNumber( string $fileName, string $skinCluster, string $geoName, int $number, int $totalNumber ) { // Setup progress window. float $amount; float $percent; int $numberOfLines; progressWindow -title ($geoName + " - " + $number + " of " + $totalNumber) -progress 0 -min 0 -max 100 -status "0 %" -isInterruptable true; // Open weight file. int $fileId = `fopen $fileName "r"`; //print ("$fileName = " + $fileName + "\n"); if ( $fileId ) { // Go first through the file to get all the lines. while ( !`feof $fileId` ) { fgetline $fileId; $numberOfLines++; } } else error ( "weightTools: Error Opening File " + $fileName ); // Now we have an idea of the number of vertices, so rewind to the start of the file. $percent = 100.0 / $numberOfLines; frewind $fileId; // Disable the weight normalization to avoid endless strings of warnings in the script editor. setAttr ($skinCluster + ".normalizeWeights") false; // Start again, but this time really execute the lines. int $count = 0; while ( !`feof $fileId` ) { if ( `progressWindow -query -isCancelled` ) break; // --------------------------------------------------------------------- $amount = $amount + $percent; int $displayAmountTmp = $amount + 1; progressWindow -edit -progress $displayAmountTmp -status ( "Load by Number - cv[" + $count + "] : " + $displayAmountTmp + " %" ); // --------------------------------------------------------------------- string $nextLine = `fgetline $fileId`; //print ( $nextLine ); // If we're not dealing with the (first) line that lists the joints, then proceed. if ( !`gmatch $nextLine "List of joints:*"` ) { // Simply Replace "$skincl" with the real $skincl and execute. string $cmd = `substitute "$skincl" $nextLine $skinCluster`; catchQuiet( `eval ($cmd)` ); $count++; } } fclose $fileId; // Re-enable weight normalization. setAttr ($skinCluster + ".normalizeWeights") true; progressWindow -endProgress; } // =========================== // Output Summary Window // =========================== global proc outputSummaryWindow( string $loadMethod, string $summaryLoad[], string $badOnes[], string $missingFiles[] ) { if ((`window -ex weightToolsSummaryWindow`) == true) deleteUI weightToolsSummaryWindow; window -w 350 -h 150 -title "Load Weights Summary" weightToolsSummaryWindow; scrollLayout -horizontalScrollBarThickness 16 -verticalScrollBarThickness 16; columnLayout -adjustableColumn true; text "======================================================"; if ( (`size $summaryLoad`) > 0 ) { text -font "smallBoldLabelFont" ("Weights Loaded Succesfully" + $loadMethod + ":"); text "======================================================"; for ($i=0;$i<(`size $summaryLoad`);$i++) { text -bgc 0.90 0.90 0.90 -align "left" ( "\"" + $summaryLoad[$i] + "\" -> weights loaded: Ok!"); } text "======================================================"; } if ( (`size $badOnes`) > 0 ) { text -font "smallBoldLabelFont" "Unable to load weights on those:"; text "======================================================"; for ($i=0;$i<(`size $badOnes`);$i++) { text -bgc 0.70 0.50 0.96 -align "left" ( "\"" + $badOnes[$i] + "\" -> is not a skin!!!"); } } if ( (`size $missingFiles`) > 0 ) { if ( (`size $badOnes`) == 0 ) { text -font "smallBoldLabelFont" "Unable to load weights on those:"; text "======================================================"; } for ($i=0;$i<(`size $missingFiles`);$i++) { text -bgc 0.81 0.64 0.96 -align "left" ( "\"" + $missingFiles[$i] + "\" -> weights file could not be found!!!"); } } text " "; button -w 30 -h 25 -label "Close" -rs true -command "deleteUI weightToolsSummaryWindow"; showWindow weightToolsSummaryWindow; } // ============================ // Load weights by position // ============================ global proc loadWeightsByPosition() { string $selection[] = `ls -sn -sl`; string $summaryLoad[]; string $badOnes[]; string $missingFiles[]; string $filePath = `textFieldButtonGrp -q -label weightToolsTextFieldTFBG`; string $fileName; string $skinCluster; string $loadMethod = " by Point Position"; waitCursor -state on; for ($i=0;$i<(`size $selection`);$i++) { if ( (`findRelatedSkinCluster($selection[$i])`) != "" ) { $skinCluster = `findRelatedSkinCluster($selection[$i])`; $fileName = ($filePath + "/" + $selection[$i] + "_pointPosWeights.mel"); int $fileId = `fopen $fileName "r"`; if ( $fileId != 0 ) { doLoadWeightsByPosition( $fileName, $skinCluster, $selection[$i], ($i+1), (`size $selection`) ); $summaryLoad = stringArrayCatenate ( { $selection[$i] }, $summaryLoad); } else { //warning ("---> There's no weight file for \"" + $selection[$i] + "\"! (Did you save one?) <---"); $missingFiles = stringArrayCatenate ( { $selection[$i] }, $missingFiles); } } else { //warning ("---> \"" + $selection[$i] + "\" is NOT a skin, so weights won't be loaded!!! <---"); $badOnes = stringArrayCatenate ( { $selection[$i] }, $badOnes); } } waitCursor -state off; select -r $selection; outputSummaryWindow ( $loadMethod, $summaryLoad, $badOnes, $missingFiles ); print "---> weightTools: Done! Please refer to Summary Window for details <---"; } // ============================ // Do load weights by position // ============================ global proc doLoadWeightsByPosition( string $fileName, string $skincl, string $geoName, int $number, int $totalNumber ) { // Get shape. string $shapeName[] = `listRelatives -type shape $geoName`; // Get geometry type. string $geoType[] = `ls -st $shapeName[0]`; // -------------------------- // 1- select all the points // -------------------------- int $pointNumber; if ( $geoType[1] == "nurbsSurface") { int $numberOfSpansTmp[] = `getAttr ($geoName+".spansUV")`; $pointNumber = $numberOfSpansTmp[0] * ($numberOfSpansTmp[1]+1); select -r ( $geoName + ".cv[0:" + ($numberOfSpansTmp[1]+2) + "][0:" + $numberOfSpansTmp[0] + "]" ); } else if ( $geoType[1] == "mesh") { int $numberOfVtxs[] = `polyEvaluate -v $geoName`; $pointNumber = $numberOfVtxs[0]; select -r ( $geoName + ".vtx[0:" + $pointNumber + "]" ); } // Setup progress window. int $amount = 0; float $percent = 100.0 / $pointNumber ; float $trueAmount = 0; progressWindow -title ($geoName + " - " + $number + " of " + $totalNumber) -progress $amount -status ( $amount + " %" ) -isInterruptable true; waitCursor -state on; // ----------------------- // start the process // ----------------------- /* now get the selected object components... 28 means CV's 31 means poly vertices 36 means SubD Points 46 means lattice points ... and then expand it into a nice list */ string $selTmp[] = `ls -sl`; string $expandedSel[0] = `filterExpand -ex 1 -sm 28 -sm 31 -sm 46 -sm 36 $selTmp[0]`; //print $expandedSel; int $nVerts = `size $expandedSel`; /* At this point the string array expandedSel[] has stuff like... nurbsSphere1.cv[4][5] for NURBS pSphere1.vtx[361] for polys ffd1Lattice.pt[1][2][3] for lattices ... in it, so we can just use each of those for the stuff below! */ string $fileNameWhere = `textFieldButtonGrp -q -label weightToolsTextFieldTFBG`; string $fileName = ($fileNameWhere + "/" + $geoName + "_pointPosWeights.mel"); // ------------------------------------- // 3- load weights file // ------------------------------------- string $nextLine; string $verts[]; // list of verts string $weights[]; // list of weighting strings for verts string $pstr[]; string $vsel; float $xpos[], $ypos[], $zpos[]; // list of x y z position for verts float $pos[]; float $delta[], $mindelta; int $i, $match; int $fileId; int $totalv = 0; // total number of read in verts float $threshold = `floatField -q -v weightToolsThreshFieldFF`; $fileId = `fopen $fileName "r"`; //print ( "\n$fileName = " + $fileName); if ($fileId != 0) { // Now read in the data $nextLine = `fgetline $fileId`; // get the vertex string //$nextLine = stripCR($nextLine); if ( $skincl == "" ){ // Process the line to get an array of joints. string $buffer[]; $numTokens = `tokenize $nextLine " " $buffer`; //print ($buffer[`size $buffer`-1]); $wordsToRemoveTmp = { "List", "of", "joints:", ";\n" }; string $toto[] = stringArrayRemove($wordsToRemoveTmp, $buffer); select -r $geoName $toto; string $skinclTmp[] = `skinCluster -toSelectedBones -ignoreHierarchy -mi 2 -dr 5`;// -n skinClusterNeck; $skincl = $skinclTmp[0]; } while ($nextLine != "") { $verts[$totalv] = $nextLine; // store vertex string $nextLine = `fgetline $fileId`; // get the position; //$nextLine = stripCR($nextLine); if ( !`gmatch $nextLine "List of joints:*"` ) { tokenize($nextLine, $pstr); // since there are spaces between xyz $xpos[$totalv] = (float)($pstr[0]); $ypos[$totalv] = (float)($pstr[1]); $zpos[$totalv] = (float)($pstr[2]); $nextLine = `fgetline $fileId`; // get the weighting string; //$nextLine = stripCR($nextLine); $weights[$totalv] = $nextLine; ++$totalv; $nextLine = `fgetline $fileId`; // get the next vertex string //$nextLine = stripCR($nextLine); } } fclose $fileId; // At this point we have a list of the original verts, weighting and // pos and the current set of selected vertices. int $d = 0; for ($vsel in $expandedSel) { if ( `progressWindow -query -isCancelled` ) break; // ----------------------------------------- $trueAmount = $trueAmount + $percent; $amount = $trueAmount + 1; progressWindow -edit -progress $amount -status ( "Load by Position - cv[" + $d + "] : " + $amount + " %" ); // ----------------------------------------- $d++; if (`radioButton -q -sl weightToolsGlobalRB`) $pos = `pointPosition -w $vsel`; // get current pos else $pos = `pointPosition -l $vsel`; // get current pos // now store distance from each saved vert for ($i=0; $i < $totalv; ++$i) { $delta[$i] = ( abs($pos[0]-$xpos[$i]) + abs($pos[1]-$ypos[$i]) + abs($pos[2]-$zpos[$i]) ) / 3; } // Now figure which one is closest $match = 0; // by default matches first one $mindelta = $delta[0]; for ($i=1; $i < $totalv; ++$i) { if ($delta[$i] < $mindelta) { // found a closer match? $match = $i; $mindelta = $delta[$i]; } } // Finally if it is within threshold, load new weights! if ($pos[0] < ($xpos[$match]+$threshold) && $pos[0] > ($xpos[$match]-$threshold) && $pos[1] < ($ypos[$match]+$threshold) && $pos[1] > ($ypos[$match]-$threshold) && $pos[2] < ($zpos[$match]+$threshold) && $pos[2] > ($zpos[$match]-$threshold) ) { // found a close enough match! string $cmd = ("skinPercent "+$weights[$match]+" "+$skincl+" "+$vsel); catchQuiet( `eval ($cmd)` ); // so update it! print ("\nVert "+$vsel+" matches old vertex "+$verts[$match]); } else print ("Vert "+$vsel+" is not within threshold enough to match "+$verts[$match]+", so not changing.\n"); } } progressWindow -endProgress; waitCursor -state off; } // ============================================= // confirmation of saving weights // ============================================= global proc saveWeigthsConfirmation () { string $selection[] = `ls -sn -sl`; string $summaryNum[] = {}; string $summaryPos[] = {}; string $badOnes[] = {}; int $checkDouble = 0; clear($summaryNum); clear($summaryPos); clear($badOnes); // ----------------- // by point number // ----------------- if (` checkBox -q -v pointNumberSaveCB` == 1 ) { int $yesToAll = 0; int $noToAll = 0; $checkDouble = ( $checkDouble + 1 ); int $amount = 0; float $trueAmount = 0; float $percent = 100.0 / (`size $selection`); progressWindow -title "Saving Weights by Point Number" -progress $amount -status ( $amount + " %" ) -isInterruptable true; for ($i=0;$i<(`size $selection`);$i++) { if ( `progressWindow -query -isCancelled` ) break; // ----------------------------------------- $trueAmount = $trueAmount + $percent; $amount = $trueAmount; progressWindow -edit -progress $amount -status ( $selection[$i] + " : " + $amount + " %" ); // ----------------------------------------- if ( (`findRelatedSkinCluster($selection[$i])`) != "" && ( $noToAll != 1 ) ) { $filePath = `textFieldButtonGrp -q -label weightToolsTextFieldTFBG`; string $fileName = ($filePath + "/" + $selection[$i] + "_pointNumWeights.mel"); if ( (`file -q -ex $fileName`) == 1 && $yesToAll == 0 ) { string $result = `confirmDialog -title "Confirm Save Weights by Point Number" -message ( "Overwrite the existing file: " + $fileName + " ?" ) -ma "center" -button "Yes" -button "No" -button "No to all" -button "Yes to all" -defaultButton "Yes" -cancelButton "No" -dismissString "No"`; if ($result == "Yes") { select -r $selection[$i]; saveWeightsByNumber( "" ); $summaryNum = stringArrayCatenate ( { $selection[$i] } , $summaryNum); } if ($result == "No to all") { $noToAll = 1; break; } if ($result == "Yes to all") { select -r $selection[$i]; saveWeightsByNumber( "" ); $summaryNum = stringArrayCatenate ( { $selection[$i] } , $summaryNum); $yesToAll = 1; } } else { select -r $selection[$i]; saveWeightsByNumber( "" ); $summaryNum = stringArrayCatenate ( { $selection[$i] } , $summaryNum); } } else { print ( "---> \"" + $selection[$i] + "\" is NOT a skin!!! <---" ); $badOnes = stringArrayCatenate ( { $selection[$i] } , $badOnes); } } progressWindow -endProgress; } // ----------------- // by point position // ----------------- if (`checkBox -q -v pointPositionSaveCB` == 1 ) { int $yesToAll = 0; int $noToAll = 0; $checkDouble = ( $checkDouble + 1 ); int $amount = 0; float $trueAmount = 0; float $percent = 100.0 / (`size $selection`); progressWindow -title "Saving Weights by Point Position" -progress $amount -status ( $amount + " %" ) -isInterruptable true; for ($i=0;$i<(`size $selection`);$i++) { if ( `progressWindow -query -isCancelled` ) break; // ----------------------------------------- $trueAmount = $trueAmount + $percent; $amount = $trueAmount; progressWindow -edit -progress $amount -status ( $selection[$i] + " : " + $amount + " %" ); // ----------------------------------------- if ( (`findRelatedSkinCluster($selection[$i])`) != "" && ( $noToAll != 1 ) ) { $filePath = `textFieldButtonGrp -q -label weightToolsTextFieldTFBG`; string $fileName = ($filePath + "/" + $selection[$i] + "_pointPosWeights.mel"); if ( (`file -q -ex $fileName`) == 1 && $yesToAll == 0 ) { string $result = `confirmDialog -title "Confirm Save Weights by Point Position" -message ( "Overwrite the existing file: " + $fileName + " ?" ) -ma "center" -button "Yes" -button "No" -button "No to all" -button "Yes to all" -dismissString "No"`; if ($result == "Yes") { select -r $selection[$i]; saveWeightsByPosition( "", "" ); $summaryPos = stringArrayCatenate ( { $selection[$i] } , $summaryPos); } if ($result == "No to all") { $noToAll = 1; break; } if ($result == "Yes to all") { select -r $selection[$i]; saveWeightsByPosition( "", "" ); $summaryPos = stringArrayCatenate ( { $selection[$i] } , $summaryPos); $yesToAll = 1; } } else { select -r $selection[$i]; saveWeightsByPosition( "", "" ); $summaryPos = stringArrayCatenate ( { $selection[$i] } , $summaryPos); } } else { //print ( "---> \"" + $selection[$i] + "\" is NOT a skin!!! <---" ); $badOnes = stringArrayCatenate ( { $selection[$i] } , $badOnes); } } progressWindow -endProgress; } // ========================================================================= // now we output the summary of what's been done in a nice lil' window... // ========================================================================= if ( ((`checkBox -q -v pointNumberSaveCB` == 0) && (`checkBox -q -v pointPositionSaveCB` == 0)) ) warning "---> You MUST select a method for saving weights (by Point Number, Point Position, or both) !!! <---"; else { print "---> weightTools: done! Please refer to Summary Window for details <---"; if ((`window -ex weightToolsSummaryWindow`) == true) deleteUI weightToolsSummaryWindow; window -w 350 -h 150 -title "Save Weights Summary" weightToolsSummaryWindow; scrollLayout -horizontalScrollBarThickness 16 -verticalScrollBarThickness 16; columnLayout -adjustableColumn true; text "======================================================"; if ( (`size $summaryNum`) > 0 ) { text -font "smallBoldLabelFont" "Summary of weights saved by Point Number:"; text "======================================================"; for ($i=0;$i<(`size $summaryNum`);$i++) { text -bgc 0.90 0.90 0.90 -align "left" ( "\"" + $summaryNum[$i] + "\" -> weights saved: Ok!"); } text "======================================================"; } if ( (`size $summaryPos`) > 0 ) { text -font "smallBoldLabelFont" "Summary of weights saved by Point Position:"; text "======================================================"; for ($i=0;$i<(`size $summaryPos`);$i++) { text -bgc 0.90 0.90 0.90 -align "left" ( "\"" + $summaryPos[$i] + "\" -> weights saved: Ok!"); } text "======================================================"; } if ( (`size $badOnes`) > 0 ) { text -font "smallBoldLabelFont" "Unable to save weights on these:"; text "======================================================"; if ( $checkDouble > 1 ) { for ($i=0;$i<( (`size $badOnes`) / 2 );$i++) { text -bgc 0.81 0.64 0.96 -align "left" ( "\"" + $badOnes[$i] + "\" -> is not a smooth-bound skin!!!"); } } else { for ($i=0;$i<(`size $badOnes`);$i++) { text -bgc 0.81 0.64 0.96 -align "left" ( "\"" + $badOnes[$i] + "\" -> is not a smooth-bound skin!!!"); } } } if ( ((`size $summaryNum`) ==0) && ((`size $summaryPos`) ==0) && ((`size $badOnes`) ==0) ) { text -font "smallBoldLabelFont" "Operation Cancelled : No weights were saved..."; text "======================================================"; } text " "; button -w 30 -h 25 -label "Close" -rs true -command "deleteUI weightToolsSummaryWindow"; showWindow weightToolsSummaryWindow; } select -r $selection; } //====================================================================== // browse for weights directory //====================================================================== global proc browseForFolder( string $startFolder ) { string $mayaFolder = `workspace -q -dir`; workspace -dir $startFolder; fileBrowserDialog -mode 4 -fileCommand ( "browseForFolderCallback \"" + $mayaFolder + "\"" ) -actionName "Pick Your Folder"; } global proc browseForFolderCallback( string $mayaFolder, string $result, string $type ) { textFieldButtonGrp -e -label $result weightToolsTextFieldTFBG; textFieldButtonGrp -e -text "" weightToolsTextFieldTFBG; workspace -dir $mayaFolder; } global proc folderInput() { string $startFolder = ((`textFieldButtonGrp -q -label weightToolsTextFieldTFBG`) + "/" ); browseForFolder( $startFolder ); } // =============================== // weightTools UI // =============================== global proc weightTools () { global string $weightToolsVersion; global string $weightToolsDefaultPath; global string $characterList[]; global string $categoryList[]; global string $currentProject = ""; // Create the weights directory (if it dosn't exist). sysFile -makeDir $weightToolsDefaultPath; if (`window -exists weightToolsWindow` ) deleteUI weightToolsWindow; window -tlb off -rtf on -menuBar true -sizeable true -width 100 -height 50 -title ("weightTools v" + $weightToolsVersion ) weightToolsWindow; menu -label "Bookmarks" -tearOff false weightToolsMenu; menuItem -subMenu true -label "Replace Bookmark With Current Path" -c weightToolsReplaceBookmark; menuItem -label "nothing" -c "menuItem -e -l `textFieldButtonGrp -q -label weightToolsTextFieldTFBG` weightToolsBookmark1; menuItem -e -l `textFieldButtonGrp -q -label weightToolsTextFieldTFBG` weightToolsBookmarkToReplace1; menuItem -e -l `textFieldButtonGrp -q -label weightToolsTextFieldTFBG` weightToolsBookmarkToClear1" weightToolsBookmarkToReplace1; menuItem -label "nothing" -c "menuItem -e -l `textFieldButtonGrp -q -label weightToolsTextFieldTFBG` weightToolsBookmark2; menuItem -e -l `textFieldButtonGrp -q -label weightToolsTextFieldTFBG` weightToolsBookmarkToReplace2; menuItem -e -l `textFieldButtonGrp -q -label weightToolsTextFieldTFBG` weightToolsBookmarkToClear2" weightToolsBookmarkToReplace2; menuItem -label "nothing" -c "menuItem -e -l `textFieldButtonGrp -q -label weightToolsTextFieldTFBG` weightToolsBookmark3; menuItem -e -l `textFieldButtonGrp -q -label weightToolsTextFieldTFBG` weightToolsBookmarkToReplace3; menuItem -e -l `textFieldButtonGrp -q -label weightToolsTextFieldTFBG` weightToolsBookmarkToClear3" weightToolsBookmarkToReplace3; menuItem -label "nothing" -c "menuItem -e -l `textFieldButtonGrp -q -label weightToolsTextFieldTFBG` weightToolsBookmark4; menuItem -e -l `textFieldButtonGrp -q -label weightToolsTextFieldTFBG` weightToolsBookmarkToReplace4; menuItem -e -l `textFieldButtonGrp -q -label weightToolsTextFieldTFBG` weightToolsBookmarkToClear4" weightToolsBookmarkToReplace4; menuItem -label "nothing" -c "menuItem -e -l `textFieldButtonGrp -q -label weightToolsTextFieldTFBG` weightToolsBookmark5; menuItem -e -l `textFieldButtonGrp -q -label weightToolsTextFieldTFBG` weightToolsBookmarkToReplace5; menuItem -e -l `textFieldButtonGrp -q -label weightToolsTextFieldTFBG` weightToolsBookmarkToClear5" weightToolsBookmarkToReplace5; setParent -menu ..; menuItem -divider true; menuItem -subMenu true -label "Clear Bookmark" -c weightToolsClearSelectedBookmark; menuItem -label "nothing" -c "menuItem -e -l \"Empty\" weightToolsBookmark1; menuItem -e -l \"1. Empty\" weightToolsBookmarkToReplace1; menuItem -e -l \"1. Empty\" weightToolsBookmarkToClear1" weightToolsBookmarkToClear1; menuItem -label "nothing" -c "menuItem -e -l \"Empty\" weightToolsBookmark2; menuItem -e -l \"2. Empty\" weightToolsBookmarkToReplace2; menuItem -e -l \"2. Empty\" weightToolsBookmarkToClear2" weightToolsBookmarkToClear2; menuItem -label "nothing" -c "menuItem -e -l \"Empty\" weightToolsBookmark3; menuItem -e -l \"3. Empty\" weightToolsBookmarkToReplace3; menuItem -e -l \"3. Empty\" weightToolsBookmarkToClear3" weightToolsBookmarkToClear3; menuItem -label "nothing" -c "menuItem -e -l \"Empty\" weightToolsBookmark4; menuItem -e -l \"4. Empty\" weightToolsBookmarkToReplace4; menuItem -e -l \"4. Empty\" weightToolsBookmarkToClear4" weightToolsBookmarkToClear4; menuItem -label "nothing" -c "menuItem -e -l \"Empty\" weightToolsBookmark5; menuItem -e -l \"5. Empty\" weightToolsBookmarkToReplace5; menuItem -e -l \"5. Empty\" weightToolsBookmarkToClear5" weightToolsBookmarkToClear5; setParent -menu ..; menuItem -divider true; radioMenuItemCollection weightToolsBookmarksRMIC; menuItem -rb true -label "Empty" -c "if ( `menuItem -q -l weightToolsBookmark1` != \"Empty\" ) textFieldButtonGrp -e -label `menuItem -q -l weightToolsBookmark1` weightToolsTextFieldTFBG" weightToolsBookmark1; menuItem -rb off -label "Empty" -c "if ( `menuItem -q -l weightToolsBookmark2` != \"Empty\" ) textFieldButtonGrp -e -label `menuItem -q -l weightToolsBookmark2` weightToolsTextFieldTFBG" weightToolsBookmark2; menuItem -rb off -label "Empty" -c "if ( `menuItem -q -l weightToolsBookmark3` != \"Empty\" ) textFieldButtonGrp -e -label `menuItem -q -l weightToolsBookmark3` weightToolsTextFieldTFBG" weightToolsBookmark3; menuItem -rb off -label "Empty" -c "if ( `menuItem -q -l weightToolsBookmark4` != \"Empty\" ) textFieldButtonGrp -e -label `menuItem -q -l weightToolsBookmark4` weightToolsTextFieldTFBG" weightToolsBookmark4; menuItem -rb off -label "Empty" -c "if ( `menuItem -q -l weightToolsBookmark5` != \"Empty\" ) textFieldButtonGrp -e -label `menuItem -q -l weightToolsBookmark5` weightToolsTextFieldTFBG" weightToolsBookmark5; menu -en off -label "Help" -helpMenu true; menuItem -label "About Application..."; columnLayout -adjustableColumn false wtMainColumnCL; // --------------- // path frame // --------------- int $h = 20; int $w = 450; separator -st "none" -w $w -h 2; frameLayout -mw 5 -bv on -lv off -collapsable false -borderStyle "etchedOut" -w 480 -p wtMainColumnCL wtPathFrameFL; columnLayout -adjustableColumn false -p wtPathFrameFL; separator -st "none" -w $w -h 2; textFieldButtonGrp -cw3 360 80 10 -adj off -bgc .8 .8 .8 -label $weightToolsDefaultPath -text "" -cc weightToolsUpdateDirectory -bc "folderInput" -bl "..." weightToolsTextFieldTFBG; separator -st "none" -w $w -h 2; setParent ..; setParent ..; // --------------- // options frame // --------------- separator -st "none" -w $w -h 4; frameLayout -mw 5 -bv on -lv off -collapsable false -borderStyle "etchedOut" -w 480 -p wtMainColumnCL weightToolsOptionsFrameFL; rowColumnLayout -nc 4 -cw 1 120 -cw 2 100 -cw 3 130 -cw 4 130 -co 3 "left" 10 -co 4 "left" 10 -p weightToolsOptionsFrameFL; text -font "smallFixedWidthFont" -align "center" "Threshold Value:"; floatField -height 22 -v 0.001 -pre 6 -min 0 weightToolsThreshFieldFF; radioCollection; radioButton -label "World Space" weightToolsGlobalRB; radioButton -label "Local Space" -sl weightToolsLocalRB; setParent ..; setParent ..; setParent ..; // --------------- // save frame // --------------- separator -st "none" -w $w -h 4; frameLayout -mw 5 -bv on -lv off -collapsable false -borderStyle "etchedOut" -w 480 -p wtMainColumnCL weightToolsSaveFrameFL; rowColumnLayout -nc 3 -cw 1 130 -cw 2 200 -cw 3 160 -co 2 "left" 20 -p weightToolsSaveFrameFL; separator -st "none" -w 500 -h 2; separator -st "none" -w 500 -h 2; separator -st "none" -w 500 -h 2; button -h $h -label "Save Weights ->" -command "string $sel[] = `ls -sn -sl`; if ($sel[0]!=\"\") saveWeigthsConfirmation"; checkBox -label " by Point Number" -align "left" -v 1 pointNumberSaveCB; checkBox -label " by Point Position" -align "left" -v 1 pointPositionSaveCB; separator -st "none" -w 500 -h 2; separator -st "none" -w 500 -h 2; separator -st "none" -w 500 -h 2; setParent ..; setParent ..; // --------------- // load frame // --------------- separator -st "none" -w $w -h 4; frameLayout -mw 5 -bv on -lv off -collapsable false -borderStyle "etchedOut" -w 480 -p wtMainColumnCL weightToolsLoadFrameFL; rowColumnLayout -nc 3 -cw 1 130 -cw 2 200 -cw 3 160 -co 2 "left" 20 -p weightToolsLoadFrameFL; separator -st "none" -w $w -h 2; separator -st "none" -w 500 -h 2; separator -st "none" -w 500 -h 2; button -h $h -label "Load Weights ->" -command "string $sel[] = `ls -sn -sl`; if ((`radioButton -q -sl pointNumberLoadRB` == 1) && ($sel[0]!=\"\")) loadWeightsByNumber; else if ((`radioButton -q -sl pointPositionLoadRB` == 1) && ($sel[0]!=\"\")) loadWeightsByPosition"; radioCollection; radioButton -label " by Point Number" -align "left" -sl -onc "floatField -e -en off weightToolsThreshFieldFF" pointNumberLoadRB; radioButton -label " by Point Position" -en on -align "left" -onc "floatField -e -en on weightToolsThreshFieldFF" pointPositionLoadRB; //separator -st "none" -w 500 -h 4; separator -st "none" -w 500 -h 2; separator -st "none" -w 500 -h 2; //checkBox -en off -l "Bind Skin to Joints" bindJointsCB; separator -st "none" -w $w -h 2; separator -st "none" -w 500 -h 2; separator -st "none" -w 500 -h 2; setParent ..; setParent ..; // --------------- // options frame // --------------- separator -st "none" -w $w -h 4; frameLayout -mw 5 -bv on -lv off -collapsable false -borderStyle "etchedOut" -w 480 -p wtMainColumnCL weightToolsPrefsFrameFL; rowColumnLayout -nc 2 -cw 1 232 -cw 2 232 -p weightToolsPrefsFrameFL; separator -st "none" -h 2; separator -st "none" -h 2; button -h $h -label "Save Preferences" -command "weightToolsSavePrefs"; button -h $h -label "Open Windows Explorer in Current Directory" -command "openWeightsDir"; separator -st "none" -w $w -h 2; setParent ..; setParent ..; setParent ..; if ( `radioButton -q -sl pointNumberLoadRB` ) floatField -e -en off weightToolsThreshFieldFF; // ------------------------- // Load preferences. // ------------------------- if ( `optionVar -exists lastPlaceStatus` ) textFieldButtonGrp -e -label `optionVar -q lastPlaceStatus` -ann `optionVar -q lastPlaceStatus` weightToolsTextFieldTFBG; if ( `optionVar -exists weightToolsBookmark1Status` ) menuItem -e -label `optionVar -q weightToolsBookmark1Status` weightToolsBookmark1; if ( `optionVar -exists weightToolsBookmark2Status` ) menuItem -e -label `optionVar -q weightToolsBookmark2Status` weightToolsBookmark2; if ( `optionVar -exists weightToolsBookmark3Status` ) menuItem -e -label `optionVar -q weightToolsBookmark3Status` weightToolsBookmark3; if ( `optionVar -exists weightToolsBookmark4Status` ) menuItem -e -label `optionVar -q weightToolsBookmark4Status` weightToolsBookmark4; if ( `optionVar -exists weightToolsBookmark5Status` ) menuItem -e -label `optionVar -q weightToolsBookmark3Status` weightToolsBookmark5; menuItem -e -label ("1. " + `menuItem -q -l weightToolsBookmark1`) weightToolsBookmarkToReplace1; menuItem -e -label ("2. " + `menuItem -q -l weightToolsBookmark2`) weightToolsBookmarkToReplace2; menuItem -e -label ("3. " + `menuItem -q -l weightToolsBookmark3`) weightToolsBookmarkToReplace3; menuItem -e -label ("4. " + `menuItem -q -l weightToolsBookmark4`) weightToolsBookmarkToReplace4; menuItem -e -label ("5. " + `menuItem -q -l weightToolsBookmark5`) weightToolsBookmarkToReplace5; menuItem -e -label ("1. " + `menuItem -q -l weightToolsBookmark1`) weightToolsBookmarkToClear1; menuItem -e -label ("2. " + `menuItem -q -l weightToolsBookmark2`) weightToolsBookmarkToClear2; menuItem -e -label ("3. " + `menuItem -q -l weightToolsBookmark3`) weightToolsBookmarkToClear3; menuItem -e -label ("4. " + `menuItem -q -l weightToolsBookmark4`) weightToolsBookmarkToClear4; menuItem -e -label ("5. " + `menuItem -q -l weightToolsBookmark5`) weightToolsBookmarkToClear5; showWindow weightToolsWindow; }