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