@null3d/engine 0.0.0 → 0.1.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.
- package/README.md +109 -0
- package/THIRD-PARTY-NOTICES.txt +0 -1
- package/dist/wasm/single/null3d.js +19 -6
- package/dist/wasm/single/null3d_bg.wasm +0 -0
- package/dist/wasm/threaded/null3d.js +19 -6
- package/dist/wasm/threaded/null3d_bg.wasm +0 -0
- package/docs/api/animation.md +23 -67
- package/docs/api/assets.md +42 -26
- package/docs/api/cameras.md +8 -6
- package/docs/api/controls.md +46 -44
- package/docs/api/debug.md +13 -8
- package/docs/api/engine.md +17 -11
- package/docs/api/feature-draws.md +3 -3
- package/docs/api/feature-effects.md +3 -3
- package/docs/api/feature-instances.md +2 -2
- package/docs/api/features.md +14 -15
- package/docs/api/geometry.md +56 -75
- package/docs/api/grass.md +1 -1
- package/docs/api/impostors.md +120 -9
- package/docs/api/input.md +4 -11
- package/docs/api/lights.md +14 -38
- package/docs/api/lines.md +8 -25
- package/docs/api/materials.md +69 -70
- package/docs/api/math.md +6 -7
- package/docs/api/objects.md +13 -13
- package/docs/api/particles.md +2 -14
- package/docs/api/points.md +3 -25
- package/docs/api/post.md +22 -23
- package/docs/api/quality.md +11 -6
- package/docs/api/raycast.md +13 -32
- package/docs/api/reference/animation.md +9 -9
- package/docs/api/reference/assets.md +18 -18
- package/docs/api/reference/cameras.md +5 -2
- package/docs/api/reference/controls.md +75 -23
- package/docs/api/reference/debug.md +23 -8
- package/docs/api/reference/engine.md +22 -10
- package/docs/api/reference/geometry.md +161 -82
- package/docs/api/reference/grass.md +1 -1
- package/docs/api/reference/impostors.md +92 -1
- package/docs/api/reference/input.md +3 -3
- package/docs/api/reference/lights.md +9 -9
- package/docs/api/reference/lines.md +7 -7
- package/docs/api/reference/materials.md +48 -48
- package/docs/api/reference/math.md +22 -22
- package/docs/api/reference/objects.md +9 -9
- package/docs/api/reference/points.md +4 -4
- package/docs/api/reference/post.md +18 -18
- package/docs/api/reference/quality.md +7 -3
- package/docs/api/reference/raycast.md +6 -6
- package/docs/api/reference/render.md +2 -2
- package/docs/api/reference/scene.md +29 -26
- package/docs/api/reference/sketch.md +4 -0
- package/docs/api/reference/sound.md +203 -0
- package/docs/api/reference/sprites.md +5 -5
- package/docs/api/reference/terrain.md +2 -1
- package/docs/api/reference/textures.md +4 -4
- package/docs/api/reference/ui.md +3 -3
- package/docs/api/reference/vertex-draws.md +3 -3
- package/docs/api/reference/water.md +77 -6
- package/docs/api/reference/wind.md +2 -2
- package/docs/api/render.md +12 -10
- package/docs/api/scene.md +40 -29
- package/docs/api/sketch.md +64 -3
- package/docs/api/sound.md +169 -0
- package/docs/api/splats.md +7 -0
- package/docs/api/sprites.md +4 -20
- package/docs/api/tasks.md +2 -2
- package/docs/api/terrain.md +2 -14
- package/docs/api/textures.md +9 -9
- package/docs/api/ui.md +3 -15
- package/docs/api/water.md +198 -15
- package/docs/api/wind.md +5 -5
- package/docs/cli/null3d.md +93 -18
- package/docs/concepts/architecture.md +10 -10
- package/docs/concepts/assets.md +2 -19
- package/docs/concepts/backends.md +7 -5
- package/docs/concepts/color-management.md +15 -26
- package/docs/concepts/culling.md +1 -1
- package/docs/concepts/instances.md +5 -5
- package/docs/concepts/large-worlds.md +1 -1
- package/docs/concepts/lighting.md +50 -55
- package/docs/concepts/lod.md +2 -15
- package/docs/concepts/materials.md +16 -16
- package/docs/concepts/post-processing.md +7 -29
- package/docs/concepts/quality-preset-tables.md +53 -50
- package/docs/concepts/quality-presets.md +56 -27
- package/docs/concepts/render-graph.md +19 -14
- package/docs/concepts/render-layers.md +3 -17
- package/docs/concepts/shadows.md +10 -28
- package/docs/concepts/static-dynamic.md +2 -2
- package/docs/cookbook/index.md +1 -1
- package/docs/data/threejs-mapping.json +136 -102
- package/docs/errors/E1214.md +3 -3
- package/docs/errors/E1307.md +23 -0
- package/docs/errors/E1420.md +3 -3
- package/docs/errors/index.md +3 -2
- package/docs/getting-started/cdn.md +17 -1
- package/docs/getting-started/first-scene.md +1 -1
- package/docs/getting-started/hosting.md +50 -9
- package/docs/getting-started/install.md +8 -7
- package/docs/getting-started/network-use.md +10 -2
- package/docs/getting-started/project-structure.md +15 -6
- package/docs/getting-started/third-party-notices.md +8 -6
- package/docs/guides/accessibility.md +1 -1
- package/docs/guides/add-ons.md +3 -2
- package/docs/guides/agents.md +16 -5
- package/docs/guides/assets-pipeline.md +13 -12
- package/docs/guides/audio.md +109 -124
- package/docs/guides/car-paint.md +1 -1
- package/docs/guides/content-pages.md +10 -6
- package/docs/guides/custom-passes.md +9 -8
- package/docs/guides/custom-shaders.md +6 -3
- package/docs/guides/debugging.md +78 -4
- package/docs/guides/deploying.md +105 -5
- package/docs/guides/deterministic-simulation.md +1 -1
- package/docs/guides/first-use-shaders.md +4 -4
- package/docs/guides/loading-screens.md +78 -33
- package/docs/guides/multiple-views.md +41 -2
- package/docs/guides/performance.md +6 -3
- package/docs/guides/phones.md +12 -1
- package/docs/guides/physics.md +1 -1
- package/docs/guides/screens.md +7 -5
- package/docs/guides/start-time.md +328 -0
- package/docs/guides/testing.md +23 -5
- package/docs/guides/ui-overlays.md +3 -3
- package/docs/index.md +12 -8
- package/docs/pages.md +26 -23
- package/docs/porting/react-three-fiber.md +228 -5
- package/docs/porting/threejs-loop-and-threads.md +220 -6
- package/docs/porting/threejs-mapping.md +86 -84
- package/docs/porting/threejs-materials.md +212 -5
- package/docs/porting/threejs-overview.md +218 -5
- package/docs/porting/threejs-postprocessing.md +2 -2
- package/docs/porting/threejs-shaders.md +298 -5
- package/docs/porting/threejs-unsupported.md +82 -6
- package/docs/porting/verification.md +181 -5
- package/docs/shaders/builtins.md +1 -1
- package/docs/shaders/library.md +63 -39
- package/docs/shaders/surface-functions.md +11 -10
- package/docs/shaders/wgsl-rules.md +1 -1
- package/lib/debug/channel.d.ts +103 -0
- package/lib/debug/channel.js +269 -0
- package/lib/debug/debug.d.ts +9 -7
- package/lib/debug/draw.d.ts +9 -0
- package/lib/debug/draw.js +49 -2
- package/lib/debug/inspector.d.ts +60 -0
- package/lib/debug/inspector.js +475 -0
- package/lib/debug/stats-panel.d.ts +1 -1
- package/lib/debug/stats.d.ts +2 -3
- package/lib/errors/codes.js +8 -2
- package/lib/errors/engine-error.js +25 -10
- package/lib/errors/fixes.d.ts +1 -0
- package/lib/errors/fixes.js +3 -2
- package/lib/generated/core.d.ts +1 -1
- package/lib/generated/core.js +1 -1
- package/lib/gpu/early-builds.d.ts +68 -0
- package/lib/gpu/early-builds.js +158 -0
- package/lib/gpu/pipeline-name.d.ts +6 -0
- package/lib/gpu/pipeline-name.js +23 -0
- package/lib/gpu/webgl2/backend.d.ts +63 -2
- package/lib/gpu/webgl2/backend.js +226 -8
- package/lib/gpu/webgl2/programs.d.ts +18 -0
- package/lib/gpu/webgl2/programs.js +4 -1
- package/lib/gpu/webgpu/backend.d.ts +89 -2
- package/lib/gpu/webgpu/backend.js +255 -8
- package/lib/gpu/webgpu/pipelines.d.ts +13 -0
- package/lib/gpu/webgpu/pipelines.js +15 -1
- package/lib/index.d.ts +6 -4
- package/lib/index.js +3 -2
- package/lib/math/color.d.ts +5 -5
- package/lib/math/color.js +5 -5
- package/lib/math/mat4.d.ts +6 -12
- package/lib/math/mat4.js +6 -12
- package/lib/math/namespaces/quat.d.ts +3 -3
- package/lib/math/namespaces/quat.js +3 -3
- package/lib/math/quat.d.ts +8 -12
- package/lib/math/quat.js +8 -12
- package/lib/math/random.d.ts +2 -3
- package/lib/math/random.js +2 -3
- package/lib/math/types.d.ts +4 -4
- package/lib/math/vec3.d.ts +3 -6
- package/lib/math/vec3.js +3 -6
- package/lib/page/capabilities.d.ts +7 -7
- package/lib/page/capabilities.js +39 -25
- package/lib/page/check-store.d.ts +14 -2
- package/lib/page/check-store.js +34 -11
- package/lib/page/engine.d.ts +103 -26
- package/lib/page/engine.js +420 -97
- package/lib/page/first-frame.d.ts +16 -0
- package/lib/page/first-frame.js +35 -0
- package/lib/page/frame-stats.d.ts +34 -1
- package/lib/page/frame-stats.js +15 -0
- package/lib/page/label-loop.d.ts +7 -3
- package/lib/page/label-loop.js +17 -10
- package/lib/page/labels.d.ts +3 -3
- package/lib/page/pipeline-store.d.ts +25 -0
- package/lib/page/pipeline-store.js +84 -0
- package/lib/page/start-marker.d.ts +4 -1
- package/lib/page/start-marker.js +5 -2
- package/lib/page/switches.d.ts +32 -2
- package/lib/page/switches.js +9 -1
- package/lib/quality/check.d.ts +24 -3
- package/lib/quality/check.js +21 -7
- package/lib/quality/chooser.d.ts +6 -0
- package/lib/quality/chooser.js +8 -0
- package/lib/quality/governor.d.ts +98 -6
- package/lib/quality/governor.js +250 -20
- package/lib/quality/preset-docs.d.ts +16 -1
- package/lib/quality/preset-docs.js +3 -0
- package/lib/quality/presets.d.ts +84 -7
- package/lib/quality/presets.js +94 -2
- package/lib/render/draw.d.ts +3 -2
- package/lib/render/draw.js +15 -5
- package/lib/render/load-draw.d.ts +7 -5
- package/lib/render/load-draw.js +7 -5
- package/lib/render/loss.d.ts +28 -10
- package/lib/render/loss.js +50 -22
- package/lib/render/recovery.d.ts +20 -0
- package/lib/render/recovery.js +44 -4
- package/lib/render/renderer.d.ts +85 -9
- package/lib/render/renderer.js +181 -42
- package/lib/render/scene-renderer.d.ts +19 -1
- package/lib/render/scene-renderer.js +25 -1
- package/lib/render/webgl2-renderers.js +8 -5
- package/lib/render/webgpu-renderers.js +5 -4
- package/lib/scene/animation.d.ts +28 -32
- package/lib/scene/animation.js +12 -15
- package/lib/scene/assets.d.ts +61 -86
- package/lib/scene/assets.js +103 -236
- package/lib/scene/background.d.ts +14 -18
- package/lib/scene/background.js +5 -2
- package/lib/scene/color.d.ts +3 -3
- package/lib/scene/downloads.d.ts +2 -0
- package/lib/scene/downloads.js +371 -0
- package/lib/scene/environment.d.ts +7 -7
- package/lib/scene/environment.js +1 -1
- package/lib/scene/fake-call-values.js +1 -1
- package/lib/scene/fog.d.ts +11 -4
- package/lib/scene/fog.js +8 -2
- package/lib/scene/frame-cameras.d.ts +19 -0
- package/lib/scene/frame-cameras.js +58 -0
- package/lib/scene/gltf.d.ts +32 -2
- package/lib/scene/gltf.js +78 -49
- package/lib/scene/grading.d.ts +2 -2
- package/lib/scene/grading.js +3 -3
- package/lib/scene/ktx2.d.ts +9 -1
- package/lib/scene/ktx2.js +3 -2
- package/lib/scene/level-rule.d.ts +120 -0
- package/lib/scene/level-rule.js +130 -0
- package/lib/scene/lines.d.ts +13 -17
- package/lib/scene/lines.js +3 -3
- package/lib/scene/lut.d.ts +1 -2
- package/lib/scene/lut.js +1 -2
- package/lib/scene/picks.d.ts +2 -2
- package/lib/scene/pointer-events.d.ts +4 -7
- package/lib/scene/post.d.ts +38 -43
- package/lib/scene/post.js +4 -1
- package/lib/scene/prefab.d.ts +7 -8
- package/lib/scene/prefab.js +7 -8
- package/lib/scene/property-animation.d.ts +1 -1
- package/lib/scene/property-animation.js +1 -1
- package/lib/scene/queries.d.ts +7 -13
- package/lib/scene/resources.d.ts +225 -254
- package/lib/scene/resources.js +179 -81
- package/lib/scene/scene.d.ts +149 -118
- package/lib/scene/scene.js +196 -98
- package/lib/scene/serial-loads.d.ts +29 -0
- package/lib/scene/serial-loads.js +68 -0
- package/lib/scene/shader-preloads.d.ts +34 -0
- package/lib/scene/shader-preloads.js +38 -0
- package/lib/scene/sprites.d.ts +14 -17
- package/lib/scene/sprites.js +5 -6
- package/lib/scene/textures.d.ts +11 -12
- package/lib/scene/textures.js +9 -10
- package/lib/scene/time-of-day.d.ts +3 -4
- package/lib/scene/time-of-day.js +2 -3
- package/lib/scene/vertex-draws.d.ts +5 -4
- package/lib/scene/vertex-draws.js +7 -5
- package/lib/shader-artifact.json +1 -0
- package/lib/shared/core.d.ts +5 -0
- package/lib/shared/core.js +1 -0
- package/lib/shared/import-once.d.ts +6 -0
- package/lib/shared/import-once.js +19 -0
- package/lib/shared/metrics.d.ts +38 -0
- package/lib/shared/metrics.js +62 -1
- package/lib/shared/run-task.js +7 -1
- package/lib/shared/task-pending.d.ts +12 -0
- package/lib/shared/task-pending.js +61 -1
- package/lib/shared/tasks.js +79 -32
- package/lib/shared/version.d.ts +17 -1
- package/lib/shared/version.js +19 -1
- package/lib/shared/wasm.d.ts +12 -4
- package/lib/shared/wasm.js +50 -27
- package/lib/shared/worker-start.d.ts +7 -0
- package/lib/shared/worker-start.js +27 -0
- package/lib/sketch/define-sketch.d.ts +35 -0
- package/lib/sketch/input.d.ts +2 -2
- package/lib/sketch/preset-check.d.ts +20 -6
- package/lib/sketch/preset-check.js +42 -17
- package/lib/sketch/quality.d.ts +69 -11
- package/lib/sketch/quality.js +54 -13
- package/lib/sketch/runner.d.ts +76 -9
- package/lib/sketch/runner.js +385 -52
- package/lib/sketch/ui.d.ts +5 -8
- package/lib/workers/probe-worker.d.ts +5 -0
- package/lib/workers/probe-worker.js +13 -4
- package/lib/workers/protocol.d.ts +61 -13
- package/lib/workers/protocol.js +4 -0
- package/lib/workers/render-worker.js +25 -4
- package/lib/workers/sketch-worker.js +104 -15
- package/package.json +2 -2
package/docs/api/water.md
CHANGED
|
@@ -3,7 +3,7 @@ id: api/water
|
|
|
3
3
|
title: "Water (@null3d/water)"
|
|
4
4
|
status: experimental
|
|
5
5
|
since: "0.3"
|
|
6
|
-
summary: "createWater: a river and a lake from one shape, with waves that the current carries, ripples, caustics, foam, a soft shore that reads the scene's depth or the shape's bed, a reflection whose cadence follows the preset, and createUnderwater for the view from below the surface. createOcean: an open sea of spectra transformed on the GPU."
|
|
6
|
+
summary: "createWater: a river and a lake from one shape, with waves that the current carries, ripples, caustics, foam, rain rings, a soft shore that reads the scene's depth or the shape's bed, a reflection whose cadence follows the preset, and createUnderwater for the view from below the surface. createWaterfall: a fall from a river's lip, with spray and mist. createOcean: an open sea of spectra transformed on the GPU."
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
# Water (@null3d/water)
|
|
@@ -24,16 +24,23 @@ flowchart LR
|
|
|
24
24
|
sea --> ocean["The sea"]
|
|
25
25
|
preset["The quality preset"] --> mirror
|
|
26
26
|
camera["A camera under the surface"] --> under["createUnderwater"]
|
|
27
|
+
lip["A river's lip,<br/>its current and a drop"] --> path["The path of<br/>falling water"]
|
|
28
|
+
path --> sheet["A column of water:<br/>streaks that ride the water"]
|
|
29
|
+
path --> spray["Spray, mist<br/>and a plume"]
|
|
30
|
+
sheet --> fall["The waterfall"]
|
|
31
|
+
spray --> fall
|
|
27
32
|
```
|
|
28
33
|
|
|
29
|
-
`@null3d/water` draws the water in a scene. A river follows a line, and a lake fills an outline, and both come from one description. The surface has long waves that the current carries downstream, and finer ripples in its normal. It draws caustics on the bed, foam around what breaks the surface, and a shore that fades where the bed rises to meet it. A reflection pass mirrors the banks and the sky, and redraws as often as the quality preset affords. The same surface draws from below, and `createUnderwater` gives the view from under the water its color, its bend and its caustics.
|
|
34
|
+
`@null3d/water` draws the water in a scene. A river follows a line, and a lake fills an outline, and both come from one description. The surface has long waves that the current carries downstream, and finer ripples in its normal. It draws caustics on the bed, foam around what breaks the surface, and a shore that fades where the bed rises to meet it. A reflection pass mirrors the banks and the sky, and redraws as often as the quality preset affords. The mirror softens where the waves lie finer than a pixel covers, since their tilt still scatters the light. A bank seen through ripples meets the surface on a soft edge, while water close to the camera stays glassy. The same surface draws from below, and `createUnderwater` gives the view from under the water its color, its bend and its caustics.
|
|
30
35
|
|
|
31
|
-
`
|
|
36
|
+
`createWaterfall` draws a fall from a river's lip, with spray at the lip, mist down the fall and a plume of mist at its foot.
|
|
32
37
|
|
|
33
|
-
The
|
|
38
|
+
`createOcean` draws an open sea instead. Its waves come from wave spectra, and the GPU transforms them into heights in every frame. The bands of swell and chop then move on their own, and the surface reads the slopes that the transform writes. Its reflection takes the same cadence as the river's: the preset's and the governor's at rest, and every frame while the camera that `update()` follows moves or turns.
|
|
39
|
+
|
|
40
|
+
The package is built on the engine's public API. Its surface and underwater shaders ship compiled, so your build does not compile them, and the package needs no extra setup for them. A waterfall's spray comes from `@null3d/particles`, which the package lists as a peer dependency. It loads with the first fall that makes spray.
|
|
34
41
|
|
|
35
42
|
```sh
|
|
36
|
-
bun add @null3d/water
|
|
43
|
+
bun add @null3d/water @null3d/particles
|
|
37
44
|
```
|
|
38
45
|
|
|
39
46
|
```ts
|
|
@@ -127,11 +134,34 @@ the bed at a point, and the current there.
|
|
|
127
134
|
| `reflectionEvery` | A frame count from 1 to 16 for each preset | 2 on Low and Medium, 1 on High and Ultra | The frames between two draws of the reflection. The frame-budget governor doubles it while frames take too long |
|
|
128
135
|
| `reflectionFollowsBudget` | `true` or `false` | `true` | Whether the frame-budget governor may raise `reflectionEvery`. Between draws the water shows the reflection of an older camera, so on a moving camera a raised count reads as a lag. `false` keeps the count |
|
|
129
136
|
| `layers` | A 32-bit mask | The camera's layers | The layers that the reflection draws. Leave out what lies on or under the water |
|
|
130
|
-
| `reflectionScale` | `1`, `0.5` or `0.25` | 1 | The reflection's size as a share of the render size each way |
|
|
137
|
+
| `reflectionScale` | `1`, `0.5` or `0.25` | The quality preset's `reflectionScale`: 0.25 on Low, 0.5 on Medium and High, 1 on Ultra | The reflection's size as a share of the render size each way |
|
|
131
138
|
| `mesh` | `{ step, across, cell, reach }` | 2, 16, 2 and 1.36 | The meters between two cross sections along a river, the sections across it, a lake's grid cell, and how far past a river's half width its mesh reaches as a factor |
|
|
132
139
|
| `bed` | `'scene'` or `'shape'` | `'scene'` | Where the surface reads the depth of the bed: the copy of the scene's depth behind each pixel, or the depth that each shape describes |
|
|
133
|
-
| `material` | The standard material values | None | The surface's material, such as its volume's tint
|
|
140
|
+
| `material` | The standard material values | None | The surface's material, such as its volume's tint. The surface works its own thickness and transmission out, so it takes no value for those |
|
|
141
|
+
| `camera` | A `Camera` | None | The camera that the reflection follows. While it moves or turns, the reflection draws in every frame, so a moving view shows no mirror of an older one; a still camera keeps the cadence above. Without one, the cadence holds whatever the view does |
|
|
134
142
|
| `wind` | A wind field's `texture`, `size` and `air` | None | The wind that lifts the surface's short waves and carries their crests. The surface reads it once for each vertex |
|
|
143
|
+
| `windRipple` | A number from 0 | 0 | The slope that the wind raises in short crests of its own, at a feature of a few tenths of a meter. At 0 the surface's waves run with their clocks alone |
|
|
144
|
+
| `rain` | A number from 0 to 1 | 0 | How hard rain falls on the surface. Each drop rings the surface where it lands. 0 draws no rings and costs nothing |
|
|
145
|
+
|
|
146
|
+
## The foam around what breaks the water
|
|
147
|
+
|
|
148
|
+
`foamMap(ctx, obstacles, options)` makes the map that the surface breaks into flecks. Each obstacle
|
|
149
|
+
is a mark `{ x, z, r }` at the water's surface. The map holds how near every point lies to a mark,
|
|
150
|
+
from 1 at its edge to 0 a little way off. It stretches that reach toward +x, so the foam trails
|
|
151
|
+
there: the map takes the water to run along +x.
|
|
152
|
+
|
|
153
|
+
| Option | Takes | Default | What it sets |
|
|
154
|
+
| --- | --- | --- | --- |
|
|
155
|
+
| `origin`, `size` | Two numbers each, in meters | Required | The world area that the map covers |
|
|
156
|
+
| `width`, `height` | Texels | 1024, 224 | The map's texels along x and along z |
|
|
157
|
+
| `reach` | A finite number above 0, in meters | 0.35 | How far the foam reaches around a mark that gives no reach of its own |
|
|
158
|
+
| `trail` | A number, in meters | 1.6 | How far the foam trails toward +x behind a mark. 0 or less leaves a ring |
|
|
159
|
+
|
|
160
|
+
A mark takes a `reach` of its own, in meters, in place of the map's. So one water can foam further
|
|
161
|
+
around some of its stones than around others. A mark without one keeps the map's reach. A reach
|
|
162
|
+
on the map or on a mark that is not a finite number above 0 stops the call.
|
|
163
|
+
The foam reaches `trail × (1 + r / reach)` meters toward +x from a mark, so a mark with a shorter
|
|
164
|
+
reach trails further in proportion to its radius.
|
|
135
165
|
|
|
136
166
|
## Wind on the surface
|
|
137
167
|
|
|
@@ -155,6 +185,36 @@ return {
|
|
|
155
185
|
|
|
156
186
|
`waveAmplitude` scales the lift that the wind gives the surface, along with the long waves. A slow stream can therefore keep a nearly flat surface, with fine ripples. Its wind field still moves the plants and the leaves around it.
|
|
157
187
|
|
|
188
|
+
A field's lift rides on a long swell, which suits a lake or a river. A pool, a basin or a fountain is small beside that swell, so the lift reads there as one flat tilt of the whole surface. Give such a body a `windRipple` and the surface takes the air in short crests of its own, a few tenths of a meter apart, so its reflection moves with the gusts that sway the trees. It is 0 by default, which leaves every other surface as it was. The crests cost one read of the field for each pixel, so a wide lake keeps the default and lets its swell answer the wind.
|
|
189
|
+
|
|
190
|
+
```ts
|
|
191
|
+
const pool = createWater(ctx, {
|
|
192
|
+
shapes,
|
|
193
|
+
wind: wind.field,
|
|
194
|
+
windRipple: 1,
|
|
195
|
+
ripple: 0,
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Rain on the surface
|
|
200
|
+
|
|
201
|
+
Give `createWater` a `rain` amount, or call `water.setRain(amount)` while the scene runs, and each
|
|
202
|
+
raindrop rings the surface where it lands. A ring grows and fades in about a second, and the rings
|
|
203
|
+
drift downstream with the current. They bend the surface's mirror and its highlights, as real rain
|
|
204
|
+
does. A light rain rings a few of the surface's cells, and a downpour rings all of them.
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
const water = createWater(ctx, { shapes, rain: 0 });
|
|
208
|
+
|
|
209
|
+
// When a storm starts:
|
|
210
|
+
water.setRain(1);
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
The rings follow the wet surface of the weather example add-on. Each cell of a grid about a meter
|
|
214
|
+
wide takes one drop at a time, with its place and its moment from the cell's hash. They give way where
|
|
215
|
+
one pixel covers more than a ring's line, so far water does not shimmer. Rain is off by default.
|
|
216
|
+
While it is off, the surface skips the rings' work.
|
|
217
|
+
|
|
158
218
|
## The water object
|
|
159
219
|
|
|
160
220
|
`createWater` returns an object:
|
|
@@ -162,11 +222,13 @@ return {
|
|
|
162
222
|
| Member | What it does |
|
|
163
223
|
| --- | --- |
|
|
164
224
|
| `update()` | Keeps the sketch's frame loop. The reflection pass carries its own cadence now, so the call changes nothing |
|
|
225
|
+
| `level` | The height of the water's surface, in meters |
|
|
165
226
|
| `reflectionEvery` | The frames between two draws of the reflection now |
|
|
166
227
|
| `waveAmplitude` | The height of the long waves and of the wind's lift, as a factor of their base height |
|
|
167
228
|
| `surfaceHeight(x, z, t)` | The height of the surface at a point and a sketch time, in meters, from its long waves |
|
|
168
229
|
| `currentAt(x, z, out)` | The current at a point, as a velocity in meters a second, written into `out` |
|
|
169
230
|
| `setCaustics(light)` | Sets the light that the ripples focus on the bed, as a linear color |
|
|
231
|
+
| `setRain(amount)` | Sets how hard rain falls on the surface, from 0 to 1 |
|
|
170
232
|
| `bodies` | The resolved bodies: their bounds, `depthAt`, `contains` and `currentAt` |
|
|
171
233
|
| `destroy()` | Removes the surface, its reflection pass and its material |
|
|
172
234
|
|
|
@@ -174,6 +236,19 @@ return {
|
|
|
174
236
|
swimmer floats and drifts with the water under it. Where a river meets a lake, `currentAt` gives the
|
|
175
237
|
current of the body that owns the point, and `surfaceHeight` follows the flat, mixed surface there.
|
|
176
238
|
|
|
239
|
+
## The tint of the water
|
|
240
|
+
|
|
241
|
+
The surface lets the bed's light through. The attenuation then takes a share of that light, for
|
|
242
|
+
each meter that it travels. The surface measures the travel as the depth of the bed under the
|
|
243
|
+
point. The water's own volume reaches from its surface down to that bed. So the tint of a shallow
|
|
244
|
+
creek follows its depth, and the caller sets how fast the tint gathers. `attenuationColor`
|
|
245
|
+
is the color that the light takes after `attenuationDistance` meters. A clear creek takes a pale
|
|
246
|
+
color over a distance of several meters. Most of the bed's light then reaches the eye at every
|
|
247
|
+
point, and a little more of it over the shallows. A dark color over a distance shorter than the
|
|
248
|
+
bed is deep takes most of that light away. The water then reads as an opaque slab of its color,
|
|
249
|
+
with no bed under it. The surface works out its own thickness and transmission, so those two
|
|
250
|
+
values do not apply here.
|
|
251
|
+
|
|
177
252
|
## The view from under the water
|
|
178
253
|
|
|
179
254
|
`createUnderwater(ctx, camera, water, options)` adds an effect while the camera is near or under the
|
|
@@ -194,6 +269,102 @@ Call `update(t, air, caustics)` in each frame with the sketch's time, the light
|
|
|
194
269
|
horizon, and the light of the caustics. The surface seen from below shows the world above through a
|
|
195
270
|
window overhead, and turns the light back past that window's edge.
|
|
196
271
|
|
|
272
|
+
## Waterfalls
|
|
273
|
+
|
|
274
|
+
`createWaterfall(ctx, options)` makes a waterfall that falls from a river's lip. The water rolls
|
|
275
|
+
over the lip as a smooth glassy tongue and arcs out. It then drops almost straight, as falling water
|
|
276
|
+
does while the air slows it. Below the tongue it turns white: a solid column of rough round ropes,
|
|
277
|
+
with soft gray shade between them and clumps of froth that ride down with the water. Its outline
|
|
278
|
+
tears into lobes and wisps. Over its first meters it draws in to about a quarter of the lip's
|
|
279
|
+
width, and its sides wander and break into separate ropes, so a notch as wide as the lip shows
|
|
280
|
+
rock beside it. Over its lower half it breaks up into clumps and dissolves into a broad mist,
|
|
281
|
+
about four times its width, that draws over its foot. So it never lands and never ends in a
|
|
282
|
+
line. Spray froths at the lip, and a plume of mist
|
|
283
|
+
rises at its foot.
|
|
284
|
+
|
|
285
|
+
The sheet's material moves each streak with the water from the sketch's time alone. So the fall
|
|
286
|
+
costs the CPU nothing in a frame. A streak rides down at the water's own speed, and it stretches as
|
|
287
|
+
the water speeds up. The fall is one closed column with an oval section. It is thin under the
|
|
288
|
+
brink, so its water hangs close to the rock, and it deepens out from the cliff over its first few
|
|
289
|
+
meters as it falls. So the fall has a solid body from the side as well as from the front. Its
|
|
290
|
+
outline thins and tears wherever the view grazes it, so no side shows a clean edge. Small drops fly
|
|
291
|
+
off the column. White water scatters the light that reaches it from all round. So the column takes
|
|
292
|
+
the sky's light as a surface facing up does, and gives back a share of the air's light that
|
|
293
|
+
`setLight` names, as the mist beside it does, so it reads as the lightest thing beside it. The
|
|
294
|
+
scene's light lights the column,
|
|
295
|
+
and the column fades where it nears a wall or a ledge behind it. The spray and
|
|
296
|
+
the mist are systems of [`@null3d/particles`](particles.md), which the water package depends on.
|
|
297
|
+
|
|
298
|
+
```ts
|
|
299
|
+
// sketch.ts
|
|
300
|
+
import { defineSketch } from '@null3d/engine';
|
|
301
|
+
import { createWater, createWaterfall } from '@null3d/water';
|
|
302
|
+
|
|
303
|
+
export default defineSketch(async (ctx) => {
|
|
304
|
+
const { scene } = ctx;
|
|
305
|
+
const camera = scene.createPerspectiveCamera({ position: [17, 5, 18], target: [0, -6, 0] });
|
|
306
|
+
scene.setActiveCamera(camera);
|
|
307
|
+
scene.createDirectionalLight({ direction: [0.35, -0.8, 0.5], intensity: 1.6 });
|
|
308
|
+
scene.setEnvironment(await ctx.assets.skyEnvironment());
|
|
309
|
+
|
|
310
|
+
// The creek runs along +x and ends at the lip.
|
|
311
|
+
const water = createWater(ctx, {
|
|
312
|
+
shapes: { kind: 'river', middle: [[-40, 0], [0, 0]], halfWidth: 2.8, depth: 0.7, speed: 1.4 },
|
|
313
|
+
});
|
|
314
|
+
const fall = await createWaterfall(ctx, {
|
|
315
|
+
lip: [0, 0],
|
|
316
|
+
direction: [1, 0],
|
|
317
|
+
halfWidth: 2.8,
|
|
318
|
+
speed: 1.4,
|
|
319
|
+
drop: 18,
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
return {
|
|
323
|
+
onUpdate() {
|
|
324
|
+
water.update();
|
|
325
|
+
},
|
|
326
|
+
onLateUpdate() {
|
|
327
|
+
fall.update();
|
|
328
|
+
},
|
|
329
|
+
};
|
|
330
|
+
});
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
End the river's own surface at the lip. The sheet starts a meter upstream of it, on the river's
|
|
334
|
+
surface, and fades in there. So the river and the fall meet without a seam.
|
|
335
|
+
|
|
336
|
+
| Option | Takes | Default | What it sets |
|
|
337
|
+
| --- | --- | --- | --- |
|
|
338
|
+
| `lip` | `[x, z]` in meters | Required | The middle of the lip, where the river's surface ends and the water falls |
|
|
339
|
+
| `direction` | `[x, z]` | Required | The way the water runs over the lip. Its length does not matter |
|
|
340
|
+
| `halfWidth` | A number above 0, in meters | Required | Half the river's width at the lip |
|
|
341
|
+
| `level` | A number, in meters | 0 | The height of the water's surface at the lip |
|
|
342
|
+
| `speed` | A number above 0, in meters a second | 1.2 | The current at the lip. It sets how far the water leaps out from the lip's line: at 1.2 m/s the back of the column is 0.6 m out 2 m down and 1.3 m out 13 m down. A wall that leans out further meets the water, and the column fades near the rock. Give the speed at the lip itself |
|
|
343
|
+
| `drop` | A number above 0, in meters | Required | How far the fall drops below the lip. The sheet thins into mist over the lower half of the drop |
|
|
344
|
+
| `spread` | A number from 0 | 0.3 | How far each side of the sheet widens for each meter that the water falls, once it has fallen a few meters: while it still falls as a stream it spreads little, and lower down it opens into a veil. At 0.3 a creek 5 m wide that falls 13 m is about three quarters as wide as the creek halfway down, and half as wide again at its foot |
|
|
345
|
+
| `apron` | A number above 0, in meters | 1 | How far up the river the fall's water starts, lying on the river's surface. It fades in at uneven distances and covers the river's square end, so the water runs into the fall with no straight edge at the lip. Give the reach of the broken water before the brink |
|
|
346
|
+
| `fadeBelow` | A number, in meters | None | The world height of a cloud sea, a fog bank or a mist that the fall drops into. A cloud that draws before the fall does not hide it, so below this height the fall vanishes itself over 2.5 m, each clump at its own depth. The water breaks up and bursts into mist over the part of the drop above it |
|
|
347
|
+
| `spray` | A number from 0 to 3 | 1 | The spray and the mist, as a factor of the fall's own. At 0 the fall makes no particles, and neither `@null3d/particles` nor the engine's particle code loads |
|
|
348
|
+
| `mist` | A number from 0 to 3 | 1 | The mist round the fall's foot and the plume that rises from it, as a factor of the fall's own, which `spray` scales too. At 0 the fall makes neither, for a scene whose own cloud draws the mist at the fall's foot: puffs lit apart from that cloud draw a gray patch over it |
|
|
349
|
+
| `layers` | A 32-bit mask | Layer 0 | The layers that the sheet and the spray draw on |
|
|
350
|
+
| `wind` | A wind field, such as `createWind`'s `field` | None | The air that carries the mist |
|
|
351
|
+
| `material` | The standard material values | None | The sheet's material, such as the color of its white water |
|
|
352
|
+
| `mesh` | `{ across, down }` | 24 and 40 | The sections round the column, and its rows from the lip to the foot |
|
|
353
|
+
|
|
354
|
+
`createWaterfall` returns a promise of a waterfall object, since the particle code downloads on
|
|
355
|
+
first use:
|
|
356
|
+
|
|
357
|
+
| Member | What it does |
|
|
358
|
+
| --- | --- |
|
|
359
|
+
| `update()` | Steps the spray and the mist. Call it once in each frame, in `onLateUpdate`, after the wind steps |
|
|
360
|
+
| `setLight(color)` | Sets the air's light on the spray and the mist, as a linear color. Particles are not lit, so give them the scene's light in each mood. The column's white water gives back a share of it too |
|
|
361
|
+
| `setSpray(amount)` | Sets the spray and the mist, from 0 to 3. A storm raises it |
|
|
362
|
+
| `fallTime` | The seconds that the water takes from the lip to the foot |
|
|
363
|
+
| `destroy()` | Removes the sheet, its material and its particles |
|
|
364
|
+
|
|
365
|
+
A fall that lies past the edge of a water's surface does not show in that water's mirror. Put it on
|
|
366
|
+
a layer that the water's `layers` option leaves out, so the reflection pass skips it.
|
|
367
|
+
|
|
197
368
|
## The ocean
|
|
198
369
|
|
|
199
370
|
`createOcean(ctx, { camera })` makes an open sea. Its waves come from two or three bands of wave
|
|
@@ -238,8 +409,9 @@ export default defineSketch(async (ctx) => {
|
|
|
238
409
|
| `foam` | A number above 0, in meters | 1.1 | The height at which foam breaks on a crest |
|
|
239
410
|
| `softness` | A number above 0, in meters | 0.12 | The gap to the bed over which the water fades at a shore |
|
|
240
411
|
| `reflectionEvery` | A frame count from 1 to 16 for each preset | 2 on Low and Medium, 1 on High and Ultra | The frames between two draws of the reflection |
|
|
412
|
+
| `reflectionFollowsBudget` | `true` or `false` | `true` | Whether the frame-budget governor may raise `reflectionEvery`. Between draws the sea shows the reflection of an older camera, so on a moving camera a raised count reads as a lag. `false` keeps the count |
|
|
241
413
|
| `layers` | A 32-bit mask | The camera's layers | The layers that the reflection draws |
|
|
242
|
-
| `reflectionScale` | `1`, `0.5` or `0.25` | 1 | The reflection's size as a share of the render size each way |
|
|
414
|
+
| `reflectionScale` | `1`, `0.5` or `0.25` | The quality preset's `reflectionScale`: 0.25 on Low, 0.5 on Medium and High, 1 on Ultra | The reflection's size as a share of the render size each way |
|
|
243
415
|
| `material` | The standard material values | None | The surface's material, such as the water's tint and its thickness |
|
|
244
416
|
|
|
245
417
|
`OCEAN_BANDS` holds the default bands. Give a band of your own to change the sea: a wider tile
|
|
@@ -251,7 +423,7 @@ holds longer waves, and a taller significant height lifts them further.
|
|
|
251
423
|
|
|
252
424
|
| Member | What it does |
|
|
253
425
|
| --- | --- |
|
|
254
|
-
| `update()` | Moves the mesh about the camera
|
|
426
|
+
| `update()` | Moves the mesh about the camera, and follows it for the reflection's cadence, which draws in every frame while the view moves. Call it once in each frame, after the camera moves |
|
|
255
427
|
| `reflectionEvery` | The frames between two draws of the reflection now |
|
|
256
428
|
| `heightAt(x, z)` | The height of the sea at a world place, in meters, at the sketch time. It runs the bands' transforms on this thread, and transforms again only when the sketch time moves, so several reads in a frame share one |
|
|
257
429
|
| `bands` | The bands, in the order that they sum |
|
|
@@ -269,7 +441,11 @@ near the eye and spends its vertices far away.
|
|
|
269
441
|
against the bank. With `bed: 'shape'`, the mesh carries each vertex's bed depth in its vertex
|
|
270
442
|
colors and the surface reads that instead, for a bed that the scene states rather than draws.
|
|
271
443
|
- **The reflection.** The pass draws the scene a second time. It draws every other frame on Low and
|
|
272
|
-
Medium, so it costs half as much on average there, and every frame on High and Ultra.
|
|
444
|
+
Medium, so it costs half as much on average there, and every frame on High and Ultra. A camera that
|
|
445
|
+
moves or turns overrides that, and the reflection then draws in every frame. A moving view never
|
|
446
|
+
shows a mirror of an older one, and the cadence returns when the view settles. While the lowest
|
|
447
|
+
quality tier applies, a still camera draws it in every 16th frame whatever the preset and the
|
|
448
|
+
governor give; leaving the tier gives the budget back. When frames
|
|
273
449
|
take too long, the frame-budget governor doubles the wait, up to every 16th frame. The stats
|
|
274
450
|
overlay shows the cadence as `reflectionEvery`. It shows the pass's GPU time and its share of a
|
|
275
451
|
frame as the water row's budget. It also shows the memory of the mesh arrays, the map of where bodies
|
|
@@ -280,16 +456,23 @@ near the eye and spends its vertices far away.
|
|
|
280
456
|
- **Transmission.** The surface lets light through, so the engine copies the scene's colors in the
|
|
281
457
|
frame that the water draws. The water draws both faces.
|
|
282
458
|
- **Nothing before its first use.** A page that never creates water downloads none of the add-on.
|
|
459
|
+
- **A waterfall.** It draws one blended mesh, a closed column of just over 2,000 triangles at the
|
|
460
|
+
default detail. It adds four particle systems. They are a froth at the lip, the drops thrown off
|
|
461
|
+
the column, the mist that the fall dissolves into, and the plume at its foot. For a fall 2.5 m
|
|
462
|
+
wide that drops 10 m, each holds a few hundred large puffs at most; a taller or wider fall makes
|
|
463
|
+
more. The column reads the copy
|
|
464
|
+
of the scene's depth. The puffs blend over the pixels that they cover, so lower `spray` where a
|
|
465
|
+
phone's frame is short.
|
|
283
466
|
- **One way to make water.** Use this package rather than a hand-written custom material, so a
|
|
284
467
|
scene's water has one owner.
|
|
285
468
|
- **One water a page.** The add-on registers one water feature, so a page makes its water with one
|
|
286
469
|
`createWater` call. Give that call every body that shares the surface and the reflection. An
|
|
287
470
|
ocean is a feature of its own, so a page may draw a river and a sea.
|
|
288
|
-
- **The ocean's transform.** A sea
|
|
289
|
-
|
|
290
|
-
room for the sketch's own. Each pass runs on a 128 by 128 grid, with a band
|
|
291
|
-
|
|
292
|
-
transform's share.
|
|
471
|
+
- **The ocean's transform.** A sea adds 14 butterfly passes, one pass that puts the heights in
|
|
472
|
+
meters and one reflection pass. Those 16 passes take 16 of the 31 passes that a sketch may add,
|
|
473
|
+
so leave room for the sketch's own. Each transform pass runs on a 128 by 128 grid, with a band
|
|
474
|
+
to a layer, and the reflection draws at the reflection scale. The stats overlay names the
|
|
475
|
+
add-on's ocean row and its budget, and the frame's GPU time holds the transform's share.
|
|
293
476
|
|
|
294
477
|
[The API reference](reference/water.md) lists every export of this page with its type and
|
|
295
478
|
description. The engine's doc comments make it.
|
package/docs/api/wind.md
CHANGED
|
@@ -323,19 +323,19 @@ The box follows the camera, so update the material's `origin` values in each fra
|
|
|
323
323
|
|
|
324
324
|
A vertex offset that reads the field orders the pass before every pass that draws the material. The shadows and the motion vectors therefore move with the plant.
|
|
325
325
|
|
|
326
|
-
Trees and plants sway through such a material. The forest demo, `examples/forest`, draws its trees made in code with one custom material.
|
|
326
|
+
Trees and plants sway through such a material. The forest demo, `examples/forest`, draws the bark of its trees made in code with one custom material, and their leaf cards with a standard material. The bark's vertex offset samples this field's block at each vertex, as the example above does. Its sway fades to nothing at the material's `swayDistance`. So a tree past it stands still, and its far shadow cascades keep their layers. A tree loaded from a glTF file sways the same way: give its meshes such a material with `setMaterial`. The grass package, [`@null3d/grass`](grass.md), reads the field for its blades. Its `swayDistanceFor(preset)` gives each quality preset's sway distance.
|
|
327
327
|
|
|
328
328
|
Every reader takes the field as a plain texture and its box, so it needs no code from this add-on. A page's own material reads it, as the forest demo's does. The grass package's blades read it, and the water add-on's `wind` option lifts a water surface. They read the same sampling block, and each copy costs the reader one of its material's six texture slots. Tests hold the readers' blocks equal to this page's.
|
|
329
329
|
|
|
330
330
|
## What the field is
|
|
331
331
|
|
|
332
|
-
The field keeps its state between frames. One pass holds two states and steps the air forward by
|
|
332
|
+
The field keeps its state between frames. One pass holds two states and steps the air forward by the preset's step interval at a time. It runs as many steps as the sketch time owes.
|
|
333
333
|
|
|
334
334
|
Each cycle pulls the air toward an analytic field of place and time. It injects the pushes and the gust, and keeps the eddies with vorticity confinement. It solves the pressure, and takes the pressure's slope out of the air, so the air never piles up. A wake therefore lasts after the body that made it has gone, and a gust sent upwind crosses the scene.
|
|
335
335
|
|
|
336
336
|
The air starts when a page makes the wind, so a field made late in a sketch runs no air from before it.
|
|
337
337
|
|
|
338
|
-
A held page steps its sketch's updates up to the held time. The
|
|
338
|
+
A held page steps its sketch's updates up to the held time. The first frame that draws runs the air that the hold owes, up to ten seconds of it. So a held picture carries the air that the hold built. Two held pages at two times within ten seconds of the wind's start therefore differ by the air that moved between them. A longer hold runs only ten seconds of air.
|
|
339
339
|
|
|
340
340
|
Beyond its box the field carries on. The box sets the detail, not the field's extent. So a plant past the box reads the air at its own place.
|
|
341
341
|
|
|
@@ -356,9 +356,9 @@ The add-on declares its work to the engine as one feature. The preset gives its
|
|
|
356
356
|
|
|
357
357
|
Low keeps no grid: every reader works the air out from the steady field. A page that gives `grid` keeps it, whatever the preset says. At Low, that page still gets a field, at the add-on's own step and pressure count. WebGL2 takes its own step row, 66 ms at Medium and above, because a step costs far more there.
|
|
358
358
|
|
|
359
|
-
The grid is one flat slice at the crown's height
|
|
359
|
+
The grid is one flat slice at the crown's height, with no layered or volume grid. High and Ultra use the flat 128 and 256 grids.
|
|
360
360
|
|
|
361
|
-
The field's own budget is 0.5, 1.2, 4.9 and 6.25 ms a frame from Low to Ultra. That budget is its own, and it is smaller than the room that
|
|
361
|
+
The field's own budget is 0.5, 1.2, 4.9 and 6.25 ms a frame from Low to Ultra. That budget is its own, and it is smaller than the room that each preset's frame leaves beside the plants' own budget. A frame that spends both grows by the field's share, and the governor is what holds it. The governor lowers the field's share by a quarter at each of its steps, down to a quarter of the budget. The field still moves at the lowest step: the step interval reaches at most 133 ms, and the pressure count stays above zero. The overlay row reads the field's cost in a frame, which grows when a slow display owes the field more than one cycle in that frame. The stats overlay shows one line for the add-on. This example is the Medium row, with an example GPU time: `wind gpu 0.62 ms windStepMs 33 · windPressureSteps 16 · windSpringTrees 8 · windGrid 64 · budget 1.2 of 1.2 ms · memory 0.1 MiB`.
|
|
362
362
|
|
|
363
363
|
A preset change that changes the grid makes the grid again at the new size. The air starts empty on the new grid. A reader takes `field.texture` again after that, because the texture is a new one.
|
|
364
364
|
|
package/docs/cli/null3d.md
CHANGED
|
@@ -3,12 +3,12 @@ id: cli/null3d
|
|
|
3
3
|
title: "The `null3d` command"
|
|
4
4
|
status: experimental
|
|
5
5
|
since: "0.1"
|
|
6
|
-
summary: "create, test, bench, check-addon, shot, upgrade, assets,
|
|
6
|
+
summary: "create, test, bench, check-addon, shot, upgrade, assets, mcp."
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
# The `null3d` command
|
|
10
10
|
|
|
11
|
-
> Roadmap step 0.1, first released in null3D 0.1.0.
|
|
11
|
+
> Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions. `test` runs image tests, and no behavior tests.
|
|
12
12
|
|
|
13
13
|
The `@null3d/cli` package holds the `null3d` command. You need no command to build or run a sketch: Vite and the null3D Vite plugin do that. The command does jobs that a bundler does not do, such as drawing a frame of your scene with no person watching.
|
|
14
14
|
|
|
@@ -28,12 +28,13 @@ The command needs Node 20.19 or later, or Node 22.12 or later, as Vite 8 does.
|
|
|
28
28
|
|
|
29
29
|
```sh
|
|
30
30
|
bunx @null3d/cli create my-game
|
|
31
|
-
bunx @null3d/cli create my-
|
|
31
|
+
bunx @null3d/cli create my-viewer --template product
|
|
32
|
+
bunx @null3d/cli create my-game --template game
|
|
32
33
|
```
|
|
33
34
|
|
|
34
35
|
| Option | Effect | Without it |
|
|
35
36
|
| --- | --- | --- |
|
|
36
|
-
| `--template <name>` | The template to copy | `empty` |
|
|
37
|
+
| `--template <name>` | The template to copy: `empty`, a turning cube; `product`, a product viewer; or `game`, a small game | `empty` |
|
|
37
38
|
|
|
38
39
|
The folder must not exist, or it must be empty. The command never overwrites an existing `.claude/settings.json` or `.codex/hooks.json`, because those files can hold your own hooks. The command writes its own version into the project's package pins, and it installs nothing. Run `bun install` in the new folder, then `bunx vite`. [Project structure](../getting-started/project-structure.md) lists the files and explains the agent hook.
|
|
39
40
|
|
|
@@ -185,6 +186,59 @@ Every image is a hold from time 0 that performs the script up to its step. So an
|
|
|
185
186
|
|
|
186
187
|
The engine reads the script only in hold mode. A page that you run with Vite never performs one, and its input stays the user's.
|
|
187
188
|
|
|
189
|
+
## mcp
|
|
190
|
+
|
|
191
|
+
`mcp` starts a Model Context Protocol server for the project in the current folder, over stdio. An agent lists and changes the live scene's objects, captures a frame, and reads the frame figures, the errors and the render graph. It can also switch the quality preset or the GPU path. The page needs a development build: a production build leaves the inspection channel out. The page must also start the engine as it loads. A held page and a replay page publish no inspection bridge, so the command cannot drive them.
|
|
192
|
+
|
|
193
|
+
```mermaid
|
|
194
|
+
flowchart LR
|
|
195
|
+
agent["A coding agent"] --> mcp["bunx @null3d/cli mcp"]
|
|
196
|
+
mcp --> server["Your project's own<br/>Vite dev server"]
|
|
197
|
+
mcp --> browser["A headless browser,<br/>or your open Chrome"]
|
|
198
|
+
browser --> page["Your page"]
|
|
199
|
+
page --> bridge["window.__null3dInspector"]
|
|
200
|
+
bridge --> worker["The sketch worker<br/>reads and changes the scene"]
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
By default the command starts the project's own Vite dev server and a headless Chrome, as `shot` does. With `--connect` it attaches to a Chrome that already runs with a debugging port. It then drives the tab that already shows the page, so the agent sees exactly what you see.
|
|
204
|
+
|
|
205
|
+
```sh
|
|
206
|
+
claude mcp add null3d -- bunx @null3d/cli mcp
|
|
207
|
+
claude mcp add null3d-session -- bunx @null3d/cli mcp --connect http://127.0.0.1:9222
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
For the second form, start Chrome with `--remote-debugging-port=9222` and open the page from your Vite dev server. Every development build publishes the inspection bridge, so the page needs no switch. `?inspect` only opens the in-page panel. The command drives the first tab whose path is the `--page` path. When no tab has that path, it drives the first tab that publishes the bridge.
|
|
211
|
+
|
|
212
|
+
| Option | Effect | Without it |
|
|
213
|
+
| --- | --- | --- |
|
|
214
|
+
| `--page <path>` | The page to open, from the server's root. With `--connect`, the path of the tab to drive | `/` |
|
|
215
|
+
| `--gpu <tier>` | Opens the server's own page on `webgpu`, `compat` or `webgl2`. `--connect` ignores it | The engine picks the path |
|
|
216
|
+
| `--size <width>x<height>` | The headless browser's window in CSS pixels. `--connect` ignores it | `1280x720` |
|
|
217
|
+
| `--timeout <seconds>` | How long the page may take to publish the inspector | 60 |
|
|
218
|
+
| `--url <address>` | Uses a dev server that already runs, instead of starting one. The server still starts its own browser | The command starts the dev server |
|
|
219
|
+
| `--connect <address>` | Attaches to Chrome's debugging endpoint and drives the tab that shows the page. Give `--url` or `--connect`, not both | The command starts its own browser |
|
|
220
|
+
|
|
221
|
+
### Objects in a call
|
|
222
|
+
|
|
223
|
+
A call names an object by its name, or by its slot as `#<slot>`, such as `#12`. A whole number names a slot too. `#camera` names the active camera. When several objects share a name, the call takes one of them, so name another by its slot. `list_objects` gives each object's slot.
|
|
224
|
+
|
|
225
|
+
`list_objects` takes two optional arguments. `filter` keeps the objects whose name or kind holds the text, and `limit` gives the most objects to return. A listing returns at most 50,000 objects. It also gives the count of objects that matched, and whether it left some out.
|
|
226
|
+
|
|
227
|
+
| Tool | What it does |
|
|
228
|
+
| --- | --- |
|
|
229
|
+
| `list_objects` | Names, slots, handles, kinds, static or dynamic, visibility, layers, parents and children, with a filter and a limit |
|
|
230
|
+
| `get_object` | Reads one object's transform, flags and material |
|
|
231
|
+
| `set_transform` | Changes a transform, visibility, the static or dynamic flag, or layers |
|
|
232
|
+
| `set_material` | Changes a mesh's material values |
|
|
233
|
+
| `capture` | Returns a PNG of the current frame |
|
|
234
|
+
| `stats` | Frame figures: frame rates, CPU and GPU time, draw calls, triangles, objects, uploads, memory, the path and the preset |
|
|
235
|
+
| `errors` | The engine errors, and the console's errors and warnings |
|
|
236
|
+
| `render_graph` | The compiled render graph as DOT text |
|
|
237
|
+
| `set_quality` | Switches the preset, or changes quality settings |
|
|
238
|
+
| `set_gpu` | Switches the GPU path and reloads the page, your own tab too with `--connect` |
|
|
239
|
+
|
|
240
|
+
Live changes are for exploring. Write the final values into the sketch and its tests. [Debugging](../guides/debugging.md#the-mcp-server) shows the calls and the in-page inspector behind them.
|
|
241
|
+
|
|
188
242
|
## test
|
|
189
243
|
|
|
190
244
|
```mermaid
|
|
@@ -253,7 +307,7 @@ Each image test compares its image with a reference image in `tests/references/<
|
|
|
253
307
|
|
|
254
308
|
Each run saves its images in `test-results/null3d/<environment>/<tier>/`: `<name>.png`, and `<name>-diff.png` when the image differs from its reference. The diff marks the pixels that differ in red. Keep `test-results/` out of git.
|
|
255
309
|
|
|
256
|
-
An image passes when at most 0.1% of its pixels differ from the reference. A pixel differs when its color moves more than 10% of the color range. Pixels on the anti-aliased edges of shapes never count.
|
|
310
|
+
An image passes when at most 0.1% of its pixels differ from the reference. A pixel differs when its color moves more than 10% of the color range. Pixels on the anti-aliased edges of shapes never count.
|
|
257
311
|
|
|
258
312
|
A new test has no reference, so its first run fails and saves the image. Open the image. When it is right, run `bunx @null3d/cli test --update-references` to keep it as the reference. Do the same after a change that alters an image on purpose, and check the new references in your git diff before you commit them. With `--update-references`, an image that matches its reference leaves the reference as it is.
|
|
259
313
|
|
|
@@ -262,7 +316,7 @@ A new test has no reference, so its first run fails and saves the image. Open th
|
|
|
262
316
|
```text
|
|
263
317
|
PASS type check (tsc --noEmit)
|
|
264
318
|
SKIP lint: the project's package.json has no lint script
|
|
265
|
-
The images are drawn in Chrome
|
|
319
|
+
The images are drawn in Chrome 156.0.8078.80 on this computer's GPU, and compared with the references in tests/references/chrome-real-gpu.
|
|
266
320
|
PASS start on webgpu: it matches the reference (image test-results/null3d/chrome-real-gpu/webgpu/start.png)
|
|
267
321
|
FAIL start on webgl2: 2.280% of pixels differ from the reference, and at most 0.100% may (image test-results/null3d/chrome-real-gpu/webgl2/start.png, reference tests/references/chrome-real-gpu/webgl2/start.png, diff test-results/null3d/chrome-real-gpu/webgl2/start-diff.png)
|
|
268
322
|
FAIL harbor-at-night on webgpu: there is no reference yet. When the image is right, bunx @null3d/cli test --update-references keeps it as the reference (image test-results/null3d/chrome-real-gpu/webgpu/harbor-at-night.png)
|
|
@@ -283,13 +337,14 @@ An image test also fails in these cases, and its line says why:
|
|
|
283
337
|
flowchart LR
|
|
284
338
|
bench["bunx @null3d/cli bench"] --> build["A production build<br/>with your Vite config"]
|
|
285
339
|
build --> page["A headless browser opens<br/>your page with ?bench"]
|
|
286
|
-
page -->
|
|
340
|
+
page --> first["The first frame<br/>and the preset check"]
|
|
341
|
+
first --> warm["Warm-up,<br/>not measured"]
|
|
287
342
|
warm --> measure["engine.measure"]
|
|
288
343
|
measure -->|"next run"| page
|
|
289
344
|
measure --> json["bench.json"]
|
|
290
345
|
```
|
|
291
346
|
|
|
292
|
-
`bench` measures the engine on your page. It builds your project for production with your Vite config, into a temporary folder, and serves the build. A production build has none of the engine's development checks, so the engine runs as your users get it. Then `bench` opens your page in a headless browser with the `?bench` switch, once for each run. Each run lets the page
|
|
347
|
+
`bench` measures the engine on your page. It builds your project for production with your Vite config, into a temporary folder, and serves the build. A production build has none of the engine's development checks, so the engine runs as your users get it. Then `bench` opens your page in a headless browser with the `?bench` switch, once for each run. Each run waits for the engine's first frame and for the end of its [preset check](../concepts/quality-presets.md#the-preset-check). It then lets the page play for the warm-up, and measures it with `engine.measure` ([Performance guide](../guides/performance.md#measure)). So a run measures the preset that plays, not the start. Your page needs no benchmark code.
|
|
293
348
|
|
|
294
349
|
```sh
|
|
295
350
|
bunx @null3d/cli bench --gpu webgpu,webgl2
|
|
@@ -301,10 +356,10 @@ bunx @null3d/cli bench --gpu webgpu,webgl2
|
|
|
301
356
|
| `--gpu <tiers>` | The GPU paths to measure, joined by commas: `webgpu`, `compat` and `webgl2` | The engine picks the path |
|
|
302
357
|
| `--runs <count>` | Fresh runs on each GPU path | 5 |
|
|
303
358
|
| `--seconds <seconds>` | How long each run measures | 30 |
|
|
304
|
-
| `--warmup <seconds>` | How long each run lets the page
|
|
359
|
+
| `--warmup <seconds>` | How long each run lets the page play, after its first frame and the preset check, before it measures | 5 |
|
|
305
360
|
| `--size <width>x<height>` | The browser window's size in CSS pixels | `1280x720` |
|
|
306
361
|
| `--out <file.json>` | The JSON file to write | `bench.json` |
|
|
307
|
-
| `--timeout <seconds>` | How long the page may take to start the engine | 60 |
|
|
362
|
+
| `--timeout <seconds>` | How long the page may take to start the engine, draw its first frame and end the preset check | 60 |
|
|
308
363
|
|
|
309
364
|
With more than one GPU path, `bench` takes one run on each path in turn. A computer that slows down during the command then slows every path alike. The runs take several minutes, so `bench` prints a line after each run.
|
|
310
365
|
|
|
@@ -340,7 +395,7 @@ When a run fails, `bench` says why after the figures of its path, and exits with
|
|
|
340
395
|
| `environment`, `browser` | Where the runs drew, as for `shot`, and the browser's version |
|
|
341
396
|
| `warmupSeconds`, `measureSeconds` | The warm-up and the measured time of each run |
|
|
342
397
|
| `paths` | One entry for each GPU path: `gpu`, the tier that `--gpu` forced or `null`; `tier`, the path that the engine drew with; `summary`, the medians and the spread of the runs; and `runs` |
|
|
343
|
-
| `runs` | Each run's figures from `engine.measure` in `stats`, with its GPU path and the engine's mode, or `ok: false` and the `error` that stopped it |
|
|
398
|
+
| `runs` | Each run's figures from `engine.measure` in `stats`, with its GPU path and the engine's mode, or `ok: false` and the `error` that stopped it. The mode names the preset that played, after the preset check |
|
|
344
399
|
| `error` | What stopped `bench` before its runs, such as a production build that failed |
|
|
345
400
|
| `errors`, `warnings` | What the pages and the server logged, each entry once |
|
|
346
401
|
|
|
@@ -357,9 +412,12 @@ When a run fails, `bench` says why after the figures of its path, and exits with
|
|
|
357
412
|
`check-addon` runs the engine's gates on one add-on package. An add-on's author runs it before a release, and a listing runs it before it publishes the add-on. It prints one line for each gate, and exits with 1 when a gate fails. [Building an add-on](../guides/add-ons.md) gives the rules that the gates check.
|
|
358
413
|
|
|
359
414
|
```sh
|
|
360
|
-
bunx @null3d/cli check-addon
|
|
415
|
+
bunx @null3d/cli check-addon # the add-on in the current folder
|
|
416
|
+
bunx @null3d/cli check-addon packages/my-addon
|
|
361
417
|
```
|
|
362
418
|
|
|
419
|
+
It checks the add-on in the folder that you name, or in the current folder without one.
|
|
420
|
+
|
|
363
421
|
| Gate | What it checks |
|
|
364
422
|
| --- | --- |
|
|
365
423
|
| package | the folder has a manifest with a name and an entry file |
|
|
@@ -367,7 +425,8 @@ bunx @null3d/cli check-addon addons/splats
|
|
|
367
425
|
| interface | the entry declares the plugin interface range that it works with, or, for a `@null3d/...` package, pins the exact engine version |
|
|
368
426
|
| shaders | a build compiles the add-on's WGSL for WebGPU and WebGL2 |
|
|
369
427
|
| sizes | each file that the add-on loads after the start holds to its budget: its own code to the budget for code, and the compiled WGSL that the build inlined in it to the budget for shader builds. The gate warns, and does not fail, when a file goes over a budget |
|
|
370
|
-
| page | the page starts from another origin under the strict policy
|
|
428
|
+
| page | the page starts from another origin under the strict policy |
|
|
429
|
+
| cost | the page's cost per frame, measured on each quality preset |
|
|
371
430
|
| allocation | the bytes per frame that the add-on's own code allocates, on each quality preset |
|
|
372
431
|
|
|
373
432
|
The shader and size gates build the add-on with the Vite and the null3D plugin that it installs. The page gates take the page of the first test in `null3d.json`, or the page that `--page` names. The page gates are skipped when there is no page.
|
|
@@ -378,7 +437,7 @@ The shader and size gates build the add-on with the Vite and the null3D plugin t
|
|
|
378
437
|
| `--skip-browser` | Runs no gate that opens a browser | The page gates run |
|
|
379
438
|
| `--skip-cost` | Leaves out the cost gate alone, for a machine whose load would show in the figures. The page and allocation gates still run | The cost gate runs |
|
|
380
439
|
|
|
381
|
-
Each page gate draws as `bench` does: with Chrome on the computer's GPU, or with Playwright's Chromium on SwiftShader when the CI variable is set. The cost gate measures the production build on each quality preset. It prints the GPU time per frame where the device times it, and the CPU time otherwise.
|
|
440
|
+
Each page gate draws as `bench` does: with Chrome on the computer's GPU, or with Playwright's Chromium on SwiftShader when the CI variable is set. The cost gate measures the production build on each quality preset. Like `bench`, it waits for the first frame and the end of the preset check before it measures. It prints the GPU time per frame where the device times it, and the CPU time otherwise.
|
|
382
441
|
|
|
383
442
|
The allocation gate samples the heaps of the page's sketch and render workers. It names each function by the source file that the build's map gives it. It prints the bytes per frame that the add-on's own code allocated on each preset, and the page's own figure beside it. A source file counts as the add-on's own when the file is in its folder, or in its copy under `node_modules`. The gate fails when it cannot measure the page, such as on a page that runs no engine worker. It also fails when the page ran none of the add-on's own code, because then it measured other code. It never fails on a figure. The gate holds at most 250,000 sampled objects for each worker in each sample, and samples a page that allocates faster less finely. On the software GPU, the page's animation frames outrun the engine's drawn frames, so the figure there is lower than on a real GPU.
|
|
384
443
|
|
|
@@ -451,7 +510,7 @@ bunx @null3d/cli assets pack-orm textures/brick_orm.ktx2 --occlusion brick_ao.pn
|
|
|
451
510
|
| `--metalness <image>` | The metalness map | Black |
|
|
452
511
|
| `--max-texture-size <pixels>` | The largest side of a `.ktx2` texture: a power of two up to 2048 | 2048 |
|
|
453
512
|
|
|
454
|
-
`assets normal-from-bump` makes a normal map from a height map, such as a
|
|
513
|
+
`assets normal-from-bump` makes a normal map from a height map, such as a bump map.
|
|
455
514
|
|
|
456
515
|
```sh
|
|
457
516
|
bunx @null3d/cli assets normal-from-bump textures/stone_bump.png textures/stone_normal.ktx2 --scale 2
|
|
@@ -459,12 +518,28 @@ bunx @null3d/cli assets normal-from-bump textures/stone_bump.png textures/stone_
|
|
|
459
518
|
|
|
460
519
|
| Option | Effect | Without it |
|
|
461
520
|
| --- | --- | --- |
|
|
462
|
-
| `--scale <number>` | The strength of the slopes, as
|
|
521
|
+
| `--scale <number>` | The strength of the slopes, as the standard material's [`bumpScale`](../api/materials.md) | 1 |
|
|
463
522
|
| `--clamp` | The map does not tile, so the edge texels take no neighbors from the opposite edge | The map tiles |
|
|
464
523
|
| `--max-texture-size <pixels>` | The largest side of a `.ktx2` texture: a power of two up to 2048 | 2048 |
|
|
465
524
|
|
|
466
525
|
Both exit with 1 when an image cannot be read. [The asset pipeline](../guides/assets-pipeline.md#pack-occlusion-roughness-and-metalness) says what each makes.
|
|
467
526
|
|
|
527
|
+
`assets impostor` bakes a model's impostor atlases ahead of time, for the cards of [`@null3d/impostors`](../api/impostors.md). It draws every mesh of the model's scene from each cell of an octahedral grid. It uses the add-on's own bake, so the atlases match a bake in the sketch texel for texel.
|
|
528
|
+
|
|
529
|
+
```sh
|
|
530
|
+
bunx @null3d/cli assets impostor models/pine.glb --out public/trees --views 25 --texels 64
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
| Option | Effect | Without it |
|
|
534
|
+
| --- | --- | --- |
|
|
535
|
+
| `--out <folder>` | The folder for the three files | The model's folder |
|
|
536
|
+
| `--views <count>` | The fewest views in the grid: the command takes the squarest grid that holds them | 25, a five by five grid |
|
|
537
|
+
| `--texels <count>` | The texels on each side of a cell | 64 |
|
|
538
|
+
|
|
539
|
+
It writes three files, named after the model. `pine-impostor.json` describes the bake: its grid, the card's size, its room and its depth. The image `pine-impostor-color.png` holds the color atlas in sRGB. The image `pine-impostor-surface.png` holds the normals, the depth and the coverage. Each image is upright: its top left cell is the grid's first cell. In the sketch, the add-on's `loadImpostorAtlas` loads the three files ([Impostors](../api/impostors.md#load-a-baked-atlas)).
|
|
540
|
+
|
|
541
|
+
The bake reads each material's base color factor and texture, its alpha mode and cutoff, and whether it draws both sides. A base color texture must be a PNG or JPEG image. So bake the source model, not a model that `assets optimize` wrote with KTX2 textures. The command draws triangle lists alone, and leaves out points and lines. An atlas holds at most 4,096 texels on a side. It exits with 1 when the model cannot be read or baked.
|
|
542
|
+
|
|
468
543
|
## upgrade
|
|
469
544
|
|
|
470
545
|
```mermaid
|
|
@@ -503,7 +578,7 @@ Run it after you upgrade the engine alone, or when a page stops with [E1432](../
|
|
|
503
578
|
|
|
504
579
|
## Where the commands draw
|
|
505
580
|
|
|
506
|
-
`shot`, `test` and `
|
|
581
|
+
`shot`, `test`, `bench` and `check-addon` draw with Chrome for Testing on your computer's GPU. So does `mcp`, unless `--connect` drives your own Chrome. When the `CI` variable is set, they draw with Playwright's Chromium on SwiftShader, a GPU in software. Most CI machines have no GPU. Set `CI=1` to draw the software GPU's images on your own computer:
|
|
507
582
|
|
|
508
583
|
```sh
|
|
509
584
|
CI=1 bunx @null3d/cli shot --out ci-shot.png
|
|
@@ -517,7 +592,7 @@ The two draw the edges of objects a little differently, so keep reference images
|
|
|
517
592
|
Chrome for Testing is Google's build of Chrome for automated runs. The tool pins one version of it on every platform. So a reference image drawn on one computer matches another's. A release of the tool may move the pin to a newer Chrome, and its notes say so when pages draw differently.
|
|
518
593
|
|
|
519
594
|
- **First use.** The first command that draws downloads the pinned build for your platform, about 200 MB. It prints what it downloads and how far it has got. Later commands reuse it.
|
|
520
|
-
- **The check.** The tool records the SHA-256 hash of the pinned build's archive on each platform. It checks the download against that hash before it unpacks it. An archive with another hash is deleted, and the
|
|
595
|
+
- **The check.** The tool records the SHA-256 hash of the pinned build's archive on each platform. It checks the download against that hash before it unpacks it. An archive with another hash is deleted, and the tool installs nothing ([E1437](../errors/E1437.md)). The command then falls back, as the next items say. The tool keeps the hash it checked beside the build, and it trusts a cached build only with that record.
|
|
521
596
|
- **Where it lives.** `null3d/chrome-for-testing/<version>` under `$XDG_CACHE_HOME` when that is set, or under `~/.cache`. Every project on the computer shares it. Delete the folder to download it again.
|
|
522
597
|
- **Why not Google Chrome.** On macOS, Google Chrome makes keys in the keychain each time it starts. It keeps them when it closes early, as a headless run often does. Many runs fill the keychain and slow its service down. Chrome for Testing has no access to the keychain.
|
|
523
598
|
- **When the download fails.** This includes a download whose hash does not match. The command draws with your installed Google Chrome instead. It warns that this may leave keys in the keychain on macOS. Its pictures can differ a little from the references when its version differs.
|