Skip to content

Commit 628e369

Browse files
committed
Make debug rendering customizable
1 parent 0b441c0 commit 628e369

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/debug_render/configuration.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ pub struct PhysicsGizmos {
8585
pub shapecast_normal_color: Option<Color>,
8686
/// The color used for the bounds of [`PhysicsIsland`](dynamics::solver::islands::PhysicsIsland)s.
8787
pub island_color: Option<Color>,
88+
/// The color used for [`ColliderTree`](crate::collider_tree) nodes.
89+
pub collider_tree_color: Option<Color>,
8890
/// Determines if the visibility of entities with [colliders](Collider) should be set to `Visibility::Hidden`,
8991
/// which will only show the debug renders.
9092
pub hide_meshes: bool,
@@ -110,6 +112,7 @@ impl Default for PhysicsGizmos {
110112
shapecast_point_color: Some(YELLOW.into()),
111113
shapecast_normal_color: Some(PINK.into()),
112114
island_color: None,
115+
collider_tree_color: None,
113116
hide_meshes: false,
114117
}
115118
}
@@ -154,6 +157,7 @@ impl PhysicsGizmos {
154157
shapecast_point_color: Some(YELLOW.into()),
155158
shapecast_normal_color: Some(PINK.into()),
156159
island_color: Some(RED.into()),
160+
collider_tree_color: Some(Color::WHITE),
157161
hide_meshes: true,
158162
}
159163
}
@@ -180,6 +184,7 @@ impl PhysicsGizmos {
180184
shapecast_point_color: None,
181185
shapecast_normal_color: None,
182186
island_color: None,
187+
collider_tree_color: None,
183188
hide_meshes: false,
184189
}
185190
}

src/debug_render/mod.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use crate::{
2121
};
2222
use bevy::{
2323
camera::visibility::VisibilitySystems,
24-
color::palettes::css::WHITE,
2524
ecs::{
2625
query::Has,
2726
system::{StaticSystemParam, SystemParam, SystemParamItem},
@@ -43,6 +42,7 @@ use bevy::{
4342
/// - [`RayCaster`]
4443
/// - [`ShapeCaster`]
4544
/// - [Simulation islands](dynamics::solver::islands)
45+
/// - [Collider tree](crate::collider_tree) nodes
4646
/// - Changing the visibility of entities to only show debug rendering
4747
///
4848
/// By default, [AABBs](ColliderAabb) and [contacts](ContactPair) are not debug rendered.
@@ -253,13 +253,23 @@ fn debug_render_aabbs(
253253
}
254254
}
255255

256-
fn debug_render_bvh(bvh: Res<ColliderTrees>, mut gizmos: Gizmos<PhysicsGizmos>) {
256+
fn debug_render_bvh(
257+
bvh: Res<ColliderTrees>,
258+
mut gizmos: Gizmos<PhysicsGizmos>,
259+
store: Res<GizmoConfigStore>,
260+
) {
261+
let config = store.config::<PhysicsGizmos>().1;
262+
263+
let Some(collider_tree_color) = config.collider_tree_color else {
264+
return;
265+
};
266+
257267
for node in bvh.dynamic_tree.bvh.nodes.iter() {
258268
if node.prim_count == 0 && node.aabb.valid() {
259269
gizmos.aabb_3d(
260270
Aabb3d::from_min_max(node.aabb.min, node.aabb.max),
261271
Transform::IDENTITY,
262-
WHITE,
272+
collider_tree_color,
263273
);
264274
}
265275
}
@@ -268,7 +278,7 @@ fn debug_render_bvh(bvh: Res<ColliderTrees>, mut gizmos: Gizmos<PhysicsGizmos>)
268278
gizmos.aabb_3d(
269279
Aabb3d::from_min_max(node.aabb.min, node.aabb.max),
270280
Transform::IDENTITY,
271-
WHITE,
281+
collider_tree_color,
272282
);
273283
}
274284
}

0 commit comments

Comments
 (0)