@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/api/assets.md
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/assets
|
|
3
3
|
title: Assets
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.1"
|
|
6
4
|
summary: "loadGltf, registerGltfExtension, loadTexture, loadImageBitmap, loadLut, lutFromData, loadEnvironment, builtinEnvironment, skyEnvironment, loadCubemap, loadLightProbeGrid, loadLightMap, lightProbeGridFile, loadJson, loadBinary, preload, onProgress, cache."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Assets
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
The `assets` object of the sketch context downloads files and decodes them. Every call returns a promise, and its download and decode run outside the sketch's frames, so a frame never waits for them. The browser decodes images off the main thread.
|
|
9
|
+
The `assets` object of the sketch context downloads files and decodes them. The calls that load and make data return promises. Their downloads and decodes run outside the sketch's frames, so a frame never waits for them. The browser decodes images off the main thread.
|
|
14
10
|
|
|
15
11
|
```ts
|
|
16
12
|
import { defineSketch } from '@null3d/engine';
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
14
|
+
const BRICKS = '/tex/bricks.png';
|
|
15
|
+
const NORMALS = '/tex/bricks-normal.png';
|
|
16
|
+
const LEVEL = '/levels/one.json';
|
|
17
|
+
|
|
18
|
+
export default defineSketch(
|
|
19
|
+
async ({ assets, page }) => {
|
|
20
|
+
assets.onProgress((loaded, total) => page.post('loading', Math.min(1, loaded / Math.max(total, loaded))));
|
|
21
|
+
const [bricks, normals, level] = await Promise.all([
|
|
22
|
+
assets.loadTexture(BRICKS, { wrap: 'repeat' }),
|
|
23
|
+
assets.loadTexture(NORMALS, { colorSpace: 'linear', wrap: 'repeat' }),
|
|
24
|
+
assets.loadJson<{ enemies: number }>(LEVEL),
|
|
25
|
+
]);
|
|
26
|
+
},
|
|
27
|
+
// The three files start to download as soon as the module has loaded.
|
|
28
|
+
{ downloads: [BRICKS, NORMALS, LEVEL] },
|
|
29
|
+
);
|
|
26
30
|
```
|
|
27
31
|
|
|
28
32
|
## The calls
|
|
@@ -36,7 +40,7 @@ export default defineSketch(async ({ assets, page }) => {
|
|
|
36
40
|
| `loadLut(url)` | A color grading table from a `.cube` or a `.3dl` file, for `post.set({ lut })`. [Color grading tables](#color-grading-tables) says what it reads |
|
|
37
41
|
| `lutFromData({ size, data })` | A color grading table made from numbers in code, with no file. [Tables from numbers](#tables-from-numbers) says what it takes |
|
|
38
42
|
| `loadEnvironment(url)` | An `Environment` for `scene.setEnvironment`, from a file of `bunx @null3d/cli assets env` or from an HDR file: Radiance (`.hdr`) or OpenEXR (`.exr`). [Environments](#environments) says what it reads |
|
|
39
|
-
| `builtinEnvironment('room')` | The built-in room,
|
|
43
|
+
| `builtinEnvironment('room')` | The built-in room, a white room with boxes and glowing panels for soft, neutral light, as an `Environment` |
|
|
40
44
|
| `skyEnvironment()` | The light of the scene's sky, as an `Environment` that follows the sky background |
|
|
41
45
|
| `loadCubemap(urls)` | A `Cubemap` of six images, a sky box for `scene.setBackground`. [Cube maps](#cube-maps) says what it reads |
|
|
42
46
|
| `loadLightProbeGrid(url)` | A probe grid baked outside the engine, as the options that `scene.setLightProbeGrid` takes. [Baked light](#baked-light) says what it reads |
|
|
@@ -46,6 +50,16 @@ export default defineSketch(async ({ assets, page }) => {
|
|
|
46
50
|
| `loadBinary(url)` | The file's bytes, as an `ArrayBuffer` |
|
|
47
51
|
| `preload(urls)` | Nothing: it downloads the files ahead of their loads |
|
|
48
52
|
| `onProgress(handler)` | A function that removes the handler |
|
|
53
|
+
| `cache(name, version)` | A namespace of the browser's cache for data that the sketch or an add-on makes itself: [The cache of derived data](#the-cache-of-derived-data) |
|
|
54
|
+
|
|
55
|
+
In [hold mode](../guides/testing.md#hold-mode), and while a recording replays, the calls run one at a time, so several loads take longer there.
|
|
56
|
+
|
|
57
|
+
<details>
|
|
58
|
+
<summary>Technical details: loads in hold mode and replays</summary>
|
|
59
|
+
|
|
60
|
+
Each load starts once the call before it has answered. A load makes its textures, meshes and materials as its files arrive, and the files arrive in another order on each run. A held frame would otherwise draw the scene's content in another order.
|
|
61
|
+
|
|
62
|
+
</details>
|
|
49
63
|
|
|
50
64
|
## glTF models
|
|
51
65
|
|
|
@@ -63,11 +77,22 @@ export default defineSketch(async ({ scene, assets }) => {
|
|
|
63
77
|
});
|
|
64
78
|
```
|
|
65
79
|
|
|
66
|
-
A model that the tool wrote with `--stages` holds its coarsest level. Each finer level downloads from a file of its own. `loadGltf` returns once the coarse level is ready. The copies that you make then refine as the finer levels arrive.
|
|
80
|
+
A model that the tool wrote with `--stages` holds its coarsest level. Each finer level downloads from a file of its own. `loadGltf` returns once the coarse level is ready. The copies that you make then refine as the finer levels arrive.
|
|
81
|
+
|
|
82
|
+
The loader holds back a level that the camera never draws, and fetches it once the camera comes close enough to show it. So a page downloads the levels that its camera shows, and no others. `maxLevels` sets the most levels to load, the file's own counted first. Set 1 to draw the coarse level alone and download no stage.
|
|
83
|
+
|
|
84
|
+
A model with a cluster tree streams the tree's bands the same way, and a band counts as a level. [Levels of detail](../concepts/lod.md#levels-from-the-asset-tool) explains the files. The [Island showcase](https://github.com/null3d-engine/null3d/tree/main/examples/showcase/island) loads models with levels and far cards.
|
|
67
85
|
|
|
68
|
-
A worker parses the file outside the sketch's frames, and decodes the images that the file holds there. The
|
|
86
|
+
A worker parses the file outside the sketch's frames, and decodes the images that the file holds there. The files that a `.gltf` file names download through `assets`, so `preload` and `onProgress` cover them too.
|
|
69
87
|
|
|
70
|
-
|
|
88
|
+
<details>
|
|
89
|
+
<summary>Technical details: what the first load downloads</summary>
|
|
90
|
+
|
|
91
|
+
The first `loadGltf` call downloads the loader and its worker, about 15 KB after Brotli, so a page without glTF files downloads neither. The worker starts as soon as the loader has arrived, while the model file still downloads. The engine copies the vertex data into its own memory, and keeps no other copy of it.
|
|
92
|
+
|
|
93
|
+
The `assets` API itself loads with its first call too, so a page that loads no file downloads none of it. Every promise answers once that code has arrived. Three calls answer at once. Both `registerGltfExtension` and `onProgress` give a function that removes the handler, and `onProgress` registers its handler when the code arrives. The `cache` call gives its namespace, whose reads and writes wait for the code.
|
|
94
|
+
|
|
95
|
+
</details>
|
|
71
96
|
|
|
72
97
|
The prefab turns each part of the file into the engine's own:
|
|
73
98
|
|
|
@@ -75,11 +100,11 @@ The prefab turns each part of the file into the engine's own:
|
|
|
75
100
|
| --- | --- |
|
|
76
101
|
| A node | A `Group`, or a `Mesh` for a node with a mesh of one material. A node with lights or a mesh of several materials becomes a group with one object for each |
|
|
77
102
|
| A mesh | One mesh for each material, with its vertex arrays in the types that the file holds them in, `KHR_mesh_quantization` types included. Points and lines are left out; development builds warn about them |
|
|
78
|
-
| A material | `materials.standard`, or `materials.unlit` with `KHR_materials_unlit`.
|
|
103
|
+
| A material | `materials.standard`, or `materials.unlit` with `KHR_materials_unlit`. [Material extensions](#material-extensions) lists what each extension sets. |
|
|
79
104
|
| A texture | A texture with the file's sampler and texture coordinates. `KHR_texture_basisu` textures load through the KTX2 transcoder |
|
|
80
105
|
| `EXT_texture_webp`, `EXT_texture_avif` | The texture's WebP or AVIF image, which the browser decodes in the loader's worker. A texture with a KTX2 image takes that first, then WebP, then AVIF. The texture's own image is a fallback for other loaders, and the engine does not download or decode it |
|
|
81
106
|
| `KHR_texture_transform` | Each map's own transform, in the material's `mapUvTransforms`: its offset, repeat and rotation. A map that the file gives no transform reads the texture coordinates as the mesh gives them |
|
|
82
|
-
| `KHR_lights_punctual` | Directional, point and spot lights, in
|
|
107
|
+
| `KHR_lights_punctual` | Directional, point and spot lights, in glTF's units: lux for a directional light, and candela for a point or spot light |
|
|
83
108
|
| `KHR_node_visibility` | A node that the file hides draws nothing until a clip shows it |
|
|
84
109
|
| `NEEDLE_lightmaps`, `NEEDLE_components` | The light map that a node's Needle `MeshRenderer` names, on the material that draws the node: its radiance, read at the second texture coordinates, and the scale and offset that place it. The texture keeps its RGBM texels, which the material decodes as [Needle's viewer](../guides/baked-light-data.md#needle-light-maps) does. A skybox or reflection entry of the extension is left out |
|
|
85
110
|
| `KHR_animation_pointer` | Property tracks of a clip, which move a light's intensity, color or range, a material's values, the offset and scale of a base color or emissive texture's transform, and a node's visibility. A pointer the engine does not read leaves its value as the file has it, and development builds warn: [Property animation](animation.md#property-animation) |
|
|
@@ -90,7 +115,7 @@ The prefab turns each part of the file into the engine's own:
|
|
|
90
115
|
| `KHR_meshopt_compression`, `EXT_meshopt_compression` | The decoded vertex and index data, as the uncompressed file holds it. The first file with meshopt data downloads the decoder, about 6 KB after Brotli. A fallback buffer never downloads |
|
|
91
116
|
| `KHR_draco_mesh_compression` | The decoded vertices and triangles. Normals and tangents become 8-bit integers, and texture coordinates between 0 and 1 become 16-bit integers. The first file with Draco data downloads Draco's decoder, about 60 KB after Brotli. Development builds warn about each such file and name the command that converts it to meshopt |
|
|
92
117
|
|
|
93
|
-
|
|
118
|
+
A mesh with vertex colors turns them on, and a mesh without normals shades flat. A mesh without tangents turns the normal map's green channel over. Blended materials write no depth. The engine finds the lights near each surface by their ranges. So a point or spot light without a range ends where its light falls below 0.001 lux.
|
|
94
119
|
|
|
95
120
|
| Member | Gives |
|
|
96
121
|
| --- | --- |
|
|
@@ -102,6 +127,37 @@ Materials follow three.js's `GLTFLoader`. A mesh with vertex colors turns them o
|
|
|
102
127
|
| `prefab.url` | The address the model came from |
|
|
103
128
|
| `prefab.destroy()` | Frees the model: [Freeing a model](#freeing-a-model) |
|
|
104
129
|
|
|
130
|
+
### Material extensions
|
|
131
|
+
|
|
132
|
+
| Extension | What it sets | See |
|
|
133
|
+
| --- | --- | --- |
|
|
134
|
+
| `KHR_materials_unlit` | `materials.unlit` instead of `materials.standard` | |
|
|
135
|
+
| `KHR_materials_emissive_strength` | `emissiveIntensity` | |
|
|
136
|
+
| `KHR_materials_specular` | `specularIntensity`, `specularColor` and their maps | [Specular reflection](materials.md#specular-reflection-and-index-of-refraction) |
|
|
137
|
+
| `KHR_materials_ior` | `ior`. An `ior` of 0 becomes 1000, a surface that reflects nearly all light | [Specular reflection](materials.md#specular-reflection-and-index-of-refraction) |
|
|
138
|
+
| `KHR_materials_transmission` | `transmission`, and its map | [Transmission](materials.md#transmission) |
|
|
139
|
+
| `KHR_materials_volume` | `thickness`, `attenuationColor` and `attenuationDistance` | [Transmission](materials.md#transmission) |
|
|
140
|
+
| `KHR_materials_dispersion` | `dispersion`, which separates the light that passes through into colors | [Transmission](materials.md#transmission) |
|
|
141
|
+
| `KHR_materials_diffuse_transmission` | `diffuseTransmission`, `diffuseTransmissionColor` and their maps | [Light through thin surfaces](materials.md#light-through-thin-surfaces) |
|
|
142
|
+
| `KHR_materials_clearcoat` | `clearcoat`, `clearcoatRoughness`, `clearcoatNormalScale` and their maps | [Clear coat and sheen](materials.md#clear-coat-and-sheen) |
|
|
143
|
+
| `KHR_materials_sheen` | `sheenColor`, `sheenRoughness` and their maps | [Clear coat and sheen](materials.md#clear-coat-and-sheen) |
|
|
144
|
+
| `KHR_materials_iridescence` | `iridescence`, `iridescenceIor`, `iridescenceThicknessRange` and their maps | [Iridescence and anisotropy](materials.md#iridescence-and-anisotropy) |
|
|
145
|
+
| `KHR_materials_anisotropy` | `anisotropy`, `anisotropyRotation` and its map | [Iridescence and anisotropy](materials.md#iridescence-and-anisotropy) |
|
|
146
|
+
| `KHR_materials_volume_scatter` (a draft) | `subsurfaceRadius` and `subsurfaceColor`, each channel spreading `attenuationDistance` times its `multiscatterColor` | [Light under the surface](materials.md#light-under-the-surface) |
|
|
147
|
+
|
|
148
|
+
A material with many extensions can drop some textures, and the loader notes each one it drops.
|
|
149
|
+
|
|
150
|
+
<details>
|
|
151
|
+
<summary>Technical details: which textures a material with many extensions keeps</summary>
|
|
152
|
+
|
|
153
|
+
A masked material keeps its transmission, so its cut-out decides which pixels draw and the light from behind fills the rest. A material that also gives specular textures keeps both families: each transmission or thickness texture samples a specular slot's texture array.
|
|
154
|
+
|
|
155
|
+
A thickness texture stays out beside a specular color texture, whose sRGB texels never share its array. A layered material goes without its specular textures and its diffuse transmission, unless a layer map fills the array that it samples, and the loader notes the one that stays out. A coat roughness or sheen roughness texture that is not the texture of its pair is not drawn.
|
|
156
|
+
|
|
157
|
+
The coat's and the sheen's textures keep their places ahead of the iridescence's and the anisotropy's, whose textures are then noted. Transmission wins over diffuse transmission. A volume without an attenuation distance spreads no light, and `scatterAnisotropy` is not drawn.
|
|
158
|
+
|
|
159
|
+
</details>
|
|
160
|
+
|
|
105
161
|
### Freeing a model
|
|
106
162
|
|
|
107
163
|
`prefab.destroy()` frees a model that the scene no longer needs. It frees every mesh, material and texture that the load made, and the model's skeleton and clips. First destroy the copies that `scene.instantiate` made and the batches of `scene.createInstances`. They can go in the same frame, just before the model:
|
|
@@ -124,23 +180,25 @@ An add-on can read a glTF extension that the engine leaves out. It registers a h
|
|
|
124
180
|
// A handler draws a marker at each primitive that carries the example extension.
|
|
125
181
|
const remove = assets.registerGltfExtension({
|
|
126
182
|
extensions: ['EXT_example_marker'],
|
|
127
|
-
load(data,
|
|
128
|
-
const mesh =
|
|
129
|
-
const material =
|
|
183
|
+
load(data, context) {
|
|
184
|
+
const mesh = context.geometry.box();
|
|
185
|
+
const material = context.materials.unlit({ color: [1, 0.6, 0] });
|
|
130
186
|
return { mesh, material };
|
|
131
187
|
},
|
|
132
188
|
});
|
|
133
189
|
remove(); // the handler reads no more files
|
|
134
190
|
```
|
|
135
191
|
|
|
136
|
-
`registerGltfExtension(handler)` returns a function that unregisters the handler.
|
|
192
|
+
`assets.registerGltfExtension(handler)` returns a function that unregisters the handler. It throws [E1213](../errors/E1213.md) for an extension that another handler reads, for a handler that names no extension, and for a handler without a `load` function.
|
|
137
193
|
|
|
138
194
|
An add-on registers its own handler as its module loads, with the engine's `registerGltfExtension`,
|
|
139
195
|
which serves every sketch of the thread. A page that imports the add-on then loads the add-on's
|
|
140
196
|
files with no other call, and a file that requires the extension names the package to import instead
|
|
141
|
-
of failing with E1417. `@null3d/splats` reads `KHR_gaussian_splatting` this way.
|
|
197
|
+
of failing with E1417. `@null3d/splats` reads `KHR_gaussian_splatting` this way.
|
|
198
|
+
|
|
199
|
+
A handler that a
|
|
142
200
|
sketch registers with `assets.registerGltfExtension` for the same extension reads its files in the
|
|
143
|
-
add-on's place.
|
|
201
|
+
add-on's place. A later add-on handler for the same extension replaces the earlier one, so a development reload of the add-on works. When two add-ons read one extension, the one that loaded last reads it.
|
|
144
202
|
|
|
145
203
|
The loader calls `load` once for each primitive that carries one of the handler's extensions. It gets `data`, which describes the primitive, and `context`, which holds the engine's makers:
|
|
146
204
|
|
|
@@ -157,24 +215,28 @@ The loader calls `load` once for each primitive that carries one of the handler'
|
|
|
157
215
|
| `context.geometry` | The engine's `geometry`, for the meshes that the handler returns |
|
|
158
216
|
| `context.materials` | The engine's `materials`, for the materials that the handler returns |
|
|
159
217
|
|
|
160
|
-
`load` returns one part, a list of parts, or nothing, which draws nothing. A part is `{ mesh, material }`. The loader places the parts at the primitive's node, so copies of the model draw them, and `prefab.destroy()` frees them. A primitive that a handler claims draws only what the handler returns.
|
|
218
|
+
`load` returns one part, a list of parts, or nothing, which draws nothing. A part is `{ mesh, material }`. The loader places the parts at the primitive's node, so copies of the model draw them, and `prefab.destroy()` frees them. A primitive that a handler claims draws only what the handler returns.
|
|
219
|
+
|
|
220
|
+
The other primitives of the same mesh draw as usual. `load` may return a promise. In hold mode, `load` must not wait for another `assets` call, since that call waits for the load that runs the handler.
|
|
161
221
|
|
|
162
|
-
A file that requires an extension which an add-on reads loads with that add-on's handler. Without it, the load fails with [E1417](../errors/E1417.md), and the message names the package to import. For example, the message for `KHR_gaussian_splatting` names `@null3d/splats`.
|
|
222
|
+
A file that requires an extension which an add-on reads loads with that add-on's handler. Without it, the load fails with [E1417](../errors/E1417.md), and the message names the package to import. For example, the message for `KHR_gaussian_splatting` names `@null3d/splats`.
|
|
223
|
+
|
|
224
|
+
A file that only uses such an extension, and does not require it, draws without that extension's data when no handler reads it. Development builds warn about each name in a file's `extensionsUsed` that neither the loader nor a registered handler reads. When an add-on reads the extension, the warning names the package to import. Production builds print nothing.
|
|
163
225
|
|
|
164
226
|
## Color grading tables
|
|
165
227
|
|
|
166
|
-
`loadLut` reads
|
|
228
|
+
`loadLut` reads two forms of file, `.cube` and `.3dl`, with tables of 2 to 256 texels a side. The table becomes a 3D texture of 4 bytes per texel: 144 KB for a table of 33, and 1.1 MB for one of 65.
|
|
167
229
|
|
|
168
230
|
- A `.cube` file gives `LUT_3D_SIZE`, and the table's values from 0 to 1, red changing fastest. Its `TITLE` becomes the table's `title`. Its domain comes from `DOMAIN_MIN` and `DOMAIN_MAX`, or from DaVinci Resolve's `LUT_3D_INPUT_RANGE`, and becomes `domainMin` and `domainMax`. A table in 1D (`LUT_1D_SIZE`) fails with E1412.
|
|
169
|
-
- A `.3dl` file gives whole numbers, blue changing fastest, after an optional line of its input grid, such as `0 64 128 ... 1023`. The grid's points may differ from even steps by one, as rounding leaves them
|
|
231
|
+
- A `.3dl` file gives whole numbers, blue changing fastest, after an optional line of its input grid, such as `0 64 128 ... 1023`. The grid's points may differ from even steps by one, as rounding leaves them. The values' bit depth comes from a Lustre `Mesh` line, or else from the largest value.
|
|
170
232
|
- Values outside 0 to 1 are clamped, as the canvas would clamp them.
|
|
171
233
|
- The first table loads the readers, a file of about 2 KB. The thread that runs the sketch reads the file between frames: a table of 33 takes about 10 ms on a desktop.
|
|
172
234
|
|
|
173
|
-
`lut.destroy()` frees the table's GPU memory. Give `post.set` a table that lives.
|
|
235
|
+
`lut.destroy()` frees the table's GPU memory. Give `post.set` a table that lives. The comparisons build their color grade with `lutFromData`: the [night town](https://github.com/null3d-engine/null3d/tree/main/examples/compare/night-town), [battle](https://github.com/null3d-engine/null3d/tree/main/examples/compare/battle) and [factory](https://github.com/null3d-engine/null3d/tree/main/examples/compare/factory) comparisons.
|
|
174
236
|
|
|
175
237
|
### Tables from numbers
|
|
176
238
|
|
|
177
|
-
`lutFromData` makes a table from numbers that your code computes
|
|
239
|
+
`lutFromData` makes a table from numbers that your code computes. It takes the numbers in the order of a `.cube` file's lines, so a file and its numbers make the same table:
|
|
178
240
|
|
|
179
241
|
```ts
|
|
180
242
|
import { defineSketch } from '@null3d/engine';
|
|
@@ -213,9 +275,11 @@ export default defineSketch(async ({ assets, post }) => {
|
|
|
213
275
|
`loadEnvironment` reads two kinds of file:
|
|
214
276
|
|
|
215
277
|
- The KTX2 file that `bunx @null3d/cli assets env` writes, the fast path. It holds a cube map in `rgb9e5ufloat` or `rgba16float`, with one mip level for each step of roughness. It also holds the nine coefficients of its diffuse light.
|
|
216
|
-
- An HDR file of an equirectangular panorama
|
|
278
|
+
- An HDR file of an equirectangular panorama: a Radiance file (`.hdr`) or an OpenEXR file (`.exr`). The engine filters it on the GPU at load, with the asset tool's steps.
|
|
279
|
+
|
|
280
|
+
Prefer the tool's KTX2 file for maps that ship with a game; use an HDR file for maps that change, such as user uploads. The [environment light demo](https://github.com/null3d-engine/null3d/tree/main/examples/environment) shows an HDR file's light, an EXR file's light and the built-in room.
|
|
217
281
|
|
|
218
|
-
`builtinEnvironment('room')` makes
|
|
282
|
+
`builtinEnvironment('room')` makes a white room with six boxes, six glowing panels and one point light. It gives soft, neutral light. `skyEnvironment()` makes the light of the sky that [`scene.setBackground({ sky })`](scene.md#environments-cube-maps-and-the-sky) draws. The GPU draws each of them and filters it, so no file downloads. Give any of them to [`scene.setEnvironment`](scene.md#the-environment).
|
|
219
283
|
|
|
220
284
|
```ts
|
|
221
285
|
import { defineSketch } from '@null3d/engine';
|
|
@@ -232,23 +296,34 @@ export default defineSketch(async ({ scene, assets }) => {
|
|
|
232
296
|
```
|
|
233
297
|
|
|
234
298
|
- An `Environment` has its cube map's `size`, the width of the largest faces, its `levels`, its `format` and its GPU `bytes`.
|
|
235
|
-
- The first
|
|
236
|
-
- A KTX2 file's cube map uploads in the frames after the load, and the scene draws without it until it is on the GPU.
|
|
237
|
-
-
|
|
238
|
-
-
|
|
239
|
-
-
|
|
240
|
-
-
|
|
241
|
-
- `skyEnvironment` loads the same code and shaders as the room, and resolves once they are ready. The next frame makes the whole map, in about 10 ms on a MacBook Pro. Until the scene's first sky background, the map shows the sky's defaults.
|
|
242
|
-
- The sky's map follows the sky. After a change that shows, the map refreshes in 20 stages, one a frame. A sun that turns less than half a degree leaves the map as it is, and so does a color value that drifts by less than 2%. Slowly drifting clouds wait too, and their changes add up. One last refresh captures the sky exactly once it stops changing. The scene draws with the old map until the last stage. Each stage takes about 1 ms of GPU time on a MacBook Pro. The map leaves out the sun's disc, whose light the scene's directional light gives. [Lighting and environment](../concepts/lighting.md#sky-and-backgrounds) gives the detail.
|
|
299
|
+
- The first room, sky or HDR call starts the download of the code and shaders that make the room, about 12 KB after Brotli, and each call resolves once they are ready.
|
|
300
|
+
- A KTX2 file's cube map uploads in the frames after the load, and the scene draws without it until it is on the GPU. Load it while the scene loads.
|
|
301
|
+
- The first HDR file loads the reader and its worker, about 6.5 KB after Brotli. A worker reads the file outside the sketch's frames, and the GPU then filters the whole map in the next frame, before that frame draws. So no frame draws the scene without its light. Load HDR files while the scene loads.
|
|
302
|
+
- `builtinEnvironment` resolves once the code and the shaders that make the room are ready. The GPU then makes the whole map in the next frame, before that frame draws. Ask for the room while the scene loads. During play, the call makes one long frame.
|
|
303
|
+
- `skyEnvironment` loads the same code and shaders as the room, and resolves once they are ready. The next frame makes the whole map. Until the scene's first sky background, the map shows the sky's defaults.
|
|
304
|
+
- The sky's map follows the sky: after a change that shows, it refreshes in stages, one a frame. A small change waits, and one last refresh captures the sky once it stops changing. The scene draws with the old map until the last stage, and the map leaves out the sun's disc, whose light the scene's directional light gives.
|
|
243
305
|
- `environment.destroy()` frees the cube map's GPU memory. The scene then draws without it.
|
|
244
306
|
- Other KTX2 files, such as `loadTexture`'s, fail with E1412. So do supercompressed files.
|
|
245
|
-
-
|
|
307
|
+
- An HDR map's faces are 256 texels by default, and an image wider than 2,048 texels is averaged down first. The HDR reader reads single-part scanline files with every compression but DWAA and DWAB. Tiled, deep and multi-part files fail with E1412, as do Radiance files stored from the bottom row up.
|
|
308
|
+
|
|
309
|
+
<details>
|
|
310
|
+
<summary>Technical details: sizes, limits and GPU times</summary>
|
|
311
|
+
|
|
312
|
+
The first environment file loads the file reader, under 1 KB after Brotli. An unclipped sun, or other light beyond 65,408, keeps its share of the rough levels and the diffuse light. Only the sharpest level stops at 65,408, as in the tool's files.
|
|
313
|
+
|
|
314
|
+
The OpenEXR reader reads single-part files of scanlines with R, G and B channels, as half floats, floats or whole numbers. It reads every compression but DWAA and DWAB: none, RLE, ZIPS, ZIP, PIZ, PXR24, B44 and B44A.
|
|
315
|
+
|
|
316
|
+
The room's map takes about 20 ms of GPU time on a MacBook Pro, and 50 to 110 ms on recent phones. The sky's map takes about 10 ms on a MacBook Pro. The sky refreshes in 20 stages, each about 1 ms of GPU time on a MacBook Pro; a sun that turns less than half a degree leaves the map as it is, and so does a color value that drifts by less than 2%.
|
|
317
|
+
|
|
318
|
+
After Brotli, Venice Sunset's 2K Radiance file takes 3.8 MB and its map 1.4 MB. A 1K OpenEXR file and its map take about 1.3 MB each. [Lighting and environment](../concepts/lighting.md#sky-and-backgrounds) gives the detail.
|
|
319
|
+
|
|
320
|
+
</details>
|
|
246
321
|
|
|
247
322
|
[Lighting and environment](../concepts/lighting.md#environment-maps) says how an environment lights the scene.
|
|
248
323
|
|
|
249
324
|
## Cube maps
|
|
250
325
|
|
|
251
|
-
`loadCubemap` loads six images into a cube map
|
|
326
|
+
`loadCubemap` loads six images into a cube map. Give their addresses in this order: the faces toward +X, -X, +Y, -Y, +Z and -Z. The engine reads the faces as seen from inside the cube, mirrored across x, so a common six-image sky box shows the right way round. Each face is square, every face has the same size, and a face takes at most 2,048 pixels a side. Give the cube map to [`scene.setBackground`](scene.md#environments-cube-maps-and-the-sky).
|
|
252
327
|
|
|
253
328
|
```ts
|
|
254
329
|
import { defineSketch } from '@null3d/engine';
|
|
@@ -291,9 +366,13 @@ A relative address resolves against the page's address, in every thread mode, as
|
|
|
291
366
|
|
|
292
367
|
## Loading screens
|
|
293
368
|
|
|
294
|
-
`
|
|
369
|
+
The files that the setup loads start sooner when `defineSketch`'s `downloads` option names them. A live start then begins to download them as soon as the sketch's module has loaded, before the setup runs ([The download list](sketch.md#the-download-list)). A development build warns when one of the setup's loads waited for another ([Loads one after another](sketch.md#loads-one-after-another)).
|
|
370
|
+
|
|
371
|
+
`preload` downloads files ahead of the loads that use them, all at once, and resolves when every file has arrived. Use it for files that a later stage loads during play. The next load of each address takes its file from memory, so it downloads nothing. The files wait in memory until then.
|
|
295
372
|
|
|
296
|
-
`onProgress` calls its handler as a download's bytes arrive and when one finishes or fails
|
|
373
|
+
`onProgress` calls its handler as a download's bytes arrive and when one finishes or fails. It passes two counts: the bytes downloaded so far and the bytes expected so far. The expected bytes are the lengths of the responses that gave one, and 0 while none has. A response with no length still counts its bytes into the first count, so a page draws `Math.min(1, loaded / Math.max(total, loaded))`.
|
|
374
|
+
|
|
375
|
+
A download that fails counts as finished too, so a loading bar reaches its end. It counts the bytes its response announced, or one byte when it announced none. Each call names the address whose bytes moved. The files of the download list count too, also the bytes that arrived before the setup added the handler.
|
|
297
376
|
|
|
298
377
|
```ts
|
|
299
378
|
assets.onProgress((loaded, total, url) => page.post('loading', { loaded, total, url }));
|
|
@@ -302,11 +381,13 @@ await assets.preload(['/tex/a.png', '/tex/b.png', '/tex/c.png']);
|
|
|
302
381
|
// (120_000, 120_000) as the last of the three arrives.
|
|
303
382
|
```
|
|
304
383
|
|
|
305
|
-
[Loading screens and warm-up](../guides/loading-screens.md) shows a whole loading screen.
|
|
384
|
+
[Loading screens and warm-up](../guides/loading-screens.md) shows a whole loading screen. The [glTF model demo](https://github.com/null3d-engine/null3d/tree/main/examples/gltf-model) drives its loading bar this way, through the demos' shared helper.
|
|
306
385
|
|
|
307
386
|
## Caching
|
|
308
387
|
|
|
309
|
-
Loads of one address at the same time share one download. Files that `preload` downloaded wait in memory until a load takes them. The HTTP cache keeps everything else, as it does for a page's own requests
|
|
388
|
+
Loads of one address at the same time share one download. Files that `preload` or the download list downloaded wait in memory until a load takes them. The HTTP cache keeps everything else, as it does for a page's own requests.
|
|
389
|
+
|
|
390
|
+
A download that the network rejects, or that a server answers with a 5xx, is tried once more after a short wait. A tunnel or a proxy can refuse the first request of a session while the same file serves a moment later. A refused answer such as a 404, and a body that arrived but will not read, are reported at once.
|
|
310
391
|
|
|
311
392
|
A game that plays with no network caches its files and the engine's in its own service worker, as [Hosting](../getting-started/hosting.md#offline-play) shows. [Caches between visits](../getting-started/hosting.md#caches-between-visits) shows how each cache fits in.
|
|
312
393
|
|
|
@@ -336,10 +417,15 @@ async function tile(x: number, z: number): Promise<Float32Array> {
|
|
|
336
417
|
- `put` returns at once, and the write starts after the call. Leave the bytes unchanged until its promise resolves. A write that fails, or that would hold too much memory, is dropped.
|
|
337
418
|
- The cache works in the sketch worker and on the page's thread. In the sketch worker it reads fastest.
|
|
338
419
|
|
|
420
|
+
<details>
|
|
421
|
+
<summary>Technical details: how much the cache keeps</summary>
|
|
422
|
+
|
|
339
423
|
Every namespace shares one budget: a tenth of the storage that the browser allows the page's origin. Chrome and Firefox allow about 10 GiB, so the cache keeps about 1 GiB there, and Safari on an iPhone keeps about 3.8 GiB. When the cache passes its budget, it deletes the entries used longest ago.
|
|
340
424
|
|
|
341
425
|
The browser can still delete the origin's storage. Under storage pressure, it deletes the storage of whole origins, the least recently used first. Safari deletes it after seven days of browsing without a visit to the site, unless the game runs from the Home Screen. The engine never asks for persistent storage, because Firefox asks the player with a prompt. A game can ask for it with `navigator.storage.persist()`.
|
|
342
426
|
|
|
427
|
+
</details>
|
|
428
|
+
|
|
343
429
|
The `?derived-cache=off` switch turns the cache off, so every load makes its data again, as on a first visit ([Testing](../guides/testing.md#switches-for-tests)).
|
|
344
430
|
|
|
345
431
|
## Errors
|
|
@@ -359,7 +445,7 @@ Each call rejects with an engine error that says how to fix the problem:
|
|
|
359
445
|
| [E1413](../errors/E1413.md) | A file from another origin, whose server did not allow the page to read it |
|
|
360
446
|
| [E1208](../errors/E1208.md) | A texture option that the engine does not know, or one that a KTX2 file cannot take. Also numbers that `lutFromData` cannot make a table from |
|
|
361
447
|
|
|
362
|
-
`preload` rejects with the error of the first file that fails. The files that arrived stay in memory, and a later load of the failed file tries again.
|
|
448
|
+
`preload` rejects with the error of the first file that fails. The files that arrived stay in memory, and a later load of the failed file tries again. A file of the download list that fails has no caller to reject. The load that takes it rejects with its error, such as E1411, which names `defineSketch()`'s downloads.
|
|
363
449
|
|
|
364
450
|
## Models that users upload
|
|
365
451
|
|
package/docs/api/cameras.md
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/cameras
|
|
3
3
|
title: Cameras
|
|
4
|
-
|
|
5
|
-
since: "0.1"
|
|
6
|
-
summary: "Perspective and orthographic cameras; a perspective camera's focal length; screenToRay; worldToScreen; layers."
|
|
4
|
+
summary: "Perspective and orthographic cameras; a perspective camera's focal length; lens shift; screenToRay; worldToScreen; layers."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Cameras
|
|
10
8
|
|
|
11
|
-
> Roadmap step 0.1, first released in null3D 0.1.0. Step 0.2 adds `screenToRay`, `worldToScreen` and `setFocalLength`. The API is experimental, so it can still change between versions.
|
|
12
|
-
|
|
13
9
|
A camera is the object that the engine draws the scene from. There are two kinds: `scene.createPerspectiveCamera` makes a perspective camera, and `scene.createOrthographicCamera` makes an orthographic one. `scene.setActiveCamera` picks the camera that the canvas shows.
|
|
14
10
|
|
|
15
11
|
```ts
|
|
@@ -38,7 +34,7 @@ A perspective camera shows near things larger than far things, as the eye does.
|
|
|
38
34
|
- `near` and `far` are the distances to the nearest and farthest things the camera shows. The defaults are 0.1 and 2000.
|
|
39
35
|
- `setFov(degrees)` and `setNearFar(near, far)` change the lens later. The `fov`, `near` and `far` properties read it.
|
|
40
36
|
|
|
41
|
-
The
|
|
37
|
+
The aspect ratio follows the canvas in every frame, so a camera needs no call when the canvas changes size.
|
|
42
38
|
|
|
43
39
|
The field of view goes from 0 to 180 degrees, and the near plane must lie in front of the camera, beyond 0. In development builds, values outside these ranges throw E1108.
|
|
44
40
|
|
|
@@ -54,7 +50,7 @@ post.set({ dof: { aperture: 1.8, focusDistance: 4 } });
|
|
|
54
50
|
|
|
55
51
|
[Depth of field](post.md#depth-of-field) takes the active camera's focal length unless its settings give one, so the blur matches the framing. The aperture and the focus distance live in `post.set`'s `dof` settings, because they change only the blur. The [depth of field demo](https://github.com/null3d-engine/null3d/tree/main/examples/camera-lens) runs a dolly zoom. Its lens goes from 35 to 85 mm while the camera backs away, so the board keeps its size.
|
|
56
52
|
|
|
57
|
-
|
|
53
|
+
The sensor's 24 mm side lies along the canvas's height, so a focal length gives the same vertical field of view on every canvas shape. A focal length that is not above 0 throws E1108 in development builds.
|
|
58
54
|
|
|
59
55
|
## Orthographic cameras
|
|
60
56
|
|
|
@@ -65,14 +61,45 @@ const camera = scene.createOrthographicCamera({ height: 20, near: 1, far: 200, p
|
|
|
65
61
|
scene.setActiveCamera(camera);
|
|
66
62
|
```
|
|
67
63
|
|
|
68
|
-
- `height` is the height of the view in world units. The width follows the canvas's aspect ratio in every frame. The default height is 2
|
|
69
|
-
- `left`, `right`, `top` and `bottom` give the four edges instead
|
|
64
|
+
- `height` is the height of the view in world units. The width follows the canvas's aspect ratio in every frame. The default height is 2.
|
|
65
|
+
- `left`, `right`, `top` and `bottom` give the four edges instead. The view then keeps these edges on any canvas, and stretches to fill it. Give all four edges and no `height`.
|
|
70
66
|
- `near` and `far` are the distances along the view to its nearest and farthest planes. The defaults are 0.1 and 2000. The near plane can lie behind the camera, because nothing in the view grows as it gets closer.
|
|
71
|
-
- `setOrthoHeight(height)` zooms: a smaller height shows less of the scene, and shows it larger. A view made from four edges scales about its center and keeps its shape
|
|
67
|
+
- `setOrthoHeight(height)` zooms: a smaller height shows less of the scene, and shows it larger. A view made from four edges scales about its center and keeps its shape.
|
|
72
68
|
- The `height` property reads the view's height. The `width` property reads the width of a view made from edges, and is `undefined` while the width follows the canvas.
|
|
73
69
|
|
|
74
70
|
In development builds, a view with no size throws E1108. So does a far plane that is not beyond the near plane, for both kinds of camera.
|
|
75
71
|
|
|
72
|
+
## Lens shift
|
|
73
|
+
|
|
74
|
+
A shift lens moves the picture off the camera's axis and keeps its perspective. A web page uses one to put a scene beside its text without turning the camera. Turning the camera would change the perspective: upright lines would lean, and the subject would show another side.
|
|
75
|
+
|
|
76
|
+
`setLensShift(x, y)` moves the view right by `x` times its width and up by `y` times its height. The scene moves the other way in the picture. The `lensShift` property reads the shift back as `[x, y]`, and the default is `[0, 0]`.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { defineSketch } from '@null3d/engine';
|
|
80
|
+
|
|
81
|
+
export default defineSketch(({ scene }) => {
|
|
82
|
+
const camera = scene.createPerspectiveCamera({ position: [0, 2, 8], target: [0, 1, 0] });
|
|
83
|
+
// The page's text fills the left half, so the target sits three quarters of the way across.
|
|
84
|
+
camera.setLensShift(-0.25, 0);
|
|
85
|
+
scene.setActiveCamera(camera);
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The shifted picture is the matching crop of a wider picture from the same place. A shift of 0.5 puts the camera's axis on the edge of the picture. Both kinds of camera take a shift. An orthographic view moves across by the same fractions of its size.
|
|
90
|
+
|
|
91
|
+
Everything that uses the camera's view follows the shift. That covers culling, the shadow cascades, picking, `screenToRay`, `worldToScreen` and HTML labels. It also covers views from `scene.createView`, and the post effects that rebuild positions from depth. A sketch can change the shift in any frame, and the call allocates nothing.
|
|
92
|
+
|
|
93
|
+
To draw one tile of a larger picture, narrow the lens to the tile and shift the view onto it. The canvas must have the tile's shape. Take a tile that is `w` of the full picture's width and `h` of its height. Its middle lies `cx` right of and `cy` above the full picture's middle. All four are fractions of the full picture:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
const half = Math.tan((fullFov * Math.PI) / 360) * h;
|
|
97
|
+
camera.setFov((360 / Math.PI) * Math.atan(half)); // or camera.setOrthoHeight(fullHeight * h)
|
|
98
|
+
camera.setLensShift(cx / w, cy / h);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The [three.js mapping](../porting/threejs-mapping.md) gives the same numbers for three.js's `setViewOffset`.
|
|
102
|
+
|
|
76
103
|
## Which kind of camera
|
|
77
104
|
|
|
78
105
|
`camera.isOrthographic` is true for an orthographic camera and false for a perspective one. Code that works with either kind, such as camera controls, reads `fov` or `height` after that check.
|
|
@@ -134,15 +161,19 @@ export default defineSketch(({ scene, input, page }) => {
|
|
|
134
161
|
|
|
135
162
|
The engine draws a frame on one thread while the sketch computes the next one on another. A click therefore lands on a frame that is older than the sketch's current camera. During a fast pan, a ray from the current camera would miss what the user clicked.
|
|
136
163
|
|
|
137
|
-
So the engine keeps the cameras of the last four views that it drew. Frames in a row with the same view count as one view. The frames that the engine draws while the setup runs count too, so a click during the setup picks what that frame showed. When `x` and `y` come from `input.pointer` or a finger in `input.touches`, the ray uses the camera of the frame on screen at that event.
|
|
164
|
+
So the engine keeps the cameras of the last four views that it drew. Frames in a row with the same view count as one view. The frames that the engine draws while the setup runs count too, so a click during the setup picks what that frame showed. When `x` and `y` come from `input.pointer` or a finger in `input.touches`, the ray uses the camera of the frame on screen at that event.
|
|
165
|
+
|
|
166
|
+
Any other point uses the camera of the frame that last ran, with its lens as it is now. This holds in every thread mode.
|
|
138
167
|
|
|
139
168
|
Objects keep their current positions. A ray finds a moving object where it is now. That can be up to a frame of its motion away from where the user saw it.
|
|
140
169
|
|
|
141
170
|
`worldToScreen` always uses the camera of the frame that last ran. In `onLateUpdate`, that is the frame being drawn, so a point placed there lines up with the image.
|
|
142
171
|
|
|
172
|
+
A view from `scene.createView` draws its camera into a rectangle of the canvas, with the rectangle's shape. `view.screenToRay(x, y, ray)` and `view.worldToScreen(point, out)` map a point of that image. They take CSS pixels from the canvas's top-left corner too. `scene.viewAt(x, y)` gives the view under a point. [Multiple views](../guides/multiple-views.md#picking-in-a-view) shows them.
|
|
173
|
+
|
|
143
174
|
## Several cameras
|
|
144
175
|
|
|
145
|
-
A scene can have several cameras, and `setActiveCamera` switches between them. The
|
|
176
|
+
A scene can have several cameras, and `setActiveCamera` switches between them. The active camera fills the canvas. `scene.createView` draws more cameras into rectangles of it ([Multiple views](../guides/multiple-views.md)). Until you pick an active camera, and after the engine removes it, the canvas shows only the background.
|
|
146
177
|
|
|
147
178
|
## Related pages
|
|
148
179
|
|
|
@@ -153,6 +184,8 @@ A scene can have several cameras, and `setActiveCamera` switches between them. T
|
|
|
153
184
|
- [Input](input.md): the pointer and touches whose positions `screenToRay` takes.
|
|
154
185
|
- [Raycasting](raycast.md): finding the objects along a ray.
|
|
155
186
|
- [Math helpers](math.md): `quat.lookAt`, and why cameras swap its eye and target.
|
|
187
|
+
- [Camera layer masks](https://github.com/null3d-engine/null3d/tree/main/examples/layers): a camera that draws another set of layers every 2 seconds.
|
|
188
|
+
- [A picture in picture](https://github.com/null3d-engine/null3d/tree/main/examples/multiple-views): one scene from two cameras, split across the canvas or in an inset.
|
|
156
189
|
|
|
157
190
|
## API reference
|
|
158
191
|
|