Babylon.js: Material SideOrientation/Normal flipped during glb export

Created on 22 Mar 2019  路  3Comments  路  Source: BabylonJS/Babylon.js

Bugs

Forum:
https://forum.babylonjs.com/t/material-sideorientation-normal-flipped-during-glb-export/2046

bug glTF

Most helpful comment

After my first iteration, I realized that the coordinate system handedness shouldn't be relevant to how we handle reversing the mesh winding. Babylon applies an inverting transformation to imported GLTF files, and applies a similar transformation when exporting to GLTF in order to convert to a RightHand coordinate system.

However, we didn't previously account for this transform when exporting, so adding an additional check to only flip Clockwise->Counterclockwise when in a positive world space.

Making the following change appears to fix our problem.

EDIT 4/5/2019
After some intense debugging with @bghgary , we found that we don't need to check the world determinant's sign either. Removing the previous check that only rewound the meshes for Left hand coordinate systems was all that was required.

All 3 comments

This one if for @drigax

Looks like we currently only reverse the winding when exporting a mesh in a Left Hand coordinate system in Babylon with Clockwise triangle winding to GLTF, which is strictly Right Hand Coordinate System with Counterclockwise triangle winding.

That should explain why this only reproduces when we setup the scene with right hand coordinate system, as our materials are setup to have clockwise side orientation by default.

I believe that changing our exporter to reverse the triangle winding when we are either in a left hand coordinate system, or are working with a mesh with material indicating clockwise side orientation should fix our issue, so that we're always reversing the mesh winding when needed.

After my first iteration, I realized that the coordinate system handedness shouldn't be relevant to how we handle reversing the mesh winding. Babylon applies an inverting transformation to imported GLTF files, and applies a similar transformation when exporting to GLTF in order to convert to a RightHand coordinate system.

However, we didn't previously account for this transform when exporting, so adding an additional check to only flip Clockwise->Counterclockwise when in a positive world space.

Making the following change appears to fix our problem.

EDIT 4/5/2019
After some intense debugging with @bghgary , we found that we don't need to check the world determinant's sign either. Removing the previous check that only rewound the meshes for Left hand coordinate systems was all that was required.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vvega-kkg picture vvega-kkg  路  3Comments

aWeirdo picture aWeirdo  路  4Comments

phuein picture phuein  路  3Comments

CadsoftBrianW picture CadsoftBrianW  路  3Comments

Speuta picture Speuta  路  5Comments