@@ -18,36 +18,54 @@ fn main() {
18
18
} ) ,
19
19
WireframePlugin ,
20
20
) )
21
+ . insert_resource ( WireframeToggleTimer ( Timer :: from_seconds (
22
+ 1.0 ,
23
+ TimerMode :: Repeating ,
24
+ ) ) )
21
25
. add_systems ( Startup , setup)
26
+ . add_systems ( Update , toggle_global_wireframe_setting)
22
27
. run ( ) ;
23
28
}
24
29
25
30
/// set up a simple 3D scene
26
31
fn setup (
27
32
mut commands : Commands ,
28
- mut wireframe_config : ResMut < WireframeConfig > ,
29
33
mut meshes : ResMut < Assets < Mesh > > ,
30
34
mut materials : ResMut < Assets < StandardMaterial > > ,
31
35
) {
32
- // To draw the wireframe on all entities, set this to 'true'
33
- wireframe_config. global = false ;
34
36
// plane
35
37
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
+ mesh : meshes. add ( Mesh :: from ( shape:: Plane :: from_size ( 5.0 ) ) ) ,
39
+ material : materials. add ( Color :: rgb ( 0.3 , 0.3 , 0.5 ) . into ( ) ) ,
40
+ ..default ( )
41
+ } ) ;
42
+
43
+ // Red cube: Never renders a wireframe
44
+ commands
45
+ . spawn ( PbrBundle {
46
+ mesh : meshes. add ( Mesh :: from ( shape:: Cube { size : 1.0 } ) ) ,
47
+ material : materials. add ( Color :: rgb ( 0.8 , 0.1 , 0.1 ) . into ( ) ) ,
48
+ transform : Transform :: from_xyz ( -1.0 , 0.5 , -1.0 ) ,
49
+ ..default ( )
50
+ } )
51
+ . insert ( Wireframe :: NeverRender ) ;
52
+ // Orange cube: Follows global wireframe setting
53
+ commands. spawn ( PbrBundle {
54
+ mesh : meshes. add ( Mesh :: from ( shape:: Cube { size : 1.0 } ) ) ,
55
+ material : materials. add ( Color :: rgb ( 0.8 , 0.8 , 0.1 ) . into ( ) ) ,
56
+ transform : Transform :: from_xyz ( 0.0 , 0.5 , 0.0 ) ,
38
57
..default ( )
39
58
} ) ;
40
- // cube
41
- commands. spawn ( (
42
- PbrBundle {
59
+ // Green cube: Always renders a wireframe
60
+ commands
61
+ . spawn ( PbrBundle {
43
62
mesh : meshes. add ( Mesh :: from ( shape:: Cube { size : 1.0 } ) ) ,
44
- material : materials. add ( Color :: rgb ( 0.8 , 0.7 , 0.6 ) . into ( ) ) ,
45
- transform : Transform :: from_xyz ( 0 .0, 0.5 , 0 .0) ,
63
+ material : materials. add ( Color :: rgb ( 0.1 , 0.8 , 0.1 ) . into ( ) ) ,
64
+ transform : Transform :: from_xyz ( 1 .0, 0.5 , 1 .0) ,
46
65
..default ( )
47
- } ,
48
- // This enables wireframe drawing on this entity
49
- Wireframe ,
50
- ) ) ;
66
+ } )
67
+ . insert ( Wireframe :: AlwaysRender ) ;
68
+
51
69
// light
52
70
commands. spawn ( PointLightBundle {
53
71
transform : Transform :: from_xyz ( 4.0 , 8.0 , 4.0 ) ,
@@ -59,3 +77,22 @@ fn setup(
59
77
..default ( )
60
78
} ) ;
61
79
}
80
+
81
+ /// This timer is used to periodically toggle the wireframe rendering.
82
+ #[ derive( Resource ) ]
83
+ struct WireframeToggleTimer ( Timer ) ;
84
+
85
+ /// Periodically turns the global wireframe setting on and off, to show the differences between
86
+ /// [`Wireframe::AlwaysRender`], [`Wireframe::NeverRender`], and no override.
87
+ fn toggle_global_wireframe_setting (
88
+ time : Res < Time > ,
89
+ mut timer : ResMut < WireframeToggleTimer > ,
90
+ mut wireframe_config : ResMut < WireframeConfig > ,
91
+ ) {
92
+ if timer. 0 . tick ( time. delta ( ) ) . just_finished ( ) {
93
+ // The global wireframe config enables drawing of wireframes on every mesh, except those with
94
+ // `WireframeOverride::NeverRender`. Meshes with `WireframeOverride::AlwaysRender` will
95
+ // always have a wireframe, regardless of the global configuration.
96
+ wireframe_config. global = !wireframe_config. global ;
97
+ }
98
+ }
0 commit comments