이 실험에 대해
격자 파티클을 Constraint로 연결해 천을 시뮬레이션한다. 상단 3개 포인트가 고정되고, 나머지는 중력과 주변 바람에 흔들린다. 마우스를 가까이 가져가면 그 방향으로 바람이 분다.
핵심 코드
// 격자 파티클 간 Constraint 연결
Constraint.create({
bodyA: particles[row][col],
bodyB: particles[row][col + 1],
length: spacingX,
stiffness: 0.6, // 낮을수록 더 흐물흐물
})
// 마우스 위치 기반 척력
const dist = distance(particle, mouse)
const influence = Math.max(0, 1 - dist / 120)
Body.applyForce(p, p.position, {
x: (dx / dist) * influence * 0.00018,
})