浏览代码

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 年之前
父节点
当前提交
6032dfe9e1
共有 2 个文件被更改,包括 3 次插入3 次删除
  1. 1 1
      loaders/src/glTF/2.0/glTFLoader.ts
  2. 2 2
      serializers/src/glTF/2.0/glTFExporter.ts

+ 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 {
         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.enableSpecularAntiAliasing = true;
         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) {
                         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;
                             if (byteOffset == null) { byteOffset = 0; }
                             let babylonIndices: Nullable<IndicesArray> = null;