blender-to-gmstudio / blender-to-smf

Import-Export of Blender model from/to SMF model format
MIT License
11 stars 2 forks source link

Some animations seem to export with some vertices being skinned to wrong bones/with wrong weights #24

Closed bartteunis closed 2 years ago

bartteunis commented 2 years ago

This can be manually fixed in Blender by using Weights > Limit Total in Weight Paint mode on every mesh that is skinned to the armature. The total should be 4 since SMF supports a total of 4 weights (accessed in sh_smf_animate through a vec4 vertex attribute).

After executing the above command on certain meshes, Blender will display an info message, e.g.: 53 vertex weights limited

Apparently something in the current code is not working correctly. Find out what is wrong and then come up with a clean way to let the exporter handle this.

bartteunis commented 2 years ago

Both Clean and Limit Total seem to be relevant here. Fix Deforms may be relevant as well.

How do these operators influence the exported vertex weights?

bartteunis commented 2 years ago

Example of some weights output on a test model using the exporter:

Without first using Limit Total:

0   [0.0005994320963509381, 0.015129164792597294, 0.030124977231025696, 0.041328683495521545]
1   [4.542731080192652e-09, 0.0053732069209218025, 0.020368875935673714, 0.027503572404384613]
2   [2.0993036642380503e-08, 0.00028961963835172355, 0.000548154697753489, 0.0051454356871545315]
3   [0.0008904895512387156, 0.11993509531021118, 0.3488568961620331, 0.5303175449371338]
4   [0.15429988503456116, 0.3503078818321228, 0.49539223313331604]
5   [3.723045427506122e-09, 0.0005388414720073342, 0.14116378128528595, 0.3868328332901001]

After first using Limit Total:

0   [0.030124977231025696, 0.041328683495521545, 0.3686990737915039, 0.5441186428070068]
1   [0.020368875935673714, 0.027503572404384613, 0.1341228038072586, 0.8126315474510193]
2   [0.000548154697753489, 0.0051454356871545315, 0.14054813981056213, 0.8534685969352722]
3   [0.0008904895512387156, 0.11993509531021118, 0.3488568961620331, 0.5303175449371338]
4   [0.15429988503456116, 0.3503078818321228, 0.49539223313331604]
5   [0.0005388414720073342, 0.14116378128528595, 0.3868328332901001, 0.4714645445346832]

It seems like some of the lower weights are wrongly exported while the higher ones disappear, e.g. vertices 0, 1 and 5 don't include some of the highest weights. Vertex 2 has completely wrong weights. Vertices 3 and 4 have the same weights.

How does this happen? How to reproduce the behavior of the built-in operators through code?

bartteunis commented 2 years ago

The groups were sorted ascending by weight. Then the 4 first items in the list were used. It should be the last 4 items in that sorted list. Tested the new code on two models that had this issue. The weights are now the same as in the version that used Limit Total first.