// scMassive saves skin weights for massive software in its native format. // added procedure for pruning weights till three decimal place using comets procedure. global proc scMassiveSkin( ) { string $massWindowName = "scMassiveSkin"; if (`window -exists $massWindowName `) deleteUI $massWindowName ; window -w 310 -h 256 -resizeToFitChildren 0 -title "scMassiveSkin" $massWindowName; formLayout -numberOfDivisions 40 scMassiveForm; text -l "SkinCluster " txScl ; textField -w 180 -tx "" tfPolyGeo ; button -l " <<<" -c ("scAddPolySkinCluster tfPolyGeo;") -ann ("Select skinCluster Mesh") btSkinCls ; separator -style "in" -h 3 sepSkin ; text -l " File name " txFile ; textField -w 180 -tx "" tfFileName ; button -l "..." -w 30 -c ("scChooseFile();") -ann ("Choose file for saving out skinWeights.") btnFile ; separator -style "in" -h 3 sepFile ; button -l "Save Weights" -align center -c ("sc_MassiveSkinCmd;") -ann ("Run process.") btnSaveWeights; text -font "boldLabelFont" -al center -label "save maya skinCluster to massive weight file" studio; text -font "boldLabelFont" -al center -label "Sunny C." names; formLayout -edit -attachForm txScl "top" 7 -attachForm txScl "left" 5 -attachForm tfPolyGeo "top" 6 -attachControl tfPolyGeo "left" 3 txScl -attachForm btSkinCls "top" 6 -attachControl btSkinCls "left" 3 tfPolyGeo -attachControl sepSkin "top" 5 tfPolyGeo -attachForm sepSkin "left" 3 -attachForm sepSkin "right" 3 -attachControl txFile "top" 7 sepSkin -attachForm txFile "left" 5 -attachControl tfFileName "top" 6 sepSkin -attachControl tfFileName "left" 7 txFile -attachControl btnFile "top" 6 sepSkin -attachControl btnFile "left" 3 tfFileName -attachControl sepFile "top" 5 tfFileName -attachForm sepFile "left" 3 -attachForm sepFile "right" 3 -attachControl btnSaveWeights "top" 10 sepFile -attachForm btnSaveWeights "left" 30 -attachForm btnSaveWeights "right" 30 -attachControl studio "top" 15 btnSaveWeights -attachForm studio "left" 10 -attachForm studio "right" 10 -attachControl names "top" 30 btnSaveWeights -attachForm names "left" 10 -attachForm names "right" 10 scMassiveForm; window -edit -widthHeight 310 190 $massWindowName ; showWindow $massWindowName ; } global proc sc_MassiveSkinCmd() { $skinClusterNode = `textField -q -tx tfPolyGeo`; $file = `textField -q -tx tfFileName`; sc_MassiveSkin $skinClusterNode $file 3; } global proc sc_MassiveSkin(string $skinClusterNode,string $file,int $prunePlaces) { $geoSkin = ` skinCluster -q -g $skinClusterNode`; if ($file == "") { error -sl 0 (" You must choose a file to save to."); } if (`filetest -r $file`) // Does file already exist? { if (`filetest -w $file` != true) // If so is it not writable? { error -sl 0 (" The file you have chosen is NOT writeable."); } string $ret = `confirmDialog -title "Overwrite File?" -message ("The file: "+$file+" \n\n Already exists. Do you wish to overwrite it?\n") -button "Save" -button "Cancel" -defaultButton "Cancel" -cancelButton "Cancel" -dismissString "Cancel" `; if ($ret != "Save") { print ("// aborted at user request. //\n") ; return ; } } // At this point we are ready to save weights. // // Open file int $fileId = `fopen $file "w"`; if ($fileId == 0) { error -sl 1 (" Error Opening File: "+$file); return; } fprint $fileId ("# massive vertex weights file, written by scMassiveSkin.mel \n"); waitCursor -state on; int $compSize[] = `polyEvaluate -v $geoSkin[0]`; string $skinJnts[] = `skinCluster -q -influence $skinClusterNode` ; int $jointCount = 0; for ($eachJnt in $skinJnts) { fprint $fileId ("deformer "+ $jointCount +" " + $eachJnt +"\n"); $jointCount++; } fprint $fileId ("\n"); int $vertC = 0; int $num = 0; string $jntL[]; string $output = "" ; float $wtsL[]; int $numJnts[]; for ($eachComp in $compSize) { clear $numJnts; clear $wtsL; clear $jntL; for ($vertC =0; $vertC<=$eachComp; $vertC++) { $output = "" ; $jntL =`skinPercent -ib 0.00001 -query -transform $skinClusterNode ($geoSkin[0]+ ".vtx" + "[" + $vertC +"]")`; $wtsL = `skinPercent -ib 0.00001 -query -value $skinClusterNode ($geoSkin[0]+ ".vtx" + "[" + $vertC +"]")`; $num = 0; for ($eachJnt in $jntL) { $numJnt = `stringArrayContainsPos $eachJnt $skinJnts`; $numJnts[$num]=$numJnt; $num++; } $n=0; cSaveW_pruneAndNormalize ($wtsL, $prunePlaces) ; for ($n=0; $n $largestVal) { $largestVal = $wts[$i] ; $largestIdx = $i ; } $wts[$i] = cSaveW_roundTo($wts[$i], $prunePlaces) ; $fTotal += $wts[$i] ; // Now keep track of total amount for current new values } // If there is any leftover due to pruning removing causing normalization to be off, // then we'll just add that small amt back to the largest weight.... float $fLeftover = 1.0 - $fTotal ; $wts[$largestIdx] += $fLeftover ; if ($wts[$largestIdx] > 1.0) $wts[$largestIdx] = 1.0 ; return $largestIdx ; } global proc scChooseFile() { fileBrowser( "scChooseFileCB", "Choose", "w", 1) ; } global proc int scChooseFileCB(string $file, string $type) { textField -e -tx $file tfFileName ; return 1 ; } // scAddPolySkinCluster add selected object into respective textfield. global proc scAddPolySkinCluster(string $txFieldName ) { string $select [ ] = `filterExpand -sm 12`; if (`size($select)` == 0) {error "please select Polygon object";} if (`size($select)` > 1) {error "Please select Only ONE Object";} string $skinCls[] =`libSkin_getSkinFromGeo $select[0]`; textField -e -tx $skinCls[0] $txFieldName; } // scMassiveSkin "pCube1" "C:/temp/delme.txt";