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

Using TriMesh::cast_local_ray_and_get_normal FeatureId out of bounds if the face is a backface #71

Open
wlinna opened this issue Feb 12, 2022 · 1 comment

Comments

@wlinna
Copy link
Contributor

wlinna commented Feb 12, 2022

TriMesh::cast_local_ray_and_get_normal requires reading source code to use correctly. The issue is that if the ray intersects with a backface, the function sets feature to FeatureId::Face(best + self.indices().len() as u32). When I unwrap the index and attempt to read the triangle (using TriMesh::triangle), I get an index out of bounds error.

This behavior isn't documented clearly enough. Later I learned that I can use TriMesh::is_backface to check whether it's a backface, but even then I can't know how to get the "real index", except by reading the source code and relying on an implementation detail.

Here's a pseudocode to demonstrate the problem

let mesh = TriMesh::new( ... );
let ray = ..;
if let Some(intersection) = mesh.cast_local_ray_and_get_normal(&ray, 1000.0, false) {
    let tri_index = intersection.feature.unwrap_face();
    // if the face is a backface, the following line panics
    let tri = mesh.triangle(tri_index);
}

@GitGhillie
Copy link

Also ran into this. Thank you for opening the issue, made it easier to troubleshoot.

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

No branches or pull requests

2 participants