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

@ -6,6 +6,62 @@ use raidillon_assets::ModelManagerRef;
use raidillon_core::EguiQueue;
use crate::settings::Settings;
/// a single debug wireframe vertex with position and color
#[derive(Clone, Copy)]
pub struct DebugWireframeVertex {
pub position: [f32; 3],
pub color: [f32; 4],
}
/// shared buffer for debug wireframe rendering
#[derive(Clone, Default)]
pub struct DebugWireframes {
pub vertices: Vec<DebugWireframeVertex>,
pub enabled: bool,
}
impl DebugWireframes {
pub fn new() -> Self {
Self { vertices: Vec::new(), enabled: true }
}
pub fn clear(&mut self) {
self.vertices.clear();
}
/// add a single line segment
pub fn add_line(&mut self, start: [f32; 3], end: [f32; 3], color: [f32; 4]) {
self.vertices.push(DebugWireframeVertex { position: start, color });
self.vertices.push(DebugWireframeVertex { position: end, color });
}
/// add a wireframe box from min/max corners
pub fn add_box(&mut self, min: [f32; 3], max: [f32; 3], color: [f32; 4]) {
let [x0, y0, z0] = min;
let [x1, y1, z1] = max;
// bottom face edges
self.add_line([x0, y0, z0], [x1, y0, z0], color);
self.add_line([x1, y0, z0], [x1, y0, z1], color);
self.add_line([x1, y0, z1], [x0, y0, z1], color);
self.add_line([x0, y0, z1], [x0, y0, z0], color);
// top face edges
self.add_line([x0, y1, z0], [x1, y1, z0], color);
self.add_line([x1, y1, z0], [x1, y1, z1], color);
self.add_line([x1, y1, z1], [x0, y1, z1], color);
self.add_line([x0, y1, z1], [x0, y1, z0], color);
// vertical edges
self.add_line([x0, y0, z0], [x0, y1, z0], color);
self.add_line([x1, y0, z0], [x1, y1, z0], color);
self.add_line([x1, y0, z1], [x1, y1, z1], color);
self.add_line([x0, y0, z1], [x0, y1, z1], color);
}
}
pub type DebugWireframesRef = Rc<RefCell<DebugWireframes>>;
#[derive(Clone)]
pub struct PlatformContext {
pub current_event: Event<()>,
@ -16,8 +72,9 @@ pub struct PlatformContext {
pub window: Arc<Mutex<winit::window::Window>>,
pub egui_queue: Rc<RefCell<EguiQueue>>,
pub settings: Arc<RwLock<Settings>>,
/// Sets whether or not egui will receive input events.
/// Added to prevent the mouse state conflict between the engine and egui.
/// shared debug wireframe buffer
pub debug_wireframes: DebugWireframesRef,
/// sets whether or not egui will receive input events
pub should_egui_receive_input_events: Rc<Cell<bool>>,
}

View file

@ -6,4 +6,4 @@ pub mod settings;
pub use platform::Platform;
pub use camera::Camera;
pub use context::{PlatformContext, TimeContext};
pub use context::{PlatformContext, TimeContext, DebugWireframes, DebugWireframesRef, DebugWireframeVertex};