Skip to content

Commit 8c8cbaf

Browse files
authored
Add option to scene_viewer that enables glTF coordinate conversion (#20609)
Add a `--use-model-forward-direction` option to the `scene_viewer` example. This enables `GltfPlugin::use_model_forward_direction`, which is useful for testing issues like #20608. I suspect the option can be `bool` rather than `Option<bool>`, but it's consistent with other `scene_viewer` options. ## Testing ```sh cargo run --example scene_viewer -- "assets/models/faces/faces.glb" --use-model-forward-direction ```
1 parent b6922f9 commit 8c8cbaf

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

examples/tools/scene_viewer/main.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use bevy::{
1313
asset::UnapprovedPathMode,
1414
camera::primitives::{Aabb, Sphere},
1515
core_pipeline::prepass::{DeferredPrepass, DepthPrepass},
16+
gltf::GltfPlugin,
1617
pbr::DefaultOpaqueRendererMethod,
1718
prelude::*,
1819
render::experimental::occlusion_culling::OcclusionCulling,
@@ -51,6 +52,22 @@ struct Args {
5152
/// spawn a light even if the scene already has one
5253
#[argh(switch)]
5354
add_light: Option<bool>,
55+
/// enable `GltfPlugin::use_model_forward_direction`
56+
#[argh(switch)]
57+
use_model_forward_direction: Option<bool>,
58+
}
59+
60+
impl Args {
61+
fn rotation(&self) -> Quat {
62+
if self.use_model_forward_direction == Some(true) {
63+
// If the scene is converted then rotate everything else to match. This
64+
// makes comparisons easier - the scene will always face the same way
65+
// relative to the camera.
66+
Quat::from_xyzw(0.0, 1.0, 0.0, 0.0)
67+
} else {
68+
Quat::IDENTITY
69+
}
70+
}
5471
}
5572

5673
fn main() {
@@ -76,6 +93,10 @@ fn main() {
7693
// Allow scenes to be loaded from anywhere on disk
7794
unapproved_path_mode: UnapprovedPathMode::Allow,
7895
..default()
96+
})
97+
.set(GltfPlugin {
98+
use_model_forward_direction: args.use_model_forward_direction.unwrap_or(false),
99+
..default()
79100
}),
80101
CameraControllerPlugin,
81102
SceneViewerPlugin,
@@ -170,8 +191,10 @@ fn setup_scene_after_load(
170191
let mut camera = commands.spawn((
171192
Camera3d::default(),
172193
Projection::from(projection),
173-
Transform::from_translation(Vec3::from(aabb.center) + size * Vec3::new(0.5, 0.25, 0.5))
174-
.looking_at(Vec3::from(aabb.center), Vec3::Y),
194+
Transform::from_translation(
195+
Vec3::from(aabb.center) + size * (args.rotation() * Vec3::new(0.5, 0.25, 0.5)),
196+
)
197+
.looking_at(Vec3::from(aabb.center), Vec3::Y),
175198
Camera {
176199
is_active: false,
177200
..default()
@@ -182,6 +205,7 @@ fn setup_scene_after_load(
182205
specular_map: asset_server
183206
.load("assets/environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),
184207
intensity: 150.0,
208+
rotation: args.rotation(),
185209
..default()
186210
},
187211
camera_controller,
@@ -211,7 +235,8 @@ fn setup_scene_after_load(
211235
info!("Spawning a directional light");
212236
let mut light = commands.spawn((
213237
DirectionalLight::default(),
214-
Transform::from_xyz(1.0, 1.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y),
238+
Transform::from_translation(args.rotation() * Vec3::new(1.0, 1.0, 0.0))
239+
.looking_at(Vec3::ZERO, Vec3::Y),
215240
));
216241
if args.occlusion_culling == Some(true) {
217242
light.insert(OcclusionCulling);

0 commit comments

Comments
 (0)