Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Conversation

brookman
Copy link

@brookman brookman commented Jul 10, 2024

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:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant