Add collider constructors for shapes obtained from convex decomposition.

This commit is contained in:
Crozet Sébastien
2021-01-21 16:29:05 +01:00
parent 98d3980db7
commit 800b35b103
3 changed files with 117 additions and 11 deletions

View File

@@ -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))
}