Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions migration-guides/0.5-to-main.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
42 changes: 21 additions & 21 deletions src/collision/collider/parry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,27 +942,27 @@ 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<Vector>, 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<Vector>, 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
/// defined by its vertex and index buffers. The given [`VhacdParameters`] are used for configuring
/// the decomposition process.
#[cfg(feature = "2d")]
pub fn convex_decomposition_with_config(
vertices: Vec<Vector>,
indices: Vec<[u32; 2]>,
vertices: &[Vector],
indices: &[[u32; 2]],
params: &VhacdParameters,
) -> Self {
SharedShape::convex_decomposition_with_params(&vertices, &indices, &params.clone().into())
SharedShape::convex_decomposition_with_params(vertices, indices, &params.clone().into())
.into()
}

Expand All @@ -971,26 +971,26 @@ impl Collider {
/// the decomposition process.
#[cfg(feature = "3d")]
pub fn convex_decomposition_with_config(
vertices: Vec<Vector>,
indices: Vec<[u32; 3]>,
params: VhacdParameters,
vertices: &[Vector],
indices: &[[u32; 3]],
params: &VhacdParameters,
) -> Self {
SharedShape::convex_decomposition_with_params(&vertices, &indices, &params.clone().into())
SharedShape::convex_decomposition_with_params(vertices, indices, &params.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<Vector>) -> Option<Self> {
SharedShape::convex_hull(&points).map(Into::into)
pub fn convex_hull(points: &[Vector]) -> Option<Self> {
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<Vector>) -> Option<Self> {
SharedShape::convex_hull(&points).map(Into::into)
pub fn convex_hull(points: &[Vector]) -> Option<Self> {
SharedShape::convex_hull(points).map(Into::into)
}

/// Creates a collider with a [convex polygon](https://en.wikipedia.org/wiki/Convex_polygon) shape **without** computing
Expand Down Expand Up @@ -1393,32 +1393,32 @@ 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 {
vertices,
indices,
params,
} => Some(Self::convex_decomposition_with_config(
vertices, indices, &params,
&vertices, &indices, &params,
)),
#[cfg(feature = "3d")]
ColliderConstructor::ConvexDecompositionWithConfig {
vertices,
indices,
params,
} => Some(Self::convex_decomposition_with_config(
vertices, indices, params,
&vertices, &indices, &params,
)),
#[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 {
Expand Down
10 changes: 7 additions & 3 deletions src/collision/collider/parry/primitives2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,15 @@ impl IntoCollider<Collider> for Rectangle {

impl IntoCollider<Collider> 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::<Vec<_>>();
let indices = (0..self.vertices.len() as u32 - 1)
.map(|i| [i, i + 1])
.collect();
Collider::convex_decomposition(vertices, indices)
.collect::<Vec<_>>();
Collider::convex_decomposition(&vertices, &indices)
}
}

Expand Down