-
-
Notifications
You must be signed in to change notification settings - Fork 131
Description
Hello!
First of all: thank you for the incredible library 😄
I am experiencing some unexpected behaviour and was wondering if someone could help me troubleshoot it. I want to test if two frustums are intersecting but it seems to be producing inconsistent results as can be seen in the video below, where I am showing the left frustum in green if I get Some(Contact) back from rapier3d::parry::query::contact::contact:
frustum_intersection_jitter_2.mp4
Here is how I am implementing the test:
impl FrustumDescriptor {
pub fn frustum_intersection_test(
&self,
other: &FrustumDescriptor,
) -> Option<rapier3d::parry::query::contact::Contact> {
rapier3d::parry::query::contact::contact(
&rapier3d::na::Isometry::identity(),
&self.to_convex_polyhedron(),
&rapier3d::na::Isometry::identity(),
&other.to_convex_polyhedron(),
0.0,
)
.unwrap()
}
pub fn to_convex_polyhedron(&self) -> ConvexPolyhedron {
let points: Vec<_> = self
.to_basic_mesh()
.vertices
.iter()
.map(|vertex| Point::from(vertex.position))
.collect();
ColliderBuilder::convex_hull(&points)
.expect("Failed to construct convex hull for frustum")
.build()
.shape()
.as_convex_polyhedron()
.unwrap()
.clone()
}
}I'm using the same to_basic_mesh() function to display the frustum in my debug setup as in the video, so I'm quite sure the vertices are OK. For full details on the implementation you can check out this commit
Update: added unit test
I've added a unit test in my fork of parry, it can be seen here. Below is a screenshot with a visualisation of the two frustums which I copied from my engine directly into the test:
The test fails despite confirming that one point of the left frustum lies inside the right frustum:
test geometry::epa3::cuboid_cuboid_EPA ... ok
test geometry::trimesh_intersection::trimesh_plane_multi_intersection ... ok
test geometry::trimesh_trimesh_toi::trimesh_trimesh_toi ... ok
test geometry::cuboid_ray_cast::shape_ray_cast_points_to_surface ... ok
test geometry::convex_hull::test_complex_convex_hull ... ok
test geometry::convex_polyhedra_contact::convex_polyhedra_contact ... FAILED
failures:
---- geometry::convex_polyhedra_contact::convex_polyhedra_contact stdout ----
thread 'geometry::convex_polyhedra_contact::convex_polyhedra_contact' panicked at 'assertion failed: contact.is_some()', crates/parry3d/tests/geometry/convex_polyhedra_contact.rs:57:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
geometry::convex_polyhedra_contact::convex_polyhedra_contact
test result: FAILED. 19 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.37s