internal bool IntersectsWith(ref Ray ray, ref float tMax, Vector3[] vertices)
{
var rayCopy = ray;
var dist = float.MaxValue;
VisitNodes(rootId, ref ray, ref tMax, (node) =>
{
if (node == null) return;
if (node.TriIndices.Length == 0) return;
foreach (var tri in node.TriIndices)
{
var v1 = vertices[tri.Index0];
var v2 = vertices[tri.Index1];
var v3 = vertices[tri.Index2];
float newDist;
if (!Intersection.RayTriangleIntersect(rayCopy, v1, v2, v3, out newDist)) continue;
//Collision happens behind the startPos
if (newDist < 0.0f) continue;
dist = Math.Min(dist, newDist);
}
});
return (dist < tMax);
}