KhronosGroup / glTF

glTF – Runtime 3D Asset Delivery
Other
7.13k stars 1.13k forks source link

The weird behavior of the rotation animation of the attached model. #1765

Open runforu opened 4 years ago

runforu commented 4 years ago

The behavior of the attached model can not be explained. The model can be displayed correctly in Windows 10 and online gltf viewer (https://gltf-viewer.donmccurdy.com/). But I find the 481 quaternions which are used to define rotation animation does not point to the same direction (see the following data I calculate by programs and by online calculator). You see the axes change over time, but the rotation animation shown in windows 10 and online viewer point to the same direction. The rotation animation does not reflect the changing axes. Would you please explain the reason? willy.zip

javagl commented 4 years ago

Going out on a limb (until someone comes up with a better explanation) :

Looking only at the rotating object, you can see that the animated node that it is attached to has an "initial" rotation:

  "rotation": [
    -0.23969714343547821,
    0.10332431644201279,
    0.04481608048081398,
    0.96429294347763062
  ]

The following image shows the respective part without this rotation (on the left) and with this rotation (on the right):

RotationIssue001

The "rest state" of the part (i.e. the actual geometry data that is stored in the mesh) is not the one that the rotation animation refers to. So each animation step has to contain a "combination" of 1. rotating the part into the desired orientation, and 2. (on top of that) applying the rotation from the animation, which then appears to be around the fixed rotation axis.

Does that sound reasonable?

(It's hard to "verify" this, strictly speaking, but maybe it makes sense...)

runforu commented 4 years ago

Thank you very much. So as you mentioned, I should conjugate the original rotation quaternion and each quaternion rotation animation frame if I want to get the correct rotation quaternion. Is it right?

runforu commented 4 years ago

I tried to combine two quaternions, but the result is still not correct. what's wrong with my calculation? I am using assimp to do that. { -0.23969714343547821, 0.10332431644201279, 0.04481608048081398, 0.96429294347763062} {0.104911, 0.051215, 0.963975, -0.239003} OR {0.104911, 0.051215, 0.963975, -0.239003} { -0.23969714343547821, 0.10332431644201279, 0.04481608048081398, 0.96429294347763062}

template inline aiQuaterniont aiQuaterniont::operator (const aiQuaterniont& t) const { return aiQuaterniont(wt.w - xt.x - yt.y - zt.z, wt.x + xt.w + yt.z - zt.y, wt.y + yt.w + zt.x - xt.z, wt.z + zt.w + xt.y - y*t.x); }