David Catuhe 8 年 前
コミット
c4c8598b08

ファイルの差分が大きいため隠しています
+ 2705 - 2705
dist/preview release/babylon.d.ts


ファイルの差分が大きいため隠しています
+ 39 - 39
dist/preview release/babylon.js


+ 237 - 78
dist/preview release/babylon.max.js

@@ -7372,19 +7372,25 @@ var BABYLON;
         var onload = function () {
         var onload = function () {
             loadedImages[index] = img;
             loadedImages[index] = img;
             loadedImages._internalCount++;
             loadedImages._internalCount++;
-            scene._removePendingData(img);
+            if (scene) {
+                scene._removePendingData(img);
+            }
             if (loadedImages._internalCount === 6) {
             if (loadedImages._internalCount === 6) {
                 onfinish(loadedImages);
                 onfinish(loadedImages);
             }
             }
         };
         };
         var onerror = function () {
         var onerror = function () {
-            scene._removePendingData(img);
+            if (scene) {
+                scene._removePendingData(img);
+            }
             if (onErrorCallBack) {
             if (onErrorCallBack) {
                 onErrorCallBack();
                 onErrorCallBack();
             }
             }
         };
         };
-        img = BABYLON.Tools.LoadImage(url, onload, onerror, scene.database);
-        scene._addPendingData(img);
+        img = BABYLON.Tools.LoadImage(url, onload, onerror, scene ? scene.database : null);
+        if (scene) {
+            scene._addPendingData(img);
+        }
     };
     };
     var cascadeLoad = function (rootUrl, scene, onfinish, files, onError) {
     var cascadeLoad = function (rootUrl, scene, onfinish, files, onError) {
         if (onError === void 0) { onError = null; }
         if (onError === void 0) { onError = null; }
@@ -7459,6 +7465,7 @@ var BABYLON;
             this._deterministicLockstep = false;
             this._deterministicLockstep = false;
             this._lockstepMaxSteps = 4;
             this._lockstepMaxSteps = 4;
             this._contextWasLost = false;
             this._contextWasLost = false;
+            this._doNotHandleContextLost = false;
             // FPS
             // FPS
             this._performanceMonitor = new BABYLON.PerformanceMonitor();
             this._performanceMonitor = new BABYLON.PerformanceMonitor();
             this._fps = 60;
             this._fps = 60;
@@ -7475,7 +7482,7 @@ var BABYLON;
             // Cache
             // Cache
             this._internalTexturesCache = new Array();
             this._internalTexturesCache = new Array();
             this._maxTextureChannels = 16;
             this._maxTextureChannels = 16;
-            this._activeTexturesCache = new Array(this._maxTextureChannels);
+            this._activeTexturesCache = {};
             this._compiledEffects = {};
             this._compiledEffects = {};
             this._vertexAttribArraysEnabled = [];
             this._vertexAttribArraysEnabled = [];
             this._uintIndicesCurrentlySet = false;
             this._uintIndicesCurrentlySet = false;
@@ -7532,6 +7539,7 @@ var BABYLON;
                 }
                 }
                 this._deterministicLockstep = options.deterministicLockstep;
                 this._deterministicLockstep = options.deterministicLockstep;
                 this._lockstepMaxSteps = options.lockstepMaxSteps;
                 this._lockstepMaxSteps = options.lockstepMaxSteps;
+                this._doNotHandleContextLost = options.doNotHandleContextLost;
                 // GL
                 // GL
                 if (!options.disableWebGL2Support) {
                 if (!options.disableWebGL2Support) {
                     try {
                     try {
@@ -7586,29 +7594,31 @@ var BABYLON;
                 options.stencil = this._gl.getContextAttributes().stencil;
                 options.stencil = this._gl.getContextAttributes().stencil;
             }
             }
             // Context lost
             // Context lost
-            this._onContextLost = function (evt) {
-                evt.preventDefault();
-                _this._contextWasLost = true;
-                BABYLON.Tools.Warn("WebGL context lost.");
-            };
-            this._onContextRestored = function (evt) {
-                _this._contextWasLost = false;
-                // Rebuild gl context
-                _this._initGLContext();
-                // Rebuild effects
-                _this._rebuildEffects();
-                // Rebuild textures
-                _this._rebuildInternalTextures();
-                // Rebuild buffers
-                _this._rebuildBuffers();
-                // Cache
-                _this.wipeCaches(true);
-                // Restart render loop
-                _this._renderLoop();
-                BABYLON.Tools.Warn("WebGL context successfully restored.");
-            };
-            canvas.addEventListener("webglcontextlost", this._onContextLost, false);
-            canvas.addEventListener("webglcontextrestored", this._onContextRestored, false);
+            if (!this._doNotHandleContextLost) {
+                this._onContextLost = function (evt) {
+                    evt.preventDefault();
+                    _this._contextWasLost = true;
+                    BABYLON.Tools.Warn("WebGL context lost.");
+                };
+                this._onContextRestored = function (evt) {
+                    _this._contextWasLost = false;
+                    // Rebuild gl context
+                    _this._initGLContext();
+                    // Rebuild effects
+                    _this._rebuildEffects();
+                    // Rebuild textures
+                    _this._rebuildInternalTextures();
+                    // Rebuild buffers
+                    _this._rebuildBuffers();
+                    // Cache
+                    _this.wipeCaches(true);
+                    // Restart render loop
+                    _this._renderLoop();
+                    BABYLON.Tools.Warn("WebGL context successfully restored.");
+                };
+                canvas.addEventListener("webglcontextlost", this._onContextLost, false);
+                canvas.addEventListener("webglcontextrestored", this._onContextRestored, false);
+            }
             // Viewport
             // Viewport
             var limitDeviceRatio = options.limitDeviceRatio || window.devicePixelRatio || 1.0;
             var limitDeviceRatio = options.limitDeviceRatio || window.devicePixelRatio || 1.0;
             this._hardwareScalingLevel = adaptToDeviceRatio ? 1.0 / Math.min(limitDeviceRatio, window.devicePixelRatio || 1.0) : 1.0;
             this._hardwareScalingLevel = adaptToDeviceRatio ? 1.0 / Math.min(limitDeviceRatio, window.devicePixelRatio || 1.0) : 1.0;
@@ -7656,6 +7666,14 @@ var BABYLON;
                 document.addEventListener("mspointerlockchange", this._onPointerLockChange, false);
                 document.addEventListener("mspointerlockchange", this._onPointerLockChange, false);
                 document.addEventListener("mozpointerlockchange", this._onPointerLockChange, false);
                 document.addEventListener("mozpointerlockchange", this._onPointerLockChange, false);
                 document.addEventListener("webkitpointerlockchange", this._onPointerLockChange, false);
                 document.addEventListener("webkitpointerlockchange", this._onPointerLockChange, false);
+                this._onVRDisplayPointerRestricted = function () {
+                    canvas.requestPointerLock();
+                };
+                this._onVRDisplayPointerUnrestricted = function () {
+                    document.exitPointerLock();
+                };
+                window.addEventListener('vrdisplaypointerrestricted', this._onVRDisplayPointerRestricted, false);
+                window.addEventListener('vrdisplaypointerunrestricted', this._onVRDisplayPointerUnrestricted, false);
             }
             }
             if (options.audioEngine && BABYLON.AudioEngine && !Engine.audioEngine) {
             if (options.audioEngine && BABYLON.AudioEngine && !Engine.audioEngine) {
                 Engine.audioEngine = new BABYLON.AudioEngine();
                 Engine.audioEngine = new BABYLON.AudioEngine();
@@ -8070,8 +8088,9 @@ var BABYLON;
             configurable: true
             configurable: true
         });
         });
         Engine.prototype._rebuildInternalTextures = function () {
         Engine.prototype._rebuildInternalTextures = function () {
-            for (var _i = 0, _a = this._internalTexturesCache; _i < _a.length; _i++) {
-                var internalTexture = _a[_i];
+            var currentState = this._internalTexturesCache.slice(); // Do a copy because the rebuild will add proxies
+            for (var _i = 0, currentState_1 = currentState; _i < currentState_1.length; _i++) {
+                var internalTexture = currentState_1[_i];
                 internalTexture._rebuild();
                 internalTexture._rebuild();
             }
             }
         };
         };
@@ -8233,8 +8252,8 @@ var BABYLON;
             this._workingContext = this._workingCanvas.getContext("2d");
             this._workingContext = this._workingCanvas.getContext("2d");
         };
         };
         Engine.prototype.resetTextureCache = function () {
         Engine.prototype.resetTextureCache = function () {
-            for (var index = 0; index < this._maxTextureChannels; index++) {
-                this._activeTexturesCache[index] = null;
+            for (var key in this._activeTexturesCache) {
+                this._activeTexturesCache[key] = null;
             }
             }
         };
         };
         Engine.prototype.isDeterministicLockStep = function () {
         Engine.prototype.isDeterministicLockStep = function () {
@@ -9521,10 +9540,11 @@ var BABYLON;
             if (onLoad === void 0) { onLoad = null; }
             if (onLoad === void 0) { onLoad = null; }
             if (onError === void 0) { onError = null; }
             if (onError === void 0) { onError = null; }
             if (buffer === void 0) { buffer = null; }
             if (buffer === void 0) { buffer = null; }
-            var texture = fallBack ? fallBack : new BABYLON.InternalTexture(this, BABYLON.InternalTexture.DATASOURCE_URL);
             var url = String(urlArg); // assign a new string, so that the original is still available in case of fallback
             var url = String(urlArg); // assign a new string, so that the original is still available in case of fallback
             var fromData = url.substr(0, 5) === "data:";
             var fromData = url.substr(0, 5) === "data:";
+            var fromBlob = url.substr(0, 5) === "blob:";
             var isBase64 = fromData && url.indexOf("base64") !== -1;
             var isBase64 = fromData && url.indexOf("base64") !== -1;
+            var texture = fallBack ? fallBack : new BABYLON.InternalTexture(this, BABYLON.InternalTexture.DATASOURCE_URL);
             // establish the file extension, if possible
             // establish the file extension, if possible
             var lastDot = url.lastIndexOf('.');
             var lastDot = url.lastIndexOf('.');
             var extension = (lastDot > 0) ? url.substring(lastDot).toLowerCase() : "";
             var extension = (lastDot > 0) ? url.substring(lastDot).toLowerCase() : "";
@@ -9536,18 +9556,26 @@ var BABYLON;
                 url = url.substring(0, lastDot) + this._textureFormatInUse;
                 url = url.substring(0, lastDot) + this._textureFormatInUse;
                 isKTX = true;
                 isKTX = true;
             }
             }
-            scene._addPendingData(texture);
+            if (scene) {
+                scene._addPendingData(texture);
+            }
             texture.url = url;
             texture.url = url;
             texture.generateMipMaps = !noMipmap;
             texture.generateMipMaps = !noMipmap;
             texture.samplingMode = samplingMode;
             texture.samplingMode = samplingMode;
             texture.invertY = invertY;
             texture.invertY = invertY;
+            if (!this._doNotHandleContextLost) {
+                // Keep a link to the buffer only if we plan to handle context lost
+                texture._buffer = buffer;
+            }
             if (onLoad) {
             if (onLoad) {
                 texture.onLoadedObservable.add(onLoad);
                 texture.onLoadedObservable.add(onLoad);
             }
             }
             if (!fallBack)
             if (!fallBack)
                 this._internalTexturesCache.push(texture);
                 this._internalTexturesCache.push(texture);
             var onerror = function () {
             var onerror = function () {
-                scene._removePendingData(texture);
+                if (scene) {
+                    scene._removePendingData(texture);
+                }
                 // fallback for when compressed file not found to try again.  For instance, etc1 does not have an alpha capable type
                 // fallback for when compressed file not found to try again.  For instance, etc1 does not have an alpha capable type
                 if (isKTX) {
                 if (isKTX) {
                     _this.createTexture(urlArg, noMipmap, invertY, scene, samplingMode, null, onError, buffer, texture);
                     _this.createTexture(urlArg, noMipmap, invertY, scene, samplingMode, null, onError, buffer, texture);
@@ -9591,7 +9619,7 @@ var BABYLON;
                 if (!buffer) {
                 if (!buffer) {
                     BABYLON.Tools.LoadFile(url, function (data) {
                     BABYLON.Tools.LoadFile(url, function (data) {
                         callback(data);
                         callback(data);
-                    }, null, scene.database, true, onerror);
+                    }, null, scene ? scene.database : null, true, onerror);
                 }
                 }
                 else {
                 else {
                     callback(buffer);
                     callback(buffer);
@@ -9600,6 +9628,11 @@ var BABYLON;
             }
             }
             else {
             else {
                 var onload = function (img) {
                 var onload = function (img) {
+                    if (fromBlob && !_this._doNotHandleContextLost) {
+                        // We need to store the image if we need to rebuild the texture
+                        // in case of a webgl context lost
+                        texture._buffer = img;
+                    }
                     _this._prepareWebGLTexture(texture, scene, img.width, img.height, invertY, noMipmap, false, function (potWidth, potHeight, continuationCallback) {
                     _this._prepareWebGLTexture(texture, scene, img.width, img.height, invertY, noMipmap, false, function (potWidth, potHeight, continuationCallback) {
                         var gl = _this._gl;
                         var gl = _this._gl;
                         var isPot = (img.width === potWidth && img.height === potHeight);
                         var isPot = (img.width === potWidth && img.height === potHeight);
@@ -9625,9 +9658,14 @@ var BABYLON;
                     }, samplingMode);
                     }, samplingMode);
                 };
                 };
                 if (!fromData || isBase64)
                 if (!fromData || isBase64)
-                    BABYLON.Tools.LoadImage(url, onload, onerror, scene.database);
+                    if (buffer instanceof HTMLImageElement) {
+                        onload(buffer);
+                    }
+                    else {
+                        BABYLON.Tools.LoadImage(url, onload, onerror, scene ? scene.database : null);
+                    }
                 else if (buffer instanceof Array || typeof buffer === "string")
                 else if (buffer instanceof Array || typeof buffer === "string")
-                    BABYLON.Tools.LoadImage(buffer, onload, onerror, scene.database);
+                    BABYLON.Tools.LoadImage(buffer, onload, onerror, scene ? scene.database : null);
                 else
                 else
                     onload(buffer);
                     onload(buffer);
             }
             }
@@ -10127,10 +10165,20 @@ var BABYLON;
             if (onError === void 0) { onError = null; }
             if (onError === void 0) { onError = null; }
             if (forcedExtension === void 0) { forcedExtension = null; }
             if (forcedExtension === void 0) { forcedExtension = null; }
             var callback = function (loadData) {
             var callback = function (loadData) {
-                if (_this._caps.textureLOD || !loadData) {
+                if (!loadData) {
+                    if (onLoad) {
+                        onLoad(null);
+                    }
+                    return;
+                }
+                var texture = loadData.texture;
+                texture._dataSource = BABYLON.InternalTexture.DATASOURCE_CUBEPREFILTERED;
+                texture._lodGenerationScale = scale;
+                texture._lodGenerationOffset = offset;
+                if (_this._caps.textureLOD) {
                     // Do not add extra process if texture lod is supported.
                     // Do not add extra process if texture lod is supported.
                     if (onLoad) {
                     if (onLoad) {
-                        onLoad();
+                        onLoad(texture);
                     }
                     }
                     return;
                     return;
                 }
                 }
@@ -10149,7 +10197,7 @@ var BABYLON;
                     var maxLODIndex = BABYLON.Scalar.Log2(width) * scale + offset; // roughness = 1
                     var maxLODIndex = BABYLON.Scalar.Log2(width) * scale + offset; // roughness = 1
                     var lodIndex = minLODIndex + (maxLODIndex - minLODIndex) * roughness;
                     var lodIndex = minLODIndex + (maxLODIndex - minLODIndex) * roughness;
                     var mipmapIndex = Math.round(Math.min(Math.max(lodIndex, 0), maxLODIndex));
                     var mipmapIndex = Math.round(Math.min(Math.max(lodIndex, 0), maxLODIndex));
-                    var glTextureFromLod = new BABYLON.InternalTexture(_this, BABYLON.InternalTexture.DATASOURCE_CUBELOD);
+                    var glTextureFromLod = new BABYLON.InternalTexture(_this, BABYLON.InternalTexture.DATASOURCE_TEMP);
                     glTextureFromLod.isCube = true;
                     glTextureFromLod.isCube = true;
                     _this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, glTextureFromLod);
                     _this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, glTextureFromLod);
                     gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
                     gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
@@ -10173,11 +10221,11 @@ var BABYLON;
                     glTextureFromLod.isReady = true;
                     glTextureFromLod.isReady = true;
                     textures.push(lodTexture);
                     textures.push(lodTexture);
                 }
                 }
-                loadData.texture._lodTextureHigh = textures[2];
-                loadData.texture._lodTextureMid = textures[1];
-                loadData.texture._lodTextureLow = textures[0];
+                texture._lodTextureHigh = textures[2];
+                texture._lodTextureMid = textures[1];
+                texture._lodTextureLow = textures[0];
                 if (onLoad) {
                 if (onLoad) {
-                    onLoad();
+                    onLoad(texture);
                 }
                 }
             };
             };
             return this.createCubeTexture(rootUrl, scene, null, false, callback, onError, format, forcedExtension);
             return this.createCubeTexture(rootUrl, scene, null, false, callback, onError, format, forcedExtension);
@@ -10192,6 +10240,10 @@ var BABYLON;
             texture.isCube = true;
             texture.isCube = true;
             texture.url = rootUrl;
             texture.url = rootUrl;
             texture.generateMipMaps = !noMipmap;
             texture.generateMipMaps = !noMipmap;
+            if (!this._doNotHandleContextLost) {
+                texture._extension = forcedExtension;
+                texture._files = files;
+            }
             var isKTX = false;
             var isKTX = false;
             var isDDS = false;
             var isDDS = false;
             var lastDot = rootUrl.lastIndexOf('.');
             var lastDot = rootUrl.lastIndexOf('.');
@@ -10277,6 +10329,7 @@ var BABYLON;
                     texture.width = width;
                     texture.width = width;
                     texture.height = height;
                     texture.height = height;
                     texture.isReady = true;
                     texture.isReady = true;
+                    texture.format = format;
                     texture.onLoadedObservable.notifyObservers(texture);
                     texture.onLoadedObservable.notifyObservers(texture);
                     texture.onLoadedObservable.clear();
                     texture.onLoadedObservable.clear();
                     if (onLoad) {
                     if (onLoad) {
@@ -10452,7 +10505,9 @@ var BABYLON;
             }
             }
             this._bindTextureDirectly(gl.TEXTURE_2D, null);
             this._bindTextureDirectly(gl.TEXTURE_2D, null);
             this.resetTextureCache();
             this.resetTextureCache();
-            scene._removePendingData(texture);
+            if (scene) {
+                scene._removePendingData(texture);
+            }
             texture.onLoadedObservable.notifyObservers(texture);
             texture.onLoadedObservable.notifyObservers(texture);
             texture.onLoadedObservable.clear();
             texture.onLoadedObservable.clear();
         };
         };
@@ -10693,9 +10748,9 @@ var BABYLON;
             if (internalTexture.samplingMode === BABYLON.Texture.NEAREST_SAMPLINGMODE) {
             if (internalTexture.samplingMode === BABYLON.Texture.NEAREST_SAMPLINGMODE) {
                 value = 1;
                 value = 1;
             }
             }
-            if (anisotropicFilterExtension && texture._cachedAnisotropicFilteringLevel !== value) {
+            if (anisotropicFilterExtension && internalTexture._cachedAnisotropicFilteringLevel !== value) {
                 this._gl.texParameterf(key, anisotropicFilterExtension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(value, this._caps.maxAnisotropy));
                 this._gl.texParameterf(key, anisotropicFilterExtension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(value, this._caps.maxAnisotropy));
-                texture._cachedAnisotropicFilteringLevel = value;
+                internalTexture._cachedAnisotropicFilteringLevel = value;
             }
             }
         };
         };
         Engine.prototype.readPixels = function (x, y, width, height) {
         Engine.prototype.readPixels = function (x, y, width, height) {
@@ -10814,9 +10869,13 @@ var BABYLON;
             // Events
             // Events
             window.removeEventListener("blur", this._onBlur);
             window.removeEventListener("blur", this._onBlur);
             window.removeEventListener("focus", this._onFocus);
             window.removeEventListener("focus", this._onFocus);
+            window.removeEventListener('vrdisplaypointerrestricted', this._onVRDisplayPointerRestricted);
+            window.removeEventListener('vrdisplaypointerunrestricted', this._onVRDisplayPointerUnrestricted);
             this._renderingCanvas.removeEventListener("pointerout", this._onCanvasBlur);
             this._renderingCanvas.removeEventListener("pointerout", this._onCanvasBlur);
-            this._renderingCanvas.removeEventListener("webglcontextlost", this._onContextLost);
-            this._renderingCanvas.removeEventListener("webglcontextrestored", this._onContextRestored);
+            if (!this._doNotHandleContextLost) {
+                this._renderingCanvas.removeEventListener("webglcontextlost", this._onContextLost);
+                this._renderingCanvas.removeEventListener("webglcontextrestored", this._onContextRestored);
+            }
             document.removeEventListener("fullscreenchange", this._onFullscreenChange);
             document.removeEventListener("fullscreenchange", this._onFullscreenChange);
             document.removeEventListener("mozfullscreenchange", this._onFullscreenChange);
             document.removeEventListener("mozfullscreenchange", this._onFullscreenChange);
             document.removeEventListener("webkitfullscreenchange", this._onFullscreenChange);
             document.removeEventListener("webkitfullscreenchange", this._onFullscreenChange);
@@ -11870,7 +11929,7 @@ var BABYLON;
     
     
             * OCCLUSION_TYPE_NONE (Default Value): this option means no occlusion query whith the Mesh.
             * OCCLUSION_TYPE_NONE (Default Value): this option means no occlusion query whith the Mesh.
     
     
-            * OCCLUSION_TYPE_OPTIMISITC: this option is means use occlusion query and if occlusionRetryCount is reached and the query is broken show the mesh.
+            * OCCLUSION_TYPE_OPTIMISTIC: this option is means use occlusion query and if occlusionRetryCount is reached and the query is broken show the mesh.
     
     
                 * OCCLUSION_TYPE_STRICT: this option is means use occlusion query and if occlusionRetryCount is reached and the query is broken restore the last state of the mesh occlusion if the mesh was visible then show the mesh if was hidden then hide don't show.
                 * OCCLUSION_TYPE_STRICT: this option is means use occlusion query and if occlusionRetryCount is reached and the query is broken restore the last state of the mesh occlusion if the mesh was visible then show the mesh if was hidden then hide don't show.
              */
              */
@@ -12282,6 +12341,15 @@ var BABYLON;
             }
             }
             return ret;
             return ret;
         };
         };
+        AbstractMesh.prototype._rebuild = function () {
+            if (!this.subMeshes) {
+                return;
+            }
+            for (var _i = 0, _a = this.subMeshes; _i < _a.length; _i++) {
+                var subMesh = _a[_i];
+                subMesh._rebuild();
+            }
+        };
         AbstractMesh.prototype._resyncLightSources = function () {
         AbstractMesh.prototype._resyncLightSources = function () {
             this._lightSources.length = 0;
             this._lightSources.length = 0;
             for (var _i = 0, _a = this.getScene().lights; _i < _a.length; _i++) {
             for (var _i = 0, _a = this.getScene().lights; _i < _a.length; _i++) {
@@ -13956,7 +14024,7 @@ var BABYLON;
                         this._occlusionInternalRetryCounter = 0;
                         this._occlusionInternalRetryCounter = 0;
                         // if optimistic set isOccluded to false regardless of the status of isOccluded. (Render in the current render loop)
                         // if optimistic set isOccluded to false regardless of the status of isOccluded. (Render in the current render loop)
                         // if strict continue the last state of the object.
                         // if strict continue the last state of the object.
-                        this._isOccluded = this.occlusionType === AbstractMesh.OCCLUSION_TYPE_OPTIMISITC ? false : this._isOccluded;
+                        this._isOccluded = this.occlusionType === AbstractMesh.OCCLUSION_TYPE_OPTIMISTIC ? false : this._isOccluded;
                     }
                     }
                     else {
                     else {
                         return;
                         return;
@@ -13980,7 +14048,7 @@ var BABYLON;
         AbstractMesh._BILLBOARDMODE_Z = 4;
         AbstractMesh._BILLBOARDMODE_Z = 4;
         AbstractMesh._BILLBOARDMODE_ALL = 7;
         AbstractMesh._BILLBOARDMODE_ALL = 7;
         AbstractMesh.OCCLUSION_TYPE_NONE = 0;
         AbstractMesh.OCCLUSION_TYPE_NONE = 0;
-        AbstractMesh.OCCLUSION_TYPE_OPTIMISITC = 1;
+        AbstractMesh.OCCLUSION_TYPE_OPTIMISTIC = 1;
         AbstractMesh.OCCLUSION_TYPE_STRICT = 2;
         AbstractMesh.OCCLUSION_TYPE_STRICT = 2;
         AbstractMesh.OCCLUSION_ALGORITHM_TYPE_ACCURATE = 0;
         AbstractMesh.OCCLUSION_ALGORITHM_TYPE_ACCURATE = 0;
         AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE = 1;
         AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE = 1;
@@ -19296,12 +19364,21 @@ var BABYLON;
                 var geometry = _a[_i];
                 var geometry = _a[_i];
                 geometry._rebuild();
                 geometry._rebuild();
             }
             }
+            for (var _b = 0, _c = this.meshes; _b < _c.length; _b++) {
+                var mesh = _c[_b];
+                mesh._rebuild();
+            }
+            for (var _d = 0, _e = this.layers; _d < _e.length; _d++) {
+                var layer = _e[_d];
+                layer._rebuild();
+            }
         };
         };
         Scene.prototype._rebuildTextures = function () {
         Scene.prototype._rebuildTextures = function () {
             for (var _i = 0, _a = this.textures; _i < _a.length; _i++) {
             for (var _i = 0, _a = this.textures; _i < _a.length; _i++) {
                 var texture = _a[_i];
                 var texture = _a[_i];
                 texture._rebuild();
                 texture._rebuild();
             }
             }
+            this.markAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
         };
         };
         Scene.prototype.createDefaultCameraOrLight = function (createArcRotateCamera, replace, attachCameraControls) {
         Scene.prototype.createDefaultCameraOrLight = function (createArcRotateCamera, replace, attachCameraControls) {
             if (createArcRotateCamera === void 0) { createArcRotateCamera = false; }
             if (createArcRotateCamera === void 0) { createArcRotateCamera = false; }
@@ -19878,7 +19955,66 @@ var BABYLON;
             this.baseHeight = height;
             this.baseHeight = height;
         };
         };
         InternalTexture.prototype._rebuild = function () {
         InternalTexture.prototype._rebuild = function () {
-            // this._engine.createTexture(this.url, !this.generateMipMaps, this.invertY, scene, this.samplingMode, null, null, this._buffer, null, this._format);
+            var _this = this;
+            var proxy;
+            this.isReady = false;
+            this._cachedCoordinatesMode = null;
+            this._cachedWrapU = null;
+            this._cachedWrapV = null;
+            this._cachedAnisotropicFilteringLevel = null;
+            switch (this._dataSource) {
+                case InternalTexture.DATASOURCE_TEMP:
+                    return;
+                case InternalTexture.DATASOURCE_URL:
+                    proxy = this._engine.createTexture(this.url, !this.generateMipMaps, this.invertY, null, this.samplingMode, function () {
+                        _this.isReady = true;
+                    }, null, this._buffer, null, this.format);
+                    proxy._swapAndDie(this);
+                    return;
+                case InternalTexture.DATASOURCE_DYNAMIC:
+                    proxy = this._engine.createDynamicTexture(this.baseWidth, this.baseHeight, this.generateMipMaps, this.samplingMode);
+                    proxy._swapAndDie(this);
+                    // The engine will make sure to update content so no need to flag it as isReady = true
+                    return;
+                case InternalTexture.DATASOURCE_CUBE:
+                    proxy = this._engine.createCubeTexture(this.url, null, this._files, !this.generateMipMaps, function () {
+                        _this.isReady = true;
+                    }, null, this.format, this._extension);
+                    proxy._swapAndDie(this);
+                    return;
+                case InternalTexture.DATASOURCE_CUBEPREFILTERED:
+                    proxy = this._engine.createPrefilteredCubeTexture(this.url, null, this._lodGenerationScale, this._lodGenerationOffset, function (proxy) {
+                        proxy._swapAndDie(_this);
+                        _this.isReady = true;
+                    }, null, this.format, this._extension);
+                    return;
+            }
+        };
+        InternalTexture.prototype._swapAndDie = function (target) {
+            target._webGLTexture = this._webGLTexture;
+            if (this._lodTextureHigh) {
+                if (target._lodTextureHigh) {
+                    target._lodTextureHigh.dispose();
+                }
+                target._lodTextureHigh = this._lodTextureHigh;
+            }
+            if (this._lodTextureMid) {
+                if (target._lodTextureMid) {
+                    target._lodTextureMid.dispose();
+                }
+                target._lodTextureMid = this._lodTextureMid;
+            }
+            if (this._lodTextureLow) {
+                if (target._lodTextureLow) {
+                    target._lodTextureLow.dispose();
+                }
+                target._lodTextureLow = this._lodTextureLow;
+            }
+            var cache = this._engine.getLoadedTexturesCache();
+            var index = cache.indexOf(this);
+            if (index !== -1) {
+                cache.splice(index, 1);
+            }
         };
         };
         InternalTexture.prototype.dispose = function () {
         InternalTexture.prototype.dispose = function () {
             if (!this._webGLTexture) {
             if (!this._webGLTexture) {
@@ -19898,8 +20034,8 @@ var BABYLON;
         InternalTexture.DATASOURCE_RENDERTARGET = 5;
         InternalTexture.DATASOURCE_RENDERTARGET = 5;
         InternalTexture.DATASOURCE_MULTIRENDERTARGET = 6;
         InternalTexture.DATASOURCE_MULTIRENDERTARGET = 6;
         InternalTexture.DATASOURCE_CUBE = 7;
         InternalTexture.DATASOURCE_CUBE = 7;
-        InternalTexture.DATASOURCE_CUBELOD = 8;
-        InternalTexture.DATASOURCE_CUBERAW = 9;
+        InternalTexture.DATASOURCE_CUBERAW = 8;
+        InternalTexture.DATASOURCE_CUBEPREFILTERED = 9;
         return InternalTexture;
         return InternalTexture;
     }());
     }());
     BABYLON.InternalTexture = InternalTexture;
     BABYLON.InternalTexture = InternalTexture;
@@ -23722,6 +23858,11 @@ var BABYLON;
             }
             }
             return intersectInfo;
             return intersectInfo;
         };
         };
+        SubMesh.prototype._rebuild = function () {
+            if (this._linesIndexBuffer) {
+                this._linesIndexBuffer = null;
+            }
+        };
         // Clone    
         // Clone    
         /**
         /**
          * Creates a new Submesh from the passed Mesh.
          * Creates a new Submesh from the passed Mesh.
@@ -40695,6 +40836,7 @@ var BABYLON;
             this._pos = 0; // index of this particle in the global "positions" array
             this._pos = 0; // index of this particle in the global "positions" array
             this.shapeId = 0; // model shape id
             this.shapeId = 0; // model shape id
             this.idxInShape = 0; // index of the particle in its shape id
             this.idxInShape = 0; // index of the particle in its shape id
+            this._stillInvisible = false; // still set as invisible in order to skip useless computations
             this.idx = particleIndex;
             this.idx = particleIndex;
             this._pos = positionIndex;
             this._pos = positionIndex;
             this._model = model;
             this._model = model;
@@ -41348,7 +41490,17 @@ var BABYLON;
                 this._shapeUV = this._particle._model._shapeUV;
                 this._shapeUV = this._particle._model._shapeUV;
                 // call to custom user function to update the particle properties
                 // call to custom user function to update the particle properties
                 this.updateParticle(this._particle);
                 this.updateParticle(this._particle);
+                // skip the computations for inactive or already invisible particles
+                if (!this._particle.alive || (this._particle._stillInvisible && !this._particle.isVisible)) {
+                    // increment indexes for the next particle
+                    pt = this._shape.length;
+                    index += pt * 3;
+                    colorIndex += pt * 4;
+                    uvIndex += pt * 2;
+                    continue;
+                }
                 if (this._particle.isVisible) {
                 if (this._particle.isVisible) {
+                    this._particle._stillInvisible = false; // un-mark permanent invisibility
                     // particle rotation matrix
                     // particle rotation matrix
                     if (this.billboard) {
                     if (this.billboard) {
                         this._particle.rotation.x = 0.0;
                         this._particle.rotation.x = 0.0;
@@ -41433,13 +41585,14 @@ var BABYLON;
                     }
                     }
                 }
                 }
                 else {
                 else {
+                    this._particle._stillInvisible = true; // mark the particle as invisible
                     for (pt = 0; pt < this._shape.length; pt++) {
                     for (pt = 0; pt < this._shape.length; pt++) {
                         idx = index + pt * 3;
                         idx = index + pt * 3;
                         colidx = colorIndex + pt * 4;
                         colidx = colorIndex + pt * 4;
                         uvidx = uvIndex + pt * 2;
                         uvidx = uvIndex + pt * 2;
-                        this._positions32[idx] = this._camera.globalPosition.x;
-                        this._positions32[idx + 1] = this._camera.globalPosition.y;
-                        this._positions32[idx + 2] = this._camera.globalPosition.z;
+                        this._positions32[idx] = 0.0;
+                        this._positions32[idx + 1] = 0.0;
+                        this._positions32[idx + 2] = 0.0;
                         this._normals32[idx] = 0.0;
                         this._normals32[idx] = 0.0;
                         this._normals32[idx + 1] = 0.0;
                         this._normals32[idx + 1] = 0.0;
                         this._normals32[idx + 2] = 0.0;
                         this._normals32[idx + 2] = 0.0;
@@ -65976,8 +66129,10 @@ var BABYLON;
             if (this._webVRsupportedAndReady) {
             if (this._webVRsupportedAndReady) {
                 this._scene.getEngine().disableVR();
                 this._scene.getEngine().disableVR();
             }
             }
-            this._position = this._scene.activeCamera.position;
-            this._scene.activeCamera.dispose();
+            if (this._scene.activeCamera) {
+                this._position = this._scene.activeCamera.position;
+                this._scene.activeCamera.dispose();
+            }
             this._scene.activeCamera = new BABYLON.DeviceOrientationCamera("deviceOrientationVRHelper", this._position, this._scene);
             this._scene.activeCamera = new BABYLON.DeviceOrientationCamera("deviceOrientationVRHelper", this._position, this._scene);
             this._scene.activeCamera.attachControl(this._canvas);
             this._scene.activeCamera.attachControl(this._canvas);
             this._isInVRMode = false;
             this._isInVRMode = false;
@@ -69983,23 +70138,7 @@ var BABYLON;
             this._scene = scene || BABYLON.Engine.LastCreatedScene;
             this._scene = scene || BABYLON.Engine.LastCreatedScene;
             this._scene.layers.push(this);
             this._scene.layers.push(this);
             var engine = this._scene.getEngine();
             var engine = this._scene.getEngine();
-            // VBO
-            var vertices = [];
-            vertices.push(1, 1);
-            vertices.push(-1, 1);
-            vertices.push(-1, -1);
-            vertices.push(1, -1);
-            var vertexBuffer = new BABYLON.VertexBuffer(engine, vertices, BABYLON.VertexBuffer.PositionKind, false, false, 2);
-            this._vertexBuffers[BABYLON.VertexBuffer.PositionKind] = vertexBuffer;
-            // Indices
-            var indices = [];
-            indices.push(0);
-            indices.push(1);
-            indices.push(2);
-            indices.push(0);
-            indices.push(2);
-            indices.push(3);
-            this._indexBuffer = engine.createIndexBuffer(indices);
+            this._rebuild();
             // Effects
             // Effects
             this._effect = engine.createEffect("layer", [BABYLON.VertexBuffer.PositionKind], ["textureMatrix", "color", "scale", "offset"], ["textureSampler"], "");
             this._effect = engine.createEffect("layer", [BABYLON.VertexBuffer.PositionKind], ["textureMatrix", "color", "scale", "offset"], ["textureSampler"], "");
             this._alphaTestEffect = engine.createEffect("layer", [BABYLON.VertexBuffer.PositionKind], ["textureMatrix", "color", "scale", "offset"], ["textureSampler"], "#define ALPHATEST");
             this._alphaTestEffect = engine.createEffect("layer", [BABYLON.VertexBuffer.PositionKind], ["textureMatrix", "color", "scale", "offset"], ["textureSampler"], "#define ALPHATEST");
@@ -70034,6 +70173,26 @@ var BABYLON;
             enumerable: true,
             enumerable: true,
             configurable: true
             configurable: true
         });
         });
+        Layer.prototype._rebuild = function () {
+            var engine = this._scene.getEngine();
+            // VBO
+            var vertices = [];
+            vertices.push(1, 1);
+            vertices.push(-1, 1);
+            vertices.push(-1, -1);
+            vertices.push(1, -1);
+            var vertexBuffer = new BABYLON.VertexBuffer(engine, vertices, BABYLON.VertexBuffer.PositionKind, false, false, 2);
+            this._vertexBuffers[BABYLON.VertexBuffer.PositionKind] = vertexBuffer;
+            // Indices
+            var indices = [];
+            indices.push(0);
+            indices.push(1);
+            indices.push(2);
+            indices.push(0);
+            indices.push(2);
+            indices.push(3);
+            this._indexBuffer = engine.createIndexBuffer(indices);
+        };
         Layer.prototype.render = function () {
         Layer.prototype.render = function () {
             var currentEffect = this.alphaTest ? this._alphaTestEffect : this._effect;
             var currentEffect = this.alphaTest ? this._alphaTestEffect : this._effect;
             // Check
             // Check

ファイルの差分が大きいため隠しています
+ 2705 - 2705
dist/preview release/babylon.module.d.ts


ファイルの差分が大きいため隠しています
+ 39 - 39
dist/preview release/babylon.worker.js


ファイルの差分が大きいため隠しています
+ 8073 - 8059
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts


ファイルの差分が大きいため隠しています
+ 31 - 30
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js


+ 218 - 73
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js

@@ -7372,19 +7372,25 @@ var BABYLON;
         var onload = function () {
         var onload = function () {
             loadedImages[index] = img;
             loadedImages[index] = img;
             loadedImages._internalCount++;
             loadedImages._internalCount++;
-            scene._removePendingData(img);
+            if (scene) {
+                scene._removePendingData(img);
+            }
             if (loadedImages._internalCount === 6) {
             if (loadedImages._internalCount === 6) {
                 onfinish(loadedImages);
                 onfinish(loadedImages);
             }
             }
         };
         };
         var onerror = function () {
         var onerror = function () {
-            scene._removePendingData(img);
+            if (scene) {
+                scene._removePendingData(img);
+            }
             if (onErrorCallBack) {
             if (onErrorCallBack) {
                 onErrorCallBack();
                 onErrorCallBack();
             }
             }
         };
         };
-        img = BABYLON.Tools.LoadImage(url, onload, onerror, scene.database);
-        scene._addPendingData(img);
+        img = BABYLON.Tools.LoadImage(url, onload, onerror, scene ? scene.database : null);
+        if (scene) {
+            scene._addPendingData(img);
+        }
     };
     };
     var cascadeLoad = function (rootUrl, scene, onfinish, files, onError) {
     var cascadeLoad = function (rootUrl, scene, onfinish, files, onError) {
         if (onError === void 0) { onError = null; }
         if (onError === void 0) { onError = null; }
@@ -7459,6 +7465,7 @@ var BABYLON;
             this._deterministicLockstep = false;
             this._deterministicLockstep = false;
             this._lockstepMaxSteps = 4;
             this._lockstepMaxSteps = 4;
             this._contextWasLost = false;
             this._contextWasLost = false;
+            this._doNotHandleContextLost = false;
             // FPS
             // FPS
             this._performanceMonitor = new BABYLON.PerformanceMonitor();
             this._performanceMonitor = new BABYLON.PerformanceMonitor();
             this._fps = 60;
             this._fps = 60;
@@ -7475,7 +7482,7 @@ var BABYLON;
             // Cache
             // Cache
             this._internalTexturesCache = new Array();
             this._internalTexturesCache = new Array();
             this._maxTextureChannels = 16;
             this._maxTextureChannels = 16;
-            this._activeTexturesCache = new Array(this._maxTextureChannels);
+            this._activeTexturesCache = {};
             this._compiledEffects = {};
             this._compiledEffects = {};
             this._vertexAttribArraysEnabled = [];
             this._vertexAttribArraysEnabled = [];
             this._uintIndicesCurrentlySet = false;
             this._uintIndicesCurrentlySet = false;
@@ -7532,6 +7539,7 @@ var BABYLON;
                 }
                 }
                 this._deterministicLockstep = options.deterministicLockstep;
                 this._deterministicLockstep = options.deterministicLockstep;
                 this._lockstepMaxSteps = options.lockstepMaxSteps;
                 this._lockstepMaxSteps = options.lockstepMaxSteps;
+                this._doNotHandleContextLost = options.doNotHandleContextLost;
                 // GL
                 // GL
                 if (!options.disableWebGL2Support) {
                 if (!options.disableWebGL2Support) {
                     try {
                     try {
@@ -7586,29 +7594,31 @@ var BABYLON;
                 options.stencil = this._gl.getContextAttributes().stencil;
                 options.stencil = this._gl.getContextAttributes().stencil;
             }
             }
             // Context lost
             // Context lost
-            this._onContextLost = function (evt) {
-                evt.preventDefault();
-                _this._contextWasLost = true;
-                BABYLON.Tools.Warn("WebGL context lost.");
-            };
-            this._onContextRestored = function (evt) {
-                _this._contextWasLost = false;
-                // Rebuild gl context
-                _this._initGLContext();
-                // Rebuild effects
-                _this._rebuildEffects();
-                // Rebuild textures
-                _this._rebuildInternalTextures();
-                // Rebuild buffers
-                _this._rebuildBuffers();
-                // Cache
-                _this.wipeCaches(true);
-                // Restart render loop
-                _this._renderLoop();
-                BABYLON.Tools.Warn("WebGL context successfully restored.");
-            };
-            canvas.addEventListener("webglcontextlost", this._onContextLost, false);
-            canvas.addEventListener("webglcontextrestored", this._onContextRestored, false);
+            if (!this._doNotHandleContextLost) {
+                this._onContextLost = function (evt) {
+                    evt.preventDefault();
+                    _this._contextWasLost = true;
+                    BABYLON.Tools.Warn("WebGL context lost.");
+                };
+                this._onContextRestored = function (evt) {
+                    _this._contextWasLost = false;
+                    // Rebuild gl context
+                    _this._initGLContext();
+                    // Rebuild effects
+                    _this._rebuildEffects();
+                    // Rebuild textures
+                    _this._rebuildInternalTextures();
+                    // Rebuild buffers
+                    _this._rebuildBuffers();
+                    // Cache
+                    _this.wipeCaches(true);
+                    // Restart render loop
+                    _this._renderLoop();
+                    BABYLON.Tools.Warn("WebGL context successfully restored.");
+                };
+                canvas.addEventListener("webglcontextlost", this._onContextLost, false);
+                canvas.addEventListener("webglcontextrestored", this._onContextRestored, false);
+            }
             // Viewport
             // Viewport
             var limitDeviceRatio = options.limitDeviceRatio || window.devicePixelRatio || 1.0;
             var limitDeviceRatio = options.limitDeviceRatio || window.devicePixelRatio || 1.0;
             this._hardwareScalingLevel = adaptToDeviceRatio ? 1.0 / Math.min(limitDeviceRatio, window.devicePixelRatio || 1.0) : 1.0;
             this._hardwareScalingLevel = adaptToDeviceRatio ? 1.0 / Math.min(limitDeviceRatio, window.devicePixelRatio || 1.0) : 1.0;
@@ -7656,6 +7666,14 @@ var BABYLON;
                 document.addEventListener("mspointerlockchange", this._onPointerLockChange, false);
                 document.addEventListener("mspointerlockchange", this._onPointerLockChange, false);
                 document.addEventListener("mozpointerlockchange", this._onPointerLockChange, false);
                 document.addEventListener("mozpointerlockchange", this._onPointerLockChange, false);
                 document.addEventListener("webkitpointerlockchange", this._onPointerLockChange, false);
                 document.addEventListener("webkitpointerlockchange", this._onPointerLockChange, false);
+                this._onVRDisplayPointerRestricted = function () {
+                    canvas.requestPointerLock();
+                };
+                this._onVRDisplayPointerUnrestricted = function () {
+                    document.exitPointerLock();
+                };
+                window.addEventListener('vrdisplaypointerrestricted', this._onVRDisplayPointerRestricted, false);
+                window.addEventListener('vrdisplaypointerunrestricted', this._onVRDisplayPointerUnrestricted, false);
             }
             }
             if (options.audioEngine && BABYLON.AudioEngine && !Engine.audioEngine) {
             if (options.audioEngine && BABYLON.AudioEngine && !Engine.audioEngine) {
                 Engine.audioEngine = new BABYLON.AudioEngine();
                 Engine.audioEngine = new BABYLON.AudioEngine();
@@ -8070,8 +8088,9 @@ var BABYLON;
             configurable: true
             configurable: true
         });
         });
         Engine.prototype._rebuildInternalTextures = function () {
         Engine.prototype._rebuildInternalTextures = function () {
-            for (var _i = 0, _a = this._internalTexturesCache; _i < _a.length; _i++) {
-                var internalTexture = _a[_i];
+            var currentState = this._internalTexturesCache.slice(); // Do a copy because the rebuild will add proxies
+            for (var _i = 0, currentState_1 = currentState; _i < currentState_1.length; _i++) {
+                var internalTexture = currentState_1[_i];
                 internalTexture._rebuild();
                 internalTexture._rebuild();
             }
             }
         };
         };
@@ -8233,8 +8252,8 @@ var BABYLON;
             this._workingContext = this._workingCanvas.getContext("2d");
             this._workingContext = this._workingCanvas.getContext("2d");
         };
         };
         Engine.prototype.resetTextureCache = function () {
         Engine.prototype.resetTextureCache = function () {
-            for (var index = 0; index < this._maxTextureChannels; index++) {
-                this._activeTexturesCache[index] = null;
+            for (var key in this._activeTexturesCache) {
+                this._activeTexturesCache[key] = null;
             }
             }
         };
         };
         Engine.prototype.isDeterministicLockStep = function () {
         Engine.prototype.isDeterministicLockStep = function () {
@@ -9521,10 +9540,11 @@ var BABYLON;
             if (onLoad === void 0) { onLoad = null; }
             if (onLoad === void 0) { onLoad = null; }
             if (onError === void 0) { onError = null; }
             if (onError === void 0) { onError = null; }
             if (buffer === void 0) { buffer = null; }
             if (buffer === void 0) { buffer = null; }
-            var texture = fallBack ? fallBack : new BABYLON.InternalTexture(this, BABYLON.InternalTexture.DATASOURCE_URL);
             var url = String(urlArg); // assign a new string, so that the original is still available in case of fallback
             var url = String(urlArg); // assign a new string, so that the original is still available in case of fallback
             var fromData = url.substr(0, 5) === "data:";
             var fromData = url.substr(0, 5) === "data:";
+            var fromBlob = url.substr(0, 5) === "blob:";
             var isBase64 = fromData && url.indexOf("base64") !== -1;
             var isBase64 = fromData && url.indexOf("base64") !== -1;
+            var texture = fallBack ? fallBack : new BABYLON.InternalTexture(this, BABYLON.InternalTexture.DATASOURCE_URL);
             // establish the file extension, if possible
             // establish the file extension, if possible
             var lastDot = url.lastIndexOf('.');
             var lastDot = url.lastIndexOf('.');
             var extension = (lastDot > 0) ? url.substring(lastDot).toLowerCase() : "";
             var extension = (lastDot > 0) ? url.substring(lastDot).toLowerCase() : "";
@@ -9536,18 +9556,26 @@ var BABYLON;
                 url = url.substring(0, lastDot) + this._textureFormatInUse;
                 url = url.substring(0, lastDot) + this._textureFormatInUse;
                 isKTX = true;
                 isKTX = true;
             }
             }
-            scene._addPendingData(texture);
+            if (scene) {
+                scene._addPendingData(texture);
+            }
             texture.url = url;
             texture.url = url;
             texture.generateMipMaps = !noMipmap;
             texture.generateMipMaps = !noMipmap;
             texture.samplingMode = samplingMode;
             texture.samplingMode = samplingMode;
             texture.invertY = invertY;
             texture.invertY = invertY;
+            if (!this._doNotHandleContextLost) {
+                // Keep a link to the buffer only if we plan to handle context lost
+                texture._buffer = buffer;
+            }
             if (onLoad) {
             if (onLoad) {
                 texture.onLoadedObservable.add(onLoad);
                 texture.onLoadedObservable.add(onLoad);
             }
             }
             if (!fallBack)
             if (!fallBack)
                 this._internalTexturesCache.push(texture);
                 this._internalTexturesCache.push(texture);
             var onerror = function () {
             var onerror = function () {
-                scene._removePendingData(texture);
+                if (scene) {
+                    scene._removePendingData(texture);
+                }
                 // fallback for when compressed file not found to try again.  For instance, etc1 does not have an alpha capable type
                 // fallback for when compressed file not found to try again.  For instance, etc1 does not have an alpha capable type
                 if (isKTX) {
                 if (isKTX) {
                     _this.createTexture(urlArg, noMipmap, invertY, scene, samplingMode, null, onError, buffer, texture);
                     _this.createTexture(urlArg, noMipmap, invertY, scene, samplingMode, null, onError, buffer, texture);
@@ -9591,7 +9619,7 @@ var BABYLON;
                 if (!buffer) {
                 if (!buffer) {
                     BABYLON.Tools.LoadFile(url, function (data) {
                     BABYLON.Tools.LoadFile(url, function (data) {
                         callback(data);
                         callback(data);
-                    }, null, scene.database, true, onerror);
+                    }, null, scene ? scene.database : null, true, onerror);
                 }
                 }
                 else {
                 else {
                     callback(buffer);
                     callback(buffer);
@@ -9600,6 +9628,11 @@ var BABYLON;
             }
             }
             else {
             else {
                 var onload = function (img) {
                 var onload = function (img) {
+                    if (fromBlob && !_this._doNotHandleContextLost) {
+                        // We need to store the image if we need to rebuild the texture
+                        // in case of a webgl context lost
+                        texture._buffer = img;
+                    }
                     _this._prepareWebGLTexture(texture, scene, img.width, img.height, invertY, noMipmap, false, function (potWidth, potHeight, continuationCallback) {
                     _this._prepareWebGLTexture(texture, scene, img.width, img.height, invertY, noMipmap, false, function (potWidth, potHeight, continuationCallback) {
                         var gl = _this._gl;
                         var gl = _this._gl;
                         var isPot = (img.width === potWidth && img.height === potHeight);
                         var isPot = (img.width === potWidth && img.height === potHeight);
@@ -9625,9 +9658,14 @@ var BABYLON;
                     }, samplingMode);
                     }, samplingMode);
                 };
                 };
                 if (!fromData || isBase64)
                 if (!fromData || isBase64)
-                    BABYLON.Tools.LoadImage(url, onload, onerror, scene.database);
+                    if (buffer instanceof HTMLImageElement) {
+                        onload(buffer);
+                    }
+                    else {
+                        BABYLON.Tools.LoadImage(url, onload, onerror, scene ? scene.database : null);
+                    }
                 else if (buffer instanceof Array || typeof buffer === "string")
                 else if (buffer instanceof Array || typeof buffer === "string")
-                    BABYLON.Tools.LoadImage(buffer, onload, onerror, scene.database);
+                    BABYLON.Tools.LoadImage(buffer, onload, onerror, scene ? scene.database : null);
                 else
                 else
                     onload(buffer);
                     onload(buffer);
             }
             }
@@ -10127,10 +10165,20 @@ var BABYLON;
             if (onError === void 0) { onError = null; }
             if (onError === void 0) { onError = null; }
             if (forcedExtension === void 0) { forcedExtension = null; }
             if (forcedExtension === void 0) { forcedExtension = null; }
             var callback = function (loadData) {
             var callback = function (loadData) {
-                if (_this._caps.textureLOD || !loadData) {
+                if (!loadData) {
+                    if (onLoad) {
+                        onLoad(null);
+                    }
+                    return;
+                }
+                var texture = loadData.texture;
+                texture._dataSource = BABYLON.InternalTexture.DATASOURCE_CUBEPREFILTERED;
+                texture._lodGenerationScale = scale;
+                texture._lodGenerationOffset = offset;
+                if (_this._caps.textureLOD) {
                     // Do not add extra process if texture lod is supported.
                     // Do not add extra process if texture lod is supported.
                     if (onLoad) {
                     if (onLoad) {
-                        onLoad();
+                        onLoad(texture);
                     }
                     }
                     return;
                     return;
                 }
                 }
@@ -10149,7 +10197,7 @@ var BABYLON;
                     var maxLODIndex = BABYLON.Scalar.Log2(width) * scale + offset; // roughness = 1
                     var maxLODIndex = BABYLON.Scalar.Log2(width) * scale + offset; // roughness = 1
                     var lodIndex = minLODIndex + (maxLODIndex - minLODIndex) * roughness;
                     var lodIndex = minLODIndex + (maxLODIndex - minLODIndex) * roughness;
                     var mipmapIndex = Math.round(Math.min(Math.max(lodIndex, 0), maxLODIndex));
                     var mipmapIndex = Math.round(Math.min(Math.max(lodIndex, 0), maxLODIndex));
-                    var glTextureFromLod = new BABYLON.InternalTexture(_this, BABYLON.InternalTexture.DATASOURCE_CUBELOD);
+                    var glTextureFromLod = new BABYLON.InternalTexture(_this, BABYLON.InternalTexture.DATASOURCE_TEMP);
                     glTextureFromLod.isCube = true;
                     glTextureFromLod.isCube = true;
                     _this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, glTextureFromLod);
                     _this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, glTextureFromLod);
                     gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
                     gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
@@ -10173,11 +10221,11 @@ var BABYLON;
                     glTextureFromLod.isReady = true;
                     glTextureFromLod.isReady = true;
                     textures.push(lodTexture);
                     textures.push(lodTexture);
                 }
                 }
-                loadData.texture._lodTextureHigh = textures[2];
-                loadData.texture._lodTextureMid = textures[1];
-                loadData.texture._lodTextureLow = textures[0];
+                texture._lodTextureHigh = textures[2];
+                texture._lodTextureMid = textures[1];
+                texture._lodTextureLow = textures[0];
                 if (onLoad) {
                 if (onLoad) {
-                    onLoad();
+                    onLoad(texture);
                 }
                 }
             };
             };
             return this.createCubeTexture(rootUrl, scene, null, false, callback, onError, format, forcedExtension);
             return this.createCubeTexture(rootUrl, scene, null, false, callback, onError, format, forcedExtension);
@@ -10192,6 +10240,10 @@ var BABYLON;
             texture.isCube = true;
             texture.isCube = true;
             texture.url = rootUrl;
             texture.url = rootUrl;
             texture.generateMipMaps = !noMipmap;
             texture.generateMipMaps = !noMipmap;
+            if (!this._doNotHandleContextLost) {
+                texture._extension = forcedExtension;
+                texture._files = files;
+            }
             var isKTX = false;
             var isKTX = false;
             var isDDS = false;
             var isDDS = false;
             var lastDot = rootUrl.lastIndexOf('.');
             var lastDot = rootUrl.lastIndexOf('.');
@@ -10277,6 +10329,7 @@ var BABYLON;
                     texture.width = width;
                     texture.width = width;
                     texture.height = height;
                     texture.height = height;
                     texture.isReady = true;
                     texture.isReady = true;
+                    texture.format = format;
                     texture.onLoadedObservable.notifyObservers(texture);
                     texture.onLoadedObservable.notifyObservers(texture);
                     texture.onLoadedObservable.clear();
                     texture.onLoadedObservable.clear();
                     if (onLoad) {
                     if (onLoad) {
@@ -10452,7 +10505,9 @@ var BABYLON;
             }
             }
             this._bindTextureDirectly(gl.TEXTURE_2D, null);
             this._bindTextureDirectly(gl.TEXTURE_2D, null);
             this.resetTextureCache();
             this.resetTextureCache();
-            scene._removePendingData(texture);
+            if (scene) {
+                scene._removePendingData(texture);
+            }
             texture.onLoadedObservable.notifyObservers(texture);
             texture.onLoadedObservable.notifyObservers(texture);
             texture.onLoadedObservable.clear();
             texture.onLoadedObservable.clear();
         };
         };
@@ -10693,9 +10748,9 @@ var BABYLON;
             if (internalTexture.samplingMode === BABYLON.Texture.NEAREST_SAMPLINGMODE) {
             if (internalTexture.samplingMode === BABYLON.Texture.NEAREST_SAMPLINGMODE) {
                 value = 1;
                 value = 1;
             }
             }
-            if (anisotropicFilterExtension && texture._cachedAnisotropicFilteringLevel !== value) {
+            if (anisotropicFilterExtension && internalTexture._cachedAnisotropicFilteringLevel !== value) {
                 this._gl.texParameterf(key, anisotropicFilterExtension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(value, this._caps.maxAnisotropy));
                 this._gl.texParameterf(key, anisotropicFilterExtension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(value, this._caps.maxAnisotropy));
-                texture._cachedAnisotropicFilteringLevel = value;
+                internalTexture._cachedAnisotropicFilteringLevel = value;
             }
             }
         };
         };
         Engine.prototype.readPixels = function (x, y, width, height) {
         Engine.prototype.readPixels = function (x, y, width, height) {
@@ -10814,9 +10869,13 @@ var BABYLON;
             // Events
             // Events
             window.removeEventListener("blur", this._onBlur);
             window.removeEventListener("blur", this._onBlur);
             window.removeEventListener("focus", this._onFocus);
             window.removeEventListener("focus", this._onFocus);
+            window.removeEventListener('vrdisplaypointerrestricted', this._onVRDisplayPointerRestricted);
+            window.removeEventListener('vrdisplaypointerunrestricted', this._onVRDisplayPointerUnrestricted);
             this._renderingCanvas.removeEventListener("pointerout", this._onCanvasBlur);
             this._renderingCanvas.removeEventListener("pointerout", this._onCanvasBlur);
-            this._renderingCanvas.removeEventListener("webglcontextlost", this._onContextLost);
-            this._renderingCanvas.removeEventListener("webglcontextrestored", this._onContextRestored);
+            if (!this._doNotHandleContextLost) {
+                this._renderingCanvas.removeEventListener("webglcontextlost", this._onContextLost);
+                this._renderingCanvas.removeEventListener("webglcontextrestored", this._onContextRestored);
+            }
             document.removeEventListener("fullscreenchange", this._onFullscreenChange);
             document.removeEventListener("fullscreenchange", this._onFullscreenChange);
             document.removeEventListener("mozfullscreenchange", this._onFullscreenChange);
             document.removeEventListener("mozfullscreenchange", this._onFullscreenChange);
             document.removeEventListener("webkitfullscreenchange", this._onFullscreenChange);
             document.removeEventListener("webkitfullscreenchange", this._onFullscreenChange);
@@ -11870,7 +11929,7 @@ var BABYLON;
     
     
             * OCCLUSION_TYPE_NONE (Default Value): this option means no occlusion query whith the Mesh.
             * OCCLUSION_TYPE_NONE (Default Value): this option means no occlusion query whith the Mesh.
     
     
-            * OCCLUSION_TYPE_OPTIMISITC: this option is means use occlusion query and if occlusionRetryCount is reached and the query is broken show the mesh.
+            * OCCLUSION_TYPE_OPTIMISTIC: this option is means use occlusion query and if occlusionRetryCount is reached and the query is broken show the mesh.
     
     
                 * OCCLUSION_TYPE_STRICT: this option is means use occlusion query and if occlusionRetryCount is reached and the query is broken restore the last state of the mesh occlusion if the mesh was visible then show the mesh if was hidden then hide don't show.
                 * OCCLUSION_TYPE_STRICT: this option is means use occlusion query and if occlusionRetryCount is reached and the query is broken restore the last state of the mesh occlusion if the mesh was visible then show the mesh if was hidden then hide don't show.
              */
              */
@@ -12282,6 +12341,15 @@ var BABYLON;
             }
             }
             return ret;
             return ret;
         };
         };
+        AbstractMesh.prototype._rebuild = function () {
+            if (!this.subMeshes) {
+                return;
+            }
+            for (var _i = 0, _a = this.subMeshes; _i < _a.length; _i++) {
+                var subMesh = _a[_i];
+                subMesh._rebuild();
+            }
+        };
         AbstractMesh.prototype._resyncLightSources = function () {
         AbstractMesh.prototype._resyncLightSources = function () {
             this._lightSources.length = 0;
             this._lightSources.length = 0;
             for (var _i = 0, _a = this.getScene().lights; _i < _a.length; _i++) {
             for (var _i = 0, _a = this.getScene().lights; _i < _a.length; _i++) {
@@ -13956,7 +14024,7 @@ var BABYLON;
                         this._occlusionInternalRetryCounter = 0;
                         this._occlusionInternalRetryCounter = 0;
                         // if optimistic set isOccluded to false regardless of the status of isOccluded. (Render in the current render loop)
                         // if optimistic set isOccluded to false regardless of the status of isOccluded. (Render in the current render loop)
                         // if strict continue the last state of the object.
                         // if strict continue the last state of the object.
-                        this._isOccluded = this.occlusionType === AbstractMesh.OCCLUSION_TYPE_OPTIMISITC ? false : this._isOccluded;
+                        this._isOccluded = this.occlusionType === AbstractMesh.OCCLUSION_TYPE_OPTIMISTIC ? false : this._isOccluded;
                     }
                     }
                     else {
                     else {
                         return;
                         return;
@@ -13980,7 +14048,7 @@ var BABYLON;
         AbstractMesh._BILLBOARDMODE_Z = 4;
         AbstractMesh._BILLBOARDMODE_Z = 4;
         AbstractMesh._BILLBOARDMODE_ALL = 7;
         AbstractMesh._BILLBOARDMODE_ALL = 7;
         AbstractMesh.OCCLUSION_TYPE_NONE = 0;
         AbstractMesh.OCCLUSION_TYPE_NONE = 0;
-        AbstractMesh.OCCLUSION_TYPE_OPTIMISITC = 1;
+        AbstractMesh.OCCLUSION_TYPE_OPTIMISTIC = 1;
         AbstractMesh.OCCLUSION_TYPE_STRICT = 2;
         AbstractMesh.OCCLUSION_TYPE_STRICT = 2;
         AbstractMesh.OCCLUSION_ALGORITHM_TYPE_ACCURATE = 0;
         AbstractMesh.OCCLUSION_ALGORITHM_TYPE_ACCURATE = 0;
         AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE = 1;
         AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE = 1;
@@ -19296,12 +19364,21 @@ var BABYLON;
                 var geometry = _a[_i];
                 var geometry = _a[_i];
                 geometry._rebuild();
                 geometry._rebuild();
             }
             }
+            for (var _b = 0, _c = this.meshes; _b < _c.length; _b++) {
+                var mesh = _c[_b];
+                mesh._rebuild();
+            }
+            for (var _d = 0, _e = this.layers; _d < _e.length; _d++) {
+                var layer = _e[_d];
+                layer._rebuild();
+            }
         };
         };
         Scene.prototype._rebuildTextures = function () {
         Scene.prototype._rebuildTextures = function () {
             for (var _i = 0, _a = this.textures; _i < _a.length; _i++) {
             for (var _i = 0, _a = this.textures; _i < _a.length; _i++) {
                 var texture = _a[_i];
                 var texture = _a[_i];
                 texture._rebuild();
                 texture._rebuild();
             }
             }
+            this.markAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
         };
         };
         Scene.prototype.createDefaultCameraOrLight = function (createArcRotateCamera, replace, attachCameraControls) {
         Scene.prototype.createDefaultCameraOrLight = function (createArcRotateCamera, replace, attachCameraControls) {
             if (createArcRotateCamera === void 0) { createArcRotateCamera = false; }
             if (createArcRotateCamera === void 0) { createArcRotateCamera = false; }
@@ -19878,7 +19955,66 @@ var BABYLON;
             this.baseHeight = height;
             this.baseHeight = height;
         };
         };
         InternalTexture.prototype._rebuild = function () {
         InternalTexture.prototype._rebuild = function () {
-            // this._engine.createTexture(this.url, !this.generateMipMaps, this.invertY, scene, this.samplingMode, null, null, this._buffer, null, this._format);
+            var _this = this;
+            var proxy;
+            this.isReady = false;
+            this._cachedCoordinatesMode = null;
+            this._cachedWrapU = null;
+            this._cachedWrapV = null;
+            this._cachedAnisotropicFilteringLevel = null;
+            switch (this._dataSource) {
+                case InternalTexture.DATASOURCE_TEMP:
+                    return;
+                case InternalTexture.DATASOURCE_URL:
+                    proxy = this._engine.createTexture(this.url, !this.generateMipMaps, this.invertY, null, this.samplingMode, function () {
+                        _this.isReady = true;
+                    }, null, this._buffer, null, this.format);
+                    proxy._swapAndDie(this);
+                    return;
+                case InternalTexture.DATASOURCE_DYNAMIC:
+                    proxy = this._engine.createDynamicTexture(this.baseWidth, this.baseHeight, this.generateMipMaps, this.samplingMode);
+                    proxy._swapAndDie(this);
+                    // The engine will make sure to update content so no need to flag it as isReady = true
+                    return;
+                case InternalTexture.DATASOURCE_CUBE:
+                    proxy = this._engine.createCubeTexture(this.url, null, this._files, !this.generateMipMaps, function () {
+                        _this.isReady = true;
+                    }, null, this.format, this._extension);
+                    proxy._swapAndDie(this);
+                    return;
+                case InternalTexture.DATASOURCE_CUBEPREFILTERED:
+                    proxy = this._engine.createPrefilteredCubeTexture(this.url, null, this._lodGenerationScale, this._lodGenerationOffset, function (proxy) {
+                        proxy._swapAndDie(_this);
+                        _this.isReady = true;
+                    }, null, this.format, this._extension);
+                    return;
+            }
+        };
+        InternalTexture.prototype._swapAndDie = function (target) {
+            target._webGLTexture = this._webGLTexture;
+            if (this._lodTextureHigh) {
+                if (target._lodTextureHigh) {
+                    target._lodTextureHigh.dispose();
+                }
+                target._lodTextureHigh = this._lodTextureHigh;
+            }
+            if (this._lodTextureMid) {
+                if (target._lodTextureMid) {
+                    target._lodTextureMid.dispose();
+                }
+                target._lodTextureMid = this._lodTextureMid;
+            }
+            if (this._lodTextureLow) {
+                if (target._lodTextureLow) {
+                    target._lodTextureLow.dispose();
+                }
+                target._lodTextureLow = this._lodTextureLow;
+            }
+            var cache = this._engine.getLoadedTexturesCache();
+            var index = cache.indexOf(this);
+            if (index !== -1) {
+                cache.splice(index, 1);
+            }
         };
         };
         InternalTexture.prototype.dispose = function () {
         InternalTexture.prototype.dispose = function () {
             if (!this._webGLTexture) {
             if (!this._webGLTexture) {
@@ -19898,8 +20034,8 @@ var BABYLON;
         InternalTexture.DATASOURCE_RENDERTARGET = 5;
         InternalTexture.DATASOURCE_RENDERTARGET = 5;
         InternalTexture.DATASOURCE_MULTIRENDERTARGET = 6;
         InternalTexture.DATASOURCE_MULTIRENDERTARGET = 6;
         InternalTexture.DATASOURCE_CUBE = 7;
         InternalTexture.DATASOURCE_CUBE = 7;
-        InternalTexture.DATASOURCE_CUBELOD = 8;
-        InternalTexture.DATASOURCE_CUBERAW = 9;
+        InternalTexture.DATASOURCE_CUBERAW = 8;
+        InternalTexture.DATASOURCE_CUBEPREFILTERED = 9;
         return InternalTexture;
         return InternalTexture;
     }());
     }());
     BABYLON.InternalTexture = InternalTexture;
     BABYLON.InternalTexture = InternalTexture;
@@ -23722,6 +23858,11 @@ var BABYLON;
             }
             }
             return intersectInfo;
             return intersectInfo;
         };
         };
+        SubMesh.prototype._rebuild = function () {
+            if (this._linesIndexBuffer) {
+                this._linesIndexBuffer = null;
+            }
+        };
         // Clone    
         // Clone    
         /**
         /**
          * Creates a new Submesh from the passed Mesh.
          * Creates a new Submesh from the passed Mesh.
@@ -40601,23 +40742,7 @@ var BABYLON;
             this._scene = scene || BABYLON.Engine.LastCreatedScene;
             this._scene = scene || BABYLON.Engine.LastCreatedScene;
             this._scene.layers.push(this);
             this._scene.layers.push(this);
             var engine = this._scene.getEngine();
             var engine = this._scene.getEngine();
-            // VBO
-            var vertices = [];
-            vertices.push(1, 1);
-            vertices.push(-1, 1);
-            vertices.push(-1, -1);
-            vertices.push(1, -1);
-            var vertexBuffer = new BABYLON.VertexBuffer(engine, vertices, BABYLON.VertexBuffer.PositionKind, false, false, 2);
-            this._vertexBuffers[BABYLON.VertexBuffer.PositionKind] = vertexBuffer;
-            // Indices
-            var indices = [];
-            indices.push(0);
-            indices.push(1);
-            indices.push(2);
-            indices.push(0);
-            indices.push(2);
-            indices.push(3);
-            this._indexBuffer = engine.createIndexBuffer(indices);
+            this._rebuild();
             // Effects
             // Effects
             this._effect = engine.createEffect("layer", [BABYLON.VertexBuffer.PositionKind], ["textureMatrix", "color", "scale", "offset"], ["textureSampler"], "");
             this._effect = engine.createEffect("layer", [BABYLON.VertexBuffer.PositionKind], ["textureMatrix", "color", "scale", "offset"], ["textureSampler"], "");
             this._alphaTestEffect = engine.createEffect("layer", [BABYLON.VertexBuffer.PositionKind], ["textureMatrix", "color", "scale", "offset"], ["textureSampler"], "#define ALPHATEST");
             this._alphaTestEffect = engine.createEffect("layer", [BABYLON.VertexBuffer.PositionKind], ["textureMatrix", "color", "scale", "offset"], ["textureSampler"], "#define ALPHATEST");
@@ -40652,6 +40777,26 @@ var BABYLON;
             enumerable: true,
             enumerable: true,
             configurable: true
             configurable: true
         });
         });
+        Layer.prototype._rebuild = function () {
+            var engine = this._scene.getEngine();
+            // VBO
+            var vertices = [];
+            vertices.push(1, 1);
+            vertices.push(-1, 1);
+            vertices.push(-1, -1);
+            vertices.push(1, -1);
+            var vertexBuffer = new BABYLON.VertexBuffer(engine, vertices, BABYLON.VertexBuffer.PositionKind, false, false, 2);
+            this._vertexBuffers[BABYLON.VertexBuffer.PositionKind] = vertexBuffer;
+            // Indices
+            var indices = [];
+            indices.push(0);
+            indices.push(1);
+            indices.push(2);
+            indices.push(0);
+            indices.push(2);
+            indices.push(3);
+            this._indexBuffer = engine.createIndexBuffer(indices);
+        };
         Layer.prototype.render = function () {
         Layer.prototype.render = function () {
             var currentEffect = this.alphaTest ? this._alphaTestEffect : this._effect;
             var currentEffect = this.alphaTest ? this._alphaTestEffect : this._effect;
             // Check
             // Check

ファイルの差分が大きいため隠しています
+ 8073 - 8059
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.module.d.ts