@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
package/docs/guides/phones.md
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: guides/phones
|
|
3
3
|
title: Phones and tablets
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.1"
|
|
6
4
|
summary: "Pixel-ratio caps; memory budgets; heat; testing on real devices."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Phones and tablets
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Phones have small GPUs, sharp screens and little memory, and they slow down when they heat up. The quality presets set how much work the engine does on each device. This guide says what the engine does on a phone or a tablet, and how to test your sketch on one.
|
|
9
|
+
A null3D sketch runs on current phones and tablets with no changes, on WebGPU or on WebGL2. Phones have small GPUs, sharp screens and little memory, and they slow down when they heat up. The quality presets set how much work the engine does on each device. This guide says what the engine does on a phone or a tablet, and how to test your sketch on one.
|
|
14
10
|
|
|
15
11
|
## The preset on a phone
|
|
16
12
|
|
|
@@ -26,7 +22,7 @@ export default defineSketch(({ quality }) => {
|
|
|
26
22
|
});
|
|
27
23
|
```
|
|
28
24
|
|
|
29
|
-
Do not force a heavier preset on phones. When a player picks one in a menu, pass it to `createEngine` with the `preset` option.
|
|
25
|
+
Do not force a heavier preset on phones. When a player picks one in a menu, switch to it with `quality.setPreset` in the sketch ([Quality API](../api/quality.md#switching-presets)). The GPU path still caps it, and `quality.highest` names the cap. To start at a choice that the page remembers, pass it to `createEngine` with the `preset` option. The [instancing demo](https://github.com/null3d-engine/null3d/tree/main/examples/instances) draws a 101 x 101 grid of columns on Low, and 317 x 317 above it.
|
|
30
26
|
|
|
31
27
|
Low, the phone's preset, leaves out the costliest work:
|
|
32
28
|
|
|
@@ -54,14 +50,27 @@ The engine caps the ratio at the preset's value, which is lowest on the Low pres
|
|
|
54
50
|
|
|
55
51
|
When frames take too long, the engine draws the scene at a lower render scale: a part of the canvas's width and height. It then scales the image up to the canvas. On the Low preset, the scale can drop to 0.5, a quarter of the pixels. It rises again when the frames have time to spare. [Quality presets](../concepts/quality-presets.md#dynamic-resolution) explains when the scale moves.
|
|
56
52
|
|
|
57
|
-
Text and fine lines in the scene get softer at a lower scale.
|
|
53
|
+
Text and fine lines in the scene get softer at a lower scale. On Low, the final pass still smooths edges with FXAA at the render size. It then scales the image up to the canvas with an edge-aware upscaler.
|
|
54
|
+
|
|
55
|
+
Draw your interface in HTML over the canvas, where it stays sharp. To keep the whole canvas on a device, set `quality.set({ minRenderScale: 1 })`. The savings of the pixel ratio cap and the render scale multiply. At a ratio of 1.5 and a scale of 0.5, the phone above fills 0.19 million pixels.
|
|
58
56
|
|
|
59
57
|
## Shadows
|
|
60
58
|
|
|
61
|
-
A directional light's shadows draw the shadow casters once for each cascade, into a map whose texels the GPU fills each frame. The preset sets the cascade count and the map size of each light whose options name neither. Low draws fewer cascades than Medium, with smaller maps, and blends fewer texels at each shadow's edge.
|
|
59
|
+
A directional light's shadows draw the shadow casters once for each cascade, into a map whose texels the GPU fills each frame. The preset sets the cascade count and the map size of each light whose options name neither. Low draws fewer cascades than Medium, with smaller maps, and blends fewer texels at each shadow's edge.
|
|
60
|
+
|
|
61
|
+
So leave `cascades` and `mapSize` out of the light's `shadow` options, and phones draw lighter shadows by themselves. [Shadows](../concepts/shadows.md#settings) lists the options, and [Quality presets](../concepts/quality-presets.md#the-settings-of-each-preset) each preset's values.
|
|
62
|
+
|
|
63
|
+
<details>
|
|
64
|
+
<summary>Technical details: how a shadow map stores depth</summary>
|
|
65
|
+
|
|
66
|
+
The shadow map stores each depth in 16 bits, which takes half the memory of 32-bit depths.
|
|
67
|
+
|
|
68
|
+
</details>
|
|
62
69
|
|
|
63
70
|
## Memory
|
|
64
71
|
|
|
72
|
+
### How much memory a tab gets
|
|
73
|
+
|
|
65
74
|
A phone closes a tab that uses too much memory, with no warning. The engine's tab memory test grew one kind of GPU memory in a tab, in steps of 32 MiB, until the tab died:
|
|
66
75
|
|
|
67
76
|
| Device and browser | GPU textures | GPU buffers |
|
|
@@ -70,25 +79,65 @@ A phone closes a tab that uses too much memory, with no warning. The engine's ta
|
|
|
70
79
|
| 11-inch iPad Pro, Safari, WebGL2 | 2,528 MiB | 2,496 MiB |
|
|
71
80
|
| Galaxy S24+, Chrome, WebGL2 | 7,296 MiB | 7,616 MiB |
|
|
72
81
|
|
|
73
|
-
No allocation failed first, and no error came. A scene holds its textures, buffers, render targets and WebAssembly memory at once, and a device with less memory gives a tab less.
|
|
82
|
+
No allocation failed first, and no error came. A scene holds its textures, buffers, render targets and WebAssembly memory at once, and a device with less memory gives a tab less.
|
|
83
|
+
|
|
84
|
+
So the quality preset's texture memory budget keeps textures under 256 MiB on Low and 512 MiB on Medium. On phones and tablets, no preset gives textures more than 1,008 MiB. The iPad's WebGPU path can stop answering at 512 MiB of GPU buffers, though not in every run. Keep a scene's GPU buffers under half the point in the table.
|
|
85
|
+
|
|
86
|
+
### The engine's WebAssembly memory
|
|
74
87
|
|
|
75
88
|
On a page with worker threads, the engine's threads share one WebAssembly memory, whose maximum the preset sets. The browser reserves address space for the whole maximum, and every other engine and WebAssembly module on the page shares what is left. [Page API: createEngine](../api/engine.md#memory) says when to ask for more.
|
|
76
89
|
|
|
90
|
+
### Use less memory
|
|
91
|
+
|
|
77
92
|
To use less memory, share meshes and materials, draw many copies with instance batches, and create objects during setup. `engine.measure` reports the WebAssembly memory in use. [Performance: memory peak](performance.md#memory-peak) shows how to read a scene's distance from its limit.
|
|
78
93
|
|
|
79
|
-
|
|
94
|
+
### Textures
|
|
95
|
+
|
|
96
|
+
Textures take GPU memory too. A texture of 1024 x 1024 texels takes about 5.3 MiB with its mip levels. When the textures pass their budget, the engine drops the largest mip levels of textures from files, and loads them again once room returns. The sketch reads the memory and the dropped levels in `quality.textureMemory`, and [Quality presets](../concepts/quality-presets.md#texture-memory) explains the order.
|
|
97
|
+
|
|
98
|
+
A texture that the sketch makes from an image or from data keeps its levels, so free one that the scene no longer needs with `texture.destroy()`. The engine keeps no copy of an image once its upload is done. [Textures](../api/textures.md#gpu-memory) gives the sizes.
|
|
99
|
+
|
|
100
|
+
Load large textures from KTX2 files. `bunx @null3d/cli assets optimize` encodes them ([The asset pipeline](assets-pipeline.md)). Phones and tablets have the ASTC and ETC2 formats, so a KTX2 texture stays compressed on the GPU. The same 1024 x 1024 texture then takes about 1.3 MiB. [Textures](../api/textures.md#ktx2-files) covers KTX2 files.
|
|
101
|
+
|
|
102
|
+
<details>
|
|
103
|
+
<summary>Technical details: encoding KTX2 textures by hand</summary>
|
|
104
|
+
|
|
105
|
+
The same texture takes 0.7 MiB in ETC2 without alpha. Encode the mip levels into the file, as `basisu -mipmap` does, because the GPU cannot make them for compressed texels. Use UASTC for normal maps and detailed color maps, and ETC1S where the download must stay small. `texture.format` tells which format the device got.
|
|
106
|
+
|
|
107
|
+
</details>
|
|
80
108
|
|
|
81
|
-
|
|
109
|
+
### A second engine on the page
|
|
82
110
|
|
|
83
111
|
A page that starts a second engine, for example in a single-page app, waits for the first engine's `destroy()` promise. The page keeps the first engine's shared memory for about 30 seconds, and the second engine takes it. So the browser need not give new memory. When the browser refuses memory at the start, the engine tries again for about 45 seconds. Then it fails with [E1109](../errors/E1109.md). `onProgress` reports `memory-wait` after 10 seconds, so the page can tell the user ([Engine](../api/engine.md#the-running-engine)).
|
|
84
112
|
|
|
85
|
-
|
|
113
|
+
### Large scenes
|
|
114
|
+
|
|
115
|
+
The scene's object tables start small and double as the scene grows. On a Galaxy S25 or a Pixel 9, a growth from 16,383 to 32,767 objects took 2.4 to 5.3 ms. For a large scene, set `createEngine`'s `expectedObjects` option, so the tables never grow during play ([Objects during play](performance.md#objects-during-play)).
|
|
116
|
+
|
|
117
|
+
### After a crash
|
|
86
118
|
|
|
87
119
|
When the tab crashes during a start, the next start of the sketch runs one preset lower. A second crash in a row starts it at Low. [Quality presets](../concepts/quality-presets.md#starts-that-crashed-the-tab) explains the note that the engine keeps for this. The page reads the count in `engine.mode.crashedStarts`.
|
|
88
120
|
|
|
121
|
+
### A page in the back-forward cache
|
|
122
|
+
|
|
123
|
+
On phones and tablets, the engine gives back its GPU device while the browser keeps the page in its back-forward cache. It starts a new one when the page comes back ([Page API](../api/engine.md#the-running-engine)).
|
|
124
|
+
|
|
89
125
|
## Heat
|
|
90
126
|
|
|
91
|
-
A phone lowers its clock speeds when it heats up, often after a few minutes of play. Leave room for it: aim for about 70% of the frame budget, and test runs of 10 minutes.
|
|
127
|
+
A phone lowers its clock speeds when it heats up, often after a few minutes of play. Leave room for it: aim for about 70% of the frame budget, and test runs of 10 minutes. In the engine's benchmarks, a warm Galaxy S24+ took about 70% longer per frame than a cool one. The [Performance guide](performance.md#phones-and-tablets) also shows how to measure the frame.
|
|
128
|
+
|
|
129
|
+
When frames still take too long, the frame-budget governor lowers the quality step by step. The `quality.onChange` handlers run after each shadow step, so the sketch can lighten its own work too ([Quality presets](../concepts/quality-presets.md#the-frame-budget-governor)).
|
|
130
|
+
|
|
131
|
+
Tablets heat up too. A warm iPad can drop from 60 to about 45 frames per second at Medium, and Low holds 60 ([Quality presets](../concepts/quality-presets.md#how-the-engine-chooses-a-preset)).
|
|
132
|
+
|
|
133
|
+
<details>
|
|
134
|
+
<summary>Technical details: what the governor lowers, and measured heat on an iPad</summary>
|
|
135
|
+
|
|
136
|
+
The governor lowers a sketch's budgets and the render scale first. It then lowers the level of detail threshold, the far shadow cascades, the shadow filter, bloom's base and ambient occlusion's size. After those, it lowers screen-space reflections, contact shadows, far characters' update interval and the volumetric fog.
|
|
137
|
+
|
|
138
|
+
The warm 11-inch iPad Pro took about 17 ms of GPU time per S4 frame at Medium, against about 12.6 ms a minute earlier. It ran at about 45 frames per second. At Low, it held 60 frames per second after 5 minutes of warm-up.
|
|
139
|
+
|
|
140
|
+
</details>
|
|
92
141
|
|
|
93
142
|
## Power
|
|
94
143
|
|
|
@@ -96,12 +145,25 @@ A view that holds still stops drawing after about a second. The engine first ble
|
|
|
96
145
|
|
|
97
146
|
## Touch input
|
|
98
147
|
|
|
99
|
-
The engine reads touches as it reads the mouse: the first finger presses `Mouse0`, and `input.touches` lists every finger on the canvas. A
|
|
148
|
+
The engine reads touches as it reads the mouse: the first finger presses `Mouse0`, and `input.touches` lists every finger on the canvas. A tap on an object calls its `click` handler, as a mouse click does ([Pointer events on objects](../api/input.md#pointer-events-on-objects)). The [picking demo](https://github.com/null3d-engine/null3d/tree/main/examples/picking) shows such a handler.
|
|
149
|
+
|
|
150
|
+
A canvas that takes touch gestures needs `touch-action: none` in its CSS. Without it, the browser scrolls or zooms the page, and it cancels the touch. [Input](../api/input.md#touches) explains touches and pinches.
|
|
151
|
+
|
|
152
|
+
```css
|
|
153
|
+
canvas { touch-action: none; }
|
|
154
|
+
```
|
|
100
155
|
|
|
101
156
|
## Networks and repeat visits
|
|
102
157
|
|
|
158
|
+
On a phone, a start is mostly downloads, the round trips between them, and the GPU's pipeline builds. A host that compresses every file, `.wasm` included, and lets the browser keep the build's files saves seconds. So does a sketch that starts its downloads together and draws before its large models arrive. A first view with few pipelines saves more: 55 pipelines took 10.9 seconds to build on a Galaxy Tab A9 Plus. [A fast start](start-time.md) gives each step, with measured times on real phones. The [Island showcase sketch](https://github.com/null3d-engine/null3d/tree/main/examples/showcase/island) starts its downloads together and draws before its large models arrive.
|
|
159
|
+
|
|
103
160
|
Phones often lose their network. A game that must play offline caches the engine's files and its own in a service worker, as [Hosting](../getting-started/hosting.md#offline-play) shows. The engine keeps each transcoded KTX2 texture in its [cache of derived data](../api/assets.md#the-cache-of-derived-data), so a repeat visit skips the transcoder. On phones that saves less time than on a tablet, because other start work takes most of a phone's start.
|
|
104
161
|
|
|
162
|
+
## When the GPU's driver refuses a shader
|
|
163
|
+
|
|
164
|
+
A phone's GPU driver can refuse to build one pipeline, such as a custom material's, though the shader is valid. The engine then builds that pipeline once more, alone. When the driver refuses it again, the engine leaves that pipeline's objects out of the frame and draws on. It reports [E1307](../errors/E1307.md) once, which does not stop the engine. A validation error, and a refused pipeline of a full-screen pass, still stop drawing with [E1404](../errors/E1404.md) ([Debugging](debugging.md)).
|
|
165
|
+
|
|
166
|
+
On a Galaxy Tab A9 Plus, the driver refused the island demo's far tree cards, and the island drew on without them ([A fast start](start-time.md#where-the-time-goes)).
|
|
105
167
|
## Browsers on iPhone and iPad
|
|
106
168
|
|
|
107
169
|
Every browser on iPhone and iPad runs Safari's WebKit engine. null3D needs Safari 18 or later there, and `createEngine` fails with [E1306](../errors/E1306.md) on an older version. [GPU tiers and backends](../concepts/backends.md#minimum-browsers) says why.
|
|
@@ -112,7 +174,8 @@ Check every rendering mode and the whole camera path, with repeats, as [Testing
|
|
|
112
174
|
|
|
113
175
|
Desktop browsers that emulate a phone show neither its GPU nor its heat, so test on the phones and tablets that your audience uses.
|
|
114
176
|
|
|
115
|
-
- Serve the page over HTTPS, or reach it as `localhost` over USB. A secure origin is what makes WebGPU, and so the High and Ultra presets, available. On a network address over plain HTTP, the engine silently falls back to WebGL2 at Medium. [Hosting and cross-origin isolation](../getting-started/hosting.md#during-development) shows both.
|
|
177
|
+
- Serve the page over HTTPS, or reach it as `localhost` over USB. A secure origin is what makes WebGPU, and so the High and Ultra presets, available. On a network address over plain HTTP, the engine silently falls back to WebGL2, which caps the preset at Medium. [Hosting and cross-origin isolation](../getting-started/hosting.md#during-development) shows both.
|
|
178
|
+
- Install the root of the page's certificate on the device. Chrome keeps no file in its cache from a site whose certificate it accepted after a warning. Every load is then as slow as a first visit.
|
|
116
179
|
- Check the preset that the engine chose in `engine.mode.preset`. The capability report in `engine.report` holds the facts that it chose from: `coarsePointer`, `screenMinEdge` and `deviceMemoryGB`.
|
|
117
180
|
- Add `?preset=low`, `?preset=medium`, `?preset=high` or `?preset=ultra` to the page's address to test each preset on one device. The GPU path still caps the preset.
|
|
118
181
|
- Add `?gpu=webgl2` to test the WebGL2 path, which many phones use.
|
package/docs/guides/physics.md
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: guides/physics
|
|
3
3
|
title: Using a physics library
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.1"
|
|
6
4
|
summary: "Running Rapier or cannon-es in the sketch worker; copying transforms."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Using a physics library
|
|
10
8
|
|
|
11
|
-
> Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
|
|
12
|
-
|
|
13
9
|
```mermaid
|
|
14
10
|
flowchart LR
|
|
15
11
|
fixed["onFixedUpdate(step)<br/>0 or more times"] --> step["The physics world<br/>takes one step"]
|
|
@@ -26,10 +22,10 @@ Physics in the sketch only moves what the player sees. A game whose server repla
|
|
|
26
22
|
|
|
27
23
|
Two libraries work well in a sketch:
|
|
28
24
|
|
|
29
|
-
| Library | Package | What it is |
|
|
30
|
-
| --- | --- | --- |
|
|
31
|
-
| Rapier | `@dimforge/rapier3d-compat` | A Rust engine compiled to WebAssembly. It is fast with many bodies. |
|
|
32
|
-
| cannon-es | `cannon-es` | A JavaScript engine. It is small and simple to use. |
|
|
25
|
+
| Library | Package | What it is | Download size |
|
|
26
|
+
| --- | --- | --- | --- |
|
|
27
|
+
| Rapier | `@dimforge/rapier3d-compat` | A Rust engine compiled to WebAssembly. It is fast with many bodies. | About 1.2 MB after Brotli compression |
|
|
28
|
+
| cannon-es | `cannon-es` | A JavaScript engine. It is small and simple to use. | About 20 KB for the example on this page |
|
|
33
29
|
|
|
34
30
|
Install one with Bun, as any other package:
|
|
35
31
|
|
|
@@ -37,6 +33,8 @@ Install one with Bun, as any other package:
|
|
|
37
33
|
bun add @dimforge/rapier3d-compat@^0.20.0
|
|
38
34
|
```
|
|
39
35
|
|
|
36
|
+
The `-compat` package holds Rapier's WebAssembly inside its JavaScript, so it needs no extra Vite setup. That is why it is large.
|
|
37
|
+
|
|
40
38
|
## Example: crates that fall on a floor
|
|
41
39
|
|
|
42
40
|
This sketch drops 300 crates onto a floor with Rapier. Each crate is a Rapier body and a row of one instance batch.
|
|
@@ -112,8 +110,6 @@ export default defineSketch(async ({ scene, geometry, materials }) => {
|
|
|
112
110
|
- The rows are views of engine memory, so the copy costs no call to the engine per crate. A dynamic batch recomputes and uploads every row in each frame. [Instances and batching](../concepts/instances.md) explains the rows.
|
|
113
111
|
- The floor never moves, so its mesh is static. A static mesh costs nothing in a frame where it does not change.
|
|
114
112
|
|
|
115
|
-
The `-compat` package holds Rapier's WebAssembly inside its JavaScript, so it needs no extra Vite setup. That makes it large: it adds about 1.2 MB after Brotli compression to the sketch's download. With cannon-es, the example on this page adds about 20 KB.
|
|
116
|
-
|
|
117
113
|
## Step the world at a fixed rate
|
|
118
114
|
|
|
119
115
|
A physics world stays stable when every step has the same length. A frame's step changes with the screen and with slow frames, so the examples step the world in `onFixedUpdate`. The engine calls it 60 times per second of sketch time, before `onUpdate`. The examples copy the transforms in `onUpdate`, once per frame, after the frame's steps.
|
|
@@ -192,7 +188,7 @@ ball.addEventListener('collide', (event: { contact: CANNON.ContactEquation }) =>
|
|
|
192
188
|
|
|
193
189
|
On the page, `onSketchMessage` receives each `bounce` message with its position and speed.
|
|
194
190
|
|
|
195
|
-
[Messages between sketch and page](../api/page.md) covers messages, and [
|
|
191
|
+
[Messages between sketch and page](../api/page.md) covers messages, and [Sound in a scene](audio.md) plays a sound at the bounce's place.
|
|
196
192
|
|
|
197
193
|
## Related pages
|
|
198
194
|
|
package/docs/guides/screens.md
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: guides/screens
|
|
3
3
|
title: In-world screens
|
|
4
|
-
|
|
5
|
-
since: "0.3"
|
|
6
|
-
summary: "Displays painted on an OffscreenCanvas in the sketch, with a refresh rate for each screen, uploads of only the changed rectangles, an LCD look that changes with distance, a boot glitch, and clicks mapped back to the canvas's coordinates."
|
|
4
|
+
summary: "An example add-on you copy: displays painted on an OffscreenCanvas in the sketch, with a refresh rate for each screen, uploads of only the changed rectangles, an LCD look that changes with distance, a boot glitch, and clicks mapped back to the canvas's coordinates."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# In-world screens
|
|
10
8
|
|
|
11
|
-
> Roadmap step 0.3, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
|
|
12
|
-
|
|
13
9
|
A screen is a plane in the world whose material samples an `OffscreenCanvas`. The sketch draws on
|
|
14
10
|
the canvas with the 2D context, and the engine uploads only the rectangles that changed. Each screen
|
|
15
11
|
keeps its own refresh rate, so a slow readout costs less than a fast one.
|
|
@@ -24,46 +20,64 @@ flowchart LR
|
|
|
24
20
|
```
|
|
25
21
|
|
|
26
22
|
The screens add-on in the repository, in the `examples/addons/screens` folder, holds the pattern.
|
|
27
|
-
It is not an npm package. Copy the folder into your project and import its entry point.
|
|
23
|
+
It is not an npm package. Copy the folder into your project and import its entry point. The [screens painted on an OffscreenCanvas](https://github.com/null3d-engine/null3d/tree/main/examples/canvas-screen) demo shows wall panels and a console, each at its own refresh rate.
|
|
28
24
|
|
|
29
25
|
## Make a screen
|
|
30
26
|
|
|
31
27
|
```ts
|
|
28
|
+
import { defineSketch } from '@null3d/engine';
|
|
32
29
|
import { createScreen } from './addons/screens';
|
|
33
30
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
context
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
export default defineSketch((ctx) => {
|
|
32
|
+
const screen = createScreen(ctx, {
|
|
33
|
+
width: 512,
|
|
34
|
+
height: 256,
|
|
35
|
+
refreshHz: 12,
|
|
36
|
+
size: [2.4, 1.2],
|
|
37
|
+
draw: (context) => {
|
|
38
|
+
context.fillStyle = '#061019';
|
|
39
|
+
context.fillRect(0, 0, 512, 256);
|
|
40
|
+
context.fillStyle = '#9fe8ff';
|
|
41
|
+
context.font = 'bold 48px sans-serif';
|
|
42
|
+
context.fillText('REACTOR 62.0', 24, 90);
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
screen.mesh.setPosition(0, 1.4, -3);
|
|
46
|
+
|
|
47
|
+
return { onUpdate() { /* below */ } };
|
|
46
48
|
});
|
|
47
|
-
screen.mesh.setPosition(0, 1.4, -3);
|
|
48
49
|
```
|
|
49
50
|
|
|
50
|
-
`draw` runs in the setup, before the first upload, so a held frame
|
|
51
|
-
changes its reading each frame repaints only the part that changed:
|
|
51
|
+
`draw` runs in the setup, before the first upload, so every frame shows the picture, a held frame too. `screen.paint(draw, changed)` draws and uploads the rectangle that changed. Without a rectangle it uploads the whole canvas.
|
|
52
52
|
|
|
53
53
|
```ts
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
});
|
|
54
|
+
screen.paint((context) => {
|
|
55
|
+
context.fillStyle = '#061019';
|
|
56
|
+
context.fillRect(24, 150, 464, 90);
|
|
57
|
+
context.fillStyle = '#9fe8ff';
|
|
58
|
+
context.fillText(`REACTOR ${reading.toFixed(1)}`, 24, 200);
|
|
59
|
+
}, { x: 24, y: 150, width: 464, height: 90 });
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
A program that changes its reading each frame can draw straight on `screen.context`:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
return {
|
|
66
|
+
onUpdate() {
|
|
67
|
+
const context = screen.context;
|
|
68
|
+
context.fillStyle = '#061019';
|
|
69
|
+
context.fillRect(24, 150, 464, 90);
|
|
70
|
+
context.fillStyle = '#9fe8ff';
|
|
71
|
+
context.fillText(`REACTOR ${reading.toFixed(1)}`, 24, 200);
|
|
72
|
+
screen.mark({ x: 24, y: 150, width: 464, height: 90 });
|
|
73
|
+
screen.flush(); // sends a change that the rate held back
|
|
74
|
+
},
|
|
75
|
+
};
|
|
59
76
|
```
|
|
60
77
|
|
|
61
|
-
`screen.
|
|
62
|
-
uploads the whole canvas. `screen.mark(rect)` adds a rectangle without drawing, and `screen.flush()`
|
|
63
|
-
uploads the marked rectangles as one change.
|
|
78
|
+
`screen.mark(rect)` adds a rectangle without drawing, and `screen.flush()` uploads the marked rectangles as one change.
|
|
64
79
|
|
|
65
|
-
A refresh that the rate or an upload in flight holds back returns false, and the change waits for
|
|
66
|
-
the next call. Call `flush` from the frame's update so it goes out.
|
|
80
|
+
A refresh that the rate or an upload in flight holds back returns false, and the change waits for the next call. Call `flush` from the frame's update so it goes out.
|
|
67
81
|
|
|
68
82
|
## The LCD look
|
|
69
83
|
|
|
@@ -91,7 +105,7 @@ takes no values.
|
|
|
91
105
|
## Clicks on a screen
|
|
92
106
|
|
|
93
107
|
A pointer hit on a mesh carries its texture coordinates. `screen.pointOf(event)` turns them into a
|
|
94
|
-
canvas point. `screen.texelOf(event)` gives the whole texel under the point.
|
|
108
|
+
canvas point. `screen.texelOf(event)` gives the whole texel under the point. The [picking demo](https://github.com/null3d-engine/null3d/tree/main/examples/picking) shows an object's click handler and the point that the ray hit.
|
|
95
109
|
|
|
96
110
|
```ts
|
|
97
111
|
screen.onClick((point) => {
|
|
@@ -114,7 +128,7 @@ that path's figures and its upload budget.
|
|
|
114
128
|
|
|
115
129
|
- The shader draws on both GPU paths. It uses `fwidth`, which both paths have.
|
|
116
130
|
- A screen's mesh needs texture coordinates, as `geometry.plane` gives.
|
|
117
|
-
-
|
|
131
|
+
- In hold mode, the held frame shows the canvas as of its last read. A change that the refresh rate held back in the last updates does not show. Paint the picture that a test checks through `draw` or in the setup.
|
|
118
132
|
- A large canvas at a high refresh rate costs its rectangle's bytes each read. Give a screen only
|
|
119
133
|
the rate that its content needs.
|
|
120
134
|
|