From bc2ae4b512b8bc7a2b61dd24d9685289453681c5 Mon Sep 17 00:00:00 2001 From: Sébastien Crozet Date: Fri, 22 Apr 2022 15:45:53 +0200 Subject: Add a basic lines-based debug-renderer --- src_testbed/debug_render.rs | 81 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src_testbed/debug_render.rs (limited to 'src_testbed/debug_render.rs') diff --git a/src_testbed/debug_render.rs b/src_testbed/debug_render.rs new file mode 100644 index 0000000..135529f --- /dev/null +++ b/src_testbed/debug_render.rs @@ -0,0 +1,81 @@ +use crate::harness::Harness; +use bevy::prelude::*; +use bevy_prototype_debug_lines::DebugLines; +use rapier::math::{Point, Real, DIM}; +use rapier::pipeline::{ + DebugRenderBackend, DebugRenderMode, DebugRenderObject, DebugRenderPipeline, +}; +use std::fmt::Debug; + +pub struct RapierDebugRenderPlugin { + depth_test: bool, +} + +impl Default for RapierDebugRenderPlugin { + fn default() -> Self { + Self { + depth_test: cfg!(feature = "dim3"), + } + } +} + +impl RapierDebugRenderPlugin { + pub fn with_depth_test(enabled: bool) -> Self { + Self { + depth_test: enabled, + } + } +} + +impl Plugin for RapierDebugRenderPlugin { + fn build(&self, app: &mut App) { + app.add_plugin( + bevy_prototype_debug_lines::DebugLinesPlugin::with_depth_test(self.depth_test), + ) + .insert_resource(DebugRenderPipeline::new( + Default::default(), + !DebugRenderMode::RIGID_BODY_AXES, + )) + .add_system_to_stage(CoreStage::Update, debug_render_scene); + } +} + +struct BevyLinesRenderBackend<'a> { + lines: &'a mut DebugLines, +} + +impl<'a> DebugRenderBackend for BevyLinesRenderBackend<'a> { + #[cfg(feature = "dim2")] + fn draw_line(&mut self, _: DebugRenderObject, a: Point, b: Point, color: [f32; 4]) { + self.lines.line_colored( + [a.x, a.y, 1.0e-8].into(), + [b.x, b.y, 1.0e-8].into(), + 0.0, + Color::hsla(color[0], color[1], color[2], color[3]), + ) + } + #[cfg(feature = "dim3")] + fn draw_line(&mut self, _: DebugRenderObject, a: Point, b: Point, color: [f32; 4]) { + self.lines.line_colored( + [a.x, a.y, a.z].into(), + [b.x, b.y, b.z].into(), + 0.0, + Color::hsla(color[0], color[1], color[2], color[3]), + ) + } +} + +fn debug_render_scene( + mut pipeline: ResMut, + harness: NonSend, + mut lines: ResMut, +) { + let mut backend = BevyLinesRenderBackend { lines: &mut *lines }; + pipeline.render( + &mut backend, + &harness.physics.bodies, + &harness.physics.colliders, + &harness.physics.impulse_joints, + &harness.physics.multibody_joints, + ); +} -- cgit From 5063fa420392455f7926f1ba3e65612f79a0b066 Mon Sep 17 00:00:00 2001 From: Sébastien Crozet Date: Thu, 28 Apr 2022 13:19:58 +0200 Subject: Testbed: switch to bevy 0.7 --- src_testbed/debug_render.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src_testbed/debug_render.rs') diff --git a/src_testbed/debug_render.rs b/src_testbed/debug_render.rs index 135529f..ff884e2 100644 --- a/src_testbed/debug_render.rs +++ b/src_testbed/debug_render.rs @@ -1,6 +1,6 @@ use crate::harness::Harness; +use crate::lines::DebugLines; use bevy::prelude::*; -use bevy_prototype_debug_lines::DebugLines; use rapier::math::{Point, Real, DIM}; use rapier::pipeline::{ DebugRenderBackend, DebugRenderMode, DebugRenderObject, DebugRenderPipeline, @@ -29,9 +29,9 @@ impl RapierDebugRenderPlugin { impl Plugin for RapierDebugRenderPlugin { fn build(&self, app: &mut App) { - app.add_plugin( - bevy_prototype_debug_lines::DebugLinesPlugin::with_depth_test(self.depth_test), - ) + app.add_plugin(crate::lines::DebugLinesPlugin::with_depth_test( + self.depth_test, + )) .insert_resource(DebugRenderPipeline::new( Default::default(), !DebugRenderMode::RIGID_BODY_AXES, -- cgit From 65824e74f3a949343059b3bf5ab51bc7920f416d Mon Sep 17 00:00:00 2001 From: Sébastien Crozet Date: Thu, 28 Apr 2022 17:30:35 +0200 Subject: Add comments for the debug-renderer --- src_testbed/debug_render.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'src_testbed/debug_render.rs') diff --git a/src_testbed/debug_render.rs b/src_testbed/debug_render.rs index ff884e2..6e41496 100644 --- a/src_testbed/debug_render.rs +++ b/src_testbed/debug_render.rs @@ -1,11 +1,10 @@ use crate::harness::Harness; use crate::lines::DebugLines; use bevy::prelude::*; -use rapier::math::{Point, Real, DIM}; +use rapier::math::{Point, Real}; use rapier::pipeline::{ DebugRenderBackend, DebugRenderMode, DebugRenderObject, DebugRenderPipeline, }; -use std::fmt::Debug; pub struct RapierDebugRenderPlugin { depth_test: bool, @@ -19,14 +18,6 @@ impl Default for RapierDebugRenderPlugin { } } -impl RapierDebugRenderPlugin { - pub fn with_depth_test(enabled: bool) -> Self { - Self { - depth_test: enabled, - } - } -} - impl Plugin for RapierDebugRenderPlugin { fn build(&self, app: &mut App) { app.add_plugin(crate::lines::DebugLinesPlugin::with_depth_test( -- cgit From 7dc038aec66783d72abda446d6251385e6ad30f4 Mon Sep 17 00:00:00 2001 From: Sébastien Crozet Date: Thu, 28 Apr 2022 17:51:17 +0200 Subject: Fix test build --- src_testbed/debug_render.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src_testbed/debug_render.rs') diff --git a/src_testbed/debug_render.rs b/src_testbed/debug_render.rs index 6e41496..913663e 100644 --- a/src_testbed/debug_render.rs +++ b/src_testbed/debug_render.rs @@ -39,8 +39,8 @@ impl<'a> DebugRenderBackend for BevyLinesRenderBackend<'a> { #[cfg(feature = "dim2")] fn draw_line(&mut self, _: DebugRenderObject, a: Point, b: Point, color: [f32; 4]) { self.lines.line_colored( - [a.x, a.y, 1.0e-8].into(), - [b.x, b.y, 1.0e-8].into(), + [a.x as f32, a.y as f32, 1.0e-8 as f32].into(), + [b.x as f32, b.y as f32, 1.0e-8 as f32].into(), 0.0, Color::hsla(color[0], color[1], color[2], color[3]), ) @@ -48,8 +48,8 @@ impl<'a> DebugRenderBackend for BevyLinesRenderBackend<'a> { #[cfg(feature = "dim3")] fn draw_line(&mut self, _: DebugRenderObject, a: Point, b: Point, color: [f32; 4]) { self.lines.line_colored( - [a.x, a.y, a.z].into(), - [b.x, b.y, b.z].into(), + [a.x as f32, a.y as f32, a.z as f32].into(), + [b.x as f32, b.y as f32, b.z as f32].into(), 0.0, Color::hsla(color[0], color[1], color[2], color[3]), ) -- cgit