Browse Source

Merge pull request #5103 from TrevorDev/subEmitterDelay

Sub emitter delay and better error for gradients dependent on targetStopDuration
David Catuhe 7 năm trước cách đây
mục cha
commit
df6230e6d6

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

@@ -44,6 +44,7 @@
   - Attached sub emitters. [Doc](http://doc.babylonjs.com/how_to/sub_emitters) ([TrevorDev](https://github.com/TrevorDev))
   - Cylinder particle emitter and constructor in baseParticle [Doc](https://doc.babylonjs.com/babylon101/particles#cylinder-emitter) ([TrevorDev](https://github.com/TrevorDev))
   - Added support for cylinder particle emitter. [Doc](https://doc.babylonjs.com/babylon101/particles#cylinder-emitter) ([TrevorDev](https://github.com/TrevorDev))
+  - Added startDelay to support delaying system start of sub emitters [Doc](https://doc.babylonjs.com/babylon101/particles#creating-the-particles) ([TrevorDev](https://github.com/TrevorDev))
   - Added support for random start cell when using animated sprite sheets. [Doc](http://doc.babylonjs.com/how_to/animate)
 - Added SceneComponent to help decoupling Scene from its components. ([sebavan](http://www.github.com/sebavan))
 - Added [Environment Texture Tools](https://doc.babylonjs.com/how_to/physically_based_rendering#creating-a-compressed-environment-texture) to reduce the size of the usual .DDS file ([sebavan](http://www.github.com/sebavan))

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

@@ -266,6 +266,17 @@ 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);
+        }
+
+        /**
+         * Defines the delay in milliseconds before starting the system (0 by default)
+         */
+        public startDelay = 0;
 
         /**
          * Gets the current list of drag gradients.

+ 5 - 2
src/Particles/babylon.gpuParticleSystem.ts

@@ -117,9 +117,12 @@
 
         /**
          * Starts the particle system and begins to emit
-         * @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 (this.startDelay by default)
          */
-        public start(delay = 0): void {
+        public start(delay = this.startDelay): 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);

+ 6 - 3
src/Particles/babylon.particleSystem.ts

@@ -997,9 +997,12 @@
 
         /**
          * Starts the particle system and begins to emit
-         * @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 (this.startDelay by default)
          */
-        public start(delay = 0): void {
+        public start(delay = this.startDelay): 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) {