@null3d/engine 0.0.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/README.md +109 -0
- package/THIRD-PARTY-NOTICES.txt +0 -1
- package/dist/wasm/single/null3d.js +25 -10
- package/dist/wasm/single/null3d_bg.wasm +0 -0
- package/dist/wasm/threaded/null3d.js +25 -10
- package/dist/wasm/threaded/null3d_bg.wasm +0 -0
- package/docs/api/animation.md +114 -86
- package/docs/api/assets.md +135 -49
- package/docs/api/cameras.md +45 -12
- package/docs/api/controls.md +88 -62
- package/docs/api/debug.md +116 -41
- package/docs/api/engine.md +117 -35
- package/docs/api/feature-draws.md +23 -17
- package/docs/api/feature-effects.md +11 -11
- package/docs/api/feature-instances.md +70 -19
- package/docs/api/features.md +77 -47
- package/docs/api/geometry.md +132 -82
- package/docs/api/grass.md +55 -13
- package/docs/api/impostors.md +175 -22
- package/docs/api/input.md +24 -18
- package/docs/api/lights.md +78 -51
- package/docs/api/lines.md +41 -33
- package/docs/api/materials.md +248 -121
- package/docs/api/math.md +12 -13
- package/docs/api/objects.md +47 -22
- package/docs/api/page.md +58 -7
- package/docs/api/particles.md +33 -20
- package/docs/api/points.md +19 -31
- package/docs/api/post.md +75 -42
- package/docs/api/quality.md +42 -17
- package/docs/api/raycast.md +65 -51
- package/docs/api/reference/animation.md +10 -11
- package/docs/api/reference/assets.md +25 -22
- package/docs/api/reference/cameras.md +8 -4
- package/docs/api/reference/controls.md +134 -25
- package/docs/api/reference/debug.md +81 -14
- package/docs/api/reference/engine.md +58 -17
- 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 +287 -97
- package/docs/api/reference/grass.md +63 -3
- package/docs/api/reference/impostors.md +208 -13
- package/docs/api/reference/input.md +4 -5
- package/docs/api/reference/lights.md +13 -12
- package/docs/api/reference/lines.md +10 -11
- package/docs/api/reference/materials.md +54 -53
- package/docs/api/reference/math.md +35 -24
- package/docs/api/reference/objects.md +11 -12
- package/docs/api/reference/particles.md +31 -6
- package/docs/api/reference/points.md +6 -7
- package/docs/api/reference/post.md +21 -20
- package/docs/api/reference/quality.md +8 -5
- package/docs/api/reference/raycast.md +7 -8
- package/docs/api/reference/render.md +5 -4
- package/docs/api/reference/scene.md +52 -30
- package/docs/api/reference/sketch.md +15 -11
- package/docs/api/reference/sound.md +234 -0
- package/docs/api/reference/splats.md +42 -3
- package/docs/api/reference/sprites.md +7 -8
- package/docs/api/reference/tasks.md +16 -3
- package/docs/api/reference/terrain.md +27 -5
- package/docs/api/reference/textures.md +5 -6
- package/docs/api/reference/three-compat.md +18 -7
- package/docs/api/reference/time.md +1 -2
- package/docs/api/reference/ui.md +12 -9
- package/docs/api/reference/vertex-draws.md +5 -6
- package/docs/api/reference/water.md +153 -9
- package/docs/api/reference/wind.md +17 -4
- package/docs/api/render.md +73 -29
- package/docs/api/scene.md +164 -60
- package/docs/api/sketch.md +102 -15
- package/docs/api/sound.md +205 -0
- package/docs/api/splats.md +46 -12
- package/docs/api/sprites.md +10 -24
- package/docs/api/tasks.md +33 -24
- package/docs/api/terrain.md +42 -22
- package/docs/api/textures.md +68 -19
- package/docs/api/three-compat.md +15 -7
- package/docs/api/time.md +3 -5
- package/docs/api/ui.md +19 -23
- package/docs/api/vertex-draws.md +13 -12
- package/docs/api/water.md +262 -35
- package/docs/api/wind.md +63 -17
- package/docs/cli/null3d.md +177 -27
- package/docs/concepts/architecture.md +73 -27
- package/docs/concepts/assets.md +57 -33
- package/docs/concepts/backends.md +69 -27
- package/docs/concepts/color-management.md +54 -36
- package/docs/concepts/culling.md +68 -47
- package/docs/concepts/handles.md +14 -5
- package/docs/concepts/instances.md +74 -25
- package/docs/concepts/large-worlds.md +18 -8
- package/docs/concepts/lighting.md +155 -87
- package/docs/concepts/lod.md +126 -44
- package/docs/concepts/materials.md +58 -27
- package/docs/concepts/particle-buffer.md +48 -35
- package/docs/concepts/post-processing.md +84 -43
- package/docs/concepts/quality-preset-tables.md +56 -52
- package/docs/concepts/quality-presets.md +164 -52
- package/docs/concepts/render-graph.md +69 -29
- package/docs/concepts/render-layers.md +11 -21
- package/docs/concepts/shadows.md +105 -52
- package/docs/concepts/static-dynamic.md +22 -7
- package/docs/cookbook/index.md +164 -120
- package/docs/data/threejs-mapping.json +362 -367
- 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 +14 -6
- 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 +40 -0
- 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 +14 -6
- 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 +54 -30
- package/docs/getting-started/cdn.md +32 -10
- package/docs/getting-started/first-scene.md +21 -13
- package/docs/getting-started/hosting.md +152 -63
- package/docs/getting-started/install.md +44 -28
- package/docs/getting-started/network-use.md +33 -15
- package/docs/getting-started/project-structure.md +33 -12
- package/docs/getting-started/third-party-notices.md +12 -14
- package/docs/guides/accessibility.md +5 -5
- package/docs/guides/add-ons.md +86 -15
- package/docs/guides/agents.md +16 -9
- package/docs/guides/assets-pipeline.md +259 -82
- package/docs/guides/audio.md +115 -128
- package/docs/guides/baked-light-data.md +44 -23
- package/docs/guides/car-paint.md +38 -32
- package/docs/guides/content-pages.md +63 -35
- package/docs/guides/custom-passes.md +65 -22
- package/docs/guides/custom-shaders.md +59 -39
- package/docs/guides/debugging.md +74 -10
- package/docs/guides/deploying.md +85 -6
- package/docs/guides/deterministic-simulation.md +24 -17
- package/docs/guides/first-use-shaders.md +83 -45
- package/docs/guides/lens-kit.md +29 -26
- package/docs/guides/loading-screens.md +132 -47
- package/docs/guides/multiple-views.md +63 -13
- package/docs/guides/performance.md +192 -38
- package/docs/guides/phones.md +78 -15
- package/docs/guides/physics.md +7 -11
- package/docs/guides/screens.md +47 -33
- package/docs/guides/start-time.md +363 -0
- package/docs/guides/testing.md +152 -95
- package/docs/guides/ui-overlays.md +19 -14
- 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 +18 -23
- package/docs/moves.json +1 -0
- package/docs/nav.json +300 -0
- package/docs/pages.md +230 -209
- package/docs/porting/react-three-fiber.md +225 -6
- package/docs/porting/threejs-loop-and-threads.md +217 -7
- package/docs/porting/threejs-mapping.md +1249 -233
- package/docs/porting/threejs-materials.md +218 -6
- package/docs/porting/threejs-overview.md +240 -7
- package/docs/porting/threejs-postprocessing.md +4 -8
- package/docs/porting/threejs-shaders.md +301 -6
- package/docs/porting/threejs-unsupported.md +83 -7
- package/docs/porting/verification.md +178 -6
- package/docs/shaders/builtins.md +15 -4
- package/docs/shaders/library.md +72 -45
- package/docs/shaders/surface-functions.md +59 -23
- package/docs/shaders/wgsl-rules.md +12 -5
- package/lib/debug/channel.d.ts +103 -0
- package/lib/debug/channel.js +269 -0
- package/lib/debug/debug.d.ts +11 -9
- package/lib/debug/draw.d.ts +11 -2
- package/lib/debug/draw.js +57 -6
- package/lib/debug/inspector.d.ts +60 -0
- package/lib/debug/inspector.js +475 -0
- 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 +22 -7
- package/lib/debug/stats-panel.js +80 -13
- package/lib/debug/stats.d.ts +2 -3
- package/lib/errors/codes.d.ts +17 -3
- package/lib/errors/codes.js +117 -105
- package/lib/errors/engine-error.js +25 -10
- package/lib/errors/fixes.d.ts +1 -0
- package/lib/errors/fixes.js +20 -19
- 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/variants.d.ts +8 -2
- package/lib/gpu/variants.js +39 -7
- 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 +5 -2
- 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 +28 -14
- package/lib/index.d.ts +7 -5
- 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 +8 -8
- 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 +117 -31
- package/lib/page/engine.js +438 -99
- 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 +26 -14
- 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/stats-switch.js +2 -0
- package/lib/page/switches.d.ts +38 -6
- package/lib/page/switches.js +29 -5
- 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/baked-light.d.ts +2 -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 +3 -3
- package/lib/scene/fog.d.ts +11 -4
- package/lib/scene/fog.js +8 -2
- package/lib/scene/frame-cameras.d.ts +35 -4
- package/lib/scene/frame-cameras.js +86 -10
- package/lib/scene/gltf.d.ts +33 -3
- 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 +121 -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/particles.d.ts +7 -3
- package/lib/scene/particles.js +3 -1
- package/lib/scene/picks.d.ts +2 -2
- package/lib/scene/pointer-events.d.ts +4 -7
- package/lib/scene/post.d.ts +39 -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 +238 -261
- package/lib/scene/resources.js +179 -81
- package/lib/scene/scene.d.ts +167 -120
- package/lib/scene/scene.js +243 -103
- 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 +11 -7
- package/lib/scene/time-of-day.js +11 -8
- 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/labels.d.ts +5 -2
- package/lib/shared/labels.js +5 -2
- package/lib/shared/metrics.d.ts +38 -0
- package/lib/shared/metrics.js +62 -1
- 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/run-task.js +7 -1
- package/lib/shared/sketch-data.d.ts +9 -0
- package/lib/shared/sketch-data.js +57 -0
- 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 +51 -7
- package/lib/sketch/define-sketch.js +2 -1
- 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 +80 -9
- package/lib/sketch/runner.js +390 -52
- package/lib/sketch/ui.d.ts +5 -8
- package/lib/sketch/ui.js +4 -2
- package/lib/stats.d.ts +1 -0
- package/lib/workers/probe-worker.d.ts +5 -0
- package/lib/workers/probe-worker.js +13 -4
- package/lib/workers/protocol.d.ts +71 -13
- package/lib/workers/protocol.js +4 -0
- package/lib/workers/render-worker.js +29 -5
- package/lib/workers/sketch-worker.js +108 -16
- package/package.json +2 -2
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: guides/start-time
|
|
3
|
+
title: A fast start
|
|
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."
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# A fast start
|
|
8
|
+
|
|
9
|
+
```mermaid
|
|
10
|
+
flowchart LR
|
|
11
|
+
html["The HTML page"] --> early["The early script<br/>starts the core's download"]
|
|
12
|
+
html --> scripts["The page's scripts<br/>call createEngine"]
|
|
13
|
+
early --> core["The engine core<br/>downloads and compiles"]
|
|
14
|
+
scripts --> during["While the core downloads:<br/>workers, the sketch module,<br/>the GPU device, the shader file"]
|
|
15
|
+
during --> setup["The setup downloads<br/>and builds the first view"]
|
|
16
|
+
core --> setup
|
|
17
|
+
setup --> frame["The first frame<br/>builds its pipelines"]
|
|
18
|
+
frame --> later["Large models and the<br/>preset check during play"]
|
|
19
|
+
```
|
|
20
|
+
|
|
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.
|
|
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
|
+
|
|
35
|
+
## Where the time goes
|
|
36
|
+
|
|
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:
|
|
38
|
+
|
|
39
|
+
| Step | Cost when skipped | What shortens it |
|
|
40
|
+
| --- | --- | --- |
|
|
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) |
|
|
47
|
+
|
|
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.
|
|
49
|
+
|
|
50
|
+
<details>
|
|
51
|
+
<summary>Technical details: measured starts on a simulated phone link and on real phones</summary>
|
|
52
|
+
|
|
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.
|
|
54
|
+
|
|
55
|
+
Over HTTP/1.1:
|
|
56
|
+
|
|
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 |
|
|
65
|
+
|
|
66
|
+
Over HTTP/2:
|
|
67
|
+
|
|
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 |
|
|
76
|
+
|
|
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:
|
|
78
|
+
|
|
79
|
+
| Device | Small demo | Skyway | Island | Creek |
|
|
80
|
+
| --- | --- | --- | --- | --- |
|
|
81
|
+
| Galaxy S25, Chrome | 3.5 to 7.3 s | 5.7 s | 8.1 s | 5.7 s |
|
|
82
|
+
| Pixel 9, Chrome | 4.0 s | 6.5 s | 13.4 s | 8.7 s |
|
|
83
|
+
| Galaxy Tab A9 Plus, Chrome | 11.3 s | 17.7 s | 39 s | 31 s |
|
|
84
|
+
| iPhone 17, Safari | 8.9 s | 17.2 s | 20.4 s | 11.1 s |
|
|
85
|
+
|
|
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.
|
|
87
|
+
|
|
88
|
+
</details>
|
|
89
|
+
|
|
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.
|
|
91
|
+
|
|
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)).
|
|
93
|
+
|
|
94
|
+
## Compress every file
|
|
95
|
+
|
|
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:
|
|
97
|
+
|
|
98
|
+
| File | As it is | gzip | Brotli |
|
|
99
|
+
| --- | --- | --- | --- |
|
|
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 |
|
|
102
|
+
|
|
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)).
|
|
104
|
+
|
|
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.
|
|
106
|
+
|
|
107
|
+
Models compress less, because their textures are compressed already. Brotli saved 0 to 25% on most of the demos' models, and 74% on one. The asset tool, `bunx @null3d/cli assets optimize`, makes models smaller to download before the host compresses them ([The asset pipeline](assets-pipeline.md)).
|
|
108
|
+
|
|
109
|
+
## Let the browser keep the files
|
|
110
|
+
|
|
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.
|
|
112
|
+
|
|
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.
|
|
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.
|
|
117
|
+
|
|
118
|
+
## Serve over HTTP/2
|
|
119
|
+
|
|
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.
|
|
121
|
+
|
|
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>
|
|
130
|
+
|
|
131
|
+
## Keep the early core script
|
|
132
|
+
|
|
133
|
+
A production build with the null3D Vite plugin adds a small script to the head of each page that starts the engine. The script starts the core's download as soon as the HTML arrives, before the page's own scripts have downloaded and run. It picks the build that `createEngine` will pick, and the engine takes its download. In the engine's startup benchmark on Slow 4G, the first frame came 0.2 seconds sooner on a MacBook Pro. On a Galaxy S24+ it came about 0.3 seconds sooner.
|
|
134
|
+
|
|
135
|
+
- Keep the script as the first tag in the page's head. A step that rewrites the built HTML must keep its `<script type="module" async>` tag.
|
|
136
|
+
- Add no `<link rel="preload">` for the core. The HTML cannot know which build the device takes, and a wrong guess downloads 0.6 MB more. Safari can also download the core twice.
|
|
137
|
+
- Create the engine as soon as the page can. A page that waits for something else first, such as a framework's hydration, delays every step that the engine takes while the core downloads.
|
|
138
|
+
- The dev server's pages have no early script.
|
|
139
|
+
- A page that loads the engine from a CDN adds the script itself, as [Try null3D from a CDN](../getting-started/cdn.md#start-the-core-early) shows.
|
|
140
|
+
|
|
141
|
+
## What the engine does while the core downloads
|
|
142
|
+
|
|
143
|
+
`createEngine` starts the rest of the start while the core downloads:
|
|
144
|
+
|
|
145
|
+
- It starts the sketch worker and the render worker, and the sketch worker imports the sketch module with all its imports.
|
|
146
|
+
- It tests the GPU, then asks for the WebGPU device and downloads the device's shader file and its renderer's code.
|
|
147
|
+
- It downloads the job workers' script, so a job worker that starts later takes it from the cache.
|
|
148
|
+
|
|
149
|
+
So when the core arrives, the setup starts almost at once.
|
|
150
|
+
|
|
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.
|
|
152
|
+
|
|
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>
|
|
159
|
+
|
|
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)).
|
|
165
|
+
|
|
166
|
+
## Start the first view's downloads at the top of the setup
|
|
167
|
+
|
|
168
|
+
A download that the setup starts after an `await` waits for that `await`, and the connection can stand idle meanwhile. So start every file that the first view needs on the setup's first lines, and await each one only where the scene needs it:
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
// sketch.ts
|
|
172
|
+
import { defineSketch } from '@null3d/engine';
|
|
173
|
+
|
|
174
|
+
const STATUE = '/models/statue-v3.glb';
|
|
175
|
+
|
|
176
|
+
export default defineSketch(async ({ assets, page, scene }) => {
|
|
177
|
+
page.post('loading', { text: 'Downloading the statue' });
|
|
178
|
+
// Both downloads start now, together.
|
|
179
|
+
const statue = assets.loadGltf(STATUE);
|
|
180
|
+
const sky = assets.loadEnvironment('/env/evening-v2.ktx2');
|
|
181
|
+
|
|
182
|
+
// Build what needs no file while the files download.
|
|
183
|
+
const camera = scene.createPerspectiveCamera({ position: [0, 2, 8], target: [0, 1, 0] });
|
|
184
|
+
scene.setActiveCamera(camera);
|
|
185
|
+
scene.createDirectionalLight({ direction: [-1, -2, -1], intensity: 3 });
|
|
186
|
+
|
|
187
|
+
scene.setEnvironment(await sky);
|
|
188
|
+
scene.instantiate(await statue);
|
|
189
|
+
});
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
`assets.preload` does the same for files that later code loads: it starts every download at once, and each later load takes its file from memory. A load of a file that is still downloading waits for that download, and starts no second one.
|
|
193
|
+
|
|
194
|
+
The engine's add-ons follow the same rule. The sound add-on downloads its recordings beside its mixer, and the splats add-on starts its decoder and its selection beside its first file.
|
|
195
|
+
|
|
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.
|
|
197
|
+
|
|
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.
|
|
208
|
+
|
|
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.
|
|
210
|
+
|
|
211
|
+
## Draw the first frame before the large models
|
|
212
|
+
|
|
213
|
+
The first frame waits for the setup. When the setup awaits a large model, the visitor sees the loading screen for the whole download. So build the first view in the setup, and let the large models that it does not need arrive after the first frame. Each one appears as it lands.
|
|
214
|
+
|
|
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.
|
|
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
|
+
|
|
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:
|
|
220
|
+
|
|
221
|
+
```ts
|
|
222
|
+
// sketch.ts
|
|
223
|
+
import { defineSketch } from '@null3d/engine';
|
|
224
|
+
|
|
225
|
+
const FOREST = '/models/forest-v2.glb';
|
|
226
|
+
|
|
227
|
+
export default defineSketch(async ({ assets, engine, scene }) => {
|
|
228
|
+
// Build the first view here.
|
|
229
|
+
|
|
230
|
+
const addForest = async () => {
|
|
231
|
+
scene.instantiate(await assets.loadGltf(FOREST));
|
|
232
|
+
};
|
|
233
|
+
// A held frame or a replay waits for the forest, so it shows the finished scene.
|
|
234
|
+
if (engine.held) await addForest();
|
|
235
|
+
else void engine.firstFrame.then(addForest).catch((error) => console.error(error)); // the forest appears as it lands
|
|
236
|
+
});
|
|
237
|
+
```
|
|
238
|
+
|
|
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)).
|
|
240
|
+
|
|
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.
|
|
242
|
+
|
|
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)).
|
|
244
|
+
|
|
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.
|
|
246
|
+
|
|
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.
|
|
248
|
+
|
|
249
|
+
The same holds for work that the first view does not need. Light maps that a scene can draw without, such as a sky's environment, need not be awaited: hand them over when they land. Make a map that only one mode of the page uses, such as a studio's room light, when that mode is first picked.
|
|
250
|
+
|
|
251
|
+
## The preset check
|
|
252
|
+
|
|
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)).
|
|
254
|
+
|
|
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.
|
|
256
|
+
|
|
257
|
+
## Pipelines on phones
|
|
258
|
+
|
|
259
|
+
Building the first frame's pipelines is the largest processor cost of a start on a phone. Each pipeline is one compile on the device's GPU driver. The demos built these pipelines for their first frame, on a first visit:
|
|
260
|
+
|
|
261
|
+
| Device | Small demo | Skyway | Island | Creek |
|
|
262
|
+
| --- | --- | --- | --- | --- |
|
|
263
|
+
| Galaxy S25 | 0.4 s | 1.8 s | 4.1 s | 5.4 s |
|
|
264
|
+
| Pixel 9 | 0.9 s | 3.1 s | 6.0 s | 6.7 s |
|
|
265
|
+
| Galaxy Tab A9 Plus | 2.8 s | 10.9 s | 23.5 s | failed |
|
|
266
|
+
| iPhone 17 | 2.4 s | 11.8 s | 13.1 s | 16.5 s |
|
|
267
|
+
| MacBook Pro | 0.1 s | 0.2 s | 0.3 s | 0.7 s |
|
|
268
|
+
|
|
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>
|
|
275
|
+
|
|
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>
|
|
279
|
+
|
|
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.
|
|
281
|
+
- Warm up behind the loading screen, so play builds no pipeline ([Loading screens and warm-up](loading-screens.md#pipelines-and-warm-up)).
|
|
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.
|
|
283
|
+
|
|
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.
|
|
301
|
+
|
|
302
|
+
These figures run from the setup's end to the first frame:
|
|
303
|
+
|
|
304
|
+
| Demo and device | Without the list | With the list |
|
|
305
|
+
| --- | --- | --- |
|
|
306
|
+
| Island, Galaxy S25, first visit | 5.79 s | 3.77 s |
|
|
307
|
+
| Island, Galaxy S25, repeat visit | 3.81 s | 1.56 s |
|
|
308
|
+
| Skyway, Galaxy S25, repeat visit | 2.29 s | about 1.5 s |
|
|
309
|
+
| Creek, Galaxy S25, repeat visit | 4.78 s | about 3.0 s |
|
|
310
|
+
| Island, Galaxy Tab A9 Plus, repeat visit | 23.6 s | 8.8 to 11.2 s |
|
|
311
|
+
|
|
312
|
+
## Cache for offline play after the first frame
|
|
313
|
+
|
|
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.
|
|
315
|
+
|
|
316
|
+
- Register the service worker once `engine.firstFrame` has resolved.
|
|
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.
|
|
318
|
+
- Keep the list small. The call `cache.addAll` keeps nothing until every file of its list has arrived. A visitor who leaves early then starts the list again on the next visit.
|
|
319
|
+
|
|
320
|
+
## Test a production build
|
|
321
|
+
|
|
322
|
+
Judge a start only on a production build that a host serves as above. The Vite dev server sends each module as a file of its own, and asks the browser to check every module on each load. Each engine thread loads its own copy of each module. Over the simulated phone connection, the dev server took 27 to 85 seconds to the first frame. The production build took 4.6 to 25.7 seconds.
|
|
323
|
+
|
|
324
|
+
A phone or tablet that tests the page must trust its certificate. Chrome keeps no file in its cache from a site whose certificate it accepted after a warning. Every load then downloads every file again: a reload of the dev server took 30 seconds instead of 15. Install the certificate's root on the device, as [During development](../getting-started/hosting.md#during-development) shows.
|
|
325
|
+
|
|
326
|
+
## Measure a start
|
|
327
|
+
|
|
328
|
+
`engine.measure()` gives the start's times in its `load` figures ([Performance guide](performance.md#measure)):
|
|
329
|
+
|
|
330
|
+
| Figure | What it is |
|
|
331
|
+
| --- | --- |
|
|
332
|
+
| `load.coreMs` | From the start of `createEngine` until the core was downloaded and compiled |
|
|
333
|
+
| `load.probeMs` | From the start of `createEngine` until the probe of the GPU paths finished |
|
|
334
|
+
| `load.drawingStart` | When the thread that draws got its WebGPU adapter and device, its shader file, the core and its renderer, in milliseconds from the page's navigation |
|
|
335
|
+
| `load.engineStartMs` | How long `createEngine` took, with the setup, and with the preset check before play |
|
|
336
|
+
| `load.firstFrameMs` and `load.firstFrameDoneMs` | From the page's navigation until the first frame was submitted, and until the GPU finished it |
|
|
337
|
+
| `load.warmUpMs` and `load.firstFramePipelines` | How long the first frame's pipelines took to build, and how many it built |
|
|
338
|
+
|
|
339
|
+
In the browser's developer tools, pick the Slow 4G profile. Time a first visit with the cache turned off, then a repeat visit with it on:
|
|
340
|
+
|
|
341
|
+
- In the network panel, check the transferred size of the core's `.wasm` file and of the shader files. A transferred size equal to the size means no compression.
|
|
342
|
+
- Check the Protocol column for `h2` or `h3`.
|
|
343
|
+
- In each request's timing, a long Queueing or Stalled time means the six connections of HTTP/1.1 are full.
|
|
344
|
+
- Look along the waterfall for gaps with nothing downloading, and for downloads that start only when another one ends.
|
|
345
|
+
- On a repeat visit, every build file should come from the cache. A `304` answer is a round trip that immutable files avoid.
|
|
346
|
+
- In the Performance panel, look for long tasks in the sketch worker before the setup's first message.
|
|
347
|
+
|
|
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.
|
|
349
|
+
|
|
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>
|
|
356
|
+
|
|
357
|
+
## Related pages
|
|
358
|
+
|
|
359
|
+
- [Hosting and cross-origin isolation](../getting-started/hosting.md): compression, cache headers, the compiled core and offline play.
|
|
360
|
+
- [Loading screens and warm-up](loading-screens.md): progress, warm-up and the preset check.
|
|
361
|
+
- [Quality presets](../concepts/quality-presets.md#the-preset-check): the preset check's rules.
|
|
362
|
+
- [Phones and tablets](phones.md): networks and repeat visits.
|
|
363
|
+
- [Network use](../getting-started/network-use.md): what the engine downloads, and when.
|