From a637408a8798f63b9f842b06706c545b6c3be082 Mon Sep 17 00:00:00 2001 From: hanbollar Date: Thu, 5 Apr 2018 11:06:51 -0400 Subject: [PATCH 1/6] particle system updates --- Source/Scene/Particle.js | 41 +++--- Source/Scene/ParticleSystem.js | 251 +++++++++++++++++++++++++-------- 2 files changed, 210 insertions(+), 82 deletions(-) diff --git a/Source/Scene/Particle.js b/Source/Scene/Particle.js index 436d71a0b649..a61869ad0650 100644 --- a/Source/Scene/Particle.js +++ b/Source/Scene/Particle.js @@ -4,14 +4,16 @@ define([ '../Core/Color', '../Core/defaultValue', '../Core/defined', - '../Core/defineProperties' + '../Core/defineProperties', + '../Core/deprecationWarning' ], function( Cartesian2, Cartesian3, Color, defaultValue, defined, - defineProperties) { + defineProperties, + deprecationWarning) { 'use strict'; var defaultSize = new Cartesian2(1.0, 1.0); @@ -26,13 +28,15 @@ define([ * @param {Number} [options.mass=1.0] The mass of particles in kilograms. * @param {Cartesian3} [options.position=Cartesian3.ZERO] The initial position of the particle in world coordinates. * @param {Cartesian3} [options.velocity=Cartesian3.ZERO] The velocity vector of the particle in world coordinates. - * @param {Number} [options.life=Number.MAX_VALUE] The life of particles in seconds. + * @param {Number} [options.life=Number.MAX_VALUE] The life of the particle in seconds. * @param {Object} [options.image] The URI, HTMLImageElement, or HTMLCanvasElement to use for the billboard. + * @param {Object} [options.color] Sets the start and end colors. * @param {Color} [options.startColor=Color.WHITE] The color of a particle when it is born. * @param {Color} [options.endColor=Color.WHITE] The color of a particle when it dies. + * @param {Object} [options.scale] Sets the start and end scales. * @param {Number} [options.startScale=1.0] The scale of the particle when it is born. * @param {Number} [options.endScale=1.0] The scale of the particle when it dies. - * @param {Cartesian2} [options.size=new Cartesian2(1.0, 1.0)] The dimensions of particles in pixels. + * @param {Cartesian2} [options.imageSize=new Cartesian2(1.0, 1.0)] The dimensions of the image representing the particle in pixels. Width by Height. */ function Particle(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); @@ -72,31 +76,35 @@ define([ * @type {Color} * @default Color.WHITE */ - this.startColor = Color.clone(defaultValue(options.startColor, Color.WHITE)); + this.startColor = Color.clone(defaultValue(options.color, defaultValue(options.startColor, Color.WHITE))); /** * The color of the particle when it dies. * @type {Color} * @default Color.WHITE */ - this.endColor = Color.clone(defaultValue(options.endColor, Color.WHITE)); + this.endColor = Color.clone(defaultValue(options.color, defaultValue(options.endColor, Color.WHITE))); /** * the scale of the particle when it is born. * @type {Number} * @default 1.0 */ - this.startScale = defaultValue(options.startScale, 1.0); + this.startScale = defaultValue(options.scale, defaultValue(options.startScale, 1.0)); /** * The scale of the particle when it dies. * @type {Number} * @default 1.0 */ - this.endScale = defaultValue(options.endScale, 1.0); + this.endScale = defaultValue(options.scale, defaultValue(options.endScale, 1.0)); /** - * The dimensions of the particle in pixels. + * The dimensions of the image representing the particle in pixels. Width by Height. * @type {Cartesian2} * @default new Cartesian(1.0, 1.0) */ - this.size = Cartesian2.clone(defaultValue(options.size, defaultSize)); + this.imageSize = Cartesian2.clone(defaultValue(options.imageSize, defaultSize)); + if (defined(options.size)) { + deprecationWarning('size', 'size was deprecated in Cesium 1.45. It will be removed in 1.46. Use imageSize instead.'); + this.imageSize = Cartesian2.clone(defaultValue(options.size, defaultSize)); + } this._age = 0.0; this._normalizedAge = 0.0; @@ -133,21 +141,14 @@ define([ /** * @private */ - Particle.prototype.update = function(dt, forces) { + Particle.prototype.update = function(dt, particleUpdateFunction) { // Apply the velocity Cartesian3.multiplyByScalar(this.velocity, dt, deltaScratch); Cartesian3.add(this.position, deltaScratch, this.position); // Update any forces. - if (defined(forces)) { - var length = forces.length; - for (var i = 0; i < length; ++i) { - var force = forces[i]; - if (typeof force === 'function') { - // Force is just a simple callback function. - force(this, dt); - } - } + if (defined(particleUpdateFunction) && typeof particleUpdateFunction === 'function') { + particleUpdateFunction(this, dt); } // Age the particle diff --git a/Source/Scene/ParticleSystem.js b/Source/Scene/ParticleSystem.js index 6ce7467f73ca..7c878c404eb2 100644 --- a/Source/Scene/ParticleSystem.js +++ b/Source/Scene/ParticleSystem.js @@ -6,6 +6,7 @@ define([ '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', + '../Core/deprecationWarning', '../Core/destroyObject', '../Core/Event', '../Core/JulianDate', @@ -22,6 +23,7 @@ define([ defaultValue, defined, defineProperties, + deprecationWarning, destroyObject, Event, JulianDate, @@ -32,6 +34,8 @@ define([ Particle) { 'use strict'; + var defaultImageSize = new Cartesian2(1.0, 1.0); + /** * A ParticleSystem manages the updating and display of a collection of particles. * @@ -40,36 +44,35 @@ define([ * * @param {Object} [options] Object with the following properties: * @param {Boolean} [options.show=true] Whether to display the particle system. - * @param {ParticleSystem~applyForce[]} [options.forces] An array of force callbacks. + * @param {ParticleSystem~updateParticle} [options.updateParticle] The callback to an update function used for every particle in this system. * @param {ParticleEmitter} [options.emitter=new CircleEmitter(0.5)] The particle emitter for this system. * @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] The 4x4 transformation matrix that transforms the particle system from model to world coordinates. * @param {Matrix4} [options.emitterModelMatrix=Matrix4.IDENTITY] The 4x4 transformation matrix that transforms the particle system emitter within the particle systems local coordinate system. - * @param {Color} [options.startColor=Color.WHITE] The color of a particle when it is born. - * @param {Color} [options.endColor=Color.WHITE] The color of a particle when it dies. - * @param {Number} [options.startScale=1.0] The scale of the particle when it is born. - * @param {Number} [options.endScale=1.0] The scale of the particle when it dies. - * @param {Number} [options.rate=5] The number of particles to emit per second. + * @param {Number} [options.emissionRate=5] The number of particles to emit per second. * @param {ParticleBurst[]} [options.bursts] An array of {@link ParticleBurst}, emitting bursts of particles at periodic times. * @param {Boolean} [options.loop=true] Whether the particle system should loop it's bursts when it is complete. - * @param {Number} [options.speed] Sets the minimum and maximum speed in meters per second + * @param {Number} [options.scale] Sets the start and end scales. + * @param {Number} [options.startScale=1.0] The scale of the particle when it is born. + * @param {Number} [options.endScale=1.0] The scale of the particle when it dies. + * @param {Color} [options.color] Sets the start and end colors. + * @param {Color} [options.startColor=Color.WHITE] The color of a particle when it is born. + * @param {Color} [options.endColor=Color.WHITE] The color of a particle when it dies. + * @param {Object} [options.image] The URI, HTMLImageElement, or HTMLCanvasElement to use for the billboard. + * @param {Cartesian2} [options.imageSize] Sets the maximum and minimum dimensions of the image representing the particle in pixels. Width by Height. + * @param {Cartesian2} [options.minimumImageSize=new Cartesian2(1.0, 1.0)] Sets the minimum dimensions of the image representing the particle in pixels. Width by Height. + * @param {Cartesian2} [options.maximumImageSize=new Cartesian2(1.0, 1.0)] Sets the maximum dimensions of the image representing the particle in pixels. Width by Height. + * @param {Number} [options.speed] Sets the minimum and maximum speed in meters per second. * @param {Number} [options.minimumSpeed=1.0] Sets the minimum speed in meters per second. * @param {Number} [options.maximumSpeed=1.0] Sets the maximum speed in meters per second. + * @param {Number} [options.lifetime=Number.MAX_VALUE] How long the particle system will emit particles, in seconds. * @param {Number} [options.life] Sets the minimum and maximum life of particles in seconds. * @param {Number} [options.minimumLife=5.0] Sets the minimum life of particles in seconds. * @param {Number} [options.maximumLife=5.0] Sets the maximum life of particles in seconds. * @param {Number} [options.mass] Sets the minimum and maximum mass of particles in kilograms. * @param {Number} [options.minimumMass=1.0] Sets the minimum mass of particles in kilograms. * @param {Number} [options.maximumMass=1.0] Sets the maximum mass of particles in kilograms. - * @param {Object} [options.image] The URI, HTMLImageElement, or HTMLCanvasElement to use for the billboard. - * @param {Number} [options.width] Sets the minimum and maximum width of particles in pixels. - * @param {Number} [options.minimumWidth=1.0] Sets the minimum width of particles in pixels. - * @param {Number} [options.maximumWidth=1.0] Sets the maximum width of particles in pixels. - * @param {Number} [options.height] Sets the minimum and maximum height of particles in pixels. - * @param {Number} [options.minimumHeight=1.0] Sets the minimum height of particles in pixels. - * @param {Number} [options.maximumHeight=1.0] Sets the maximum height of particles in pixels. - * @param {Number} [options.lifeTime=Number.MAX_VALUE] How long the particle system will emit particles, in seconds. - * - * @demo {@link https://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=ParticleSystem.html|Particle Systems Demo} + * @demo {@link https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=Particle%20System.html&label=Showcases|Particle Systems Plane Demo} + * @demo {@link https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=Particle%20System%20Fireworks.html&label=Showcases|Particle Systems Fireworks Demo} */ function ParticleSystem(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); @@ -83,11 +86,14 @@ define([ /** * An array of force callbacks. The callback is passed a {@link Particle} and the difference from the last time - * @type {ParticleSystem~applyForce[]} + * @type {ParticleSystem~updateParticle} * @default undefined */ - this.forces = options.forces; - + this.updateParticle = options.updateParticle; + if (defined(options.forces)) { + deprecationWarning('forces', 'forces was deprecated in Cesium 1.45. It will be removed in 1.46. Use updateParticle instead.'); + this.updateParticle = options.forces[0]; + } /** * Whether the particle system should loop it's bursts when it is complete. * @type {Boolean} @@ -115,13 +121,17 @@ define([ this._matrixDirty = true; this._combinedMatrix = new Matrix4(); - this._startColor = Color.clone(defaultValue(options.startColor, Color.WHITE)); - this._endColor = Color.clone(defaultValue(options.endColor, Color.WHITE)); + this._startColor = Color.clone(defaultValue(options.color, defaultValue(options.startColor, Color.WHITE))); + this._endColor = Color.clone(defaultValue(options.color, defaultValue(options.endColor, Color.WHITE))); - this._startScale = defaultValue(options.startScale, 1.0); - this._endScale = defaultValue(options.endScale, 1.0); + this._startScale = defaultValue(options.scale, defaultValue(options.startScale, 1.0)); + this._endScale = defaultValue(options.scale, defaultValue(options.endScale, 1.0)); - this._rate = defaultValue(options.rate, 5); + this._emissionRate = defaultValue(options.emissionRate, 5); + if (defined(options.rate)) { + deprecationWarning('rate', 'rate was deprecated in Cesium 1.45. It will be removed in 1.46. Use emissionRate instead.'); + this._emissionRate = options.rate; + } this._minimumSpeed = defaultValue(options.speed, defaultValue(options.minimumSpeed, 1.0)); this._maximumSpeed = defaultValue(options.speed, defaultValue(options.maximumSpeed, 1.0)); @@ -132,13 +142,32 @@ define([ this._minimumMass = defaultValue(options.mass, defaultValue(options.minimumMass, 1.0)); this._maximumMass = defaultValue(options.mass, defaultValue(options.maximumMass, 1.0)); - this._minimumWidth = defaultValue(options.width, defaultValue(options.minimumWidth, 1.0)); - this._maximumWidth = defaultValue(options.width, defaultValue(options.maximumWidth, 1.0)); + this._minimumImageSize = defaultValue(options.imageSize, defaultValue(options.minimumImageSize, defaultImageSize)); + this._maximumImageSize = defaultValue(options.imageSize, defaultValue(options.minimumImageSize, defaultImageSize)); + if (defined(options.width) || defined(options.minimumWidth) || defined(options.maximumWidth) + || defined(options.height) || defined(options.minimumHeight) || defined(options.maximumHeight)) { - this._minimumHeight = defaultValue(options.height, defaultValue(options.minimumHeight, 1.0)); - this._maximumHeight = defaultValue(options.height, defaultValue(options.maximumHeight, 1.0)); + if (defined(options.width)) { + deprecationWarning('width', 'width was deprecated in Cesium 1.45. It will be removed in 1.46. Instead of width' + + ' and height components for pixel dimensions we switched to a Cartesian2. Use imageSize instead.'); + } + if (defined(options.height)) { + deprecationWarning('height', 'height was deprecated in Cesium 1.45. It will be removed in 1.46. Instead of width' + + ' and height components for pixel dimensions we switched to a Cartesian2. Use imageSize instead.'); + } + var minimumWidth = defaultValue(options.width, defaultValue(options.minimumWidth, 1.0)); + var maximumWidth = defaultValue(options.width, defaultValue(options.maximumWidth, 1.0)); + var minimumHeight = defaultValue(options.height, defaultValue(options.minimumHeight, 1.0)); + var maximumHeight = defaultValue(options.height, defaultValue(options.maximumHeight, 1.0)); + this._minimumImageSize = new Cartesian2(minimumWidth, minimumHeight); + this._maximumImageSize = new Cartesian2(maximumWidth, maximumHeight); + } - this._lifeTime = defaultValue(options.lifeTime, Number.MAX_VALUE); + this._lifetime = defaultValue(options.lifetime, Number.MAX_VALUE); + if (defined(options.lifeTime)) { + deprecationWarning('lifeTime', 'lifeTime was deprecated in Cesium 1.45. It will be removed in 1.46. Use lifetime instead.'); + this._lifetime = defaultValue(options.lifeTime, Number.MAX_VALUE); + } this._billboardCollection = undefined; this._particles = []; @@ -162,7 +191,7 @@ define([ * The particle emitter for this * @memberof ParticleSystem.prototype * @type {ParticleEmitter} - * @default CricleEmitter + * @default CircleEmitter */ emitter : { get : function() { @@ -298,16 +327,37 @@ define([ * @memberof ParticleSystem.prototype * @type {Number} * @default 5 + * @deprecated */ rate : { get : function() { - return this._rate; + deprecationWarning('rate', 'rate was deprecated in Cesium 1.45. It will be removed in 1.46. Use emissionRate instead.'); + return this._emissionRate; }, set : function(value) { + deprecationWarning('rate', 'rate was deprecated in Cesium 1.45. It will be removed in 1.46. Use emissionRate instead.'); //>>includeStart('debug', pragmas.debug); Check.typeOf.number.greaterThanOrEquals('value', value, 0.0); //>>includeEnd('debug'); - this._rate = value; + this._emissionRate = value; + this._updateParticlePool = true; + } + }, + /** + * The number of particles to emit per second. + * @memberof ParticleSystem.prototype + * @type {Number} + * @default 5 + */ + emissionRate : { + get : function() { + return this._emissionRate; + }, + set : function(value) { + //>>includeStart('debug', pragmas.debug); + Check.typeOf.number.greaterThanOrEquals('value', value, 0.0); + //>>includeEnd('debug'); + this._emissionRate = value; this._updateParticlePool = true; } }, @@ -329,7 +379,7 @@ define([ } }, /** - * Sets the maximum speed in meters per second. + * Sets the maximum velocity in meters per second. * @memberof ParticleSystem.prototype * @type {Number} * @default 1.0 @@ -419,16 +469,21 @@ define([ * @memberof ParticleSystem.prototype * @type {Number} * @default 1.0 + * @deprecated */ minimumWidth : { get : function() { - return this._minimumWidth; + deprecationWarning('width', 'width was deprecated in Cesium 1.45. It will be removed in 1.46. Instead of width' + + ' and height components for pixel dimensions we switched to a Cartesian2. Use imageSize instead.'); + return this._minimumImageSize.x; }, set : function(value) { + deprecationWarning('width', 'width was deprecated in Cesium 1.45. It will be removed in 1.46. Instead of width' + + ' and height components for pixel dimensions we switched to a Cartesian2. Use imageSize instead.'); //>>includeStart('debug', pragmas.debug); Check.typeOf.number.greaterThanOrEquals('value', value, 0.0); //>>includeEnd('debug'); - this._minimumWidth = value; + this.this._minimumImageSize.x = value; } }, /** @@ -436,16 +491,21 @@ define([ * @memberof ParticleSystem.prototype * @type {Number} * @default 1.0 + * @deprecated */ maximumWidth : { get : function() { - return this._maximumWidth; + deprecationWarning('width', 'width was deprecated in Cesium 1.45. It will be removed in 1.46. Instead of width' + + ' and height components for pixel dimensions we switched to a Cartesian2. Use imageSize instead.'); + return this._maximumImageSize.x; }, set : function(value) { + deprecationWarning('width', 'width was deprecated in Cesium 1.45. It will be removed in 1.46. Instead of width' + + ' and height components for pixel dimensions we switched to a Cartesian2. Use imageSize instead.'); //>>includeStart('debug', pragmas.debug); Check.typeOf.number.greaterThanOrEquals('value', value, 0.0); //>>includeEnd('debug'); - this._maximumWidth = value; + this._maximumImageSize.x = value; } }, /** @@ -453,16 +513,21 @@ define([ * @memberof ParticleSystem.prototype * @type {Number} * @default 1.0 + * @deprecated */ minimumHeight : { get : function() { - return this._minimumHeight; + deprecationWarning('height', 'height was deprecated in Cesium 1.45. It will be removed in 1.46. Instead of width' + + ' and height components for pixel dimensions we switched to a Cartesian2. Use imageSize instead.'); + return this._minimumImageSize.y; }, set : function(value) { + deprecationWarning('height', 'height was deprecated in Cesium 1.45. It will be removed in 1.46. Instead of width' + + ' and height components for pixel dimensions we switched to a Cartesian2. Use imageSize instead.'); //>>includeStart('debug', pragmas.debug); Check.typeOf.number.greaterThanOrEquals('value', value, 0.0); //>>includeEnd('debug'); - this._minimumHeight = value; + this._minimumImageSize.y = value; } }, /** @@ -470,16 +535,59 @@ define([ * @memberof ParticleSystem.prototype * @type {Number} * @default 1.0 + * @deprecated */ maximumHeight : { get : function() { - return this._maximumHeight; + deprecationWarning('height', 'height was deprecated in Cesium 1.45. It will be removed in 1.46. Instead of width' + + ' height components for pixel dimensions we switched to a Cartesian2. Use imageSize instead.'); + return this._maximumImageSize.y; }, set : function(value) { + deprecationWarning('height', 'height was deprecated in Cesium 1.45. It will be removed in 1.46. Instead of width' + + ' and height components for pixel dimensions we switched to a Cartesian2. Use imageSize instead.'); //>>includeStart('debug', pragmas.debug); Check.typeOf.number.greaterThanOrEquals('value', value, 0.0); //>>includeEnd('debug'); - this._maximumHeight = value; + this._maximumImageSize.y = value; + } + }, + /** + * Sets the maximum width and height of particles in pixels. + * @memberof ParticleSystem.prototype + * @type {Cartesian2} + * @default new Cartesian2(1.0, 1.0) + */ + minimumImageSize : { + get : function() { + return this._minimumImageSize; + }, + set : function(value) { + //>>includeStart('debug', pragmas.debug); + Check.typeOf.object('value', value); + Check.typeOf.number.greaterThanOrEquals('value.x', value.x, 0.0); + Check.typeOf.number.greaterThanOrEquals('value.y', value.y, 0.0); + //>>includeEnd('debug'); + this._minimumImageSize = value; + } + }, + /** + * Sets the maximum width and height of particles in pixels. + * @memberof ParticleSystem.prototype + * @type {Cartesian2} + * @default new Cartesian2(1.0, 1.0) + */ + maximumImageSize : { + get : function() { + return this._maximumImageSize; + }, + set : function(value) { + //>>includeStart('debug', pragmas.debug); + Check.typeOf.object('value', value); + Check.typeOf.number.greaterThanOrEquals('value.x', value.x, 0.0); + Check.typeOf.number.greaterThanOrEquals('value.y', value.y, 0.0); + //>>includeEnd('debug'); + this._maximumImageSize = value; } }, /** @@ -487,16 +595,36 @@ define([ * @memberof ParticleSystem.prototype * @type {Number} * @default Number.MAX_VALUE + * @deprecated */ lifeTime : { get : function() { - return this._lifeTime; + deprecationWarning('lifeTime', 'lifeTime was deprecated in Cesium 1.45. It will be removed in 1.46. Use lifetime instead.'); + return this._lifetime; }, set : function(value) { + deprecationWarning('lifeTime', 'lifeTime was deprecated in Cesium 1.45. It will be removed in 1.46. Use lifetime instead.'); //>>includeStart('debug', pragmas.debug); Check.typeOf.number.greaterThanOrEquals('value', value, 0.0); //>>includeEnd('debug'); - this._lifeTime = value; + this._lifetime = value; + } + }, + /** + * How long the particle system will emit particles, in seconds. + * @memberof ParticleSystem.prototype + * @type {Number} + * @default Number.MAX_VALUE + */ + lifetime : { + get : function() { + return this._lifetime; + }, + set : function(value) { + //>>includeStart('debug', pragmas.debug); + Check.typeOf.number.greaterThanOrEquals('value', value, 0.0); + //>>includeEnd('debug'); + this._lifetime = value; } }, /** @@ -522,7 +650,7 @@ define([ }); function updateParticlePool(system) { - var rate = system._rate; + var emissionRate = system._emissionRate; var life = system._maximumLife; var burstAmount = 0; @@ -537,7 +665,7 @@ define([ var billboardCollection = system._billboardCollection; var image = system.image; - var particleEstimate = Math.ceil(rate * life + burstAmount); + var particleEstimate = Math.ceil(emissionRate * life + burstAmount); var particles = system._particles; var particlePool = system._particlePool; var numToAdd = Math.max(particleEstimate - particles.length - particlePool.length, 0); @@ -597,8 +725,8 @@ define([ image : particle.image }); } - billboard.width = particle.size.x; - billboard.height = particle.size.y; + billboard.width = particle.imageSize.x; + billboard.height = particle.imageSize.y; billboard.position = particle.position; billboard.show = true; @@ -622,10 +750,8 @@ define([ particle.image = system.image; particle.life = CesiumMath.randomBetween(system._minimumLife, system._maximumLife); particle.mass = CesiumMath.randomBetween(system._minimumMass, system._maximumMass); - - var width = CesiumMath.randomBetween(system._minimumWidth, system._maximumWidth); - var height = CesiumMath.randomBetween(system._minimumHeight, system._maximumHeight); - particle.size = Cartesian2.fromElements(width, height, particle.size); + particle.imageSize.x = CesiumMath.randomBetween(system._minimumImageSize.x, system._maximumImageSize.x); + particle.imageSize.y = CesiumMath.randomBetween(system._minimumImageSize.y, system._maximumImageSize.y); // Reset the normalizedAge and age in case the particle was reused. particle._normalizedAge = 0.0; @@ -643,10 +769,10 @@ define([ return 0; } - dt = CesiumMath.mod(dt, system._lifeTime); + dt = CesiumMath.mod(dt, system._lifetime); - // Compute the number of particles to emit based on the rate. - var v = dt * system._rate; + // Compute the number of particles to emit based on the emissionRate. + var v = dt * system._emissionRate; var numToEmit = Math.floor(v); system._carryOver += (v - numToEmit); if (system._carryOver > 1.0) @@ -702,7 +828,7 @@ define([ var particles = this._particles; var emitter = this._emitter; - var forces = this.forces; + var updateParticle = this.updateParticle; var i; var particle; @@ -711,7 +837,7 @@ define([ var length = particles.length; for (i = 0; i < length; ++i) { particle = particles[i]; - if (!particle.update(dt, forces)) { + if (!particle.update(dt, updateParticle)) { removeBillboard(particle); // Add the particle back to the pool so it can be reused. addParticleToPool(this, particle); @@ -763,9 +889,9 @@ define([ this._previousTime = JulianDate.clone(frameState.time, this._previousTime); this._currentTime += dt; - if (this._lifeTime !== Number.MAX_VALUE && this._currentTime > this._lifeTime) { + if (this._lifetime !== Number.MAX_VALUE && this._currentTime > this._lifetime) { if (this.loop) { - this._currentTime = CesiumMath.mod(this._currentTime, this._lifeTime); + this._currentTime = CesiumMath.mod(this._currentTime, this._lifetime); if (this.bursts) { var burstLength = this.bursts.length; // Reset any bursts @@ -817,10 +943,11 @@ define([ }; /** - * A function used to apply a force to the particle on each time step. - * @callback ParticleSystem~applyForce + * A function used to modify attributes of the particle at each time step. This can include force modifications, + * color, sizing, etc. + * @callback ParticleSystem~updateParticle * - * @param {Particle} particle The particle to apply the force to. + * @param {Particle} particle The particle being updated. * @param {Number} dt The time since the last update. * * @example From f2e7261a205df03fdd7a483944fdcbe35ca26d38 Mon Sep 17 00:00:00 2001 From: hanbollar Date: Thu, 5 Apr 2018 16:32:51 -0400 Subject: [PATCH 2/6] updated spec for name changes --- Source/Scene/ParticleSystem.js | 4 +- Specs/Scene/ParticleSpec.js | 13 +++--- Specs/Scene/ParticleSystemSpec.js | 68 ++++++++++++++----------------- 3 files changed, 37 insertions(+), 48 deletions(-) diff --git a/Source/Scene/ParticleSystem.js b/Source/Scene/ParticleSystem.js index 7c878c404eb2..4f2339e020c8 100644 --- a/Source/Scene/ParticleSystem.js +++ b/Source/Scene/ParticleSystem.js @@ -143,7 +143,7 @@ define([ this._maximumMass = defaultValue(options.mass, defaultValue(options.maximumMass, 1.0)); this._minimumImageSize = defaultValue(options.imageSize, defaultValue(options.minimumImageSize, defaultImageSize)); - this._maximumImageSize = defaultValue(options.imageSize, defaultValue(options.minimumImageSize, defaultImageSize)); + this._maximumImageSize = defaultValue(options.imageSize, defaultValue(options.maximumImageSize, defaultImageSize)); if (defined(options.width) || defined(options.minimumWidth) || defined(options.maximumWidth) || defined(options.height) || defined(options.minimumHeight) || defined(options.maximumHeight)) { @@ -483,7 +483,7 @@ define([ //>>includeStart('debug', pragmas.debug); Check.typeOf.number.greaterThanOrEquals('value', value, 0.0); //>>includeEnd('debug'); - this.this._minimumImageSize.x = value; + this._minimumImageSize.x = value; } }, /** diff --git a/Specs/Scene/ParticleSpec.js b/Specs/Scene/ParticleSpec.js index 5353c5fec733..a3b44db55e6e 100644 --- a/Specs/Scene/ParticleSpec.js +++ b/Specs/Scene/ParticleSpec.js @@ -21,7 +21,7 @@ defineSuite([ expect(p.endColor).toEqual(Color.WHITE); expect(p.startScale).toEqual(1.0); expect(p.endScale).toEqual(1.0); - expect(p.size).toEqual(new Cartesian2(1.0, 1.0)); + expect(p.imageSize).toEqual(new Cartesian2(1.0, 1.0)); }); it('constructor', function() { @@ -35,7 +35,7 @@ defineSuite([ endColor : Color.LIME, startScale : 0.5, endScale : 20.0, - size : new Cartesian2(7.0, 8.0) + imageSize : new Cartesian2(7.0, 8.0) }; var p = new Particle(options); expect(p.mass).toEqual(options.mass); @@ -47,7 +47,7 @@ defineSuite([ expect(p.endColor).toEqual(options.endColor); expect(p.startScale).toEqual(options.startScale); expect(p.endScale).toEqual(options.endScale); - expect(p.size).toEqual(options.size); + expect(p.imageSize).toEqual(options.imageSize); }); it('update without forces', function() { @@ -71,13 +71,10 @@ defineSuite([ }); it('update with forces', function() { - var times2 = function(particle, dt) { - Cartesian3.add(particle.position, Cartesian3.multiplyByScalar(particle.velocity, dt, new Cartesian3()), particle.position); - }; var increaseMass = function(particle, dt) { particle.mass++; }; - var forces = [times2, increaseMass]; + var forces = increaseMass; var position = new Cartesian3(1.0, 2.0, 3.0); var velocity = Cartesian3.normalize(new Cartesian3(-1.0, 1.0, 1.0), new Cartesian3()); @@ -88,8 +85,8 @@ defineSuite([ }); var dt = 10.0; - var expectedPosition = Cartesian3.add(p.position, Cartesian3.multiplyByScalar(p.velocity, 2.0 * dt, new Cartesian3()), new Cartesian3()); var expectedMass = p.mass + 1; + var expectedPosition = Cartesian3.add(p.position, Cartesian3.multiplyByScalar(p.velocity, dt, new Cartesian3()), new Cartesian3()); expect(p.update(dt, forces)).toEqual(true); expect(p.position).toEqual(expectedPosition); diff --git a/Specs/Scene/ParticleSystemSpec.js b/Specs/Scene/ParticleSystemSpec.js index f772e51fd666..745933f07c97 100644 --- a/Specs/Scene/ParticleSystemSpec.js +++ b/Specs/Scene/ParticleSystemSpec.js @@ -1,5 +1,6 @@ defineSuite([ 'Scene/ParticleSystem', + 'Core/Cartesian2', 'Core/Cartesian3', 'Core/Color', 'Core/Matrix4', @@ -9,6 +10,7 @@ defineSuite([ 'Specs/createScene' ], function( ParticleSystem, + Cartesian2, Cartesian3, Color, Matrix4, @@ -43,7 +45,7 @@ defineSuite([ expect(p.endColor).toEqual(Color.WHITE); expect(p.startScale).toEqual(1.0); expect(p.endScale).toEqual(1.0); - expect(p.rate).toEqual(5.0); + expect(p.emissionRate).toEqual(5.0); expect(p.bursts).toBeUndefined(); expect(p.loop).toEqual(true); expect(p.minimumSpeed).toEqual(1.0); @@ -53,11 +55,11 @@ defineSuite([ expect(p.minimumMass).toEqual(1.0); expect(p.maximumMass).toEqual(1.0); expect(p.image).toBeUndefined(); - expect(p.minimumWidth).toEqual(1.0); - expect(p.maximumWidth).toEqual(1.0); - expect(p.minimumHeight).toEqual(1.0); - expect(p.maximumHeight).toEqual(1.0); - expect(p.lifeTime).toEqual(Number.MAX_VALUE); + expect(p.minimumImageSize.x).toEqual(1.0); + expect(p.minimumImageSize.y).toEqual(1.0); + expect(p.maximumImageSize.x).toEqual(1.0); + expect(p.maximumImageSize.y).toEqual(1.0); + expect(p.lifetime).toEqual(Number.MAX_VALUE); expect(p.complete).toBeDefined(); expect(p.isComplete).toEqual(false); }); @@ -65,7 +67,7 @@ defineSuite([ it('constructor', function() { var options = { show : false, - forces : [function(p) { p.mass++; }], + updateParticle : (function(p) { p.mass++; }), emitter : new CircleEmitter(10.0), modelMatrix : new Matrix4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0), emitterModelMatrix : new Matrix4(10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0), @@ -73,7 +75,7 @@ defineSuite([ endColor : Color.LAVENDAR_BLUSH, startScale : 19.0, endScale : 20.0, - rate : 21.0, + emissionRate : 21.0, bursts : [new ParticleBurst()], loop : false, minimumSpeed : 22.0, @@ -83,15 +85,13 @@ defineSuite([ minimumMass : 26.0, maximumMass : 27.0, image : 'url/to/image', - minimumWidth : 28.0, - maximumWidth : 29.0, - minimumHeight : 30.0, - maximumHeight : 31.0, - lifeTime : 32.0 + minimumImageSize : new Cartesian2(28.0, 30.0), + maximumImageSize : new Cartesian2(29.0, 31.0), + lifetime : 32.0 }; var p = new ParticleSystem(options); expect(p.show).toEqual(options.show); - expect(p.forces).toEqual(options.forces); + expect(p.updateParticle).toEqual(options.updateParticle); expect(p.emitter).toEqual(options.emitter); expect(p.modelMatrix).toEqual(options.modelMatrix); expect(p.emitterModelMatrix).toEqual(options.emitterModelMatrix); @@ -99,7 +99,7 @@ defineSuite([ expect(p.endColor).toEqual(options.endColor); expect(p.startScale).toEqual(options.startScale); expect(p.endScale).toEqual(options.endScale); - expect(p.rate).toEqual(options.rate); + expect(p.emissionRate).toEqual(options.emissionRate); expect(p.bursts).toEqual(options.bursts); expect(p.loop).toEqual(options.loop); expect(p.minimumSpeed).toEqual(options.minimumSpeed); @@ -109,11 +109,9 @@ defineSuite([ expect(p.minimumMass).toEqual(options.minimumMass); expect(p.maximumMass).toEqual(options.maximumMass); expect(p.image).toEqual(options.image); - expect(p.minimumWidth).toEqual(options.minimumWidth); - expect(p.maximumWidth).toEqual(options.maximumWidth); - expect(p.minimumHeight).toEqual(options.minimumHeight); - expect(p.maximumHeight).toEqual(options.maximumHeight); - expect(p.lifeTime).toEqual(options.lifeTime); + expect(p.minimumImageSize).toEqual(options.minimumImageSize); + expect(p.maximumImageSize).toEqual(options.maximumImageSize); + expect(p.lifetime).toEqual(options.lifetime); expect(p.complete).toBeDefined(); expect(p.isComplete).toEqual(false); }); @@ -128,7 +126,7 @@ defineSuite([ var endColor = Color.LAVENDAR_BLUSH; var startScale = 19.0; var endScale = 20.0; - var rate = 21.0; + var emissionRate = 21.0; var bursts = [new ParticleBurst()]; var loop = false; var minimumSpeed = 22.0; @@ -138,11 +136,9 @@ defineSuite([ var minimumMass = 26.0; var maximumMass = 27.0; var image = 'url/to/image'; - var minimumWidth = 28.0; - var maximumWidth = 29.0; - var minimumHeight = 30.0; - var maximumHeight = 31.0; - var lifeTime = 32.0; + var minimumImageSize = new Cartesian2(28.0, 30.0); + var maximumImageSize = new Cartesian2(29.0, 31.0); + var lifetime = 32.0; var p = new ParticleSystem(); p.show = show; @@ -154,7 +150,7 @@ defineSuite([ p.endColor = endColor; p.startScale = startScale; p.endScale = endScale; - p.rate = rate; + p.emissionRate = emissionRate; p.bursts = bursts; p.loop = loop; p.minimumSpeed = minimumSpeed; @@ -164,11 +160,9 @@ defineSuite([ p.minimumMass = minimumMass; p.maximumMass = maximumMass; p.image = image; - p.minimumWidth = minimumWidth; - p.maximumWidth = maximumWidth; - p.minimumHeight = minimumHeight; - p.maximumHeight = maximumHeight; - p.lifeTime = lifeTime; + p.minimumImageSize = Cartesian2.clone(minimumImageSize, new Cartesian2()); + p.maximumImageSize = Cartesian2.clone(maximumImageSize, new Cartesian2()); + p.lifetime = lifetime; expect(p.show).toEqual(show); expect(p.forces).toEqual(forces); @@ -179,7 +173,7 @@ defineSuite([ expect(p.endColor).toEqual(endColor); expect(p.startScale).toEqual(startScale); expect(p.endScale).toEqual(endScale); - expect(p.rate).toEqual(rate); + expect(p.emissionRate).toEqual(emissionRate); expect(p.bursts).toEqual(bursts); expect(p.loop).toEqual(loop); expect(p.minimumSpeed).toEqual(minimumSpeed); @@ -189,11 +183,9 @@ defineSuite([ expect(p.minimumMass).toEqual(minimumMass); expect(p.maximumMass).toEqual(maximumMass); expect(p.image).toEqual(image); - expect(p.minimumWidth).toEqual(minimumWidth); - expect(p.maximumWidth).toEqual(maximumWidth); - expect(p.minimumHeight).toEqual(minimumHeight); - expect(p.maximumHeight).toEqual(maximumHeight); - expect(p.lifeTime).toEqual(lifeTime); + expect(p.minimumImageSize).toEqual(minimumImageSize); + expect(p.maximumImageSize).toEqual(maximumImageSize); + expect(p.lifetime).toEqual(lifetime); expect(p.complete).toBeDefined(); expect(p.isComplete).toEqual(false); }); From 85bcece9fe9ba16768e39d744f9a31743da48e4a Mon Sep 17 00:00:00 2001 From: hanbollar Date: Thu, 5 Apr 2018 17:02:51 -0400 Subject: [PATCH 3/6] updated Changes.md --- CHANGES.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 7e22c39a0be0..074dac8b0887 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,22 @@ Change Log * Allow loadWithXhr to work with string URLs in a web worker. * Fix Firefox WebGL console warnings. [#5912](https://github.com/AnalyticalGraphicsInc/cesium/issues/5912) +##### Deprecated :hourglass_flowing_sand: +* `Particle.size` has been renamed to `Particle.imageSize`. Use of the `size` parameter is deprecated and will be removed in Cesium 1.46. +* `ParticleSystem.rate` has been renamed to `ParticleSystem.emissionRate`. Use of the `rate` parameter is deprecated and will be removed in Cesium 1.46. +* `ParticleSystem.forces` array has been switched out for singular function `ParticleSystems.updateParticle`. Use of the `forces` parameter is deprecated and will be removed in Cesium 1.46. +* `ParticleSystem.lifeTime` has been renamed to `ParticleSystem.lifetime`. Use of the `lifeTime` parameter is deprecated and will be removed in Cesium 1.46. +* `ParticleSystem.minimumWidth` will no longer be an individual component. Instead of width and height components for pixel dimensions we switched to the Cartesian2, minimumImageSize, instead. Use of the `minimumWidth` parameter is deprecated and will be removed in Cesium 1.46. +* `ParticleSystem.minimumHeight` will no longer be an individual component. Instead of width and height components for pixel dimensions we switched to the Cartesian2, minimumImageSize, instead. Use of the `minimumHeight` parameter is deprecated and will be removed in Cesium 1.46. +* `ParticleSystem.maximumWidth` will no longer be an individual component. Instead of width and height components for pixel dimensions we switched to the Cartesian2, maximumImageSize, instead. Use of the `maximumWidth` parameter is deprecated and will be removed in Cesium 1.46. +* `ParticleSystem.maximumHeight` will no longer be an individual component. Instead of width and height components for pixel dimensions we switched to the Cartesian2, maximumImageSize, instead. Use of the `maximumHeight` parameter is deprecated and will be removed in Cesium 1.46. + +##### Additions :tada: +* Added color attribute to the `Particle` class constructor that when defined sets both start and endColor. [#6429](https://github.com/AnalyticalGraphicsInc/cesium/pull/6429) +* Added scale attribute to the `Particle` class constructor that when defined sets both start and endColor. [#6429](https://github.com/AnalyticalGraphicsInc/cesium/pull/6429) +* Added color attribute to the `ParticleSystem` class constructor that when defined sets both start and endColor. [#6429](https://github.com/AnalyticalGraphicsInc/cesium/pull/6429) +* Added scale attribute to the `ParticleSystem` class constructor that when defined sets both start and endScale. [#6429](https://github.com/AnalyticalGraphicsInc/cesium/pull/6429) + ### 1.44 - 2018-04-02 ##### Highlights :sparkler: From fc2c0e521d6921b8b405f7274b34db3947f14bd3 Mon Sep 17 00:00:00 2001 From: hanbollar Date: Thu, 5 Apr 2018 17:11:25 -0400 Subject: [PATCH 4/6] renamed updateParticle to updateCallback --- CHANGES.md | 2 +- Source/Scene/ParticleSystem.js | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 074dac8b0887..f0da48bb63ba 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,7 +13,7 @@ Change Log ##### Deprecated :hourglass_flowing_sand: * `Particle.size` has been renamed to `Particle.imageSize`. Use of the `size` parameter is deprecated and will be removed in Cesium 1.46. * `ParticleSystem.rate` has been renamed to `ParticleSystem.emissionRate`. Use of the `rate` parameter is deprecated and will be removed in Cesium 1.46. -* `ParticleSystem.forces` array has been switched out for singular function `ParticleSystems.updateParticle`. Use of the `forces` parameter is deprecated and will be removed in Cesium 1.46. +* `ParticleSystem.forces` array has been switched out for singular function `ParticleSystems.updateCallback`. Use of the `forces` parameter is deprecated and will be removed in Cesium 1.46. * `ParticleSystem.lifeTime` has been renamed to `ParticleSystem.lifetime`. Use of the `lifeTime` parameter is deprecated and will be removed in Cesium 1.46. * `ParticleSystem.minimumWidth` will no longer be an individual component. Instead of width and height components for pixel dimensions we switched to the Cartesian2, minimumImageSize, instead. Use of the `minimumWidth` parameter is deprecated and will be removed in Cesium 1.46. * `ParticleSystem.minimumHeight` will no longer be an individual component. Instead of width and height components for pixel dimensions we switched to the Cartesian2, minimumImageSize, instead. Use of the `minimumHeight` parameter is deprecated and will be removed in Cesium 1.46. diff --git a/Source/Scene/ParticleSystem.js b/Source/Scene/ParticleSystem.js index 4f2339e020c8..df5e728a5e8a 100644 --- a/Source/Scene/ParticleSystem.js +++ b/Source/Scene/ParticleSystem.js @@ -44,7 +44,7 @@ define([ * * @param {Object} [options] Object with the following properties: * @param {Boolean} [options.show=true] Whether to display the particle system. - * @param {ParticleSystem~updateParticle} [options.updateParticle] The callback to an update function used for every particle in this system. + * @param {ParticleSystem~updateCallback} [options.updateCallback] The callback to an update function used for every particle in this system. * @param {ParticleEmitter} [options.emitter=new CircleEmitter(0.5)] The particle emitter for this system. * @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] The 4x4 transformation matrix that transforms the particle system from model to world coordinates. * @param {Matrix4} [options.emitterModelMatrix=Matrix4.IDENTITY] The 4x4 transformation matrix that transforms the particle system emitter within the particle systems local coordinate system. @@ -86,13 +86,13 @@ define([ /** * An array of force callbacks. The callback is passed a {@link Particle} and the difference from the last time - * @type {ParticleSystem~updateParticle} + * @type {ParticleSystem~updateCallback} * @default undefined */ - this.updateParticle = options.updateParticle; + this.updateCallback = options.updateCallback; if (defined(options.forces)) { - deprecationWarning('forces', 'forces was deprecated in Cesium 1.45. It will be removed in 1.46. Use updateParticle instead.'); - this.updateParticle = options.forces[0]; + deprecationWarning('forces', 'forces was deprecated in Cesium 1.45. It will be removed in 1.46. Use updateCallback instead.'); + this.updateCallback = options.forces[0]; } /** * Whether the particle system should loop it's bursts when it is complete. @@ -828,7 +828,7 @@ define([ var particles = this._particles; var emitter = this._emitter; - var updateParticle = this.updateParticle; + var updateCallback = this.updateCallback; var i; var particle; @@ -837,7 +837,7 @@ define([ var length = particles.length; for (i = 0; i < length; ++i) { particle = particles[i]; - if (!particle.update(dt, updateParticle)) { + if (!particle.update(dt, updateCallback)) { removeBillboard(particle); // Add the particle back to the pool so it can be reused. addParticleToPool(this, particle); @@ -945,7 +945,7 @@ define([ /** * A function used to modify attributes of the particle at each time step. This can include force modifications, * color, sizing, etc. - * @callback ParticleSystem~updateParticle + * @callback ParticleSystem~updateCallback * * @param {Particle} particle The particle being updated. * @param {Number} dt The time since the last update. From 3bf7697b74f53bfeb3b913a248ffb3077e51f33b Mon Sep 17 00:00:00 2001 From: hanbollar Date: Fri, 6 Apr 2018 16:43:17 -0400 Subject: [PATCH 5/6] updated deprecations and renames and included them back into the doc. current issue is fireworks example is slightly wrong with this implementation. need to figure out why --- CHANGES.md | 15 +-- Source/Scene/Particle.js | 44 +++++-- Source/Scene/ParticleSystem.js | 186 ++++++++++++++++++++++-------- Specs/Scene/ParticleSpec.js | 30 +++++ Specs/Scene/ParticleSystemSpec.js | 36 +++--- 5 files changed, 222 insertions(+), 89 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f0da48bb63ba..88fa265dfe02 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,20 +11,13 @@ Change Log * Fix Firefox WebGL console warnings. [#5912](https://github.com/AnalyticalGraphicsInc/cesium/issues/5912) ##### Deprecated :hourglass_flowing_sand: -* `Particle.size` has been renamed to `Particle.imageSize`. Use of the `size` parameter is deprecated and will be removed in Cesium 1.46. -* `ParticleSystem.rate` has been renamed to `ParticleSystem.emissionRate`. Use of the `rate` parameter is deprecated and will be removed in Cesium 1.46. +* `Particle.size`, `ParticleSystem.rate`, `ParticleSystem.lifeTime` have been renamed to `Particle.imageSize`, `ParticleSystem.emissionRate`, and `ParticleSystem.lifetime`. Use of the `size`, `rate`, and `lifeTime` parameters is deprecated and will be removed in Cesium 1.46. +* `ParticleSystem.life`, `ParticleSystem.minimumLife`, and `ParticleSystem.maximumLife` have been renamed to `ParticleSystem.particleLife`, `ParticleSystem.minimumParticleLife`, and `ParticleSystem.maximumParticleLife`. Use of the `life`, `minimumLife`, and `maximumLife` parameters is deprecated and will be removed in Cesium 1.46. * `ParticleSystem.forces` array has been switched out for singular function `ParticleSystems.updateCallback`. Use of the `forces` parameter is deprecated and will be removed in Cesium 1.46. -* `ParticleSystem.lifeTime` has been renamed to `ParticleSystem.lifetime`. Use of the `lifeTime` parameter is deprecated and will be removed in Cesium 1.46. -* `ParticleSystem.minimumWidth` will no longer be an individual component. Instead of width and height components for pixel dimensions we switched to the Cartesian2, minimumImageSize, instead. Use of the `minimumWidth` parameter is deprecated and will be removed in Cesium 1.46. -* `ParticleSystem.minimumHeight` will no longer be an individual component. Instead of width and height components for pixel dimensions we switched to the Cartesian2, minimumImageSize, instead. Use of the `minimumHeight` parameter is deprecated and will be removed in Cesium 1.46. -* `ParticleSystem.maximumWidth` will no longer be an individual component. Instead of width and height components for pixel dimensions we switched to the Cartesian2, maximumImageSize, instead. Use of the `maximumWidth` parameter is deprecated and will be removed in Cesium 1.46. -* `ParticleSystem.maximumHeight` will no longer be an individual component. Instead of width and height components for pixel dimensions we switched to the Cartesian2, maximumImageSize, instead. Use of the `maximumHeight` parameter is deprecated and will be removed in Cesium 1.46. +* Any width and height variables in `ParticleSystem` will no longer be individual components. `ParticleSystem.minimumWidth` and `ParticleSystem.minimumHeight` will now be `ParticleSystem.minimumImageSize`, `ParticleSystem.maximumWidth` and `ParticleSystem.maximumHeight` will now be `ParticleSystem.maximumImageSize`, and `ParticleSystem.width` and `ParticleSystem.height` will now be `ParticleSystem.imageSize`. Use of the `minimumWidth`, `minimumHeight`, `maximumWidth`, `maximumHeight`, `width`, and `height` parameters is deprecated and will be removed in Cesium 1.46. ##### Additions :tada: -* Added color attribute to the `Particle` class constructor that when defined sets both start and endColor. [#6429](https://github.com/AnalyticalGraphicsInc/cesium/pull/6429) -* Added scale attribute to the `Particle` class constructor that when defined sets both start and endColor. [#6429](https://github.com/AnalyticalGraphicsInc/cesium/pull/6429) -* Added color attribute to the `ParticleSystem` class constructor that when defined sets both start and endColor. [#6429](https://github.com/AnalyticalGraphicsInc/cesium/pull/6429) -* Added scale attribute to the `ParticleSystem` class constructor that when defined sets both start and endScale. [#6429](https://github.com/AnalyticalGraphicsInc/cesium/pull/6429) +* Added color and scale attributes to the `ParticleSystem` class constructor. When defined the variables override startColor and endColor and startScale and endScale. [#6429](https://github.com/AnalyticalGraphicsInc/cesium/pull/6429) ### 1.44 - 2018-04-02 diff --git a/Source/Scene/Particle.js b/Source/Scene/Particle.js index a61869ad0650..33b07080cfea 100644 --- a/Source/Scene/Particle.js +++ b/Source/Scene/Particle.js @@ -25,17 +25,16 @@ define([ * @constructor * * @param {Object} options An object with the following properties: - * @param {Number} [options.mass=1.0] The mass of particles in kilograms. + * @param {Number} [options.mass=1.0] The mass of the particle in kilograms. * @param {Cartesian3} [options.position=Cartesian3.ZERO] The initial position of the particle in world coordinates. * @param {Cartesian3} [options.velocity=Cartesian3.ZERO] The velocity vector of the particle in world coordinates. * @param {Number} [options.life=Number.MAX_VALUE] The life of the particle in seconds. * @param {Object} [options.image] The URI, HTMLImageElement, or HTMLCanvasElement to use for the billboard. - * @param {Object} [options.color] Sets the start and end colors. * @param {Color} [options.startColor=Color.WHITE] The color of a particle when it is born. * @param {Color} [options.endColor=Color.WHITE] The color of a particle when it dies. - * @param {Object} [options.scale] Sets the start and end scales. * @param {Number} [options.startScale=1.0] The scale of the particle when it is born. * @param {Number} [options.endScale=1.0] The scale of the particle when it dies. + * @param {Cartesian2} [options.size=new Cartesian2(1.0, 1.0)] The dimensions of particles in pixels. This has been deprecated. Use imageSize instead. * @param {Cartesian2} [options.imageSize=new Cartesian2(1.0, 1.0)] The dimensions of the image representing the particle in pixels. Width by Height. */ function Particle(options) { @@ -76,25 +75,25 @@ define([ * @type {Color} * @default Color.WHITE */ - this.startColor = Color.clone(defaultValue(options.color, defaultValue(options.startColor, Color.WHITE))); + this.startColor = Color.clone(defaultValue(options.startColor, Color.WHITE)); /** * The color of the particle when it dies. * @type {Color} * @default Color.WHITE */ - this.endColor = Color.clone(defaultValue(options.color, defaultValue(options.endColor, Color.WHITE))); + this.endColor = Color.clone(defaultValue(options.endColor, Color.WHITE)); /** * the scale of the particle when it is born. * @type {Number} * @default 1.0 */ - this.startScale = defaultValue(options.scale, defaultValue(options.startScale, 1.0)); + this.startScale = defaultValue(options.startScale, 1.0); /** * The scale of the particle when it dies. * @type {Number} * @default 1.0 */ - this.endScale = defaultValue(options.scale, defaultValue(options.endScale, 1.0)); + this.endScale = defaultValue(options.endScale, 1.0); /** * The dimensions of the image representing the particle in pixels. Width by Height. * @type {Cartesian2} @@ -133,6 +132,22 @@ define([ get : function() { return this._normalizedAge; } + }, + /** + * The dimensions of the particle in pixels. This has been deprecated. Use {@link Particle#imageSize} instead. + * @type {Cartesian2} + * @default new Cartesian(1.0, 1.0) + * @deprecated + */ + size : { + get : function() { + deprecationWarning('size', 'size was deprecated in Cesium 1.45. It will be removed in 1.46. Use imageSize instead.'); + return this.imageSize; + }, + set : function(value) { + deprecationWarning('size', 'size was deprecated in Cesium 1.45. It will be removed in 1.46. Use imageSize instead.'); + this.imageSize = value; + } } }); @@ -147,8 +162,19 @@ define([ Cartesian3.add(this.position, deltaScratch, this.position); // Update any forces. - if (defined(particleUpdateFunction) && typeof particleUpdateFunction === 'function') { - particleUpdateFunction(this, dt); + if (defined(particleUpdateFunction)) { + if (typeof particleUpdateFunction === 'function') { + particleUpdateFunction(this, dt); + } else if (particleUpdateFunction instanceof Array) { + var length = particleUpdateFunction.length; + for (var i = 0; i < length; ++i) { + var force = particleUpdateFunction[i]; + if (typeof force === 'function') { + // Force is just a simple callback function. + force(this, dt); + } + } + } } // Age the particle diff --git a/Source/Scene/ParticleSystem.js b/Source/Scene/ParticleSystem.js index df5e728a5e8a..1c104c6d6a6a 100644 --- a/Source/Scene/ParticleSystem.js +++ b/Source/Scene/ParticleSystem.js @@ -44,34 +44,46 @@ define([ * * @param {Object} [options] Object with the following properties: * @param {Boolean} [options.show=true] Whether to display the particle system. + * @param {ParticleSystem~applyForce[]} [options.forces] An array of force callbacks. This has been deprecated. Use updateCallback instead. * @param {ParticleSystem~updateCallback} [options.updateCallback] The callback to an update function used for every particle in this system. * @param {ParticleEmitter} [options.emitter=new CircleEmitter(0.5)] The particle emitter for this system. * @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] The 4x4 transformation matrix that transforms the particle system from model to world coordinates. * @param {Matrix4} [options.emitterModelMatrix=Matrix4.IDENTITY] The 4x4 transformation matrix that transforms the particle system emitter within the particle systems local coordinate system. + * @param {Number} [options.rate = 5] The number of particles to emit per second. This has been deprecated. Use emissionRate instead. * @param {Number} [options.emissionRate=5] The number of particles to emit per second. * @param {ParticleBurst[]} [options.bursts] An array of {@link ParticleBurst}, emitting bursts of particles at periodic times. * @param {Boolean} [options.loop=true] Whether the particle system should loop it's bursts when it is complete. - * @param {Number} [options.scale] Sets the start and end scales. - * @param {Number} [options.startScale=1.0] The scale of the particle when it is born. - * @param {Number} [options.endScale=1.0] The scale of the particle when it dies. - * @param {Color} [options.color] Sets the start and end colors. - * @param {Color} [options.startColor=Color.WHITE] The color of a particle when it is born. - * @param {Color} [options.endColor=Color.WHITE] The color of a particle when it dies. + * @param {Number} [options.scale=1.0] Sets the start and end scales. + * @param {Number} [options.startScale] The scale of the particle when it is born. + * @param {Number} [options.endScale] The scale of the particle when it dies. + * @param {Color} [options.color=Color.WHITE] Sets the start and end colors. + * @param {Color} [options.startColor] The color of a particle when it is born. + * @param {Color} [options.endColor] The color of a particle when it dies. * @param {Object} [options.image] The URI, HTMLImageElement, or HTMLCanvasElement to use for the billboard. - * @param {Cartesian2} [options.imageSize] Sets the maximum and minimum dimensions of the image representing the particle in pixels. Width by Height. - * @param {Cartesian2} [options.minimumImageSize=new Cartesian2(1.0, 1.0)] Sets the minimum dimensions of the image representing the particle in pixels. Width by Height. - * @param {Cartesian2} [options.maximumImageSize=new Cartesian2(1.0, 1.0)] Sets the maximum dimensions of the image representing the particle in pixels. Width by Height. - * @param {Number} [options.speed] Sets the minimum and maximum speed in meters per second. - * @param {Number} [options.minimumSpeed=1.0] Sets the minimum speed in meters per second. - * @param {Number} [options.maximumSpeed=1.0] Sets the maximum speed in meters per second. + * @param {Number} [options.width=1.0] Sets the minimum and maximum width of particles in pixels. This has been deprecated. Use imageSize's x component instead. + * @param {Number} [options.minimumWidth] Sets the minimum width of particles in pixels. This has been deprecated. Use minimumImageSize's x component instead. + * @param {Number} [options.maximumWidth] Sets the maximum width of particles in pixels. This has been deprecated. Use maximumImageSize's x component instead. + * @param {Number} [options.height=1.0] Overwrites the minimum and maximum height of particles in pixels. This has been deprecated. Use imageSize's y component instead. + * @param {Number} [options.minimumHeight] Sets the minimum height of particles in pixels. This has been deprecated. Use minimumImageSize's y component instead. + * @param {Number} [options.maximumHeight] Sets the maximum height of particles in pixels. This has been deprecated. Use maximumImageSize's y component instead. + * @param {Cartesian2} [options.imageSize=new Cartesian2(1.0, 1.0)] If set, overrides the minimumImageSize and maximumImageSize inputs with this value. + * @param {Cartesian2} [options.minimumImageSize] Sets the minimum dimensions of the image representing the particle in pixels. Width by Height. + * @param {Cartesian2} [options.maximumImageSize] Sets the maximum dimensions of the image representing the particle in pixels. Width by Height. + * @param {Number} [options.speed=1.0] If set, overrides the minimumSpeed and maximumSpeed inputs with this value. + * @param {Number} [options.minimumSpeed] Sets the minimum speed in meters per second. + * @param {Number} [options.maximumSpeed] Sets the maximum speed in meters per second. + * @param {Number} [options.lifeTime=Number.MAX_VALUE] How long the particle system will emit particles, in seconds. This has been deprecated. Use lifetime instead. * @param {Number} [options.lifetime=Number.MAX_VALUE] How long the particle system will emit particles, in seconds. - * @param {Number} [options.life] Sets the minimum and maximum life of particles in seconds. - * @param {Number} [options.minimumLife=5.0] Sets the minimum life of particles in seconds. - * @param {Number} [options.maximumLife=5.0] Sets the maximum life of particles in seconds. - * @param {Number} [options.mass] Sets the minimum and maximum mass of particles in kilograms. - * @param {Number} [options.minimumMass=1.0] Sets the minimum mass of particles in kilograms. - * @param {Number} [options.maximumMass=1.0] Sets the maximum mass of particles in kilograms. - * @demo {@link https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=Particle%20System.html&label=Showcases|Particle Systems Plane Demo} + * @param {Number} [options.life=5.0] If set, overrides the minimumLife and maximumLife inputs with this value. This has been deprecated. Use particleLife instead. + * @param {Number} [options.minimumLife] Sets the minimum life of particles in seconds. This has been deprecated. Use minimumParticleLife instead. + * @param {Number} [options.maximumLife] Sets the maximum life of particles in seconds. This has been deprecated. Use maximumParticleLife instead. + * @param {Number} [options.particleLife=5.0] If set, overrides the minimumParticleLife and maximumParticleLife inputs with this value. + * @param {Number} [options.minimumParticleLife] Sets the minimum life of particles in seconds. + * @param {Number} [options.maximumParticleLife] Sets the maximum life of particles in seconds. + * @param {Number} [options.mass=1.0] Sets the minimum and maximum mass of particles in kilograms. + * @param {Number} [options.minimumMass] Sets the minimum mass of particles in kilograms. + * @param {Number} [options.maximumMass] Sets the maximum mass of particles in kilograms. + * @demo {@link https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=Particle%20System.html&label=Showcases|Particle Systems Tutorial} * @demo {@link https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=Particle%20System%20Fireworks.html&label=Showcases|Particle Systems Fireworks Demo} */ function ParticleSystem(options) { @@ -90,9 +102,15 @@ define([ * @default undefined */ this.updateCallback = options.updateCallback; + /** + * An array of force callbacks. The callback is passed a {@link Particle} and the difference from the last time. This has been deprecated. Use updateCallback instead. + * @type {ParticleSystem~applyForce[]} + * @default undefined + * @deprecated + */ if (defined(options.forces)) { deprecationWarning('forces', 'forces was deprecated in Cesium 1.45. It will be removed in 1.46. Use updateCallback instead.'); - this.updateCallback = options.forces[0]; + this.updateCallback = options.forces; } /** * Whether the particle system should loop it's bursts when it is complete. @@ -121,11 +139,11 @@ define([ this._matrixDirty = true; this._combinedMatrix = new Matrix4(); - this._startColor = Color.clone(defaultValue(options.color, defaultValue(options.startColor, Color.WHITE))); - this._endColor = Color.clone(defaultValue(options.color, defaultValue(options.endColor, Color.WHITE))); + this._startColor = Color.clone(defaultValue(options.startColor, defaultValue(options.color, Color.WHITE))); + this._endColor = Color.clone(defaultValue(options.endColor, defaultValue(options.color, Color.WHITE))); - this._startScale = defaultValue(options.scale, defaultValue(options.startScale, 1.0)); - this._endScale = defaultValue(options.scale, defaultValue(options.endScale, 1.0)); + this._startScale = defaultValue(options.startScale, defaultValue(options.scale, 1.0)); + this._endScale = defaultValue(options.endScale, defaultValue(options.scale, 1.0)); this._emissionRate = defaultValue(options.emissionRate, 5); if (defined(options.rate)) { @@ -133,17 +151,25 @@ define([ this._emissionRate = options.rate; } - this._minimumSpeed = defaultValue(options.speed, defaultValue(options.minimumSpeed, 1.0)); - this._maximumSpeed = defaultValue(options.speed, defaultValue(options.maximumSpeed, 1.0)); + this._minimumSpeed = defaultValue(options.minimumSpeed, defaultValue(options.speed, 1.0)); + this._maximumSpeed = defaultValue(options.maximumSpeed, defaultValue(options.speed, 1.0)); - this._minimumLife = defaultValue(options.life, defaultValue(options.minimumLife, 5.0)); - this._maximumLife = defaultValue(options.life, defaultValue(options.maximumLife, 5.0)); + this._minimumParticleLife = defaultValue(options.minimumParticleLife, defaultValue(options.particleLife, 5.0)); + if (defined(options.minimumLife)) { + deprecationWarning('minimumLife', 'minimumLife was deprecated in Cesium 1.45. It will be removed in 1.46. Use minimumParticleLife instead.'); + this._minimumParticleLife = defaultValue(options.minimumLife, defaultValue(options.life, 5.0)); + } + this._maximumParticleLife = defaultValue(options.maximumParticleLife, defaultValue(options.particleLife, 5.0)); + if (defined(options.maximumLife)) { + deprecationWarning('maximumLife', 'maximumLife was deprecated in Cesium 1.45. It will be removed in 1.46. Use maximumParticleLife instead.'); + this._maximumParticleLife = defaultValue(options.maximumLife, defaultValue(options.life, 5.0)); + } - this._minimumMass = defaultValue(options.mass, defaultValue(options.minimumMass, 1.0)); - this._maximumMass = defaultValue(options.mass, defaultValue(options.maximumMass, 1.0)); + this._minimumMass = defaultValue(options.minimumMass, defaultValue(options.mass, 1.0)); + this._maximumMass = defaultValue(options.maximumMass, defaultValue(options.mass, 1.0)); - this._minimumImageSize = defaultValue(options.imageSize, defaultValue(options.minimumImageSize, defaultImageSize)); - this._maximumImageSize = defaultValue(options.imageSize, defaultValue(options.maximumImageSize, defaultImageSize)); + this._minimumImageSize = defaultValue(options.minimumImageSize, defaultValue(options.imageSize, defaultImageSize)); + this._maximumImageSize = defaultValue(options.maximumImageSize, defaultValue(options.imageSize, defaultImageSize)); if (defined(options.width) || defined(options.minimumWidth) || defined(options.maximumWidth) || defined(options.height) || defined(options.minimumHeight) || defined(options.maximumHeight)) { @@ -155,10 +181,10 @@ define([ deprecationWarning('height', 'height was deprecated in Cesium 1.45. It will be removed in 1.46. Instead of width' + ' and height components for pixel dimensions we switched to a Cartesian2. Use imageSize instead.'); } - var minimumWidth = defaultValue(options.width, defaultValue(options.minimumWidth, 1.0)); - var maximumWidth = defaultValue(options.width, defaultValue(options.maximumWidth, 1.0)); - var minimumHeight = defaultValue(options.height, defaultValue(options.minimumHeight, 1.0)); - var maximumHeight = defaultValue(options.height, defaultValue(options.maximumHeight, 1.0)); + var minimumWidth = defaultValue(options.minimumWidth, defaultValue(options.width, 1.0)); + var maximumWidth = defaultValue(options.maximumWidth, defaultValue(options.width, 1.0)); + var minimumHeight = defaultValue(options.minimumHeight, defaultValue(options.height, 1.0)); + var maximumHeight = defaultValue(options.maximumHeight, defaultValue(options.height, 1.0)); this._minimumImageSize = new Cartesian2(minimumWidth, minimumHeight); this._maximumImageSize = new Cartesian2(maximumWidth, maximumHeight); } @@ -323,7 +349,7 @@ define([ } }, /** - * The number of particles to emit per second. + * The number of particles to emit per second. This has been deprecated. Use {@link ParticleSystem#emissionRate} instead. * @memberof ParticleSystem.prototype * @type {Number} * @default 5 @@ -379,7 +405,7 @@ define([ } }, /** - * Sets the maximum velocity in meters per second. + * Sets the maximum speed in meters per second. * @memberof ParticleSystem.prototype * @type {Number} * @default 1.0 @@ -396,37 +422,78 @@ define([ } }, /** - * Sets the minimum life of particles in seconds. + * Sets the minimum life of particles in seconds. This has been deprecated. Use {@link ParticleSystem#minimumParticleLife} instead. * @memberof ParticleSystem.prototype * @type {Number} * @default 5.0 + * @deprecated */ minimumLife : { get : function() { - return this._minimumLife; + deprecationWarning('minimumLife', 'minimumLife was deprecated in Cesium 1.45. It will be removed in 1.46. Use minimumParticleLife instead.'); + return this._minimumParticleLife; }, set : function(value) { + deprecationWarning('minimumLife', 'minimumLife was deprecated in Cesium 1.45. It will be removed in 1.46. Use minimumParticleLife instead.'); //>>includeStart('debug', pragmas.debug); Check.typeOf.number.greaterThanOrEquals('value', value, 0.0); //>>includeEnd('debug'); - this._minimumLife = value; + this._minimumParticleLife = value; } }, /** - * Sets the maximum life of particles in seconds. + * Sets the minimum life of particles in seconds. * @memberof ParticleSystem.prototype * @type {Number} * @default 5.0 */ + minimumParticleLife : { + get : function() { + return this._minimumParticleLife; + }, + set : function(value) { + //>>includeStart('debug', pragmas.debug); + Check.typeOf.number.greaterThanOrEquals('value', value, 0.0); + //>>includeEnd('debug'); + this._minimumParticleLife = value; + } + }, + /** + * Sets the maximum life of particles in seconds. This has been deprecated. Use {@link ParticleSystem#maximumParticleLife} instead. + * @memberof ParticleSystem.prototype + * @type {Number} + * @default 5.0 + * @deprecated + */ maximumLife : { get : function() { - return this._maximumLife; + deprecationWarning('maximumLife', 'maximumLife was deprecated in Cesium 1.45. It will be removed in 1.46. Use maximumParticleLife instead.'); + return this._maximumParticleLife; + }, + set : function(value) { + deprecationWarning('maximumLife', 'maximumLife was deprecated in Cesium 1.45. It will be removed in 1.46. Use maximumParticleLife instead.'); + //>>includeStart('debug', pragmas.debug); + Check.typeOf.number.greaterThanOrEquals('value', value, 0.0); + //>>includeEnd('debug'); + this._maximumParticleLife = value; + this._updateParticlePool = true; + } + }, + /** + * Sets the maximum life of particles in seconds. + * @memberof ParticleSystem.prototype + * @type {Number} + * @default 5.0 + */ + maximumParticleLife : { + get : function() { + return this._maximumParticleLife; }, set : function(value) { //>>includeStart('debug', pragmas.debug); Check.typeOf.number.greaterThanOrEquals('value', value, 0.0); //>>includeEnd('debug'); - this._maximumLife = value; + this._maximumParticleLife = value; this._updateParticlePool = true; } }, @@ -465,7 +532,7 @@ define([ } }, /** - * Sets the minimum width of particles in pixels. + * Sets the minimum width of particles in pixels. This has been deprecated. Use {@link ParticleSystem#minimumImageSize} instead. * @memberof ParticleSystem.prototype * @type {Number} * @default 1.0 @@ -487,7 +554,7 @@ define([ } }, /** - * Sets the maximum width of particles in pixels. + * Sets the maximum width of particles in pixels. This has been deprecated. Use {@link ParticleSystem#maximumImageSize} instead. * @memberof ParticleSystem.prototype * @type {Number} * @default 1.0 @@ -509,7 +576,7 @@ define([ } }, /** - * Sets the minimum height of particles in pixels. + * Sets the minimum height of particles in pixels. This has been deprecated. Use {@link ParticleSystem#minimumImageSize} instead. * @memberof ParticleSystem.prototype * @type {Number} * @default 1.0 @@ -531,7 +598,7 @@ define([ } }, /** - * Sets the maximum height of particles in pixels. + * Sets the maximum height of particles in pixels. This has been deprecated. Use {@link ParticleSystem#maximumImageSize} instead. * @memberof ParticleSystem.prototype * @type {Number} * @default 1.0 @@ -591,7 +658,7 @@ define([ } }, /** - * How long the particle system will emit particles, in seconds. + * How long the particle system will emit particles, in seconds. This has been deprecated. Use {@link ParticleSystem#lifetime} instead. * @memberof ParticleSystem.prototype * @type {Number} * @default Number.MAX_VALUE @@ -651,7 +718,7 @@ define([ function updateParticlePool(system) { var emissionRate = system._emissionRate; - var life = system._maximumLife; + var life = system._maximumParticleLife; var burstAmount = 0; var bursts = system._bursts; @@ -748,7 +815,7 @@ define([ particle.startScale = system._startScale; particle.endScale = system._endScale; particle.image = system.image; - particle.life = CesiumMath.randomBetween(system._minimumLife, system._maximumLife); + particle.life = CesiumMath.randomBetween(system._minimumParticleLife, system._maximumParticleLife); particle.mass = CesiumMath.randomBetween(system._minimumMass, system._maximumMass); particle.imageSize.x = CesiumMath.randomBetween(system._minimumImageSize.x, system._maximumImageSize.x); particle.imageSize.y = CesiumMath.randomBetween(system._minimumImageSize.y, system._maximumImageSize.y); @@ -959,5 +1026,22 @@ define([ * } */ + /** + * A function used to apply a force to the particle on each time step. This has been deprecated because forces[] + * was deprecated. Use updateCallback instead. + * @callback ParticleSystem~applyForce + * + * @param {Particle} particle The particle to apply the force to. + * @param {Number} dt The time since the last update. + * + * @example + * function applyGravity(particle, dt) { + * var position = particle.position; + * var gravityVector = Cesium.Cartesian3.normalize(position, new Cesium.Cartesian3()); + * Cesium.Cartesian3.multiplyByScalar(gravityVector, GRAVITATIONAL_CONSTANT * dt, gravityVector); + * particle.velocity = Cesium.Cartesian3.add(particle.velocity, gravityVector, particle.velocity); + * } + */ + return ParticleSystem; }); diff --git a/Specs/Scene/ParticleSpec.js b/Specs/Scene/ParticleSpec.js index a3b44db55e6e..00b45c6c67da 100644 --- a/Specs/Scene/ParticleSpec.js +++ b/Specs/Scene/ParticleSpec.js @@ -71,6 +71,36 @@ defineSuite([ }); it('update with forces', function() { + var times2 = function(particle, dt) { + Cartesian3.add(particle.position, Cartesian3.multiplyByScalar(particle.velocity, dt, new Cartesian3()), particle.position); + }; + var increaseMass = function(particle, dt) { + particle.mass++; + }; + var forces = [times2, increaseMass]; + + var position = new Cartesian3(1.0, 2.0, 3.0); + var velocity = Cartesian3.normalize(new Cartesian3(-1.0, 1.0, 1.0), new Cartesian3()); + var p = new Particle({ + life : 15.0, + position : position, + velocity : velocity + }); + + var dt = 10.0; + var expectedPosition = Cartesian3.add(p.position, Cartesian3.multiplyByScalar(p.velocity, 2.0 * dt, new Cartesian3()), new Cartesian3()); + var expectedMass = p.mass + 1; + + expect(p.update(dt, forces)).toEqual(true); + expect(p.position).toEqual(expectedPosition); + expect(p.velocity).toEqual(velocity); + expect(p.age).toEqual(dt); + expect(p.normalizedAge).toEqual(dt / p.life); + expect(p.mass).toEqual(expectedMass); + expect(p.update(dt)).toEqual(false); + }); + + it('update with updateFunction', function() { var increaseMass = function(particle, dt) { particle.mass++; }; diff --git a/Specs/Scene/ParticleSystemSpec.js b/Specs/Scene/ParticleSystemSpec.js index 745933f07c97..7d9ca783c95a 100644 --- a/Specs/Scene/ParticleSystemSpec.js +++ b/Specs/Scene/ParticleSystemSpec.js @@ -50,8 +50,8 @@ defineSuite([ expect(p.loop).toEqual(true); expect(p.minimumSpeed).toEqual(1.0); expect(p.maximumSpeed).toEqual(1.0); - expect(p.minimumLife).toEqual(5.0); - expect(p.maximumLife).toEqual(5.0); + expect(p.minimumParticleLife).toEqual(5.0); + expect(p.maximumParticleLife).toEqual(5.0); expect(p.minimumMass).toEqual(1.0); expect(p.maximumMass).toEqual(1.0); expect(p.image).toBeUndefined(); @@ -67,7 +67,7 @@ defineSuite([ it('constructor', function() { var options = { show : false, - updateParticle : (function(p) { p.mass++; }), + updateCallback : (function(p) { p.mass++; }), emitter : new CircleEmitter(10.0), modelMatrix : new Matrix4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0), emitterModelMatrix : new Matrix4(10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0), @@ -80,8 +80,8 @@ defineSuite([ loop : false, minimumSpeed : 22.0, maximumSpeed : 23.0, - minimumLife : 24.0, - maximumLife : 25.0, + minimumParticleLife : 24.0, + maximumParticleLife : 25.0, minimumMass : 26.0, maximumMass : 27.0, image : 'url/to/image', @@ -91,7 +91,7 @@ defineSuite([ }; var p = new ParticleSystem(options); expect(p.show).toEqual(options.show); - expect(p.updateParticle).toEqual(options.updateParticle); + expect(p.updateCallback).toEqual(options.updateCallback); expect(p.emitter).toEqual(options.emitter); expect(p.modelMatrix).toEqual(options.modelMatrix); expect(p.emitterModelMatrix).toEqual(options.emitterModelMatrix); @@ -104,8 +104,8 @@ defineSuite([ expect(p.loop).toEqual(options.loop); expect(p.minimumSpeed).toEqual(options.minimumSpeed); expect(p.maximumSpeed).toEqual(options.maximumSpeed); - expect(p.minimumLife).toEqual(options.minimumLife); - expect(p.maximumLife).toEqual(options.maximumLife); + expect(p.minimumParticleLife).toEqual(options.minimumParticleLife); + expect(p.maximumParticleLife).toEqual(options.maximumParticleLife); expect(p.minimumMass).toEqual(options.minimumMass); expect(p.maximumMass).toEqual(options.maximumMass); expect(p.image).toEqual(options.image); @@ -131,8 +131,8 @@ defineSuite([ var loop = false; var minimumSpeed = 22.0; var maximumSpeed = 23.0; - var minimumLife = 24.0; - var maximumLife = 25.0; + var minimumParticleLife = 24.0; + var maximumParticleLife = 25.0; var minimumMass = 26.0; var maximumMass = 27.0; var image = 'url/to/image'; @@ -155,8 +155,8 @@ defineSuite([ p.loop = loop; p.minimumSpeed = minimumSpeed; p.maximumSpeed = maximumSpeed; - p.minimumLife = minimumLife; - p.maximumLife = maximumLife; + p.minimumParticleLife = minimumParticleLife; + p.maximumParticleLife = maximumParticleLife; p.minimumMass = minimumMass; p.maximumMass = maximumMass; p.image = image; @@ -178,8 +178,8 @@ defineSuite([ expect(p.loop).toEqual(loop); expect(p.minimumSpeed).toEqual(minimumSpeed); expect(p.maximumSpeed).toEqual(maximumSpeed); - expect(p.minimumLife).toEqual(minimumLife); - expect(p.maximumLife).toEqual(maximumLife); + expect(p.minimumParticleLife).toEqual(minimumParticleLife); + expect(p.maximumParticleLife).toEqual(maximumParticleLife); expect(p.minimumMass).toEqual(minimumMass); expect(p.maximumMass).toEqual(maximumMass); expect(p.image).toEqual(image); @@ -260,17 +260,17 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('throws with invalid minimumLife', function() { + it('throws with invalid minimumParticleLife', function() { var p = new ParticleSystem(); expect(function() { - p.minimumLife = -1.0; + p.minimumParticleLife = -1.0; }).toThrowDeveloperError(); }); - it('throws with invalid maximumLife', function() { + it('throws with invalid maximumParticleLife', function() { var p = new ParticleSystem(); expect(function() { - p.maximumLife = -1.0; + p.maximumParticleLife = -1.0; }).toThrowDeveloperError(); }); From 603640c627706735d391486bd7c3b24877d77cf2 Mon Sep 17 00:00:00 2001 From: hanbollar Date: Thu, 12 Apr 2018 16:20:56 -0400 Subject: [PATCH 6/6] current deprecations --- CHANGES.md | 12 +- Source/Core/FeatureDetection.js | 17 ++- Source/Core/arraySlice.js | 68 ++++------- Source/Scene/Particle.js | 4 +- Source/Scene/ParticleSystem.js | 195 +++++++++++++++--------------- Specs/Scene/ParticleSystemSpec.js | 21 ++-- Specs/equals.js | 18 +-- 7 files changed, 158 insertions(+), 177 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6cb16d4626ba..029116bdfca2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,17 +9,17 @@ Change Log * Fixed glTF support to handle skinned meshes when no skin is supplied. [#6061](https://github.com/AnalyticalGraphicsInc/cesium/issues/6061) * Allow loadWithXhr to work with string URLs in a web worker. * Fix Firefox WebGL console warnings. [#5912](https://github.com/AnalyticalGraphicsInc/cesium/issues/5912) - -##### Deprecated :hourglass_flowing_sand: -* `Particle.size`, `ParticleSystem.rate`, `ParticleSystem.lifeTime` have been renamed to `Particle.imageSize`, `ParticleSystem.emissionRate`, and `ParticleSystem.lifetime`. Use of the `size`, `rate`, and `lifeTime` parameters is deprecated and will be removed in Cesium 1.46. -* `ParticleSystem.life`, `ParticleSystem.minimumLife`, and `ParticleSystem.maximumLife` have been renamed to `ParticleSystem.particleLife`, `ParticleSystem.minimumParticleLife`, and `ParticleSystem.maximumParticleLife`. Use of the `life`, `minimumLife`, and `maximumLife` parameters is deprecated and will be removed in Cesium 1.46. -* `ParticleSystem.forces` array has been switched out for singular function `ParticleSystems.updateCallback`. Use of the `forces` parameter is deprecated and will be removed in Cesium 1.46. -* Any width and height variables in `ParticleSystem` will no longer be individual components. `ParticleSystem.minimumWidth` and `ParticleSystem.minimumHeight` will now be `ParticleSystem.minimumImageSize`, `ParticleSystem.maximumWidth` and `ParticleSystem.maximumHeight` will now be `ParticleSystem.maximumImageSize`, and `ParticleSystem.width` and `ParticleSystem.height` will now be `ParticleSystem.imageSize`. Use of the `minimumWidth`, `minimumHeight`, `maximumWidth`, `maximumHeight`, `width`, and `height` parameters is deprecated and will be removed in Cesium 1.46. +* Fix parsing Cesium.js in older browsers that do not support all TypedArray types. [#6396](https://github.com/AnalyticalGraphicsInc/cesium/pull/6396) ##### Additions :tada: * Added color and scale attributes to the `ParticleSystem` class constructor. When defined the variables override startColor and endColor and startScale and endScale. [#6429](https://github.com/AnalyticalGraphicsInc/cesium/pull/6429) * Improved `MapboxImageryProvider` performance by 300% via `tiles.mapbox.com` subdomain switching. [#6426](https://github.com/AnalyticalGraphicsInc/cesium/issues/6426) +##### Deprecated :hourglass_flowing_sand: +* `Particle.size`, `ParticleSystem.rate`, `ParticleSystem.lifeTime`, `ParticleSystem.life`, `ParticleSystem.minimumLife`, and `ParticleSystem.maximumLife` have been renamed to `Particle.imageSize`, `ParticleSystem.emissionRate`, `ParticleSystem.lifetime`, `ParticleSystem.particleLife`, `ParticleSystem.minimumParticleLife`, and `ParticleSystem.maximumParticleLife`. Use of the `size`, `rate`, `lifeTime`, `life`, `minimumLife`, and `maximumLife` parameters is deprecated and will be removed in Cesium 1.46. +* `ParticleSystem.forces` array has been switched out for singular function `ParticleSystems.updateCallback`. Use of the `forces` parameter is deprecated and will be removed in Cesium 1.46. +* Any width and height variables in `ParticleSystem` will no longer be individual components. `ParticleSystem.minimumWidth` and `ParticleSystem.minimumHeight` will now be `ParticleSystem.minimumImageSize`, `ParticleSystem.maximumWidth` and `ParticleSystem.maximumHeight` will now be `ParticleSystem.maximumImageSize`, and `ParticleSystem.width` and `ParticleSystem.height` will now be `ParticleSystem.imageSize`. Use of the `minimumWidth`, `minimumHeight`, `maximumWidth`, `maximumHeight`, `width`, and `height` parameters is deprecated and will be removed in Cesium 1.46. + ### 1.44 - 2018-04-02 ##### Highlights :sparkler: diff --git a/Source/Core/FeatureDetection.js b/Source/Core/FeatureDetection.js index 772b744ea697..1d9ee2a17224 100644 --- a/Source/Core/FeatureDetection.js +++ b/Source/Core/FeatureDetection.js @@ -7,6 +7,7 @@ define([ defined, Fullscreen) { 'use strict'; + /*global CanvasPixelArray*/ var theNavigator; if (typeof navigator !== 'undefined') { @@ -196,6 +197,19 @@ define([ return supportsImageRenderingPixelated() ? imageRenderingValueResult : undefined; } + var typedArrayTypes = []; + if (typeof ArrayBuffer !== 'undefined') { + typedArrayTypes.push(Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array); + + if (typeof Uint8ClampedArray !== 'undefined') { + typedArrayTypes.push(Uint8ClampedArray); + } + + if (typeof CanvasPixelArray !== 'undefined') { + typedArrayTypes.push(CanvasPixelArray); + } + } + /** * A set of functions to detect whether the current browser supports * various features. @@ -219,7 +233,8 @@ define([ hardwareConcurrency : defaultValue(theNavigator.hardwareConcurrency, 3), supportsPointerEvents : supportsPointerEvents, supportsImageRenderingPixelated: supportsImageRenderingPixelated, - imageRenderingValue: imageRenderingValue + imageRenderingValue: imageRenderingValue, + typedArrayTypes: typedArrayTypes }; /** diff --git a/Source/Core/arraySlice.js b/Source/Core/arraySlice.js index deb9aa766eeb..a8f0e03b1b9c 100644 --- a/Source/Core/arraySlice.js +++ b/Source/Core/arraySlice.js @@ -10,7 +10,17 @@ define([ FeatureDetection) { 'use strict'; - var slice = function(array, begin, end) { + /** + * Create a shallow copy of an array from begin to end. + * + * @param {Array} array The array to fill. + * @param {Number} [begin=0] The index to start at. + * @param {Number} [end=array.length] The index to end at which is not included. + * + * @returns {Array} The resulting array. + * @private + */ + function arraySlice(array, begin, end) { //>>includeStart('debug', pragmas.debug); Check.defined('array', array); if (defined(begin)) { @@ -20,54 +30,22 @@ define([ Check.typeOf.number('end', end); } //>>includeEnd('debug'); - return array.slice(begin, end); - }; - - if (FeatureDetection.supportsTypedArrays()) { - var tempArray = new Uint8Array(1); - if (typeof tempArray.slice !== 'function') { - var typedArrayTypes = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array]; - slice = function(array, begin, end) { - //>>includeStart('debug', pragmas.debug); - Check.defined('array', array); - if (defined(begin)) { - Check.typeOf.number('begin', begin); - } - if (defined(end)) { - Check.typeOf.number('end', end); - } - //>>includeEnd('debug'); - - if (typeof array.slice === 'function') { - return array.slice(begin, end); - } - var copy = Array.prototype.slice.call(array, begin, end); - var length = typedArrayTypes.length; - for (var i = 0; i < length; ++i) { - if (array instanceof typedArrayTypes[i]) { - copy = new typedArrayTypes[i](copy); - break; - } - } + if (typeof array.slice === 'function') { + return array.slice(begin, end); + } - return copy; - }; + var copy = Array.prototype.slice.call(array, begin, end); + var typedArrayTypes = FeatureDetection.typedArrayTypes; + var length = typedArrayTypes.length; + for (var i = 0; i < length; ++i) { + if (array instanceof typedArrayTypes[i]) { + copy = new typedArrayTypes[i](copy); + break; + } } - } - /** - * Create a shallow copy of an array from begin to end. - * - * @param {Array} array The array to fill. - * @param {Number} [begin=0] The index to start at. - * @param {Number} [end=array.length] The index to end at which is not included. - * - * @returns {Array} The resulting array. - * @private - */ - function arraySlice(array, begin, end) { - return slice(array, begin, end); + return copy; } return arraySlice; diff --git a/Source/Scene/Particle.js b/Source/Scene/Particle.js index 33b07080cfea..052daf14ef7e 100644 --- a/Source/Scene/Particle.js +++ b/Source/Scene/Particle.js @@ -35,7 +35,7 @@ define([ * @param {Number} [options.startScale=1.0] The scale of the particle when it is born. * @param {Number} [options.endScale=1.0] The scale of the particle when it dies. * @param {Cartesian2} [options.size=new Cartesian2(1.0, 1.0)] The dimensions of particles in pixels. This has been deprecated. Use imageSize instead. - * @param {Cartesian2} [options.imageSize=new Cartesian2(1.0, 1.0)] The dimensions of the image representing the particle in pixels. Width by Height. + * @param {Cartesian2} [options.imageSize=new Cartesian2(1.0, 1.0)] The dimensions, width by height, to scale the particle image in pixels. */ function Particle(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); @@ -95,7 +95,7 @@ define([ */ this.endScale = defaultValue(options.endScale, 1.0); /** - * The dimensions of the image representing the particle in pixels. Width by Height. + * The dimensions, width by height, to scale the particle image in pixels. * @type {Cartesian2} * @default new Cartesian(1.0, 1.0) */ diff --git a/Source/Scene/ParticleSystem.js b/Source/Scene/ParticleSystem.js index 1c104c6d6a6a..28e26ad5720a 100644 --- a/Source/Scene/ParticleSystem.js +++ b/Source/Scene/ParticleSystem.js @@ -45,20 +45,20 @@ define([ * @param {Object} [options] Object with the following properties: * @param {Boolean} [options.show=true] Whether to display the particle system. * @param {ParticleSystem~applyForce[]} [options.forces] An array of force callbacks. This has been deprecated. Use updateCallback instead. - * @param {ParticleSystem~updateCallback} [options.updateCallback] The callback to an update function used for every particle in this system. + * @param {ParticleSystem~updateCallback} [options.updateCallback] The callback function to be called each frame to update a particle. * @param {ParticleEmitter} [options.emitter=new CircleEmitter(0.5)] The particle emitter for this system. * @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] The 4x4 transformation matrix that transforms the particle system from model to world coordinates. * @param {Matrix4} [options.emitterModelMatrix=Matrix4.IDENTITY] The 4x4 transformation matrix that transforms the particle system emitter within the particle systems local coordinate system. * @param {Number} [options.rate = 5] The number of particles to emit per second. This has been deprecated. Use emissionRate instead. * @param {Number} [options.emissionRate=5] The number of particles to emit per second. * @param {ParticleBurst[]} [options.bursts] An array of {@link ParticleBurst}, emitting bursts of particles at periodic times. - * @param {Boolean} [options.loop=true] Whether the particle system should loop it's bursts when it is complete. - * @param {Number} [options.scale=1.0] Sets the start and end scales. - * @param {Number} [options.startScale] The scale of the particle when it is born. - * @param {Number} [options.endScale] The scale of the particle when it dies. - * @param {Color} [options.color=Color.WHITE] Sets the start and end colors. - * @param {Color} [options.startColor] The color of a particle when it is born. - * @param {Color} [options.endColor] The color of a particle when it dies. + * @param {Boolean} [options.loop=true] Whether the particle system should loop its bursts when it is complete. + * @param {Number} [options.scale=1.0] Sets the scale to apply to the image of the particle for the duration of its particleLife. + * @param {Number} [options.startScale] The initial scale to apply to the image of the particle at the beginning of its life. + * @param {Number} [options.endScale] The final scale to apply to the image of the particle at the end of its life. + * @param {Color} [options.color=Color.WHITE] Sets the color of a particle for the duration of its particleLife. + * @param {Color} [options.startColor] The color of the particle at the beginning of its life. + * @param {Color} [options.endColor] The color of the particle at the end of its life. * @param {Object} [options.image] The URI, HTMLImageElement, or HTMLCanvasElement to use for the billboard. * @param {Number} [options.width=1.0] Sets the minimum and maximum width of particles in pixels. This has been deprecated. Use imageSize's x component instead. * @param {Number} [options.minimumWidth] Sets the minimum width of particles in pixels. This has been deprecated. Use minimumImageSize's x component instead. @@ -66,24 +66,25 @@ define([ * @param {Number} [options.height=1.0] Overwrites the minimum and maximum height of particles in pixels. This has been deprecated. Use imageSize's y component instead. * @param {Number} [options.minimumHeight] Sets the minimum height of particles in pixels. This has been deprecated. Use minimumImageSize's y component instead. * @param {Number} [options.maximumHeight] Sets the maximum height of particles in pixels. This has been deprecated. Use maximumImageSize's y component instead. - * @param {Cartesian2} [options.imageSize=new Cartesian2(1.0, 1.0)] If set, overrides the minimumImageSize and maximumImageSize inputs with this value. - * @param {Cartesian2} [options.minimumImageSize] Sets the minimum dimensions of the image representing the particle in pixels. Width by Height. - * @param {Cartesian2} [options.maximumImageSize] Sets the maximum dimensions of the image representing the particle in pixels. Width by Height. + * @param {Cartesian2} [options.imageSize=new Cartesian2(1.0, 1.0)] If set, overrides the minimumImageSize and maximumImageSize inputs that scale the particle image's dimensions in pixels. + * @param {Cartesian2} [options.minimumImageSize] Sets the minimum bound, width by height, above which to randomly scale the particle image's dimensions in pixels. + * @param {Cartesian2} [options.maximumImageSize] Sets the maximum bound, width by height, below which to randomly scale the particle image's dimensions in pixels. * @param {Number} [options.speed=1.0] If set, overrides the minimumSpeed and maximumSpeed inputs with this value. - * @param {Number} [options.minimumSpeed] Sets the minimum speed in meters per second. - * @param {Number} [options.maximumSpeed] Sets the maximum speed in meters per second. + * @param {Number} [options.minimumSpeed] Sets the minimum bound in meters per second above which a particle's actual speed will be randomly chosen. + * @param {Number} [options.maximumSpeed] Sets the maximum bound in meters per second below which a particle's actual speed will be randomly chosen. * @param {Number} [options.lifeTime=Number.MAX_VALUE] How long the particle system will emit particles, in seconds. This has been deprecated. Use lifetime instead. * @param {Number} [options.lifetime=Number.MAX_VALUE] How long the particle system will emit particles, in seconds. * @param {Number} [options.life=5.0] If set, overrides the minimumLife and maximumLife inputs with this value. This has been deprecated. Use particleLife instead. * @param {Number} [options.minimumLife] Sets the minimum life of particles in seconds. This has been deprecated. Use minimumParticleLife instead. * @param {Number} [options.maximumLife] Sets the maximum life of particles in seconds. This has been deprecated. Use maximumParticleLife instead. * @param {Number} [options.particleLife=5.0] If set, overrides the minimumParticleLife and maximumParticleLife inputs with this value. - * @param {Number} [options.minimumParticleLife] Sets the minimum life of particles in seconds. - * @param {Number} [options.maximumParticleLife] Sets the maximum life of particles in seconds. + * @param {Number} [options.minimumParticleLife] Sets the minimum bound in seconds for the possible duration of a particle's life above which a particle's actual life will be randomly chosen. + * @param {Number} [options.maximumParticleLife] Sets the maximum bound in seconds for the possible duration of a particle's life below which a particle's actual life will be randomly chosen. * @param {Number} [options.mass=1.0] Sets the minimum and maximum mass of particles in kilograms. - * @param {Number} [options.minimumMass] Sets the minimum mass of particles in kilograms. - * @param {Number} [options.maximumMass] Sets the maximum mass of particles in kilograms. - * @demo {@link https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=Particle%20System.html&label=Showcases|Particle Systems Tutorial} + * @param {Number} [options.minimumMass] Sets the minimum bound for the mass of a particle in kilograms. A particle's actual mass will be chosen as a random amount above this value. + * @param {Number} [options.maximumMass] Sets the maximum mass of particles in kilograms. A particle's actual mass will be chosen as a random amount below this value. + * @tutorial {@link https://cesiumjs.org/tutorials/Particle-Systems-Tutorial/|Particle Systems Tutorial} + * @demo {@link https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=Particle%20System.html&label=Showcases|Particle Systems Tutorial Demo} * @demo {@link https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=Particle%20System%20Fireworks.html&label=Showcases|Particle Systems Fireworks Demo} */ function ParticleSystem(options) { @@ -139,52 +140,78 @@ define([ this._matrixDirty = true; this._combinedMatrix = new Matrix4(); - this._startColor = Color.clone(defaultValue(options.startColor, defaultValue(options.color, Color.WHITE))); - this._endColor = Color.clone(defaultValue(options.endColor, defaultValue(options.color, Color.WHITE))); + this._startColor = Color.clone(defaultValue(options.color, defaultValue(options.startColor, Color.WHITE))); + this._endColor = Color.clone(defaultValue(options.color, defaultValue(options.endColor, Color.WHITE))); - this._startScale = defaultValue(options.startScale, defaultValue(options.scale, 1.0)); - this._endScale = defaultValue(options.endScale, defaultValue(options.scale, 1.0)); + this._startScale = defaultValue(options.scale, defaultValue(options.startScale, 1.0)); + this._endScale = defaultValue(options.scale, defaultValue(options.endScale, 1.0)); - this._emissionRate = defaultValue(options.emissionRate, 5); + this._emissionRate = defaultValue(options.emissionRate, 5.0); if (defined(options.rate)) { deprecationWarning('rate', 'rate was deprecated in Cesium 1.45. It will be removed in 1.46. Use emissionRate instead.'); this._emissionRate = options.rate; } - this._minimumSpeed = defaultValue(options.minimumSpeed, defaultValue(options.speed, 1.0)); - this._maximumSpeed = defaultValue(options.maximumSpeed, defaultValue(options.speed, 1.0)); + this._minimumSpeed = defaultValue(options.speed, defaultValue(options.minimumSpeed, 1.0)); + this._maximumSpeed = defaultValue(options.speed, defaultValue(options.maximumSpeed, 1.0)); - this._minimumParticleLife = defaultValue(options.minimumParticleLife, defaultValue(options.particleLife, 5.0)); - if (defined(options.minimumLife)) { + var particleLife; + if (defined(options.life)) { + deprecationWarning('life', 'life was deprecated in Cesium 1.45. It will be removed in 1.46. Use particleLife instead.'); + particleLife = options.life; + } + this._minimumParticleLife = defaultValue(options.particleLife, defaultValue(options.minimumParticleLife, 5.0)); + if (defined(particleLife) || defined(options.minimumLife)) { deprecationWarning('minimumLife', 'minimumLife was deprecated in Cesium 1.45. It will be removed in 1.46. Use minimumParticleLife instead.'); - this._minimumParticleLife = defaultValue(options.minimumLife, defaultValue(options.life, 5.0)); + this._minimumParticleLife = defaultValue(particleLife, defaultValue(options.minimumLife, 5.0)); } - this._maximumParticleLife = defaultValue(options.maximumParticleLife, defaultValue(options.particleLife, 5.0)); - if (defined(options.maximumLife)) { + this._maximumParticleLife = defaultValue(options.particleLife, defaultValue(options.maximumParticleLife, 5.0)); + if (defined(particleLife) || defined(options.maximumLife)) { deprecationWarning('maximumLife', 'maximumLife was deprecated in Cesium 1.45. It will be removed in 1.46. Use maximumParticleLife instead.'); - this._maximumParticleLife = defaultValue(options.maximumLife, defaultValue(options.life, 5.0)); + this._maximumParticleLife = defaultValue(particleLife, defaultValue(options.maximumLife, 5.0)); } - this._minimumMass = defaultValue(options.minimumMass, defaultValue(options.mass, 1.0)); - this._maximumMass = defaultValue(options.maximumMass, defaultValue(options.mass, 1.0)); - - this._minimumImageSize = defaultValue(options.minimumImageSize, defaultValue(options.imageSize, defaultImageSize)); - this._maximumImageSize = defaultValue(options.maximumImageSize, defaultValue(options.imageSize, defaultImageSize)); - if (defined(options.width) || defined(options.minimumWidth) || defined(options.maximumWidth) - || defined(options.height) || defined(options.minimumHeight) || defined(options.maximumHeight)) { + this._minimumMass = defaultValue(options.mass, defaultValue(options.minimumMass, 1.0)); + this._maximumMass = defaultValue(options.mass, defaultValue(options.maximumMass, 1.0)); - if (defined(options.width)) { - deprecationWarning('width', 'width was deprecated in Cesium 1.45. It will be removed in 1.46. Instead of width' + - ' and height components for pixel dimensions we switched to a Cartesian2. Use imageSize instead.'); + var width; + if (defined(options.width)) { + deprecationWarning('width', 'width was deprecated in Cesium 1.45. It will be removed in 1.46. Instead of width' + + ' and height components for pixel dimensions we switched to a Cartesian2. Use imageSize instead.'); + width = options.width; + } + var height; + if (defined(options.height)) { + deprecationWarning('height', 'height was deprecated in Cesium 1.45. It will be removed in 1.46. Instead of width' + + ' and height components for pixel dimensions we switched to a Cartesian2. Use imageSize instead.'); + height = options.height; + } + this._minimumImageSize = defaultValue(options.imageSize, defaultValue(options.minimumImageSize, defaultImageSize)); + this._maximumImageSize = defaultValue(options.imageSize, defaultValue(options.maximumImageSize, defaultImageSize)); + if (defined(width) || defined(options.minimumWidth) || defined(options.maximumWidth) + || defined(height) || defined(options.minimumHeight) || defined(options.maximumHeight)) { + + if (defined(options.minimumWidth)) { + deprecationWarning('minimumWidth', 'minimumWidth was deprecated in Cesium 1.45. It will be removed in 1.46. Instead of width' + + ' and height components for pixel dimensions we switched to a Cartesian2. Use the x component of minimumImageSize instead.'); } - if (defined(options.height)) { - deprecationWarning('height', 'height was deprecated in Cesium 1.45. It will be removed in 1.46. Instead of width' + - ' and height components for pixel dimensions we switched to a Cartesian2. Use imageSize instead.'); + if (defined(options.maximumWidth)) { + deprecationWarning('maximumWidth', 'maximumWidth was deprecated in Cesium 1.45. It will be removed in 1.46. Instead of width' + + ' and height components for pixel dimensions we switched to a Cartesian2. Use the x component of maximumImageSize instead.'); + } + if (defined(options.minimumHeight)) { + deprecationWarning('minimumHeight', 'minimumHeight was deprecated in Cesium 1.45. It will be removed in 1.46. Instead of width' + + ' and height components for pixel dimensions we switched to a Cartesian2. Use the y component of minimumImageSize instead.'); + } + if (defined(options.maximumHeight)) { + deprecationWarning('maximumHeight', 'maximumHeight was deprecated in Cesium 1.45. It will be removed in 1.46. Instead of width' + + ' and height components for pixel dimensions we switched to a Cartesian2. Use the y component of maximumImageSize instead.'); } - var minimumWidth = defaultValue(options.minimumWidth, defaultValue(options.width, 1.0)); - var maximumWidth = defaultValue(options.maximumWidth, defaultValue(options.width, 1.0)); - var minimumHeight = defaultValue(options.minimumHeight, defaultValue(options.height, 1.0)); - var maximumHeight = defaultValue(options.maximumHeight, defaultValue(options.height, 1.0)); + + var minimumWidth = defaultValue(width, defaultValue(options.minimumWidth, 1.0)); + var maximumWidth = defaultValue(width, defaultValue(options.maximumWidth, 1.0)); + var minimumHeight = defaultValue(height, defaultValue(options.minimumHeight, 1.0)); + var maximumHeight = defaultValue(height, defaultValue(options.maximumHeight, 1.0)); this._minimumImageSize = new Cartesian2(minimumWidth, minimumHeight); this._maximumImageSize = new Cartesian2(maximumWidth, maximumHeight); } @@ -281,7 +308,7 @@ define([ } }, /** - * The color of a particle when it is born. + * The color of the particle at the beginning of its life. * @memberof ParticleSystem.prototype * @type {Color} * @default Color.WHITE @@ -298,7 +325,7 @@ define([ } }, /** - * The color of a particle when it dies. + * The color of the particle at the end of its life. * @memberof ParticleSystem.prototype * @type {Color} * @default Color.WHITE @@ -315,7 +342,7 @@ define([ } }, /** - * The scale of the particle when it is born. + * The initial scale to apply to the image of the particle at the beginning of its life. * @memberof ParticleSystem.prototype * @type {Number} * @default 1.0 @@ -332,7 +359,7 @@ define([ } }, /** - * The scale of the particle when it dies. + * The final scale to apply to the image of the particle at the end of its life. * @memberof ParticleSystem.prototype * @type {Number} * @default 1.0 @@ -362,11 +389,7 @@ define([ }, set : function(value) { deprecationWarning('rate', 'rate was deprecated in Cesium 1.45. It will be removed in 1.46. Use emissionRate instead.'); - //>>includeStart('debug', pragmas.debug); - Check.typeOf.number.greaterThanOrEquals('value', value, 0.0); - //>>includeEnd('debug'); - this._emissionRate = value; - this._updateParticlePool = true; + this.emissionRate = value; } }, /** @@ -388,7 +411,7 @@ define([ } }, /** - * Sets the minimum speed in meters per second. + * Sets the minimum bound in meters per second above which a particle's actual speed will be randomly chosen. * @memberof ParticleSystem.prototype * @type {Number} * @default 1.0 @@ -405,7 +428,7 @@ define([ } }, /** - * Sets the maximum speed in meters per second. + * Sets the maximum bound in meters per second below which a particle's actual speed will be randomly chosen. * @memberof ParticleSystem.prototype * @type {Number} * @default 1.0 @@ -435,14 +458,11 @@ define([ }, set : function(value) { deprecationWarning('minimumLife', 'minimumLife was deprecated in Cesium 1.45. It will be removed in 1.46. Use minimumParticleLife instead.'); - //>>includeStart('debug', pragmas.debug); - Check.typeOf.number.greaterThanOrEquals('value', value, 0.0); - //>>includeEnd('debug'); - this._minimumParticleLife = value; + this.minimumParticleLife = value; } }, /** - * Sets the minimum life of particles in seconds. + * Sets the minimum bound in seconds for the possible duration of a particle's life above which a particle's actual life will be randomly chosen. * @memberof ParticleSystem.prototype * @type {Number} * @default 5.0 @@ -472,15 +492,11 @@ define([ }, set : function(value) { deprecationWarning('maximumLife', 'maximumLife was deprecated in Cesium 1.45. It will be removed in 1.46. Use maximumParticleLife instead.'); - //>>includeStart('debug', pragmas.debug); - Check.typeOf.number.greaterThanOrEquals('value', value, 0.0); - //>>includeEnd('debug'); - this._maximumParticleLife = value; - this._updateParticlePool = true; + this.maximumParticleLife = value; } }, /** - * Sets the maximum life of particles in seconds. + * Sets the maximum bound in seconds for the possible duration of a particle's life below which a particle's actual life will be randomly chosen. * @memberof ParticleSystem.prototype * @type {Number} * @default 5.0 @@ -547,10 +563,7 @@ define([ set : function(value) { deprecationWarning('width', 'width was deprecated in Cesium 1.45. It will be removed in 1.46. Instead of width' + ' and height components for pixel dimensions we switched to a Cartesian2. Use imageSize instead.'); - //>>includeStart('debug', pragmas.debug); - Check.typeOf.number.greaterThanOrEquals('value', value, 0.0); - //>>includeEnd('debug'); - this._minimumImageSize.x = value; + this.minimumImageSize = new Cartesian2(value, this.minimumImageSize.y); } }, /** @@ -569,10 +582,7 @@ define([ set : function(value) { deprecationWarning('width', 'width was deprecated in Cesium 1.45. It will be removed in 1.46. Instead of width' + ' and height components for pixel dimensions we switched to a Cartesian2. Use imageSize instead.'); - //>>includeStart('debug', pragmas.debug); - Check.typeOf.number.greaterThanOrEquals('value', value, 0.0); - //>>includeEnd('debug'); - this._maximumImageSize.x = value; + this.maximumImageSize = new Cartesian2(value, this.maximumImageSize.y); } }, /** @@ -591,10 +601,7 @@ define([ set : function(value) { deprecationWarning('height', 'height was deprecated in Cesium 1.45. It will be removed in 1.46. Instead of width' + ' and height components for pixel dimensions we switched to a Cartesian2. Use imageSize instead.'); - //>>includeStart('debug', pragmas.debug); - Check.typeOf.number.greaterThanOrEquals('value', value, 0.0); - //>>includeEnd('debug'); - this._minimumImageSize.y = value; + this.minimumImageSize = new Cartesian2(this.minimumImageSize.x, value); } }, /** @@ -613,14 +620,11 @@ define([ set : function(value) { deprecationWarning('height', 'height was deprecated in Cesium 1.45. It will be removed in 1.46. Instead of width' + ' and height components for pixel dimensions we switched to a Cartesian2. Use imageSize instead.'); - //>>includeStart('debug', pragmas.debug); - Check.typeOf.number.greaterThanOrEquals('value', value, 0.0); - //>>includeEnd('debug'); - this._maximumImageSize.y = value; + this.maximumImageSize = new Cartesian2(this.maximumImageSize.x, value); } }, /** - * Sets the maximum width and height of particles in pixels. + * Sets the minimum bound, width by height, above which to randomly scale the particle image's dimensions in pixels. * @memberof ParticleSystem.prototype * @type {Cartesian2} * @default new Cartesian2(1.0, 1.0) @@ -639,7 +643,7 @@ define([ } }, /** - * Sets the maximum width and height of particles in pixels. + * Sets the maximum bound, width by height, below which to randomly scale the particle image's dimensions in pixels. * @memberof ParticleSystem.prototype * @type {Cartesian2} * @default new Cartesian2(1.0, 1.0) @@ -671,10 +675,7 @@ define([ }, set : function(value) { deprecationWarning('lifeTime', 'lifeTime was deprecated in Cesium 1.45. It will be removed in 1.46. Use lifetime instead.'); - //>>includeStart('debug', pragmas.debug); - Check.typeOf.number.greaterThanOrEquals('value', value, 0.0); - //>>includeEnd('debug'); - this._lifetime = value; + this.lifetime = value; } }, /** @@ -805,8 +806,7 @@ define([ billboard.color = new Color(r,g,b,a); // Update the scale - var scale = CesiumMath.lerp(particle.startScale, particle.endScale, particle.normalizedAge); - billboard.scale = scale; + billboard.scale = CesiumMath.lerp(particle.startScale, particle.endScale, particle.normalizedAge); } function addParticle(system, particle) { @@ -1012,10 +1012,13 @@ define([ /** * A function used to modify attributes of the particle at each time step. This can include force modifications, * color, sizing, etc. + * + * @see {@link https://cesiumjs.org/tutorials/Particle-Systems-Tutorial/|Particle Systems Tutorial} + * * @callback ParticleSystem~updateCallback * * @param {Particle} particle The particle being updated. - * @param {Number} dt The time since the last update. + * @param {Number} dt The time in seconds since the last update. * * @example * function applyGravity(particle, dt) { @@ -1034,6 +1037,8 @@ define([ * @param {Particle} particle The particle to apply the force to. * @param {Number} dt The time since the last update. * + * @deprecated + * * @example * function applyGravity(particle, dt) { * var position = particle.position; diff --git a/Specs/Scene/ParticleSystemSpec.js b/Specs/Scene/ParticleSystemSpec.js index 7d9ca783c95a..907e97cd2c02 100644 --- a/Specs/Scene/ParticleSystemSpec.js +++ b/Specs/Scene/ParticleSystemSpec.js @@ -239,10 +239,10 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('throws with invalid rate', function() { + it('throws with invalid emissionRate', function() { var p = new ParticleSystem(); expect(function() { - p.rate = -1.0; + p.emissionRate = -1.0; }).toThrowDeveloperError(); }); @@ -291,35 +291,35 @@ defineSuite([ it('throws with invalid minimumWidth', function() { var p = new ParticleSystem(); expect(function() { - p.minimumWidth = -1.0; + p.minimumImageSize = new Cartesian2(-1.0, 2.0); }).toThrowDeveloperError(); }); it('throws with invalid maximumWidth', function() { var p = new ParticleSystem(); expect(function() { - p.maximumWidth = -1.0; + p.maximumImageSize = new Cartesian2(-1.0, 2.0); }).toThrowDeveloperError(); }); it('throws with invalid minimumHeight', function() { var p = new ParticleSystem(); expect(function() { - p.minimumHeight = -1.0; + p.minimumImageSize = new Cartesian2(2.0, -1.0); }).toThrowDeveloperError(); }); it('throws with invalid maximumHeight', function() { var p = new ParticleSystem(); expect(function() { - p.maximumHeight = -1.0; + p.maximumImageSize = new Cartesian2(2.0, -1.0); }).toThrowDeveloperError(); }); - it('throws with invalid lifeTime', function() { + it('throws with invalid lifetime', function() { var p = new ParticleSystem(); expect(function() { - p.lifeTime = -1.0; + p.lifetime = -1.0; }).toThrowDeveloperError(); }); @@ -327,9 +327,8 @@ defineSuite([ scene.primitives.add(new ParticleSystem({ image : greenImage, emitter : new CircleEmitter(1.0), - rate : 10000, - width : 100, - height : 100 + emissoinRate : 10000, + imageSize : new Cartesian2(100, 100) })); scene.camera.position = new Cartesian3(0.0, 0.0, 20.0); scene.camera.direction = new Cartesian3(0.0, 0.0, -1.0); diff --git a/Specs/equals.js b/Specs/equals.js index caeb2a650d39..6d47c07f9016 100644 --- a/Specs/equals.js +++ b/Specs/equals.js @@ -3,25 +3,9 @@ define([ ], function( FeatureDetection) { 'use strict'; - /*global CanvasPixelArray*/ - - var typedArrayTypes = []; - - // Earlier versions of IE do not support typed arrays - if (FeatureDetection.supportsTypedArrays()) { - typedArrayTypes.push(Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array); - - if (typeof Uint8ClampedArray !== 'undefined') { - typedArrayTypes.push(Uint8ClampedArray); - } - - if (typeof CanvasPixelArray !== 'undefined') { - typedArrayTypes.push(CanvasPixelArray); - } - } function isTypedArray(o) { - return typedArrayTypes.some(function(type) { + return FeatureDetection.typedArrayTypes.some(function(type) { return o instanceof type; }); }