3
3
use bevy:: {
4
4
pbr:: wireframe:: { Wireframe , WireframeConfig , WireframePlugin } ,
5
5
prelude:: * ,
6
- render:: { render_resource:: WgpuFeatures , settings:: WgpuSettings , RenderPlugin } ,
6
+ render:: {
7
+ render_resource:: WgpuFeatures ,
8
+ settings:: { RenderCreation , WgpuSettings } ,
9
+ RenderPlugin ,
10
+ } ,
7
11
} ;
8
12
9
13
fn main ( ) {
10
14
App :: new ( )
11
15
. add_plugins ( (
12
16
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
14
19
features : WgpuFeatures :: POLYGON_MODE_LINE ,
15
20
..default ( )
16
- }
17
- . into ( ) ,
21
+ } ) ,
22
+ .. default ( )
18
23
} ) ,
24
+ // You need to add this plugin to enable wireframe rendering
19
25
WireframePlugin ,
20
26
) )
21
27
. add_systems ( Startup , setup)
28
+ . add_systems ( Update , toggle_global_wireframe)
22
29
. run ( ) ;
23
30
}
24
31
25
32
/// set up a simple 3D scene
26
33
fn setup (
27
34
mut commands : Commands ,
28
- mut wireframe_config : ResMut < WireframeConfig > ,
29
35
mut meshes : ResMut < Assets < Mesh > > ,
30
36
mut materials : ResMut < Assets < StandardMaterial > > ,
31
37
) {
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
- } ) ;
40
38
// cube
41
39
commands. spawn ( (
42
40
PbrBundle {
@@ -48,6 +46,14 @@ fn setup(
48
46
// This enables wireframe drawing on this entity
49
47
Wireframe ,
50
48
) ) ;
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
+
51
57
// light
52
58
commands. spawn ( PointLightBundle {
53
59
transform : Transform :: from_xyz ( 4.0 , 8.0 , 4.0 ) ,
@@ -59,3 +65,13 @@ fn setup(
59
65
..default ( )
60
66
} ) ;
61
67
}
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