| 89 | * Force field module for applying external forces to particles |
| 90 | */ |
| 91 | export class ForceFieldModule implements IParticleModule { |
| 92 | readonly name = 'ForceField'; |
| 93 | enabled = true; |
| 94 | |
| 95 | /** 力场列表 | Force field list */ |
| 96 | forceFields: ForceField[] = []; |
| 97 | |
| 98 | /** 发射器位置(运行时设置)| Emitter position (set at runtime) */ |
| 99 | emitterX: number = 0; |
| 100 | emitterY: number = 0; |
| 101 | |
| 102 | /** 时间累计(用于湍流)| Time accumulator (for turbulence) */ |
| 103 | private _time: number = 0; |
| 104 | |
| 105 | /** |
| 106 | * 添加力场 |
| 107 | * Add force field |
| 108 | */ |
| 109 | addForceField(field: ForceField): void { |
| 110 | this.forceFields.push(field); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * 添加风力 |
| 115 | * Add wind force |
| 116 | */ |
| 117 | addWind(directionX: number, directionY: number, strength: number = 100): ForceField { |
| 118 | const field: ForceField = { |
| 119 | type: ForceFieldType.Wind, |
| 120 | enabled: true, |
| 121 | strength, |
| 122 | directionX, |
| 123 | directionY, |
| 124 | }; |
| 125 | this.forceFields.push(field); |
| 126 | return field; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * 添加吸引/排斥点 |
| 131 | * Add attraction/repulsion point |
| 132 | */ |
| 133 | addAttractor(x: number, y: number, strength: number = 100, radius: number = 100): ForceField { |
| 134 | const field: ForceField = { |
| 135 | type: ForceFieldType.Point, |
| 136 | enabled: true, |
| 137 | strength, // 正数=吸引,负数=排斥 | positive=attract, negative=repel |
| 138 | positionX: x, |
| 139 | positionY: y, |
| 140 | radius, |
| 141 | falloff: 'linear', |
| 142 | }; |
| 143 | this.forceFields.push(field); |
| 144 | return field; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * 添加漩涡 |
nothing calls this directly
no outgoing calls
no test coverage detected