Skip to content

Commit c9a012f

Browse files
committed
improve example
1 parent f7f5f88 commit c9a012f

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

examples/3d/wireframe.rs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,38 @@
33
use bevy::{
44
pbr::wireframe::{Wireframe, WireframeConfig, WireframePlugin},
55
prelude::*,
6-
render::{render_resource::WgpuFeatures, settings::WgpuSettings, RenderPlugin},
6+
render::{
7+
render_resource::WgpuFeatures,
8+
settings::{RenderCreation, WgpuSettings},
9+
RenderPlugin,
10+
},
711
};
812

913
fn main() {
1014
App::new()
1115
.add_plugins((
1216
DefaultPlugins.set(RenderPlugin {
13-
render_creation: WgpuSettings {
17+
render_creation: RenderCreation::Automatic(WgpuSettings {
18+
// WARN this is a native only feature. It will not work with webgl or webgpu
1419
features: WgpuFeatures::POLYGON_MODE_LINE,
1520
..default()
16-
}
17-
.into(),
21+
}),
22+
..default()
1823
}),
24+
// You need to add this plugin to enable wireframe rendering
1925
WireframePlugin,
2026
))
2127
.add_systems(Startup, setup)
28+
.add_systems(Update, toggle_global_wireframe)
2229
.run();
2330
}
2431

2532
/// set up a simple 3D scene
2633
fn setup(
2734
mut commands: Commands,
28-
mut wireframe_config: ResMut<WireframeConfig>,
2935
mut meshes: ResMut<Assets<Mesh>>,
3036
mut materials: ResMut<Assets<StandardMaterial>>,
3137
) {
32-
// To draw the wireframe on all entities, set this to 'true'
33-
wireframe_config.global = false;
34-
// plane
35-
commands.spawn(PbrBundle {
36-
mesh: meshes.add(shape::Plane::from_size(5.0).into()),
37-
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
38-
..default()
39-
});
4038
// cube
4139
commands.spawn((
4240
PbrBundle {
@@ -48,6 +46,14 @@ fn setup(
4846
// This enables wireframe drawing on this entity
4947
Wireframe,
5048
));
49+
50+
// plane
51+
commands.spawn(PbrBundle {
52+
mesh: meshes.add(shape::Plane::from_size(5.0).into()),
53+
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
54+
..default()
55+
});
56+
5157
// light
5258
commands.spawn(PointLightBundle {
5359
transform: Transform::from_xyz(4.0, 8.0, 4.0),
@@ -59,3 +65,13 @@ fn setup(
5965
..default()
6066
});
6167
}
68+
69+
fn toggle_global_wireframe(
70+
mut wireframe_config: ResMut<WireframeConfig>,
71+
keyboard_input: Res<Input<KeyCode>>,
72+
) {
73+
if keyboard_input.just_pressed(KeyCode::T) {
74+
// To draw the wireframe on all entities, set this to 'true'
75+
wireframe_config.global = !wireframe_config.global;
76+
}
77+
}

0 commit comments

Comments
 (0)