增加涡流修改器
This commit is contained in:
1 parent
3f2699a946
commit
5f3a4a33fe
10 files changed
+136
-7
No files matched your search
@@ -6,7 +6,7 @@ import { pickImageResource, pickTrailResource, imageFrameState, imageFrameTextur
|
||||
import type { SceneCollider, EmitterConfig, ParticleState } from './particleTypes'
|
||||
import { defaultConfig, ensureEmitterConfig } from './particleConfig'
|
||||
import { BLEND_MAP, MAX_PARTICLES } from './particleConstants'
|
||||
import { lerp, finite, localToWorldMath, worldMathToLocal, localVelocityToWorldMath, worldVelocityToLocalMath, resolveColliderPoint, tFromLife, seededUnit, initialValue, overLifeValue, curveAt, mulberry32, hexToNumber, gradientColorAt } from './particleMath'
|
||||
import { lerp, finite, localToWorldMath, worldMathToLocal, localVelocityToWorldMath, worldVelocityToLocalMath, resolveColliderPoint, tFromLife, seededUnit, initialValue, overLifeValue, curveAt, mulberry32, hexToNumber, gradientColorAt, fieldFalloff, vortexAcceleration } from './particleMath'
|
||||
|
||||
// 保留原有入口,现有调用方无需随内部拆分修改。
|
||||
export type * from './particleTypes'
|
||||
@@ -258,9 +258,7 @@ export class ParticleEmitter extends Container {
|
||||
const dy = cfg.forceCenterY - particleWorldY
|
||||
const distance = Math.hypot(dx, dy)
|
||||
if (distance > 0.0001 && distance <= cfg.forceRadius) {
|
||||
let falloff = 1
|
||||
if (cfg.forceFalloff === 'linear') falloff = 1 - distance / cfg.forceRadius
|
||||
else if (cfg.forceFalloff === 'inverse') falloff = Math.min(10, cfg.forceRadius / Math.max(distance, cfg.forceRadius * 0.1))
|
||||
const falloff = fieldFalloff(cfg.forceFalloff, distance, cfg.forceRadius)
|
||||
const force = cfg.forceStrength * falloff * 10
|
||||
const accelWorldX = dx / distance * force
|
||||
const accelWorldY = dy / distance * force
|
||||
@@ -270,6 +268,18 @@ export class ParticleEmitter extends Container {
|
||||
p.vy += (-sinRoot * accelScreenX + cosRoot * accelScreenY) / rootScaleY * dt
|
||||
}
|
||||
}
|
||||
// 漩涡力在全局数学坐标中沿半径切线方向作用。
|
||||
if (!p.collisionPaused && cfg.vortex && cfg.vortexStrength !== 0 && cfg.vortexRadius > 0) {
|
||||
const world = localToWorldMath(cfg, p.x, p.y, this.simulationTransform)
|
||||
const acceleration = vortexAcceleration(
|
||||
world.x, world.y,
|
||||
cfg.vortexCenterX, cfg.vortexCenterY,
|
||||
cfg.vortexStrength, cfg.vortexRadius, cfg.vortexFalloff,
|
||||
)
|
||||
const localAcceleration = worldVelocityToLocalMath(cfg, acceleration.x, acceleration.y, this.simulationTransform)
|
||||
p.vx += localAcceleration.x * dt
|
||||
p.vy += localAcceleration.y * dt
|
||||
}
|
||||
// 阻尼:速度按衰减系数逐渐减小
|
||||
if (!p.collisionPaused && cfg.damping > 0) {
|
||||
const f = Math.max(0, 1 - cfg.damping * dt)
|
||||
|
||||
Reference in new issue
Block a user