# 粒子系统创建工厂

粒子系统创建工厂(ParticleSystemFactory)主要是为了配合粒子系统模板使用,提供粒子渲染器、粒子属性初始化器、粒子行为控制器、粒子位置初始区域的构造方法注册以及通过模板创建粒子系统等相关接口。

# 接口

🌏 registerRenderer 注册粒子渲染器构造方法

import { ParticleSystemFactory, SpriteParticleRenderer } from '@tx3d/particlesystem';

// 注册SpriteParticleRenderer
ParticleSystemFactory.registerRenderer( 'Sprite', SpriteParticleRenderer );
1
2
3
4

🌏 registerInitializer 注册粒子属性初始化器构造方法

import { ColorInitializer, ParticleSystemFactory } from '@tx3d/particlesystem';

// 注册ColorInitializer
ParticleSystemFactory.registerInitializer( 'Color', ColorInitializer );
1
2
3
4

🌏 registerBehaviour 注册粒子行为控制器构造方法

import { AlphaBehaviour, ParticleSystemFactory } from '@tx3d/particlesystem';

// 注册AlphaBehaviour
ParticleSystemFactory.registerBehaviour( 'Alpha', AlphaBehaviour );
1
2
3
4

🌏 registerZone

import { BoxZone, ParticleSystemFactory } from '@tx3d/particlesystem';

// 注册BoxZone
ParticleSystemFactory.registerZone( 'Box', BoxZone );
1
2
3
4

🌏 load 加载模板文件创建粒子系统

import { ParticleSystem, ParticleSystemFactory } from '@tx3d/particlesystem';

// 创建实体
const entity = engine.createEntity();

// 加载粒子模板
ParticleSystemFactory.load( entity, './assets/jsons/particles/rain.json' ).then( ( particleSystem: ParticleSystem ) => {

    // 加载成功回调

}, ( error ) => {

    // 加载失败回调

} );
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

🌏 create 通过模板数据创建粒子系统

import { AssetsManager } from '@tx3d/core';
import { ParticleSystemFactory } from '@tx3d/particlesystem';

// 加载模板文件
AssetsManager.loadFile( './assets/jsons/particles/rain.json' ).then( ( data ) => {

    // 创建实体
    const entity = engine.createEntity();

    // 创建粒子系统
    const particleSystem = ParticleSystemFactory.create( entity, JSON.parse( data ) );

} );
1
2
3
4
5
6
7
8
9
10
11
12
13
Last Updated: 9/18/2023, 3:24:59 PM