Explorar o código

Fixed bug with indexbuffer cache

David Catuhe %!s(int64=8) %!d(string=hai) anos
pai
achega
b6ce1efe94

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 20 - 20
dist/preview release/babylon.core.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1700 - 1699
dist/preview release/babylon.d.ts


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 30 - 30
dist/preview release/babylon.js


+ 44 - 36
dist/preview release/babylon.max.js

@@ -7403,40 +7403,40 @@ var BABYLON;
             }
         };
         Engine.prototype.bindBuffers = function (vertexBuffers, indexBuffer, effect) {
-            //   if (this._cachedVertexBuffers !== vertexBuffers || this._cachedEffectForVertexBuffers !== effect) {
-            this._cachedVertexBuffers = vertexBuffers;
-            this._cachedEffectForVertexBuffers = effect;
-            var attributes = effect.getAttributesNames();
-            for (var index = 0; index < attributes.length; index++) {
-                var order = effect.getAttributeLocation(index);
-                if (order >= 0) {
-                    var vertexBuffer = vertexBuffers[attributes[index]];
-                    if (!vertexBuffer) {
-                        if (this._vertexAttribArraysEnabled[order]) {
-                            this._gl.disableVertexAttribArray(order);
-                            this._vertexAttribArraysEnabled[order] = false;
+            if (this._cachedVertexBuffers !== vertexBuffers || this._cachedEffectForVertexBuffers !== effect) {
+                this._cachedVertexBuffers = vertexBuffers;
+                this._cachedEffectForVertexBuffers = effect;
+                var attributes = effect.getAttributesNames();
+                for (var index = 0; index < attributes.length; index++) {
+                    var order = effect.getAttributeLocation(index);
+                    if (order >= 0) {
+                        var vertexBuffer = vertexBuffers[attributes[index]];
+                        if (!vertexBuffer) {
+                            if (this._vertexAttribArraysEnabled[order]) {
+                                this._gl.disableVertexAttribArray(order);
+                                this._vertexAttribArraysEnabled[order] = false;
+                            }
+                            continue;
+                        }
+                        if (!this._vertexAttribArraysEnabled[order]) {
+                            this._gl.enableVertexAttribArray(order);
+                            this._vertexAttribArraysEnabled[order] = true;
+                        }
+                        var buffer = vertexBuffer.getBuffer();
+                        this.vertexAttribPointer(buffer, order, vertexBuffer.getSize(), this._gl.FLOAT, false, vertexBuffer.getStrideSize() * 4, vertexBuffer.getOffset() * 4);
+                        if (vertexBuffer.getIsInstanced()) {
+                            this._caps.instancedArrays.vertexAttribDivisorANGLE(order, 1);
+                            this._currentInstanceLocations.push(order);
+                            this._currentInstanceBuffers.push(buffer);
                         }
-                        continue;
-                    }
-                    if (!this._vertexAttribArraysEnabled[order]) {
-                        this._gl.enableVertexAttribArray(order);
-                        this._vertexAttribArraysEnabled[order] = true;
-                    }
-                    var buffer = vertexBuffer.getBuffer();
-                    this.vertexAttribPointer(buffer, order, vertexBuffer.getSize(), this._gl.FLOAT, false, vertexBuffer.getStrideSize() * 4, vertexBuffer.getOffset() * 4);
-                    if (vertexBuffer.getIsInstanced()) {
-                        this._caps.instancedArrays.vertexAttribDivisorANGLE(order, 1);
-                        this._currentInstanceLocations.push(order);
-                        this._currentInstanceBuffers.push(buffer);
                     }
                 }
             }
-            //   }
-            // if (indexBuffer != null && this._cachedIndexBuffer !== indexBuffer) {
-            this._cachedIndexBuffer = indexBuffer;
-            this.bindIndexBuffer(indexBuffer);
-            this._uintIndicesCurrentlySet = indexBuffer.is32Bits;
-            //}
+            if (indexBuffer != null && this._cachedIndexBuffer !== indexBuffer) {
+                this._cachedIndexBuffer = indexBuffer;
+                this.bindIndexBuffer(indexBuffer);
+                this._uintIndicesCurrentlySet = indexBuffer.is32Bits;
+            }
         };
         Engine.prototype.unbindInstanceAttributes = function () {
             var boundBuffer;
@@ -47426,6 +47426,9 @@ var BABYLON;
             configurable: true
         });
         SolidParticle.prototype.intersectsMesh = function (target) {
+            if (!(this.isVisible && target.isVisible)) {
+                return false; // only visible particle and target can intersect
+            }
             if (!this._boundingInfo || !target._boundingInfo) {
                 return false;
             }
@@ -47586,6 +47589,7 @@ var BABYLON;
             vertexData.applyToMesh(mesh, this._updatable);
             this.mesh = mesh;
             this.mesh.isPickable = this._pickable;
+            this._wm = this.mesh.getWorldMatrix();
             // free memory
             this._positions = null;
             this._normals = null;
@@ -47670,10 +47674,14 @@ var BABYLON;
                 for (v = 0; v < shape.length; v++) {
                     shape[v].subtractInPlace(barycenter);
                 }
+                var bInfo;
+                if (this._particlesIntersect) {
+                    bInfo = new BABYLON.BoundingInfo(barycenter, barycenter);
+                }
                 var modelShape = new BABYLON.ModelShape(this._shapeCounter, shape, shapeUV, null, null);
                 // add the particle in the SPS
                 this._meshBuilder(this._index, shape, this._positions, facetInd, this._indices, facetUV, this._uvs, facetCol, this._colors, meshNor, this._normals, idx, 0, null);
-                this._addParticle(idx, this._positions.length, modelShape, this._shapeCounter, 0);
+                this._addParticle(idx, this._positions.length, modelShape, this._shapeCounter, 0, bInfo);
                 // initialize the particle position
                 this.particles[this.nbParticles].position.addInPlace(barycenter);
                 this._index += shape.length;
@@ -47792,8 +47800,8 @@ var BABYLON;
             return shapeUV;
         };
         // adds a new particle object in the particles array
-        SolidParticleSystem.prototype._addParticle = function (idx, idxpos, model, shapeId, idxInShape, bbInfo) {
-            this.particles.push(new BABYLON.SolidParticle(idx, idxpos, model, shapeId, idxInShape, bbInfo));
+        SolidParticleSystem.prototype._addParticle = function (idx, idxpos, model, shapeId, idxInShape, bInfo) {
+            this.particles.push(new BABYLON.SolidParticle(idx, idxpos, model, shapeId, idxInShape, bInfo));
         };
         /**
         * Adds some particles to the SPS from the model shape. Returns the shape id.
@@ -47913,7 +47921,7 @@ var BABYLON;
             // if the particles will always face the camera
             if (this.billboard) {
                 // compute the camera position and un-rotate it by the current mesh rotation
-                if (this.mesh._worldMatrix.decompose(this._scale, this._quaternion, this._translation)) {
+                if (this._wm.decompose(this._scale, this._quaternion, this._translation)) {
                     this._quaternionToRotationMatrix();
                     this._rotMatrix.invertToRef(this._invertMatrix);
                     this._camera._currentTarget.subtractToRef(this._camera.globalPosition, this._camDir);
@@ -48099,8 +48107,8 @@ var BABYLON;
                         bSphere.radius = 0.0;
                     }
                     // then update the bbox and the bsphere into the world system
-                    bBox._update(this.mesh.getWorldMatrix());
-                    bSphere._update(this.mesh.getWorldMatrix());
+                    bBox._update(this._wm);
+                    bSphere._update(this._wm);
                 }
                 // increment indexes for the next particle
                 index = idx + 3;

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 30 - 30
dist/preview release/babylon.noworker.js


+ 3 - 0
src/Particles/babylon.solidParticle.js

@@ -47,6 +47,9 @@ var BABYLON;
             configurable: true
         });
         SolidParticle.prototype.intersectsMesh = function (target) {
+            if (!(this.isVisible && target.isVisible)) {
+                return false; // only visible particle and target can intersect
+            }
             if (!this._boundingInfo || !target._boundingInfo) {
                 return false;
             }

+ 11 - 6
src/Particles/babylon.solidParticleSystem.js

@@ -137,6 +137,7 @@ var BABYLON;
             vertexData.applyToMesh(mesh, this._updatable);
             this.mesh = mesh;
             this.mesh.isPickable = this._pickable;
+            this._wm = this.mesh.getWorldMatrix();
             // free memory
             this._positions = null;
             this._normals = null;
@@ -221,10 +222,14 @@ var BABYLON;
                 for (v = 0; v < shape.length; v++) {
                     shape[v].subtractInPlace(barycenter);
                 }
+                var bInfo;
+                if (this._particlesIntersect) {
+                    bInfo = new BABYLON.BoundingInfo(barycenter, barycenter);
+                }
                 var modelShape = new BABYLON.ModelShape(this._shapeCounter, shape, shapeUV, null, null);
                 // add the particle in the SPS
                 this._meshBuilder(this._index, shape, this._positions, facetInd, this._indices, facetUV, this._uvs, facetCol, this._colors, meshNor, this._normals, idx, 0, null);
-                this._addParticle(idx, this._positions.length, modelShape, this._shapeCounter, 0);
+                this._addParticle(idx, this._positions.length, modelShape, this._shapeCounter, 0, bInfo);
                 // initialize the particle position
                 this.particles[this.nbParticles].position.addInPlace(barycenter);
                 this._index += shape.length;
@@ -343,8 +348,8 @@ var BABYLON;
             return shapeUV;
         };
         // adds a new particle object in the particles array
-        SolidParticleSystem.prototype._addParticle = function (idx, idxpos, model, shapeId, idxInShape, bbInfo) {
-            this.particles.push(new BABYLON.SolidParticle(idx, idxpos, model, shapeId, idxInShape, bbInfo));
+        SolidParticleSystem.prototype._addParticle = function (idx, idxpos, model, shapeId, idxInShape, bInfo) {
+            this.particles.push(new BABYLON.SolidParticle(idx, idxpos, model, shapeId, idxInShape, bInfo));
         };
         /**
         * Adds some particles to the SPS from the model shape. Returns the shape id.
@@ -464,7 +469,7 @@ var BABYLON;
             // if the particles will always face the camera
             if (this.billboard) {
                 // compute the camera position and un-rotate it by the current mesh rotation
-                if (this.mesh._worldMatrix.decompose(this._scale, this._quaternion, this._translation)) {
+                if (this._wm.decompose(this._scale, this._quaternion, this._translation)) {
                     this._quaternionToRotationMatrix();
                     this._rotMatrix.invertToRef(this._invertMatrix);
                     this._camera._currentTarget.subtractToRef(this._camera.globalPosition, this._camDir);
@@ -650,8 +655,8 @@ var BABYLON;
                         bSphere.radius = 0.0;
                     }
                     // then update the bbox and the bsphere into the world system
-                    bBox._update(this.mesh.getWorldMatrix());
-                    bSphere._update(this.mesh.getWorldMatrix());
+                    bBox._update(this._wm);
+                    bSphere._update(this._wm);
                 }
                 // increment indexes for the next particle
                 index = idx + 3;

+ 30 - 30
src/babylon.engine.js

@@ -1159,40 +1159,40 @@ var BABYLON;
             }
         };
         Engine.prototype.bindBuffers = function (vertexBuffers, indexBuffer, effect) {
-            //   if (this._cachedVertexBuffers !== vertexBuffers || this._cachedEffectForVertexBuffers !== effect) {
-            this._cachedVertexBuffers = vertexBuffers;
-            this._cachedEffectForVertexBuffers = effect;
-            var attributes = effect.getAttributesNames();
-            for (var index = 0; index < attributes.length; index++) {
-                var order = effect.getAttributeLocation(index);
-                if (order >= 0) {
-                    var vertexBuffer = vertexBuffers[attributes[index]];
-                    if (!vertexBuffer) {
-                        if (this._vertexAttribArraysEnabled[order]) {
-                            this._gl.disableVertexAttribArray(order);
-                            this._vertexAttribArraysEnabled[order] = false;
+            if (this._cachedVertexBuffers !== vertexBuffers || this._cachedEffectForVertexBuffers !== effect) {
+                this._cachedVertexBuffers = vertexBuffers;
+                this._cachedEffectForVertexBuffers = effect;
+                var attributes = effect.getAttributesNames();
+                for (var index = 0; index < attributes.length; index++) {
+                    var order = effect.getAttributeLocation(index);
+                    if (order >= 0) {
+                        var vertexBuffer = vertexBuffers[attributes[index]];
+                        if (!vertexBuffer) {
+                            if (this._vertexAttribArraysEnabled[order]) {
+                                this._gl.disableVertexAttribArray(order);
+                                this._vertexAttribArraysEnabled[order] = false;
+                            }
+                            continue;
+                        }
+                        if (!this._vertexAttribArraysEnabled[order]) {
+                            this._gl.enableVertexAttribArray(order);
+                            this._vertexAttribArraysEnabled[order] = true;
+                        }
+                        var buffer = vertexBuffer.getBuffer();
+                        this.vertexAttribPointer(buffer, order, vertexBuffer.getSize(), this._gl.FLOAT, false, vertexBuffer.getStrideSize() * 4, vertexBuffer.getOffset() * 4);
+                        if (vertexBuffer.getIsInstanced()) {
+                            this._caps.instancedArrays.vertexAttribDivisorANGLE(order, 1);
+                            this._currentInstanceLocations.push(order);
+                            this._currentInstanceBuffers.push(buffer);
                         }
-                        continue;
-                    }
-                    if (!this._vertexAttribArraysEnabled[order]) {
-                        this._gl.enableVertexAttribArray(order);
-                        this._vertexAttribArraysEnabled[order] = true;
-                    }
-                    var buffer = vertexBuffer.getBuffer();
-                    this.vertexAttribPointer(buffer, order, vertexBuffer.getSize(), this._gl.FLOAT, false, vertexBuffer.getStrideSize() * 4, vertexBuffer.getOffset() * 4);
-                    if (vertexBuffer.getIsInstanced()) {
-                        this._caps.instancedArrays.vertexAttribDivisorANGLE(order, 1);
-                        this._currentInstanceLocations.push(order);
-                        this._currentInstanceBuffers.push(buffer);
                     }
                 }
             }
-            //   }
-            // if (indexBuffer != null && this._cachedIndexBuffer !== indexBuffer) {
-            this._cachedIndexBuffer = indexBuffer;
-            this.bindIndexBuffer(indexBuffer);
-            this._uintIndicesCurrentlySet = indexBuffer.is32Bits;
-            //}
+            if (indexBuffer != null && this._cachedIndexBuffer !== indexBuffer) {
+                this._cachedIndexBuffer = indexBuffer;
+                this.bindIndexBuffer(indexBuffer);
+                this._uintIndicesCurrentlySet = indexBuffer.is32Bits;
+            }
         };
         Engine.prototype.unbindInstanceAttributes = function () {
             var boundBuffer;

+ 4 - 4
src/babylon.engine.ts

@@ -1349,7 +1349,7 @@
         }
 
         public bindBuffers(vertexBuffers: { [key: string]: VertexBuffer; }, indexBuffer: WebGLBuffer, effect: Effect): void {
-         //   if (this._cachedVertexBuffers !== vertexBuffers || this._cachedEffectForVertexBuffers !== effect) {
+            if (this._cachedVertexBuffers !== vertexBuffers || this._cachedEffectForVertexBuffers !== effect) {
                 this._cachedVertexBuffers = vertexBuffers;
                 this._cachedEffectForVertexBuffers = effect;
 
@@ -1384,13 +1384,13 @@
                         }
                     }
                 }
-         //   }
+            }
 
-           // if (indexBuffer != null && this._cachedIndexBuffer !== indexBuffer) {
+            if (indexBuffer != null && this._cachedIndexBuffer !== indexBuffer) {
                 this._cachedIndexBuffer = indexBuffer;
                 this.bindIndexBuffer(indexBuffer);
                 this._uintIndicesCurrentlySet = indexBuffer.is32Bits;
-            //}
+            }
         }
 
         public unbindInstanceAttributes() {