粒子行为模拟 (Simulation)
Simulation 通常指的是通过脚本对粒子系统进行扩展和控制的方式。例如,可以通过编写脚本来改变粒子的颜色、大小、速度等属性,或者根据游戏状态动态调整粒子系统的参数。这使得粒子效果能够响应游戏逻辑,增加互动性。
常用行为模拟类
施加力 ApplyForce
模拟行为类型名称: ApplyForce
| 属性 | 类型 | 描述 |
|---|---|---|
| direction | vec3 | 方向(不会归一化,向量长度会直接乘进加速度,需要时自行 normalize()) |
| magnitude | value | 力大小——实际是加速度:每帧 velocity += direction × magnitude × delta(与粒子质量无关) |
噪声 Noise
模拟行为类型名称: Noise
| 属性 | 类型 | 描述 |
|---|---|---|
| frequency | value | |
| power | value | |
| positionAmount | value | |
| rotationAmount | value |
振荡力场 TurbulenceField
模拟行为类型名称: TurbulenceField
| 属性 | 类型 | 描述 |
|---|---|---|
| scale | vec3 | |
| octaves | number | 噪声函数的八度数 |
| velocityMultiplier | vec3 | |
| timeScale | vec3 |
重力 GravityForce
模拟行为类型名称: GravityForce
| 属性 | 类型 | 描述 |
|---|---|---|
| center | vec3 | 中心 |
| magnitude | number | 引力强度:粒子朝 center 的加速度 = magnitude / 距离²(距离越近越强) |
生命周期内颜色 ColorOverLife
模拟行为类型名称: ColorOverLife
| 属性 | 类型 | 描述 |
|---|---|---|
| color | colorFunc | 颜色 |
生命周期内旋转 RotationOverLife
模拟行为类型名称: RotationOverLife
| 属性 | 类型 | 描述 |
|---|---|---|
| angularVelocity | valueFunc |
生命周期内旋转3D Rotation3DOverLife
模拟行为类型名称: Rotation3DOverLife
| 属性 | 类型 | 描述 |
|---|---|---|
| angularVelocity | rotationFunc |
生命周期内大小 SizeOverLife
模拟行为类型名称: SizeOverLife
| 属性 | 类型 | 描述 |
|---|---|---|
| size | valueFunc |
颜色随速度变化 ColorBySpeed
模拟行为类型名称: ColorBySpeed
| 属性 | 类型 | 描述 |
|---|---|---|
| color | colorFunc | 颜色 |
| speedRange | range | 速度区间 |
旋转随速度变化 RotationBySpeed
模拟行为类型名称: RotationBySpeed
| 属性 | 类型 | 描述 |
|---|---|---|
| angularVelocity | valueFunc | |
| speedRange | range | 速度区间 |
大小随速度变化 SizeBySpeed
模拟行为类型名称: SizeBySpeed
| 属性 | 类型 | 描述 |
|---|---|---|
| size | valueFunc | |
| speedRange | range | 速度区间 |
生命周期内速度 SpeedOverLife
模拟行为类型名称: SpeedOverLife
| 属性 | 类型 | 描述 |
|---|---|---|
| speed | valueFunc |
生命周期内帧率 FrameOverLife
模拟行为类型名称: FrameOverLife
| 属性 | 类型 | 描述 |
|---|---|---|
| frame | valueFunc |
生命周期内受力 ForceOverLife
模拟行为类型名称: ForceOverLife
| 属性 | 类型 | 描述 |
|---|---|---|
| x | valueFunc | |
| y | valueFunc | |
| z | valueFunc |
OrbitOverLife
模拟行为类型名称: OrbitOverLife
| 属性 | 类型 | 描述 |
|---|---|---|
| orbitSpeed | valueFunc | |
| axis | vec3 |
WidthOverLength
模拟行为类型名称: WidthOverLength
| 属性 | 类型 | 描述 |
|---|---|---|
| width | valueFunc |
改变发射方向 ChangeEmitDirection
模拟行为类型名称: ChangeEmitDirection
| 属性 | 类型 | 描述 |
|---|---|---|
| angle | value |
发射子粒子系统 EmitSubParticleSystem
模拟行为类型名称: EmitSubParticleSystem
| 属性 | 类型 | 描述 |
|---|---|---|
| particleSystem | self | |
| useVelocityAsBasis | boolean | |
| subParticleSystem | ParticleEmitter | 子粒子系统的发射器对象(如 addParticle(...) 的返回值,不是 ParticleSystem) |
| mode | number | 何时发射子粒子:0 = Death(粒子死亡时)、1 = Birth(粒子出生时)、2 = Frame(每帧,默认);可用 vjmap3d.SubParticleEmitMode.Death 等枚举 |
| emitProbability | number |
生命周期内限速 LimitSpeedOverLife
模拟行为类型名称: LimitSpeedOverLife
| 属性 | 类型 | 描述 |
|---|---|---|
| speed | valueFunc | |
| dampen | number | 抑制值 |
应用碰撞 ApplyCollision
模拟行为类型名称: ApplyCollision
| 属性 | 类型 | 描述 |
|---|---|---|
| resolver | PhysicsResolver { resolve(pos: Vector3, normal: Vector3): boolean } |
碰撞求解器对象(注意字段名是 resolver 不是 resolve) |
| bounce | number | 反弹系数(碰撞后速度乘以该值)。必须传数字,传 ValueGenerator(如 new ConstantValue(0.5))会得到 NaN |