[Solved] Assigning bind pose to a mesh imported at runtime

Hi everyone,

I am trying to import a character mesh, the skeletal information, the weight information, and put everything together.

As you can see, the mesh, the skeleton, and the weights are imported correctly.

Now when I assign the bindposes using:

var bindPoses = new Matrix4x4[joints.Lenght];

for(int i = 0; i < bindPoses.Length; i++)
{
    bindPoses[i] = joints[i].worldToLocalMatrix * transform.localToWorldMatrix;
}

mesh.bindposes = bindPoses;

my mesh explodes:

Transform is referring the transform of the “Rig” GameObject. It doesn’t matter how the joints are oriented before creating and assigning the bindposes (facing their parent, or facing their child), the deformation looks exactly the same.

What am I doing wrong? There is very little documetation on bindposes. I hope someone here can help me.

Thanks a lot in advance,
Wavy

I recognized that the weights might be offset. The elbow joint affects the vertices that should be affected by the shoulder joint. The weight data import is correct, though. Perhaps I have to recalculate the weighting for Unity, as the weight data is coming from a different source.

I have now remapped the weights, and the deformation looks EXACTLY the same.

Does anyone have an idea what I’m doing wrong here?

I figured it out. It had NOTHING to do with the matrices. When assigning the weights, I mistakenly thought it would be a good idea to gather the 4 weight values for the BoneWeight object in a Vector4 struct, and normalize it. I had a brain fart. Vector normalization makes the length of the vector equal 1, and not the sum of the vector components.