Maya Mel Script - 如何获得模型的底点?

Maya Mel Script - How to get bottom point of model?

如何通过Mel脚本获取模型的底点?

如果我能得到底部点的y坐标,我就可以得到底部的点,但我不知道如何得到。

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.

我算出来了:底点Y坐标=模型最低顶点Y坐标。所以这样做:遍历所有顶点以获得最低顶点。

假设目标对象是:"pCube1"。这是获得最低 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);

所以最低点=(pCube1.X,lowestY,pCube1.Z).

遍历所有顶点可能会很慢,尤其是对于密集网格。可以做的是使用对象的边界框:

float $bb[] = `getAttr pCube1.boundingBoxMin`;
print($bb[1]); // Lowest position in Y

这样做的另一个好处是您不依赖于顶点,因此它不必是多边形网格。