Browse Source

fix remaining particles when not removing the tail

Jérôme Bousquié 5 năm trước cách đây
mục cha
commit
093a1ccca3
1 tập tin đã thay đổi với 12 bổ sung3 xóa
  1. 12 3
      src/Particles/solidParticleSystem.ts

+ 12 - 3
src/Particles/solidParticleSystem.ts

@@ -317,7 +317,7 @@ export class SolidParticleSystem implements IDisposable {
             if (this._particlesIntersect) {
                 bInfo = new BoundingInfo(minimum, maximum);
             }
-            var modelShape = new ModelShape(this._shapeCounter, shape, shapeInd, shapeNor, shapeUV, shapeCol, null, null);
+            var modelShape = new ModelShape(this._shapeCounter, shape, shapeInd, shapeNor, shapeCol, shapeUV, null, null);
 
             // add the particle in the SPS
             var currentPos = this._positions.length;
@@ -537,7 +537,7 @@ export class SolidParticleSystem implements IDisposable {
         var posfunc = options ? options.positionFunction : null;
         var vtxfunc = options ? options.vertexFunction : null;
 
-        var modelShape = new ModelShape(this._shapeCounter, shape, indices, shapeNormals, shapeUV, shapeColors, posfunc, vtxfunc);
+        var modelShape = new ModelShape(this._shapeCounter, shape, indices, shapeNormals, shapeColors, shapeUV, posfunc, vtxfunc);
 
         // particles
         var sp;
@@ -640,11 +640,20 @@ export class SolidParticleSystem implements IDisposable {
      * @returns an array populated with the removed particles
      */
     public removeParticles(start: number, end: number): SolidParticle[] {
-        const particles = this.particles;
         var nb = end - start + 1;
         if (!this._expandable || nb <= 0 || nb >= this.nbParticles) {
             return [];
         }
+        const particles = this.particles;
+        const currentNb = this.nbParticles;
+        if (end < currentNb - 1) {              // update the particle indexes in the positions array in case they're remaining particles after the last removed
+            var startPositionIndex = particles[start]._pos;
+            var firstRemaining = end + 1;
+            var shift = particles[firstRemaining]._pos - startPositionIndex;
+            for (var i = firstRemaining; i < currentNb; i++) {
+                particles[i]._pos -= shift;
+            }
+        }
         var removed = particles.splice(start, nb);
         this._positions.length = 0;
         this._indices.length = 0;