David Catuhe vor 7 Jahren
Ursprung
Commit
2c0fa24469

Datei-Diff unterdrückt, da er zu groß ist
+ 645 - 645
dist/preview release/babylon.d.ts


Datei-Diff unterdrückt, da er zu groß ist
+ 16 - 16
dist/preview release/babylon.js


+ 99 - 34
dist/preview release/babylon.max.js

@@ -49640,6 +49640,7 @@ var BABYLON;
     var PostProcess = /** @class */ (function () {
         function PostProcess(name, fragmentUrl, parameters, samplers, options, camera, samplingMode, engine, reusable, defines, textureType, vertexUrl, indexParameters, blockCompilation) {
             if (samplingMode === void 0) { samplingMode = BABYLON.Texture.NEAREST_SAMPLINGMODE; }
+            if (defines === void 0) { defines = null; }
             if (textureType === void 0) { textureType = BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT; }
             if (vertexUrl === void 0) { vertexUrl = "postprocess"; }
             if (blockCompilation === void 0) { blockCompilation = false; }
@@ -49802,7 +49803,10 @@ var BABYLON;
             return this;
         };
         PostProcess.prototype.updateEffect = function (defines, uniforms, samplers, indexParameters, onCompiled, onError) {
-            this._effect = this._engine.createEffect({ vertex: this._vertexUrl, fragment: this._fragmentUrl }, ["position"], uniforms || this._parameters, samplers || this._samplers, defines !== undefined ? defines : "", undefined, onCompiled, onError, indexParameters || this._indexParameters);
+            if (defines === void 0) { defines = null; }
+            if (uniforms === void 0) { uniforms = null; }
+            if (samplers === void 0) { samplers = null; }
+            this._effect = this._engine.createEffect({ vertex: this._vertexUrl, fragment: this._fragmentUrl }, ["position"], uniforms || this._parameters, samplers || this._samplers, defines !== null ? defines : "", undefined, onCompiled, onError, indexParameters || this._indexParameters);
         };
         PostProcess.prototype.isReusable = function () {
             return this._reusable;
@@ -51113,7 +51117,9 @@ var BABYLON;
             };
             var manifestChecked = function (success) {
                 BABYLON.Tools.LoadFile(rootUrl + sceneFilename, dataCallback, onProgress, database, useArrayBuffer, function (request) {
-                    onError(request.status + " " + request.statusText);
+                    if (request) {
+                        onError(request.status + " " + request.statusText);
+                    }
                 });
             };
             if (directLoad) {
@@ -51176,6 +51182,9 @@ var BABYLON;
         * @param onError a callback with the scene, a message, and possibly an exception when import fails
         */
         SceneLoader.ImportMesh = function (meshNames, rootUrl, sceneFilename, scene, onSuccess, onProgress, onError) {
+            if (onSuccess === void 0) { onSuccess = null; }
+            if (onProgress === void 0) { onProgress = null; }
+            if (onError === void 0) { onError = null; }
             if (sceneFilename.substr && sceneFilename.substr(0, 1) === "/") {
                 BABYLON.Tools.Error("Wrong sceneFilename parameter");
                 return;
@@ -54077,8 +54086,12 @@ var BABYLON;
         };
         GamepadManager.prototype.dispose = function () {
             if (this._gamepadEventSupported) {
-                window.removeEventListener('gamepadconnected', this._onGamepadConnectedEvent);
-                window.removeEventListener('gamepaddisconnected', this._onGamepadDisconnectedEvent);
+                if (this._onGamepadConnectedEvent) {
+                    window.removeEventListener('gamepadconnected', this._onGamepadConnectedEvent);
+                }
+                if (this._onGamepadDisconnectedEvent) {
+                    window.removeEventListener('gamepaddisconnected', this._onGamepadDisconnectedEvent);
+                }
                 this._onGamepadConnectedEvent = null;
                 this._onGamepadDisconnectedEvent = null;
             }
@@ -54681,8 +54694,9 @@ var BABYLON;
                     this.devicePosition.scaleToRef(this.deviceScaleFactor, this._calculatedPosition);
                     this._calculatedPosition.addInPlace(this.position);
                 }
-                if (poseData.orientation) {
-                    this.deviceRotationQuaternion.copyFromFloats(this.rawPose.orientation[0], this.rawPose.orientation[1], -this.rawPose.orientation[2], -this.rawPose.orientation[3]);
+                var pose = this.rawPose;
+                if (poseData.orientation && pose.orientation) {
+                    this.deviceRotationQuaternion.copyFromFloats(pose.orientation[0], pose.orientation[1], -pose.orientation[2], -pose.orientation[3]);
                     if (this._mesh) {
                         if (this._mesh.getScene().useRightHandedSystem) {
                             this.deviceRotationQuaternion.z *= -1;
@@ -54699,7 +54713,7 @@ var BABYLON;
         };
         PoseEnabledController.prototype.attachToMesh = function (mesh) {
             if (this._mesh) {
-                this._mesh.parent = undefined;
+                this._mesh.parent = null;
             }
             this._mesh = mesh;
             if (this._poseControlledCamera) {
@@ -54719,7 +54733,7 @@ var BABYLON;
             if (this._mesh) {
                 this._mesh.dispose();
             }
-            this._mesh = undefined;
+            this._mesh = null;
             _super.prototype.dispose.call(this);
         };
         Object.defineProperty(PoseEnabledController.prototype, "mesh", {
@@ -55253,6 +55267,9 @@ var BABYLON;
             BABYLON.Vector3.LerpToRef(meshInfo.unpressed.position, meshInfo.pressed.position, buttonValue, meshInfo.value.position);
         };
         WindowsMotionController.prototype.lerpAxisTransform = function (axis, axisValue) {
+            if (!this._loadedMeshInfo) {
+                return;
+            }
             var meshInfo = this._loadedMeshInfo.axisMeshes[axis];
             if (!meshInfo) {
                 return;
@@ -71376,7 +71393,8 @@ var BABYLON;
                 blurTextureSizeRatio: 0.5,
                 blurHorizontalSize: 1.0,
                 blurVerticalSize: 1.0,
-                alphaBlendingMode: BABYLON.Engine.ALPHA_COMBINE
+                alphaBlendingMode: BABYLON.Engine.ALPHA_COMBINE,
+                camera: null
             };
             this._options.mainTextureRatio = this._options.mainTextureRatio || 0.5;
             this._options.blurTextureSizeRatio = this._options.blurTextureSizeRatio || 1.0;
@@ -71454,7 +71472,10 @@ var BABYLON;
             this._indexBuffer = engine.createIndexBuffer(indices);
         };
         HighlightLayer.prototype._rebuild = function () {
-            this._vertexBuffers[BABYLON.VertexBuffer.PositionKind]._rebuild();
+            var vb = this._vertexBuffers[BABYLON.VertexBuffer.PositionKind];
+            if (vb) {
+                vb._rebuild();
+            }
             this._createIndexBuffer();
         };
         /**
@@ -71514,11 +71535,17 @@ var BABYLON;
             }
             this._mainTexture.onAfterUnbindObservable.add(function () {
                 _this.onBeforeBlurObservable.notifyObservers(_this);
-                _this._scene.postProcessManager.directRender([_this._downSamplePostprocess, _this._horizontalBlurPostprocess, _this._verticalBlurPostprocess], _this._blurTexture.getInternalTexture(), true);
+                var internalTexture = _this._blurTexture.getInternalTexture();
+                if (internalTexture) {
+                    _this._scene.postProcessManager.directRender([_this._downSamplePostprocess, _this._horizontalBlurPostprocess, _this._verticalBlurPostprocess], internalTexture, true);
+                }
                 _this.onAfterBlurObservable.notifyObservers(_this);
             });
             // Custom render function
             var renderSubMesh = function (subMesh) {
+                if (!_this._meshes) {
+                    return;
+                }
                 var mesh = subMesh.getRenderingMesh();
                 var scene = _this._scene;
                 var engine = scene.getEngine();
@@ -71530,7 +71557,7 @@ var BABYLON;
                     return;
                 }
                 // Excluded Mesh
-                if (_this._excludedMeshes[mesh.uniqueId]) {
+                if (_this._excludedMeshes && _this._excludedMeshes[mesh.uniqueId]) {
                     return;
                 }
                 ;
@@ -71556,7 +71583,10 @@ var BABYLON;
                         var alphaTexture = material.getAlphaTestTexture();
                         if (alphaTexture) {
                             _this._glowMapGenerationEffect.setTexture("diffuseSampler", alphaTexture);
-                            _this._glowMapGenerationEffect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
+                            var textureMatrix = alphaTexture.getTextureMatrix();
+                            if (textureMatrix) {
+                                _this._glowMapGenerationEffect.setMatrix("diffuseMatrix", textureMatrix);
+                            }
                         }
                     }
                     // Glow emissive only
@@ -71754,6 +71784,9 @@ var BABYLON;
          * @param mesh The mesh to exclude from the highlight layer
          */
         HighlightLayer.prototype.addExcludedMesh = function (mesh) {
+            if (!this._excludedMeshes) {
+                return;
+            }
             var meshExcluded = this._excludedMeshes[mesh.uniqueId];
             if (!meshExcluded) {
                 this._excludedMeshes[mesh.uniqueId] = {
@@ -71772,12 +71805,19 @@ var BABYLON;
           * @param mesh The mesh to highlight
           */
         HighlightLayer.prototype.removeExcludedMesh = function (mesh) {
+            if (!this._excludedMeshes) {
+                return;
+            }
             var meshExcluded = this._excludedMeshes[mesh.uniqueId];
             if (meshExcluded) {
-                mesh.onBeforeRenderObservable.remove(meshExcluded.beforeRender);
-                mesh.onAfterRenderObservable.remove(meshExcluded.afterRender);
+                if (meshExcluded.beforeRender) {
+                    mesh.onBeforeRenderObservable.remove(meshExcluded.beforeRender);
+                }
+                if (meshExcluded.afterRender) {
+                    mesh.onAfterRenderObservable.remove(meshExcluded.afterRender);
+                }
             }
-            this._excludedMeshes[mesh.uniqueId] = undefined;
+            this._excludedMeshes[mesh.uniqueId] = null;
         };
         /**
          * Add a mesh in the highlight layer in order to make it glow with the chosen color.
@@ -71788,6 +71828,9 @@ var BABYLON;
         HighlightLayer.prototype.addMesh = function (mesh, color, glowEmissiveOnly) {
             var _this = this;
             if (glowEmissiveOnly === void 0) { glowEmissiveOnly = false; }
+            if (!this._meshes) {
+                return;
+            }
             var meshHighlight = this._meshes[mesh.uniqueId];
             if (meshHighlight) {
                 meshHighlight.color = color;
@@ -71798,7 +71841,7 @@ var BABYLON;
                     color: color,
                     // Lambda required for capture due to Observable this context
                     observerHighlight: mesh.onBeforeRenderObservable.add(function (mesh) {
-                        if (_this._excludedMeshes[mesh.uniqueId]) {
+                        if (_this._excludedMeshes && _this._excludedMeshes[mesh.uniqueId]) {
                             _this.defaultStencilReference(mesh);
                         }
                         else {
@@ -71816,12 +71859,19 @@ var BABYLON;
          * @param mesh The mesh to highlight
          */
         HighlightLayer.prototype.removeMesh = function (mesh) {
+            if (!this._meshes) {
+                return;
+            }
             var meshHighlight = this._meshes[mesh.uniqueId];
             if (meshHighlight) {
-                mesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
-                mesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
+                if (meshHighlight.observerHighlight) {
+                    mesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
+                }
+                if (meshHighlight.observerDefault) {
+                    mesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
+                }
             }
-            this._meshes[mesh.uniqueId] = undefined;
+            this._meshes[mesh.uniqueId] = null;
             this._shouldRender = false;
             for (var meshHighlightToCheck in this._meshes) {
                 if (meshHighlightToCheck) {
@@ -71883,23 +71933,35 @@ var BABYLON;
             }
             // Clean textures and post processes
             this.disposeTextureAndPostProcesses();
-            // Clean mesh references 
-            for (var id in this._meshes) {
-                var meshHighlight = this._meshes[id];
-                if (meshHighlight && meshHighlight.mesh) {
-                    meshHighlight.mesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
-                    meshHighlight.mesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
+            if (this._meshes) {
+                // Clean mesh references 
+                for (var id in this._meshes) {
+                    var meshHighlight = this._meshes[id];
+                    if (meshHighlight && meshHighlight.mesh) {
+                        if (meshHighlight.observerHighlight) {
+                            meshHighlight.mesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
+                        }
+                        if (meshHighlight.observerDefault) {
+                            meshHighlight.mesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
+                        }
+                    }
                 }
+                this._meshes = null;
             }
-            this._meshes = null;
-            for (var id in this._excludedMeshes) {
-                var meshHighlight = this._excludedMeshes[id];
-                if (meshHighlight) {
-                    meshHighlight.mesh.onBeforeRenderObservable.remove(meshHighlight.beforeRender);
-                    meshHighlight.mesh.onAfterRenderObservable.remove(meshHighlight.afterRender);
+            if (this._excludedMeshes) {
+                for (var id in this._excludedMeshes) {
+                    var meshHighlight = this._excludedMeshes[id];
+                    if (meshHighlight) {
+                        if (meshHighlight.beforeRender) {
+                            meshHighlight.mesh.onBeforeRenderObservable.remove(meshHighlight.beforeRender);
+                        }
+                        if (meshHighlight.afterRender) {
+                            meshHighlight.mesh.onAfterRenderObservable.remove(meshHighlight.afterRender);
+                        }
+                    }
                 }
+                this._excludedMeshes = null;
             }
-            this._excludedMeshes = null;
             // Remove from scene
             var index = this._scene.highlightLayers.indexOf(this, 0);
             if (index > -1) {
@@ -73140,7 +73202,10 @@ var BABYLON;
             this._indexBuffer = engine.createIndexBuffer(indices);
         };
         Layer.prototype._rebuild = function () {
-            this._vertexBuffers[BABYLON.VertexBuffer.PositionKind]._rebuild();
+            var vb = this._vertexBuffers[BABYLON.VertexBuffer.PositionKind];
+            if (vb) {
+                vb._rebuild();
+            }
             this._createIndexBuffer();
         };
         Layer.prototype.render = function () {

Datei-Diff unterdrückt, da er zu groß ist
+ 645 - 645
dist/preview release/babylon.module.d.ts


Datei-Diff unterdrückt, da er zu groß ist
+ 16 - 16
dist/preview release/babylon.worker.js


Datei-Diff unterdrückt, da er zu groß ist
+ 3520 - 3520
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts


Datei-Diff unterdrückt, da er zu groß ist
+ 16 - 16
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js


+ 99 - 34
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js

@@ -49640,6 +49640,7 @@ var BABYLON;
     var PostProcess = /** @class */ (function () {
         function PostProcess(name, fragmentUrl, parameters, samplers, options, camera, samplingMode, engine, reusable, defines, textureType, vertexUrl, indexParameters, blockCompilation) {
             if (samplingMode === void 0) { samplingMode = BABYLON.Texture.NEAREST_SAMPLINGMODE; }
+            if (defines === void 0) { defines = null; }
             if (textureType === void 0) { textureType = BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT; }
             if (vertexUrl === void 0) { vertexUrl = "postprocess"; }
             if (blockCompilation === void 0) { blockCompilation = false; }
@@ -49802,7 +49803,10 @@ var BABYLON;
             return this;
         };
         PostProcess.prototype.updateEffect = function (defines, uniforms, samplers, indexParameters, onCompiled, onError) {
-            this._effect = this._engine.createEffect({ vertex: this._vertexUrl, fragment: this._fragmentUrl }, ["position"], uniforms || this._parameters, samplers || this._samplers, defines !== undefined ? defines : "", undefined, onCompiled, onError, indexParameters || this._indexParameters);
+            if (defines === void 0) { defines = null; }
+            if (uniforms === void 0) { uniforms = null; }
+            if (samplers === void 0) { samplers = null; }
+            this._effect = this._engine.createEffect({ vertex: this._vertexUrl, fragment: this._fragmentUrl }, ["position"], uniforms || this._parameters, samplers || this._samplers, defines !== null ? defines : "", undefined, onCompiled, onError, indexParameters || this._indexParameters);
         };
         PostProcess.prototype.isReusable = function () {
             return this._reusable;
@@ -51113,7 +51117,9 @@ var BABYLON;
             };
             var manifestChecked = function (success) {
                 BABYLON.Tools.LoadFile(rootUrl + sceneFilename, dataCallback, onProgress, database, useArrayBuffer, function (request) {
-                    onError(request.status + " " + request.statusText);
+                    if (request) {
+                        onError(request.status + " " + request.statusText);
+                    }
                 });
             };
             if (directLoad) {
@@ -51176,6 +51182,9 @@ var BABYLON;
         * @param onError a callback with the scene, a message, and possibly an exception when import fails
         */
         SceneLoader.ImportMesh = function (meshNames, rootUrl, sceneFilename, scene, onSuccess, onProgress, onError) {
+            if (onSuccess === void 0) { onSuccess = null; }
+            if (onProgress === void 0) { onProgress = null; }
+            if (onError === void 0) { onError = null; }
             if (sceneFilename.substr && sceneFilename.substr(0, 1) === "/") {
                 BABYLON.Tools.Error("Wrong sceneFilename parameter");
                 return;
@@ -54077,8 +54086,12 @@ var BABYLON;
         };
         GamepadManager.prototype.dispose = function () {
             if (this._gamepadEventSupported) {
-                window.removeEventListener('gamepadconnected', this._onGamepadConnectedEvent);
-                window.removeEventListener('gamepaddisconnected', this._onGamepadDisconnectedEvent);
+                if (this._onGamepadConnectedEvent) {
+                    window.removeEventListener('gamepadconnected', this._onGamepadConnectedEvent);
+                }
+                if (this._onGamepadDisconnectedEvent) {
+                    window.removeEventListener('gamepaddisconnected', this._onGamepadDisconnectedEvent);
+                }
                 this._onGamepadConnectedEvent = null;
                 this._onGamepadDisconnectedEvent = null;
             }
@@ -54681,8 +54694,9 @@ var BABYLON;
                     this.devicePosition.scaleToRef(this.deviceScaleFactor, this._calculatedPosition);
                     this._calculatedPosition.addInPlace(this.position);
                 }
-                if (poseData.orientation) {
-                    this.deviceRotationQuaternion.copyFromFloats(this.rawPose.orientation[0], this.rawPose.orientation[1], -this.rawPose.orientation[2], -this.rawPose.orientation[3]);
+                var pose = this.rawPose;
+                if (poseData.orientation && pose.orientation) {
+                    this.deviceRotationQuaternion.copyFromFloats(pose.orientation[0], pose.orientation[1], -pose.orientation[2], -pose.orientation[3]);
                     if (this._mesh) {
                         if (this._mesh.getScene().useRightHandedSystem) {
                             this.deviceRotationQuaternion.z *= -1;
@@ -54699,7 +54713,7 @@ var BABYLON;
         };
         PoseEnabledController.prototype.attachToMesh = function (mesh) {
             if (this._mesh) {
-                this._mesh.parent = undefined;
+                this._mesh.parent = null;
             }
             this._mesh = mesh;
             if (this._poseControlledCamera) {
@@ -54719,7 +54733,7 @@ var BABYLON;
             if (this._mesh) {
                 this._mesh.dispose();
             }
-            this._mesh = undefined;
+            this._mesh = null;
             _super.prototype.dispose.call(this);
         };
         Object.defineProperty(PoseEnabledController.prototype, "mesh", {
@@ -55253,6 +55267,9 @@ var BABYLON;
             BABYLON.Vector3.LerpToRef(meshInfo.unpressed.position, meshInfo.pressed.position, buttonValue, meshInfo.value.position);
         };
         WindowsMotionController.prototype.lerpAxisTransform = function (axis, axisValue) {
+            if (!this._loadedMeshInfo) {
+                return;
+            }
             var meshInfo = this._loadedMeshInfo.axisMeshes[axis];
             if (!meshInfo) {
                 return;
@@ -71376,7 +71393,8 @@ var BABYLON;
                 blurTextureSizeRatio: 0.5,
                 blurHorizontalSize: 1.0,
                 blurVerticalSize: 1.0,
-                alphaBlendingMode: BABYLON.Engine.ALPHA_COMBINE
+                alphaBlendingMode: BABYLON.Engine.ALPHA_COMBINE,
+                camera: null
             };
             this._options.mainTextureRatio = this._options.mainTextureRatio || 0.5;
             this._options.blurTextureSizeRatio = this._options.blurTextureSizeRatio || 1.0;
@@ -71454,7 +71472,10 @@ var BABYLON;
             this._indexBuffer = engine.createIndexBuffer(indices);
         };
         HighlightLayer.prototype._rebuild = function () {
-            this._vertexBuffers[BABYLON.VertexBuffer.PositionKind]._rebuild();
+            var vb = this._vertexBuffers[BABYLON.VertexBuffer.PositionKind];
+            if (vb) {
+                vb._rebuild();
+            }
             this._createIndexBuffer();
         };
         /**
@@ -71514,11 +71535,17 @@ var BABYLON;
             }
             this._mainTexture.onAfterUnbindObservable.add(function () {
                 _this.onBeforeBlurObservable.notifyObservers(_this);
-                _this._scene.postProcessManager.directRender([_this._downSamplePostprocess, _this._horizontalBlurPostprocess, _this._verticalBlurPostprocess], _this._blurTexture.getInternalTexture(), true);
+                var internalTexture = _this._blurTexture.getInternalTexture();
+                if (internalTexture) {
+                    _this._scene.postProcessManager.directRender([_this._downSamplePostprocess, _this._horizontalBlurPostprocess, _this._verticalBlurPostprocess], internalTexture, true);
+                }
                 _this.onAfterBlurObservable.notifyObservers(_this);
             });
             // Custom render function
             var renderSubMesh = function (subMesh) {
+                if (!_this._meshes) {
+                    return;
+                }
                 var mesh = subMesh.getRenderingMesh();
                 var scene = _this._scene;
                 var engine = scene.getEngine();
@@ -71530,7 +71557,7 @@ var BABYLON;
                     return;
                 }
                 // Excluded Mesh
-                if (_this._excludedMeshes[mesh.uniqueId]) {
+                if (_this._excludedMeshes && _this._excludedMeshes[mesh.uniqueId]) {
                     return;
                 }
                 ;
@@ -71556,7 +71583,10 @@ var BABYLON;
                         var alphaTexture = material.getAlphaTestTexture();
                         if (alphaTexture) {
                             _this._glowMapGenerationEffect.setTexture("diffuseSampler", alphaTexture);
-                            _this._glowMapGenerationEffect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
+                            var textureMatrix = alphaTexture.getTextureMatrix();
+                            if (textureMatrix) {
+                                _this._glowMapGenerationEffect.setMatrix("diffuseMatrix", textureMatrix);
+                            }
                         }
                     }
                     // Glow emissive only
@@ -71754,6 +71784,9 @@ var BABYLON;
          * @param mesh The mesh to exclude from the highlight layer
          */
         HighlightLayer.prototype.addExcludedMesh = function (mesh) {
+            if (!this._excludedMeshes) {
+                return;
+            }
             var meshExcluded = this._excludedMeshes[mesh.uniqueId];
             if (!meshExcluded) {
                 this._excludedMeshes[mesh.uniqueId] = {
@@ -71772,12 +71805,19 @@ var BABYLON;
           * @param mesh The mesh to highlight
           */
         HighlightLayer.prototype.removeExcludedMesh = function (mesh) {
+            if (!this._excludedMeshes) {
+                return;
+            }
             var meshExcluded = this._excludedMeshes[mesh.uniqueId];
             if (meshExcluded) {
-                mesh.onBeforeRenderObservable.remove(meshExcluded.beforeRender);
-                mesh.onAfterRenderObservable.remove(meshExcluded.afterRender);
+                if (meshExcluded.beforeRender) {
+                    mesh.onBeforeRenderObservable.remove(meshExcluded.beforeRender);
+                }
+                if (meshExcluded.afterRender) {
+                    mesh.onAfterRenderObservable.remove(meshExcluded.afterRender);
+                }
             }
-            this._excludedMeshes[mesh.uniqueId] = undefined;
+            this._excludedMeshes[mesh.uniqueId] = null;
         };
         /**
          * Add a mesh in the highlight layer in order to make it glow with the chosen color.
@@ -71788,6 +71828,9 @@ var BABYLON;
         HighlightLayer.prototype.addMesh = function (mesh, color, glowEmissiveOnly) {
             var _this = this;
             if (glowEmissiveOnly === void 0) { glowEmissiveOnly = false; }
+            if (!this._meshes) {
+                return;
+            }
             var meshHighlight = this._meshes[mesh.uniqueId];
             if (meshHighlight) {
                 meshHighlight.color = color;
@@ -71798,7 +71841,7 @@ var BABYLON;
                     color: color,
                     // Lambda required for capture due to Observable this context
                     observerHighlight: mesh.onBeforeRenderObservable.add(function (mesh) {
-                        if (_this._excludedMeshes[mesh.uniqueId]) {
+                        if (_this._excludedMeshes && _this._excludedMeshes[mesh.uniqueId]) {
                             _this.defaultStencilReference(mesh);
                         }
                         else {
@@ -71816,12 +71859,19 @@ var BABYLON;
          * @param mesh The mesh to highlight
          */
         HighlightLayer.prototype.removeMesh = function (mesh) {
+            if (!this._meshes) {
+                return;
+            }
             var meshHighlight = this._meshes[mesh.uniqueId];
             if (meshHighlight) {
-                mesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
-                mesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
+                if (meshHighlight.observerHighlight) {
+                    mesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
+                }
+                if (meshHighlight.observerDefault) {
+                    mesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
+                }
             }
-            this._meshes[mesh.uniqueId] = undefined;
+            this._meshes[mesh.uniqueId] = null;
             this._shouldRender = false;
             for (var meshHighlightToCheck in this._meshes) {
                 if (meshHighlightToCheck) {
@@ -71883,23 +71933,35 @@ var BABYLON;
             }
             // Clean textures and post processes
             this.disposeTextureAndPostProcesses();
-            // Clean mesh references 
-            for (var id in this._meshes) {
-                var meshHighlight = this._meshes[id];
-                if (meshHighlight && meshHighlight.mesh) {
-                    meshHighlight.mesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
-                    meshHighlight.mesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
+            if (this._meshes) {
+                // Clean mesh references 
+                for (var id in this._meshes) {
+                    var meshHighlight = this._meshes[id];
+                    if (meshHighlight && meshHighlight.mesh) {
+                        if (meshHighlight.observerHighlight) {
+                            meshHighlight.mesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
+                        }
+                        if (meshHighlight.observerDefault) {
+                            meshHighlight.mesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
+                        }
+                    }
                 }
+                this._meshes = null;
             }
-            this._meshes = null;
-            for (var id in this._excludedMeshes) {
-                var meshHighlight = this._excludedMeshes[id];
-                if (meshHighlight) {
-                    meshHighlight.mesh.onBeforeRenderObservable.remove(meshHighlight.beforeRender);
-                    meshHighlight.mesh.onAfterRenderObservable.remove(meshHighlight.afterRender);
+            if (this._excludedMeshes) {
+                for (var id in this._excludedMeshes) {
+                    var meshHighlight = this._excludedMeshes[id];
+                    if (meshHighlight) {
+                        if (meshHighlight.beforeRender) {
+                            meshHighlight.mesh.onBeforeRenderObservable.remove(meshHighlight.beforeRender);
+                        }
+                        if (meshHighlight.afterRender) {
+                            meshHighlight.mesh.onAfterRenderObservable.remove(meshHighlight.afterRender);
+                        }
+                    }
                 }
+                this._excludedMeshes = null;
             }
-            this._excludedMeshes = null;
             // Remove from scene
             var index = this._scene.highlightLayers.indexOf(this, 0);
             if (index > -1) {
@@ -73140,7 +73202,10 @@ var BABYLON;
             this._indexBuffer = engine.createIndexBuffer(indices);
         };
         Layer.prototype._rebuild = function () {
-            this._vertexBuffers[BABYLON.VertexBuffer.PositionKind]._rebuild();
+            var vb = this._vertexBuffers[BABYLON.VertexBuffer.PositionKind];
+            if (vb) {
+                vb._rebuild();
+            }
             this._createIndexBuffer();
         };
         Layer.prototype.render = function () {

Datei-Diff unterdrückt, da er zu groß ist
+ 3520 - 3520
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.module.d.ts


+ 1 - 1
dist/preview release/what's new.md

@@ -16,7 +16,7 @@
 - Added support for `material.separateCullingPass`. [Doc here](http://doc.babylonjs.com/tutorials/transparency_and_how_meshes_are_rendered#things-to-do-and-not-to-do) ([sebavan](https://github.com/sebavan))
 - Added support for Windows Motion Controllers ([Lewis Weaver](https://github.com/leweaver))
 - Added support for Particle animation in ParticleSystem. [Doc here](http://doc.babylonjs.com/tutorials/particles#particle-animation) ([Ibraheem Osama](https://github.com/IbraheemOsama))
-- More robust TypeScript code with *noImplicitAny*, *noImplicitThis* and *noImplicitReturns* compiler options ([deltakosh](https://github.com/deltakosh))
+- More robust TypeScript code with *strictNullChecks*, *noImplicitAny*, *noImplicitThis* and *noImplicitReturns* compiler options ([deltakosh](https://github.com/deltakosh))
 - Introduced `NullEngine` which can be used to use Babylon.js in headless mode. [Doc here](http://doc.babylonjs.com/generals/nullengine) ([deltakosh](https://github.com/deltakosh)) 
 
 ## Updates

+ 3 - 3
src/Engine/babylon.engine.ts

@@ -2091,7 +2091,7 @@
             }
         }
 
-        private _bindIndexBufferWithCache(indexBuffer: WebGLBuffer): void {
+        private _bindIndexBufferWithCache(indexBuffer: Nullable<WebGLBuffer>): void {
             if (indexBuffer == null) {
                 return;
             }
@@ -2102,7 +2102,7 @@
             }
         }
 
-        private _bindVertexBuffersAttributes(vertexBuffers: { [key: string]: VertexBuffer; }, effect: Effect) {
+        private _bindVertexBuffersAttributes(vertexBuffers: { [key: string]: Nullable<VertexBuffer> }, effect: Effect) {
             var attributes = effect.getAttributesNames();
 
             if (!this._vaoRecordInProgress) {
@@ -2211,7 +2211,7 @@
             this._gl.bindVertexArray(null);
         }
 
-        public bindBuffers(vertexBuffers: { [key: string]: VertexBuffer; }, indexBuffer: WebGLBuffer, effect: Effect): void {
+        public bindBuffers(vertexBuffers: { [key: string]: Nullable<VertexBuffer>; }, indexBuffer: Nullable<WebGLBuffer>, effect: Effect): void {
             if (this._cachedVertexBuffers !== vertexBuffers || this._cachedEffectForVertexBuffers !== effect) {
                 this._cachedVertexBuffers = vertexBuffers;
                 this._cachedEffectForVertexBuffers = effect;

+ 7 - 6
src/Gamepad/Controllers/babylon.poseEnabledController.ts

@@ -54,7 +54,7 @@ module BABYLON {
 
         public rawPose: DevicePose; //GamepadPose;
 
-        public _mesh: AbstractMesh; // a node that will be attached to this Gamepad
+        public _mesh: Nullable<AbstractMesh>; // a node that will be attached to this Gamepad
         private _poseControlledCamera: TargetCamera;
 
         private _leftHandSystemQuaternion: Quaternion = new Quaternion();
@@ -97,8 +97,9 @@ module BABYLON {
                     this._calculatedPosition.addInPlace(this.position);
 
                 }
-                if (poseData.orientation) {
-                    this.deviceRotationQuaternion.copyFromFloats(this.rawPose.orientation[0], this.rawPose.orientation[1], -this.rawPose.orientation[2], -this.rawPose.orientation[3]);
+                let pose = this.rawPose;
+                if (poseData.orientation && pose.orientation) {
+                    this.deviceRotationQuaternion.copyFromFloats(pose.orientation[0], pose.orientation[1], -pose.orientation[2], -pose.orientation[3]);
                     if (this._mesh) {
                         if (this._mesh.getScene().useRightHandedSystem) {
                             this.deviceRotationQuaternion.z *= -1;
@@ -117,7 +118,7 @@ module BABYLON {
 
         public attachToMesh(mesh: AbstractMesh) {
             if (this._mesh) {
-                this._mesh.parent = undefined;
+                this._mesh.parent = null;
             }
             this._mesh = mesh;
             if (this._poseControlledCamera) {
@@ -139,12 +140,12 @@ module BABYLON {
             if (this._mesh) {
                 this._mesh.dispose();
             }
-            this._mesh = undefined;
+            this._mesh = null;
 
             super.dispose();
         }
 
-        public get mesh(): AbstractMesh {
+        public get mesh(): Nullable<AbstractMesh> {
             return this._mesh;
         }
 

+ 7 - 3
src/Gamepad/Controllers/babylon.windowsMotionController.ts

@@ -30,7 +30,7 @@ module BABYLON {
         public static readonly GAMEPAD_ID_PREFIX:string = 'Spatial Controller (Spatial Interaction Source) ';
         private static readonly GAMEPAD_ID_PATTERN = /([0-9a-zA-Z]+-[0-9a-zA-Z]+)$/;
 
-        private _loadedMeshInfo: LoadedMeshInfo;
+        private _loadedMeshInfo: Nullable<LoadedMeshInfo>;
         private readonly _mapping = {
             // Semantic button names
             buttons: ['thumbstick', 'trigger', 'grip', 'menu', 'trackpad'],
@@ -151,6 +151,10 @@ module BABYLON {
         }
         
         protected lerpAxisTransform(axis:number, axisValue: number) {
+            if (!this._loadedMeshInfo) {
+                return;
+            }
+
             let meshInfo = this._loadedMeshInfo.axisMeshes[axis];
             if (!meshInfo) {
                 return;
@@ -235,14 +239,14 @@ module BABYLON {
          * @param meshes list of meshes that make up the controller model to process
          * @return structured view of the given meshes, with mapping of buttons and axes to meshes that can be transformed.
          */
-        private processModel(scene: Scene, meshes: AbstractMesh[]) : LoadedMeshInfo {
+        private processModel(scene: Scene, meshes: AbstractMesh[]) : Nullable<LoadedMeshInfo> {
             let loadedMeshInfo = null;
 
             // Create a new mesh to contain the glTF hierarchy
             let parentMesh = new BABYLON.Mesh(this.id + " " + this.hand, scene);
 
             // Find the root node in the loaded glTF scene, and attach it as a child of 'parentMesh'
-            let childMesh : AbstractMesh = null;
+            let childMesh : Nullable<AbstractMesh> = null;
             for (let i = 0; i < meshes.length; i++) {
                 let mesh = meshes[i];
 

+ 10 - 5
src/Gamepad/babylon.gamepadManager.ts

@@ -10,8 +10,8 @@
         public onGamepadConnectedObservable: Observable<Gamepad>;
         public onGamepadDisconnectedObservable = new Observable<Gamepad>();
 
-        private _onGamepadConnectedEvent: (evt: any) => void;
-        private _onGamepadDisconnectedEvent: (evt: any) => void;
+        private _onGamepadConnectedEvent: Nullable<(evt: any) => void>;
+        private _onGamepadDisconnectedEvent: Nullable<(evt: any) => void>;
 
         constructor() {
             if (!Tools.IsWindowObjectExist()) {
@@ -91,7 +91,7 @@
             return this._babylonGamepads;
         }
 
-        public getGamepadByType(type: number = Gamepad.XBOX): Gamepad {
+        public getGamepadByType(type: number = Gamepad.XBOX): Nullable<Gamepad> {
             for (var gamepad of this._babylonGamepads) {
                 if (gamepad && gamepad.type === type) {
                     return gamepad;
@@ -103,8 +103,13 @@
 
         public dispose() {
             if (this._gamepadEventSupported) {
-                window.removeEventListener('gamepadconnected', this._onGamepadConnectedEvent);
-                window.removeEventListener('gamepaddisconnected', this._onGamepadDisconnectedEvent);
+                if (this._onGamepadConnectedEvent) {
+                    window.removeEventListener('gamepadconnected', this._onGamepadConnectedEvent);
+                }
+
+                if (this._onGamepadDisconnectedEvent) {
+                    window.removeEventListener('gamepaddisconnected', this._onGamepadDisconnectedEvent);
+                }
                 this._onGamepadConnectedEvent = null;
                 this._onGamepadDisconnectedEvent = null;
             }

+ 105 - 43
src/Layer/babylon.highlightlayer.ts

@@ -7,7 +7,7 @@ module BABYLON {
      * It enforces keeping the most luminous color in the color channel.
      */
     class GlowBlurPostProcess extends PostProcess {
-        constructor(name: string, public direction: Vector2, public kernel: number, options: number | PostProcessOptions, camera: Camera, samplingMode: number = Texture.BILINEAR_SAMPLINGMODE, engine?: Engine, reusable?: boolean) {
+        constructor(name: string, public direction: Vector2, public kernel: number, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode: number = Texture.BILINEAR_SAMPLINGMODE, engine?: Engine, reusable?: boolean) {
             super(name, "glowBlurPostProcess", ["screenSize", "direction", "blurWidth"], null, options, camera, samplingMode, engine, reusable);
 
             this.onApplyObservable.add((effect: Effect) => {
@@ -27,7 +27,7 @@ module BABYLON {
          * Multiplication factor apply to the canvas size to compute the render target size
          * used to generated the glowing objects (the smaller the faster).
          */
-        mainTextureRatio?: number;
+        mainTextureRatio: number;
 
         /**
          * Enforces a fixed size texture to ensure resize independant blur.
@@ -38,27 +38,27 @@ module BABYLON {
          * Multiplication factor apply to the main texture size in the first step of the blur to reduce the size 
          * of the picture to blur (the smaller the faster).
          */
-        blurTextureSizeRatio?: number;
+        blurTextureSizeRatio: number;
 
         /**
          * How big in texel of the blur texture is the vertical blur.
          */
-        blurVerticalSize?: number;
+        blurVerticalSize: number;
 
         /**
          * How big in texel of the blur texture is the horizontal blur.
          */
-        blurHorizontalSize?: number;
+        blurHorizontalSize: number;
 
         /**
          * Alpha blending mode used to apply the blur. Default is combine.
          */
-        alphaBlendingMode?: number
+        alphaBlendingMode: number
 
         /**
          * The camera attached to the layer.
          */
-        camera?: Camera;
+        camera: Nullable<Camera>;
     }
 
     /**
@@ -76,11 +76,11 @@ module BABYLON {
         /**
          * The mesh render callback use to insert stencil information
          */
-        observerHighlight: Observer<Mesh>;
+        observerHighlight: Nullable<Observer<Mesh>>;
         /**
          * The mesh render callback use to come to the default behavior
          */
-        observerDefault: Observer<Mesh>;
+        observerDefault: Nullable<Observer<Mesh>>;
         /**
          * If it exists, the emissive color of the material will be used to generate the glow.
          * Else it falls back to the current color.
@@ -99,11 +99,11 @@ module BABYLON {
         /**
          * The mesh render callback use to prevent stencil use
          */
-        beforeRender: Observer<Mesh>;
+        beforeRender: Nullable<Observer<Mesh>>;
         /**
          * The mesh render callback use to restore previous stencil use
          */
-        afterRender: Observer<Mesh>;
+        afterRender: Nullable<Observer<Mesh>>;
     }
 
     /**
@@ -134,8 +134,8 @@ module BABYLON {
         private _scene: Scene;
         private _engine: Engine;
         private _options: IHighlightLayerOptions;
-        private _vertexBuffers: { [key: string]: VertexBuffer } = {};
-        private _indexBuffer: WebGLBuffer;
+        private _vertexBuffers: { [key: string]: Nullable<VertexBuffer> } = {};
+        private _indexBuffer: Nullable<WebGLBuffer>;
         private _downSamplePostprocess: PassPostProcess;
         private _horizontalBlurPostprocess: GlowBlurPostProcess;
         private _verticalBlurPostprocess: GlowBlurPostProcess;
@@ -145,11 +145,11 @@ module BABYLON {
         private _blurTexture: RenderTargetTexture;
         private _mainTexture: RenderTargetTexture;
         private _mainTextureDesiredSize: ISize = { width: 0, height: 0 };
-        private _meshes: { [id: string]: IHighlightLayerMesh } = {};
+        private _meshes: Nullable<{ [id: string]: Nullable<IHighlightLayerMesh> }> = {};
         private _maxSize: number = 0;
         private _shouldRender = false;
         private _instanceGlowingMeshStencilReference = HighlightLayer.glowingMeshStencilReference++;
-        private _excludedMeshes: { [id: string]: IHighlightLayerExcludedMesh } = {};
+        private _excludedMeshes: Nullable<{ [id: string]: Nullable<IHighlightLayerExcludedMesh> }> = {};
 
         /**
          * Specifies whether or not the inner glow is ACTIVE in the layer.
@@ -197,7 +197,7 @@ module BABYLON {
         /**
          * Gets the camera attached to the layer.
          */
-        public get camera(): Camera {
+        public get camera(): Nullable<Camera> {
             return this._options.camera;
         }
 
@@ -267,7 +267,8 @@ module BABYLON {
                 blurTextureSizeRatio: 0.5,
                 blurHorizontalSize: 1.0,
                 blurVerticalSize: 1.0,
-                alphaBlendingMode: Engine.ALPHA_COMBINE
+                alphaBlendingMode: Engine.ALPHA_COMBINE,
+                camera: null
             };
             this._options.mainTextureRatio = this._options.mainTextureRatio || 0.5;
             this._options.blurTextureSizeRatio = this._options.blurTextureSizeRatio || 1.0;
@@ -317,7 +318,11 @@ module BABYLON {
         }
 
         public _rebuild(): void {
-            this._vertexBuffers[VertexBuffer.PositionKind]._rebuild();
+            let vb  = this._vertexBuffers[VertexBuffer.PositionKind];
+
+            if (vb) {
+                vb._rebuild();
+            }
 
             this._createIndexBuffer();
         }        
@@ -401,15 +406,24 @@ module BABYLON {
             this._mainTexture.onAfterUnbindObservable.add(() => {
                 this.onBeforeBlurObservable.notifyObservers(this);
 
+                let internalTexture = this._blurTexture.getInternalTexture();
+
+                if (internalTexture) {
                 this._scene.postProcessManager.directRender(
                     [this._downSamplePostprocess, this._horizontalBlurPostprocess, this._verticalBlurPostprocess],
-                    this._blurTexture.getInternalTexture(), true);
+                    internalTexture, true);
+                }
 
                 this.onAfterBlurObservable.notifyObservers(this);
             });
 
             // Custom render function
             var renderSubMesh = (subMesh: SubMesh): void => {
+
+                if (!this._meshes) {
+                    return;
+                }
+
                 var mesh = subMesh.getRenderingMesh();
                 var scene = this._scene;
                 var engine = scene.getEngine();
@@ -424,7 +438,7 @@ module BABYLON {
                 }
 
                 // Excluded Mesh
-                if (this._excludedMeshes[mesh.uniqueId]) {
+                if (this._excludedMeshes && this._excludedMeshes[mesh.uniqueId]) {
                     return;
                 };
 
@@ -432,7 +446,7 @@ module BABYLON {
 
                 var highlightLayerMesh = this._meshes[mesh.uniqueId];
                 var material = subMesh.getMaterial();
-                var emissiveTexture: Texture = null;
+                var emissiveTexture: Nullable<Texture> = null;
                 if (highlightLayerMesh && highlightLayerMesh.glowEmissiveOnly && material) {
                     emissiveTexture = (<any>material).emissiveTexture;
                 }
@@ -462,7 +476,11 @@ module BABYLON {
                         var alphaTexture = material.getAlphaTestTexture();
                         if (alphaTexture) {
                             this._glowMapGenerationEffect.setTexture("diffuseSampler", alphaTexture);
-                            this._glowMapGenerationEffect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
+                            let textureMatrix = alphaTexture.getTextureMatrix();
+
+                            if (textureMatrix) {
+                                this._glowMapGenerationEffect.setMatrix("diffuseMatrix", textureMatrix);
+                            }
                         }
                     }
 
@@ -526,7 +544,7 @@ module BABYLON {
          * @param emissiveTexture the associated emissive texture used to generate the glow
          * @return true if ready otherwise, false
          */
-        private isReady(subMesh: SubMesh, useInstances: boolean, emissiveTexture: Texture): boolean {
+        private isReady(subMesh: SubMesh, useInstances: boolean, emissiveTexture: Nullable<Texture>): boolean {
             if (!subMesh.getMaterial().isReady(subMesh.getMesh(), useInstances)) {
                 return false;
             }
@@ -700,6 +718,10 @@ module BABYLON {
          * @param mesh The mesh to exclude from the highlight layer
          */
         public addExcludedMesh(mesh: Mesh) {
+            if (!this._excludedMeshes) {
+                return;
+            }
+
             var meshExcluded = this._excludedMeshes[mesh.uniqueId];
             if (!meshExcluded) {
                 this._excludedMeshes[mesh.uniqueId] = {
@@ -719,13 +741,22 @@ module BABYLON {
           * @param mesh The mesh to highlight
           */
         public removeExcludedMesh(mesh: Mesh) {
+            if (!this._excludedMeshes) {
+                return;
+            }
+
             var meshExcluded = this._excludedMeshes[mesh.uniqueId];
             if (meshExcluded) {
-                mesh.onBeforeRenderObservable.remove(meshExcluded.beforeRender);
-                mesh.onAfterRenderObservable.remove(meshExcluded.afterRender);
+                if (meshExcluded.beforeRender) {
+                    mesh.onBeforeRenderObservable.remove(meshExcluded.beforeRender);
+                }
+
+                if (meshExcluded.afterRender) {
+                    mesh.onAfterRenderObservable.remove(meshExcluded.afterRender);
+                }
             }
 
-            this._excludedMeshes[mesh.uniqueId] = undefined;
+            this._excludedMeshes[mesh.uniqueId] = null;
         }
 
         /**
@@ -735,6 +766,10 @@ module BABYLON {
          * @param glowEmissiveOnly Extract the glow from the emissive texture
          */
         public addMesh(mesh: Mesh, color: Color3, glowEmissiveOnly = false) {
+            if (!this._meshes) {
+                return;
+            }
+
             var meshHighlight = this._meshes[mesh.uniqueId];
             if (meshHighlight) {
                 meshHighlight.color = color;
@@ -745,7 +780,7 @@ module BABYLON {
                     color: color,
                     // Lambda required for capture due to Observable this context
                     observerHighlight: mesh.onBeforeRenderObservable.add((mesh: Mesh) => {
-                        if (this._excludedMeshes[mesh.uniqueId]) {
+                        if (this._excludedMeshes && this._excludedMeshes[mesh.uniqueId]) {
                             this.defaultStencilReference(mesh);
                         }
                         else {
@@ -765,13 +800,23 @@ module BABYLON {
          * @param mesh The mesh to highlight
          */
         public removeMesh(mesh: Mesh) {
+            if (!this._meshes) {
+                return;
+            }
+
             var meshHighlight = this._meshes[mesh.uniqueId];
             if (meshHighlight) {
-                mesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
-                mesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
+
+                if (meshHighlight.observerHighlight) {
+                    mesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
+                }
+
+                if (meshHighlight.observerDefault) {
+                    mesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
+                }
             }
 
-            this._meshes[mesh.uniqueId] = undefined;
+            this._meshes[mesh.uniqueId] = null;
 
             this._shouldRender = false;
             for (var meshHighlightToCheck in this._meshes) {
@@ -844,23 +889,40 @@ module BABYLON {
             // Clean textures and post processes
             this.disposeTextureAndPostProcesses();
 
-            // Clean mesh references 
-            for (let id in this._meshes) {
-                let meshHighlight = this._meshes[id];
-                if (meshHighlight && meshHighlight.mesh) {
-                    meshHighlight.mesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
-                    meshHighlight.mesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
+            if (this._meshes) {
+                // Clean mesh references 
+                for (let id in this._meshes) {
+                    let meshHighlight = this._meshes[id];
+                    if (meshHighlight && meshHighlight.mesh) {
+
+                        if (meshHighlight.observerHighlight) {
+                            meshHighlight.mesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
+                        }
+
+                        if (meshHighlight.observerDefault) {
+                            meshHighlight.mesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
+                        }
+                    }
                 }
+                this._meshes = null;
             }
-            this._meshes = null;
-            for (let id in this._excludedMeshes) {
-                let meshHighlight = this._excludedMeshes[id];
-                if (meshHighlight) {
-                    meshHighlight.mesh.onBeforeRenderObservable.remove(meshHighlight.beforeRender);
-                    meshHighlight.mesh.onAfterRenderObservable.remove(meshHighlight.afterRender);
+
+            if (this._excludedMeshes) {
+                for (let id in this._excludedMeshes) {
+                    let meshHighlight = this._excludedMeshes[id];
+                    if (meshHighlight) {
+
+                        if (meshHighlight.beforeRender) {
+                            meshHighlight.mesh.onBeforeRenderObservable.remove(meshHighlight.beforeRender);
+                        }
+
+                        if (meshHighlight.afterRender) {
+                            meshHighlight.mesh.onAfterRenderObservable.remove(meshHighlight.afterRender);
+                        }
+                    }
                 }
+                this._excludedMeshes = null;
             }
-            this._excludedMeshes = null;
 
             // Remove from scene
             var index = this._scene.highlightLayers.indexOf(this, 0);

+ 11 - 7
src/Layer/babylon.layer.ts

@@ -1,6 +1,6 @@
 module BABYLON {
     export class Layer {
-        public texture: Texture;
+        public texture: Nullable<Texture>;
         public isBackground: boolean;
         public color: Color4;
         public scale = new Vector2(1, 1);
@@ -10,8 +10,8 @@
         public layerMask: number = 0x0FFFFFFF;
         
         private _scene: Scene;
-        private _vertexBuffers: { [key: string]: VertexBuffer } = {};
-        private _indexBuffer: WebGLBuffer;
+        private _vertexBuffers: { [key: string]: Nullable<VertexBuffer> } = {};
+        private _indexBuffer: Nullable<WebGLBuffer>;
         private _effect: Effect;
         private _alphaTestEffect: Effect;
 
@@ -24,7 +24,7 @@
         */
         public onDisposeObservable = new Observable<Layer>();
 
-        private _onDisposeObserver: Observer<Layer>;
+        private _onDisposeObserver: Nullable<Observer<Layer>>;
         public set onDispose(callback: () => void) {
             if (this._onDisposeObserver) {
                 this.onDisposeObservable.remove(this._onDisposeObserver);
@@ -38,7 +38,7 @@
         */
         public onBeforeRenderObservable = new Observable<Layer>();
 
-        private _onBeforeRenderObserver: Observer<Layer>;
+        private _onBeforeRenderObserver: Nullable<Observer<Layer>>;
         public set onBeforeRender(callback: () => void) {
             if (this._onBeforeRenderObserver) {
                 this.onBeforeRenderObservable.remove(this._onBeforeRenderObserver);
@@ -52,7 +52,7 @@
         */
         public onAfterRenderObservable = new Observable<Layer>();
 
-        private _onAfterRenderObserver: Observer<Layer>;
+        private _onAfterRenderObserver: Nullable<Observer<Layer>>;
         public set onAfterRender(callback: () => void) {
             if (this._onAfterRenderObserver) {
                 this.onAfterRenderObservable.remove(this._onAfterRenderObserver);
@@ -111,7 +111,11 @@
         }
 
         public _rebuild(): void {
-            this._vertexBuffers[VertexBuffer.PositionKind]._rebuild();
+            let vb = this._vertexBuffers[VertexBuffer.PositionKind];
+
+            if (vb) {
+                vb._rebuild();
+            }
 
             this._createIndexBuffer();
         }

+ 8 - 6
src/Loading/babylon.sceneLoader.ts

@@ -130,7 +130,7 @@
         }
 
         // use babylon file loader directly if sceneFilename is prefixed with "data:"
-        private static _getDirectLoad(sceneFilename: string): string {
+        private static _getDirectLoad(sceneFilename: string): Nullable<string> {
             if (sceneFilename.substr && sceneFilename.substr(0, 5) === "data:") {
                 return sceneFilename.substr(5);
             }
@@ -138,7 +138,7 @@
             return null;
         }
 
-        private static _loadData(rootUrl: string, sceneFilename: string, scene: Scene, onSuccess: (plugin: ISceneLoaderPlugin | ISceneLoaderPluginAsync, data: any) => void, onProgress: (event: ProgressEvent) => void, onError: (message?: string, exception?: any) => void): void {
+        private static _loadData(rootUrl: string, sceneFilename: string, scene: Scene, onSuccess: (plugin: ISceneLoaderPlugin | ISceneLoaderPluginAsync, data: any) => void, onProgress: (event: ProgressEvent) => void, onError: (message: Nullable<string>, exception?: any) => void): void {
             var directLoad = SceneLoader._getDirectLoad(sceneFilename);
             var registeredPlugin = directLoad ? SceneLoader._getPluginForDirectLoad(sceneFilename) : SceneLoader._getPluginForFilename(sceneFilename);
             var plugin = registeredPlugin.plugin;
@@ -165,7 +165,9 @@
 
             var manifestChecked = (success: any) => {
                 Tools.LoadFile(rootUrl + sceneFilename, dataCallback, onProgress, database, useArrayBuffer, request => {
-                    onError(request.status + " " + request.statusText);
+                    if (request) {
+                        onError(request.status + " " + request.statusText);
+                    }
                 });
             };
 
@@ -232,7 +234,7 @@
         * @param onProgress a callback with a progress event for each file being loaded
         * @param onError a callback with the scene, a message, and possibly an exception when import fails
         */
-        public static ImportMesh(meshNames: any, rootUrl: string, sceneFilename: string, scene: Scene, onSuccess?: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onProgress?: (event: ProgressEvent) => void, onError?: (scene: Scene, message: string, exception?: any) => void): void {
+        public static ImportMesh(meshNames: any, rootUrl: string, sceneFilename: string, scene: Scene, onSuccess: Nullable<(meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void> = null, onProgress: Nullable<(event: ProgressEvent) => void> = null, onError: Nullable<(scene: Scene, message: string, exception?: any) => void> = null): void {
             if (sceneFilename.substr && sceneFilename.substr(0, 1) === "/") {
                 Tools.Error("Wrong sceneFilename parameter");
                 return;
@@ -241,7 +243,7 @@
             var loadingToken = {};
             scene._addPendingData(loadingToken);
 
-            var errorHandler = (message?: string, exception?: any) => {
+            var errorHandler = (message: Nullable<string>, exception?: any) => {
                 let errorMessage = "Unable to import meshes from " + rootUrl + sceneFilename + (message ? ": " + message : "");
                 if (onError) {
                     onError(scene, errorMessage, exception);
@@ -333,7 +335,7 @@
             var loadingToken = {};
             scene._addPendingData(loadingToken);
 
-            var errorHandler = (message?: string, exception?: any) => {
+            var errorHandler = (message: Nullable<string>, exception?: any) => {
                 let errorMessage = "Unable to load from " + rootUrl + sceneFilename + (message ? ": " + message : "");
                 if (onError) {
                     onError(scene, errorMessage, exception);

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

@@ -29,7 +29,7 @@
         public renderParticles = true;
         public renderSprites = false;
         public coordinatesMode = Texture.PROJECTION_MODE;
-        public activeCamera: Camera;
+        public activeCamera: Nullable<Camera>;
         public customRenderFunction: (opaqueSubMeshes: SmartArray<SubMesh>, alphaTestSubMeshes: SmartArray<SubMesh>, transparentSubMeshes: SmartArray<SubMesh>, depthOnlySubMeshes: SmartArray<SubMesh>, beforeTransparents?: () => void) => void;
         public useCameraPostProcesses: boolean;
         public ignoreCameraViewport: boolean = false;
@@ -51,7 +51,7 @@
         */
         public onAfterUnbindObservable = new Observable<RenderTargetTexture>();
 
-        private _onAfterUnbindObserver: Observer<RenderTargetTexture>;
+        private _onAfterUnbindObserver: Nullable<Observer<RenderTargetTexture>>;
         public set onAfterUnbind(callback: () => void) {
             if (this._onAfterUnbindObserver) {
                 this.onAfterUnbindObservable.remove(this._onAfterUnbindObserver);
@@ -65,7 +65,7 @@
         */
         public onBeforeRenderObservable = new Observable<number>();
 
-        private _onBeforeRenderObserver: Observer<number>;
+        private _onBeforeRenderObserver: Nullable<Observer<number>>;
         public set onBeforeRender(callback: (faceIndex: number) => void) {
             if (this._onBeforeRenderObserver) {
                 this.onBeforeRenderObservable.remove(this._onBeforeRenderObserver);
@@ -79,7 +79,7 @@
         */
         public onAfterRenderObservable = new Observable<number>();
 
-        private _onAfterRenderObserver: Observer<number>;
+        private _onAfterRenderObserver: Nullable<Observer<number>>;
         public set onAfterRender(callback: (faceIndex: number) => void) {
             if (this._onAfterRenderObserver) {
                 this.onAfterRenderObservable.remove(this._onAfterRenderObserver);
@@ -93,7 +93,7 @@
         */
         public onClearObservable = new Observable<Engine>();
 
-        private _onClearObserver: Observer<Engine>;
+        private _onClearObserver: Nullable<Observer<Engine>>;
         public set onClear(callback: (Engine: Engine) => void) {
             if (this._onClearObserver) {
                 this.onClearObservable.remove(this._onClearObserver);

+ 1 - 1
src/PostProcess/babylon.blurPostProcess.ts

@@ -43,7 +43,7 @@
 			return this._packedFloat;
 		}
 
-        constructor(name: string, public direction: Vector2, kernel: number, options: number | PostProcessOptions, camera: Camera, samplingMode: number = Texture.BILINEAR_SAMPLINGMODE, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
+        constructor(name: string, public direction: Vector2, kernel: number, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode: number = Texture.BILINEAR_SAMPLINGMODE, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
             super(name, "kernelBlur", ["delta", "direction"], null, options, camera, samplingMode, engine, reusable, null, textureType, "kernelBlur", {varyingCount: 0, depCount: 0}, true);
             this.onApplyObservable.add((effect: Effect) => {
                 effect.setFloat2('delta', (1 / this.width) * this.direction.x, (1 / this.height) * this.direction.y);

+ 8 - 8
src/PostProcess/babylon.postProcess.ts

@@ -49,7 +49,7 @@
         */
         public onActivateObservable = new Observable<Camera>();
 
-        private _onActivateObserver: Observer<Camera>;
+        private _onActivateObserver: Nullable<Observer<Camera>>;
         public set onActivate(callback: (camera: Camera) => void) {
             if (this._onActivateObserver) {
                 this.onActivateObservable.remove(this._onActivateObserver);
@@ -63,7 +63,7 @@
         */
         public onSizeChangedObservable = new Observable<PostProcess>();
 
-        private _onSizeChangedObserver: Observer<PostProcess>;
+        private _onSizeChangedObserver: Nullable<Observer<PostProcess>>;
         public set onSizeChanged(callback: (postProcess: PostProcess) => void) {
             if (this._onSizeChangedObserver) {
                 this.onSizeChangedObservable.remove(this._onSizeChangedObserver);
@@ -77,7 +77,7 @@
         */
         public onApplyObservable = new Observable<Effect>();
 
-        private _onApplyObserver: Observer<Effect>;
+        private _onApplyObserver: Nullable<Observer<Effect>>;
         public set onApply(callback: (effect: Effect) => void) {
             if (this._onApplyObserver) {
                 this.onApplyObservable.remove(this._onApplyObserver);
@@ -91,7 +91,7 @@
         */
         public onBeforeRenderObservable = new Observable<Effect>();
 
-        private _onBeforeRenderObserver: Observer<Effect>;
+        private _onBeforeRenderObserver: Nullable<Observer<Effect>>;
         public set onBeforeRender(callback: (effect: Effect) => void) {
             if (this._onBeforeRenderObserver) {
                 this.onBeforeRenderObservable.remove(this._onBeforeRenderObserver);
@@ -105,7 +105,7 @@
         */
         public onAfterRenderObservable = new Observable<Effect>();
 
-        private _onAfterRenderObserver: Observer<Effect>;
+        private _onAfterRenderObserver: Nullable<Observer<Effect>>;
         public set onAfterRender(callback: (efect: Effect) => void) {
             if (this._onAfterRenderObserver) {
                 this.onAfterRenderObservable.remove(this._onAfterRenderObserver);
@@ -138,7 +138,7 @@
         }
 
         constructor(public name: string, fragmentUrl: string, parameters: Nullable<string[]>, samplers: Nullable<string[]>, options: number | PostProcessOptions, camera: Nullable<Camera>, 
-                    samplingMode: number = Texture.NEAREST_SAMPLINGMODE, engine?: Engine, reusable?: boolean, defines?: string, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT, vertexUrl: string = "postprocess", indexParameters?: any, blockCompilation = false) {
+                    samplingMode: number = Texture.NEAREST_SAMPLINGMODE, engine?: Engine, reusable?: boolean, defines: Nullable<string> = null, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT, vertexUrl: string = "postprocess", indexParameters?: any, blockCompilation = false) {
             if (camera != null) {
                 this._camera = camera;
                 this._scene = camera.getScene();
@@ -189,13 +189,13 @@
             return this;
         }
         
-        public updateEffect(defines?: string, uniforms?: string[], samplers?: string[], indexParameters?: any,
+        public updateEffect(defines: Nullable<string> = null, uniforms: Nullable<string[]> = null, samplers: Nullable<string[]> = null, indexParameters?: any,
                             onCompiled?: (effect: Effect) => void, onError?: (effect: Effect, errors: string) => void) {
             this._effect = this._engine.createEffect({ vertex: this._vertexUrl, fragment: this._fragmentUrl },
                 ["position"],
                 uniforms || this._parameters,
                 samplers || this._samplers, 
-                defines !== undefined ? defines : "",
+                defines !== null ? defines : "",
                 undefined,
                 onCompiled,
                 onError,

+ 1 - 1
src/babylon.node.ts

@@ -77,7 +77,7 @@ module BABYLON {
         */
         public onDisposeObservable = new Observable<Node>();
 
-        private _onDisposeObserver: Observer<Node>;
+        private _onDisposeObserver: Nullable<Observer<Node>>;
         public set onDispose(callback: () => void) {
             if (this._onDisposeObserver) {
                 this.onDisposeObservable.remove(this._onDisposeObserver);