Skip to content

Commit

Permalink
add stop method in particle system and add more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Alchemist0823 committed Jul 1, 2024
1 parent eac8b9b commit 509019b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/quarks.core/src/IParticleSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export interface IParticleSystem {

paused: boolean;
pause(): void;
stop(): void;
play(): void;
restart(): void;

Expand Down
5 changes: 5 additions & 0 deletions packages/quarks.nodes/src/nodes/NodeVFX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ export class NodeVFX implements IParticleSystem {
this.prewarmed = false;
}

stop(): void {
this.restart();
this.pause();
}

pause() {
this.paused = true;
}
Expand Down
19 changes: 19 additions & 0 deletions packages/three.quarks/src/ParticleSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -778,14 +778,29 @@ export class ParticleSystem implements IParticleSystem {
this.prewarmed = false;
}

/**
* Pause the simulation of the particle system
*/
pause() {
this.paused = true;
}

/**
* Unpause the simulation of the particle system
*/
play() {
this.paused = false;
}

/**
* remove all existing particles, reset the particle system
* and pause at the beginning
*/
stop() {
this.restart();
this.pause();
}

private spawn(count: number, emissionState: EmissionState, matrix: Matrix4) {
tempQ.setFromRotationMatrix(matrix as unknown as Matrix4);
const translation = tempV;
Expand Down Expand Up @@ -910,6 +925,10 @@ export class ParticleSystem implements IParticleSystem {
if (this.emitter.parent) this.emitter.parent.remove(this.emitter);
}

/**
* remove all existing particles, reset the particle system
* and restart the particle system
*/
restart() {
this.memory.length = 0;
this.paused = false;
Expand Down

0 comments on commit 509019b

Please sign in to comment.