Skip to content

Commit 28ae21e

Browse files
committed
scene_viewer: Use a struct as a system label instead of a string
1 parent c25be9f commit 28ae21e

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

examples/tools/scene_viewer.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use bevy::{
22
asset::{AssetServerSettings, LoadState},
33
input::mouse::MouseMotion,
4+
math::Vec3A,
45
prelude::*,
56
render::{
67
camera::{Camera2d, Camera3d, CameraProjection},
@@ -9,6 +10,9 @@ use bevy::{
910
scene::InstanceId,
1011
};
1112

13+
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemLabel)]
14+
struct CameraControllerCheckSystem;
15+
1216
fn main() {
1317
println!(
1418
"
@@ -41,9 +45,9 @@ Controls:
4145
.add_startup_system(setup)
4246
.add_system_to_stage(CoreStage::PreUpdate, scene_load_check)
4347
.add_system_to_stage(CoreStage::PreUpdate, camera_spawn_check)
44-
.add_system(camera_controller_check.label("camera_controller_check"))
48+
.add_system(camera_controller_check.label(CameraControllerCheckSystem))
4549
.add_system(update_lights)
46-
.add_system(camera_controller.after("camera_controller_check"))
50+
.add_system(camera_controller.after(CameraControllerCheckSystem))
4751
.run();
4852
}
4953

@@ -133,29 +137,30 @@ fn camera_spawn_check(
133137
return;
134138
}
135139

136-
let mut min = Vec3::splat(f32::MAX);
137-
let mut max = Vec3::splat(f32::MIN);
140+
let mut min = Vec3A::splat(f32::MAX);
141+
let mut max = Vec3A::splat(f32::MIN);
138142
for (transform, maybe_aabb) in meshes.iter() {
139143
let aabb = maybe_aabb.unwrap();
140144
// If the Aabb had not been rotated, applying the non-uniform scale would produce the
141145
// correct bounds. However, it could very well be rotated and so we first convert to
142146
// a Sphere, and then back to an Aabb to find the conservative min and max points.
143147
let sphere = Sphere {
144-
center: transform.mul_vec3(aabb.center),
145-
radius: (transform.scale * aabb.half_extents).length(),
148+
center: Vec3A::from(transform.mul_vec3(Vec3::from(aabb.center))),
149+
radius: (Vec3A::from(transform.scale) * aabb.half_extents).length(),
146150
};
147151
let aabb = Aabb::from(sphere);
148152
min = min.min(aabb.min());
149153
max = max.max(aabb.max());
150154
}
151155

152156
let size = (max - min).length();
153-
let aabb = Aabb::from_min_max(min, max);
157+
let aabb = Aabb::from_min_max(Vec3::from(min), Vec3::from(max));
154158

155159
if !scene_handle.has_camera {
156-
let transform =
157-
Transform::from_translation(aabb.center + size * Vec3::new(0.5, 0.25, 0.5))
158-
.looking_at(aabb.center, Vec3::Y);
160+
let transform = Transform::from_translation(
161+
Vec3::from(aabb.center) + size * Vec3::new(0.5, 0.25, 0.5),
162+
)
163+
.looking_at(Vec3::from(aabb.center), Vec3::Y);
159164
let view = transform.compute_matrix();
160165
let mut perspective_projection = PerspectiveProjection::default();
161166
perspective_projection.far = perspective_projection.far.max(size * 10.0);

0 commit comments

Comments
 (0)