C++ Barycentric coordinates
27 Nov 2018Doing research to find out how to approach a mesh deformer. I think I can use this to create a free form deformation (FFD) deformer: https://en.wikipedia.org/wiki/Barycentric_coordinate_system
How does it work
In order to deform a point within another shape, we have to remap the point in world space relative to the cage.
-
Binding.
In this example I use a triangle as the cage, the first step in the process is called ‘binding’, this will loop through all points in a mesh and calculate the coordinates in the cage, once we have those coordinates we can store them and access them later.
-
Update the cage points.
Change the position of the cage after doing the binding step.
-
Apply new coordinates of the mesh based on the new cage points
FVector cagePointC = VertexBuffer[0].Position; FVector cagePointB = VertexBuffer[1].Position; FVector cagePointA = VertexBuffer[2].Position; float u = barycentric_coordinates[0].X; float v = barycentric_coordinates[1].Y; float w = barycentric_coordinates[2].Z; float n = (u * cagePointC.X) + (v * cagePointB.X) + (w * cagePointA.X);