Pārlūkot izejas kodu

adding appened particle vertex with minimal if else

DESKTOP-QJU4N0L\mityh 8 gadi atpakaļ
vecāks
revīzija
76701d03d2

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 2420 - 2416
dist/preview release/babylon.d.ts


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 16 - 16
dist/preview release/babylon.js


+ 30 - 18
dist/preview release/babylon.max.js

@@ -41020,6 +41020,7 @@ var BABYLON;
             this._sheetDirection = 1;
             this._time = 0;
             this._vertixBufferSize = 11;
+            this.appendParticleVertexes = null;
             this.id = name;
             this._capacity = capacity;
             this._epsilon = epsilon;
@@ -41325,30 +41326,41 @@ var BABYLON;
                 var rowSize = baseSize.width / this.cellWidth;
                 var engine = this._scene.getEngine();
                 deltaTime = engine.getDeltaTime();
-            }
-            // Update VBO
-            var offset = 0;
-            if (this.cellSize) {
-                for (var index = 0; index < this.particles.length; index++) {
-                    var particle = this.particles[index];
-                    this._appendParticleVertexWithAnimation(offset++, particle, 0, 0, rowSize);
-                    this._appendParticleVertexWithAnimation(offset++, particle, 1, 0, rowSize);
-                    this._appendParticleVertexWithAnimation(offset++, particle, 1, 1, rowSize);
-                    this._appendParticleVertexWithAnimation(offset++, particle, 0, 1, rowSize);
-                    particle._animate(deltaTime);
+                if (this._animationStarted) {
+                    this.appendParticleVertexes = this.appenedAllParticleVertexesWithSheetAndAnimationStarted;
+                }
+                else {
+                    this.appendParticleVertexes = this.appenedAllParticleVertexesWithSheet;
                 }
             }
             else {
-                for (var index = 0; index < this.particles.length; index++) {
-                    var particle = this.particles[index];
-                    this._appendParticleVertex(offset++, particle, 0, 0);
-                    this._appendParticleVertex(offset++, particle, 1, 0);
-                    this._appendParticleVertex(offset++, particle, 1, 1);
-                    this._appendParticleVertex(offset++, particle, 0, 1);
-                }
+                this.appendParticleVertexes = this.appenedParticleVertexesNoSheet;
+            }
+            // Update VBO
+            var offset = 0;
+            for (var index = 0; index < this.particles.length; index++) {
+                var particle = this.particles[index];
+                this.appendParticleVertexes(offset, particle, rowSize, deltaTime);
+                offset += 4;
             }
             this._vertexBuffer.update(this._vertexData);
         };
+        ParticleSystem.prototype.appenedAllParticleVertexesWithSheet = function (offset, particle, rowSize, deltaTime) {
+            this._appendParticleVertexWithAnimation(offset++, particle, 0, 0, rowSize);
+            this._appendParticleVertexWithAnimation(offset++, particle, 1, 0, rowSize);
+            this._appendParticleVertexWithAnimation(offset++, particle, 1, 1, rowSize);
+            this._appendParticleVertexWithAnimation(offset++, particle, 0, 1, rowSize);
+        };
+        ParticleSystem.prototype.appenedAllParticleVertexesWithSheetAndAnimationStarted = function (offset, particle, rowSize, deltaTime) {
+            this.appenedAllParticleVertexesWithSheet(offset, particle, rowSize, deltaTime);
+            particle._animate(deltaTime);
+        };
+        ParticleSystem.prototype.appenedParticleVertexesNoSheet = function (offset, particle, rowSize, deltaTime) {
+            this._appendParticleVertex(offset++, particle, 0, 0);
+            this._appendParticleVertex(offset++, particle, 1, 0);
+            this._appendParticleVertex(offset++, particle, 1, 1);
+            this._appendParticleVertex(offset++, particle, 0, 1);
+        };
         ParticleSystem.prototype.rebuild = function () {
             this._createIndexBuffer();
             this._vertexBuffer._rebuild();

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 2420 - 2416
dist/preview release/babylon.module.d.ts


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 26 - 26
dist/preview release/babylon.worker.js


+ 36 - 19
src/Particles/babylon.particleSystem.ts

@@ -368,7 +368,7 @@
                     particle.cellIndex = this._fromIndex;
                 } else {
                     if (this.cellSize) {
-                        particle = new Particle(this, this.cellWidth, this.cellHeight, this.cellIndex, this.invertU, this.invertV, this._loopAnimation, this._fromIndex, this._toIndex, this._delay, this._sheetDirection, this._time,this.disposeParticlesWhenFinishedAnimating);
+                        particle = new Particle(this, this.cellWidth, this.cellHeight, this.cellIndex, this.invertU, this.invertV, this._loopAnimation, this._fromIndex, this._toIndex, this._delay, this._sheetDirection, this._time, this.disposeParticlesWhenFinishedAnimating);
                     }
                     else {
                         particle = new Particle(this);
@@ -506,33 +506,50 @@
                 var rowSize = baseSize.width / this.cellWidth;
                 var engine = this._scene.getEngine();
                 deltaTime = engine.getDeltaTime();
-            }
 
-            // Update VBO
-            var offset = 0;
-            if (this.cellSize) {
-                for (var index = 0; index < this.particles.length; index++) {
-                    var particle = this.particles[index];
-                    this._appendParticleVertexWithAnimation(offset++, particle, 0, 0, rowSize);
-                    this._appendParticleVertexWithAnimation(offset++, particle, 1, 0, rowSize);
-                    this._appendParticleVertexWithAnimation(offset++, particle, 1, 1, rowSize);
-                    this._appendParticleVertexWithAnimation(offset++, particle, 0, 1, rowSize);
-                    particle._animate(deltaTime);
+                if (this._animationStarted) {
+                    this.appendParticleVertexes = this.appenedAllParticleVertexesWithSheetAndAnimationStarted;
+                }
+                else {
+                    this.appendParticleVertexes = this.appenedAllParticleVertexesWithSheet;
                 }
             }
             else {
-                for (var index = 0; index < this.particles.length; index++) {
-                    var particle = this.particles[index];
-                    this._appendParticleVertex(offset++, particle, 0, 0);
-                    this._appendParticleVertex(offset++, particle, 1, 0);
-                    this._appendParticleVertex(offset++, particle, 1, 1);
-                    this._appendParticleVertex(offset++, particle, 0, 1);
-                }
+                this.appendParticleVertexes = this.appenedParticleVertexesNoSheet;
+            }
+
+            // Update VBO
+            var offset = 0;
+            for (var index = 0; index < this.particles.length; index++) {
+                var particle = this.particles[index];
+                this.appendParticleVertexes(offset, particle, rowSize, deltaTime);
+                offset += 4;
             }
 
             this._vertexBuffer.update(this._vertexData);
         }
 
+        public appendParticleVertexes: (offset: number, particle: Particle, rowSize: number, deltaTime: number) => void = null;
+
+        private appenedAllParticleVertexesWithSheet(offset: number, particle: Particle, rowSize: number, deltaTime: number) {
+            this._appendParticleVertexWithAnimation(offset++, particle, 0, 0, rowSize);
+            this._appendParticleVertexWithAnimation(offset++, particle, 1, 0, rowSize);
+            this._appendParticleVertexWithAnimation(offset++, particle, 1, 1, rowSize);
+            this._appendParticleVertexWithAnimation(offset++, particle, 0, 1, rowSize);
+        }
+
+        private appenedAllParticleVertexesWithSheetAndAnimationStarted(offset: number, particle: Particle, rowSize: number, deltaTime: number) {
+            this.appenedAllParticleVertexesWithSheet(offset, particle, rowSize, deltaTime);
+            particle._animate(deltaTime);
+        }
+
+        private appenedParticleVertexesNoSheet(offset: number, particle: Particle, rowSize: number, deltaTime: number) {
+            this._appendParticleVertex(offset++, particle, 0, 0);
+            this._appendParticleVertex(offset++, particle, 1, 0);
+            this._appendParticleVertex(offset++, particle, 1, 1);
+            this._appendParticleVertex(offset++, particle, 0, 1);
+        }
+
         public rebuild(): void {
             this._createIndexBuffer();