[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 / 04-operations.mdx
2.3 kB 103 lines
1import LoftDemo from './components/LoftDemo.astro' 2 3# Operations 4 5Standalone functions for combining and manipulating meshes. 6 7## merge 8 9Combine multiple meshes into one. Automatically normalizes attributes (colors, UVs, normals) and handles mixed indexed/non-indexed geometry. 10 11```ts 12import { merge, box, sphere } from 'shapecraft' 13 14const combined = merge( 15 box().translate(-1, 0, 0), 16 sphere().translate(1, 0, 0), 17) 18``` 19 20## center 21 22Recenter a mesh's bounding box to the origin. 23 24```ts 25import { center } from 'shapecraft' 26const centered = center(mesh) 27``` 28 29## clone 30 31Deep copy a mesh. 32 33```ts 34import { clone } from 'shapecraft' 35const copy = clone(mesh) 36``` 37 38## loft, tube & thicken 39 40<LoftDemo /> 41 42### loft 43 44Sweep a 2D cross-section along a 3D path. The cross-section is oriented using rotation-minimizing frames (or a fixed `up` vector). 45 46```ts 47import { loft } from 'shapecraft' 48 49// Fixed cross-section 50loft({ 51 path: [[0,0,0], [0,1,0], [0.5,2,0]], 52 shape: [[-0.1,0], [0.1,0], [0,0.1]], 53}) 54 55// Varying cross-section (tapered leaf shape) 56loft({ 57 path: frondPath, 58 shape: (t) => { 59 const w = 0.3 * (1 - t) 60 return [[-w, 0], [0, w*0.3], [w, 0]] 61 }, 62 closedShape: false, // open cross-section (no bottom) 63 closed: false, // no end caps 64 up: [0, 1, 0], // keep cross-section aligned to world up 65}) 66``` 67 68Options: 69- `shape` — `[x,y][]` or `(t: number) => [x,y][]` for varying along path 70- `closed` — cap the ends (default `true`) 71- `closedShape` — connect last shape point to first (default `true`) 72- `up` — reference up vector for consistent orientation (default: auto) 73 74### tube 75 76Shorthand for circular loft — sweep a radius along a path. Great for branches, vines, trunks. 77 78```ts 79import { tube } from 'shapecraft' 80 81// Fixed radius 82tube([[0,0,0], [0,1,0], [0.3,2,0]], 0.05, 6) 83 84// Tapered — radius function of t (0-1 along path) 85tube(path, (t) => 0.1 * (1 - t), 6) 86 87// Palm trunk with bulge waves 88tube(path, (t) => { 89 const taper = 0.1 * (1 - t * 0.6) 90 const wave = 1 + Math.sin(t * Math.PI * 14) * 0.15 91 return taper * wave 92}, 5) 93``` 94 95### thicken 96 97Give a flat mesh depth by duplicating it, offsetting along normals, and stitching boundary edges. Works best with indexed geometry (e.g. from `loft`). 98 99```ts 100import { thicken } from 'shapecraft' 101 102const leaf = thicken(flatLeafMesh, 0.02) 103```