@null3d/engine 0.1.0 → 0.1.1
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/dist/wasm/single/null3d.js +10 -8
- package/dist/wasm/single/null3d_bg.wasm +0 -0
- package/dist/wasm/threaded/null3d.js +10 -8
- package/dist/wasm/threaded/null3d_bg.wasm +0 -0
- package/docs/api/animation.md +96 -24
- package/docs/api/assets.md +99 -29
- package/docs/api/cameras.md +38 -7
- package/docs/api/controls.md +47 -23
- package/docs/api/debug.md +105 -35
- package/docs/api/engine.md +108 -32
- package/docs/api/feature-draws.md +21 -15
- package/docs/api/feature-effects.md +8 -8
- package/docs/api/feature-instances.md +68 -17
- package/docs/api/features.md +68 -37
- package/docs/api/geometry.md +83 -14
- package/docs/api/grass.md +55 -13
- package/docs/api/impostors.md +92 -50
- package/docs/api/input.md +22 -9
- package/docs/api/lights.md +67 -16
- package/docs/api/lines.md +38 -13
- package/docs/api/materials.md +187 -59
- package/docs/api/math.md +6 -6
- package/docs/api/objects.md +40 -15
- package/docs/api/page.md +58 -7
- package/docs/api/particles.md +36 -11
- package/docs/api/points.md +18 -8
- package/docs/api/post.md +57 -23
- package/docs/api/quality.md +36 -16
- package/docs/api/raycast.md +57 -24
- package/docs/api/reference/animation.md +1 -2
- package/docs/api/reference/assets.md +7 -4
- package/docs/api/reference/cameras.md +3 -2
- package/docs/api/reference/controls.md +59 -2
- package/docs/api/reference/debug.md +58 -6
- package/docs/api/reference/engine.md +39 -10
- package/docs/api/reference/feature-draws.md +3 -4
- package/docs/api/reference/feature-effects.md +2 -3
- package/docs/api/reference/feature-instances.md +5 -4
- package/docs/api/reference/features.md +7 -4
- package/docs/api/reference/geometry.md +132 -21
- package/docs/api/reference/grass.md +62 -2
- package/docs/api/reference/impostors.md +120 -16
- package/docs/api/reference/input.md +1 -2
- package/docs/api/reference/lights.md +4 -3
- package/docs/api/reference/lines.md +3 -4
- package/docs/api/reference/materials.md +7 -6
- package/docs/api/reference/math.md +13 -2
- package/docs/api/reference/objects.md +2 -3
- package/docs/api/reference/particles.md +31 -6
- package/docs/api/reference/points.md +2 -3
- package/docs/api/reference/post.md +4 -3
- package/docs/api/reference/quality.md +1 -2
- package/docs/api/reference/raycast.md +1 -2
- package/docs/api/reference/render.md +4 -3
- package/docs/api/reference/scene.md +24 -5
- package/docs/api/reference/sketch.md +11 -11
- package/docs/api/reference/sound.md +33 -2
- package/docs/api/reference/splats.md +42 -3
- package/docs/api/reference/sprites.md +2 -3
- package/docs/api/reference/tasks.md +16 -3
- package/docs/api/reference/terrain.md +26 -5
- package/docs/api/reference/textures.md +1 -2
- package/docs/api/reference/three-compat.md +18 -7
- package/docs/api/reference/time.md +1 -2
- package/docs/api/reference/ui.md +10 -7
- package/docs/api/reference/vertex-draws.md +2 -3
- package/docs/api/reference/water.md +78 -5
- package/docs/api/reference/wind.md +15 -2
- package/docs/api/render.md +67 -25
- package/docs/api/scene.md +129 -36
- package/docs/api/sketch.md +45 -19
- package/docs/api/sound.md +48 -12
- package/docs/api/splats.md +42 -15
- package/docs/api/sprites.md +8 -6
- package/docs/api/tasks.md +31 -22
- package/docs/api/terrain.md +44 -12
- package/docs/api/textures.md +61 -12
- package/docs/api/three-compat.md +15 -7
- package/docs/api/time.md +3 -5
- package/docs/api/ui.md +18 -10
- package/docs/api/vertex-draws.md +13 -12
- package/docs/api/water.md +111 -67
- package/docs/api/wind.md +61 -15
- package/docs/cli/null3d.md +90 -15
- package/docs/concepts/architecture.md +69 -23
- package/docs/concepts/assets.md +57 -16
- package/docs/concepts/backends.md +65 -25
- package/docs/concepts/color-management.md +42 -13
- package/docs/concepts/culling.md +68 -47
- package/docs/concepts/handles.md +14 -5
- package/docs/concepts/instances.md +72 -23
- package/docs/concepts/large-worlds.md +17 -7
- package/docs/concepts/lighting.md +117 -44
- package/docs/concepts/lod.md +128 -33
- package/docs/concepts/materials.md +43 -12
- package/docs/concepts/particle-buffer.md +48 -35
- package/docs/concepts/post-processing.md +77 -14
- package/docs/concepts/quality-preset-tables.md +3 -2
- package/docs/concepts/quality-presets.md +122 -39
- package/docs/concepts/render-graph.md +56 -21
- package/docs/concepts/render-layers.md +9 -5
- package/docs/concepts/shadows.md +96 -25
- package/docs/concepts/static-dynamic.md +22 -7
- package/docs/cookbook/index.md +163 -119
- package/docs/data/threejs-mapping.json +301 -340
- package/docs/errors/E1101.md +23 -5
- package/docs/errors/E1102.md +11 -3
- package/docs/errors/E1103.md +11 -3
- package/docs/errors/E1104.md +11 -3
- package/docs/errors/E1105.md +13 -5
- package/docs/errors/E1106.md +11 -3
- package/docs/errors/E1107.md +15 -5
- package/docs/errors/E1108.md +11 -3
- package/docs/errors/E1109.md +32 -6
- package/docs/errors/E1110.md +23 -5
- package/docs/errors/E1111.md +11 -3
- package/docs/errors/E1112.md +11 -3
- package/docs/errors/E1203.md +12 -4
- package/docs/errors/E1204.md +11 -3
- package/docs/errors/E1205.md +11 -3
- package/docs/errors/E1206.md +28 -6
- package/docs/errors/E1207.md +11 -3
- package/docs/errors/E1208.md +12 -3
- package/docs/errors/E1209.md +11 -3
- package/docs/errors/E1213.md +27 -5
- package/docs/errors/E1214.md +11 -3
- package/docs/errors/E1215.md +31 -6
- package/docs/errors/E1216.md +31 -6
- package/docs/errors/E1217.md +29 -6
- package/docs/errors/E1218.md +22 -6
- package/docs/errors/E1219.md +11 -3
- package/docs/errors/E1220.md +24 -5
- package/docs/errors/E1221.md +24 -5
- package/docs/errors/E1222.md +11 -3
- package/docs/errors/E1223.md +39 -6
- package/docs/errors/E1224.md +11 -3
- package/docs/errors/E1225.md +11 -3
- package/docs/errors/E1301.md +11 -3
- package/docs/errors/E1302.md +11 -3
- package/docs/errors/E1303.md +11 -3
- package/docs/errors/E1304.md +11 -3
- package/docs/errors/E1305.md +13 -3
- package/docs/errors/E1306.md +11 -3
- package/docs/errors/E1307.md +23 -6
- package/docs/errors/E1401.md +11 -3
- package/docs/errors/E1402.md +13 -5
- package/docs/errors/E1403.md +11 -3
- package/docs/errors/E1404.md +13 -3
- package/docs/errors/E1405.md +15 -4
- package/docs/errors/E1406.md +31 -5
- package/docs/errors/E1407.md +11 -3
- package/docs/errors/E1408.md +11 -3
- package/docs/errors/E1409.md +11 -3
- package/docs/errors/E1410.md +13 -5
- package/docs/errors/E1411.md +11 -3
- package/docs/errors/E1412.md +29 -6
- package/docs/errors/E1413.md +11 -3
- package/docs/errors/E1414.md +11 -3
- package/docs/errors/E1415.md +11 -3
- package/docs/errors/E1416.md +27 -6
- package/docs/errors/E1417.md +11 -3
- package/docs/errors/E1418.md +12 -3
- package/docs/errors/E1419.md +13 -5
- package/docs/errors/E1420.md +11 -3
- package/docs/errors/E1421.md +11 -3
- package/docs/errors/E1422.md +12 -3
- package/docs/errors/E1423.md +12 -3
- package/docs/errors/E1424.md +24 -5
- package/docs/errors/E1425.md +11 -3
- package/docs/errors/E1426.md +11 -3
- package/docs/errors/E1430.md +11 -3
- package/docs/errors/E1431.md +11 -3
- package/docs/errors/E1432.md +11 -3
- package/docs/errors/E1433.md +11 -3
- package/docs/errors/E1434.md +15 -6
- package/docs/errors/E1435.md +11 -3
- package/docs/errors/E1436.md +11 -3
- package/docs/errors/E1437.md +14 -6
- package/docs/errors/E1501.md +41 -6
- package/docs/errors/E1502.md +13 -3
- package/docs/errors/E1503.md +11 -3
- package/docs/errors/E1504.md +11 -3
- package/docs/errors/E1505.md +23 -5
- package/docs/errors/E1506.md +11 -3
- package/docs/errors/index.md +52 -29
- package/docs/getting-started/cdn.md +15 -9
- package/docs/getting-started/first-scene.md +20 -12
- package/docs/getting-started/hosting.md +111 -63
- package/docs/getting-started/install.md +39 -24
- package/docs/getting-started/network-use.md +31 -21
- package/docs/getting-started/project-structure.md +20 -8
- package/docs/getting-started/third-party-notices.md +6 -10
- package/docs/guides/accessibility.md +4 -4
- package/docs/guides/add-ons.md +83 -13
- package/docs/guides/agents.md +2 -6
- package/docs/guides/assets-pipeline.md +248 -72
- package/docs/guides/audio.md +17 -15
- package/docs/guides/baked-light-data.md +44 -23
- package/docs/guides/car-paint.md +37 -31
- package/docs/guides/content-pages.md +53 -29
- package/docs/guides/custom-passes.md +59 -17
- package/docs/guides/custom-shaders.md +54 -37
- package/docs/guides/debugging.md +31 -41
- package/docs/guides/deploying.md +6 -27
- package/docs/guides/deterministic-simulation.md +23 -16
- package/docs/guides/first-use-shaders.md +83 -45
- package/docs/guides/lens-kit.md +29 -26
- package/docs/guides/loading-screens.md +70 -30
- package/docs/guides/multiple-views.md +22 -11
- package/docs/guides/performance.md +188 -37
- package/docs/guides/phones.md +71 -19
- package/docs/guides/physics.md +6 -10
- package/docs/guides/screens.md +41 -29
- package/docs/guides/start-time.md +120 -85
- package/docs/guides/testing.md +137 -98
- package/docs/guides/ui-overlays.md +17 -12
- package/docs/guides/video-textures.md +14 -13
- package/docs/images/api/animation/character.webp +0 -0
- package/docs/images/api/animation/look-at-ring.webp +0 -0
- package/docs/images/api/animation/morph-tulips.webp +0 -0
- package/docs/images/api/animation/skeleton-lines.webp +0 -0
- package/docs/images/api/controls/gizmo-handles.webp +0 -0
- package/docs/images/api/controls/walk-and-fly.webp +0 -0
- package/docs/images/api/debug/debug-shapes.webp +0 -0
- package/docs/images/api/debug/levels-view.webp +0 -0
- package/docs/images/api/engine/transparent-canvas.webp +0 -0
- package/docs/images/api/feature-draws/feature-draw-clouds.webp +0 -0
- package/docs/images/api/feature-instances/compute-instances.webp +0 -0
- package/docs/images/api/feature-instances/instances-shadow.webp +0 -0
- package/docs/images/api/geometry/extra-shapes.webp +0 -0
- package/docs/images/api/geometry/generators.webp +0 -0
- package/docs/images/api/geometry/mesh-arrays.webp +0 -0
- package/docs/images/api/geometry/vertex-updates.webp +0 -0
- package/docs/images/api/grass/grass-grove.webp +0 -0
- package/docs/images/api/grass/grass-presets.webp +0 -0
- package/docs/images/api/grass/grass-shadow.webp +0 -0
- package/docs/images/api/impostors/impostor-handover.webp +0 -0
- package/docs/images/api/impostors/impostor-shadow.webp +0 -0
- package/docs/images/api/impostors/impostors-forest.webp +0 -0
- package/docs/images/api/lights/spot-cookies.webp +0 -0
- package/docs/images/api/lines/lines-lit.webp +0 -0
- package/docs/images/api/lines/lines-widths.webp +0 -0
- package/docs/images/api/materials/coat-and-sheen.webp +0 -0
- package/docs/images/api/materials/decals.webp +0 -0
- package/docs/images/api/materials/iridescence-and-anisotropy.webp +0 -0
- package/docs/images/api/materials/relief.webp +0 -0
- package/docs/images/api/materials/shader-inputs.webp +0 -0
- package/docs/images/api/materials/standard-grid.webp +0 -0
- package/docs/images/api/materials/subsurface.webp +0 -0
- package/docs/images/api/materials/translucency.webp +0 -0
- package/docs/images/api/objects/objects-turntable.webp +0 -0
- package/docs/images/api/particles/campfire.webp +0 -0
- package/docs/images/api/points/galaxy.webp +0 -0
- package/docs/images/api/reference/textures/texture-wrap.webp +0 -0
- package/docs/images/api/render/fullscreen-glow.webp +0 -0
- package/docs/images/api/render/reflection-mirror.webp +0 -0
- package/docs/images/api/render/security-camera.webp +0 -0
- package/docs/images/api/scene/aurora-sky-layer.webp +0 -0
- package/docs/images/api/sound/sound-demo.webp +0 -0
- package/docs/images/api/splats/splats-demo.webp +0 -0
- package/docs/images/api/sprites/sprites-lines.webp +0 -0
- package/docs/images/api/terrain/terrain-demo.webp +0 -0
- package/docs/images/api/textures/canvas-screen.webp +0 -0
- package/docs/images/api/textures/mipmaps.webp +0 -0
- package/docs/images/api/vertex-draws/rain.webp +0 -0
- package/docs/images/api/water/ocean.webp +0 -0
- package/docs/images/api/water/water-demo.webp +0 -0
- package/docs/images/api/water/water-rain.webp +0 -0
- package/docs/images/api/water/waterfall.webp +0 -0
- package/docs/images/concepts/assets/gltf-model.webp +0 -0
- package/docs/images/concepts/color-management/tone-mapped.webp +0 -0
- package/docs/images/concepts/culling/far-from-origin.webp +0 -0
- package/docs/images/concepts/instances/instances.webp +0 -0
- package/docs/images/concepts/instances/per-row-colors.webp +0 -0
- package/docs/images/concepts/large-worlds/large-world.webp +0 -0
- package/docs/images/concepts/lighting/area-lights.webp +0 -0
- package/docs/images/concepts/lighting/atmosphere.webp +0 -0
- package/docs/images/concepts/lighting/environment.webp +0 -0
- package/docs/images/concepts/lighting/light-shafts.webp +0 -0
- package/docs/images/concepts/lighting/reflection-probes.webp +0 -0
- package/docs/images/concepts/lod/forest.webp +0 -0
- package/docs/images/concepts/materials/weighted-transparency.webp +0 -0
- package/docs/images/concepts/post-processing/auto-exposure.webp +0 -0
- package/docs/images/concepts/post-processing/bounce-light.webp +0 -0
- package/docs/images/concepts/post-processing/depth-of-field.webp +0 -0
- package/docs/images/concepts/post-processing/post-effects-alley.webp +0 -0
- package/docs/images/concepts/post-processing/sharpen.webp +0 -0
- package/docs/images/concepts/post-processing/ssr-wet-street.webp +0 -0
- package/docs/images/concepts/render-layers/layers-cottages.webp +0 -0
- package/docs/images/concepts/shadows/hero-shadow.webp +0 -0
- package/docs/images/cookbook/index/picking.webp +0 -0
- package/docs/images/cookbook/index/time-of-day.webp +0 -0
- package/docs/images/errors/E1431/area-lights-no-tables.webp +0 -0
- package/docs/images/guides/custom-passes/reflection-water.webp +0 -0
- package/docs/images/guides/deterministic-simulation/replay-demo.webp +0 -0
- package/docs/images/guides/multiple-views/split-screen.webp +0 -0
- package/docs/images/guides/performance/overdraw-view.webp +0 -0
- package/docs/images/guides/testing/hold-mode-frame.webp +0 -0
- package/docs/images/index/showcase-island.webp +0 -0
- package/docs/images/porting/threejs-shaders/dissolve.webp +0 -0
- package/docs/images/shaders/builtins/builtins.webp +0 -0
- package/docs/images/shaders/surface-functions/custom-surface.webp +0 -0
- package/docs/images/shaders/surface-functions/vertex-offset.webp +0 -0
- package/docs/images/shots.json +2231 -0
- package/docs/index.md +14 -23
- package/docs/moves.json +1 -0
- package/docs/nav.json +300 -0
- package/docs/pages.md +230 -212
- package/docs/porting/react-three-fiber.md +2 -6
- package/docs/porting/threejs-loop-and-threads.md +1 -5
- package/docs/porting/threejs-mapping.md +1248 -234
- package/docs/porting/threejs-materials.md +10 -5
- package/docs/porting/threejs-overview.md +26 -6
- package/docs/porting/threejs-postprocessing.md +2 -6
- package/docs/porting/threejs-shaders.md +16 -14
- package/docs/porting/threejs-unsupported.md +6 -6
- package/docs/porting/verification.md +0 -4
- package/docs/shaders/builtins.md +15 -4
- package/docs/shaders/library.md +9 -6
- package/docs/shaders/surface-functions.md +51 -16
- package/docs/shaders/wgsl-rules.md +12 -5
- package/lib/debug/debug.d.ts +2 -2
- package/lib/debug/draw.d.ts +2 -2
- package/lib/debug/draw.js +8 -4
- package/lib/debug/overlay-look.d.ts +6 -0
- package/lib/debug/overlay-look.js +29 -7
- package/lib/debug/overlay.js +15 -11
- package/lib/debug/stats-options.d.ts +13 -0
- package/lib/debug/stats-panel.d.ts +21 -6
- package/lib/debug/stats-panel.js +80 -13
- package/lib/errors/codes.d.ts +17 -3
- package/lib/errors/codes.js +111 -105
- package/lib/errors/fixes.js +18 -18
- package/lib/gpu/variants.d.ts +8 -2
- package/lib/gpu/variants.js +39 -7
- package/lib/gpu/webgl2/programs.js +1 -1
- package/lib/gpu/webgpu/pipelines.js +13 -13
- package/lib/index.d.ts +1 -1
- package/lib/page/capabilities.d.ts +1 -1
- package/lib/page/engine.d.ts +14 -5
- package/lib/page/engine.js +18 -2
- package/lib/page/label-loop.js +9 -4
- package/lib/page/stats-switch.js +2 -0
- package/lib/page/switches.d.ts +6 -4
- package/lib/page/switches.js +20 -4
- package/lib/scene/baked-light.d.ts +2 -2
- package/lib/scene/fake-call-values.js +2 -2
- package/lib/scene/frame-cameras.d.ts +16 -4
- package/lib/scene/frame-cameras.js +28 -10
- package/lib/scene/gltf.d.ts +1 -1
- package/lib/scene/level-rule.d.ts +6 -5
- package/lib/scene/level-rule.js +2 -2
- package/lib/scene/particles.d.ts +7 -3
- package/lib/scene/particles.js +3 -1
- package/lib/scene/post.d.ts +3 -2
- package/lib/scene/resources.d.ts +15 -9
- package/lib/scene/scene.d.ts +18 -2
- package/lib/scene/scene.js +47 -5
- package/lib/scene/time-of-day.d.ts +10 -5
- package/lib/scene/time-of-day.js +11 -7
- package/lib/shader-artifact.json +1 -1
- package/lib/shared/labels.d.ts +5 -2
- package/lib/shared/labels.js +5 -2
- package/lib/shared/permutation-words.d.ts +2 -0
- package/lib/shared/permutation-words.js +8 -0
- package/lib/shared/recording.d.ts +13 -5
- package/lib/shared/recording.js +31 -10
- package/lib/shared/sketch-data.d.ts +9 -0
- package/lib/shared/sketch-data.js +57 -0
- package/lib/shared/version.d.ts +1 -1
- package/lib/shared/version.js +1 -1
- package/lib/sketch/define-sketch.d.ts +16 -7
- package/lib/sketch/define-sketch.js +2 -1
- package/lib/sketch/runner.d.ts +4 -0
- package/lib/sketch/runner.js +5 -0
- package/lib/sketch/ui.js +4 -2
- package/lib/stats.d.ts +1 -0
- package/lib/workers/protocol.d.ts +10 -0
- package/lib/workers/render-worker.js +4 -1
- package/lib/workers/sketch-worker.js +4 -1
- package/package.json +1 -1
package/docs/guides/physics.md
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: guides/physics
|
|
3
3
|
title: Using a physics library
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.1"
|
|
6
4
|
summary: "Running Rapier or cannon-es in the sketch worker; copying transforms."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Using a physics library
|
|
10
8
|
|
|
11
|
-
> Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
|
|
12
|
-
|
|
13
9
|
```mermaid
|
|
14
10
|
flowchart LR
|
|
15
11
|
fixed["onFixedUpdate(step)<br/>0 or more times"] --> step["The physics world<br/>takes one step"]
|
|
@@ -26,10 +22,10 @@ Physics in the sketch only moves what the player sees. A game whose server repla
|
|
|
26
22
|
|
|
27
23
|
Two libraries work well in a sketch:
|
|
28
24
|
|
|
29
|
-
| Library | Package | What it is |
|
|
30
|
-
| --- | --- | --- |
|
|
31
|
-
| Rapier | `@dimforge/rapier3d-compat` | A Rust engine compiled to WebAssembly. It is fast with many bodies. |
|
|
32
|
-
| cannon-es | `cannon-es` | A JavaScript engine. It is small and simple to use. |
|
|
25
|
+
| Library | Package | What it is | Download size |
|
|
26
|
+
| --- | --- | --- | --- |
|
|
27
|
+
| Rapier | `@dimforge/rapier3d-compat` | A Rust engine compiled to WebAssembly. It is fast with many bodies. | About 1.2 MB after Brotli compression |
|
|
28
|
+
| cannon-es | `cannon-es` | A JavaScript engine. It is small and simple to use. | About 20 KB for the example on this page |
|
|
33
29
|
|
|
34
30
|
Install one with Bun, as any other package:
|
|
35
31
|
|
|
@@ -37,6 +33,8 @@ Install one with Bun, as any other package:
|
|
|
37
33
|
bun add @dimforge/rapier3d-compat@^0.20.0
|
|
38
34
|
```
|
|
39
35
|
|
|
36
|
+
The `-compat` package holds Rapier's WebAssembly inside its JavaScript, so it needs no extra Vite setup. That is why it is large.
|
|
37
|
+
|
|
40
38
|
## Example: crates that fall on a floor
|
|
41
39
|
|
|
42
40
|
This sketch drops 300 crates onto a floor with Rapier. Each crate is a Rapier body and a row of one instance batch.
|
|
@@ -112,8 +110,6 @@ export default defineSketch(async ({ scene, geometry, materials }) => {
|
|
|
112
110
|
- The rows are views of engine memory, so the copy costs no call to the engine per crate. A dynamic batch recomputes and uploads every row in each frame. [Instances and batching](../concepts/instances.md) explains the rows.
|
|
113
111
|
- The floor never moves, so its mesh is static. A static mesh costs nothing in a frame where it does not change.
|
|
114
112
|
|
|
115
|
-
The `-compat` package holds Rapier's WebAssembly inside its JavaScript, so it needs no extra Vite setup. That makes it large: it adds about 1.2 MB after Brotli compression to the sketch's download. With cannon-es, the example on this page adds about 20 KB.
|
|
116
|
-
|
|
117
113
|
## Step the world at a fixed rate
|
|
118
114
|
|
|
119
115
|
A physics world stays stable when every step has the same length. A frame's step changes with the screen and with slow frames, so the examples step the world in `onFixedUpdate`. The engine calls it 60 times per second of sketch time, before `onUpdate`. The examples copy the transforms in `onUpdate`, once per frame, after the frame's steps.
|
package/docs/guides/screens.md
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: guides/screens
|
|
3
3
|
title: In-world screens
|
|
4
|
-
|
|
5
|
-
since: "0.3"
|
|
6
|
-
summary: "Displays painted on an OffscreenCanvas in the sketch, with a refresh rate for each screen, uploads of only the changed rectangles, an LCD look that changes with distance, a boot glitch, and clicks mapped back to the canvas's coordinates."
|
|
4
|
+
summary: "An example add-on you copy: displays painted on an OffscreenCanvas in the sketch, with a refresh rate for each screen, uploads of only the changed rectangles, an LCD look that changes with distance, a boot glitch, and clicks mapped back to the canvas's coordinates."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# In-world screens
|
|
10
8
|
|
|
11
|
-
> Roadmap step 0.3, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
|
|
12
|
-
|
|
13
9
|
A screen is a plane in the world whose material samples an `OffscreenCanvas`. The sketch draws on
|
|
14
10
|
the canvas with the 2D context, and the engine uploads only the rectangles that changed. Each screen
|
|
15
11
|
keeps its own refresh rate, so a slow readout costs less than a fast one.
|
|
@@ -24,48 +20,64 @@ flowchart LR
|
|
|
24
20
|
```
|
|
25
21
|
|
|
26
22
|
The screens add-on in the repository, in the `examples/addons/screens` folder, holds the pattern.
|
|
27
|
-
It is not an npm package. Copy the folder into your project and import its entry point.
|
|
23
|
+
It is not an npm package. Copy the folder into your project and import its entry point. The [screens painted on an OffscreenCanvas](https://github.com/null3d-engine/null3d/tree/main/examples/canvas-screen) demo shows wall panels and a console, each at its own refresh rate.
|
|
28
24
|
|
|
29
25
|
## Make a screen
|
|
30
26
|
|
|
31
27
|
```ts
|
|
28
|
+
import { defineSketch } from '@null3d/engine';
|
|
32
29
|
import { createScreen } from './addons/screens';
|
|
33
30
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
context
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
export default defineSketch((ctx) => {
|
|
32
|
+
const screen = createScreen(ctx, {
|
|
33
|
+
width: 512,
|
|
34
|
+
height: 256,
|
|
35
|
+
refreshHz: 12,
|
|
36
|
+
size: [2.4, 1.2],
|
|
37
|
+
draw: (context) => {
|
|
38
|
+
context.fillStyle = '#061019';
|
|
39
|
+
context.fillRect(0, 0, 512, 256);
|
|
40
|
+
context.fillStyle = '#9fe8ff';
|
|
41
|
+
context.font = 'bold 48px sans-serif';
|
|
42
|
+
context.fillText('REACTOR 62.0', 24, 90);
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
screen.mesh.setPosition(0, 1.4, -3);
|
|
46
|
+
|
|
47
|
+
return { onUpdate() { /* below */ } };
|
|
46
48
|
});
|
|
47
|
-
screen.mesh.setPosition(0, 1.4, -3);
|
|
48
49
|
```
|
|
49
50
|
|
|
50
|
-
`draw` runs in the setup, before the first upload, so a held frame
|
|
51
|
-
|
|
51
|
+
`draw` runs in the setup, before the first upload, so every frame shows the picture, a held frame too. `screen.paint(draw, changed)` draws and uploads the rectangle that changed. Without a rectangle it uploads the whole canvas.
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
screen.paint((context) => {
|
|
55
|
+
context.fillStyle = '#061019';
|
|
56
|
+
context.fillRect(24, 150, 464, 90);
|
|
57
|
+
context.fillStyle = '#9fe8ff';
|
|
58
|
+
context.fillText(`REACTOR ${reading.toFixed(1)}`, 24, 200);
|
|
59
|
+
}, { x: 24, y: 150, width: 464, height: 90 });
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
A program that changes its reading each frame can draw straight on `screen.context`:
|
|
52
63
|
|
|
53
64
|
```ts
|
|
54
65
|
return {
|
|
55
66
|
onUpdate() {
|
|
56
|
-
|
|
67
|
+
const context = screen.context;
|
|
68
|
+
context.fillStyle = '#061019';
|
|
69
|
+
context.fillRect(24, 150, 464, 90);
|
|
70
|
+
context.fillStyle = '#9fe8ff';
|
|
71
|
+
context.fillText(`REACTOR ${reading.toFixed(1)}`, 24, 200);
|
|
57
72
|
screen.mark({ x: 24, y: 150, width: 464, height: 90 });
|
|
58
73
|
screen.flush(); // sends a change that the rate held back
|
|
59
74
|
},
|
|
60
75
|
};
|
|
61
76
|
```
|
|
62
77
|
|
|
63
|
-
`screen.
|
|
64
|
-
uploads the whole canvas. `screen.mark(rect)` adds a rectangle without drawing, and `screen.flush()`
|
|
65
|
-
uploads the marked rectangles as one change.
|
|
78
|
+
`screen.mark(rect)` adds a rectangle without drawing, and `screen.flush()` uploads the marked rectangles as one change.
|
|
66
79
|
|
|
67
|
-
A refresh that the rate or an upload in flight holds back returns false, and the change waits for
|
|
68
|
-
the next call. Call `flush` from the frame's update so it goes out.
|
|
80
|
+
A refresh that the rate or an upload in flight holds back returns false, and the change waits for the next call. Call `flush` from the frame's update so it goes out.
|
|
69
81
|
|
|
70
82
|
## The LCD look
|
|
71
83
|
|
|
@@ -93,7 +105,7 @@ takes no values.
|
|
|
93
105
|
## Clicks on a screen
|
|
94
106
|
|
|
95
107
|
A pointer hit on a mesh carries its texture coordinates. `screen.pointOf(event)` turns them into a
|
|
96
|
-
canvas point. `screen.texelOf(event)` gives the whole texel under the point.
|
|
108
|
+
canvas point. `screen.texelOf(event)` gives the whole texel under the point. The [picking demo](https://github.com/null3d-engine/null3d/tree/main/examples/picking) shows an object's click handler and the point that the ray hit.
|
|
97
109
|
|
|
98
110
|
```ts
|
|
99
111
|
screen.onClick((point) => {
|
|
@@ -116,7 +128,7 @@ that path's figures and its upload budget.
|
|
|
116
128
|
|
|
117
129
|
- The shader draws on both GPU paths. It uses `fwidth`, which both paths have.
|
|
118
130
|
- A screen's mesh needs texture coordinates, as `geometry.plane` gives.
|
|
119
|
-
-
|
|
131
|
+
- In hold mode, the held frame shows the canvas as of its last read. A change that the refresh rate held back in the last updates does not show. Paint the picture that a test checks through `draw` or in the setup.
|
|
120
132
|
- A large canvas at a high refresh rate costs its rectangle's bytes each read. Give a screen only
|
|
121
133
|
the rate that its content needs.
|
|
122
134
|
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: guides/start-time
|
|
3
3
|
title: A fast start
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.1"
|
|
6
4
|
summary: "Where a page's start goes, on a simulated phone link and on real phones; compression, cache headers, the compiled core and HTTP/2 on the host; the early core script; what the engine does while the core downloads; downloads of the first view and of the rest; the preset check; pipelines on phones; testing and measuring a start."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# A fast start
|
|
10
8
|
|
|
11
|
-
> Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
|
|
12
|
-
|
|
13
9
|
```mermaid
|
|
14
10
|
flowchart LR
|
|
15
11
|
html["The HTML page"] --> early["The early script<br/>starts the core's download"]
|
|
@@ -24,77 +20,61 @@ flowchart LR
|
|
|
24
20
|
|
|
25
21
|
A visitor waits from the moment the page's address loads until the first frame shows. Most of that wait is downloads, the round trips between them, and on a phone the GPU's pipeline builds. A round trip takes 150 to 560 ms on a phone's network, so each download that waits for another one adds that much. The host, the page and the sketch each decide part of the start. This guide gives the steps that shorten it, in the order of the start.
|
|
26
22
|
|
|
23
|
+
The steps that shorten a start, in the order of the start:
|
|
24
|
+
|
|
25
|
+
1. [Compress every file](#compress-every-file), `.wasm` included.
|
|
26
|
+
2. [Let the browser keep the files](#let-the-browser-keep-the-files).
|
|
27
|
+
3. [Serve over HTTP/2](#serve-over-http2).
|
|
28
|
+
4. [Keep the early core script](#keep-the-early-core-script), and create the engine as soon as the page can.
|
|
29
|
+
5. [Start the first view's downloads at the top of the setup](#start-the-first-views-downloads-at-the-top-of-the-setup).
|
|
30
|
+
6. [Draw the first frame before the large models](#draw-the-first-frame-before-the-large-models).
|
|
31
|
+
7. [Keep the first view's pipelines few](#pipelines-on-phones).
|
|
32
|
+
8. [Start an offline cache only after the first frame](#cache-for-offline-play-after-the-first-frame).
|
|
33
|
+
9. [Test a production build](#test-a-production-build), and [measure the start](#measure-a-start).
|
|
34
|
+
|
|
27
35
|
## Where the time goes
|
|
28
36
|
|
|
29
|
-
The engine's demos were timed as a production build over a simulated phone connection. It had 150 ms for each round trip and 10 Mbit/s, and the browser's cache was empty.
|
|
37
|
+
The engine's demos were timed as a production build over a simulated phone connection. It had 150 ms for each round trip and 10 Mbit/s, and the browser's cache was empty. These are the steps of a first visit today, with what each costs when it is skipped:
|
|
30
38
|
|
|
31
|
-
| Step |
|
|
39
|
+
| Step | Cost when skipped | What shortens it |
|
|
32
40
|
| --- | --- | --- |
|
|
33
|
-
| The HTML page | 0.5 s | Three round trips on a new connection: TCP, TLS and the request |
|
|
34
|
-
| The engine core | 2.3 s |
|
|
35
|
-
| The sketch module's imports | 0.6 to 1.0 s | Three or four rounds of imports, one after another,
|
|
36
|
-
| The sketch module's top-level code | 1.2 s in one scene | Terrain
|
|
37
|
-
| The scene's own files | 22 s in one scene | 18 MB of models in two batches.
|
|
38
|
-
| The first frame's pipelines | 0.7 to 1.3 s |
|
|
41
|
+
| The HTML page | 0.5 s | Three round trips on a new connection: TCP, TLS and the request. [Serve over HTTP/2](#serve-over-http2) |
|
|
42
|
+
| The engine core | 2.3 s | 2.0 MB of WebAssembly with no compression. [Compress every file](#compress-every-file) makes it about 0.6 MB |
|
|
43
|
+
| The sketch module's imports | 0.6 to 1.0 s | Three or four rounds of imports, one after another. [The import chain, asked for at once](#what-the-engine-does-while-the-core-downloads) |
|
|
44
|
+
| The sketch module's top-level code | 1.2 s in one scene | Terrain built as the module loaded. [Start the first view's downloads early](#start-the-first-views-downloads-at-the-top-of-the-setup) |
|
|
45
|
+
| The scene's own files | 22 s in one scene | 18 MB of models in two batches. [Draw the first frame before the large models](#draw-the-first-frame-before-the-large-models) |
|
|
46
|
+
| The first frame's pipelines | 0.7 to 1.3 s | Shaders compiled while the last files downloaded. [Keep the first view's pipelines few](#pipelines-on-phones) |
|
|
39
47
|
|
|
40
|
-
|
|
48
|
+
With these steps applied, the engine's demos draw the first frame in 2.7 to 7.6 seconds over that link. On real phones, they draw it in 3.5 to 39 seconds. The block below gives each demo's figure.
|
|
41
49
|
|
|
42
|
-
|
|
50
|
+
<details>
|
|
51
|
+
<summary>Technical details: measured starts on a simulated phone link and on real phones</summary>
|
|
43
52
|
|
|
44
|
-
|
|
45
|
-
| --- | --- | --- | --- |
|
|
46
|
-
| [Compress every file](#compress-every-file), `.wasm` included, with a smaller page script and no offline cache | A small demo's first frame | 4.6 s | 3.0 s |
|
|
47
|
-
| The same | The creek demo's repeat visit | 3.0 s, or 5.6 s with its offline cache | 1.7 s |
|
|
48
|
-
| [The sketch module loads while the core downloads](#what-the-engine-does-while-the-core-downloads) | From the core's arrival to the setup's start | 0.64 to 0.96 s | 0.15 to 0.51 s |
|
|
49
|
-
| [The sketch's whole import chain is asked for at once](#what-the-engine-does-while-the-core-downloads), over HTTP/2 with Brotli | A small demo's first frame, and the skyway demo's | 3.24 s and 3.52 s | 2.90 s and 3.23 s |
|
|
50
|
-
| [The stored list of the first frame's pipelines](#pipelines-on-phones) | The island's repeat visit on a Galaxy S25, from the setup's end to the first frame | 3.81 s | 1.56 s |
|
|
51
|
-
| [The first frame before the large models](#draw-the-first-frame-before-the-large-models) | The creek demo's first frame | 25.7 s | 5.7 s, with every model in at 25.0 s |
|
|
52
|
-
| The same for the island's trees, town and people, with its heavy work moved to first use | The island demo's first frame on WebGPU, and on WebGL2 | 9.37 s and 23.56 s | 6.84 s and 7.97 s |
|
|
53
|
-
| The splat scan draws once the nearest parts are in | The splat demo's first frame | 29.1 s | 8.8 s, with every part in at 28.2 s |
|
|
54
|
-
| The splats add-on starts its decoder and its selection beside its first download | The splat demo's first parts on screen | 8.3 s | 7.0 s |
|
|
55
|
-
| [The download list](#start-the-first-views-downloads-at-the-top-of-the-setup) names the creek demo's eleven models, with every model drawn before the first frame | The creek demo's first frame, and the time with nothing downloading before it | 25.9 s and 3.3 s | 21.3 s and 0.2 s |
|
|
56
|
-
| [The first view's downloads start together](#start-the-first-views-downloads-at-the-top-of-the-setup): a light map and a model | The character demo's first frame | 8.55 s | 8.2 s |
|
|
57
|
-
| [The preset check during play](#the-preset-check) | A small demo's loading screen on a first visit, at full speed on a MacBook Pro | 1.18 s | 0.49 s |
|
|
58
|
-
| [Chrome keeps the compiled core](#let-the-browser-keep-the-files) | A repeat visit's first frame on the engine's test page, at full speed, and the core's functions that it compiled again | 176 to 180 ms, 273 functions | 160 ms, 3 functions |
|
|
59
|
-
|
|
60
|
-
With every change together, the same Mac timed the engine before and after the changes in turns, over the same simulated phone connection. Each figure is the median of three loads, in seconds to the first finished frame. A cold load starts with an empty cache. A reload comes after a first visit that ran for 30 seconds. The load average is the Mac's during each pair of loads, before and after.
|
|
53
|
+
Each figure is the median of three loads, in seconds to the first finished frame. A cold load starts with an empty cache, and a reload comes after a first visit of 30 seconds.
|
|
61
54
|
|
|
62
55
|
Over HTTP/1.1:
|
|
63
56
|
|
|
64
|
-
| Demo and load |
|
|
65
|
-
| --- | --- |
|
|
66
|
-
| Small demo, cold |
|
|
67
|
-
| Skyway, cold |
|
|
68
|
-
| Island, cold |
|
|
69
|
-
| Creek, cold |
|
|
70
|
-
| Island, reload |
|
|
71
|
-
| Creek, reload |
|
|
57
|
+
| Demo and load | Time |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| Small demo, cold | 2.9 s |
|
|
60
|
+
| Skyway, cold | 3.5 s |
|
|
61
|
+
| Island, cold | 7.6 s |
|
|
62
|
+
| Creek, cold | 4.3 s |
|
|
63
|
+
| Island, reload | 2.2 s |
|
|
64
|
+
| Creek, reload | 1.3 s |
|
|
72
65
|
|
|
73
66
|
Over HTTP/2:
|
|
74
67
|
|
|
75
|
-
| Demo and load |
|
|
76
|
-
| --- | --- |
|
|
77
|
-
| Small demo, cold |
|
|
78
|
-
| Skyway, cold |
|
|
79
|
-
| Island, cold |
|
|
80
|
-
| Creek, cold |
|
|
81
|
-
| Island, reload |
|
|
82
|
-
| Creek, reload |
|
|
83
|
-
|
|
84
|
-
### On real phones
|
|
85
|
-
|
|
86
|
-
The same demos also ran on real phones, over a tunnel of about 105 ms for each round trip and 1 to 60 Mbit/s. Before the changes, a first visit drew its first frame in these times:
|
|
87
|
-
|
|
88
|
-
| Device | Small demo | Skyway | Island | Creek |
|
|
89
|
-
| --- | --- | --- | --- | --- |
|
|
90
|
-
| Galaxy S25, Chrome | 4.7 s | 7.8 s | 13.4 s | 25.1 s |
|
|
91
|
-
| Pixel 9, Chrome | 6.5 s | 10.3 s | 18.8 s | 38.8 s |
|
|
92
|
-
| Galaxy Tab A9 Plus, Chrome | 9.1 s | 20.2 s | 46.7 s | failed |
|
|
93
|
-
| iPhone 17, Safari | 11.6 s | 19.0 s | 24.4 s | 34.5 s |
|
|
94
|
-
|
|
95
|
-
Safari on the iPhone 17 kept the files and its compiled shaders between visits. Its repeat visits drew their first frame in 0.9 to 5.5 seconds. Chrome on the Android devices kept no file between visits, because they had accepted the test server's certificate after a warning ([Test a production build](#test-a-production-build)).
|
|
68
|
+
| Demo and load | Time |
|
|
69
|
+
| --- | --- |
|
|
70
|
+
| Small demo, cold | 2.7 s |
|
|
71
|
+
| Skyway, cold | 2.8 s |
|
|
72
|
+
| Island, cold | 7.0 s |
|
|
73
|
+
| Creek, cold | 3.3 s |
|
|
74
|
+
| Island, reload | 2.4 s |
|
|
75
|
+
| Creek, reload | 0.9 s |
|
|
96
76
|
|
|
97
|
-
|
|
77
|
+
The same demos ran on real phones, over a tunnel of about 100 ms for each round trip and 4 to 9 Mbit/s. A first visit in a fresh session drew its first frame in these times:
|
|
98
78
|
|
|
99
79
|
| Device | Small demo | Skyway | Island | Creek |
|
|
100
80
|
| --- | --- | --- | --- | --- |
|
|
@@ -105,21 +85,22 @@ With the changes, on the same devices, a first visit in a fresh session drew its
|
|
|
105
85
|
|
|
106
86
|
The phones start at Low and run no preset check. On the Galaxy Tab A9 Plus, the check runs during play for 12 to 38 seconds after the first frame, and settles on Low. There the creek demo lost its GPU in 2 of 6 loads. The iPhone 17's repeat visits drew their first frame in 0.4 to 3.1 seconds. The small demo's times follow the tunnel's speed, which differed between the two runs.
|
|
107
87
|
|
|
88
|
+
</details>
|
|
89
|
+
|
|
108
90
|
A phone's processor makes the largest difference from a computer. The first frame's pipeline builds take seconds there, as [Pipelines on phones](#pipelines-on-phones) shows. The Galaxy Tab A9 Plus failed to build one custom material's pipeline in the creek demo, and on repeat visits of the island.
|
|
109
91
|
|
|
110
92
|
The engine builds a pipeline that the driver refuses once more, alone. When the driver refuses it again, the engine leaves that pipeline's objects out and draws on, with [E1307](../errors/E1307.md), which does not stop it. So the island draws on that tablet without its far tree cards, at 1.1 frames a second at Low. The creek demo reaches its first frame at 71 seconds there, but the tablet runs out of GPU memory 4 seconds later ([E1302](../errors/E1302.md)).
|
|
111
93
|
|
|
112
94
|
## Compress every file
|
|
113
95
|
|
|
114
|
-
The host's compression decides the size of the start's largest downloads. Send every file of the build with Brotli where the host has it, and with gzip where it does not:
|
|
96
|
+
The host's compression decides the size of the start's largest downloads. Send every file of the build with Brotli where the host has it, and with gzip where it does not. A device loads one start shader file, picked by what its GPU supports:
|
|
115
97
|
|
|
116
98
|
| File | As it is | gzip | Brotli |
|
|
117
99
|
| --- | --- | --- | --- |
|
|
118
|
-
| The
|
|
119
|
-
| The
|
|
120
|
-
| The WebGPU start shader file | 0.42 MB | 0.09 MB | 0.04 MB |
|
|
100
|
+
| The largest WebGL2 start shader file | 1.4 MB | 0.21 MB | 0.06 MB |
|
|
101
|
+
| The largest WebGPU start shader file | 0.47 MB | 0.09 MB | 0.04 MB |
|
|
121
102
|
|
|
122
|
-
|
|
103
|
+
The engine core's `.wasm` file takes about 0.6 MB with Brotli ([Send the files with Brotli](../getting-started/hosting.md#send-the-files-with-brotli)).
|
|
123
104
|
|
|
124
105
|
The null3D Vite plugin compresses in both of its servers. `vite preview` compresses the build's files and models with Brotli, `.wasm` included, for every visitor. The dev server compresses its answers to other devices, such as a phone on the network, and leaves `localhost` as it is.
|
|
125
106
|
|
|
@@ -130,14 +111,22 @@ Models compress less, because their textures are compressed already. Brotli save
|
|
|
130
111
|
A repeat visit is fast when the browser keeps what the first visit downloaded. Vite names each file in `assets/` with a hash of its content. Serve those files as immutable, and the HTML page so that the browser checks it each time, as [Hosting](../getting-started/hosting.md#let-browsers-keep-the-build-files) shows. A repeat visit then downloads only the page.
|
|
131
112
|
|
|
132
113
|
- A file served with `no-cache` costs one round trip on every visit, even when it has not changed. Give your own large files, such as models, a hash or a version in their addresses, such as `statue-v3.glb`, and serve those addresses as immutable. Serve every other address with `no-cache`, so a changed file never shows its old copy.
|
|
133
|
-
- Send
|
|
134
|
-
|
|
114
|
+
- Send the build's files as [Hosting](../getting-started/hosting.md#let-browsers-keep-the-build-files) shows, including the header that lets Chrome keep the compiled core ([let Chrome keep the compiled core](../getting-started/hosting.md#let-chrome-keep-the-compiled-core)).
|
|
115
|
+
|
|
116
|
+
On the engine's test page, a repeat visit took 160 ms to the first frame with the compiled core kept. It took 176 to 180 ms with only the file kept. Chrome recompiled 3 functions in the first case, and 273 in the second.
|
|
135
117
|
|
|
136
118
|
## Serve over HTTP/2
|
|
137
119
|
|
|
138
120
|
Over HTTP/1.1, a browser opens at most six connections to a host. The page, every engine worker and every download share them. A large download holds a connection, and the other requests wait in a queue. Over HTTP/2 or HTTP/3, one connection carries every request at once. Cloudflare Pages, Netlify, Vercel and most CDNs serve HTTP/2. The network panel's Protocol column shows `h2` or `h3` for each file.
|
|
139
121
|
|
|
140
|
-
The null3D Vite plugin serves its
|
|
122
|
+
The null3D Vite plugin serves its dev server over HTTP/1.1, because Safari on an iPad sometimes stalls over HTTP/2. Its `http2: true` option serves HTTP/2 for other browsers ([During development](../getting-started/hosting.md#during-development)).
|
|
123
|
+
|
|
124
|
+
<details>
|
|
125
|
+
<summary>Technical details: HTTP/2 on the dev server</summary>
|
|
126
|
+
|
|
127
|
+
Over the simulated phone connection, HTTP/2 cut a small demo's first visit from the dev server from 13.8 to 7.2 seconds. Its reload fell from 11.7 to 4.7 seconds.
|
|
128
|
+
|
|
129
|
+
</details>
|
|
141
130
|
|
|
142
131
|
## Keep the early core script
|
|
143
132
|
|
|
@@ -159,11 +148,20 @@ A production build with the null3D Vite plugin adds a small script to the head o
|
|
|
159
148
|
|
|
160
149
|
So when the core arrives, the setup starts almost at once.
|
|
161
150
|
|
|
162
|
-
|
|
151
|
+
Because the sketch worker imports the sketch module during the download, the module's top-level code runs before the engine has started. It also runs when the start fails.
|
|
163
152
|
|
|
164
|
-
|
|
153
|
+
Work there must not need the engine: a call that makes scene data before the core starts fails with [E1403](../errors/E1403.md). Work that needs no engine can run there and overlap the download, such as a height grid that the first view reads. Hold mode, a replay and a recording load the module only after the engine has started. There, such work still holds up the setup ([Sketch API](../api/sketch.md)).
|
|
154
|
+
|
|
155
|
+
The Vite plugin also writes into the built sketch module every file that the module reaches through its imports. So the sketch worker asks for all of them as soon as the module arrives. It needs no round trip for each step of the chain. A sketch's code then arrives in about 2 rounds instead of 4 to 6. Over HTTP/1.1 the six connections still queue those files, so the gain there is small.
|
|
156
|
+
|
|
157
|
+
<details>
|
|
158
|
+
<summary>Technical details: the engine package's sideEffects field</summary>
|
|
165
159
|
|
|
166
|
-
The
|
|
160
|
+
The engine's package declares no `sideEffects` list. A build with one started more slowly.
|
|
161
|
+
|
|
162
|
+
</details>
|
|
163
|
+
|
|
164
|
+
`engine.measure()` reports when the thread that draws had its device, its shader file and its renderer, in `load.drawingStart` ([Measure a start](#measure-a-start)).
|
|
167
165
|
|
|
168
166
|
## Start the first view's downloads at the top of the setup
|
|
169
167
|
|
|
@@ -197,7 +195,16 @@ The engine's add-ons follow the same rule. The sound add-on downloads its record
|
|
|
197
195
|
|
|
198
196
|
Post the first loading message on the setup's first line, so the loading screen names the scene's own work from the start.
|
|
199
197
|
|
|
200
|
-
Name the first view's files in the `downloads` option of `defineSketch`, in the order that the setup needs them: `defineSketch(setup, { downloads: [...] })`. They start to download as soon as the sketch module loads, often before the core has arrived.
|
|
198
|
+
Name the first view's files in the `downloads` option of `defineSketch`, in the order that the setup needs them: `defineSketch(setup, { downloads: [...] })`. They start to download as soon as the sketch module loads, often before the core has arrived.
|
|
199
|
+
|
|
200
|
+
<details>
|
|
201
|
+
<summary>Technical details: how the download list is scheduled</summary>
|
|
202
|
+
|
|
203
|
+
Two files download at a time, at a low priority, so the engine's own files still find free connections. A load that waits for a listed file moves it to the front, and up to four then download at once. Hold mode, replays and recordings ignore the list ([The download list](../api/sketch.md#the-download-list)).
|
|
204
|
+
|
|
205
|
+
</details>
|
|
206
|
+
|
|
207
|
+
Over the simulated phone link, the creek demo's eleven models took 21.3 seconds with the download list. They took 25.9 seconds without it, with every model drawn before the first frame. With nothing downloading before the first frame, it took 0.2 seconds with the list and 3.3 seconds without. The [character demo](https://github.com/null3d-engine/null3d/tree/main/examples/character) starts its two loads together, after it builds the courtyard.
|
|
201
208
|
|
|
202
209
|
List only the files that the first frame needs, and start the rest from `engine.firstFrame`, as the next section shows. A development build warns once in a live start when a scene's own load started only after another one finished, with nothing else downloading. Pass `serialLoadWarning: false` to turn the warning off where the second address comes from the first file.
|
|
203
210
|
|
|
@@ -207,6 +214,8 @@ The first frame waits for the setup. When the setup awaits a large model, the vi
|
|
|
207
214
|
|
|
208
215
|
Start those downloads after the first frame, not in the setup. Over HTTP/1.1, large files that the setup starts take all six connections, and the first frame's own shader and code files wait behind them. A lower fetch priority does not help: the large files take the free connections before the shader requests exist. Started with the setup, a scene's 2.85 MB of town models made its first frame 0.7 to 1.0 seconds later.
|
|
209
216
|
|
|
217
|
+
On the simulated phone link, the creek demo's first frame takes 5.7 seconds when its large models come after it. It takes 25.7 seconds when the setup waits for them. The [Creek showcase](https://github.com/null3d-engine/null3d/tree/main/examples/showcase/creek) draws its first frame before its large models arrive.
|
|
218
|
+
|
|
210
219
|
In the sketch, `engine.firstFrame` resolves once the GPU has finished the first frame, as `engine.firstFrame` does on the page. Unlike the page's promise, it never rejects: when the engine stops first, it stays pending. Start the later downloads when it resolves:
|
|
211
220
|
|
|
212
221
|
```ts
|
|
@@ -229,11 +238,11 @@ export default defineSketch(async ({ assets, engine, scene }) => {
|
|
|
229
238
|
|
|
230
239
|
Never await `engine.firstFrame` in the setup, because the first frame waits for the setup. A frame number is no such signal. The thread that draws can still be drawing the first frame while the sketch runs the second ([The engine field](../api/sketch.md#the-engine-field)).
|
|
231
240
|
|
|
232
|
-
`engine.held` is true in hold mode and in a replay, so tests still draw the finished scene. A held start that waits for many files starts them all on the setup's first line with `assets.preload`. It then builds the scene in one fixed order. The
|
|
241
|
+
`engine.held` is true in hold mode and in a replay, so tests still draw the finished scene. A held start that waits for many files starts them all on the setup's first line with `assets.preload`. It then builds the scene in one fixed order. The Island demo takes a `?grown` switch that does the same on a live page. A page that measures frame rates then measures the finished scene.
|
|
233
242
|
|
|
234
243
|
While the engine holds frames or replays, the sketch's `assets` calls run one at a time, in the order the sketch made them. So the held picture never depends on which file lands first ([Hold mode](testing.md#hold-mode)).
|
|
235
244
|
|
|
236
|
-
A scene that streams its content, such as a splat scan, can draw once the parts nearest the camera are in. The rest then stream in after the first frame. The engine's splat demo drew its first frame after 8.8 seconds that way, over the simulated phone connection. It took 29.1 seconds when it waited for every part.
|
|
245
|
+
A scene that streams its content, such as a splat scan, can draw once the parts nearest the camera are in. The rest then stream in after the first frame. The engine's splat demo drew its first frame after 8.8 seconds that way, over the simulated phone connection. It took 29.1 seconds when it waited for every part. The [splats demo](https://github.com/null3d-engine/null3d/tree/main/examples/splats) streams the scan's nearest chunks first.
|
|
237
246
|
|
|
238
247
|
A model that appears after the first frame draws once its pipelines are built, on both GPU paths. Without `KHR_parallel_shader_compile`, as in Chrome on some Android phones, each new WebGL2 program compiles at its first draw. That frame then runs long, once for each new program. To show a later group of models whole, create them hidden and warm up, as [A later loading stage](loading-screens.md#a-later-loading-stage) shows.
|
|
239
248
|
|
|
@@ -241,11 +250,9 @@ The same holds for work that the first view does not need. Light maps that a sce
|
|
|
241
250
|
|
|
242
251
|
## The preset check
|
|
243
252
|
|
|
244
|
-
When the engine picks the quality preset itself, it checks the preset in the first frames of play on a first visit. The
|
|
245
|
-
|
|
246
|
-
A check before play costs a slow tablet the most. On a Galaxy Tab A9 Plus, it held the loading screen 8 to 18 seconds after the first frame. A page that would rather hide a change of preset behind its loading screen passes `presetCheck: 'before-play'` to `createEngine`. The check then runs before play, and `createEngine` waits for it, at least three quarters of a second for each preset that it measures. The `?preset-check=` switch sets the same from the page's address ([The preset check](loading-screens.md#the-preset-check)).
|
|
253
|
+
When the engine picks the quality preset itself, it checks the preset in the first frames of play on a first visit. The check can lower the preset in front of the viewer. On a Galaxy Tab A9 Plus, a check during play ran 12 to 38 seconds after the first frame. A check before play held the loading screen 8 to 18 seconds after it. `presetCheck: 'before-play'` hides the change behind the loading screen, and `createEngine` waits for it. The `?preset-check=` switch sets the same from the page's address ([The preset check](loading-screens.md#the-preset-check)).
|
|
247
254
|
|
|
248
|
-
On a slow tablet the check
|
|
255
|
+
On a slow tablet the check takes many seconds, as each lighter preset builds its pipelines. It stores each round as it lowers the preset, so the next start begins at the preset that it reached. A page or a tool that measures steady play waits for `engine.presetChecked`, because the check can lower the preset inside the measured window. A repeat visit takes the stored result and runs no check, and a phone starts at Low, which has no check.
|
|
249
256
|
|
|
250
257
|
## Pipelines on phones
|
|
251
258
|
|
|
@@ -259,19 +266,42 @@ Building the first frame's pipelines is the largest processor cost of a start on
|
|
|
259
266
|
| iPhone 17 | 2.4 s | 11.8 s | 13.1 s | 16.5 s |
|
|
260
267
|
| MacBook Pro | 0.1 s | 0.2 s | 0.3 s | 0.7 s |
|
|
261
268
|
|
|
262
|
-
The phones built 16 to 17, 53 to 55, 61 to 63 and 45 to 46 pipelines for the four demos. The MacBook Pro built 31, 73, 84 and 73 at its higher preset, in a fraction of the time.
|
|
269
|
+
The phones built 16 to 17, 53 to 55, 61 to 63 and 45 to 46 pipelines for the four demos. The MacBook Pro built 31, 73, 84 and 73 at its higher preset, in a fraction of the time.
|
|
270
|
+
|
|
271
|
+
On a repeat visit, Safari reused its compiled shaders, and the iPhone 17 built each demo's pipelines in 0.2 seconds or less. In Chrome on Android, the small demo built its pipelines 4 to 5 times faster, and the larger demos built theirs no faster.
|
|
272
|
+
|
|
273
|
+
<details>
|
|
274
|
+
<summary>Technical details: Chrome's pipeline cache</summary>
|
|
263
275
|
|
|
264
|
-
|
|
276
|
+
Chrome on Android keeps about 2 MB of a site's compiled WebGPU pipelines between visits, and 128 KB on a low-end phone. A computer keeps 6 MB. A scene with many large shaders overflows it, so the engine keeps a list of its own.
|
|
277
|
+
|
|
278
|
+
</details>
|
|
265
279
|
|
|
266
280
|
- Keep the first view's pipelines few. A pipeline serves every object of one shading model, vertex format and set of material features, as the [Performance guide](performance.md#how-the-engine-batches-builds-pipelines-and-times-frames) lists. A new feature on one material, such as a normal map, makes a new pipeline.
|
|
267
281
|
- Warm up behind the loading screen, so play builds no pipeline ([Loading screens and warm-up](loading-screens.md#pipelines-and-warm-up)).
|
|
268
282
|
- Time the start on the phones and tablets of your audience. A desktop browser that emulates a phone builds pipelines at the computer's speed.
|
|
269
283
|
|
|
270
|
-
The engine
|
|
284
|
+
The engine's own passes add pipelines too, and the first frame builds only those that it draws with:
|
|
285
|
+
|
|
286
|
+
- On WebGPU, the pass that lists each cluster's point, spot and area lights takes 4 compute pipelines. Where the GPU fits the clusters to the measured depth (`lightFit`), it takes 4 more. A first frame whose scene holds none of these lights leaves them out.
|
|
287
|
+
- The final pass's second step scales a lower render scale up to the canvas, and takes 1 pipeline on both paths. A first frame at the whole render scale that does not sharpen leaves it out.
|
|
288
|
+
|
|
289
|
+
The pipelines that the first frame leaves out build in the background once it shows. So a light or a lower render scale that comes later finds them built. In the engine's start bench, a small lit page's first frame at Low builds 4 pipelines on each path. With the light clustering and the second step, it would build 13 on WebGPU and 5 on WebGL2. A light that comes while they still build lights nothing until they are built. A lower render scale draws at the whole scale meanwhile. So create the lights of the first view in the setup.
|
|
290
|
+
|
|
291
|
+
The engine keeps a list of the pipelines that a sketch's first frame built, in the page's `localStorage`. On the next start, the thread that draws builds each of those pipelines as soon as its shader arrives. The engine downloads and the setup runs meanwhile. Hold mode, replays and recordings neither read nor store the list, and `?builds=fresh` turns it off ([Repeat visits](loading-screens.md#repeat-visits)).
|
|
292
|
+
|
|
293
|
+
<details>
|
|
294
|
+
<summary>Technical details: how the stored pipeline list works</summary>
|
|
295
|
+
|
|
296
|
+
The list is kept for each engine version, GPU path, set of the device's shader bits, preset and canvas format. A scene that changed since the last start builds some pipelines that no frame takes, and its first frame stores a new list. Before the first frame, the engine also builds in the background the pipelines that the frame's list asks for partway through. Identical pipelines share one build.
|
|
297
|
+
|
|
298
|
+
</details>
|
|
299
|
+
|
|
300
|
+
On a repeat visit, the stored list cut the island's time on a Galaxy S25 from 3.81 to 1.56 seconds. It measures from the setup's end to the first frame.
|
|
271
301
|
|
|
272
302
|
These figures run from the setup's end to the first frame:
|
|
273
303
|
|
|
274
|
-
| Demo and device |
|
|
304
|
+
| Demo and device | Without the list | With the list |
|
|
275
305
|
| --- | --- | --- |
|
|
276
306
|
| Island, Galaxy S25, first visit | 5.79 s | 3.77 s |
|
|
277
307
|
| Island, Galaxy S25, repeat visit | 3.81 s | 1.56 s |
|
|
@@ -281,7 +311,7 @@ These figures run from the setup's end to the first frame:
|
|
|
281
311
|
|
|
282
312
|
## Cache for offline play after the first frame
|
|
283
313
|
|
|
284
|
-
A service worker that caches the build for offline play downloads files of its own. When it starts at the page's load, its downloads share the connection with the start. A worker that caches every file of a large build makes every first visit slower, and every repeat visit too until its cache is complete.
|
|
314
|
+
A service worker that caches the build for offline play downloads files of its own. When it starts at the page's load, its downloads share the connection with the start. A worker that caches every file of a large build makes every first visit slower, and every repeat visit too until its cache is complete. On the engine's demo page, a worker that cached every file sent about 1,570 requests and 820 MB over the start's connections.
|
|
285
315
|
|
|
286
316
|
- Register the service worker once `engine.firstFrame` has resolved.
|
|
287
317
|
- Cache only what the game needs: its pages, the start's files and the features that it uses, as [Offline play](../getting-started/hosting.md#offline-play) shows.
|
|
@@ -317,7 +347,12 @@ In the browser's developer tools, pick the Slow 4G profile. Time a first visit w
|
|
|
317
347
|
|
|
318
348
|
Chrome's network throttling does not slow a service worker's own downloads. Its CPU throttling slows the page's thread, while the engine's setup and drawing run in workers. So time the setup's work and the pipeline builds on a real phone, through remote debugging.
|
|
319
349
|
|
|
320
|
-
|
|
350
|
+
<details>
|
|
351
|
+
<summary>Technical details: how the engine's own start is timed</summary>
|
|
352
|
+
|
|
353
|
+
The engine's repository times its own start with `bun run bench:startup`. It loads the engine's test page cold and warm in Chrome, on Slow 4G by default. It prints the median of each stage, with the drawing thread's device, shader file and renderer.
|
|
354
|
+
|
|
355
|
+
</details>
|
|
321
356
|
|
|
322
357
|
## Related pages
|
|
323
358
|
|