问题
How to get bottom point of model via Mel script?
If I can get the Y-coordinate of the bottom point, I can get the point of the bottom, but I can't figure out how to get it.
回答1:
Looping through all vertices can be slow, especially with a dense mesh. What can be done instead is to use the object's bounding box:
float $bb[] = `getAttr pCube1.boundingBoxMin`;
print($bb[1]); // Lowest position in Y
Another benefit of this is that you aren't relying on vertices, so it doesn't have to be a polygonal mesh.
回答2:
If I can get the Y-coordinate of the bottom point, I can get the point of the bottom, but I can't figure out how to get it.
I figure it out: Y-coordinate of the bottom point = Y-coordinate of the lowest vertex of the model. So do it like this: Loop through all vertices to get the lowest vertex.
Assume the target object is: "pCube1". Here is the code to get the lowest Y.
int $vtxIdx;
int $vCount[] = `polyEvaluate -vertex pCube1`; //Get vertex count
float $lowestY = 2147483647.0;
float $crtY = 0.0;
for ($vtxIdx = 0; $vtxIdx < $vCount[0]; $vtxIdx++)//Loop through vetex
{
float $pos[] = `xform -q -ws -t ("pCube1.vtx["+$vtxIdx+"]")`;//Get vertex position
$crtY = $pos[1];
if($crtY < $lowestY)
{
$lowestY = $crtY;//Get the lowest Y
}
}
print ($lowestY);
So the lowest point = (pCube1.X, lowestY, pCube1.Z).
来源:https://stackoverflow.com/questions/50757011/maya-mel-script-how-to-get-bottom-point-of-model