GetBarycentric Find UV coordinates of mesh without a raycast
public static Vector3 GetBarycentric(Vector3 aV1, Vector3 aV2, Vector3 aV3, Vector3 aP)
{
Vector3 a = aV2 - aV3, b = aV1 - aV3, c = aP - aV3;
float aLen = a.x * a.x + a.y * a.y + a.z * a.z;
float bLen = b.x * b.x + b.y * b.y + b.z * b.z;
float ab = a.x * b.x + a.y * b.y + a.z * b.z;
float ca = a.x * c.x + a.y * c.y + a.z * c.z;
float cb = b.x * c.x + b.y * c.y + b.z * c.z;
float d = aLen * bLen - ab * ab;
Vector3 B = new Vector3((aLen * cb - ab * ca), (bLen * ca - ab * cb)) /d;
B.z = 1.0f - B.x - B.y;
return B;
}
No comments:
Post a Comment