Skip to content

Commit 2319cc8

Browse files
Add on_top setting toggle to the 3d_gizmos example
Co-authored-by: IceSentry <c.giguere42@gmail.com>
1 parent f0d8826 commit 2319cc8

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

examples/3d/3d_gizmos.rs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,52 @@ fn main() {
99
.add_startup_system(setup)
1010
.add_system(system)
1111
.add_system(rotate_camera)
12+
.add_system(update_config)
1213
.run();
1314
}
1415

15-
fn setup(mut commands: Commands) {
16+
fn setup(
17+
mut commands: Commands,
18+
mut meshes: ResMut<Assets<Mesh>>,
19+
mut materials: ResMut<Assets<StandardMaterial>>,
20+
asset_server: Res<AssetServer>,
21+
) {
1622
commands.spawn(Camera3dBundle {
1723
transform: Transform::from_xyz(0., 1.5, 6.).looking_at(Vec3::ZERO, Vec3::Y),
1824
..default()
1925
});
26+
// plane
27+
commands.spawn(PbrBundle {
28+
mesh: meshes.add(Mesh::from(shape::Plane::from_size(5.0))),
29+
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
30+
..default()
31+
});
32+
// cube
33+
commands.spawn(PbrBundle {
34+
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
35+
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
36+
transform: Transform::from_xyz(0.0, 0.5, 0.0),
37+
..default()
38+
});
39+
// light
40+
commands.spawn(PointLightBundle {
41+
point_light: PointLight {
42+
intensity: 1500.0,
43+
shadows_enabled: true,
44+
..default()
45+
},
46+
transform: Transform::from_xyz(4.0, 8.0, 4.0),
47+
..default()
48+
});
49+
// text
50+
commands.spawn(TextBundle::from_section(
51+
"Press 't' to toggle drawing gizmos on top of everything else in the scene",
52+
TextStyle {
53+
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
54+
font_size: 24.,
55+
color: Color::WHITE,
56+
},
57+
));
2058
}
2159

2260
fn system(mut gizmos: Gizmos, time: Res<Time>) {
@@ -33,7 +71,12 @@ fn system(mut gizmos: Gizmos, time: Res<Time>) {
3371
Color::GREEN,
3472
);
3573

36-
gizmos.sphere(Vec3::new(1., 0.5, 0.), Quat::IDENTITY, 0.5, Color::RED);
74+
gizmos.sphere(
75+
Vec3::new(1., 0.5, 0.),
76+
Quat::IDENTITY,
77+
0.5,
78+
Color::RED.with_a(0.5),
79+
);
3780

3881
for y in [0., 0.5, 1.] {
3982
gizmos.ray(
@@ -59,3 +102,9 @@ fn rotate_camera(mut query: Query<&mut Transform, With<Camera>>, time: Res<Time>
59102

60103
transform.rotate_around(Vec3::ZERO, Quat::from_rotation_y(time.delta_seconds() / 2.));
61104
}
105+
106+
fn update_config(mut gizmo_config: ResMut<GizmoConfig>, keyboard: Res<Input<KeyCode>>) {
107+
if keyboard.just_pressed(KeyCode::T) {
108+
gizmo_config.on_top = !gizmo_config.on_top;
109+
}
110+
}

0 commit comments

Comments
 (0)