I have a 3D model which already has every buffer I can dream : positions, normals, uvs, etc. I would like to modify its geometry (moving an existing vertex or creating a new one) to, for instance, chamfer my edges. I can easily compute the new position and the new normal (3D vectors), but I wonder how to compute the new UVs (2D vector), or rather, deduce them from the adjacent vertices UVs.
It could be cool if someone knows how to do it in a generic way. But maybe my specific use case provides more useful data:
In my specific use case, the new vertex (D) will be on the bisector of the angle α (BAC), which I know. Moreover, as I know the 3D position of every vertex, I have all distances AC, AB and AD.
Seems like I should revise my geometry lessons.. Is trigonometry enough to solve this ?
Thanks in advance !
Finally found this solution that perfectly answers the question !
Using barycentric interpolation it's easy to retrieve the new UVs from the new point position. Here is the generic code in javascript using BabylonJS for vector classes and operations:
var f1 = p1.subtract(f);
var f2 = p2.subtract(f);
var f3 = p3.subtract(f);
var va = BABYLON.Vector3.Cross(p1.subtract(p2), p1.subtract(p3));
var va1 = BABYLON.Vector3.Cross(f2, f3);
var va2 = BABYLON.Vector3.Cross(f3, f1);
var va3 = BABYLON.Vector3.Cross(f1, f2);
var a = va.length();
var a1 = va1.length() / a * Math.sign(BABYLON.Vector3.Dot(va, va1));
var a2 = va2.length() / a * Math.sign(BABYLON.Vector3.Dot(va, va2));
var a3 = va3.length() / a * Math.sign(BABYLON.Vector3.Dot(va, va3));
return uv1.scale(a1).addInPlace(uv2.scale(a2)).addInPlace(uv3.scale(a3));
With:
This works for any point on the plane of the triangle p1p2p3, points outside the triangle included.
Obviously, this doesn't work if the three points are aligned, they must form a triangle with an area greater than zero.