diff --git a/src_testbed/debug_render.rs b/src_testbed/debug_render.rs index 8b79edc4c..463386539 100644 --- a/src_testbed/debug_render.rs +++ b/src_testbed/debug_render.rs @@ -7,17 +7,23 @@ use rapier::pipeline::{ }; #[derive(Resource)] -pub struct DebugRenderPipelineResource(pub DebugRenderPipeline); +pub struct DebugRenderPipelineResource { + pub pipeline: DebugRenderPipeline, + pub enabled: bool, +} #[derive(Default)] pub struct RapierDebugRenderPlugin {} impl Plugin for RapierDebugRenderPlugin { fn build(&self, app: &mut App) { - app.insert_resource(DebugRenderPipelineResource(DebugRenderPipeline::new( - Default::default(), - !DebugRenderMode::RIGID_BODY_AXES & !DebugRenderMode::COLLIDER_AABBS, - ))) + app.insert_resource(DebugRenderPipelineResource { + pipeline: DebugRenderPipeline::new( + Default::default(), + !DebugRenderMode::RIGID_BODY_AXES & !DebugRenderMode::COLLIDER_AABBS, + ), + enabled: false, + }) .add_systems(Update, debug_render_scene); } } @@ -46,17 +52,19 @@ impl<'a> DebugRenderBackend for BevyLinesRenderBackend<'a> { } fn debug_render_scene( - mut pipeline: ResMut, + mut debug_render: ResMut, harness: NonSend, gizmos: Gizmos, ) { - let mut backend = BevyLinesRenderBackend { gizmos }; - pipeline.0.render( - &mut backend, - &harness.physics.bodies, - &harness.physics.colliders, - &harness.physics.impulse_joints, - &harness.physics.multibody_joints, - &harness.physics.narrow_phase, - ); + if debug_render.enabled { + let mut backend = BevyLinesRenderBackend { gizmos }; + debug_render.pipeline.render( + &mut backend, + &harness.physics.bodies, + &harness.physics.colliders, + &harness.physics.impulse_joints, + &harness.physics.multibody_joints, + &harness.physics.narrow_phase, + ); + } } diff --git a/src_testbed/testbed.rs b/src_testbed/testbed.rs index a3c9e6fa7..9b08e90b1 100644 --- a/src_testbed/testbed.rs +++ b/src_testbed/testbed.rs @@ -3,6 +3,7 @@ use std::mem; use bevy::prelude::*; +use crate::debug_render::{DebugRenderPipelineResource, RapierDebugRenderPlugin}; use crate::physics::{PhysicsEvents, PhysicsSnapshot, PhysicsState}; use crate::plugin::TestbedPlugin; use crate::ui; @@ -391,7 +392,7 @@ impl TestbedApp { .add_plugins(DefaultPlugins.set(window_plugin)) .add_plugins(OrbitCameraPlugin) .add_plugins(WireframePlugin) - // .add_plugins(debug_render::RapierDebugRenderPlugin::default()) + .add_plugins(RapierDebugRenderPlugin::default()) .add_plugins(bevy_egui::EguiPlugin); #[cfg(target_arch = "wasm32")] @@ -1083,6 +1084,7 @@ fn update_testbed( builders: ResMut, mut graphics: NonSendMut, mut state: ResMut, + mut debug_render: ResMut, mut harness: NonSendMut, #[cfg(feature = "other-backends")] mut other_backends: NonSendMut, mut plugins: NonSendMut, @@ -1127,7 +1129,7 @@ fn update_testbed( // Update UI { let harness = &mut *harness; - ui::update_ui(&mut ui_context, &mut state, harness); + ui::update_ui(&mut ui_context, &mut state, harness, &mut debug_render); for plugin in &mut plugins.0 { plugin.update_ui( diff --git a/src_testbed/ui.rs b/src_testbed/ui.rs index 3983934ba..fee4abcb9 100644 --- a/src_testbed/ui.rs +++ b/src_testbed/ui.rs @@ -1,6 +1,7 @@ use rapier::counters::Counters; use rapier::math::Real; +use crate::debug_render::DebugRenderPipelineResource; use crate::harness::Harness; use crate::testbed::{ RunMode, TestbedActionFlags, TestbedState, TestbedStateFlags, PHYSX_BACKEND_PATCH_FRICTION, @@ -11,7 +12,12 @@ use crate::PhysicsState; use bevy_egui::egui::Slider; use bevy_egui::{egui, EguiContexts}; -pub fn update_ui(ui_context: &mut EguiContexts, state: &mut TestbedState, harness: &mut Harness) { +pub fn update_ui( + ui_context: &mut EguiContexts, + state: &mut TestbedState, + harness: &mut Harness, + debug_render: &mut DebugRenderPipelineResource, +) { egui::Window::new("Parameters").show(ui_context.ctx_mut(), |ui| { if state.backend_names.len() > 1 && !state.example_names.is_empty() { let mut changed = false; @@ -157,6 +163,7 @@ pub fn update_ui(ui_context: &mut EguiContexts, state: &mut TestbedState, harnes ui.checkbox(&mut sleep, "sleep enabled"); // ui.checkbox(&mut contact_points, "draw contacts"); // ui.checkbox(&mut wireframe, "draw wireframes"); + ui.checkbox(&mut debug_render.enabled, "debug render enabled"); state.flags.set(TestbedStateFlags::SLEEP, sleep); // state