powroupi / blender_mmd_tools

mmd_tools is a blender addon for importing Models and Motions of MikuMikuDance.
GNU General Public License v3.0
1.83k stars 277 forks source link

Quaternion value imported from VMD file is incorrect at some point #392

Open xzhuah opened 2 years ago

xzhuah commented 2 years ago

I noticed that importing the same VMD file into Blender and MMD, results in slightly different pose at some key frames.

X8@QQYTHVL48{2ZF}_~HZ5X

I spent some time investigating what happened and I wrote a little python script to decde the VMD file and read the Quaternion value. Now I saw the problem: when imported to the blender, the Quaternion value changed for some reason. The Quaternion value being used in blender is different from what is in the VMD file. When I manually correct the Quaternion value in blender, the pose restore to normal

4FA (_42%A$L{(BXX6FRUWU.

Could you please double check the VMD file loader to see why this happen?

xzhuah commented 2 years ago

I did some debugging, my finding is that: in the vmd/importer.py

For the BoneConverter.convert_rotation:

rot = Quaternion() rot.x, rot.y, rot.z, rot.w = rotation_xyzw return Quaternion(matmul(self.__mat, rot.axis) * -1, rot.angle).normalized()

I don't quite understand why we need to do that matmul calucation there. But if we return rot directly, the bone rotation of my above example would become visually correct. However, other bones would go wrong. So I guess, in some cases, we don't need to do that calcuation?

I also noticed that the error bone rotation typically happens when the rotation value change dramatically: like in the following diragram, it happen at those troughs. GOZHUX`K8(00%PEZJ6OM TT