public bool IsLocalRayOriginInMesh(ref Ray ray, out RayHit hit)
{
var overlapList = CommonResources.GetIntList();
hit = new RayHit();
hit.T = float.MaxValue;
if (triangleMesh.Tree.GetOverlaps(ray, overlapList))
{
bool minimumClockwise = false;
for (int i = 0; i < overlapList.Count; i++)
{
Vector3 vA, vB, vC;
triangleMesh.Data.GetTriangle(overlapList[i], out vA, out vB, out vC);
bool hitClockwise;
RayHit tempHit;
if (Toolbox.FindRayTriangleIntersection(ref ray, float.MaxValue, ref vA, ref vB, ref vC, out hitClockwise, out tempHit) &&
tempHit.T < hit.T)
{
hit = tempHit;
minimumClockwise = hitClockwise;
}
}
CommonResources.GiveBack(overlapList);
//If the mesh is hit from behind by the ray on the first hit, then the ray is inside.
return hit.T < float.MaxValue && ((solidSidedness == TriangleSidedness.Clockwise && !minimumClockwise) || (solidSidedness == TriangleSidedness.Counterclockwise && minimumClockwise));
}
CommonResources.GiveBack(overlapList);
return false;
}