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

Unify triangle_index for indexed and non-indexed meshes #117

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant