Pārlūkot izejas kodu

error when no targetStopDuration is supplied but a gradient depends on it

Trevor Baron 7 gadi atpakaļ
vecāks
revīzija
80ba960b41

+ 6 - 0
src/Particles/babylon.baseParticleSystem.ts

@@ -266,6 +266,12 @@ module BABYLON {
         protected _rampGradients: Nullable<Array<Color3Gradient>> = null;
         protected _colorRemapGradients: Nullable<Array<FactorGradient>> = null;
         protected _alphaRemapGradients: Nullable<Array<FactorGradient>> = null;        
+        
+        protected _hasTargetStopDurationDependantGradient(){
+            return (this._startSizeGradients && this._startSizeGradients.length > 0)
+                || (this._emitRateGradients && this._emitRateGradients.length > 0)
+                || (this._lifeTimeGradients && this._lifeTimeGradients.length > 0);
+        }
 
         /**
          * Gets the current list of drag gradients.

+ 4 - 1
src/Particles/babylon.particleSystem.ts

@@ -1000,6 +1000,9 @@
          * @param delay defines the delay in milliseconds before starting the system (0 by default)
          */
         public start(delay = 0): void {
+            if(!this.targetStopDuration && this._hasTargetStopDurationDependantGradient()){
+                throw "Particle system started with a targetStopDuration dependant gradient (eg. startSizeGradients) but no targetStopDuration set";
+            }
             if (delay) {
                 setTimeout(() => {
                     this.start(0);
@@ -1286,7 +1289,7 @@
                 particle.scale.copyFromFloats(Scalar.RandomRange(this.minScaleX, this.maxScaleX), Scalar.RandomRange(this.minScaleY, this.maxScaleY));
 
                 // Adjust scale by start size
-                if (this._startSizeGradients && this._startSizeGradients[0]) {
+                if (this._startSizeGradients && this._startSizeGradients[0] && this.targetStopDuration) {
                     const ratio = this._actualFrame / this.targetStopDuration;
                     Tools.GetCurrentGradient(ratio, this._startSizeGradients, (currentGradient, nextGradient, scale) => {
                         if (currentGradient !== this._currentStartSizeGradient) {