Does anyone have a sample script of snapping an object to the center of the selected poly face on another object?
say you have a cone named "polycone" and you want to snap it to the center of the selected face of an object called "polycylinder" so that "polycone" sticks out the normal of the face...
I looked at all the snapping scripts in downloads, and none of them seem to do that..
the Modify/Snap Together tool sort of works ( it's not centered, and I need to script it)..
thanks!!
this what the Snap Together tool does, but it's not much help..
The problem is not the positioning. Problem is to get the euler rotaion from the Vector of the selected face.
Good ol polyInfo -faceNormals delivers the face normal in its weirdy manner. So here is a helper for the start:
CODE global proc float[] getPolyFaceNormals(string $faces[]) { // expand face input $faces = filterExpand -ex 1 -sm 34 $faces; // if nothing given take selection if (!size($faces)) $faces = filterExpand -ex 1 -sm 34; float $return[]; int $count = 0; for ($face in $faces) { string $polyInfo[] = polyInfo -faceNormals $face; string $buffer[]; tokenize $polyInfo[0] $buffer; $return[$count++] = $buffer[2]; $return[$count++] = $buffer[3]; $return[$count++] = $buffer[4]; } return $return; } Put in an array of faces and get an array of float normals. Oh boy you are lucky that I'm interested in this. I wouldn't do a keystroke otherwise ;]
OK. Now how to get the euler rotation from that vector? I think we have to project the vector on each plane and get the angle via angle command. CODE float $faceNormal[] = getPolyFaceNormals($selFace); float $eulerRot[]; $eulerRot[0] = rad_to_deg(angle <<0, $faceNormal[1], $faceNormal[2]>> <<0,1,0>>); $eulerRot[1] = rad_to_deg(angle <<$faceNormal[0], 0, $faceNormal[2]>> <<1,0,0>>); $eulerRot[2] = rad_to_deg(angle <<$faceNormal[0], $faceNormal[1], 0>> <<0,1,0>>);
But thats still not it.. I had this problem already. We have to flip some axes here if they are negative or something...
How about this for finding the normal of the selected face? I was thinking about having it snap to a single face,, but I guess the option for more would be better. As for figuring out the rotation,, I'm in way over my head..
string $selected[] = ls -sl; // this checks the direction of selected face