Skip to content

Commit fb2bbb0

Browse files
janhohenheimcartAlephCubed
authored
Nudge users into migrating to new default glTF coordinate conversion (#19816)
# Objective *Step towards #19686 We now have all the infrastructure in place to migrate Bevy's default behavior when loading glTF files to respect their coordinate system. Let's start migrating! For motivation, see the issue linked above ## Solution - Introduce a feature flag called `gltf_convert_coordinates_default` - Currently,`GltfPlugin::convert_coordinates` defaults to `false` - If `gltf_convert_coordinates_default` is enabled, `GltfPlugin::convert_coordinates` will default to `true` - If `gltf_convert_coordinates_default` is not enabled *and* `GltfPlugin::convert_coordinates` is false, we assume the user is implicitly using the old behavior. Print a warning *once* in that case, but only when a glTF was actually loaded - A user can opt into the new behavior either - Globally, by enabling `gltf_convert_coordinates_default` in their `Cargo.toml` - Globally, by enabling `GltfPlugin::convert_coordinates` - Per asset, by enabling `GltfLoaderSettings::convert_coordinates` - A user can explicitly opt out of the new behavior and silence the warning by - Enabling `gltf_convert_coordinates_default` in their `Cargo.toml` and disabling `GltfPlugin::convert_coordinates` - This PR also moves the existing release note into a migration guide Note that I'm very open to change any features, mechanisms, warning texts, etc. as needed :) ## Future Work - This PR leaves all examples fully functional by not enabling this flag internally yet. A followup PR will enable it as a `dev-dependency` and migrate all of our examples involving glTFs to the new behavior. - After 0.17 (and the RC before) lands, we'll gather feedback to see if anything breaks or the suggested migration is inconvenient in some way - If all goes well, we'll kill this flag and change the default of `GltfPlugin::convert_coordinates` to `true` in 0.18 ## Testing - Ran examples with and without the flag --------- Co-authored-by: Carter Anderson <mcanders1@gmail.com> Co-authored-by: AlephCubed <76791009+AlephCubed@users.noreply.github.com>
1 parent e6ba9a6 commit fb2bbb0

File tree

7 files changed

+51
-7
lines changed

7 files changed

+51
-7
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,11 @@ web = ["bevy_internal/web"]
561561
# Enable hotpatching of Bevy systems
562562
hotpatching = ["bevy_internal/hotpatching"]
563563

564+
# Enable converting glTF coordinates to Bevy's coordinate system by default. This will be Bevy's default behavior starting in 0.18.
565+
gltf_convert_coordinates_default = [
566+
"bevy_internal/gltf_convert_coordinates_default",
567+
]
568+
564569
# Enable collecting debug information about systems and components to help with diagnostics
565570
debug = ["bevy_internal/debug"]
566571

crates/bevy_gltf/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pbr_multi_layer_material_textures = [
1515
]
1616
pbr_anisotropy_texture = ["bevy_pbr/pbr_anisotropy_texture"]
1717
pbr_specular_textures = ["bevy_pbr/pbr_specular_textures"]
18+
gltf_convert_coordinates_default = []
1819

1920
[dependencies]
2021
# bevy
@@ -64,8 +65,6 @@ serde = { version = "1.0", features = ["derive"] }
6465
serde_json = "1.0.140"
6566
smallvec = "1.11"
6667
tracing = { version = "0.1", default-features = false, features = ["std"] }
67-
68-
[dev-dependencies]
6968
bevy_log = { path = "../bevy_log", version = "0.17.0-dev" }
7069

7170
[lints]

crates/bevy_gltf/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ impl Default for GltfPlugin {
185185
GltfPlugin {
186186
default_sampler: ImageSamplerDescriptor::linear(),
187187
custom_vertex_attributes: HashMap::default(),
188-
convert_coordinates: false,
188+
convert_coordinates: cfg!(feature = "gltf_convert_coordinates_default"),
189189
}
190190
}
191191
}

crates/bevy_gltf/src/loader/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ mod extensions;
22
mod gltf_ext;
33

44
use alloc::sync::Arc;
5+
use bevy_log::warn_once;
56
use std::{
67
io::Error,
78
path::{Path, PathBuf},
@@ -297,7 +298,18 @@ async fn load_gltf<'a, 'b, 'c>(
297298

298299
let convert_coordinates = match settings.convert_coordinates {
299300
Some(convert_coordinates) => convert_coordinates,
300-
None => loader.default_convert_coordinates,
301+
None => {
302+
let convert_by_default = loader.default_convert_coordinates;
303+
if !convert_by_default && !cfg!(feature = "gltf_convert_coordinates_default") {
304+
warn_once!(
305+
"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. \
306+
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. \
307+
If you encounter any issues please file a bug! \
308+
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."
309+
);
310+
}
311+
convert_by_default
312+
}
301313
};
302314

303315
#[cfg(feature = "bevy_animation")]

crates/bevy_internal/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ web = [
355355

356356
hotpatching = ["bevy_app/hotpatching", "bevy_ecs/hotpatching"]
357357

358+
gltf_convert_coordinates_default = [
359+
"bevy_gltf?/gltf_convert_coordinates_default",
360+
]
361+
358362
debug = ["bevy_utils/debug"]
359363

360364
[dependencies]

docs/cargo_features.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ The default feature set enables most of the expected features of a game engine,
8989
|ghost_nodes|Experimental support for nodes that are ignored for UI layouting|
9090
|gif|GIF image format support|
9191
|glam_assert|Enable assertions to check the validity of parameters passed to glam|
92+
|gltf_convert_coordinates_default|Enable converting glTF coordinates to Bevy's coordinate system by default. This will be Bevy's default behavior starting in 0.18.|
9293
|hotpatching|Enable hotpatching of Bevy systems|
9394
|ico|ICO image format support|
9495
|jpeg|JPEG image format support|

release-content/release-notes/convert-coordinates.md renamed to release-content/migration-guides/convert-coordinates.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Allow importing glTFs with a corrected coordinate system
33
authors: ["@janhohenheim"]
4-
pull_requests: [19633, 19685]
4+
pull_requests: [19633, 19685, 19816]
55
---
66

77
glTF uses the following coordinate system:
@@ -24,7 +24,27 @@ Long-term, we'd like to fix our glTF imports to use the correct coordinate syste
2424
But changing the import behavior would mean that *all* imported glTFs of *all* users would suddenly look different, breaking their scenes!
2525
Not to mention that any bugs in the conversion code would be incredibly frustating for users.
2626

27-
This is why we are now gradually rolling out support for corrected glTF imports. Starting now you can opt into the new behavior by setting `convert_coordinates` on `GltfPlugin`:
27+
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:
28+
29+
> 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.
30+
> 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.
31+
> If you encounter any issues please file a bug!
32+
> 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`.
33+
> See the migration guide for more details.
34+
35+
As the warning says, you can opt into the new behavior by enabling the `gltf_convert_coordinates_default` feature in your `Cargo.toml`:
36+
37+
```toml
38+
# old behavior, ignores glTF's coordinate system
39+
[dependencies]
40+
bevy = "0.17.0"
41+
42+
# new behavior, converts the coordinate system of all glTF assets into Bevy's coordinate system
43+
[dependencies]
44+
bevy = { version = "0.17.0", features = ["gltf_convert_coordinates_default"] }
45+
```
46+
47+
If you prefer, you can also do this in code by setting `convert_coordinates` on `GltfPlugin`:
2848

2949
```rust
3050
// old behavior, ignores glTF's coordinate system
@@ -41,6 +61,9 @@ App::new()
4161
.run();
4262
```
4363

64+
If you want to continue using the old behavior in the future, you can silence the warning by enabling the `gltf_convert_coordinates_default` feature
65+
and explicitly setting `convert_coordinates: false` on `GltfPlugin`.
66+
4467
You can also control this on a per-asset-level:
4568

4669
```rust
@@ -56,7 +79,7 @@ let handle = asset_server.load_with_settings(
5679
);
5780
```
5881

59-
Afterwards, your scene will be oriented such that your modeling software's forward direction correctly corresponds to Bevy's forward direction.
82+
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.
6083

6184
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
6285
oriented the right way across all programs in your pipeline:

0 commit comments

Comments
 (0)