您的位置:首页 > 其它

mel加载一个物体不同姿态的模型实现动画效果

2015-12-18 22:50 477 查看
题目,我从VS导出一个物体的不同姿态生成一系列obj文件



然后想通过MAYA MEL来实现这一系列的动画

script如下:

global proc loadObjs()
{
    string $pathOfFiles = "G:\\My_Works\\3D\\Physical_based_simulation\\Physical_based_simulation\\model\\obj0_";
    string $fileType = ".obj";
    int $start = 0;
    int $end = 228;
    int $i;
    for($i = $start; $i <= $end; ++$i)
    {
        $fullfilename=$pathOfFiles+$i+$fileType;
        file -i $fullfilename;// load obj file into maya
    }
}

global proc animateObj()
{	
	string $obj, $index;
	string $objects[] = `ls -transforms "obj0_*_pPlane1"`; // list all transform objects
	
	int $i, $num = `size($objects)`;
	playbackOptions -minTime 0 -maxTime $num; // set length of the playback
	
	for ($i = 0; $i <= $num; ++$i)
	{
        currentTime -edit ($i);// edit ith frame
    	for ($obj in $objects)
    	{
			$index = substituteAllString($obj, "obj0_", "");// drop "obj0_" in obj name
	    	$index = substituteAllString($index, "_pPlane1", ""); // drop "_pPlane1" in obj name
       		
    	    if (((int)$index == $i - 1) || ((int)$index == $i + 1))//为什么要+1,因为每帧需要初始化为不透明
    	    {
    	        setAttr ($obj + ".visibility") 0 ;
    	        setKeyframe -attribute "visibility" $obj;
    	    }
    	    else if ($i == (int)$index)
    	    {
    	        setAttr ($obj + ".visibility") 1;
    	        setKeyframe -attribute "visibility" $obj;
    	    }
    	}
    	
	}
    currentTime -edit 1;// return back to the ith frame
}
//loadObjs(); // only run at the first time
animateObj();


整个脚本的大概意思就是先用loadObjs()函数加载每个obj文件

加载后的界面如下:



然后用animateObj函数,在每一帧的时候设置第i个物体为可见,第i-1个物体为不可见,并且在这帧只操作这两个物体为关键帧

最后结果为(只取一帧来显示):



最后右击帧条,选择playblast就可以产生视频了

视频地址:https://youtu.be/RT6ONa60ToQ
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: