dimforge / nphysics

2 and 3-dimensional rigid body physics engine for Rust.
https://nphysics.org
Apache License 2.0
1.63k stars 121 forks source link

Broad phase pair filters cannot access body information #273

Open neachdainn opened 4 years ago

neachdainn commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

Alternatives discussed on Discord: