-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Improve glTF coordinate migration guide #20123
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
Open
janhohenheim
wants to merge
10
commits into
bevyengine:main
Choose a base branch
from
janhohenheim:gltf-desc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+35
−17
Open
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5bf8952
Improve glTF coordinate migration guide
janhohenheim d60ba1f
Improve phrase
janhohenheim 7527ee6
Improve phrase
janhohenheim 95cce42
Improve phrase
janhohenheim 722df2c
Improve phrase
janhohenheim 55f8e1d
Improve phrase
janhohenheim 737ff6d
Improve phrase
janhohenheim 00a51bb
Improve phrase
janhohenheim 3b75737
Update convert-coordinates.md
janhohenheim 1db7b6b
Merge branch 'main' into gltf-desc
janhohenheim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,34 +4,53 @@ authors: ["@janhohenheim"] | |
pull_requests: [19633, 19685, 19816] | ||
--- | ||
|
||
glTF uses the following coordinate system: | ||
If you're loading a glTF, you will be greeted by the following deprecation warning: | ||
|
||
> Starting from Bevy 0.18, by default all imported glTF scenes will be rotated by 180 degrees around the Y axis to align with Bevy's coordinate system. | ||
> You are currently importing glTF scenes using the old behavior. Consider opting-in to the new import behavior by enabling the `gltf_convert_coordinates_default` feature. | ||
> If you encounter any issues please file a bug! | ||
> If you want to continue using the old behavior going forward (even when the default changes in 0.18), manually set the corresponding option in the `GltfPlugin` or `GltfLoaderSettings`. | ||
> See the migration guide for more details. | ||
|
||
As the warning says, this means that from now on glTF scenes will imported with a 180 degree rotation around the Y axis when compared to the old behavior. | ||
To understand why this is desirable, we need to take a look at coordinate systems. | ||
|
||
Bevy uses the following coordinate system: | ||
|
||
- forward: -Z | ||
- up: Y | ||
- right: X | ||
|
||
Even though we never explicitly stated this anywhere, it was implicitly accepted that this coordinate system was used for all things that have a `Transform`, | ||
as indicated by e.g. `Transform::forward()` returning the local -Z direction. In contrast, glTF is a bit more complicated. Models loaded from glTF scenes use the following coordinate system: | ||
|
||
- forward: Z | ||
- up: Y | ||
- right: -X | ||
|
||
and Bevy uses: | ||
but cameras and lights loaded from glTFs use the following coordinate system: | ||
|
||
- forward: -Z | ||
- up: Y | ||
- right: X | ||
|
||
This means that to correctly import glTFs into Bevy, vertex data should be rotated by 180 degrees around the Y axis. | ||
For the longest time, Bevy has simply ignored this distinction. That caused issues when working across programs, as most software respects the | ||
glTF coordinate system when importing and exporting glTFs. Your scene might have looked correct in Blender, Maya, TrenchBroom, etc. but everything would be flipped when importing it into Bevy! | ||
As you can see, this clashes with how Bevy assumes that everything in the world uses the same coordinate system. | ||
In the past, we have imported glTFs using the camera / light coordinate system for everything, as it is already aligned with Bevy. | ||
In other words, the glTF imported simply assumed that glTF models used -Z as their forward direction, even though they use +Z. | ||
|
||
Long-term, we'd like to fix our glTF imports to use the correct coordinate system by default. | ||
But changing the import behavior would mean that *all* imported glTFs of *all* users would suddenly look different, breaking their scenes! | ||
Not to mention that any bugs in the conversion code would be incredibly frustating for users. | ||
But that meant that a glTF model's `Transform::forward()` would actually point backwards from the point of view of the model, | ||
which is counterintuitive and very annoying when working across different art pipelines. | ||
|
||
This is why we are now gradually rolling out support for corrected glTF imports. You will now be greeted by the following warning when using the old behavior: | ||
To remedy this, we want to change the default glTF import behavior so that the coordinate system of glTF *models* instead of glTF *cameras* is aligned with Bevy. | ||
In practice, this means rotating the scene as described above. | ||
The downside is that glTF cameras that have an identity transform in glTF will now look to +Z instead of -Z in Bevy. | ||
This should not be a problem, as the whole scene rotated anyways, so the end result on your screen will look the exact same. | ||
|
||
> Starting from Bevy 0.18, by default all imported glTF models will be rotated by 180 degrees around the Y axis to align with Bevy's coordinate system. | ||
> You are currently importing glTF files using the old behavior. Consider opting-in to the new import behavior by enabling the `gltf_convert_coordinates_default` feature. | ||
> If you encounter any issues please file a bug! | ||
> If you want to continue using the old behavior going forward (even when the default changes in 0.18), manually set the corresponding option in the `GltfPlugin` or `GltfLoaderSettings`. | ||
> See the migration guide for more details. | ||
But, since most users load only models and not cameras through glTF, | ||
changing the import behavior in one big swoop would mean that most imported glTF models would suddenly look different, breaking users' scenes! | ||
Not to mention that any bugs in the conversion code would be incredibly frustrating for users. | ||
|
||
This is why we are now gradually rolling out support for corrected glTF imports. | ||
As the warning says, you can opt into the new behavior by enabling the `gltf_convert_coordinates_default` feature in your `Cargo.toml`: | ||
|
||
```toml | ||
|
@@ -79,10 +98,9 @@ let handle = asset_server.load_with_settings( | |
); | ||
``` | ||
|
||
After opting into the new behavior, your scene will be oriented such that your modeling software's forward direction correctly corresponds to Bevy's forward direction. | ||
After opting into the new behavior, your scene will be oriented such that other software's model forward direction correctly corresponds to Bevy's forward direction. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should mention that is only relevant to importing scene's through bevy's gLTF importer. If someone uses something else like FBX or obj we can't make that guarantee since they would use an external importer. |
||
|
||
For example, Blender assumes -Y to be forward, so exporting the following model to glTF and loading it in Bevy with the new settings will ensure everything is | ||
oriented the right way across all programs in your pipeline: | ||
For example, Blender assumes -Y to be forward for models, so exporting the following model to glTF and loading it in Bevy with the new settings will ensure that the fox looks to -Z in Bevy: | ||
|
||
<!-- TODO: Add png from PR description --> | ||
 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.