Camera animation in GLTF

I’ve generated a camera animation and exported it in GLTF format. However, upon playback, the animation exhibited irregularities, prompting me to delve deeper into the file’s data (specifically, the binary file). Upon comparison with a similar animation exported from Blender, I noticed some difference.
While the quaternion values were correctly exported in my file, there seemed to be an issue with the position values.

Currently, I’m exporting the actual camera positions along a curved path in the viewer by calculating points on the curve and exporting them accordingly.
Additionally, in a separate attempt, I’ve experimented with exporting only the initial and final positions of the camera and dividing the path between them into eleven segments.
Despite these adjustments, each playback of the animation yields different results.
Don’t know he exact cause but may be this position can play vital role in my animation.

I’m grateful for your assistance ahead of time.

1] Screenshot : my file and blender file comparison

2] My created file
cubezcamera.bin (1.0 KB)
cubezcamera.gltf (4.4 KB)

3] Blender File
Square_camera_anim_Z_Blender_Baked.bin (5.1 KB)
Square_camera_anim_Z_Blender_Baked.gltf (6.2 KB)

1 Like

If playback is yielding different results each time, i’d suspect your playback code might be weird. Perhaps not passing the correct deltaT into the mixer or similar?

Also r.e. comparing blender->gltf output, the exporter transforms the coordinate system of the scene to z up and changes the hierarchy a bit too so you may not find 1 to 1 correspondence betw blender data and what is exported.

The deltaT isn’t the problem, as the animation displays correctly in Blender’s exported model. The issue lies in my process of encoding the camera animation data into GLTF. Currently, I export both interpolated quaternion values and position values, but there’s a missing element in my approach.

Are you writing your own gltf exporter or smth?

Yes. I am writing my own GLTF using Open cascade

OK. just wanted to clarify with the above statement…

Animation playback is always interpolated to create smooth playback, so you can’t expect the output of the animationmixer to be your exact keyframes, unless you are explicitly setting the time on the mixer to the exact keyframe time you are hoping to sample.

I have to applied animation to camera.
while exporting in the GLTF
should I have to export position data with quaternion data ?
In the node should I have to specify the transformation applied to camera also?(like position from origin)

There’s no reason you need to include a position keyframe track, if only the rotation (quaternion) of the camera is changing. If both position and rotation change, you’ll need both. I’d recommend running your generated files through glTF Validator if you have not already.

Suppose the camera rotate around the object. So it must follow circular path around object.
In this case we need to export the qauternion and position (point on that circular path).
Is that right?
Also my initial camera position is (290,-290,450). Do I need to consider that also?

In that case yes, you’ll need to export both position and rotation of the camera in the animation track. The initial position/rotation of the camera has no effect on the animation while it is playing. If you don’t want to see a sudden ‘jump’ when the animation starts playing, then the animation should probably begin at the same position and rotation. Depends how you are using the model and animation, though – you can always reposition the model in three.js after loading.

1 Like

Thank you very much, @donmccurdy. Your insights have been incredibly helpful for me in understanding the camera animation.