////////////////////////////////////////////////////////////////////// // // // Written by Ryan Ellis. April 1, 2007. // // Feel free to use as you wish. // // ////////////////////////////////////////////////////////////////////// global proc re_paintHairs() { /// Sets up the command and starts the paint tool artUserPaintToolScript 4; artUserPaintCtx -e -tsc "re_paintHairsSetup" `currentCtx`; re_paintHairsSetup artUserPaintContext; } global proc re_paintHairsSetup(string $toolContext) { /// Sets up the paint context and assigns the commands to the tool artUserPaintCtx -e -tcc "re_paintHairsCleanup" -ic "re_paintHairsSettings" -fc "re_paintHairsFinalize" -svc "re_paintHairsStroke" $toolContext; } global proc re_paintHairsCleanup (string $toolContextName) { /// command runs when tool is exited } global proc string re_paintHairsSettings(string $surfaceName) { /// Sets the flags for the return information Runs before each stroke global int $g_dup_count; $g_dup_count = 0; global string $paintGroup; $paintGroup = `group -empty -name "Hairs_#"`; ////////////////////////////////////////////////////////// Tweak this change the hair density int $gridDensity = 40; string $flags = ("-position world -normal world -uv surface -grid "+$gridDensity+" "+$gridDensity+" -jitter true -dither true"); return $flags; } global proc re_paintHairsFinalize(int $surfaceID) { } global proc re_paintHairsStroke( int $surfaceID, int $index, float $value, float $u, float $v, float $locx, float $locy, float $locz, float $normalx, float $normaly, float $normalz ) { /// command that runs per sample. gets uv values, world location and surface world normal global string $paintGroup; $locx = getCorrectUnits($locx); $locy = getCorrectUnits($locy); $locz = getCorrectUnits($locz); /////////////////////////////////////////////////////////////////// Tweak This For Length float $distRand = rand(.05,1.0); //Normal length //float $distRand = rand(.6,2.0); //Long length //float $distRand = rand(.005,0.1); //Stubble string $line = `curve -d 1 -p $locx $locy $locz -p (($locx)+$normalx*$distRand) (($locy)+$normaly*$distRand) (($locz)+$normalz*$distRand)`; string $lineRebuild[] = `rebuildCurve -ch 1 -rpo 1 -rt 0 -end 1 -kr 0 -kcp 0 -kep 1 -kt 0 -s 5 -d 3 -tol 1e-006 $line`; string $bend[] = `nonLinear -type bend -lowBound -1 -highBound 1 -curvature 0 $lineRebuild[0]`; float $rand1 = rand(0,2); float $rand2 = rand(-2,0); float $randRot[]; $randRot[0] = rand(-180,180); $randRot[1] = rand(-180,180); $randRot[2] = rand(-180,180); setAttr ($bend[0]+".curvature") 1; setAttr ($bend[0]+".highBound") $rand1; setAttr ($bend[0]+".lowBound") $rand2; rotate -r -os $randRot[0] $randRot[1] $randRot[2] $bend[1]; select $lineRebuild[0]; delete -ch; float $randRot2[]; /////////////////////////////////////////////////////////////////// These settings affect how the hairs lay //$randRot2[0] = rand(45,65); // Stand Up $randRot2[0] = rand(65,85); $randRot2[1] = rand(-40,40); $randRot2[2] = rand(0,0); move -a $locx $locy $locz ($lineRebuild[0]+".scalePivot") ($lineRebuild[0]+".rotatePivot") ; rotate -r -os $randRot2[0] $randRot2[1] $randRot2[2] $lineRebuild[0]; string $cross[0] = `circle -c 0 0 0 -nr 0 1 0 -sw 360 -r .006 -d 3 -ut 0 -tol 1e-006 -s 8 -ch 1`; string $surf[] = `extrude -ch true -rn false -po 1 -et 2 -ucp 1 -fpt 1 -upn 1 -rotation 0 -scale 1 -rsp 1 $cross[0] $lineRebuild[0]`; select $surf[0]; delete -ch; select $cross[0]; delete; select $lineRebuild[0]; delete; parent $surf[0] $paintGroup; select -cl; }