diff options
| author | Crozet Sébastien <developer@crozet.re> | 2020-12-14 15:51:43 +0100 |
|---|---|---|
| committer | Crozet Sébastien <developer@crozet.re> | 2020-12-29 11:31:00 +0100 |
| commit | cc6d1b973002b4d366bc81ec6bf9e8240ad7b404 (patch) | |
| tree | 66827195ef82f22e545fc9ee4e0bade9baa8031b /src/geometry | |
| parent | 9bf1321f8f1d2e116f44c2461a53f302c4ef4171 (diff) | |
| download | rapier-cc6d1b973002b4d366bc81ec6bf9e8240ad7b404.tar.gz rapier-cc6d1b973002b4d366bc81ec6bf9e8240ad7b404.tar.bz2 rapier-cc6d1b973002b4d366bc81ec6bf9e8240ad7b404.zip | |
Outsource the Shape trait, wquadtree, and shape types.
Diffstat (limited to 'src/geometry')
23 files changed, 85 insertions, 1584 deletions
diff --git a/src/geometry/ball.rs b/src/geometry/ball.rs index 7f4ad03..2d9f7be 100644 --- a/src/geometry/ball.rs +++ b/src/geometry/ball.rs @@ -1,16 +1,16 @@ #[cfg(feature = "simd-is-enabled")] -use crate::math::{Point, SimdFloat}; +use crate::math::{Point, SimdReal}; #[cfg(feature = "simd-is-enabled")] #[derive(Copy, Clone, Debug)] pub(crate) struct WBall { - pub center: Point<SimdFloat>, - pub radius: SimdFloat, + pub center: Point<SimdReal>, + pub radius: SimdReal, } #[cfg(feature = "simd-is-enabled")] impl WBall { - pub fn new(center: Point<SimdFloat>, radius: SimdFloat) -> Self { + pub fn new(center: Point<SimdReal>, radius: SimdReal) -> Self { WBall { center, radius } } } diff --git a/src/geometry/collider.rs b/src/geometry/collider.rs index 8154554..1275358 100644 --- a/src/geometry/collider.rs +++ b/src/geometry/collider.rs @@ -1,12 +1,13 @@ +use crate::buckler::shape::HalfSpace; use crate::dynamics::{MassProperties, RigidBodyHandle, RigidBodySet}; -use crate::geometry::{ - Ball, Capsule, Cuboid, HeightField, InteractionGroups, Segment, Shape, ShapeType, Triangle, - Trimesh, -}; -#[cfg(feature = "dim3")] -use crate::geometry::{Cone, Cylinder, RoundCylinder}; +use crate::geometry::InteractionGroups; use crate::math::{AngVector, Isometry, Point, Rotation, Vector}; use buckler::bounding_volume::AABB; +use buckler::shape::{ + Ball, Capsule, Cuboid, HeightField, Segment, Shape, ShapeType, TriMesh, Triangle, +}; +#[cfg(feature = "dim3")] +use buckler::shape::{Cone, Cylinder, RoundCylinder}; use na::Point3; use std::ops::Deref; use std::sync::Arc; @@ -77,7 +78,7 @@ impl ColliderShape { /// Initializes a triangle mesh shape defined by its vertex and index buffers. pub fn trimesh(vertices: Vec<Point<f32>>, indices: Vec<Point3<u32>>) -> Self { - ColliderShape(Arc::new(Trimesh::new(vertices, indices))) + ColliderShape(Arc::new(TriMesh::new(vertices, indices))) } /// Initializes an heightfield shape defined by its set of height and a scale @@ -165,8 +166,9 @@ impl<'de> serde::Deserialize<'de> for ColliderShape { Some(ShapeType::Capsule) => deser::<A, Capsule>(&mut seq)?, Some(ShapeType::Triangle) => deser::<A, Triangle>(&mut seq)?, Some(ShapeType::Segment) => deser::<A, Segment>(&mut seq)?, - Some(ShapeType::Trimesh) => deser::<A, Trimesh>(&mut seq)?, + Some(ShapeType::TriMesh) => deser::<A, TriMesh>(&mut seq)?, Some(ShapeType::HeightField) => deser::<A, HeightField>(&mut seq)?, + Some(ShapeType::HalfSpace) => deser::<A, HalfSpace>(&mut seq)?, #[cfg(feature = "dim3")] Some(ShapeType::Cylinder) => deser::<A, Cylinder>(&mut seq)?, #[cfg(feature = "dim3")] diff --git a/src/geometry/contact.rs b/src/geometry/contact.rs index 1f0a902..14646d9 100644 --- a/src/geometry/contact.rs +++ b/src/geometry/contact.rs @@ -6,7 +6,7 @@ use crate::geometry::{Collider, ColliderPair, ColliderSet, Contact, ContactManif use crate::math::{Isometry, Point, Vector}; #[cfg(feature = "simd-is-enabled")] use { - crate::math::{SimdFloat, SIMD_WIDTH}, + crate::math::{SimdReal, SIMD_WIDTH}, simba::simd::SimdValue, }; @@ -22,11 +22,11 @@ bitflags::bitflags! { #[cfg(feature = "simd-is-enabled")] pub(crate) struct WContact { - pub local_p1: Point<SimdFloat>, - pub local_p2: Point<SimdFloat>, - pub local_n1: Vector<SimdFloat>, - pub local_n2: Vector<SimdFloat>, - pub dist: SimdFloat, + pub local_p1: Point<SimdReal>, + pub local_p2: Point<SimdReal>, + pub local_n1: Vector<SimdReal>, + pub local_n2: Vector<SimdReal>, + pub dist: SimdReal, pub fid1: [u8; SIMD_WIDTH], pub fid2: [u8; SIMD_WIDTH], } diff --git a/src/geometry/contact_generator/ball_ball_contact_generator.rs b/src/geometry/contact_generator/ball_ball_contact_generator.rs index 7122998..f2ca7af 100644 --- a/src/geometry/contact_generator/ball_ball_contact_generator.rs +++ b/src/geometry/contact_generator/ball_ball_contact_generator.rs @@ -5,12 +5,12 @@ use crate::math::{Point, Vector}; use { crate::geometry::contact_generator::PrimitiveContactGenerationContextSimd, crate::geometry::{WBall, WContact}, - crate::math::{Isometry, SimdFloat, SIMD_WIDTH}, + crate::math::{Isometry, SimdReal, SIMD_WIDTH}, simba::simd::SimdValue, }; #[cfg(feature = "simd-is-enabled")] -fn generate_contacts_simd(ball1: &WBall, ball2: &WBall, pos21: &Isometry<SimdFloat>) -> WContact { +fn generate_contacts_simd(ball1: &WBall, ball2: &WBall, pos21: &Isometry<SimdReal>) -> WContact { let dcenter = ball2.center - ball1.center; let center_dist = dcenter.magnitude(); let normal = dcenter / center_dist; @@ -30,9 +30,9 @@ fn generate_contacts_simd(ball1: &WBall, ball2: &WBall, pos21: &Isometry<SimdFlo pub fn generate_contacts_ball_ball_simd(ctxt: &mut PrimitiveContactGenerationContextSimd) { let pos_ba = ctxt.positions2.inverse() * ctxt.positions1; let radii_a = - SimdFloat::from(array![|ii| ctxt.shapes1[ii].as_ball().unwrap().radius; SIMD_WIDTH]); + SimdReal::from(array![|ii| ctxt.shapes1[ii].as_ball().unwrap().radius; SIMD_WIDTH]); let radii_b = - SimdFloat::from(array![|ii| ctxt.shapes2[ii].as_ball().unwrap().radius; SIMD_WIDTH]); + SimdReal::from(array![|ii| ctxt.shapes2[ii].as_ball().unwrap().radius; SIMD_WIDTH]); let wball_a = WBall::new(Point::origin(), radii_a); let wball_b = WBall::new(pos_ba.inverse_transform_point(&Point::origin()), radii_b); diff --git a/src/geometry/contact_generator/contact_dispatcher.rs b/src/geometry/contact_generator/contact_dispatcher.rs index 7c32714..9b247f3 100644 --- a/src/geometry/contact_generator/contact_dispatcher.rs +++ b/src/geometry/contact_generator/contact_dispatcher.rs @@ -3,9 +3,9 @@ use crate::geometry::contact_generator::PfmPfmContactManifoldGeneratorWorkspace; use crate::geometry::contact_generator::{ ContactGenerator, ContactGeneratorWorkspace, ContactPhase, HeightFieldShapeContactGeneratorWorkspace, PrimitiveContactGenerator, - TrimeshShapeContactGeneratorWorkspace, + TriMeshShapeContactGeneratorWorkspace, }; -use crate::geometry::ShapeType; +use buckler::shape::ShapeType; /// Trait implemented by structures responsible for selecting a collision-detection algorithm /// for a given pair of shapes. @@ -114,13 +114,13 @@ impl ContactDispatcher for DefaultContactDispatcher { shape2: ShapeType, ) -> (ContactPhase, Option<ContactGeneratorWorkspace>) { match (shape1, shape2) { - (ShapeType::Trimesh, _) | (_, ShapeType::Trimesh) => ( + (ShapeType::TriMesh, _) | (_, ShapeType::TriMesh) => ( ContactPhase::NearPhase(ContactGenerator { generate_contacts: super::generate_contacts_trimesh_shape, ..ContactGenerator::default() }), Some(ContactGeneratorWorkspace::from( - TrimeshShapeContactGeneratorWorkspace::new(), + TriMeshShapeContactGeneratorWorkspace::new(), )), ), (ShapeType::HeightField, _) | (_, ShapeType::HeightField) => ( diff --git a/src/geometry/contact_generator/contact_generator.rs b/src/geometry/contact_generator/contact_generator.rs index b1b1be6..06ab265 100644 --- a/src/geometry/contact_generator/contact_generator.rs +++ b/src/geometry/contact_generator/contact_generator.rs @@ -1,11 +1,11 @@ use crate::data::MaybeSerializableData; use crate::geometry::{ Collider, ColliderSet, ContactDispatcher, ContactEvent, ContactManifold, ContactPair, Shape, - SolverFlags, + ShapeType, SolverFlags, }; use crate::math::Isometry; #[cfg(feature = "simd-is-enabled")] -use crate::math::{SimdFloat, SIMD_WIDTH}; +use crate::math::{SimdReal, SIMD_WIDTH}; use crate::pipeline::EventHandler; #[derive(Copy, Clone)] @@ -158,8 +158,8 @@ pub struct PrimitiveContactGenerationContextSimd<'a, 'b> { pub colliders2: [&'a Collider; SIMD_WIDTH], pub shapes1: [&'a dyn Shape; SIMD_WIDTH], pub shapes2: [&'a dyn Shape; SIMD_WIDTH], - pub positions1: &'a Isometry<SimdFloat>, - pub positions2: &'a Isometry<SimdFloat>, + pub positions1: &'a Isometry<SimdReal>, + pub positions2: &'a Isometry<SimdReal>, pub manifolds: &'a mut [&'b mut ContactManifold], pub workspaces: &'a mut [Option<&'b mut (dyn MaybeSerializableData)>], } diff --git a/src/geometry/contact_generator/contact_generator_workspace.rs b/src/geometry/contact_generator/contact_generator_workspace.rs index e89395f..7aac592 100644 --- a/src/geometry/contact_generator/contact_generator_workspace.rs +++ b/src/geometry/contact_generator/contact_generator_workspace.rs @@ -2,7 +2,7 @@ use crate::data::MaybeSerializableData; #[cfg(feature = "dim3")] use crate::geometry::contact_generator::PfmPfmContactManifoldGeneratorWorkspace; use crate::geometry::contact_generator::{ - HeightFieldShapeContactGeneratorWorkspace, TrimeshShapeContactGeneratorWorkspace, + HeightFieldShapeContactGeneratorWorkspace, TriMeshShapeContactGeneratorWorkspace, WorkspaceSerializationTag, }; @@ -81,8 +81,8 @@ impl<'de> serde::Deserialize<'de> for ContactGeneratorWorkspace { Some(WorkspaceSerializationTag::HeightfieldShapeContactGeneratorWorkspace) => { deser::<A, HeightFieldShapeContactGeneratorWorkspace>(&mut seq)? } - Some(WorkspaceSerializationTag::TrimeshShapeContactGeneratorWorkspace) => { - deser::<A, TrimeshShapeContactGeneratorWorkspace>(&mut seq)? + Some(WorkspaceSerializationTag::TriMeshShapeContactGeneratorWorkspace) => { + deser::<A, TriMeshShapeContactGeneratorWorkspace>(&mut seq)? } #[cfg(feature = "dim3")] Some(WorkspaceSerializationTag::PfmPfmContactGeneratorWorkspace) => { diff --git a/src/geometry/contact_generator/heightfield_shape_contact_generator.rs b/src/geometry/contact_generator/heightfield_shape_contact_generator.rs index 358ac84..125ac34 100644 --- a/src/geometry/contact_generator/heightfield_shape_contact_generator.rs +++ b/src/geometry/contact_generator/heightfield_shape_contact_generator.rs @@ -5,9 +5,10 @@ use crate::geometry::contact_generator::{ ContactGenerationContext, ContactGeneratorWorkspace, PrimitiveContactGenerationContext, PrimitiveContactGenerator, }; +use crate::geometry::{Collider, ContactManifold, ContactManifoldData}; #[cfg(feature = "dim2")] -use crate::geometry::Capsule; -use crate::geometry::{Collider, ContactManifold, ContactManifoldData, HeightField, Shape}; +use buckler::shape::Capsule; +use buckler::shape::{HeightField, Shape}; #[cfg(feature = "serde-serialize")] use erased_serde::Serialize; @@ -95,7 +96,7 @@ fn do_generate_contacts( #[cfg(feature = "dim3")] let sub_shape1 = *part1; - let sub_detector = match workspace.sub_detectors.entry(i) { + let sub_detector = match workspace.sub_detectors.entry(i as usize) { Entry::Occupied(entry) => { let sub_detector = entry.into_mut(); let manifold = workspace.old_manifolds[sub_detector.manifold_id].take(); @@ -119,7 +120,7 @@ fn do_generate_contacts( collider2, solver_flags, ); - manifolds.push(ContactManifold::with_data((i, 0), manifold_data)); + manifolds.push(ContactManifold::with_data((i as usize, 0), manifold_data)); entry.insert(sub_detector) } diff --git a/src/geometry/contact_generator/mod.rs b/src/geometry/contact_generator/mod.rs index f539d7a..4c0716a 100644 --- a/src/geometry/contact_generator/mod.rs +++ b/src/geometry/contact_generator/mod.rs @@ -25,7 +25,7 @@ pub use self::pfm_pfm_contact_generator::{ // pub use self::polygon_polygon_contact_generator::generate_contacts_polygon_polygon; pub use self::contact_generator_workspace::ContactGeneratorWorkspace; pub use self::trimesh_shape_contact_generator::{ - generate_contacts_trimesh_shape, TrimeshShapeContactGeneratorWorkspace, + generate_contacts_trimesh_shape, TriMeshShapeContactGeneratorWorkspace, }; pub(self) use self::serializable_workspace_tag::WorkspaceSerializationTag; diff --git a/src/geometry/contact_generator/serializable_workspace_tag.rs b/src/geometry/contact_generator/serializable_workspace_tag.rs index 2488c1e..4bdb902 100644 --- a/src/geometry/contact_generator/serializable_workspace_tag.rs +++ b/src/geometry/contact_generator/serializable_workspace_tag.rs @@ -2,7 +2,7 @@ use num_derive::FromPrimitive; #[derive(Copy, Clone, Debug, FromPrimitive)] pub(super) enum WorkspaceSerializationTag { - TrimeshShapeContactGeneratorWorkspace = 0, + TriMeshShapeContactGeneratorWorkspace = 0, #[cfg(feature = "dim3")] PfmPfmContactGeneratorWorkspace, HeightfieldShapeContactGeneratorWorkspace, diff --git a/src/geometry/contact_generator/trimesh_shape_contact_generator.rs b/src/geometry/contact_generator/trimesh_shape_contact_generator.rs index 172069d..209ac42 100644 --- a/src/geometry/contact_generator/trimesh_shape_contact_generator.rs +++ b/src/geometry/contact_generator/trimesh_shape_contact_generator.rs @@ -3,21 +3,21 @@ use crate::data::MaybeSerializableData; use crate::geometry::contact_generator::{ ContactGenerationContext, PrimitiveContactGenerationContext, }; -use crate::geometry::{Collider, ContactManifold, ContactManifoldData, ShapeType, Trimesh}; +use crate::geometry::{Collider, ContactManifold, ContactManifoldData, ShapeType, TriMesh}; #[cfg(feature = "serde-serialize")] use erased_serde::Serialize; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[derive(Clone)] -pub struct TrimeshShapeContactGeneratorWorkspace { - interferences: Vec<usize>, +pub struct TriMeshShapeContactGeneratorWorkspace { + interferences: Vec<u32>, local_aabb2: AABB, - old_interferences: Vec<usize>, + old_interferences: Vec<u32>, #[cfg_attr(feature = "serde-serialize", serde(skip))] old_manifolds: Vec<ContactManifold>, } -impl TrimeshShapeContactGeneratorWorkspace { +impl TriMeshShapeContactGeneratorWorkspace { pub fn new() -> Self { Self { interferences: Vec::new(), @@ -40,7 +40,7 @@ pub fn generate_contacts_trimesh_shape(ctxt: &mut ContactGenerationContext) { } fn do_generate_contacts( - trimesh1: &Trimesh, + trimesh1: &TriMesh, collider1: &Collider, collider2: &Collider, ctxt: &mut ContactGenerationContext, @@ -52,14 +52,14 @@ fn do_generate_contacts( ctxt.pair.pair }; - let workspace: &mut TrimeshShapeContactGeneratorWorkspace = ctxt + let workspace: &mut TriMeshShapeContactGeneratorWorkspace = ctxt .pair .generator_workspace .as_mut() - .expect("The TrimeshShapeContactGeneratorWorkspace is missing.") + .expect("The TriMeshShapeContactGeneratorWorkspace is missing.") .0 .downcast_mut() - .expect("Invalid workspace type, expected a TrimeshShapeContactGeneratorWorkspace."); + .expect("Invalid workspace type, expected a TriMeshShapeContactGeneratorWorkspace."); /* * Compute interferences. @@ -97,9 +97,9 @@ fn do_generate_contacts( .iter() .map(|manifold| { if manifold.data.pair.collider1 == ctxt_collider1 { - manifold.subshape_index_pair.0 + manifold.subshape_index_pair.0 as u32 } else { - manifold.subshape_index_pair.1 + manifold.subshape_index_pair.1 as u32 } }) .collect(); @@ -118,7 +118,7 @@ fn do_generate_contacts( workspace.interferences.clear(); trimesh1 - .waabbs() + .quadtree() .intersect_aabb(&local_aabb2, &mut workspace.interferences); workspace.local_aabb2 = local_aabb2; } @@ -134,7 +134,7 @@ fn do_generate_contacts( // TODO: don't redispatch at each frame (we should probably do the same as // the heightfield). for (i, triangle_id) in new_interferences.iter().enumerate() { - if *triangle_id >= trimesh1.num_triangles() { + if *triangle_id >= trimesh1.num_triangles() as u32 { // Because of SIMD padding, the broad-phase may return tiangle indices greater // than the max. continue; @@ -160,7 +160,7 @@ fn do_generate_contacts( ctxt.solver_flags, ); - ContactManifold::with_data((*triangle_id, 0), data) + ContactManifold::with_data((*triangle_id as usize, 0), data) } else { // We already have a manifold for this triangle. old_inter_it.next(); @@ -206,11 +206,11 @@ fn do_generate_contacts( } } -impl MaybeSerializableData for TrimeshShapeContactGeneratorWorkspace { +impl MaybeSerializableData for TriMeshShapeContactGeneratorWorkspace { #[cfg(feature = "serde-serialize")] fn as_serialize(&self) -> Option<(u32, &dyn Serialize)> { Some(( - super::WorkspaceSerializationTag::TrimeshShapeContactGeneratorWorkspace as u32, + super::WorkspaceSerializationTag::TriMeshShapeContactGeneratorWorkspace as u32, self, )) } diff --git a/src/geometry/mod.rs b/src/geometry/mod.rs index caa229a..46fe360 100644 --- a/src/geometry/mod.rs +++ b/src/geometry/mod.rs @@ -13,9 +13,6 @@ pub use self::narrow_phase::NarrowPhase; pub use self::polygon::Polygon; pub use self::proximity::ProximityPair; pub use self::proximity_detector::{DefaultProximityDispatcher, ProximityDispatcher}; -#[cfg(feature = "dim3")] -pub use self::round_cylinder::RoundCylinder; -pub use self::trimesh::Trimesh; pub use self::user_callbacks::{ContactPairFilter, PairFilterContext, ProximityPairFilter}; pub use buckler::query::Proximity; @@ -106,11 +103,10 @@ pub(crate) use self::collider_set::RemovedCollider; #[cfg(feature = "simd-is-enabled")] pub(crate) use self::contact::WContact; pub(crate) use self::narrow_phase::ContactManifoldIndex; -pub(crate) use self::waabb::{WRay, WAABB}; -pub(crate) use self::wquadtree::WQuadtree; +pub(crate) use buckler::partitioning::WQuadtree; //pub(crate) use self::z_order::z_cmp_floats; pub use self::interaction_groups::InteractionGroups; -pub use self::shape::{Shape, ShapeType}; +pub use buckler::shape::*; mod ball; mod broad_phase_multi_sap; @@ -125,12 +121,6 @@ mod proximity; mod proximity_detector; pub(crate) mod sat; pub(crate) mod triangle; -mod trimesh; -mod waabb; -mod wquadtree; //mod z_order; mod interaction_groups; -#[cfg(feature = "dim3")] -mod round_cylinder; -mod shape; mod user_callbacks; diff --git a/src/geometry/narrow_phase.rs b/src/geometry/narrow_phase.rs index 463dd99..ad2d514 100644 --- a/src/geometry/narrow_phase.rs +++ b/src/geometry/narrow_phase.rs @@ -20,7 +20,7 @@ use crate::geometry::{ }; use crate::geometry::{ColliderSet, ContactManifold, ContactPair, InteractionGraph}; //#[cfg(feature = "simd-is-enabled")] -//use crate::math::{SimdFloat, SIMD_WIDTH}; +//use crate::math::{SimdReal, SIMD_WIDTH}; use crate::buckler::query::Proximity; use crate::data::pubsub::Subscription; use crate::data::Coarena; diff --git a/src/geometry/proximity_detector/ball_ball_proximity_detector.rs b/src/geometry/proximity_detector/ball_ball_proximity_detector.rs index 2106c9f..65c141c 100644 --- a/src/geometry/proximity_detector/ball_ball_proximity_detector.rs +++ b/src/geometry/proximity_detector/ball_ball_proximity_detector.rs @@ -5,12 +5,12 @@ use crate::math::Point; #[cfg(feature = "simd-is-enabled")] use { crate::geometry::{proximity_detector::PrimitiveProximityDetectionContextSimd, WBall}, - crate::math::{SimdFloat, SIMD_WIDTH}, + crate::math::{SimdReal, SIMD_WIDTH}, simba::simd::SimdValue, }; #[cfg(feature = "simd-is-enabled")] -fn ball_distance_simd(ball1: &WBall, ball2: &WBall) -> SimdFloat { +fn ball_distance_simd(ball1: &WBall, ball2: &WBall) -> SimdReal { let dcenter = ball2.center - ball1.center; let center_dist = dcenter.magnitude(); center_dist - ball1.radius - ball2.radius @@ -22,9 +22,9 @@ pub fn detect_proximity_ball_ball_simd( ) -> [Proximity; SIMD_WIDTH] { let pos_ba = ctxt.positions2.inverse() * ctxt.positions1; let radii_a = - SimdFloat::from(array![|ii| ctxt.shapes1[ii].as_ball().unwrap().radius; SIMD_WIDTH]); + SimdReal::from(array![|ii| ctxt.shapes1[ii].as_ball().unwrap().radius; SIMD_WIDTH]); let radii_b = - SimdFloat::from(array![|ii| ctxt.shapes2[ii].as_ball().unwrap().radius; SIMD_WIDTH]); + SimdReal::from(array![|ii| ctxt.shapes2[ii].as_ball().unwrap().radius; SIMD_WIDTH]); let wball_a = WBall::new(Point::origin(), radii_a); let wball_b = WBall::new(pos_ba.inverse_transform_point(&Point::origin()), radii_b); diff --git a/src/geometry/proximity_detector/mod.rs b/src/geometry/proximity_detector/mod.rs index a99372f..fc904da 100644 --- a/src/geometry/proximity_detector/mod.rs +++ b/src/geometry/proximity_detector/mod.rs @@ -15,7 +15,7 @@ pub use self::proximity_detector::{ }; pub use self::proximity_dispatcher::{DefaultProximityDispatcher, ProximityDispatcher}; pub use self::trimesh_shape_proximity_detector::{ - detect_proximity_trimesh_shape, TrimeshShapeProximityDetectorWorkspace, + detect_proximity_trimesh_shape, TriMeshShapeProximityDetectorWorkspace, }; mod ball_ball_proximity_detector; diff --git a/src/geometry/proximity_detector/proximity_detector.rs b/src/geometry/proximity_detector/proximity_detector.rs index 7c8ad20..ea362de 100644 --- a/src/geometry/proximity_detector/proximity_detector.rs +++ b/src/geometry/proximity_detector/proximity_detector.rs @@ -3,7 +3,7 @@ use crate::geometry::{ }; use crate::math::Isometry; #[cfg(feature = "simd-is-enabled")] -use crate::math::{SimdFloat, SIMD_WIDTH}; +use crate::math::{SimdReal, SIMD_WIDTH}; use crate::pipeline::EventHandler; use std::any::Any; @@ -134,8 +134,8 @@ pub struct PrimitiveProximityDetectionContextSimd<'a, 'b> { pub colliders2: [&'a Collider; SIMD_WIDTH], pub shapes1: [&'a dyn Shape; SIMD_WIDTH], pub shapes2: [&'a dyn Shape; SIMD_WIDTH], - pub positions1: &'a Isometry<SimdFloat>, - pub positions2: &'a Isometry<SimdFloat>, + pub positions1: &'a Isometry<SimdReal>, + pub positions2: &'a Isometry<SimdReal>, pub workspaces: &'a mut [Option<&'b mut (dyn Any + Send + Sync)>], } diff --git a/src/geometry/proximity_detector/proximity_dispatcher.rs b/src/geometry/proximity_detector/proximity_dispatcher.rs index 768aca6..709521e 100644 --- a/src/geometry/proximity_detector/proximity_dispatcher.rs +++ b/src/geometry/proximity_detector/proximity_dispatcher.rs @@ -1,6 +1,6 @@ use crate::geometry::proximity_detector::{ PrimitiveProximityDetector, ProximityDetector, ProximityPhase, - TrimeshShapeProximityDetectorWorkspace, + TriMeshShapeProximityDetectorWorkspace, }; use crate::geometry::ShapeType; use std::any::Any; @@ -113,19 +113,19 @@ impl ProximityDispatcher for DefaultProximityDispatcher { shape2: ShapeType, ) -> (ProximityPhase, Option<Box<dyn Any + Send + Sync>>) { match (shape1, shape2) { - (ShapeType::Trimesh, _) => ( + (ShapeType::TriMesh, _) => ( ProximityPhase::NearPhase(ProximityDetector { detect_proximity: super::detect_proximity_trimesh_shape, ..ProximityDetector::default() }), - Some(Box::new(TrimeshShapeProximityDetectorWorkspace::new())), + Some(Box::new(TriMeshShapeProximityDetectorWorkspace::new())), ), - (_, ShapeType::Trimesh) => ( + (_, ShapeType::TriMesh) => ( ProximityPhase::NearPhase(ProximityDetector { detect_proximity: super::detect_proximity_trimesh_shape, ..ProximityDetector::default() }), - Some(Box::new(TrimeshShapeProximityDetectorWorkspace::new())), + Some(Box::new(TriMeshShapeProximityDetectorWorkspace::new())), ), _ => { let (gen, workspace) = self.dispatch_primitives(shape1, shape2); diff --git a/src/geometry/proximity_detector/trimesh_shape_proximity_detector.rs b/src/geometry/proximity_detector/trimesh_shape_proximity_detector.rs index 5366b39..dbb20f5 100644 --- a/src/geometry/proximity_detector/trimesh_shape_proximity_detector.rs +++ b/src/geometry/proximity_detector/trimesh_shape_proximity_detector.rs @@ -2,15 +2,15 @@ use crate::buckler::bounding_volume::{BoundingVolume, AABB}; use crate::geometry::proximity_detector::{ PrimitiveProximityDetectionContext, ProximityDetectionContext, }; -use crate::geometry::{Collider, Proximity, ShapeType, Trimesh}; +use crate::geometry::{Collider, Proximity, ShapeType, TriMesh}; -pub struct TrimeshShapeProximityDetectorWorkspace { - interferences: Vec<usize>, +pub struct TriMeshShapeProximityDetectorWorkspace { + interferences: Vec<u32>, local_aabb2: AABB, - old_interferences: Vec<usize>, + old_interferences: Vec<u32>, } -impl TrimeshShapeProximityDetectorWorkspace { +impl TriMeshShapeProximityDetectorWorkspace { pub fn new() -> Self { Self { interferences: Vec::new(), @@ -34,18 +34,18 @@ pub fn detect_proximity_trimesh_shape(ctxt: &mut ProximityDetectionContext) -> P } fn do_detect_proximity( - trimesh1: &Trimesh, + trimesh1: &TriMesh, collider1: &Collider, collider2: &Collider, ctxt: &mut ProximityDetectionContext, ) -> Proximity { - let workspace: &mut TrimeshShapeProximityDetectorWorkspace = ctxt + let workspace: &mut TriMeshShapeProximityDetectorWorkspace = ctxt .pair .detector_workspace .as_mut() - .expect("The TrimeshShapeProximityDetectorWorkspace is missing.") + .expect("The TriMeshShapeProximityDetectorWorkspace is missing.") .downcast_mut() - .expect("Invalid workspace type, expected a TrimeshShapeProximityDetectorWorkspace."); + .expect("Invalid workspace type, expected a TriMeshShapeProximityDetectorWorkspace."); /* * Compute interferences. @@ -72,7 +72,7 @@ fn do_detect_proximity( workspace.interferences.clear(); trimesh1 - .waabbs() + .quadtree() .intersect_aabb(&local_aabb2, &mut workspace.interferences); workspace.local_aabb2 = local_aabb2; } @@ -86,7 +86,7 @@ fn do_detect_proximity( let shape_type2 = collider2.shape().shape_type(); for triangle_id in new_interferences.iter() { - if *triangle_id >= trimesh1.num_triangles() { + if *triangle_id >= trimesh1.num_triangles() as u32 { // Because of SIMD padding, the broad-phase may return tiangle indices greater // than the max. continue; diff --git a/src/geometry/round_cylinder.rs b/src/geometry/round_cylinder.rs deleted file mode 100644 index 450a9fc..0000000 --- a/src/geometry/round_cylinder.rs +++ /dev/null @@ -1,92 +0,0 @@ -use crate::geometry::Cylinder; -use crate::math::{Isometry, Point, Vector}; -use buckler::query::{ - gjk::VoronoiSimplex, PointProjection, PointQuery, Ray, RayCast, RayIntersection, -}; -use buckler::shape::{FeatureId, SupportMap}; -use na::Unit; - -/// A rounded cylinder. -#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] -#[derive(Copy, Clone, Debug)] -pub struct RoundCylinder { - /// The cylinder being rounded. - pub cylinder: Cylinder, - /// The rounding radius. - pub border_radius: f32, -} - -impl RoundCylinder { - /// Create sa new cylinder where all its edges and vertices are rounded by a radius of `radius`. - /// - /// This is done by applying a dilation of the given radius to the cylinder. - pub fn new(half_height: f32, radius: f32, border_radius: f32) -> Self { - Self { - cylinder: Cylinder::new(half_height, radius), - border_radius, - } - } -} - -impl SupportMap for RoundCylinder { - fn local_support_point(&self, dir: &Vector<f32>) -> Point<f32> { - self.local_support_point_toward(&Unit::new_normalize(*dir)) - } - - fn local_support_point_toward(&self, dir: &Unit<Vector<f32>>) -> Point<f32> { - self.cylinder.local_support_point_toward(dir) + **dir * self.border_radius - } - |
