2008年9月4日星期四

定位极向量

当一个IK链不在x*y*z=0的平面上时,如何确定极向量的位置需要一定的技巧。通常我用的也是Aaron Holly 的方法,即用点约束和目标约束结合找到平面上的两点连线并使控制器在该点上的旋转轴指向第三个点,然后可以再在该平面上移动控制器......。
今天在http://scroll-lock.eu/看到Marin Petrov提到了更简便的code,整体思想是类似的,但用数学方法避免了约束的操作,下面把mel转贴一下,原文请去http://scroll-lock.eu/看。

Marin Petrov&Slavi Kaslev's method:


global proc string mp_CScreatePoleLocator(string $jointA, string $jointB, string $jointC)
{
vector $a = `xform -q -a -ws -t $jointA`;
vector $b = `xform -q -a -ws -t $jointB`;
vector $c = `xform -q -a -ws -t $jointC`;

vector $ab = $b - $a;
vector $ac = $c - $a;

vector $up = cross($ab, $ac);
vector $direction = cross($ac, $up);

float $rot[] = vector2rot($direction, $up);

string $locator = firstS(`spaceLocator`);
move -a -ws ($b.x) ($b.y) ($b.z);
rotate -a -ws ($rot[0]) ($rot[1]) ($rot[2]);

// NOTE: Change here for locator offset
move -r -os 0 0 5;

return $locator;
}




firstS /on the 15th row/ is a proc that simply returns the first string.



另一种类似的方法
Me and Dobri Georgiev made another solution for this :

//the three points and their absolute coords

vector $a = `xform -q -a -ws -t joint1`;
vector $b = `xform -q -a -ws -t joint2`;
vector $c = `xform -q -a -ws -t joint3`;

//the distance between the points as vectors

vector $ab = unit($b - $a);
vector $bc = unit($b - $c);

//make the vectors start from the B point and offset them by 10

vector $f = $b + 10*$ab;
vector $g = $b + 10*$bc;

// find the center of the triangle made by the new vectors

vector $center = ($f + $g + $b)/3;


string $locator = firstS(`spaceLocator`);
move -a -ws ($center.x) ($center.y) ($center.z);


没有评论: