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