/* begin jf_downAxis.mel Jean-Francois Fortin -=WHAT IT DOES=- will return which axis your joint is pointing. doesnt work if axis is pointing negative. -=RETURN=- <<0,10>> -=EXAMPLES=- -=REQUIRES=- -=NONE=- -=UPDATES=- end */ //// global proc vector jf_downAxis() { float $cx; float $sx; float $cy; float $sy; float $cz; float $sz; float $ox; float $ux; float $oy; float $uy; float $oz; float $uz; float $angles[]; float $pi = 3.14159265; matrix $rotT[4][4]; matrix $oriT[4][4]; matrix $total[4][4]; vector $dd; vector $pPoss; vector $cPoss; string $joints[] = `ls -sl -typ joint`; string $child[] = `listRelatives -c -typ joint $joints[0]`; string $parent[] = `listRelatives -p -typ joint $joints[0]`; if( `size($parent)` ) { parent -w $joints[0]; $angles = `joint -q -o $joints[0]`; parent $joints[0] $parent[0]; } else { $angles = `joint -q -o $joints[0]`; } if( !`size($child[0])` &&`size($parent[0])` ) { $pPoss = `xform -q -ws -a -t $joints[0]`; $cPoss = `xform -q -ws -a -t $parent[0]`; $dd = $pPoss - $cPoss; } else { $pPoss = `xform -q -ws -a -t $joints[0]`; $cPoss = `xform -q -ws -a -t $child[0]`; $dd = $cPoss - $pPoss; } float $rotX = `getAttr ( $joints[0]+".rotateX")`; float $rotY = `getAttr ( $joints[0]+".rotateY")`; float $rotZ = `getAttr ( $joints[0]+".rotateZ")`; $cx = cos( $angles[0]*$pi/180 ); $sx = sin( $angles[0]*$pi/180 ); $cy = cos( $angles[1]*$pi/180 ); $sy = sin( $angles[1]*$pi/180 ); $cz = cos( $angles[2]*$pi/180 ); $sz = sin( $angles[2]*$pi/180 ); $ox = cos( $rotX *$pi/180 ); $ux = sin( $rotX *$pi/180 ); $oy = cos( $rotY*$pi/180 ); $uy = sin( $rotY*$pi/180 ); $oz = cos( $rotZ*$pi/180 ); $uz = sin( $rotZ*$pi/180 ); matrix $ojx[4][4] = <<1,0,0,0; 0,$cx,($sx*-1),0; 0,$sx,$cx,0; 0,0,0,1>>; matrix $ojy[4][4] = <<$cy,0,$sy,0; 0,1,0,0; ($sy*-1),0,$cy,0; 0,0,0,1>>; matrix $ojz[4][4] = <<$cz,($sz*-1),0,0; $sz,$cz,0,0; 0,0,1,0; 0,0,0,1>>; matrix $rox[4][4] = <<1,0,0,0; 0,$ox,($ux*-1),0; 0,$ux,$ox,0; 0,0,0,1>>; matrix $roy[4][4] = <<$oy,0,$uy,0; 0,1,0,0; ($uy*-1),0,$oy,0; 0,0,0,1>>; matrix $roz[4][4] = <<$oz,($uz*-1),0,0; $uz,$oz,0,0; 0,0,1,0; 0,0,0,1>>; $rotT = $roz*$roy*$rox; $oriT = $ojz*$ojy*$ojx; $total = $oriT*$rotT; matrix $x[4][1] = <<1;0;0;1>>; matrix $y[4][1] = <<0;1;0;1>>; matrix $z[4][1] = <<0;0;1;1>>; matrix $xT[4][1] = $total*$x; matrix $yT[4][1] = $total*$y; matrix $zT[4][1] = $total*$z; vector $vxT = << $xT[0][0],$xT[1][0],$xT[2][0] >>; vector $vyT = << $yT[0][0],$yT[1][0],$yT[2][0] >>; vector $vzT = << $zT[0][0],$zT[1][0],$zT[2][0] >>; vector $lx = sqrt($dd.x*$dd.x+$dd.y*$dd.y+$dd.z*$dd.z); vector $lxa = sqrt($vxT.x*$vxT.x+$vxT.y*$vxT.y+$vxT.z*$vxT.z); vector $lya = sqrt($vyT.x*$vyT.x+$vyT.y*$vyT.y+$vyT.z*$vyT.z); vector $lza = sqrt($vzT.x*$vzT.x+$vzT.y*$vzT.y+$vzT.z*$vzT.z); $dd = $dd/$lx; $vxT = $vxT/$lxa; $vyT = $vyT/$lxa; $vzT = $vzT/$lxa; float $dotx = dot( $dd,$vxT ); float $doty = dot( $dd,$vyT ); float $dotz = dot( $dd,$vzT ); if( $dotx > 0.99 ) { return <<1,0,0>>; } else if( $doty > 0.99 ) { return <<0,1,0>>; } else if( $dotz > 0.99 ) { return <<0,0,1>>; } else { return "none"; } }