From 838c38cb50d682b205733b779a50983a6d94166e Mon Sep 17 00:00:00 2001 From: Forrest Sun Date: Mon, 9 Sep 2024 21:41:11 -0700 Subject: [PATCH] fix clone bug on stretched billboard --- CHANGELOG.md | 2 ++ .../three.quarks/examples/explosionDemo.js | 36 +++++++++++++------ packages/three.quarks/package.json | 2 +- packages/three.quarks/src/ParticleSystem.ts | 5 +++ 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c65f2a3..f2cc7fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,6 @@ # Change Log +## Version 0.15.5 +- Fix stretched billboard settings are not cloned in clone function ## Version 0.15.4 - Fix 1 frame lag bug when parent entity of a particle system is moved diff --git a/packages/three.quarks/examples/explosionDemo.js b/packages/three.quarks/examples/explosionDemo.js index 7faa7f8..a9fd4d6 100644 --- a/packages/three.quarks/examples/explosionDemo.js +++ b/packages/three.quarks/examples/explosionDemo.js @@ -8,24 +8,40 @@ import {Demo} from './demo.js'; export class ExplosionDemo extends Demo { name = 'explosion (Unity Exported)'; refreshTime = 2; + loadedEffect = null; + + newInstance() { + function listener(event) { + console.log(event.type); + } + const effect = this.loadedEffect.clone(true); + QuarksUtil.runOnAllParticleEmitters(effect, (emitter) => { + emitter.system.addEventListener("emitEnd", listener); + }) + QuarksUtil.setAutoDestroy(effect, true); + QuarksUtil.addToBatchRenderer(effect, this.batchRenderer); + QuarksUtil.play(effect); + this.scene.add(effect); + } + + + render(delta) { + if (this.totalTime + delta > this.refreshTime) { + this.newInstance(); + } + super.render(delta); + } + initScene() { super.initScene(); this.batchRenderer = new BatchedParticleRenderer(); this.scene.add(this.batchRenderer); - function listener(event) { - console.log(event.type); - } new QuarksLoader().load('ps.json', (obj) => { - QuarksUtil.addToBatchRenderer(obj, this.batchRenderer); - QuarksUtil.runOnAllParticleEmitters(obj, (emitter) => { - emitter.system.addEventListener("emitEnd", listener); - }) - this.scene.add(obj); - this.groups.push(obj); + this.loadedEffect = obj; + this.newInstance(); }); - return this.scene; } } diff --git a/packages/three.quarks/package.json b/packages/three.quarks/package.json index 80d32ae..612882c 100644 --- a/packages/three.quarks/package.json +++ b/packages/three.quarks/package.json @@ -1,6 +1,6 @@ { "name": "three.quarks", - "version": "0.15.4", + "version": "0.15.5", "description": "A General-Purpose Particle System for three.js", "type": "module", "types": "./dist/types/index.d.ts", diff --git a/packages/three.quarks/src/ParticleSystem.ts b/packages/three.quarks/src/ParticleSystem.ts index 11fa85c..1c99870 100644 --- a/packages/three.quarks/src/ParticleSystem.ts +++ b/packages/three.quarks/src/ParticleSystem.ts @@ -1405,6 +1405,11 @@ export class ParticleSystem implements IParticleSystem { startLength: (this.rendererEmitterSettings as TrailSettings).startLength.clone(), followLocalOrigin: (this.rendererEmitterSettings as TrailSettings).followLocalOrigin, }; + } else if (this.renderMode === RenderMode.StretchedBillBoard) { + rendererEmitterSettings = { + lengthFactor: (this.rendererEmitterSettings as StretchedBillBoardSettings).lengthFactor, + speedFactor: (this.rendererEmitterSettings as StretchedBillBoardSettings).speedFactor, + }; } else { rendererEmitterSettings = {}; }