Skip to content

Commit

Permalink
Add trimesh_with_flags and trimesh_from_bevy_mesh_with_flags (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jondolf authored Jul 17, 2023
1 parent 61e6b20 commit b3ce346
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/components/collider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use parry::{
shape::{SharedShape, TypedShape},
};

/// Flags used for the preprocessing of a triangle mesh collider.
pub type TriMeshFlags = parry::shape::TriMeshFlags;

/// A collider used for collision detection.
///
/// By default, colliders generate [collision events](#collision-events) and cause a collision response for
Expand Down Expand Up @@ -244,6 +247,17 @@ impl Collider {
SharedShape::trimesh(vertices, indices).into()
}

/// Creates a collider with a triangle mesh shape defined by its vertex and index buffers
/// and flags controlling the preprocessing.
pub fn trimesh_with_flags(
vertices: Vec<Vector>,
indices: Vec<[u32; 3]>,
flags: TriMeshFlags,
) -> Self {
let vertices = vertices.into_iter().map(|v| v.into()).collect();
SharedShape::trimesh_with_flags(vertices, indices, flags).into()
}

/// Creates a collider with a triangle mesh shape built from a given Bevy `Mesh`.
#[cfg(all(feature = "3d", feature = "collider-from-mesh"))]
pub fn trimesh_from_bevy_mesh(mesh: &Mesh) -> Option<Self> {
Expand All @@ -255,6 +269,14 @@ impl Collider {
})
}

/// Creates a collider with a triangle mesh shape built from a given Bevy `Mesh` and flags
/// controlling its preprocessing.
#[cfg(all(feature = "3d", feature = "collider-from-mesh"))]
pub fn trimesh_from_bevy_mesh_with_flags(mesh: &Mesh, flags: TriMeshFlags) -> Option<Self> {
let vertices_indices = extract_mesh_vertices_indices(mesh);
vertices_indices.map(|(v, i)| SharedShape::trimesh_with_flags(v, i, flags).into())
}

/// Creates a collider with a compound shape obtained from the decomposition of a triangle mesh
/// built from a given Bevy `Mesh`.
#[cfg(all(feature = "3d", feature = "collider-from-mesh"))]
Expand Down

0 comments on commit b3ce346

Please sign in to comment.