diff --git a/migration-guides/0.5-to-main.md b/migration-guides/0.5-to-main.md index 0f77b03f..ec876960 100644 --- a/migration-guides/0.5-to-main.md +++ b/migration-guides/0.5-to-main.md @@ -75,3 +75,7 @@ In most cases this should just work, but if it doesn't, you can replace your imp The `SleepBody` and `WakeBody` commands now return an error when applied for an entity that doesn't exist or doesn't belong to an island. Previously, they logged a warning instead. + +## `Collider::convex_decomposition` and `Collider::convex_hull` + +The `Collider::convex_decomposition` and `Collider::convex_hull` methods now borrow the vertices and indices parameters. diff --git a/src/collision/collider/parry/mod.rs b/src/collision/collider/parry/mod.rs index a55f7bee..fa56a8cf 100644 --- a/src/collision/collider/parry/mod.rs +++ b/src/collision/collider/parry/mod.rs @@ -942,15 +942,15 @@ impl Collider { /// Creates a collider shape with a compound shape obtained from the decomposition of a given polyline /// defined by its vertex and index buffers. #[cfg(feature = "2d")] - pub fn convex_decomposition(vertices: Vec, indices: Vec<[u32; 2]>) -> Self { - SharedShape::convex_decomposition(&vertices, &indices).into() + pub fn convex_decomposition(vertices: &[Vector], indices: &[[u32; 2]]) -> Self { + SharedShape::convex_decomposition(vertices, indices).into() } /// Creates a collider shape with a compound shape obtained from the decomposition of a given trimesh /// defined by its vertex and index buffers. #[cfg(feature = "3d")] - pub fn convex_decomposition(vertices: Vec, indices: Vec<[u32; 3]>) -> Self { - SharedShape::convex_decomposition(&vertices, &indices).into() + pub fn convex_decomposition(vertices: &[Vector], indices: &[[u32; 3]]) -> Self { + SharedShape::convex_decomposition(vertices, indices).into() } /// Creates a collider shape with a compound shape obtained from the decomposition of a given polyline @@ -958,11 +958,11 @@ impl Collider { /// the decomposition process. #[cfg(feature = "2d")] pub fn convex_decomposition_with_config( - vertices: Vec, - indices: Vec<[u32; 2]>, + vertices: &[Vector], + indices: &[[u32; 2]], params: &VhacdParameters, ) -> Self { - SharedShape::convex_decomposition_with_params(&vertices, &indices, ¶ms.clone().into()) + SharedShape::convex_decomposition_with_params(vertices, indices, ¶ms.clone().into()) .into() } @@ -971,26 +971,26 @@ impl Collider { /// the decomposition process. #[cfg(feature = "3d")] pub fn convex_decomposition_with_config( - vertices: Vec, - indices: Vec<[u32; 3]>, - params: VhacdParameters, + vertices: &[Vector], + indices: &[[u32; 3]], + params: &VhacdParameters, ) -> Self { - SharedShape::convex_decomposition_with_params(&vertices, &indices, ¶ms.clone().into()) + SharedShape::convex_decomposition_with_params(vertices, indices, ¶ms.clone().into()) .into() } /// Creates a collider with a [convex polygon](https://en.wikipedia.org/wiki/Convex_polygon) shape obtained after computing /// the [convex hull](https://en.wikipedia.org/wiki/Convex_hull) of the given points. #[cfg(feature = "2d")] - pub fn convex_hull(points: Vec) -> Option { - SharedShape::convex_hull(&points).map(Into::into) + pub fn convex_hull(points: &[Vector]) -> Option { + SharedShape::convex_hull(points).map(Into::into) } /// Creates a collider with a [convex polyhedron](https://en.wikipedia.org/wiki/Convex_polytope) shape obtained after computing /// the [convex hull](https://en.wikipedia.org/wiki/Convex_hull) of the given points. #[cfg(feature = "3d")] - pub fn convex_hull(points: Vec) -> Option { - SharedShape::convex_hull(&points).map(Into::into) + pub fn convex_hull(points: &[Vector]) -> Option { + SharedShape::convex_hull(points).map(Into::into) } /// Creates a collider with a [convex polygon](https://en.wikipedia.org/wiki/Convex_polygon) shape **without** computing @@ -1393,11 +1393,11 @@ impl Collider { } => Some(Self::trimesh_with_config(vertices, indices, flags)), #[cfg(feature = "2d")] ColliderConstructor::ConvexDecomposition { vertices, indices } => { - Some(Self::convex_decomposition(vertices, indices)) + Some(Self::convex_decomposition(&vertices, &indices)) } #[cfg(feature = "3d")] ColliderConstructor::ConvexDecomposition { vertices, indices } => { - Some(Self::convex_decomposition(vertices, indices)) + Some(Self::convex_decomposition(&vertices, &indices)) } #[cfg(feature = "2d")] ColliderConstructor::ConvexDecompositionWithConfig { @@ -1405,7 +1405,7 @@ impl Collider { indices, params, } => Some(Self::convex_decomposition_with_config( - vertices, indices, ¶ms, + &vertices, &indices, ¶ms, )), #[cfg(feature = "3d")] ColliderConstructor::ConvexDecompositionWithConfig { @@ -1413,12 +1413,12 @@ impl Collider { indices, params, } => Some(Self::convex_decomposition_with_config( - vertices, indices, params, + &vertices, &indices, ¶ms, )), #[cfg(feature = "2d")] - ColliderConstructor::ConvexHull { points } => Self::convex_hull(points), + ColliderConstructor::ConvexHull { points } => Self::convex_hull(&points), #[cfg(feature = "3d")] - ColliderConstructor::ConvexHull { points } => Self::convex_hull(points), + ColliderConstructor::ConvexHull { points } => Self::convex_hull(&points), #[cfg(feature = "2d")] ColliderConstructor::ConvexPolyline { points } => Self::convex_polyline(points), ColliderConstructor::Voxels { diff --git a/src/collision/collider/parry/primitives2d.rs b/src/collision/collider/parry/primitives2d.rs index fa0f23da..32a0a6a8 100644 --- a/src/collision/collider/parry/primitives2d.rs +++ b/src/collision/collider/parry/primitives2d.rs @@ -197,11 +197,15 @@ impl IntoCollider for Rectangle { impl IntoCollider for Polygon { fn collider(&self) -> Collider { - let vertices = self.vertices.iter().map(|v| v.adjust_precision()).collect(); + let vertices = self + .vertices + .iter() + .map(|v| v.adjust_precision()) + .collect::>(); let indices = (0..self.vertices.len() as u32 - 1) .map(|i| [i, i + 1]) - .collect(); - Collider::convex_decomposition(vertices, indices) + .collect::>(); + Collider::convex_decomposition(&vertices, &indices) } }