Rework the event system
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
use crate::dynamics::{CoefficientCombineRule, MassProperties, RigidBodyHandle};
|
||||
use crate::geometry::{
|
||||
ColliderBroadPhaseData, ColliderChanges, ColliderGroups, ColliderMassProperties,
|
||||
ColliderBroadPhaseData, ColliderChanges, ColliderFlags, ColliderGroups, ColliderMassProps,
|
||||
ColliderMaterial, ColliderParent, ColliderPosition, ColliderShape, ColliderType,
|
||||
InteractionGroups, SharedShape,
|
||||
};
|
||||
use crate::math::{AngVector, Isometry, Point, Real, Rotation, Vector, DIM};
|
||||
use crate::parry::transformation::vhacd::VHACDParameters;
|
||||
use crate::pipeline::PhysicsHooksFlags;
|
||||
use crate::pipeline::{ActiveEvents, ActiveHooks};
|
||||
use na::Unit;
|
||||
use parry::bounding_volume::AABB;
|
||||
use parry::shape::Shape;
|
||||
@@ -19,11 +19,12 @@ use parry::shape::Shape;
|
||||
pub struct Collider {
|
||||
pub(crate) co_type: ColliderType,
|
||||
pub(crate) co_shape: ColliderShape,
|
||||
pub(crate) co_mprops: ColliderMassProperties,
|
||||
pub(crate) co_mprops: ColliderMassProps,
|
||||
pub(crate) co_changes: ColliderChanges,
|
||||
pub(crate) co_parent: Option<ColliderParent>,
|
||||
pub(crate) co_pos: ColliderPosition,
|
||||
pub(crate) co_material: ColliderMaterial,
|
||||
pub(crate) co_flags: ColliderFlags,
|
||||
pub(crate) co_groups: ColliderGroups,
|
||||
pub(crate) co_bf_data: ColliderBroadPhaseData,
|
||||
/// User-defined data associated to this rigid-body.
|
||||
@@ -48,13 +49,23 @@ impl Collider {
|
||||
}
|
||||
|
||||
/// The physics hooks enabled for this collider.
|
||||
pub fn active_hooks(&self) -> PhysicsHooksFlags {
|
||||
self.co_material.active_hooks
|
||||
pub fn active_hooks(&self) -> ActiveHooks {
|
||||
self.co_flags.active_hooks
|
||||
}
|
||||
|
||||
/// Sets the physics hooks enabled for this collider.
|
||||
pub fn set_active_hooks(&mut self, active_hooks: PhysicsHooksFlags) {
|
||||
self.co_material.active_hooks = active_hooks;
|
||||
pub fn set_active_hooks(&mut self, active_hooks: ActiveHooks) {
|
||||
self.co_flags.active_hooks = active_hooks;
|
||||
}
|
||||
|
||||
/// The physics hooks enabled for this collider.
|
||||
pub fn active_events(&self) -> ActiveEvents {
|
||||
self.co_flags.active_events
|
||||
}
|
||||
|
||||
/// Sets the physics hooks enabled for this collider.
|
||||
pub fn set_active_events(&mut self, active_events: ActiveEvents) {
|
||||
self.co_flags.active_events = active_events;
|
||||
}
|
||||
|
||||
/// The friction coefficient of this collider.
|
||||
@@ -201,8 +212,8 @@ impl Collider {
|
||||
/// The density of this collider, if set.
|
||||
pub fn density(&self) -> Option<Real> {
|
||||
match &self.co_mprops {
|
||||
ColliderMassProperties::Density(density) => Some(*density),
|
||||
ColliderMassProperties::MassProperties(_) => None,
|
||||
ColliderMassProps::Density(density) => Some(*density),
|
||||
ColliderMassProps::MassProperties(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,8 +253,8 @@ impl Collider {
|
||||
/// Compute the local-space mass properties of this collider.
|
||||
pub fn mass_properties(&self) -> MassProperties {
|
||||
match &self.co_mprops {
|
||||
ColliderMassProperties::Density(density) => self.co_shape.mass_properties(*density),
|
||||
ColliderMassProperties::MassProperties(mass_properties) => **mass_properties,
|
||||
ColliderMassProps::Density(density) => self.co_shape.mass_properties(*density),
|
||||
ColliderMassProps::MassProperties(mass_properties) => **mass_properties,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -272,7 +283,9 @@ pub struct ColliderBuilder {
|
||||
/// Is this collider a sensor?
|
||||
pub is_sensor: bool,
|
||||
/// Physics hooks enabled for this collider.
|
||||
pub active_hooks: PhysicsHooksFlags,
|
||||
pub active_hooks: ActiveHooks,
|
||||
/// Events enabled for this collider.
|
||||
pub active_events: ActiveEvents,
|
||||
/// The user-data of the collider being built.
|
||||
pub user_data: u128,
|
||||
/// The collision groups for the collider being built.
|
||||
@@ -297,7 +310,8 @@ impl ColliderBuilder {
|
||||
solver_groups: InteractionGroups::all(),
|
||||
friction_combine_rule: CoefficientCombineRule::Average,
|
||||
restitution_combine_rule: CoefficientCombineRule::Average,
|
||||
active_hooks: PhysicsHooksFlags::empty(),
|
||||
active_hooks: ActiveHooks::empty(),
|
||||
active_events: ActiveEvents::empty(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -581,11 +595,17 @@ impl ColliderBuilder {
|
||||
}
|
||||
|
||||
/// The set of physics hooks enabled for this collider.
|
||||
pub fn active_hooks(mut self, active_hooks: PhysicsHooksFlags) -> Self {
|
||||
pub fn active_hooks(mut self, active_hooks: ActiveHooks) -> Self {
|
||||
self.active_hooks = active_hooks;
|
||||
self
|
||||
}
|
||||
|
||||
/// The set of events enabled for this collider.
|
||||
pub fn active_events(mut self, active_events: ActiveEvents) -> Self {
|
||||
self.active_events = active_events;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the friction coefficient of the collider this builder will build.
|
||||
pub fn friction(mut self, friction: Real) -> Self {
|
||||
self.friction = friction;
|
||||
@@ -672,12 +692,22 @@ impl ColliderBuilder {
|
||||
|
||||
/// Builds a new collider attached to the given rigid-body.
|
||||
pub fn build(&self) -> Collider {
|
||||
let (co_changes, co_pos, co_bf_data, co_shape, co_type, co_groups, co_material, co_mprops) =
|
||||
self.components();
|
||||
let (
|
||||
co_changes,
|
||||
co_pos,
|
||||
co_bf_data,
|
||||
co_shape,
|
||||
co_type,
|
||||
co_groups,
|
||||
co_material,
|
||||
co_flags,
|
||||
co_mprops,
|
||||
) = self.components();
|
||||
Collider {
|
||||
co_shape,
|
||||
co_mprops,
|
||||
co_material,
|
||||
co_flags,
|
||||
co_parent: None,
|
||||
co_changes,
|
||||
co_pos,
|
||||
@@ -699,14 +729,15 @@ impl ColliderBuilder {
|
||||
ColliderType,
|
||||
ColliderGroups,
|
||||
ColliderMaterial,
|
||||
ColliderMassProperties,
|
||||
ColliderFlags,
|
||||
ColliderMassProps,
|
||||
) {
|
||||
let mass_info = if let Some(mp) = self.mass_properties {
|
||||
ColliderMassProperties::MassProperties(Box::new(mp))
|
||||
ColliderMassProps::MassProperties(Box::new(mp))
|
||||
} else {
|
||||
let default_density = Self::default_density();
|
||||
let density = self.density.unwrap_or(default_density);
|
||||
ColliderMassProperties::Density(density)
|
||||
ColliderMassProps::Density(density)
|
||||
};
|
||||
|
||||
let co_shape = self.shape.clone();
|
||||
@@ -716,7 +747,10 @@ impl ColliderBuilder {
|
||||
restitution: self.restitution,
|
||||
friction_combine_rule: self.friction_combine_rule,
|
||||
restitution_combine_rule: self.restitution_combine_rule,
|
||||
};
|
||||
let co_flags = ColliderFlags {
|
||||
active_hooks: self.active_hooks,
|
||||
active_events: self.active_events,
|
||||
};
|
||||
let co_changes = ColliderChanges::all();
|
||||
let co_pos = ColliderPosition(self.position);
|
||||
@@ -739,6 +773,7 @@ impl ColliderBuilder {
|
||||
co_type,
|
||||
co_groups,
|
||||
co_material,
|
||||
co_flags,
|
||||
co_mprops,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::dynamics::{CoefficientCombineRule, MassProperties, RigidBodyHandle};
|
||||
use crate::geometry::{InteractionGroups, SAPProxyIndex, Shape, SharedShape};
|
||||
use crate::math::{Isometry, Real};
|
||||
use crate::parry::partitioning::IndexedData;
|
||||
use crate::pipeline::PhysicsHooksFlags;
|
||||
use crate::pipeline::{ActiveEvents, ActiveHooks};
|
||||
use std::ops::Deref;
|
||||
|
||||
/// The unique identifier of a collider added to a collider set.
|
||||
@@ -118,7 +118,7 @@ pub type ColliderShape = SharedShape;
|
||||
#[derive(Clone)]
|
||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
/// The mass-properties of a collider.
|
||||
pub enum ColliderMassProperties {
|
||||
pub enum ColliderMassProps {
|
||||
/// The collider is given a density.
|
||||
///
|
||||
/// Its actual `MassProperties` are computed automatically with
|
||||
@@ -128,13 +128,19 @@ pub enum ColliderMassProperties {
|
||||
MassProperties(Box<MassProperties>),
|
||||
}
|
||||
|
||||
impl Default for ColliderMassProperties {
|
||||
impl Default for ColliderMassProps {
|
||||
fn default() -> Self {
|
||||
ColliderMassProperties::Density(1.0)
|
||||
ColliderMassProps::Density(1.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl ColliderMassProperties {
|
||||
impl From<MassProperties> for ColliderMassProps {
|
||||
fn from(mprops: MassProperties) -> Self {
|
||||
ColliderMassProps::MassProperties(Box::new(mprops))
|
||||
}
|
||||
}
|
||||
|
||||
impl ColliderMassProps {
|
||||
/// The mass-properties of this collider.
|
||||
///
|
||||
/// If `self` is the `Density` variant, then this computes the mass-properties based
|
||||
@@ -242,8 +248,6 @@ pub struct ColliderMaterial {
|
||||
pub friction_combine_rule: CoefficientCombineRule,
|
||||
/// The rule applied to combine the restitution coefficients of two colliders.
|
||||
pub restitution_combine_rule: CoefficientCombineRule,
|
||||
/// The physics hooks enabled for contact pairs and intersection pairs involving this collider.
|
||||
pub active_hooks: PhysicsHooksFlags,
|
||||
}
|
||||
|
||||
impl ColliderMaterial {
|
||||
@@ -264,7 +268,43 @@ impl Default for ColliderMaterial {
|
||||
restitution: 0.0,
|
||||
friction_combine_rule: CoefficientCombineRule::default(),
|
||||
restitution_combine_rule: CoefficientCombineRule::default(),
|
||||
active_hooks: PhysicsHooksFlags::empty(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
/// A set of flags controlling the active hooks and events for this colliders.
|
||||
pub struct ColliderFlags {
|
||||
/// The physics hooks enabled for contact pairs and intersection pairs involving this collider.
|
||||
pub active_hooks: ActiveHooks,
|
||||
/// The events enabled for this collider.
|
||||
pub active_events: ActiveEvents,
|
||||
}
|
||||
|
||||
impl Default for ColliderFlags {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
active_hooks: ActiveHooks::empty(),
|
||||
active_events: ActiveEvents::empty(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ActiveHooks> for ColliderFlags {
|
||||
fn from(active_hooks: ActiveHooks) -> Self {
|
||||
Self {
|
||||
active_hooks,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ActiveEvents> for ColliderFlags {
|
||||
fn from(active_events: ActiveEvents) -> Self {
|
||||
Self {
|
||||
active_events,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ use crate::data::arena::Arena;
|
||||
use crate::data::{ComponentSet, ComponentSetMut, ComponentSetOption};
|
||||
use crate::dynamics::{IslandManager, RigidBodyHandle, RigidBodySet};
|
||||
use crate::geometry::{
|
||||
Collider, ColliderBroadPhaseData, ColliderGroups, ColliderMassProperties, ColliderMaterial,
|
||||
ColliderParent, ColliderPosition, ColliderShape, ColliderType,
|
||||
Collider, ColliderBroadPhaseData, ColliderFlags, ColliderGroups, ColliderMassProps,
|
||||
ColliderMaterial, ColliderParent, ColliderPosition, ColliderShape, ColliderType,
|
||||
};
|
||||
use crate::geometry::{ColliderChanges, ColliderHandle};
|
||||
use std::ops::{Index, IndexMut};
|
||||
@@ -59,10 +59,11 @@ macro_rules! impl_field_component_set(
|
||||
|
||||
impl_field_component_set!(ColliderType, co_type);
|
||||
impl_field_component_set!(ColliderShape, co_shape);
|
||||
impl_field_component_set!(ColliderMassProperties, co_mprops);
|
||||
impl_field_component_set!(ColliderMassProps, co_mprops);
|
||||
impl_field_component_set!(ColliderChanges, co_changes);
|
||||
impl_field_component_set!(ColliderPosition, co_pos);
|
||||
impl_field_component_set!(ColliderMaterial, co_material);
|
||||
impl_field_component_set!(ColliderFlags, co_flags);
|
||||
impl_field_component_set!(ColliderGroups, co_groups);
|
||||
impl_field_component_set!(ColliderBroadPhaseData, co_bf_data);
|
||||
|
||||
|
||||
@@ -14,8 +14,10 @@ use crate::geometry::{
|
||||
};
|
||||
use crate::math::{Real, Vector};
|
||||
use crate::pipeline::{
|
||||
ContactModificationContext, EventHandler, PairFilterContext, PhysicsHooks, PhysicsHooksFlags,
|
||||
ActiveEvents, ActiveHooks, ContactModificationContext, EventHandler, PairFilterContext,
|
||||
PhysicsHooks,
|
||||
};
|
||||
use crate::prelude::ColliderFlags;
|
||||
use parry::query::{DefaultQueryDispatcher, PersistentQueryDispatcher};
|
||||
use parry::utils::IsometryOpt;
|
||||
use std::collections::HashMap;
|
||||
@@ -101,21 +103,26 @@ impl NarrowPhase {
|
||||
///
|
||||
/// It is strongly recommended to use the [`NarrowPhase::contacts_with`] method instead. This
|
||||
/// method can be used if the generation number of the collider handle isn't known.
|
||||
pub fn contacts_with_unknown_gen(
|
||||
&self,
|
||||
collider: u32,
|
||||
) -> Option<impl Iterator<Item = (ColliderHandle, ColliderHandle, &ContactPair)>> {
|
||||
let id = self.graph_indices.get_unknown_gen(collider)?;
|
||||
Some(self.contact_graph.interactions_with(id.contact_graph_index))
|
||||
pub fn contacts_with_unknown_gen(&self, collider: u32) -> impl Iterator<Item = &ContactPair> {
|
||||
self.graph_indices
|
||||
.get_unknown_gen(collider)
|
||||
.map(|id| id.contact_graph_index)
|
||||
.into_iter()
|
||||
.flat_map(move |id| self.contact_graph.interactions_with(id))
|
||||
.map(|pair| pair.2)
|
||||
}
|
||||
|
||||
/// All the contacts involving the given collider.
|
||||
pub fn contacts_with(
|
||||
pub fn contacts_with<'a>(
|
||||
&self,
|
||||
collider: ColliderHandle,
|
||||
) -> Option<impl Iterator<Item = (ColliderHandle, ColliderHandle, &ContactPair)>> {
|
||||
let id = self.graph_indices.get(collider.0)?;
|
||||
Some(self.contact_graph.interactions_with(id.contact_graph_index))
|
||||
) -> impl Iterator<Item = &ContactPair> {
|
||||
self.graph_indices
|
||||
.get(collider.0)
|
||||
.map(|id| id.contact_graph_index)
|
||||
.into_iter()
|
||||
.flat_map(move |id| self.contact_graph.interactions_with(id))
|
||||
.map(|pair| pair.2)
|
||||
}
|
||||
|
||||
/// All the intersections involving the given collider.
|
||||
@@ -125,26 +132,32 @@ impl NarrowPhase {
|
||||
pub fn intersections_with_unknown_gen(
|
||||
&self,
|
||||
collider: u32,
|
||||
) -> Option<impl Iterator<Item = (ColliderHandle, ColliderHandle, bool)> + '_> {
|
||||
let id = self.graph_indices.get_unknown_gen(collider)?;
|
||||
Some(
|
||||
self.intersection_graph
|
||||
.interactions_with(id.intersection_graph_index)
|
||||
.map(|e| (e.0, e.1, *e.2)),
|
||||
)
|
||||
) -> impl Iterator<Item = (ColliderHandle, ColliderHandle, bool)> + '_ {
|
||||
self.graph_indices
|
||||
.get_unknown_gen(collider)
|
||||
.map(|id| id.intersection_graph_index)
|
||||
.into_iter()
|
||||
.flat_map(move |id| {
|
||||
self.intersection_graph
|
||||
.interactions_with(id)
|
||||
.map(|e| (e.0, e.1, *e.2))
|
||||
})
|
||||
}
|
||||
|
||||
/// All the intersections involving the given collider.
|
||||
pub fn intersections_with(
|
||||
&self,
|
||||
collider: ColliderHandle,
|
||||
) -> Option<impl Iterator<Item = (ColliderHandle, ColliderHandle, bool)> + '_> {
|
||||
let id = self.graph_indices.get(collider.0)?;
|
||||
Some(
|
||||
self.intersection_graph
|
||||
.interactions_with(id.intersection_graph_index)
|
||||
.map(|e| (e.0, e.1, *e.2)),
|
||||
)
|
||||
) -> impl Iterator<Item = (ColliderHandle, ColliderHandle, bool)> + '_ {
|
||||
self.graph_indices
|
||||
.get(collider.0)
|
||||
.map(|id| id.intersection_graph_index)
|
||||
.into_iter()
|
||||
.flat_map(move |id| {
|
||||
self.intersection_graph
|
||||
.interactions_with(id)
|
||||
.map(|e| (e.0, e.1, *e.2))
|
||||
})
|
||||
}
|
||||
|
||||
/// The contact pair involving two specific colliders.
|
||||
@@ -244,8 +257,9 @@ impl NarrowPhase {
|
||||
+ ComponentSet<RigidBodyType>
|
||||
+ ComponentSetMut<RigidBodyIds>,
|
||||
Colliders: ComponentSet<ColliderChanges>
|
||||
+ ComponentSetOption<ColliderParent>
|
||||
+ ComponentSet<ColliderType>,
|
||||
+ ComponentSet<ColliderType>
|
||||
+ ComponentSet<ColliderFlags>
|
||||
+ ComponentSetOption<ColliderParent>,
|
||||
{
|
||||
// TODO: avoid these hash-maps.
|
||||
// They are necessary to handle the swap-remove done internally
|
||||
@@ -340,8 +354,9 @@ impl NarrowPhase {
|
||||
+ ComponentSet<RigidBodyType>
|
||||
+ ComponentSetMut<RigidBodyIds>,
|
||||
Colliders: ComponentSet<ColliderChanges>
|
||||
+ ComponentSetOption<ColliderParent>
|
||||
+ ComponentSet<ColliderType>,
|
||||
+ ComponentSet<ColliderType>
|
||||
+ ComponentSet<ColliderFlags>
|
||||
+ ComponentSetOption<ColliderParent>,
|
||||
{
|
||||
let mut pairs_to_remove = vec![];
|
||||
|
||||
@@ -456,7 +471,9 @@ impl NarrowPhase {
|
||||
Bodies: ComponentSetMut<RigidBodyActivation>
|
||||
+ ComponentSet<RigidBodyType>
|
||||
+ ComponentSetMut<RigidBodyIds>,
|
||||
Colliders: ComponentSet<ColliderType> + ComponentSetOption<ColliderParent>,
|
||||
Colliders: ComponentSet<ColliderType>
|
||||
+ ComponentSet<ColliderFlags>
|
||||
+ ComponentSetOption<ColliderParent>,
|
||||
{
|
||||
let co_type1: Option<&ColliderType> = colliders.get(pair.collider1.0);
|
||||
let co_type2: Option<&ColliderType> = colliders.get(pair.collider2.0);
|
||||
@@ -478,9 +495,16 @@ impl NarrowPhase {
|
||||
|
||||
// Emit an intersection lost event if we had an intersection before removing the edge.
|
||||
if Some(true) == was_intersecting {
|
||||
let prox_event =
|
||||
IntersectionEvent::new(pair.collider1, pair.collider2, false);
|
||||
events.handle_intersection_event(prox_event)
|
||||
let co_flag1: &ColliderFlags = colliders.index(pair.collider1.0);
|
||||
let co_flag2: &ColliderFlags = colliders.index(pair.collider2.0);
|
||||
|
||||
if (co_flag1.active_events | co_flag2.active_events)
|
||||
.contains(ActiveEvents::INTERSECTION_EVENTS)
|
||||
{
|
||||
let prox_event =
|
||||
IntersectionEvent::new(pair.collider1, pair.collider2, false);
|
||||
events.handle_intersection_event(prox_event)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let contact_pair = self
|
||||
@@ -506,10 +530,17 @@ impl NarrowPhase {
|
||||
}
|
||||
}
|
||||
|
||||
events.handle_contact_event(ContactEvent::Stopped(
|
||||
pair.collider1,
|
||||
pair.collider2,
|
||||
))
|
||||
let co_flag1: &ColliderFlags = colliders.index(pair.collider1.0);
|
||||
let co_flag2: &ColliderFlags = colliders.index(pair.collider2.0);
|
||||
|
||||
if (co_flag1.active_events | co_flag2.active_events)
|
||||
.contains(ActiveEvents::CONTACT_EVENTS)
|
||||
{
|
||||
events.handle_contact_event(
|
||||
ContactEvent::Stopped(pair.collider1, pair.collider2),
|
||||
&ctct,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -606,9 +637,11 @@ impl NarrowPhase {
|
||||
events: &dyn EventHandler,
|
||||
) where
|
||||
Bodies: ComponentSetMut<RigidBodyActivation>
|
||||
+ ComponentSet<RigidBodyType>
|
||||
+ ComponentSetMut<RigidBodyIds>,
|
||||
Colliders: ComponentSet<ColliderType> + ComponentSetOption<ColliderParent>,
|
||||
+ ComponentSetMut<RigidBodyIds>
|
||||
+ ComponentSet<RigidBodyType>,
|
||||
Colliders: ComponentSet<ColliderType>
|
||||
+ ComponentSet<ColliderFlags>
|
||||
+ ComponentSetOption<ColliderParent>,
|
||||
{
|
||||
for event in broad_phase_events {
|
||||
match event {
|
||||
@@ -645,7 +678,8 @@ impl NarrowPhase {
|
||||
+ ComponentSet<ColliderGroups>
|
||||
+ ComponentSet<ColliderShape>
|
||||
+ ComponentSet<ColliderPosition>
|
||||
+ ComponentSet<ColliderMaterial>,
|
||||
+ ComponentSet<ColliderMaterial>
|
||||
+ ComponentSet<ColliderFlags>,
|
||||
{
|
||||
if modified_colliders.is_empty() {
|
||||
return;
|
||||
@@ -660,21 +694,21 @@ impl NarrowPhase {
|
||||
let handle2 = nodes[edge.target().index()].weight;
|
||||
|
||||
let co_parent1: Option<&ColliderParent> = colliders.get(handle1.0);
|
||||
let (co_changes1, co_groups1, co_shape1, co_pos1, co_material1): (
|
||||
let (co_changes1, co_groups1, co_shape1, co_pos1, co_flags1): (
|
||||
&ColliderChanges,
|
||||
&ColliderGroups,
|
||||
&ColliderShape,
|
||||
&ColliderPosition,
|
||||
&ColliderMaterial,
|
||||
&ColliderFlags,
|
||||
) = colliders.index_bundle(handle1.0);
|
||||
|
||||
let co_parent2: Option<&ColliderParent> = colliders.get(handle2.0);
|
||||
let (co_changes2, co_groups2, co_shape2, co_pos2, co_material2): (
|
||||
let (co_changes2, co_groups2, co_shape2, co_pos2, co_flags2): (
|
||||
&ColliderChanges,
|
||||
&ColliderGroups,
|
||||
&ColliderShape,
|
||||
&ColliderPosition,
|
||||
&ColliderMaterial,
|
||||
&ColliderFlags,
|
||||
) = colliders.index_bundle(handle2.0);
|
||||
|
||||
if !co_changes1.needs_narrow_phase_update() && !co_changes2.needs_narrow_phase_update()
|
||||
@@ -717,9 +751,10 @@ impl NarrowPhase {
|
||||
return;
|
||||
}
|
||||
|
||||
let active_hooks = co_material1.active_hooks | co_material2.active_hooks;
|
||||
let active_hooks = co_flags1.active_hooks | co_flags2.active_hooks;
|
||||
let active_events = co_flags1.active_events | co_flags2.active_events;
|
||||
|
||||
if !active_hooks.contains(PhysicsHooksFlags::FILTER_INTERSECTION_PAIR)
|
||||
if !active_hooks.contains(ActiveHooks::FILTER_INTERSECTION_PAIR)
|
||||
&& !status1.is_dynamic()
|
||||
&& !status2.is_dynamic()
|
||||
{
|
||||
@@ -727,7 +762,7 @@ impl NarrowPhase {
|
||||
return;
|
||||
}
|
||||
|
||||
if active_hooks.contains(PhysicsHooksFlags::FILTER_INTERSECTION_PAIR) {
|
||||
if active_hooks.contains(ActiveHooks::FILTER_INTERSECTION_PAIR) {
|
||||
let context = PairFilterContext {
|
||||
bodies,
|
||||
colliders,
|
||||
@@ -748,7 +783,9 @@ impl NarrowPhase {
|
||||
if let Ok(intersection) =
|
||||
query_dispatcher.intersection_test(&pos12, &**co_shape1, &**co_shape2)
|
||||
{
|
||||
if intersection != edge.weight {
|
||||
if active_events.contains(ActiveEvents::INTERSECTION_EVENTS)
|
||||
&& intersection != edge.weight
|
||||
{
|
||||
edge.weight = intersection;
|
||||
events.handle_intersection_event(IntersectionEvent::new(
|
||||
handle1,
|
||||
@@ -777,7 +814,8 @@ impl NarrowPhase {
|
||||
+ ComponentSet<ColliderGroups>
|
||||
+ ComponentSet<ColliderShape>
|
||||
+ ComponentSet<ColliderPosition>
|
||||
+ ComponentSet<ColliderMaterial>,
|
||||
+ ComponentSet<ColliderMaterial>
|
||||
+ ComponentSet<ColliderFlags>,
|
||||
{
|
||||
if modified_colliders.is_empty() {
|
||||
return;
|
||||
@@ -790,21 +828,23 @@ impl NarrowPhase {
|
||||
let pair = &mut edge.weight;
|
||||
|
||||
let co_parent1: Option<&ColliderParent> = colliders.get(pair.collider1.0);
|
||||
let (co_changes1, co_groups1, co_shape1, co_pos1, co_material1): (
|
||||
let (co_changes1, co_groups1, co_shape1, co_pos1, co_material1, co_flags1): (
|
||||
&ColliderChanges,
|
||||
&ColliderGroups,
|
||||
&ColliderShape,
|
||||
&ColliderPosition,
|
||||
&ColliderMaterial,
|
||||
&ColliderFlags,
|
||||
) = colliders.index_bundle(pair.collider1.0);
|
||||
|
||||
let co_parent2: Option<&ColliderParent> = colliders.get(pair.collider2.0);
|
||||
let (co_changes2, co_groups2, co_shape2, co_pos2, co_material2): (
|
||||
let (co_changes2, co_groups2, co_shape2, co_pos2, co_material2, co_flags2): (
|
||||
&ColliderChanges,
|
||||
&ColliderGroups,
|
||||
&ColliderShape,
|
||||
&ColliderPosition,
|
||||
&ColliderMaterial,
|
||||
&ColliderFlags,
|
||||
) = colliders.index_bundle(pair.collider2.0);
|
||||
|
||||
if !co_changes1.needs_narrow_phase_update() && !co_changes2.needs_narrow_phase_update()
|
||||
@@ -847,8 +887,10 @@ impl NarrowPhase {
|
||||
return;
|
||||
}
|
||||
|
||||
let active_hooks = co_material1.active_hooks | co_material2.active_hooks;
|
||||
if !active_hooks.contains(PhysicsHooksFlags::FILTER_CONTACT_PAIR)
|
||||
let active_hooks = co_flags1.active_hooks | co_flags2.active_hooks;
|
||||
let active_events = co_flags1.active_events | co_flags2.active_events;
|
||||
|
||||
if !active_hooks.contains(ActiveHooks::FILTER_CONTACT_PAIRS)
|
||||
&& !status1.is_dynamic()
|
||||
&& !status2.is_dynamic()
|
||||
{
|
||||
@@ -856,8 +898,7 @@ impl NarrowPhase {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut solver_flags = if active_hooks.contains(PhysicsHooksFlags::FILTER_CONTACT_PAIR)
|
||||
{
|
||||
let mut solver_flags = if active_hooks.contains(ActiveHooks::FILTER_CONTACT_PAIRS) {
|
||||
let context = PairFilterContext {
|
||||
bodies,
|
||||
colliders,
|
||||
@@ -959,7 +1000,7 @@ impl NarrowPhase {
|
||||
}
|
||||
|
||||
// Apply the user-defined contact modification.
|
||||
if active_hooks.contains(PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS) {
|
||||
if active_hooks.contains(ActiveHooks::MODIFY_SOLVER_CONTACTS) {
|
||||
let mut modifiable_solver_contacts =
|
||||
std::mem::replace(&mut manifold.data.solver_contacts, Vec::new());
|
||||
let mut modifiable_user_data = manifold.data.user_data;
|
||||
@@ -987,16 +1028,18 @@ impl NarrowPhase {
|
||||
}
|
||||
|
||||
if has_any_active_contact != pair.has_any_active_contact {
|
||||
if has_any_active_contact {
|
||||
events.handle_contact_event(ContactEvent::Started(
|
||||
pair.collider1,
|
||||
pair.collider2,
|
||||
));
|
||||
} else {
|
||||
events.handle_contact_event(ContactEvent::Stopped(
|
||||
pair.collider1,
|
||||
pair.collider2,
|
||||
));
|
||||
if active_events.contains(ActiveEvents::CONTACT_EVENTS) {
|
||||
if has_any_active_contact {
|
||||
events.handle_contact_event(
|
||||
ContactEvent::Started(pair.collider1, pair.collider2),
|
||||
pair,
|
||||
);
|
||||
} else {
|
||||
events.handle_contact_event(
|
||||
ContactEvent::Stopped(pair.collider1, pair.collider2),
|
||||
pair,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pair.has_any_active_contact = has_any_active_contact;
|
||||
|
||||
Reference in New Issue
Block a user