OBJ export mirrored?


I ran into this issue today, please let me know if this is a potential bug or a misusage of Babylon.js API :wink: .

Consider this very simple demo playground (forked it from another issue):


From this playground, I’m exporting a OBJ file with BABYLON.OBJExport.OBJ and also a GLB file using the inspector and “export glb” button

This gives me those two files:

Then I import those files into Blender I get this

GLB file (correct)

Screenshot 2020-05-14 at 09.30.22

OBJ file ( mirrored)

Screenshot 2020-05-14 at 09.29.58

Both on the same canvas

It looks like some magic transform settings I need to set… tried to play around with things but couldn’t make the GLB export match the OBJ export.

Any ideas ?


Hey there.
I stumbled accross a related issure when importing .obj into the sandbox:

Maybe they are related?
Lets wait for some input from the devs.

@tdurand @mamu

OBJ is a right handed format. I believe the inversion you’re seeing is due to our mesh being exported from babylon’s left handed system to OBJ, then imported into blender’s right handed system. even if we align the proper forward, and up vector, then our right vector is inverted. that’s not right… I’ll try to fix that.

I imagine if the OBJ is exported from a right handed babylon scene, then we would not see this inversion…

Actually after further investigation, i’m not sure if that’s the case. see:

imported into Blender with default settings we see:

Which is incorrect, but that’s because we’re using the wrong settings.

Babylon, like Unity is a left handed coordinate system with +Z forward, +Y up and +X right. changing the import settings to:

We should instead get:

This seems to work regardless of export from babylon using global or local coordinates and scene handedness…I’m not sure if any fixes need to be made here…


Thanks for looking into this. I tried to play with the -Z + Z options when importing in blender but I’m not able to have the same models. Seems the obj is Mirrored on the X axis

I’ve made up a “not symetrical” scene so you can reproduce what I mean.

Consider this playground with a Terrain mesh generated from height map


Then this is exported as OBJ and GLB:

Then in blender I get his

For GLB file with +Z forward:

For OBJ file import with +Z forward:

Thanks !

Ah, I see what you mean.

Using this PG:

If you change the scene handedness to right handed, the OBJ and GLB export are identical, as would be expected. Otherwise, if we use a left handed system, the OBJ and GLB export are mirrored along the X axis. When imported to Blender with default settings…not great.

Would you be interested in delivering a fix to the OBJ exporter? I expect we would just need to add an additional parameter to the OBJSerializer.OBJ that represents whether or not to convert our model geometry to right handed coordinates, and invert the geometry X position as a result.


Yes I would be interested in trying to work on this over the week-end, could you give two pointers (sorry I didn’t looked up the documentation as I’m on my mobile and also I’m not an expert with Babylon.js and 3D)

Many Thanks


Ok I was able to do what you said by using

scene.useRightHandedSystem = true;

Now I’m looking into fixing the OBJ Exporter depending on whether this flag is true or false

I would need some help with this… I’m trying to figure out how to flip the geometry along the X axis …

I’ve tried to do this:

// invert along X axis
var inversionAlongXAxisMatrix = Matrix.FromValues(
                -1, 0, 0, 0,
                0, 1, 0, 0,
                0, 0, 1, 0,
                0, 0, 0, 1)

Inside the OBJ serializer… but the export is still incorrect… Any idea ?

Thanks and have a nice week-end

Try modifying the vertices immediately before exporting to our OBJ:

Where we may want to invert trunkVerts[i] (@L70) depending on the scene handedness

Ok, it does work !

I’ve started a pull request: Fix OBJ serializing mirrored by tdurand · Pull Request #8216 · BabylonJS/Babylon.js · GitHub :wink:

1 Like

Thanks, I’ll test your fix before signing off

1 Like

Marking this as solved, the PR was merged : Fix OBJ serializing mirrored by tdurand · Pull Request #8216 · BabylonJS/Babylon.js · GitHub

1 Like