Update particle-system.ts (#13615)

Even if the rateOverDistance is 0, it will still get the world position and calculate the distance, which is waste. To improve performance, only if the rateOverDistance is above 0, it would get the world position and calculate the distance
This commit is contained in:
iwae
2022-12-01 14:43:41 +08:00
committed by GitHub
parent dff52ce66f
commit 9566f88ba5
+7 -4
View File
@@ -1389,10 +1389,13 @@ export class ParticleSystem extends ModelRenderer {
}
// emit by rateOverDistance
this.node.getWorldPosition(this._curWPos);
const distance = Vec3.distance(this._curWPos, this._oldWPos);
Vec3.copy(this._oldWPos, this._curWPos);
this._emitRateDistanceCounter += distance * this.rateOverDistance.evaluate(this._time / this.duration, 1)!;
const rateOverDistance = this.rateOverDistance.evaluate(this._time / this.duration, 1)!;
if (rateOverDistance > 0) {
Vec3.copy(this._oldWPos, this._curWPos);
this.node.getWorldPosition(this._curWPos);
const distance = Vec3.distance(this._curWPos, this._oldWPos);
this._emitRateDistanceCounter += distance * rateOverDistance;
}
if (this._emitRateDistanceCounter > 1) {
const emitNum = Math.floor(this._emitRateDistanceCounter);