pub trait BevyPhysicsHooks:
SystemParam
+ Send
+ Sync {
// Provided methods
fn filter_contact_pair(
&self,
_context: PairFilterContextView<'_>,
) -> Option<SolverFlags> { ... }
fn filter_intersection_pair(
&self,
_context: PairFilterContextView<'_>,
) -> bool { ... }
fn modify_solver_contacts(
&self,
_context: ContactModificationContextView<'_, '_>,
) { ... }
}Expand description
User-defined functions called by the physics engines during one timestep in order to customize its behavior.
Note that the default implementations of the filtering methods match Rapier’s
PhysicsHooks defaults: Self::filter_contact_pair returns
Some(SolverFlags::COMPUTE_RIGID_IMPULSES) and Self::filter_intersection_pair returns
true, so enabling a hook on a collider without overriding the corresponding method does not
change which pairs interact.
Provided Methods§
Sourcefn filter_contact_pair(
&self,
_context: PairFilterContextView<'_>,
) -> Option<SolverFlags>
fn filter_contact_pair( &self, _context: PairFilterContextView<'_>, ) -> Option<SolverFlags>
Applies the contact pair filter.
Note that this method will only be called if at least one of the colliders
involved in the contact contains the ActiveHooks::FILTER_CONTACT_PAIRS flags
in its physics hooks flags.
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
This filter doesn’t replace the built-in filtering: it is only called for the pairs that
passed it. Rapier first discards the pairs of colliders attached to the same rigid-body or
to multibody links (or impulse joints) with contacts disabled between them, then the pairs
rejected by the ActiveCollisionTypes of both colliders (e.g. two non-dynamic bodies by
default), then the pairs rejected by their CollisionGroups. The SolverGroups are
applied to the returned solver flags afterwards.
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_RIGID_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.
The default implementation returns Some(SolverFlags::COMPUTE_RIGID_IMPULSES).
Sourcefn filter_intersection_pair(&self, _context: PairFilterContextView<'_>) -> bool
fn filter_intersection_pair(&self, _context: PairFilterContextView<'_>) -> bool
Applies the intersection pair filter.
Note that this method will only be called if at least one of the colliders
involved in the contact contains the ActiveHooks::FILTER_INTERSECTION_PAIR flags
in its physics hooks flags.
User-defined filter for potential intersection pairs detected by the broad-phase.
This can be used to apply custom logic in order to decide whether two colliders should have their intersection computed by the narrow-phase.
This filter doesn’t replace the built-in filtering: it is only called for the pairs that
passed it. Rapier first discards the pairs rejected by the ActiveCollisionTypes of both
colliders (e.g. two non-dynamic bodies by default), then the pairs rejected by their
CollisionGroups.
If this returns false, then the narrow-phase will ignore this pair and
not compute any intersection information for it.
If this return true then the narrow-phase will compute intersection
information for this pair.
The default implementation returns true.
Sourcefn modify_solver_contacts(
&self,
_context: ContactModificationContextView<'_, '_>,
)
fn modify_solver_contacts( &self, _context: ContactModificationContextView<'_, '_>, )
Modifies the set of contacts seen by the constraints solver.
Note that this method will only be called if at least one of the colliders
involved in the contact contains the ActiveHooks::MODIFY_SOLVER_CONTACTS flags
in its physics hooks flags.
It is called on each contact manifold (with at least one solver contact) of such pairs, after the solver contacts were computed from the manifold’s contact points. This can be used to modify the set of solver contacts seen by the constraints solver: contacts can be removed and modified.
Note that if all the contacts have to be ignored by the constraint solver, you may simply
clear them with context.solver_contacts_mut().
Modifying the solver contacts allow you to achieve various effects, including:
- Simulating conveyor belts by setting the
tangent_velocityof a solver contact. - Simulating shapes with multiply materials by modifying the friction and restitution coefficient depending of the features in contacts.
- Simulating one-way platforms depending on the contact normal.
Each contact manifold is given a u32 user-defined data that is persistent between
timesteps (as long as the contact manifold exists). This user-defined data is initialized
as 0 and can be modified with ContactModificationContextView::set_user_data.
The world-space contact normal, friction and restitution can be modified with
ContactModificationContextView::set_normal,
ContactModificationContextView::set_friction and
ContactModificationContextView::set_restitution.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".