# OBJ exported scene rotated 180º around up axis

**URL:** <https://forum.babylonjs.com/t/obj-exported-scene-rotated-180-around-up-axis/48825>\
**Category:** Bugs\
**Tags:** export\
**Created:** [March 16, 2024, 8:40pm UTC](https://forum.babylonjs.com/t/obj-exported-scene-rotated-180-around-up-axis/48825 "2024-03-16T20:40:45Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![tdurand](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tdurand/32/884_2.png) [@tdurand](https://forum.babylonjs.com/u/tdurand)\
**Post date:** [March 16, 2024, 8:40pm UTC](https://forum.babylonjs.com/t/obj-exported-scene-rotated-180-around-up-axis/48825/1 "2024-03-16T20:40:45Z")

</div>

Hello,

I might have found an issue with the `OBJExport.OBJ` output.

To reproduce

Use this simple playground: [https://playground.babylonjs.com/#JTLL3M#3](https://playground.babylonjs.com/#JTLL3M#3)

- Enable the debuguer and export the scene as a GLB file
- Open devtool of your browser, and copy the .obj file that is logged to the console by `BABYLON.OBJExport.OBJ()` and save it to test.obj

You should get those two files:

- Test.obj: [test.obj - pCloud](https://u.pcloud.link/publink/show?code=XZfjdF0ZL93qQyDBMayRMUSBiYYVHXPdWL07)
- Test.glb: [test.glb - pCloud](https://u.pcloud.link/publink/show?code=XZjjdF0Z8waUBoRUV2mucHAJtRKXKjzq7da7)

If you import them on blender for example

- you get this for the .GLB:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/a/6/a6ae00b564c0ea677b7322264936b4215053156d.jpeg)

- you get this for the .OBJ:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/2/e/2edf6a64e33ad177f475b2e7643244a40aaac573.jpeg)

The OBJ file is rotate 180º around the up axis

I am not sure how to fix this ? or workaround it ? I would like to have consistent exports between OBJ and GLB

Thanks a lot for the help

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [March 17, 2024, 9:11am UTC](https://forum.babylonjs.com/t/obj-exported-scene-rotated-180-around-up-axis/48825/3 "2024-03-17T09:11:59Z")

</div>

> [@tdurand](#):
>
> The OBJ file is rotate 180º around the up axis

I don’t think so. I think the obj file is correct. It’s your glb/gltf that once imported in blender using the right-handed system of blender, displays mirrored. I never tried the export, so I don’t know whether this is a bug or just unhandled behavior on export. On import, BJS creates a parent and fixes the transform through a minus scaling on the Z-axis and Math.PI on the Y- axis to face the camera/scene. On export, probably it doesn’t, I didn’t check on it. But apparently, from your screenshot, it doesn’t.  
The workaround would be to apply the conversion manually before export I believe. May be this export thingy can be improved somehow. May be you’ll have to wait a little because 1)it’s sunday 2) there’s a code freeze until the launch of v7.  
Meanwhile, enjoy your weekend 🕶

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [March 18, 2024, 8:38am UTC](https://forum.babylonjs.com/t/obj-exported-scene-rotated-180-around-up-axis/48825/4 "2024-03-18T08:38:10Z")

</div>

cc @bghgary.

---

<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:** [March 18, 2024, 4:02pm UTC](https://forum.babylonjs.com/t/obj-exported-scene-rotated-180-around-up-axis/48825/5 "2024-03-18T16:02:27Z")

</div>

AFAIK, there is no forward convention specified in OBJ, so there isn’t a right way to export an OBJ, but we should try to be consistent with the ecosystem if possible. Does the OBJ import into Babylon sandbox in the same orientation?

---

<div class="post-metadata">

**Author:** ![tdurand](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tdurand/32/884_2.png) [@tdurand](https://forum.babylonjs.com/u/tdurand)\
**Post date:** [March 18, 2024, 8:03pm UTC](https://forum.babylonjs.com/t/obj-exported-scene-rotated-180-around-up-axis/48825/6 "2024-03-18T20:03:49Z")

</div>

Hello,

Thanks a lot for the quick replies.

I did a few more test with this playground: [https://playground.babylonjs.com/#JTLL3M#11](https://playground.babylonjs.com/#JTLL3M#11) , adding the axis as tube to see a bit better what it happening, the shorter tube is the X axis, the bigger one is the Z axis in babylonjs coordinates system

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/8/7/8757a4d0b2c773373b9056742504ced5bf74691f.png)

Here are the two files exported from Babylon.js as GLB and OBJ

- [scene-test.obj](https://u.pcloud.link/publink/show?code=XZDKOF0Zs31IWn9ikOyY5cavtTyNtLircERk)
- [scene\_test\_glb.glb - pCloud](https://u.pcloud.link/publink/show?code=XZuKOF0Zo1ufaOwx2RVaDx4l3dieqhuj20ty)

**Then imported in blender:**

- OBJ file: The X axis is the same as in babylon.js, and the Z and Y axis has been swapped , the object is the same, but the camera is from the other side

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/a/b/ab1d973912a815b34a646b41ec9ab666411369a7.jpeg)

- GLB file: X, Y and Z axis are different… the object is the same and the camera is from the same side

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/f/e/fe2e5f5d7ba2cd3dad32d197d61ee4bdebf17ded.jpeg)

**Opening in 3D Viewer on windows:**

- OBJ file : object is the same and camera is from the same side

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/0/0/00f34e51720ed1f6f06be96f8fb17fe5e2e66568.jpeg)

- GLB file: object is correct but camera is 180 degree the other side like when importing in the sandbox.

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/c/3/c3d7bc359a388d6bef137199e2ef03812f55bef6.jpeg)

**importing them back on the babylon.js sandbox playground**

- OBJ file , here the object **seems to be mirrored** (not the same), there is some issue with import OBJ

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/f/7/f7d66b97267e73ac4aa81b378baa195def794fff.png)

- GLB file: The object look correct but the camera is reversed from the export

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/3/7/37ecc557804546a73a593719663da67438d55676.jpeg)

I am not sure what to think of all this to be honest:

- I am wondering why when you export in GLB with babylonjs and then open it again in the sandbox the camera is reversed ?

- Might have a bug with the OBJ import that mirror the model ?

- regarding consistency between OBJ and GLB exports (what I am looking for), I could either rotate the scene 180 before exporting in GLB or in OBJ and I think I would reach what I want… maybe we could add an option in the exporter to follow some convention or not ?

Thanks a lot for the help and the work on babylon.js

---

<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:** [March 18, 2024, 9:03pm UTC](https://forum.babylonjs.com/t/obj-exported-scene-rotated-180-around-up-axis/48825/7 "2024-03-18T21:03:53Z")

</div>

There are a lot of conventions to consider:

1. Right-handed vs left-handed coordinates system. In Babylon.js terms, the scene defaults to left-handed. You can change it to right-handed by doing this `scene.useRightHandedSystem = true`. Both glTF and OBJ are right-handed. It appears the obj exporter in Babylon.[js converts to right-handed by only inverting Z position](https://github.com/BabylonJS/Babylon.js/blob/40d021d9f42ac4c6d9d97540642bf362d1d4f5b0/packages/dev/serializers/src/OBJ/objSerializer.ts#L75-L81), which I don’t think is going to work for all cases, but I think it is okay for your case.
2. Babylon.js is Y-up. glTF is Y-up. OBJ, AFAICT, does not specify which way is up. Blender, IIRC, is Z-up. This might have some implications on what’s going on with the axes.
3. Forward convention (i.e., which way is front). glTF is [the only one that specifies](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#coordinate-system-and-units), but Babylon.js also implicitly defines this in order for the exporters to know what to do.

> [@tdurand](#):
>
> I am wondering why when you export in GLB with babylonjs and then open it again in the sandbox the camera is reversed ?

This is a combination of the handedness and forward convention.

> [@tdurand](#):
>
> Might have a bug with the OBJ import that mirror the model ?

Possibly, but we should rule out some of the problems. Maybe try doing everything with Babylon.js in right-handed system to see if we can at least rule that one out?

> [@tdurand](#):
>
> regarding consistency between OBJ and GLB exports (what I am looking for), I could either rotate the scene 180 before exporting in GLB or in OBJ and I think I would reach what I want… maybe we could add an option in the exporter to follow some convention or not ?

Try with right-handed first and then we’ll see.

---

<div class="post-metadata">

**Author:** ![tdurand](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tdurand/32/884_2.png) [@tdurand](https://forum.babylonjs.com/u/tdurand)\
**Post date:** [March 19, 2024, 5:58pm UTC](https://forum.babylonjs.com/t/obj-exported-scene-rotated-180-around-up-axis/48825/8 "2024-03-19T17:58:12Z")

</div>

Thanks for the reply.

- If I set my scene to `useRightHandedSystem = true` the exports are consistent. Importing in blender both GLB scene and OBJ scene result to the same scene.

I used this code to convert all my meshes after setting: `useRightHandedSystem = true` :

```javascript
this._scene.meshes.map((mesh) => {
      mesh.bakeCurrentTransformIntoVertices();
      const scaleMatrix = BABYLON.Matrix.Scaling(1, 1, -1);
      mesh.bakeTransformIntoVertices(scaleMatrix);
 })

```

And I get the same scene with the rightHanded coordinate system.

- I do think there is a bug with the import OBJ function in the playground, because when importing back the scene (exported with `useRightHanded`) in the playground , I get the object mirrored on the X axis

Here is the playground with useRightHanded : [https://playground.babylonjs.com/#JTLL3M#12](https://playground.babylonjs.com/#JTLL3M#12)

And the exports in GLB and OBJ

- GLB : [test\_righthanded\_glb.glb - pCloud](https://u.pcloud.link/publink/show?code=XZVpNF0Z5YPEgyFPA4bjR35U1DgIpzg9yJeX)
- OBJ: [test\_righthanded\_obj.obj - pCloud](https://u.pcloud.link/publink/show?code=XZmpNF0ZteO2G3xE7uyLSSSP2RQ01LlkkdwX)

And the results in the sandbox:

- OBJ:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/3/6/36704aedfb2b160fbbef11974da09716ca43b55e.png)

- GLB:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/b/9/b9f2b4a99af12228829fafb96dfeab8354666f8a.jpeg)

My takeaways for now are:

- If you want consistent import from a babylon.js exported scene in GLB and OBJ, do use a `useRightHandedSystem = true` in your scene

- There might be a bug in the code that imports a scene from an .OBJ file in the sandbox

Thanks a lot

---

<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:** [March 19, 2024, 6:13pm UTC](https://forum.babylonjs.com/t/obj-exported-scene-rotated-180-around-up-axis/48825/9 "2024-03-19T18:13:11Z")

</div>

Interesting. It does appear the obj loaded into Babylon.js is inverted compared to other viewers. I will investigate.

---

<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:** [March 19, 2024, 6:13pm UTC](https://forum.babylonjs.com/t/obj-exported-scene-rotated-180-around-up-axis/48825/10 "2024-03-19T18:13:33Z")

</div>

Assigned @bghgary on March 19, 2024, 6:13pm UTC



---

<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:** [March 20, 2024, 10:43pm UTC](https://forum.babylonjs.com/t/obj-exported-scene-rotated-180-around-up-axis/48825/11 "2024-03-20T22:43:36Z")

</div>

It appears our OBJ importer and exporter had many issues with handedness since it was written. I’ve attempted to fix most of the issues in this PR.

[Fix obj loader and exporter to support handedness correctly by bghgary · Pull Request #14884 · BabylonJS/Babylon.js (github.com)](https://github.com/BabylonJS/Babylon.js/pull/14884)

---

<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:** [March 20, 2024, 10:43pm UTC](https://forum.babylonjs.com/t/obj-exported-scene-rotated-180-around-up-axis/48825/12 "2024-03-20T22:43:40Z")

</div>

Unassigned @bghgary on March 20, 2024, 10:43pm UTC



---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [March 21, 2024, 9:28am UTC](https://forum.babylonjs.com/t/obj-exported-scene-rotated-180-around-up-axis/48825/13 "2024-03-21T09:28:32Z")

</div>

> [@bghgary](#):
>
> OBJ importer and exporter had many issues with handedness since it was written

I hope this is not going to mess with my current settings, is it? I’m not using the exporter but I do import lots of OBJ and I wouldn’t like my scene breaking just before the imminent launch (because it says ‘breaking change’) 😅

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [March 21, 2024, 10:12am UTC](https://forum.babylonjs.com/t/obj-exported-scene-rotated-180-around-up-axis/48825/14 "2024-03-21T10:12:32Z")

</div>

This will probably break your scene, as the objects will be mirrored (maybe not if you use `scene.useRightHandedSystem = true`). You should stick to one version before the PR is merged for your release, and update your code afterwards.

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [March 21, 2024, 10:30am UTC](https://forum.babylonjs.com/t/obj-exported-scene-rotated-180-around-up-axis/48825/15 "2024-03-21T10:30:48Z")

</div>

I don’t use right-handed. OBJ is my standard and else everything from my demos are pure BJS (left-handed) 😃  
I can’t say I like this answer but thanks a lot for the warning 🤗.  
I will retrieve the latest version library and link my scenes to this until I find the time to conform them to new.  
Good thing is that with the launch of v7 I was going to do this anyway.  
Bad thing is that, meanwhile, I will not be developing sync with latest 😢

Have a great day 🕶

---

<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:** [March 21, 2024, 10:09pm UTC](https://forum.babylonjs.com/t/obj-exported-scene-rotated-180-around-up-axis/48825/16 "2024-03-21T22:09:43Z")

</div>

@RaananW @sebavan and I debated this a bunch. If this is messing up your workflow, we can introduce a flag to put it back to the old (wrong) behavior.

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [March 26, 2024, 7:41am UTC](https://forum.babylonjs.com/t/obj-exported-scene-rotated-180-around-up-axis/48825/17 "2024-03-26T07:41:24Z")

</div>

So where do we stand with this? I mean, I know it’s not my role and I have also been warned (by @Evgeni_Popov) that there’s a risk of breaking everything related to .obj import. But that’s just me. If this is really going to happen, shouldn’t you Guys make an announcement to warn the community? Just thinking 🤔 (sorry to interfere) 🙏

---

<div class="post-metadata">

**Author:** ![MeshSlayer](https://avatars.discourse-cdn.com/v4/letter/m/9f8e36/32.png) [@MeshSlayer](https://forum.babylonjs.com/u/MeshSlayer)\
**Post date:** [March 26, 2024, 11:10am UTC](https://forum.babylonjs.com/t/obj-exported-scene-rotated-180-around-up-axis/48825/18 "2024-03-26T11:10:00Z")

</div>

Hey @bghgary will this resolve [GltfExport - flipped camera](https://forum.babylonjs.com/t/gltfexport-flipped-camera/45986) ?

I did a temporary fix on my project where I wrapped the models under a transform node and to fix the camera rotation (when it’s animated) I had to create a temporary animation group and multiplied the rotation with 180 on both z and y.

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [March 26, 2024, 11:46am UTC](https://forum.babylonjs.com/t/obj-exported-scene-rotated-180-around-up-axis/48825/19 "2024-03-26T11:46:59Z")

</div>

> [@MeshSlayer](#):
>
> wrapped the models under a transform node and to fix the camera rotation (when it’s animated) I had to create a temporary animation group and multiplied the rotation with 180 on both z and y.

Well, that’s basically what I imagined when I told the poster

> [@mawa](#):
>
> apply the conversion manually before export

but that’s just a fix on export. The way I understand it is that everything is wrong from this handling. Eventually, only a breaking change will let us return to ‘normal condition’. At least, that’s my understanding of this.

---

<div class="post-metadata">

**Author:** ![MeshSlayer](https://avatars.discourse-cdn.com/v4/letter/m/9f8e36/32.png) [@MeshSlayer](https://forum.babylonjs.com/u/MeshSlayer)\
**Post date:** [March 26, 2024, 12:02pm UTC](https://forum.babylonjs.com/t/obj-exported-scene-rotated-180-around-up-axis/48825/20 "2024-03-26T12:02:43Z")

</div>

Totally agree,  
We won’t know for sure what procedure we need to undo to follow this fix.  
As you said, an announcement would be great

---

<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:** [March 26, 2024, 8:05pm UTC](https://forum.babylonjs.com/t/obj-exported-scene-rotated-180-around-up-axis/48825/21 "2024-03-26T20:05:15Z")

</div>

> [@MeshSlayer](#):
>
> Hey @bghgary will this resolve [GltfExport - flipped camera](https://forum.babylonjs.com/t/gltfexport-flipped-camera/45986) ?

No, unfortunately not. I am refactoring the serializer to make this work properly. This won’t make the 7.0 release.

> [@mawa](#):
>
> So where do we stand with this? I mean, I know it’s not my role and I have also been warned (by @Evgeni_Popov) that there’s a risk of breaking everything related to .obj import.

I think if people are concerned by this change, we should add a flag to revert to the old behavior but keep the default the hopefully correct behavior. We are guessing not a lot of people are using `obj` files since this has been wrong since it was written.

> [@mawa](#):
>
> The way I understand it is that everything is wrong from this handling. Eventually, only a breaking change will let us return to ‘normal condition’. At least, that’s my understanding of this.

Yes, a breaking change is required to get the default to the correct behavior.

> [@MeshSlayer](#):
>
> an announcement would be great

We can announce something if we suspect many people will be affected. @Deltakosh @sebavan Any thoughts?

[Next page](https://forum.babylonjs.com/t/obj-exported-scene-rotated-180-around-up-axis/48825.md?page=2)
