aboutsummaryrefslogtreecommitdiff
path: root/src/geometry/collider_shape.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/geometry/collider_shape.rs')
-rw-r--r--src/geometry/collider_shape.rs63
1 files changed, 62 insertions, 1 deletions
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)));