protected virtual UVPlaneData GetUVPlaneData(int triA, int triB) { UVPlaneData data = new UVPlaneData(); int iA; int iB; int iC1; int iC2; GetQuadVertices(triA, triB, out iA, out iB, out iC1, out iC2); Utils.Assert(iA >= 0 && iB >= 0 && iC1 >= 0 && iC2 >= 0, "GeoSurface.GetUVPlaneData: triA (" + triA + ") and triB (" + triB + ") must have exactly one common side"); Vector3 vA = NormalizePoint(nodes[iA].position); Vector3 vB = NormalizePoint(nodes[iB].position); Vector3 vC1 = NormalizePoint(nodes[iC1].position); Vector3 vC2 = NormalizePoint(nodes[iC2].position); Plane planeA = new Plane(vA, vC1, vC2); Plane planeB = new Plane(vB, vC2, vC1); Vector3 nA = planeA.normal; Vector3 nB = planeB.normal; if (Vector3.Dot(nA, vA) < 0f) { nA = -nA; nB = -nB; } Vector3 nAB = (nA + nB).normalized; Vector3 pA = Math3d.ProjectPointOnPlane(nAB, vA, vA, vA); Vector3 pB = Math3d.ProjectPointOnPlane(nAB, vA, vB, vB); Vector3 pC1 = Math3d.ProjectPointOnPlane(nAB, vA, vC1, vC1); Vector3 pC2 = Math3d.ProjectPointOnPlane(nAB, vA, vC2, vC2); data.normal = nAB; data.posA = vA; data.posB = vB; data.posC1 = vC1; data.posC2 = vC2; data.projA = pA; data.projB = pB; data.projC1 = pC1; data.projC2 = pC2; data.axisC1A = (pC1 - pA).normalized; data.axisC2A = (pC2 - pA).normalized; data.distC1A = (pC1 - pA).magnitude; data.distC2A = (pC2 - pA).magnitude; return(data); }
protected override Vector3 GetVertexPositionFromUV(Vector2 uv, int tripairIndex) { float u = uv.x; float v = uv.y; UVPlaneData uvPlane = uvPlanesData[tripairIndex]; Vector3 pAC1 = Utils.VectorLerpUnclamped(uvPlane.projA, uvPlane.projC1, v); Vector3 pC2B = Utils.VectorLerpUnclamped(uvPlane.projC2, uvPlane.projB, v); return(Utils.VectorLerpUnclamped(pAC1, pC2B, u).normalized); }
protected override Vector2 GetVertexUV(Vector3 position, int tripairIndex) { Vector3 p = NormalizePoint(position); UVPlaneData uvPlane = uvPlanesData[tripairIndex]; Vector3 pP = Math3d.ProjectPointOnPlane(uvPlane.normal, uvPlane.posA, p, p); float u = Math3d.PointLineDistance(pP, uvPlane.projA, uvPlane.axisC1A) / uvPlane.distC2A; float v = Math3d.PointLineDistance(pP, uvPlane.projA, uvPlane.axisC2A) / uvPlane.distC1A; return(new Vector2(u * 1.5f, v * 1.5f)); // i have no idea why 1.5 works }