Skip to content

Commit

Permalink
Added variant TriMeshWithFlags to ComputedCollider (#251)
Browse files Browse the repository at this point in the history
fixes #248 
adds a variant `ComputedCollider::TriMeshWithFlags` that allows for generation of Colliders with flags using AsyncCollider.
  • Loading branch information
Adamkob12 authored Nov 15, 2023
1 parent 7592ed8 commit 9f85b03
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/components/collider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ pub struct AsyncCollider(pub ComputedCollider);
/// // Generate colliders for everything except specific meshes by name
/// commands.spawn((
/// scene,
/// AsyncSceneCollider::new(ComputedCollider::TriMesh)
/// AsyncSceneCollider::new(ComputedCollider::TriMeshWithFlags(TriMeshFlags::MERGE_DUPLICATE_VERTICES))
/// .without_shape_for_name("Tree"),
/// ));
/// }
Expand Down Expand Up @@ -1016,6 +1016,8 @@ pub enum ComputedCollider {
/// A triangle mesh.
#[default]
TriMesh,
/// A triangle mesh with a custom configuration.
TriMeshWithFlags(TriMeshFlags),
/// A convex hull.
ConvexHull,
/// A compound shape obtained from a decomposition into convex parts using the specified
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ pub fn init_async_colliders(
if let Some(mesh) = meshes.get(mesh_handle) {
let collider = match &async_collider.0 {
ComputedCollider::TriMesh => Collider::trimesh_from_mesh(mesh),
ComputedCollider::TriMeshWithFlags(flags) => {
Collider::trimesh_from_mesh_with_config(mesh, *flags)
}
ComputedCollider::ConvexHull => Collider::convex_hull_from_mesh(mesh),
ComputedCollider::ConvexDecomposition(params) => {
Collider::convex_decomposition_from_mesh_with_config(mesh, params)
Expand Down Expand Up @@ -468,6 +471,9 @@ pub fn init_async_scene_colliders(

let collider = match collider_data.shape {
ComputedCollider::TriMesh => Collider::trimesh_from_mesh(mesh),
ComputedCollider::TriMeshWithFlags(flags) => {
Collider::trimesh_from_mesh_with_config(mesh, flags)
}
ComputedCollider::ConvexHull => Collider::convex_hull_from_mesh(mesh),
ComputedCollider::ConvexDecomposition(params) => {
Collider::convex_decomposition_from_mesh_with_config(mesh, &params)
Expand Down

0 comments on commit 9f85b03

Please sign in to comment.