ロゴ メインコンテンツへ
RSSフィード
「デジタルコンテンツ制作」に関連する記事一覧

MEL 階層構造を無視してGeometry Cache作成

2011/10/12
(この記事の文字数: 1758)
トランスフォームノードの親子階層を無視して親子付けされているポリゴンのアニメーションを頂点にベイクするMELスクリプトを載せます。

ジオメトリキャッシュをとるときに親にアニメーションがついているオブジェクトだと親のアニメーションデータが完全に無視されてジオメトリキャッシュがとられてしまうようなので、それを回避するためのスクリプトです。どんな方法でポリゴンオブジェクトにアニメーションをつけていたとしても、このスクリプトでは毎フレーム頂点のワールド座標を記録していくので、ベイク後にポリゴンアニメーションをジオメトリキャッシュに変換することができます。

追記 ---------------------------------------------
ポリゴンモデルの頂点をベイクしたい場合であれば、このスクリプトを使わなくても親子構造を持っているジオメトリ群をcombineしてあげれば、簡単にアニメーションをベイクできることがわかりました。このスクリプトが有効なのはポリゴン以外ということになります。スクリプト内のfilterExpand -sm 31のセレクションマスク31を変えるとControl Vertexなどの他のコンポーネントでも行けるはずです。
----------------------------------------------------

ただし、このスクリプトはループ回数が頂点数xフレーム数なので、ポリゴン数が多いとめちゃくちゃ重くなるので実用的ではありません。本来ならスクリプトではなくplug-inで作るべき機能です。それだけ注意して下さい。

This is a MEL script for baking animation on vertices ignoring transform hierarchical structure.
However, it is very slow. Actually, it has to be developed as plug-in made by C++.
 
source code
global proc bakeTransformedVertices(string $target_obj,
                                                                      string $src_obj,
                                                                      int $start_frame,
                                                                      int $end_frame)
{
    float $init_pos_ls[], $tmp[], $posw[];
    int $frame;
    string $vtxs[] = `filterExpand -sm 31 ($src_obj+".vtx[*]")`;
    string $tv;
    int $end = $end_frame+1;
    int $i=0;
    currentTime $start_frame;
    for($v in $vtxs){
       $tv = ($target_obj+".vtx["+$i+"]");
        $tmp = `xform -q -t -ws $v`;
        $init_pos_ls[$i*3]  = $tmp[0];
        $init_pos_ls[$i*3+1]= $tmp[1];
        $init_pos_ls[$i*3+2]= $tmp[2];
        setKeyframe $tv;
        $i++;
    }
    for($frame=$start_frame+1; $frame<$end; $frame++){
        currentTime $frame;
        int $i=0;
        for($v in $vtxs){
            $tv = ($target_obj+".vtx["+$i+"]");
            $posw = `xform -q -t -ws $v`;
            xform -ws -t $posw[0] $posw[1] $posw[2] $tv;
            setKeyframe $tv;
            $i++;
        }
    }
}
 

How to use

1. duplicate source object you want to convert into geometry cache
2. execute following command in script editor, 

bakeTransformedVertices(A, B, C, D);

where
A is destination object name
B is source object name
C is start frame number
D is end frame number

Example
bakeTransformedVertices("destObjName", "srcObjName", 1, 100);

  このエントリーをはてなブックマークに追加  

<<「デジタルコンテンツ制作」の記事一覧に戻る

<<「デジタルコンテンツ制作」の次の記事
「デジタルコンテンツ制作」の前の記事 >>

コメント(0 件)



コンテンツロード: 0.0081 sec
Copyright(C)2006-2024 puarts All Rights Reserved