//The autoColor process was developed by Ted Forgrave and Ben Bathen. //ted@megoodanimator.com //www.benbathen.com global proc autoColor() { string $sel[] = `ls -sl`; if (size ($sel) > 1) { error "Select only one object at a time."; } if (size ($sel) == 0) { error "Select at least one polygonal object."; } int $howManyFaces2[] = `polyEvaluate -f $sel[0]`; //Make all 6 shaders if ((`objExists XpositiveShader`) != 1) { string $shaderName = `shadingNode -asShader lambert -n "XpositiveShader"`; sets -renderable true -noSurfaceShader true -empty -name XpositiveShaderSG; connectAttr -f XpositiveShader.outColor XpositiveShaderSG.surfaceShader; setAttr "XpositiveShader.color" 1 .48 .48 ; addAttr -dt "string" -ln "projectionName" $shaderName; } if ((`objExists XnegativeShader`) != 1) { string $shaderName = `shadingNode -asShader lambert -n "XnegativeShader"`; sets -renderable true -noSurfaceShader true -empty -name XnegativeShaderSG; connectAttr -f XnegativeShader.outColor XnegativeShaderSG.surfaceShader; setAttr "XnegativeShader.color" .57 .14 .14 ; addAttr -dt "string" -ln "projectionName" $shaderName; } if ((`objExists YpositiveShader`) != 1) { string $shaderName = `shadingNode -asShader lambert -n "YpositiveShader"`; sets -renderable true -noSurfaceShader true -empty -name YpositiveShaderSG; connectAttr -f YpositiveShader.outColor YpositiveShaderSG.surfaceShader; setAttr "YpositiveShader.color" .3 1 .4 ; addAttr -dt "string" -ln "projectionName" $shaderName; } if ((`objExists YnegativeShader`) != 1) { string $shaderName = `shadingNode -asShader lambert -n "YnegativeShader"`; sets -renderable true -noSurfaceShader true -empty -name YnegativeShaderSG; connectAttr -f YnegativeShader.outColor YnegativeShaderSG.surfaceShader; setAttr "YnegativeShader.color" .0 .4 .01 ; addAttr -dt "string" -ln "projectionName" $shaderName; } if ((`objExists ZpositiveShader`) != 1) { string $shaderName = `shadingNode -asShader lambert -n "ZpositiveShader"`; sets -renderable true -noSurfaceShader true -empty -name ZpositiveShaderSG; connectAttr -f ZpositiveShader.outColor ZpositiveShaderSG.surfaceShader; setAttr "ZpositiveShader.color" .56 .56 1 ; addAttr -dt "string" -ln "projectionName" $shaderName; } if ((`objExists ZnegativeShader`) != 1) { string $shaderName = `shadingNode -asShader lambert -n "ZnegativeShader"`; sets -renderable true -noSurfaceShader true -empty -name ZnegativeShaderSG; connectAttr -f ZnegativeShader.outColor ZnegativeShaderSG.surfaceShader; setAttr "ZnegativeShader.color" .16 .16 .5 ; addAttr -dt "string" -ln "projectionName" $shaderName; } //loop through faces on object for ($x=0;$x<$howManyFaces2[0];$x++) { string $selFace = ($sel[0] + ".f[" + $x + "]"); //this section gets the normal direction from the selected face string $normalFromFaceString[] =`polyInfo -fn $selFace`; string $filtered[]; tokenize $normalFromFaceString[0] ". " $filtered; //by default, the polyInfo -fn gives the normal vector in string format //so it has to be converted to a float string $assembledXString = $filtered[2] + "." + $filtered[3]; string $assembledYString = $filtered[4] + "." + $filtered[5]; string $assembledZString = $filtered[6] + "." + $filtered[7]; float $xDirection = $assembledXString; float $yDirection = $assembledYString; float $zDirection = $assembledZString; /* print "\n"; print "\n"; print $xDirection; print "\n"; print $yDirection; print "\n"; print $zDirection; print "\n"; */ //this section decides which direction the normal is pointing and assigns a shader if ((`abs $xDirection` >= `abs $yDirection`) && (`abs $xDirection` >= `abs $zDirection`)) { if ($xDirection > 0) { //print "+X Shader"; //print "\n"; sets -e -forceElement XpositiveShaderSG $selFace; } else { //print "-X Shader"; //print "\n"; sets -e -forceElement XnegativeShaderSG $selFace; } } if ((`abs $yDirection` >= `abs $xDirection`) && (`abs $yDirection` >= `abs $zDirection`)) { if ($yDirection > 0) { //print "+Y Shader"; //print "\n"; sets -e -forceElement YpositiveShaderSG $selFace; } else { //print "-Y Shader"; //print "\n"; sets -e -forceElement YnegativeShaderSG $selFace; } } if ((`abs $zDirection` > `abs $xDirection`) && (`abs $zDirection` > `abs $yDirection`)) { if ($zDirection > 0) { //print "+Z Shader"; //print "\n"; sets -e -forceElement ZpositiveShaderSG $selFace; } else { //print "-Z Shader"; //print "\n"; sets -e -forceElement ZnegativeShaderSG $selFace; } } } }