aevyrie / bevy_mod_raycast

A little mesh raycasting plugin for Bevy
https://crates.io/crates/bevy_mod_raycast
MIT License
303 stars 92 forks source link

Expose barycentric coord and triangle index #103

Closed ottah closed 5 months ago

ottah commented 8 months ago

This change exposes the intersection's barycentric coord and the triangle index so they can be used to look up vertex attributes and texcoords.

brookman commented 5 months ago

Maybe I misunderstand something, but it seems that triangle_index contains only the first vertex index of the triangle. How can I get the other two vertex indices?

aevyrie commented 4 months ago

This should give you the triange index. In indexed geometry, you would look up the triangle with this index, and get the three vertices. In a non-indexed geometry the next three vertices should give you the triangle.

brookman commented 1 week ago

Hi @aevyrie

Sorry for bothering you again with this issue, but after looking at the code again I'm pretty sure that it does not contain the triangle index but a vertex index. Looking at this line: https://github.com/aevyrie/bevy_mod_raycast/blob/dbc5ef32fe48997a1a7eeec7434d9dd8b829e52e/src/raycast.rs#L118

Current implementation

for index in indices.chunks(3) {
    let triangle_index = Some(index[0].into_usize());

How it could be implemented instead:

for (i, index) in indices.chunks(3).enumerate() {
    let triangle_index = Some(i);
aevyrie commented 1 week ago

Ah, I see the issue. Please open a PR or a new issue, or this is going to get lost.