-
Notifications
You must be signed in to change notification settings - Fork 480
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
Coordinate System #257
Comments
Hi Jenni, Unity's coordinate system is left-handed, and glTF's coordinate system is right-handed. UnityGLTF converts between these coordinate systems on import an export by inverting the x component of positions and directions. You can see where this is defined in SchemaExtensions.cs. // glTF matrix: column vectors, column-major storage, +Y up, +Z forward, -X right, right-handed
// unity matrix: column vectors, column-major storage, +Y up, +Z forward, +X right, left-handed
// multiply by a negative X scale to convert handedness
public static readonly GLTF.Math.Vector3 CoordinateSpaceConversionScale = new GLTF.Math.Vector3(-1, 1, 1); You can see this being used in Have you been experiencing issues when importing/exporting models? Could you provide any more info on where there's a 180° rotation in the code? Thanks, |
Thanks for the answer!
By applying this method a 180 degree rotation around the x axis is applied. |
A positive rotation in Unity rotates clockwise, while a positive rotation in glTF rotates counterclockwise. To convert from Unity's Quaternion rotations to glTF, the code should flip the direction of rotation. This can be done for example by negating the (y and z) or (x and w) components of a quaternion. Edit: fixed axes because of the forward convention |
But by calculation the variable newAxis the y and z axis gets negated, right? |
In GLTFSceneExporter the function TransformAttributes does not exist, right? So where is this transformation done? |
Sorry, I didn't mean the code is necessarily doing it correctly. @dave-hill Can you investigate? |
Sure thing, thanks Gary. Hi Jenni, you're right that the net result of the logic in ToGltfQuaternionConvert is to negate the y and z components of the rotation quaternion. This turns a clockwise rotation into a counter-clockwise rotation and vice-versa, as Gary described. I've just been testing this code by exporting a scene with various rotations and verified that the output result was correct each time. Note that negating the components of a quaternion doesn't behave in the same way as negating the components of a position vector - the rotation direction is mirrored rather than applying a 180° rotation. Could you tell me a bit more about any issue you're seeing here, and maybe some repro steps? Are you seeing incorrect rotations when importing or exporting to glTF? Or did the code just look weird and you just wanted to make sure it was right? It took me a while to work out what was going on in that function! Edit: After writing this, I dug further into the code and wrote a bit more about what the code is doing as a comment to #256. I think the code is correct and we can consider closing these issues after giving people a chance to comment. Thanks, |
I've just created PR #294 to add some comments to help explain how some of this math works. |
Hello :)
Is it right, that UnityGLTF is using a right coordinate system with y down?
So y down, x to the right and z to the screen.
I am asking since i saw in your code that you are using a 180 degree rotation around x to transform Unity coord to yours.
Jenni
The text was updated successfully, but these errors were encountered: