Ver código fonte

"They haven't told him it was impossible..They should have" step 8

David Catuhe 7 anos atrás
pai
commit
407b2d3f0f
43 arquivos alterados com 29714 adições e 29276 exclusões
  1. 4937 4937
      dist/preview release/babylon.d.ts
  2. 19 19
      dist/preview release/babylon.js
  3. 228 120
      dist/preview release/babylon.max.js
  4. 4937 4937
      dist/preview release/babylon.module.d.ts
  5. 19 19
      dist/preview release/babylon.worker.js
  6. 9369 9365
      dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts
  7. 35 35
      dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js
  8. 376 193
      dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js
  9. 9369 9365
      dist/preview release/customConfigurations/minimalGLTFViewer/babylon.module.d.ts
  10. 32 32
      dist/preview release/gui/babylon.gui.d.ts
  11. 32 32
      dist/preview release/gui/babylon.gui.module.d.ts
  12. 3 3
      src/Engine/babylon.engine.ts
  13. 1 1
      src/Materials/babylon.effect.ts
  14. 39 21
      src/Physics/Plugins/babylon.cannonJSPlugin.ts
  15. 22 11
      src/Physics/Plugins/babylon.oimoJSPlugin.ts
  16. 4 4
      src/Physics/babylon.physicsEngine.ts
  17. 5 5
      src/Physics/babylon.physicsImpostor.ts
  18. 3 3
      src/Physics/babylon.physicsJoint.ts
  19. 10 10
      src/PostProcess/RenderPipeline/Pipelines/babylon.defaultRenderingPipeline.ts
  20. 13 11
      src/PostProcess/RenderPipeline/Pipelines/babylon.lensRenderingPipeline.ts
  21. 18 2
      src/PostProcess/RenderPipeline/Pipelines/babylon.ssao2RenderingPipeline.ts
  22. 58 45
      src/PostProcess/RenderPipeline/Pipelines/babylon.standardRenderingPipeline.ts
  23. 39 19
      src/PostProcess/RenderPipeline/babylon.postProcessRenderEffect.ts
  24. 40 24
      src/PostProcess/RenderPipeline/babylon.postProcessRenderPipeline.ts
  25. 1 1
      src/PostProcess/RenderPipeline/babylon.postProcessRenderPipelineManager.ts
  26. 1 1
      src/PostProcess/babylon.anaglyphPostProcess.ts
  27. 1 1
      src/PostProcess/babylon.displayPassPostProcess.ts
  28. 1 1
      src/PostProcess/babylon.filterPostProcess.ts
  29. 1 1
      src/PostProcess/babylon.fxaaPostProcess.ts
  30. 1 1
      src/PostProcess/babylon.highlightsPostProcess.ts
  31. 4 4
      src/PostProcess/babylon.imageProcessingPostProcess.ts
  32. 4 2
      src/PostProcess/babylon.postProcess.ts
  33. 1 1
      src/PostProcess/babylon.stereoscopicInterlacePostProcess.ts
  34. 1 1
      src/PostProcess/babylon.tonemapPostProcess.ts
  35. 22 14
      src/PostProcess/babylon.volumetricLightScatteringPostProcess.ts
  36. 1 1
      src/PostProcess/babylon.vrDistortionCorrectionPostProcess.ts
  37. 5 3
      src/Probes/babylon.reflectionProbe.ts
  38. 9 6
      src/Rendering/babylon.boundingBoxRenderer.ts
  39. 14 7
      src/Rendering/babylon.depthRenderer.ts
  40. 10 5
      src/Rendering/babylon.edgesRenderer.ts
  41. 16 8
      src/Rendering/babylon.geometryBufferRenderer.ts
  42. 7 3
      src/Rendering/babylon.outlineRenderer.ts
  43. 6 2
      src/Rendering/babylon.renderingGroup.ts

Diferenças do arquivo suprimidas por serem muito extensas
+ 4937 - 4937
dist/preview release/babylon.d.ts


Diferenças do arquivo suprimidas por serem muito extensas
+ 19 - 19
dist/preview release/babylon.js


+ 228 - 120
dist/preview release/babylon.max.js

@@ -11336,7 +11336,7 @@ var BABYLON;
             this._bindTextureDirectly(this._gl.TEXTURE_2D, texture);
         };
         Engine.prototype.setTextureFromPostProcess = function (channel, postProcess) {
-            this._bindTexture(channel, postProcess._textures.data[postProcess._currentRenderTextureInd]);
+            this._bindTexture(channel, postProcess ? postProcess._textures.data[postProcess._currentRenderTextureInd] : null);
         };
         Engine.prototype.unbindAllTextures = function () {
             for (var channel = 0; channel < this._caps.maxTexturesImageUnits; channel++) {
@@ -16869,7 +16869,7 @@ var BABYLON;
                 subMesh = sortedArray[subIndex];
                 if (transparent) {
                     var material = subMesh.getMaterial();
-                    if (material.needDepthPrePass) {
+                    if (material && material.needDepthPrePass) {
                         var engine = material.getScene().getEngine();
                         engine.setColorWrite(false);
                         engine.setAlphaTesting(true);
@@ -16975,6 +16975,9 @@ var BABYLON;
         RenderingGroup.prototype.dispatch = function (subMesh) {
             var material = subMesh.getMaterial();
             var mesh = subMesh.getMesh();
+            if (!material) {
+                return;
+            }
             if (material.needAlphaBlending() || mesh.visibility < 1.0 || mesh.hasVertexAlpha) {
                 this._transparentSubMeshes.push(subMesh);
             }
@@ -32098,7 +32101,6 @@ var BABYLON;
                 defines.IMAGEPROCESSINGPOSTPROCESS = this.applyByPostProcess;
                 return;
             }
-            var engine = this.colorGradingTexture.getScene().getEngine();
             defines.VIGNETTE = this.vignetteEnabled;
             defines.VIGNETTEBLENDMODEMULTIPLY = (this.vignetteBlendMode === ImageProcessingConfiguration._VIGNETTEMODE_MULTIPLY);
             defines.VIGNETTEBLENDMODEOPAQUE = !defines.VIGNETTEBLENDMODEMULTIPLY;
@@ -32107,7 +32109,7 @@ var BABYLON;
             defines.EXPOSURE = (this.exposure !== 1.0);
             defines.COLORCURVES = (this.colorCurvesEnabled && !!this.colorCurves);
             defines.COLORGRADING = (this.colorGradingEnabled && !!this.colorGradingTexture);
-            defines.COLORGRADING3D = defines.COLORGRADING && (engine.webGLVersion > 1);
+            defines.COLORGRADING3D = defines.COLORGRADING && (this.colorGradingTexture.getScene().getEngine().webGLVersion > 1);
             defines.SAMPLER3DGREENDEPTH = this.colorGradingWithGreenDepth;
             defines.SAMPLER3DBGRMAP = this.colorGradingBGR;
             defines.IMAGEPROCESSINGPOSTPROCESS = this.applyByPostProcess;
@@ -50454,7 +50456,9 @@ var BABYLON;
                 if (this._onActivateObserver) {
                     this.onActivateObservable.remove(this._onActivateObserver);
                 }
-                this._onActivateObserver = this.onActivateObservable.add(callback);
+                if (callback) {
+                    this._onActivateObserver = this.onActivateObservable.add(callback);
+                }
             },
             enumerable: true,
             configurable: true
@@ -56548,6 +56552,7 @@ var BABYLON;
             this._renderPipelines[renderPipeline._name] = renderPipeline;
         };
         PostProcessRenderPipelineManager.prototype.attachCamerasToRenderPipeline = function (renderPipelineName, cameras, unique) {
+            if (unique === void 0) { unique = false; }
             var renderPipeline = this._renderPipelines[renderPipelineName];
             if (!renderPipeline) {
                 return;
@@ -56727,9 +56732,12 @@ var BABYLON;
         };
         PostProcessRenderEffect.prototype._attachCameras = function (cameras) {
             var cameraKey;
-            var _cam = BABYLON.Tools.MakeArray(cameras || this._cameras);
-            for (var i = 0; i < _cam.length; i++) {
-                var camera = _cam[i];
+            var cams = BABYLON.Tools.MakeArray(cameras || this._cameras);
+            if (!cams) {
+                return;
+            }
+            for (var i = 0; i < cams.length; i++) {
+                var camera = cams[i];
                 var cameraName = camera.name;
                 if (this._singleInstance) {
                     cameraKey = 0;
@@ -56753,9 +56761,12 @@ var BABYLON;
             this._linkParameters();
         };
         PostProcessRenderEffect.prototype._detachCameras = function (cameras) {
-            var _cam = BABYLON.Tools.MakeArray(cameras || this._cameras);
-            for (var i = 0; i < _cam.length; i++) {
-                var camera = _cam[i];
+            var cams = BABYLON.Tools.MakeArray(cameras || this._cameras);
+            if (!cams) {
+                return;
+            }
+            for (var i = 0; i < cams.length; i++) {
+                var camera = cams[i];
                 var cameraName = camera.name;
                 camera.detachPostProcess(this._postProcesses[this._singleInstance ? 0 : cameraName]);
                 if (this._cameras[cameraName]) {
@@ -56768,9 +56779,12 @@ var BABYLON;
             }
         };
         PostProcessRenderEffect.prototype._enable = function (cameras) {
-            var _cam = BABYLON.Tools.MakeArray(cameras || this._cameras);
-            for (var i = 0; i < _cam.length; i++) {
-                var camera = _cam[i];
+            var cams = BABYLON.Tools.MakeArray(cameras || this._cameras);
+            if (!cams) {
+                return;
+            }
+            for (var i = 0; i < cams.length; i++) {
+                var camera = cams[i];
                 var cameraName = camera.name;
                 for (var j = 0; j < this._indicesForCamera[cameraName].length; j++) {
                     if (camera._postProcesses[this._indicesForCamera[cameraName][j]] === undefined) {
@@ -56783,9 +56797,12 @@ var BABYLON;
             }
         };
         PostProcessRenderEffect.prototype._disable = function (cameras) {
-            var _cam = BABYLON.Tools.MakeArray(cameras || this._cameras);
-            for (var i = 0; i < _cam.length; i++) {
-                var camera = _cam[i];
+            var cams = BABYLON.Tools.MakeArray(cameras || this._cameras);
+            if (!cams) {
+                return;
+            }
+            for (var i = 0; i < cams.length; i++) {
+                var camera = cams[i];
                 var cameraName = camera.Name;
                 camera.detachPostProcess(this._postProcesses[this._singleInstance ? 0 : cameraName]);
                 for (var passName in this._renderPasses) {
@@ -56798,6 +56815,9 @@ var BABYLON;
                 return this._postProcesses[0];
             }
             else {
+                if (!camera) {
+                    return null;
+                }
                 return this._postProcesses[camera.name];
             }
         };
@@ -56876,11 +56896,14 @@ var BABYLON;
             renderEffects._disable(BABYLON.Tools.MakeArray(cameras || this._cameras));
         };
         PostProcessRenderPipeline.prototype._attachCameras = function (cameras, unique) {
-            var _cam = BABYLON.Tools.MakeArray(cameras || this._cameras);
+            var cams = BABYLON.Tools.MakeArray(cameras || this._cameras);
+            if (!cams) {
+                return;
+            }
             var indicesToDelete = [];
             var i;
-            for (i = 0; i < _cam.length; i++) {
-                var camera = _cam[i];
+            for (i = 0; i < cams.length; i++) {
+                var camera = cams[i];
                 var cameraName = camera.name;
                 if (this._cameras.indexOf(camera) === -1) {
                     this._cameras[cameraName] = camera;
@@ -56894,24 +56917,30 @@ var BABYLON;
             }
             for (var renderEffectName in this._renderEffects) {
                 if (this._renderEffects.hasOwnProperty(renderEffectName)) {
-                    this._renderEffects[renderEffectName]._attachCameras(_cam);
+                    this._renderEffects[renderEffectName]._attachCameras(cams);
                 }
             }
         };
         PostProcessRenderPipeline.prototype._detachCameras = function (cameras) {
-            var _cam = BABYLON.Tools.MakeArray(cameras || this._cameras);
+            var cams = BABYLON.Tools.MakeArray(cameras || this._cameras);
+            if (!cams) {
+                return;
+            }
             for (var renderEffectName in this._renderEffects) {
                 if (this._renderEffects.hasOwnProperty(renderEffectName)) {
-                    this._renderEffects[renderEffectName]._detachCameras(_cam);
+                    this._renderEffects[renderEffectName]._detachCameras(cams);
                 }
             }
-            for (var i = 0; i < _cam.length; i++) {
-                this._cameras.splice(this._cameras.indexOf(_cam[i]), 1);
+            for (var i = 0; i < cams.length; i++) {
+                this._cameras.splice(this._cameras.indexOf(cams[i]), 1);
             }
         };
         PostProcessRenderPipeline.prototype._enableDisplayOnlyPass = function (passName, cameras) {
             var _this = this;
-            var _cam = BABYLON.Tools.MakeArray(cameras || this._cameras);
+            var cams = BABYLON.Tools.MakeArray(cameras || this._cameras);
+            if (!cams) {
+                return;
+            }
             var pass = null;
             var renderEffectName;
             for (renderEffectName in this._renderEffects) {
@@ -56927,14 +56956,14 @@ var BABYLON;
             }
             for (renderEffectName in this._renderEffects) {
                 if (this._renderEffects.hasOwnProperty(renderEffectName)) {
-                    this._renderEffects[renderEffectName]._disable(_cam);
+                    this._renderEffects[renderEffectName]._disable(cams);
                 }
             }
             pass._name = PostProcessRenderPipeline.PASS_SAMPLER_NAME;
-            for (var i = 0; i < _cam.length; i++) {
-                var camera = _cam[i];
+            for (var i = 0; i < cams.length; i++) {
+                var camera = cams[i];
                 var cameraName = camera.name;
-                this._renderEffectsForIsolatedPass[cameraName] = this._renderEffectsForIsolatedPass[cameraName] || new BABYLON.PostProcessRenderEffect(this._engine, PostProcessRenderPipeline.PASS_EFFECT_NAME, function () { return new BABYLON.DisplayPassPostProcess(PostProcessRenderPipeline.PASS_EFFECT_NAME, 1.0, null, null, _this._engine, true); });
+                this._renderEffectsForIsolatedPass[cameraName] = this._renderEffectsForIsolatedPass[cameraName] || new BABYLON.PostProcessRenderEffect(this._engine, PostProcessRenderPipeline.PASS_EFFECT_NAME, function () { return new BABYLON.DisplayPassPostProcess(PostProcessRenderPipeline.PASS_EFFECT_NAME, 1.0, null, undefined, _this._engine, true); });
                 this._renderEffectsForIsolatedPass[cameraName].emptyPasses();
                 this._renderEffectsForIsolatedPass[cameraName].addPass(pass);
                 this._renderEffectsForIsolatedPass[cameraName]._attachCameras(camera);
@@ -56942,16 +56971,19 @@ var BABYLON;
         };
         PostProcessRenderPipeline.prototype._disableDisplayOnlyPass = function (cameras) {
             var _this = this;
-            var _cam = BABYLON.Tools.MakeArray(cameras || this._cameras);
-            for (var i = 0; i < _cam.length; i++) {
-                var camera = _cam[i];
+            var cams = BABYLON.Tools.MakeArray(cameras || this._cameras);
+            if (!cams) {
+                return;
+            }
+            for (var i = 0; i < cams.length; i++) {
+                var camera = cams[i];
                 var cameraName = camera.name;
-                this._renderEffectsForIsolatedPass[cameraName] = this._renderEffectsForIsolatedPass[cameraName] || new BABYLON.PostProcessRenderEffect(this._engine, PostProcessRenderPipeline.PASS_EFFECT_NAME, function () { return new BABYLON.DisplayPassPostProcess(PostProcessRenderPipeline.PASS_EFFECT_NAME, 1.0, null, null, _this._engine, true); });
+                this._renderEffectsForIsolatedPass[cameraName] = this._renderEffectsForIsolatedPass[cameraName] || new BABYLON.PostProcessRenderEffect(this._engine, PostProcessRenderPipeline.PASS_EFFECT_NAME, function () { return new BABYLON.DisplayPassPostProcess(PostProcessRenderPipeline.PASS_EFFECT_NAME, 1.0, null, undefined, _this._engine, true); });
                 this._renderEffectsForIsolatedPass[cameraName]._disable(camera);
             }
             for (var renderEffectName in this._renderEffects) {
                 if (this._renderEffects.hasOwnProperty(renderEffectName)) {
-                    this._renderEffects[renderEffectName]._enable(_cam);
+                    this._renderEffects[renderEffectName]._enable(cams);
                 }
             }
         };
@@ -57011,28 +57043,33 @@ var BABYLON;
                 var mesh = subMesh.getRenderingMesh();
                 var scene = _this._scene;
                 var engine = scene.getEngine();
+                var material = subMesh.getMaterial();
+                if (!material) {
+                    return;
+                }
                 // Culling
-                engine.setState(subMesh.getMaterial().backFaceCulling);
+                engine.setState(material.backFaceCulling);
                 // Managing instances
                 var batch = mesh._getInstancesRenderList(subMesh._id);
                 if (batch.mustReturn) {
                     return;
                 }
                 var hardwareInstancedRendering = (engine.getCaps().instancedArrays) && (batch.visibleInstances[subMesh._id] !== null);
-                if (_this.isReady(subMesh, hardwareInstancedRendering)) {
+                if (_this.isReady(subMesh, hardwareInstancedRendering) && scene.activeCamera) {
                     engine.enableEffect(_this._effect);
                     mesh._bind(subMesh, _this._effect, BABYLON.Material.TriangleFillMode);
-                    var material = subMesh.getMaterial();
                     _this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
                     _this._effect.setFloat2("depthValues", scene.activeCamera.minZ, scene.activeCamera.minZ + scene.activeCamera.maxZ);
                     // Alpha test
                     if (material && material.needAlphaTesting()) {
                         var alphaTexture = material.getAlphaTestTexture();
-                        _this._effect.setTexture("diffuseSampler", alphaTexture);
-                        _this._effect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
+                        if (alphaTexture) {
+                            _this._effect.setTexture("diffuseSampler", alphaTexture);
+                            _this._effect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
+                        }
                     }
                     // Bones
-                    if (mesh.useBones && mesh.computeBonesUsingShaders) {
+                    if (mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {
                         _this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
                     }
                     // Draw
@@ -57085,7 +57122,7 @@ var BABYLON;
                     attribs.push(BABYLON.VertexBuffer.MatricesWeightsExtraKind);
                 }
                 defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
-                defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
+                defines.push("#define BonesPerMesh " + (mesh.skeleton ? mesh.skeleton.bones.length + 1 : 0));
             }
             else {
                 defines.push("#define NUM_BONE_INFLUENCERS 0");
@@ -57466,9 +57503,10 @@ var BABYLON;
                 blurRatio: blurRatio
             };
             // Set up assets
+            var geometryBufferRenderer = scene.enableGeometryBufferRenderer();
             _this._createRandomTexture();
-            _this._depthTexture = scene.enableGeometryBufferRenderer().getGBuffer().textures[0];
-            _this._normalTexture = scene.enableGeometryBufferRenderer().getGBuffer().textures[1];
+            _this._depthTexture = geometryBufferRenderer.getGBuffer().textures[0];
+            _this._normalTexture = geometryBufferRenderer.getGBuffer().textures[1];
             _this._originalColorPostProcess = new BABYLON.PassPostProcess("SSAOOriginalSceneColor", 1.0, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
             _this._createSSAOPostProcess(1.0);
             _this._createBlurPostProcess(ssaoRatio, blurRatio);
@@ -57518,6 +57556,9 @@ var BABYLON;
             */
             get: function () {
                 var engine = BABYLON.Engine.LastCreatedEngine;
+                if (!engine) {
+                    return false;
+                }
                 return engine.getCaps().drawBuffersExtension;
             },
             enumerable: true,
@@ -57553,6 +57594,9 @@ var BABYLON;
             }
             this._blurHPostProcess = new BABYLON.PostProcess("BlurH", "ssao2", ["outSize", "samplerOffsets", "near", "far", "radius"], ["depthSampler"], ssaoRatio, null, BABYLON.Texture.TRILINEAR_SAMPLINGMODE, this._scene.getEngine(), false, "#define BILATERAL_BLUR\n#define BILATERAL_BLUR_H\n#define SAMPLES 16\n#define EXPENSIVE " + (expensive ? "1" : "0") + "\n");
             this._blurHPostProcess.onApply = function (effect) {
+                if (!_this._scene.activeCamera) {
+                    return;
+                }
                 effect.setFloat("outSize", _this._ssaoCombinePostProcess.width);
                 effect.setFloat("near", _this._scene.activeCamera.minZ);
                 effect.setFloat("far", _this._scene.activeCamera.maxZ);
@@ -57564,6 +57608,9 @@ var BABYLON;
             };
             this._blurVPostProcess = new BABYLON.PostProcess("BlurV", "ssao2", ["outSize", "samplerOffsets", "near", "far", "radius"], ["depthSampler"], blurRatio, null, BABYLON.Texture.TRILINEAR_SAMPLINGMODE, this._scene.getEngine(), false, "#define BILATERAL_BLUR\n#define BILATERAL_BLUR_V\n#define SAMPLES 16\n#define EXPENSIVE " + (expensive ? "1" : "0") + "\n");
             this._blurVPostProcess.onApply = function (effect) {
+                if (!_this._scene.activeCamera) {
+                    return;
+                }
                 effect.setFloat("outSize", _this._ssaoCombinePostProcess.height);
                 effect.setFloat("near", _this._scene.activeCamera.minZ);
                 effect.setFloat("far", _this._scene.activeCamera.maxZ);
@@ -57612,6 +57659,9 @@ var BABYLON;
                     effect.setArray3("sampleSphere", _this._sampleSphere);
                     effect.setFloat("randTextureTiles", 4.0);
                 }
+                if (!_this._scene.activeCamera) {
+                    return;
+                }
                 effect.setFloat("samplesFactor", 1 / _this.samples);
                 effect.setFloat("totalStrength", _this.totalStrength);
                 effect.setFloat2("texelSize", 1 / _this._ssaoPostProcess.width, 1 / _this._ssaoPostProcess.height);
@@ -57833,9 +57883,9 @@ var BABYLON;
         LensRenderingPipeline.prototype.dispose = function (disableDepthRender) {
             if (disableDepthRender === void 0) { disableDepthRender = false; }
             this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, this._scene.cameras);
-            this._chromaticAberrationPostProcess = undefined;
-            this._highlightsPostProcess = undefined;
-            this._depthOfFieldPostProcess = undefined;
+            this._chromaticAberrationPostProcess = null;
+            this._highlightsPostProcess = null;
+            this._depthOfFieldPostProcess = null;
             this._grainTexture.dispose();
             if (disableDepthRender)
                 this._scene.disableDepthRenderer();
@@ -57848,8 +57898,8 @@ var BABYLON;
             ratio, null, BABYLON.Texture.TRILINEAR_SAMPLINGMODE, this._scene.getEngine(), false);
             this._chromaticAberrationPostProcess.onApply = function (effect) {
                 effect.setFloat('chromatic_aberration', _this._chromaticAberration);
-                effect.setFloat('screen_width', _this._scene.getEngine().getRenderingCanvas().width);
-                effect.setFloat('screen_height', _this._scene.getEngine().getRenderingCanvas().height);
+                effect.setFloat('screen_width', _this._scene.getEngine().getRenderWidth());
+                effect.setFloat('screen_height', _this._scene.getEngine().getRenderHeight());
             };
         };
         // highlights enhancing
@@ -57862,8 +57912,8 @@ var BABYLON;
                 effect.setFloat('gain', _this._highlightsGain);
                 effect.setFloat('threshold', _this._highlightsThreshold);
                 effect.setTextureFromPostProcess("textureSampler", _this._chromaticAberrationPostProcess);
-                effect.setFloat('screen_width', _this._scene.getEngine().getRenderingCanvas().width);
-                effect.setFloat('screen_height', _this._scene.getEngine().getRenderingCanvas().height);
+                effect.setFloat('screen_width', _this._scene.getEngine().getRenderWidth());
+                effect.setFloat('screen_height', _this._scene.getEngine().getRenderHeight());
             };
         };
         // colors shifting and distortion
@@ -57880,8 +57930,8 @@ var BABYLON;
                 effect.setTextureFromPostProcess("highlightsSampler", _this._depthOfFieldPostProcess);
                 effect.setFloat('grain_amount', _this._grainAmount);
                 effect.setBool('blur_noise', _this._blurNoise);
-                effect.setFloat('screen_width', _this._scene.getEngine().getRenderingCanvas().width);
-                effect.setFloat('screen_height', _this._scene.getEngine().getRenderingCanvas().height);
+                effect.setFloat('screen_width', _this._scene.getEngine().getRenderWidth());
+                effect.setFloat('screen_height', _this._scene.getEngine().getRenderHeight());
                 effect.setFloat('distortion', _this._distortion);
                 effect.setBool('dof_enabled', (_this._dofDistance !== -1));
                 effect.setFloat('screen_distance', 1.0 / (0.1 - 1.0 / _this._dofDistance));
@@ -57889,8 +57939,10 @@ var BABYLON;
                 effect.setFloat('darken', _this._dofDarken);
                 effect.setFloat('edge_blur', _this._edgeBlur);
                 effect.setBool('highlights', (_this._highlightsGain !== -1));
-                effect.setFloat('near', _this._scene.activeCamera.minZ);
-                effect.setFloat('far', _this._scene.activeCamera.maxZ);
+                if (_this._scene.activeCamera) {
+                    effect.setFloat('near', _this._scene.activeCamera.minZ);
+                    effect.setFloat('far', _this._scene.activeCamera.maxZ);
+                }
             };
         };
         // creates a black and white random noise texture, 512x512
@@ -58201,10 +58253,12 @@ var BABYLON;
             this.downSampleX4PostProcess = new BABYLON.PostProcess("HDRDownSampleX4", "standard", ["dsOffsets"], [], ratio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, "#define DOWN_SAMPLE_X4", BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT);
             this.downSampleX4PostProcess.onApply = function (effect) {
                 var id = 0;
+                var width = _this.downSampleX4PostProcess.width;
+                var height = _this.downSampleX4PostProcess.height;
                 for (var i = -2; i < 2; i++) {
                     for (var j = -2; j < 2; j++) {
-                        downSampleX4Offsets[id] = (i + 0.5) * (1.0 / _this.downSampleX4PostProcess.width);
-                        downSampleX4Offsets[id + 1] = (j + 0.5) * (1.0 / _this.downSampleX4PostProcess.height);
+                        downSampleX4Offsets[id] = (i + 0.5) * (1.0 / width);
+                        downSampleX4Offsets[id + 1] = (j + 0.5) * (1.0 / height);
                         id += 2;
                     }
                 }
@@ -58243,11 +58297,11 @@ var BABYLON;
             var blurX = new BABYLON.BlurPostProcess("HDRBlurH" + "_" + indice, new BABYLON.Vector2(1, 0), this[blurWidthKey], ratio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT);
             var blurY = new BABYLON.BlurPostProcess("HDRBlurV" + "_" + indice, new BABYLON.Vector2(0, 1), this[blurWidthKey], ratio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT);
             blurX.onActivateObservable.add(function () {
-                var dw = blurX.width / engine.getRenderingCanvas().width;
+                var dw = blurX.width / engine.getRenderWidth();
                 blurX.kernel = _this[blurWidthKey] * dw;
             });
             blurY.onActivateObservable.add(function () {
-                var dw = blurY.height / engine.getRenderingCanvas().height;
+                var dw = blurY.height / engine.getRenderHeight();
                 blurY.kernel = _this.horizontalBlur ? 64 * dw : _this[blurWidthKey] * dw;
             });
             this.addEffect(new BABYLON.PostProcessRenderEffect(scene.getEngine(), "HDRBlurH" + indice, function () { return blurX; }, true));
@@ -58277,13 +58331,13 @@ var BABYLON;
             this.volumetricLightPostProcess = new BABYLON.PostProcess("HDRVLS", "standard", ["shadowViewProjection", "cameraPosition", "sunDirection", "sunColor", "scatteringCoefficient", "scatteringPower", "depthValues"], ["shadowMapSampler", "positionSampler"], ratio / 8, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, "#define VLS\n#define NB_STEPS " + this._volumetricLightStepsCount.toFixed(1));
             var depthValues = BABYLON.Vector2.Zero();
             this.volumetricLightPostProcess.onApply = function (effect) {
-                if (_this.sourceLight && _this.sourceLight.getShadowGenerator()) {
+                if (_this.sourceLight && _this.sourceLight.getShadowGenerator() && _this._scene.activeCamera) {
                     var generator = _this.sourceLight.getShadowGenerator();
                     effect.setTexture("shadowMapSampler", generator.getShadowMap());
                     effect.setTexture("positionSampler", geometry.textures[2]);
                     effect.setColor3("sunColor", _this.sourceLight.diffuse);
                     effect.setVector3("sunDirection", _this.sourceLight.getShadowDirection());
-                    effect.setVector3("cameraPosition", scene.activeCamera.globalPosition);
+                    effect.setVector3("cameraPosition", _this._scene.activeCamera.globalPosition);
                     effect.setMatrix("shadowViewProjection", generator.getTransformMatrix());
                     effect.setFloat("scatteringCoefficient", _this.volumetricLightCoefficient);
                     effect.setFloat("scatteringPower", _this.volumetricLightPower);
@@ -58340,6 +58394,9 @@ var BABYLON;
             this.luminanceDownSamplePostProcesses.forEach(function (pp, index) {
                 var downSampleOffsets = new Array(18);
                 pp.onApply = function (effect) {
+                    if (!lastLuminance) {
+                        return;
+                    }
                     var id = 0;
                     for (var x = -1; x < 2; x++) {
                         for (var y = -1; y < 2; y++) {
@@ -58425,6 +58482,9 @@ var BABYLON;
             var scaleBias1 = BABYLON.Matrix.FromValues(2.0, 0.0, -1.0, 0.0, 0.0, 2.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0);
             var scaleBias2 = BABYLON.Matrix.FromValues(0.5, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0);
             this.lensFlareComposePostProcess.onApply = function (effect) {
+                if (!_this._scene.activeCamera) {
+                    return;
+                }
                 effect.setTextureFromPostProcess("otherSampler", _this._currentDepthOfFieldSource);
                 effect.setTexture("lensDirtSampler", _this.lensFlareDirtTexture);
                 effect.setTexture("lensStarSampler", _this.lensStarTexture);
@@ -58478,7 +58538,8 @@ var BABYLON;
         };
         StandardRenderingPipeline.prototype._getDepthTexture = function () {
             if (this._scene.getEngine().getCaps().drawBuffersExtension) {
-                return this._scene.enableGeometryBufferRenderer().getGBuffer().textures[0];
+                var renderer = this._scene.enableGeometryBufferRenderer();
+                return renderer.getGBuffer().textures[0];
             }
             return this._scene.enableDepthRenderer().getDepthMap();
         };
@@ -58688,6 +58749,7 @@ var BABYLON;
     var FxaaPostProcess = /** @class */ (function (_super) {
         __extends(FxaaPostProcess, _super);
         function FxaaPostProcess(name, options, camera, samplingMode, engine, reusable, textureType) {
+            if (camera === void 0) { camera = null; }
             if (textureType === void 0) { textureType = BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT; }
             var _this = _super.call(this, name, "fxaa", ["texelSize"], null, options, camera, samplingMode || BABYLON.Texture.BILINEAR_SAMPLINGMODE, engine, reusable, null, textureType, "fxaa") || this;
             _this.onApplyObservable.add(function (effect) {
@@ -58874,7 +58936,7 @@ var BABYLON;
                 this.blurX.alwaysForcePOT = true;
                 this.blurX.autoClear = false;
                 this.blurX.onActivateObservable.add(function () {
-                    var dw = _this.blurX.width / engine.getRenderingCanvas().width;
+                    var dw = _this.blurX.width / engine.getRenderWidth(true);
                     _this.blurX.kernel = _this.bloomKernel * dw;
                 });
                 this.blurY = new BABYLON.BlurPostProcess("vertical blur", new BABYLON.Vector2(0, 1.0), 10.0, this.bloomScale, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, engine, false, this._defaultPipelineTextureType);
@@ -58882,7 +58944,7 @@ var BABYLON;
                 this.blurY.alwaysForcePOT = true;
                 this.blurY.autoClear = false;
                 this.blurY.onActivateObservable.add(function () {
-                    var dh = _this.blurY.height / engine.getRenderingCanvas().height;
+                    var dh = _this.blurY.height / engine.getRenderHeight(true);
                     _this.blurY.kernel = _this.bloomKernel * dh;
                 });
                 this.copyBack = new BABYLON.PassPostProcess("bloomBlendBlit", this.bloomScale, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, engine, false, this._defaultPipelineTextureType);
@@ -59098,7 +59160,7 @@ var BABYLON;
                     attribs.push(BABYLON.VertexBuffer.MatricesWeightsExtraKind);
                 }
                 defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
-                defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
+                defines.push("#define BonesPerMesh " + (mesh.skeleton ? mesh.skeleton.bones.length + 1 : 0));
             }
             else {
                 defines.push("#define NUM_BONE_INFLUENCERS 0");
@@ -59115,7 +59177,7 @@ var BABYLON;
             var join = defines.join("\n");
             if (this._cachedDefines !== join) {
                 this._cachedDefines = join;
-                this._effect = this._scene.getEngine().createEffect("geometry", attribs, ["world", "mBones", "viewProjection", "diffuseMatrix", "view"], ["diffuseSampler"], join, null, null, null, { buffersCount: this._enablePosition ? 3 : 2 });
+                this._effect = this._scene.getEngine().createEffect("geometry", attribs, ["world", "mBones", "viewProjection", "diffuseMatrix", "view"], ["diffuseSampler"], join, undefined, undefined, undefined, { buffersCount: this._enablePosition ? 3 : 2 });
             }
             return this._effect.isReady();
         };
@@ -59132,7 +59194,7 @@ var BABYLON;
             var count = this._enablePosition ? 3 : 2;
             this._multiRenderTarget = new BABYLON.MultiRenderTarget("gBuffer", { width: engine.getRenderWidth() * this._ratio, height: engine.getRenderHeight() * this._ratio }, count, this._scene, { generateMipMaps: false, generateDepthTexture: true });
             if (!this.isSupported) {
-                return null;
+                return;
             }
             this._multiRenderTarget.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
             this._multiRenderTarget.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
@@ -59148,8 +59210,12 @@ var BABYLON;
                 var mesh = subMesh.getRenderingMesh();
                 var scene = _this._scene;
                 var engine = scene.getEngine();
+                var material = subMesh.getMaterial();
+                if (!material) {
+                    return;
+                }
                 // Culling
-                engine.setState(subMesh.getMaterial().backFaceCulling);
+                engine.setState(material.backFaceCulling);
                 // Managing instances
                 var batch = mesh._getInstancesRenderList(subMesh._id);
                 if (batch.mustReturn) {
@@ -59159,17 +59225,18 @@ var BABYLON;
                 if (_this.isReady(subMesh, hardwareInstancedRendering)) {
                     engine.enableEffect(_this._effect);
                     mesh._bind(subMesh, _this._effect, BABYLON.Material.TriangleFillMode);
-                    var material = subMesh.getMaterial();
                     _this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
                     _this._effect.setMatrix("view", scene.getViewMatrix());
                     // Alpha test
                     if (material && material.needAlphaTesting()) {
                         var alphaTexture = material.getAlphaTestTexture();
-                        _this._effect.setTexture("diffuseSampler", alphaTexture);
-                        _this._effect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
+                        if (alphaTexture) {
+                            _this._effect.setTexture("diffuseSampler", alphaTexture);
+                            _this._effect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
+                        }
                     }
                     // Bones
-                    if (mesh.useBones && mesh.computeBonesUsingShaders) {
+                    if (mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {
                         _this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
                     }
                     // Draw
@@ -59371,11 +59438,11 @@ var BABYLON;
             * @type {number}
             */
             _this.density = 0.926;
-            scene = (camera === null) ? scene : camera.getScene(); // parameter "scene" can be null.
-            var engine = scene.getEngine();
+            scene = ((camera === null) ? scene : camera.getScene()); // parameter "scene" can be null.
+            engine = scene.getEngine();
             _this._viewPort = new BABYLON.Viewport(0, 0, 1, 1).toGlobal(engine.getRenderWidth(), engine.getRenderHeight());
             // Configure mesh
-            _this.mesh = (mesh !== null) ? mesh : VolumetricLightScatteringPostProcess.CreateDefaultMesh("VolumetricLightScatteringMesh", scene);
+            _this.mesh = ((mesh !== null) ? mesh : VolumetricLightScatteringPostProcess.CreateDefaultMesh("VolumetricLightScatteringMesh", scene));
             // Configure
             _this._createPass(scene, ratio.passRatio || ratio);
             _this.onActivate = function (camera) {
@@ -59412,7 +59479,7 @@ var BABYLON;
         VolumetricLightScatteringPostProcess.prototype.isReady = function (subMesh, useInstances) {
             var mesh = subMesh.getMesh();
             // Render this.mesh as default
-            if (mesh === this.mesh) {
+            if (mesh === this.mesh && mesh.material) {
                 return mesh.material.isReady(mesh);
             }
             var defines = [];
@@ -59437,7 +59504,7 @@ var BABYLON;
                 attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
                 attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
                 defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
-                defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
+                defines.push("#define BonesPerMesh " + (mesh.skeleton ? (mesh.skeleton.bones.length + 1) : 0));
             }
             else {
                 defines.push("#define NUM_BONE_INFLUENCERS 0");
@@ -59518,10 +59585,14 @@ var BABYLON;
                 if (_this._meshExcluded(mesh)) {
                     return;
                 }
+                var material = subMesh.getMaterial();
+                if (!material) {
+                    return;
+                }
                 var scene = mesh.getScene();
                 var engine = scene.getEngine();
                 // Culling
-                engine.setState(subMesh.getMaterial().backFaceCulling);
+                engine.setState(material.backFaceCulling);
                 // Managing instances
                 var batch = mesh._getInstancesRenderList(subMesh._id);
                 if (batch.mustReturn) {
@@ -59535,16 +59606,15 @@ var BABYLON;
                             effect = subMesh.effect;
                         }
                         else {
-                            effect = subMesh.getMaterial().getEffect();
+                            effect = material.getEffect();
                         }
                     }
                     engine.enableEffect(effect);
                     mesh._bind(subMesh, effect, BABYLON.Material.TriangleFillMode);
                     if (mesh === _this.mesh) {
-                        subMesh.getMaterial().bind(mesh.getWorldMatrix(), mesh);
+                        material.bind(mesh.getWorldMatrix(), mesh);
                     }
                     else {
-                        var material = subMesh.getMaterial();
                         _this._volumetricLightScatteringPass.setMatrix("viewProjection", scene.getTransformMatrix());
                         // Alpha test
                         if (material && material.needAlphaTesting()) {
@@ -59555,7 +59625,7 @@ var BABYLON;
                             }
                         }
                         // Bones
-                        if (mesh.useBones && mesh.computeBonesUsingShaders) {
+                        if (mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {
                             _this._volumetricLightScatteringPass.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
                         }
                     }
@@ -59595,8 +59665,11 @@ var BABYLON;
                     // Sort sub meshes
                     for (index = 0; index < transparentSubMeshes.length; index++) {
                         var submesh = transparentSubMeshes.data[index];
-                        submesh._alphaIndex = submesh.getMesh().alphaIndex;
-                        submesh._distanceToCamera = submesh.getBoundingInfo().boundingSphere.centerWorld.subtract(scene.activeCamera.position).length();
+                        var boundingInfo = submesh.getBoundingInfo();
+                        if (boundingInfo && scene.activeCamera) {
+                            submesh._alphaIndex = submesh.getMesh().alphaIndex;
+                            submesh._distanceToCamera = boundingInfo.boundingSphere.centerWorld.subtract(scene.activeCamera.position).length();
+                        }
                     }
                     var sortedArray = transparentSubMeshes.data.slice(0, transparentSubMeshes.length);
                     sortedArray.sort(function (a, b) {
@@ -59744,7 +59817,7 @@ var BABYLON;
         function TonemapPostProcess(name, _operator, exposureAdjustment, camera, samplingMode, engine, textureFormat) {
             if (samplingMode === void 0) { samplingMode = BABYLON.Texture.BILINEAR_SAMPLINGMODE; }
             if (textureFormat === void 0) { textureFormat = BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT; }
-            var _this = _super.call(this, name, "tonemap", ["_ExposureAdjustment"], null, 1.0, camera, samplingMode, engine, true, defines, textureFormat) || this;
+            var _this = _super.call(this, name, "tonemap", ["_ExposureAdjustment"], null, 1.0, camera, samplingMode, engine, true, null, textureFormat) || this;
             _this._operator = _operator;
             _this.exposureAdjustment = exposureAdjustment;
             var defines = "#define ";
@@ -59812,6 +59885,7 @@ var BABYLON;
     var ImageProcessingPostProcess = /** @class */ (function (_super) {
         __extends(ImageProcessingPostProcess, _super);
         function ImageProcessingPostProcess(name, options, camera, samplingMode, engine, reusable, textureType) {
+            if (camera === void 0) { camera = null; }
             if (textureType === void 0) { textureType = BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT; }
             var _this = _super.call(this, name, "imageProcessing", [], [], options, camera, samplingMode, engine, reusable, null, textureType, "postprocess", null, true) || this;
             _this._fromLinearSpace = true;
@@ -65110,7 +65184,7 @@ var BABYLON;
          * @param {number} maxForce max force for this motor.
          */
         MotorEnabledJoint.prototype.setMotor = function (force, maxForce) {
-            this._physicsPlugin.setMotor(this, force, maxForce);
+            this._physicsPlugin.setMotor(this, force || 0, maxForce);
         };
         /**
          * Set the motor's limits.
@@ -65137,7 +65211,7 @@ var BABYLON;
          * @param {number} maxForce max force for this motor.
          */
         HingeJoint.prototype.setMotor = function (force, maxForce) {
-            this._physicsPlugin.setMotor(this, force, maxForce);
+            this._physicsPlugin.setMotor(this, force || 0, maxForce);
         };
         /**
          * Set the motor's limits.
@@ -65166,7 +65240,7 @@ var BABYLON;
          */
         Hinge2Joint.prototype.setMotor = function (force, maxForce, motorIndex) {
             if (motorIndex === void 0) { motorIndex = 0; }
-            this._physicsPlugin.setMotor(this, force, maxForce, motorIndex);
+            this._physicsPlugin.setMotor(this, force || 0, maxForce, motorIndex);
         };
         /**
          * Set the motor limits.
@@ -66030,6 +66104,9 @@ var BABYLON;
             var currentRotation = mainImpostor.object.rotationQuaternion;
             if (meshChildren.length) {
                 var processMesh = function (localPosition, mesh) {
+                    if (!currentRotation || !mesh.rotationQuaternion) {
+                        return;
+                    }
                     var childImpostor = mesh.getPhysicsImpostor();
                     if (childImpostor) {
                         var parent = childImpostor.parent;
@@ -66176,14 +66253,15 @@ var BABYLON;
             return returnValue;
         };
         CannonJSPlugin.prototype._createHeightmap = function (object, pointDepth) {
-            var pos = object.getVerticesData(BABYLON.VertexBuffer.PositionKind);
+            var pos = (object.getVerticesData(BABYLON.VertexBuffer.PositionKind));
             var matrix = new Array();
             //For now pointDepth will not be used and will be automatically calculated.
             //Future reference - try and find the best place to add a reference to the pointDepth variable.
             var arraySize = pointDepth || ~~(Math.sqrt(pos.length / 3) - 1);
-            var dim = Math.min(object.getBoundingInfo().boundingBox.extendSizeWorld.x, object.getBoundingInfo().boundingBox.extendSizeWorld.z);
+            var boundingInfo = (object.getBoundingInfo());
+            var dim = Math.min(boundingInfo.boundingBox.extendSizeWorld.x, boundingInfo.boundingBox.extendSizeWorld.z);
+            var minY = boundingInfo.boundingBox.extendSizeWorld.y;
             var elementSize = dim * 2 / arraySize;
-            var minY = object.getBoundingInfo().boundingBox.extendSizeWorld.y;
             for (var i = 0; i < pos.length; i = i + 3) {
                 var x = Math.round((pos[i + 0]) / elementSize + arraySize / 2);
                 var z = Math.round(((pos[i + 2]) / elementSize - arraySize / 2) * -1);
@@ -66232,6 +66310,9 @@ var BABYLON;
             this._tmpDeltaPosition.copyFrom(object.position.subtract(center));
             this._tmpPosition.copyFrom(center);
             var quaternion = object.rotationQuaternion;
+            if (!quaternion) {
+                return;
+            }
             //is shape is a plane or a heightmap, it must be rotated 90 degs in the X axis.
             if (impostor.type === BABYLON.PhysicsImpostor.PlaneImpostor || impostor.type === BABYLON.PhysicsImpostor.HeightmapImpostor || impostor.type === BABYLON.PhysicsImpostor.CylinderImpostor) {
                 //-90 DEG in X, precalculated
@@ -66243,6 +66324,7 @@ var BABYLON;
             //If it is a heightfield, if should be centered.
             if (impostor.type === BABYLON.PhysicsImpostor.HeightmapImpostor) {
                 var mesh = object;
+                var boundingInfo = mesh.getBoundingInfo();
                 //calculate the correct body position:
                 var rotationQuaternion = mesh.rotationQuaternion;
                 mesh.rotationQuaternion = this._tmpUnityRotation;
@@ -66253,15 +66335,15 @@ var BABYLON;
                 //rotation is back
                 mesh.rotationQuaternion = rotationQuaternion;
                 //calculate the new center using a pivot (since this.BJSCANNON.js doesn't center height maps)
-                var p = BABYLON.Matrix.Translation(mesh.getBoundingInfo().boundingBox.extendSizeWorld.x, 0, -mesh.getBoundingInfo().boundingBox.extendSizeWorld.z);
+                var p = BABYLON.Matrix.Translation(boundingInfo.boundingBox.extendSizeWorld.x, 0, -boundingInfo.boundingBox.extendSizeWorld.z);
                 mesh.setPivotMatrix(p);
                 mesh.computeWorldMatrix(true);
                 //calculate the translation
-                var translation = mesh.getBoundingInfo().boundingBox.centerWorld.subtract(center).subtract(mesh.position).negate();
-                this._tmpPosition.copyFromFloats(translation.x, translation.y - mesh.getBoundingInfo().boundingBox.extendSizeWorld.y, translation.z);
+                var translation = boundingInfo.boundingBox.centerWorld.subtract(center).subtract(mesh.position).negate();
+                this._tmpPosition.copyFromFloats(translation.x, translation.y - boundingInfo.boundingBox.extendSizeWorld.y, translation.z);
                 //add it inverted to the delta
-                this._tmpDeltaPosition.copyFrom(mesh.getBoundingInfo().boundingBox.centerWorld.subtract(c));
-                this._tmpDeltaPosition.y += mesh.getBoundingInfo().boundingBox.extendSizeWorld.y;
+                this._tmpDeltaPosition.copyFrom(boundingInfo.boundingBox.centerWorld.subtract(c));
+                this._tmpDeltaPosition.y += boundingInfo.boundingBox.extendSizeWorld.y;
                 mesh.setPivotMatrix(oldPivot);
                 mesh.computeWorldMatrix(true);
             }
@@ -66276,7 +66358,9 @@ var BABYLON;
         };
         CannonJSPlugin.prototype.setTransformationFromPhysicsBody = function (impostor) {
             impostor.object.position.copyFrom(impostor.physicsBody.position);
-            impostor.object.rotationQuaternion.copyFrom(impostor.physicsBody.quaternion);
+            if (impostor.object.rotationQuaternion) {
+                impostor.object.rotationQuaternion.copyFrom(impostor.physicsBody.quaternion);
+            }
         };
         CannonJSPlugin.prototype.setPhysicsBodyTransformation = function (impostor, newPosition, newRotation) {
             impostor.physicsBody.position.copy(newPosition);
@@ -66293,14 +66377,16 @@ var BABYLON;
         };
         CannonJSPlugin.prototype.getLinearVelocity = function (impostor) {
             var v = impostor.physicsBody.velocity;
-            if (!v)
+            if (!v) {
                 return null;
+            }
             return new BABYLON.Vector3(v.x, v.y, v.z);
         };
         CannonJSPlugin.prototype.getAngularVelocity = function (impostor) {
             var v = impostor.physicsBody.angularVelocity;
-            if (!v)
+            if (!v) {
                 return null;
+            }
             return new BABYLON.Vector3(v.x, v.y, v.z);
         };
         CannonJSPlugin.prototype.setBodyMass = function (impostor, mass) {
@@ -66359,10 +66445,12 @@ var BABYLON;
             mesh.position.x = body.position.x;
             mesh.position.y = body.position.y;
             mesh.position.z = body.position.z;
-            mesh.rotationQuaternion.x = body.quaternion.x;
-            mesh.rotationQuaternion.y = body.quaternion.y;
-            mesh.rotationQuaternion.z = body.quaternion.z;
-            mesh.rotationQuaternion.w = body.quaternion.w;
+            if (mesh.rotationQuaternion) {
+                mesh.rotationQuaternion.x = body.quaternion.x;
+                mesh.rotationQuaternion.y = body.quaternion.y;
+                mesh.rotationQuaternion.z = body.quaternion.z;
+                mesh.rotationQuaternion.w = body.quaternion.w;
+            }
         };
         CannonJSPlugin.prototype.getRadius = function (impostor) {
             var shape = impostor.physicsBody.shapes[0];
@@ -66484,6 +66572,9 @@ var BABYLON;
                     return Math.max(value, BABYLON.PhysicsEngine.Epsilon);
                 };
                 impostors.forEach(function (i) {
+                    if (!impostor.object.rotationQuaternion) {
+                        return;
+                    }
                     //get the correct bounding box
                     var oldQuaternion = i.object.rotationQuaternion;
                     var rot = new _this.BJSOIMO.Euler().setFromQuaternion({
@@ -66648,8 +66739,10 @@ var BABYLON;
                 else {
                     impostor.object.position.copyFrom(impostor.physicsBody.getPosition());
                 }
-                impostor.object.rotationQuaternion.copyFrom(impostor.physicsBody.getQuaternion());
-                impostor.object.rotationQuaternion.normalize();
+                if (impostor.object.rotationQuaternion) {
+                    impostor.object.rotationQuaternion.copyFrom(impostor.physicsBody.getQuaternion());
+                    impostor.object.rotationQuaternion.normalize();
+                }
             }
         };
         OimoJSPlugin.prototype.setPhysicsBodyTransformation = function (impostor, newPosition, newRotation) {
@@ -66674,14 +66767,16 @@ var BABYLON;
         };
         OimoJSPlugin.prototype.getLinearVelocity = function (impostor) {
             var v = impostor.physicsBody.linearVelocity;
-            if (!v)
+            if (!v) {
                 return null;
+            }
             return new BABYLON.Vector3(v.x, v.y, v.z);
         };
         OimoJSPlugin.prototype.getAngularVelocity = function (impostor) {
             var v = impostor.physicsBody.angularVelocity;
-            if (!v)
+            if (!v) {
                 return null;
+            }
             return new BABYLON.Vector3(v.x, v.y, v.z);
         };
         OimoJSPlugin.prototype.setBodyMass = function (impostor, mass) {
@@ -66737,10 +66832,12 @@ var BABYLON;
             mesh.position.x = body.position.x;
             mesh.position.y = body.position.y;
             mesh.position.z = body.position.z;
-            mesh.rotationQuaternion.x = body.orientation.x;
-            mesh.rotationQuaternion.y = body.orientation.y;
-            mesh.rotationQuaternion.z = body.orientation.z;
-            mesh.rotationQuaternion.w = body.orientation.s;
+            if (mesh.rotationQuaternion) {
+                mesh.rotationQuaternion.x = body.orientation.x;
+                mesh.rotationQuaternion.y = body.orientation.y;
+                mesh.rotationQuaternion.z = body.orientation.z;
+                mesh.rotationQuaternion.w = body.orientation.s;
+            }
         };
         OimoJSPlugin.prototype.getRadius = function (impostor) {
             return impostor.physicsBody.shapes.radius;
@@ -68220,7 +68317,10 @@ var BABYLON;
             this._indexBuffer = engine.createIndexBuffer([0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 7, 1, 6, 2, 5, 3, 4]);
         };
         BoundingBoxRenderer.prototype._rebuild = function () {
-            this._vertexBuffers[BABYLON.VertexBuffer.PositionKind]._rebuild();
+            var vb = this._vertexBuffers[BABYLON.VertexBuffer.PositionKind];
+            if (vb) {
+                vb._rebuild();
+            }
             this._createIndexBuffer();
         };
         BoundingBoxRenderer.prototype.reset = function () {
@@ -68271,7 +68371,7 @@ var BABYLON;
         };
         BoundingBoxRenderer.prototype.renderOcclusionBoundingBox = function (mesh) {
             this._prepareRessources();
-            if (!this._colorShader.isReady()) {
+            if (!this._colorShader.isReady() || !mesh._boundingInfo) {
                 return;
             }
             var engine = this._scene.getEngine();
@@ -69070,7 +69170,7 @@ var BABYLON;
                 'Scale',
                 'ScaleIn',
                 'HmdWarpParam'
-            ], null, vrMetrics.postProcessScaleFactor, camera, BABYLON.Texture.BILINEAR_SAMPLINGMODE, null, null) || this;
+            ], null, vrMetrics.postProcessScaleFactor, camera, BABYLON.Texture.BILINEAR_SAMPLINGMODE) || this;
             _this._isRightEye = isRightEye;
             _this._distortionFactors = vrMetrics.distortionK;
             _this._postProcessScaleFactor = vrMetrics.postProcessScaleFactor;
@@ -71557,6 +71657,9 @@ var BABYLON;
             }
             var mesh = subMesh.getRenderingMesh();
             var material = subMesh.getMaterial();
+            if (!material || !scene.activeCamera) {
+                return;
+            }
             engine.enableEffect(this._effect);
             // Logarithmic depth
             if (material.useLogarithmicDepth) {
@@ -71566,7 +71669,7 @@ var BABYLON;
             this._effect.setColor4("color", useOverlay ? mesh.overlayColor : mesh.outlineColor, useOverlay ? mesh.overlayAlpha : material.alpha);
             this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
             // Bones
-            if (mesh.useBones && mesh.computeBonesUsingShaders) {
+            if (mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {
                 this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
             }
             mesh._bind(subMesh, this._effect, BABYLON.Material.TriangleFillMode);
@@ -71614,7 +71717,7 @@ var BABYLON;
                     attribs.push(BABYLON.VertexBuffer.MatricesWeightsExtraKind);
                 }
                 defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
-                defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
+                defines.push("#define BonesPerMesh " + (mesh.skeleton ? mesh.skeleton.bones.length + 1 : 0));
             }
             else {
                 defines.push("#define NUM_BONE_INFLUENCERS 0");
@@ -71786,6 +71889,9 @@ var BABYLON;
         EdgesRenderer.prototype._generateEdgesLines = function () {
             var positions = this._source.getVerticesData(BABYLON.VertexBuffer.PositionKind);
             var indices = this._source.getIndices();
+            if (!indices || !positions) {
+                return;
+            }
             // First let's find adjacencies
             var adjacencies = new Array();
             var faceNormals = new Array();
@@ -71820,7 +71926,7 @@ var BABYLON;
                     var otherP1 = indices[otherIndex * 3 + 1];
                     var otherP2 = indices[otherIndex * 3 + 2];
                     for (var edgeIndex = 0; edgeIndex < 3; edgeIndex++) {
-                        var otherEdgeIndex;
+                        var otherEdgeIndex = 0;
                         if (faceAdjacencies.edges[edgeIndex] !== undefined) {
                             continue;
                         }
@@ -71879,10 +71985,10 @@ var BABYLON;
             this._indicesCount = this._linesIndices.length;
         };
         EdgesRenderer.prototype.render = function () {
-            if (!this._lineShader.isReady()) {
+            var scene = this._source.getScene();
+            if (!this._lineShader.isReady() || !scene.activeCamera) {
                 return;
             }
-            var scene = this._source.getScene();
             var engine = scene.getEngine();
             this._lineShader._preBind();
             // VBOs
@@ -73308,7 +73414,9 @@ var BABYLON;
             this._renderTargetTexture.onAfterUnbindObservable.add(function () {
                 scene.updateTransformMatrix(true);
             });
-            this._projectionMatrix = BABYLON.Matrix.PerspectiveFovLH(Math.PI / 2, 1, scene.activeCamera.minZ, scene.activeCamera.maxZ);
+            if (scene.activeCamera) {
+                this._projectionMatrix = BABYLON.Matrix.PerspectiveFovLH(Math.PI / 2, 1, scene.activeCamera.minZ, scene.activeCamera.maxZ);
+            }
         }
         Object.defineProperty(ReflectionProbe.prototype, "samples", {
             get: function () {

Diferenças do arquivo suprimidas por serem muito extensas
+ 4937 - 4937
dist/preview release/babylon.module.d.ts


Diferenças do arquivo suprimidas por serem muito extensas
+ 19 - 19
dist/preview release/babylon.worker.js


Diferenças do arquivo suprimidas por serem muito extensas
+ 9369 - 9365
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts


Diferenças do arquivo suprimidas por serem muito extensas
+ 35 - 35
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js


Diferenças do arquivo suprimidas por serem muito extensas
+ 376 - 193
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js


Diferenças do arquivo suprimidas por serem muito extensas
+ 9369 - 9365
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.module.d.ts


+ 32 - 32
dist/preview release/gui/babylon.gui.d.ts

@@ -36,7 +36,7 @@ declare module BABYLON.GUI {
         readonly layer: Layer;
         readonly rootContainer: Container;
         focusedControl: IFocusableControl;
-        constructor(name: string, width: number | undefined, height: number | undefined, scene: Scene, generateMipMaps?: boolean, samplingMode?: number);
+        constructor(name: string, width: number, height: number, scene: Scene, generateMipMaps?: boolean, samplingMode?: number);
         executeOnAllControls(func: (control: Control) => void, container?: Container): void;
         markAsDirty(): void;
         addControl(control: Control): AdvancedDynamicTexture;
@@ -126,7 +126,7 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class Control {
-        name: string | undefined;
+        name: string;
         private _alpha;
         private _alphaSet;
         private _zIndex;
@@ -254,7 +254,7 @@ declare module BABYLON.GUI {
         readonly linkOffsetYInPixels: number;
         readonly centerX: number;
         readonly centerY: number;
-        constructor(name?: string | undefined);
+        constructor(name?: string);
         protected _getTypeName(): string;
         getLocalCoordinates(globalCoordinates: Vector2): Vector2;
         getLocalCoordinatesToRef(globalCoordinates: Vector2, result: Vector2): Control;
@@ -315,13 +315,13 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class Container extends Control {
-        name: string | undefined;
+        name: string;
         protected _children: Control[];
         protected _measureForChildren: Measure;
         protected _background: string;
         background: string;
         readonly children: Control[];
-        constructor(name?: string | undefined);
+        constructor(name?: string);
         protected _getTypeName(): string;
         getChildByName(name: string): Control;
         getChildByType(name: string, type: string): Control;
@@ -344,7 +344,7 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class StackPanel extends Container {
-        name: string | undefined;
+        name: string;
         private _isVertical;
         private _manualWidth;
         private _manualHeight;
@@ -353,7 +353,7 @@ declare module BABYLON.GUI {
         isVertical: boolean;
         width: string | number;
         height: string | number;
-        constructor(name?: string | undefined);
+        constructor(name?: string);
         protected _getTypeName(): string;
         protected _preMeasure(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
     }
@@ -362,12 +362,12 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class Rectangle extends Container {
-        name: string | undefined;
+        name: string;
         private _thickness;
         private _cornerRadius;
         thickness: number;
         cornerRadius: number;
-        constructor(name?: string | undefined);
+        constructor(name?: string);
         protected _getTypeName(): string;
         protected _localDraw(context: CanvasRenderingContext2D): void;
         protected _additionalProcessing(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
@@ -379,10 +379,10 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class Ellipse extends Container {
-        name: string | undefined;
+        name: string;
         private _thickness;
         thickness: number;
-        constructor(name?: string | undefined);
+        constructor(name?: string);
         protected _getTypeName(): string;
         protected _localDraw(context: CanvasRenderingContext2D): void;
         protected _additionalProcessing(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
@@ -393,7 +393,7 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class Line extends Control {
-        name: string | undefined;
+        name: string;
         private _lineWidth;
         private _x1;
         private _y1;
@@ -413,7 +413,7 @@ declare module BABYLON.GUI {
         verticalAlignment: number;
         private readonly _effectiveX2;
         private readonly _effectiveY2;
-        constructor(name?: string | undefined);
+        constructor(name?: string);
         protected _getTypeName(): string;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         _measure(): void;
@@ -425,7 +425,7 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class Slider extends Control {
-        name: string | undefined;
+        name: string;
         private _thumbWidth;
         private _minimum;
         private _maximum;
@@ -443,7 +443,7 @@ declare module BABYLON.GUI {
         minimum: number;
         maximum: number;
         value: number;
-        constructor(name?: string | undefined);
+        constructor(name?: string);
         protected _getTypeName(): string;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         private _pointerIsDown;
@@ -457,7 +457,7 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class Checkbox extends Control {
-        name: string | undefined;
+        name: string;
         private _isChecked;
         private _background;
         private _checkSizeRatio;
@@ -467,7 +467,7 @@ declare module BABYLON.GUI {
         checkSizeRatio: number;
         background: string;
         isChecked: boolean;
-        constructor(name?: string | undefined);
+        constructor(name?: string);
         protected _getTypeName(): string;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         _onPointerDown(target: Control, coordinates: Vector2, buttonIndex: number): boolean;
@@ -477,7 +477,7 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class RadioButton extends Control {
-        name: string | undefined;
+        name: string;
         private _isChecked;
         private _background;
         private _checkSizeRatio;
@@ -488,7 +488,7 @@ declare module BABYLON.GUI {
         checkSizeRatio: number;
         background: string;
         isChecked: boolean;
-        constructor(name?: string | undefined);
+        constructor(name?: string);
         protected _getTypeName(): string;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         _onPointerDown(target: Control, coordinates: Vector2, buttonIndex: number): boolean;
@@ -498,7 +498,7 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class TextBlock extends Control {
-        name: string | undefined;
+        name: string;
         private _text;
         private _textWrapping;
         private _textHorizontalAlignment;
@@ -515,23 +515,23 @@ declare module BABYLON.GUI {
         text: string;
         textHorizontalAlignment: number;
         textVerticalAlignment: number;
-        constructor(name?: string | undefined, text?: string);
+        constructor(name?: string, text?: string);
         protected _getTypeName(): string;
         private _drawText(text, textWidth, y, context);
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         protected _additionalProcessing(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
-        protected _parseLine(line: string | undefined, context: CanvasRenderingContext2D): object;
-        protected _parseLineWithTextWrapping(line: string | undefined, context: CanvasRenderingContext2D): object;
+        protected _parseLine(line: string, context: CanvasRenderingContext2D): object;
+        protected _parseLineWithTextWrapping(line: string, context: CanvasRenderingContext2D): object;
         protected _renderLines(context: CanvasRenderingContext2D): void;
         dispose(): void;
     }
 }
 
 
-declare var DOMImage: new (width?: number | undefined, height?: number | undefined) => HTMLImageElement;
+declare var DOMImage: new (width?: number, height?: number) => HTMLImageElement;
 declare module BABYLON.GUI {
     class Image extends Control {
-        name: string | undefined;
+        name: string;
         private _domImage;
         private _imageWidth;
         private _imageHeight;
@@ -552,7 +552,7 @@ declare module BABYLON.GUI {
         domImage: HTMLImageElement;
         private _onImageLoaded();
         source: string;
-        constructor(name?: string | undefined, url?: string);
+        constructor(name?: string, url?: string);
         protected _getTypeName(): string;
         synchronizeSizeWithContent(): void;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
@@ -570,12 +570,12 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class Button extends Rectangle {
-        name: string | undefined;
+        name: string;
         pointerEnterAnimation: () => void;
         pointerOutAnimation: () => void;
         pointerDownAnimation: () => void;
         pointerUpAnimation: () => void;
-        constructor(name?: string | undefined);
+        constructor(name?: string);
         protected _getTypeName(): string;
         _processPicking(x: number, y: number, type: number, buttonIndex: number): boolean;
         _onPointerEnter(target: Control): boolean;
@@ -592,7 +592,7 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class ColorPicker extends Control {
-        name: string | undefined;
+        name: string;
         private _colorWheelCanvas;
         private _value;
         private _tmpColor;
@@ -609,7 +609,7 @@ declare module BABYLON.GUI {
         width: string | number;
         height: string | number;
         size: string | number;
-        constructor(name?: string | undefined);
+        constructor(name?: string);
         protected _getTypeName(): string;
         private _updateSquareProps();
         private _drawGradientSquare(hueValue, left, top, width, height, context);
@@ -631,7 +631,7 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class InputText extends Control implements IFocusableControl {
-        name: string | undefined;
+        name: string;
         private _text;
         private _placeholderText;
         private _background;
@@ -663,7 +663,7 @@ declare module BABYLON.GUI {
         placeholderColor: string;
         placeholderText: string;
         text: string;
-        constructor(name?: string | undefined, text?: string);
+        constructor(name?: string, text?: string);
         onBlur(): void;
         onFocus(): void;
         protected _getTypeName(): string;

+ 32 - 32
dist/preview release/gui/babylon.gui.module.d.ts

@@ -41,7 +41,7 @@ declare module BABYLON.GUI {
         readonly layer: Layer;
         readonly rootContainer: Container;
         focusedControl: IFocusableControl;
-        constructor(name: string, width: number | undefined, height: number | undefined, scene: Scene, generateMipMaps?: boolean, samplingMode?: number);
+        constructor(name: string, width: number, height: number, scene: Scene, generateMipMaps?: boolean, samplingMode?: number);
         executeOnAllControls(func: (control: Control) => void, container?: Container): void;
         markAsDirty(): void;
         addControl(control: Control): AdvancedDynamicTexture;
@@ -131,7 +131,7 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class Control {
-        name: string | undefined;
+        name: string;
         private _alpha;
         private _alphaSet;
         private _zIndex;
@@ -259,7 +259,7 @@ declare module BABYLON.GUI {
         readonly linkOffsetYInPixels: number;
         readonly centerX: number;
         readonly centerY: number;
-        constructor(name?: string | undefined);
+        constructor(name?: string);
         protected _getTypeName(): string;
         getLocalCoordinates(globalCoordinates: Vector2): Vector2;
         getLocalCoordinatesToRef(globalCoordinates: Vector2, result: Vector2): Control;
@@ -320,13 +320,13 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class Container extends Control {
-        name: string | undefined;
+        name: string;
         protected _children: Control[];
         protected _measureForChildren: Measure;
         protected _background: string;
         background: string;
         readonly children: Control[];
-        constructor(name?: string | undefined);
+        constructor(name?: string);
         protected _getTypeName(): string;
         getChildByName(name: string): Control;
         getChildByType(name: string, type: string): Control;
@@ -349,7 +349,7 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class StackPanel extends Container {
-        name: string | undefined;
+        name: string;
         private _isVertical;
         private _manualWidth;
         private _manualHeight;
@@ -358,7 +358,7 @@ declare module BABYLON.GUI {
         isVertical: boolean;
         width: string | number;
         height: string | number;
-        constructor(name?: string | undefined);
+        constructor(name?: string);
         protected _getTypeName(): string;
         protected _preMeasure(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
     }
@@ -367,12 +367,12 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class Rectangle extends Container {
-        name: string | undefined;
+        name: string;
         private _thickness;
         private _cornerRadius;
         thickness: number;
         cornerRadius: number;
-        constructor(name?: string | undefined);
+        constructor(name?: string);
         protected _getTypeName(): string;
         protected _localDraw(context: CanvasRenderingContext2D): void;
         protected _additionalProcessing(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
@@ -384,10 +384,10 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class Ellipse extends Container {
-        name: string | undefined;
+        name: string;
         private _thickness;
         thickness: number;
-        constructor(name?: string | undefined);
+        constructor(name?: string);
         protected _getTypeName(): string;
         protected _localDraw(context: CanvasRenderingContext2D): void;
         protected _additionalProcessing(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
@@ -398,7 +398,7 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class Line extends Control {
-        name: string | undefined;
+        name: string;
         private _lineWidth;
         private _x1;
         private _y1;
@@ -418,7 +418,7 @@ declare module BABYLON.GUI {
         verticalAlignment: number;
         private readonly _effectiveX2;
         private readonly _effectiveY2;
-        constructor(name?: string | undefined);
+        constructor(name?: string);
         protected _getTypeName(): string;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         _measure(): void;
@@ -430,7 +430,7 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class Slider extends Control {
-        name: string | undefined;
+        name: string;
         private _thumbWidth;
         private _minimum;
         private _maximum;
@@ -448,7 +448,7 @@ declare module BABYLON.GUI {
         minimum: number;
         maximum: number;
         value: number;
-        constructor(name?: string | undefined);
+        constructor(name?: string);
         protected _getTypeName(): string;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         private _pointerIsDown;
@@ -462,7 +462,7 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class Checkbox extends Control {
-        name: string | undefined;
+        name: string;
         private _isChecked;
         private _background;
         private _checkSizeRatio;
@@ -472,7 +472,7 @@ declare module BABYLON.GUI {
         checkSizeRatio: number;
         background: string;
         isChecked: boolean;
-        constructor(name?: string | undefined);
+        constructor(name?: string);
         protected _getTypeName(): string;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         _onPointerDown(target: Control, coordinates: Vector2, buttonIndex: number): boolean;
@@ -482,7 +482,7 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class RadioButton extends Control {
-        name: string | undefined;
+        name: string;
         private _isChecked;
         private _background;
         private _checkSizeRatio;
@@ -493,7 +493,7 @@ declare module BABYLON.GUI {
         checkSizeRatio: number;
         background: string;
         isChecked: boolean;
-        constructor(name?: string | undefined);
+        constructor(name?: string);
         protected _getTypeName(): string;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         _onPointerDown(target: Control, coordinates: Vector2, buttonIndex: number): boolean;
@@ -503,7 +503,7 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class TextBlock extends Control {
-        name: string | undefined;
+        name: string;
         private _text;
         private _textWrapping;
         private _textHorizontalAlignment;
@@ -520,23 +520,23 @@ declare module BABYLON.GUI {
         text: string;
         textHorizontalAlignment: number;
         textVerticalAlignment: number;
-        constructor(name?: string | undefined, text?: string);
+        constructor(name?: string, text?: string);
         protected _getTypeName(): string;
         private _drawText(text, textWidth, y, context);
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         protected _additionalProcessing(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
-        protected _parseLine(line: string | undefined, context: CanvasRenderingContext2D): object;
-        protected _parseLineWithTextWrapping(line: string | undefined, context: CanvasRenderingContext2D): object;
+        protected _parseLine(line: string, context: CanvasRenderingContext2D): object;
+        protected _parseLineWithTextWrapping(line: string, context: CanvasRenderingContext2D): object;
         protected _renderLines(context: CanvasRenderingContext2D): void;
         dispose(): void;
     }
 }
 
 
-declare var DOMImage: new (width?: number | undefined, height?: number | undefined) => HTMLImageElement;
+declare var DOMImage: new (width?: number, height?: number) => HTMLImageElement;
 declare module BABYLON.GUI {
     class Image extends Control {
-        name: string | undefined;
+        name: string;
         private _domImage;
         private _imageWidth;
         private _imageHeight;
@@ -557,7 +557,7 @@ declare module BABYLON.GUI {
         domImage: HTMLImageElement;
         private _onImageLoaded();
         source: string;
-        constructor(name?: string | undefined, url?: string);
+        constructor(name?: string, url?: string);
         protected _getTypeName(): string;
         synchronizeSizeWithContent(): void;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
@@ -575,12 +575,12 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class Button extends Rectangle {
-        name: string | undefined;
+        name: string;
         pointerEnterAnimation: () => void;
         pointerOutAnimation: () => void;
         pointerDownAnimation: () => void;
         pointerUpAnimation: () => void;
-        constructor(name?: string | undefined);
+        constructor(name?: string);
         protected _getTypeName(): string;
         _processPicking(x: number, y: number, type: number, buttonIndex: number): boolean;
         _onPointerEnter(target: Control): boolean;
@@ -597,7 +597,7 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class ColorPicker extends Control {
-        name: string | undefined;
+        name: string;
         private _colorWheelCanvas;
         private _value;
         private _tmpColor;
@@ -614,7 +614,7 @@ declare module BABYLON.GUI {
         width: string | number;
         height: string | number;
         size: string | number;
-        constructor(name?: string | undefined);
+        constructor(name?: string);
         protected _getTypeName(): string;
         private _updateSquareProps();
         private _drawGradientSquare(hueValue, left, top, width, height, context);
@@ -636,7 +636,7 @@ declare module BABYLON.GUI {
 
 declare module BABYLON.GUI {
     class InputText extends Control implements IFocusableControl {
-        name: string | undefined;
+        name: string;
         private _text;
         private _placeholderText;
         private _background;
@@ -668,7 +668,7 @@ declare module BABYLON.GUI {
         placeholderColor: string;
         placeholderText: string;
         text: string;
-        constructor(name?: string | undefined, text?: string);
+        constructor(name?: string, text?: string);
         onBlur(): void;
         onFocus(): void;
         protected _getTypeName(): string;

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

@@ -4382,7 +4382,7 @@
             }
         }
 
-        public _bindTexture(channel: number, texture: InternalTexture): void {
+        public _bindTexture(channel: number, texture: Nullable<InternalTexture>): void {
             if (channel < 0) {
                 return;
             }
@@ -4391,8 +4391,8 @@
             this._bindTextureDirectly(this._gl.TEXTURE_2D, texture);
         }
 
-        public setTextureFromPostProcess(channel: number, postProcess: PostProcess): void {
-            this._bindTexture(channel, postProcess._textures.data[postProcess._currentRenderTextureInd]);
+        public setTextureFromPostProcess(channel: number, postProcess: Nullable<PostProcess>): void {
+            this._bindTexture(channel, postProcess ? postProcess._textures.data[postProcess._currentRenderTextureInd] : null);
         }
 
         public unbindAllTextures(): void {

+ 1 - 1
src/Materials/babylon.effect.ts

@@ -664,7 +664,7 @@
             this._engine.setTextureArray(this._samplers.indexOf(channel), this.getUniform(channel), textures);
         }
 
-        public setTextureFromPostProcess(channel: string, postProcess: PostProcess): void {
+        public setTextureFromPostProcess(channel: string, postProcess: Nullable<PostProcess>): void {
             this._engine.setTextureFromPostProcess(this._samplers.indexOf(channel), postProcess);
         }
 

+ 39 - 21
src/Physics/Plugins/babylon.cannonJSPlugin.ts

@@ -112,9 +112,14 @@
 
         private _processChildMeshes(mainImpostor: PhysicsImpostor) {
             var meshChildren = mainImpostor.object.getChildMeshes ? mainImpostor.object.getChildMeshes(true) : [];
-            let currentRotation: Quaternion = mainImpostor.object.rotationQuaternion;
+            let currentRotation: Nullable<Quaternion> = mainImpostor.object.rotationQuaternion;
             if (meshChildren.length) {
                 var processMesh = (localPosition: Vector3, mesh: AbstractMesh) => {
+
+                    if (!currentRotation || ! mesh.rotationQuaternion) {
+                        return;
+                    }
+
                     var childImpostor = mesh.getPhysicsImpostor();
                     if (childImpostor) {
                         var parent = childImpostor.parent;
@@ -275,19 +280,18 @@
         }
 
         private _createHeightmap(object: IPhysicsEnabledObject, pointDepth?: number) {
-            var pos = object.getVerticesData(VertexBuffer.PositionKind);
+            var pos = <FloatArray>(object.getVerticesData(VertexBuffer.PositionKind));
             var matrix = new Array<Array<any>>();
 
             //For now pointDepth will not be used and will be automatically calculated.
             //Future reference - try and find the best place to add a reference to the pointDepth variable.
             var arraySize = pointDepth || ~~(Math.sqrt(pos.length / 3) - 1);
-
-            var dim = Math.min(object.getBoundingInfo().boundingBox.extendSizeWorld.x, object.getBoundingInfo().boundingBox.extendSizeWorld.z);
-
+            let boundingInfo = <BoundingInfo>(object.getBoundingInfo());
+            var dim = Math.min(boundingInfo.boundingBox.extendSizeWorld.x, boundingInfo.boundingBox.extendSizeWorld.z);
+            var minY = boundingInfo.boundingBox.extendSizeWorld.y;
+            
             var elementSize = dim * 2 / arraySize;
 
-            var minY = object.getBoundingInfo().boundingBox.extendSizeWorld.y;
-
             for (var i = 0; i < pos.length; i = i + 3) {
                 var x = Math.round((pos[i + 0]) / elementSize + arraySize / 2);
                 var z = Math.round(((pos[i + 2]) / elementSize - arraySize / 2) * -1);
@@ -349,6 +353,11 @@
             this._tmpDeltaPosition.copyFrom(object.position.subtract(center));
             this._tmpPosition.copyFrom(center);
             var quaternion = object.rotationQuaternion;
+
+            if (!quaternion) {
+                return;
+            }
+
             //is shape is a plane or a heightmap, it must be rotated 90 degs in the X axis.
             if (impostor.type === PhysicsImpostor.PlaneImpostor || impostor.type === PhysicsImpostor.HeightmapImpostor || impostor.type === PhysicsImpostor.CylinderImpostor) {
                 //-90 DEG in X, precalculated
@@ -361,6 +370,7 @@
             //If it is a heightfield, if should be centered.
             if (impostor.type === PhysicsImpostor.HeightmapImpostor) {
                 var mesh = <AbstractMesh>(<any>object);
+                let boundingInfo = <BoundingInfo>mesh.getBoundingInfo();
                 //calculate the correct body position:
                 var rotationQuaternion = mesh.rotationQuaternion;
                 mesh.rotationQuaternion = this._tmpUnityRotation;
@@ -375,17 +385,17 @@
                 mesh.rotationQuaternion = rotationQuaternion;
 
                 //calculate the new center using a pivot (since this.BJSCANNON.js doesn't center height maps)
-                var p = Matrix.Translation(mesh.getBoundingInfo().boundingBox.extendSizeWorld.x, 0, -mesh.getBoundingInfo().boundingBox.extendSizeWorld.z);
+                var p = Matrix.Translation(boundingInfo.boundingBox.extendSizeWorld.x, 0, -boundingInfo.boundingBox.extendSizeWorld.z);
                 mesh.setPivotMatrix(p);
                 mesh.computeWorldMatrix(true);
 
                 //calculate the translation
-                var translation = mesh.getBoundingInfo().boundingBox.centerWorld.subtract(center).subtract(mesh.position).negate();
+                var translation = boundingInfo.boundingBox.centerWorld.subtract(center).subtract(mesh.position).negate();
 
-                this._tmpPosition.copyFromFloats(translation.x, translation.y - mesh.getBoundingInfo().boundingBox.extendSizeWorld.y, translation.z);
+                this._tmpPosition.copyFromFloats(translation.x, translation.y - boundingInfo.boundingBox.extendSizeWorld.y, translation.z);
                 //add it inverted to the delta
-                this._tmpDeltaPosition.copyFrom(mesh.getBoundingInfo().boundingBox.centerWorld.subtract(c));
-                this._tmpDeltaPosition.y += mesh.getBoundingInfo().boundingBox.extendSizeWorld.y;
+                this._tmpDeltaPosition.copyFrom(boundingInfo.boundingBox.centerWorld.subtract(c));
+                this._tmpDeltaPosition.y += boundingInfo.boundingBox.extendSizeWorld.y;
 
                 mesh.setPivotMatrix(oldPivot);
                 mesh.computeWorldMatrix(true);
@@ -402,7 +412,9 @@
 
         public setTransformationFromPhysicsBody(impostor: PhysicsImpostor) {
             impostor.object.position.copyFrom(impostor.physicsBody.position);
-            impostor.object.rotationQuaternion.copyFrom(impostor.physicsBody.quaternion);
+            if (impostor.object.rotationQuaternion) {
+                impostor.object.rotationQuaternion.copyFrom(impostor.physicsBody.quaternion);
+            }
         }
 
         public setPhysicsBodyTransformation(impostor: PhysicsImpostor, newPosition: Vector3, newRotation: Quaternion) {
@@ -422,14 +434,18 @@
             impostor.physicsBody.angularVelocity.copy(velocity);
         }
 
-        public getLinearVelocity(impostor: PhysicsImpostor): Vector3 {
+        public getLinearVelocity(impostor: PhysicsImpostor): Nullable<Vector3> {
             var v = impostor.physicsBody.velocity;
-            if (!v) return null;
+            if (!v) {
+                return null;
+            }
             return new Vector3(v.x, v.y, v.z)
         }
-        public getAngularVelocity(impostor: PhysicsImpostor): Vector3 {
+        public getAngularVelocity(impostor: PhysicsImpostor): Nullable<Vector3> {
             var v = impostor.physicsBody.angularVelocity;
-            if (!v) return null;
+            if (!v) {
+                return null;
+            }
             return new Vector3(v.x, v.y, v.z)
         }
 
@@ -504,10 +520,12 @@
             mesh.position.y = body.position.y;
             mesh.position.z = body.position.z;
 
-            mesh.rotationQuaternion.x = body.quaternion.x;
-            mesh.rotationQuaternion.y = body.quaternion.y;
-            mesh.rotationQuaternion.z = body.quaternion.z;
-            mesh.rotationQuaternion.w = body.quaternion.w;
+            if (mesh.rotationQuaternion) {
+                mesh.rotationQuaternion.x = body.quaternion.x;
+                mesh.rotationQuaternion.y = body.quaternion.y;
+                mesh.rotationQuaternion.z = body.quaternion.z;
+                mesh.rotationQuaternion.w = body.quaternion.w;
+            }
         }
 
         public getRadius(impostor: PhysicsImpostor): number {

+ 22 - 11
src/Physics/Plugins/babylon.oimoJSPlugin.ts

@@ -120,7 +120,9 @@ module BABYLON {
                 }
 
                 impostors.forEach((i) => {
-
+                    if (!impostor.object.rotationQuaternion) {
+                        return;
+                    }
                     //get the correct bounding box
                     var oldQuaternion = i.object.rotationQuaternion;
                     var rot = new this.BJSOIMO.Euler().setFromQuaternion({
@@ -316,8 +318,11 @@ module BABYLON {
                     impostor.object.position.copyFrom(impostor.physicsBody.getPosition());
 
                 }
-                impostor.object.rotationQuaternion.copyFrom(impostor.physicsBody.getQuaternion());
-                impostor.object.rotationQuaternion.normalize();
+
+                if (impostor.object.rotationQuaternion) {
+                    impostor.object.rotationQuaternion.copyFrom(impostor.physicsBody.getQuaternion());
+                    impostor.object.rotationQuaternion.normalize();
+                }
             }
         }
 
@@ -347,14 +352,18 @@ module BABYLON {
             impostor.physicsBody.angularVelocity.init(velocity.x, velocity.y, velocity.z);
         }
 
-        public getLinearVelocity(impostor: PhysicsImpostor): Vector3 {
+        public getLinearVelocity(impostor: PhysicsImpostor): Nullable<Vector3> {
             var v = impostor.physicsBody.linearVelocity;
-            if (!v) return null;
+            if (!v) {
+                return null;
+            }
             return new Vector3(v.x, v.y, v.z)
         }
-        public getAngularVelocity(impostor: PhysicsImpostor): Vector3 {
+        public getAngularVelocity(impostor: PhysicsImpostor): Nullable<Vector3> {
             var v = impostor.physicsBody.angularVelocity;
-            if (!v) return null;
+            if (!v) {
+                return null;
+            }
             return new Vector3(v.x, v.y, v.z)
         }
 
@@ -424,10 +433,12 @@ module BABYLON {
             mesh.position.y = body.position.y;
             mesh.position.z = body.position.z;
 
-            mesh.rotationQuaternion.x = body.orientation.x;
-            mesh.rotationQuaternion.y = body.orientation.y;
-            mesh.rotationQuaternion.z = body.orientation.z;
-            mesh.rotationQuaternion.w = body.orientation.s;
+            if (mesh.rotationQuaternion) {
+                mesh.rotationQuaternion.x = body.orientation.x;
+                mesh.rotationQuaternion.y = body.orientation.y;
+                mesh.rotationQuaternion.z = body.orientation.z;
+                mesh.rotationQuaternion.w = body.orientation.s;
+            }
         }
 
         public getRadius(impostor: PhysicsImpostor): number {

+ 4 - 4
src/Physics/babylon.physicsEngine.ts

@@ -184,10 +184,10 @@
         isSupported(): boolean;
         setTransformationFromPhysicsBody(impostor: PhysicsImpostor): void;
         setPhysicsBodyTransformation(impostor: PhysicsImpostor, newPosition: Vector3, newRotation: Quaternion): void;
-        setLinearVelocity(impostor: PhysicsImpostor, velocity: Vector3): void;
-        setAngularVelocity(impostor: PhysicsImpostor, velocity: Vector3): void;
-        getLinearVelocity(impostor: PhysicsImpostor) : Vector3;
-        getAngularVelocity(impostor: PhysicsImpostor) : Vector3;
+        setLinearVelocity(impostor: PhysicsImpostor, velocity: Nullable<Vector3>): void;
+        setAngularVelocity(impostor: PhysicsImpostor, velocity: Nullable<Vector3>): void;
+        getLinearVelocity(impostor: PhysicsImpostor): Nullable<Vector3>;
+        getAngularVelocity(impostor: PhysicsImpostor): Nullable<Vector3>;
         setBodyMass(impostor: PhysicsImpostor, mass: number): void;
         getBodyMass(impostor: PhysicsImpostor): number;
         getBodyFriction(impostor: PhysicsImpostor): number;

+ 5 - 5
src/Physics/babylon.physicsImpostor.ts

@@ -17,7 +17,7 @@ module BABYLON {
         computeWorldMatrix?(force: boolean): void;
         getWorldMatrix?(): Matrix;
         getChildMeshes?(directDescendantsOnly?: boolean): Array<AbstractMesh>;
-        getVerticesData?(kind: string): Nullable<Array<number> | Float32Array>;
+        getVerticesData(kind: string): Nullable<Array<number> | Float32Array>;
         getIndices?(): Nullable<IndicesArray>;
         getScene?(): Scene;
         getAbsolutePosition(): Vector3;
@@ -284,21 +284,21 @@ module BABYLON {
             }
         }
 
-        public getLinearVelocity(): Vector3 {
+        public getLinearVelocity(): Nullable<Vector3> {
             return this._physicsEngine ? this._physicsEngine.getPhysicsPlugin().getLinearVelocity(this) : Vector3.Zero();
         }
 
-        public setLinearVelocity(velocity: Vector3) {
+        public setLinearVelocity(velocity: Nullable<Vector3>) {
             if (this._physicsEngine) {
                 this._physicsEngine.getPhysicsPlugin().setLinearVelocity(this, velocity);
             }
         }
 
-        public getAngularVelocity(): Vector3 {
+        public getAngularVelocity(): Nullable<Vector3> {
             return this._physicsEngine ? this._physicsEngine.getPhysicsPlugin().getAngularVelocity(this) : Vector3.Zero();
         }
 
-        public setAngularVelocity(velocity: Vector3) {
+        public setAngularVelocity(velocity: Nullable<Vector3>) {
             if (this._physicsEngine) {
                 this._physicsEngine.getPhysicsPlugin().setAngularVelocity(this, velocity);
             }

+ 3 - 3
src/Physics/babylon.physicsJoint.ts

@@ -101,7 +101,7 @@ module BABYLON {
          * @param {number} maxForce max force for this motor.
          */
         public setMotor(force?: number, maxForce?: number) {
-            this._physicsPlugin.setMotor(this, force, maxForce);
+            this._physicsPlugin.setMotor(this, force || 0, maxForce);
         }
         
         /**
@@ -129,7 +129,7 @@ module BABYLON {
          * @param {number} maxForce max force for this motor.
          */
         public setMotor(force?: number, maxForce?: number) {
-            this._physicsPlugin.setMotor(this, force, maxForce);
+            this._physicsPlugin.setMotor(this, force || 0, maxForce);
         }
         
         /**
@@ -158,7 +158,7 @@ module BABYLON {
          * @param {motorIndex} the motor's index, 0 or 1.
          */
         public setMotor(force?: number, maxForce?: number, motorIndex: number = 0) {
-            this._physicsPlugin.setMotor(this, force, maxForce, motorIndex);
+            this._physicsPlugin.setMotor(this, force || 0, maxForce, motorIndex);
         }
         
         /**

+ 10 - 10
src/PostProcess/RenderPipeline/Pipelines/babylon.defaultRenderingPipeline.ts

@@ -193,7 +193,7 @@
 				this.blurX.alwaysForcePOT = true;
 				this.blurX.autoClear = false;
 				this.blurX.onActivateObservable.add(() => {
-					let dw = this.blurX.width / engine.getRenderingCanvas().width;
+					let dw = this.blurX.width / engine.getRenderWidth(true);
 					this.blurX.kernel = this.bloomKernel * dw;
 				});
 
@@ -202,7 +202,7 @@
 				this.blurY.alwaysForcePOT = true;
 				this.blurY.autoClear = false;
 				this.blurY.onActivateObservable.add(() => {
-					let dh = this.blurY.height / engine.getRenderingCanvas().height;
+					let dh = this.blurY.height / engine.getRenderHeight(true);
 					this.blurY.kernel = this.bloomKernel * dh;
 				});				
 
@@ -302,14 +302,14 @@
                 }                
             }
 
-            this.pass = null;
-            this.highlights = null;
-            this.blurX = null;
-            this.blurY = null;
-            this.copyBack = null;
-            this.imageProcessing = null;
-            this.fxaa = null;
-            this.finalMerge = null;
+            (<any>this.pass) = null;
+            (<any>this.highlights) = null;
+            (<any>this.blurX) = null;
+            (<any>this.blurY) = null;
+            (<any>this.copyBack) = null;
+            (<any>this.imageProcessing) = null;
+            (<any>this.fxaa) = null;
+            (<any>this.finalMerge) = null;
         }
 
         // Dispose

+ 13 - 11
src/PostProcess/RenderPipeline/Pipelines/babylon.lensRenderingPipeline.ts

@@ -167,9 +167,9 @@ module BABYLON {
         public dispose(disableDepthRender: boolean = false): void {
             this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, this._scene.cameras);
 
-            this._chromaticAberrationPostProcess = undefined;
-            this._highlightsPostProcess = undefined;
-            this._depthOfFieldPostProcess = undefined;
+            (<any>this._chromaticAberrationPostProcess) = null;
+            (<any>this._highlightsPostProcess) = null;
+            (<any>this._depthOfFieldPostProcess) = null;
 
             this._grainTexture.dispose();
 
@@ -187,8 +187,8 @@ module BABYLON {
 
             this._chromaticAberrationPostProcess.onApply = (effect: Effect) => {
                 effect.setFloat('chromatic_aberration', this._chromaticAberration);
-                effect.setFloat('screen_width', this._scene.getEngine().getRenderingCanvas().width);
-                effect.setFloat('screen_height', this._scene.getEngine().getRenderingCanvas().height);
+                effect.setFloat('screen_width', this._scene.getEngine().getRenderWidth());
+                effect.setFloat('screen_height', this._scene.getEngine().getRenderHeight());
             };
         }
 
@@ -205,8 +205,8 @@ module BABYLON {
                 effect.setFloat('gain', this._highlightsGain);
                 effect.setFloat('threshold', this._highlightsThreshold);
                 effect.setTextureFromPostProcess("textureSampler", this._chromaticAberrationPostProcess);
-                effect.setFloat('screen_width', this._scene.getEngine().getRenderingCanvas().width);
-                effect.setFloat('screen_height', this._scene.getEngine().getRenderingCanvas().height);
+                effect.setFloat('screen_width', this._scene.getEngine().getRenderWidth());
+                effect.setFloat('screen_height', this._scene.getEngine().getRenderHeight());
             };
         }
 
@@ -231,8 +231,8 @@ module BABYLON {
                 effect.setFloat('grain_amount', this._grainAmount);
                 effect.setBool('blur_noise', this._blurNoise);
 
-                effect.setFloat('screen_width', this._scene.getEngine().getRenderingCanvas().width);
-                effect.setFloat('screen_height', this._scene.getEngine().getRenderingCanvas().height);
+                effect.setFloat('screen_width', this._scene.getEngine().getRenderWidth());
+                effect.setFloat('screen_height', this._scene.getEngine().getRenderHeight());
 
                 effect.setFloat('distortion', this._distortion);
 
@@ -245,8 +245,10 @@ module BABYLON {
 
                 effect.setBool('highlights', (this._highlightsGain !== -1));
 
-                effect.setFloat('near', this._scene.activeCamera.minZ);
-                effect.setFloat('far', this._scene.activeCamera.maxZ);
+                if (this._scene.activeCamera) {
+                    effect.setFloat('near', this._scene.activeCamera.minZ);
+                    effect.setFloat('far', this._scene.activeCamera.maxZ);
+                }
             };
         }
 

+ 18 - 2
src/PostProcess/RenderPipeline/Pipelines/babylon.ssao2RenderingPipeline.ts

@@ -120,6 +120,9 @@
         */
         public static get IsSupported(): boolean {
             var engine = Engine.LastCreatedEngine;
+            if (!engine) {
+                return false;
+            }
             return engine.getCaps().drawBuffersExtension;
         }
 
@@ -164,9 +167,10 @@
             };
 
             // Set up assets
+            let geometryBufferRenderer = <GeometryBufferRenderer>scene.enableGeometryBufferRenderer();
             this._createRandomTexture();
-            this._depthTexture = scene.enableGeometryBufferRenderer().getGBuffer().textures[0]; 
-            this._normalTexture = scene.enableGeometryBufferRenderer().getGBuffer().textures[1];
+            this._depthTexture = geometryBufferRenderer.getGBuffer().textures[0]; 
+            this._normalTexture = geometryBufferRenderer.getGBuffer().textures[1];
 
             this._originalColorPostProcess = new PassPostProcess("SSAOOriginalSceneColor", 1.0, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
             this._createSSAOPostProcess(1.0);
@@ -224,6 +228,10 @@
 
             this._blurHPostProcess = new PostProcess("BlurH", "ssao2", ["outSize", "samplerOffsets", "near", "far", "radius"], ["depthSampler"], ssaoRatio, null, Texture.TRILINEAR_SAMPLINGMODE, this._scene.getEngine(), false, "#define BILATERAL_BLUR\n#define BILATERAL_BLUR_H\n#define SAMPLES 16\n#define EXPENSIVE " + (expensive ? "1" : "0") + "\n");
             this._blurHPostProcess.onApply = (effect: Effect) => {
+                if (!this._scene.activeCamera) {
+                    return;
+                }
+
                 effect.setFloat("outSize", this._ssaoCombinePostProcess.width);
                 effect.setFloat("near", this._scene.activeCamera.minZ);
                 effect.setFloat("far", this._scene.activeCamera.maxZ);
@@ -237,6 +245,10 @@
 
             this._blurVPostProcess = new PostProcess("BlurV", "ssao2", ["outSize", "samplerOffsets", "near", "far", "radius"], ["depthSampler"], blurRatio, null, Texture.TRILINEAR_SAMPLINGMODE, this._scene.getEngine(), false, "#define BILATERAL_BLUR\n#define BILATERAL_BLUR_V\n#define SAMPLES 16\n#define EXPENSIVE " + (expensive ? "1" : "0") + "\n");
             this._blurVPostProcess.onApply = (effect: Effect) => {
+                if (!this._scene.activeCamera) {
+                    return;
+                }
+
                 effect.setFloat("outSize", this._ssaoCombinePostProcess.height);
                 effect.setFloat("near", this._scene.activeCamera.minZ);
                 effect.setFloat("far", this._scene.activeCamera.maxZ);
@@ -306,6 +318,10 @@
                     effect.setFloat("randTextureTiles", 4.0);
                 }
 
+                if (!this._scene.activeCamera) {
+                    return;
+                }
+
                 effect.setFloat("samplesFactor", 1 / this.samples);
                 effect.setFloat("totalStrength", this.totalStrength);
                 effect.setFloat2("texelSize", 1 / this._ssaoPostProcess.width, 1 / this._ssaoPostProcess.height);

+ 58 - 45
src/PostProcess/RenderPipeline/Pipelines/babylon.standardRenderingPipeline.ts

@@ -4,33 +4,33 @@
         * Public members
         */
         // Post-processes
-        public originalPostProcess: PostProcess;
-        public downSampleX4PostProcess: PostProcess = null;
-        public brightPassPostProcess: PostProcess = null;
+        public originalPostProcess: Nullable<PostProcess>;
+        public downSampleX4PostProcess: Nullable<PostProcess> = null;
+        public brightPassPostProcess: Nullable<PostProcess> = null;
         public blurHPostProcesses: PostProcess[] = [];
         public blurVPostProcesses: PostProcess[] = [];
-        public textureAdderPostProcess: PostProcess = null;
+        public textureAdderPostProcess: Nullable<PostProcess> = null;
 
-        public volumetricLightPostProcess: PostProcess = null;
-        public volumetricLightSmoothXPostProcess: BlurPostProcess = null;
-        public volumetricLightSmoothYPostProcess: BlurPostProcess = null;
-        public volumetricLightMergePostProces: PostProcess = null;
-        public volumetricLightFinalPostProcess: PostProcess = null;
+        public volumetricLightPostProcess: Nullable<PostProcess> = null;
+        public volumetricLightSmoothXPostProcess: Nullable<BlurPostProcess> = null;
+        public volumetricLightSmoothYPostProcess: Nullable<BlurPostProcess> = null;
+        public volumetricLightMergePostProces: Nullable<PostProcess> = null;
+        public volumetricLightFinalPostProcess: Nullable<PostProcess> = null;
 
-        public luminancePostProcess: PostProcess = null;
+        public luminancePostProcess: Nullable<PostProcess> = null;
         public luminanceDownSamplePostProcesses: PostProcess[] = [];
-        public hdrPostProcess: PostProcess = null;
+        public hdrPostProcess: Nullable<PostProcess> = null;
 
-        public textureAdderFinalPostProcess: PostProcess = null;
-        public lensFlareFinalPostProcess: PostProcess = null;
-        public hdrFinalPostProcess: PostProcess = null;
+        public textureAdderFinalPostProcess: Nullable<PostProcess> = null;
+        public lensFlareFinalPostProcess: Nullable<PostProcess> = null;
+        public hdrFinalPostProcess: Nullable<PostProcess> = null;
 
-        public lensFlarePostProcess: PostProcess = null;
-        public lensFlareComposePostProcess: PostProcess = null;
+        public lensFlarePostProcess: Nullable<PostProcess> = null;
+        public lensFlareComposePostProcess: Nullable<PostProcess> = null;
 
-        public motionBlurPostProcess: PostProcess = null;
+        public motionBlurPostProcess: Nullable<PostProcess> = null;
 
-        public depthOfFieldPostProcess: PostProcess = null;
+        public depthOfFieldPostProcess: Nullable<PostProcess> = null;
 
         // Values
         @serialize()
@@ -44,7 +44,7 @@
         @serialize()
         public exposure: number = 1.0;
         @serializeAsTexture("lensTexture")
-        public lensTexture: Texture = null;
+        public lensTexture: Nullable<Texture> = null;
 
         @serialize()
         public volumetricLightCoefficient: number = 0.2;
@@ -53,7 +53,7 @@
         @serialize()
         public volumetricLightBlurScale: number = 64.0;
 
-        public sourceLight: SpotLight | DirectionalLight = null;
+        public sourceLight: Nullable<SpotLight | DirectionalLight> = null;
 
         @serialize()
         public hdrMinimumLuminance: number = 1.0;
@@ -63,7 +63,7 @@
         public hdrIncreaseRate: number = 0.5;
 
         @serializeAsTexture("lensColorTexture")
-        public lensColorTexture: Texture = null;
+        public lensColorTexture: Nullable<Texture> = null;
         @serialize()
         public lensFlareStrength: number = 20.0;
         @serialize()
@@ -73,9 +73,9 @@
         @serialize()
         public lensFlareDistortionStrength: number = 16.0;
         @serializeAsTexture("lensStarTexture")
-        public lensStarTexture: Texture = null;
+        public lensStarTexture: Nullable<Texture> = null;
         @serializeAsTexture("lensFlareDirtTexture")
-        public lensFlareDirtTexture: Texture = null;
+        public lensFlareDirtTexture: Nullable<Texture> = null;
 
         @serialize()
         public depthOfFieldDistance: number = 10.0;
@@ -93,8 +93,8 @@
         * Private members
         */
         private _scene: Scene;
-        private _currentDepthOfFieldSource: PostProcess = null;
-        private _basePostProcess: PostProcess;
+        private _currentDepthOfFieldSource: Nullable<PostProcess> = null;
+        private _basePostProcess: Nullable<PostProcess>;
 
         private _hdrCurrentLuminance: number = 1.0;
 
@@ -238,7 +238,7 @@
          * @param {BABYLON.PostProcess} originalPostProcess - the custom original color post-process. Must be "reusable". Can be null.
          * @param {BABYLON.Camera[]} cameras - The array of cameras that the rendering pipeline will be attached to
          */
-        constructor(name: string, scene: Scene, ratio: number, originalPostProcess: PostProcess = null, cameras?: Camera[]) {
+        constructor(name: string, scene: Scene, ratio: number, originalPostProcess: Nullable<PostProcess> = null, cameras?: Camera[]) {
             super(scene.getEngine(), name);
             this._cameras = cameras || [];
 
@@ -350,10 +350,14 @@
 
             this.downSampleX4PostProcess.onApply = (effect: Effect) => {
                 var id = 0;
+                let width = (<PostProcess>this.downSampleX4PostProcess).width;
+                let height = (<PostProcess>this.downSampleX4PostProcess).height;
+
+
                 for (var i = -2; i < 2; i++) {
                     for (var j = -2; j < 2; j++) {
-                        downSampleX4Offsets[id] = (i + 0.5) * (1.0 / this.downSampleX4PostProcess.width);
-                        downSampleX4Offsets[id + 1] = (j + 0.5) * (1.0 / this.downSampleX4PostProcess.height);
+                        downSampleX4Offsets[id] = (i + 0.5) * (1.0 / width);
+                        downSampleX4Offsets[id + 1] = (j + 0.5) * (1.0 / height);
                         id += 2;
                     }
                 }
@@ -371,8 +375,8 @@
             this.brightPassPostProcess = new PostProcess("HDRBrightPass", "standard", ["dsOffsets", "brightThreshold"], [], ratio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, "#define BRIGHT_PASS", Engine.TEXTURETYPE_UNSIGNED_INT);
 
             this.brightPassPostProcess.onApply = (effect: Effect) => {
-                var sU = (1.0 / this.brightPassPostProcess.width);
-                var sV = (1.0 / this.brightPassPostProcess.height);
+                var sU = (1.0 / (<PostProcess>this.brightPassPostProcess).width);
+                var sV = (1.0 / (<PostProcess>this.brightPassPostProcess).height);
 
                 brightOffsets[0] = -0.5 * sU;
                 brightOffsets[1] = 0.5 * sV;
@@ -399,12 +403,12 @@
             var blurY = new BlurPostProcess("HDRBlurV" + "_" + indice, new Vector2(0, 1), (<any>this)[blurWidthKey], ratio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, Engine.TEXTURETYPE_UNSIGNED_INT);
 
             blurX.onActivateObservable.add(() => {
-                let dw = blurX.width / engine.getRenderingCanvas().width;
+                let dw = blurX.width / engine.getRenderWidth();
                 blurX.kernel = (<any>this)[blurWidthKey] * dw;
             });
 
             blurY.onActivateObservable.add(() => {
-                let dw = blurY.height / engine.getRenderingCanvas().height;
+                let dw = blurY.height / engine.getRenderHeight();
                 blurY.kernel = this.horizontalBlur ? 64 * dw : (<any>this)[blurWidthKey] * dw;
             });
 
@@ -432,7 +436,7 @@
         }
 
         private _createVolumetricLightPostProcess(scene: Scene, ratio: number): void {
-            var geometryRenderer = scene.enableGeometryBufferRenderer();
+            var geometryRenderer = <GeometryBufferRenderer>scene.enableGeometryBufferRenderer();
             geometryRenderer.enablePosition = true;
 
             var geometry = geometryRenderer.getGBuffer();
@@ -450,7 +454,7 @@
             var depthValues = Vector2.Zero();
 
             this.volumetricLightPostProcess.onApply = (effect: Effect) => {
-                if (this.sourceLight && this.sourceLight.getShadowGenerator()) {
+                if (this.sourceLight && this.sourceLight.getShadowGenerator() && this._scene.activeCamera) {
                     var generator = <ShadowGenerator>this.sourceLight.getShadowGenerator();
 
                     effect.setTexture("shadowMapSampler", generator.getShadowMap());
@@ -459,7 +463,7 @@
                     effect.setColor3("sunColor", this.sourceLight.diffuse);
                     effect.setVector3("sunDirection", this.sourceLight.getShadowDirection());
                     
-                    effect.setVector3("cameraPosition", scene.activeCamera.globalPosition);
+                    effect.setVector3("cameraPosition", this._scene.activeCamera.globalPosition);
                     effect.setMatrix("shadowViewProjection", generator.getTransformMatrix());
 
                     effect.setFloat("scatteringCoefficient", this.volumetricLightCoefficient);
@@ -496,8 +500,8 @@
 
             var offsets: number[] = [];
             this.luminancePostProcess.onApply = (effect: Effect) => {
-                var sU = (1.0 / this.luminancePostProcess.width);
-                var sV = (1.0 / this.luminancePostProcess.height);
+                var sU = (1.0 / (<PostProcess>this.luminancePostProcess).width);
+                var sV = (1.0 / (<PostProcess>this.luminancePostProcess).height);
 
                 offsets[0] = -0.5 * sU;
                 offsets[1] = 0.5 * sV;
@@ -528,12 +532,16 @@
             }
 
             // Create callbacks and add effects
-            var lastLuminance = this.luminancePostProcess;
+            var lastLuminance: Nullable<PostProcess> = this.luminancePostProcess;
 
             this.luminanceDownSamplePostProcesses.forEach((pp, index) => {
                 var downSampleOffsets = new Array<number>(18);
 
                 pp.onApply = (effect: Effect) => {
+                    if (!lastLuminance) {
+                        return;
+                    }
+
                     var id = 0;
                     for (var x = -1; x < 2; x++) {
                         for (var y = -1; y < 2; y++) {
@@ -627,8 +635,8 @@
                 effect.setFloat("haloWidth", this.lensFlareHaloWidth);
 
                 // Shift
-                resolution.x = this.lensFlarePostProcess.width;
-                resolution.y = this.lensFlarePostProcess.height;
+                resolution.x = (<PostProcess>this.lensFlarePostProcess).width;
+                resolution.y = (<PostProcess>this.lensFlarePostProcess).height;
                 effect.setVector2("resolution", resolution);
 
                 effect.setFloat("distortionStrength", this.lensFlareDistortionStrength);
@@ -650,13 +658,17 @@
             );
 
             this.lensFlareComposePostProcess.onApply = (effect: Effect) => {
+                if (!this._scene.activeCamera) {
+                    return;
+                }
+
                 effect.setTextureFromPostProcess("otherSampler", this._currentDepthOfFieldSource);
                 effect.setTexture("lensDirtSampler", this.lensFlareDirtTexture);
                 effect.setTexture("lensStarSampler", this.lensStarTexture);
 
                 // Lens start rotation matrix
-                var camerax = this._scene.activeCamera.getViewMatrix().getRow(0);
-                var cameraz = this._scene.activeCamera.getViewMatrix().getRow(2);
+                var camerax = (<Vector4>this._scene.activeCamera.getViewMatrix().getRow(0));
+                var cameraz = (<Vector4>this._scene.activeCamera.getViewMatrix().getRow(2));
                 var camRot = Vector3.Dot(camerax.toVector3(), new Vector3(1.0, 0.0, 0.0)) + Vector3.Dot(cameraz.toVector3(), new Vector3(0.0, 0.0, 1.0));
                 camRot *= 4.0;
 
@@ -711,8 +723,8 @@
                 effect.setMatrix("prevViewProjection", prevViewProjection);
                 prevViewProjection = viewProjection;
 
-                screenSize.x = this.motionBlurPostProcess.width;
-                screenSize.y = this.motionBlurPostProcess.height;
+                screenSize.x = (<PostProcess>this.motionBlurPostProcess).width;
+                screenSize.y = (<PostProcess>this.motionBlurPostProcess).height;
                 effect.setVector2("screenSize", screenSize);
 
                 motionScale = scene.getEngine().getFps() / 60.0;
@@ -727,7 +739,8 @@
 
         private _getDepthTexture(): Texture {
             if (this._scene.getEngine().getCaps().drawBuffersExtension) {
-                return this._scene.enableGeometryBufferRenderer().getGBuffer().textures[0];
+                let renderer = <GeometryBufferRenderer>this._scene.enableGeometryBufferRenderer();
+                return renderer.getGBuffer().textures[0];
             }
 
             return this._scene.enableDepthRenderer().getDepthMap();

+ 39 - 19
src/PostProcess/RenderPipeline/babylon.postProcessRenderEffect.ts

@@ -3,11 +3,11 @@ module BABYLON {
         private _engine: Engine;
 
         private _postProcesses: any;
-        private _getPostProcess: () => PostProcess;
+        private _getPostProcess: () => Nullable<PostProcess>;
 
         private _singleInstance: boolean;
 
-        private _cameras: { [key:string]: Camera};
+        private _cameras: { [key:string]: Nullable<Camera>};
         private _indicesForCamera: { [key:string]: number[]};
 
         private _renderPasses: any;
@@ -18,7 +18,7 @@ module BABYLON {
 
         public applyParameters: (postProcess: PostProcess) => void;
 
-        constructor(engine: Engine, name: string, getPostProcess: () => PostProcess, singleInstance?: boolean) {
+        constructor(engine: Engine, name: string, getPostProcess: () => Nullable<PostProcess>, singleInstance?: boolean) {
             this._engine = engine;
             this._name = name;
             this._singleInstance = singleInstance || true;
@@ -67,7 +67,7 @@ module BABYLON {
             this._linkParameters();
         }
 
-        public getPass(passName: string): PostProcessRenderPass {
+        public getPass(passName: string): Nullable<PostProcessRenderPass> {
             for (var renderPassName in this._renderPasses) {
                 if (renderPassName === passName) {
                     return this._renderPasses[passName];
@@ -89,10 +89,14 @@ module BABYLON {
         public _attachCameras(cameras: any): void {
             var cameraKey;
 
-            var _cam = Tools.MakeArray(cameras || this._cameras);
+            var cams = Tools.MakeArray(cameras || this._cameras);
 
-            for (var i = 0; i < _cam.length; i++) {
-                var camera = _cam[i];
+            if (!cams) {
+                return;
+            }
+
+            for (var i = 0; i < cams.length; i++) {
+                var camera = cams[i];
                 var cameraName = camera.name;
 
                 if (this._singleInstance) {
@@ -128,10 +132,14 @@ module BABYLON {
         public _detachCameras(cameras: Camera): void;
         public _detachCameras(cameras: Camera[]): void;
         public _detachCameras(cameras: any): void {
-            var _cam = Tools.MakeArray(cameras || this._cameras);
+            var cams = Tools.MakeArray(cameras || this._cameras);
 
-            for (var i = 0; i < _cam.length; i++) {
-                var camera: Camera = _cam[i];
+            if (!cams) {
+                return;
+            }
+
+            for (var i = 0; i < cams.length; i++) {
+                var camera: Camera = cams[i];
                 var cameraName: string = camera.name;
 
                 camera.detachPostProcess(this._postProcesses[this._singleInstance ? 0 : cameraName]);
@@ -149,12 +157,16 @@ module BABYLON {
 
         // private
         public _enable(cameras: Camera): void;
-        public _enable(cameras: Camera[]): void;
+        public _enable(cameras: Nullable<Camera[]>): void;
         public _enable(cameras: any): void {
-            var _cam = Tools.MakeArray(cameras || this._cameras);
+            var cams = Tools.MakeArray(cameras || this._cameras);
+
+            if (!cams) {
+                return;
+            }
 
-            for (var i = 0; i < _cam.length; i++) {
-                var camera = _cam[i];
+            for (var i = 0; i < cams.length; i++) {
+                var camera = cams[i];
                 var cameraName = camera.name;
 
                 for (var j = 0; j < this._indicesForCamera[cameraName].length; j++) {
@@ -171,12 +183,16 @@ module BABYLON {
 
         // private
         public _disable(cameras: Camera): void;
-        public _disable(cameras: Camera[]): void;
+        public _disable(cameras: Nullable<Camera[]>): void;
         public _disable(cameras: any): void {
-            var _cam = Tools.MakeArray(cameras || this._cameras);
+            var cams = Tools.MakeArray(cameras || this._cameras);
+
+            if (!cams) {
+                return;
+            }
 
-            for (var i = 0; i < _cam.length; i++) {
-                var camera = _cam[i];
+            for (var i = 0; i < cams.length; i++) {
+                var camera = cams[i];
                 var cameraName = camera.Name;
 
                 camera.detachPostProcess(this._postProcesses[this._singleInstance ? 0 : cameraName]);
@@ -187,11 +203,15 @@ module BABYLON {
             }
         }
 
-        public getPostProcess(camera?: Camera): PostProcess {
+        public getPostProcess(camera?: Camera): Nullable<PostProcess> {
             if (this._singleInstance) {
                 return this._postProcesses[0];
             }
             else {
+
+                if (!camera) {
+                    return null;
+                }
                 return this._postProcesses[camera.name];
             }
         }

+ 40 - 24
src/PostProcess/RenderPipeline/babylon.postProcessRenderPipeline.ts

@@ -62,9 +62,9 @@ module BABYLON {
             renderEffects._enable(Tools.MakeArray(cameras || this._cameras));
         }
 
-        public _disableEffect(renderEffectName: string, cameras: Camera[]): void;
-        public _disableEffect(renderEffectName: string, cameras: Camera[]): void;
-        public _disableEffect(renderEffectName: string, cameras: Camera[]): void {
+        public _disableEffect(renderEffectName: string, cameras: Nullable<Camera[]>): void;
+        public _disableEffect(renderEffectName: string, cameras: Nullable<Camera[]>): void;
+        public _disableEffect(renderEffectName: string, cameras: Nullable<Camera[]>): void {
             var renderEffects: PostProcessRenderEffect = (<any>this._renderEffects)[renderEffectName];
 
             if (!renderEffects) {
@@ -77,12 +77,16 @@ module BABYLON {
         public _attachCameras(cameras: Camera, unique: boolean): void;
         public _attachCameras(cameras: Camera[], unique: boolean): void;
         public _attachCameras(cameras: any, unique: boolean): void {
-            var _cam = Tools.MakeArray(cameras || this._cameras);
+            var cams = Tools.MakeArray(cameras || this._cameras);
+
+            if (!cams) {
+                return;
+            }
 
             var indicesToDelete = [];
             var i: number;
-            for (i = 0; i < _cam.length; i++) {
-                var camera = _cam[i];
+            for (i = 0; i < cams.length; i++) {
+                var camera = cams[i];
                 var cameraName = camera.name;
 
                 if (this._cameras.indexOf(camera) === -1) {
@@ -99,33 +103,41 @@ module BABYLON {
 
             for (var renderEffectName in this._renderEffects) {
                 if (this._renderEffects.hasOwnProperty(renderEffectName)) {
-                    this._renderEffects[renderEffectName]._attachCameras(_cam);
+                    this._renderEffects[renderEffectName]._attachCameras(cams);
                 }
             }
         }
 
         public _detachCameras(cameras: Camera): void;
-        public _detachCameras(cameras: Camera[]): void;
+        public _detachCameras(cameras: Nullable<Camera[]>): void;
         public _detachCameras(cameras: any): void {
-            var _cam = Tools.MakeArray(cameras || this._cameras);
+            var cams = Tools.MakeArray(cameras || this._cameras);
+
+            if (!cams) {
+                return;
+            }
 
             for (var renderEffectName in this._renderEffects) {
                 if (this._renderEffects.hasOwnProperty(renderEffectName)) {
-                    this._renderEffects[renderEffectName]._detachCameras(_cam);
+                    this._renderEffects[renderEffectName]._detachCameras(cams);
                 }
             }
 
-            for (var i = 0; i < _cam.length; i++) {
-                this._cameras.splice(this._cameras.indexOf(_cam[i]), 1);
+            for (var i = 0; i < cams.length; i++) {
+                this._cameras.splice(this._cameras.indexOf(cams[i]), 1);
             }
         }
 
         public _enableDisplayOnlyPass(passName: string, cameras: Camera): void;
-        public _enableDisplayOnlyPass(passName: string, cameras: Camera[]): void;
+        public _enableDisplayOnlyPass(passName: string, cameras: Nullable<Camera[]>): void;
         public _enableDisplayOnlyPass(passName: string, cameras: any): void {
-            var _cam = Tools.MakeArray(cameras || this._cameras);
+            var cams = Tools.MakeArray(cameras || this._cameras);
 
-            var pass: PostProcessRenderPass = null;
+            if (!cams) {
+                return;
+            }
+
+            var pass: Nullable<PostProcessRenderPass> = null;
             var renderEffectName;
             for (renderEffectName in this._renderEffects) {
                 if (this._renderEffects.hasOwnProperty(renderEffectName)) {
@@ -143,18 +155,18 @@ module BABYLON {
 
             for (renderEffectName in this._renderEffects) {
                 if (this._renderEffects.hasOwnProperty(renderEffectName)) {
-                    this._renderEffects[renderEffectName]._disable(_cam);
+                    this._renderEffects[renderEffectName]._disable(cams);
                 }
             }
 
             pass._name = PostProcessRenderPipeline.PASS_SAMPLER_NAME;
 
-            for (var i = 0; i < _cam.length; i++) {
-                var camera = _cam[i];
+            for (var i = 0; i < cams.length; i++) {
+                var camera = cams[i];
                 var cameraName = camera.name;
 
                 this._renderEffectsForIsolatedPass[cameraName] = this._renderEffectsForIsolatedPass[cameraName] || new PostProcessRenderEffect(this._engine, PostProcessRenderPipeline.PASS_EFFECT_NAME,
-                    () => {return new DisplayPassPostProcess(PostProcessRenderPipeline.PASS_EFFECT_NAME, 1.0, null, null, this._engine, true) });
+                    () => {return new DisplayPassPostProcess(PostProcessRenderPipeline.PASS_EFFECT_NAME, 1.0, null, undefined, this._engine, true) });
                 this._renderEffectsForIsolatedPass[cameraName].emptyPasses();
                 this._renderEffectsForIsolatedPass[cameraName].addPass(pass);
                 this._renderEffectsForIsolatedPass[cameraName]._attachCameras(camera);
@@ -164,20 +176,24 @@ module BABYLON {
         public _disableDisplayOnlyPass(cameras: Camera): void;
         public _disableDisplayOnlyPass(cameras: Camera[]): void;
         public _disableDisplayOnlyPass(cameras: any): void {
-            var _cam = Tools.MakeArray(cameras || this._cameras);
+            var cams = Tools.MakeArray(cameras || this._cameras);
+
+            if (!cams) {
+                return;
+            }
 
-            for (var i = 0; i < _cam.length; i++) {
-                var camera = _cam[i];
+            for (var i = 0; i < cams.length; i++) {
+                var camera = cams[i];
                 var cameraName = camera.name;
 
                 this._renderEffectsForIsolatedPass[cameraName] = this._renderEffectsForIsolatedPass[cameraName] || new PostProcessRenderEffect(this._engine, PostProcessRenderPipeline.PASS_EFFECT_NAME, 
-                                    () => {return new DisplayPassPostProcess(PostProcessRenderPipeline.PASS_EFFECT_NAME, 1.0, null, null, this._engine, true) });
+                                    () => {return new DisplayPassPostProcess(PostProcessRenderPipeline.PASS_EFFECT_NAME, 1.0, null, undefined, this._engine, true) });
                 this._renderEffectsForIsolatedPass[cameraName]._disable(camera);
             }
 
             for (var renderEffectName in this._renderEffects) {
                 if (this._renderEffects.hasOwnProperty(renderEffectName)) {
-                    this._renderEffects[renderEffectName]._enable(_cam);
+                    this._renderEffects[renderEffectName]._enable(cams);
                 }
             }
         }

+ 1 - 1
src/PostProcess/RenderPipeline/babylon.postProcessRenderPipelineManager.ts

@@ -12,7 +12,7 @@ module BABYLON {
 
         public attachCamerasToRenderPipeline(renderPipelineName: string, cameras: Camera, unique?: boolean): void;
         public attachCamerasToRenderPipeline(renderPipelineName: string, cameras: Camera[], unique?: boolean): void;
-        public attachCamerasToRenderPipeline(renderPipelineName: string, cameras: any, unique?: boolean): void {
+        public attachCamerasToRenderPipeline(renderPipelineName: string, cameras: any, unique: boolean = false): void {
             var renderPipeline: PostProcessRenderPipeline = this._renderPipelines[renderPipelineName];
 
             if (!renderPipeline) {

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

@@ -1,6 +1,6 @@
 module BABYLON {
     export class AnaglyphPostProcess extends PostProcess {
-        private _passedProcess : PostProcess;
+        private _passedProcess : Nullable<PostProcess>;
 
         constructor(name: string, options: number | PostProcessOptions,  rigCameras: Camera[], samplingMode?: number, engine?: Engine, reusable?: boolean) {
             super(name, "anaglyph", null, ["leftSampler"], options, rigCameras[1], samplingMode, engine, reusable);

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

@@ -1,6 +1,6 @@
 module BABYLON {
     export class DisplayPassPostProcess extends PostProcess {
-        constructor(name: string, options: number | PostProcessOptions, camera: Camera, samplingMode?: number, engine?: Engine, reusable?: boolean) {
+        constructor(name: string, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode?: number, engine?: Engine, reusable?: boolean) {
             super(name, "displayPass", ["passSampler"], ["passSampler"], options, camera, samplingMode, engine, reusable);
         }
     }

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

@@ -1,6 +1,6 @@
 module BABYLON {
     export class FilterPostProcess extends PostProcess {
-        constructor(name: string, public kernelMatrix: Matrix, options: number | PostProcessOptions, camera?: Camera, samplingMode?: number, engine?: Engine, reusable?: boolean) {
+        constructor(name: string, public kernelMatrix: Matrix, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode?: number, engine?: Engine, reusable?: boolean) {
             super(name, "filter", ["kernelMatrix"], null, options, camera, samplingMode, engine, reusable);
 
             this.onApply = (effect: Effect) => {

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

@@ -3,7 +3,7 @@
         public texelWidth: number;
         public texelHeight: number;
 
-        constructor(name: string, options: number | PostProcessOptions, camera: Camera, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
+        constructor(name: string, options: number | PostProcessOptions, camera: Nullable<Camera> = null, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
             super(name, "fxaa", ["texelSize"], null, options, camera, samplingMode || BABYLON.Texture.BILINEAR_SAMPLINGMODE, engine, reusable, null, textureType, "fxaa");
 
             this.onApplyObservable.add((effect: Effect) => {

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

@@ -1,6 +1,6 @@
 module BABYLON {
     export class HighlightsPostProcess extends PostProcess {
-        constructor(name: string, options: number | PostProcessOptions, camera: Camera, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
+        constructor(name: string, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
             super(name, "highlights", null, null, options, camera, samplingMode, engine, reusable, null, textureType);
         }
     }

+ 4 - 4
src/PostProcess/babylon.imageProcessingPostProcess.ts

@@ -25,13 +25,13 @@
         /**
          * Keep track of the image processing observer to allow dispose and replace.
          */
-        private _imageProcessingObserver: Observer<ImageProcessingConfiguration>;
+        private _imageProcessingObserver: Nullable<Observer<ImageProcessingConfiguration>>;
 
         /**
          * Attaches a new image processing configuration to the PBR Material.
          * @param configuration 
          */
-        protected _attachImageProcessingConfiguration(configuration: ImageProcessingConfiguration, doNotBuild = false): void {
+        protected _attachImageProcessingConfiguration(configuration: Nullable<ImageProcessingConfiguration>, doNotBuild = false): void {
             if (configuration === this._imageProcessingConfiguration) {
                 return;
             }
@@ -58,7 +58,7 @@
                     scene = BABYLON.Engine.LastCreatedScene;
                 }
 
-                this._imageProcessingConfiguration = scene.imageProcessingConfiguration;
+                this._imageProcessingConfiguration = (<Scene>scene).imageProcessingConfiguration;
             }
             else {
                 this._imageProcessingConfiguration = configuration;
@@ -312,7 +312,7 @@
             EXPOSURE: false,
         }
 
-        constructor(name: string, options: number | PostProcessOptions, camera?: Camera, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
+        constructor(name: string, options: number | PostProcessOptions, camera: Nullable<Camera> = null, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
             super(name, "imageProcessing", [], [], options, camera, samplingMode, engine, reusable,
                                             null, textureType, "postprocess", null, true);
 

+ 4 - 2
src/PostProcess/babylon.postProcess.ts

@@ -50,11 +50,13 @@
         public onActivateObservable = new Observable<Camera>();
 
         private _onActivateObserver: Nullable<Observer<Camera>>;
-        public set onActivate(callback: (camera: Camera) => void) {
+        public set onActivate(callback: Nullable<(camera: Camera) => void>) {
             if (this._onActivateObserver) {
                 this.onActivateObservable.remove(this._onActivateObserver);
             }
-            this._onActivateObserver = this.onActivateObservable.add(callback);
+            if (callback) {
+                this._onActivateObserver = this.onActivateObservable.add(callback);
+            }
         }
 
         /**

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

@@ -1,7 +1,7 @@
 module BABYLON {
     export class StereoscopicInterlacePostProcess extends PostProcess {
         private _stepSize : Vector2;
-        private _passedProcess : PostProcess;
+        private _passedProcess : Nullable<PostProcess>;
 
         constructor(name: string, rigCameras: Camera[], isStereoscopicHoriz: boolean, samplingMode?: number, engine?: Engine, reusable?: boolean) {
             super(name, "stereoscopicInterlace", ['stepSize'], ['camASampler'], 1, rigCameras[1], samplingMode, engine, reusable, isStereoscopicHoriz ? "#define IS_STEREOSCOPIC_HORIZ 1" : undefined);

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

@@ -9,7 +9,7 @@
     export class TonemapPostProcess extends PostProcess {
 
         constructor(name: string, private _operator: TonemappingOperator, public exposureAdjustment: number, camera: Camera, samplingMode: number = Texture.BILINEAR_SAMPLINGMODE, engine?: Engine, textureFormat = Engine.TEXTURETYPE_UNSIGNED_INT) {
-            super(name, "tonemap", ["_ExposureAdjustment"], null, 1.0, camera, samplingMode, engine, true, defines, textureFormat);
+            super(name, "tonemap", ["_ExposureAdjustment"], null, 1.0, camera, samplingMode, engine, true, null, textureFormat);
 
             var defines = "#define ";
 

+ 22 - 14
src/PostProcess/babylon.volumetricLightScatteringPostProcess.ts

@@ -100,13 +100,13 @@
          */
         constructor(name: string, ratio: any, camera: Camera, mesh?: Mesh, samples: number = 100, samplingMode: number = Texture.BILINEAR_SAMPLINGMODE, engine?: Engine, reusable?: boolean, scene?: Scene) {
             super(name, "volumetricLightScattering", ["decay", "exposure", "weight", "meshPositionOnScreen", "density"], ["lightScatteringSampler"], ratio.postProcessRatio || ratio, camera, samplingMode, engine, reusable, "#define NUM_SAMPLES " + samples);
-            scene = (camera === null) ? scene : camera.getScene(); // parameter "scene" can be null.
+            scene = <Scene>((camera === null) ? scene : camera.getScene()) // parameter "scene" can be null.
 
-            var engine = scene.getEngine();
+            engine = scene.getEngine();
             this._viewPort = new Viewport(0, 0, 1, 1).toGlobal(engine.getRenderWidth(), engine.getRenderHeight());
 
             // Configure mesh
-            this.mesh = (mesh !== null) ? mesh : VolumetricLightScatteringPostProcess.CreateDefaultMesh("VolumetricLightScatteringMesh", scene);
+            this.mesh = (<Mesh>((mesh !== null) ? mesh : VolumetricLightScatteringPostProcess.CreateDefaultMesh("VolumetricLightScatteringMesh", scene)));
 
             // Configure
             this._createPass(scene, ratio.passRatio || ratio);
@@ -120,7 +120,7 @@
             };
 
             this.onApplyObservable.add((effect: Effect) => {
-                this._updateMeshScreenCoordinates(scene);
+                this._updateMeshScreenCoordinates(<Scene>scene);
 
                 effect.setTexture("lightScatteringSampler", this._volumetricLightScatteringRTT);
                 effect.setFloat("exposure", this.exposure);
@@ -139,7 +139,7 @@
             var mesh = subMesh.getMesh();
 
             // Render this.mesh as default
-            if (mesh === this.mesh) {
+            if (mesh === this.mesh && mesh.material) {
                 return mesh.material.isReady(mesh);
             }
 
@@ -168,7 +168,7 @@
                 attribs.push(VertexBuffer.MatricesIndicesKind);
                 attribs.push(VertexBuffer.MatricesWeightsKind);
                 defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
-                defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
+                defines.push("#define BonesPerMesh " + (mesh.skeleton ? (mesh.skeleton.bones.length + 1) : 0));
             } else {
                 defines.push("#define NUM_BONE_INFLUENCERS 0"); 
             }
@@ -265,12 +265,18 @@
                 if (this._meshExcluded(mesh)) {
                     return;
                 }
+                
+                let material = subMesh.getMaterial();
+
+                if (!material) {
+                    return;
+                }
 
                 var scene = mesh.getScene();
                 var engine = scene.getEngine();
 
                 // Culling
-                engine.setState(subMesh.getMaterial().backFaceCulling);
+                engine.setState(material.backFaceCulling);
 
                 // Managing instances
                 var batch = mesh._getInstancesRenderList(subMesh._id);
@@ -287,7 +293,7 @@
                         if (subMesh.effect) {
                             effect = subMesh.effect;
                         } else {
-                            effect = subMesh.getMaterial().getEffect();
+                            effect = <Effect>material.getEffect();
                         }
                     }
 
@@ -295,11 +301,9 @@
                     mesh._bind(subMesh, effect, Material.TriangleFillMode);
 
                     if (mesh === this.mesh) {
-                        subMesh.getMaterial().bind(mesh.getWorldMatrix(), mesh);
+                        material.bind(mesh.getWorldMatrix(), mesh);
                     }
                     else {
-                        var material: any = subMesh.getMaterial();
-
                         this._volumetricLightScatteringPass.setMatrix("viewProjection", scene.getTransformMatrix());
 
                         // Alpha test
@@ -314,7 +318,7 @@
                         }
 
                         // Bones
-                        if (mesh.useBones && mesh.computeBonesUsingShaders) {
+                        if (mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {
                             this._volumetricLightScatteringPass.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
                         }
                     }
@@ -364,8 +368,12 @@
                     // Sort sub meshes
                     for (index = 0; index < transparentSubMeshes.length; index++) {
                         var submesh = transparentSubMeshes.data[index];
-                        submesh._alphaIndex = submesh.getMesh().alphaIndex;
-                        submesh._distanceToCamera = submesh.getBoundingInfo().boundingSphere.centerWorld.subtract(scene.activeCamera.position).length();
+                        let boundingInfo = submesh.getBoundingInfo();
+
+                        if (boundingInfo && scene.activeCamera) {
+                            submesh._alphaIndex = submesh.getMesh().alphaIndex;
+                            submesh._distanceToCamera = boundingInfo.boundingSphere.centerWorld.subtract(scene.activeCamera.position).length();
+                        }
                     }
 
                     var sortedArray = transparentSubMeshes.data.slice(0, transparentSubMeshes.length);

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

@@ -16,7 +16,7 @@
                 'Scale',
                 'ScaleIn',
                 'HmdWarpParam'
-            ], null, vrMetrics.postProcessScaleFactor, camera, Texture.BILINEAR_SAMPLINGMODE, null, null);
+            ], null, vrMetrics.postProcessScaleFactor, camera, Texture.BILINEAR_SAMPLINGMODE);
 
             this._isRightEye = isRightEye;
             this._distortionFactors = vrMetrics.distortionK;

+ 5 - 3
src/Probes/babylon.reflectionProbe.ts

@@ -56,7 +56,9 @@
                 scene.updateTransformMatrix(true);
             });
 
-            this._projectionMatrix = Matrix.PerspectiveFovLH(Math.PI / 2, 1, scene.activeCamera.minZ, scene.activeCamera.maxZ);
+            if (scene.activeCamera) {
+                this._projectionMatrix = Matrix.PerspectiveFovLH(Math.PI / 2, 1, scene.activeCamera.minZ, scene.activeCamera.maxZ);
+            }
         }
 
         public get samples(): number {
@@ -83,7 +85,7 @@
             return this._renderTargetTexture;
         }
 
-        public get renderList(): AbstractMesh[] {
+        public get renderList(): Nullable<AbstractMesh[]> {
             return this._renderTargetTexture.renderList;
         }
 
@@ -111,7 +113,7 @@
 
             if (this._renderTargetTexture) {
                 this._renderTargetTexture.dispose();
-                this._renderTargetTexture = null;
+                (<any>this._renderTargetTexture) = null;
             }
         }
     }    

+ 9 - 6
src/Rendering/babylon.boundingBoxRenderer.ts

@@ -7,7 +7,7 @@
 
         private _scene: Scene;
         private _colorShader: ShaderMaterial;
-        private _vertexBuffers: { [key: string]: VertexBuffer } = {};
+        private _vertexBuffers: { [key: string]: Nullable<VertexBuffer> } = {};
         private _indexBuffer: WebGLBuffer;
 
         constructor(scene: Scene) {
@@ -28,7 +28,7 @@
 
             var engine = this._scene.getEngine();
             var boxdata = VertexData.CreateBox({ size: 1.0 });
-            this._vertexBuffers[VertexBuffer.PositionKind] = new VertexBuffer(engine, boxdata.positions, VertexBuffer.PositionKind, false);
+            this._vertexBuffers[VertexBuffer.PositionKind] = new VertexBuffer(engine, <FloatArray>boxdata.positions, VertexBuffer.PositionKind, false);
             this._createIndexBuffer();
         }
 
@@ -38,7 +38,10 @@
         }
 
         public _rebuild(): void {
-            this._vertexBuffers[VertexBuffer.PositionKind]._rebuild();
+            let vb = this._vertexBuffers[VertexBuffer.PositionKind];
+            if (vb) {
+                vb._rebuild();
+            }
             this._createIndexBuffer();
         }
 
@@ -72,7 +75,7 @@
                     .multiply(boundingBox.getWorldMatrix());
 
                 // VBOs
-                engine.bindBuffers(this._vertexBuffers, this._indexBuffer, this._colorShader.getEffect());
+                engine.bindBuffers(this._vertexBuffers, this._indexBuffer, <Effect>this._colorShader.getEffect());
 
                 if (this.showBackLines) {
                     // Back
@@ -103,7 +106,7 @@
 
             this._prepareRessources();
 
-            if (!this._colorShader.isReady()) {
+            if (!this._colorShader.isReady() || !mesh._boundingInfo) {
                 return;
             }
 
@@ -122,7 +125,7 @@
                 .multiply(Matrix.Translation(median.x, median.y, median.z))
                 .multiply(boundingBox.getWorldMatrix());
 
-            engine.bindBuffers(this._vertexBuffers, this._indexBuffer, this._colorShader.getEffect());
+            engine.bindBuffers(this._vertexBuffers, this._indexBuffer, <Effect>this._colorShader.getEffect());
 
             engine.setDepthFunctionToLess();
             this._scene.resetCachedMaterial();

+ 14 - 7
src/Rendering/babylon.depthRenderer.ts

@@ -28,9 +28,14 @@
                 var mesh = subMesh.getRenderingMesh();
                 var scene = this._scene;
                 var engine = scene.getEngine();
+                let material = subMesh.getMaterial();
+
+                if (!material) {
+                    return;
+                }
 
                 // Culling
-                engine.setState(subMesh.getMaterial().backFaceCulling);
+                engine.setState(material.backFaceCulling);
 
                 // Managing instances
                 var batch = mesh._getInstancesRenderList(subMesh._id);
@@ -41,10 +46,9 @@
 
                 var hardwareInstancedRendering = (engine.getCaps().instancedArrays) && (batch.visibleInstances[subMesh._id] !== null);
 
-                if (this.isReady(subMesh, hardwareInstancedRendering)) {
+                if (this.isReady(subMesh, hardwareInstancedRendering) && scene.activeCamera) {
                     engine.enableEffect(this._effect);
                     mesh._bind(subMesh, this._effect, Material.TriangleFillMode);
-                    var material = subMesh.getMaterial();
 
                     this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
 
@@ -53,12 +57,15 @@
                     // Alpha test
                     if (material && material.needAlphaTesting()) {
                         var alphaTexture = material.getAlphaTestTexture();
-                        this._effect.setTexture("diffuseSampler", alphaTexture);
-                        this._effect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
+
+                        if (alphaTexture) {
+                            this._effect.setTexture("diffuseSampler", alphaTexture);
+                            this._effect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
+                        }
                     }
 
                     // Bones
-                    if (mesh.useBones && mesh.computeBonesUsingShaders) {
+                    if (mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {
                         this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
                     }
 
@@ -123,7 +130,7 @@
                     attribs.push(VertexBuffer.MatricesWeightsExtraKind);
                 }
                 defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
-                defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
+                defines.push("#define BonesPerMesh " + (mesh.skeleton ? mesh.skeleton.bones.length + 1 : 0));
             } else {
                 defines.push("#define NUM_BONE_INFLUENCERS 0");
             }

+ 10 - 5
src/Rendering/babylon.edgesRenderer.ts

@@ -20,7 +20,7 @@
 
         private _lineShader: ShaderMaterial;
         private _ib: WebGLBuffer;
-        private _buffers: { [key: string]: VertexBuffer; } = {};
+        private _buffers: { [key: string]: Nullable<VertexBuffer> } = {};
         private _checkVerticesInsteadOfIndices = false;
 
         // Beware when you use this class with complex objects as the adjacencies computation can be really long
@@ -182,6 +182,10 @@
             var positions = this._source.getVerticesData(VertexBuffer.PositionKind);
             var indices = this._source.getIndices();
 
+            if (!indices || !positions) {
+                return;
+            }
+
             // First let's find adjacencies
             var adjacencies = new Array<FaceAdjacencies>();
             var faceNormals = new Array<Vector3>();
@@ -226,7 +230,7 @@
                     var otherP2 = indices[otherIndex * 3 + 2];
 
                     for (var edgeIndex = 0; edgeIndex < 3; edgeIndex++) {
-                        var otherEdgeIndex: number;
+                        var otherEdgeIndex: number = 0;
 
                         if (faceAdjacencies.edges[edgeIndex] !== undefined) {
                             continue;
@@ -295,16 +299,17 @@
         }
 
         public render(): void {
-            if (!this._lineShader.isReady()) {
+            var scene = this._source.getScene();
+
+            if (!this._lineShader.isReady() || !scene.activeCamera) {
                 return;
             }
 
-            var scene = this._source.getScene();
             var engine = scene.getEngine();
             this._lineShader._preBind();
 
             // VBOs
-            engine.bindBuffers(this._buffers, this._ib, this._lineShader.getEffect());
+            engine.bindBuffers(this._buffers, this._ib, <Effect>this._lineShader.getEffect());
 
             scene.resetCachedMaterial();
             this._lineShader.setColor4("color", this._source.edgesColor);

+ 16 - 8
src/Rendering/babylon.geometryBufferRenderer.ts

@@ -75,7 +75,7 @@ module BABYLON {
                     attribs.push(VertexBuffer.MatricesWeightsExtraKind);
                 }
                 defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
-                defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
+                defines.push("#define BonesPerMesh " + (mesh.skeleton ? mesh.skeleton.bones.length + 1 : 0));
             } else {
                 defines.push("#define NUM_BONE_INFLUENCERS 0");
             }
@@ -97,7 +97,7 @@ module BABYLON {
                     attribs,
                     ["world", "mBones", "viewProjection", "diffuseMatrix", "view"],
                     ["diffuseSampler"], join,
-                    null, null, null,
+                    undefined, undefined, undefined,
                     { buffersCount: this._enablePosition ? 3 : 2 });
             }
 
@@ -119,7 +119,7 @@ module BABYLON {
 
             this._multiRenderTarget = new MultiRenderTarget("gBuffer", { width: engine.getRenderWidth() * this._ratio, height: engine.getRenderHeight() * this._ratio }, count, this._scene, { generateMipMaps : false, generateDepthTexture: true });
             if (!this.isSupported) {
-                return null;
+                return;
             }
             this._multiRenderTarget.wrapU = Texture.CLAMP_ADDRESSMODE;
             this._multiRenderTarget.wrapV = Texture.CLAMP_ADDRESSMODE;
@@ -137,9 +137,14 @@ module BABYLON {
                 var mesh = subMesh.getRenderingMesh();
                 var scene = this._scene;
                 var engine = scene.getEngine();
+                let material = subMesh.getMaterial();
+
+                if (!material) {
+                    return;
+                }
 
                 // Culling
-                engine.setState(subMesh.getMaterial().backFaceCulling);
+                engine.setState(material.backFaceCulling);
 
                 // Managing instances
                 var batch = mesh._getInstancesRenderList(subMesh._id);
@@ -153,7 +158,7 @@ module BABYLON {
                 if (this.isReady(subMesh, hardwareInstancedRendering)) {
                     engine.enableEffect(this._effect);
                     mesh._bind(subMesh, this._effect, Material.TriangleFillMode);
-                    var material = subMesh.getMaterial();
+                    
 
                     this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
                     this._effect.setMatrix("view", scene.getViewMatrix());
@@ -161,12 +166,15 @@ module BABYLON {
                     // Alpha test
                     if (material && material.needAlphaTesting()) {
                         var alphaTexture = material.getAlphaTestTexture();
-                        this._effect.setTexture("diffuseSampler", alphaTexture);
-                        this._effect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
+
+                        if (alphaTexture) {
+                            this._effect.setTexture("diffuseSampler", alphaTexture);
+                            this._effect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
+                        }
                     }
 
                     // Bones
-                    if (mesh.useBones && mesh.computeBonesUsingShaders) {
+                    if (mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {
                         this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
                     }
 

+ 7 - 3
src/Rendering/babylon.outlineRenderer.ts

@@ -10,7 +10,7 @@
             this._scene = scene;
         }
 
-        public render(subMesh: SubMesh, batch: _InstancesBatch, useOverlay: boolean = false) {
+        public render(subMesh: SubMesh, batch: _InstancesBatch, useOverlay: boolean = false): void {
             var scene = this._scene;
             var engine = this._scene.getEngine();
 
@@ -23,6 +23,10 @@
             var mesh = subMesh.getRenderingMesh();
             var material = subMesh.getMaterial();
 
+            if (!material || !scene.activeCamera) {
+                return;
+            }
+
             engine.enableEffect(this._effect);
 
             // Logarithmic depth
@@ -36,7 +40,7 @@
             this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
 
             // Bones
-            if (mesh.useBones && mesh.computeBonesUsingShaders) {
+            if (mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {
                 this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
             }
 
@@ -95,7 +99,7 @@
                     attribs.push(VertexBuffer.MatricesWeightsExtraKind);
                 }
                 defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
-                defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
+                defines.push("#define BonesPerMesh " + (mesh.skeleton ? mesh.skeleton.bones.length + 1 : 0));
             } else {
                 defines.push("#define NUM_BONE_INFLUENCERS 0");
             }

+ 6 - 2
src/Rendering/babylon.renderingGroup.ts

@@ -187,7 +187,7 @@
             for (; subIndex < subMeshes.length; subIndex++) {
                 subMesh = subMeshes.data[subIndex];
                 subMesh._alphaIndex = subMesh.getMesh().alphaIndex;
-                subMesh._distanceToCamera = subMesh.getBoundingInfo().boundingSphere.centerWorld.subtract(cameraPosition).length();
+                subMesh._distanceToCamera = (<BoundingInfo>subMesh.getBoundingInfo()).boundingSphere.centerWorld.subtract(cameraPosition).length();
             }
 
             let sortedArray = subMeshes.data.slice(0, subMeshes.length);
@@ -202,7 +202,7 @@
                 if (transparent) {
                     let material = subMesh.getMaterial();
 
-                    if (material.needDepthPrePass) {
+                    if (material && material.needDepthPrePass) {
                         let engine = material.getScene().getEngine();
                         engine.setColorWrite(false);
                         engine.setAlphaTesting(true);
@@ -320,6 +320,10 @@
             var material = subMesh.getMaterial();
             var mesh = subMesh.getMesh();
 
+            if (!material) {
+                return;
+            }
+
             if (material.needAlphaBlending() || mesh.visibility < 1.0 || mesh.hasVertexAlpha) { // Transparent
                 this._transparentSubMeshes.push(subMesh);
             } else if (material.needAlphaTesting()) { // Alpha test