Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix edge of mesh intersections being filtered out due to returning NaN #119

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion src/immediate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ impl<'w, 's> Raycast<'w, 's> {
};
if should_raycast {
if let Some([near, _]) = intersects_aabb(ray, aabb, &transform.compute_matrix())
.filter(|[_, far]| *far >= 0.0)
// intersections on edge of mesh may return [NaN,NaN]
.filter(|[_, far]| *far >= 0.0 || far.is_nan())
{
aabb_hits_tx.send((FloatOrd(near), entity)).ok();
}
Expand Down
1 change: 1 addition & 0 deletions src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ pub mod rays {
}

/// Checks if the ray intersects with an AABB of a mesh, returning `[near, far]` if it does.
/// Intersections on the edge of meshes may return [NaN, NaN]
pub fn intersects_aabb(ray: Ray3d, aabb: &Aabb, model_to_world: &Mat4) -> Option<[f32; 2]> {
// Transform the ray to model space
let world_to_model = model_to_world.inverse();
Expand Down
Loading