diff options
Diffstat (limited to 'src/geometry')
| -rw-r--r-- | src/geometry/collider.rs | 15 | ||||
| -rw-r--r-- | src/geometry/mesh_converter.rs | 9 |
2 files changed, 17 insertions, 7 deletions
diff --git a/src/geometry/collider.rs b/src/geometry/collider.rs index c0cec6b..4f5312f 100644 --- a/src/geometry/collider.rs +++ b/src/geometry/collider.rs @@ -10,7 +10,7 @@ use crate::pipeline::{ActiveEvents, ActiveHooks}; use crate::prelude::ColliderEnabled; use na::Unit; use parry::bounding_volume::{Aabb, BoundingVolume}; -use parry::shape::{Shape, TriMeshFlags}; +use parry::shape::{Shape, TriMeshBuilderError, TriMeshFlags}; #[cfg(feature = "dim3")] use crate::geometry::HeightFieldFlags; @@ -685,8 +685,11 @@ impl ColliderBuilder { } /// Initializes a collider builder with a triangle mesh shape defined by its vertex and index buffers. - pub fn trimesh(vertices: Vec<Point<Real>>, indices: Vec<[u32; 3]>) -> Self { - Self::new(SharedShape::trimesh(vertices, indices)) + pub fn trimesh( + vertices: Vec<Point<Real>>, + indices: Vec<[u32; 3]>, + ) -> Result<Self, TriMeshBuilderError> { + Ok(Self::new(SharedShape::trimesh(vertices, indices)?)) } /// Initializes a collider builder with a triangle mesh shape defined by its vertex and index buffers and @@ -695,8 +698,10 @@ impl ColliderBuilder { vertices: Vec<Point<Real>>, indices: Vec<[u32; 3]>, flags: TriMeshFlags, - ) -> Self { - Self::new(SharedShape::trimesh_with_flags(vertices, indices, flags)) + ) -> Result<Self, TriMeshBuilderError> { + Ok(Self::new(SharedShape::trimesh_with_flags( + vertices, indices, flags, + )?)) } /// Initializes a collider builder with a shape converted from the given triangle mesh index diff --git a/src/geometry/mesh_converter.rs b/src/geometry/mesh_converter.rs index cfa1391..13868fd 100644 --- a/src/geometry/mesh_converter.rs +++ b/src/geometry/mesh_converter.rs @@ -1,6 +1,6 @@ use parry::bounding_volume; use parry::math::{Isometry, Point, Real}; -use parry::shape::{Cuboid, SharedShape, TriMeshFlags}; +use parry::shape::{Cuboid, SharedShape, TriMeshBuilderError, TriMeshFlags}; #[cfg(feature = "dim3")] use parry::transformation::vhacd::VHACDParameters; @@ -17,6 +17,9 @@ pub enum MeshConverterError { /// The convex hull calculation carried out by the [`MeshConverter::ConvexHull`] failed. #[error("convex-hull computation failed")] ConvexHullFailed, + /// The TriMesh building failed. + #[error("TriMesh building failed")] + TriMeshBuilderError(TriMeshBuilderError), } /// Determines how meshes (generally when loaded from a file) are converted into Rapier colliders. @@ -61,9 +64,11 @@ impl MeshConverter { ) -> Result<(SharedShape, Isometry<Real>), MeshConverterError> { let mut transform = Isometry::identity(); let shape = match self { - MeshConverter::TriMesh => SharedShape::trimesh(vertices, indices), + MeshConverter::TriMesh => SharedShape::trimesh(vertices, indices) + .map_err(MeshConverterError::TriMeshBuilderError)?, MeshConverter::TriMeshWithFlags(flags) => { SharedShape::trimesh_with_flags(vertices, indices, *flags) + .map_err(MeshConverterError::TriMeshBuilderError)? } MeshConverter::Obb => { let (pose, cuboid) = parry::utils::obb(&vertices); |
