/* beginHelpText createLoRez.mel pthuriot 061004 -=OVERVIEW=- Use this tool to quickly create basic loRez geometries for a rig. -=RETURN=- -=NONE=- -=EXAMPLES=- Bind a creature via normal tools. Select the boundSkin and run tool. it will create loRez geo (default sizes are changable) per joints. Edit these new geometries quickly to closely match the volume. Run the finalize tool to snap each vert to the bound surface's closest point. Edit till your hearts content. -=REQUIRES=- -=NONE=- -=UPDATES=- version 1.0 061004 pthuriot initial, basic tool. endHelpText */ //beginProcHelp==================================================================== // PROCEDURE: createLoRez_createGeo (local) // ARGUEMENTS: joint to create geo for (string) // poly subDivisions X (int) // poly subDivisions Y (int) // poly subDivisions Z (int) // RETURN: newly created geo (string) // DESCRIPTION: will create a polyGeo for the given joint and parent/ orient it //endProcHelp====================================================================== proc string createLoRez_createGeo(string $joint, int $subDivX, int $subDivY, int $subDivZ) { string $loRezGeo; string $childJt[] = `listRelatives -c -pa -type "joint" $joint`; if(`objExists $childJt[0]`) { float $tx = `getAttr ($childJt[0] + ".tx")`; if(abs($tx) > 0.0) { //make a "defaultGeo" string $pc[] = `polyCylinder -ax 0 0 0 -sx $subDivX -sy $subDivY -sz $subDivZ -name ($joint+"loRezGeo_#")`; xform -a -ws -piv 0 -1 0 $pc[0]; xform -a -ws -t 0 1 0 $pc[0]; if($tx > 0) xform -a -ws -ro 0 0 -90 $pc[0]; else xform -a -ws -ro 0 0 90 $pc[0]; makeIdentity -apply true -t 1 -r 1 -s 1 $pc[0]; DeleteHistory $pc[0]; //apply the defaultGeo to the specified joint string $bb[] = `parent $pc[0] $joint`; setAttr ($bb[0] +".t") 0 0 0; setAttr ($bb[0] +".r") 0 0 0; setAttr ($bb[0] + ".sx") ((abs($tx))/2); makeIdentity -apply true -t 1 -r 1 -s 1 $bb[0]; $loRezGeo = $bb[0]; } } return $loRezGeo; } //beginProcHelp==================================================================== // PROCEDURE: createLoRez_moveGeo (local) // ARGUEMENTS: loRez geo to edit (string) // bound skin surface to "match" (string) // RETURN: NONE // DESCRIPTION: will find the closest point on the boundSkin mesh for each // polyVert of the loRez geo and move the vert to it via // geometryConstraint cheat //endProcHelp====================================================================== proc createLoRez_moveGeo(string $loRez, string $skin) { string $loc[] = `spaceLocator -p 0 0 0`; select -r ($loRez+".vtx[*]"); string $points[] = `ls -sl -flatten`; for ($point in $points) { float $xyzs[] = `xform -a -ws -q -t $point`; xform -a -ws -t $xyzs[0] $xyzs[1] $xyzs[2] $loc[0]; string $geoCon[] = `geometryConstraint $skin $loc[0]`; float $to[] = `xform -a -ws -q -t $loc[0]`; xform -a -ws -t $to[0] $to[1] $to[2] $point; delete $geoCon[0]; flushUndo; } delete $loc; } //beginProcHelp==================================================================== // PROCEDURE: createLoRez (global) // ARGUEMENTS: NONE // RETURN: NONE // DESCRIPTION: initial call to the tool. UI //endProcHelp====================================================================== global proc createLoRez() { if(`window -exists createLoRez_ui`) deleteUI createLoRez_ui; window -t "Create LoRez Geo" createLoRez_ui; columnLayout -adj 1; string $divX = `intSliderGrp -label "Divisions X" -field true -minValue 1 -maxValue 10 -fieldMinValue 1 -fieldMaxValue 100 -value 6`; string $divY = `intSliderGrp -label "Divisions Y" -field true -minValue 1 -maxValue 10 -fieldMinValue 1 -fieldMaxValue 100 -value 2`; string $divZ = `intSliderGrp -label "Divisions Z" -field true -minValue 0 -maxValue 10 -fieldMinValue 0 -fieldMaxValue 100 -value 0`; button -l "Create Lo Rez By SkinCluster" -ann "Select at least one bound surface and run" -c ("createLoRez_bySkinCluster "+$divX+" "+$divY+" "+$divZ); button -l "Adjust For Closest Points" -ann "Select all the new Geo Surfaces THEN the single boundSkin surface to match and run" -c ("createLoRez_moveGeoAfter"); showWindow createLoRez_ui; } //beginProcHelp==================================================================== // PROCEDURE: createLoRezBySkinCluster (global) // ARGUEMENTS: DivX ui (string) // DivY ui (string) // DivZ ui (string) // RETURN: NONE // DESCRIPTION: call to the tool. will read GUI and run //endProcHelp====================================================================== global proc createLoRez_bySkinCluster(string $divX, string $divY, string $divZ) { int $sx = `intSliderGrp -q -v $divX`; int $sy = `intSliderGrp -q -v $divY`; int $sz = `intSliderGrp -q -v $divZ`; string $loRezGeo[]; clear($loRezGeo); int $cur = 0; string $selSurfs[] = `ls -sl`; if(`size($selSurfs)` < 1) error("createLoRez_bySkinCluster :: Select At least one bound surface"); for($each in $selSurfs) { string $skinCluster = `findRelatedSkinCluster $each`; string $scJts[] = `skinCluster -q -wi $skinCluster`; string $shape[] = `listRelatives -s -pa $each`; for($joint in $scJts) { string $geo = `createLoRez_createGeo $joint $sx $sy $sz`; if (`objExists $geo`) { $loRezGeo[$cur]= $geo; $cur++; } } } select -cl; for ($each in $loRezGeo) select -add $each; } //beginProcHelp==================================================================== // PROCEDURE: createLoRez_moveGeoAfter (global) // ARGUEMENTS: NONE // RETURN: NONE // DESCRIPTION: Will move all select geoVerts to the closest points on the // last select bound surface via geometryConstraints //endProcHelp====================================================================== global proc createLoRez_moveGeoAfter() { global string $gMainProgressBar; string $sel[] = `ls -sl`; select -cl; progressBar -edit -beginProgress -isInterruptable true -status "Adjusting LoRez Geo..." -maxValue (size($sel)-1) $gMainProgressBar; for ($i = 0; $i < (size($sel)-1); $i++) { if(`progressBar -query -isCancelled $gMainProgressBar`) break; progressBar -edit -step 1 $gMainProgressBar; createLoRez_moveGeo $sel[$i] $sel[(size($sel)-1)]; } progressBar -edit -endProgress $gMainProgressBar; select -cl; }