博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mel加载一个物体不同姿态的模型实现动画效果
阅读量:4041 次
发布时间:2019-05-24

本文共 1635 字,大约阅读时间需要 5 分钟。

题目,我从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 timeanimateObj();

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

加载后的界面如下:

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

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

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

视频地址:https://youtu.be/RT6ONa60ToQ

你可能感兴趣的文章
Maven跳过单元测试的两种方式
查看>>
通过C++反射实现C++与任意脚本(lua、js等)的交互(二)
查看>>
利用清华镜像站解决pip超时问题
查看>>
[leetcode BY python]1两数之和
查看>>
微信小程序开发全线记录
查看>>
PTA:一元多项式的加乘运算
查看>>
CCF 分蛋糕
查看>>
解决python2.7中UnicodeEncodeError
查看>>
小谈python 输出
查看>>
Django objects.all()、objects.get()与objects.filter()之间的区别介绍
查看>>
python:如何将excel文件转化成CSV格式
查看>>
机器学习实战之决策树(一)
查看>>
机器学习实战之决策树二
查看>>
[LeetCode By Python]7 Reverse Integer
查看>>
[leetCode By Python] 14. Longest Common Prefix
查看>>
[LeetCode By Python]118. Pascal's Triangle
查看>>
[LeetCode By Python]121. Best Time to Buy and Sell Stock
查看>>
[LeetCode By Python]122. Best Time to Buy and Sell Stock II
查看>>
[LeetCode By Python]125. Valid Palindrome
查看>>
[LeetCode By Python]136. Single Number
查看>>