Skip to content

Commit db923d6

Browse files
authored
Fix mesh_picking not working due to mixing vertex and triangle indices. (#18533)
# Objective - #18495 ## Solution - The code in the PR #18232 accidentally used a vertex index as a triangle index, causing the wrong triangle to be used for normal computation and if the triangle went out of bounds, it would skip the ray-hit. - Don't do that. ## Testing - Run `cargo run --example mesh_picking`
1 parent 70c6841 commit db923d6

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

crates/bevy_picking/src/mesh_picking/ray_cast/intersections.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ pub fn ray_mesh_intersection<I: TryInto<usize> + Clone + Copy>(
8383

8484
indices
8585
.chunks_exact(3)
86+
.enumerate()
8687
.fold(
8788
(f32::MAX, None),
88-
|(closest_distance, closest_hit), triangle| {
89+
|(closest_distance, closest_hit), (tri_idx, triangle)| {
8990
let [Ok(a), Ok(b), Ok(c)] = [
9091
triangle[0].try_into(),
9192
triangle[1].try_into(),
@@ -104,7 +105,7 @@ pub fn ray_mesh_intersection<I: TryInto<usize> + Clone + Copy>(
104105

105106
match ray_triangle_intersection(&ray, &tri_vertices, backface_culling) {
106107
Some(hit) if hit.distance >= 0. && hit.distance < closest_distance => {
107-
(hit.distance, Some((a, hit)))
108+
(hit.distance, Some((tri_idx, hit)))
108109
}
109110
_ => (closest_distance, closest_hit),
110111
}

0 commit comments

Comments
 (0)