Skip to content

Particle Emitter Module

The particle emitter module is an essential component of a particle system that defines and controls the emission behavior of particles. It determines the initial position, velocity, direction, and other properties of particles, thus influencing the overall effect of the particle system.

Usage

The emitter module is a required module for the particle simulator. The following code demonstrates how to add an emitter module to a particle simulator:

ts
let emitter = simulator.addModule(ParticleEmitterModule);
// Set the maximum number of particles
emitter.maxParticle = 10000;
// Set the duration of emission
emitter.duration = 10;
// Set the emission rate (number of particles per second)
emitter.emissionRate = 1000;
// Set the particle's lifecycle size
emitter.startLifecycle.setScalar(1);
// Set the shape type of the emitter
emitter.shapeType = ShapeType.Box;
// Set the size of the emitter's shape
emitter.boxSize = new Vector3(10, 10, 10);
// Set the emission location on the shape
emitter.emitLocation = EmitLocation.Edge;

The particle emitter module, ParticleEmitterModule includes several important emission parameters. Each parameter has the following significance:

NameDescription
maxParticleMaximum number of particles
durationDuration of particle emission (in seconds)
emissionRateEmission rate (number of particles per second)
startLifecycleParticle lifecycle (in seconds)
shapeTypeEmitter shape (e.g., circle, rectangle, sphere, cone)
emitLocationEmission location (based on entity, surface, edge)
angleAngle (applicable when the emitter shape is a cone)
radiusRadius (applicable when the emitter shape is a circle, sphere, or cone)
boxSizeSize of the rectangle/box shape

WebGPU is not supported in your browser
Please upgrade to latest Chrome/Edge

<
ts
import { Engine3D, AtmosphericComponent, Vector3, View3D, HoverCameraController, Object3D, PlaneGeometry, Scene3D, CameraUtil, webGPUContext } from '@orillusion/core';
import { ParticleSystem, ParticleMaterial, ParticleStandardSimulator, ParticleEmitterModule, ShapeType, EmitLocation } from '@orillusion/particle';

class Sample_ParticleEmitter {
    async run() {
        await Engine3D.init();

        let scene = new Scene3D();
        scene.addComponent(AtmosphericComponent).sunY = 0.6;

        let camera = CameraUtil.createCamera3DObject(scene);
        camera.perspective(60, webGPUContext.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;
        Engine3D.startRenderView(view);
    }

    async initScene(scene: Scene3D) {
        // 创建实体对象
        let obj = new Object3D();
        scene.addChild(obj);

        // 添加粒子系统组件
        let particleSystem = obj.addComponent(ParticleSystem);

        // 设置粒子材质
        let material = new ParticleMaterial();
        material.baseMap = await Engine3D.res.loadTexture('https://cdn.orillusion.com/particle/fx_a_glow_003.png');

        // 设置粒子形状
        particleSystem.geometry = new PlaneGeometry(1, 1, 1, 1, Vector3.Z_AXIS);
        particleSystem.material = material;

        // 使用指定仿真器
        let simulator = particleSystem.useSimulator(ParticleStandardSimulator);

        // 添加发射器模块
        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;

        // 开始播放
        particleSystem.play();
    }
}

new Sample_ParticleEmitter().run();