Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quaternions "(x,y,z,w) convention" quite misleading :( #2250

Closed
apendua opened this issue Jul 27, 2012 · 5 comments
Closed

Quaternions "(x,y,z,w) convention" quite misleading :( #2250

apendua opened this issue Jul 27, 2012 · 5 comments

Comments

@apendua
Copy link
Contributor

apendua commented Jul 27, 2012

Recently, I've been working on skeletal animation exporter from Blender to THREE. After long hours spent on looking for imaginary bugs I finally managed to get something that is actually working. Surprisingly, the most difficult part was to realize that the JSONLoader, or more precisely the Quaternion constructor, is in fact accepting quaternion coordinates in the form of (x,y,z,w), contrary to the Blender's (not only!) standard notation (w,x,y,z). Clearly, this seems to be a minor issue, but I think it at least deserves mentioning somewhere :) Quaternion.js is not an obvious place to look for a problem when your animation code does not work as expected, to be honest.

Also keep in mind, that the "Blender convention" is not at all accidental. In maths, one usually write a quaternion in the form:

q = w + i * x + j * y + z * k,

where i, j, k are some special constants, e.g. the unit quaternion is just q = 1 = 1 + i * 0 + j * 0 + k * 0. So the w-coordinate is evidently distinguished, and it feels more natural to write it on the first position. Similarly, the real part of a complex number always takes precedence over the imaginary part, and no one objects ;)

Cheers,
Tomasz

@mrdoob
Copy link
Owner

mrdoob commented Jul 27, 2012

I wonder what @WestLangley thinks about this.

@alteredq
Copy link
Contributor

@mrdoob Brief googling shows this seems to be pretty arbitrary convention (as is often the case in computer graphics) - e.g. DirectX, XNA, Unity or Maya use xyzw like we do, OGRE uses wxyz.

But this seems to be quite moot, anyways even with Blender you access quaternions mostly via named properties (e.g. I wasn't even aware it used wxyz).

@apendua Are you aware there already is skeletal animation export for Blender? It's still bit rough around edges but it works (see #2106):

http://alteredqualia.com/three/examples/webgl_crowd.html
http://alteredqualia.com/three/examples/webgl_animation_skinning_tf2.html

@apendua
Copy link
Contributor Author

apendua commented Jul 28, 2012

@alteredq I only became aware of this brand new exporter a few hours ago, while I was looking for some clues to find out what was wrong with my code. If there's anything I could help with - at least at the blender site - please keep me updated.

Talking about this "quaternion convention"... what I was trying to say was not that it's not arbitrary - you could as well write zyxw or anything - but one of these orderings seems to be more natural than the others and the reasons for that are purely mathematical. Or, if it does not convince you, lets just agree that we should put the coordinates in the alphabetical order, like "uv coordinates" not "vu" ;)

As you said, since quaternions are mostly used as black boxes - i.e. access through methods and props - the problem only occurs while importing or exporting the data into a file. So why not embed the information about quaternion encoding into the meta data section? Come on, if you decided to put the "generated by" attribute in there, the you could as well declare quaternion encoding.

@mrdoob, @alteredq By the way, I've been also thinking about implementing some more advanced animation features for THREE.js, like action graphs / bone constraints / inverse kinematics. Do you have any suggestions where to start? This would definitely require some major modifications in the file format, so any guidance would be greatly appreciated :)

@WestLangley
Copy link
Collaborator

@mrdoob To me, this is a matter of personal preference. With all due respect to @apendua, I really don't see a compelling reason to change the signature.

@apendua
Copy link
Contributor Author

apendua commented Jul 28, 2012

@WestLangley I've never asked anyone to do so. In fact, I really appreciate your work guys and would never bother you with such a small problem, if it wasn't for the fact that at some point I wasted several hours of debugging, not being aware of the issue. My only goal was to bring this matter to the world, hoping that it saves someone's time in the future.

But maybe it won't, since the only place where it really matters is the source code of animation exporter, which is already there :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants