// =============================== // polySmooth (requires Maya 4.5) // =============================== global string $pSmoothVersion = "v2.5c"; // ======================= // help window // ======================= global proc helpWin() { global string $pSmoothVersion ; if ((`window -ex helpWindow`) == true) deleteUI helpWindow; window -t "polySmooth Help" -w 650 -h 550 -s 1 helpWindow; scrollLayout -horizontalScrollBarThickness 16 -verticalScrollBarThickness 16; columnLayout -adjustableColumn true; text -align "center" -font "smallFixedWidthFont" -l ( "polySmooth " + $pSmoothVersion ) ; text -align "left" -l "=> Create Smoothed Copy: "; text -align "left" -l " Creates a smoothedCopy based on the selected poly object(s). The original objects"; text -align "left" -l " turn to wireframe, to let you see the smoothedCopy. Note that the smoothedCopy"; text -align "left" -l " itself is referenced, so that you can't select it by mistake. The \"mirror\" option will also create"; text -align "left" -l " a mirrored smoothedCopy on the -X axis."; text -align "center" -l ""; text -align "left" -l "=> Show/Hide Low-rez Cage:"; text -align "left" -l " Hides the selected low-res poly object(s) to let you see their smoothedCopy only."; text -align "left" -l " Push again the button to make them re-appear."; text -align "center" -l ""; text -align "left" -l "=> Delete Smoothed Copy:"; text -align "left" -l " Deletes the smoothedCopy of the selected poly object(s) and restores the poly object(s)"; text -align "left" -l " to their original (shaded) state, as if nothing."; text -align "center" -l ""; text -align "left" -l "=> Smooth Level:"; text -align "left" -l " Adjusts the smooth level (divisions) of the smoothedCopy on the selected poly object(s)."; text -align "left" -l " Be careful: 2 is high enough, and depending on complexity, 3 can take very long to compute."; text -align "left" -l " The \"Update!\" button will make the selected poly objects(s) all share the same smooth setting."; text -align "center" -l ""; text -align "left" -l "=> Mirror Geometry:"; text -align "left" -l " Just that. If you're working on half a head, it mirrors it. Note that you now have ONE"; text -align "left" -l " symetrical poly object. So if you want to create a smoothedCopy, think about unchecking"; text -align "left" -l " the \"mirror\" option!"; text -align "center" -l ""; text -align "left" -l "=> Delete Half:"; text -align "left" -l " Deletes half of the selected poly object(s). Usefull when you used \"Mirror Geometry\","; text -align "left" -l " and want to go back to just half the object. Be careful, though: Only use on PERFECTLY"; text -align "left" -l " SYMETRICAL poly object(s). That means same number of faces on BOTH sides, and"; text -align "left" -l " no faces with their center in the middle."; text -align "center" -l ""; text -align "left" -l "=> Soften/Harden:"; text -align "left" -l " Name says it all. It's the default command, just here for practical reasons."; text -align "center" -l ""; button -w 30 -h 25 -label "Close" -rs true -command "deleteUI helpWindow"; showWindow helpWindow; } // ======================= // show/hide low-rez // ======================= global proc showHideLowRez () { string $selection[] = `ls -sl -l` ; if ( $selection[0] != "" ) { for ($i=0;$i<(`size $selection`);$i++) { int $numTokensFirst ; string $bufferFirst[] ; $numTokensFirst = `tokenize $selection[$i] "|" $bufferFirst`; string $shortObjectName = $bufferFirst[$numTokensFirst - 1] ; if ( ( size (`ls $shortObjectName`)) < 2 ) { string $original[] = `listConnections -s off -d on $shortObjectName` ; //print (" SHOW/HIDE LOWREZ - $original = " + $original[0] + "\n" ) ; if ( $original[0] != "" ) { setAttr ( $selection[$i] + ".visibility" ) 0 ; select -cl; } else warning ( "--> \"" + $shortObjectName + "\" is NOT a Low-rez Cage!!! <--- Skipping!" ) ; } } } else { string $everyInvisible[] = `ls -tr -iv -l` ; if ( $everyInvisible[0] != "" ) { for ($i=0;$i<(`size $everyInvisible`);$i++) { select -r $everyInvisible[$i] ; string $longObjectName[] = `ls -sl -l -dag` ; //print (" SHOW/HIDE LOWREZ - $longObjectName = " + $longObjectName[0] + "\n" ) ; int $numTokensFirst ; string $bufferFirst[] ; $numTokensFirst = `tokenize $longObjectName[0] "|" $bufferFirst`; string $shortObjectName = $bufferFirst[$numTokensFirst - 1] ; //print (" SHOW/HIDE LOWREZ - $shortObjectName(" + $i + ") = " + $shortObjectName + "\n" ) ; if ( catchQuiet (`ls $shortObjectName`) ) print "" ; else if ( size (`ls $shortObjectName`) == 1 ) { string $shortShapeName[] = `listRelatives -s $shortObjectName` ; //print (" SHOW/HIDE LOWREZ - $shortShapeName = " + $shortShapeName[0] + "\n" ) ; string $smoothedCopyName[] = `listConnections -d on -s off $longObjectName[0]`; //print ( " SHOW/HIDE LOWREZ - $smoothedCopyName = " + $smoothedCopyName[0] + "\n" ) ; if ( $smoothedCopyName[0] != "" ) { string $smoothedCopyShapeName[] = `listRelatives -s $smoothedCopyName` ; //print (" SHOW/HIDE LOWREZ - $smoothedCopyShapeName = " + $smoothedCopyShapeName[0] + "\n" ) ; if ( $smoothedCopyShapeName[0] != "" ) setAttr ( $everyInvisible[$i] + ".visibility" ) 1 ; } } } } } //select -r $selection ; select -cl ; } // ======================= // delete half // ======================= global proc deleteHalfGeo () { string $selection[] = `ls -sl -l` ; if ( $selection[0] != "" ) { for ( $i = 0; $i < (`size $selection`); $i++) { select -r $selection[$i] ; string $objectType[] = `ls -sl -dag -s -showType` ; if ( $objectType[1] == "mesh" ) { $numberOfFaces = `polyEvaluate -f $selection[$i]` ; int $totalFaces = $numberOfFaces[0] ; int $halfFaces = ( $numberOfFaces[0] / 2 ) ; delete ( $selection[$i] + ".f[" + $halfFaces + ":" + $totalFaces + "]" ) ; //delete ( $selection[$i] + ".f[0:" + ($halfFaces - 1) + "]" ) ; } } select -r $selection ; } } // ======================= // soften/harden // ======================= global proc softenHardenGeo () { string $selection[] = `ls -sl -l` ; if ( $selection[0] != "" ) { for ($i=0;$i<(`size $selection`);$i++) { select -r $selection[$i] ; string $objectType[] = `ls -sl -dag -s -showType` ; if ( $objectType[1] == "mesh" ) { $numberOfEdges = `polyEvaluate -e $selection[0]` ; int $totalEdges = $numberOfEdges[0] ; polySoftEdge -a 0 -ch 1 ( $selection[$i] + ".e[0:" + $totalEdges + "]" ) ; // polySoftEdge -a 180 -ch 1 ( $selection[$i] + ".e[0:" + $totalEdges + "]" ) ; } } select -r $selection ; } } // ======================= // mirrorGeo // ======================= global proc mirrorGeo () { string $selection[] = `ls -sl` ; if ( $selection[0] != "" ) { for ($i=0;$i<(`size $selection`);$i++) { select -r $selection[$i] ; string $objectType[] = `ls -sl -dag -s -showType` ; string $longObjectName[] = `ls -sl -l -dag` ; int $numTokensFirst ; string $bufferFirst[] ; $numTokensFirst = `tokenize $longObjectName[0] "|" $bufferFirst`; string $shortObjectName = $bufferFirst[$numTokensFirst - 1] ; //print ( " $shortObjectName = " + $shortObjectName ) ; string $allSameNames = $shortObjectName ; string $checkIfUnique[] = `ls $allSameNames` ; if ( ( (`size $checkIfUnique`) < 2 ) && ( $objectType[1] == "mesh" ) ) { string $shortShapeName[] = `listRelatives -s $shortObjectName` ; string $smoothFaceName[] = `listConnections -t polySmoothFace $shortShapeName`; if ( $smoothFaceName[0] == "" ) { waitCursor -state on; polyMirror -1 0 0 0; waitCursor -state off; $numberOfEdges = `polyEvaluate -e $selection[$i]` ; int $allEdges = $numberOfEdges[0] ; polySoftEdge -a 0 -ch 1 ( $selection[$i] + ".e[0:" + $allEdges + "]" ) ; } else if ($smoothFaceName[0] != "" ) warning ( "--> \"" + $selection[$i] + "\" has a pSmoothed Copy, so mirroring will not be applied => skipping!"); } else if ( $objectType[1] != "mesh" ) warning ( "--> \"" + $selection[$i] + "\" is not a polygonal object!!!"); } select -r $selection; } } // ======================= // delete smoothed copy // ======================= global proc deleteSmoothedCopy () { string $selection[] = `ls -sl -l` ; for ($i=0;$i<(`size $selection`);$i++) { select -r $selection[$i] ; string $longObjectName[] = `ls -sl -l -dag` ; //print (" DELETE - $longObjectName = " + $longObjectName[0] + "\n" ) ; string $objectType[] = `ls -sl -dag -s -showType` ; //print (" DELETE - $objectType = " + $objectType[1] + "\n" ) ; int $numTokensFirst ; string $bufferFirst[] ; $numTokensFirst = `tokenize $longObjectName[0] "|" $bufferFirst`; string $shortObjectName = $bufferFirst[$numTokensFirst - 1] ; //print (" DELETE - $shortObjectName = " + $shortObjectName + "\n" ) ; if ( (size (`ls $shortObjectName`) == 1) && ( $objectType[1] == "mesh" ) ) // be sure it's a unique name { string $shortShapeName[] = `listRelatives -s $shortObjectName` ; //print (" DELETE - $shortShapeName = " + $shortShapeName[0] + "\n" ) ; string $smoothedCopyName[] = `listConnections -d on -s off $longObjectName[0]`; //print ( " DELETE - $smoothedCopyName = " + $smoothedCopyName[0] + "\n" ) ; if ( $smoothedCopyName[0] != "" ) { string $smoothedCopyShapeName[] = `listRelatives -s $smoothedCopyName` ; //print (" DELETE - $smoothedCopyShapeName = " + $smoothedCopyShapeName[0] + "\n" ) ; string $smoothFaceName[] = `listConnections -t polySmoothFace $smoothedCopyShapeName[0]`; //print (" DELETE - $smoothFaceName = " + $smoothFaceName[0] + "\n" ) ; delete $smoothedCopyName ; setAttr ($shortShapeName[0] + ".overrideEnabled") 1; setAttr ($shortShapeName[0] + ".overrideShading") 1; setAttr ($shortShapeName[0] + ".primaryVisibility") 1; setAttr ($shortShapeName[0] + ".castsShadows") 1; if ( `objExists ($smoothedCopyName[0] + "_IC")` == 1 ) { disconnectAttr ( $shortObjectName + ".scale") ( $smoothedCopyName[0] + "_ICGRP.scale" ) ; delete ($smoothedCopyName[0] + "_IC" ) ($smoothedCopyName[0] + "_ICGRP" ); } if ( (size (`ls "|reserved_for_pSmooth_copies|*"`)) == 0 ) delete reserved_for_pSmooth_copies ; } else warning ( "--> \"" + $shortObjectName + "\" does NOT have a pSmoothed Copy!!! => skipping!" ) ; } else warning ( "--> \"" + $shortObjectName + "\" is not a unique name => skipping!" ) ; } select -r $selection ; } // ======================= // updateSmooth // ======================= global proc updateSmooth () { string $selection[] = `ls -sl -l` ; string $list[] = {} ; clear($list) ; string $thisPolySmooth[] ; if ( $selection[0] != "" ) { for ($i=0;$i<(`size $selection`);$i++) { select -r $selection[$i] ; string $longObjectName[] = `ls -sl -l -dag` ; //print (" UPDATE - $longObjectName = " + $longObjectName[0] + "\n" ) ; int $numTokensFirst ; string $bufferFirst[] ; $numTokensFirst = `tokenize $longObjectName[0] "|" $bufferFirst`; string $shortObjectName = $bufferFirst[$numTokensFirst - 1] ; //print (" UPDATE - $shortObjectName(" + $i + ") = " + $shortObjectName + "\n" ) ; if ( size (`ls $shortObjectName`) == 1 ) { string $shortShapeName[] = `listRelatives -s $shortObjectName` ; //print (" UPDATE - $shortShapeName = " + $shortShapeName[0] + "\n" ) ; string $smoothedCopyName[] = `listConnections -d on -s off $longObjectName[0]`; //print ( " UPDATE - $smoothedCopyName = " + $smoothedCopyName[0] + "\n" ) ; if ( $smoothedCopyName[0] != "" ) { string $smoothedCopyShapeName[] = `listRelatives -s $smoothedCopyName` ; //print (" UPDATE - $smoothedCopyShapeName = " + $smoothedCopyShapeName[0] + "\n" ) ; string $smoothFaceName[] = `listConnections -t polySmoothFace $smoothedCopyShapeName[0]`; //print (" UPDATE - $smoothFaceName = " + $smoothFaceName[0] + "\n" ) ; string $thisPolySmooth = ( $smoothFaceName[0] + ".divisions" ); //print ( " UPDATE - $thisPolySmooth(" + $i + ") = " + $thisPolySmooth + "\n" ) ; $list = stringArrayCatenate ( { $thisPolySmooth } , $list) ; //print ( " UPDATE - $list = " + $list[0] + "\n" ) ; if ( $thisPolySmooth != ".divisions" ) connectControl smoothField $list; } } else warning " UPDATE - Not a unique name!!! " ; } select -r $selection ; } } // ======================= // polySmooth action // ======================= global proc pSmoothAction () { string $selection[] = `ls -sl -l` ; if ( $selection[0] != "" ) { for ($i=0;$i<(`size $selection`);$i++) { select -r $selection[$i] ; string $longObjectName[] = `ls -sl -l -dag` ; //print (" CREATE - $longObjectName = " + $longObjectName[0] + "\n" ) ; string $objectType[] = `ls -sl -dag -s -showType` ; //print (" $objectType = " + $objectType[1] + "\n" ) ; int $numTokensFirst ; string $bufferFirst[] ; $numTokensFirst = `tokenize $longObjectName[0] "|" $bufferFirst`; string $shortObjectName = $bufferFirst[$numTokensFirst -1] ; //print (" CREATE - $shortObjectName = " + $shortObjectName + "\n" ) ; if ( size (`ls $shortObjectName`) == 1 ) { string $shortShapeName[] = `listRelatives -s $shortObjectName` ; //print (" CREATE - $shortShapeName = " + $shortShapeName[0] + "\n" ) ; string $smoothedCopyName[] = `listConnections -d on -s off $longObjectName[0]`; //print ( " CREATE - $smoothedCopyName = " + $smoothedCopyName[0] + "\n" ) ; if ( ($smoothedCopyName[0] == "") && ( $objectType[1] == "mesh" ) ) { if ( `objExists reserved_for_pSmooth_copies` == 0 ) { CreateEmptyGroup ; rename reserved_for_pSmooth_copies ; select -r $selection[$i] ; } setAttr ($shortShapeName[0] + ".overrideEnabled") 1; setAttr ($shortShapeName[0] + ".overrideShading") 1; polyDuplicateAndConnect; string $smoothedCopyName = ($shortObjectName + "_smoothedCopy"); //print (" CREATE - $smoothedCopyName = " + $smoothedCopyName + "\n" ) ; rename $smoothedCopyName; select -add reserved_for_pSmooth_copies ; Parent ; string $smoothedCopyShapeName[] = `ls -sl -s -dag -l` ; //print (" CREATE - $smoothedCopyShapeName1 = " + $smoothedCopyShapeName[0] + "\n" ) ; select -r $smoothedCopyName ; $numberOfFaces = `polyEvaluate -f $smoothedCopyName` ; int $allFaces = $numberOfFaces[0] ; polySmooth -dv 1 -c 1 -kb 0 -ksb 0 -kt 0 -ch 1 ( $smoothedCopyName + ".f[0:" + $allFaces + "]" ) ; string $checkForPolySmooth[] = `listConnections -t polySmoothFace $smoothedCopyShapeName`; string $polySmoothName = ("polySmoothFace_" + $shortObjectName) ; rename $checkForPolySmooth[0] $polySmoothName ; setAttr ($polySmoothName + ".keepBorder") 0; setAttr ($polySmoothName + ".inputComponents") -type "componentList" 1 "f[*]"; connectAttr -f ( $shortObjectName + ".translate") ( $smoothedCopyName + ".translate" ) ; connectAttr -f ( $shortObjectName + ".rotate") ( $smoothedCopyName + ".rotate" ) ; connectAttr -f ( $shortObjectName + ".scale") ( $smoothedCopyName + ".scale" ) ; select -r $smoothedCopyName ; setAttr ($smoothedCopyShapeName[0] + ".overrideEnabled") 1; setAttr ($smoothedCopyShapeName[0] + ".overrideDisplayType") 2; setAttr ($smoothedCopyShapeName[0] + ".castsShadows") 1; setAttr ($smoothedCopyShapeName[0] + ".primaryVisibility") 1; setAttr ($shortShapeName[0] + ".overrideShading") 0; setAttr ($shortShapeName[0] + ".primaryVisibility") 0; setAttr ($shortShapeName[0] + ".castsShadows") 0; int $mirrorChoice = `checkBox -q -v isItMirrored`; if ( $mirrorChoice == 1 ) { //string $smoothedCopyShapeName3[] = `ls -sl -s -dag -l` ; //print (" CREATE - $smoothedCopyShapeName3 = " + $smoothedCopyShapeName3[0] + "\n" ) ; instance -n ($smoothedCopyName + "_IC") $smoothedCopyName ; scale -r -1 1 1 ; connectAttr -f ( $shortObjectName + ".translate") ( $smoothedCopyName + "_IC.translate" ) ; connectAttr -f ( $shortObjectName + ".rotate") ( $smoothedCopyName + "_IC.rotate" ) ; float $originalObjectPivot[] = `xform -q -ws -t $shortObjectName`; group -n ( $smoothedCopyName + "_ICGRP" ) ( $smoothedCopyName + "_IC" ) ; xform -a -ws -piv $originalObjectPivot[0] $originalObjectPivot[1] $originalObjectPivot[2] ($smoothedCopyName + "_ICGRP") ; connectAttr -f ( $shortObjectName + ".scale") ( $smoothedCopyName + "_ICGRP.scale" ) ; } select $selection ; updateSmooth ; } else if ( ($smoothedCopyName[0] != "") && ( $objectType[1] == "mesh" ) ) { warning ( "--> \"" + $shortObjectName + "\" already has a pSmoothed Copy!!!"); print ("\n " + $smoothedCopyName[0]) ; } else if ( ($smoothedCopyName[0] == "") && ( $objectType[1] != "mesh" ) ) { warning ( "--> \"" + $shortObjectName + "\" is NOT a polygonal object!!!"); } } else warning ( "--> \"" + $shortObjectName + "\" is not a unique name => skipping!" ) ; } select -r $selection; } else warning "--> Select a polygonal object first!!!"; } // ======================= // polySmooth UI // ======================= global proc pSmooth () { global string $pSmoothVersion; if ((`window -ex pSmoothWindow`) == true) deleteUI pSmoothWindow; //windowPref -remove pSmoothWindow; window -widthHeight 205 155 -title ("pSmooth " + $pSmoothVersion) pSmoothWindow; string $form = `formLayout -numberOfDivisions 100`; string $separator1 = `separator -height 5 -style "out"` ; string $separator2 = `separator -height 5 -style "out"` ; string $a0 = `button -bgc 0.62 0.73 0.60 -height 24 -label "Show/Hide Low-rez Cage" -command "showHideLowRez"`; string $a1 = `button -bgc 0.90 0.80 0.56 -height 24 -label "Create Smoothed Copy" -command "pSmoothAction"`; string $a2 = `button -bgc 0.58 0.70 0.73 -height 24 -label "Delete Smoothed Copy" -command "deleteSmoothedCopy"`; string $cb1 = `checkBox -label "mirror " -align "right" isItMirrored`; string $title1 = `text -al "center" -fn "smallFixedWidthFont" -label "Smooth Level (1-3)"` ; string $b1 = `intSliderGrp -field true -width 40 -minValue 1 -maxValue 3 -cw2 30 50 -ad2 2 -ss 1 -value 1 smoothField`; string $b2 = `button -height 22 -label "Update!" -command "updateSmooth"`; string $b3 = `button -height 24 -label "Mirror Geometry" -command "mirrorGeo"`; string $b4 = `button -height 24 -label "Soften/harden" -command "softenHardenGeo"`; string $b5 = `button -height 24 -label "Delete Half" -command "deleteHalfGeo"`; string $b6 = `button -height 24 -label "Help" -command "helpWin"`; formLayout -edit // ==================================================================== -attachForm $a0 "top" 1 -attachForm $a0 "left" 2 -attachForm $a0 "right" 2 -attachControl $a1 "top" 1 $a0 -attachForm $a1 "left" 2 -attachPosition $a1 "right" 10 75 -attachControl $cb1 "top" 4 $a0 -attachControl $cb1 "left" 2 $a1 -attachForm $cb1 "right" 2 -attachControl $a2 "top" 1 $a1 -attachForm $a2 "left" 2 -attachForm $a2 "right" 2 -attachControl $separator1 "top" 1 $a2 -attachForm $separator1 "left" 0 -attachForm $separator1 "right" 0 -attachControl $title1 "top" 1 $separator1 -attachForm $title1 "left" 2 -attachForm $title1 "right" 2 -attachControl $b1 "top" 1 $title1 -attachForm $b1 "left" 4 -attachPosition $b1 "right" 50 90 -attachControl $b2 "top" 0 $title1 -attachControl $b2 "left" 2 $b1 -attachForm $b2 "right" 2 -attachControl $separator2 "top" 1 $b1 -attachForm $separator2 "left" 0 -attachForm $separator2 "right" 0 -attachControl $b3 "top" 2 $separator2 -attachForm $b3 "left" 2 -attachPosition $b3 "right" 2 53 -attachControl $b4 "top" 2 $separator2 -attachControl $b4 "left" 2 $b3 -attachForm $b4 "right" 2 -attachControl $b5 "top" 1 $b4 -attachForm $b5 "left" 2 -attachPosition $b5 "right" 2 53 -attachControl $b6 "top" 1 $b4 -attachControl $b6 "left" 2 $b5 -attachForm $b6 "right" 2 // ==================================================================== $form; showWindow pSmoothWindow; }