PDA

View Full Version : expression causes fatal error...


Jboy
10-23-2005, 01:50 AM
I can't make any sense out of this. The expression:


float $RShoulderLoc[] = `joint -q -p -a R_Shoulder`;
float $worldVector[3];

$worldVector[0] = (R_Arm_IK.translateY - $RShoulderLoc[1]) * -1;
$worldVector[1] = (R_Arm_IK.translateX - $RShoulderLoc[0]);
$worldVector[2] = 0;

float $localMatrix[] = `xform -q -ws -m R_Clavicle`;

float $localVector[3] = pointMatrixMult($worldVector, $localMatrix);

R_Arm_IK.poleVectorX = $localVector[0];
R_Arm_IK.poleVectorY = $localVector[1];
R_Arm_IK.poleVectorZ = $localVector[2];


...causes Maya to crash.

I've figured out that the pointMatrixMult() function is what is causing the crash, but I can't figure out why. I can execute this same block of code (with some `getAttr`'s) in the script editor and it works. Is it just that an expression can't do matrix math? Too complex?

Can anyone help?

Thanks.

AndersEgleus
10-26-2005, 09:51 PM
The pointMatrixMult procedure is not recommended to be used in expressions. What happens is, every time you call it, it creates a pointMatrixMult node, and then uses setAttr and getAttr on the inputs to return the transformed point (it also returns the wrong answer by default since it sets the operation to vector matrix multiply, not point matrix multiply, but in your case, you probably want vector matrix multiply anyway). Before the procedure ends, it deletes the node. This means that it will create and delete a node every time the expression executes.

This could be why maya crashes, I'm not sure, but regardless, it's not a very efficient way of doing things.

What you should do is open the hypergraph or hypershade and create either a pointMatrixMult node or a vectorProduct node and set its operation to Vector Matrix Product, then connect R_Clavicle's worldMatrix attribute to matrix attribute of the pointMatrixMult or vectorProduct node, and change the expression (assuming you've created a vectorProduct node):


float $RShoulderLoc[] = `joint -q -p -a R_Shoulder`;
float $worldVector[3];

$worldVector[0] = (R_Arm_IK.translateY - $RShoulderLoc[1]) * -1;
$worldVector[1] = (R_Arm_IK.translateX - $RShoulderLoc[0]);
$worldVector[2] = 0;

vectorProduct1.input1X = $worldVector[0];
vectorProduct1.input1Y = $worldVector[1];
vectorProduct1.input1Z = $worldVector[2];

R_Arm_IK.poleVectorX = vectorProduct1.outputX;
R_Arm_IK.poleVectorY = vectorProduct1.outputY;
R_Arm_IK.poleVectorZ = vectorProduct1.outputZ;

In fact, you could build up the entire expression with a node network - use a decomposeMatrix node with R_Shoulder's worldMatrix attribute as input to get its translation in world coordinates, and use simple plusMinusAverage and multiplyDivide nodes to get the results of lines four and five of the expression and connect the outputs into the vectorProduct node, the output of which can be connected directly into the poleVector attribute of R_Arm_IK. Simple, fast, and stable.

Jboy
10-27-2005, 07:14 AM
Thank you Anders!!!

You're right, that fixes the problem. All is well now. You truly are a "know it all". :)

I haven't done too much with node networks - I always assumed they were intended for use with shaders, and I guess they are but now I realize you can use them for other purposes as well... very interesting.

AndersEgleus
10-27-2005, 07:58 AM
Lol, I wouldn't go that far, That user title is just what you're rewarded if you post 300 times here :)

Yes, node networks are great, they're one of the main things which make maya so powerful. They're especially great for character setup when you need a visual representation of the rig "engine" without having to look through a wad of expressions.

CGTalk Moderation
10-27-2005, 07:58 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.