Browse Source

Merge pull request #5225 from TrevorDev/emitRateBugFix

reset emit rate on particle system start
David Catuhe 7 years ago
parent
commit
0feb4c3932
2 changed files with 13 additions and 11 deletions
  1. 1 0
      dist/preview release/what's new.md
  2. 12 11
      src/Particles/babylon.particleSystem.ts

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

@@ -201,6 +201,7 @@
 - trackPosition:false not working in webVRCamera/controllers ([TrevorDev](https://github.com/TrevorDev))
 - Spring Joint could not be removed ([TrevorDev](https://github.com/TrevorDev))
 - Sometimes duplicate controller models are loaded in VR ([TrevorDev](https://github.com/TrevorDev))
+- Particle emit rate over time does not reset on every particle system start ([TrevorDev](https://github.com/TrevorDev))
 
 ### Core Engine
 

+ 12 - 11
src/Particles/babylon.particleSystem.ts

@@ -655,17 +655,6 @@
             }
 
             this._addFactorGradient(this._emitRateGradients, gradient, factor, factor2);
-
-            if (!this._currentEmitRateGradient) {
-                this._currentEmitRateGradient = this._emitRateGradients[0];
-                this._currentEmitRate1 = this._currentEmitRateGradient.getFactor();
-                this._currentEmitRate2 = this._currentEmitRate1;
-            }
-
-            if (this._emitRateGradients.length === 2) {
-                this._currentEmitRate2 = this._emitRateGradients[1].getFactor();
-            }
-
             return this;
         }
 
@@ -1035,6 +1024,18 @@
                 this.activeSubSystems = new Array<ParticleSystem>();
             }
 
+            // Reset emit gradient so it acts the same on every start
+            if(this._emitRateGradients){
+                if(this._emitRateGradients.length > 0){
+                    this._currentEmitRateGradient = this._emitRateGradients[0];
+                    this._currentEmitRate1 = this._currentEmitRateGradient.getFactor();
+                    this._currentEmitRate2 = this._currentEmitRate1;
+                }
+                if(this._emitRateGradients.length > 1){
+                    this._currentEmitRate2 = this._emitRateGradients[1].getFactor();
+                }
+            }
+
             if (this.preWarmCycles) {
                 if (this.emitter instanceof AbstractMesh) {
                     this.emitter.computeWorldMatrix(true);