bevy_mod_raycast
                                
                                 bevy_mod_raycast copied to clipboard
                                
                                    bevy_mod_raycast copied to clipboard
                            
                            
                            
                        Unify triangle_index for indexed and non-indexed meshes
For indexed meshes triangle_index contained the (looked up / resolved) index of the first vertex of the triangle. This made it impossible to find the other two vertices because there was no data on the triangle (one vertex can belong to multiple triangles).
This PR unifies the way how indexed and non-indexed meshes are handled without increasing the size of the IntersectionData struct. In turn the users have to implement the lookup of the indices themselves. In my case I'm using a function like this:
fn get_indices(mesh: &Mesh, intersection: &IntersectionData) -> Result<(usize, usize, usize)> {
    let i = intersection
        .triangle_index()
        .ok_or_eyre("Intersection Index not found")?;
    Ok(mesh.indices().map_or_else(
        || (i, i + 1, i + 2),
        |indices| match indices {
            Indices::U16(indices) => (
                indices[i].into_usize(),
                indices[i + 1].into_usize(),
                indices[i + 2].into_usize(),
            ),
            Indices::U32(indices) => (
                indices[i].into_usize(),
                indices[i + 1].into_usize(),
                indices[i + 2].into_usize(),
            ),
        },
    ))
}
Maybe this could be added as convenience function to IntersectionData or Mesh in the future?
This PR addresses the issues discussed here:
- #77
- #103
- #107
- #113