Check if raycast hits front or back of triangle

Hello.

I am working on a system to detect the collision of a box against a surface that does not lend itself well to HACD.

So far I have created a compound of all of the mesh triangles, and have been able to succesfully check if the box is intersecting the triangles of the mesh (with great performance too, Seb, you are a wizard).

However, I am now trying to puzzle out if a box is inside or outside the terrain. My thought was to use closest_points with a big max_dist. I then use the closest points to raycast from the box to the surface.

I thought that I would be able to use the normal of intersection with the triangle to figure out if the box is inside/outside.

I am now trying to puzzle out a way to go into the compound using the feature id to find the triangle, and perform a backface search.

However, I am thinking that checking for backface is probably part of the raycast somehow.

Is it possible for me to use the raycaster to figure out which side of a triangle I am in, given the closest points from the box to the triangle, If the triangle is wrapped in Compound<ShapeHandle?