public void Reinitialize()
{
//Pick a point that is known to be outside the mesh as the origin.
Vector3 origin = (triangleMesh.Tree.BoundingBox.Max - triangleMesh.Tree.BoundingBox.Min) * 1.5f + triangleMesh.Tree.BoundingBox.Min;
//Pick a direction which will definitely hit the mesh.
Vector3 a, b, c;
triangleMesh.Data.GetTriangle(0, out a, out b, out c);
var direction = (a + b + c) / 3 - origin;
var ray = new Ray(origin, direction);
var triangles = CommonResources.GetIntList();
triangleMesh.Tree.GetOverlaps(ray, triangles);
float minimumT = float.MaxValue;
for (int i = 0; i < triangles.Count; i++)
{
triangleMesh.Data.GetTriangle(triangles.Elements[i], out a, out b, out c);
RayHit hit;
bool hitClockwise;
if (Toolbox.FindRayTriangleIntersection(ref ray, float.MaxValue, ref a, ref b, ref c, out hitClockwise, out hit))
{
if (hit.T < minimumT)
{
minimumT = hit.T;
innerFacingIsClockwise = !hitClockwise;
}
}
}
CommonResources.GiveBack(triangles);
}