Mesh is messed up after adding bones despite using inverseBindMatrices

Hello! I was hoping someone here could help me with a problem I’ve been tearing my hair out over for days now. I have a 3D model that I’m converting to glTF. I’m importing it from elsewhere, I didn’t create it myself, so I don’t have control over the data. The conversion is working fine, up until I add the bones.

When I add the bones to the mesh, with a translation, rotation, and scale for each, the skeleton appears to be correct, though the mesh gets deformed out of shape. As I understand it, I now need to add an “inverse bind matrix” for each bone, which should cancel out the translation, rotation, and scale and un-deform the model. However, adding the inverseBindMatrices doesn’t correct the mesh. I’ve tried two different software libraries for calculating the matrix inverses and gotten the same results, so I think the matrices themselves are correct. I’ve tried many different things over the last 4 days or so, but haven’t been able to get the mesh to look right after the bones have been added.

I have two copies of the model, one where it’s rendering correctly before the bones are added, and a second where the bones and inverseBindMatrices have been added but the mesh is messed up. I’d like to share them, however this forum says I don’t have permission to upload files or even include web links in my post, so I’m not sure how to share them exactly.

Edit: since I can’t link anything here, I also posted the question on Stack Overflow, with links to the files. I can’t post a link to the Stack Overflow question, but the title is “GLTF mesh is messed up after adding bones despite using inverseBindMatrices.”

I’d really appreciate it if someone could help me discover what I’m doing wrong.

Thank you!