pub use self::broad_phase::BroadPhase;
pub use self::broad_phase_multi_sap::{BroadPhaseMultiSap, BroadPhasePairEvent, ColliderPair};
pub use self::collider::{Collider, ColliderBuilder};
pub use self::collider_components::*;
pub use self::collider_set::ColliderSet;
pub use self::contact_pair::{
ContactData, ContactManifoldData, ContactPair, IntersectionPair, SolverContact, SolverFlags,
};
pub use self::interaction_graph::{
ColliderGraphIndex, InteractionGraph, RigidBodyGraphIndex, TemporaryInteractionIndex,
};
pub use self::interaction_groups::{Group, InteractionGroups};
pub use self::mesh_converter::{MeshConverter, MeshConverterError};
pub use self::narrow_phase::NarrowPhase;
pub use parry::bounding_volume::BoundingVolume;
pub use parry::query::{PointQuery, PointQueryWithLocation, RayCast, TrackedContact};
pub use parry::shape::{SharedShape, VoxelPrimitiveGeometry, VoxelState, VoxelType, Voxels};
use crate::math::{Real, Vector};
pub type Contact = parry::query::TrackedContact<ContactData>;
pub type ContactManifold = parry::query::ContactManifold<ContactManifoldData, ContactData>;
pub type Segment = parry::shape::Segment;
pub type Cuboid = parry::shape::Cuboid;
pub type Triangle = parry::shape::Triangle;
pub type Ball = parry::shape::Ball;
pub type Capsule = parry::shape::Capsule;
pub type HeightField = parry::shape::HeightField;
#[cfg(feature = "dim3")]
pub type Cylinder = parry::shape::Cylinder;
#[cfg(feature = "dim3")]
pub type Cone = parry::shape::Cone;
pub type Aabb = parry::bounding_volume::Aabb;
pub type Ray = parry::query::Ray;
pub type RayIntersection = parry::query::RayIntersection;
pub type PointProjection = parry::query::PointProjection;
pub type ShapeCastHit = parry::query::ShapeCastHit;
pub type DefaultBroadPhase = BroadPhaseMultiSap;
bitflags::bitflags! {
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
pub struct CollisionEventFlags: u32 {
const SENSOR = 0b0001;
const REMOVED = 0b0010;
}
}
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Hash, Debug)]
pub enum CollisionEvent {
Started(ColliderHandle, ColliderHandle, CollisionEventFlags),
Stopped(ColliderHandle, ColliderHandle, CollisionEventFlags),
}
impl CollisionEvent {
pub fn started(self) -> bool {
matches!(self, CollisionEvent::Started(..))
}
pub fn stopped(self) -> bool {
matches!(self, CollisionEvent::Stopped(..))
}
pub fn collider1(self) -> ColliderHandle {
match self {
Self::Started(h, _, _) | Self::Stopped(h, _, _) => h,
}
}
pub fn collider2(self) -> ColliderHandle {
match self {
Self::Started(_, h, _) | Self::Stopped(_, h, _) => h,
}
}
pub fn sensor(self) -> bool {
match self {
Self::Started(_, _, f) | Self::Stopped(_, _, f) => {
f.contains(CollisionEventFlags::SENSOR)
}
}
}
pub fn removed(self) -> bool {
match self {
Self::Started(_, _, f) | Self::Stopped(_, _, f) => {
f.contains(CollisionEventFlags::REMOVED)
}
}
}
}
#[derive(Copy, Clone, PartialEq, Debug, Default)]
pub struct ContactForceEvent {
pub collider1: ColliderHandle,
pub collider2: ColliderHandle,
pub total_force: Vector<Real>,
pub total_force_magnitude: Real,
pub max_force_direction: Vector<Real>,
pub max_force_magnitude: Real,
}
impl ContactForceEvent {
pub fn from_contact_pair(dt: Real, pair: &ContactPair, total_force_magnitude: Real) -> Self {
let mut result = ContactForceEvent {
collider1: pair.collider1,
collider2: pair.collider2,
total_force_magnitude,
..ContactForceEvent::default()
};
for m in &pair.manifolds {
let mut total_manifold_impulse = 0.0;
for pt in m.contacts() {
total_manifold_impulse += pt.data.impulse;
if pt.data.impulse > result.max_force_magnitude {
result.max_force_magnitude = pt.data.impulse;
result.max_force_direction = m.data.normal;
}
}
result.total_force += m.data.normal * total_manifold_impulse;
}
let inv_dt = crate::utils::inv(dt);
result.total_force *= inv_dt;
result.max_force_magnitude *= inv_dt;
result
}
}
pub(crate) use self::broad_phase::BroadPhaseProxyIndex;
pub(crate) use self::collider_set::ModifiedColliders;
pub(crate) use self::narrow_phase::ContactManifoldIndex;
pub(crate) use parry::partitioning::Qbvh;
pub use parry::shape::*;
#[cfg(feature = "serde-serialize")]
pub(crate) fn default_persistent_query_dispatcher(
) -> std::sync::Arc<dyn parry::query::PersistentQueryDispatcher<ContactManifoldData, ContactData>> {
std::sync::Arc::new(parry::query::DefaultQueryDispatcher)
}
#[cfg(feature = "serde-serialize")]
pub(crate) fn default_query_dispatcher() -> std::sync::Arc<dyn parry::query::QueryDispatcher> {
std::sync::Arc::new(parry::query::DefaultQueryDispatcher)
}
mod broad_phase_multi_sap;
mod collider_components;
mod contact_pair;
mod interaction_graph;
mod interaction_groups;
mod narrow_phase;
mod broad_phase;
mod broad_phase_qbvh;
mod collider;
mod collider_set;
mod mesh_converter;