Skip to content

Commit ba1a515

Browse files
committed
cleanup
1 parent b0ff5b7 commit ba1a515

File tree

2 files changed

+39
-30
lines changed

2 files changed

+39
-30
lines changed

crates/bevy_debug_draw/src/debug_draw.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::f32::consts::TAU;
1+
use std::{f32::consts::TAU, mem};
22

33
use bevy_asset::Handle;
44
use bevy_ecs::system::Resource;
@@ -191,10 +191,7 @@ impl DebugDraw {
191191
/// Take the positions and colors data from `self` and overwrite the `mesh`'s vertex positions and colors.
192192
#[inline]
193193
pub fn update_mesh(&mut self, mesh: &mut Mesh) {
194-
mesh.insert_attribute(
195-
Mesh::ATTRIBUTE_POSITION,
196-
std::mem::take(&mut self.positions),
197-
);
198-
mesh.insert_attribute(Mesh::ATTRIBUTE_COLOR, std::mem::take(&mut self.colors));
194+
mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, mem::take(&mut self.positions));
195+
mesh.insert_attribute(Mesh::ATTRIBUTE_COLOR, mem::take(&mut self.colors));
199196
}
200197
}

crates/bevy_debug_draw/src/lib.rs

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use bevy_render::{
1616

1717
#[cfg(feature = "bevy_pbr")]
1818
use bevy_pbr::{NotShadowCaster, NotShadowReceiver};
19+
#[cfg(feature = "bevy_pbr")]
20+
use bevy_render::view::NoFrustumCulling;
1921
#[cfg(feature = "bevy_sprite")]
2022
use bevy_sprite::Mesh2dHandle;
2123

@@ -109,33 +111,43 @@ fn update(
109111
mut meshes: ResMut<Assets<Mesh>>,
110112
mut commands: Commands,
111113
) {
112-
if let Some(mesh) = debug_draw
114+
let mesh = debug_draw
113115
.mesh_handle
114116
.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+
}
123150
}
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();
139151
}
140152
}
141153

0 commit comments

Comments
 (0)