diff options
| author | Sébastien Crozet <developer@crozet.re> | 2022-05-31 10:22:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-31 10:22:28 +0200 |
| commit | fb1bfc762c89cd8c5bd745a82998c1662a1bf196 (patch) | |
| tree | 0ece4f99d458f47f1408c78f79b85345036d3671 /src/pipeline/debug_render_pipeline | |
| parent | c630635e57624385123b4a0fb658018bc6fdba91 (diff) | |
| parent | 0640f5e660aef579a9e6b134b7066e9bcae32b8b (diff) | |
| download | rapier-fb1bfc762c89cd8c5bd745a82998c1662a1bf196.tar.gz rapier-fb1bfc762c89cd8c5bd745a82998c1662a1bf196.tar.bz2 rapier-fb1bfc762c89cd8c5bd745a82998c1662a1bf196.zip | |
Merge pull request #334 from dimforge/fixes
Some CCD and debug-render improvements
Diffstat (limited to 'src/pipeline/debug_render_pipeline')
| -rw-r--r-- | src/pipeline/debug_render_pipeline/debug_render_pipeline.rs | 74 | ||||
| -rw-r--r-- | src/pipeline/debug_render_pipeline/debug_render_style.rs | 12 |
2 files changed, 85 insertions, 1 deletions
diff --git a/src/pipeline/debug_render_pipeline/debug_render_pipeline.rs b/src/pipeline/debug_render_pipeline/debug_render_pipeline.rs index 14da40d..bcd19e8 100644 --- a/src/pipeline/debug_render_pipeline/debug_render_pipeline.rs +++ b/src/pipeline/debug_render_pipeline/debug_render_pipeline.rs @@ -2,7 +2,7 @@ use super::{outlines, DebugRenderBackend}; use crate::dynamics::{ GenericJoint, ImpulseJointSet, MultibodyJointSet, RigidBodySet, RigidBodyType, }; -use crate::geometry::{Ball, ColliderSet, Cuboid, Shape, TypedShape}; +use crate::geometry::{Ball, ColliderSet, Cuboid, NarrowPhase, Shape, TypedShape}; #[cfg(feature = "dim3")] use crate::geometry::{Cone, Cylinder}; use crate::math::{Isometry, Point, Real, Vector, DIM}; @@ -24,6 +24,12 @@ bitflags::bitflags! { const MULTIBODY_JOINTS = 1 << 2; /// If this flag is set, the impulse joints will be rendered. const IMPULSE_JOINTS = 1 << 3; + /// If this flag is set, the solver contacts will be rendered. + const SOLVER_CONTACTS = 1 << 4; + /// If this flag is set, the geometric contacts will be rendered. + const CONTACTS = 1 << 5; + /// If this flag is set, the AABBs of colliders will be rendered. + const COLLIDER_AABBS = 1 << 6; } } @@ -71,10 +77,62 @@ impl DebugRenderPipeline { colliders: &ColliderSet, impulse_joints: &ImpulseJointSet, multibody_joints: &MultibodyJointSet, + narrow_phase: &NarrowPhase, ) { self.render_rigid_bodies(backend, bodies); self.render_colliders(backend, bodies, colliders); self.render_joints(backend, bodies, impulse_joints, multibody_joints); + self.render_contacts(backend, colliders, narrow_phase); + } + + /// Render contact. + pub fn render_contacts( + &mut self, + backend: &mut impl DebugRenderBackend, + colliders: &ColliderSet, + narrow_phase: &NarrowPhase, + ) { + if self.mode.contains(DebugRenderMode::CONTACTS) { + for pair in narrow_phase.contact_pairs() { + if let (Some(co1), Some(co2)) = + (colliders.get(pair.collider1), colliders.get(pair.collider2)) + { + for manifold in &pair.manifolds { + for contact in manifold.contacts() { + backend.draw_line( + DebugRenderObject::Other, + co1.position() * contact.local_p1, + co2.position() * contact.local_p2, + self.style.contact_depth_color, + ); + backend.draw_line( + DebugRenderObject::Other, + co1.position() * contact.local_p1, + co1.position() + * (contact.local_p1 + + manifold.local_n1 * self.style.contact_normal_length), + self.style.contact_normal_color, + ); + } + } + } + } + } + + if self.mode.contains(DebugRenderMode::SOLVER_CONTACTS) { + for pair in narrow_phase.contact_pairs() { + for manifold in &pair.manifolds { + for contact in &manifold.data.solver_contacts { + backend.draw_line( + DebugRenderObject::Other, + contact.point, + contact.point + manifold.data.normal * self.style.contact_normal_length, + self.style.contact_normal_color, + ); + } + } + } + } } /// Render only the joints from the scene. @@ -224,6 +282,20 @@ impl DebugRenderPipeline { self.render_shape(object, backend, co.shape(), co.position(), color) } } + + if self.mode.contains(DebugRenderMode::COLLIDER_AABBS) { + for (_, co) in colliders.iter() { + let aabb = co.compute_aabb(); + let cuboid = Cuboid::new(aabb.half_extents()); + self.render_shape( + DebugRenderObject::Other, + backend, + &cuboid, + &aabb.center().into(), + self.style.collider_aabb_color, + ); + } + } } #[cfg(feature = "dim2")] diff --git a/src/pipeline/debug_render_pipeline/debug_render_style.rs b/src/pipeline/debug_render_pipeline/debug_render_style.rs index ac2b3a3..987d95d 100644 --- a/src/pipeline/debug_render_pipeline/debug_render_style.rs +++ b/src/pipeline/debug_render_pipeline/debug_render_style.rs @@ -38,6 +38,14 @@ pub struct DebugRenderStyle { pub sleep_color_multiplier: [f32; 4], /// The length of the local coordinate axes rendered for a rigid-body. pub rigid_body_axes_length: Real, + /// The collor for the segments joining the two contact points. + pub contact_depth_color: DebugColor, + /// The color of the contact normals. + pub contact_normal_color: DebugColor, + /// The length of the contact normals. + pub contact_normal_length: Real, + /// The color of the colliders AABBs. + pub collider_aabb_color: DebugColor, } impl Default for DebugRenderStyle { @@ -55,6 +63,10 @@ impl Default for DebugRenderStyle { multibody_joint_separation_color: [0.0, 1.0, 0.4, 1.0], sleep_color_multiplier: [1.0, 1.0, 0.2, 1.0], rigid_body_axes_length: 0.5, + contact_depth_color: [120.0, 1.0, 0.4, 1.0], + contact_normal_color: [0.0, 1.0, 1.0, 1.0], + contact_normal_length: 0.3, + collider_aabb_color: [124.0, 1.0, 0.4, 1.0], } } } |
