瀏覽代碼

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

Trevor Baron 7 年之前
父節點
當前提交
80ba960b41
共有 2 個文件被更改,包括 10 次插入1 次删除
  1. 6 0
      src/Particles/babylon.baseParticleSystem.ts
  2. 4 1
      src/Particles/babylon.particleSystem.ts

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

@@ -266,6 +266,12 @@ module BABYLON {
         protected _rampGradients: Nullable<Array<Color3Gradient>> = null;
         protected _rampGradients: Nullable<Array<Color3Gradient>> = null;
         protected _colorRemapGradients: Nullable<Array<FactorGradient>> = null;
         protected _colorRemapGradients: Nullable<Array<FactorGradient>> = null;
         protected _alphaRemapGradients: 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.
          * 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)
          * @param delay defines the delay in milliseconds before starting the system (0 by default)
          */
          */
         public start(delay = 0): void {
         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) {
             if (delay) {
                 setTimeout(() => {
                 setTimeout(() => {
                     this.start(0);
                     this.start(0);
@@ -1286,7 +1289,7 @@
                 particle.scale.copyFromFloats(Scalar.RandomRange(this.minScaleX, this.maxScaleX), Scalar.RandomRange(this.minScaleY, this.maxScaleY));
                 particle.scale.copyFromFloats(Scalar.RandomRange(this.minScaleX, this.maxScaleX), Scalar.RandomRange(this.minScaleY, this.maxScaleY));
 
 
                 // Adjust scale by start size
                 // 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;
                     const ratio = this._actualFrame / this.targetStopDuration;
                     Tools.GetCurrentGradient(ratio, this._startSizeGradients, (currentGradient, nextGradient, scale) => {
                     Tools.GetCurrentGradient(ratio, this._startSizeGradients, (currentGradient, nextGradient, scale) => {
                         if (currentGradient !== this._currentStartSizeGradient) {
                         if (currentGradient !== this._currentStartSizeGradient) {