Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/flo-bit/shapecraft. flo-bit.dev/shapecraft
Something went wrong. Try again.
958 B · 30 lines
TypeScript
at main
12345678910111213141516171819202122232425262728293031import type { WarpFn, Vec3 } from '../core/types'
export function bend(options: { axis?: 'x' | 'y' | 'z'; amount: number }): WarpFn { const { axis = 'y', amount } = options
return function bendWarp(position: Vec3): Vec3 { const [x, y, z] = position if (amount === 0) return [x, y, z]
if (axis === 'y') { const angle = y * amount const cos = Math.cos(angle) const sin = Math.sin(angle) const radius = 1 / amount + x return [radius * cos - 1 / amount, radius * sin, z] } else if (axis === 'x') { const angle = x * amount const cos = Math.cos(angle) const sin = Math.sin(angle) const radius = 1 / amount + y return [radius * sin, radius * cos - 1 / amount, z] } else { const angle = z * amount const cos = Math.cos(angle) const sin = Math.sin(angle) const radius = 1 / amount + x return [radius * cos - 1 / amount, y, radius * sin] } }}