|
@@ -50479,7 +50479,7 @@ var BABYLON;
|
|
|
*/
|
|
|
this.updateSpeed = 0.01;
|
|
|
/**
|
|
|
- * The amount of time the particle system is running (depends of the overall speed above).
|
|
|
+ * The amount of time the particle system is running (depends of the overall update speed).
|
|
|
*/
|
|
|
this.targetStopDuration = 0;
|
|
|
/**
|
|
@@ -51760,8 +51760,14 @@ var BABYLON;
|
|
|
this._targetIndex = 0;
|
|
|
this._currentRenderId = -1;
|
|
|
this._started = false;
|
|
|
+ this._stopped = false;
|
|
|
this._timeDelta = 0;
|
|
|
this._attributesStrideSize = 14;
|
|
|
+ this._actualFrame = 0;
|
|
|
+ /**
|
|
|
+ * List of animations used by the particle system.
|
|
|
+ */
|
|
|
+ this.animations = [];
|
|
|
/**
|
|
|
* An event triggered when the system is disposed.
|
|
|
*/
|
|
@@ -51771,6 +51777,10 @@ var BABYLON;
|
|
|
*/
|
|
|
this.updateSpeed = 0.01;
|
|
|
/**
|
|
|
+ * The amount of time the particle system is running (depends of the overall update speed).
|
|
|
+ */
|
|
|
+ this.targetStopDuration = 0;
|
|
|
+ /**
|
|
|
* Blend mode use to render the particle, it can be either ParticleSystem.BLENDMODE_ONEONE or ParticleSystem.BLENDMODE_STANDARD.
|
|
|
*/
|
|
|
this.blendMode = BABYLON.ParticleSystem.BLENDMODE_ONEONE;
|
|
@@ -51855,6 +51865,7 @@ var BABYLON;
|
|
|
this._randomTexture = new BABYLON.RawTexture(new Float32Array(d), maxTextureSize, 1, BABYLON.Engine.TEXTUREFORMAT_RGBA32F, this._scene, false, false, BABYLON.Texture.NEAREST_SAMPLINGMODE, BABYLON.Engine.TEXTURETYPE_FLOAT);
|
|
|
this._randomTexture.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
|
|
|
this._randomTexture.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
|
|
|
+ this._randomTextureSize = maxTextureSize;
|
|
|
}
|
|
|
Object.defineProperty(GPUParticleSystem, "IsSupported", {
|
|
|
/**
|
|
@@ -51869,16 +51880,13 @@ var BABYLON;
|
|
|
enumerable: true,
|
|
|
configurable: true
|
|
|
});
|
|
|
- Object.defineProperty(GPUParticleSystem.prototype, "capacity", {
|
|
|
- /**
|
|
|
- * Gets the maximum number of particles supported by this system
|
|
|
- */
|
|
|
- get: function () {
|
|
|
- return this._capacity;
|
|
|
- },
|
|
|
- enumerable: true,
|
|
|
- configurable: true
|
|
|
- });
|
|
|
+ /**
|
|
|
+ * Gets the maximum number of particles active at the same time.
|
|
|
+ * @returns The max number of active particles.
|
|
|
+ */
|
|
|
+ GPUParticleSystem.prototype.getCapacity = function () {
|
|
|
+ return this._capacity;
|
|
|
+ };
|
|
|
Object.defineProperty(GPUParticleSystem.prototype, "activeParticleCount", {
|
|
|
/**
|
|
|
* Gets or set the number of active particles
|
|
@@ -51904,18 +51912,22 @@ var BABYLON;
|
|
|
*/
|
|
|
GPUParticleSystem.prototype.start = function () {
|
|
|
this._started = true;
|
|
|
+ this._stopped = false;
|
|
|
};
|
|
|
/**
|
|
|
* Stops the particle system.
|
|
|
*/
|
|
|
GPUParticleSystem.prototype.stop = function () {
|
|
|
- this._started = false;
|
|
|
+ this._stopped = true;
|
|
|
};
|
|
|
/**
|
|
|
- * Animates the particle system for the current frame by emitting new particles and or animating the living ones.
|
|
|
+ * Remove all active particles
|
|
|
*/
|
|
|
- GPUParticleSystem.prototype.animate = function () {
|
|
|
- this._timeDelta = this.updateSpeed * this._scene.getAnimationRatio();
|
|
|
+ GPUParticleSystem.prototype.reset = function () {
|
|
|
+ this._releaseBuffers();
|
|
|
+ this._releaseVAOs();
|
|
|
+ this._currentActiveCount = 0;
|
|
|
+ this._targetIndex = 0;
|
|
|
};
|
|
|
GPUParticleSystem.prototype._createUpdateVAO = function (source) {
|
|
|
var updateVertexBuffers = {};
|
|
@@ -51973,10 +51985,10 @@ var BABYLON;
|
|
|
data.push(0.0);
|
|
|
}
|
|
|
// Sprite data
|
|
|
- var spriteData = new Float32Array([1, 1, 1, 1,
|
|
|
- -1, 1, 0, 1,
|
|
|
- -1, -1, 0, 0,
|
|
|
- 1, -1, 1, 0]);
|
|
|
+ var spriteData = new Float32Array([0.5, 0.5, 1, 1,
|
|
|
+ -0.5, 0.5, 0, 1,
|
|
|
+ -0.5, -0.5, 0, 0,
|
|
|
+ 0.5, -0.5, 1, 0]);
|
|
|
// Buffers
|
|
|
this._buffer0 = new BABYLON.Buffer(engine, data, false, this._attributesStrideSize);
|
|
|
this._buffer1 = new BABYLON.Buffer(engine, data, false, this._attributesStrideSize);
|
|
@@ -52000,10 +52012,27 @@ var BABYLON;
|
|
|
this._updateEffect = new BABYLON.Effect("gpuUpdateParticles", this._updateEffectOptions, this._scene.getEngine());
|
|
|
};
|
|
|
/**
|
|
|
+ * Animates the particle system for the current frame by emitting new particles and or animating the living ones.
|
|
|
+ */
|
|
|
+ GPUParticleSystem.prototype.animate = function () {
|
|
|
+ if (!this._stopped) {
|
|
|
+ this._timeDelta = this.updateSpeed * this._scene.getAnimationRatio();
|
|
|
+ this._actualFrame += this._timeDelta;
|
|
|
+ if (this.targetStopDuration && this._actualFrame >= this.targetStopDuration)
|
|
|
+ this.stop();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this._timeDelta = 0;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ /**
|
|
|
* Renders the particle system in its current state.
|
|
|
* @returns the current number of particles
|
|
|
*/
|
|
|
GPUParticleSystem.prototype.render = function () {
|
|
|
+ if (!this._started) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
if (this.particleEmitterType) {
|
|
|
this._recreateUpdateEffect(this.particleEmitterType.getEffectDefines());
|
|
|
}
|
|
@@ -52088,14 +52117,7 @@ var BABYLON;
|
|
|
GPUParticleSystem.prototype.rebuild = function () {
|
|
|
this._initialize(true);
|
|
|
};
|
|
|
- /**
|
|
|
- * Disposes the particle system and free the associated resources.
|
|
|
- */
|
|
|
- GPUParticleSystem.prototype.dispose = function () {
|
|
|
- var index = this._scene.particleSystems.indexOf(this);
|
|
|
- if (index > -1) {
|
|
|
- this._scene.particleSystems.splice(index, 1);
|
|
|
- }
|
|
|
+ GPUParticleSystem.prototype._releaseBuffers = function () {
|
|
|
if (this._buffer0) {
|
|
|
this._buffer0.dispose();
|
|
|
this._buffer0 = null;
|
|
@@ -52104,6 +52126,12 @@ var BABYLON;
|
|
|
this._buffer1.dispose();
|
|
|
this._buffer1 = null;
|
|
|
}
|
|
|
+ if (this._spriteBuffer) {
|
|
|
+ this._spriteBuffer.dispose();
|
|
|
+ this._spriteBuffer = null;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ GPUParticleSystem.prototype._releaseVAOs = function () {
|
|
|
for (var index = 0; index < this._updateVAO.length; index++) {
|
|
|
this._engine.releaseVertexArrayObject(this._updateVAO[index]);
|
|
|
}
|
|
@@ -52112,6 +52140,17 @@ var BABYLON;
|
|
|
this._engine.releaseVertexArrayObject(this._renderVAO[index]);
|
|
|
}
|
|
|
this._renderVAO = [];
|
|
|
+ };
|
|
|
+ /**
|
|
|
+ * Disposes the particle system and free the associated resources.
|
|
|
+ */
|
|
|
+ GPUParticleSystem.prototype.dispose = function () {
|
|
|
+ var index = this._scene.particleSystems.indexOf(this);
|
|
|
+ if (index > -1) {
|
|
|
+ this._scene.particleSystems.splice(index, 1);
|
|
|
+ }
|
|
|
+ this._releaseBuffers();
|
|
|
+ this._releaseVAOs();
|
|
|
if (this._randomTexture) {
|
|
|
this._randomTexture.dispose();
|
|
|
this._randomTexture = null;
|
|
@@ -52135,6 +52174,43 @@ var BABYLON;
|
|
|
* @returns the JSON object
|
|
|
*/
|
|
|
GPUParticleSystem.prototype.serialize = function () {
|
|
|
+ var serializationObject = {};
|
|
|
+ serializationObject.name = this.name;
|
|
|
+ serializationObject.id = this.id;
|
|
|
+ // Emitter
|
|
|
+ if (this.emitter.position) {
|
|
|
+ var emitterMesh = this.emitter;
|
|
|
+ serializationObject.emitterId = emitterMesh.id;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ var emitterPosition = this.emitter;
|
|
|
+ serializationObject.emitter = emitterPosition.asArray();
|
|
|
+ }
|
|
|
+ serializationObject.capacity = this.getCapacity();
|
|
|
+ if (this.particleTexture) {
|
|
|
+ serializationObject.textureName = this.particleTexture.name;
|
|
|
+ }
|
|
|
+ // Animations
|
|
|
+ BABYLON.Animation.AppendSerializedAnimations(this, serializationObject);
|
|
|
+ // Particle system
|
|
|
+ serializationObject.activeParticleCount = this.activeParticleCount;
|
|
|
+ serializationObject.randomTextureSize = this._randomTextureSize;
|
|
|
+ serializationObject.minSize = this.minSize;
|
|
|
+ serializationObject.maxSize = this.maxSize;
|
|
|
+ serializationObject.minEmitPower = this.minEmitPower;
|
|
|
+ serializationObject.maxEmitPower = this.maxEmitPower;
|
|
|
+ serializationObject.minLifeTime = this.minLifeTime;
|
|
|
+ serializationObject.maxLifeTime = this.maxLifeTime;
|
|
|
+ serializationObject.emitRate = this.emitRate;
|
|
|
+ serializationObject.gravity = this.gravity.asArray();
|
|
|
+ serializationObject.color1 = this.color1.asArray();
|
|
|
+ serializationObject.color2 = this.color2.asArray();
|
|
|
+ serializationObject.colorDead = this.colorDead.asArray();
|
|
|
+ serializationObject.updateSpeed = this.updateSpeed;
|
|
|
+ serializationObject.targetStopDuration = this.targetStopDuration;
|
|
|
+ serializationObject.blendMode = this.blendMode;
|
|
|
+ // Emitters
|
|
|
+ return serializationObject;
|
|
|
};
|
|
|
return GPUParticleSystem;
|
|
|
}());
|