I have a simple cube which is grouped. the local translation for the cube is {0 -1.5 0} and {0 1.5 0} for the group (so the world position of the cube is 0 0 0) I'd like to compute the position of the cube in world space so i do:
CODE pointMatrixMult ( $pos, $mat );
where $pos is the cube's translation (which is in local space) and $mat in the cube's parentMatrix (which is in world space)
And i get wrong results!!!! (ie {0,-1.5,0}) i had done my own point * matrix procedure and it give me the right result.
pointMatrixMult create a node in order to compute the result is there any difference between mel's matrix and api's matrix? where can i get more information on maya's matrix representation?
Cube(world) = Cube(local) * Cube(parentWorld) and Cube(translationWorld) = Cube(translationLocal) * Cube(parentWorld) (i'm in this case)
I'm not using xform because xform is using the cube's translateX, translateY,... (which , in this case is fine...) But i added attributes to save keyframe animations (which are local transforms) and i wanted to have them back in world space
here is my procedure (note that xform is giving me the same result that my operation)
Works as expected. You need to multiply (0,0,0) with world matrix, not local translation. That's because position of the cube transform is always zero in it's own coordinate space
yes theres s light glitch in the script, its actulay doing a vector matrix multiplication not a point matrix multiplication. THis has been discussed eralier.
Se the FACTORY melscript looks as follows:
CODE global proc float[] pointMatrixMult( float $point[], float $matrix[] ) // // Description: // Multiplies a point by a matrix and returns the result. // { float $result[];
if ( size($point) != 3 || size($matrix) != 16 ) { warning("Point must be an array of 3 doubles and matrix must be an array of 16 doubles."); return $result; }
// create the node that will do the actual computation // string $multNode; if ( catch($multNode = createNode pointMatrixMult) ) { warning("Could not create pointMatrixMult node."); return $result; }
// set the matrix and point inputs to the node //
setAttr ($multNode+".vectorMultiply") true; // note this is set to true it should be false.
// get the result and delete the node since it is no longer required // $result = getAttr ($multNode+".output"); delete $multNode;
return $result; }
now the line setAttr ($multNode+".vectorMultiply") true; is ovoiusly worng! so copy the scriipt into ypur own script directory and change true on that line to false. Adn it then works correctly
yes thats smart as its MUCH faster, to use expressivity than use the temp node build discard. (unless you leve ot IN pplace in wich case you can jsut read it when you need it)
for example matricx playground has a full set of just this.