Maya魔方绑定的原理 Rubik’sCube rigging

魔方的实现有很多种方法,但是实现的过程都大同小异。我采用的的表达式让时间帧来控制主程序,或者可以使用scriptJob直观的去控制旋转。魔方分别有右、左、前、后、上、下六个面,创建六个控制器并且标号(也可以用8个控制器,俩个中间的)以6个控制器为例:right - 0/left -1 /front -2 /back - 3/up -4/down - 5

一、控制器如何分别控制所对应区域的方块:所有的方块都被6个控制器父子约束,根据标号跟方块的位置参数做比较

二、如何得到旋转的控制器是哪个方向:

1、探测当前控制器在时间线上的度数,可以得到在旋转的方向的标记号

2、如果旋转度数等于0度或90度或者90度的倍数(包括负数) 返回 0

3、如果旋转度数不等于0度或90度或者90度的倍数(包括负数)返回 1

假如等到标记号是1,$index =1;

获取所有方块的$axis[$index]的位移值,如:block1.tx

核心原理如下:

//方块约束节点的名称放入数组
 
$parentNum[] = {".rightW0" , ".leftW1" , ".frontW2" ,  ".backW3" , ".upW4" , "downW5"}
 
$axis[] = {".tx","tx",".tz",".tz",".ty".".ty"}
 
$refValue[] = {   1,   -1,    1,    -1,   1,    -1 }
 
//获取cubeGrp下的所有方块
 
String $blocks[]=`listRelatives -children "cubeGrp";
 
for ($i in $blocks)
 
{
 
string $attr = $i+$axis[$index];
 
$tv = getAttr($attr);
 
if ($tv == $value[$index])
 
{
 
setAttr ($i+"_parentConstraint1"+$parentNum[$index]) 1;
 
}
 
}

Comments (0)

› No comments yet.

Leave a Reply

*

Allowed Tags - You may use these HTML tags and attributes in your comment.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>