@@ -15,39 +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_startup_system ( setup)
23
+ . add_system ( 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
- // This enables drawing of wireframes on every mesh, except those with
30
- // `WireframeOverride::NeverRender`.
31
- // To instead enable it on individual meshes, make this `false`, and add a
32
- // `WireframeOverride::AlwaysRender` component for the meshes that should have wireframes.
33
- wireframe_config. global = true ;
34
33
// plane
35
- commands. spawn ( (
36
- PbrBundle {
37
- mesh : meshes. add ( Mesh :: from ( shape:: Plane { size : 5.0 } ) ) ,
38
- material : materials. add ( Color :: rgb ( 0.3 , 0.5 , 0.3 ) . into ( ) ) ,
34
+ commands. spawn ( PbrBundle {
35
+ mesh : meshes. add ( Mesh :: from ( shape:: Plane { 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 ) ,
39
46
..default ( )
40
- } ,
41
- // This disables wireframe rendering for this entity.
42
- WireframeOverride :: NeverRender ,
43
- ) ) ;
44
- // cube
47
+ } )
48
+ . insert ( WireframeOverride :: NeverRender ) ;
49
+ // Orange cube: Follows global wireframe setting
45
50
commands. spawn ( PbrBundle {
46
51
mesh : meshes. add ( Mesh :: from ( shape:: Cube { size : 1.0 } ) ) ,
47
- material : materials. add ( Color :: rgb ( 0.8 , 0.7 , 0.6 ) . into ( ) ) ,
52
+ material : materials. add ( Color :: rgb ( 0.8 , 0.8 , 0.1 ) . into ( ) ) ,
48
53
transform : Transform :: from_xyz ( 0.0 , 0.5 , 0.0 ) ,
49
54
..default ( )
50
55
} ) ;
56
+ // Green cube: Always renders a wireframe
57
+ commands
58
+ . spawn ( PbrBundle {
59
+ mesh : meshes. add ( Mesh :: from ( shape:: Cube { size : 1.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 ) ,
62
+ ..default ( )
63
+ } )
64
+ . insert ( WireframeOverride :: AlwaysRender ) ;
65
+
51
66
// light
52
67
commands. spawn ( PointLightBundle {
53
68
transform : Transform :: from_xyz ( 4.0 , 8.0 , 4.0 ) ,
@@ -59,3 +74,22 @@ fn setup(
59
74
..default ( )
60
75
} ) ;
61
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
+ /// [`WireframeOverride::AlwaysRender`], [`WireframeOverride::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