//The autoColor process was developed by Ted Forgrave and Ben Bathen. //ted@megoodanimator.com //www.benbathen.com global proc autoProjection() { string $objSel[] = `ls -sl`; string $sel[] = `listShaders`; //get shaders assigned to geometry if ((`attributeExists "projectionSize" $objSel[0]`) == 0) { //make an attribute on object that controls all the projections addAttr -ln projectionSize -at double $objSel[0]; setAttr -k 1 ($objSel[0] + ".projectionSize"); setAttr ($objSel[0] + ".projectionSize") 4; } string $current; //string $selFaces[]; for ($current in $sel) { string $shaderName; string $currentUpper = `toupper $current`; if ((`gmatch $currentUpper "*XPOS*"`) || (`gmatch $currentUpper "*XUP*"`)) { $shaderName = "XPos"; } if ((`gmatch $currentUpper "*XNEG*"`) || (`gmatch $currentUpper "*XDOWN*"`)) { $shaderName = "XNeg"; } if ((`gmatch $currentUpper "*YPOS*"`) || (`gmatch $currentUpper "*YUP*"`)) { $shaderName = "YPos"; } if ((`gmatch $currentUpper "*YNEG*"`) || (`gmatch $currentUpper "*YDOWN*"`)) { $shaderName = "YNeg"; } if ((`gmatch $currentUpper "*ZPOS*"`) || (`gmatch $currentUpper "*ZUP*"`)) { $shaderName = "ZPos"; } if ((`gmatch $currentUpper "*ZNEG*"`) || (`gmatch $currentUpper "*ZDOWN*"`)) { $shaderName = "ZNeg"; } switch ($shaderName) { case "XPos": hyperShade -objects $current; string $Xpos[] = `ls -sl`; //make sure shader has at least one face assigned to it if ((size($Xpos)) != 0) { string $projX[] = `polyPlanarProjection -md x $Xpos`; setAttr ($projX[0] + ".projectionHeight") 4; setAttr ($projX[0] + ".projectionWidth") 4; connectAttr -f ($objSel[0] + ".projectionSize") ($projX[0] + ".projectionHeight"); connectAttr -f ($objSel[0] + ".projectionSize") ($projX[0] + ".projectionWidth"); string $newProjectionName = `rename $projX rightSideProjection`; setAttr -type "string" ($current + ".projectionName") $newProjectionName; } break; case "XNeg": hyperShade -objects $current; string $Xneg[] = `ls -sl`; //make sure shader has at least one face assigned to it if ((size($Xneg)) != 0) { string $projX[] = `polyPlanarProjection -md x $Xneg`; setAttr ($projX[0] + ".rotateY") (-90); setAttr ($projX[0] + ".projectionHeight") 4; setAttr ($projX[0] + ".projectionWidth") 4; connectAttr -f ($objSel[0] + ".projectionSize") ($projX[0] + ".projectionHeight"); connectAttr -f ($objSel[0] + ".projectionSize") ($projX[0] + ".projectionWidth"); string $newProjectionName = `rename $projX leftSideProjection`; setAttr -type "string" ($current + ".projectionName") $newProjectionName; } break; case "YPos": hyperShade -objects $current; string $Ypos[] = `ls -sl`; //make sure shader has at least one face assigned to it if ((size($Ypos)) != 0) { string $projY[] = `polyPlanarProjection -md y $Ypos`; setAttr ($projY[0] + ".projectionHeight") 4; setAttr ($projY[0] + ".projectionWidth") 4; connectAttr -f ($objSel[0] + ".projectionSize") ($projY[0] + ".projectionHeight"); connectAttr -f ($objSel[0] + ".projectionSize") ($projY[0] + ".projectionWidth"); string $newProjectionName = `rename $projY topSideProjection`; setAttr -type "string" ($current + ".projectionName") $newProjectionName; } break; case "YNeg": hyperShade -objects $current; string $Yneg[] = `ls -sl`; //make sure shader has at least one face assigned to it if ((size($Yneg)) != 0) { string $projY[] = `polyPlanarProjection -md y $Yneg`; setAttr ($projY[0] + ".rotateX") 90; setAttr ($projY[0] + ".projectionHeight") 4; setAttr ($projY[0] + ".projectionWidth") 4; connectAttr -f ($objSel[0] + ".projectionSize") ($projY[0] + ".projectionHeight"); connectAttr -f ($objSel[0] + ".projectionSize") ($projY[0] + ".projectionWidth"); string $newProjectionName = `rename $projY bottomSideProjection`; setAttr -type "string" ($current + ".projectionName") $newProjectionName; } break; case "ZPos": hyperShade -objects $current; string $Zpos[] = `ls -sl`; //make sure shader has at least one face assigned to it if ((size($Zpos)) != 0) { string $projZ[] = `polyPlanarProjection -md z $Zpos`; setAttr ($projZ[0] + ".projectionHeight") 4; setAttr ($projZ[0] + ".projectionWidth") 4; connectAttr -f ($objSel[0] + ".projectionSize") ($projZ[0] + ".projectionHeight"); connectAttr -f ($objSel[0] + ".projectionSize") ($projZ[0] + ".projectionWidth"); string $newProjectionName = `rename $projZ frontSideProjection`; setAttr -type "string" ($current + ".projectionName") $newProjectionName; } break; case "ZNeg": hyperShade -objects $current; string $Zneg[] = `ls -sl`; //make sure shader has at least one face assigned to it if ((size($Zneg)) != 0) { string $projZ[] = `polyPlanarProjection -md z $Zneg`; setAttr ($projZ[0] + ".rotateY") 180; setAttr ($projZ[0] + ".projectionHeight") 4; setAttr ($projZ[0] + ".projectionWidth") 4; connectAttr -f ($objSel[0] + ".projectionSize") ($projZ[0] + ".projectionHeight"); connectAttr -f ($objSel[0] + ".projectionSize") ($projZ[0] + ".projectionWidth"); string $newProjectionName = `rename $projZ backSideProjection`; setAttr -type "string" ($current + ".projectionName") $newProjectionName; } break; } } select -cl; } ////////////////////////////////// global proc string[] listShaders() ////////////////////////////////// { string $sel[] = `ls -sl`; select -cl; string $allShaders[] =`ls -mat`; string $assignedShaders[]; string $current; int $z = 0; //to increment the new assignedShader array for ($current in $allShaders) { string $currentUpper = `toupper $current`; if ((`gmatch $currentUpper "*X*"`) || (`gmatch $currentUpper "*Y*"`) || (`gmatch $currentUpper "*Z*"`)) { //print "*****************************************"; //print "\n"; //print $current; //print "\n"; //list connections on $current shader in the loop string $shaderConnections[] = `listConnections $current`; //loop through connections on the shader and ... for ($x=0;$x " + $engineConnections[$y]); //print "\n"; //print "\n"; if ($engineConnections[$y] == $sel[0]) { $assignedShaders[$z] = $current; $z++; } } } } } } //print ($sel[0] + " is attached to shader "); //print "\n"; //print $assignedShaders; return $assignedShaders; }