-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 mismatch between Bevy and glTF #5670
Comments
Interesting. I didn't know that glTF stated that if a model has a clear forward direction, that it should point along +z. I thought it was up to the modeller / team to define their convention. The question of "what direction is forward?" came up in the rendering Discord channel a while ago. My answer back then was that whatever is the natural forward direction of the model defines what its forward should be, but also that for a camera, -z is forward because the identity transform leaves the camera looking along -z as per projection conventions for right-handed x-right, y-up, z-back. glTF has a convention where forward is +z, but does that mean all glTF models have front pointing along +z? Also, I expect bevy will support importing from other formats through plugins or so, and I don't know if they have such conventions too. My initial feeling was that I don't like proposal 1, and either 2 or 3 would be agreeable. But if one considers other formats having other conventions, or just that any imported model from any format, regardless of suggested conventions, may have a different direction for forward, maybe what we should do is make it easy to specify the forward direction of the model. Perhaps @cart has already thought about this and has some opinions, I don't know. :) |
I actually prefer proposal 1 over the other two. My reasoning is as follows: Ideally, the direction that is forward in the modelling application (e.g Blender has a front, top and right view which determine this) is preserved through the asset pipeline (export + possibly some intermediate conversions + import) such that in Bevy Transform::forward() aligns with this direction. Why drop this information somewhere along the way (proposal 3) if you have it and can make use of it. Therefore for every conversion, when both the previous and the new format have such a convention, the conversion needs to preserve the forward direction (Blender certainly does so for it's export). This includes the import from a given model format into Bevy. I assume you agree that if Bevy were to support a Z-up file format, the loader should definitely do some coordinate transformation instead of just taking X, Y and Z as is. So it only makes sense for the glTF loader to transform from the glTF convention to the Bevy convention. The question then is, what the Bevy convention should be. You presented a reason for -Z being forward in Bevy which already matches the current Transform implementation. I don't think there is any reason to mix conventions when it is avoidable. Looking at #1153 it might however also require a change to the look_at implementation to be consistent there. |
I'd like to see how this is solved, it's relevant to: |
Here's some discussion on this issue that happened in the Discord. Copying it here for discoverability.
|
Choosing -z as forward came from the following; With right handed y-up and x-right, the "default" view (ex: the view in 2d and 3d) points in the negative z direction, with positive z coming out of the screen. In this context, if I move anything in 2d or 3d (a sprite, a 3d model, a UI element) "forward" (relative to the camera view) it is moving in the negative z direction. This made sense to me. Treating z-positive as forward would mean a "default" camera (standard orthographic projection with identity transform matrix) would be facing "backward". But if somebody does a survey of popular right handed y-up software in the gamedev space and finds a reasonably consistent z-positive-is-forward, I'm happy to revisit this. I'd also like to know how they handle default cameras in that context though. (ex: do they spawn them rotated 180 degrees around the y axis? do they just let them face backward by default?) |
@cart - that response discusses axis conventions and camera forward conventions within those axes. But how do you feel about what we should do with assets that have a strong definition of what forward means, such as gltf that has the same axis conventions but +z is forwards? |
We definitely want to honor format intentions to the best of our abilities. If after we resolve the "z-forward" conversation we continue considering z-negative as forward, I think we should add a "flip z axis" setting to the GLTF importer, which defaults to |
@cart, can we have a generic "apply custom Transform" setting for GLTF importer? I have 3d models from sketchfab that are wrongly rotated, moved or scaled. Sometimes I can't fix them due to "no-modification" license clause. I can of course add them as a child entity, but that seems like a needless burden for transform propagation system. Suggestion: instead of edit: argument could be made for similar setting for all loaded assets (e.g. sprites), but I haven't worked with these enough to see if it makes sense to generalize further |
This sounds like a good use case for the "Asset Transforms" we've been discussing in #8624, which would allow arbitrary transformations of assets after the initial load. But I'm also open to an "apply transform" field in the GTLF importer. |
I would find it very beneficial to have an easy way of setting the coordinate system. We have a system that works cross platform/game engines (multiplayer) and as such went with a vendor neutral coordinate system that gltf uses. Would be great to use gltf for my use case |
Here's a handy chart comparing the coordinate systems of various game engines and DCC apps: https://twitter.com/FreyaHolmer/status/644881436982575104/photo/1 |
Opinion from game industry veteran from discussion. |
The convention is that the camera is looking at the front of the asset. And for purpose of viewing and constructing assets this is pretty helpful. For the most part only 1st/3rd person player characters/entities would be accurately represented by a forward facing camera, and even then only by the owning player. For this reason I prefer +z forward. |
Generally I think it sounds like the proposed preprocessing will provide a really solid catch all for any asset pipeline and would be an upgrade to Unity and Unreal, where often tech artists are writing adhoc equivalents. |
@cart what would a software survey look like? In my mind it'd be, "what DCC do you use, what rigging plugins, and what's your coord system before exporting" |
Actually gltf 2.0 has different requirements for assets:
and cameras:
|
This is a great callout. I see some conflation of the viewer's space and world space for what the asset coordinate space should be. The biggest pain points in game production for coordinate spaces in my experience (and anybody I've talked with in the industry) come from rigged assets, i.e. Root Motion, runtime bone attachment. I understand that there are whole swaths of games that won't have to deal with these problems, but transforms are typically easier to solve for in those cases. And since there's a pretty solid standard for rig coordinate spaces across film and games I'd like to see that standard get more direct support in Bevy. |
Bevy version
0.8.0
What you did
What you expected
Model moves forward.
What went wrong
Both Bevy and glTF use a right-handed Y-up coordinate system. They do however disagree on what direction is forward and right:
Possible solutions
In any case, Bevy should be consistent regarding its coordinate system. Currently, the look_at function follows the glTF convention and not the Transform's definition of forward and right (see #1153)
The text was updated successfully, but these errors were encountered: