Monday, December 19, 2005

Solutions for Gimbal Lock

Ah gimbal lock, every animator's nemesis. Gimbal lock rears its ugly head when you decide to rotate something in 3D space a little too much on all axes and it decides to stop playing nice and refuse to move in the directions you really want it to. Every animator has, at one point or another, pulled their hair out over a shoulder that won't pivot correctly, often having to manually key every single frame in order to force the arm to follow the arc they want.

Gimbal lock such as this is caused by two factors; the rotation order of the joint or object, and the order rotations that an animator has used to get the object into that position. Probably the worst case of gimbal lock I've ever experienced was when I was developing a vehicle rig for a car that needed to crash, flip over several times, roll, and spin on every axis. Gimbal lock was virtually inevitable.

I tried several possible solutions, including nesting the vehicle within several groups and given each group a different pivot, but that was scrapped because it was too difficult to manage the nested animation. Another solution was to use a series of parent constraints and "pass" the vehicle along the chain of constraints, rotating them to do the flips, rolls and spins. This solution was also scrapped because it turned out gimbal lock still happened on the vehicle because the constraints were simply changing the objects channels.

The best solution was to key the rotation order. Nearly every object in Maya that can be transformed has a hidden attribute called Rotation Order. Simply use the Channel Editor to make the attribute visible and keyable. Keying this allows you to adjust the rotation order on the fly, effectivly dodging gimbal lock. When your object approaches gimbal lock, you'll see the rotational axes begin to line up with eachother, which you can tell by looking at the rotation gimbal. If you need to make your object rotate in a different direction, simply key the rotation order attribute to an order that does allow rotation in the direction you need, again, this can be determined by simply looking at the rotation gimbal.

Something to keep in mind about keying the rotation order, Maya doesn't like when the drop down menus are used in the channel list for some reason. The drop down list represents values of 0, 1, 2, 3, etc. But if you try to change the order and key it using the drop down menu, you'll notice the value jump suddenly to 6000 or some other outrageously high number. So in order to bring that value back down into the range of the drop down list values, you have to open the graph editor and manually bring the keyframe back down to the single digit range. A simple MEL script can be written to do this sort of thing for you with the click of a button.

One of the drawbacks to keying the rotational order rears its head during rendering. 3D motion blur relies on the rotation information of an object to accuratly predict the path of the blur. Changing the rotation order will cause the blur to glitch momentarily in the wrong direction. The simplest solution to this is to simply bake your animation down to the verticies, removing the rotations, and instead translating verts, effectivly morphing the object from frame to frame. Just make sure you save out a new version of your animation before baking it.

1 Comments:

Blogger Unknown said...

Jesus of gimbal lock!

3:15 AM  

Post a Comment

<< Home