nphysics icon indicating copy to clipboard operation
nphysics copied to clipboard

Broad phase pair filters cannot access body information

Open neachdainn opened this issue 3 years ago • 2 comments

The current API for the broad phase pair filter cannot access any information about the bodies that are colliding. The filter has access to the handles via the BroadPhasePairFilter trait but there is not way to retrieve the body information from the set due to the fact that MechanicalWorld::step, which calls the filter, requires mutable access to the body set. Utilizing the user data on the collider is sufficient for cases where the information does not change during each step (e.g., parent information) but cannot be used for information about a body that may have been updated.

neachdainn avatar Jul 08 '20 22:07 neachdainn

I investigated having nphysics define its own BroadPhasePairFilter trait but almost 100% of the collision logic happens in ncollide (unsurprisingly). So it looks like this will have to be a change within ncollide.


I suspect the best approach would be to modify the BroadPhasePairFilter to the following:

pub trait BroadPhasePairFilter<N: RealField, Object, Handle, Set>: Any  + Send + Sync {
    fn is_pair_valid(&self, b1: &Object, b2: &Object, h1: Handle, h2: Handle, set: &Set) -> bool;
}

where Set becomes the BodySet in nphysics. This will require a change at every step between nphysics and ncollide's src/pipeline/glue/update.rs, so it's a fairly sizable change. I'll wait to start working on this until I get input.

neachdainn avatar Jul 08 '20 22:07 neachdainn

Alternatives discussed on Discord:

  • Using an associated type with a default and implementing a default fn is_pair_valid_in_set.
  • Creating a new trait BroadPhasePairSetFilter that is auto-implemented for (or auto-implements) BroadPhasePairFilter

neachdainn avatar Jul 09 '20 03:07 neachdainn