@null3d/engine 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/wasm/single/null3d.js +10 -8
- package/dist/wasm/single/null3d_bg.wasm +0 -0
- package/dist/wasm/threaded/null3d.js +10 -8
- package/dist/wasm/threaded/null3d_bg.wasm +0 -0
- package/docs/api/animation.md +96 -24
- package/docs/api/assets.md +99 -29
- package/docs/api/cameras.md +38 -7
- package/docs/api/controls.md +47 -23
- package/docs/api/debug.md +105 -35
- package/docs/api/engine.md +108 -32
- package/docs/api/feature-draws.md +21 -15
- package/docs/api/feature-effects.md +8 -8
- package/docs/api/feature-instances.md +68 -17
- package/docs/api/features.md +68 -37
- package/docs/api/geometry.md +83 -14
- package/docs/api/grass.md +55 -13
- package/docs/api/impostors.md +92 -50
- package/docs/api/input.md +22 -9
- package/docs/api/lights.md +67 -16
- package/docs/api/lines.md +38 -13
- package/docs/api/materials.md +187 -59
- package/docs/api/math.md +6 -6
- package/docs/api/objects.md +40 -15
- package/docs/api/page.md +58 -7
- package/docs/api/particles.md +36 -11
- package/docs/api/points.md +18 -8
- package/docs/api/post.md +57 -23
- package/docs/api/quality.md +36 -16
- package/docs/api/raycast.md +57 -24
- package/docs/api/reference/animation.md +1 -2
- package/docs/api/reference/assets.md +7 -4
- package/docs/api/reference/cameras.md +3 -2
- package/docs/api/reference/controls.md +59 -2
- package/docs/api/reference/debug.md +58 -6
- package/docs/api/reference/engine.md +39 -10
- package/docs/api/reference/feature-draws.md +3 -4
- package/docs/api/reference/feature-effects.md +2 -3
- package/docs/api/reference/feature-instances.md +5 -4
- package/docs/api/reference/features.md +7 -4
- package/docs/api/reference/geometry.md +132 -21
- package/docs/api/reference/grass.md +62 -2
- package/docs/api/reference/impostors.md +120 -16
- package/docs/api/reference/input.md +1 -2
- package/docs/api/reference/lights.md +4 -3
- package/docs/api/reference/lines.md +3 -4
- package/docs/api/reference/materials.md +7 -6
- package/docs/api/reference/math.md +13 -2
- package/docs/api/reference/objects.md +2 -3
- package/docs/api/reference/particles.md +31 -6
- package/docs/api/reference/points.md +2 -3
- package/docs/api/reference/post.md +4 -3
- package/docs/api/reference/quality.md +1 -2
- package/docs/api/reference/raycast.md +1 -2
- package/docs/api/reference/render.md +4 -3
- package/docs/api/reference/scene.md +24 -5
- package/docs/api/reference/sketch.md +11 -11
- package/docs/api/reference/sound.md +33 -2
- package/docs/api/reference/splats.md +42 -3
- package/docs/api/reference/sprites.md +2 -3
- package/docs/api/reference/tasks.md +16 -3
- package/docs/api/reference/terrain.md +26 -5
- package/docs/api/reference/textures.md +1 -2
- package/docs/api/reference/three-compat.md +18 -7
- package/docs/api/reference/time.md +1 -2
- package/docs/api/reference/ui.md +10 -7
- package/docs/api/reference/vertex-draws.md +2 -3
- package/docs/api/reference/water.md +78 -5
- package/docs/api/reference/wind.md +15 -2
- package/docs/api/render.md +67 -25
- package/docs/api/scene.md +129 -36
- package/docs/api/sketch.md +45 -19
- package/docs/api/sound.md +48 -12
- package/docs/api/splats.md +42 -15
- package/docs/api/sprites.md +8 -6
- package/docs/api/tasks.md +31 -22
- package/docs/api/terrain.md +44 -12
- package/docs/api/textures.md +61 -12
- package/docs/api/three-compat.md +15 -7
- package/docs/api/time.md +3 -5
- package/docs/api/ui.md +18 -10
- package/docs/api/vertex-draws.md +13 -12
- package/docs/api/water.md +111 -67
- package/docs/api/wind.md +61 -15
- package/docs/cli/null3d.md +90 -15
- package/docs/concepts/architecture.md +69 -23
- package/docs/concepts/assets.md +57 -16
- package/docs/concepts/backends.md +65 -25
- package/docs/concepts/color-management.md +42 -13
- package/docs/concepts/culling.md +68 -47
- package/docs/concepts/handles.md +14 -5
- package/docs/concepts/instances.md +72 -23
- package/docs/concepts/large-worlds.md +17 -7
- package/docs/concepts/lighting.md +117 -44
- package/docs/concepts/lod.md +128 -33
- package/docs/concepts/materials.md +43 -12
- package/docs/concepts/particle-buffer.md +48 -35
- package/docs/concepts/post-processing.md +77 -14
- package/docs/concepts/quality-preset-tables.md +3 -2
- package/docs/concepts/quality-presets.md +122 -39
- package/docs/concepts/render-graph.md +56 -21
- package/docs/concepts/render-layers.md +9 -5
- package/docs/concepts/shadows.md +96 -25
- package/docs/concepts/static-dynamic.md +22 -7
- package/docs/cookbook/index.md +163 -119
- package/docs/data/threejs-mapping.json +301 -340
- package/docs/errors/E1101.md +23 -5
- package/docs/errors/E1102.md +11 -3
- package/docs/errors/E1103.md +11 -3
- package/docs/errors/E1104.md +11 -3
- package/docs/errors/E1105.md +13 -5
- package/docs/errors/E1106.md +11 -3
- package/docs/errors/E1107.md +15 -5
- package/docs/errors/E1108.md +11 -3
- package/docs/errors/E1109.md +32 -6
- package/docs/errors/E1110.md +23 -5
- package/docs/errors/E1111.md +11 -3
- package/docs/errors/E1112.md +11 -3
- package/docs/errors/E1203.md +12 -4
- package/docs/errors/E1204.md +11 -3
- package/docs/errors/E1205.md +11 -3
- package/docs/errors/E1206.md +28 -6
- package/docs/errors/E1207.md +11 -3
- package/docs/errors/E1208.md +12 -3
- package/docs/errors/E1209.md +11 -3
- package/docs/errors/E1213.md +27 -5
- package/docs/errors/E1214.md +11 -3
- package/docs/errors/E1215.md +31 -6
- package/docs/errors/E1216.md +31 -6
- package/docs/errors/E1217.md +29 -6
- package/docs/errors/E1218.md +22 -6
- package/docs/errors/E1219.md +11 -3
- package/docs/errors/E1220.md +24 -5
- package/docs/errors/E1221.md +24 -5
- package/docs/errors/E1222.md +11 -3
- package/docs/errors/E1223.md +39 -6
- package/docs/errors/E1224.md +11 -3
- package/docs/errors/E1225.md +11 -3
- package/docs/errors/E1301.md +11 -3
- package/docs/errors/E1302.md +11 -3
- package/docs/errors/E1303.md +11 -3
- package/docs/errors/E1304.md +11 -3
- package/docs/errors/E1305.md +13 -3
- package/docs/errors/E1306.md +11 -3
- package/docs/errors/E1307.md +23 -6
- package/docs/errors/E1401.md +11 -3
- package/docs/errors/E1402.md +13 -5
- package/docs/errors/E1403.md +11 -3
- package/docs/errors/E1404.md +13 -3
- package/docs/errors/E1405.md +15 -4
- package/docs/errors/E1406.md +31 -5
- package/docs/errors/E1407.md +11 -3
- package/docs/errors/E1408.md +11 -3
- package/docs/errors/E1409.md +11 -3
- package/docs/errors/E1410.md +13 -5
- package/docs/errors/E1411.md +11 -3
- package/docs/errors/E1412.md +29 -6
- package/docs/errors/E1413.md +11 -3
- package/docs/errors/E1414.md +11 -3
- package/docs/errors/E1415.md +11 -3
- package/docs/errors/E1416.md +27 -6
- package/docs/errors/E1417.md +11 -3
- package/docs/errors/E1418.md +12 -3
- package/docs/errors/E1419.md +13 -5
- package/docs/errors/E1420.md +11 -3
- package/docs/errors/E1421.md +11 -3
- package/docs/errors/E1422.md +12 -3
- package/docs/errors/E1423.md +12 -3
- package/docs/errors/E1424.md +24 -5
- package/docs/errors/E1425.md +11 -3
- package/docs/errors/E1426.md +11 -3
- package/docs/errors/E1430.md +11 -3
- package/docs/errors/E1431.md +11 -3
- package/docs/errors/E1432.md +11 -3
- package/docs/errors/E1433.md +11 -3
- package/docs/errors/E1434.md +15 -6
- package/docs/errors/E1435.md +11 -3
- package/docs/errors/E1436.md +11 -3
- package/docs/errors/E1437.md +14 -6
- package/docs/errors/E1501.md +41 -6
- package/docs/errors/E1502.md +13 -3
- package/docs/errors/E1503.md +11 -3
- package/docs/errors/E1504.md +11 -3
- package/docs/errors/E1505.md +23 -5
- package/docs/errors/E1506.md +11 -3
- package/docs/errors/index.md +52 -29
- package/docs/getting-started/cdn.md +15 -9
- package/docs/getting-started/first-scene.md +20 -12
- package/docs/getting-started/hosting.md +111 -63
- package/docs/getting-started/install.md +39 -24
- package/docs/getting-started/network-use.md +31 -21
- package/docs/getting-started/project-structure.md +20 -8
- package/docs/getting-started/third-party-notices.md +6 -10
- package/docs/guides/accessibility.md +4 -4
- package/docs/guides/add-ons.md +83 -13
- package/docs/guides/agents.md +2 -6
- package/docs/guides/assets-pipeline.md +248 -72
- package/docs/guides/audio.md +17 -15
- package/docs/guides/baked-light-data.md +44 -23
- package/docs/guides/car-paint.md +37 -31
- package/docs/guides/content-pages.md +53 -29
- package/docs/guides/custom-passes.md +59 -17
- package/docs/guides/custom-shaders.md +54 -37
- package/docs/guides/debugging.md +31 -41
- package/docs/guides/deploying.md +6 -27
- package/docs/guides/deterministic-simulation.md +23 -16
- package/docs/guides/first-use-shaders.md +83 -45
- package/docs/guides/lens-kit.md +29 -26
- package/docs/guides/loading-screens.md +70 -30
- package/docs/guides/multiple-views.md +22 -11
- package/docs/guides/performance.md +188 -37
- package/docs/guides/phones.md +71 -19
- package/docs/guides/physics.md +6 -10
- package/docs/guides/screens.md +41 -29
- package/docs/guides/start-time.md +120 -85
- package/docs/guides/testing.md +137 -98
- package/docs/guides/ui-overlays.md +17 -12
- package/docs/guides/video-textures.md +14 -13
- package/docs/images/api/animation/character.webp +0 -0
- package/docs/images/api/animation/look-at-ring.webp +0 -0
- package/docs/images/api/animation/morph-tulips.webp +0 -0
- package/docs/images/api/animation/skeleton-lines.webp +0 -0
- package/docs/images/api/controls/gizmo-handles.webp +0 -0
- package/docs/images/api/controls/walk-and-fly.webp +0 -0
- package/docs/images/api/debug/debug-shapes.webp +0 -0
- package/docs/images/api/debug/levels-view.webp +0 -0
- package/docs/images/api/engine/transparent-canvas.webp +0 -0
- package/docs/images/api/feature-draws/feature-draw-clouds.webp +0 -0
- package/docs/images/api/feature-instances/compute-instances.webp +0 -0
- package/docs/images/api/feature-instances/instances-shadow.webp +0 -0
- package/docs/images/api/geometry/extra-shapes.webp +0 -0
- package/docs/images/api/geometry/generators.webp +0 -0
- package/docs/images/api/geometry/mesh-arrays.webp +0 -0
- package/docs/images/api/geometry/vertex-updates.webp +0 -0
- package/docs/images/api/grass/grass-grove.webp +0 -0
- package/docs/images/api/grass/grass-presets.webp +0 -0
- package/docs/images/api/grass/grass-shadow.webp +0 -0
- package/docs/images/api/impostors/impostor-handover.webp +0 -0
- package/docs/images/api/impostors/impostor-shadow.webp +0 -0
- package/docs/images/api/impostors/impostors-forest.webp +0 -0
- package/docs/images/api/lights/spot-cookies.webp +0 -0
- package/docs/images/api/lines/lines-lit.webp +0 -0
- package/docs/images/api/lines/lines-widths.webp +0 -0
- package/docs/images/api/materials/coat-and-sheen.webp +0 -0
- package/docs/images/api/materials/decals.webp +0 -0
- package/docs/images/api/materials/iridescence-and-anisotropy.webp +0 -0
- package/docs/images/api/materials/relief.webp +0 -0
- package/docs/images/api/materials/shader-inputs.webp +0 -0
- package/docs/images/api/materials/standard-grid.webp +0 -0
- package/docs/images/api/materials/subsurface.webp +0 -0
- package/docs/images/api/materials/translucency.webp +0 -0
- package/docs/images/api/objects/objects-turntable.webp +0 -0
- package/docs/images/api/particles/campfire.webp +0 -0
- package/docs/images/api/points/galaxy.webp +0 -0
- package/docs/images/api/reference/textures/texture-wrap.webp +0 -0
- package/docs/images/api/render/fullscreen-glow.webp +0 -0
- package/docs/images/api/render/reflection-mirror.webp +0 -0
- package/docs/images/api/render/security-camera.webp +0 -0
- package/docs/images/api/scene/aurora-sky-layer.webp +0 -0
- package/docs/images/api/sound/sound-demo.webp +0 -0
- package/docs/images/api/splats/splats-demo.webp +0 -0
- package/docs/images/api/sprites/sprites-lines.webp +0 -0
- package/docs/images/api/terrain/terrain-demo.webp +0 -0
- package/docs/images/api/textures/canvas-screen.webp +0 -0
- package/docs/images/api/textures/mipmaps.webp +0 -0
- package/docs/images/api/vertex-draws/rain.webp +0 -0
- package/docs/images/api/water/ocean.webp +0 -0
- package/docs/images/api/water/water-demo.webp +0 -0
- package/docs/images/api/water/water-rain.webp +0 -0
- package/docs/images/api/water/waterfall.webp +0 -0
- package/docs/images/concepts/assets/gltf-model.webp +0 -0
- package/docs/images/concepts/color-management/tone-mapped.webp +0 -0
- package/docs/images/concepts/culling/far-from-origin.webp +0 -0
- package/docs/images/concepts/instances/instances.webp +0 -0
- package/docs/images/concepts/instances/per-row-colors.webp +0 -0
- package/docs/images/concepts/large-worlds/large-world.webp +0 -0
- package/docs/images/concepts/lighting/area-lights.webp +0 -0
- package/docs/images/concepts/lighting/atmosphere.webp +0 -0
- package/docs/images/concepts/lighting/environment.webp +0 -0
- package/docs/images/concepts/lighting/light-shafts.webp +0 -0
- package/docs/images/concepts/lighting/reflection-probes.webp +0 -0
- package/docs/images/concepts/lod/forest.webp +0 -0
- package/docs/images/concepts/materials/weighted-transparency.webp +0 -0
- package/docs/images/concepts/post-processing/auto-exposure.webp +0 -0
- package/docs/images/concepts/post-processing/bounce-light.webp +0 -0
- package/docs/images/concepts/post-processing/depth-of-field.webp +0 -0
- package/docs/images/concepts/post-processing/post-effects-alley.webp +0 -0
- package/docs/images/concepts/post-processing/sharpen.webp +0 -0
- package/docs/images/concepts/post-processing/ssr-wet-street.webp +0 -0
- package/docs/images/concepts/render-layers/layers-cottages.webp +0 -0
- package/docs/images/concepts/shadows/hero-shadow.webp +0 -0
- package/docs/images/cookbook/index/picking.webp +0 -0
- package/docs/images/cookbook/index/time-of-day.webp +0 -0
- package/docs/images/errors/E1431/area-lights-no-tables.webp +0 -0
- package/docs/images/guides/custom-passes/reflection-water.webp +0 -0
- package/docs/images/guides/deterministic-simulation/replay-demo.webp +0 -0
- package/docs/images/guides/multiple-views/split-screen.webp +0 -0
- package/docs/images/guides/performance/overdraw-view.webp +0 -0
- package/docs/images/guides/testing/hold-mode-frame.webp +0 -0
- package/docs/images/index/showcase-island.webp +0 -0
- package/docs/images/porting/threejs-shaders/dissolve.webp +0 -0
- package/docs/images/shaders/builtins/builtins.webp +0 -0
- package/docs/images/shaders/surface-functions/custom-surface.webp +0 -0
- package/docs/images/shaders/surface-functions/vertex-offset.webp +0 -0
- package/docs/images/shots.json +2231 -0
- package/docs/index.md +14 -23
- package/docs/moves.json +1 -0
- package/docs/nav.json +300 -0
- package/docs/pages.md +230 -212
- package/docs/porting/react-three-fiber.md +2 -6
- package/docs/porting/threejs-loop-and-threads.md +1 -5
- package/docs/porting/threejs-mapping.md +1248 -234
- package/docs/porting/threejs-materials.md +10 -5
- package/docs/porting/threejs-overview.md +26 -6
- package/docs/porting/threejs-postprocessing.md +2 -6
- package/docs/porting/threejs-shaders.md +16 -14
- package/docs/porting/threejs-unsupported.md +6 -6
- package/docs/porting/verification.md +0 -4
- package/docs/shaders/builtins.md +15 -4
- package/docs/shaders/library.md +9 -6
- package/docs/shaders/surface-functions.md +51 -16
- package/docs/shaders/wgsl-rules.md +12 -5
- package/lib/debug/debug.d.ts +2 -2
- package/lib/debug/draw.d.ts +2 -2
- package/lib/debug/draw.js +8 -4
- package/lib/debug/overlay-look.d.ts +6 -0
- package/lib/debug/overlay-look.js +29 -7
- package/lib/debug/overlay.js +15 -11
- package/lib/debug/stats-options.d.ts +13 -0
- package/lib/debug/stats-panel.d.ts +21 -6
- package/lib/debug/stats-panel.js +80 -13
- package/lib/errors/codes.d.ts +17 -3
- package/lib/errors/codes.js +111 -105
- package/lib/errors/fixes.js +18 -18
- package/lib/gpu/variants.d.ts +8 -2
- package/lib/gpu/variants.js +39 -7
- package/lib/gpu/webgl2/programs.js +1 -1
- package/lib/gpu/webgpu/pipelines.js +13 -13
- package/lib/index.d.ts +1 -1
- package/lib/page/capabilities.d.ts +1 -1
- package/lib/page/engine.d.ts +14 -5
- package/lib/page/engine.js +18 -2
- package/lib/page/label-loop.js +9 -4
- package/lib/page/stats-switch.js +2 -0
- package/lib/page/switches.d.ts +6 -4
- package/lib/page/switches.js +20 -4
- package/lib/scene/baked-light.d.ts +2 -2
- package/lib/scene/fake-call-values.js +2 -2
- package/lib/scene/frame-cameras.d.ts +16 -4
- package/lib/scene/frame-cameras.js +28 -10
- package/lib/scene/gltf.d.ts +1 -1
- package/lib/scene/level-rule.d.ts +6 -5
- package/lib/scene/level-rule.js +2 -2
- package/lib/scene/particles.d.ts +7 -3
- package/lib/scene/particles.js +3 -1
- package/lib/scene/post.d.ts +3 -2
- package/lib/scene/resources.d.ts +15 -9
- package/lib/scene/scene.d.ts +18 -2
- package/lib/scene/scene.js +47 -5
- package/lib/scene/time-of-day.d.ts +10 -5
- package/lib/scene/time-of-day.js +11 -7
- package/lib/shader-artifact.json +1 -1
- package/lib/shared/labels.d.ts +5 -2
- package/lib/shared/labels.js +5 -2
- package/lib/shared/permutation-words.d.ts +2 -0
- package/lib/shared/permutation-words.js +8 -0
- package/lib/shared/recording.d.ts +13 -5
- package/lib/shared/recording.js +31 -10
- package/lib/shared/sketch-data.d.ts +9 -0
- package/lib/shared/sketch-data.js +57 -0
- package/lib/shared/version.d.ts +1 -1
- package/lib/shared/version.js +1 -1
- package/lib/sketch/define-sketch.d.ts +16 -7
- package/lib/sketch/define-sketch.js +2 -1
- package/lib/sketch/runner.d.ts +4 -0
- package/lib/sketch/runner.js +5 -0
- package/lib/sketch/ui.js +4 -2
- package/lib/stats.d.ts +1 -0
- package/lib/workers/protocol.d.ts +10 -0
- package/lib/workers/render-worker.js +4 -1
- package/lib/workers/sketch-worker.js +4 -1
- package/package.json +1 -1
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: getting-started/cdn
|
|
3
3
|
title: Try null3D from a CDN
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.2"
|
|
6
4
|
summary: "The CDN build; its production and development entries; one HTML file with no bundler; import maps; the policy and CORS headers; both thread modes; what needs a build step."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Try null3D from a CDN
|
|
10
8
|
|
|
11
|
-
> Roadmap step 0.2, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
|
|
12
|
-
|
|
13
9
|
A page can draw a null3D scene with no build step: one HTML file that imports the engine from a CDN. This suits a quick trial, a documentation example or a CodePen-style page. A project that grows past a trial uses Vite and the plugin, as [Install null3D](install.md) shows.
|
|
14
10
|
|
|
15
11
|
```mermaid
|
|
@@ -21,9 +17,14 @@ flowchart LR
|
|
|
21
17
|
|
|
22
18
|
## Make the CDN build
|
|
23
19
|
|
|
24
|
-
The build holds the engine's JavaScript, its shaders, both WebAssembly builds and its vendor files, with each foundation add-on under `addons/<name>/`. The npm package leaves the built shaders out, because they are large and a Vite build supplies them. A page with no build step therefore needs this folder.
|
|
20
|
+
The CDN build comes from the engine's source, not from npm. It holds the engine's JavaScript, its shaders, both WebAssembly builds and its vendor files, with each foundation add-on under `addons/<name>/`. The npm package leaves the built shaders out, because they are large and a Vite build supplies them. A page with no build step therefore needs this folder.
|
|
21
|
+
|
|
22
|
+
Install Bun and the Rust toolchain through [rustup](https://rustup.rs), then run these commands in a clone of the [repository](https://github.com/null3d-engine/null3d#development):
|
|
25
23
|
|
|
26
24
|
```sh
|
|
25
|
+
git clone https://github.com/null3d-engine/null3d.git
|
|
26
|
+
cd null3d
|
|
27
|
+
bun install
|
|
27
28
|
bun run build
|
|
28
29
|
bun run build:cdn
|
|
29
30
|
```
|
|
@@ -59,10 +60,15 @@ The production entry behaves like a production build from Vite and the plugin. T
|
|
|
59
60
|
|
|
60
61
|
Use one entry for the whole page: the page's import, the sketch's import, the import map and each add-on. An add-on's development entry is `addons/<name>/lib-dev/index.js`. A page that mixes the two loads two copies of the engine's code.
|
|
61
62
|
|
|
63
|
+
<details>
|
|
64
|
+
<summary>Technical details: telling the entries apart, and a benchmark build</summary>
|
|
65
|
+
|
|
62
66
|
To see which entry a page runs, read the address that it imports. On a page with the [isolation headers](#both-thread-modes), the `?threads=off` switch also tells them apart. With it, `engine.mode.build` is `'single'` from the development entry and `'threaded'` from the production entry.
|
|
63
67
|
|
|
64
68
|
A benchmark page may time a production build and still set switches, such as `?gpu=webgl2`. It needs a third form. `bun run build:cdn --url-switches` makes the production entry read the address switches. Use that build for benchmark pages only, and never ship it, because a link can then change how the page runs.
|
|
65
69
|
|
|
70
|
+
</details>
|
|
71
|
+
|
|
66
72
|
## One HTML file
|
|
67
73
|
|
|
68
74
|
Save this page, change the CDN address to your own, and serve it from a web server. A browser refuses the modules and workers of a page opened from a file on disk.
|
|
@@ -169,9 +175,9 @@ Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' b
|
|
|
169
175
|
```
|
|
170
176
|
|
|
171
177
|
- `blob:` in `script-src`: the page makes the sketch module at a `blob:` address.
|
|
172
|
-
- `
|
|
173
|
-
|
|
174
|
-
-
|
|
178
|
+
- `'unsafe-inline'` in `script-src` and `style-src`: the example page holds its script and style inline.
|
|
179
|
+
|
|
180
|
+
The `blob:` in `worker-src`, and the CDN in `script-src`, `worker-src` and `connect-src`, are there for the reasons that [Hosting](hosting.md#the-engines-files-on-a-cdn) gives, with the error that each missing item causes.
|
|
175
181
|
|
|
176
182
|
Missing items give [E1422](../errors/E1422.md), [E1423](../errors/E1423.md) or [E1418](../errors/E1418.md), as [Hosting](hosting.md#the-engines-files-on-a-cdn) lists them.
|
|
177
183
|
|
|
@@ -225,7 +231,7 @@ export default defineSketch((ctx) => {
|
|
|
225
231
|
|
|
226
232
|
An import map can name an add-on for the page's own modules, but a worker reads no import map. Name the add-on by its full address in the sketch, as the example does.
|
|
227
233
|
|
|
228
|
-
The build also writes `null3d-third-party-notices.txt`, with the license notices of the engine and of each add-on that ships other projects' code. Keep that file with the folder when you publish it, or show its text in your credits.
|
|
234
|
+
The build also writes `null3d-third-party-notices.txt`, with the license notices of the engine and of each add-on that ships other projects' code. Keep that file with the folder when you publish it, or show its text in your credits ([Third-party notices](third-party-notices.md)).
|
|
229
235
|
|
|
230
236
|
## Related pages
|
|
231
237
|
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: getting-started/first-scene
|
|
3
3
|
title: Your first scene
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.1"
|
|
6
4
|
summary: "page.ts with createEngine; sketch.ts with defineSketch; camera, light, mesh; running it with Vite."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Your first scene
|
|
10
8
|
|
|
11
|
-
> Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
|
|
12
|
-
|
|
13
9
|
```mermaid
|
|
14
10
|
flowchart LR
|
|
15
11
|
html["index.html<br/>the canvas"] --> page["page.ts<br/>main thread: createEngine"]
|
|
@@ -19,7 +15,7 @@ flowchart LR
|
|
|
19
15
|
|
|
20
16
|
A null3D project has two modules. The page module, `page.ts`, runs on the page's main thread: it creates the engine and keeps the HTML. The sketch module, `sketch.ts`, builds the 3D scene and updates it every frame, in a worker of its own. This page builds a turning box with a camera and two lights.
|
|
21
17
|
|
|
22
|
-
Put the four files below in one folder. The project needs the `@null3d/engine` package, and Vite with the `@null3d/vite-plugin` package: [Install null3D](install.md) lists them.
|
|
18
|
+
Put the four files below in one folder. The project needs the `@null3d/engine` package, and Vite with the `@null3d/vite-plugin` package: [Install null3D](install.md) lists them. `bunx @null3d/cli create` writes this same project for you, with the two modules in `src/`. See [Project structure](project-structure.md).
|
|
23
19
|
|
|
24
20
|
## The HTML page
|
|
25
21
|
|
|
@@ -47,19 +43,26 @@ CSS sets the canvas's size. The engine draws at that size times the screen's pix
|
|
|
47
43
|
|
|
48
44
|
```ts
|
|
49
45
|
// page.ts
|
|
50
|
-
import { createEngine } from '@null3d/engine';
|
|
46
|
+
import { createEngine, EngineError } from '@null3d/engine';
|
|
51
47
|
|
|
52
48
|
const canvas = document.querySelector('canvas')!;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
try {
|
|
50
|
+
const engine = await createEngine({
|
|
51
|
+
canvas,
|
|
52
|
+
sketch: new URL('./sketch.ts', import.meta.url),
|
|
53
|
+
});
|
|
54
|
+
await engine.firstFrame; // the first frame is on the screen
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (!(error instanceof EngineError)) throw error;
|
|
57
|
+
const note = document.createElement('p');
|
|
58
|
+
note.textContent = 'This browser cannot show the 3D scene.';
|
|
59
|
+
canvas.replaceWith(note);
|
|
60
|
+
}
|
|
58
61
|
```
|
|
59
62
|
|
|
60
63
|
`createEngine` picks the GPU path, starts the engine's threads and runs the sketch's setup. It resolves once the setup has run. `engine.firstFrame` resolves once the GPU has finished the first frame, which is the moment to remove a loading screen.
|
|
61
64
|
|
|
62
|
-
`createEngine` rejects with an `EngineError` when the browser cannot run the engine. Examples are Safari before 18 ([E1306](../errors/E1306.md)), a browser without WebAssembly SIMD ([E1303](../errors/E1303.md)), and one without a usable GPU path ([E1301](../errors/E1301.md)).
|
|
65
|
+
`createEngine` rejects with an `EngineError` when the browser cannot run the engine. Examples are Safari before 18 ([E1306](../errors/E1306.md)), a browser without WebAssembly SIMD ([E1303](../errors/E1303.md)), and one without a usable GPU path ([E1301](../errors/E1301.md)). The `catch` above shows the page without the scene. [Debugging](../guides/debugging.md#where-problems-appear) lists every error the start can give, and `engine.onFailure` for failures after the start.
|
|
63
66
|
|
|
64
67
|
## The sketch module
|
|
65
68
|
|
|
@@ -123,6 +126,11 @@ Open the address that Vite prints. `bunx vite build` writes the production files
|
|
|
123
126
|
|
|
124
127
|
## Next steps
|
|
125
128
|
|
|
129
|
+
- [Show a model](../cookbook/index.md#a-loading-screen-for-models): load a glTF file and an environment, and wait for the first frame.
|
|
130
|
+
- [Orbit controls](../api/controls.md): let the user turn and zoom the camera.
|
|
131
|
+
- [Lighting and environment](../concepts/lighting.md): light types, environment maps and fog.
|
|
132
|
+
- [Project structure](project-structure.md): start from the `product` template, which has orbit controls and soft studio light.
|
|
133
|
+
- glTF model example: a full sketch that shows a model on a turntable.
|
|
126
134
|
- [Objects and transforms](../api/objects.md): move, turn, parent and hide objects.
|
|
127
135
|
- [Static and dynamic objects](../concepts/static-dynamic.md): when to pass `dynamic: true`.
|
|
128
136
|
- [Instances and batching](../concepts/instances.md): draw thousands of copies of one mesh.
|
|
@@ -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,7 +81,7 @@ 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'`.
|
|
@@ -55,7 +90,7 @@ Content-Security-Policy: default-src 'self'; script-src 'self' 'wasm-unsafe-eval
|
|
|
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
|
|
|
@@ -114,41 +149,6 @@ The single-threaded build is fully supported. Use it where you cannot set header
|
|
|
114
149
|
|
|
115
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.
|
|
116
151
|
|
|
117
|
-
## Headers on common hosts
|
|
118
|
-
|
|
119
|
-
Netlify and Cloudflare Pages read a `_headers` file at the root of the site:
|
|
120
|
-
|
|
121
|
-
```text
|
|
122
|
-
/*
|
|
123
|
-
Cross-Origin-Opener-Policy: same-origin
|
|
124
|
-
Cross-Origin-Embedder-Policy: require-corp
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
Vercel reads `vercel.json`:
|
|
128
|
-
|
|
129
|
-
```json
|
|
130
|
-
{
|
|
131
|
-
"headers": [
|
|
132
|
-
{
|
|
133
|
-
"source": "/(.*)",
|
|
134
|
-
"headers": [
|
|
135
|
-
{ "key": "Cross-Origin-Opener-Policy", "value": "same-origin" },
|
|
136
|
-
{ "key": "Cross-Origin-Embedder-Policy", "value": "require-corp" }
|
|
137
|
-
]
|
|
138
|
-
}
|
|
139
|
-
]
|
|
140
|
-
}
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
nginx:
|
|
144
|
-
|
|
145
|
-
```nginx
|
|
146
|
-
add_header Cross-Origin-Opener-Policy same-origin always;
|
|
147
|
-
add_header Cross-Origin-Embedder-Policy require-corp always;
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
GitHub Pages cannot send custom headers, so a null3D page there runs single-threaded.
|
|
151
|
-
|
|
152
152
|
## Desktop apps with Electron
|
|
153
153
|
|
|
154
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:
|
|
@@ -196,18 +196,27 @@ To check the app, open its developer tools and read `crossOriginIsolated` in the
|
|
|
196
196
|
|
|
197
197
|
## Send the files with Brotli
|
|
198
198
|
|
|
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.
|
|
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:
|
|
200
200
|
|
|
201
|
-
| The host sends | The engine's JavaScript
|
|
202
|
-
| --- | --- |
|
|
203
|
-
| Brotli |
|
|
204
|
-
| gzip at level 9 |
|
|
205
|
-
| gzip at level 6, a common setting for compression on the fly |
|
|
206
|
-
| 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
207
|
|
|
208
|
-
The
|
|
208
|
+
The figures are for a pipelined page on WebGL2, the largest start:
|
|
209
209
|
|
|
210
|
-
|
|
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.
|
|
211
220
|
|
|
212
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.
|
|
213
222
|
|
|
@@ -216,7 +225,7 @@ The null3D Vite plugin's own servers compress with Brotli too, as [During develo
|
|
|
216
225
|
|
|
217
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.
|
|
218
227
|
|
|
219
|
-
[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.
|
|
220
229
|
|
|
221
230
|
## Caches between visits
|
|
222
231
|
|
|
@@ -240,7 +249,14 @@ Every engine thread loads its own copy of its script and of the core's loader. W
|
|
|
240
249
|
|
|
241
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.
|
|
242
251
|
|
|
243
|
-
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)).
|
|
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>
|
|
244
260
|
|
|
245
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:
|
|
246
262
|
|
|
@@ -264,7 +280,18 @@ The engine core is about 2 MB of WebAssembly, and the browser compiles it as it
|
|
|
264
280
|
|
|
265
281
|
With another type the engine still starts: it compiles the file as it downloads, but Chrome compiles it again on each visit.
|
|
266
282
|
|
|
267
|
-
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.
|
|
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>
|
|
268
295
|
|
|
269
296
|
## Offline play
|
|
270
297
|
|
|
@@ -288,13 +315,22 @@ A game can play with no network after its first visit. Its own service worker ca
|
|
|
288
315
|
|
|
289
316
|
| Feature | Files | The game uses it when it calls |
|
|
290
317
|
| --- | --- | --- |
|
|
291
|
-
|
|
|
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 |
|
|
292
319
|
| `gltf` | The glTF loader, its worker, and the meshopt and Draco decoders | `assets.loadGltf` |
|
|
293
320
|
| `ktx2` | The KTX2 loader and the Basis Universal transcoder | `assets.loadTexture` or `assets.loadGltf` with a KTX2 texture |
|
|
294
321
|
| `environment` | The readers of environment maps, the built-in environments and the code that prefilters them | `assets.loadEnvironment` or `assets.builtinEnvironment` |
|
|
295
322
|
| `lut` | The readers and makers of color grading tables | `assets.loadLut` or `assets.lutFromData` |
|
|
296
323
|
|
|
297
|
-
|
|
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>
|
|
298
334
|
|
|
299
335
|
This service worker caches the page, the start's files and the features that the game names:
|
|
300
336
|
|
|
@@ -347,7 +383,9 @@ Put the game's own files that the build does not hold, such as its models in `pu
|
|
|
347
383
|
|
|
348
384
|
### Keep the page isolated
|
|
349
385
|
|
|
350
|
-
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.
|
|
351
389
|
|
|
352
390
|
### The preload list and the cache
|
|
353
391
|
|
|
@@ -363,7 +401,14 @@ The engine keeps its [cache of derived data](../api/assets.md#the-cache-of-deriv
|
|
|
363
401
|
|
|
364
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.
|
|
365
403
|
|
|
366
|
-
Both servers compress what a phone or tablet on the network downloads, with Brotli, or with gzip for a browser that lacks Brotli.
|
|
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>
|
|
367
412
|
|
|
368
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`.
|
|
369
414
|
|
|
@@ -381,17 +426,20 @@ Keep the `certs` folder out of version control, because it holds a private key.
|
|
|
381
426
|
export default defineConfig({ plugins: [null3d({ https: true, certDir: 'certs' })] });
|
|
382
427
|
```
|
|
383
428
|
|
|
384
|
-
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.
|
|
385
430
|
|
|
386
|
-
|
|
431
|
+
<details>
|
|
432
|
+
<summary>Technical details: why HTTP/1.1 is the default</summary>
|
|
387
433
|
|
|
388
|
-
|
|
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.
|
|
389
435
|
|
|
390
|
-
|
|
436
|
+
</details>
|
|
391
437
|
|
|
392
|
-
|
|
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.
|
|
393
441
|
|
|
394
|
-
|
|
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.
|
|
395
443
|
|
|
396
444
|
## Related pages
|
|
397
445
|
|
|
@@ -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 and imports like any other library. 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
|
|
|
@@ -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';
|
|
@@ -47,20 +45,40 @@ Every Vite build of a null3D project needs the plugin, for the dev server and fo
|
|
|
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
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)).
|
|
50
|
-
- 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.
|
|
51
|
-
- 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.
|
|
52
|
-
-
|
|
53
|
-
- Builds the engine's workers as ES modules, so that they share the shader files.
|
|
54
|
-
-
|
|
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.
|
|
55
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.
|
|
56
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.
|
|
57
|
-
-
|
|
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.
|
|
58
57
|
|
|
59
|
-
|
|
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>
|
|
60
68
|
|
|
61
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.
|
|
62
70
|
|
|
63
|
-
##
|
|
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
|
|
64
82
|
|
|
65
83
|
The plugin compiles the WGSL in your project on each build and each start of the dev server:
|
|
66
84
|
|
|
@@ -68,26 +86,23 @@ The plugin compiles the WGSL in your project on each build and each start of the
|
|
|
68
86
|
- Every template literal that a `/* wgsl */` comment tags, in a script.
|
|
69
87
|
- Every custom material, post effect and tone curve, built into the engine's own templates.
|
|
70
88
|
|
|
71
|
-
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.
|
|
72
90
|
|
|
73
|
-
|
|
91
|
+
<details>
|
|
92
|
+
<summary>Technical details: what the cache keys on</summary>
|
|
74
93
|
|
|
75
|
-
|
|
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.
|
|
76
95
|
|
|
77
|
-
|
|
78
|
-
rm -rf node_modules/.cache/null3d-shaders
|
|
79
|
-
```
|
|
96
|
+
</details>
|
|
80
97
|
|
|
81
|
-
|
|
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.
|
|
82
99
|
|
|
83
|
-
|
|
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:
|
|
84
101
|
|
|
85
102
|
```sh
|
|
86
|
-
|
|
103
|
+
rm -rf node_modules/.cache/null3d-shaders
|
|
87
104
|
```
|
|
88
105
|
|
|
89
|
-
Open the address that Vite prints. `bunx vite build` writes the production files. Serve them from a host that sends the two headers.
|
|
90
|
-
|
|
91
106
|
## Keep versions in step
|
|
92
107
|
|
|
93
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.
|