aboutsummaryrefslogtreecommitdiff
path: root/src/geometry/user_callbacks.rs
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2020-10-27 17:36:45 +0100
committerGitHub <noreply@github.com>2020-10-27 17:36:45 +0100
commite279c7050cd55426cb28c8c9fb2ac9d4f0205d7c (patch)
tree446cbf59cf32a82a67ed889f0041ab886c5ace7e /src/geometry/user_callbacks.rs
parenta52fb8d7e4649dce02e2131d848b84166df82d64 (diff)
parent74f0297221607e1929db75e79089d7cb75558dfe (diff)
downloadrapier-e279c7050cd55426cb28c8c9fb2ac9d4f0205d7c.tar.gz
rapier-e279c7050cd55426cb28c8c9fb2ac9d4f0205d7c.tar.bz2
rapier-e279c7050cd55426cb28c8c9fb2ac9d4f0205d7c.zip
Merge pull request #44 from dimforge/custom_callbacks_filtering
Added user-implementable traits for collision/proximity pair filtering.
Diffstat (limited to 'src/geometry/user_callbacks.rs')
-rw-r--r--src/geometry/user_callbacks.rs57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/geometry/user_callbacks.rs b/src/geometry/user_callbacks.rs
new file mode 100644
index 0000000..ae0119f
--- /dev/null
+++ b/src/geometry/user_callbacks.rs
@@ -0,0 +1,57 @@
+use crate::dynamics::RigidBody;
+use crate::geometry::{Collider, SolverFlags};
+
+/// Context given to custom collision filters to filter-out collisions.
+pub struct PairFilterContext<'a> {
+ /// The first collider involved in the potential collision.
+ pub rigid_body1: &'a RigidBody,
+ /// The first collider involved in the potential collision.
+ pub rigid_body2: &'a RigidBody,
+ /// The first collider involved in the potential collision.
+ pub collider1: &'a Collider,
+ /// The first collider involved in the potential collision.
+ pub collider2: &'a Collider,
+}
+
+/// User-defined filter for potential contact pairs detected by the broad-phase.
+///
+/// This can be used to apply custom logic in order to decide whether two colliders
+/// should have their contact computed by the narrow-phase, and if these contact
+/// should be solved by the constraints solver
+pub trait ContactPairFilter: Send + Sync {
+ /// Applies the contact pair filter.
+ ///
+ /// Note that using a contact pair filter will replace the default contact filtering
+ /// which consists of preventing contact computation between two non-dynamic bodies.
+ ///
+ /// This filtering method is called after taking into account the colliders collision groups.
+ ///
+ /// If this returns `None`, then the narrow-phase will ignore this contact pair and
+ /// not compute any contact manifolds for it.
+ /// If this returns `Some`, then the narrow-phase will compute contact manifolds for
+ /// this pair of colliders, and configure them with the returned solver flags. For
+ /// example, if this returns `Some(SolverFlags::COMPUTE_IMPULSES)` then the contacts
+ /// will be taken into account by the constraints solver. If this returns
+ /// `Some(SolverFlags::empty())` then the constraints solver will ignore these
+ /// contacts.
+ fn filter_contact_pair(&self, context: &PairFilterContext) -> Option<SolverFlags>;
+}
+
+/// User-defined filter for potential proximity pairs detected by the broad-phase.
+///
+/// This can be used to apply custom logic in order to decide whether two colliders
+/// should have their proximity computed by the narrow-phase.
+pub trait ProximityPairFilter: Send + Sync {
+ /// Applies the proximity pair filter.
+ ///
+ /// Note that using a proximity pair filter will replace the default proximity filtering
+ /// which consists of preventing proximity computation between two non-dynamic bodies.
+ ///
+ /// This filtering method is called after taking into account the colliders collision groups.
+ ///
+ /// If this returns `false`, then the narrow-phase will ignore this pair and
+ /// not compute any proximity information for it.
+ /// If this return `true` then the narrow-phase will compute proximity
+ /// information for this pair.
+ fn filter_proximity_pair(&self, context: &PairFilterContext) -> bool;
+}