Maya坐標歸到模型中心底部代碼1

原理:

抓取軸向數(shù)據(jù)(從右側(cè)屬性數(shù)據(jù)里抓取,并不是坐標所在位置的數(shù)據(jù)),然后找到模型最低點,把移動放過去。



比如原始坐標數(shù)據(jù)就在物體中心,他就會在物體中心底部。




比如原始坐標數(shù)據(jù)為不在模型身上,他就會抓取x和z軸數(shù)據(jù),y的數(shù)據(jù)在模型底部

所以在執(zhí)行之前最好坐標歸位到物體中心,烘焙坐標數(shù)據(jù),再執(zhí)行代碼。
如果多選模型,則x、z按照數(shù)字數(shù)據(jù),y軸所有模型的最低點。

代碼:

 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. 將代碼復(fù)制,粘貼到MEL代碼窗口



  2. 選中要修改的模型,把坐標歸位到物體中心,烘焙坐標數(shù)據(jù),直接按藍色播放鍵或者小鍵盤的enter執(zhí)行代碼

  3. 全選代碼按住中間拖到工具欄里生成按鈕


引用地址1
引用地址2

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容