Pārlūkot izejas kodu

Revision of proposed fix, removed exporter winding reversal based on coordinate system (since we already accomodate for this via inverting the worldspace on export to RH CCW). Added a check for world matrix inversion on export. Inverted GLTF loader winding (since the Babylon default should be LH CCW, rather than LH CW)

Nicholas Barlow 6 gadi atpakaļ
vecāks
revīzija
6032dfe9e1

+ 1 - 1
loaders/src/glTF/2.0/glTFLoader.ts

@@ -1558,7 +1558,7 @@ export class GLTFLoader implements IGLTFLoader {
 
 
     private _createDefaultMaterial(name: string, babylonDrawMode: number): Material {
     private _createDefaultMaterial(name: string, babylonDrawMode: number): Material {
         const babylonMaterial = new PBRMaterial(name, this._babylonScene);
         const babylonMaterial = new PBRMaterial(name, this._babylonScene);
-        babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
+        babylonMaterial.sideOrientation = !this._babylonScene.useRightHandedSystem ? Material.ClockWiseSideOrientation : Material.CounterClockWiseSideOrientation;
         babylonMaterial.fillMode = babylonDrawMode;
         babylonMaterial.fillMode = babylonDrawMode;
         babylonMaterial.enableSpecularAntiAliasing = true;
         babylonMaterial.enableSpecularAntiAliasing = true;
         babylonMaterial.useRadianceOverAlpha = !this._parent.transparencyAsCoverage;
         babylonMaterial.useRadianceOverAlpha = !this._parent.transparencyAsCoverage;

+ 2 - 2
serializers/src/glTF/2.0/glTFExporter.ts

@@ -1195,8 +1195,8 @@ export class _Exporter {
                     if (materialIndex != null && Object.keys(meshPrimitive.attributes).length > 0) {
                     if (materialIndex != null && Object.keys(meshPrimitive.attributes).length > 0) {
                         let sideOrientation = babylonMaterial.sideOrientation;
                         let sideOrientation = babylonMaterial.sideOrientation;
 
 
-                        if (this._convertToRightHandedSystem || sideOrientation === Material.ClockWiseSideOrientation) {
-                            //Overwrite the indices to be counter-clockwise
+                        // Only reverse the winding if we have a clockwise winding in a positive worldspace
+                        if (sideOrientation === Material.ClockWiseSideOrientation && babylonTransformNode._getWorldMatrixDeterminant() > 0){
                             let byteOffset = indexBufferViewIndex != null ? this._bufferViews[indexBufferViewIndex].byteOffset : null;
                             let byteOffset = indexBufferViewIndex != null ? this._bufferViews[indexBufferViewIndex].byteOffset : null;
                             if (byteOffset == null) { byteOffset = 0; }
                             if (byteOffset == null) { byteOffset = 0; }
                             let babylonIndices: Nullable<IndicesArray> = null;
                             let babylonIndices: Nullable<IndicesArray> = null;