[READ-ONLY] Mirror of https://github.com/flo-bit/shapecraft.
flo-bit.dev/shapecraft/
1.2 kB
52 lines
1import QuickstartDemo from './components/QuickstartDemo.astro'
2
3# Quickstart
4
5## Install
6
7```bash
8npm install shapecraft three
9```
10
11Three.js is a peer dependency — you provide it.
12
13## Basic usage
14
15```ts
16import { box, sphere, merge } from 'shapecraft'
17import { toThreeMesh } from 'shapecraft/three'
18
19const b = box({ size: 1 })
20const s = sphere({ radius: 0.5 }).translate(2, 0, 0)
21const combined = merge(b, s)
22
23const threeMesh = toThreeMesh(combined)
24scene.add(threeMesh)
25```
26
27<QuickstartDemo />
28
29## Core idea
30
31Everything is a `Mesh`. Primitives return meshes. Transforms and modifiers return **new** meshes (immutable). You compose by chaining method calls and merging results.
32
33```ts
34const leg = cylinder({ radius: 0.05, height: 1 })
35 .translate(0, 0.5, 0)
36 .vertexColor('#8B4513')
37
38const seat = box({ width: 1, height: 0.1, depth: 1 })
39 .translate(0, 1, 0)
40 .vertexColor('#A0522D')
41
42const chair = merge(seat, leg.translate(-0.4, 0, -0.4), leg.translate(0.4, 0, -0.4),
43 leg.translate(-0.4, 0, 0.4), leg.translate(0.4, 0, 0.4))
44```
45
46## Running the demo
47
48```bash
49npm run dev
50```
51
52Opens a Vite dev server with a demo scene at `http://localhost:5173`.