|
@@ -51038,7 +51038,11 @@ var BABYLON;
|
|
|
* Creates a new instance of @see Particle
|
|
|
* @param particleSystem the particle system the particle belongs to
|
|
|
*/
|
|
|
- function Particle(particleSystem) {
|
|
|
+ function Particle(
|
|
|
+ /**
|
|
|
+ * particleSystem the particle system the particle belongs to.
|
|
|
+ */
|
|
|
+ particleSystem) {
|
|
|
this.particleSystem = particleSystem;
|
|
|
/**
|
|
|
* The world position of the particle in the scene.
|
|
@@ -51084,15 +51088,18 @@ var BABYLON;
|
|
|
if (!this.particleSystem.isAnimationSheetEnabled) {
|
|
|
return;
|
|
|
}
|
|
|
+ this.updateCellInfoFromSystem();
|
|
|
+ }
|
|
|
+ Particle.prototype.updateCellInfoFromSystem = function () {
|
|
|
this.cellIndex = this.particleSystem.startSpriteCellID;
|
|
|
if (this.particleSystem.spriteCellChangeSpeed == 0) {
|
|
|
- this.updateCellIndex = this.updateCellIndexWithSpeedCalculated;
|
|
|
+ this.updateCellIndex = this._updateCellIndexWithSpeedCalculated;
|
|
|
}
|
|
|
else {
|
|
|
- this.updateCellIndex = this.updateCellIndexWithCustomSpeed;
|
|
|
+ this.updateCellIndex = this._updateCellIndexWithCustomSpeed;
|
|
|
}
|
|
|
- }
|
|
|
- Particle.prototype.updateCellIndexWithSpeedCalculated = function (scaledUpdateSpeed) {
|
|
|
+ };
|
|
|
+ Particle.prototype._updateCellIndexWithSpeedCalculated = function (scaledUpdateSpeed) {
|
|
|
// (ageOffset / scaledUpdateSpeed) / available cells
|
|
|
var numberOfScaledUpdatesPerCell = ((this.lifeTime - this.age) / scaledUpdateSpeed) / (this.particleSystem.endSpriteCellID + 1 - this.cellIndex);
|
|
|
this._currentFrameCounter += scaledUpdateSpeed;
|
|
@@ -51104,7 +51111,7 @@ var BABYLON;
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
- Particle.prototype.updateCellIndexWithCustomSpeed = function () {
|
|
|
+ Particle.prototype._updateCellIndexWithCustomSpeed = function () {
|
|
|
if (this._currentFrameCounter >= this.particleSystem.spriteCellChangeSpeed) {
|
|
|
this.cellIndex++;
|
|
|
this._currentFrameCounter = 0;
|
|
@@ -51321,6 +51328,40 @@ var BABYLON;
|
|
|
this._stopped = false;
|
|
|
this._actualFrame = 0;
|
|
|
this._vertexBufferSize = 11;
|
|
|
+ // start of sub system methods
|
|
|
+ /**
|
|
|
+ * "Recycles" one of the particle by copying it back to the "stock" of particles and removing it from the active list.
|
|
|
+ * Its lifetime will start back at 0.
|
|
|
+ */
|
|
|
+ this.recycleParticle = function (particle) {
|
|
|
+ var lastParticle = _this._particles.pop();
|
|
|
+ if (lastParticle !== particle) {
|
|
|
+ lastParticle.copyTo(particle);
|
|
|
+ }
|
|
|
+ _this._stockParticles.push(lastParticle);
|
|
|
+ };
|
|
|
+ this._createParticle = function () {
|
|
|
+ var particle;
|
|
|
+ if (_this._stockParticles.length !== 0) {
|
|
|
+ particle = _this._stockParticles.pop();
|
|
|
+ particle.age = 0;
|
|
|
+ particle.cellIndex = _this.startSpriteCellID;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ particle = new BABYLON.Particle(_this);
|
|
|
+ }
|
|
|
+ return particle;
|
|
|
+ };
|
|
|
+ this._emitFromParticle = function (particle) {
|
|
|
+ if (!_this.subEmitters || _this.subEmitters.length === 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var templateIndex = Math.floor(Math.random() * _this.subEmitters.length);
|
|
|
+ var subSystem = _this.subEmitters[templateIndex].clone(_this.name + "_sub", particle.position.clone());
|
|
|
+ subSystem._rootParticleSystem = _this;
|
|
|
+ _this.activeSubSystems.push(subSystem);
|
|
|
+ subSystem.start();
|
|
|
+ };
|
|
|
this._appendParticleVertexes = null;
|
|
|
this.id = name;
|
|
|
this.name = name;
|
|
@@ -51354,6 +51395,7 @@ var BABYLON;
|
|
|
var particle = particles[index];
|
|
|
particle.age += _this._scaledUpdateSpeed;
|
|
|
if (particle.age >= particle.lifeTime) {
|
|
|
+ _this._emitFromParticle(particle);
|
|
|
_this.recycleParticle(particle);
|
|
|
index--;
|
|
|
continue;
|
|
@@ -51475,6 +51517,7 @@ var BABYLON;
|
|
|
configurable: true
|
|
|
});
|
|
|
Object.defineProperty(ParticleSystem.prototype, "particles", {
|
|
|
+ //end of Sub-emitter
|
|
|
/**
|
|
|
* Gets the current list of active particles
|
|
|
*/
|
|
@@ -51506,18 +51549,6 @@ var BABYLON;
|
|
|
this._indexBuffer = this._scene.getEngine().createIndexBuffer(indices);
|
|
|
};
|
|
|
/**
|
|
|
- * "Recycles" one of the particle by copying it back to the "stock" of particles and removing it from the active list.
|
|
|
- * Its lifetime will start back at 0.
|
|
|
- * @param particle The particle to recycle
|
|
|
- */
|
|
|
- ParticleSystem.prototype.recycleParticle = function (particle) {
|
|
|
- var lastParticle = this._particles.pop();
|
|
|
- if (lastParticle !== particle) {
|
|
|
- lastParticle.copyTo(particle);
|
|
|
- this._stockParticles.push(lastParticle);
|
|
|
- }
|
|
|
- };
|
|
|
- /**
|
|
|
* Gets the maximum number of particles active at the same time.
|
|
|
* @returns The max number of active particles.
|
|
|
*/
|
|
@@ -51545,13 +51576,22 @@ var BABYLON;
|
|
|
this._started = true;
|
|
|
this._stopped = false;
|
|
|
this._actualFrame = 0;
|
|
|
+ if (this.subEmitters && this.subEmitters.length != 0) {
|
|
|
+ this.activeSubSystems = new Array();
|
|
|
+ }
|
|
|
};
|
|
|
/**
|
|
|
* Stops the particle system.
|
|
|
+ * @param stopSubEmitters if true it will stop the current system and all created sub-Systems if false it will stop the current root system only, this param is used by the root particle system only. the default value is true.
|
|
|
*/
|
|
|
- ParticleSystem.prototype.stop = function () {
|
|
|
+ ParticleSystem.prototype.stop = function (stopSubEmitters) {
|
|
|
+ if (stopSubEmitters === void 0) { stopSubEmitters = true; }
|
|
|
this._stopped = true;
|
|
|
+ if (stopSubEmitters) {
|
|
|
+ this._stopSubEmitters();
|
|
|
+ }
|
|
|
};
|
|
|
+ // animation sheet
|
|
|
/**
|
|
|
* Remove all active particles
|
|
|
*/
|
|
@@ -51602,6 +51642,25 @@ var BABYLON;
|
|
|
this._vertexData[offset + 10] = offsetY;
|
|
|
this._vertexData[offset + 11] = particle.cellIndex;
|
|
|
};
|
|
|
+ ParticleSystem.prototype._stopSubEmitters = function () {
|
|
|
+ if (!this.activeSubSystems) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.activeSubSystems.forEach(function (subSystem) {
|
|
|
+ subSystem.stop(true);
|
|
|
+ });
|
|
|
+ this.activeSubSystems = new Array();
|
|
|
+ };
|
|
|
+ ParticleSystem.prototype._removeFromRoot = function () {
|
|
|
+ if (!this._rootParticleSystem) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var index = this._rootParticleSystem.activeSubSystems.indexOf(this);
|
|
|
+ if (index !== -1) {
|
|
|
+ this._rootParticleSystem.activeSubSystems.splice(index, 1);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ // end of sub system methods
|
|
|
ParticleSystem.prototype._update = function (newParticles) {
|
|
|
// Update current
|
|
|
this._alive = this._particles.length > 0;
|
|
@@ -51621,14 +51680,7 @@ var BABYLON;
|
|
|
if (this._particles.length === this._capacity) {
|
|
|
break;
|
|
|
}
|
|
|
- if (this._stockParticles.length !== 0) {
|
|
|
- particle = this._stockParticles.pop();
|
|
|
- particle.age = 0;
|
|
|
- particle.cellIndex = this.startSpriteCellID;
|
|
|
- }
|
|
|
- else {
|
|
|
- particle = new BABYLON.Particle(this);
|
|
|
- }
|
|
|
+ particle = this._createParticle();
|
|
|
this._particles.push(particle);
|
|
|
var emitPower = BABYLON.Scalar.RandomRange(this.minEmitPower, this.maxEmitPower);
|
|
|
if (this.startPositionFunction) {
|
|
@@ -51751,6 +51803,9 @@ var BABYLON;
|
|
|
if (this._vertexBuffer) {
|
|
|
this._vertexBuffer.update(this._vertexData);
|
|
|
}
|
|
|
+ if (this.manualEmitCount === 0 && this.disposeOnStop) {
|
|
|
+ this.stop();
|
|
|
+ }
|
|
|
};
|
|
|
ParticleSystem.prototype._appenedParticleVertexesWithSheet = function (offset, particle) {
|
|
|
this._appendParticleVertexWithAnimation(offset++, particle, 0, 0);
|
|
@@ -51837,6 +51892,7 @@ var BABYLON;
|
|
|
this.particleTexture.dispose();
|
|
|
this.particleTexture = null;
|
|
|
}
|
|
|
+ this._removeFromRoot();
|
|
|
// Remove from scene
|
|
|
var index = this._scene.particleSystems.indexOf(this);
|
|
|
if (index > -1) {
|
|
@@ -51903,6 +51959,7 @@ var BABYLON;
|
|
|
this.particleEmitterType = particleEmitter;
|
|
|
return particleEmitter;
|
|
|
};
|
|
|
+ // Clone
|
|
|
/**
|
|
|
* Clones the particle system.
|
|
|
* @param name The name of the cloned object
|
|
@@ -111032,15 +111089,15 @@ var BABYLON;
|
|
|
if (babylonMesh._delayInfo.indexOf(kind) === -1) {
|
|
|
babylonMesh._delayInfo.push(kind);
|
|
|
}
|
|
|
+ if (attribute === "COLOR_0") {
|
|
|
+ // Assume vertex color has alpha on the mesh. The alphaMode of the material controls whether the material should use alpha or not.
|
|
|
+ babylonMesh.hasVertexAlpha = true;
|
|
|
+ }
|
|
|
var accessor = GLTFLoader._GetProperty(context + "/attributes/" + attribute, _this._gltf.accessors, attributes[attribute]);
|
|
|
promises.push(_this._loadAccessorAsync("#/accessors/" + accessor._index, accessor).then(function (data) {
|
|
|
var attributeData = GLTFLoader._ConvertToFloat32Array(context, accessor, data);
|
|
|
- if (attribute === "COLOR_0") {
|
|
|
- // Assume vertex color has alpha on the mesh. The alphaMode of the material controls whether the material should use alpha or not.
|
|
|
- babylonMesh.hasVertexAlpha = true;
|
|
|
- if (accessor.type === "VEC3") {
|
|
|
- attributeData = GLTFLoader._ConvertVec3ToVec4(context, attributeData);
|
|
|
- }
|
|
|
+ if (attribute === "COLOR_0" && accessor.type === "VEC3") {
|
|
|
+ attributeData = GLTFLoader._ConvertVec3ToVec4(context, attributeData);
|
|
|
}
|
|
|
babylonVertexData.set(attributeData, kind);
|
|
|
}));
|
|
@@ -111898,6 +111955,8 @@ var BABYLON;
|
|
|
if (babylonMaterial && babylonMeshes) {
|
|
|
for (var _b = 0, babylonMeshes_1 = babylonMeshes; _b < babylonMeshes_1.length; _b++) {
|
|
|
var babylonMesh = babylonMeshes_1[_b];
|
|
|
+ // Ensure nonUniformScaling is set if necessary.
|
|
|
+ babylonMesh.computeWorldMatrix(true);
|
|
|
promises.push(babylonMaterial.forceCompilationAsync(babylonMesh));
|
|
|
if (this.useClipPlane) {
|
|
|
promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true }));
|