public static Vector3 ClosestPtPointTriangle(Vector3 p, Vector3 a, Vector3 b, Vector3 c)
{
var vector = b - a;
var vector2 = c - a;
var vector3 = c - b;
var num = Vector3.Dot(p - a, vector);
var num2 = Vector3.Dot(p - b, a - b);
var num3 = Vector3.Dot(p - a, vector2);
var num4 = Vector3.Dot(p - c, a - c);
if ((num <= 0f) && (num3 <= 0f))
{
return a;
}
var num5 = Vector3.Dot(p - b, vector3);
var num6 = Vector3.Dot(p - c, b - c);
if ((num2 <= 0f) && (num5 <= 0f))
{
return b;
}
if ((num4 <= 0f) && (num6 <= 0f))
{
return c;
}
var vector4 = Vector3.Cross(b - a, c - a);
var num7 = Vector3.Dot(vector4, Vector3.Cross(a - p, b - p));
if (((num7 <= 0f) && (num >= 0f)) && (num2 >= 0f))
{
return (a + (((num / (num + num2)) * vector)));
}
var num8 = Vector3.Dot(vector4, Vector3.Cross(b - p, c - p));
if (((num8 <= 0f) && (num5 >= 0f)) && (num6 >= 0f))
{
return (b + (((num5 / (num5 + num6)) * vector3)));
}
var num9 = Vector3.Dot(vector4, Vector3.Cross(c - p, a - p));
if (((num9 <= 0f) && (num3 >= 0f)) && (num4 >= 0f))
{
return (a + (((num3 / (num3 + num4)) * vector2)));
}
var num10 = num8 / ((num8 + num9) + num7);
var num11 = num9 / ((num8 + num9) + num7);
var num12 = (1f - num10) - num11;
return (((num10 * a) + (num11 * b)) + (num12 * c));
}