瀏覽代碼

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

David Catuhe 8 年之前
父節點
當前提交
8d42165d9a

+ 34 - 17
loaders/src/glTF/2.0/babylon.glTFLoader.ts

@@ -489,8 +489,6 @@ module BABYLON.GLTF2 {
         var indexStarts = [];
         var indexCounts = [];
 
-        var morphTargetManager: MorphTargetManager;
-
         // Positions, normals and UVs
         for (var primitiveIndex = 0; primitiveIndex < mesh.primitives.length; primitiveIndex++) {
             // Temporary vertex data
@@ -546,7 +544,6 @@ module BABYLON.GLTF2 {
             if (accessor) {
                 buffer = GLTFUtils.GetBufferFromAccessor(runtime, accessor);
                 tempVertexData.indices = <Uint32Array>buffer;
-                indexCounts.push(tempVertexData.indices.length);
             }
             else {
                 // Set indices on the fly
@@ -554,9 +551,8 @@ module BABYLON.GLTF2 {
                 for (var index = 0; index < tempVertexData.indices.length; index++) {
                     tempVertexData.indices[index] = index;
                 }
-
-                indexCounts.push(tempVertexData.indices.length);
             }
+            indexCounts.push(tempVertexData.indices.length);
 
             vertexData.merge(tempVertexData);
             tempVertexData = undefined;
@@ -623,12 +619,11 @@ module BABYLON.GLTF2 {
                     }
 
                     if (morph.getPositions()) {
-                        if (!morphTargetManager) {
-                            morphTargetManager = new MorphTargetManager();
-                            babylonMesh.morphTargetManager = morphTargetManager;
+                        if (!babylonMesh.morphTargetManager) {
+                            babylonMesh.morphTargetManager = new MorphTargetManager();
                         }
 
-                        morphTargetManager.addTarget(morph);
+                        babylonMesh.morphTargetManager.addTarget(morph);
                     }
                     else {
                         Tools.Warn("Not adding morph target '" + morph.name + "' because it has no position data");
@@ -917,7 +912,34 @@ module BABYLON.GLTF2 {
             return material;
         }
 
-        public static LoadMetallicRoughnessMaterialPropertiesAsync(runtime: IGLTFRuntime, material: IGLTFMaterial, onSuccess: () => void, onError: () => void): void {
+        public static LoadCoreMaterialAsync(runtime: IGLTFRuntime, index: number, onSuccess: () => void, onError: () => void): void {
+            var material = GLTFLoader.LoadMaterial(runtime, index);
+            if (!material) {
+                onSuccess();
+                return;
+            }
+
+            var metallicRoughnessPropertiesSuccess = false;
+            var commonPropertiesSuccess = false;
+
+            var checkSuccess = () => {
+                if (metallicRoughnessPropertiesSuccess && commonPropertiesSuccess) {
+                    onSuccess();
+                }
+            }
+
+            GLTFLoader._loadMetallicRoughnessMaterialPropertiesAsync(runtime, material, () => {
+                metallicRoughnessPropertiesSuccess = true;
+                checkSuccess();
+            }, onError);
+
+            GLTFLoader.LoadCommonMaterialPropertiesAsync(runtime, material, () => {
+                commonPropertiesSuccess = true;
+                checkSuccess();
+            }, onError);
+        }
+
+        private static _loadMetallicRoughnessMaterialPropertiesAsync(runtime: IGLTFRuntime, material: IGLTFMaterial, onSuccess: () => void, onError: () => void): void {
             // Ensure metallic workflow
             material.babylonMaterial.metallic = 1;
             material.babylonMaterial.roughness = 1;
@@ -933,8 +955,8 @@ module BABYLON.GLTF2 {
             //
 
             material.babylonMaterial.albedoColor = properties.baseColorFactor ? Color3.FromArray(properties.baseColorFactor) : new Color3(1, 1, 1);
-            material.babylonMaterial.metallic = properties.metallicFactor || 1;
-            material.babylonMaterial.roughness = properties.roughnessFactor || 1;
+            material.babylonMaterial.metallic = properties.metallicFactor === undefined ? 1 : properties.metallicFactor;
+            material.babylonMaterial.roughness = properties.roughnessFactor === undefined ? 1 : properties.roughnessFactor;
 
             //
             // Load Textures
@@ -1190,17 +1212,12 @@ module BABYLON.GLTF2 {
                 }
             }
 
-            // Load buffers, materials, etc.
             GLTFLoader._loadBuffersAsync(runtime, () => {
                 GLTFLoader._loadMaterialsAsync(runtime, () => {
                     postLoad(runtime);
                     onSuccess(meshes, null, skeletons);
                 }, onError);
             }, onError);
-
-            if (BABYLON.GLTFFileLoader.IncrementalLoading && onSuccess) {
-                onSuccess(meshes, null, skeletons);
-            }
         }
 
         /**

+ 10 - 27
loaders/src/glTF/2.0/babylon.glTFLoaderExtension.ts

@@ -4,6 +4,8 @@ module BABYLON.GLTF2 {
     export abstract class GLTFLoaderExtension {
         private _name: string;
 
+        public enabled: boolean = true;
+
         public constructor(name: string) {
             this._name = name;
         }
@@ -24,42 +26,23 @@ module BABYLON.GLTF2 {
         public static PostCreateRuntime(runtime: IGLTFRuntime): void {
             for (var extensionName in GLTFLoader.Extensions) {
                 var extension = GLTFLoader.Extensions[extensionName];
-                extension.postCreateRuntime(runtime);
+                if (extension.enabled) {
+                    extension.postCreateRuntime(runtime);
+                }
             }
         }
 
         public static LoadMaterialAsync(runtime: IGLTFRuntime, index: number, onSuccess: () => void, onError: () => void): void {
             for (var extensionName in GLTFLoader.Extensions) {
                 var extension = GLTFLoader.Extensions[extensionName];
-                if (extension.loadMaterialAsync(runtime, index, onSuccess, onError)) {
-                    return;
+                if (extension.enabled) {
+                    if (extension.loadMaterialAsync(runtime, index, onSuccess, onError)) {
+                        return;
+                    }
                 }
             }
 
-            var material = GLTFLoader.LoadMaterial(runtime, index);
-            if (!material) {
-                onSuccess();
-                return;
-            }
-
-            var metallicRoughnessPropertiesSuccess = false;
-            var commonPropertiesSuccess = false;
-
-            var checkSuccess = () => {
-                if (metallicRoughnessPropertiesSuccess && commonPropertiesSuccess) {
-                    onSuccess();
-                }
-            }
-
-            GLTFLoader.LoadMetallicRoughnessMaterialPropertiesAsync(runtime, material, () => {
-                metallicRoughnessPropertiesSuccess = true;
-                checkSuccess();
-            }, onError);
-
-            GLTFLoader.LoadCommonMaterialPropertiesAsync(runtime, material, () => {
-                commonPropertiesSuccess = true;
-                checkSuccess();
-            }, onError);
+            GLTFLoader.LoadCoreMaterialAsync(runtime, index, onSuccess, onError);
         }
     }
 }

+ 1 - 0
materialsLibrary/src/cell/babylon.cellMaterial.ts

@@ -18,6 +18,7 @@ module BABYLON {
         public NDOTL = true;
         public CUSTOMUSERLIGHTING = true;
         public CELLBASIC = true;
+        public USERIGHTHANDEDSYSTEM = false;
 
         constructor() {
             super();

+ 1 - 0
materialsLibrary/src/fur/babylon.furMaterial.ts

@@ -17,6 +17,7 @@ module BABYLON {
         public BonesPerMesh = 0;
         public INSTANCES = false;
         public HIGHLEVEL = false;
+        public USERIGHTHANDEDSYSTEM = false;
 
         constructor() {
             super();

+ 1 - 0
materialsLibrary/src/gradient/babylon.gradientMaterial.ts

@@ -48,6 +48,7 @@ module BABYLON {
         public NUM_BONE_INFLUENCERS = 0;
         public BonesPerMesh = 0;
         public INSTANCES = false;
+        public USERIGHTHANDEDSYSTEM = false;
 
         constructor() {
             super();

+ 2 - 0
materialsLibrary/src/grid/babylon.gridmaterial.ts

@@ -6,6 +6,8 @@ module BABYLON {
 
         public FOG = false;
 
+        public USERIGHTHANDEDSYSTEM = false;
+
         constructor() {
             super();
             this.rebuild();

+ 1 - 0
materialsLibrary/src/lava/babylon.lavaMaterial.ts

@@ -48,6 +48,7 @@ module BABYLON {
         public NUM_BONE_INFLUENCERS = 0;
         public BonesPerMesh = 0;
         public INSTANCES = false;
+        public USERIGHTHANDEDSYSTEM = false;
 
         constructor() {
             super();

+ 1 - 0
materialsLibrary/src/normal/babylon.normalMaterial.ts

@@ -48,6 +48,7 @@ module BABYLON {
         public NUM_BONE_INFLUENCERS = 0;
         public BonesPerMesh = 0;
         public INSTANCES = false;
+        public USERIGHTHANDEDSYSTEM = false;
 
         constructor() {
             super();

+ 1 - 0
materialsLibrary/src/shadowOnly/babylon.shadowOnlyMaterial.ts

@@ -9,6 +9,7 @@ module BABYLON {
         public NUM_BONE_INFLUENCERS = 0;
         public BonesPerMesh = 0;
         public INSTANCES = false;
+        public USERIGHTHANDEDSYSTEM = false;
 
         constructor() {
             super();

+ 1 - 0
materialsLibrary/src/simple/babylon.simpleMaterial.ts

@@ -15,6 +15,7 @@ module BABYLON {
         public NUM_BONE_INFLUENCERS = 0;
         public BonesPerMesh = 0;
         public INSTANCES = false;
+        public USERIGHTHANDEDSYSTEM = false;
 
         constructor() {
             super();

+ 1 - 0
materialsLibrary/src/sky/babylon.skyMaterial.ts

@@ -7,6 +7,7 @@ module BABYLON {
         public FOG = false;
         public VERTEXCOLOR = false;
         public VERTEXALPHA = false;
+        public USERIGHTHANDEDSYSTEM = false;
 
         constructor() {
             super();

+ 1 - 0
materialsLibrary/src/terrain/babylon.terrainMaterial.ts

@@ -18,6 +18,7 @@ module BABYLON {
         public NUM_BONE_INFLUENCERS = 0;
         public BonesPerMesh = 0;
         public INSTANCES = false;
+        public USERIGHTHANDEDSYSTEM = false;
 
         constructor() {
             super();

+ 1 - 0
materialsLibrary/src/triPlanar/babylon.triPlanarMaterial.ts

@@ -21,6 +21,7 @@ module BABYLON {
         public NUM_BONE_INFLUENCERS = 0;
         public BonesPerMesh = 0;
         public INSTANCES = false;
+        public USERIGHTHANDEDSYSTEM = false;
 
         constructor() {
             super();

+ 1 - 1
materialsLibrary/src/water/babylon.waterMaterial.ts

@@ -21,7 +21,7 @@ module BABYLON {
         public FRESNELSEPARATE = false;
         public BUMPSUPERIMPOSE = false;
         public BUMPAFFECTSREFLECTION = false;
-
+        public USERIGHTHANDEDSYSTEM = false;
 
         constructor() {
             super();

+ 1 - 0
src/Materials/babylon.materialHelper.ts

@@ -6,6 +6,7 @@
                 defines["LOGARITHMICDEPTH"] = useLogarithmicDepth;
                 defines["POINTSIZE"] = (pointsCloud || scene.forcePointsCloud);
                 defines["FOG"] = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE && fogEnabled);
+                defines["USERIGHTHANDEDSYSTEM"] = scene.useRightHandedSystem;
             }
         }
 

+ 6 - 1
src/Materials/babylon.pbrMaterial.ts

@@ -66,6 +66,7 @@
         public INVERTNORMALMAPY = false;
         public TWOSIDEDLIGHTING = false;
         public SHADOWFULLFLOAT = false;
+        public USERIGHTHANDEDSYSTEM = false;
 
         public METALLICWORKFLOW = false;
         public METALLICMAP = false;
@@ -763,7 +764,11 @@
                     if (scene._mirroredCameraPosition) {
                         this._defines.INVERTNORMALMAPX = !this._defines.INVERTNORMALMAPX;
                         this._defines.INVERTNORMALMAPY = !this._defines.INVERTNORMALMAPY;
-                    }                        
+                    }
+
+                    if (scene.useRightHandedSystem) {
+                        this._defines.USERIGHTHANDEDSYSTEM = true;
+                    }
                 }
 
                 if (this.refractionTexture && StandardMaterial.RefractionTextureEnabled) {

+ 1 - 0
src/Materials/babylon.standardMaterial.ts

@@ -63,6 +63,7 @@ module BABYLON {
         public MORPHTARGETS_NORMAL = false;
         public MORPHTARGETS_TANGENT = false;
         public NUM_MORPH_INFLUENCERS = 0;
+        public USERIGHTHANDEDSYSTEM = false;
 
         constructor() {
             super();

+ 4 - 0
src/Shaders/ShadersInclude/bumpFragmentFunctions.fx

@@ -23,6 +23,10 @@
 		vec3 tangent = dp2perp * duv1.x + dp1perp * duv2.x;
 		vec3 binormal = dp2perp * duv1.y + dp1perp * duv2.y;
 
+	#ifdef USERIGHTHANDEDSYSTEM
+		binormal = -binormal;
+	#endif
+
 		// construct a scale-invariant frame 
 		float invmax = inversesqrt(max(dot(tangent, tangent), dot(binormal, binormal)));
 		return mat3(tangent * invmax, binormal * invmax, normal);

+ 17 - 1
src/babylon.scene.ts

@@ -206,7 +206,6 @@
         public clipPlane: Plane;
         public animationsEnabled = true;
         public constantlyUpdateMeshUnderPointer = false;
-        public useRightHandedSystem = false;
 
         public hoverCursor = "pointer";
 
@@ -414,6 +413,23 @@
         private _onKeyDown: (evt: Event) => void;
         private _onKeyUp: (evt: Event) => void;
 
+        // Coordinate system
+        /**
+        * use right-handed coordinate system on this scene.
+        * @type {boolean}
+        */
+        private _useRightHandedSystem = false;
+        public set useRightHandedSystem(value: boolean) {
+            if (this._useRightHandedSystem === value) {
+                return;
+            }
+            this._useRightHandedSystem = value;
+            this.markAllMaterialsAsDirty(Material.MiscDirtyFlag);
+        }
+        public get useRightHandedSystem(): boolean {
+            return this._useRightHandedSystem;
+        }
+
         // Fog
         /**
         * is fog enabled on this scene.