aboutsummaryrefslogtreecommitdiff
path: root/src/geometry/contact_generator
diff options
context:
space:
mode:
Diffstat (limited to 'src/geometry/contact_generator')
-rw-r--r--src/geometry/contact_generator/ball_convex_contact_generator.rs23
-rw-r--r--src/geometry/contact_generator/capsule_capsule_contact_generator.rs15
-rw-r--r--src/geometry/contact_generator/contact_dispatcher.rs78
-rw-r--r--src/geometry/contact_generator/cuboid_capsule_contact_generator.rs8
-rw-r--r--src/geometry/contact_generator/cuboid_cuboid_contact_generator.rs2
-rw-r--r--src/geometry/contact_generator/cuboid_triangle_contact_generator.rs6
-rw-r--r--src/geometry/contact_generator/heightfield_shape_contact_generator.rs35
-rw-r--r--src/geometry/contact_generator/mod.rs2
-rw-r--r--src/geometry/contact_generator/polygon_polygon_contact_generator.rs29
-rw-r--r--src/geometry/contact_generator/trimesh_shape_contact_generator.rs11
10 files changed, 101 insertions, 108 deletions
diff --git a/src/geometry/contact_generator/ball_convex_contact_generator.rs b/src/geometry/contact_generator/ball_convex_contact_generator.rs
index 0856029..62ebfab 100644
--- a/src/geometry/contact_generator/ball_convex_contact_generator.rs
+++ b/src/geometry/contact_generator/ball_convex_contact_generator.rs
@@ -5,30 +5,17 @@ use na::Unit;
use ncollide::query::PointQuery;
pub fn generate_contacts_ball_convex(ctxt: &mut PrimitiveContactGenerationContext) {
- if let Shape::Ball(ball1) = ctxt.shape1 {
+ if let Some(ball1) = ctxt.shape1.as_ball() {
ctxt.manifold.swap_identifiers();
-
- match ctxt.shape2 {
- Shape::Triangle(tri2) => do_generate_contacts(tri2, ball1, ctxt, true),
- Shape::Cuboid(cube2) => do_generate_contacts(cube2, ball1, ctxt, true),
- Shape::Capsule(capsule2) => do_generate_contacts(capsule2, ball1, ctxt, true),
- Shape::Cylinder(cylinder2) => do_generate_contacts(cylinder2, ball1, ctxt, true),
- _ => unimplemented!(),
- }
- } else if let Shape::Ball(ball2) = ctxt.shape2 {
- match ctxt.shape1 {
- Shape::Triangle(tri1) => do_generate_contacts(tri1, ball2, ctxt, false),
- Shape::Cuboid(cube1) => do_generate_contacts(cube1, ball2, ctxt, false),
- Shape::Capsule(capsule1) => do_generate_contacts(capsule1, ball2, ctxt, false),
- Shape::Cylinder(cylinder1) => do_generate_contacts(cylinder1, ball2, ctxt, false),
- _ => unimplemented!(),
- }
+ do_generate_contacts(ctxt.shape2, ball1, ctxt, true);
+ } else if let Some(ball2) = ctxt.shape2.as_ball() {
+ do_generate_contacts(ctxt.shape1, ball2, ctxt, false);
}
ctxt.manifold.sort_contacts(ctxt.prediction_distance);
}
-fn do_generate_contacts<P: PointQuery<f32>>(
+fn do_generate_contacts<P: ?Sized + PointQuery<f32>>(
point_query1: &P,
ball2: &Ball,
ctxt: &mut PrimitiveContactGenerationContext,
diff --git a/src/geometry/contact_generator/capsule_capsule_contact_generator.rs b/src/geometry/contact_generator/capsule_capsule_contact_generator.rs
index 3800ce6..4d9bbc7 100644
--- a/src/geometry/contact_generator/capsule_capsule_contact_generator.rs
+++ b/src/geometry/contact_generator/capsule_capsule_contact_generator.rs
@@ -8,7 +8,7 @@ use na::Unit;
use ncollide::shape::{Segment, SegmentPointLocation};
pub fn generate_contacts_capsule_capsule(ctxt: &mut PrimitiveContactGenerationContext) {
- if let (Shape::Capsule(capsule1), Shape::Capsule(capsule2)) = (ctxt.shape1, ctxt.shape2) {
+ if let (Some(capsule1), Some(capsule2)) = (ctxt.shape1.as_capsule(), ctxt.shape2.as_capsule()) {
generate_contacts(
ctxt.prediction_distance,
capsule1,
@@ -94,7 +94,7 @@ pub fn generate_contacts<'a>(
if dir1.dot(&dir2).abs() >= crate::utils::COS_FRAC_PI_8
&& dir1.dot(&local_n1).abs() < crate::utils::SIN_FRAC_PI_8
{
- // Capsules axii are almost parallel and are almost perpendicular to the normal.
+ // Capsules axes are almost parallel and are almost perpendicular to the normal.
// Find a second contact point.
if let Some((clip_a, clip_b)) = crate::geometry::clip_segments_with_normal(
(capsule1.a, capsule1.b),
@@ -156,17 +156,18 @@ pub fn generate_contacts<'a>(
let pos12 = pos1.inverse() * pos2;
let pos21 = pos12.inverse();
- let capsule2_1 = capsule1.transform_by(&pos12);
+ let seg1 = capsule1.segment();
+ let seg2_1 = capsule2.segment().transformed(&pos12);
let (loc1, loc2) = ncollide::query::closest_points_segment_segment_with_locations_nD(
- (&capsule1.a, &capsule1.b),
- (&capsule2_1.a, &capsule2_1.b),
+ (&seg1.a, &seg1.b),
+ (&seg2_1.a, &seg2_1.b),
);
{
let bcoords1 = loc1.barycentric_coordinates();
let bcoords2 = loc2.barycentric_coordinates();
- let local_p1 = capsule1.a * bcoords1[0] + capsule1.b.coords * bcoords1[1];
- let local_p2 = capsule2_1.a * bcoords2[0] + capsule2_1.b.coords * bcoords2[1];
+ let local_p1 = seg1.a * bcoords1[0] + seg1.b.coords * bcoords1[1];
+ let local_p2 = seg2_1.a * bcoords2[0] + seg2_1.b.coords * bcoords2[1];
let local_n1 =
Unit::try_new(local_p2 - local_p1, f32::default_epsilon()).unwrap_or(Vector::y_axis());
diff --git a/src/geometry/contact_generator/contact_dispatcher.rs b/src/geometry/contact_generator/contact_dispatcher.rs
index e925fd5..01bbc46 100644
--- a/src/geometry/contact_generator/contact_dispatcher.rs
+++ b/src/geometry/contact_generator/contact_dispatcher.rs
@@ -3,7 +3,7 @@ use crate::geometry::contact_generator::{
PfmPfmContactManifoldGeneratorWorkspace, PrimitiveContactGenerator,
TrimeshShapeContactGeneratorWorkspace,
};
-use crate::geometry::Shape;
+use crate::geometry::{Shape, ShapeType};
use std::any::Any;
/// Trait implemented by structures responsible for selecting a collision-detection algorithm
@@ -12,8 +12,8 @@ pub trait ContactDispatcher {
/// Select the collision-detection algorithm for the given pair of primitive shapes.
fn dispatch_primitives(
&self,
- shape1: &Shape,
- shape2: &Shape,
+ shape1: ShapeType,
+ shape2: ShapeType,
) -> (
PrimitiveContactGenerator,
Option<Box<dyn Any + Send + Sync>>,
@@ -21,8 +21,8 @@ pub trait ContactDispatcher {
/// Select the collision-detection algorithm for the given pair of non-primitive shapes.
fn dispatch(
&self,
- shape1: &Shape,
- shape2: &Shape,
+ shape1: ShapeType,
+ shape2: ShapeType,
) -> (ContactPhase, Option<Box<dyn Any + Send + Sync>>);
}
@@ -32,14 +32,14 @@ pub struct DefaultContactDispatcher;
impl ContactDispatcher for DefaultContactDispatcher {
fn dispatch_primitives(
&self,
- shape1: &Shape,
- shape2: &Shape,
+ shape1: ShapeType,
+ shape2: ShapeType,
) -> (
PrimitiveContactGenerator,
Option<Box<dyn Any + Send + Sync>>,
) {
match (shape1, shape2) {
- (Shape::Ball(_), Shape::Ball(_)) => (
+ (ShapeType::Ball, ShapeType::Ball) => (
PrimitiveContactGenerator {
generate_contacts: super::generate_contacts_ball_ball,
#[cfg(feature = "simd-is-enabled")]
@@ -48,56 +48,58 @@ impl ContactDispatcher for DefaultContactDispatcher {
},
None,
),
- (Shape::Cuboid(_), Shape::Cuboid(_)) => (
+ (ShapeType::Cuboid, ShapeType::Cuboid) => (
PrimitiveContactGenerator {
generate_contacts: super::generate_contacts_cuboid_cuboid,
..PrimitiveContactGenerator::default()
},
None,
),
- (Shape::Polygon(_), Shape::Polygon(_)) => (
- PrimitiveContactGenerator {
- generate_contacts: super::generate_contacts_polygon_polygon,
- ..PrimitiveContactGenerator::default()
- },
- None,
- ),
- (Shape::Capsule(_), Shape::Capsule(_)) => (
+ // (ShapeType::Polygon, ShapeType::Polygon) => (
+ // PrimitiveContactGenerator {
+ // generate_contacts: super::generate_contacts_polygon_polygon,
+ // ..PrimitiveContactGenerator::default()
+ // },
+ // None,
+ // ),
+ (ShapeType::Capsule, ShapeType::Capsule) => (
PrimitiveContactGenerator {
generate_contacts: super::generate_contacts_capsule_capsule,
..PrimitiveContactGenerator::default()
},
None,
),
- (Shape::Cuboid(_), Shape::Ball(_))
- | (Shape::Ball(_), Shape::Cuboid(_))
- | (Shape::Triangle(_), Shape::Ball(_))
- | (Shape::Ball(_), Shape::Triangle(_))
- | (Shape::Capsule(_), Shape::Ball(_))
- | (Shape::Ball(_), Shape::Capsule(_))
- | (Shape::Cylinder(_), Shape::Ball(_))
- | (Shape::Ball(_), Shape::Cylinder(_)) => (
+ (ShapeType::Cuboid, ShapeType::Ball)
+ | (ShapeType::Ball, ShapeType::Cuboid)
+ | (ShapeType::Triangle, ShapeType::Ball)
+ | (ShapeType::Ball, ShapeType::Triangle)
+ | (ShapeType::Capsule, ShapeType::Ball)
+ | (ShapeType::Ball, ShapeType::Capsule)
+ | (ShapeType::Cylinder, ShapeType::Ball)
+ | (ShapeType::Ball, ShapeType::Cylinder) => (
PrimitiveContactGenerator {
generate_contacts: super::generate_contacts_ball_convex,
..PrimitiveContactGenerator::default()
},
None,
),
- (Shape::Capsule(_), Shape::Cuboid(_)) | (Shape::Cuboid(_), Shape::Capsule(_)) => (
+ (ShapeType::Capsule, ShapeType::Cuboid) | (ShapeType::Cuboid, ShapeType::Capsule) => (
PrimitiveContactGenerator {
generate_contacts: super::generate_contacts_cuboid_capsule,
..PrimitiveContactGenerator::default()
},
None,
),
- (Shape::Triangle(_), Shape::Cuboid(_)) | (Shape::Cuboid(_), Shape::Triangle(_)) => (
- PrimitiveContactGenerator {
- generate_contacts: super::generate_contacts_cuboid_triangle,
- ..PrimitiveContactGenerator::default()
- },
- None,
- ),
- (Shape::Cylinder(_), _) | (_, Shape::Cylinder(_)) => (
+ (ShapeType::Triangle, ShapeType::Cuboid) | (ShapeType::Cuboid, ShapeType::Triangle) => {
+ (
+ PrimitiveContactGenerator {
+ generate_contacts: super::generate_contacts_cuboid_triangle,
+ ..PrimitiveContactGenerator::default()
+ },
+ None,
+ )
+ }
+ (ShapeType::Cylinder, _) | (_, ShapeType::Cylinder) => (
PrimitiveContactGenerator {
generate_contacts: super::generate_contacts_pfm_pfm,
..PrimitiveContactGenerator::default()
@@ -110,18 +112,18 @@ impl ContactDispatcher for DefaultContactDispatcher {
fn dispatch(
&self,
- shape1: &Shape,
- shape2: &Shape,
+ shape1: ShapeType,
+ shape2: ShapeType,
) -> (ContactPhase, Option<Box<dyn Any + Send + Sync>>) {
match (shape1, shape2) {
- (Shape::Trimesh(_), _) | (_, Shape::Trimesh(_)) => (
+ (ShapeType::Trimesh, _) | (_, ShapeType::Trimesh) => (
ContactPhase::NearPhase(ContactGenerator {
generate_contacts: super::generate_contacts_trimesh_shape,
..ContactGenerator::default()
}),
Some(Box::new(TrimeshShapeContactGeneratorWorkspace::new())),
),
- (Shape::HeightField(_), _) | (_, Shape::HeightField(_)) => (
+ (ShapeType::HeightField, _) | (_, ShapeType::HeightField) => (
ContactPhase::NearPhase(ContactGenerator {
generate_contacts: super::generate_contacts_heightfield_shape,
..ContactGenerator::default()
diff --git a/src/geometry/contact_generator/cuboid_capsule_contact_generator.rs b/src/geometry/contact_generator/cuboid_capsule_contact_generator.rs
index a7857a1..c3cf588 100644
--- a/src/geometry/contact_generator/cuboid_capsule_contact_generator.rs
+++ b/src/geometry/contact_generator/cuboid_capsule_contact_generator.rs
@@ -9,7 +9,7 @@ use crate::math::Vector;
use ncollide::shape::Segment;
pub fn generate_contacts_cuboid_capsule(ctxt: &mut PrimitiveContactGenerationContext) {
- if let (Shape::Cuboid(cube1), Shape::Capsule(capsule2)) = (ctxt.shape1, ctxt.shape2) {
+ if let (Some(cube1), Some(capsule2)) = (ctxt.shape1.as_cuboid(), ctxt.shape2.as_capsule()) {
generate_contacts(
ctxt.prediction_distance,
cube1,
@@ -20,7 +20,9 @@ pub fn generate_contacts_cuboid_capsule(ctxt: &mut PrimitiveContactGenerationCon
false,
);
ctxt.manifold.update_warmstart_multiplier();
- } else if let (Shape::Capsule(capsule1), Shape::Cuboid(cube2)) = (ctxt.shape1, ctxt.shape2) {
+ } else if let (Some(capsule1), Some(cube2)) =
+ (ctxt.shape1.as_capsule(), ctxt.shape2.as_cuboid())
+ {
generate_contacts(
ctxt.prediction_distance,
cube2,
@@ -53,7 +55,7 @@ pub fn generate_contacts<'a>(
return;
}
- let segment2 = Segment::new(capsule2.a, capsule2.b);
+ let segment2 = capsule2.segment();
/*
*
diff --git a/src/geometry/contact_generator/cuboid_cuboid_contact_generator.rs b/src/geometry/contact_generator/cuboid_cuboid_contact_generator.rs
index d879a22..596cfb1 100644
--- a/src/geometry/contact_generator/cuboid_cuboid_contact_generator.rs
+++ b/src/geometry/contact_generator/cuboid_cuboid_contact_generator.rs
@@ -6,7 +6,7 @@ use crate::math::Vector;
use ncollide::shape::Cuboid;
pub fn generate_contacts_cuboid_cuboid(ctxt: &mut PrimitiveContactGenerationContext) {
- if let (Shape::Cuboid(cube1), Shape::Cuboid(cube2)) = (ctxt.shape1, ctxt.shape2) {
+ if let (Some(cube1), Some(cube2)) = (ctxt.shape1.as_cuboid(), ctxt.shape2.as_cuboid()) {
generate_contacts(
ctxt.prediction_distance,
cube1,
diff --git a/src/geometry/contact_generator/cuboid_triangle_contact_generator.rs b/src/geometry/contact_generator/cuboid_triangle_contact_generator.rs
index 1a0358d..6744c0e 100644
--- a/src/geometry/contact_generator/cuboid_triangle_contact_generator.rs
+++ b/src/geometry/contact_generator/cuboid_triangle_contact_generator.rs
@@ -10,7 +10,7 @@ use crate::{
};
pub fn generate_contacts_cuboid_triangle(ctxt: &mut PrimitiveContactGenerationContext) {
- if let (Shape::Cuboid(cube1), Shape::Triangle(triangle2)) = (ctxt.shape1, ctxt.shape2) {
+ if let (Some(cube1), Some(triangle2)) = (ctxt.shape1.as_cuboid(), ctxt.shape2.as_triangle()) {
generate_contacts(
ctxt.prediction_distance,
cube1,
@@ -21,7 +21,9 @@ pub fn generate_contacts_cuboid_triangle(ctxt: &mut PrimitiveContactGenerationCo
false,
);
ctxt.manifold.update_warmstart_multiplier();
- } else if let (Shape::Triangle(triangle1), Shape::Cuboid(cube2)) = (ctxt.shape1, ctxt.shape2) {
+ } else if let (Some(triangle1), Some(cube2)) =
+ (ctxt.shape1.as_triangle(), ctxt.shape2.as_cuboid())
+ {
generate_contacts(
ctxt.prediction_distance,
cube2,
diff --git a/src/geometry/contact_generator/heightfield_shape_contact_generator.rs b/src/geometry/contact_generator/heightfield_shape_contact_generator.rs
index 04afc65..f507caf 100644
--- a/src/geometry/contact_generator/heightfield_shape_contact_generator.rs
+++ b/src/geometry/contact_generator/heightfield_shape_contact_generator.rs
@@ -3,7 +3,7 @@ use crate::geometry::contact_generator::{
};
#[cfg(feature = "dim2")]
use crate::geometry::Capsule;
-use crate::geometry::{Collider, ContactManifold, HeightField, Shape};
+use crate::geometry::{Collider, ContactManifold, HeightField, Shape, ShapeType};
use crate::ncollide::bounding_volume::BoundingVolume;
#[cfg(feature = "dim3")]
use crate::{geometry::Triangle, math::Point};
@@ -38,9 +38,9 @@ pub fn generate_contacts_heightfield_shape(ctxt: &mut ContactGenerationContext)
let collider1 = &ctxt.colliders[ctxt.pair.pair.collider1];
let collider2 = &ctxt.colliders[ctxt.pair.pair.collider2];
- if let Shape::HeightField(heightfield1) = collider1.shape() {
+ if let Some(heightfield1) = collider1.shape().as_heightfield() {
do_generate_contacts(heightfield1, collider1, collider2, ctxt, false)
- } else if let Shape::HeightField(heightfield2) = collider2.shape() {
+ } else if let Some(heightfield2) = collider2.shape().as_heightfield() {
do_generate_contacts(heightfield2, collider2, collider1, ctxt, true)
}
}
@@ -59,6 +59,7 @@ fn do_generate_contacts(
.expect("The HeightFieldShapeContactGeneratorWorkspace is missing.")
.downcast_mut()
.expect("Invalid workspace type, expected a HeightFieldShapeContactGeneratorWorkspace.");
+ let shape_type2 = collider2.shape().shape_type();
/*
* Detect if the detector context has been reset.
@@ -76,19 +77,9 @@ fn do_generate_contacts(
// subshape_id, manifold.subshape_index_pair
// );
- // Use dummy shapes for the dispatch.
- #[cfg(feature = "dim2")]
- let sub_shape1 =
- Shape::Capsule(Capsule::new(na::Point::origin(), na::Point::origin(), 0.0));
- #[cfg(feature = "dim3")]
- let sub_shape1 = Shape::Triangle(Triangle::new(
- Point::origin(),
- Point::origin(),
- Point::origin(),
- ));
let (generator, workspace2) = ctxt
.dispatcher
- .dispatch_primitives(&sub_shape1, collider2.shape());
+ .dispatch_primitives(ShapeType::Capsule, shape_type2);
let sub_detector = SubDetector {
generator,
@@ -120,12 +111,18 @@ fn do_generate_contacts(
let manifolds = &mut ctxt.pair.manifolds;
let prediction_distance = ctxt.prediction_distance;
let dispatcher = ctxt.dispatcher;
+ let shape_type2 = collider2.shape().shape_type();
heightfield1.map_elements_in_local_aabb(&ls_aabb2, &mut |i, part1, _| {
+ let position1 = *collider1.position();
#[cfg(feature = "dim2")]
- let sub_shape1 = Shape::Capsule(Capsule::new(part1.a, part1.b, 0.0));
+ let (position1, sub_shape1) = {
+ let (dpos, height) = crate::utils::segment_to_capsule(&part1.a, &part1.b);
+ (position1 * dpos, Capsule::new(height, 0.0));
+ };
#[cfg(feature = "dim3")]
- let sub_shape1 = Shape::Triangle(*part1);
+ let sub_shape1 = *part1;
+
let sub_detector = match workspace.sub_detectors.entry(i) {
Entry::Occupied(entry) => {
let sub_detector = entry.into_mut();
@@ -137,7 +134,7 @@ fn do_generate_contacts(
}
Entry::Vacant(entry) => {
let (generator, workspace2) =
- dispatcher.dispatch_primitives(&sub_shape1, collider2.shape());
+ dispatcher.dispatch_primitives(ShapeType::Triangle, shape_type2);
let sub_detector = SubDetector {
generator,
manifold_id: manifolds.len(),
@@ -162,7 +159,7 @@ fn do_generate_contacts(
shape1: collider2.shape(),
shape2: &sub_shape1,
position1: collider2.position(),
- position2: collider1.position(),
+ position2: &position1,
manifold,
workspace: sub_detector.workspace.as_deref_mut(),
}
@@ -173,7 +170,7 @@ fn do_generate_contacts(
collider2,
shape1: &sub_shape1,
shape2: collider2.shape(),
- position1: collider1.position(),
+ position1: &position1,
position2: collider2.position(),
manifold,
workspace: sub_detector.workspace.as_deref_mut(),
diff --git a/src/geometry/contact_generator/mod.rs b/src/geometry/contact_generator/mod.rs
index d8a523f..0549420 100644
--- a/src/geometry/contact_generator/mod.rs
+++ b/src/geometry/contact_generator/mod.rs
@@ -22,7 +22,7 @@ pub use self::heightfield_shape_contact_generator::{
pub use self::pfm_pfm_contact_generator::{
generate_contacts_pfm_pfm, PfmPfmContactManifoldGeneratorWorkspace,
};
-pub use self::polygon_polygon_contact_generator::generate_contacts_polygon_polygon;
+// pub use self::polygon_polygon_contact_generator::generate_contacts_polygon_polygon;
pub use self::trimesh_shape_contact_generator::{
generate_contacts_trimesh_shape, TrimeshShapeContactGeneratorWorkspace,
};
diff --git a/src/geometry/contact_generator/polygon_polygon_contact_generator.rs b/src/geometry/contact_generator/polygon_polygon_contact_generator.rs
index 33b54e4..c150e83 100644
--- a/src/geometry/contact_generator/polygon_polygon_contact_generator.rs
+++ b/src/geometry/contact_generator/polygon_polygon_contact_generator.rs
@@ -5,20 +5,21 @@ use crate::math::{Isometry, Point};
use crate::{math::Vector, utils};
pub fn generate_contacts_polygon_polygon(ctxt: &mut PrimitiveContactGenerationContext) {
- if let (Shape::Polygon(polygon1), Shape::Polygon(polygon2)) = (ctxt.shape1, ctxt.shape2) {
- generate_contacts(
- polygon1,
- &ctxt.position1,
- polygon2,
- &ctxt.position2,
- ctxt.manifold,
- );
- ctxt.manifold.update_warmstart_multiplier();
- } else {
- unreachable!()
- }
-
- ctxt.manifold.sort_contacts(ctxt.prediction_distance);
+ unimplemented!()
+ // if let (Shape::Polygon(polygon1), Shape::Polygon(polygon2)) = (ctxt.shape1, ctxt.shape2) {
+ // generate_contacts(
+ // polygon1,
+ // &ctxt.position1,
+ // polygon2,
+ // &ctxt.position2,
+ // ctxt.manifold,
+ // );
+ // ctxt.manifold.update_warmstart_multiplier();
+ // } else {
+ // unreachable!()
+ // }
+ //
+ // ctxt.manifold.sort_contacts(ctxt.prediction_distance);
}
fn generate_contacts<'a>(
diff --git a/src/geometry/contact_generator/trimesh_shape_contact_generator.rs b/src/geometry/contact_generator/trimesh_shape_contact_generator.rs
index 52ba9b7..49e9b40 100644
--- a/src/geometry/contact_generator/trimesh_shape_contact_generator.rs
+++ b/src/geometry/contact_generator/trimesh_shape_contact_generator.rs
@@ -1,7 +1,7 @@
use crate::geometry::contact_generator::{
ContactGenerationContext, PrimitiveContactGenerationContext,
};
-use crate::geometry::{Collider, ContactManifold, Shape, Trimesh};
+use crate::geometry::{Collider, ContactManifold, Shape, ShapeType, Trimesh};
use crate::ncollide::bounding_volume::{BoundingVolume, AABB};
pub struct TrimeshShapeContactGeneratorWorkspace {
@@ -26,9 +26,9 @@ pub fn generate_contacts_trimesh_shape(ctxt: &mut ContactGenerationContext) {
let collider1 = &ctxt.colliders[ctxt.pair.pair.collider1];
let collider2 = &ctxt.colliders[ctxt.pair.pair.collider2];
- if let Shape::Trimesh(trimesh1) = collider1.shape() {
+ if let Some(trimesh1) = collider1.shape().as_trimesh() {
do_generate_contacts(trimesh1, collider1, collider2, ctxt, false)
- } else if let Shape::Trimesh(trimesh2) = collider2.shape() {
+ } else if let Some(trimesh2) = collider2.shape().as_trimesh() {
do_generate_contacts(trimesh2, collider2, collider1, ctxt, true)
}
}
@@ -121,6 +121,7 @@ fn do_generate_contacts(
let new_interferences = &workspace.interferences;
let mut old_inter_it = workspace.old_interferences.drain(..).peekable();
let mut old_manifolds_it = workspace.old_manifolds.drain(..);
+ let shape_type2 = collider2.shape().shape_type();
for (i, triangle_id) in new_interferences.iter().enumerate() {
if *triangle_id >= trimesh1.num_triangles() {
@@ -159,10 +160,10 @@ fn do_generate_contacts(
}
let manifold = &mut ctxt.pair.manifolds[i];
- let triangle1 = Shape::Triangle(trimesh1.triangle(*triangle_id));
+ let triangle1 = trimesh1.triangle(*triangle_id);
let (generator, mut workspace2) = ctxt
.dispatcher
- .dispatch_primitives(&triangle1, collider2.shape());
+ .dispatch_primitives(ShapeType::Triangle, shape_type2);
let mut ctxt2 = if ctxt_pair_pair.collider1 != manifold.pair.collider1 {
PrimitiveContactGenerationContext {