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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## Unreleased

### Added

- `CompoundFlags::FIX_INTERNAL_EDGES` makes a `Compound` treat the edges (2D) or faces (3D) its parts share as
interior to the union, so a body sliding across the cut between two parts of a convex
decomposition no longer catches on it. `Compound::PartNormalConstraints` is now
`CompoundPseudoNormals`, matching what `TriMesh` and `Polyline` already provide.
- Ray casts and point projections against a `Compound` now identify the part that was hit:
the returned feature is `FeatureId::Face(part_index)`, the way `TriMesh` reports the
triangle. Both previously discarded the part index.

## 0.30.2

### Added
Expand Down
17 changes: 8 additions & 9 deletions src/query/point/point_composite_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,16 @@ impl PointQuery for Compound {
.unwrap_or(PointProjection::new(false, point))
}

/// The returned feature identifies the part the point projects onto:
/// `FeatureId::Face(part_index)`, the way [`TriMesh`] reports the triangle.
#[inline]
fn project_local_point_and_get_feature(&self, point: Vector) -> (PointProjection, FeatureId) {
(
CompositeShapeRef(self)
.project_local_point_and_get_feature(point, Real::MAX)
.map(|(_, (proj, _))| proj)
// No candidate: `point` (or `self`) isn’t finite. See
// `Polyline::project_local_point_and_get_feature`.
.unwrap_or(PointProjection::new(false, point)),
FeatureId::Unknown,
)
CompositeShapeRef(self)
.project_local_point_and_get_feature(point, Real::MAX)
.map(|(part_index, (proj, _))| (proj, FeatureId::Face(part_index)))
// No candidate: `point` (or `self`) isn’t finite. See
// `Polyline::project_local_point_and_get_feature`.
.unwrap_or((PointProjection::new(false, point), FeatureId::Unknown))
}

#[inline]
Expand Down
16 changes: 5 additions & 11 deletions src/query/point/point_segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,20 @@ impl PointQueryWithLocation for Segment {
let ab_ap = ab.dot(ap);
let sqnab = ab.length_squared();

let proj;
let location;

if ab_ap <= 0.0 {
let (location, proj) = if ab_ap <= 0.0 {
// Voronoï region of vertex 'a'.
location = SegmentPointLocation::OnVertex(0);
proj = self.a;
(SegmentPointLocation::OnVertex(0), self.a)
} else if ab_ap >= sqnab {
// Voronoï region of vertex 'b'.
location = SegmentPointLocation::OnVertex(1);
proj = self.b;
(SegmentPointLocation::OnVertex(1), self.b)
} else {
assert!(sqnab != 0.0);

// Voronoï region of the segment interior.
let u = ab_ap / sqnab;
let bcoords = [1.0 - u, u];
location = SegmentPointLocation::OnEdge(bcoords);
proj = self.a + ab * u;
}
(SegmentPointLocation::OnEdge(bcoords), self.a + ab * u)
};

// TODO: is this acceptable?
let inside = relative_eq_vector(proj, pt);
Expand Down
8 changes: 7 additions & 1 deletion src/query/ray/ray_composite_shape.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::math::Real;
use crate::partitioning::BvhNode;
use crate::query::{Ray, RayCast, RayIntersection};
use crate::shape::FeatureId;
use crate::shape::{CompositeShapeRef, Compound, Polyline, TypedCompositeShape};

impl<S: TypedCompositeShape> CompositeShapeRef<'_, S> {
Expand Down Expand Up @@ -91,6 +92,8 @@ impl RayCast for Compound {
.map(|hit| hit.1)
}

/// The returned intersection identifies the part that was hit: its `feature` is
/// `FeatureId::Face(part_index)`, the way [`TriMesh`](crate::shape::TriMesh) reports the triangle it hit.
#[inline]
fn cast_local_ray_and_get_normal(
&self,
Expand All @@ -100,6 +103,9 @@ impl RayCast for Compound {
) -> Option<RayIntersection> {
CompositeShapeRef(self)
.cast_local_ray_and_get_normal(ray, max_time_of_impact, solid)
.map(|hit| hit.1)
.map(|(part_index, mut hit)| {
hit.feature = FeatureId::Face(part_index);
hit
})
}
}
Loading
Loading