# GLTF Export Bug: FreeCamera rotation has wrong offset

**URL:** <https://forum.babylonjs.com/t/gltf-export-bug-freecamera-rotation-has-wrong-offset/31278>\
**Category:** Bugs\
**Created:** [June 12, 2022, 3:20pm UTC](https://forum.babylonjs.com/t/gltf-export-bug-freecamera-rotation-has-wrong-offset/31278 "2022-06-12T15:20:36Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrlooi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mrlooi/32/18406_2.png) [@mrlooi](https://forum.babylonjs.com/u/mrlooi)\
**Post date:** [June 12, 2022, 3:20pm UTC](https://forum.babylonjs.com/t/gltf-export-bug-freecamera-rotation-has-wrong-offset/31278/1 "2022-06-12T15:20:36Z")

</div>

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](https://playground.babylonjs.com/#HZBCXR#99)

**Before export**  
90 degrees  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/4/f/4f2ab79d45ef9c58e2c0fc6e37e2a2a7c278a7d2.png)

**After Export**  
180 degrees  
(Loaded this in sandbox BJS)  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/1/b/1b0d7099bd43dd74f59a2e9b169ed1b13bc89a13.png)

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

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [June 13, 2022, 1:05pm UTC](https://forum.babylonjs.com/t/gltf-export-bug-freecamera-rotation-has-wrong-offset/31278/2 "2022-06-13T13:05:04Z")

</div>

cc @Guillaume_Pelletier and @bghgary

---

<div class="post-metadata">

**Author:** ![Guillaume\_Pelletier](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/guillaume_pelletier/32/3695_2.png) [@Guillaume\_Pelletier](https://forum.babylonjs.com/u/Guillaume_Pelletier)\
**Post date:** [June 14, 2022, 9:50am UTC](https://forum.babylonjs.com/t/gltf-export-bug-freecamera-rotation-has-wrong-offset/31278/3 "2022-06-14T09:50:51Z")

</div>

Hello,  
this is perfectly legit into GLTF camera [documentation](https://github.com/KhronosGroup/glTF-Tutorials/blob/master/gltfTutorial/gltfTutorial_016_Cameras.md#camera-orientation), 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.

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

```

and camera objects are binded later to the corresponding node.

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

```

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

```auto

```

---

<div class="post-metadata">

**Author:** ![mrlooi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mrlooi/32/18406_2.png) [@mrlooi](https://forum.babylonjs.com/u/mrlooi)\
**Post date:** [June 14, 2022, 10:36am UTC](https://forum.babylonjs.com/t/gltf-export-bug-freecamera-rotation-has-wrong-offset/31278/4 "2022-06-14T10:36:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [June 14, 2022, 4:24pm UTC](https://forum.babylonjs.com/t/gltf-export-bug-freecamera-rotation-has-wrong-offset/31278/5 "2022-06-14T16:24:04Z")

</div>

> [@Guillaume\_Pelletier](#):
>
> Which is (as far i know) **NOT** the case into Babylon rendering.

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

---

<div class="post-metadata">

**Author:** ![mrlooi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mrlooi/32/18406_2.png) [@mrlooi](https://forum.babylonjs.com/u/mrlooi)\
**Post date:** [June 15, 2022, 10:05am UTC](https://forum.babylonjs.com/t/gltf-export-bug-freecamera-rotation-has-wrong-offset/31278/6 "2022-06-15T10:05:40Z")

</div>

Is there going to be a PR for this 🤕

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [June 15, 2022, 10:08pm UTC](https://forum.babylonjs.com/t/gltf-export-bug-freecamera-rotation-has-wrong-offset/31278/7 "2022-06-15T22:08:30Z")

</div>

@Guillaume_Pelletier Can you take another look?

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [June 15, 2022, 10:08pm UTC](https://forum.babylonjs.com/t/gltf-export-bug-freecamera-rotation-has-wrong-offset/31278/8 "2022-06-15T22:08:36Z")

</div>

Assigned @Guillaume\_Pelletier on June 15, 2022, 10:08pm UTC



---

<div class="post-metadata">

**Author:** ![Guillaume\_Pelletier](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/guillaume_pelletier/32/3695_2.png) [@Guillaume\_Pelletier](https://forum.babylonjs.com/u/Guillaume_Pelletier)\
**Post date:** [June 16, 2022, 5:46am UTC](https://forum.babylonjs.com/t/gltf-export-bug-freecamera-rotation-has-wrong-offset/31278/9 "2022-06-16T05:46:00Z")

</div>

ya right… 🙃

---

<div class="post-metadata">

**Author:** ![Guillaume\_Pelletier](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/guillaume_pelletier/32/3695_2.png) [@Guillaume\_Pelletier](https://forum.babylonjs.com/u/Guillaume_Pelletier)\
**Post date:** [June 16, 2022, 5:49am UTC](https://forum.babylonjs.com/t/gltf-export-bug-freecamera-rotation-has-wrong-offset/31278/10 "2022-06-16T05:49:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mrlooi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mrlooi/32/18406_2.png) [@mrlooi](https://forum.babylonjs.com/u/mrlooi)\
**Post date:** [June 21, 2022, 8:41am UTC](https://forum.babylonjs.com/t/gltf-export-bug-freecamera-rotation-has-wrong-offset/31278/11 "2022-06-21T08:41:24Z")

</div>

any updates on this PR? 🙂

---

<div class="post-metadata">

**Author:** ![mrlooi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mrlooi/32/18406_2.png) [@mrlooi](https://forum.babylonjs.com/u/mrlooi)\
**Post date:** [June 23, 2022, 9:24am UTC](https://forum.babylonjs.com/t/gltf-export-bug-freecamera-rotation-has-wrong-offset/31278/12 "2022-06-23T09:24:24Z")

</div>

@Guillaume_Pelletier

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [June 23, 2022, 3:43pm UTC](https://forum.babylonjs.com/t/gltf-export-bug-freecamera-rotation-has-wrong-offset/31278/13 "2022-06-23T15:43:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Guillaume\_Pelletier](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/guillaume_pelletier/32/3695_2.png) [@Guillaume\_Pelletier](https://forum.babylonjs.com/u/Guillaume_Pelletier)\
**Post date:** [June 27, 2022, 3:29pm UTC](https://forum.babylonjs.com/t/gltf-export-bug-freecamera-rotation-has-wrong-offset/31278/14 "2022-06-27T15:29:28Z")

</div>

Published a [PR](https://github.com/BabylonJS/Babylon.js/pull/12682) on the subject.

---

<div class="post-metadata">

**Author:** ![mrlooi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mrlooi/32/18406_2.png) [@mrlooi](https://forum.babylonjs.com/u/mrlooi)\
**Post date:** [June 27, 2022, 3:44pm UTC](https://forum.babylonjs.com/t/gltf-export-bug-freecamera-rotation-has-wrong-offset/31278/15 "2022-06-27T15:44:14Z")

</div>

Can’t wait to test this out!

---

<div class="post-metadata">

**Author:** ![mrlooi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mrlooi/32/18406_2.png) [@mrlooi](https://forum.babylonjs.com/u/mrlooi)\
**Post date:** [June 27, 2022, 3:44pm UTC](https://forum.babylonjs.com/t/gltf-export-bug-freecamera-rotation-has-wrong-offset/31278/16 "2022-06-27T15:44:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Guillaume\_Pelletier](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/guillaume_pelletier/32/3695_2.png) [@Guillaume\_Pelletier](https://forum.babylonjs.com/u/Guillaume_Pelletier)\
**Post date:** [June 27, 2022, 4:32pm UTC](https://forum.babylonjs.com/t/gltf-export-bug-freecamera-rotation-has-wrong-offset/31278/17 "2022-06-27T16:32:19Z")

</div>

Only focus on the camera for this PR.
