Apr 20, 2007

Quick Trick: Gimbal Lock... Just Ignore It ! ( with a little help from Maya )

Update 2012:
Wow.. this is really old. I`m not sure I would suggest this workflow anymore. At the time of writing I did a lot of my animation by "just looking at it" in the viewport and not looking at how curves were actually driving movement in the graph editor. I have since discovered the magic of actually understanding what the graph editor is telling me and using it to animate more logically ( because its easier to polish that way ). If you use local rotation manipulator, youre STILL going to see curves that make no sense in the graph editor, at the cost of getting that direct manipulation.. euler filter or not. I would try and figure out a way of using the "extra node" approach, where you basically make a controller that rotates your object along its widest and most common axis, and your xyz rotates sit under that extra node as a child. 

Saying that though... I animated for a LONG time without ever looking in the graph editor, and got results I really liked. We change our approaches a lot over time, and that's all good. If you're struggling with this, I would still read the article below and see if it could work for you as it was a winner for me for years.

What is gimbal lock ?

To tell you the truth, despite the fact that I am pretty well versed in the technical side of 3D animation, I never really fully understood exactly what gimble lock is. As I understand it, its when one or more of your controller's rotation axes become "locked" or "stuck" ( or more accurately - stuck on a plane that no longer properly represents the direction of that axis ):

Time and time again I hear animators moaning about gimbal lock, and I am used to seeing many bizarre and long winded approaches to solving it scattered around on the internet. My solution to this odd problem is simply to ignore it! Gimbal lock has practically never been a problem for me, and here's the quick trick to show you how:

Broad workflow technique, and what rotation manipulator you use is the key...

When I first started in 3D animation, I had only a very small level of 2D experience, and none of it professional, but I thought in a 2D way. I still probably don't think 2D enough from day to day, but I never made the mistake of thinking about 3D animation as separate channels of X Y and Z. Many animators do however. They spend too much time worrying about organization of keyframes, only changing the X rotate value if thats all they need to do, and not keying the translation for example if they don't need it on that frame. In my opinion this is a strange and analytical way of working, that takes longer to manage, and takes away from the core experience of animating. I don't care what channels are keyed on what frame, in fact I deliberately key all the channels on an object when I'm finished posing it.

The nuts and bolts of this workflow is that I never use the gimbal rotation mode for my rotation manipulator. I always work in local mode, and Maya is great because its still doing the same mathematics behind the rotations, but its always giving you all three axes to work with, and never locking them. The gimbal rotation manipulator is for people who like to work in the analytical way - they only need an X rotation so they only rotate the X axis. With Local rotation mode setting, you can still only rotate the X axis, but maya will rotate the other axes also ( unnoticeable to you ) so you don't get axes stuck on top of each other.

Its a mystery to me why some people choose not to work this way. I suppose its easier to manage your curves if you only have keys you specifically set, and easier to cleanup and make changes. On the whole, "keyframe messiness" has never really been that much of a problem for me. I like to concentrate on the performance, and if I have specific areas of keys that I need to clean up or delete, I just do it then as I see fit. I'm not saying its wrong or "dumb" to manage your keys so carefully, I'm sure lots of animators are very happy this way and have their own solutions to gimbal lock... I'm just giving an example of a workflow that has worked very well for me.

Euler Filter - your best friend when you work in Local mode...

So what happens when gimbal lock happens in Local mode ?

When you work with Local mode, you never really see gimbal lock happening - in that you never see the axes getting stuck, but you occasionally see the result of a rotation calculation not going entirely as planned, because gimbal lock is under the hood causing problems. See the image below:

I just want to take the arm and rotate it around the Y axis ( green ). I also rotated just a tiny amount around X and Z.. but the main big rotation here is in Y. Notice that after I have rotated into the new pose, my rotation manipulator is still giving me full control of all 3 axes.

So from the images above, you would expect the arm to do a nice clean sweep from the first pose into the second pose. Most of the time that is what happens, but occasionally this happens:

Strange ? yeah. Well its not what I wanted at least. It seems like the arm is going through the torso, and doing a slight weird twisting at the same time... you must have seen this happening before in your animations.
When I first started animating, I used to go in and add inbetweens whenever this happened to fix the problem... it used to really annoy me, because I had no understanding of why it was happening. This is gimbal lock going on in the background, and because you're using Local rotate mode, its kind of "hidden" from you by Maya.
This is where the magical wonder that is the "Euler filter" ( pronounced "oiler" ) comes into action. Maya takes these rotation curves that have become entangled, and reorganises them so we get the rotation we originally wanted - effectively completely solving the gimbal lock problem in one mouse click.

After applying the euler filter, the rotation of the arm is exactly as we "planned" it to look when we set the original poses. There is probably some pretty intense mathematics going on here, but luckily we don't have to worry about that!

So if you choose to work in a certain way, you can effectively just ignore gimbal lock and concentrate on your animation. If you ever see weird interpolation happening on your rotations, just apply the euler filter, watch it fix itself, and carry on animating!


mrc said...

I actually came across your blog while searching for a
sollution to this problem. I also work in local rotation,
I just don't understand why Maya won't with me. The euler filter has never worked for me
and I run into this problem with every scene I animate.
It ends up costing me many frusterating hours. I would kill for a local rotation button in the graph editor, So each
curve would control one rotaion axis the way it should. Y=Y, X=X and so on; and more importantly the axises would remain their relationship
to the character through out the animation. Right now on frame 150 Y contols the a twist in the arm, but on frame 159 it raises the arm to the side
making it impossible to adjust my spacing in an intuative way. Im really in disbielf we have to work this way.
Did those people you work with come up with anything? Nice blogg by the way. I'll keep comming back for more.
Good luck on your project and cute kid.

Cameron Fielding said...

why has euler filter never worked?

- a few pointers that might help:

euler filter works on the whole animation range, not just selected keys in the graph ed. You can literally see the euler filter working, because your curves will change quite dramatically... if you dont see anything change, then you dont have gimbal lock problems and the euler filter wasn't neccesary. Euler filter will always work if it needs to. I would check your animation and make 100% sure that gimbal is actually the root of your problem if you are trying to apply it and it seems to "not work".

from your comment - it seems to me like you are working with the local manipulator, but youre still thinking in terms of X Y and Z. Maybe this is your problem. Think of rotations as POSES and not numbers or channels. POSES are the combination of X Y and Z. If you need to adjust your spacing, in my opinion it over complicates things to think of separate channels.. just pose your object and think of it like a drawing. Translation is a little different, its much simpler and occasionally important to think of XY and Z because the much simpler nature of the mathematics behind it... but even then, try and think POSES and not translation, rotation or XYZ ! :)

hope that helps somehow...

Bartek said...

Mr.Euler is my friend. Mr.Gimbal is not. Great blog dude! :) We gotta get in touch again!

Chintan Shah said...

Hello sir,

Just visited your blog... havent been thru all the posts... but i have to say it is AWESOME :D..... loads of gr8 stuff... thank you so much :D

God Bless,
Chintan :)

Anonymous said...

That kind of workflow is ideal to an animator; Poses, Spacing and Timing - let the machine figure out the math.

OK, on goes my TD hat ...

If your animation will be later driving more complex deformations or other motions (set driven keys for muscles etc) or cloth sims, than this kind of animation data is quite unruly for a TD to wrangle.

If your working with simple characters and/or your TD's have devised a system to accomaodate this kind of workflow than ROCK ON.

Otherwise there could be problems in the pipeline later.

I should have prefaced this comment with a giant "Nerd Alert" banner ;)

Anyway, I thought I'd just throw that out there. Great blog btw!

Sean Gilley said...

Yes, this is exactly how I work in Maya too. I started off animating in MAX and always used quaternion rotation controllers so I never had to deal with gimbal lock ever. It's a great way to animate IMHO cause you don't have to worry about the technical side, you just worry about the performance of the character. Unfortunately Maya's quaternion rotation controllers don't really work. Still though, using local mode for rotating your controls is something everyone should learn at one point or another.

Sheldon Kruger said...

Cameron...You're the man!

I am an Animation Mentor student and posted in the forum that Gimbal Lock....scares me when I see it happening.

Someone posted a link to your blog. I read it, gave the Euler filter a try..."BAM!"...its fixed.

I don't understand why there is such fear of gimbal lock then...when theres such an easy fix like the Euler filter. Or is just in the way people think/animate like you explained.

It just seems too good be true. Is it?

Thank you very much!

-Sheldon Kruger

Lou Hamou-Lhadj said...

Maybe I missed something, but why not just change your settings in Maya to use quaternions instead of euler angles...?

- Tim Sormin - said...

When I first learned Maya the Euler filter worked great for me, then one day it didn't. I don't remember if it was a different version of Maya (I think it was) or a different rig, but for the next 3 years of school I had to get by euler filter free and I set my manipulator to gimbal mode quite often - but only when I was running into problems. Now the filter works again. So basically, it's great to know what's happening in case you HAVE to fix it yourself, but hopefully you won't ever have to.

Anonymous said...

its easy for you to work in local manipulator mode ,but the fact is that even though your axes seem fine there is gimbal in your shot. This will effect the inbetweens on the keyframes.Working in local mode doesn't remove gimbal issue it just gives you different axes to rotate.If you rotate y axis in local it is actually rotating x,y,z axes in gimbal mode.

Cameron Fielding said...

hey Anonymous!

Yes youre exactly right. Working with "Local" mode manipulation does NOT remove gimbal issues at all.. however, it seems the euler filter has some crazy way of resolving gimbal issues when they occur ( but in fact, you could still animate with the gimbal manipulator, and allow euler filter to attempt to fix curves for you ).

Bear in mind this is a "quick trick" post and not a full-on solution to gimble lock - thats a whole other beast. Using the local manipulator and euler filter works fine 99% of the time for me...

Unknown said...

i try to solve it myself for a week i missed school and sleep time, but Mr.Euler worked just great,so now i can continue with my life

Chickens and Beandip said...

To the first commentor, what is likely happening, is a problem I used to do, You have a set pose with say rotation in x and y. Then the next pose is radically different, so you zero out the rotations and then set the new key only you forgot that the last time you were using x and y and instead set the new pose with z and y. Which looks like gimbal lock but it just a mistake in your keys. That one took me a while. But that is what he's talking about in thinking in X and Y instead of as keys.

rancie11 said...

The Euler Filter is really great for solving rotational problems that occur as a result of, say, rotating a foot around a twirling character. Where, instead of 1/2 a turn after a full turn (120 degrees + 360 degrees = 480 degrees) the keys on the graph fall under the 360 line. The Euler Filter does the math quite smartly. We always considered this problem Gimbal Flip, as opposed to Gimbal Lock. Lock being where the rotational tool is unusable because two axies fall on top of each other.
This is still a great article , even for me to read. Keep 'em up!

ThePatriotWhisper said...

Holy crap! This has just made my past rage on freaking gimbal lock all seem pointless! Thanks for saving my (and the guy beside me's) life!

rakesh said...

thank you so much.I never even knew about the euler filter and rectified gimbal problems by adding wierd inbetweens.After seeing your post, i tried to solve a wierdo rotation prob by using euler filter..dt didnt help but it opened my eyes to a bunch of other 'magic switches' and syvch. quaternion interpolation did it for me. THANKS!

Tejus V said...

You are a life saver!!!

Thanks a ton!

Unknown said...

OMG. Amazing.

Matt said...

You are my hero and have just saved me an immense headache.

Andrew Banta said...

You sir, have just changed my life. How was I never told about this?!!? Thanks a lot!

Anonymous said...

You saved my life!
Thanks a lot :-)