代码之家  ›  专栏  ›  技术社区  ›  123iamking

maya mel脚本-将轴放到对象的底部?

mel
  •  0
  • 123iamking  · 技术社区  · 6 年前

    我看到以前有人问过这个问题(例如: here )。那么,如何自动将轴心设置到模型的底部呢?

    1 回复  |  直到 6 年前
        1
  •  0
  •   123iamking    6 年前

    这样做:

    步骤1: find the bottom point .

    步骤2:将轴设置为底点。

    以下是MEL脚本帮助您执行此操作:

        string $sel[]= `ls -sl`;
    
        //$sel[0] != "" to check if the first item is empty, but `size $sel` == 1 already cover that
        if(`size $sel` > 0)
        {
            int $vtxIdx;
            int $vCount[];
            float $lowestY = 2147483647.0;
            float  $crtY = 0.0;
            float $pos[];
    
            string $item;
            for ($item in $sel)
            {
                $vCount = `polyEvaluate -vertex $item`; //Get vertex count
                for ($vtxIdx = 0; $vtxIdx < $vCount[0]; $vtxIdx++)//Loop through vetex
                {
                    $pos = `xform -q -ws -t ($item+".vtx["+$vtxIdx+"]")`;//Get vertex position
                    $crtY = $pos[1];
                    if($crtY < $lowestY)
                    {
                        $lowestY = $crtY;//Get the lowest Y
                    }
                }
                $pos = `xform -q -ws -t ($item)`;
                xform -ws -a -piv $pos[0] $lowestY $pos[2] ($item);
                print ($lowestY);
            }
    
        }
    

    用途:

    步骤1:选择需要将pivot设置为bottom的对象

    步骤2:执行脚本

    轴心点应该这样设置 Pivot to bottom 如果您的要求是:轴心点必须在模型中,那么您应该稍微编辑一下这个脚本。