So I’ve never done this before. I’ve recently created a obj imported so I can now import any mesh I make externally directly into my c++ containers, and then into a Runtime Mesh Component. Now I’d like to add some functionality to warp and distort these objects on the fly. I know from using Maya that volumes are used to deform meshes. For my purposes I would like to start with a Volume triangle (I imagine this is the easiest). If anyone knows of some sources that I could read up on I would greatly appreciate it. Any input or advice on how to approach this is appreciated, thanks!
Creating a deformation volume to warp a list of vertices locations
I would imagine this is a cut and paste type of operation. The best I’ve got figured out so far is that I need to get the new direction vector by something like…
FVector dA = deformToVertA - deformFromVertA;
FVector dB = deformToVertB - deformFromVertB;
FVector dC = deformToVertC - deformFromVertC;
Then maybe I move each sub vert in the new mesh (the mesh to be deformed) by its 0.0 - 1.0 distance to each vert using that corresponding direction vector (by the percent of distance to original vert) something like…
//Arbitrary vert in deform mesh
AVIDM += (((deformFromVertA - AVIDM).size() * dA) + ((deformFromVertB - AVIDM).size() * dB) + ((deformFromVertC - AVIDM).size() * dC)) / 3;
Someone shot me a helpful idea to use barycentric coordinates. Here. This seems very promising. FMath::ComputeBaryCentric3D will return a FVector4, each 0 - 1.0 float representing the percentage of distance towards it’s respective vertex. This is great because I could get the triangleToDeformTo barycentric center, then loop through each of the 4 verts defining this tetrahedron, get (vert - centerVert) * floatAmountForThisVert + centerVert. I wish there was an easier way to convert the bary coords to a vector, maybe that’s just wishful thinking. Also, I’ve heard there is a way to do this using matrices, does anyone know how that would work?
I believe I can accomplish the deformation using Barycentric Coordinates as someone very kindly pointed out to me. The function FMath::ComputeBaryCentric3D appears to take 4 vertices that make a tetrahedron, and one point to fetch the barycentric coordinates for. I could pre-compute this in my object type storing FVector4 instead of FVector3 for the vertices, and this way I could deform based upon the Deform to mesh. What I’m curious about now is how I could accomplish this using matrices for the transformation. In that function above I notice that they build a tetrahedron matrix like so
const FVector B1 = (B-A); const FVector B2 = (C-A); const FVector B3 = (D-A); //Create a matrix of linearly independent vectors const FMatrix SolvMat(B1, B2, B3, FVector::ZeroVector);
This leads me to believe that the I could use matrices to do the warping for the vertices. Attached is a drawing of what I’m trying to accomplish. I’m very new to Matrices so any help is appreciated. One advantage I’m guessing to using matrices for this is that I could use them to fix the normal of the vertices too, so I don’t have to manually compute them and set them. Although I don’t know that it’s much difference in performance. Maybe not even as performant. It may be best to precompute the barycentric coordinates, offset the vertices, and just compute the normal adjustment for them. One problem I keep running into is figuring out which verts belong to which matrix.