3 ms·
Be aware, quaternions are not always the right solution. There's a reason Unity, Unreal, 3DSMax, Maya, Blender, etc all support Euler interpolation in animation
by greggman3 5y ago
Be aware, quaternions are not always the right solution. There's a reason Unity, Unreal, 3DSMax, Maya, Blender, etc all support Euler interpolation in animation. A simple example is an artist might want to show a clock hand spinning fast to show the progress of time. To do that they set a start angle of 0 and an end angle of say 20000. Sure, there may be ways to represent that with specialized quaternions but in general the 3D tools all seems to default to using Eulers.
This is an issue with the GLTF format. They chose quaternions to represent rotations in animation and as such can't easily represent what the artist's intent was.
You might claim you can sample the Euler animation and split it into multiple quaternion slerps but that brings up another issue which is you need support for discontinuous animations in order to handle other situations (another thing the GLTF format apparently didn't consider).
- sillysaurusx 5y ago“Why not both?”
- mottosso 5y agoYes, exactly. The article even points this out: > However writing a rotation directly in quaternion form isn't really intuitive, what we do instead is convert an Euler angle to a quaternion then use it for rotating.
- jonas21 5y agoYeah, I think any time you need to interface with a human, Euler angles are better because they're more intuitive. There's a good reason aircraft instruments display things in Euler angles, for example.
- klodolph 5y agoQuaternions usually match artist's intent, and Euler angles usually don't. glTF isn't alone in using quaternions. I did a bunch of FBX imports a while back all the orientation channels are just quaternions. It makes sense, because it's one natural way to interpolate rotation data, just based on the orientations of bones during the keyframes. The kind of stuff that you interpolate using Euler angles is going to be stuff that is naturally on gimbals, like cameras, tanks, robots, turrets, and stuff like that. You can do that easily enough by adding another node to your transform hierarchy with quaternions, but if you started off with Euler angles, you don't really have a way to back out. Quaternions are not always right, but they are the right default. If you want Euler angles, you can always translate to-from quaternions. Quaternions are independent of the way you set up the coordinate system and each axis is equal. Unity, for example, uses quaternions internally. It exposes getters and setters for Euler angles that do the conversion to/from quaternions as a convenience. The editor edits Euler angles but they disappear as soon as you are in-game, and if you open up your scene file in a text editor, you'll see m_LocalRotation with the x/y/z/w of a quaternion. I believe Unreal is the same way. Honestly, that just makes too much sense. Trying to do a physics simulation with Euler angles is just adding extra steps, because Euler angles are not easily composable. If you want to compose two Euler angles to get a third, the easy way to do it is to convert to quaternions, multiply, and then convert back to euler angles. You can see Euler angles in the editor when you are animating a model, but most of the time you are just dragging stuff around on screen or matching mocap data and quaternions make 100x more sense than Euler angles for representing that stuff. My sense is that any code which does a lot of trig, when there's an obvious way to write the code that does no trig, should probably be rewritten to eliminate the trig. A little bit of sin/cos/tan is fine but as soon as you are doing round trips with acos/asin/atan, you have to start considering where the branch cuts are.
- greggman3 5y agoUnity uses quaternions in the rotation but the actual animation curves are still interpolating Euler angles. Same with Unreal, Maya, 3DSMax, Blender etc... GLTF requires you to convert the animation curves to quaternions. That's a lossy operation