aboutsummaryrefslogtreecommitdiff
path: root/src/geometry
diff options
context:
space:
mode:
authorCrozet Sébastien <developer@crozet.re>2021-01-21 16:29:05 +0100
committerCrozet Sébastien <developer@crozet.re>2021-01-21 16:29:05 +0100
commit800b35b103c60a3f13dffdfe1c20561074041cea (patch)
treefdedf5109816f7790278c0ab40403f7b646db7f2 /src/geometry
parent98d3980db7a9803f4ee965237599a87771a417d1 (diff)
downloadrapier-800b35b103c60a3f13dffdfe1c20561074041cea.tar.gz
rapier-800b35b103c60a3f13dffdfe1c20561074041cea.tar.bz2
rapier-800b35b103c60a3f13dffdfe1c20561074041cea.zip
Add collider constructors for shapes obtained from convex decomposition.
Diffstat (limited to 'src/geometry')
-rw-r--r--src/geometry/collider.rs51
-rw-r--r--src/geometry/collider_shape.rs63
2 files changed, 112 insertions, 2 deletions
diff --git a/src/geometry/collider.rs b/src/geometry/collider.rs
index c5f53f7..232b246 100644
--- a/src/geometry/collider.rs
+++ b/src/geometry/collider.rs
@@ -1,6 +1,7 @@
+use crate::cdl::transformation::vhacd::VHACDParameters;
use crate::dynamics::{CoefficientCombineRule, MassProperties, RigidBodyHandle};
use crate::geometry::{ColliderShape, InteractionGroups};
-use crate::math::{AngVector, Isometry, Point, Real, Rotation, Vector};
+use crate::math::{AngVector, Isometry, Point, Real, Rotation, Vector, DIM};
use cdl::bounding_volume::AABB;
use cdl::shape::Shape;
#[cfg(feature = "dim2")]
@@ -299,6 +300,54 @@ impl ColliderBuilder {
Self::new(ColliderShape::trimesh(vertices, indices))
}
+ /// Initializes a collider builder with a compound shape obtained from the decomposition of
+ /// the given trimesh (in 3D) or polyline (in 2D) into convex parts.
+ pub fn convex_decomposition(vertices: &[Point<Real>], indices: &[[u32; DIM]]) -> Self {
+ Self::new(ColliderShape::convex_decomposition(vertices, indices))
+ }
+
+ /// Initializes a collider builder with a compound shape obtained from the decomposition of
+ /// the given trimesh (in 3D) or polyline (in 2D) into convex parts dilated with round corners.
+ pub fn round_convex_decomposition(
+ vertices: &[Point<Real>],
+ indices: &[[u32; DIM]],
+ border_radius: Real,
+ ) -> Self {
+ Self::new(ColliderShape::round_convex_decomposition(
+ vertices,
+ indices,
+ border_radius,
+ ))
+ }
+
+ /// Initializes a collider builder with a compound shape obtained from the decomposition of
+ /// the given trimesh (in 3D) or polyline (in 2D) into convex parts.
+ pub fn convex_decomposition_with_params(
+ vertices: &[Point<Real>],
+ indices: &[[u32; DIM]],
+ params: &VHACDParameters,
+ ) -> Self {
+ Self::new(ColliderShape::convex_decomposition_with_params(
+ vertices, indices, params,
+ ))
+ }
+
+ /// Initializes a collider builder with a compound shape obtained from the decomposition of
+ /// the given trimesh (in 3D) or polyline (in 2D) into convex parts dilated with round corners.
+ pub fn round_convex_decomposition_with_params(
+ vertices: &[Point<Real>],
+ indices: &[[u32; DIM]],
+ params: &VHACDParameters,
+ border_radius: Real,
+ ) -> Self {
+ Self::new(ColliderShape::round_convex_decomposition_with_params(
+ vertices,
+ indices,
+ params,
+ border_radius,
+ ))
+ }
+
pub fn convex_hull(points: &[Point<Real>]) -> Option<Self> {
ColliderShape::convex_hull(points).map(|cp| Self::new(cp))
}
diff --git a/src/geometry/collider_shape.rs b/src/geometry/collider_shape.rs
index 4777850..05067ef 100644
--- a/src/geometry/collider_shape.rs
+++ b/src/geometry/collider_shape.rs
@@ -1,4 +1,5 @@
-use crate::math::{Isometry, Point, Real, Vector};
+use crate::cdl::transformation::vhacd::{VHACDParameters, VHACD};
+use crate::math::{Isometry, Point, Real, Vector, DIM};
use cdl::shape::{
Ball, Capsule, Compound, Cuboid, HalfSpace, HeightField, RoundCuboid, RoundShape,
RoundTriangle, Segment, Shape, ShapeType, TriMesh, Triangle,
@@ -122,6 +123,66 @@ impl ColliderShape {
ColliderShape(Arc::new(TriMesh::new(vertices, indices)))
}
+ /// Initializes a compound shape obtained from the decomposition of the given trimesh (in 3D) or
+ /// polyline (in 2D) into convex parts.
+ pub fn convex_decomposition(vertices: &[Point<Real>], indices: &[[u32; DIM]]) -> Self {
+ Self::convex_decomposition_with_params(vertices, indices, &VHACDParameters::default())
+ }
+
+ /// Initializes a compound shape obtained from the decomposition of the given trimesh (in 3D) or
+ /// polyline (in 2D) into convex parts dilated with round corners.
+ pub fn round_convex_decomposition(
+ vertices: &[Point<Real>],
+ indices: &[[u32; DIM]],
+ border_radius: Real,
+ ) -> Self {
+ Self::round_convex_decomposition_with_params(
+ vertices,
+ indices,
+ &VHACDParameters::default(),
+ border_radius,
+ )
+ }
+
+ /// Initializes a compound shape obtained from the decomposition of the given trimesh (in 3D) or
+ /// polyline (in 2D) into convex parts.
+ pub fn convex_decomposition_with_params(
+ vertices: &[Point<Real>],
+ indices: &[[u32; DIM]],
+ params: &VHACDParameters,
+ ) -> Self {
+ let mut parts = vec![];
+ let decomp = VHACD::decompose(params, &vertices, &indices, true);
+
+ for (vertices, indices) in decomp.compute_exact_convex_hulls(&vertices, &indices) {
+ if let Some(convex) = Self::convex_mesh(vertices, &indices) {
+ parts.push((Isometry::identity(), convex));
+ }
+ }
+
+ Self::compound(parts)
+ }
+
+ /// Initializes a compound shape obtained from the decomposition of the given trimesh (in 3D) or
+ /// polyline (in 2D) into convex parts dilated with round corners.
+ pub fn round_convex_decomposition_with_params(
+ vertices: &[Point<Real>],
+ indices: &[[u32; DIM]],
+ params: &VHACDParameters,
+ border_radius: Real,
+ ) -> Self {
+ let mut parts = vec![];
+ let decomp = VHACD::decompose(params, &vertices, &indices, true);
+
+ for (vertices, indices) in decomp.compute_exact_convex_hulls(&vertices, &indices) {
+ if let Some(convex) = Self::round_convex_mesh(vertices, &indices, border_radius) {
+ parts.push((Isometry::identity(), convex));
+ }
+ }
+
+ Self::compound(parts)
+ }
+
pub fn convex_hull(points: &[Point<Real>]) -> Option<Self> {
#[cfg(feature = "dim2")]
return ConvexPolygon::from_convex_hull(points).map(|ch| ColliderShape(Arc::new(ch)));