@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
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: getting-started/hosting
|
|
3
3
|
title: Hosting and cross-origin isolation
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.1"
|
|
6
4
|
summary: "COOP and COEP headers; require-corp on Safari; CORS and CORP for assets; the Content-Security-Policy; the engine's files on a CDN; Brotli; the third-party notices; offline play with a service worker and the build's file list; the caches between visits; the single-threaded fallback; Electron desktop apps served from a custom scheme."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Hosting and cross-origin isolation
|
|
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 TD
|
|
15
11
|
load["The page loads the engine"] --> check{"crossOriginIsolated<br/>is true?"}
|
|
@@ -32,6 +28,45 @@ Chrome and Firefox also accept `Cross-Origin-Embedder-Policy: credentialless`, w
|
|
|
32
28
|
|
|
33
29
|
To check a page, open the browser console and read `crossOriginIsolated`. It is `true` on an isolated page. The engine also reports the mode in `engine.capabilities.threaded`.
|
|
34
30
|
|
|
31
|
+
## Headers on common hosts
|
|
32
|
+
|
|
33
|
+
Netlify and Cloudflare Pages read a `_headers` file at the root of the site:
|
|
34
|
+
|
|
35
|
+
```text
|
|
36
|
+
/*
|
|
37
|
+
Cross-Origin-Opener-Policy: same-origin
|
|
38
|
+
Cross-Origin-Embedder-Policy: require-corp
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Vercel reads `vercel.json`:
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"headers": [
|
|
46
|
+
{
|
|
47
|
+
"source": "/(.*)",
|
|
48
|
+
"headers": [
|
|
49
|
+
{ "key": "Cross-Origin-Opener-Policy", "value": "same-origin" },
|
|
50
|
+
{ "key": "Cross-Origin-Embedder-Policy", "value": "require-corp" }
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
nginx:
|
|
58
|
+
|
|
59
|
+
```nginx
|
|
60
|
+
add_header Cross-Origin-Opener-Policy same-origin always;
|
|
61
|
+
add_header Cross-Origin-Embedder-Policy require-corp always;
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
GitHub Pages cannot send custom headers, so a null3D page there runs single-threaded.
|
|
65
|
+
|
|
66
|
+
## What isolation changes
|
|
67
|
+
|
|
68
|
+
`Cross-Origin-Opener-Policy: same-origin` cuts the link between your page and any cross-origin window it opens. A sign-in flow that opens a popup on another site and waits for a message through `window.opener` stops working. Check such flows before you turn isolation on. Under `require-corp`, files from other origins also need to opt in, as [Files from other sites](#files-from-other-sites) explains.
|
|
69
|
+
|
|
35
70
|
## Files from other sites
|
|
36
71
|
|
|
37
72
|
With `require-corp`, the browser loads a file from another origin only when that file allows it. This covers models, textures, fonts and scripts from a CDN or a separate asset domain. Each such file needs one of these:
|
|
@@ -46,16 +81,16 @@ Files from the page's own origin need nothing.
|
|
|
46
81
|
The engine starts under a strict policy. Send this one, or add its parts to your own:
|
|
47
82
|
|
|
48
83
|
```http
|
|
49
|
-
Content-Security-Policy: default-src 'self'; script-src 'self' 'wasm-unsafe-eval'; worker-src 'self'
|
|
84
|
+
Content-Security-Policy: default-src 'self'; script-src 'self' 'wasm-unsafe-eval'; worker-src 'self'; connect-src 'self'
|
|
50
85
|
```
|
|
51
86
|
|
|
52
87
|
- `script-src 'self' 'wasm-unsafe-eval'`: the engine core, the meshopt and Draco decoders and the KTX2 transcoder are WebAssembly, and a policy blocks WebAssembly unless it holds `'wasm-unsafe-eval'`. This keyword allows WebAssembly and no JavaScript `eval`. Without it, `createEngine` rejects with [E1418](../errors/E1418.md). The engine needs no `'unsafe-eval'`.
|
|
53
|
-
- `worker-src 'self'`: the engine's sketch, render, job and probe workers, and the glTF loader's worker.
|
|
88
|
+
- `worker-src 'self'`: the engine's sketch, render, job and probe workers, and its helper workers. These are the glTF loader's worker, the panorama worker for HDR and EXR files and the task worker.
|
|
54
89
|
- `connect-src`: the engine downloads its `.wasm` files and your sketch module from the page's origin, which `default-src 'self'` allows. Add the origin of each CDN that your sketch loads models or textures from.
|
|
55
90
|
|
|
56
91
|
The engine needs no inline script and no inline style. It sets styles from code, which a policy does not block. A page's own inline `<style>` element needs `style-src 'self' 'unsafe-inline'`.
|
|
57
92
|
|
|
58
|
-
A worker follows the policy of its own script's response, not the page's. A host that sends the header on every file, as the examples
|
|
93
|
+
A worker follows the policy of its own script's response, not the page's. A host that sends the header on every file, as the examples above do for the isolation headers, applies the same policy to the workers.
|
|
59
94
|
|
|
60
95
|
## The engine's files on a CDN
|
|
61
96
|
|
|
@@ -78,6 +113,8 @@ Access-Control-Allow-Origin: *
|
|
|
78
113
|
|
|
79
114
|
It may name the page's origin in place of `*`. `Cross-Origin-Resource-Policy` alone does not serve, because the engine imports modules and downloads `.wasm` files in CORS mode. The HTML page still sends the two isolation headers. Without them the engine runs single-threaded, as on any host.
|
|
80
115
|
|
|
116
|
+
The CDN also sends each `.wasm` file with `Content-Type: application/wasm`, and lets browsers keep it. Chrome then keeps the compiled engine core between visits ([Let Chrome keep the compiled core](#let-chrome-keep-the-compiled-core)).
|
|
117
|
+
|
|
81
118
|
A worker that starts from a `blob:` address follows the page's policy. Add these parts to the page's policy, with your CDN's origin:
|
|
82
119
|
|
|
83
120
|
```http
|
|
@@ -112,41 +149,6 @@ The single-threaded build is fully supported. Use it where you cannot set header
|
|
|
112
149
|
|
|
113
150
|
A game starts in either build. Do not gate its Play button on `crossOriginIsolated`, and do not offer a single-threaded mode of its own: the engine falls back by itself. Read `engine.capabilities.threaded` to record which build a run used.
|
|
114
151
|
|
|
115
|
-
## Headers on common hosts
|
|
116
|
-
|
|
117
|
-
Netlify and Cloudflare Pages read a `_headers` file at the root of the site:
|
|
118
|
-
|
|
119
|
-
```text
|
|
120
|
-
/*
|
|
121
|
-
Cross-Origin-Opener-Policy: same-origin
|
|
122
|
-
Cross-Origin-Embedder-Policy: require-corp
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
Vercel reads `vercel.json`:
|
|
126
|
-
|
|
127
|
-
```json
|
|
128
|
-
{
|
|
129
|
-
"headers": [
|
|
130
|
-
{
|
|
131
|
-
"source": "/(.*)",
|
|
132
|
-
"headers": [
|
|
133
|
-
{ "key": "Cross-Origin-Opener-Policy", "value": "same-origin" },
|
|
134
|
-
{ "key": "Cross-Origin-Embedder-Policy", "value": "require-corp" }
|
|
135
|
-
]
|
|
136
|
-
}
|
|
137
|
-
]
|
|
138
|
-
}
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
nginx:
|
|
142
|
-
|
|
143
|
-
```nginx
|
|
144
|
-
add_header Cross-Origin-Opener-Policy same-origin always;
|
|
145
|
-
add_header Cross-Origin-Embedder-Policy require-corp always;
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
GitHub Pages cannot send custom headers, so a null3D page there runs single-threaded.
|
|
149
|
-
|
|
150
152
|
## Desktop apps with Electron
|
|
151
153
|
|
|
152
154
|
Electron ships Chromium, so a null3D game runs in it as it runs in Chrome. The threaded build needs the same cross-origin isolation as on a website. Two common setups do not give it:
|
|
@@ -194,42 +196,67 @@ To check the app, open its developer tools and read `crossOriginIsolated` in the
|
|
|
194
196
|
|
|
195
197
|
## Send the files with Brotli
|
|
196
198
|
|
|
197
|
-
The engine's shader text compresses well with Brotli, which finds text that repeats far apart. gzip finds only repeats that are close together. So the host's compression changes what a page downloads at its start.
|
|
199
|
+
The engine's shader text compresses well with Brotli, which finds text that repeats far apart. gzip finds only repeats that are close together. So the host's compression changes what a page downloads at its start. On a threaded page, in the default latency mode ([Architecture](../concepts/architecture.md#latency-modes)), the engine's part of the start downloads about:
|
|
198
200
|
|
|
199
|
-
| The host sends | The engine's JavaScript
|
|
200
|
-
| --- | --- |
|
|
201
|
-
| Brotli |
|
|
202
|
-
| gzip at level 9 |
|
|
203
|
-
| gzip at level 6, a common setting for compression on the fly |
|
|
204
|
-
| Files as they are | 0.
|
|
201
|
+
| The host sends | The engine's JavaScript | The engine core | Together |
|
|
202
|
+
| --- | --- | --- | --- |
|
|
203
|
+
| Brotli | 217 KB | 627 KB | 844 KB |
|
|
204
|
+
| gzip at level 9 | 404 KB | 818 KB | 1.2 MB |
|
|
205
|
+
| gzip at level 6, a common setting for compression on the fly | 429 KB | 829 KB | 1.2 MB |
|
|
206
|
+
| Files as they are | 2.0 MB | 2.0 MB | 4.0 MB |
|
|
207
|
+
|
|
208
|
+
The figures are for a pipelined page on WebGL2, the largest start:
|
|
209
|
+
|
|
210
|
+
- The JavaScript counts the engine's code for the page and its workers, the WebGL2 renderer, and the largest shader file that a start can load. A WebGPU start downloads about 14 KB less after Brotli, because its shader file is smaller.
|
|
211
|
+
- The core counts the core's WebAssembly file, 602 KB after Brotli, and its JavaScript glue, 25 KB.
|
|
212
|
+
- Neither counts the page's own code or the scene's files.
|
|
213
|
+
- A kilobyte here is 1,024 bytes. The browser's network panel counts 1,000 bytes to the kB, so it shows figures about 2% larger.
|
|
214
|
+
|
|
215
|
+
The core's WebAssembly file is the start's largest file. Many servers compress only text, and send `.wasm` files as they are. To check a host, open the browser's network panel and compare the core's transferred size with its size.
|
|
216
|
+
|
|
217
|
+
Netlify, Cloudflare Pages and Vercel send Brotli to browsers that accept it. GitHub Pages sends gzip only. nginx sends gzip with its own module, and Brotli with the `ngx_brotli` module.
|
|
218
|
+
|
|
219
|
+
With nginx, compress the files once when you deploy them, with `brotli -q 11` on each file in `dist/assets/`, the `.wasm` files included. Then send the compressed files with `brotli_static on;`. nginx's own gzip compresses only the types that `gzip_types` lists, so add `application/wasm` there.
|
|
220
|
+
|
|
221
|
+
The null3D Vite plugin's own servers compress with Brotli too, as [During development](#during-development) says. [A fast start](../guides/start-time.md) gives the other steps that shorten a start.
|
|
205
222
|
|
|
206
|
-
Netlify, Cloudflare Pages and Vercel send Brotli to browsers that accept it. GitHub Pages sends gzip only. nginx sends gzip with its own module, and Brotli with the `ngx_brotli` module. With nginx, compress the files once when you deploy them, with `brotli -q 11` on each file in `dist/assets/`, and send the compressed files with `brotli_static on;`.
|
|
207
223
|
|
|
208
224
|
## Publish the third-party notices
|
|
209
225
|
|
|
210
226
|
The engine and some add-ons ship code from other projects, under their licenses. A production build with the null3D Vite plugin collects every package's notices into `null3d-third-party-notices.txt` beside the page. Keep that file with the build when you publish it, or show its text in your game's credits.
|
|
211
227
|
|
|
212
|
-
[Third-party notices](third-party-notices.md) lists every part and its license.
|
|
228
|
+
[Third-party notices](third-party-notices.md) lists every part and its license.
|
|
213
229
|
|
|
214
230
|
## Caches between visits
|
|
215
231
|
|
|
216
|
-
A repeat visit starts sooner when the browser keeps what the first visit downloaded and made.
|
|
232
|
+
A repeat visit starts sooner when the browser keeps what the first visit downloaded and made. Seven caches do that, and each keeps something else:
|
|
217
233
|
|
|
218
234
|
| Cache | What it keeps | Who sets it up |
|
|
219
235
|
| --- | --- | --- |
|
|
220
236
|
| The HTTP cache | The build's files: the engine, its workers, the shaders and your own files | The host, with the headers below |
|
|
237
|
+
| Chrome's code cache | The machine code that Chrome compiled from the engine core | Chrome, for each `.wasm` file that the host sends as `application/wasm` and that the HTTP cache keeps ([Let Chrome keep the compiled core](#let-chrome-keep-the-compiled-core)) |
|
|
221
238
|
| A service worker's cache | Every file the game needs, so it plays with no network | Your game, as [Offline play](#offline-play) shows |
|
|
222
239
|
| The cache of derived data | Data that the engine and add-ons make from files, such as transcoded KTX2 textures, and data that your sketch makes itself | The engine, with no setup. `assets.cache` gives your sketch its own namespace ([Caching](../api/assets.md#caching)) |
|
|
223
240
|
| The stored preset check | The quality preset that the device held | The engine, in `localStorage` ([Quality presets](../concepts/quality-presets.md#repeat-visits)) |
|
|
241
|
+
| The stored pipeline list | Which GPU pipelines the first frame needed, so the next start builds them while it loads | The engine, in `localStorage` ([Loading screens](../guides/loading-screens.md#repeat-visits)) |
|
|
224
242
|
| The back/forward cache | The whole running page, for the browser's back and forward buttons | The browser ([Content pages](../guides/content-pages.md#second-visits-and-navigation)) |
|
|
225
243
|
|
|
226
|
-
The
|
|
244
|
+
The HTTP cache and a service worker's cache keep files, so a repeat visit downloads less. The code cache and the cache of derived data keep the work done on those files, so a repeat visit skips it. A page whose KTX2 files are all in it never downloads the transcoder. The browser can delete any of them to free space, and the engine then downloads or makes the data again.
|
|
227
245
|
|
|
228
246
|
## Let browsers keep the build files
|
|
229
247
|
|
|
230
248
|
Every engine thread loads its own copy of its script and of the core's loader. When the host lets the browser keep those files, each copy after the first comes from the cache. When the host asks the browser to check each file again, the copies wait for one another, one round trip each. A computer with many cores starts many threads, and on a slow phone connection one round trip can take more than half a second.
|
|
231
249
|
|
|
232
|
-
With worker threads, the
|
|
250
|
+
With worker threads, the sketch worker imports the sketch module while the engine core downloads. The page also downloads the job worker's script then, and the job workers that start later take it from the cache. That saves a round trip only when the host lets the browser keep the file.
|
|
251
|
+
|
|
252
|
+
A sketch that names its files in the `downloads` option of `defineSketch` starts them as soon as its module has loaded ([The download list](../api/sketch.md#the-download-list)). The engine's own files, such as the first frame's shaders, then still find a free connection.
|
|
253
|
+
|
|
254
|
+
<details>
|
|
255
|
+
<summary>Technical details: listed downloads over HTTP/1.1 and HTTP/2</summary>
|
|
256
|
+
|
|
257
|
+
Over HTTP/1.1 a browser opens at most six connections to one server, and each large file holds one until it has arrived. So two listed files download at a time, and four at most while the setup's loads wait for them. Over HTTP/2 every request shares one connection. The listed files ask for low priority there, so a server that follows priorities sends the engine's own files first.
|
|
258
|
+
|
|
259
|
+
</details>
|
|
233
260
|
|
|
234
261
|
Vite names the files in `assets/` with a hash of their content, so a file under a given name never changes. Serve them with a long cache lifetime, and serve the HTML page so that browsers check it each time:
|
|
235
262
|
|
|
@@ -242,6 +269,30 @@ Vite names the files in `assets/` with a hash of their content, so a file under
|
|
|
242
269
|
|
|
243
270
|
That is the `_headers` form for Netlify and Cloudflare Pages. In nginx, add `add_header Cache-Control "public, max-age=31536000, immutable" always;` inside a `location /assets/` block.
|
|
244
271
|
|
|
272
|
+
Send no `Vary: Origin` header with the build's files when they come from the page's own origin. A worker's request for a module carries an `Origin` header that the page's own download of the same file does not. With `Vary: Origin`, the browser then checks the file again, one round trip, instead of taking its copy. A CDN that answers with `Access-Control-Allow-Origin: *` needs no `Vary: Origin` either.
|
|
273
|
+
|
|
274
|
+
### Let Chrome keep the compiled core
|
|
275
|
+
|
|
276
|
+
The engine core is about 2 MB of WebAssembly, and the browser compiles it as it downloads. Chrome then keeps the machine code that it compiled, beside the file in the HTTP cache. A repeat visit that takes the core from the HTTP cache reads that code and skips most of the compile. The engine loads its other `.wasm` files, such as the KTX2 transcoder, the same way. Chrome keeps the code only when the host does both of these:
|
|
277
|
+
|
|
278
|
+
- Send each `.wasm` file with `Content-Type: application/wasm`, with nothing after it. Chrome refuses a parameter such as `; charset=utf-8`. Most hosts send this type already. To check, read the headers with `curl -I` and the address of a `.wasm` file in your build's `assets/` folder.
|
|
279
|
+
- Let the HTTP cache keep the file, as the headers above do. A file served with `no-cache` keeps its code too, when the server answers the browser's check with `304 Not Modified`. A file served with `no-store` keeps nothing.
|
|
280
|
+
|
|
281
|
+
With another type the engine still starts: it compiles the file as it downloads, but Chrome compiles it again on each visit.
|
|
282
|
+
|
|
283
|
+
Chrome writes the code while the page runs, not when the download ends. It first compiles each function quickly, and optimizes the functions that run most. The engine keeps optimizing for its first seconds, so a repeat visit gains only after an earlier visit ran the engine for a while. Chrome 157 and later keep it; Chrome 156 and earlier rarely do.
|
|
284
|
+
|
|
285
|
+
<details>
|
|
286
|
+
<summary>Technical details: when Chrome writes the compiled core</summary>
|
|
287
|
+
|
|
288
|
+
Once Chrome has new optimized code, it waits until no further function has been optimized for two seconds. It then writes that code. With 1 MB of new optimized code, it writes at once.
|
|
289
|
+
|
|
290
|
+
On the engine's test page in Chrome 158, the write came about 6 seconds after the first frame. A repeat visit that read it compiled none of the core again, and its optimizing work fell from about 110 ms to 30 ms. In the engine's startup benchmark at full speed, a repeat visit that read the compiled core finished its first frame at 160 ms. Without it, the first frame took 176 to 180 ms. It compiled 3 of the core's functions again, against 273.
|
|
291
|
+
|
|
292
|
+
Chrome 156 and earlier have a fault in this wait, which can put the write off for up to about half an hour.
|
|
293
|
+
|
|
294
|
+
</details>
|
|
295
|
+
|
|
245
296
|
## Offline play
|
|
246
297
|
|
|
247
298
|
A game can play with no network after its first visit. Its own service worker caches the page and the build's files, and answers the page's requests from that cache. null3D ships no service worker. A production build with the null3D Vite plugin writes a list of the build's files for one, `null3d-files.json`, beside the page:
|
|
@@ -264,13 +315,22 @@ A game can play with no network after its first visit. Its own service worker ca
|
|
|
264
315
|
|
|
265
316
|
| Feature | Files | The game uses it when it calls |
|
|
266
317
|
| --- | --- | --- |
|
|
267
|
-
|
|
|
318
|
+
| Every shader feature in [Shaders that load on first use](../guides/first-use-shaders.md), such as `skinning`, `bloom` or `color_copy` | The feature's shaders, and the code of sprites and lines | The call that the same page names for it |
|
|
268
319
|
| `gltf` | The glTF loader, its worker, and the meshopt and Draco decoders | `assets.loadGltf` |
|
|
269
320
|
| `ktx2` | The KTX2 loader and the Basis Universal transcoder | `assets.loadTexture` or `assets.loadGltf` with a KTX2 texture |
|
|
270
321
|
| `environment` | The readers of environment maps, the built-in environments and the code that prefilters them | `assets.loadEnvironment` or `assets.builtinEnvironment` |
|
|
271
322
|
| `lut` | The readers and makers of color grading tables | `assets.loadLut` or `assets.lutFromData` |
|
|
272
323
|
|
|
273
|
-
|
|
324
|
+
Read `features` in your build's own `null3d-files.json` to see every name that it holds.
|
|
325
|
+
|
|
326
|
+
Each feature's shaders come in a file for each GPU path and each device's settings. The start's files and the skinning shaders are the largest groups, several MB each as the cache keeps them, uncompressed. Your build's output lists each file with its size. With compression, the downloads are about a fifth of that.
|
|
327
|
+
|
|
328
|
+
<details>
|
|
329
|
+
<summary>Technical details: shader files for each device</summary>
|
|
330
|
+
|
|
331
|
+
A device can need another of them during play, for example when bloom turns on HDR color, so a feature's list holds them all. Shaders that need two features, such as a skinned mesh with a hashed material, have files of their own. The list puts such a file under each of its features, so a game that caches either feature has it.
|
|
332
|
+
|
|
333
|
+
</details>
|
|
274
334
|
|
|
275
335
|
This service worker caches the page, the start's files and the features that the game names:
|
|
276
336
|
|
|
@@ -303,17 +363,29 @@ async function update() {
|
|
|
303
363
|
}
|
|
304
364
|
```
|
|
305
365
|
|
|
306
|
-
The page registers it in production builds only,
|
|
366
|
+
The page registers it once the first frame has drawn, and in production builds only. The worker's downloads then leave the connection to the start's own files, and the dev server's pages stay out of the cache:
|
|
307
367
|
|
|
308
368
|
```ts
|
|
309
|
-
|
|
369
|
+
// page.ts, after createEngine
|
|
370
|
+
engine.firstFrame.then(
|
|
371
|
+
() => {
|
|
372
|
+
if (import.meta.env.PROD) void navigator.serviceWorker?.register('./sw.js');
|
|
373
|
+
},
|
|
374
|
+
() => {}, // the engine stopped before its first frame: cache nothing
|
|
375
|
+
);
|
|
310
376
|
```
|
|
311
377
|
|
|
378
|
+
A worker that starts with the page shares the connection with every file of the start, so the first frame comes later. Over HTTP/1.1, a long list holds every connection the browser opens to the host.
|
|
379
|
+
|
|
312
380
|
Put the game's own files that the build does not hold, such as its models in `public/`, in the list that `cache.addAll` takes. On each visit with a network, the worker checks the list. When the build changed, it caches the new build in one step and deletes the old caches. The new build then runs from the next visit.
|
|
313
381
|
|
|
382
|
+
`cache.addAll` keeps no file until every file of its list has arrived. A visitor who leaves before then starts the whole list again on the next visit, and each such visit shares its connection with the start. So keep the list to the files that the game needs. A build of many pages lists the files of every page in `start`.
|
|
383
|
+
|
|
314
384
|
### Keep the page isolated
|
|
315
385
|
|
|
316
|
-
The cache keeps each response with its headers, so the cached page keeps the two isolation headers and the engine starts threaded offline. A service worker that makes a new response for the page, instead of one from `fetch` or the cache, must copy those headers. Without them the page loses its isolation, and the engine starts its single-threaded build with no error.
|
|
386
|
+
The cache keeps each response with its headers, so the cached page keeps the two isolation headers and the engine starts threaded offline. A service worker that makes a new response for the page, instead of one from `fetch` or the cache, must copy those headers. Without them the page loses its isolation, and the engine starts its single-threaded build with no error.
|
|
387
|
+
|
|
388
|
+
A development build of the engine warns in the console when a service worker controls a page that is not isolated. To check a production build, reload the page offline and read `crossOriginIsolated` in the console.
|
|
317
389
|
|
|
318
390
|
### The preload list and the cache
|
|
319
391
|
|
|
@@ -329,6 +401,15 @@ The engine keeps its [cache of derived data](../api/assets.md#the-cache-of-deriv
|
|
|
329
401
|
|
|
330
402
|
The null3D Vite plugin sends both isolation headers on every response from `vite` and `vite preview`. That includes the `.wasm` files and the worker scripts. `vite preview` also lets the browser keep the hashed files in `assets/`, as a well-set host does.
|
|
331
403
|
|
|
404
|
+
Both servers compress what a phone or tablet on the network downloads, with Brotli, or with gzip for a browser that lacks Brotli.
|
|
405
|
+
|
|
406
|
+
<details>
|
|
407
|
+
<summary>Technical details: what the dev server and the preview compress</summary>
|
|
408
|
+
|
|
409
|
+
The dev server compresses its answers to every request from another device, and leaves requests over `localhost` as they are. The preview compresses the build's scripts, WebAssembly, glTF models and other text for every request. After its first answers, it compresses each file again at Brotli's best level while no request waits. Later visits then download the same sizes as from a host that compresses its files ahead of time.
|
|
410
|
+
|
|
411
|
+
</details>
|
|
412
|
+
|
|
332
413
|
Shared memory and WebGPU also need a secure context: HTTPS, or `localhost`. WebGPU, and so the High and Ultra presets, only exist there. A page served over plain HTTP on a network address silently falls back to WebGL2 at Medium. An Android phone connected by USB can reach your computer's `localhost` through `adb reverse tcp:5173 tcp:5173`.
|
|
333
414
|
|
|
334
415
|
To test on a phone or tablet over your local network, serve HTTPS with a local certificate. Make one with [mkcert](https://github.com/FiloSottile/mkcert), for `localhost` and your computer's network name:
|
|
@@ -345,15 +426,23 @@ Keep the `certs` folder out of version control, because it holds a private key.
|
|
|
345
426
|
export default defineConfig({ plugins: [null3d({ https: true, certDir: 'certs' })] });
|
|
346
427
|
```
|
|
347
428
|
|
|
348
|
-
The plugin serves this HTTPS over HTTP/1.1
|
|
429
|
+
The plugin serves this HTTPS over HTTP/1.1, because Safari on an iPad sometimes stops over HTTP/2. For other browsers, the `http2: true` option serves HTTP/2, which sends every request at once.
|
|
349
430
|
|
|
350
|
-
|
|
431
|
+
<details>
|
|
432
|
+
<summary>Technical details: why HTTP/1.1 is the default</summary>
|
|
351
433
|
|
|
352
|
-
|
|
434
|
+
The dev server sends each module as its own file, and every engine thread loads its own copy of each. So a page asks for hundreds of files, and HTTP/1.1 sends six at a time.
|
|
435
|
+
|
|
436
|
+
</details>
|
|
437
|
+
|
|
438
|
+
The device must trust mkcert's root certificate. `mkcert -CAROOT` prints its folder. Copy `rootCA.pem` to the device and install it. On an iPhone or iPad, also turn on full trust in Settings > General > About > Certificate Trust Settings.
|
|
439
|
+
|
|
440
|
+
Install the root certificate on every device that tests a page. A browser without it shows a warning; accepting the warning stops Chrome caching any file from the site. Every reload is then as slow as a first visit, and every timing of a start is wrong.
|
|
353
441
|
|
|
354
|
-
|
|
442
|
+
The dev server also asks the browser to check every module on each load. So time a start only on a production build that a host serves, as [A fast start](../guides/start-time.md#test-a-production-build) explains.
|
|
355
443
|
|
|
356
444
|
## Related pages
|
|
357
445
|
|
|
358
446
|
- [Architecture: threads and the frame](../concepts/architecture.md): what the worker threads do.
|
|
359
447
|
- [GPU tiers and backends](../concepts/backends.md): which browsers get WebGPU.
|
|
448
|
+
- [A fast start](../guides/start-time.md): what a host, a page and a sketch do for a fast start.
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: getting-started/install
|
|
3
3
|
title: Install null3D
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.1"
|
|
6
4
|
summary: "The npm packages; the Vite plugin, which every Vite build needs; package versions always match; the optional `null3d` command."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Install null3D
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
null3D installs from npm like any other library, and you import it in your code as you would import `three`. You need no command-line tool to build or run a null3D sketch. To try the engine in one HTML file with no install, see [Try null3D from a CDN](cdn.md).
|
|
9
|
+
null3D installs from npm and imports like any other library. It builds with Vite and the null3D Vite plugin. You do not need the optional `null3d` command to build or run a sketch. To try the engine in one HTML file with no bundler, see [Try null3D from a CDN](cdn.md). That page builds the engine from its source once.
|
|
14
10
|
|
|
15
11
|
The commands on these pages use [Bun](https://bun.sh) 1.4.3 or newer. Older Bun can drop its link to the browser that `bunx @null3d/cli test` and the tool's other browser commands drive, and the command then waits forever. npm, pnpm and Yarn work too, with their own install and run commands.
|
|
16
12
|
|
|
@@ -25,7 +21,7 @@ bun add -d vite @null3d/vite-plugin
|
|
|
25
21
|
| --- | --- |
|
|
26
22
|
| `@null3d/engine` | The API as JavaScript with TypeScript declarations, the worker entry points, both WebAssembly builds and these docs |
|
|
27
23
|
| `@null3d/vite-plugin` | The build and dev server setup that null3D needs, and the shader compiler |
|
|
28
|
-
| `@null3d/controls` | Orbit, map, fly and first-person camera controls, for sketches that use them |
|
|
24
|
+
| `@null3d/controls` | Orbit, map, fly and first-person camera controls, and gizmos that move, turn and scale objects, for sketches that use them |
|
|
29
25
|
|
|
30
26
|
Add the controls when a sketch uses them:
|
|
31
27
|
|
|
@@ -35,6 +31,8 @@ bun add @null3d/controls
|
|
|
35
31
|
|
|
36
32
|
## Add the Vite plugin
|
|
37
33
|
|
|
34
|
+
null3D requires Vite with this plugin. Other bundlers are not supported or tested. The engine loads its workers, its WebAssembly and its other files in the standard form, `new URL('<file>', import.meta.url)`, which other bundlers read too.
|
|
35
|
+
|
|
38
36
|
```ts
|
|
39
37
|
// vite.config.ts
|
|
40
38
|
import { defineConfig } from 'vite';
|
|
@@ -43,23 +41,44 @@ import null3d from '@null3d/vite-plugin';
|
|
|
43
41
|
export default defineConfig({ plugins: [null3d()] });
|
|
44
42
|
```
|
|
45
43
|
|
|
46
|
-
Every Vite build of a null3D project needs the plugin, for the dev server and for production. The plugin does these jobs
|
|
44
|
+
Every Vite build of a null3D project needs the plugin, for the dev server and for production. The plugin does these jobs:
|
|
47
45
|
|
|
48
46
|
- Sends the two headers that let worker threads share memory, on the dev server and on `vite preview`. [Hosting and cross-origin isolation](hosting.md) explains them.
|
|
49
|
-
-
|
|
50
|
-
- Compiles
|
|
51
|
-
-
|
|
52
|
-
-
|
|
53
|
-
-
|
|
54
|
-
-
|
|
47
|
+
- Compresses what `vite preview` sends with Brotli, `.wasm` included, and what the dev server sends to another device, such as a phone. Its `https` option serves HTTPS on your network, and its `http2` option serves that over HTTP/2 ([During development](hosting.md#during-development)).
|
|
48
|
+
- Compiles your sketch file for the sketch worker, and ships the engine's WebAssembly core with the production build. The build stops with an error if the installed engine lacks its core.
|
|
49
|
+
- Compiles the WGSL in your code, in `.wgsl` files and in strings tagged `/* wgsl */`, for WebGPU and WebGL2. A shader error stops Vite with its file, line and column. [Custom shaders](../guides/custom-shaders.md) explains both forms.
|
|
50
|
+
- Removes the engine's development checks from production builds. Without the plugin, nothing tells the engine's code which build it is in, so it runs as a development build, with every check on.
|
|
51
|
+
- Builds the engine's workers as ES modules, so that they share the shader files. The plugin warns if another setting builds workers in another format.
|
|
52
|
+
- Starts each worker's on-demand imports together with the file that imports them, so a worker does not wait one round trip for each file.
|
|
53
|
+
- Writes the notices of the third-party code that the engine and the add-ons ship beside the page in each production build. [Hosting](hosting.md#publish-the-third-party-notices) says what to do with them.
|
|
55
54
|
- Writes the list of the build's files, `null3d-files.json`, beside the page in each production build. A game's service worker caches the files of that list for offline play, as [Hosting](hosting.md#offline-play) shows.
|
|
56
|
-
-
|
|
55
|
+
- Copies the engine's compiled shader files into a production build, each as a file of its own. Its `shaders.list` option names a list of the permutation words that your pages draw with. The build then copies only their builds ([Build only the shader permutations you draw with](../guides/assets-pipeline.md#build-only-the-shader-permutations-you-draw-with)).
|
|
56
|
+
- Keeps each of the engine's files a file of its own, so a strict Content-Security-Policy does not block them. Vite still turns your own small files into `data:` addresses, which such a policy blocks.
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
<details>
|
|
59
|
+
<summary>Technical details: how the plugin builds workers and files</summary>
|
|
60
|
+
|
|
61
|
+
Each built page that loads the engine gets a small script of its own, which starts the core's download as soon as the page arrives. Beside each `.wgsl` file, the plugin writes a TypeScript declaration that holds the types of the file's uniforms. It compiles on worker threads, so the dev server goes on serving while a shader compiles. On the dev server, a shader that you change reaches the running page without a reload.
|
|
62
|
+
|
|
63
|
+
The engine's code reads the page's address switches in a development build. This also holds for another bundler, and for a page that imports the package's files with no bundler. The [CDN build](cdn.md#production-and-development-entries) has a production entry for such pages. Without the plugin, Vite builds each worker as one classic script that holds every shader file. Each worker is then about 34 MB, and the page downloads them all at its start.
|
|
64
|
+
|
|
65
|
+
The built file of your sketch, and of each add-on's task, names every file that it reaches through other files. So the worker asks for all of them as soon as that file arrives, instead of one round trip for each step of the chain. Your own small files keep Vite's inline setting.
|
|
66
|
+
|
|
67
|
+
</details>
|
|
59
68
|
|
|
60
69
|
The build's files may come from a CDN, with the HTML page on your own origin. [The engine's files on a CDN](hosting.md#the-engines-files-on-a-cdn) gives the headers and the policy that this needs.
|
|
61
70
|
|
|
62
|
-
##
|
|
71
|
+
## Run the sketch
|
|
72
|
+
|
|
73
|
+
Write `page.ts` and `sketch.ts` as [Your first scene](first-scene.md) shows, then start Vite:
|
|
74
|
+
|
|
75
|
+
```sh
|
|
76
|
+
bunx vite
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Open the address that Vite prints. `bunx vite build` writes the production files. Serve them from a host that sends the two headers.
|
|
80
|
+
|
|
81
|
+
## Shader compiles and the cache
|
|
63
82
|
|
|
64
83
|
The plugin compiles the WGSL in your project on each build and each start of the dev server:
|
|
65
84
|
|
|
@@ -67,33 +86,30 @@ The plugin compiles the WGSL in your project on each build and each start of the
|
|
|
67
86
|
- Every template literal that a `/* wgsl */` comment tags, in a script.
|
|
68
87
|
- Every custom material, post effect and tone curve, built into the engine's own templates.
|
|
69
88
|
|
|
70
|
-
A compile can take most of a second, and a project has many. So the plugin keeps each compiled shader in `node_modules/.cache/null3d-shaders`.
|
|
89
|
+
A compile can take most of a second, and a project has many. So the plugin keeps each compiled shader in `node_modules/.cache/null3d-shaders`. A later build of the same shader takes the cached result and starts no compiler. A changed shader, a changed variant or a newer compiler misses and compiles again, so the cache never serves a wrong shader.
|
|
71
90
|
|
|
72
|
-
|
|
91
|
+
<details>
|
|
92
|
+
<summary>Technical details: what the cache keys on</summary>
|
|
73
93
|
|
|
74
|
-
|
|
94
|
+
An entry's key is a hash of the WGSL, the path it came from, the variant spec given to the compiler, and the compiler's version. That version is the engine's version plus the shader build's own stamp, so any engine or compiler upgrade misses every entry.
|
|
75
95
|
|
|
76
|
-
|
|
77
|
-
rm -rf node_modules/.cache/null3d-shaders
|
|
78
|
-
```
|
|
96
|
+
</details>
|
|
79
97
|
|
|
80
|
-
|
|
98
|
+
The first build has no cached results, so it compiles every shader in the project and pauses while it does. The plugin prints a line that names the file it is compiling and the cache folder, so the pause does not look like a hang. Later builds read the cache and compile nothing.
|
|
81
99
|
|
|
82
|
-
|
|
100
|
+
To ignore the cache, set `NULL3D_NO_CACHE=1`, or start the dev server with Vite's `--force`. To clear it, delete the folder:
|
|
83
101
|
|
|
84
102
|
```sh
|
|
85
|
-
|
|
103
|
+
rm -rf node_modules/.cache/null3d-shaders
|
|
86
104
|
```
|
|
87
105
|
|
|
88
|
-
Open the address that Vite prints. `bunx vite build` writes the production files. Serve them from a host that sends the two headers.
|
|
89
|
-
|
|
90
106
|
## Keep versions in step
|
|
91
107
|
|
|
92
108
|
All `@null3d/*` packages share one version number, because the WebAssembly core and the TypeScript API must match. Install the same version of each. The docs in `node_modules/@null3d/engine/docs/` always match the installed engine.
|
|
93
109
|
|
|
94
110
|
## The `null3d` command
|
|
95
111
|
|
|
96
|
-
The `null3d` command, in the `@null3d/cli` package, is optional. It does jobs that a bundler does not do
|
|
112
|
+
The `null3d` command, in the `@null3d/cli` package, is optional. It does jobs that a bundler does not do, such as image tests and screenshots in a headless browser and benchmarks of a production build. It also connects a coding agent to the live scene. Install it when you need one of them, and run it as `bunx @null3d/cli` followed by the command:
|
|
97
113
|
|
|
98
114
|
```sh
|
|
99
115
|
bun add -d @null3d/cli
|