GLTF Export Bug: FreeCamera rotation has wrong offset

Hi team,

There is a rotation offset bug with freecamera GLTF exports.

The exported freecamera wrongly adds a rotation offset that is equal to its parent.
Suppose freecamera.parent = tnode;
If tnode.rotation.z = 90 degrees, the exported GLTF will ALSO have freecamera.rotation.z = 90 degrees. This results in the camera having a total rotation.z of 180 degrees, which is weird

Here is a simple PG: https://playground.babylonjs.com/#HZBCXR#99

Before export
90 degrees
image

After Export
180 degrees
(Loaded this in sandbox BJS)
image

You can see that the Z rotation offset accumulates based on its parent Z rotation.

cc @Guillaume_Pelletier and @bghgary

Hello,
this is perfectly legit into GLTF camera documentation, where the camera might be attached to a node to define the orientation.
But from Babylon Point of view, a camera is NOT a transform node

When exporting, scene is defined as a node list using the following statement.

const nodes: Node[] = [...babylonScene.transformNodes, ...babylonScene.meshes, ...babylonScene.lights, ...babylonScene.cameras];

and camera objects are binded later to the corresponding node.

if (babylonNode instanceof Camera) {
    glTFNode.camera = cameraMap.get(babylonNode);
}

consequently, into GLTF, the camera inherit from his parent transformations.

Yes, the thing is it’s not just BJS, Blender also imports the GLTF with the wrong rotation offsets in the exact same way
So I think solving this issue (perhaps like you suggested KEEP_BABYLON_CAMERA_BEHAVIOUR in the export code) would be extremely useful for lots of people who use cameras in BJS

I don’t think this is right. If you change the transform of the parent of the camera, it moves the camera.

Is there going to be a PR for this :face_with_head_bandage:

@Guillaume_Pelletier Can you take another look?

ya right… :upside_down_face:

I’m going to dig in this week, seems my first assumption were wrong and some stuff may be corrected with the camera export.

any updates on this PR? :slight_smile:

@Guillaume_Pelletier

@Guillaume_Pelletier is aware of this. He will be back on this soon. :slight_smile:

Published a PR on the subject.

Can’t wait to test this out!

Is this also fixed for lights too? I believe it also has a similar issue, if I’m not mistaken

Only focus on the camera for this PR.