blender-to-gmstudio / blender-to-smf

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

Twitching occurs in animations when porting to SMF1 #32

Open bartteunis opened 2 years ago

bartteunis commented 2 years ago

Bones can be inverted inbetween some keyframes. This works fine in SMF v10 and the corresponding version of the Model Tool because it has additional math for inverting DQs. When porting these animations to SMF1 and previewing in Model Tool 0.8.9, the twitching occurs. Can these corrections be done in the Blender exporter? If so, what should be added to export correct DQs? Is this issue related to DQs or also to matrices?

bartteunis commented 2 years ago

This requires #9 DQ export option

It seems to correspond to the if-else part in smf_model_load_from_buffer that is checked for every node:

if (i > 0)
{
// ...
bartteunis commented 2 years ago

A subtle yet important remark: smf_dq_invert doesn't invert a DQ but negates it. See Quaternions and spatial rotation:

It can be proven that the inverse of a unit quaternion is obtained simply by changing the sign of its imaginary components.

smf_dq_invert, however, changes the sign of all components, so rather it performs a scalar multiplication by -1. So it is negate that should be used instead of invert.

bartteunis commented 2 years ago

Untested, test to see if this is solved by #9