Skip to content

Commit 626f0c3

Browse files
authored
feat: decouple the FIX_INTERNAL_EDGES from the ORIENTED trimesh flags (#333)
* feat: decouple the FIX_INTERNAL_EDGES from the ORIENTED trimesh flags * chore: cargo fmt
1 parent 95288fa commit 626f0c3

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@
99
- Add `SharedShape::from_convex_polyline_unmodified` and `ConvexPolygon::from_convex_polyline_unmodified`
1010
to initialize a polyline from a set of points assumed to be convex, and without modifying this set even
1111
if some points are collinear.
12+
- Add `TriMesh::pseudo_normals_if_oriented` that returns `Some` only if the mesh has the `TriMeshFlags::ORIENTED`
13+
flag enabled.
1214

1315
### Modified
1416

17+
- The `TriMeshFlags::FIX_INTERNAL_EDGES` flag no longer automatically enable the `TriMeshFlags::ORIENTED`
18+
flag (but the mesh pseudo-normals will still be computed).
1519
- Improve `no_std` compatibility.
1620
- Everything is now compatible, except `mesh_intersections`, `split_trimesh`,
1721
convex hull validation, and computation of connected components for `TriMesh`.

src/query/point/point_composite_shape.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl PointQueryWithLocation for TriMesh {
168168
.traverse_best_first_node(&mut visitor, 0, max_dist)
169169
{
170170
#[cfg(feature = "dim3")]
171-
if let Some(pseudo_normals) = self.pseudo_normals() {
171+
if let Some(pseudo_normals) = self.pseudo_normals_if_oriented() {
172172
let pseudo_normal = match location {
173173
TrianglePointLocation::OnFace(..) | TrianglePointLocation::OnSolid => {
174174
Some(self.triangle(part_id).scaled_normal())

src/query/split/split_trimesh.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl TriMesh {
9494
bias: Real,
9595
epsilon: Real,
9696
) -> SplitResult<Self> {
97-
let mut triangulation = if self.pseudo_normals().is_some() {
97+
let mut triangulation = if self.pseudo_normals_if_oriented().is_some() {
9898
Some(Triangulation::new(*local_axis, self.vertices()[0]))
9999
} else {
100100
None
@@ -654,7 +654,7 @@ impl TriMesh {
654654
flip_cuboid: bool,
655655
_epsilon: Real,
656656
) -> Result<Option<Self>, MeshIntersectionError> {
657-
if self.topology().is_some() && self.pseudo_normals().is_some() {
657+
if self.topology().is_some() && self.pseudo_normals_if_oriented().is_some() {
658658
let (cuboid_vtx, cuboid_idx) = cuboid.to_trimesh();
659659
let cuboid_trimesh = TriMesh::with_flags(
660660
cuboid_vtx,

src/shape/trimesh.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ bitflags::bitflags! {
270270
///
271271
/// This is achieved by taking into account adjacent triangle normals when computing contact
272272
/// points for a given triangle.
273-
const FIX_INTERNAL_EDGES = (1 << 7) | Self::ORIENTED.bits() | Self::MERGE_DUPLICATE_VERTICES.bits();
273+
const FIX_INTERNAL_EDGES = (1 << 7) | Self::MERGE_DUPLICATE_VERTICES.bits();
274274
}
275275
}
276276

@@ -350,7 +350,7 @@ impl TriMesh {
350350
}
351351

352352
#[cfg(feature = "dim3")]
353-
if !flags.contains(TriMeshFlags::ORIENTED) {
353+
if !flags.intersects(TriMeshFlags::ORIENTED | TriMeshFlags::FIX_INTERNAL_EDGES) {
354354
self.pseudo_normals = None;
355355
}
356356

@@ -384,7 +384,7 @@ impl TriMesh {
384384
}
385385

386386
#[cfg(feature = "dim3")]
387-
if difference.contains(TriMeshFlags::ORIENTED) {
387+
if difference.intersects(TriMeshFlags::ORIENTED | TriMeshFlags::FIX_INTERNAL_EDGES) {
388388
self.compute_pseudo_normals();
389389
}
390390

@@ -1064,6 +1064,17 @@ impl TriMesh {
10641064
pub fn pseudo_normals(&self) -> Option<&TriMeshPseudoNormals> {
10651065
self.pseudo_normals.as_ref()
10661066
}
1067+
1068+
/// The pseudo-normals of this triangle mesh, if they have been computed **and** this mesh was
1069+
/// marked as [`TriMeshFlags::ORIENTED`].
1070+
#[cfg(feature = "dim3")]
1071+
pub fn pseudo_normals_if_oriented(&self) -> Option<&TriMeshPseudoNormals> {
1072+
if self.flags.intersects(TriMeshFlags::ORIENTED) {
1073+
self.pseudo_normals.as_ref()
1074+
} else {
1075+
None
1076+
}
1077+
}
10671078
}
10681079

10691080
#[cfg(feature = "dim3")]

src/transformation/mesh_intersection/mesh_intersection.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ pub fn intersect_meshes_with_tolerances(
109109
return Err(MeshIntersectionError::MissingTopology);
110110
}
111111

112-
if mesh1.pseudo_normals().is_none() || mesh2.pseudo_normals().is_none() {
112+
if mesh1.pseudo_normals_if_oriented().is_none() || mesh2.pseudo_normals_if_oriented().is_none()
113+
{
113114
return Err(MeshIntersectionError::MissingPseudoNormals);
114115
}
115116

0 commit comments

Comments
 (0)