Bläddra i källkod

creating public properties for spriteCellWidth

DESKTOP-QJU4N0L\mityh 8 år sedan
förälder
incheckning
0214ba0979

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 847 - 850
dist/preview release/babylon.d.ts


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 15 - 15
dist/preview release/babylon.js


+ 35 - 50
dist/preview release/babylon.max.js

@@ -40930,16 +40930,8 @@ var BABYLON;
 var BABYLON;
 (function (BABYLON) {
     var Particle = (function () {
-        function Particle(particleSystem, cellIndex, _loopAnimation, _fromIndex, _toIndex) {
-            if (cellIndex === void 0) { cellIndex = 0; }
-            if (_loopAnimation === void 0) { _loopAnimation = false; }
-            if (_fromIndex === void 0) { _fromIndex = 0; }
-            if (_toIndex === void 0) { _toIndex = 0; }
+        function Particle(particleSystem) {
             this.particleSystem = particleSystem;
-            this.cellIndex = cellIndex;
-            this._loopAnimation = _loopAnimation;
-            this._fromIndex = _fromIndex;
-            this._toIndex = _toIndex;
             this.position = BABYLON.Vector3.Zero();
             this.direction = BABYLON.Vector3.Zero();
             this.color = new BABYLON.Color4(0, 0, 0, 0);
@@ -40950,7 +40942,11 @@ var BABYLON;
             this.angle = 0;
             this.angularSpeed = 0;
             this._currentFrameCounter = 0;
-            this.cellIndex = this._fromIndex;
+            this.cellIndex = 0;
+            if (!this.particleSystem.IsAnimationSheetEnabled) {
+                return;
+            }
+            this.cellIndex = this.particleSystem.startSpriteCellID;
             if (this.particleSystem.spriteCellChangeSpeed == 0) {
                 this.updateCellIndex = this.updateCellIndexWithSpeedCalculated;
             }
@@ -40961,14 +40957,14 @@ var BABYLON;
         Particle.prototype.updateCellIndexWithSpeedCalculated = function (scaledUpdateSpeed) {
             var ageOffset = this.lifeTime - this.age;
             var numberOfScaledSlots = ageOffset / scaledUpdateSpeed;
-            var availableIndexes = this._toIndex + 1 - this.cellIndex;
+            var availableIndexes = this.particleSystem.endSpriteCellID + 1 - this.cellIndex;
             var incrementAt = numberOfScaledSlots / availableIndexes;
             this._currentFrameCounter += scaledUpdateSpeed;
             if (this._currentFrameCounter >= incrementAt * scaledUpdateSpeed) {
                 this._currentFrameCounter = 0;
                 this.cellIndex++;
-                if (this.cellIndex > this._toIndex) {
-                    this.cellIndex = this._toIndex;
+                if (this.cellIndex > this.particleSystem.endSpriteCellID) {
+                    this.cellIndex = this.particleSystem.endSpriteCellID;
                 }
             }
         };
@@ -40976,12 +40972,12 @@ var BABYLON;
             if (this._currentFrameCounter >= this.particleSystem.spriteCellChangeSpeed) {
                 this.cellIndex++;
                 this._currentFrameCounter = 0;
-                if (this.cellIndex > this._toIndex) {
-                    if (this._loopAnimation) {
-                        this.cellIndex = this._fromIndex;
+                if (this.cellIndex > this.particleSystem.endSpriteCellID) {
+                    if (this.particleSystem.spriteCellLoop) {
+                        this.cellIndex = this.particleSystem.startSpriteCellID;
                     }
                     else {
-                        this.cellIndex = this._toIndex;
+                        this.cellIndex = this.particleSystem.endSpriteCellID;
                     }
                 }
             }
@@ -41001,12 +40997,6 @@ var BABYLON;
             other.angularSpeed = this.angularSpeed;
             other.particleSystem = this.particleSystem;
             other.cellIndex = this.cellIndex;
-            other._loopAnimation = this._loopAnimation;
-            other._fromIndex = this._fromIndex;
-            other._toIndex = this._toIndex;
-        };
-        Particle.prototype.readyForRecycling = function () {
-            this.age = this.lifeTime;
         };
         return Particle;
     }());
@@ -41026,11 +41016,12 @@ var BABYLON;
     };
     var ParticleSystem = (function () {
         // end of sheet animation
-        function ParticleSystem(name, capacity, scene, customEffect, spriteCellSize, epsilon) {
+        function ParticleSystem(name, capacity, scene, customEffect, _isAnimationSheetEnabled, epsilon) {
+            if (_isAnimationSheetEnabled === void 0) { _isAnimationSheetEnabled = false; }
             if (epsilon === void 0) { epsilon = 0.01; }
             var _this = this;
             this.name = name;
-            this.spriteCellSize = spriteCellSize;
+            this._isAnimationSheetEnabled = _isAnimationSheetEnabled;
             // Members
             this.animations = [];
             this.renderingGroupId = 0;
@@ -41084,24 +41075,16 @@ var BABYLON;
             this.startSpriteCellID = 0;
             this.endSpriteCellID = 0;
             this.spriteCellLoop = true;
-            this.spriteCellChangeSpeed = 0; //(cellID++ every 4 frames). If this value is set to 0 (default) then we need to compute the speed base on lifetime like we are doing for colorDead. In other word, the particle will born with startCellId and die at endCellId
-            this._spriteCellWidth = 0;
-            this._spriteCellHeight = 0;
+            this.spriteCellChangeSpeed = 0;
+            this.spriteCellWidth = 0;
+            this.spriteCellHeight = 0;
             this._vertexBufferSize = 11;
             this.appendParticleVertexes = null;
             this.id = name;
             this._capacity = capacity;
             this._epsilon = epsilon;
-            if (spriteCellSize) {
+            if (_isAnimationSheetEnabled) {
                 this._vertexBufferSize = 12;
-                if (spriteCellSize.width && spriteCellSize.height) {
-                    this._spriteCellWidth = spriteCellSize.width;
-                    this._spriteCellHeight = spriteCellSize.height;
-                }
-                else {
-                    this._spriteCellWidth = spriteCellSize;
-                    this._spriteCellHeight = spriteCellSize;
-                }
             }
             this._scene = scene || BABYLON.Engine.LastCreatedScene;
             this._customEffect = customEffect;
@@ -41113,7 +41096,7 @@ var BABYLON;
             var positions = this._vertexBuffer.createVertexBuffer(BABYLON.VertexBuffer.PositionKind, 0, 3);
             var colors = this._vertexBuffer.createVertexBuffer(BABYLON.VertexBuffer.ColorKind, 3, 4);
             var options = this._vertexBuffer.createVertexBuffer("options", 7, 4);
-            if (this.spriteCellSize) {
+            if (this._isAnimationSheetEnabled) {
                 var cellIndexBuffer = this._vertexBuffer.createVertexBuffer("cellIndex", 11, 1);
                 this._vertexBuffers["cellIndex"] = cellIndexBuffer;
             }
@@ -41152,7 +41135,7 @@ var BABYLON;
                         particle.position.addInPlace(_this._scaledDirection);
                         _this.gravity.scaleToRef(_this._scaledUpdateSpeed, _this._scaledGravity);
                         particle.direction.addInPlace(_this._scaledGravity);
-                        if (_this.spriteCellSize) {
+                        if (_this._isAnimationSheetEnabled) {
                             particle.updateCellIndex(_this._scaledUpdateSpeed);
                         }
                     }
@@ -41169,6 +41152,13 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        Object.defineProperty(ParticleSystem.prototype, "IsAnimationSheetEnabled", {
+            get: function () {
+                return this._isAnimationSheetEnabled;
+            },
+            enumerable: true,
+            configurable: true
+        });
         ParticleSystem.prototype._createIndexBuffer = function () {
             var indices = [];
             var index = 0;
@@ -41270,12 +41260,7 @@ var BABYLON;
                     particle.cellIndex = this.startSpriteCellID;
                 }
                 else {
-                    if (this.spriteCellSize) {
-                        particle = new BABYLON.Particle(this, this.startSpriteCellID, this.spriteCellLoop, this.startSpriteCellID, this.endSpriteCellID);
-                    }
-                    else {
-                        particle = new BABYLON.Particle(this);
-                    }
+                    particle = new BABYLON.Particle(this);
                 }
                 this.particles.push(particle);
                 var emitPower = randomNumber(this.minEmitPower, this.maxEmitPower);
@@ -41299,7 +41284,7 @@ var BABYLON;
             if (this._scene.clipPlane) {
                 defines.push("#define CLIPPLANE");
             }
-            if (this.spriteCellSize) {
+            if (this._isAnimationSheetEnabled) {
                 defines.push("#define ANIMATESHEET");
             }
             // Effect
@@ -41308,7 +41293,7 @@ var BABYLON;
                 this._cachedDefines = join;
                 var attributesNamesOrOptions;
                 var effectCreationOption;
-                if (this.spriteCellSize) {
+                if (this._isAnimationSheetEnabled) {
                     attributesNamesOrOptions = [BABYLON.VertexBuffer.PositionKind, BABYLON.VertexBuffer.ColorKind, "options", "cellIndex"];
                     effectCreationOption = ["invView", "view", "projection", "particlesInfos", "vClipPlane", "textureMask"];
                 }
@@ -41370,7 +41355,7 @@ var BABYLON;
                 }
             }
             // Animation sheet
-            if (this.spriteCellSize) {
+            if (this._isAnimationSheetEnabled) {
                 this.appendParticleVertexes = this.appenedParticleVertexesWithSheet;
             }
             else {
@@ -41414,9 +41399,9 @@ var BABYLON;
             effect.setTexture("diffuseSampler", this.particleTexture);
             effect.setMatrix("view", viewMatrix);
             effect.setMatrix("projection", this._scene.getProjectionMatrix());
-            if (this.spriteCellSize) {
+            if (this._isAnimationSheetEnabled) {
                 var baseSize = this.particleTexture.getBaseSize();
-                effect.setFloat3("particlesInfos", this._spriteCellWidth / baseSize.width, this._spriteCellHeight / baseSize.height, baseSize.width / this._spriteCellWidth);
+                effect.setFloat3("particlesInfos", this.spriteCellWidth / baseSize.width, this.spriteCellHeight / baseSize.height, baseSize.width / this.spriteCellWidth);
             }
             effect.setFloat4("textureMask", this.textureMask.r, this.textureMask.g, this.textureMask.b, this.textureMask.a);
             if (this._scene.clipPlane) {

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 847 - 850
dist/preview release/babylon.module.d.ts


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 15 - 15
dist/preview release/babylon.worker.js


+ 14 - 16
src/Particles/babylon.particle.ts

@@ -12,9 +12,14 @@
         public angularSpeed = 0;
 
         private _currentFrameCounter = 0;
+        public cellIndex: number = 0;
 
-        constructor(private particleSystem: ParticleSystem, public cellIndex: number = 0, private _loopAnimation = false, private _fromIndex = 0, private _toIndex = 0) {
-            this.cellIndex = this._fromIndex;
+        constructor(private particleSystem: ParticleSystem) {
+            if (!this.particleSystem.IsAnimationSheetEnabled) {
+                return;
+            }
+
+            this.cellIndex = this.particleSystem.startSpriteCellID;
 
             if (this.particleSystem.spriteCellChangeSpeed == 0) {
                 this.updateCellIndex = this.updateCellIndexWithSpeedCalculated;
@@ -29,15 +34,15 @@
         private updateCellIndexWithSpeedCalculated(scaledUpdateSpeed: number): void {
             var ageOffset = this.lifeTime - this.age;
             var numberOfScaledSlots = ageOffset / scaledUpdateSpeed;
-            var availableIndexes = this._toIndex +1 - this.cellIndex;
+            var availableIndexes = this.particleSystem.endSpriteCellID + 1 - this.cellIndex;
             var incrementAt = numberOfScaledSlots / availableIndexes;
 
             this._currentFrameCounter += scaledUpdateSpeed;
             if (this._currentFrameCounter >= incrementAt * scaledUpdateSpeed) {
                 this._currentFrameCounter = 0;
                 this.cellIndex++;
-                if (this.cellIndex > this._toIndex) {
-                    this.cellIndex = this._toIndex;
+                if (this.cellIndex > this.particleSystem.endSpriteCellID) {
+                    this.cellIndex = this.particleSystem.endSpriteCellID;
                 }
             }
         }
@@ -46,12 +51,12 @@
             if (this._currentFrameCounter >= this.particleSystem.spriteCellChangeSpeed) {
                 this.cellIndex++;
                 this._currentFrameCounter = 0;
-                if (this.cellIndex > this._toIndex) {
-                    if (this._loopAnimation) {
-                        this.cellIndex = this._fromIndex;
+                if (this.cellIndex > this.particleSystem.endSpriteCellID) {
+                    if (this.particleSystem.spriteCellLoop) {
+                        this.cellIndex = this.particleSystem.startSpriteCellID;
                     }
                     else {
-                        this.cellIndex = this._toIndex;
+                        this.cellIndex = this.particleSystem.endSpriteCellID;
                     }
                 }
             }
@@ -72,13 +77,6 @@
             other.angularSpeed = this.angularSpeed;
             other.particleSystem = this.particleSystem;
             other.cellIndex = this.cellIndex;
-            other._loopAnimation = this._loopAnimation;
-            other._fromIndex = this._fromIndex;
-            other._toIndex = this._toIndex;
-        }
-
-        public readyForRecycling() {
-            this.age = this.lifeTime;
         }
     }
 } 

+ 17 - 25
src/Particles/babylon.particleSystem.ts

@@ -126,27 +126,24 @@
         public startSpriteCellID = 0;
         public endSpriteCellID = 0;
         public spriteCellLoop = true;
-        public spriteCellChangeSpeed = 0; //(cellID++ every 4 frames). If this value is set to 0 (default) then we need to compute the speed base on lifetime like we are doing for colorDead. In other word, the particle will born with startCellId and die at endCellId
+        public spriteCellChangeSpeed = 0;
 
-        private _spriteCellWidth = 0;
-        private _spriteCellHeight = 0;
+        public spriteCellWidth = 0;
+        public spriteCellHeight = 0;
         private _vertexBufferSize = 11;
+
+        public get IsAnimationSheetEnabled(): Boolean {
+            return this._isAnimationSheetEnabled;
+        }
         // end of sheet animation
 
-        constructor(public name: string, capacity: number, scene: Scene, customEffect?: Effect, private spriteCellSize?: any, epsilon: number = 0.01) {
+        constructor(public name: string, capacity: number, scene: Scene, customEffect?: Effect, private _isAnimationSheetEnabled: boolean = false, epsilon: number = 0.01) {
             this.id = name;
             this._capacity = capacity;
 
             this._epsilon = epsilon;
-            if (spriteCellSize) {
+            if (_isAnimationSheetEnabled) {
                 this._vertexBufferSize = 12;
-                if (spriteCellSize.width && spriteCellSize.height) {
-                    this._spriteCellWidth = spriteCellSize.width;
-                    this._spriteCellHeight = spriteCellSize.height;
-                } else {
-                    this._spriteCellWidth = spriteCellSize;
-                    this._spriteCellHeight = spriteCellSize;
-                }
             }
 
             this._scene = scene || Engine.LastCreatedScene;
@@ -165,7 +162,7 @@
             var colors = this._vertexBuffer.createVertexBuffer(VertexBuffer.ColorKind, 3, 4);
             var options = this._vertexBuffer.createVertexBuffer("options", 7, 4);
 
-            if (this.spriteCellSize) {
+            if (this._isAnimationSheetEnabled) {
                 var cellIndexBuffer = this._vertexBuffer.createVertexBuffer("cellIndex", 11, 1);
                 this._vertexBuffers["cellIndex"] = cellIndexBuffer;
             }
@@ -216,7 +213,7 @@
                         this.gravity.scaleToRef(this._scaledUpdateSpeed, this._scaledGravity);
                         particle.direction.addInPlace(this._scaledGravity);
 
-                        if (this.spriteCellSize) {
+                        if (this._isAnimationSheetEnabled) {
                             particle.updateCellIndex(this._scaledUpdateSpeed);
                         }
                     }
@@ -343,12 +340,7 @@
                     particle.age = 0;
                     particle.cellIndex = this.startSpriteCellID;
                 } else {
-                    if (this.spriteCellSize) {
-                        particle = new Particle(this, this.startSpriteCellID, this.spriteCellLoop, this.startSpriteCellID, this.endSpriteCellID);
-                    }
-                    else {
-                        particle = new Particle(this);
-                    }
+                    particle = new Particle(this);
                 }
 
                 this.particles.push(particle);
@@ -384,7 +376,7 @@
                 defines.push("#define CLIPPLANE");
             }
 
-            if (this.spriteCellSize) {
+            if (this._isAnimationSheetEnabled) {
                 defines.push("#define ANIMATESHEET");
             }
 
@@ -396,7 +388,7 @@
                 var attributesNamesOrOptions: any;
                 var effectCreationOption: any;
 
-                if (this.spriteCellSize) {
+                if (this._isAnimationSheetEnabled) {
                     attributesNamesOrOptions = [VertexBuffer.PositionKind, VertexBuffer.ColorKind, "options", "cellIndex"];
                     effectCreationOption = ["invView", "view", "projection", "particlesInfos", "vClipPlane", "textureMask"];
                 }
@@ -477,7 +469,7 @@
             }
 
             // Animation sheet
-            if (this.spriteCellSize) {
+            if (this._isAnimationSheetEnabled) {
                 this.appendParticleVertexes = this.appenedParticleVertexesWithSheet;
             }
             else {
@@ -535,9 +527,9 @@
             effect.setMatrix("view", viewMatrix);
             effect.setMatrix("projection", this._scene.getProjectionMatrix());
 
-            if (this.spriteCellSize) {
+            if (this._isAnimationSheetEnabled) {
                 var baseSize = this.particleTexture.getBaseSize();
-                effect.setFloat3("particlesInfos", this._spriteCellWidth / baseSize.width, this._spriteCellHeight / baseSize.height, baseSize.width / this._spriteCellWidth);
+                effect.setFloat3("particlesInfos", this.spriteCellWidth / baseSize.width, this.spriteCellHeight / baseSize.height, baseSize.width / this.spriteCellWidth);
             }
 
             effect.setFloat4("textureMask", this.textureMask.r, this.textureMask.g, this.textureMask.b, this.textureMask.a);