Browse Source

Merge remote-tracking branch 'BabylonJS/master'

MackeyK24 8 years ago
parent
commit
d2b2105c04
62 changed files with 21538 additions and 21306 deletions
  1. BIN
      assets/meshes/Tree/Tree.tga
  2. 5 0
      assets/meshes/Tree/tree.babylon
  3. 4149 4126
      dist/preview release/babylon.d.ts
  4. 42 42
      dist/preview release/babylon.js
  5. 100 49
      dist/preview release/babylon.max.js
  6. 4149 4126
      dist/preview release/babylon.module.d.ts
  7. 43 43
      dist/preview release/babylon.worker.js
  8. 6151 6128
      dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts
  9. 33 33
      dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js
  10. 111 65
      dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js
  11. 6151 6128
      dist/preview release/customConfigurations/minimalGLTFViewer/babylon.module.d.ts
  12. 1 1
      dist/preview release/gui/babylon.gui.min.js
  13. 263 263
      dist/preview release/inspector/babylon.inspector.bundle.js
  14. 8 0
      dist/preview release/inspector/babylon.inspector.d.ts
  15. 40 40
      dist/preview release/inspector/babylon.inspector.js
  16. 3 3
      dist/preview release/inspector/babylon.inspector.min.js
  17. 2 2
      dist/preview release/loaders/babylon.glTF1FileLoader.min.js
  18. 5 6
      dist/preview release/loaders/babylon.glTF2FileLoader.d.ts
  19. 14 16
      dist/preview release/loaders/babylon.glTF2FileLoader.js
  20. 1 1
      dist/preview release/loaders/babylon.glTF2FileLoader.min.js
  21. 5 6
      dist/preview release/loaders/babylon.glTFFileLoader.d.ts
  22. 14 16
      dist/preview release/loaders/babylon.glTFFileLoader.js
  23. 2 2
      dist/preview release/loaders/babylon.glTFFileLoader.min.js
  24. 1 1
      dist/preview release/loaders/babylon.objFileLoader.min.js
  25. 0 2
      dist/preview release/materialsLibrary/babylon.customMaterial.d.ts
  26. 8 10
      dist/preview release/materialsLibrary/babylon.customMaterial.js
  27. 2 2
      dist/preview release/materialsLibrary/babylon.customMaterial.min.js
  28. 10 15
      dist/preview release/materialsLibrary/babylon.legacyPbrMaterial.js
  29. 3 3
      dist/preview release/materialsLibrary/babylon.legacyPbrMaterial.min.js
  30. 1 1
      dist/preview release/materialsLibrary/babylon.waterMaterial.min.js
  31. 1 1
      dist/preview release/postProcessesLibrary/babylon.asciiArtPostProcess.min.js
  32. 1 1
      dist/preview release/postProcessesLibrary/babylon.digitalRainPostProcess.min.js
  33. 37 0
      gui/package.json
  34. 6 0
      inspector/src/properties.ts
  35. 14 9
      inspector/src/tabs/ConsoleTab.ts
  36. 8 4
      inspector/src/tabs/StatsTab.ts
  37. 0 1
      inspector/src/tabs/TabBar.ts
  38. 19 34
      inspector/src/tabs/TextureTab.ts
  39. 14 4
      inspector/test/index.js
  40. 4 3
      loaders/src/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts
  41. 5 5
      loaders/src/glTF/2.0/Extensions/MSFT_lod.ts
  42. 12 16
      loaders/src/glTF/2.0/babylon.glTFLoader.ts
  43. 2 2
      loaders/src/glTF/2.0/babylon.glTFLoaderExtension.ts
  44. 8 12
      materialsLibrary/src/custom/babylon.customMaterial.ts
  45. 10 17
      materialsLibrary/src/legacyPBR/babylon.legacyPBRMaterial.ts
  46. 2 2
      materialsLibrary/src/legacyPBR/babylon.legacyPbrMaterial.js.include.fx
  47. 1 0
      materialsLibrary/src/legacyPBR/legacyPbrFragmentDeclaration.fx
  48. 1 0
      materialsLibrary/src/legacyPBR/legacyPbrUboDeclaration.fx
  49. 2 6
      package.json
  50. 3 0
      src/Audio/babylon.sound.ts
  51. 11 13
      src/Materials/PBR/babylon.pbrBaseMaterial.ts
  52. 14 0
      src/Materials/PBR/babylon.pbrMaterial.ts
  53. 14 10
      src/Materials/Textures/babylon.baseTexture.ts
  54. 5 5
      src/Materials/Textures/babylon.cubeTexture.ts
  55. 8 12
      src/Materials/babylon.standardMaterial.ts
  56. 2 6
      src/Shaders/ShadersInclude/bumpFragmentFunctions.fx
  57. 1 0
      src/Shaders/ShadersInclude/defaultFragmentDeclaration.fx
  58. 1 0
      src/Shaders/ShadersInclude/defaultUboDeclaration.fx
  59. 1 0
      src/Shaders/ShadersInclude/pbrFragmentDeclaration.fx
  60. 1 2
      src/Shaders/ShadersInclude/pbrLightFunctions.fx
  61. 1 0
      src/Shaders/ShadersInclude/pbrUboDeclaration.fx
  62. 12 11
      src/babylon.engine.ts

BIN
assets/meshes/Tree/Tree.tga


File diff suppressed because it is too large
+ 5 - 0
assets/meshes/Tree/tree.babylon


File diff suppressed because it is too large
+ 4149 - 4126
dist/preview release/babylon.d.ts


File diff suppressed because it is too large
+ 42 - 42
dist/preview release/babylon.js


File diff suppressed because it is too large
+ 100 - 49
dist/preview release/babylon.max.js


File diff suppressed because it is too large
+ 4149 - 4126
dist/preview release/babylon.module.d.ts


File diff suppressed because it is too large
+ 43 - 43
dist/preview release/babylon.worker.js


File diff suppressed because it is too large
+ 6151 - 6128
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts


File diff suppressed because it is too large
+ 33 - 33
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js


File diff suppressed because it is too large
+ 111 - 65
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js


File diff suppressed because it is too large
+ 6151 - 6128
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.module.d.ts


File diff suppressed because it is too large
+ 1 - 1
dist/preview release/gui/babylon.gui.min.js


File diff suppressed because it is too large
+ 263 - 263
dist/preview release/inspector/babylon.inspector.bundle.js


+ 8 - 0
dist/preview release/inspector/babylon.inspector.d.ts

@@ -113,6 +113,12 @@ declare module INSPECTOR {
         'BaseTexture': {
         'BaseTexture': {
             type: typeof BABYLON.BaseTexture;
             type: typeof BABYLON.BaseTexture;
         };
         };
+        'CubeTexture': {
+            type: typeof BABYLON.CubeTexture;
+        };
+        'HDRCubeTexture': {
+            type: typeof BABYLON.HDRCubeTexture;
+        };
         'FontTexture': {
         'FontTexture': {
             type: typeof BABYLON.FontTexture;
             type: typeof BABYLON.FontTexture;
         };
         };
@@ -969,6 +975,7 @@ declare module INSPECTOR {
         constructor(tabbar: TabBar, insp: Inspector);
         constructor(tabbar: TabBar, insp: Inspector);
         /** Overrides super.dispose */
         /** Overrides super.dispose */
         dispose(): void;
         dispose(): void;
+        active(b: boolean): void;
         private _message(type, message, caller);
         private _message(type, message, caller);
         private _addConsoleLog(...params);
         private _addConsoleLog(...params);
         private _addConsoleWarn(...params);
         private _addConsoleWarn(...params);
@@ -993,6 +1000,7 @@ declare module INSPECTOR {
         /** Update each properties of the stats panel */
         /** Update each properties of the stats panel */
         private _update();
         private _update();
         dispose(): void;
         dispose(): void;
+        active(b: boolean): void;
     }
     }
 }
 }
 
 

+ 40 - 40
dist/preview release/inspector/babylon.inspector.js

@@ -403,6 +403,12 @@ var INSPECTOR;
         'BaseTexture': {
         'BaseTexture': {
             type: BABYLON.BaseTexture
             type: BABYLON.BaseTexture
         },
         },
+        'CubeTexture': {
+            type: BABYLON.CubeTexture
+        },
+        'HDRCubeTexture': {
+            type: BABYLON.HDRCubeTexture
+        },
         'FontTexture': {
         'FontTexture': {
             type: BABYLON.FontTexture
             type: BABYLON.FontTexture
         },
         },
@@ -3147,12 +3153,13 @@ var INSPECTOR;
             INSPECTOR.Helpers.CleanDiv(this._imagePanel);
             INSPECTOR.Helpers.CleanDiv(this._imagePanel);
             // Get the texture object
             // Get the texture object
             var texture = item.adapter.object;
             var texture = item.adapter.object;
+            var imgs = [];
             var img = INSPECTOR.Helpers.CreateElement('img', 'texture-image', this._imagePanel);
             var img = INSPECTOR.Helpers.CreateElement('img', 'texture-image', this._imagePanel);
-            var img1 = INSPECTOR.Helpers.CreateElement('img', 'texture-image', this._imagePanel);
-            var img2 = INSPECTOR.Helpers.CreateElement('img', 'texture-image', this._imagePanel);
-            var img3 = INSPECTOR.Helpers.CreateElement('img', 'texture-image', this._imagePanel);
-            var img4 = INSPECTOR.Helpers.CreateElement('img', 'texture-image', this._imagePanel);
-            var img5 = INSPECTOR.Helpers.CreateElement('img', 'texture-image', this._imagePanel);
+            imgs.push(img);
+            //Create five other images elements
+            for (var i = 0; i < 5; i++) {
+                imgs.push(INSPECTOR.Helpers.CreateElement('img', 'texture-image', this._imagePanel));
+            }
             if (texture instanceof BABYLON.MapTexture) {
             if (texture instanceof BABYLON.MapTexture) {
                 // instance of Map texture
                 // instance of Map texture
                 texture.bindTextureForPosSize(new BABYLON.Vector2(0, 0), new BABYLON.Size(texture.getSize().width, texture.getSize().height), false);
                 texture.bindTextureForPosSize(new BABYLON.Vector2(0, 0), new BABYLON.Size(texture.getSize().width, texture.getSize().height), false);
@@ -3172,31 +3179,7 @@ var INSPECTOR;
                 screenShotTexture.onBeforeRenderObservable = texture.onBeforeRenderObservable;
                 screenShotTexture.onBeforeRenderObservable = texture.onBeforeRenderObservable;
                 // To display the texture after rendering
                 // To display the texture after rendering
                 screenShotTexture.onAfterRenderObservable.add(function (faceIndex) {
                 screenShotTexture.onAfterRenderObservable.add(function (faceIndex) {
-                    var targetImg;
-                    switch (faceIndex) {
-                        case 0:
-                            targetImg = img;
-                            break;
-                        case 1:
-                            targetImg = img1;
-                            break;
-                        case 2:
-                            targetImg = img2;
-                            break;
-                        case 3:
-                            targetImg = img3;
-                            break;
-                        case 4:
-                            targetImg = img4;
-                            break;
-                        case 5:
-                            targetImg = img5;
-                            break;
-                        default:
-                            targetImg = img;
-                            break;
-                    }
-                    BABYLON.Tools.DumpFramebuffer(size_1.width, size_1.height, engine_1, function (data) { return targetImg.src = data; }, "image/png");
+                    BABYLON.Tools.DumpFramebuffer(size_1.width, size_1.height, engine_1, function (data) { return imgs[faceIndex].src = data; }, "image/png");
                 });
                 });
                 // Render the texture
                 // Render the texture
                 scene.incrementRenderId();
                 scene.incrementRenderId();
@@ -3204,6 +3187,15 @@ var INSPECTOR;
                 screenShotTexture.render();
                 screenShotTexture.render();
                 screenShotTexture.dispose();
                 screenShotTexture.dispose();
             }
             }
+            else if (texture instanceof BABYLON.CubeTexture) {
+                // Display all textures of the CubeTexture
+                var i = 0;
+                for (var _i = 0, _a = texture['_files']; _i < _a.length; _i++) {
+                    var filename = _a[_i];
+                    imgs[i].src = filename;
+                    i++;
+                }
+            }
             else if (texture.url) {
             else if (texture.url) {
                 // If an url is present, the texture is an image
                 // If an url is present, the texture is an image
                 img.src = texture.url;
                 img.src = texture.url;
@@ -3745,13 +3737,6 @@ var INSPECTOR;
             // Contents
             // Contents
             _this._consolePanelContent = INSPECTOR.Helpers.CreateDiv('console-panel-content', consolePanel);
             _this._consolePanelContent = INSPECTOR.Helpers.CreateDiv('console-panel-content', consolePanel);
             _this._bjsPanelContent = INSPECTOR.Helpers.CreateDiv('console-panel-content', bjsPanel);
             _this._bjsPanelContent = INSPECTOR.Helpers.CreateDiv('console-panel-content', bjsPanel);
-            // save old console.log
-            _this._oldConsoleLog = console.log;
-            _this._oldConsoleWarn = console.warn;
-            _this._oldConsoleError = console.error;
-            console.log = _this._addConsoleLog.bind(_this);
-            console.warn = _this._addConsoleWarn.bind(_this);
-            console.error = _this._addConsoleError.bind(_this);
             // Bjs logs
             // Bjs logs
             _this._bjsPanelContent.innerHTML = BABYLON.Tools.LogCache;
             _this._bjsPanelContent.innerHTML = BABYLON.Tools.LogCache;
             BABYLON.Tools.OnNewCacheEntry = function (entry) {
             BABYLON.Tools.OnNewCacheEntry = function (entry) {
@@ -3775,6 +3760,18 @@ var INSPECTOR;
             console.warn = this._oldConsoleWarn;
             console.warn = this._oldConsoleWarn;
             console.error = this._oldConsoleError;
             console.error = this._oldConsoleError;
         };
         };
+        ConsoleTab.prototype.active = function (b) {
+            _super.prototype.active.call(this, b);
+            if (b) {
+                // save old console.log
+                this._oldConsoleLog = console.log;
+                this._oldConsoleWarn = console.warn;
+                this._oldConsoleError = console.error;
+                console.log = this._addConsoleLog.bind(this);
+                console.warn = this._addConsoleWarn.bind(this);
+                console.error = this._addConsoleError.bind(this);
+            }
+        };
         ConsoleTab.prototype._message = function (type, message, caller) {
         ConsoleTab.prototype._message = function (type, message, caller) {
             var callerLine = INSPECTOR.Helpers.CreateDiv('caller', this._consolePanelContent);
             var callerLine = INSPECTOR.Helpers.CreateDiv('caller', this._consolePanelContent);
             callerLine.textContent = caller;
             callerLine.textContent = caller;
@@ -4089,8 +4086,6 @@ var INSPECTOR;
                     updateFct: function () { return "WebGL v" + _this._engine.webGLVersion + " - " + _this._glInfo.version + " - " + _this._glInfo.renderer; }
                     updateFct: function () { return "WebGL v" + _this._engine.webGLVersion + " - " + _this._glInfo.version + " - " + _this._glInfo.renderer; }
                 });
                 });
             }
             }
-            // Register the update loop
-            _this._scene.registerAfterRender(_this._updateLoopHandler);
             return _this;
             return _this;
         }
         }
         StatsTab.prototype._createStatLabel = function (content, parent) {
         StatsTab.prototype._createStatLabel = function (content, parent) {
@@ -4108,6 +4103,12 @@ var INSPECTOR;
         StatsTab.prototype.dispose = function () {
         StatsTab.prototype.dispose = function () {
             this._scene.unregisterAfterRender(this._updateLoopHandler);
             this._scene.unregisterAfterRender(this._updateLoopHandler);
         };
         };
+        StatsTab.prototype.active = function (b) {
+            _super.prototype.active.call(this, b);
+            if (b) {
+                this._scene.registerAfterRender(this._updateLoopHandler);
+            }
+        };
         return StatsTab;
         return StatsTab;
     }(INSPECTOR.Tab));
     }(INSPECTOR.Tab));
     INSPECTOR.StatsTab = StatsTab;
     INSPECTOR.StatsTab = StatsTab;
@@ -4160,7 +4161,6 @@ var INSPECTOR;
             //Check initialTab is defined and between tabs bounds
             //Check initialTab is defined and between tabs bounds
             if (!initialTab || initialTab < 0 || initialTab >= _this._tabs.length) {
             if (!initialTab || initialTab < 0 || initialTab >= _this._tabs.length) {
                 initialTab = 0;
                 initialTab = 0;
-                console.warn('');
             }
             }
             _this._tabs[initialTab].active(true);
             _this._tabs[initialTab].active(true);
             // set all tab as visible
             // set all tab as visible

File diff suppressed because it is too large
+ 3 - 3
dist/preview release/inspector/babylon.inspector.min.js


File diff suppressed because it is too large
+ 2 - 2
dist/preview release/loaders/babylon.glTF1FileLoader.min.js


+ 5 - 6
dist/preview release/loaders/babylon.glTF2FileLoader.d.ts

@@ -318,7 +318,6 @@ declare module BABYLON.GLTF2 {
         private _createBone(node, skin);
         private _createBone(node, skin);
         private _loadMesh(node);
         private _loadMesh(node);
         private _loadMeshData(node, mesh, babylonMesh);
         private _loadMeshData(node, mesh, babylonMesh);
-        private _assignMaterial(multiMaterial, index, subMaterial);
         private _loadVertexDataAsync(primitive, onSuccess);
         private _loadVertexDataAsync(primitive, onSuccess);
         private _createMorphTargets(node, mesh, primitive, babylonMesh);
         private _createMorphTargets(node, mesh, primitive, babylonMesh);
         private _loadMorphTargetsData(mesh, primitive, vertexData, babylonMesh);
         private _loadMorphTargetsData(mesh, primitive, vertexData, babylonMesh);
@@ -337,7 +336,7 @@ declare module BABYLON.GLTF2 {
         removeLoaderPendingData(data: any): void;
         removeLoaderPendingData(data: any): void;
         private _getDefaultMaterial();
         private _getDefaultMaterial();
         private _loadMaterialMetallicRoughnessProperties(material);
         private _loadMaterialMetallicRoughnessProperties(material);
-        loadMaterial(index: number, assign: (material: Material) => void): void;
+        loadMaterial(index: number, assign: (babylonMaterial: Material, isNew: boolean) => void): void;
         createPbrMaterial(material: IGLTFMaterial): void;
         createPbrMaterial(material: IGLTFMaterial): void;
         loadMaterialBaseProperties(material: IGLTFMaterial): void;
         loadMaterialBaseProperties(material: IGLTFMaterial): void;
         loadMaterialAlphaProperties(material: IGLTFMaterial, colorFactor?: number[]): void;
         loadMaterialAlphaProperties(material: IGLTFMaterial, colorFactor?: number[]): void;
@@ -377,9 +376,9 @@ declare module BABYLON.GLTF2 {
     abstract class GLTFLoaderExtension {
     abstract class GLTFLoaderExtension {
         enabled: boolean;
         enabled: boolean;
         readonly abstract name: string;
         readonly abstract name: string;
-        protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (material: Material) => void): boolean;
+        protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
         static _Extensions: GLTFLoaderExtension[];
         static _Extensions: GLTFLoaderExtension[];
-        static LoadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (material: Material) => void): boolean;
+        static LoadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
         private static _ApplyExtensions(action);
         private static _ApplyExtensions(action);
     }
     }
 }
 }
@@ -388,7 +387,7 @@ declare module BABYLON.GLTF2 {
 declare module BABYLON.GLTF2.Extensions {
 declare module BABYLON.GLTF2.Extensions {
     class MSFTLOD extends GLTFLoaderExtension {
     class MSFTLOD extends GLTFLoaderExtension {
         readonly name: string;
         readonly name: string;
-        protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (material: Material) => void): boolean;
+        protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
         private loadMaterialLOD(loader, material, materialLODs, lod, assign);
         private loadMaterialLOD(loader, material, materialLODs, lod, assign);
     }
     }
 }
 }
@@ -397,7 +396,7 @@ declare module BABYLON.GLTF2.Extensions {
 declare module BABYLON.GLTF2.Extensions {
 declare module BABYLON.GLTF2.Extensions {
     class KHRMaterialsPbrSpecularGlossiness extends GLTFLoaderExtension {
     class KHRMaterialsPbrSpecularGlossiness extends GLTFLoaderExtension {
         readonly name: string;
         readonly name: string;
-        protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (material: Material) => void): boolean;
+        protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
         private _loadSpecularGlossinessProperties(loader, material, properties);
         private _loadSpecularGlossinessProperties(loader, material, properties);
     }
     }
 }
 }

+ 14 - 16
dist/preview release/loaders/babylon.glTF2FileLoader.js

@@ -417,8 +417,8 @@ var BABYLON;
                 this.removePendingData(this);
                 this.removePendingData(this);
             };
             };
             GLTFLoader.prototype._onError = function (message) {
             GLTFLoader.prototype._onError = function (message) {
-                this.dispose();
                 this._errorCallback(message);
                 this._errorCallback(message);
+                this.dispose();
             };
             };
             GLTFLoader.prototype._onProgress = function (event) {
             GLTFLoader.prototype._onProgress = function (event) {
                 this._progressCallback(event);
                 this._progressCallback(event);
@@ -632,14 +632,17 @@ var BABYLON;
                             babylonMultiMaterial.subMaterials[i] = _this._getDefaultMaterial();
                             babylonMultiMaterial.subMaterials[i] = _this._getDefaultMaterial();
                         }
                         }
                         else {
                         else {
-                            _this.loadMaterial(primitive.material, function (babylonSubMaterial) {
+                            _this.loadMaterial(primitive.material, function (babylonMaterial, isNew) {
+                                if (isNew && _this._parent.onMaterialLoaded) {
+                                    _this._parent.onMaterialLoaded(babylonMaterial);
+                                }
                                 if (_this._renderReady) {
                                 if (_this._renderReady) {
-                                    babylonSubMaterial.forceCompilation(babylonMesh, function (babylonSubMaterial) {
-                                        _this._assignMaterial(babylonMultiMaterial, i, babylonSubMaterial);
+                                    babylonMaterial.forceCompilation(babylonMesh, function (babylonSubMaterial) {
+                                        babylonMultiMaterial.subMaterials[i] = babylonSubMaterial;
                                     });
                                     });
                                 }
                                 }
                                 else {
                                 else {
-                                    _this._assignMaterial(babylonMultiMaterial, i, babylonSubMaterial);
+                                    babylonMultiMaterial.subMaterials[i] = babylonMaterial;
                                 }
                                 }
                             });
                             });
                         }
                         }
@@ -657,12 +660,6 @@ var BABYLON;
                     _loop_1(i);
                     _loop_1(i);
                 }
                 }
             };
             };
-            GLTFLoader.prototype._assignMaterial = function (multiMaterial, index, subMaterial) {
-                multiMaterial.subMaterials[index] = subMaterial;
-                if (this._parent.onMaterialLoaded) {
-                    this._parent.onMaterialLoaded(subMaterial);
-                }
-            };
             GLTFLoader.prototype._loadVertexDataAsync = function (primitive, onSuccess) {
             GLTFLoader.prototype._loadVertexDataAsync = function (primitive, onSuccess) {
                 var _this = this;
                 var _this = this;
                 var attributes = primitive.attributes;
                 var attributes = primitive.attributes;
@@ -1119,7 +1116,7 @@ var BABYLON;
                 var material = this._gltf.materials[index];
                 var material = this._gltf.materials[index];
                 material.index = index;
                 material.index = index;
                 if (material.babylonMaterial) {
                 if (material.babylonMaterial) {
-                    assign(material.babylonMaterial);
+                    assign(material.babylonMaterial, false);
                     return;
                     return;
                 }
                 }
                 if (GLTF2.GLTFLoaderExtension.LoadMaterial(this, material, assign)) {
                 if (GLTF2.GLTFLoaderExtension.LoadMaterial(this, material, assign)) {
@@ -1128,7 +1125,7 @@ var BABYLON;
                 this.createPbrMaterial(material);
                 this.createPbrMaterial(material);
                 this.loadMaterialBaseProperties(material);
                 this.loadMaterialBaseProperties(material);
                 this._loadMaterialMetallicRoughnessProperties(material);
                 this._loadMaterialMetallicRoughnessProperties(material);
-                assign(material.babylonMaterial);
+                assign(material.babylonMaterial, true);
             };
             };
             GLTFLoader.prototype.createPbrMaterial = function (material) {
             GLTFLoader.prototype.createPbrMaterial = function (material) {
                 var babylonMaterial = new BABYLON.PBRMaterial(material.name || "mat" + material.index, this._babylonScene);
                 var babylonMaterial = new BABYLON.PBRMaterial(material.name || "mat" + material.index, this._babylonScene);
@@ -1452,8 +1449,8 @@ var BABYLON;
                 };
                 };
                 MSFTLOD.prototype.loadMaterialLOD = function (loader, material, materialLODs, lod, assign) {
                 MSFTLOD.prototype.loadMaterialLOD = function (loader, material, materialLODs, lod, assign) {
                     var _this = this;
                     var _this = this;
-                    loader.loadMaterial(materialLODs[lod], function (babylonMaterial) {
-                        assign(babylonMaterial);
+                    loader.loadMaterial(materialLODs[lod], function (babylonMaterial, isNew) {
+                        assign(babylonMaterial, isNew);
                         // Loading is complete if this is the highest quality LOD.
                         // Loading is complete if this is the highest quality LOD.
                         if (lod === 0) {
                         if (lod === 0) {
                             loader.removeLoaderPendingData(material);
                             loader.removeLoaderPendingData(material);
@@ -1518,7 +1515,7 @@ var BABYLON;
                     loader.createPbrMaterial(material);
                     loader.createPbrMaterial(material);
                     loader.loadMaterialBaseProperties(material);
                     loader.loadMaterialBaseProperties(material);
                     this._loadSpecularGlossinessProperties(loader, material, properties);
                     this._loadSpecularGlossinessProperties(loader, material, properties);
-                    assign(material.babylonMaterial);
+                    assign(material.babylonMaterial, true);
                     return true;
                     return true;
                 };
                 };
                 KHRMaterialsPbrSpecularGlossiness.prototype._loadSpecularGlossinessProperties = function (loader, material, properties) {
                 KHRMaterialsPbrSpecularGlossiness.prototype._loadSpecularGlossinessProperties = function (loader, material, properties) {
@@ -1532,6 +1529,7 @@ var BABYLON;
                     }
                     }
                     if (properties.specularGlossinessTexture) {
                     if (properties.specularGlossinessTexture) {
                         babylonMaterial.reflectivityTexture = loader.loadTexture(properties.specularGlossinessTexture);
                         babylonMaterial.reflectivityTexture = loader.loadTexture(properties.specularGlossinessTexture);
+                        babylonMaterial.reflectivityTexture.hasAlpha = true;
                         babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
                         babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
                     }
                     }
                     loader.loadMaterialAlphaProperties(material, properties.diffuseFactor);
                     loader.loadMaterialAlphaProperties(material, properties.diffuseFactor);

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/loaders/babylon.glTF2FileLoader.min.js


+ 5 - 6
dist/preview release/loaders/babylon.glTFFileLoader.d.ts

@@ -813,7 +813,6 @@ declare module BABYLON.GLTF2 {
         private _createBone(node, skin);
         private _createBone(node, skin);
         private _loadMesh(node);
         private _loadMesh(node);
         private _loadMeshData(node, mesh, babylonMesh);
         private _loadMeshData(node, mesh, babylonMesh);
-        private _assignMaterial(multiMaterial, index, subMaterial);
         private _loadVertexDataAsync(primitive, onSuccess);
         private _loadVertexDataAsync(primitive, onSuccess);
         private _createMorphTargets(node, mesh, primitive, babylonMesh);
         private _createMorphTargets(node, mesh, primitive, babylonMesh);
         private _loadMorphTargetsData(mesh, primitive, vertexData, babylonMesh);
         private _loadMorphTargetsData(mesh, primitive, vertexData, babylonMesh);
@@ -832,7 +831,7 @@ declare module BABYLON.GLTF2 {
         removeLoaderPendingData(data: any): void;
         removeLoaderPendingData(data: any): void;
         private _getDefaultMaterial();
         private _getDefaultMaterial();
         private _loadMaterialMetallicRoughnessProperties(material);
         private _loadMaterialMetallicRoughnessProperties(material);
-        loadMaterial(index: number, assign: (material: Material) => void): void;
+        loadMaterial(index: number, assign: (babylonMaterial: Material, isNew: boolean) => void): void;
         createPbrMaterial(material: IGLTFMaterial): void;
         createPbrMaterial(material: IGLTFMaterial): void;
         loadMaterialBaseProperties(material: IGLTFMaterial): void;
         loadMaterialBaseProperties(material: IGLTFMaterial): void;
         loadMaterialAlphaProperties(material: IGLTFMaterial, colorFactor?: number[]): void;
         loadMaterialAlphaProperties(material: IGLTFMaterial, colorFactor?: number[]): void;
@@ -872,9 +871,9 @@ declare module BABYLON.GLTF2 {
     abstract class GLTFLoaderExtension {
     abstract class GLTFLoaderExtension {
         enabled: boolean;
         enabled: boolean;
         readonly abstract name: string;
         readonly abstract name: string;
-        protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (material: Material) => void): boolean;
+        protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
         static _Extensions: GLTFLoaderExtension[];
         static _Extensions: GLTFLoaderExtension[];
-        static LoadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (material: Material) => void): boolean;
+        static LoadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
         private static _ApplyExtensions(action);
         private static _ApplyExtensions(action);
     }
     }
 }
 }
@@ -883,7 +882,7 @@ declare module BABYLON.GLTF2 {
 declare module BABYLON.GLTF2.Extensions {
 declare module BABYLON.GLTF2.Extensions {
     class MSFTLOD extends GLTFLoaderExtension {
     class MSFTLOD extends GLTFLoaderExtension {
         readonly name: string;
         readonly name: string;
-        protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (material: Material) => void): boolean;
+        protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
         private loadMaterialLOD(loader, material, materialLODs, lod, assign);
         private loadMaterialLOD(loader, material, materialLODs, lod, assign);
     }
     }
 }
 }
@@ -892,7 +891,7 @@ declare module BABYLON.GLTF2.Extensions {
 declare module BABYLON.GLTF2.Extensions {
 declare module BABYLON.GLTF2.Extensions {
     class KHRMaterialsPbrSpecularGlossiness extends GLTFLoaderExtension {
     class KHRMaterialsPbrSpecularGlossiness extends GLTFLoaderExtension {
         readonly name: string;
         readonly name: string;
-        protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (material: Material) => void): boolean;
+        protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
         private _loadSpecularGlossinessProperties(loader, material, properties);
         private _loadSpecularGlossinessProperties(loader, material, properties);
     }
     }
 }
 }

+ 14 - 16
dist/preview release/loaders/babylon.glTFFileLoader.js

@@ -2575,8 +2575,8 @@ var BABYLON;
                 this.removePendingData(this);
                 this.removePendingData(this);
             };
             };
             GLTFLoader.prototype._onError = function (message) {
             GLTFLoader.prototype._onError = function (message) {
-                this.dispose();
                 this._errorCallback(message);
                 this._errorCallback(message);
+                this.dispose();
             };
             };
             GLTFLoader.prototype._onProgress = function (event) {
             GLTFLoader.prototype._onProgress = function (event) {
                 this._progressCallback(event);
                 this._progressCallback(event);
@@ -2790,14 +2790,17 @@ var BABYLON;
                             babylonMultiMaterial.subMaterials[i] = _this._getDefaultMaterial();
                             babylonMultiMaterial.subMaterials[i] = _this._getDefaultMaterial();
                         }
                         }
                         else {
                         else {
-                            _this.loadMaterial(primitive.material, function (babylonSubMaterial) {
+                            _this.loadMaterial(primitive.material, function (babylonMaterial, isNew) {
+                                if (isNew && _this._parent.onMaterialLoaded) {
+                                    _this._parent.onMaterialLoaded(babylonMaterial);
+                                }
                                 if (_this._renderReady) {
                                 if (_this._renderReady) {
-                                    babylonSubMaterial.forceCompilation(babylonMesh, function (babylonSubMaterial) {
-                                        _this._assignMaterial(babylonMultiMaterial, i, babylonSubMaterial);
+                                    babylonMaterial.forceCompilation(babylonMesh, function (babylonSubMaterial) {
+                                        babylonMultiMaterial.subMaterials[i] = babylonSubMaterial;
                                     });
                                     });
                                 }
                                 }
                                 else {
                                 else {
-                                    _this._assignMaterial(babylonMultiMaterial, i, babylonSubMaterial);
+                                    babylonMultiMaterial.subMaterials[i] = babylonMaterial;
                                 }
                                 }
                             });
                             });
                         }
                         }
@@ -2815,12 +2818,6 @@ var BABYLON;
                     _loop_1(i);
                     _loop_1(i);
                 }
                 }
             };
             };
-            GLTFLoader.prototype._assignMaterial = function (multiMaterial, index, subMaterial) {
-                multiMaterial.subMaterials[index] = subMaterial;
-                if (this._parent.onMaterialLoaded) {
-                    this._parent.onMaterialLoaded(subMaterial);
-                }
-            };
             GLTFLoader.prototype._loadVertexDataAsync = function (primitive, onSuccess) {
             GLTFLoader.prototype._loadVertexDataAsync = function (primitive, onSuccess) {
                 var _this = this;
                 var _this = this;
                 var attributes = primitive.attributes;
                 var attributes = primitive.attributes;
@@ -3277,7 +3274,7 @@ var BABYLON;
                 var material = this._gltf.materials[index];
                 var material = this._gltf.materials[index];
                 material.index = index;
                 material.index = index;
                 if (material.babylonMaterial) {
                 if (material.babylonMaterial) {
-                    assign(material.babylonMaterial);
+                    assign(material.babylonMaterial, false);
                     return;
                     return;
                 }
                 }
                 if (GLTF2.GLTFLoaderExtension.LoadMaterial(this, material, assign)) {
                 if (GLTF2.GLTFLoaderExtension.LoadMaterial(this, material, assign)) {
@@ -3286,7 +3283,7 @@ var BABYLON;
                 this.createPbrMaterial(material);
                 this.createPbrMaterial(material);
                 this.loadMaterialBaseProperties(material);
                 this.loadMaterialBaseProperties(material);
                 this._loadMaterialMetallicRoughnessProperties(material);
                 this._loadMaterialMetallicRoughnessProperties(material);
-                assign(material.babylonMaterial);
+                assign(material.babylonMaterial, true);
             };
             };
             GLTFLoader.prototype.createPbrMaterial = function (material) {
             GLTFLoader.prototype.createPbrMaterial = function (material) {
                 var babylonMaterial = new BABYLON.PBRMaterial(material.name || "mat" + material.index, this._babylonScene);
                 var babylonMaterial = new BABYLON.PBRMaterial(material.name || "mat" + material.index, this._babylonScene);
@@ -3610,8 +3607,8 @@ var BABYLON;
                 };
                 };
                 MSFTLOD.prototype.loadMaterialLOD = function (loader, material, materialLODs, lod, assign) {
                 MSFTLOD.prototype.loadMaterialLOD = function (loader, material, materialLODs, lod, assign) {
                     var _this = this;
                     var _this = this;
-                    loader.loadMaterial(materialLODs[lod], function (babylonMaterial) {
-                        assign(babylonMaterial);
+                    loader.loadMaterial(materialLODs[lod], function (babylonMaterial, isNew) {
+                        assign(babylonMaterial, isNew);
                         // Loading is complete if this is the highest quality LOD.
                         // Loading is complete if this is the highest quality LOD.
                         if (lod === 0) {
                         if (lod === 0) {
                             loader.removeLoaderPendingData(material);
                             loader.removeLoaderPendingData(material);
@@ -3676,7 +3673,7 @@ var BABYLON;
                     loader.createPbrMaterial(material);
                     loader.createPbrMaterial(material);
                     loader.loadMaterialBaseProperties(material);
                     loader.loadMaterialBaseProperties(material);
                     this._loadSpecularGlossinessProperties(loader, material, properties);
                     this._loadSpecularGlossinessProperties(loader, material, properties);
-                    assign(material.babylonMaterial);
+                    assign(material.babylonMaterial, true);
                     return true;
                     return true;
                 };
                 };
                 KHRMaterialsPbrSpecularGlossiness.prototype._loadSpecularGlossinessProperties = function (loader, material, properties) {
                 KHRMaterialsPbrSpecularGlossiness.prototype._loadSpecularGlossinessProperties = function (loader, material, properties) {
@@ -3690,6 +3687,7 @@ var BABYLON;
                     }
                     }
                     if (properties.specularGlossinessTexture) {
                     if (properties.specularGlossinessTexture) {
                         babylonMaterial.reflectivityTexture = loader.loadTexture(properties.specularGlossinessTexture);
                         babylonMaterial.reflectivityTexture = loader.loadTexture(properties.specularGlossinessTexture);
+                        babylonMaterial.reflectivityTexture.hasAlpha = true;
                         babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
                         babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
                     }
                     }
                     loader.loadMaterialAlphaProperties(material, properties.diffuseFactor);
                     loader.loadMaterialAlphaProperties(material, properties.diffuseFactor);

File diff suppressed because it is too large
+ 2 - 2
dist/preview release/loaders/babylon.glTFFileLoader.min.js


File diff suppressed because it is too large
+ 1 - 1
dist/preview release/loaders/babylon.objFileLoader.min.js


+ 0 - 2
dist/preview release/materialsLibrary/babylon.customMaterial.d.ts

@@ -54,8 +54,6 @@ declare module BABYLON {
         REFRACTION: boolean;
         REFRACTION: boolean;
         REFRACTIONMAP_3D: boolean;
         REFRACTIONMAP_3D: boolean;
         REFLECTIONOVERALPHA: boolean;
         REFLECTIONOVERALPHA: boolean;
-        INVERTNORMALMAPX: boolean;
-        INVERTNORMALMAPY: boolean;
         TWOSIDEDLIGHTING: boolean;
         TWOSIDEDLIGHTING: boolean;
         SHADOWFLOAT: boolean;
         SHADOWFLOAT: boolean;
         MORPHTARGETS: boolean;
         MORPHTARGETS: boolean;

+ 8 - 10
dist/preview release/materialsLibrary/babylon.customMaterial.js

@@ -75,8 +75,6 @@ var BABYLON;
             _this.REFRACTION = false;
             _this.REFRACTION = false;
             _this.REFRACTIONMAP_3D = false;
             _this.REFRACTIONMAP_3D = false;
             _this.REFLECTIONOVERALPHA = false;
             _this.REFLECTIONOVERALPHA = false;
-            _this.INVERTNORMALMAPX = false;
-            _this.INVERTNORMALMAPY = false;
             _this.TWOSIDEDLIGHTING = false;
             _this.TWOSIDEDLIGHTING = false;
             _this.SHADOWFLOAT = false;
             _this.SHADOWFLOAT = false;
             _this.MORPHTARGETS = false;
             _this.MORPHTARGETS = false;
@@ -498,8 +496,6 @@ var BABYLON;
                         else {
                         else {
                             defines._needUVs = true;
                             defines._needUVs = true;
                             defines.BUMP = true;
                             defines.BUMP = true;
-                            defines.INVERTNORMALMAPX = this.invertNormalMapX;
-                            defines.INVERTNORMALMAPY = this.invertNormalMapY;
                             defines.PARALLAX = this._useParallax;
                             defines.PARALLAX = this._useParallax;
                             defines.PARALLAXOCCLUSION = this._useParallaxOcclusion;
                             defines.PARALLAXOCCLUSION = this._useParallaxOcclusion;
                         }
                         }
@@ -569,11 +565,6 @@ var BABYLON;
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
             BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
             BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
-            if (scene._mirroredCameraPosition && defines.BUMP) {
-                defines.INVERTNORMALMAPX = !this.invertNormalMapX;
-                defines.INVERTNORMALMAPY = !this.invertNormalMapY;
-                defines.markAsUnprocessed();
-            }
             // Get correct effect      
             // Get correct effect      
             if (defines.isDirty) {
             if (defines.isDirty) {
                 defines.markAsProcessed();
                 defines.markAsProcessed();
@@ -650,7 +641,7 @@ var BABYLON;
                     "mBones",
                     "mBones",
                     "vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix", "lightmapMatrix", "refractionMatrix",
                     "vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix", "lightmapMatrix", "refractionMatrix",
                     "diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor", "refractionLeftColor", "refractionRightColor",
                     "diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor", "refractionLeftColor", "refractionRightColor",
-                    "logarithmicDepthConstant"
+                    "logarithmicDepthConstant", "vNormalReoderParams"
                 ];
                 ];
                 var samplers = ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"];
                 var samplers = ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"];
                 var uniformBuffers = ["Material", "Scene"];
                 var uniformBuffers = ["Material", "Scene"];
@@ -714,6 +705,7 @@ var BABYLON;
             this._uniformBuffer.addUniform("lightmapMatrix", 16);
             this._uniformBuffer.addUniform("lightmapMatrix", 16);
             this._uniformBuffer.addUniform("specularMatrix", 16);
             this._uniformBuffer.addUniform("specularMatrix", 16);
             this._uniformBuffer.addUniform("bumpMatrix", 16);
             this._uniformBuffer.addUniform("bumpMatrix", 16);
+            this._uniformBuffer.addUniform("vNormalReoderParams", 4);
             this._uniformBuffer.addUniform("refractionMatrix", 16);
             this._uniformBuffer.addUniform("refractionMatrix", 16);
             this._uniformBuffer.addUniform("vRefractionInfos", 4);
             this._uniformBuffer.addUniform("vRefractionInfos", 4);
             this._uniformBuffer.addUniform("vSpecularColor", 4);
             this._uniformBuffer.addUniform("vSpecularColor", 4);
@@ -804,6 +796,12 @@ var BABYLON;
                         if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial_OldVer.BumpTextureEnabled) {
                         if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial_OldVer.BumpTextureEnabled) {
                             this._uniformBuffer.updateFloat3("vBumpInfos", this._bumpTexture.coordinatesIndex, 1.0 / this._bumpTexture.level, this.parallaxScaleBias);
                             this._uniformBuffer.updateFloat3("vBumpInfos", this._bumpTexture.coordinatesIndex, 1.0 / this._bumpTexture.level, this.parallaxScaleBias);
                             this._uniformBuffer.updateMatrix("bumpMatrix", this._bumpTexture.getTextureMatrix());
                             this._uniformBuffer.updateMatrix("bumpMatrix", this._bumpTexture.getTextureMatrix());
+                            if (scene._mirroredCameraPosition) {
+                                this._uniformBuffer.updateFloat4("vNormalReoderParams", this.invertNormalMapX ? 0 : 1.0, this.invertNormalMapX ? 1.0 : -1.0, this.invertNormalMapY ? 0 : 1.0, this.invertNormalMapY ? 1.0 : -1.0);
+                            }
+                            else {
+                                this._uniformBuffer.updateFloat4("vNormalReoderParams", this.invertNormalMapX ? 1.0 : 0, this.invertNormalMapX ? -1.0 : 1.0, this.invertNormalMapY ? 1.0 : 0, this.invertNormalMapY ? -1.0 : 1.0);
+                            }
                         }
                         }
                         if (this._refractionTexture && StandardMaterial_OldVer.RefractionTextureEnabled) {
                         if (this._refractionTexture && StandardMaterial_OldVer.RefractionTextureEnabled) {
                             var depth = 1.0;
                             var depth = 1.0;

File diff suppressed because it is too large
+ 2 - 2
dist/preview release/materialsLibrary/babylon.customMaterial.min.js


File diff suppressed because it is too large
+ 10 - 15
dist/preview release/materialsLibrary/babylon.legacyPbrMaterial.js


File diff suppressed because it is too large
+ 3 - 3
dist/preview release/materialsLibrary/babylon.legacyPbrMaterial.min.js


File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.waterMaterial.min.js


File diff suppressed because it is too large
+ 1 - 1
dist/preview release/postProcessesLibrary/babylon.asciiArtPostProcess.min.js


File diff suppressed because it is too large
+ 1 - 1
dist/preview release/postProcessesLibrary/babylon.digitalRainPostProcess.min.js


+ 37 - 0
gui/package.json

@@ -0,0 +1,37 @@
+{
+  "author": {
+    "name": "David CATUHE"
+  },
+  "name": "babylonjs-gui",
+  "description": "The Babylon.js GUI library is an extension you can use to generate interactive user interface. It is build on top of the DynamicTexture.",
+  "version": "3.1.0-alpha1.1",
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/BabylonJS/Babylon.js.git"
+  },
+  "main": "../dist/preview release/gui/babylon.gui.js",
+  "files": [
+    "../dist/preview release/gui/babylon.gui.js",
+    "../dist/preview release/gui/babylon.gui.min.js",
+    "../dist/preview release/gui/babylon.gui.d.ts",
+
+    "package.json"
+  ],
+  "typings": "../dist/preview release/gui/babylon.gui.d.ts",
+  "keywords": [
+    "3D",
+    "javascript",
+    "html5",
+    "webgl",
+    "gui"
+  ],
+  "license": "Apache-2.0",
+  "dependencies": {
+    "babylonjs": "3.1.0-alpha1"
+  },
+  "engines": {
+    "node": "*"
+  },
+  "_id": "babylonjs-gui@3.1.0-alpha1",
+  "_from": "babylonjs-gui@"
+}

+ 6 - 0
inspector/src/properties.ts

@@ -71,6 +71,12 @@ module INSPECTOR {
         'BaseTexture': {
         'BaseTexture': {
             type: BABYLON.BaseTexture
             type: BABYLON.BaseTexture
         },
         },
+        'CubeTexture': {
+            type: BABYLON.CubeTexture
+        },
+        'HDRCubeTexture': {
+            type: BABYLON.HDRCubeTexture
+        },
         'FontTexture': {
         'FontTexture': {
             type: BABYLON.FontTexture
             type: BABYLON.FontTexture
         },
         },

+ 14 - 9
inspector/src/tabs/ConsoleTab.ts

@@ -47,15 +47,6 @@ module INSPECTOR {
             this._consolePanelContent = Helpers.CreateDiv('console-panel-content', consolePanel) as HTMLDivElement;
             this._consolePanelContent = Helpers.CreateDiv('console-panel-content', consolePanel) as HTMLDivElement;
             this._bjsPanelContent     = Helpers.CreateDiv('console-panel-content', bjsPanel) as HTMLDivElement;
             this._bjsPanelContent     = Helpers.CreateDiv('console-panel-content', bjsPanel) as HTMLDivElement;
 
 
-            // save old console.log
-            this._oldConsoleLog       = console.log;
-            this._oldConsoleWarn      = console.warn;
-            this._oldConsoleError     = console.error;
-
-            console.log               = this._addConsoleLog.bind(this);
-            console.warn              = this._addConsoleWarn.bind(this);
-            console.error             = this._addConsoleError.bind(this);
-
             // Bjs logs
             // Bjs logs
             this._bjsPanelContent.innerHTML = BABYLON.Tools.LogCache;
             this._bjsPanelContent.innerHTML = BABYLON.Tools.LogCache;
             BABYLON.Tools.OnNewCacheEntry = (entry: string) => {
             BABYLON.Tools.OnNewCacheEntry = (entry: string) => {
@@ -83,6 +74,20 @@ module INSPECTOR {
             console.error = this._oldConsoleError;
             console.error = this._oldConsoleError;
 
 
         }
         }
+        
+        public active(b: boolean){
+            super.active(b);
+            if(b){
+                // save old console.log
+                this._oldConsoleLog       = console.log;
+                this._oldConsoleWarn      = console.warn;
+                this._oldConsoleError     = console.error;
+
+                console.log               = this._addConsoleLog.bind(this);
+                console.warn              = this._addConsoleWarn.bind(this);
+                console.error             = this._addConsoleError.bind(this);
+            }
+        }
 
 
         private _message(type:string, message:any, caller:string) {
         private _message(type:string, message:any, caller:string) {
             let callerLine = Helpers.CreateDiv('caller', this._consolePanelContent);
             let callerLine = Helpers.CreateDiv('caller', this._consolePanelContent);

+ 8 - 4
inspector/src/tabs/StatsTab.ts

@@ -267,11 +267,8 @@ module INSPECTOR {
                     updateFct:() => { return "WebGL v" + this._engine.webGLVersion + " - " + this._glInfo.version + " - "+this._glInfo.renderer}
                     updateFct:() => { return "WebGL v" + this._engine.webGLVersion + " - " + this._glInfo.version + " - "+this._glInfo.renderer}
                 });
                 });
             }
             }
-
-
-            // Register the update loop
-            this._scene.registerAfterRender(this._updateLoopHandler);
         }
         }
+        
         private _createStatLabel(content:string, parent: HTMLElement) : HTMLElement {
         private _createStatLabel(content:string, parent: HTMLElement) : HTMLElement {
             let elem = Helpers.CreateDiv('stat-label', parent);
             let elem = Helpers.CreateDiv('stat-label', parent);
             elem.textContent = content;
             elem.textContent = content;
@@ -288,5 +285,12 @@ module INSPECTOR {
         public dispose() {
         public dispose() {
             this._scene.unregisterAfterRender(this._updateLoopHandler);
             this._scene.unregisterAfterRender(this._updateLoopHandler);
         }
         }
+
+        public active(b: boolean){
+            super.active(b);
+            if(b){
+                this._scene.registerAfterRender(this._updateLoopHandler);
+            }
+        }
     }
     }
 }
 }

+ 0 - 1
inspector/src/tabs/TabBar.ts

@@ -47,7 +47,6 @@ module INSPECTOR {
             //Check initialTab is defined and between tabs bounds
             //Check initialTab is defined and between tabs bounds
             if (!initialTab || initialTab < 0 || initialTab >= this._tabs.length) {
             if (!initialTab || initialTab < 0 || initialTab >= this._tabs.length) {
                 initialTab = 0;
                 initialTab = 0;
-                console.warn('');
             }
             }
 
 
             this._tabs[initialTab].active(true);
             this._tabs[initialTab].active(true);

+ 19 - 34
inspector/src/tabs/TextureTab.ts

@@ -79,12 +79,14 @@ module INSPECTOR {
             // Get the texture object
             // Get the texture object
             let texture = item.adapter.object;
             let texture = item.adapter.object;
 
 
+            let imgs: HTMLImageElement[] = [];
             let img = Helpers.CreateElement('img', 'texture-image', this._imagePanel) as HTMLImageElement;
             let img = Helpers.CreateElement('img', 'texture-image', this._imagePanel) as HTMLImageElement;
-            let img1 = Helpers.CreateElement('img', 'texture-image', this._imagePanel) as HTMLImageElement;
-            let img2 = Helpers.CreateElement('img', 'texture-image', this._imagePanel) as HTMLImageElement;
-            let img3 = Helpers.CreateElement('img', 'texture-image', this._imagePanel) as HTMLImageElement;
-            let img4 = Helpers.CreateElement('img', 'texture-image', this._imagePanel) as HTMLImageElement;
-            let img5 = Helpers.CreateElement('img', 'texture-image', this._imagePanel) as HTMLImageElement;
+            imgs.push(img);
+            
+            //Create five other images elements
+            for(let i = 0; i<5; i++){
+                imgs.push(Helpers.CreateElement('img', 'texture-image', this._imagePanel) as HTMLImageElement);
+            }
 
 
             if (texture instanceof BABYLON.MapTexture) {
             if (texture instanceof BABYLON.MapTexture) {
                 // instance of Map texture
                 // instance of Map texture
@@ -108,31 +110,8 @@ module INSPECTOR {
                 
                 
                 // To display the texture after rendering
                 // To display the texture after rendering
                 screenShotTexture.onAfterRenderObservable.add((faceIndex: number) => {
                 screenShotTexture.onAfterRenderObservable.add((faceIndex: number) => {
-                    let targetImg: HTMLImageElement;
-                    switch(faceIndex){
-                        case 0:
-                            targetImg = img;
-                            break;
-                        case 1:
-                            targetImg = img1;
-                            break;
-                        case 2:
-                            targetImg = img2;
-                            break;
-                        case 3:
-                            targetImg = img3;
-                            break;
-                        case 4:
-                            targetImg = img4;
-                            break;
-                        case 5:
-                            targetImg = img5;
-                            break;
-                        default:
-                            targetImg = img;
-                            break;
-                    }
-                    BABYLON.Tools.DumpFramebuffer(size.width, size.height, engine,  (data) => targetImg.src = data, "image/png");
+                    BABYLON.Tools.DumpFramebuffer(size.width, size.height, engine,  
+                        (data) => imgs[faceIndex].src = data, "image/png");
                 });
                 });
 
 
                 // Render the texture
                 // Render the texture
@@ -140,7 +119,15 @@ module INSPECTOR {
                 scene.resetCachedMaterial();
                 scene.resetCachedMaterial();
                 screenShotTexture.render();
                 screenShotTexture.render();
                 screenShotTexture.dispose();
                 screenShotTexture.dispose();
-            } else if (texture.url) {
+            }else if(texture instanceof BABYLON.CubeTexture){
+                // Display all textures of the CubeTexture
+                let i: number = 0;
+                for(let filename of (texture as BABYLON.CubeTexture)['_files']){
+                    imgs[i].src = filename;
+                    i++;
+                }
+            }
+             else if (texture.url) {
                 // If an url is present, the texture is an image
                 // If an url is present, the texture is an image
                 img.src = texture.url;
                 img.src = texture.url;
 
 
@@ -148,9 +135,7 @@ module INSPECTOR {
                 // Dynamic texture
                 // Dynamic texture
                 let base64Image = texture['_canvas'].toDataURL("image/png");
                 let base64Image = texture['_canvas'].toDataURL("image/png");
                 img.src = base64Image;
                 img.src = base64Image;
-
-            }
-
+            } 
 
 
         }
         }
 
 

+ 14 - 4
inspector/test/index.js

@@ -66,6 +66,17 @@ var Test = (function () {
             }
             }
         });
         });
 
 
+        // Skybox
+        var skybox = BABYLON.Mesh.CreateBox("skyBox", 500.0, scene);
+        var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene);
+        skyboxMaterial.backFaceCulling = false;
+        skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("/assets/textures/skybox/TropicalSunnyDay", scene);
+        skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
+        skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
+        skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
+        skyboxMaterial.disableLighting = true;
+        skybox.material = skyboxMaterial;
+
         var sphere1 = BABYLON.Mesh.CreateSphere("Sphere1", 10.0, 9.0, scene);
         var sphere1 = BABYLON.Mesh.CreateSphere("Sphere1", 10.0, 9.0, scene);
         var sphere2 = BABYLON.Mesh.CreateSphere("Sphere2", 2.0, 9.0, scene);//Only two segments
         var sphere2 = BABYLON.Mesh.CreateSphere("Sphere2", 2.0, 9.0, scene);//Only two segments
         var sphere3 = BABYLON.Mesh.CreateSphere("Sphere3", 10.0, 9.0, scene);
         var sphere3 = BABYLON.Mesh.CreateSphere("Sphere3", 10.0, 9.0, scene);
@@ -249,7 +260,7 @@ var Test = (function () {
         sphere_3.parent = assets_mesh;
         sphere_3.parent = assets_mesh;
 
 
         for (var i=0; i<10 ; i++){
         for (var i=0; i<10 ; i++){
-            var inst = sphere_1.clone("C_" + i + "clone");
+            var inst = sphere_1.createInstance("C_" + i + "clone");
             inst.isVisible = true;
             inst.isVisible = true;
             inst.setEnabled = true;
             inst.setEnabled = true;
             inst.parent = scene_mesh;
             inst.parent = scene_mesh;
@@ -317,9 +328,8 @@ var Test = (function () {
         advancedTexture.addControl(checkbox);    
         advancedTexture.addControl(checkbox);    
         advancedTexture.addControl(slider);    
         advancedTexture.addControl(slider);    
         advancedTexture.addControl(line);    
         advancedTexture.addControl(line);    
-        advancedTexture.addControl(checkbox);    
-
-
+        advancedTexture.addControl(checkbox);  
+        
         this.scene = scene;
         this.scene = scene;
     };
     };
     return Test;
     return Test;

+ 4 - 3
loaders/src/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts

@@ -14,7 +14,7 @@ module BABYLON.GLTF2.Extensions {
             return "KHR_materials_pbrSpecularGlossiness";
             return "KHR_materials_pbrSpecularGlossiness";
         }
         }
 
 
-        protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (material: Material) => void): boolean {
+        protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean {
             if (!material.extensions) {
             if (!material.extensions) {
                 return false;
                 return false;
             }
             }
@@ -27,7 +27,7 @@ module BABYLON.GLTF2.Extensions {
             loader.createPbrMaterial(material);
             loader.createPbrMaterial(material);
             loader.loadMaterialBaseProperties(material);
             loader.loadMaterialBaseProperties(material);
             this._loadSpecularGlossinessProperties(loader, material, properties);
             this._loadSpecularGlossinessProperties(loader, material, properties);
-            assign(material.babylonMaterial);
+            assign(material.babylonMaterial, true);
             return true;
             return true;
         }
         }
 
 
@@ -45,6 +45,7 @@ module BABYLON.GLTF2.Extensions {
 
 
             if (properties.specularGlossinessTexture) {
             if (properties.specularGlossinessTexture) {
                 babylonMaterial.reflectivityTexture = loader.loadTexture(properties.specularGlossinessTexture);
                 babylonMaterial.reflectivityTexture = loader.loadTexture(properties.specularGlossinessTexture);
+                babylonMaterial.reflectivityTexture.hasAlpha = true;
                 babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
                 babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
             }
             }
 
 
@@ -53,4 +54,4 @@ module BABYLON.GLTF2.Extensions {
     }
     }
 
 
     GLTFLoader.RegisterExtension(new KHRMaterialsPbrSpecularGlossiness());
     GLTFLoader.RegisterExtension(new KHRMaterialsPbrSpecularGlossiness());
-}
+}

+ 5 - 5
loaders/src/glTF/2.0/Extensions/MSFT_lod.ts

@@ -10,7 +10,7 @@ module BABYLON.GLTF2.Extensions {
             return "MSFT_lod";
             return "MSFT_lod";
         }
         }
 
 
-        protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (material: Material) => void): boolean {
+        protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean {
             if (!material.extensions) {
             if (!material.extensions) {
                 return false;
                 return false;
             }
             }
@@ -33,9 +33,9 @@ module BABYLON.GLTF2.Extensions {
             return true;
             return true;
         }
         }
 
 
-        private loadMaterialLOD(loader: GLTFLoader, material: IGLTFMaterial, materialLODs: number[], lod: number, assign: (material: Material) => void): void {
-            loader.loadMaterial(materialLODs[lod], babylonMaterial => {
-                assign(babylonMaterial);
+        private loadMaterialLOD(loader: GLTFLoader, material: IGLTFMaterial, materialLODs: number[], lod: number, assign: (material: Material, isNew: boolean) => void): void {
+            loader.loadMaterial(materialLODs[lod], (babylonMaterial, isNew) => {
+                assign(babylonMaterial, isNew);
 
 
                 // Loading is complete if this is the highest quality LOD.
                 // Loading is complete if this is the highest quality LOD.
                 if (lod === 0) {
                 if (lod === 0) {
@@ -56,4 +56,4 @@ module BABYLON.GLTF2.Extensions {
     }
     }
 
 
     GLTFLoader.RegisterExtension(new MSFTLOD());
     GLTFLoader.RegisterExtension(new MSFTLOD());
-}
+}

+ 12 - 16
loaders/src/glTF/2.0/babylon.glTFLoader.ts

@@ -127,8 +127,8 @@ module BABYLON.GLTF2 {
         }
         }
 
 
         private _onError(message: string): void {
         private _onError(message: string): void {
-            this.dispose();
             this._errorCallback(message);
             this._errorCallback(message);
+            this.dispose();
         }
         }
 
 
         private _onProgress(event: ProgressEvent): void {
         private _onProgress(event: ProgressEvent): void {
@@ -392,14 +392,18 @@ module BABYLON.GLTF2 {
                         babylonMultiMaterial.subMaterials[i] = this._getDefaultMaterial();
                         babylonMultiMaterial.subMaterials[i] = this._getDefaultMaterial();
                     }
                     }
                     else {
                     else {
-                        this.loadMaterial(primitive.material, (babylonSubMaterial: Material) => {
+                        this.loadMaterial(primitive.material, (babylonMaterial, isNew) => {
+                            if (isNew && this._parent.onMaterialLoaded) {
+                                this._parent.onMaterialLoaded(babylonMaterial);
+                            }
+
                             if (this._renderReady) {
                             if (this._renderReady) {
-                                babylonSubMaterial.forceCompilation(babylonMesh, babylonSubMaterial => {
-                                    this._assignMaterial(babylonMultiMaterial, i, babylonSubMaterial);
+                                babylonMaterial.forceCompilation(babylonMesh, babylonSubMaterial => {
+                                    babylonMultiMaterial.subMaterials[i] = babylonSubMaterial;
                                 });
                                 });
                             }
                             }
                             else {
                             else {
-                                this._assignMaterial(babylonMultiMaterial, i, babylonSubMaterial);
+                                babylonMultiMaterial.subMaterials[i] = babylonMaterial;
                             }
                             }
                         });
                         });
                     }
                     }
@@ -416,14 +420,6 @@ module BABYLON.GLTF2 {
             }
             }
         }
         }
 
 
-        private _assignMaterial(multiMaterial: MultiMaterial, index: number, subMaterial: Material): void {
-            multiMaterial.subMaterials[index] = subMaterial;
-
-            if (this._parent.onMaterialLoaded) {
-                this._parent.onMaterialLoaded(subMaterial);
-            }
-        }
-
         private _loadVertexDataAsync(primitive: IGLTFMeshPrimitive, onSuccess: (vertexData: VertexData) => void): void {
         private _loadVertexDataAsync(primitive: IGLTFMeshPrimitive, onSuccess: (vertexData: VertexData) => void): void {
             var attributes = primitive.attributes;
             var attributes = primitive.attributes;
             if (!attributes) {
             if (!attributes) {
@@ -920,12 +916,12 @@ module BABYLON.GLTF2 {
             this.loadMaterialAlphaProperties(material, properties.baseColorFactor);
             this.loadMaterialAlphaProperties(material, properties.baseColorFactor);
         }
         }
 
 
-        public loadMaterial(index: number, assign: (material: Material) => void): void {
+        public loadMaterial(index: number, assign: (babylonMaterial: Material, isNew: boolean) => void): void {
             var material = this._gltf.materials[index];
             var material = this._gltf.materials[index];
             material.index = index;
             material.index = index;
 
 
             if (material.babylonMaterial) {
             if (material.babylonMaterial) {
-                assign(material.babylonMaterial);
+                assign(material.babylonMaterial, false);
                 return;
                 return;
             }
             }
 
 
@@ -936,7 +932,7 @@ module BABYLON.GLTF2 {
             this.createPbrMaterial(material);
             this.createPbrMaterial(material);
             this.loadMaterialBaseProperties(material);
             this.loadMaterialBaseProperties(material);
             this._loadMaterialMetallicRoughnessProperties(material);
             this._loadMaterialMetallicRoughnessProperties(material);
-            assign(material.babylonMaterial);
+            assign(material.babylonMaterial, true);
         }
         }
 
 
         public createPbrMaterial(material: IGLTFMaterial): void {
         public createPbrMaterial(material: IGLTFMaterial): void {

+ 2 - 2
loaders/src/glTF/2.0/babylon.glTFLoaderExtension.ts

@@ -6,7 +6,7 @@ module BABYLON.GLTF2 {
 
 
         public abstract get name(): string;
         public abstract get name(): string;
 
 
-        protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (material: Material) => void): boolean { return false; }
+        protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean { return false; }
 
 
         //
         //
         // Utilities
         // Utilities
@@ -14,7 +14,7 @@ module BABYLON.GLTF2 {
 
 
         public static _Extensions: GLTFLoaderExtension[] = [];
         public static _Extensions: GLTFLoaderExtension[] = [];
 
 
-        public static LoadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (material: Material) => void): boolean {
+        public static LoadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean {
             return this._ApplyExtensions(extension => extension.loadMaterial(loader, material, assign));
             return this._ApplyExtensions(extension => extension.loadMaterial(loader, material, assign));
         }
         }
 
 

+ 8 - 12
materialsLibrary/src/custom/babylon.customMaterial.ts

@@ -57,8 +57,6 @@ module BABYLON {
         public REFRACTION = false;
         public REFRACTION = false;
         public REFRACTIONMAP_3D = false;
         public REFRACTIONMAP_3D = false;
         public REFLECTIONOVERALPHA = false;
         public REFLECTIONOVERALPHA = false;
-        public INVERTNORMALMAPX = false;
-        public INVERTNORMALMAPY = false;
         public TWOSIDEDLIGHTING = false;
         public TWOSIDEDLIGHTING = false;
         public SHADOWFLOAT = false;
         public SHADOWFLOAT = false;
         public MORPHTARGETS = false;
         public MORPHTARGETS = false;
@@ -640,9 +638,6 @@ module BABYLON {
                             defines._needUVs = true;
                             defines._needUVs = true;
                             defines.BUMP = true;
                             defines.BUMP = true;
 
 
-                            defines.INVERTNORMALMAPX = this.invertNormalMapX;
-                            defines.INVERTNORMALMAPY = this.invertNormalMapY;
-
                             defines.PARALLAX = this._useParallax;
                             defines.PARALLAX = this._useParallax;
                             defines.PARALLAXOCCLUSION = this._useParallaxOcclusion;
                             defines.PARALLAXOCCLUSION = this._useParallaxOcclusion;
                         }
                         }
@@ -728,12 +723,6 @@ module BABYLON {
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
             MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
             MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
 
 
-            if (scene._mirroredCameraPosition && defines.BUMP) {
-                defines.INVERTNORMALMAPX = !this.invertNormalMapX;
-                defines.INVERTNORMALMAPY = !this.invertNormalMapY;
-                defines.markAsUnprocessed();
-            }
-
             // Get correct effect      
             // Get correct effect      
             if (defines.isDirty) {
             if (defines.isDirty) {
                 defines.markAsProcessed();
                 defines.markAsProcessed();
@@ -834,7 +823,7 @@ module BABYLON {
                     "mBones",
                     "mBones",
                     "vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix", "lightmapMatrix", "refractionMatrix",
                     "vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix", "lightmapMatrix", "refractionMatrix",
                     "diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor", "refractionLeftColor", "refractionRightColor",
                     "diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor", "refractionLeftColor", "refractionRightColor",
-                    "logarithmicDepthConstant"
+                    "logarithmicDepthConstant", "vNormalReoderParams"
                 ];
                 ];
 
 
                 var samplers = ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"]
                 var samplers = ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"]
@@ -911,6 +900,7 @@ module BABYLON {
             this._uniformBuffer.addUniform("lightmapMatrix", 16);
             this._uniformBuffer.addUniform("lightmapMatrix", 16);
             this._uniformBuffer.addUniform("specularMatrix", 16);
             this._uniformBuffer.addUniform("specularMatrix", 16);
             this._uniformBuffer.addUniform("bumpMatrix", 16);
             this._uniformBuffer.addUniform("bumpMatrix", 16);
+            this._uniformBuffer.addUniform("vNormalReoderParams", 4);            
             this._uniformBuffer.addUniform("refractionMatrix", 16);
             this._uniformBuffer.addUniform("refractionMatrix", 16);
             this._uniformBuffer.addUniform("vRefractionInfos", 4);
             this._uniformBuffer.addUniform("vRefractionInfos", 4);
             this._uniformBuffer.addUniform("vSpecularColor", 4);
             this._uniformBuffer.addUniform("vSpecularColor", 4);
@@ -1024,6 +1014,12 @@ module BABYLON {
                         if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial_OldVer.BumpTextureEnabled) {
                         if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial_OldVer.BumpTextureEnabled) {
                             this._uniformBuffer.updateFloat3("vBumpInfos", this._bumpTexture.coordinatesIndex, 1.0 / this._bumpTexture.level, this.parallaxScaleBias);
                             this._uniformBuffer.updateFloat3("vBumpInfos", this._bumpTexture.coordinatesIndex, 1.0 / this._bumpTexture.level, this.parallaxScaleBias);
                             this._uniformBuffer.updateMatrix("bumpMatrix", this._bumpTexture.getTextureMatrix());
                             this._uniformBuffer.updateMatrix("bumpMatrix", this._bumpTexture.getTextureMatrix());
+
+                            if (scene._mirroredCameraPosition) {
+                                this._uniformBuffer.updateFloat4("vNormalReoderParams", this.invertNormalMapX ? 0 : 1.0, this.invertNormalMapX ? 1.0 : -1.0, this.invertNormalMapY ? 0 : 1.0, this.invertNormalMapY ? 1.0 : -1.0);
+                            } else {
+                                this._uniformBuffer.updateFloat4("vNormalReoderParams", this.invertNormalMapX ? 1.0 : 0, this.invertNormalMapX ? -1.0 : 1.0, this.invertNormalMapY ? 1.0 : 0, this.invertNormalMapY ? -1.0 : 1.0);
+                            }                                                          
                         }
                         }
 
 
                         if (this._refractionTexture && StandardMaterial_OldVer.RefractionTextureEnabled) {
                         if (this._refractionTexture && StandardMaterial_OldVer.RefractionTextureEnabled) {

+ 10 - 17
materialsLibrary/src/legacyPBR/babylon.legacyPBRMaterial.ts

@@ -66,8 +66,6 @@ module BABYLON {
         public RADIANCEOVERALPHA = false;
         public RADIANCEOVERALPHA = false;
         public USEPMREMREFLECTION = false;
         public USEPMREMREFLECTION = false;
         public USEPMREMREFRACTION = false;
         public USEPMREMREFRACTION = false;
-        public INVERTNORMALMAPX = false;
-        public INVERTNORMALMAPY = false;
         public TWOSIDEDLIGHTING = false;
         public TWOSIDEDLIGHTING = false;
         public SHADOWFLOAT = false;
         public SHADOWFLOAT = false;
 
 
@@ -851,20 +849,7 @@ module BABYLON {
                         if (this.useParallaxOcclusion) {
                         if (this.useParallaxOcclusion) {
                             this._defines.PARALLAXOCCLUSION = true;
                             this._defines.PARALLAXOCCLUSION = true;
                         }
                         }
-                    }
-
-                    if (this.invertNormalMapX) {
-                        this._defines.INVERTNORMALMAPX = true;
-                    }
-
-                    if (this.invertNormalMapY) {
-                        this._defines.INVERTNORMALMAPY = true;
-                    }
-
-                    if (scene._mirroredCameraPosition) {
-                        this._defines.INVERTNORMALMAPX = !this._defines.INVERTNORMALMAPX;
-                        this._defines.INVERTNORMALMAPY = !this._defines.INVERTNORMALMAPY;
-                    }                        
+                    }                     
                 }
                 }
 
 
                 if (this.refractionTexture && StandardMaterial.RefractionTextureEnabled) {
                 if (this.refractionTexture && StandardMaterial.RefractionTextureEnabled) {
@@ -1154,7 +1139,7 @@ module BABYLON {
                         "vSphericalXX", "vSphericalYY", "vSphericalZZ",
                         "vSphericalXX", "vSphericalYY", "vSphericalZZ",
                         "vSphericalXY", "vSphericalYZ", "vSphericalZX",
                         "vSphericalXY", "vSphericalYZ", "vSphericalZX",
                         "vMicrosurfaceTextureLods",
                         "vMicrosurfaceTextureLods",
-                        "vCameraInfos"
+                        "vCameraInfos", "vNormalReoderParams"
                 ];
                 ];
 
 
                 var samplers = ["albedoSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "reflectivitySampler", "microSurfaceSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"];
                 var samplers = ["albedoSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "reflectivitySampler", "microSurfaceSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"];
@@ -1233,6 +1218,7 @@ module BABYLON {
             this._uniformBuffer.addUniform("reflectivityMatrix", 16);
             this._uniformBuffer.addUniform("reflectivityMatrix", 16);
             this._uniformBuffer.addUniform("microSurfaceSamplerMatrix", 16);
             this._uniformBuffer.addUniform("microSurfaceSamplerMatrix", 16);
             this._uniformBuffer.addUniform("bumpMatrix", 16);
             this._uniformBuffer.addUniform("bumpMatrix", 16);
+            this._uniformBuffer.addUniform("vNormalReoderParams", 4);
             this._uniformBuffer.addUniform("refractionMatrix", 16);
             this._uniformBuffer.addUniform("refractionMatrix", 16);
             this._uniformBuffer.addUniform("reflectionMatrix", 16);
             this._uniformBuffer.addUniform("reflectionMatrix", 16);
 
 
@@ -1377,6 +1363,13 @@ module BABYLON {
                         if (this.bumpTexture && this._myScene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled && !this.disableBumpMap) {
                         if (this.bumpTexture && this._myScene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled && !this.disableBumpMap) {
                             this._uniformBuffer.updateFloat3("vBumpInfos", this.bumpTexture.coordinatesIndex, 1.0 / this.bumpTexture.level, this.parallaxScaleBias);
                             this._uniformBuffer.updateFloat3("vBumpInfos", this.bumpTexture.coordinatesIndex, 1.0 / this.bumpTexture.level, this.parallaxScaleBias);
                             this._uniformBuffer.updateMatrix("bumpMatrix", this.bumpTexture.getTextureMatrix());
                             this._uniformBuffer.updateMatrix("bumpMatrix", this.bumpTexture.getTextureMatrix());
+
+
+                            if (this._myScene._mirroredCameraPosition) {
+                                this._uniformBuffer.updateFloat4("vNormalReoderParams", this.invertNormalMapX ? 0 : 1.0, this.invertNormalMapX ? 1.0 : -1.0, this.invertNormalMapY ? 0 : 1.0, this.invertNormalMapY ? 1.0 : -1.0);
+                            } else {
+                                this._uniformBuffer.updateFloat4("vNormalReoderParams", this.invertNormalMapX ? 1.0 : 0, this.invertNormalMapX ? -1.0 : 1.0, this.invertNormalMapY ? 1.0 : 0, this.invertNormalMapY ? -1.0 : 1.0);
+                            }                              
                         }
                         }
 
 
                         if (this.refractionTexture && StandardMaterial.RefractionTextureEnabled) {
                         if (this.refractionTexture && StandardMaterial.RefractionTextureEnabled) {

File diff suppressed because it is too large
+ 2 - 2
materialsLibrary/src/legacyPBR/babylon.legacyPbrMaterial.js.include.fx


+ 1 - 0
materialsLibrary/src/legacyPBR/legacyPbrFragmentDeclaration.fx

@@ -36,6 +36,7 @@ uniform vec3 vAmbientInfos;
 
 
 #ifdef BUMP
 #ifdef BUMP
 uniform vec3 vBumpInfos;
 uniform vec3 vBumpInfos;
+uniform vec4 vNormalReoderParams;
 #endif
 #endif
 
 
 #ifdef OPACITY	
 #ifdef OPACITY	

+ 1 - 0
materialsLibrary/src/legacyPBR/legacyPbrUboDeclaration.fx

@@ -20,6 +20,7 @@ uniform Material
 	uniform mat4 reflectivityMatrix;
 	uniform mat4 reflectivityMatrix;
 	uniform mat4 microSurfaceSamplerMatrix;
 	uniform mat4 microSurfaceSamplerMatrix;
 	uniform mat4 bumpMatrix;
 	uniform mat4 bumpMatrix;
+	uniform vec4 vNormalReoderParams;
 	uniform mat4 refractionMatrix;
 	uniform mat4 refractionMatrix;
 	uniform mat4 reflectionMatrix;
 	uniform mat4 reflectionMatrix;
 
 

+ 2 - 6
package.json

@@ -8,7 +8,7 @@
   ],
   ],
   "name": "babylonjs",
   "name": "babylonjs",
   "description": "Babylon.js is a JavaScript 3D engine based on webgl.",
   "description": "Babylon.js is a JavaScript 3D engine based on webgl.",
-  "version": "3.1.0-alpha0",
+  "version": "3.1.0-alpha1",
   "repository": {
   "repository": {
     "type": "git",
     "type": "git",
     "url": "https://github.com/BabylonJS/Babylon.js.git"
     "url": "https://github.com/BabylonJS/Babylon.js.git"
@@ -21,10 +21,6 @@
     "dist/preview release/babylon.max.js",
     "dist/preview release/babylon.max.js",
     "dist/preview release/babylon.worker.js",
     "dist/preview release/babylon.worker.js",
 
 
-    "dist/preview release/gui/babylon.gui.js",
-    "dist/preview release/gui/babylon.gui.min.js",
-    "dist/preview release/gui/babylon.gui.d.ts",
-
     "dist/preview release/loaders/babylon.glTFFileLoader.min.js",
     "dist/preview release/loaders/babylon.glTFFileLoader.min.js",
     "dist/preview release/loaders/babylon.objFileLoader.min.js",
     "dist/preview release/loaders/babylon.objFileLoader.min.js",
     "dist/preview release/loaders/babylon.stlFileLoader.min.js",
     "dist/preview release/loaders/babylon.stlFileLoader.min.js",
@@ -74,6 +70,6 @@
   },
   },
   "readme": "Babylon.js is a 3D engine based on webgl and javascript",
   "readme": "Babylon.js is a 3D engine based on webgl and javascript",
   "readmeFilename": "README.md",
   "readmeFilename": "README.md",
-  "_id": "babylonjs@3.1.0-alpha0",
+  "_id": "babylonjs@3.1.0-alpha1",
   "_from": "babylonjs@"
   "_from": "babylonjs@"
 }
 }

+ 3 - 0
src/Audio/babylon.sound.ts

@@ -124,6 +124,9 @@ module BABYLON {
                                 if (url.indexOf(".wav", url.length - 4) !== -1) {
                                 if (url.indexOf(".wav", url.length - 4) !== -1) {
                                     codecSupportedFound = true;
                                     codecSupportedFound = true;
                                 }
                                 }
+                                if (url.indexOf("blob:") !== -1) {
+                                    codecSupportedFound = true;
+                                }
                                 if (codecSupportedFound) {
                                 if (codecSupportedFound) {
                                     // Loading sound using XHR2
                                     // Loading sound using XHR2
                                     if (!this._streaming) {
                                     if (!this._streaming) {

+ 11 - 13
src/Materials/PBR/babylon.pbrBaseMaterial.ts

@@ -54,8 +54,6 @@
         public BUMPDIRECTUV = 0;
         public BUMPDIRECTUV = 0;
         public PARALLAX = false;
         public PARALLAX = false;
         public PARALLAXOCCLUSION = false;
         public PARALLAXOCCLUSION = false;
-        public INVERTNORMALMAPX = false;
-        public INVERTNORMALMAPY = false;
         public NORMALXYSCALE = true;
         public NORMALXYSCALE = true;
 
 
         public LIGHTMAP = false;
         public LIGHTMAP = false;
@@ -351,12 +349,12 @@
         protected _maxSimultaneousLights = 4;  
         protected _maxSimultaneousLights = 4;  
 
 
         /**
         /**
-         * If sets to true, x component of normal map value will invert (x = 1.0 - x).
+         * If sets to true, x component of normal map value will be inverted (x = 1.0 - x).
          */
          */
         protected _invertNormalMapX = false;
         protected _invertNormalMapX = false;
 
 
         /**
         /**
-         * If sets to true, y component of normal map value will invert (y = 1.0 - y).
+         * If sets to true, y component of normal map value will be inverted (y = 1.0 - y).
          */
          */
         protected _invertNormalMapY = false;
         protected _invertNormalMapY = false;
 
 
@@ -732,14 +730,6 @@
                             defines.PARALLAX = false;
                             defines.PARALLAX = false;
                         }
                         }
 
 
-                        defines.INVERTNORMALMAPX = !!this._invertNormalMapX;
-                        defines.INVERTNORMALMAPY = !!this._invertNormalMapY;
-
-                        if (scene._mirroredCameraPosition) {
-                            defines.INVERTNORMALMAPX = !defines.INVERTNORMALMAPX;
-                            defines.INVERTNORMALMAPY = !defines.INVERTNORMALMAPY;
-                        }
-
                         defines.USERIGHTHANDEDSYSTEM = scene.useRightHandedSystem;
                         defines.USERIGHTHANDEDSYSTEM = scene.useRightHandedSystem;
                     } else {
                     } else {
                         defines.BUMP = false;
                         defines.BUMP = false;
@@ -925,7 +915,8 @@
                         "vSphericalX", "vSphericalY", "vSphericalZ",
                         "vSphericalX", "vSphericalY", "vSphericalZ",
                         "vSphericalXX", "vSphericalYY", "vSphericalZZ",
                         "vSphericalXX", "vSphericalYY", "vSphericalZZ",
                         "vSphericalXY", "vSphericalYZ", "vSphericalZX",
                         "vSphericalXY", "vSphericalYZ", "vSphericalZX",
-                        "vReflectionMicrosurfaceInfos", "vRefractionMicrosurfaceInfos"
+                        "vReflectionMicrosurfaceInfos", "vRefractionMicrosurfaceInfos",
+                        "vNormalReoderParams"
                 ];
                 ];
 
 
                 var samplers = ["albedoSampler", "reflectivitySampler", "ambientSampler", "emissiveSampler", 
                 var samplers = ["albedoSampler", "reflectivitySampler", "ambientSampler", "emissiveSampler", 
@@ -1001,6 +992,7 @@
             this._uniformBuffer.addUniform("reflectivityMatrix", 16);
             this._uniformBuffer.addUniform("reflectivityMatrix", 16);
             this._uniformBuffer.addUniform("microSurfaceSamplerMatrix", 16);
             this._uniformBuffer.addUniform("microSurfaceSamplerMatrix", 16);
             this._uniformBuffer.addUniform("bumpMatrix", 16);
             this._uniformBuffer.addUniform("bumpMatrix", 16);
+            this._uniformBuffer.addUniform("vNormalReoderParams", 4);
             this._uniformBuffer.addUniform("refractionMatrix", 16);
             this._uniformBuffer.addUniform("refractionMatrix", 16);
             this._uniformBuffer.addUniform("reflectionMatrix", 16);
             this._uniformBuffer.addUniform("reflectionMatrix", 16);
 
 
@@ -1132,6 +1124,12 @@
                         if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled && !this._disableBumpMap) {
                         if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled && !this._disableBumpMap) {
                             this._uniformBuffer.updateFloat3("vBumpInfos", this._bumpTexture.coordinatesIndex, this._bumpTexture.level, this._parallaxScaleBias);
                             this._uniformBuffer.updateFloat3("vBumpInfos", this._bumpTexture.coordinatesIndex, this._bumpTexture.level, this._parallaxScaleBias);
                             MaterialHelper.BindTextureMatrix(this._bumpTexture, this._uniformBuffer, "bump");
                             MaterialHelper.BindTextureMatrix(this._bumpTexture, this._uniformBuffer, "bump");
+
+                            if (scene._mirroredCameraPosition) {
+                                this._uniformBuffer.updateFloat4("vNormalReoderParams", this._invertNormalMapX ? 0 : 1.0, this._invertNormalMapX ? 1.0 : -1.0, this._invertNormalMapY ? 0 : 1.0, this._invertNormalMapY ? 1.0 : -1.0);
+                            } else {
+                                this._uniformBuffer.updateFloat4("vNormalReoderParams", this._invertNormalMapX ? 1.0 : 0, this._invertNormalMapX ? -1.0 : 1.0, this._invertNormalMapY ? 1.0 : 0, this._invertNormalMapY ? -1.0 : 1.0);
+                            }                                                         
                         }
                         }
 
 
                         var refractionTexture = this._getRefractionTexture();
                         var refractionTexture = this._getRefractionTexture();

+ 14 - 0
src/Materials/PBR/babylon.pbrMaterial.ts

@@ -227,6 +227,20 @@
         @serialize()
         @serialize()
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         public useAlphaFromAlbedoTexture = false;
         public useAlphaFromAlbedoTexture = false;
+
+        /**
+         * Enforces alpha test in opaque or blend mode in order to improve the performances of some situations.
+         */
+        @serialize()
+        @expandToProperty("_markAllSubMeshesAsTexturesDirty")
+        public forceAlphaTest = false;
+
+        /**
+         * Defines the alpha limits in alpha test mode.
+         */
+        @serialize()
+        @expandToProperty("_markAllSubMeshesAsTexturesDirty")
+        public alphaCutOff = 0.4;
         
         
         /**
         /**
          * Specifies that the material will keeps the specular highlights over a transparent surface (only the most limunous ones).
          * Specifies that the material will keeps the specular highlights over a transparent surface (only the most limunous ones).

+ 14 - 10
src/Materials/Textures/babylon.baseTexture.ts

@@ -332,28 +332,32 @@
             return serializationObject;
             return serializationObject;
         }
         }
 
 
-        public static WhenAllReady(textures: BaseTexture[], onLoad: () => void): void {
-            var numReady = 0;
+        public static WhenAllReady(textures: BaseTexture[], callback: () => void): void {
+            let numRemaining = textures.length;
+            if (numRemaining === 0) {
+                callback();
+                return;
+            }
 
 
             for (var i = 0; i < textures.length; i++) {
             for (var i = 0; i < textures.length; i++) {
                 var texture = textures[i];
                 var texture = textures[i];
 
 
                 if (texture.isReady()) {
                 if (texture.isReady()) {
-                    if (++numReady === textures.length) {
-                        onLoad();
+                    if (--numRemaining === 0) {
+                        callback();
                     }
                     }
                 }
                 }
                 else {
                 else {
-                    var observable = (texture as any).onLoadObservable as Observable<Texture>;
+                    var onLoadObservable = (texture as any).onLoadObservable as Observable<Texture>;
 
 
-                    let callback = () => {
-                        observable.removeCallback(callback);
-                        if (++numReady === textures.length) {
-                            onLoad();
+                    let onLoadCallback = () => {
+                        onLoadObservable.removeCallback(onLoadCallback);
+                        if (--numRemaining === 0) {
+                            callback();
                         }
                         }
                     };
                     };
 
 
-                    observable.add(callback);
+                    onLoadObservable.add(onLoadCallback);
                 }
                 }
             }
             }
         }
         }

+ 5 - 5
src/Materials/Textures/babylon.cubeTexture.ts

@@ -14,11 +14,11 @@
             return new CubeTexture("", scene, null, noMipmap, files);
             return new CubeTexture("", scene, null, noMipmap, files);
         }
         }
 
 
-        public static CreateFromPrefilteredData(url: string, scene: Scene) {
-            return new CubeTexture(url, scene, null, false, null, null, null, undefined, true);
+        public static CreateFromPrefilteredData(url: string, scene: Scene, forcedExtension = null) {
+            return new CubeTexture(url, scene, null, false, null, null, null, undefined, true, forcedExtension);
         }
         }
 
 
-        constructor(rootUrl: string, scene: Scene, extensions?: string[], noMipmap?: boolean, files?: string[], onLoad: () => void = null, onError: () => void = null, format: number = Engine.TEXTUREFORMAT_RGBA, prefiltered = false) {
+        constructor(rootUrl: string, scene: Scene, extensions?: string[], noMipmap?: boolean, files?: string[], onLoad: () => void = null, onError: () => void = null, format: number = Engine.TEXTUREFORMAT_RGBA, prefiltered = false, forcedExtension = null) {
             super(scene);
             super(scene);
 
 
             this.name = rootUrl;
             this.name = rootUrl;
@@ -59,10 +59,10 @@
             if (!this._texture) {
             if (!this._texture) {
                 if (!scene.useDelayedTextureLoading) {
                 if (!scene.useDelayedTextureLoading) {
                     if (prefiltered) {
                     if (prefiltered) {
-                        this._texture = scene.getEngine().createPrefilteredCubeTexture(rootUrl, scene, this.lodGenerationScale, this.lodGenerationOffset, onLoad, onError, format);
+                        this._texture = scene.getEngine().createPrefilteredCubeTexture(rootUrl, scene, this.lodGenerationScale, this.lodGenerationOffset, onLoad, onError, format, forcedExtension);
                     }
                     }
                     else {
                     else {
-                        this._texture = scene.getEngine().createCubeTexture(rootUrl, scene, files, noMipmap, onLoad, onError, this._format);
+                        this._texture = scene.getEngine().createCubeTexture(rootUrl, scene, files, noMipmap, onLoad, onError, this._format, forcedExtension);
                     }
                     }
                 } else {
                 } else {
                     this.delayLoadState = Engine.DELAYLOADSTATE_NOTLOADED;
                     this.delayLoadState = Engine.DELAYLOADSTATE_NOTLOADED;

+ 8 - 12
src/Materials/babylon.standardMaterial.ts

@@ -62,8 +62,6 @@ module BABYLON {
         public REFRACTION = false;
         public REFRACTION = false;
         public REFRACTIONMAP_3D = false;
         public REFRACTIONMAP_3D = false;
         public REFLECTIONOVERALPHA = false;
         public REFLECTIONOVERALPHA = false;
-        public INVERTNORMALMAPX = false;
-        public INVERTNORMALMAPY = false;
         public TWOSIDEDLIGHTING = false;
         public TWOSIDEDLIGHTING = false;
         public SHADOWFLOAT = false;
         public SHADOWFLOAT = false;
         public MORPHTARGETS = false;
         public MORPHTARGETS = false;
@@ -640,9 +638,6 @@ module BABYLON {
                         } else {
                         } else {
                             MaterialHelper.PrepareDefinesForMergedUV(this._bumpTexture, defines, "BUMP");
                             MaterialHelper.PrepareDefinesForMergedUV(this._bumpTexture, defines, "BUMP");
 
 
-                            defines.INVERTNORMALMAPX = this.invertNormalMapX;
-                            defines.INVERTNORMALMAPY = this.invertNormalMapY;
-
                             defines.PARALLAX = this._useParallax;
                             defines.PARALLAX = this._useParallax;
                             defines.PARALLAXOCCLUSION = this._useParallaxOcclusion;
                             defines.PARALLAXOCCLUSION = this._useParallaxOcclusion;
                         }
                         }
@@ -728,12 +723,6 @@ module BABYLON {
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
             MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
             MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
 
 
-            if (scene._mirroredCameraPosition && defines.BUMP) {
-                defines.INVERTNORMALMAPX = !this.invertNormalMapX;
-                defines.INVERTNORMALMAPY = !this.invertNormalMapY;
-                defines.markAsUnprocessed();
-            }
-
             // Get correct effect      
             // Get correct effect      
             if (defines.isDirty) {
             if (defines.isDirty) {
                 defines.markAsProcessed();
                 defines.markAsProcessed();
@@ -834,7 +823,7 @@ module BABYLON {
                     "mBones",
                     "mBones",
                     "vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix", "lightmapMatrix", "refractionMatrix",
                     "vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix", "lightmapMatrix", "refractionMatrix",
                     "diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor", "refractionLeftColor", "refractionRightColor",
                     "diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor", "refractionLeftColor", "refractionRightColor",
-                    "logarithmicDepthConstant"
+                    "logarithmicDepthConstant", "vNormalReoderParams"
                 ];
                 ];
 
 
                 var samplers = ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"]
                 var samplers = ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"]
@@ -911,6 +900,7 @@ module BABYLON {
             this._uniformBuffer.addUniform("lightmapMatrix", 16);
             this._uniformBuffer.addUniform("lightmapMatrix", 16);
             this._uniformBuffer.addUniform("specularMatrix", 16);
             this._uniformBuffer.addUniform("specularMatrix", 16);
             this._uniformBuffer.addUniform("bumpMatrix", 16);
             this._uniformBuffer.addUniform("bumpMatrix", 16);
+            this._uniformBuffer.addUniform("vNormalReoderParams", 4);
             this._uniformBuffer.addUniform("refractionMatrix", 16);
             this._uniformBuffer.addUniform("refractionMatrix", 16);
             this._uniformBuffer.addUniform("vRefractionInfos", 4);
             this._uniformBuffer.addUniform("vRefractionInfos", 4);
             this._uniformBuffer.addUniform("vSpecularColor", 4);
             this._uniformBuffer.addUniform("vSpecularColor", 4);
@@ -1024,6 +1014,12 @@ module BABYLON {
                         if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled) {
                         if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled) {
                             this._uniformBuffer.updateFloat3("vBumpInfos", this._bumpTexture.coordinatesIndex, 1.0 / this._bumpTexture.level, this.parallaxScaleBias);
                             this._uniformBuffer.updateFloat3("vBumpInfos", this._bumpTexture.coordinatesIndex, 1.0 / this._bumpTexture.level, this.parallaxScaleBias);
                             MaterialHelper.BindTextureMatrix(this._bumpTexture, this._uniformBuffer, "bump");
                             MaterialHelper.BindTextureMatrix(this._bumpTexture, this._uniformBuffer, "bump");
+
+                            if (scene._mirroredCameraPosition) {
+                                this._uniformBuffer.updateFloat4("vNormalReoderParams", this.invertNormalMapX ? 0 : 1.0, this.invertNormalMapX ? 1.0 : -1.0, this.invertNormalMapY ? 0 : 1.0, this.invertNormalMapY ? 1.0 : -1.0);
+                            } else {
+                                this._uniformBuffer.updateFloat4("vNormalReoderParams", this.invertNormalMapX ? 1.0 : 0, this.invertNormalMapX ? -1.0 : 1.0, this.invertNormalMapY ? 1.0 : 0, this.invertNormalMapY ? -1.0 : 1.0);
+                            }                           
                         }
                         }
 
 
                         if (this._refractionTexture && StandardMaterial.RefractionTextureEnabled) {
                         if (this._refractionTexture && StandardMaterial.RefractionTextureEnabled) {

+ 2 - 6
src/Shaders/ShadersInclude/bumpFragmentFunctions.fx

@@ -42,12 +42,8 @@
 	{
 	{
 		vec3 map = texture2D(bumpSampler, uv).xyz;
 		vec3 map = texture2D(bumpSampler, uv).xyz;
 
 
-	#ifdef INVERTNORMALMAPX
-		map.x = 1.0 - map.x;
-	#endif
-	#ifdef INVERTNORMALMAPY
-		map.y = 1.0 - map.y;
-	#endif
+		map.x = vNormalReoderParams.x + vNormalReoderParams.y * map.x;
+		map.y = vNormalReoderParams.z + vNormalReoderParams.w * map.y;
 
 
 		map = map * 255. / 127. - 128. / 127.;
 		map = map * 255. / 127. - 128. / 127.;
 		return normalize(cotangentFrame * map);
 		return normalize(cotangentFrame * map);

+ 1 - 0
src/Shaders/ShadersInclude/defaultFragmentDeclaration.fx

@@ -27,6 +27,7 @@ uniform vec2 vLightmapInfos;
 
 
 #ifdef BUMP
 #ifdef BUMP
 uniform vec3 vBumpInfos;
 uniform vec3 vBumpInfos;
+uniform vec4 vNormalReoderParams;
 #endif
 #endif
 
 
 #if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION)
 #if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION)

+ 1 - 0
src/Shaders/ShadersInclude/defaultUboDeclaration.fx

@@ -27,6 +27,7 @@ uniform Material
 	mat4 lightmapMatrix;
 	mat4 lightmapMatrix;
 	mat4 specularMatrix;
 	mat4 specularMatrix;
 	mat4 bumpMatrix; 
 	mat4 bumpMatrix; 
+	vec4 vNormalReoderParams;
 	mat4 refractionMatrix;
 	mat4 refractionMatrix;
 	vec4 vRefractionInfos;
 	vec4 vRefractionInfos;
 	vec4 vSpecularColor;
 	vec4 vSpecularColor;

+ 1 - 0
src/Shaders/ShadersInclude/pbrFragmentDeclaration.fx

@@ -18,6 +18,7 @@ uniform vec3 vAmbientInfos;
 
 
 #ifdef BUMP
 #ifdef BUMP
 uniform vec3 vBumpInfos;
 uniform vec3 vBumpInfos;
+uniform vec4 vNormalReoderParams;
 #endif
 #endif
 
 
 #ifdef OPACITY	
 #ifdef OPACITY	

+ 1 - 2
src/Shaders/ShadersInclude/pbrLightFunctions.fx

@@ -18,12 +18,11 @@ float computeDistanceLightFalloff(vec3 lightOffset, float lightDistanceSquared,
     return lightDistanceFalloff;
     return lightDistanceFalloff;
 }
 }
 
 
-float computeDirectionalLightFalloff(vec3 lightDirection, vec3 directionToLightCenterW, float lightAngle, float exponent)
+float computeDirectionalLightFalloff(vec3 lightDirection, vec3 directionToLightCenterW, float cosHalfAngle, float exponent)
 {
 {
     float falloff = 0.0;
     float falloff = 0.0;
     
     
     #ifdef USEPHYSICALLIGHTFALLOFF
     #ifdef USEPHYSICALLIGHTFALLOFF
-        float cosHalfAngle = cos(lightAngle * 0.5);
         const float kMinusLog2ConeAngleIntensityRatio = 6.64385618977; // -log2(0.01)
         const float kMinusLog2ConeAngleIntensityRatio = 6.64385618977; // -log2(0.01)
 
 
         // Calculate a Spherical Gaussian (von Mises-Fisher distribution, not angle-based Gaussian) such that the peak is in the light direction,
         // Calculate a Spherical Gaussian (von Mises-Fisher distribution, not angle-based Gaussian) such that the peak is in the light direction,

+ 1 - 0
src/Shaders/ShadersInclude/pbrUboDeclaration.fx

@@ -20,6 +20,7 @@ uniform Material
 	uniform mat4 reflectivityMatrix;
 	uniform mat4 reflectivityMatrix;
 	uniform mat4 microSurfaceSamplerMatrix;
 	uniform mat4 microSurfaceSamplerMatrix;
 	uniform mat4 bumpMatrix;
 	uniform mat4 bumpMatrix;
+	uniform vec4 vNormalReoderParams;
 	uniform mat4 refractionMatrix;
 	uniform mat4 refractionMatrix;
 	uniform mat4 reflectionMatrix;
 	uniform mat4 reflectionMatrix;
 
 

+ 12 - 11
src/babylon.engine.ts

@@ -1720,7 +1720,7 @@
 
 
         public bindArrayBuffer(buffer: WebGLBuffer): void {
         public bindArrayBuffer(buffer: WebGLBuffer): void {
             if (!this._vaoRecordInProgress) {
             if (!this._vaoRecordInProgress) {
-                this._unBindVertexArrayObject();
+                this._unbindVertexArrayObject();
             }
             }
             this.bindBuffer(buffer, this._gl.ARRAY_BUFFER);
             this.bindBuffer(buffer, this._gl.ARRAY_BUFFER);
         }
         }
@@ -1741,7 +1741,7 @@
 
 
         private bindIndexBuffer(buffer: WebGLBuffer): void {
         private bindIndexBuffer(buffer: WebGLBuffer): void {
             if (!this._vaoRecordInProgress) {
             if (!this._vaoRecordInProgress) {
-                this._unBindVertexArrayObject();
+                this._unbindVertexArrayObject();
             }
             }
             this.bindBuffer(buffer, this._gl.ELEMENT_ARRAY_BUFFER);
             this.bindBuffer(buffer, this._gl.ELEMENT_ARRAY_BUFFER);
         }
         }
@@ -1801,7 +1801,7 @@
             var attributes = effect.getAttributesNames();
             var attributes = effect.getAttributesNames();
 
 
             if (!this._vaoRecordInProgress) {
             if (!this._vaoRecordInProgress) {
-                this._unBindVertexArrayObject();
+                this._unbindVertexArrayObject();
             }
             }
 
 
             this.unbindAllAttributes();
             this.unbindAllAttributes();
@@ -1873,7 +1873,7 @@
 
 
                 let attributesCount = effect.getAttributesCount();
                 let attributesCount = effect.getAttributesCount();
 
 
-                this._unBindVertexArrayObject();
+                this._unbindVertexArrayObject();
                 this.unbindAllAttributes();
                 this.unbindAllAttributes();
 
 
                 var offset = 0;
                 var offset = 0;
@@ -1897,7 +1897,7 @@
             this._bindIndexBufferWithCache(indexBuffer);
             this._bindIndexBufferWithCache(indexBuffer);
         }
         }
 
 
-        private _unBindVertexArrayObject(): void {
+        private _unbindVertexArrayObject(): void {
             if (!this._cachedVertexArrayObject) {
             if (!this._cachedVertexArrayObject) {
                 return;
                 return;
             }
             }
@@ -2445,6 +2445,7 @@
             }
             }
             this.resetTextureCache();
             this.resetTextureCache();
             this._currentEffect = null;
             this._currentEffect = null;
+            this._currentProgram = null;
 
 
             // 6/8/2017: deltakosh: Should not be required anymore. 
             // 6/8/2017: deltakosh: Should not be required anymore. 
             // This message is then mostly for the future myself which will scream out loud when seeing that actually it was required :)
             // This message is then mostly for the future myself which will scream out loud when seeing that actually it was required :)
@@ -2458,7 +2459,7 @@
             this._cachedVertexBuffers = null;
             this._cachedVertexBuffers = null;
             this._cachedIndexBuffer = null;
             this._cachedIndexBuffer = null;
             this._cachedEffectForVertexBuffers = null;
             this._cachedEffectForVertexBuffers = null;
-            this._unBindVertexArrayObject();
+            this._unbindVertexArrayObject();
             this.bindIndexBuffer(null);
             this.bindIndexBuffer(null);
             this.bindArrayBuffer(null);
             this.bindArrayBuffer(null);
         }
         }
@@ -3240,7 +3241,7 @@
             return texture;
             return texture;
         }
         }
 
 
-        public createPrefilteredCubeTexture(rootUrl: string, scene: Scene, scale: number, offset: number, onLoad: () => void, onError: () => void = null, format?: number): WebGLTexture {
+        public createPrefilteredCubeTexture(rootUrl: string, scene: Scene, scale: number, offset: number, onLoad: () => void, onError: () => void = null, format?: number, forcedExtension = null): WebGLTexture {
             var callback = (loadData) => {
             var callback = (loadData) => {
                 if (this._caps.textureLOD || !loadData) {
                 if (this._caps.textureLOD || !loadData) {
                     // Do not add extra process if texture lod is supported.
                     // Do not add extra process if texture lod is supported.
@@ -3310,10 +3311,10 @@
                 }
                 }
             };
             };
 
 
-            return this.createCubeTexture(rootUrl, scene, null, false, callback, onError, format);
+            return this.createCubeTexture(rootUrl, scene, null, false, callback, onError, format, forcedExtension);
         }
         }
 
 
-        public createCubeTexture(rootUrl: string, scene: Scene, files: string[], noMipmap?: boolean, onLoad: (data?: any) => void = null, onError: () => void = null, format?: number): WebGLTexture {
+        public createCubeTexture(rootUrl: string, scene: Scene, files: string[], noMipmap?: boolean, onLoad: (data?: any) => void = null, onError: () => void = null, format?: number, forcedExtension = null): WebGLTexture {
             var gl = this._gl;
             var gl = this._gl;
 
 
             var texture = gl.createTexture();
             var texture = gl.createTexture();
@@ -3326,7 +3327,7 @@
             var isKTX = false;
             var isKTX = false;
             var isDDS = false;
             var isDDS = false;
             var lastDot = rootUrl.lastIndexOf('.');
             var lastDot = rootUrl.lastIndexOf('.');
-            var extension = rootUrl.substring(lastDot).toLowerCase();
+            var extension = forcedExtension ? forcedExtension : rootUrl.substring(lastDot).toLowerCase();
             if (this._textureFormatInUse) {
             if (this._textureFormatInUse) {
                 extension = this._textureFormatInUse;
                 extension = this._textureFormatInUse;
                 rootUrl = rootUrl.substring(0, lastDot) + this._textureFormatInUse;
                 rootUrl = rootUrl.substring(0, lastDot) + this._textureFormatInUse;
@@ -4168,7 +4169,7 @@
             }
             }
 
 
             gl.readPixels(0, 0, width, height, gl.RGBA, readType, buffer);
             gl.readPixels(0, 0, width, height, gl.RGBA, readType, buffer);
-            gl.bindFramebuffer(gl.FRAMEBUFFER, null);
+            gl.bindFramebuffer(gl.FRAMEBUFFER, this._currentFramebuffer);
 
 
             return buffer;
             return buffer;
         }
         }