// aimNormalToCamera takes all the selected vertexFaces (or the vertexFaces associated with // selected faces, edges, or vertexes), and point their normals toward the Perspective camera. // // Alex Hogan, Turbine proc aimNormalToCameraWork ( string $currentObject, string $camera ) { /* This procedure should handle the main work of grabbing the vector from each polygon vertexFace to the target object (persp cam) and setting the normal of the vertexFace to the normalized vector */ string $vertexFaceList[] = `polyListComponentConversion -toVertexFace $currentObject`; // convert and faces, edges, or normal vertex to their vertexFace equivalent $vertexFaceList = `filterExpand -sm 70 -ex true $vertexFaceList`; // expand the vertex face list into individual names, instead of Maya's default compressed format string $vtxFace; for ($vtxFace in $vertexFaceList) { float $vtx[3] = `xform -ws -q -t $vtxFace`; // gets the worldspace location of the vertexface in vector style form (i don't like Maya vectors, so it's an array) float $targetVect[3] = `xform -ws -q -t $camera`; // gets worldspace location of target object (camera) float $vectVal[3]; $vectVal[0] = $targetVect[0] - $vtx[0]; $vectVal[1] = $targetVect[1] - $vtx[1]; $vectVal[2] = $targetVect[2] - $vtx[2]; // this gives you $vectVal, which is the vector from the vtxFace to the target object (camera) //normalize da vector! warning, inefficient code ahead //also, I know there is a normalize command, but it doesn't work like I want it to. float $highestVal = $vectVal[0]; if ( abs($vectVal[1]) > abs($highestVal) ) $highestVal = $vectVal[1]; if ( abs($vectVal[2]) > abs($highestVal) ) $highestVal = $vectVal[2]; // gets the highest value of the 3 $vectVal[0] = $vectVal[0] / abs($highestVal); $vectVal[1] = $vectVal[1] / abs($highestVal); $vectVal[2] = $vectVal[2] / abs($highestVal); // normalizes the three numbers, keeping their relative values the same, ratio wise polyNormalPerVertex -xyz $vectVal[0] $vectVal[1] $vectVal[2] $vtxFace; //(normalized vector Should work damnit!) // (Might not work, since you may be doing shared normals one at a time, and // they could move each other as you do them) // could also try selecting groups of normals in the same affected family, and setting their // normals all at once } } global proc aimNormalToCamera () { $selectionList = `ls -sl`; //get selection list $curPanel = `getPanel -withFocus`; string $camera = `modelPanel -q -camera $curPanel`; for ($node in $selectionList) { aimNormalToCameraWork( $node, $camera ); } return; }