@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
|
@@ -59,7 +59,7 @@ Starts the engine on the page. It tests the device, picks the build and the GPU
|
|
|
59
59
|
type DepthMode = 'reversed' | 'reversed-gl' | 'standard';
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
How the GPU path stores depth. In `reversed` depth, the near plane stores 1 and the far plane 0, in a 32-bit float depth buffer. That keeps depth precise far from the camera. WebGPU always draws it. WebGL2 draws it where the browser has the `EXT_clip_control` extension, which gives WebGL2 the depth range from 0 to 1 that WebGPU has. The `reversed-gl` mode keeps the same order, but in WebGL2's own depth range from -1 to 1, which loses most of the precision. In `standard` depth, the near plane stores 0
|
|
62
|
+
How the GPU path stores depth. In `reversed` depth, the near plane stores 1 and the far plane 0, in a 32-bit float depth buffer. That keeps depth precise far from the camera. WebGPU always draws it. WebGL2 draws it where the browser has the `EXT_clip_control` extension, which gives WebGL2 the depth range from 0 to 1 that WebGPU has. The `reversed-gl` mode keeps the same order, but in WebGL2's own depth range from -1 to 1, which loses most of the precision. In `standard` depth, the near plane stores 0 and the far plane 1.
|
|
63
63
|
|
|
64
64
|
## `DrawPathReason`
|
|
65
65
|
|
|
@@ -88,18 +88,20 @@ A running engine, as `createEngine` returns it.
|
|
|
88
88
|
| `readonly capabilities: EngineCapabilities` | The GPU path the engine chose, and what it offers. |
|
|
89
89
|
| `readonly report: CapabilityReport` | The full capability report, as plain JSON. |
|
|
90
90
|
| `readonly mode: EngineMode` | How the engine runs on this device. |
|
|
91
|
-
| `readonly firstFrame: Promise<void>` | Resolves once the GPU has finished the first frame, so it is on screen: the moment to remove a loading screen. It
|
|
91
|
+
| `readonly firstFrame: Promise<void>` | Resolves once the GPU has finished the first frame after the setup, so it is on screen: the moment to remove a loading screen. It rejects when the engine stops drawing first, with the failure that ended its frames, such as E1404 when the thread that draws fails at its first frame. A destroy before the first frame rejects it with E1420. A page that never waits for it gets no unhandled rejection. |
|
|
92
|
+
| `readonly presetChecked: Promise<void>` | Resolves once the preset check has ended, so `mode.preset` holds the preset that the check chose and `mode.presetCheck` what it measured. It has resolved when `createEngine` resolves where no check runs: for a preset that the page names, a stored result, Low, and hold mode, and with the `presetCheck` option's `before-play`. When the engine stops drawing first, it resolves then, and `mode.presetCheck` stays null. |
|
|
92
93
|
| `readonly labels: EngineLabels` | The HTML elements that follow the labels the sketch tracks with `ui.trackLabel`. |
|
|
93
94
|
| `registerVideo(video: HTMLVideoElement, options: VideoOptions): () => void` | Shows a video element on the page as a texture in the sketch, which makes it with `textures.fromVideo(name)`. The page sends the image of each frame that the video presents, as an `ImageBitmap` of the size that the options allow, and the sketch uploads it in its turn, within the frame's upload budget. The sketch asks for the frames when its texture follows the video, so a video that no texture shows sends none, and a paused video presents no frame, so it costs nothing. Returns a function that stops the frames, which the video's texture then keeps the last frame of. Throws E1213 for a name that another video holds, or an option out of range. |
|
|
94
95
|
| `postToSketch(name: string, data?: unknown, transfer?: Transferable[]): void` | Sends a message to the sketch, which receives it through `ctx.page.onMessage`. |
|
|
95
96
|
| `onSketchMessage(handler: (name: string, data: unknown) => void): () => void` | Receives the messages the sketch sends with `ctx.page.post`. When no handler listened from the start, the first handler also receives the messages sent before it was registered. Returns a function that removes the handler. |
|
|
96
|
-
| `onFailure(handler: (error: EngineError) => void): () => void` | Receives a failure after the engine started: the browser took the GPU away and the engine could not carry on with a new device (E1302), or an engine thread failed (E1404). A custom shader's builds that a pipeline needs and that did not download fail the thread that draws with E1424. After E1404 or E1424 the engine draws no new frames: destroy it and start a new one. On WebGPU, the GPU can also run out of memory (E1304) or reject the engine's work (E1305),
|
|
97
|
+
| `onFailure(handler: (error: EngineError) => void): () => void` | Receives a failure after the engine started: the browser took the GPU away and the engine could not carry on with a new device (E1302), or an engine thread failed (E1404). A custom shader's builds that a pipeline needs and that did not download fail the thread that draws with E1424. After E1404 or E1424 the engine draws no new frames: destroy it and start a new one. On WebGPU, the GPU can also run out of memory (E1304) or reject the engine's work (E1305). On either GPU path, its driver can refuse to build a pipeline that draws objects of the scene twice (E1307). After these three the engine draws on without the objects that failed. The engine reports each failure once. A failure that no handler listened for when the engine reported it reaches the first handler that listens, so a failure that the app could not hear yet still arrives, and the engine also logs it to the console. A failure that ends the frames reaches these handlers before `onStop`'s. Returns a function that removes the handler. |
|
|
97
98
|
| `onStop(handler: () => void): () => void` | Calls `handler` once, when the engine stops drawing for good: as `destroy()` begins, or at a failure after which it draws no new frames (E1302, E1404 or E1424). At such a failure, the `onFailure` handlers hear it first. A handler added after that runs at once. A handler that throws reaches the console, and the other handlers and the stop go on. Use it to end the page's own work for the engine, such as a frame loop that sends the sketch messages. Returns a function that removes the handler. |
|
|
98
99
|
| `onSketchError(handler: (error: Error) => void): () => void` | Receives each distinct error that the sketch's own code, or a core call in a frame, threw while the engine runs. The engine keeps drawing, so this error alone does not stop it: a frame whose update failed is counted in `measure().updateErrors` and left out of `measure().updatedFps`. The handler receives the errors reported after it was added. Returns a function that removes the handler. Without a handler, the error also reaches the console. |
|
|
99
100
|
| `setPaused(paused: boolean): void` | Pauses or resumes the sketch's frames. A pause also stops input: the sketch sees every key and button that was down come up, and input that comes during the pause never reaches it. |
|
|
100
101
|
| `detach(): void` | Takes the canvas off the page and pauses the engine. The engine keeps its threads, its GPU resources and the scene, and stops reading input. Use it when a single-page app leaves the view that shows the canvas, and `attach` when the view comes back. |
|
|
101
102
|
| `attach(container: Element): void` | Puts the canvas at the end of `container` and resumes the engine where it stopped, unless `setPaused(true)` paused it. |
|
|
102
103
|
| `measure(seconds: number, options?: MeasureOptions): Promise<FrameMetrics>` | Measures the running engine for a number of seconds, then returns CPU time per frame by thread and phase, GPU time, frame intervals, uploads, draw calls, memory and load time. The first call downloads the code that turns the frame records into these figures. `slowMs` adds the frames whose interval broke that many milliseconds, each with the frame's own GPU parts. |
|
|
104
|
+
| `inspect(call: string, args?: unknown): Promise<unknown>` | Runs an inspection call against the live scene, for the in-page inspector and the MCP server: `objects`, `object`, `setObject`, `setMaterial`, `stats`, `errors`, `graph`, `setQuality`, `highlight` and `info`, with the arguments that [Debugging](../../guides/debugging.md#the-in-page-inspector) lists. The call runs between frames, in the thread that runs the sketch, and its value is JSON-safe. The page answers `capture` itself, with `{ png, bytes }`: the PNG image of the next frame as base64 text, and its size in bytes. The method exists only in a development build, which is the build that carries the channel; a release build leaves it out, so code that uses it must check for it first. |
|
|
103
105
|
| `stats(show?: boolean \| StatsOverlayOptions): void` | Shows an overlay of figures over the top-right corner of the canvas, or hides it with `false`: the GPU path, the frame rates, CPU time per frame of each thread, GPU time, draw calls, triangles and objects drawn, memory, and the page thread's long tasks and input delay. Its header is a button with the frame rate, which shows and hides the other figures. Options pick whether the overlay starts collapsed to its header; a call on a shown overlay changes the options it names. The page draws the overlay and updates it a few times a second, and its code downloads at the first call. While the other figures show, the engine times one frame in eleven on the GPU and reads back the counts of the objects that the GPU culls, which costs a little GPU time. The sketch's `debug.stats` shows and hides the same overlay, and the last call wins. |
|
|
104
106
|
| `capture(): Promise<Blob>` | Resolves with an image of the next frame that the engine draws, as a PNG file. The thread that draws reads the frame back and encodes it, so the page's thread does no work for it when a worker draws. In hold mode it is an image of the held frame, whose pixels the page keeps, so the GPU draws nothing for it. While the engine is paused, the image shows the frame on the canvas. A hidden page draws no frames, so its image comes once the page shows again. When no new frame comes within a second or two, as after a sketch error, the image shows the frame drawn last. Fails with E1414 once the engine has stopped, when the thread that draws gives no answer within the engine's wait, or when that thread could not read the frame back, with the cause that the GPU gave, such as a lost device or too little memory. |
|
|
105
107
|
| `captureFrame(): Promise<{ width: number; height: number; pixels: Uint8Array; frame: number; }>` | Resolves with the pixels of the next frame that the engine draws, as RGBA8 rows, top row first, for tests. The thread that draws waits until its frame loop has taken a new frame, then draws that frame again offscreen and reads it back, so captures back to back give newer frames even where each readback holds that thread up. `frame` is the sketch frame that the capture drew: a capture that follows a scene change can hold the frame recorded before it, and a test that measures frames aligns them by this number. In hold mode, and while the engine is paused, it returns the frame on the canvas. A hidden page draws no frames, so its pixels come once the page shows again. When no new frame comes within a second or two, as after a sketch error, it returns the frame drawn last. It fails when the thread that draws gives no answer within the engine's wait, rather than waiting with no end. |
|
|
@@ -153,8 +155,8 @@ How the engine runs on this device: its build, its latency mode and its threads.
|
|
|
153
155
|
| `renderThread: 'render-worker' \| 'sketch-worker' \| 'main'` | The thread that owns the canvas and draws. |
|
|
154
156
|
| `jobWorkers: number` | The most job workers that share the engine's parallel work. The engine starts none at first, and starts them as the work grows. |
|
|
155
157
|
| `hold: number \| null` | The sketch time in seconds that hold mode holds the sketch at, or null for a live engine. |
|
|
156
|
-
| `preset: QualityPreset` | The quality preset that the engine runs. The preset check can lower it before `createEngine` resolves
|
|
157
|
-
| `presetCheck: PresetCheck \| null` | What the preset check measured, or null when no check ran. The engine checks the preset when it chose it from the device: after the first frame, it measures the frame rate of the scene
|
|
158
|
+
| `preset: QualityPreset` | The quality preset that the engine runs now. The preset check can lower it while it runs: during the first frames of play, or before `createEngine` resolves with the `presetCheck` option's `before-play`. `ctx.quality.setPreset` in the sketch changes it later. Once `engine.presetChecked` has resolved, it holds the preset that the check chose. |
|
|
159
|
+
| `presetCheck: PresetCheck \| null` | What the preset check measured, or null while the check runs, and when no check ran or the sketch chose its own preset first. The engine checks the preset when it chose it from the device: after the first frame, it measures the frame rate of the scene, and lowers the preset until one holds the target. A later start of the sketch in the same browser on the same device takes the stored result instead, and starts at its preset. `reused` is then true. A start after a check that never ended starts at the preset that the check had lowered to, and its own check goes on from there, with the earlier rounds first. |
|
|
158
160
|
| `crashedStarts: number` | The starts of this sketch before this one that crashed the tab, one after another, as the engine's note in `localStorage` records them. After one, the engine starts a preset lower, and after two at `low`. |
|
|
159
161
|
| `memoryMaximumMiB: number \| null` | The shared memory's maximum in MiB, or null for the single-threaded build, whose memory is not shared. |
|
|
160
162
|
| `renderFallback: RenderFallback \| null` | Why the page draws when a worker was meant to, or null when the thread that draws is the one that the options asked for. `report.worker` holds the probe's answer. |
|
|
@@ -172,6 +174,7 @@ Options for `createEngine`.
|
|
|
172
174
|
| `sketch: URL \| string` | The sketch module, which runs in the sketch worker; `new URL('./sketch.ts', import.meta.url)`. |
|
|
173
175
|
| `preset?: 'auto' \| QualityPreset` | The quality preset: `auto`, the default, lets the engine choose one for the device, and `low`, `medium`, `high` or `ultra` names one. The GPU path caps it: WebGL2 and WebGPU's compatibility mode run at most `medium`. After a start that crashed the tab, the engine starts a preset lower. Another value fails with E1213. The `?preset=` switch wins over it. |
|
|
174
176
|
| `targetFps?: TargetFps` | The frame rate that the engine defends: the preset check and the quality governor lower the quality when frames fall below it. Without it, the target is the display's refresh rate, at most 60. `display` targets the display's full rate, such as 120 or 144 for a game on a fast display. A whole number from 1 up caps the target at that rate. The engine draws at the display's rate in every case. The `?target-fps=` switch wins over it. Another value fails with E1213. |
|
|
177
|
+
| `presetCheck?: PresetCheckTiming` | When the preset check measures, on a start where the engine checks the preset that it chose. With `during-play`, the default, the scene shows at its first frame: `createEngine` resolves once the setup has run, and `engine.firstFrame` once the GPU has finished the first frame. The check then measures the first frames of play, a lighter preset applies in front of the viewer, and `engine.presetChecked` resolves once the check has ended. With `before-play`, the check measures the scene that the setup built before the sketch's update runs, and `createEngine` resolves after it, so a loading screen hides the check and any change of preset. A start that takes the stored result of an earlier check, or that runs no check, plays at once either way. Another value fails with E1213. The `?preset-check=` switch wins over it. |
|
|
175
178
|
| `maxPixelRatio?: number` | Cap for the device pixel ratio, a number from 0.5 up. Without it, the quality preset sets the cap. `ctx.quality.set` changes it during play. |
|
|
176
179
|
| `gpu?: 'auto' \| 'webgpu' \| 'webgl2'` | Forces a GPU tier, for testing only. |
|
|
177
180
|
| `powerPreference?: 'high-performance' \| 'low-power'` | Which GPU to draw with on a device that has two, such as a laptop with a separate graphics chip: `high-performance`, the default, for the faster one, or `low-power` to save battery. The browser treats it as a request. A device with one GPU ignores it. |
|
|
@@ -183,14 +186,14 @@ Options for `createEngine`.
|
|
|
183
186
|
| `shadowTileSize?: number` | Texels on each side of each tile of the shadow atlas: 256, 512, 1,024 or 2,048. Without it, the quality preset sets it. Another value fails with E1213. |
|
|
184
187
|
| `heroTileSize?: number` | Texels on each side of the tile that holds a directional light's hero shadow, for each light whose `shadow` options name no `heroTileSize`: 1,024, 2,048 or 4,096. Without it, the quality preset sets it. Another value fails with E1213. |
|
|
185
188
|
| `pointLightShadows?: boolean` | True makes point lights cast shadows, false keeps them from it. Without it, the quality preset decides: High and Ultra turn them on. Another value fails with E1213. |
|
|
186
|
-
| `depthPrepass?: boolean` | True to draw the depth of the opaque objects before the engine shades them, so each pixel is shaded once, for its nearest surface. It saves GPU time in scenes where objects hide many others and shading costs much, and costs a second pass over the objects' vertices. Without it, the quality preset decides: every preset draws the prepass on WebGL2, and none on WebGPU.
|
|
189
|
+
| `depthPrepass?: boolean` | True to draw the depth of the opaque objects before the engine shades them, so each pixel is shaded once, for its nearest surface. It saves GPU time in scenes where objects hide many others and shading costs much, and costs a second pass over the objects' vertices. Without it, the quality preset decides: every preset draws the prepass on WebGL2, and none on WebGPU. A sketch can change it during play with `quality.set`, and the `?prepass=on` or `?prepass=off` switch wins over this option. Another value fails with E1213. |
|
|
187
190
|
| `momentTransparency?: boolean` | True to blend the camera's blended surfaces in the moment transparency layer. It needs no sort and is nearer an exact back-to-front blend than `blending: 'weighted'` is, and it draws those surfaces twice. Every preset leaves it off, and the `?moments=on` or `?moments=off` switch wins over this option. It stays fixed while the engine runs. Another value fails with E1213. |
|
|
188
191
|
| `gpuOcclusion?: boolean` | True to run GPU occlusion culling on WebGPU: large opaque objects hide the objects that lie wholly behind them, so the GPU skips those. Each camera view draws the depth of the opaque objects that it showed in the last frame and that look large on the screen, and tests every object against it. `setOccluder(false)` keeps an object out of them. A check during play turns the extra passes off while they hide too little or make the GPU's frame longer, and on again when they pay. Without the option, the High and Ultra presets turn it on for desktops, and phones and tablets leave it off. It stays fixed while the engine runs, and the `?occlusion=on` or `?occlusion=off` switch wins over this option. WebGL2 and the depth prepass draw without it. Another value fails with E1213. |
|
|
189
192
|
| `morphTargets?: number` | The most morph target weights of each object that a WebGL2 device draws, a whole number from 1 to 256. Each object keeps the weights farthest from 0. Without it, the quality preset sets it. WebGPU draws every weight. Another value fails with E1213. |
|
|
190
193
|
| `cloudSteps?: number` | The steps of each ray of the sky's volumetric cloud tier when the engine starts, a whole number from 0 to 64. Above 0 the sky draws volumetric clouds in place of the flat layer, from the same cloud settings; 0 draws the flat layer. Without it, the quality preset sets it: 0 on Low and Medium, 32 on High and 48 on Ultra. It lets a page on WebGL2 or in compatibility mode, whose presets stop at Medium, draw the tier. The sky's environment map marches at most 16 steps, and draws them only when this option is above 0, because the map picks its tier's shaders at the page's start. A sketch can change the sky's count during play with `quality.set`. Another value fails with E1213. |
|
|
191
194
|
| `softwareOcclusion?: boolean` | True to run software occlusion culling on WebGL2: objects that `setOccluder(true)` marks hide the objects that lie wholly behind them, so the GPU skips those. False turns it off. Without it, the quality preset decides, and a sketch can change it during play with `quality.set`. The `?occlusion=on` or `?occlusion=off` switch wins over this option. WebGPU ignores it. Another value fails with E1213. |
|
|
192
195
|
| `textureMemoryMiB?: number` | The GPU memory in MiB that textures may take, a whole number from 64 to 16,384. Past it, the engine drops the largest mip levels of textures from files, and loads them again once room returns. Without it, the quality preset sets it: 256, 512, 1,024 or 2,048 from Low to Ultra, and at most 1,008 on phones and tablets. A sketch can change it during play with `quality.set`. Another value fails with E1213. |
|
|
193
|
-
| `keepTextureCopies?: boolean` | True keeps the engine's copy of each texture's texels after their upload, so a texture that maps an image draws with its map again after the browser takes the GPU away. It costs about one more copy of each image in memory. False frees each copy once no frame reads it, and such a texture draws with its color alone until the sketch gives it texels again. Without this option, a phone and a tablet keep copies and a desktop does not, because a phone or a tablet is likeliest to lose its GPU. |
|
|
196
|
+
| `keepTextureCopies?: boolean` | True keeps the engine's copy of each texture's texels after their upload, so a texture that maps an image draws with its map again after the browser takes the GPU away. It costs about one more copy of each image in memory. False frees each copy once no frame reads it, and such a texture draws with its color alone until the sketch gives it texels again. Without this option, a phone and a tablet keep copies and a desktop does not, because a phone or a tablet is likeliest to lose its GPU. With copies, the engine also gives its GPU back while the browser keeps the page in its back/forward cache, and starts a new device when the page shows again. |
|
|
194
197
|
| `transparent?: boolean` | True for a see-through canvas: the page shows through wherever no object draws, until the sketch sets a background color. The canvas holds premultiplied alpha, as a browser composites it. The default is false, an opaque canvas. |
|
|
195
198
|
| `hdr?: boolean` | False draws the scene into 8-bit color, where each material's shader applies the output transform, instead of HDR color, which the final pass tone maps. Both paths honour a material's `toneMapped: false`, and the 8-bit path also honours it on a blended surface. The default lets the engine pick the path from the device, which draws HDR color wherever it can. The `?hdr=off` switch takes the 8-bit path too. |
|
|
196
199
|
| `largeWorld?: boolean` | True for scenes that reach far beyond a city, such as a planet. Object positions then keep the precision of JavaScript's numbers at any distance from the origin: 0.03 mm or better. Without it, positions are 32-bit floats, which move in steps of 6 cm at 1,000 km from the origin and 0.5 m at the Earth's radius. It costs 12 bytes of memory per object and a little work in each position setter. The default is false. Instance batches need no mode: give each one an `origin` near its rows. |
|
|
@@ -199,14 +202,14 @@ Options for `createEngine`.
|
|
|
199
202
|
| `maxLabels?: number` | The most HTML labels that the sketch can track at once with `ui.trackLabel`: a whole number from 1 to 65,536, 4,096 by default. Another value fails with E1213. The engine keeps three tables of 16 bytes per label in memory that its threads share, so 4,096 labels take 192 KB. |
|
|
200
203
|
| `maxLabels3d?: number` | The most labels that the sketch can track at once with `ui.trackLabel` whose `transform` is `'world'` or `'billboard'`: a whole number from 0 to 65,536, 256 by default. Another value fails with E1213. Each of them is a plane of the scene, which takes three tables of 52 bytes per label, so 256 of them take 40 KB. A sketch that tracks one more fails with E1219. |
|
|
201
204
|
| `expectedObjects?: number` | The number of objects that the scene will hold at most, when the sketch knows it: a whole number from 1 to 1,048,575. Another value fails with E1213. The scene then starts with room for that many, so it never grows during play. Without it, the scene starts with room for 1,023 objects. A scene grows on its own when it needs more: it doubles its room at the start of a frame once it is three quarters full. A create call that finds it full doubles it at once. Each growth copies the scene's tables, about 267 bytes per object, in one short pause. Set this option for a scene that creates many objects during play, so they never wait for one. |
|
|
202
|
-
| `onProgress?: (stage: StartupStage, progress?: StartupProgress) => void` | Called as the start reaches each stage, in this order: `core-download` as the engine core's file downloads, with the bytes that have arrived; `core` once the engine core is compiled and the GPU paths are tested; `sketch` once the sketch's setup has run; and `first-frame` once the GPU has finished the first frame. Before `core`, `core-download` reports the core file's bytes, and `memory-wait` comes when the browser has refused the engine's memory for 10 seconds. The engine then tries for about 35 seconds more before it fails with E1109. `progress` gives a stage's figures while it has some: the bytes of a download, measured against the length that the server announced. |
|
|
205
|
+
| `onProgress?: (stage: StartupStage, progress?: StartupProgress) => void` | Called as the start reaches each stage, in this order: `core-download` as the engine core's file downloads, with the bytes that have arrived; `core` once the engine core is compiled and the GPU paths are tested; `sketch` once the sketch's setup has run; and `first-frame` once the GPU has finished the first frame after the setup. The preset check does not hold up either stage, unless the `presetCheck` option is `before-play`: `sketch` then comes after the check too. Before `core`, `core-download` reports the core file's bytes, and `memory-wait` comes when the browser has refused the engine's memory for 10 seconds. The engine then tries for about 35 seconds more before it fails with E1109. `progress` gives a stage's figures while it has some: the bytes of a download, measured against the length that the server announced. |
|
|
203
206
|
| `onSketchMessage?: (name: string, data: unknown) => void` | Receives the messages the sketch sends with `ctx.page.post`, from the start of the sketch's setup. Use it for progress that the sketch reports while it loads. `engine.onSketchMessage` adds more handlers once the engine has started. |
|
|
204
207
|
| `onSketchError?: (error: Error) => void` | Receives each distinct error that the sketch's own code, or a core call in a frame, threw while the engine runs. The error's message holds the failure, such as `E1102: ...`. The engine keeps drawing and presenting frames, so the error alone does not stop it: a frame whose update failed is counted in `measure().updateErrors` and left out of `measure().updatedFps`. `engine.onSketchError` adds more handlers once the engine has started. Without a handler, the error also reaches the console. |
|
|
205
208
|
| `onWorkerRetry?: (worker: string, script: string) => void` | Called when a worker's script did not load before the worker's first message, and the engine started a second copy of it. The fault comes and goes, so the engine recovers on its own: the call names the worker, such as `render` or `job 2`, and the address of its script. The engine also warns in the console. Without a second copy that loads, the start fails with E1405, which names the worker and its script. |
|
|
206
209
|
| `signal?: AbortSignal` | Cancels a start in progress, for example when the user leaves the page. `createEngine` then stops the engine's threads and rejects with the signal's reason. |
|
|
207
210
|
| `hold?: number` | Starts the engine in hold mode for image tests, held at this many seconds of sketch time. The engine steps the sketch from 0 to the time in fixed steps of 1/60 second, with no frame loop. `math.random` and `Math.random` in the sketch's thread give the same numbers on every run, and the sketch gets no input: every key and button stays up. The engine then draws that one frame and reads it back, and `createEngine` resolves. The `?hold=<seconds>` switch overrides this time, and a bare `?hold` holds at it, or at 0 without it. |
|
|
208
211
|
| `input?: boolean` | False keeps the engine from listening for input, for a page whose input another library records, such as a game whose simulation replays a log of it. The engine's input then adds no listener: none for pointers, keys, the wheel, focus, page visibility, the pointer lock or gamepads. It captures no pointer on the canvas, and leaves the canvas's context menu to the browser. The engine keeps its listeners that take no input, such as the canvas watch's `visibilitychange`, after which the sketch's next step counts no hidden time. The sketch's `ctx.input` stays at rest: every key, button and action is up, `value` gives 0, `input.touches` is empty, and the pointer stays at the canvas's top-left corner with no movement, wheel or buttons. Objects get no pointer events, and `requestPointerLock` fails with E1426. A development build warns in the console, once for each kind, when the sketch reads `ctx.input`, gives an object a pointer event handler or imports `@null3d/controls`. The warning about the controls comes as they load in the sketch's thread, so it misses controls that another sketch in that thread loaded first. Two engines on the page's thread both hear a load by either one's sketch. The default is true. |
|
|
209
|
-
| `preload?: readonly ShaderFeature[]` | Features whose shaders load before the first frame, for a game that must fetch nothing while it plays. Each feature's shaders otherwise download the first time the sketch uses it: `'skinning'` with the first skinned mesh, `'morph'` with the first morphed mesh, `'bloom'` and `'ao'` when `post.set` turns them on, `'sprites'` and `'lines'` with the first batch, `'background'` with a texture, environment or cube map background, `'sky'` with the sky, `'coverage'` with the first masked material that MSAA smooths, `'hash'` with the first hashed material, `'cutout'` with the first masked object that casts shadows, which casts none until its shaders are built, `'transmission'` with the first material that lets light through, `'color_copy'` with the first step that reads the color of the frame before, which the preset's bounce light draws at its start, `'translucency'` with the first material that lets light through to its other side, `'subsurface'` with the first material with a `subsurfaceRadius` while the subsurface blur has taps, `'coat_sheen'` with the first material with a clear coat or a sheen, `'weighted'` with the first material of the `weighted` blending, and `'occlusion'` with the first opaque
|
|
212
|
+
| `preload?: readonly ShaderFeature[]` | Features whose shaders load before the first frame, for a game that must fetch nothing while it plays. Each feature's shaders otherwise download the first time the sketch uses it: `'skinning'` with the first skinned mesh, `'morph'` with the first morphed mesh, `'bloom'` and `'ao'` when `post.set` turns them on, `'sprites'` and `'lines'` with the first batch, `'background'` with a texture, environment or cube map background, `'sky'` with the sky, `'coverage'` with the first masked material that MSAA smooths, `'hash'` with the first hashed material, `'cutout'` with the first masked object that casts shadows, which casts none until its shaders are built, `'transmission'` with the first material that lets light through, `'color_copy'` with the first step that reads the color of the frame before, which the preset's bounce light draws at its start, `'translucency'` with the first material that lets light through to its other side, `'subsurface'` with the first material with a `subsurfaceRadius` while the subsurface blur has taps, `'coat_sheen'` with the first material with a clear coat or a sheen, `'weighted'` with the first material of the `weighted` blending, and `'occlusion'` with the first opaque material while GPU occlusion culling runs on WebGPU. WebGPU morphs in the skinning pass, so there `'morph'` loads the skinning shaders, and WebGL2 has no `'occlusion'` shaders to load. Listed features download beside the engine's own shaders, so the start waits only for the largest. The shaders that two or more listed features need together, such as a skinned mesh's with the alpha hash, download with them. Loading a glTF file with skins or morph targets, or making a batch, also starts its feature's download at once, before the objects draw. Throws E1421 for a name it does not know. |
|
|
210
213
|
| `stats?: boolean \| StatsOverlayOptions` | True or options show the stats overlay over the canvas from the first frame, as `engine.stats` does with the same value. The default is false. The `?stats` or `?stats=on` switch shows it too, with these options when they are given, and `?stats=off` hides it, whatever this option says. A held engine for image tests shows no overlay. |
|
|
211
214
|
| `still?: boolean` | False draws every frame of a view that holds still. By default such a view blends its frames into a sharper picture and then stops drawing until something changes. The `?still-camera=off` switch turns it off too, and hold mode draws without it. |
|
|
212
215
|
|
|
@@ -252,6 +255,7 @@ type ErrorCode =
|
|
|
252
255
|
| 'E1304'
|
|
253
256
|
| 'E1305'
|
|
254
257
|
| 'E1306'
|
|
258
|
+
| 'E1307'
|
|
255
259
|
| 'E1401'
|
|
256
260
|
| 'E1402'
|
|
257
261
|
| 'E1403'
|
|
@@ -432,6 +436,14 @@ Options for `engine.requestPointerLock`.
|
|
|
432
436
|
| --- | --- |
|
|
433
437
|
| `unadjustedMovement?: boolean` | True asks for the mouse's raw movement, without the speed-up that the system applies. Browsers that cannot give it refuse the lock with E1425. The default is false. |
|
|
434
438
|
|
|
439
|
+
## `PresetCheckTiming`
|
|
440
|
+
|
|
441
|
+
```ts
|
|
442
|
+
type PresetCheckTiming = 'during-play' | 'before-play';
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
When the preset check measures, as `createEngine`'s `presetCheck` option and the `?preset-check=` switch name it. With `during-play`, the default, the scene plays from its first frame, and the check measures the first frames of play. With `before-play`, the check measures before the sketch's update runs, and the start waits for it.
|
|
446
|
+
|
|
435
447
|
## `readDeviceHints`
|
|
436
448
|
|
|
437
449
|
```ts
|
|
@@ -549,7 +561,7 @@ The GPU path the engine draws with: core WebGPU, WebGPU in compatibility mode on
|
|
|
549
561
|
## `VERSION`
|
|
550
562
|
|
|
551
563
|
```ts
|
|
552
|
-
const VERSION: '0.
|
|
564
|
+
const VERSION: '0.1.0'
|
|
553
565
|
```
|
|
554
566
|
|
|
555
567
|
The engine version, which the WebAssembly core and this package always share.
|