利用者:Lucarood/SurfaceDeform/Technical
Technical Documentation
This briefly explains how the Surface Deform Modifier works, without getting into the details of the interpolation algorithm.
Bind
- For each vertex on the modified mesh, the nearest face of the target mesh if found, by means of a BVH search.
- On the target face, the nearest vertex to the modified vertex is found, and a list is built, containing all the faces adjacent to this vertex, on the target mesh.
- The interpolation algorithm now goes over these faces, analyzing their relationship with the modified vertex, and thus how much each should influence it (this is the complicated part, and is probably about 80% of the code)
- Each of the analyzed faces, if relevant to the modified vertex, now gets the vertex projected onto it. If the vertex lies inside the face, mean value coordinates are calculated. If the vertex is outside the face, external barycentric coordinates are computed, with regard to the two vertices on the face that comprise the edge closest to the modified vertex, and the centroid of the face (actually just the average of the vertices...)
- The normal distance is calculated between the projected point and the original location of the modified vertex.
Now we have all vertices of the modified mesh, mapped to the tangent space of the target mesh, with displacements computed in normal space, while nicely dealing with faces of any amount of sides. And taking into consideration all the near faces, computing influence values for each of them.
Deformation
Now that the meshes are bound, we have to update the modified mesh with any deformation on the target mesh.
- For each vertex on the modified mesh:
- For each face it is bound to, a projected coordinate is computed, using the stored mean value coordinates for the projected vertex on that face.
- The projected coordinates are moved in the normal direction of their respective faces, by the normal distance that has also been stored.
- Interpolated coordinates are computed from all the individual coordinates calculated with respect to each face, by means of a weighted average, using the stored influences for each face.
Now we have a pretty mesh, deformed nicely with respect to the target mesh.