David Catuhe 8 years ago
parent
commit
d83e5d1960

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


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


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


+ 102 - 51
dist/preview release/babylon.max.js

@@ -5820,11 +5820,15 @@ var BABYLON;
     var Internals;
     (function (Internals) {
         var _AlphaState = (function () {
+            /**
+             * Initializes the state.
+             */
             function _AlphaState() {
                 this._isAlphaBlendDirty = false;
                 this._isBlendFunctionParametersDirty = false;
                 this._alphaBlend = false;
                 this._blendFunctionParameters = new Array(4);
+                this.reset();
             }
             Object.defineProperty(_AlphaState.prototype, "isDirty", {
                 get: function () {
@@ -5900,6 +5904,9 @@ var BABYLON;
     var Internals;
     (function (Internals) {
         var _DepthCullingState = (function () {
+            /**
+             * Initializes the state.
+             */
             function _DepthCullingState() {
                 this._isDepthTestDirty = false;
                 this._isDepthMaskDirty = false;
@@ -5907,6 +5914,7 @@ var BABYLON;
                 this._isCullFaceDirty = false;
                 this._isCullDirty = false;
                 this._isZOffsetDirty = false;
+                this.reset();
             }
             Object.defineProperty(_DepthCullingState.prototype, "isDirty", {
                 get: function () {
@@ -22932,7 +22940,18 @@ var BABYLON;
             this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NONE;
             this._scene = scene;
             this._scene.textures.push(this);
+            this._uid = null;
         }
+        Object.defineProperty(BaseTexture.prototype, "uid", {
+            get: function () {
+                if (!this._uid) {
+                    this._uid = BABYLON.Tools.RandomId();
+                }
+                return this._uid;
+            },
+            enumerable: true,
+            configurable: true
+        });
         BaseTexture.prototype.toString = function () {
             return this.name;
         };
@@ -24693,6 +24712,12 @@ var BABYLON;
                 callback(vertexCode);
                 return;
             }
+            // Base64 encoded ?
+            if (vertex.substr(0, 7) === "base64:") {
+                var vertexBinary = window.atob(vertex.substr(7));
+                callback(vertexBinary);
+                return;
+            }
             // Is in local store ?
             if (Effect.ShadersStore[vertex + "VertexShader"]) {
                 callback(Effect.ShadersStore[vertex + "VertexShader"]);
@@ -24715,6 +24740,12 @@ var BABYLON;
                 callback(fragmentCode);
                 return;
             }
+            // Base64 encoded ?
+            if (fragment(0, 7) === "base64:") {
+                var fragmentBinary = window.atob(fragment.substr(7));
+                callback(fragmentBinary);
+                return;
+            }
             // Is in local store ?
             if (Effect.ShadersStore[fragment + "PixelShader"]) {
                 callback(Effect.ShadersStore[fragment + "PixelShader"]);
@@ -37720,14 +37751,21 @@ var BABYLON;
          * @param mesh The mesh to exclude from the highlight layer
          */
         HighlightLayer.prototype.addExcludedMesh = function (mesh) {
-            var meshExcluded = this._excludedMeshes[mesh.id];
+            var sourceMesh;
+            if (mesh instanceof BABYLON.InstancedMesh) {
+                sourceMesh = mesh.sourceMesh;
+            }
+            else {
+                sourceMesh = mesh;
+            }
+            var meshExcluded = this._excludedMeshes[sourceMesh.id];
             if (!meshExcluded) {
-                this._excludedMeshes[mesh.id] = {
-                    mesh: mesh,
-                    beforeRender: mesh.onBeforeRenderObservable.add(function (mesh) {
+                this._excludedMeshes[sourceMesh.id] = {
+                    mesh: sourceMesh,
+                    beforeRender: sourceMesh.onBeforeRenderObservable.add(function (mesh) {
                         mesh.getEngine().setStencilBuffer(false);
                     }),
-                    afterRender: mesh.onAfterRenderObservable.add(function (mesh) {
+                    afterRender: sourceMesh.onAfterRenderObservable.add(function (mesh) {
                         mesh.getEngine().setStencilBuffer(true);
                     }),
                 };
@@ -37738,12 +37776,19 @@ var BABYLON;
           * @param mesh The mesh to highlight
           */
         HighlightLayer.prototype.removeExcludedMesh = function (mesh) {
-            var meshExcluded = this._excludedMeshes[mesh.id];
+            var sourceMesh;
+            if (mesh instanceof BABYLON.InstancedMesh) {
+                sourceMesh = mesh.sourceMesh;
+            }
+            else {
+                sourceMesh = mesh;
+            }
+            var meshExcluded = this._excludedMeshes[sourceMesh.id];
             if (meshExcluded) {
-                mesh.onBeforeRenderObservable.remove(meshExcluded.beforeRender);
-                mesh.onAfterRenderObservable.remove(meshExcluded.afterRender);
+                sourceMesh.onBeforeRenderObservable.remove(meshExcluded.beforeRender);
+                sourceMesh.onAfterRenderObservable.remove(meshExcluded.afterRender);
             }
-            this._excludedMeshes[mesh.id] = undefined;
+            this._excludedMeshes[sourceMesh.id] = undefined;
         };
         /**
          * Add a mesh in the highlight layer in order to make it glow with the chosen color.
@@ -37754,16 +37799,23 @@ var BABYLON;
         HighlightLayer.prototype.addMesh = function (mesh, color, glowEmissiveOnly) {
             var _this = this;
             if (glowEmissiveOnly === void 0) { glowEmissiveOnly = false; }
-            var meshHighlight = this._meshes[mesh.id];
+            var sourceMesh;
+            if (mesh instanceof BABYLON.InstancedMesh) {
+                sourceMesh = mesh.sourceMesh;
+            }
+            else {
+                sourceMesh = mesh;
+            }
+            var meshHighlight = this._meshes[sourceMesh.id];
             if (meshHighlight) {
                 meshHighlight.color = color;
             }
             else {
-                this._meshes[mesh.id] = {
-                    mesh: mesh,
+                this._meshes[sourceMesh.id] = {
+                    mesh: sourceMesh,
                     color: color,
                     // Lambda required for capture due to Observable this context
-                    observerHighlight: mesh.onBeforeRenderObservable.add(function (mesh) {
+                    observerHighlight: sourceMesh.onBeforeRenderObservable.add(function (mesh) {
                         if (_this._excludedMeshes[mesh.id]) {
                             _this.defaultStencilReference(mesh);
                         }
@@ -37771,7 +37823,7 @@ var BABYLON;
                             mesh.getScene().getEngine().setStencilFunctionReference(_this._instanceGlowingMeshStencilReference);
                         }
                     }),
-                    observerDefault: mesh.onAfterRenderObservable.add(this.defaultStencilReference),
+                    observerDefault: sourceMesh.onAfterRenderObservable.add(this.defaultStencilReference),
                     glowEmissiveOnly: glowEmissiveOnly
                 };
             }
@@ -37782,12 +37834,19 @@ var BABYLON;
          * @param mesh The mesh to highlight
          */
         HighlightLayer.prototype.removeMesh = function (mesh) {
-            var meshHighlight = this._meshes[mesh.id];
+            var sourceMesh;
+            if (mesh instanceof BABYLON.InstancedMesh) {
+                sourceMesh = mesh.sourceMesh;
+            }
+            else {
+                sourceMesh = mesh;
+            }
+            var meshHighlight = this._meshes[sourceMesh.id];
             if (meshHighlight) {
-                mesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
-                mesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
+                sourceMesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
+                sourceMesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
             }
-            this._meshes[mesh.id] = undefined;
+            this._meshes[sourceMesh.id] = undefined;
             this._shouldRender = false;
             for (var meshHighlightToCheck in this._meshes) {
                 if (meshHighlightToCheck) {
@@ -47566,7 +47625,7 @@ var BABYLON;
          * `idxInShape` (integer) is the index of the particle in the current model (ex: the 10th box of addShape(box, 30))
          * `modelBoundingInfo` is the reference to the model BoundingInfo used for intersection computations.
          */
-        function SolidParticle(particleIndex, positionIndex, model, shapeId, idxInShape, modelBoundingInfo) {
+        function SolidParticle(particleIndex, positionIndex, model, shapeId, idxInShape, sps, modelBoundingInfo) {
             this.idx = 0; // particle global index
             this.color = new BABYLON.Color4(1.0, 1.0, 1.0, 1.0); // color
             this.position = BABYLON.Vector3.Zero(); // position
@@ -47584,6 +47643,7 @@ var BABYLON;
             this._model = model;
             this.shapeId = shapeId;
             this.idxInShape = idxInShape;
+            this._sps = sps;
             if (modelBoundingInfo) {
                 this._modelBoundingInfo = modelBoundingInfo;
                 this._boundingInfo = new BABYLON.BoundingInfo(modelBoundingInfo.minimum, modelBoundingInfo.maximum);
@@ -47624,6 +47684,9 @@ var BABYLON;
             if (!this._boundingInfo || !target._boundingInfo) {
                 return false;
             }
+            if (this._sps._bSphereOnly) {
+                return BABYLON.BoundingSphere.Intersects(this._boundingInfo.boundingSphere, target._boundingInfo.boundingSphere);
+            }
             return this._boundingInfo.intersects(target._boundingInfo, false);
         };
         return SolidParticle;
@@ -47699,7 +47762,7 @@ var BABYLON;
             this._isVisibilityBoxLocked = false;
             this._alwaysVisible = false;
             this._shapeCounter = 0;
-            this._copy = new BABYLON.SolidParticle(null, null, null, null, null);
+            this._copy = new BABYLON.SolidParticle(null, null, null, null, null, null);
             this._color = new BABYLON.Color4(0, 0, 0, 0);
             this._computeParticleColor = true;
             this._computeParticleTexture = true;
@@ -47739,11 +47802,13 @@ var BABYLON;
             this._minBbox = BABYLON.Tmp.Vector3[4];
             this._maxBbox = BABYLON.Tmp.Vector3[5];
             this._particlesIntersect = false;
+            this._bSphereOnly = false;
             this.name = name;
             this._scene = scene;
             this._camera = scene.activeCamera;
             this._pickable = options ? options.isPickable : false;
             this._particlesIntersect = options ? options.particleIntersection : false;
+            this._bSphereOnly = options ? options.boundingSphereOnly : false;
             if (options && options.updatable) {
                 this._updatable = options.updatable;
             }
@@ -47998,7 +48063,7 @@ var BABYLON;
         };
         // adds a new particle object in the particles array
         SolidParticleSystem.prototype._addParticle = function (idx, idxpos, model, shapeId, idxInShape, bInfo) {
-            this.particles.push(new BABYLON.SolidParticle(idx, idxpos, model, shapeId, idxInShape, bInfo));
+            this.particles.push(new BABYLON.SolidParticle(idx, idxpos, model, shapeId, idxInShape, this, bInfo));
         };
         /**
         * Adds some particles to the SPS from the model shape. Returns the shape id.
@@ -48264,9 +48329,9 @@ var BABYLON;
                     var bInfo = this._particle._boundingInfo;
                     var bBox = bInfo.boundingBox;
                     var bSphere = bInfo.boundingSphere;
-                    // place, scale and rotate the particle bbox within the SPS local system
-                    for (var b = 0; b < bBox.vectors.length; b++) {
-                        if (this._particle.isVisible) {
+                    if (!this._bSphereOnly) {
+                        // place, scale and rotate the particle bbox within the SPS local system, then update it
+                        for (var b = 0; b < bBox.vectors.length; b++) {
                             this._vertex.x = this._particle._modelBoundingInfo.boundingBox.vectors[b].x * this._particle.scaling.x;
                             this._vertex.y = this._particle._modelBoundingInfo.boundingBox.vectors[b].y * this._particle.scaling.y;
                             this._vertex.z = this._particle._modelBoundingInfo.boundingBox.vectors[b].z * this._particle.scaling.z;
@@ -48278,33 +48343,19 @@ var BABYLON;
                             bBox.vectors[b].y = this._particle.position.y + this._cam_axisX.y * this._rotated.x + this._cam_axisY.y * this._rotated.y + this._cam_axisZ.y * this._rotated.z;
                             bBox.vectors[b].z = this._particle.position.z + this._cam_axisX.z * this._rotated.x + this._cam_axisY.z * this._rotated.y + this._cam_axisZ.z * this._rotated.z;
                         }
-                        else {
-                            bBox.vectors[b].x = this._camera.position.x;
-                            bBox.vectors[b].y = this._camera.position.y;
-                            bBox.vectors[b].z = this._camera.position.z;
-                        }
-                    }
-                    // place and scale the particle bouding sphere in the SPS local system
-                    if (this._particle.isVisible) {
-                        this._minBbox.x = this._particle._modelBoundingInfo.minimum.x * this._particle.scaling.x;
-                        this._minBbox.y = this._particle._modelBoundingInfo.minimum.y * this._particle.scaling.y;
-                        this._minBbox.z = this._particle._modelBoundingInfo.minimum.z * this._particle.scaling.z;
-                        this._maxBbox.x = this._particle._modelBoundingInfo.maximum.x * this._particle.scaling.x;
-                        this._maxBbox.y = this._particle._modelBoundingInfo.maximum.y * this._particle.scaling.y;
-                        this._maxBbox.z = this._particle._modelBoundingInfo.maximum.z * this._particle.scaling.z;
-                        bSphere.center.x = this._particle.position.x + (this._minBbox.x + this._maxBbox.x) * 0.5;
-                        bSphere.center.y = this._particle.position.y + (this._minBbox.y + this._maxBbox.y) * 0.5;
-                        bSphere.center.z = this._particle.position.z + (this._minBbox.z + this._maxBbox.z) * 0.5;
-                        bSphere.radius = BABYLON.Vector3.Distance(this._minimum, this._maximum) * 0.5;
-                    }
-                    else {
-                        bSphere.center.x = this._camera.position.x;
-                        bSphere.center.y = this._camera.position.x;
-                        bSphere.center.z = this._camera.position.x;
-                        bSphere.radius = 0.0;
-                    }
-                    // then update the bbox and the bsphere into the world system
-                    bBox._update(this.mesh._worldMatrix);
+                        bBox._update(this.mesh._worldMatrix);
+                    }
+                    // place and scale the particle bouding sphere in the SPS local system, then update it
+                    this._minBbox.x = this._particle._modelBoundingInfo.minimum.x * this._particle.scaling.x;
+                    this._minBbox.y = this._particle._modelBoundingInfo.minimum.y * this._particle.scaling.y;
+                    this._minBbox.z = this._particle._modelBoundingInfo.minimum.z * this._particle.scaling.z;
+                    this._maxBbox.x = this._particle._modelBoundingInfo.maximum.x * this._particle.scaling.x;
+                    this._maxBbox.y = this._particle._modelBoundingInfo.maximum.y * this._particle.scaling.y;
+                    this._maxBbox.z = this._particle._modelBoundingInfo.maximum.z * this._particle.scaling.z;
+                    bSphere.center.x = this._particle.position.x + (this._minBbox.x + this._maxBbox.x) * 0.5;
+                    bSphere.center.y = this._particle.position.y + (this._minBbox.y + this._maxBbox.y) * 0.5;
+                    bSphere.center.z = this._particle.position.z + (this._minBbox.z + this._maxBbox.z) * 0.5;
+                    bSphere.radius = 0.5 * Math.sqrt((this._maxBbox.x - this._minBbox.x) * (this._maxBbox.x - this._minBbox.x) + (this._maxBbox.y - this._minBbox.y) * (this._maxBbox.y - this._minBbox.y) + (this._maxBbox.z - this._minBbox.z) * (this._maxBbox.z - this._minBbox.z));
                     bSphere._update(this.mesh._worldMatrix);
                 }
                 // increment indexes for the next particle

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


+ 46 - 18
src/Layer/babylon.highlightlayer.js

@@ -441,14 +441,21 @@ var BABYLON;
          * @param mesh The mesh to exclude from the highlight layer
          */
         HighlightLayer.prototype.addExcludedMesh = function (mesh) {
-            var meshExcluded = this._excludedMeshes[mesh.id];
+            var sourceMesh;
+            if (mesh instanceof BABYLON.InstancedMesh) {
+                sourceMesh = mesh.sourceMesh;
+            }
+            else {
+                sourceMesh = mesh;
+            }
+            var meshExcluded = this._excludedMeshes[sourceMesh.id];
             if (!meshExcluded) {
-                this._excludedMeshes[mesh.id] = {
-                    mesh: mesh,
-                    beforeRender: mesh.onBeforeRenderObservable.add(function (mesh) {
+                this._excludedMeshes[sourceMesh.id] = {
+                    mesh: sourceMesh,
+                    beforeRender: sourceMesh.onBeforeRenderObservable.add(function (mesh) {
                         mesh.getEngine().setStencilBuffer(false);
                     }),
-                    afterRender: mesh.onAfterRenderObservable.add(function (mesh) {
+                    afterRender: sourceMesh.onAfterRenderObservable.add(function (mesh) {
                         mesh.getEngine().setStencilBuffer(true);
                     }),
                 };
@@ -459,12 +466,19 @@ var BABYLON;
           * @param mesh The mesh to highlight
           */
         HighlightLayer.prototype.removeExcludedMesh = function (mesh) {
-            var meshExcluded = this._excludedMeshes[mesh.id];
+            var sourceMesh;
+            if (mesh instanceof BABYLON.InstancedMesh) {
+                sourceMesh = mesh.sourceMesh;
+            }
+            else {
+                sourceMesh = mesh;
+            }
+            var meshExcluded = this._excludedMeshes[sourceMesh.id];
             if (meshExcluded) {
-                mesh.onBeforeRenderObservable.remove(meshExcluded.beforeRender);
-                mesh.onAfterRenderObservable.remove(meshExcluded.afterRender);
+                sourceMesh.onBeforeRenderObservable.remove(meshExcluded.beforeRender);
+                sourceMesh.onAfterRenderObservable.remove(meshExcluded.afterRender);
             }
-            this._excludedMeshes[mesh.id] = undefined;
+            this._excludedMeshes[sourceMesh.id] = undefined;
         };
         /**
          * Add a mesh in the highlight layer in order to make it glow with the chosen color.
@@ -475,16 +489,23 @@ var BABYLON;
         HighlightLayer.prototype.addMesh = function (mesh, color, glowEmissiveOnly) {
             var _this = this;
             if (glowEmissiveOnly === void 0) { glowEmissiveOnly = false; }
-            var meshHighlight = this._meshes[mesh.id];
+            var sourceMesh;
+            if (mesh instanceof BABYLON.InstancedMesh) {
+                sourceMesh = mesh.sourceMesh;
+            }
+            else {
+                sourceMesh = mesh;
+            }
+            var meshHighlight = this._meshes[sourceMesh.id];
             if (meshHighlight) {
                 meshHighlight.color = color;
             }
             else {
-                this._meshes[mesh.id] = {
-                    mesh: mesh,
+                this._meshes[sourceMesh.id] = {
+                    mesh: sourceMesh,
                     color: color,
                     // Lambda required for capture due to Observable this context
-                    observerHighlight: mesh.onBeforeRenderObservable.add(function (mesh) {
+                    observerHighlight: sourceMesh.onBeforeRenderObservable.add(function (mesh) {
                         if (_this._excludedMeshes[mesh.id]) {
                             _this.defaultStencilReference(mesh);
                         }
@@ -492,7 +513,7 @@ var BABYLON;
                             mesh.getScene().getEngine().setStencilFunctionReference(_this._instanceGlowingMeshStencilReference);
                         }
                     }),
-                    observerDefault: mesh.onAfterRenderObservable.add(this.defaultStencilReference),
+                    observerDefault: sourceMesh.onAfterRenderObservable.add(this.defaultStencilReference),
                     glowEmissiveOnly: glowEmissiveOnly
                 };
             }
@@ -503,12 +524,19 @@ var BABYLON;
          * @param mesh The mesh to highlight
          */
         HighlightLayer.prototype.removeMesh = function (mesh) {
-            var meshHighlight = this._meshes[mesh.id];
+            var sourceMesh;
+            if (mesh instanceof BABYLON.InstancedMesh) {
+                sourceMesh = mesh.sourceMesh;
+            }
+            else {
+                sourceMesh = mesh;
+            }
+            var meshHighlight = this._meshes[sourceMesh.id];
             if (meshHighlight) {
-                mesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
-                mesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
+                sourceMesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
+                sourceMesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
             }
-            this._meshes[mesh.id] = undefined;
+            this._meshes[sourceMesh.id] = undefined;
             this._shouldRender = false;
             for (var meshHighlightToCheck in this._meshes) {
                 if (meshHighlightToCheck) {

+ 11 - 0
src/Materials/Textures/babylon.baseTexture.js

@@ -27,7 +27,18 @@ var BABYLON;
             this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NONE;
             this._scene = scene;
             this._scene.textures.push(this);
+            this._uid = null;
         }
+        Object.defineProperty(BaseTexture.prototype, "uid", {
+            get: function () {
+                if (!this._uid) {
+                    this._uid = BABYLON.Tools.RandomId();
+                }
+                return this._uid;
+            },
+            enumerable: true,
+            configurable: true
+        });
         BaseTexture.prototype.toString = function () {
             return this.name;
         };

+ 6 - 6
src/Materials/babylon.effect.js

@@ -135,9 +135,9 @@ var BABYLON;
             }
             // Base64 encoded ?
             if (vertex.substr(0, 7) === "base64:") {
-            	var vertexBinary = window.atob(vertex.substr(7));
-            	callback(vertexBinary);
-            	return;
+                var vertexBinary = window.atob(vertex.substr(7));
+                callback(vertexBinary);
+                return;
             }
             // Is in local store ?
             if (Effect.ShadersStore[vertex + "VertexShader"]) {
@@ -163,9 +163,9 @@ var BABYLON;
             }
             // Base64 encoded ?
             if (fragment(0, 7) === "base64:") {
-            	var fragmentBinary = window.atob(fragment.substr(7));
-            	callback(fragmentBinary);
-            	return;
+                var fragmentBinary = window.atob(fragment.substr(7));
+                callback(fragmentBinary);
+                return;
             }
             // Is in local store ?
             if (Effect.ShadersStore[fragment + "PixelShader"]) {

+ 5 - 1
src/Particles/babylon.solidParticle.js

@@ -11,7 +11,7 @@ var BABYLON;
          * `idxInShape` (integer) is the index of the particle in the current model (ex: the 10th box of addShape(box, 30))
          * `modelBoundingInfo` is the reference to the model BoundingInfo used for intersection computations.
          */
-        function SolidParticle(particleIndex, positionIndex, model, shapeId, idxInShape, modelBoundingInfo) {
+        function SolidParticle(particleIndex, positionIndex, model, shapeId, idxInShape, sps, modelBoundingInfo) {
             this.idx = 0; // particle global index
             this.color = new BABYLON.Color4(1.0, 1.0, 1.0, 1.0); // color
             this.position = BABYLON.Vector3.Zero(); // position
@@ -29,6 +29,7 @@ var BABYLON;
             this._model = model;
             this.shapeId = shapeId;
             this.idxInShape = idxInShape;
+            this._sps = sps;
             if (modelBoundingInfo) {
                 this._modelBoundingInfo = modelBoundingInfo;
                 this._boundingInfo = new BABYLON.BoundingInfo(modelBoundingInfo.minimum, modelBoundingInfo.maximum);
@@ -69,6 +70,9 @@ var BABYLON;
             if (!this._boundingInfo || !target._boundingInfo) {
                 return false;
             }
+            if (this._sps._bSphereOnly) {
+                return BABYLON.BoundingSphere.Intersects(this._boundingInfo.boundingSphere, target._boundingInfo.boundingSphere);
+            }
             return this._boundingInfo.intersects(target._boundingInfo, false);
         };
         return SolidParticle;

+ 19 - 31
src/Particles/babylon.solidParticleSystem.js

@@ -51,7 +51,7 @@ var BABYLON;
             this._isVisibilityBoxLocked = false;
             this._alwaysVisible = false;
             this._shapeCounter = 0;
-            this._copy = new BABYLON.SolidParticle(null, null, null, null, null);
+            this._copy = new BABYLON.SolidParticle(null, null, null, null, null, null);
             this._color = new BABYLON.Color4(0, 0, 0, 0);
             this._computeParticleColor = true;
             this._computeParticleTexture = true;
@@ -91,11 +91,13 @@ var BABYLON;
             this._minBbox = BABYLON.Tmp.Vector3[4];
             this._maxBbox = BABYLON.Tmp.Vector3[5];
             this._particlesIntersect = false;
+            this._bSphereOnly = false;
             this.name = name;
             this._scene = scene;
             this._camera = scene.activeCamera;
             this._pickable = options ? options.isPickable : false;
             this._particlesIntersect = options ? options.particleIntersection : false;
+            this._bSphereOnly = options ? options.boundingSphereOnly : false;
             if (options && options.updatable) {
                 this._updatable = options.updatable;
             }
@@ -350,7 +352,7 @@ var BABYLON;
         };
         // adds a new particle object in the particles array
         SolidParticleSystem.prototype._addParticle = function (idx, idxpos, model, shapeId, idxInShape, bInfo) {
-            this.particles.push(new BABYLON.SolidParticle(idx, idxpos, model, shapeId, idxInShape, bInfo));
+            this.particles.push(new BABYLON.SolidParticle(idx, idxpos, model, shapeId, idxInShape, this, bInfo));
         };
         /**
         * Adds some particles to the SPS from the model shape. Returns the shape id.
@@ -616,9 +618,9 @@ var BABYLON;
                     var bInfo = this._particle._boundingInfo;
                     var bBox = bInfo.boundingBox;
                     var bSphere = bInfo.boundingSphere;
-                    // place, scale and rotate the particle bbox within the SPS local system
-                    for (var b = 0; b < bBox.vectors.length; b++) {
-                        if (this._particle.isVisible) {
+                    if (!this._bSphereOnly) {
+                        // place, scale and rotate the particle bbox within the SPS local system, then update it
+                        for (var b = 0; b < bBox.vectors.length; b++) {
                             this._vertex.x = this._particle._modelBoundingInfo.boundingBox.vectors[b].x * this._particle.scaling.x;
                             this._vertex.y = this._particle._modelBoundingInfo.boundingBox.vectors[b].y * this._particle.scaling.y;
                             this._vertex.z = this._particle._modelBoundingInfo.boundingBox.vectors[b].z * this._particle.scaling.z;
@@ -630,33 +632,19 @@ var BABYLON;
                             bBox.vectors[b].y = this._particle.position.y + this._cam_axisX.y * this._rotated.x + this._cam_axisY.y * this._rotated.y + this._cam_axisZ.y * this._rotated.z;
                             bBox.vectors[b].z = this._particle.position.z + this._cam_axisX.z * this._rotated.x + this._cam_axisY.z * this._rotated.y + this._cam_axisZ.z * this._rotated.z;
                         }
-                        else {
-                            bBox.vectors[b].x = this._camera.position.x;
-                            bBox.vectors[b].y = this._camera.position.y;
-                            bBox.vectors[b].z = this._camera.position.z;
-                        }
-                    }
-                    // place and scale the particle bouding sphere in the SPS local system
-                    if (this._particle.isVisible) {
-                        this._minBbox.x = this._particle._modelBoundingInfo.minimum.x * this._particle.scaling.x;
-                        this._minBbox.y = this._particle._modelBoundingInfo.minimum.y * this._particle.scaling.y;
-                        this._minBbox.z = this._particle._modelBoundingInfo.minimum.z * this._particle.scaling.z;
-                        this._maxBbox.x = this._particle._modelBoundingInfo.maximum.x * this._particle.scaling.x;
-                        this._maxBbox.y = this._particle._modelBoundingInfo.maximum.y * this._particle.scaling.y;
-                        this._maxBbox.z = this._particle._modelBoundingInfo.maximum.z * this._particle.scaling.z;
-                        bSphere.center.x = this._particle.position.x + (this._minBbox.x + this._maxBbox.x) * 0.5;
-                        bSphere.center.y = this._particle.position.y + (this._minBbox.y + this._maxBbox.y) * 0.5;
-                        bSphere.center.z = this._particle.position.z + (this._minBbox.z + this._maxBbox.z) * 0.5;
-                        bSphere.radius = BABYLON.Vector3.Distance(this._minimum, this._maximum) * 0.5;
-                    }
-                    else {
-                        bSphere.center.x = this._camera.position.x;
-                        bSphere.center.y = this._camera.position.x;
-                        bSphere.center.z = this._camera.position.x;
-                        bSphere.radius = 0.0;
+                        bBox._update(this.mesh._worldMatrix);
                     }
-                    // then update the bbox and the bsphere into the world system
-                    bBox._update(this.mesh._worldMatrix);
+                    // place and scale the particle bouding sphere in the SPS local system, then update it
+                    this._minBbox.x = this._particle._modelBoundingInfo.minimum.x * this._particle.scaling.x;
+                    this._minBbox.y = this._particle._modelBoundingInfo.minimum.y * this._particle.scaling.y;
+                    this._minBbox.z = this._particle._modelBoundingInfo.minimum.z * this._particle.scaling.z;
+                    this._maxBbox.x = this._particle._modelBoundingInfo.maximum.x * this._particle.scaling.x;
+                    this._maxBbox.y = this._particle._modelBoundingInfo.maximum.y * this._particle.scaling.y;
+                    this._maxBbox.z = this._particle._modelBoundingInfo.maximum.z * this._particle.scaling.z;
+                    bSphere.center.x = this._particle.position.x + (this._minBbox.x + this._maxBbox.x) * 0.5;
+                    bSphere.center.y = this._particle.position.y + (this._minBbox.y + this._maxBbox.y) * 0.5;
+                    bSphere.center.z = this._particle.position.z + (this._minBbox.z + this._maxBbox.z) * 0.5;
+                    bSphere.radius = 0.5 * Math.sqrt((this._maxBbox.x - this._minBbox.x) * (this._maxBbox.x - this._minBbox.x) + (this._maxBbox.y - this._minBbox.y) * (this._maxBbox.y - this._minBbox.y) + (this._maxBbox.z - this._minBbox.z) * (this._maxBbox.z - this._minBbox.z));
                     bSphere._update(this.mesh._worldMatrix);
                 }
                 // increment indexes for the next particle

+ 4 - 0
src/States/babylon.alphaCullingState.js

@@ -3,11 +3,15 @@ var BABYLON;
     var Internals;
     (function (Internals) {
         var _AlphaState = (function () {
+            /**
+             * Initializes the state.
+             */
             function _AlphaState() {
                 this._isAlphaBlendDirty = false;
                 this._isBlendFunctionParametersDirty = false;
                 this._alphaBlend = false;
                 this._blendFunctionParameters = new Array(4);
+                this.reset();
             }
             Object.defineProperty(_AlphaState.prototype, "isDirty", {
                 get: function () {

+ 4 - 0
src/States/babylon.depthCullingState.js

@@ -3,6 +3,9 @@ var BABYLON;
     var Internals;
     (function (Internals) {
         var _DepthCullingState = (function () {
+            /**
+             * Initializes the state.
+             */
             function _DepthCullingState() {
                 this._isDepthTestDirty = false;
                 this._isDepthMaskDirty = false;
@@ -10,6 +13,7 @@ var BABYLON;
                 this._isCullFaceDirty = false;
                 this._isCullDirty = false;
                 this._isZOffsetDirty = false;
+                this.reset();
             }
             Object.defineProperty(_DepthCullingState.prototype, "isDirty", {
                 get: function () {