Skip to content

Commit

Permalink
Add TriMeshFlags to ComputedColliderShape::TriMesh (dimforge#559)
Browse files Browse the repository at this point in the history
  • Loading branch information
DiSaber authored and Vrixyz committed Aug 8, 2024
1 parent 5563ba9 commit 3000fa8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## Unreleased

### Added

- Added a `TriMeshFlags` parameter for `ComputedColliderShape`,
its default value is `TriMeshFlags::MERGE_DUPLICATE_VERTICES`,
which was its hardcoded behaviour.

## v0.27.0 (07 July 2024)

**This is an update from rapier 0.19 to Rapier 0.21 which includes several stability improvements
Expand Down
19 changes: 14 additions & 5 deletions src/geometry/collider.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::fmt;

#[cfg(all(feature = "dim3", feature = "async-collider"))]
use {crate::geometry::VHACDParameters, bevy::utils::HashMap};
use {
crate::geometry::{TriMeshFlags, VHACDParameters},
bevy::utils::HashMap,
};

use bevy::prelude::*;

Expand Down Expand Up @@ -40,25 +43,31 @@ pub struct AsyncSceneCollider {
impl Default for AsyncSceneCollider {
fn default() -> Self {
Self {
shape: Some(ComputedColliderShape::TriMesh),
shape: Some(Default::default()),
named_shapes: Default::default(),
}
}
}

/// Shape type based on a Bevy mesh asset.
#[cfg(all(feature = "dim3", feature = "async-collider"))]
#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone)]
pub enum ComputedColliderShape {
/// Triangle-mesh.
#[default]
TriMesh,
TriMesh(TriMeshFlags),
/// Convex hull.
ConvexHull,
/// Convex decomposition.
ConvexDecomposition(VHACDParameters),
}

#[cfg(all(feature = "dim3", feature = "async-collider"))]
impl Default for ComputedColliderShape {
fn default() -> Self {
Self::TriMesh(TriMeshFlags::MERGE_DUPLICATE_VERTICES)
}
}

/// A geometric entity that can be attached to a [`RigidBody`] so it can be affected by contacts
/// and intersection queries.
///
Expand Down
7 changes: 3 additions & 4 deletions src/geometry/collider_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,9 @@ impl Collider {
let (vtx, idx) = extract_mesh_vertices_indices(mesh)?;

match collider_shape {
ComputedColliderShape::TriMesh => Some(
SharedShape::trimesh_with_flags(vtx, idx, TriMeshFlags::MERGE_DUPLICATE_VERTICES)
.into(),
),
ComputedColliderShape::TriMesh(flags) => {
Some(SharedShape::trimesh_with_flags(vtx, idx, *flags).into())
}
ComputedColliderShape::ConvexHull => {
SharedShape::convex_hull(&vtx).map(|shape| shape.into())
}
Expand Down

0 comments on commit 3000fa8

Please sign in to comment.