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);
}
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 setsfeature
toFeatureId::Face(best + self.indices().len() as u32)
. When I unwrap the index and attempt to read the triangle (usingTriMesh::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