1pub use self::broad_phase::BroadPhase;
4pub use self::broad_phase_bvh::{BroadPhaseBvh, BvhOptimizationStrategy};
5pub use self::broad_phase_pair_event::{BroadPhasePairEvent, ColliderPair};
6pub use self::collider::{Collider, ColliderBuilder};
7pub use self::collider_components::*;
8pub use self::collider_set::ColliderSet;
9pub use self::contact_pair::{
10 ContactData, ContactManifoldData, ContactPair, IntersectionPair, SolverContact, SolverFlags,
11};
12pub use self::interaction_graph::{
13 ColliderGraphIndex, InteractionGraph, RigidBodyGraphIndex, TemporaryInteractionIndex,
14};
15pub use self::interaction_groups::{Group, InteractionGroups};
16pub use self::mesh_converter::{MeshConverter, MeshConverterError};
17pub use self::narrow_phase::NarrowPhase;
18
19pub use parry::bounding_volume::BoundingVolume;
20pub use parry::partitioning::{Bvh, BvhBuildStrategy};
21pub use parry::query::{PointQuery, PointQueryWithLocation, RayCast, TrackedContact};
22pub use parry::shape::{SharedShape, VoxelState, VoxelType, Voxels};
23
24use crate::math::{Real, Vector};
25
26pub type Contact = parry::query::TrackedContact<ContactData>;
28pub type ContactManifold = parry::query::ContactManifold<ContactManifoldData, ContactData>;
30pub type Segment = parry::shape::Segment;
32pub type Cuboid = parry::shape::Cuboid;
34pub type Triangle = parry::shape::Triangle;
36pub type Ball = parry::shape::Ball;
38pub type Capsule = parry::shape::Capsule;
40pub type HeightField = parry::shape::HeightField;
42#[cfg(feature = "dim3")]
44pub type Cylinder = parry::shape::Cylinder;
45#[cfg(feature = "dim3")]
47pub type Cone = parry::shape::Cone;
48pub type Aabb = parry::bounding_volume::Aabb;
50pub type Ray = parry::query::Ray;
52pub type RayIntersection = parry::query::RayIntersection;
54pub type PointProjection = parry::query::PointProjection;
56pub type ShapeCastHit = parry::query::ShapeCastHit;
58pub type DefaultBroadPhase = BroadPhaseBvh;
60
61bitflags::bitflags! {
62 #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
64 #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
65 pub struct CollisionEventFlags: u32 {
66 const SENSOR = 0b0001;
69 const REMOVED = 0b0010;
72 }
73}
74
75#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
76#[derive(Copy, Clone, Hash, Debug)]
77pub enum CollisionEvent {
79 Started(ColliderHandle, ColliderHandle, CollisionEventFlags),
81 Stopped(ColliderHandle, ColliderHandle, CollisionEventFlags),
83}
84
85impl CollisionEvent {
86 pub fn started(self) -> bool {
88 matches!(self, CollisionEvent::Started(..))
89 }
90
91 pub fn stopped(self) -> bool {
93 matches!(self, CollisionEvent::Stopped(..))
94 }
95
96 pub fn collider1(self) -> ColliderHandle {
98 match self {
99 Self::Started(h, _, _) | Self::Stopped(h, _, _) => h,
100 }
101 }
102
103 pub fn collider2(self) -> ColliderHandle {
105 match self {
106 Self::Started(_, h, _) | Self::Stopped(_, h, _) => h,
107 }
108 }
109
110 pub fn sensor(self) -> bool {
112 match self {
113 Self::Started(_, _, f) | Self::Stopped(_, _, f) => {
114 f.contains(CollisionEventFlags::SENSOR)
115 }
116 }
117 }
118
119 pub fn removed(self) -> bool {
121 match self {
122 Self::Started(_, _, f) | Self::Stopped(_, _, f) => {
123 f.contains(CollisionEventFlags::REMOVED)
124 }
125 }
126 }
127}
128
129#[derive(Copy, Clone, PartialEq, Debug, Default)]
130pub struct ContactForceEvent {
133 pub collider1: ColliderHandle,
135 pub collider2: ColliderHandle,
137 pub total_force: Vector<Real>,
139 pub total_force_magnitude: Real,
145 pub max_force_direction: Vector<Real>,
147 pub max_force_magnitude: Real,
149}
150
151impl ContactForceEvent {
152 pub fn from_contact_pair(dt: Real, pair: &ContactPair, total_force_magnitude: Real) -> Self {
154 let mut result = ContactForceEvent {
155 collider1: pair.collider1,
156 collider2: pair.collider2,
157 total_force_magnitude,
158 ..ContactForceEvent::default()
159 };
160
161 for m in &pair.manifolds {
162 let mut total_manifold_impulse = 0.0;
163 for pt in m.contacts() {
164 total_manifold_impulse += pt.data.impulse;
165
166 if pt.data.impulse > result.max_force_magnitude {
167 result.max_force_magnitude = pt.data.impulse;
168 result.max_force_direction = m.data.normal;
169 }
170 }
171
172 result.total_force += m.data.normal * total_manifold_impulse;
173 }
174
175 let inv_dt = crate::utils::inv(dt);
176 result.total_force *= inv_dt;
181 result.max_force_magnitude *= inv_dt;
182 result
183 }
184}
185
186pub(crate) use self::collider_set::ModifiedColliders;
187pub(crate) use self::narrow_phase::ContactManifoldIndex;
188pub use parry::shape::*;
189
190#[cfg(feature = "serde-serialize")]
191pub(crate) fn default_persistent_query_dispatcher()
192-> std::sync::Arc<dyn parry::query::PersistentQueryDispatcher<ContactManifoldData, ContactData>> {
193 std::sync::Arc::new(parry::query::DefaultQueryDispatcher)
194}
195
196mod collider_components;
197mod contact_pair;
198mod interaction_graph;
199mod interaction_groups;
200mod narrow_phase;
201
202mod broad_phase;
203mod broad_phase_bvh;
204mod broad_phase_pair_event;
205mod collider;
206mod collider_set;
207mod mesh_converter;