# Material SideOrientation/Normal flipped during glb export

**URL:** <https://forum.babylonjs.com/t/material-sideorientation-normal-flipped-during-glb-export/2046>\
**Category:** Bugs\
**Created:** [March 21, 2019, 3:31pm UTC](https://forum.babylonjs.com/t/material-sideorientation-normal-flipped-during-glb-export/2046 "2019-03-21T15:31:28Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![BrianW](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@BrianW](https://forum.babylonjs.com/u/BrianW)\
**Post date:** [March 21, 2019, 3:31pm UTC](https://forum.babylonjs.com/t/material-sideorientation-normal-flipped-during-glb-export/2046/1 "2019-03-21T15:31:28Z")

</div>

Hello!

I am importing an obj file into my scene. Then I am exporting it using GLTF2Export.GLBAsync.  
I am using a right-handed coordinate system. When I re-import the glb file I have the wrong sideOrientation on materials. Is it possibly an issue of converting between standard material and PBR material not taking into account the right handed coordinate system? When I switch to left handed it works fine.

Best Regards,  
-Brian

---

<div class="post-metadata">

**Author:** ![MZIskandar](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mziskandar/32/422_2.png) [@MZIskandar](https://forum.babylonjs.com/u/MZIskandar)\
**Post date:** [March 21, 2019, 3:37pm UTC](https://forum.babylonjs.com/t/material-sideorientation-normal-flipped-during-glb-export/2046/2 "2019-03-21T15:37:05Z")

</div>

Try…

var theMesh = scene.getMeshByID(“theMeshName”);  
theMesh.overrideMaterialSideOrientation = 1;

---

<div class="post-metadata">

**Author:** ![BrianW](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@BrianW](https://forum.babylonjs.com/u/BrianW)\
**Post date:** [March 21, 2019, 3:42pm UTC](https://forum.babylonjs.com/t/material-sideorientation-normal-flipped-during-glb-export/2046/3 "2019-03-21T15:42:39Z")

</div>

That would fix the issue but it seems like a band-aid?

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [March 21, 2019, 4:32pm UTC](https://forum.babylonjs.com/t/material-sideorientation-normal-flipped-during-glb-export/2046/4 "2019-03-21T16:32:10Z")

</div>

This should work as we are taking the useRightHandedSystem in account in the exporter.  
Can you repro on the playground?  
Pinging @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 21, 2019, 4:32pm UTC](https://forum.babylonjs.com/t/material-sideorientation-normal-flipped-during-glb-export/2046/5 "2019-03-21T16:32:45Z")

</div>

Yeah, this sounds like a bug. A PG would be helpful.

---

<div class="post-metadata">

**Author:** ![BrianW](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@BrianW](https://forum.babylonjs.com/u/BrianW)\
**Post date:** [March 21, 2019, 6:30pm UTC](https://forum.babylonjs.com/t/material-sideorientation-normal-flipped-during-glb-export/2046/6 "2019-03-21T18:30:41Z")

</div>

I’m working on a playground. I got it to this point:  
[https://www.babylonjs-playground.com/#95MJI8#15](https://www.babylonjs-playground.com/#95MJI8#15)

Unable to import exported glb at the moment.

---

<div class="post-metadata">

**Author:** ![BrianW](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@BrianW](https://forum.babylonjs.com/u/BrianW)\
**Post date:** [March 21, 2019, 7:44pm UTC](https://forum.babylonjs.com/t/material-sideorientation-normal-flipped-during-glb-export/2046/7 "2019-03-21T19:44:06Z")

</div>

Okay I can reproduce it now.  
Here you go:  
[https://www.babylonjs-playground.com/#95MJI8#22](https://www.babylonjs-playground.com/#95MJI8#22)

When right handed the material orientation is wrong.

---

<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 22, 2019, 12:26am UTC](https://forum.babylonjs.com/t/material-sideorientation-normal-flipped-during-glb-export/2046/8 "2019-03-22T00:26:56Z")

</div>

@BrianW Thanks for the PG. Do you mind filing a GitHub issue?

---

<div class="post-metadata">

**Author:** ![BrianW](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@BrianW](https://forum.babylonjs.com/u/BrianW)\
**Post date:** [March 22, 2019, 12:15pm UTC](https://forum.babylonjs.com/t/material-sideorientation-normal-flipped-during-glb-export/2046/9 "2019-03-22T12:15:40Z")

</div>

Not at all. Here you go:

> <https://github.com/BabylonJS/Babylon.js/issues/6103>

Thanks!

---

<div class="post-metadata">

**Author:** ![BrianW](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@BrianW](https://forum.babylonjs.com/u/BrianW)\
**Post date:** [May 14, 2019, 6:45pm UTC](https://forum.babylonjs.com/t/material-sideorientation-normal-flipped-during-glb-export/2046/10 "2019-05-14T18:45:02Z")

</div>

I’m having the same issue with another block. I believe it has something to do with multi-material.

Also the difference in lighting between the direct import vs glb import is strange if anyone could explain it to me I would be very happy.  
[https://www.babylonjs-playground.com/index.html#95MJI8#32](https://www.babylonjs-playground.com/index.html#95MJI8#32)

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [May 14, 2019, 6:50pm UTC](https://forum.babylonjs.com/t/material-sideorientation-normal-flipped-during-glb-export/2046/11 "2019-05-14T18:50:18Z")

</div>

pinging @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:** [May 14, 2019, 7:53pm UTC](https://forum.babylonjs.com/t/material-sideorientation-normal-flipped-during-glb-export/2046/12 "2019-05-14T19:53:46Z")

</div>

The root of the problem is that the babylon file is referencing a texture `https://dl.dropbox.com/s/oziv24ps27qhel2/basket_texture.jpg` that isn’t an image. The handling of this is wrong somewhere in the rendering/export for this edge case, but fixing the asset will probably make it work.

---

<div class="post-metadata">

**Author:** ![BrianW](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@BrianW](https://forum.babylonjs.com/u/BrianW)\
**Post date:** [May 15, 2019, 12:37pm UTC](https://forum.babylonjs.com/t/material-sideorientation-normal-flipped-during-glb-export/2046/13 "2019-05-15T12:37:58Z")

</div>

Replaced texture with base64 string. The issue seems to still be there…  
[https://www.babylonjs-playground.com/index.html#95MJI8#33](https://www.babylonjs-playground.com/index.html#95MJI8#33)

---

<div class="post-metadata">

**Author:** ![BrianW](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@BrianW](https://forum.babylonjs.com/u/BrianW)\
**Post date:** [May 15, 2019, 6:06pm UTC](https://forum.babylonjs.com/t/material-sideorientation-normal-flipped-during-glb-export/2046/14 "2019-05-15T18:06:25Z")

</div>

I was not adding in the multi-material + sub materials to the scene. This fixed the side-orientation issue.  
Texture doesn’t seem to import though.

[https://www.babylonjs-playground.com/index.html#95MJI8#34](https://www.babylonjs-playground.com/index.html#95MJI8#34)

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [May 15, 2019, 10:54pm UTC](https://forum.babylonjs.com/t/material-sideorientation-normal-flipped-during-glb-export/2046/15 "2019-05-15T22:54:30Z")

</div>

@bghgary should be able to answer soon (We have a busy week, sorry for the inconvenience )

---

<div class="post-metadata">

**Author:** ![BrianW](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@BrianW](https://forum.babylonjs.com/u/BrianW)\
**Post date:** [May 16, 2019, 11:42am UTC](https://forum.babylonjs.com/t/material-sideorientation-normal-flipped-during-glb-export/2046/16 "2019-05-16T11:42:26Z")

</div>

No problem. Thanks for the help.

---

<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:** [May 16, 2019, 5:27pm UTC](https://forum.babylonjs.com/t/material-sideorientation-normal-flipped-during-glb-export/2046/17 "2019-05-16T17:27:08Z")

</div>

Looks like there is an issue with the exporting code. @BrianW Can you file an issue on GitHub? @Drigax Can you look at this? Something is wrong with the way the materials are being exported. I can show you offline.

---

<div class="post-metadata">

**Author:** ![Drigax](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/drigax/32/16585_2.png) [@Drigax](https://forum.babylonjs.com/u/Drigax)\
**Post date:** [May 17, 2019, 11:41am UTC](https://forum.babylonjs.com/t/material-sideorientation-normal-flipped-during-glb-export/2046/18 "2019-05-17T11:41:18Z")

</div>

Sure, I have about 2 weeks worth of backlog to get through before I can give this my full attention, but I’d greatly appreciate any analysis 🙂

---

<div class="post-metadata">

**Author:** ![BrianW](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@BrianW](https://forum.babylonjs.com/u/BrianW)\
**Post date:** [May 21, 2019, 2:50pm UTC](https://forum.babylonjs.com/t/material-sideorientation-normal-flipped-during-glb-export/2046/19 "2019-05-21T14:50:56Z")

</div>

Heres the issue:

> <https://github.com/BabylonJS/Babylon.js/issues/6373>

---

<div class="post-metadata">

**Author:** ![trevordev](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/trevordev/32/16_2.png) [@trevordev](https://forum.babylonjs.com/u/trevordev)\
**Post date:** [May 22, 2019, 5:12pm UTC](https://forum.babylonjs.com/t/material-sideorientation-normal-flipped-during-glb-export/2046/20 "2019-05-22T17:12:34Z")

</div>

Thanks for creating the issue, I’ll try to take a look at this today.

Created a possible PR to fix this here:

> <https://github.com/BabylonJS/Babylon.js/pull/6381>
