[READ-ONLY] Mirror of https://github.com/flo-bit/shapecraft. flo-bit.dev/shapecraft/
0

Configure Feed

Select the types of activity you want to include in your feed.

shapecraft / docs / 05-modifiers.mdx
1.3 kB 58 lines
1# Modifiers 2 3Modifiers come in two patterns: 4 5**Warp functions** return a `WarpFn`, used with `mesh.warp(fn)`: 6 7```ts 8import { twist, bend, taper } from 'shapecraft' 9``` 10 11**Mesh-in mesh-out** take and return a Mesh directly: 12 13```ts 14import { smooth } from 'shapecraft' 15``` 16 17## twist 18 19Rotate vertices around an axis proportional to their position along that axis. 20 21```ts 22mesh.warp(twist({ amount: 2 })) // twist around Y (default) 23mesh.warp(twist({ axis: 'x', amount: 1.5 })) 24``` 25 26Higher `amount` = more twist. Works best on geometry with enough segments along the twist axis. 27 28## bend 29 30Curve geometry along an axis. 31 32```ts 33mesh.warp(bend({ amount: 1 })) // bend around Y 34mesh.warp(bend({ axis: 'z', amount: 2 })) 35``` 36 37## taper 38 39Scale vertices perpendicular to an axis based on a curve function. 40 41```ts 42// Linear taper: full size at y=0, half at y=1 43mesh.warp(taper({ curve: (t) => 1 - t * 0.5 })) 44 45// Custom curve along X axis 46mesh.warp(taper({ axis: 'x', curve: (t) => Math.cos(t * Math.PI) })) 47``` 48 49The curve receives the raw coordinate value along the axis. 50 51## smooth 52 53Laplacian smoothing moves each vertex toward the average of its neighbors. 54 55```ts 56const smoothed = smooth(mesh) // 1 iteration 57const verySmooth = smooth(mesh, 5) // 5 iterations 58```