KhronosGroup / glTF-Blender-IO

Blender glTF 2.0 importer and exporter
https://docs.blender.org/manual/en/latest/addons/import_export/scene_gltf2.html
Apache License 2.0
1.46k stars 310 forks source link

CUBICSPLINE rotation export: invalid values #1072

Open u3shit opened 4 years ago

u3shit commented 4 years ago

Describe the bug I have a simple blend file with some bezier curves animation. Upon exporting it to gltf and opening in a viewer (like babylonjs sandbox), the animation sometimes jumps.

To Reproduce Steps to reproduce the behavior:

  1. Open the blend file
  2. Export it to gltf or glb with "Always sample animations" turned off
  3. See erron in a gltf viewer
  4. Curiously, importing it back to blender, the animation plays back correctly

Expected behavior The animation is exported correctly.

Screenshots Here's the output opened in babylonjs (I can't upload a webm, sorry for the bad quality): babylonjs

Here's the curve I'm exporting: exporting An interesting info is that I ended up with this curve by repeatedly exporting to gltf and importing back to blender this curve: original You can see that w became y, x became z and got inverted.

.blend file/ .gltf example.zip

Version

Additional context The problem manifest itself first between keyframe 1 and 2 (at frame 3.2 and 4.8). If I look at the exported gltf data, the target values for these two keyframes are:

[ [ -0.0024046599864959717, -0.014678483828902245, -0.0007305145263671875, 0.004064374603331089 ], [ 0.10037517547607422, 0.027345599606633186, -0.9945357441902161, 0.008700160309672356 ], [ -0.0024046599864959717, -0.014678480103611946, -0.0007305145263671875, 0.004064374603331089 ] ]
[ [ 0.0009030848741531372, 0.008994728326797485, 0.0008977651596069336, -0.004734877496957779 ], [ -0.10758800804615021, -0.07530241459608078, 0.9912505149841309, 0.013295253738760948 ], [ 0.0009030848741531372, 0.008994728326797485, 0.0008977651596069336, -0.004734877496957779 ] ]

The tangent values are pretty small so they shouldn't matter much, but the z values for the two vertices are -0.9945357441902161 and 0.9912505149841309 for keyframe 1 and 2 respectively. According to my f-curves both of them should be positive, around 0.99.

u3shit commented 4 years ago

Disregard what I wrote in the last paragraph, keyframe 1 is a 179deg rotation around almost -z axis, while keyframe 2 is 178deg rotation around about the z axis, so they are pretty near, but it looks like none of the gltf viewers I checked (babylon.js and https://gltf-viewer.donmccurdy.com/) use slerp with CUBICSPLINE (Checking the gltf spec only mentions slerp at the LINEAR interpolation, in appendix C it only mentions that the resulting quaternion must be normalized and exporters should take care not to produce 0 length quaternions.).

emackey commented 4 years ago

There's more discussion of this in #960.