(Originally posted as a forum thread here)
I’m trying to merge together several skinned meshes into a single SkinnedMeshRenderer, for performance reasons. I can do the basic concatenation of the mesh OK, but some of the parts reference the same bones, and so concatenation means those bones are getting referenced more than once - it makes for 80 bones total, rather than 60. So I want to try and patch up the mesh when I combine it so that it shares bones correctly.
Question 1: Is this actually possible?
What I’m finding is that I need to patch up the vertex positions, because the new mesh has different bindposes to the old one.
Question 2: Does it actually make sense that this would be the case?
I’m still fuzzy on exactly what the bindposes are so I’m not entirely sure what determines whether they’re the same or different. I have this vague understanding that they map from mesh-local space to bone-local space. The runtime then maps from bone-local space to world space. So, if I want to use different bindpose matrices, I should only need to alter the mesh-local vertex positions so that they end up in the same bone-local space positions.
So I thought I had to do this:
var boneLocalPosition = oldBindPoses[bone].MultiplyPoint3x4(vertex);
var newVertex = newBindPoses[bone].inverse.MultiplyPoint3x4(boneLocalPosition);
but this produces something that, while roughly correct (no horrendous distortion) doesn’t have the parts in quite the right places, and it begins to distort horribly when the character starts animating.
Question 3: Why didn’t this work?
If you’re with me this far, then hopefully you can answer the most important question:
Question 4: How do I patch the vertices in my skinned meshes to account for new bindpose matrices, in a way that is visually identical to running the meshes through separate SkinnedMeshRenderers on the same skeleton?