//by 喵喵动画屋 旋转归零
string $lanzi[] = `ls -sl`;
int $shuliang = size($lanzi);
print($shuliang+"\n");
for($i=0;$i<$shuliang;$i++)
{
print($lanzi[$i]+"\n");
int $rotate_ret = `getAttr -se ($lanzi[$i]+".rotateX")`;
if($rotate_ret==1)
{
setAttr ($lanzi[$i]+".rotateX") 0;
}
$rotate_ret = `getAttr -se ($lanzi[$i]+".rotateY")`;
if($rotate_ret==1)
{
setAttr ($lanzi[$i]+".rotateY") 0;
}
$rotate_ret = `getAttr -se ($lanzi[$i]+".rotateZ")`;
if($rotate_ret==1)
{
setAttr ($lanzi[$i]+".rotateZ") 0;
}
print($rotate_ret+"\n");
}
//by 喵喵动画屋 平移归零
string $lanzi[] = `ls -sl`;
int $shuliang = size($lanzi);
print($shuliang+"\n");
for($i=0;$i<$shuliang;$i++)
{
print($lanzi[$i]+"\n");
int $translate_ret = `getAttr -se ($lanzi[$i]+".translateX")`;
if($translate_ret==1)
{
setAttr ($lanzi[$i]+".translateX") 0;
}
$translate_ret = `getAttr -se ($lanzi[$i]+".translateY")`;
if($translate_ret==1)
{
setAttr ($lanzi[$i]+".translateY") 0;
}
$translate_ret = `getAttr -se ($lanzi[$i]+".translateZ")`;
if($translate_ret==1)
{
setAttr ($lanzi[$i]+".translateZ") 0;
}
print($translate_ret+"\n");
}
Maya脚本:在指定帧的位置开始执行命令
本次案例讲解:在指定帧位置,开始执行命令的表达式。
- 表达式原理:利用if表达式进行判断执行相应的命令。
if(frame==0)
{
pCube1.translateY =-0.1;
}
else
{
pCube1.translateY =0.1;
}
Maya脚本:跟随时间变化的表达式
本次视频讲解:跟随时间变化的表达式=time。
- 表达式原理:让复杂运动更具规律性。
Maya脚本:循环执行命令
本次视频讲解:循环执行命令的脚本。
- 脚本作用:批量执行的必要条件之一。
for ($i=初始值;$i<=结束值;$i+=循环步调)
{
print ($i+”,”);
//所执行命令
}
Maya脚本:获取选定对象的名称和完整属性名
本次视频讲解:Mel获取选定对象的名称和完整属性名的方法。
- 脚本作用:可对单个选定对象执行命令。
//获取属性名称
string $sel[] = `ls -sl`;
float $cc=getAttr($sel[0]+”.translateY”);
print $cc;
//代入增减值计算
$cc = $cc + 增减值;
print $cc;
setAttr($sel[0]+”.translateY”) $cc;
Maya脚本:给对象属性递增或递减一个固定值
本次案例:增减属性值的脚本。
- 脚本原理:累加和递减计算。
float $cc=getAttr(“增减属性”);
$cc=$cc + 增减值;
setAttr “增减属性” $cc;
Maya脚本:动画自动上下振动
本次案例:上下振动的动画表达式。
- 表达式原理:奇偶数判断,通过setAttr设置属性。
if(frame%2==0)
{
振动属性 = 参数一;
}
else
{
振动属性 = 参数二;
}
Maya脚本:轮子自动跟随位移精确旋转
本次案例:轮子跟随位移精确旋转。
- 表达式原理:让表达式,计算出【前一帧和当前帧】的位移差。计算出位移差之后,我们用【位移差/周长】得到一个百分比,然后我们再用百分比*360度,就得出了每帧旋转的角度。最后我采用一个累加的方式,将累加的值传递到旋转属性值上。
float $last = `getAttr -time (frame-1) 位移属性`;
float $now= `getAttr -time (frame-0) 位移属性`;
float $chazhi = $now – $last;
float $baifenbi = $chazhi/(3.14*直径);
float $jiaodu = $baifenbi*360;
float $default_jiaodu=旋转属性 + $jiaodu;
setAttr “旋转属性” $default_jiaodu;
Maya脚本:Mery睁眼+握拳脚本使用方法
最近老是有小伙伴问我“握拳”手势用的是什么插件,其实这只是一个简单的mel脚本,这里我就连同“睁眼”一起放出来,操作方法:打开脚本编辑器>>粘贴MEL>>全选MEL>>点击三角符号运行。除此之外也可以将MEL脚本直接拖到工具架上运行。
//睁眼
setAttr "Mery_ac_rg_supfLid_move_sg.translateY" 0.65;
setAttr "Mery_ac_lf_supfLid_move_sg.translateY" 0.65;
//握拳
setAttr "Mery_ac_lf_ring02.rotateX" 0.827389;
setAttr "Mery_ac_lf_thumb01.rotateX" 28.302883;
setAttr "Mery_ac_lf_index03.rotateX" 3.30324;
setAttr "Mery_ac_lf_index02.rotateX" 0.373954;
setAttr "Mery_ac_lf_index01.rotateX" -13.880063;
setAttr "Mery_ac_lf_index_base.rotateX" 0;
setAttr "Mery_ac_lf_thumb03.rotateX" -6.725448;
setAttr "Mery_ac_lf_thumb02.rotateX" -10.301769;
setAttr "Mery_ac_lf_ring01.rotateX" 3.487558;
setAttr "Mery_ac_lf_ring_base.rotateX" 0;
setAttr "Mery_ac_lf_pinky03.rotateX" -2.291831;
setAttr "Mery_ac_lf_pinky02.rotateX" 0.691009;
setAttr "Mery_ac_lf_pinky01.rotateX" 4.557372;
setAttr "Mery_ac_lf_pinky_base.rotateX" 0;
setAttr "Mery_ac_lf_middle03.rotateX" -2.291831;
setAttr "Mery_ac_lf_middle02.rotateX" 0.293705;
setAttr "Mery_ac_lf_middle01.rotateX" -1.216076;
setAttr "Mery_ac_lf_middle_base.rotateX" 0;
setAttr "Mery_ac_lf_ring03.rotateX" -2.291831;
setAttr "Mery_ac_lf_ring02.rotateY" -3.133414;
setAttr "Mery_ac_lf_thumb01.rotateY" -4.043442;
setAttr "Mery_ac_lf_index03.rotateY" 0.399745;
setAttr "Mery_ac_lf_index02.rotateY" -3.219081;
setAttr "Mery_ac_lf_index01.rotateY" -7.40807;
setAttr "Mery_ac_lf_index_base.rotateY" 0;
setAttr "Mery_ac_lf_thumb03.rotateY" 5.749484;
setAttr "Mery_ac_lf_thumb02.rotateY" 10.317666;
setAttr "Mery_ac_lf_ring01.rotateY" -3.855357;
setAttr "Mery_ac_lf_ring_base.rotateY" 0;
setAttr "Mery_ac_lf_pinky03.rotateY" -2.291831;
setAttr "Mery_ac_lf_pinky02.rotateY" -3.166255;
setAttr "Mery_ac_lf_pinky01.rotateY" -14.830043;
setAttr "Mery_ac_lf_pinky_base.rotateY" 0;
setAttr "Mery_ac_lf_middle03.rotateY" -2.291831;
setAttr "Mery_ac_lf_middle02.rotateY" -3.227384;
setAttr "Mery_ac_lf_middle01.rotateY" -6.141131;
setAttr "Mery_ac_lf_middle_base.rotateY" 0;
setAttr "Mery_ac_lf_ring03.rotateY" -2.291831;
setAttr "Mery_ac_lf_ring02.rotateZ" -102.114342;
setAttr "Mery_ac_lf_thumb01.rotateZ" -8.354095;
setAttr "Mery_ac_lf_index03.rotateZ" -70.73108;
setAttr "Mery_ac_lf_index02.rotateZ" -83.944531;
setAttr "Mery_ac_lf_index01.rotateZ" -75.51321;
setAttr "Mery_ac_lf_index_base.rotateZ" 0;
setAttr "Mery_ac_lf_thumb03.rotateZ" -43.610245;
setAttr "Mery_ac_lf_thumb02.rotateZ" -17.469513;
setAttr "Mery_ac_lf_ring01.rotateZ" -89.515243;
setAttr "Mery_ac_lf_ring_base.rotateZ" 0;
setAttr "Mery_ac_lf_pinky03.rotateZ" -42.291831;
setAttr "Mery_ac_lf_pinky02.rotateZ" -89.632704;
setAttr "Mery_ac_lf_pinky01.rotateZ" -93.331885;
setAttr "Mery_ac_lf_pinky_base.rotateZ" 0;
setAttr "Mery_ac_lf_middle03.rotateZ" -42.291831;
setAttr "Mery_ac_lf_middle02.rotateZ" -102.517377;
setAttr "Mery_ac_lf_middle01.rotateZ" -86.476423;
setAttr "Mery_ac_lf_middle_base.rotateZ" 0;
setAttr "Mery_ac_lf_ring03.rotateZ" -42.291831;
setAttr "Mery_ac_rg_ring02.rotateX" 0.827389;
setAttr "Mery_ac_rg_thumb01.rotateX" 28.302883;
setAttr "Mery_ac_rg_index03.rotateX" 3.30324;
setAttr "Mery_ac_rg_index02.rotateX" 0.373954;
setAttr "Mery_ac_rg_index01.rotateX" -13.880063;
setAttr "Mery_ac_rg_index_base.rotateX" 0;
setAttr "Mery_ac_rg_thumb03.rotateX" -6.725448;
setAttr "Mery_ac_rg_thumb02.rotateX" -10.301769;
setAttr "Mery_ac_rg_ring01.rotateX" 3.487558;
setAttr "Mery_ac_rg_ring_base.rotateX" 0;
setAttr "Mery_ac_rg_pinky03.rotateX" -2.291831;
setAttr "Mery_ac_rg_pinky02.rotateX" 0.691009;
setAttr "Mery_ac_rg_pinky01.rotateX" 4.557372;
setAttr "Mery_ac_rg_pinky_base.rotateX" 0;
setAttr "Mery_ac_rg_middle03.rotateX" -2.291831;
setAttr "Mery_ac_rg_middle02.rotateX" 0.293705;
setAttr "Mery_ac_rg_middle01.rotateX" -1.216076;
setAttr "Mery_ac_rg_middle_base.rotateX" 0;
setAttr "Mery_ac_rg_ring03.rotateX" -2.291831;
setAttr "Mery_ac_rg_ring02.rotateY" -3.133414;
setAttr "Mery_ac_rg_thumb01.rotateY" -4.043442;
setAttr "Mery_ac_rg_index03.rotateY" 0.399745;
setAttr "Mery_ac_rg_index02.rotateY" -3.219081;
setAttr "Mery_ac_rg_index01.rotateY" -7.40807;
setAttr "Mery_ac_rg_index_base.rotateY" 0;
setAttr "Mery_ac_rg_thumb03.rotateY" 5.749484;
setAttr "Mery_ac_rg_thumb02.rotateY" 10.317666;
setAttr "Mery_ac_rg_ring01.rotateY" -3.855357;
setAttr "Mery_ac_rg_ring_base.rotateY" 0;
setAttr "Mery_ac_rg_pinky03.rotateY" -2.291831;
setAttr "Mery_ac_rg_pinky02.rotateY" -3.166255;
setAttr "Mery_ac_rg_pinky01.rotateY" -14.830043;
setAttr "Mery_ac_rg_pinky_base.rotateY" 0;
setAttr "Mery_ac_rg_middle03.rotateY" -2.291831;
setAttr "Mery_ac_rg_middle02.rotateY" -3.227384;
setAttr "Mery_ac_rg_middle01.rotateY" -6.141131;
setAttr "Mery_ac_rg_middle_base.rotateY" 0;
setAttr "Mery_ac_rg_ring03.rotateY" -2.291831;
setAttr "Mery_ac_rg_ring02.rotateZ" -102.114342;
setAttr "Mery_ac_rg_thumb01.rotateZ" -8.354095;
setAttr "Mery_ac_rg_index03.rotateZ" -70.73108;
setAttr "Mery_ac_rg_index02.rotateZ" -83.944531;
setAttr "Mery_ac_rg_index01.rotateZ" -75.51321;
setAttr "Mery_ac_rg_index_base.rotateZ" 0;
setAttr "Mery_ac_rg_thumb03.rotateZ" -43.610245;
setAttr "Mery_ac_rg_thumb02.rotateZ" -17.469513;
setAttr "Mery_ac_rg_ring01.rotateZ" -89.515243;
setAttr "Mery_ac_rg_ring_base.rotateZ" 0;
setAttr "Mery_ac_rg_pinky03.rotateZ" -42.291831;
setAttr "Mery_ac_rg_pinky02.rotateZ" -89.632704;
setAttr "Mery_ac_rg_pinky01.rotateZ" -93.331885;
setAttr "Mery_ac_rg_pinky_base.rotateZ" 0;
setAttr "Mery_ac_rg_middle03.rotateZ" -42.291831;
setAttr "Mery_ac_rg_middle02.rotateZ" -102.517377;
setAttr "Mery_ac_rg_middle01.rotateZ" -86.476423;
setAttr "Mery_ac_rg_middle_base.rotateZ" 0;
setAttr "Mery_ac_rg_ring03.rotateZ" -42.291831;
//半握拳
setAttr "Mery_ac_lf_pinky_base.rotateX" -2.291831;
setAttr "Mery_ac_lf_thumb03.rotateX" -2.291831;
setAttr "Mery_ac_lf_thumb02.rotateX" -2.291831;
setAttr "Mery_ac_lf_thumb01.rotateX" 19.708169;
setAttr "Mery_ac_lf_index03.rotateX" -2.291831;
setAttr "Mery_ac_lf_index02.rotateX" -2.291831;
setAttr "Mery_ac_lf_ring03.rotateX" -2.291831;
setAttr "Mery_ac_lf_ring02.rotateX" -2.291831;
setAttr "Mery_ac_lf_ring01.rotateX" -0.168926;
setAttr "Mery_ac_lf_ring_base.rotateX" -2.291831;
setAttr "Mery_ac_lf_pinky03.rotateX" -2.291831;
setAttr "Mery_ac_lf_pinky02.rotateX" -2.291831;
setAttr "Mery_ac_lf_index01.rotateX" -2.291831;
setAttr "Mery_ac_lf_index_base.rotateX" -2.291831;
setAttr "Mery_ac_lf_middle03.rotateX" -2.291831;
setAttr "Mery_ac_lf_middle02.rotateX" -2.291831;
setAttr "Mery_ac_lf_middle01.rotateX" -2.291831;
setAttr "Mery_ac_lf_middle_base.rotateX" -2.291831;
setAttr "Mery_ac_lf_pinky01.rotateX" -2.291831;
setAttr "Mery_ac_lf_pinky_base.rotateY" -2.291831;
setAttr "Mery_ac_lf_thumb03.rotateY" -2.291831;
setAttr "Mery_ac_lf_thumb02.rotateY" 9.708169;
setAttr "Mery_ac_lf_thumb01.rotateY" 4.708169;
setAttr "Mery_ac_lf_index03.rotateY" -2.291831;
setAttr "Mery_ac_lf_index02.rotateY" -2.291831;
setAttr "Mery_ac_lf_ring03.rotateY" -2.291831;
setAttr "Mery_ac_lf_ring02.rotateY" -2.291831;
setAttr "Mery_ac_lf_ring01.rotateY" -3.938286;
setAttr "Mery_ac_lf_ring_base.rotateY" -2.291831;
setAttr "Mery_ac_lf_pinky03.rotateY" -2.291831;
setAttr "Mery_ac_lf_pinky02.rotateY" -2.291831;
setAttr "Mery_ac_lf_index01.rotateY" 6.807102;
setAttr "Mery_ac_lf_index_base.rotateY" -2.291831;
setAttr "Mery_ac_lf_middle03.rotateY" -2.291831;
setAttr "Mery_ac_lf_middle02.rotateY" -2.291831;
setAttr "Mery_ac_lf_middle01.rotateY" 1.008259;
setAttr "Mery_ac_lf_middle_base.rotateY" -2.291831;
setAttr "Mery_ac_lf_pinky01.rotateY" -17.037031;
setAttr "Mery_ac_lf_pinky_base.rotateZ" -2.291831;
setAttr "Mery_ac_lf_thumb03.rotateZ" -24.291831;
setAttr "Mery_ac_lf_thumb02.rotateZ" -4.291831;
setAttr "Mery_ac_lf_thumb01.rotateZ" -7.291831;
setAttr "Mery_ac_lf_index03.rotateZ" -22.291831;
setAttr "Mery_ac_lf_index02.rotateZ" -32.291831;
setAttr "Mery_ac_lf_ring03.rotateZ" -42.291831;
setAttr "Mery_ac_lf_ring02.rotateZ" -42.291831;
setAttr "Mery_ac_lf_ring01.rotateZ" -42.291831;
setAttr "Mery_ac_lf_ring_base.rotateZ" -2.291831;
setAttr "Mery_ac_lf_pinky03.rotateZ" -42.291831;
setAttr "Mery_ac_lf_pinky02.rotateZ" -32.291831;
setAttr "Mery_ac_lf_index01.rotateZ" -22.291831;
setAttr "Mery_ac_lf_index_base.rotateZ" -2.291831;
setAttr "Mery_ac_lf_middle03.rotateZ" -42.291831;
setAttr "Mery_ac_lf_middle02.rotateZ" -52.291831;
setAttr "Mery_ac_lf_middle01.rotateZ" -32.291831;
setAttr "Mery_ac_lf_middle_base.rotateZ" -2.291831;
setAttr "Mery_ac_lf_pinky01.rotateZ" -47.291831;
setAttr "Mery_ac_rg_pinky_base.rotateX" -2.291831;
setAttr "Mery_ac_rg_thumb03.rotateX" -2.291831;
setAttr "Mery_ac_rg_thumb02.rotateX" -2.291831;
setAttr "Mery_ac_rg_thumb01.rotateX" 19.708169;
setAttr "Mery_ac_rg_index03.rotateX" -2.291831;
setAttr "Mery_ac_rg_index02.rotateX" -2.291831;
setAttr "Mery_ac_rg_ring03.rotateX" -2.291831;
setAttr "Mery_ac_rg_ring02.rotateX" -2.291831;
setAttr "Mery_ac_rg_ring01.rotateX" -0.168926;
setAttr "Mery_ac_rg_ring_base.rotateX" -2.291831;
setAttr "Mery_ac_rg_pinky03.rotateX" -2.291831;
setAttr "Mery_ac_rg_pinky02.rotateX" -2.291831;
setAttr "Mery_ac_rg_index01.rotateX" -2.291831;
setAttr "Mery_ac_rg_index_base.rotateX" -2.291831;
setAttr "Mery_ac_rg_middle03.rotateX" -2.291831;
setAttr "Mery_ac_rg_middle02.rotateX" -2.291831;
setAttr "Mery_ac_rg_middle01.rotateX" -2.291831;
setAttr "Mery_ac_rg_middle_base.rotateX" -2.291831;
setAttr "Mery_ac_rg_pinky01.rotateX" -2.291831;
setAttr "Mery_ac_rg_pinky_base.rotateY" -2.291831;
setAttr "Mery_ac_rg_thumb03.rotateY" -2.291831;
setAttr "Mery_ac_rg_thumb02.rotateY" 9.708169;
setAttr "Mery_ac_rg_thumb01.rotateY" 4.708169;
setAttr "Mery_ac_rg_index03.rotateY" -2.291831;
setAttr "Mery_ac_rg_index02.rotateY" -2.291831;
setAttr "Mery_ac_rg_ring03.rotateY" -2.291831;
setAttr "Mery_ac_rg_ring02.rotateY" -2.291831;
setAttr "Mery_ac_rg_ring01.rotateY" -3.938286;
setAttr "Mery_ac_rg_ring_base.rotateY" -2.291831;
setAttr "Mery_ac_rg_pinky03.rotateY" -2.291831;
setAttr "Mery_ac_rg_pinky02.rotateY" -2.291831;
setAttr "Mery_ac_rg_index01.rotateY" 6.807102;
setAttr "Mery_ac_rg_index_base.rotateY" -2.291831;
setAttr "Mery_ac_rg_middle03.rotateY" -2.291831;
setAttr "Mery_ac_rg_middle02.rotateY" -2.291831;
setAttr "Mery_ac_rg_middle01.rotateY" 1.008259;
setAttr "Mery_ac_rg_middle_base.rotateY" -2.291831;
setAttr "Mery_ac_rg_pinky01.rotateY" -17.037031;
setAttr "Mery_ac_rg_pinky_base.rotateZ" -2.291831;
setAttr "Mery_ac_rg_thumb03.rotateZ" -24.291831;
setAttr "Mery_ac_rg_thumb02.rotateZ" -4.291831;
setAttr "Mery_ac_rg_thumb01.rotateZ" -7.291831;
setAttr "Mery_ac_rg_index03.rotateZ" -22.291831;
setAttr "Mery_ac_rg_index02.rotateZ" -32.291831;
setAttr "Mery_ac_rg_ring03.rotateZ" -42.291831;
setAttr "Mery_ac_rg_ring02.rotateZ" -42.291831;
setAttr "Mery_ac_rg_ring01.rotateZ" -42.291831;
setAttr "Mery_ac_rg_ring_base.rotateZ" -2.291831;
setAttr "Mery_ac_rg_pinky03.rotateZ" -42.291831;
setAttr "Mery_ac_rg_pinky02.rotateZ" -32.291831;
setAttr "Mery_ac_rg_index01.rotateZ" -22.291831;
setAttr "Mery_ac_rg_index_base.rotateZ" -2.291831;
setAttr "Mery_ac_rg_middle03.rotateZ" -42.291831;
setAttr "Mery_ac_rg_middle02.rotateZ" -52.291831;
setAttr "Mery_ac_rg_middle01.rotateZ" -32.291831;
setAttr "Mery_ac_rg_middle_base.rotateZ" -2.291831;
setAttr "Mery_ac_rg_pinky01.rotateZ" -47.291831;