Emitter Module
The emitter module is an important part of the particle system, used to define and control the emission behavior of particles. It determines the initial position, speed, direction, and other properties of particles in space, thereby affecting the effect of the entire particle system.
Usage
The emitter module is a required module of the particle simulator. The following code shows how to add an emitter module to the particle simulator:
ts
let emitter = simulator.addModule(ParticleEmitterModule);
// Set the maximum number of particles
emitter.maxParticle = 10000;
// Set the continuous emission duration
emitter.duration = 10;
// Set the emission rate (x particles/second)
emitter.emissionRate = 1000;
// Set the particle lifecycle
emitter.startLifecycle.setScalar(1);
// Set the emission shape of the emitter
emitter.shapeType = ShapeType.Box;
// Set the size of the emitter's emission shape
emitter.boxSize = new Vector3(10, 10, 10);
// Set from which position of the emission shape the emitter emits
emitter.emitLocation = EmitLocation.Edge;The particle emitter module ParticleEmitterModule contains some important emission parameters. The function of each parameter is as follows:
| Name | Description |
|---|---|
| maxParticle | Maximum number of particles |
| duration | Particle emission duration (unit: seconds) |
| emissionRate | Emission rate (how many particles are emitted per second) |
| startLifecycle | Particle lifecycle (unit: seconds) |
| shapeType | Emitter shape (circle, rectangle, sphere, cone) |
| emitLocation | Emission location (based on entity, surface, edge) |
| angle | Angle (valid when the emitter shape is a cone) |
| radius | Radius (valid when the emitter shape is a circle, sphere, or cone) |
| boxSize | Rectangle/box size |
ts
import { Engine3D, AtmosphericComponent, Vector3, View3D, HoverCameraController, Object3D, PlaneGeometry, Scene3D, CameraUtil } from '@orillusion/core';
import { ParticleSystem, ParticleMaterial, ParticleStandardSimulator, ParticleEmitterModule, ShapeType, EmitLocation } from '@orillusion/particle';
class Sample_ParticleEmitter {
engine: Engine3D;
async run() {
this.engine = await Engine3D.init();
let scene = new Scene3D();
scene.addComponent(AtmosphericComponent).sunY = 0.6;
let camera = CameraUtil.createCamera3DObject(scene);
camera.perspective(60, this.engine.aspect, 0.1, 5000.0);
let ctrl = camera.object3D.addComponent(HoverCameraController);
ctrl.setCamera(45, -15, 30);
await this.initScene(scene);
let view = new View3D();
view.scene = scene;
view.camera = camera;
this.engine.startRenderView(view);
}
async initScene(scene: Scene3D) {
// create entity object
let obj = new Object3D();
scene.addChild(obj);
// add particle system component
let particleSystem = obj.addComponent(ParticleSystem);
// set particle material
let material = new ParticleMaterial();
material.baseMap = await this.engine.res.loadTexture('https://cdn.orillusion.com/particle/fx_a_glow_003.png');
// set particle geometry
particleSystem.geometry = new PlaneGeometry(1, 1, 1, 1, Vector3.Z_AXIS);
particleSystem.material = material;
// use the specified simulator
let simulator = particleSystem.useSimulator(ParticleStandardSimulator);
// add the emitter module
let emitter = simulator.addModule(ParticleEmitterModule);
emitter.maxParticle = 1 * 10000;
emitter.duration = 10;
emitter.emissionRate = 1000;
emitter.startLifecycle.setScalar(1);
emitter.shapeType = ShapeType.Box;
emitter.boxSize = new Vector3(10, 10, 10);
emitter.emitLocation = EmitLocation.Edge;
// start playing
particleSystem.play();
}
}
new Sample_ParticleEmitter().run();
