For a deforming mesh you need to be able to construct a TM that can be created at any frame, which will correspond to the same location on the mesh. Obviously the object's TM won't work, but luckily such a TM is easy to construct.
You need 4 vectors to create such a TM: Forward, right, up and translation. The process for creating these is as follows:
First, at frame 0, find the closest point on the mesh and get the face index as well as the barycentric coordinates. From the face, get vertex1, 2 and 3 which create the face.
For the forward vector, use (vertex1 - vertex2) and normalize it.
For the right vector, use the cross product of (vertex1 - vertex2) and (vertex3 - vertex2) and normalize it.
For the up vector, use the cross product of forward and right.
Finally, orthogonalize the TM by resetting the right vector as the cross of up and forward.
For the translation, multiply the barycentric coordinates by the vertex1, 2 and 3 coordinates (v1 * b.x + v2 * b.y + v3 * b.z).
Use all 4 vectors to construct your TM (Matrix3 tm = new Matrix3(forward, right, up, translation); )
Then, store the barycentric coordinates and face index in custom data channels for later access.
Later, at any given frame, reconstruct the TM using the face index (to get v1, v2, v3) and barycentric coordinates. Use the method previous explained in this thread to also get the localTM you'll be storing and loading from using this new deformation-compatible TM.
You need 4 vectors to create such a TM: Forward, right, up and translation. The process for creating these is as follows:
First, at frame 0, find the closest point on the mesh and get the face index as well as the barycentric coordinates. From the face, get vertex1, 2 and 3 which create the face.
For the forward vector, use (vertex1 - vertex2) and normalize it.
For the right vector, use the cross product of (vertex1 - vertex2) and (vertex3 - vertex2) and normalize it.
For the up vector, use the cross product of forward and right.
Finally, orthogonalize the TM by resetting the right vector as the cross of up and forward.
For the translation, multiply the barycentric coordinates by the vertex1, 2 and 3 coordinates (v1 * b.x + v2 * b.y + v3 * b.z).
Use all 4 vectors to construct your TM (Matrix3 tm = new Matrix3(forward, right, up, translation); )
Then, store the barycentric coordinates and face index in custom data channels for later access.
Later, at any given frame, reconstruct the TM using the face index (to get v1, v2, v3) and barycentric coordinates. Use the method previous explained in this thread to also get the localTM you'll be storing and loading from using this new deformation-compatible TM.