18 April, 2009

True on the fly Rotation Order Change

True on the fly rotation order change means that the object should not jump from its current pose. I started looking into matrix to achieve this. Basically, I thought if I can formulate the equation that involves rotation values and rotation order I can solve that equation to get the rotation values that will keep the object in the same pose. I found that I could actually have separate matrices for each axis, RX, RY and RZ and then multiply them one by one based on rotation order to get this rotation value. However, in trying to find if I can set matrix value of an object using MEL I ended up finding a solution of my actual problem. It can't get simpler than this.

xform -preserve true -rotateOrder yxz;

Select your object, rotate in any position and then change rotation order using this command. Object will stay in the same pose! Thanks to "-preserve" flag.

6 comments:

This one is pretty neat actually. I am glad that xform command has preserve flag. Using this I wrote a script to change the rotation order of a control without affecting any animation on it. I wish I had figured this out earlier. Because while doing animation last quarter I had to change rotation order and so I ended up redoing the animation for that controller.

Rotation values in channel box is calculated according to the rotation order. If you have rotation values say x=30, y=90, z=45 and your rotation order is "xyz". So maya will rotate object in this order: first z=45, y=90, x=30

if you change this order to say "zxy" and you have the same rotation values for each axis then object may end up in different orientation because the rotation values are evaluated in different order(in this case, y, x, z). Check the link below for very detailed explanation.