-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add QuarksUtil class to simplify controlling of particle systems.
- Loading branch information
1 parent
12ad577
commit 9dce462
Showing
5 changed files
with
90 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import {Object3D} from 'three'; | ||
import {ParticleEmitter} from './ParticleEmitter'; | ||
import {BatchedRenderer} from './BatchedRenderer'; | ||
|
||
|
||
export class QuarksUtil { | ||
/** | ||
* Run a function on all particle emitters in the object and the object's children. | ||
* @param obj | ||
* @param func | ||
*/ | ||
static runOnAllParticleEmitters(obj: Object3D, func: (ps: ParticleEmitter) => void) { | ||
obj.traverse((child) => { | ||
if (child.type === 'ParticleEmitter') { | ||
func(child as ParticleEmitter); | ||
} | ||
}); | ||
if (obj.type === 'ParticleEmitter') { | ||
func(obj as ParticleEmitter); | ||
} | ||
} | ||
|
||
/** | ||
* Add all particle systems in the object and the object's children to the batch renderer. | ||
* @param obj | ||
* @param batchRenderer | ||
*/ | ||
static addToBatchRenderer(obj: Object3D, batchRenderer: BatchedRenderer) { | ||
QuarksUtil.runOnAllParticleEmitters(obj, (ps) => { | ||
batchRenderer.addSystem(ps.system); | ||
}); | ||
} | ||
|
||
/** | ||
* Start playing all particle systems in the object and the object's children. | ||
* @param obj | ||
*/ | ||
static play(obj: Object3D) { | ||
QuarksUtil.runOnAllParticleEmitters(obj, (ps) => { | ||
ps.system.play(); | ||
}); | ||
} | ||
|
||
/** | ||
* Stop all particle systems in the object and the object's children. | ||
* this call will clear all existing particles. | ||
* @param obj | ||
*/ | ||
static stop(obj: Object3D) { | ||
QuarksUtil.runOnAllParticleEmitters(obj, (ps) => { | ||
ps.system.stop(); | ||
}); | ||
} | ||
|
||
/** | ||
* Stop emit new particles from all particle systems and | ||
* keep simulating the existing particles in the object and the object's children. | ||
* @param obj | ||
*/ | ||
static endEmit(obj: Object3D) { | ||
QuarksUtil.runOnAllParticleEmitters(obj, (ps) => { | ||
ps.system.endEmit(); | ||
}); | ||
} | ||
|
||
/** | ||
* Restart all particle systems in the object and the object's children. | ||
* @param obj | ||
*/ | ||
static restart(obj: Object3D) { | ||
QuarksUtil.runOnAllParticleEmitters(obj, (ps) => { | ||
ps.system.restart(); | ||
}); | ||
} | ||
|
||
/** | ||
* Pause the simulation of all particle systems in the object and the object's children. | ||
* @param obj | ||
*/ | ||
static pause(obj: Object3D) { | ||
QuarksUtil.runOnAllParticleEmitters(obj, (ps) => { | ||
ps.system.restart(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters