depthview-mcp 0.2.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,175 @@
1
+ # How award-level 3D sites are built
2
+
3
+ What separates igloo.inc, organimo.com and their peers from an ordinary three.js page. Read this
4
+ before planning a 3D site, then the topic files for each part.
5
+
6
+ ## The short version
7
+
8
+ They are not built from more geometry or more effects. They are built from:
9
+
10
+ 1. **Baked assets.** Lighting, ambient occlusion and detail are computed offline (Blender,
11
+ Houdini) and shipped as textures. The browser draws them; it does not compute them.
12
+ 2. **One custom material per hero object**, written or patched in GLSL, not a stack of stock
13
+ materials.
14
+ 3. **A tiny draw-call count.** Organimo was measured at about 15 draw calls per frame. Fifteen.
15
+ 4. **One art-directed post-processing chain**, tuned in the browser, the same on every section.
16
+ 5. **Motion that never stops and never jumps**: damped scroll, damped pointer, eased camera.
17
+ 6. **A loading sequence that hides every hitch**: shaders compiled and textures uploaded before
18
+ the first reveal.
19
+
20
+ ## Case: igloo.inc (Abeto, with Bureaux; Awwwards Site of the Year)
21
+
22
+ From the studio's own case study:
23
+
24
+ - **Tools.** 3D and textures in Houdini and Blender. Code: three.js, three-mesh-bvh, Svelte
25
+ (for the little DOM there is), GSAP, Vite, plain JavaScript. No React.
26
+ - **Ice blocks are procedural.** A custom algorithm "grows" ice crystals inside a base shape
27
+ (cube, cylinder), offline. Every project gets its own block. The result ships as geometry
28
+ through **custom geometry exporters**, written to cut load time.
29
+ - **Volumes without slice sheets.** They wrote an exporter that turns VDB volume data into a
30
+ browser format and compress it: smaller than an ordinary image. Not a strip of 2D slices.
31
+ - **Particles follow shapes.** The link section is a particle simulation that flows into the
32
+ shape of each model, coloured by speed, glowing while it changes shape. Sound follows the
33
+ motion.
34
+ - **The interface is drawn in WebGL**, not HTML: text is SDF glyphs, so a text scramble is an
35
+ offset into the glyph texture and a glitch is a small shader. No style recalculation, no
36
+ layout cost.
37
+ - **Scene transitions are shader effects**: chromatic aberration, a "tech" displacement, a
38
+ frost effect.
39
+ - **The intro is real time**, animated in code and shaders. No video file.
40
+ - **Loading.** Textures are loaded and shaders compiled in stages, some during the first load
41
+ and some in the background, so nothing stalls when a section first appears.
42
+ - **Workflow.** Their own tools reload shaders, textures and models while the page runs, and
43
+ they measure frame rate on low-end devices during development, not at the end.
44
+
45
+ ## Case: organimo.com (Unseen Studio)
46
+
47
+ No official write-up. Measured by third parties: three.js r151, WebGL 2, about 15 draw calls
48
+ per frame, a WordPress site with the scene in the theme. What can be seen on the page: one
49
+ product scene carried through the whole scroll, liquid and organic shader motion, a strong
50
+ grade. The lesson is in the draw-call count: a scene that looks rich is a handful of merged
51
+ meshes with baked textures and custom shaders.
52
+
53
+ ## The pipeline, step by step
54
+
55
+ | Step | What they do | In this project |
56
+ | ---------------- | --------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
57
+ | Look development | Model and light in Blender or Houdini. Decide the look there. | `compare_to_reference` against a still from that render |
58
+ | Baking | Bake lighting and AO into textures (lightmap, or everything into the base colour). Bake normals from high-poly to low-poly. | Materials become `MeshBasicMaterial` + baked map, or a custom shader |
59
+ | Export | glTF with Draco or Meshopt geometry, KTX2 (Basis) textures. Merge everything that shares a material. | `get_resources`, `get_performance` to check the result |
60
+ | Material | One shader per hero object: baked light plus the few live things (fresnel, a moving highlight, a reveal) | `patch_shader`, `set_shader`, `add_effect kind:"custom"` |
61
+ | Atmosphere | Particles, fog, dust, light shafts: cheap, they sell depth and scale | `add_effect` |
62
+ | Motion | Scroll drives a timeline, the camera follows a curve, everything is damped | `get_camera_path`, `edit_camera_path` |
63
+ | Final image | One post chain: AA, bloom on HDR highlights only, grade, grain, vignette | `set_look effects`, `get_realism` |
64
+ | Hardening | Test on a phone, cap pixel ratio, adaptive quality, preload and precompile | `audit_visuals`, `set_viewport`, `lighten_look` |
65
+
66
+ ## What makes it feel expensive
67
+
68
+ - **Light with a direction.** One key light with a clear direction, a weaker fill, a rim from
69
+ behind. Even on baked scenes the highlight should move a little with the pointer.
70
+ - **Roughness variation.** A surface with one roughness value looks like plastic. A roughness
71
+ map (fingerprints, wear, brushed lines) or `set_surface detail` gives it life.
72
+ - **Fresnel everywhere.** Edges facing away from the camera are brighter and more reflective.
73
+ A rim term in a custom shader costs one dot product.
74
+ - **Depth cues.** Fog that takes the background colour, dust in the air, depth of field on a
75
+ hero shot. Without them the scene reads as a flat cut-out.
76
+ - **A restrained palette.** Two or three colours, one accent. Grade the whole frame so the
77
+ scene and the page share it.
78
+ - **Grain and dither.** A little noise hides banding in dark gradients and ties CG to the page.
79
+ - **Type and UI at the same level.** The 3D can only look as good as the typography on top
80
+ of it. Give the HTML the same care (or draw it in WebGL like igloo).
81
+ - **Sound**, when there is any, follows the motion.
82
+
83
+ ## Motion rules
84
+
85
+ - Never bind the camera straight to `scrollY`. Bind a **target** to scroll and move the camera
86
+ towards it: `current += (target - current) * (1 - Math.exp(-dt * 6))`. Frame-rate
87
+ independent, no jumps on a mouse wheel.
88
+ - Smooth scroll with Lenis (or a virtual scroll like igloo) so wheel steps become a curve.
89
+ - The camera travels a curve (`CatmullRomCurve3`) and looks at a second curve. Edit both as
90
+ keys: `edit_camera_path`.
91
+ - Ease everything: `power2.inOut` or `expo.out`, never linear. Durations 0.8 to 1.6 s for
92
+ camera moves, 0.3 to 0.6 s for UI.
93
+ - Idle motion: a slow float, a breathing light, dust. A frame where nothing moves looks broken.
94
+ - Pointer parallax of a few degrees, damped.
95
+ - Respect `prefers-reduced-motion`: cut the camera travel, keep the fades.
96
+
97
+ ### Is the scroll camera cinematic? Measure it
98
+
99
+ `audit_camera_motion` scrolls the page in even steps, reads the camera at each and reports what
100
+ an editor would mark on the shot. Run it after every change to the camera path.
101
+
102
+ | Issue | What the visitor sees | Fix in the source |
103
+ | ------------ | ------------------------------------------- | -------------------------------------------------------------- |
104
+ | `jump` | A pop in the middle of a move | Put the stray key on its neighbours' curve; overlap hand-overs |
105
+ | `abrupt` | A move that starts or stops dead | Ease both ends (smoothstep, `power2.inOut`), never linear |
106
+ | `reversal` | Scrolling forward takes the camera backward | Remove the overshooting key; start a shot where the last ended |
107
+ | `wag` | The view swings left, right, left | One smooth look-at line per shot; turn one way |
108
+ | `whip` | A spin too fast to read | Under about 12° of turn per 1% of scroll; give it more scroll |
109
+ | `roll` | A tilted horizon | `lookAt` with up (0, 1, 0), not a slerp of rotations |
110
+ | `dead` | Scrolling and nothing answers | A slow push-in during the hold, or a shorter section |
111
+ | `busy` | Travel, turn and zoom all at once | One idea per shot; hold the lens |
112
+ | `zoom-pump` | The lens breathing in and out | One field of view per scene; change it at a cut |
113
+ | `idle-drift` | The frame moving while the hand is still | Keep sway under 0.5°; mute it while scrolling |
114
+
115
+ #### Measured on live sites (27 November 2026, 48 scroll steps, headless Chrome)
116
+
117
+ | Site | Score | Total turn | Lens (field of view) | Speed variation | Cuts | Holds |
118
+ | ------------ | ----- | ---------- | -------------------- | --------------- | ---- | ------------- |
119
+ | organimo.com | 91 | 403° | 34.7° to 42.1° | 0.49 | 4 | 19% of scroll |
120
+ | igloo.inc | 59 | 93° | 30° fixed | 0.90 | 0 | none |
121
+
122
+ What the two have in common, and a scene that feels restless does not:
123
+
124
+ - **Little turning.** Under about 400° of turn over the whole page. A page that turns the camera
125
+ 1,500° or more is showing the visitor the move, not the subject.
126
+ - **One lens.** igloo never changes its field of view; organimo stays inside 8°. Change the lens at
127
+ a cut.
128
+ - **One move per shot.** organimo is: hold, one long pan with a slow zoom, cut, hold, cut, hold,
129
+ cut, one long push-in. Four moves for the whole page.
130
+ - **Cuts between set-ups, not flights.** To get from one framing to a far one, cut (through black,
131
+ a flash, a cloud). A fast flight between two set-ups is the move the visitor did not ask for.
132
+ - **Even speed.** Speed variation under 1: the camera does not lurch.
133
+
134
+ igloo's lower score comes from a repeated back-and-forth at each section boundary (every 12.5% of
135
+ scroll). The page scrolls by wheel steps that the tool has to steer, so part of that may be the
136
+ steering and not the site: on such a page read `confidence`, and check the flagged stops by eye.
137
+
138
+ A cut is not a fault: it is listed under `shots`. Hide it in black, a flash or a cloud. The tool
139
+ does not know the subject, so framing is judged by eye: `set_scroll` to each of `checkAt` and
140
+ `take_screenshot view:"site"`. Show only what the story needs: every shot is a push-in, a pan, an
141
+ orbit or a hold, and a shot that is none of these is a move to delete.
142
+
143
+ ## Loading rules
144
+
145
+ - Show the first frame only when it is complete: `await renderer.compileAsync(scene, camera)`
146
+ (r158 and later), then one hidden render to upload textures, then the reveal.
147
+ - Split the scene: what the first screen needs, then the rest in the background while the
148
+ visitor reads.
149
+ - KTX2 textures stay compressed on the GPU: a 2048² texture is about 2.7 MB of video memory
150
+ as ETC1S/UASTC instead of 22 MB as PNG. Draco or Meshopt for geometry.
151
+ - A real progress number (bytes or assets), not a fake timer. Reveal with a transition that
152
+ belongs to the site.
153
+ - Target: under 3 s to first frame on fast 4G, under 5 MB for the first screen, 60 fps on a
154
+ mid-range laptop, 30 fps stable on a three-year-old phone.
155
+
156
+ ## When asked to build "a site like igloo.inc"
157
+
158
+ Do not copy their models, textures, shaders or layout: learn the method, make something of
159
+ the user's own.
160
+
161
+ 1. Agree on the hero object and the journey (three to five scroll stations) before any code.
162
+ 2. `create_scene` for the scaffold. Get a real model in early (`find_assets`, `import_asset`,
163
+ or the user's own glTF), then `adapt_model`.
164
+ 3. Light and grade live: `fix_realism`, `set_look`, `set_surface`. Compare with a reference.
165
+ 4. Give the hero object one custom touch with `patch_shader` (fresnel rim, reveal, frost).
166
+ 5. Add atmosphere with `add_effect` (dust, fog, snow). Subtle.
167
+ 6. Camera path: `edit_camera_path`, preview, save.
168
+ 7. Harden: `audit_visuals` with `scroll: [0, 25, 50, 75, 100]`, `get_performance`,
169
+ `set_viewport` at phone size, `lighten_look`.
170
+ 8. Write everything into the source: `save_look`, `save_camera_path`, `get_effect_code`,
171
+ `apply_changes_to_code`.
172
+
173
+ Be honest about the gap: the last 20% of those sites is weeks of asset work in Houdini and
174
+ Blender by technical artists. Code gets the lighting, materials, atmosphere, motion and
175
+ polish right; it cannot invent a sculpted hero asset. Say so, and ask for the asset.
@@ -0,0 +1,190 @@
1
+ # The Depthview extension: what the developer sees
2
+
3
+ Read this before telling the developer where to click, and when a tool result looks wrong for
4
+ no reason in the scene. `get_inspector_state` reports the current state of everything below.
5
+ Use the names here exactly: they are the labels on screen.
6
+
7
+ ## Opening and closing
8
+
9
+ - Click the Depthview icon in Chrome's toolbar to open the inspector on the current tab. Click
10
+ it again, press `Esc`, or use **Exit** to close.
11
+ - A page that was open before the extension was installed or reloaded must be reloaded first:
12
+ the three.js hook has to be on the page before the site's own code runs. `get_status` then
13
+ shows `sceneAvailable: false`, and `get_inspector_state` says the hook is missing.
14
+ - On exit every live change is put back, unless **Keep changes on the page after exit** is
15
+ ticked. Either way nothing is in the source until it is written there.
16
+ - Sites on the WebGPU renderer, other engines, or with no three.js show the page as flat
17
+ layers only: there is no scene to read.
18
+
19
+ ## The window
20
+
21
+ | Part | What is in it |
22
+ | ------------ | ----------------------------------------------------------------------------------- |
23
+ | Top | The mode switch (layer view / scene view), **Live preview**, **Exit** |
24
+ | Left toolbar | The pointer tools (below) |
25
+ | Centre | The view: the page as layers, or the 3D scene |
26
+ | Side panel | Tabs: **Inspect**, **Realism**, **Perf**, **Resources**, **Animate**, **Learn** |
27
+ | Bottom bar | The scroll timeline, **Record scroll**, the **View** switches, view angles and zoom |
28
+
29
+ ### Left toolbar
30
+
31
+ | Tool | Does |
32
+ | ---------------------- | --------------------------------------------------------------- |
33
+ | Rotate view | Drag to orbit |
34
+ | Pan | Right-drag, or `Space` + drag |
35
+ | Zoom | Wheel, or drag up and down |
36
+ | Select an object | Click an object in the view |
37
+ | Fly | Hold `W` `A` `S` `D`, `Q` / `E`, drag to look (scene view only) |
38
+ | Select the site camera | Selects the camera the site renders with |
39
+ | Select the next light | Steps through the scene's lights |
40
+
41
+ ### Bottom bar
42
+
43
+ - **Scroll** slider (also `Shift` + wheel over the view): scrolls the real site. A wheel-driven
44
+ site (no native page scroll) moves stop by stop.
45
+ - **Record scroll**: scrolls the page top to bottom and draws the camera path with a marker per
46
+ section. Needed before **Edit camera path**.
47
+ - **View** switches:
48
+
49
+ | Switch | On means | Matters to your tools |
50
+ | ----------------- | ------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
51
+ | **Site pipeline** | The site draws through its own passes, post-processing included. Off: a raw draw, and the site stops drawing | Off: `get_performance` counts no draw calls, `audit_visuals` cannot read a real frame, effects are not seen through the site's passes. **Ask for it to be on.** |
52
+ | **Follow camera** | The inspector's camera keeps its offset from the site camera as it travels | No |
53
+ | **Helpers** | Outlines and icons for cameras and lights | Shows in `take_screenshot view:"scene"`, not in `view:"site"` |
54
+ | **HTML plane** | The page's HTML drawn as a plane in front of the site camera, with a distance slider | Same |
55
+ | **Grid** | A ground grid | Same |
56
+ | **Wireframe** | Every mesh as wireframe | Scene screenshots show wireframes |
57
+ | **Site hover** | Pointer moves over the view are passed to the site, so its hover effects play | No |
58
+
59
+ - View angles: front (`F`), side (`S`), back (`B`), zoom in and out, and back to the site's own
60
+ view (`R`).
61
+
62
+ ### Top
63
+
64
+ - **Live preview**: hides the inspector and shows the real page through the site's own camera,
65
+ HTML included. `Esc` comes back. This is what `take_screenshot view:"site"` captures.
66
+
67
+ ## Side panel tabs
68
+
69
+ ### Inspect
70
+
71
+ - **Camera path**: appears after **Record scroll**. **Edit camera path** turns the recording
72
+ into a few points; click one in the view, drag its orange handle to move the camera or its
73
+ cyan handle to change where it looks. Add a point at the current scroll, delete (`Delete`),
74
+ undo. **Preview on site** puts the site camera on the edited path; **Site camera view** looks
75
+ through it. Then save as `camera-path.json`, or copy as code.
76
+ - **Scene tree**: every object. Click to select. From a row an object can be shown alone
77
+ (isolate): everything else is hidden until it is turned off, in screenshots too. A
78
+ **Scenes** picker appears when the site draws several scenes; Auto shows the one on screen.
79
+ - **Properties** of the selection: **Transform** (Position, Rotation°, Scale), **Material**
80
+ (Colour, Roughness, Metalness, Opacity, Emissive, shader uniforms), **Light** (Colour,
81
+ Intensity, Distance, Decay, Angle°, Penumbra), **Camera** (FOV, Near, Far, Zoom). Drag a
82
+ field's letter to scrub, or type. The material's shader and its graph can be opened from
83
+ here; a texture slot can try an image of the developer's own.
84
+ - Gizmo: `W` move, `E` rotate, `Q` off.
85
+ - Changes: **Undo** (`Ctrl/Cmd+Z`), **Reset changes**, **Copy as R3F** (JSX, plain three.js
86
+ or JSON, with original and new values), **Copy for AI** (a message listing each change with
87
+ file and line: works without the MCP server), **Apply to code** (writes through the local
88
+ server), **Keep changes on the page after exit**.
89
+ - **AI agent & code sync (local)**: **Port** and **Pairing code**. This is where the developer
90
+ types the code from `get_status`. Shows the edits sent to the server and their status.
91
+
92
+ What the developer changes here by hand reaches you through `get_changes`, and their selection
93
+ through `get_object` with no arguments.
94
+
95
+ ### Realism
96
+
97
+ The look, by hand: the same object `get_realism` and `set_look` work on.
98
+
99
+ - The **check**: a score out of 100, each issue with a one-click fix.
100
+ - **Colour & sharpness**: tone mapping, Exposure, Full resolution, Sharp textures, Smooth 1×
101
+ screens.
102
+ - **World lighting**: studio presets made of light boxes; drag a light on the top-down pad;
103
+ Turn rotates them all; Reflections strength; Show behind the scene.
104
+ - **Shadows**, **Surface** (presets, Roughness, Metallic, Clear coat, Glass, and fine
105
+ **Detail** drawn as a normal map), **Edges** (Bevel this object, Amount).
106
+ - **Lens & effects**: Smooth edges, Ambient occlusion, Bloom, Depth of field, Vignette, Film
107
+ grain. Locked until the project has the dev bridge (`depthviewVite()`).
108
+ - **Performance**: frames per second with the look and without, what each part costs,
109
+ **Lighten**, **Step down on slow devices**.
110
+ - **Models**: each model with size, triangles, textures; **Adapt**, **Set down**, **Scale**.
111
+ - **Match a reference**: drop in a picture of the look wanted.
112
+ - **Your site's controls**: values the site declares with `depthviewControls`.
113
+ - **Save to project** writes `depthview-look.json`.
114
+
115
+ The developer may change the look while you work: call `get_realism` again before building on
116
+ an earlier result.
117
+
118
+ ### Perf
119
+
120
+ Frames per second, Frame time, Long frames, Draw calls, Triangles, Render passes, JS memory,
121
+ and the render calls of one frame. The same numbers as `get_performance`.
122
+
123
+ ### Resources
124
+
125
+ Textures, Geometries and Materials with memory and how many objects use each; selecting a row
126
+ selects an object that uses it. The same as `get_resources`.
127
+
128
+ ### Animate
129
+
130
+ Hold and step the site's clock (the same as `set_time`), and camera keyframes; edits can be
131
+ saved to and loaded from a JSON file.
132
+
133
+ ### Learn
134
+
135
+ **How it's made**: what the site is **Built with**, its techniques with **How to build it**
136
+ and what to **Look up**, **Motion** and **Renderer**. For learning how a site works; it does
137
+ not export the site's models, textures or code. **Ask AI how this is made** opens the built-in
138
+ assistant.
139
+
140
+ ## The built-in assistant
141
+
142
+ A chat panel inside the inspector, separate from you. It answers with the developer's own
143
+ Anthropic API key, or a limited number of free questions. It is the only part of the extension
144
+ that sends anything to the network, and only when asked a question. You do not control it and
145
+ do not see its conversation.
146
+
147
+ ## Layer view
148
+
149
+ Every site, 3D or not. The page is captured as layers (background, 3D scene, HTML, fixed UI)
150
+ that can be rotated and pulled apart (**Separate layers**, `L`). **Whole page (every scroll
151
+ stop)** captures up to 8 screens; **Recapture** after the page changes. Hover the HTML layer to
152
+ highlight elements, click one for its styles. `M` switches between layer view and scene view.
153
+
154
+ ## Keyboard
155
+
156
+ | Key | Action |
157
+ | -------------------------- | ------------------------------------- |
158
+ | `Esc` | Exit (closes an open dialog first) |
159
+ | `M` | Layer view / scene view |
160
+ | `F` / `S` / `B` | Front / side / back |
161
+ | `R` | Reset to the site's own view |
162
+ | `L` | Separate layers |
163
+ | `W` / `E` / `Q` | Gizmo: move / rotate / off |
164
+ | `Delete` | Remove the selected camera-path point |
165
+ | `Ctrl/Cmd+Z` | Undo |
166
+ | `Space` + drag, right-drag | Pan |
167
+ | `Shift` + wheel | Scroll the site |
168
+
169
+ ## What you can and cannot do to the inspector
170
+
171
+ - You can: select an object for the developer (`select_object`, which also switches to the
172
+ scene view), scroll (`set_scroll`), hold the clock (`set_time`), change the look, add
173
+ effects, record and edit the camera path. They see each of these happen.
174
+ - You cannot: flip the **View** switches, change tabs, isolate an object, open the assistant,
175
+ or tick **Keep changes on the page after exit**. Ask the developer, with the name of the
176
+ switch and where it is.
177
+ - With `open_preview` there is no inspector at all: none of this applies, and the page runs as
178
+ a visitor gets it.
179
+
180
+ ## When a result looks wrong: check these first
181
+
182
+ | Result | Likely switch |
183
+ | ----------------------------------------------------------- | ------------------------------------------------------------------------------ |
184
+ | `get_performance` shows 0 draw calls | **Site pipeline** is off |
185
+ | `audit_visuals` reports a blank frame on a scene that shows | **Site pipeline** off, or the tab is not in front |
186
+ | A screenshot shows one object on its own | An object is isolated in the scene tree |
187
+ | A screenshot is all lines | **Wireframe** is on |
188
+ | `set_value` on the camera does nothing | A camera-path preview is driving the camera |
189
+ | `take_screenshot` fails or is black | The tab is not in front, or the window is minimised |
190
+ | Object ids no longer work | The page reloaded (a source edit hot-reloaded the scene): `find_objects` again |
@@ -0,0 +1,198 @@
1
+ # Modelling the subject in code
2
+
3
+ When there is no model file, the subject is built from three.js geometry. That is not a
4
+ second-best: a product made of turned, extruded and bevelled parts is exactly what these
5
+ classes produce, and it loads in no time. What it cannot do is organic sculpture (a face, an
6
+ animal, cloth): ask for a model there, or `find_assets`.
7
+
8
+ Check signatures with `three_docs { name }`; defaults below are from r187.
9
+
10
+ ## Think like a workshop
11
+
12
+ Take the object apart into pieces that a machine could make:
13
+
14
+ | The piece is | Made with |
15
+ | ---------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
16
+ | Round about an axis: bottle, cap, glass, knob, ring, column, bowl, lens, wheel | `LatheGeometry` from a profile |
17
+ | A flat outline with thickness: block bottle, phone, card, key, logo, bracket, gear | `ExtrudeGeometry` from a `Shape`, with a bevel |
18
+ | A box with soft edges | `RoundedBoxGeometry`, or an extruded rounded rectangle (better bevel control) |
19
+ | A line with thickness: cable, tube, handle, frame, ribbon | `TubeGeometry` along a `CatmullRomCurve3` |
20
+ | Many of the same: screws, studs, keys, tiles, seeds | `InstancedMesh` |
21
+ | A natural lump: rock, ice, a planet, a pebble | `IcosahedronGeometry(1, 5+)` displaced with noise |
22
+ | Lettering, a logo, a dial | A `CanvasTexture` (colour, `alphaMap` or `bumpMap`) |
23
+
24
+ Each piece is its own mesh with its own material and a `name`, grouped under one `Group`
25
+ whose origin is where the object stands (y = 0 at its base). Then it can be placed, turned
26
+ and grounded as one.
27
+
28
+ ## A profile on a lathe
29
+
30
+ x is the radius (above 0), y the height. Every corner in the profile is an edge on the
31
+ object, so every corner gets two or three points: that is the bevel.
32
+
33
+ ```js
34
+ const profile = [
35
+ [0.0, 0.0],
36
+ [0.3, 0.0], // the base, to the edge
37
+ [0.315, 0.012], // a small chamfer instead of a sharp corner
38
+ [0.315, 0.07],
39
+ [0.3, 0.085], // the wall, and the chamfer at its top
40
+ [0.255, 0.085],
41
+ [0.255, 0.16], // a step in
42
+ [0.0, 0.16], // closed on the axis
43
+ ].map(([r, y]) => new THREE.Vector2(r, y));
44
+ const collar = new THREE.LatheGeometry(profile, 96);
45
+ ```
46
+
47
+ - For a curved body (a vase, a glass) run the control points through
48
+ `new THREE.SplineCurve(points).getPoints(60)` first.
49
+ - Segments round: 96 for something seen whole, 128 to 160 for a close-up.
50
+ - A lathe's UVs run round the axis. A texture on a flat top comes out as radial streaks:
51
+ for that mesh write the UVs from the positions
52
+ (`uv.setXY(i, pos.getX(i) * k, pos.getZ(i) * k)`).
53
+ - The normals at a sharp profile corner are averaged and shade as a soft roll. For a crisp
54
+ edge either keep the chamfer points close together, or
55
+ `BufferGeometryUtils.toCreasedNormals(geometry, Math.PI / 6)`.
56
+
57
+ ## An outline, extruded and bevelled
58
+
59
+ ```js
60
+ const roundedRect = (w, d, r) => {
61
+ const s = new THREE.Shape();
62
+ const x = -w / 2,
63
+ y = -d / 2;
64
+ s.moveTo(x + r, y);
65
+ s.lineTo(x + w - r, y);
66
+ s.absarc(x + w - r, y + r, r, -Math.PI / 2, 0);
67
+ s.lineTo(x + w, y + d - r);
68
+ s.absarc(x + w - r, y + d - r, r, 0, Math.PI / 2);
69
+ s.lineTo(x + r, y + d);
70
+ s.absarc(x + r, y + d - r, r, Math.PI / 2, Math.PI);
71
+ s.lineTo(x, y + r);
72
+ s.absarc(x + r, y + r, r, Math.PI, Math.PI * 1.5);
73
+ return s;
74
+ };
75
+
76
+ /** A block with rounded corners and a bevel on every edge, standing on y = 0. */
77
+ function block(w, d, h, corner, bevel) {
78
+ const g = new THREE.ExtrudeGeometry(roundedRect(w - bevel * 2, d - bevel * 2, corner), {
79
+ depth: h - bevel * 2,
80
+ bevelEnabled: true,
81
+ bevelThickness: bevel,
82
+ bevelSize: bevel,
83
+ bevelSegments: 8,
84
+ curveSegments: 24,
85
+ });
86
+ g.rotateX(-Math.PI / 2); // extrusion runs along +z: stand it up
87
+ g.translate(0, bevel, 0);
88
+ return g;
89
+ }
90
+ ```
91
+
92
+ - The bevel adds to the outline and to the depth: subtract it from both, as above, to keep
93
+ the outer size.
94
+ - `bevelSegments` 6 to 8 for a round edge that catches a soft line of light; 1 for a hard
95
+ chamfer.
96
+ - Holes: `shape.holes.push(new THREE.Path()...)`. A logo: build the `Shape` from its
97
+ outline, or `SVGLoader` (`three/addons/loaders/SVGLoader.js`) and
98
+ `SVGLoader.createShapes(path)`.
99
+
100
+ ## Detail cut into a surface
101
+
102
+ Real grooves, where the silhouette shows them. Displace the vertices and recompute the
103
+ normals:
104
+
105
+ ```js
106
+ const FLUTES = 120;
107
+ const geo = new THREE.CylinderGeometry(R, R, H, FLUTES * 6, 1, true); // 6 vertices per flute
108
+ const p = geo.attributes.position;
109
+ for (let i = 0; i < p.count; i++) {
110
+ const a = Math.atan2(p.getZ(i), p.getX(i));
111
+ const r = R - 0.011 * (0.5 + 0.5 * Math.cos(a * FLUTES));
112
+ p.setXYZ(i, Math.cos(a) * r, p.getY(i), Math.sin(a) * r);
113
+ }
114
+ geo.computeVertexNormals();
115
+ ```
116
+
117
+ The same idea makes knurling (two crossing sets), threads (the angle plus the height),
118
+ ribs, facets. The count of segments must be several per feature or it aliases into noise.
119
+
120
+ Detail that is too fine for the silhouette goes into a map instead: a `bumpMap` or
121
+ `normalMap` drawn on a canvas (brushed lines, a grid, engraved text), or
122
+ `set_surface detail` which draws it for you.
123
+
124
+ ## A natural shape
125
+
126
+ ```js
127
+ const geo = new THREE.IcosahedronGeometry(1, 6); // even triangles, no pole
128
+ const p = geo.attributes.position;
129
+ const v = new THREE.Vector3();
130
+ for (let i = 0; i < p.count; i++) {
131
+ v.fromBufferAttribute(p, i);
132
+ const n = fbm(v.x * 1.4, v.y * 1.4, v.z * 1.4); // your noise, 3 to 5 octaves
133
+ v.multiplyScalar(1 + n * 0.22);
134
+ p.setXYZ(i, v.x, v.y, v.z);
135
+ }
136
+ geo.deleteAttribute('uv'); // so the seam vertices can be joined
137
+ const rock = BufferGeometryUtils.mergeVertices(geo);
138
+ rock.computeVertexNormals();
139
+ ```
140
+
141
+ - An icosahedron has duplicated vertices along edges: without `mergeVertices` the displaced
142
+ surface cracks and shades in facets.
143
+ - `three/addons/math/ImprovedNoise.js` and `SimplexNoise.js` are in the package.
144
+ - Faceted on purpose (a crystal, low-poly): `flatShading: true`, detail 0 to 2, and stretch
145
+ the shape (`geo.scale(1, 1.8, 1)`) so it is not a ball.
146
+ - Liquid, blobs, anything that must move every frame: displace in the vertex shader
147
+ (`patch_shader` on `#include <begin_vertex>`), not on the CPU.
148
+
149
+ ## Surface, drawn on a canvas
150
+
151
+ ```js
152
+ function labelTexture() {
153
+ const c = document.createElement('canvas');
154
+ c.width = c.height = 1024;
155
+ const x = c.getContext('2d');
156
+ x.fillStyle = '#000';
157
+ x.fillRect(0, 0, 1024, 1024); // black: cut out
158
+ x.fillStyle = '#fff';
159
+ x.textAlign = 'center'; // white: ink
160
+ x.font = "300 118px 'Cormorant Garamond', Georgia, serif";
161
+ x.letterSpacing = '34px';
162
+ x.fillText('NOCTUA', 512, 470);
163
+ const t = new THREE.CanvasTexture(c);
164
+ t.anisotropy = 8;
165
+ return t; // use as alphaMap
166
+ }
167
+ ```
168
+
169
+ - Wait for `document.fonts.ready` before drawing, or the label is set in the fallback font.
170
+ - As `map` the texture is colour: `texture.colorSpace = THREE.SRGBColorSpace`. As
171
+ `alphaMap`, `bumpMap`, `roughnessMap` it is data: leave it.
172
+ - Tiling noise for stone, concrete, leather: value noise summed over octaves into
173
+ `ImageData`, wrapped by taking the lattice coordinates modulo the period, then
174
+ `RepeatWrapping` and `repeat`.
175
+ - 1024 for a label seen close, 512 for a tiling surface. `anisotropy` 8 for anything seen
176
+ at a slant.
177
+
178
+ ## What makes it read as real
179
+
180
+ - **Bevels on every edge**, 2 to 5% of the piece's size.
181
+ - **Thickness.** Glass has a thick foot; a cap has a lid and a skirt; a ring has an inside.
182
+ A single surface with no thickness looks like paper.
183
+ - **Parts that meet with a small gap or a step**, not flush: a collar between cap and
184
+ bottle, a seam, a foot. The shadow in the gap is free detail.
185
+ - **Imperfection in the surface, not the shape**: a faint bump, a brushed direction, a
186
+ variation in colour towards the edges. Never in the silhouette of a manufactured object.
187
+ - **Real proportions.** Look the object up: a 50 ml bottle is about 6 × 3.5 × 9 cm, its cap
188
+ a third of the height. Keep those ratios in scene units.
189
+ - **Shadows on the pieces**: `castShadow` on each part, `receiveShadow` on what it stands on.
190
+ - Name every mesh. Under 60 draw calls for a product: merge what shares a material and never
191
+ moves apart (`BufferGeometryUtils.mergeGeometries`).
192
+
193
+ ## When to stop modelling and ask for a file
194
+
195
+ A recognisable real product (a specific shoe, phone, car), anything organic, anything with
196
+ many small parts (a watch movement). Say what code can and cannot do, build the set, light
197
+ and motion around a stand-in of the right size, and take the glTF when it comes:
198
+ `import_asset` or the user's file, then `adapt_model`.