@@ -16,6 +16,8 @@ use bevy_render::{
16
16
17
17
#[ cfg( feature = "bevy_pbr" ) ]
18
18
use bevy_pbr:: { NotShadowCaster , NotShadowReceiver } ;
19
+ #[ cfg( feature = "bevy_pbr" ) ]
20
+ use bevy_render:: view:: NoFrustumCulling ;
19
21
#[ cfg( feature = "bevy_sprite" ) ]
20
22
use bevy_sprite:: Mesh2dHandle ;
21
23
@@ -109,33 +111,43 @@ fn update(
109
111
mut meshes : ResMut < Assets < Mesh > > ,
110
112
mut commands : Commands ,
111
113
) {
112
- if let Some ( mesh) = debug_draw
114
+ let mesh = debug_draw
113
115
. mesh_handle
114
116
. as_ref ( )
115
- . and_then ( |handle| meshes. get_mut ( handle) )
116
- {
117
- if config. enabled {
118
- debug_draw. update_mesh ( mesh) ;
119
- } else {
120
- debug_draw. clear ( ) ;
121
- mesh. remove_attribute ( Mesh :: ATTRIBUTE_POSITION ) ;
122
- mesh. remove_attribute ( Mesh :: ATTRIBUTE_COLOR ) ;
117
+ . and_then ( |handle| meshes. get_mut ( handle) ) ;
118
+ match mesh {
119
+ Some ( mesh) => {
120
+ if config. enabled {
121
+ debug_draw. update_mesh ( mesh) ;
122
+ } else {
123
+ debug_draw. clear ( ) ;
124
+ mesh. remove_attribute ( Mesh :: ATTRIBUTE_POSITION ) ;
125
+ mesh. remove_attribute ( Mesh :: ATTRIBUTE_COLOR ) ;
126
+ }
127
+ }
128
+ None => {
129
+ if config. enabled {
130
+ let mut mesh = Mesh :: new ( PrimitiveTopology :: LineList ) ;
131
+ debug_draw. update_mesh ( & mut mesh) ;
132
+ let mesh_handle = meshes. add ( mesh) ;
133
+ commands. spawn ( (
134
+ SpatialBundle :: VISIBLE_IDENTITY ,
135
+ DebugDrawMesh ,
136
+ #[ cfg ( feature = "bevy_pbr" ) ]
137
+ (
138
+ mesh_handle. clone_weak ( ) ,
139
+ NotShadowCaster ,
140
+ NotShadowReceiver ,
141
+ NoFrustumCulling ,
142
+ ) ,
143
+ #[ cfg ( feature = "bevy_sprite" ) ]
144
+ Mesh2dHandle ( mesh_handle. clone_weak ( ) ) ,
145
+ ) ) ;
146
+ debug_draw. mesh_handle = Some ( mesh_handle) ;
147
+ } else {
148
+ debug_draw. clear ( ) ;
149
+ }
123
150
}
124
- } else if config. enabled {
125
- let mut mesh = Mesh :: new ( PrimitiveTopology :: LineList ) ;
126
- debug_draw. update_mesh ( & mut mesh) ;
127
- let mesh_handle = meshes. add ( mesh) ;
128
- commands. spawn ( (
129
- SpatialBundle :: VISIBLE_IDENTITY ,
130
- DebugDrawMesh ,
131
- #[ cfg ( feature = "bevy_pbr" ) ]
132
- ( mesh_handle. clone_weak ( ) , NotShadowCaster , NotShadowReceiver ) ,
133
- #[ cfg ( feature = "bevy_sprite" ) ]
134
- Mesh2dHandle ( mesh_handle. clone_weak ( ) ) ,
135
- ) ) ;
136
- debug_draw. mesh_handle = Some ( mesh_handle) ;
137
- } else {
138
- debug_draw. clear ( ) ;
139
151
}
140
152
}
141
153
0 commit comments