Add debug wireframe rendering support

This commit is contained in:
reo 2025-12-15 15:53:54 +03:00
parent 8041c7e01d
commit 73692b710e
12 changed files with 221 additions and 7 deletions

View file

@ -8,7 +8,8 @@ use winit::event::{Event, WindowEvent};
use systems::debug_camera::FPSDebugCameraSystem;
use crate::systems::common::should_draw_menu;
use crate::systems::{
DisplaySettings, KeybindsSystem, KinematicCharacterController, MenuSystem, PhysicsSystem
DisplaySettings, KeybindsSystem, KinematicCharacterController, MenuSystem, PhysicsSystem,
PhysicsDebugSystem,
};
const TEST_GLTF: &str = "sphere.glb";
@ -125,6 +126,7 @@ impl System for MainSystem {
fn main() {
raidillon_app::App::new()
.add_system::<PhysicsSystem>()
.add_system::<PhysicsDebugSystem>()
.add_system::<KeybindsSystem>()
.add_system::<KinematicCharacterController>()
.add_system::<FPSDebugCameraSystem>()

View file

@ -1,4 +1,5 @@
mod physics;
mod physics_debug;
mod kinematic_character_controller;
mod keybinds;
mod menu;
@ -7,6 +8,7 @@ pub mod common;
mod display_settings;
pub use physics::PhysicsSystem;
pub use physics_debug::PhysicsDebugSystem;
pub use kinematic_character_controller::KinematicCharacterController;
pub use keybinds::KeybindsSystem;
pub use menu::MenuSystem;

View file

@ -0,0 +1,35 @@
use raidillon_app::prelude::*;
/// renders aabb wireframes for all physics colliders
#[derive(Default)]
pub struct PhysicsDebugSystem;
impl System for PhysicsDebugSystem {
fn frame_update(&mut self, res: &mut EngineResources, scene: &mut Scene) {
let pctx = res.get::<PlatformContext>().expect("PlatformContext missing").clone();
let mut debug_wireframes = pctx.debug_wireframes.borrow_mut();
if !debug_wireframes.enabled {
return;
}
let physics = match scene.resources.get::<Physics>() {
Some(p) => p,
None => return,
};
let color = [1.0, 0.0, 0.0, 1.0];
for (_, collider) in physics.collider_set.iter() {
let aabb = collider.compute_aabb();
let min = aabb.mins;
let max = aabb.maxs;
debug_wireframes.add_box(
[min.x, min.y, min.z],
[max.x, max.y, max.z],
color,
);
}
}
}