@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/raycast.md
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/raycast
|
|
3
3
|
title: Raycasting and spatial queries
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.2"
|
|
6
4
|
summary: "raycast, raycastAny, raycastAll, raycastBatch, overlap queries, pointer events on objects."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Raycasting and spatial queries
|
|
10
8
|
|
|
11
|
-
> Roadmap step 0.2, first released in null3D 0.1.0. The API is experimental, so it can still change between versions. Queries test a skinned character in its bind pose, not in its animated pose. Pixel-exact picking draws each character as it is posed.
|
|
12
|
-
|
|
13
9
|
```mermaid
|
|
14
10
|
flowchart LR
|
|
15
11
|
query["A ray, a sphere<br/>or a box"] --> scene["The scene's trees:<br/>static and dynamic objects"]
|
|
@@ -18,9 +14,9 @@ flowchart LR
|
|
|
18
14
|
test --> hits["Hits, written into<br/>your own objects"]
|
|
19
15
|
```
|
|
20
16
|
|
|
21
|
-
A raycast finds where a ray meets the scene's objects. An overlap query finds the objects inside a sphere or a box. Every query tests the triangles of objects and instance rows
|
|
17
|
+
A raycast finds where a ray meets the scene's objects. An overlap query finds the objects inside a sphere or a box. Every query tests the triangles of objects and instance rows. Raycasts also hit [sprites, points and lines](#sprites-points-and-lines) where they draw. The engine keeps a tree over the scene's objects and a tree over each mesh's triangles. So a query tests only the few triangles near it.
|
|
22
18
|
|
|
23
|
-
Queries run in the sketch, on the scene. They write their results into objects and arrays that you create once, so a query in every frame allocates nothing.
|
|
19
|
+
Queries run in the sketch, on the scene. They write their results into objects and arrays that you create once, so a query in every frame allocates nothing. The engine's allocation benchmark checks it in every frame. The [picking demo](https://github.com/null3d-engine/null3d/tree/main/examples/picking) casts rays from the pointer, and its `object.on` events report the hit point.
|
|
24
20
|
|
|
25
21
|
```ts
|
|
26
22
|
import { defineSketch, type RaycastHit, vec3 } from '@null3d/engine';
|
|
@@ -77,7 +73,7 @@ A ray starts at `origin` and runs along `direction`, which needs no unit length.
|
|
|
77
73
|
|
|
78
74
|
`options` is `undefined` or an object with these optional fields:
|
|
79
75
|
|
|
80
|
-
- `layers`: the layers to test, a 32-bit mask as `setLayers` takes. A query tests an object when their masks share a layer. The default is layer 0 alone, as for a camera
|
|
76
|
+
- `layers`: the layers to test, a 32-bit mask as `setLayers` takes. A query tests an object when their masks share a layer. The default is layer 0 alone, as for a camera.
|
|
81
77
|
- `maxDistance`: the farthest hit in meters. The default is no limit.
|
|
82
78
|
- `pointThreshold`: a distance in meters. When you set it, a ray hits a point that it passes within this distance of, whatever the point's size.
|
|
83
79
|
- `lineThreshold`: a distance in meters. When you set it, a ray hits a line that it passes within this distance of, whatever the line's width.
|
|
@@ -91,8 +87,8 @@ A hit has these fields:
|
|
|
91
87
|
| `point` | Where the ray hit, in world space |
|
|
92
88
|
| `normal` | The unit normal of the hit triangle in world space, on the side that faces the ray's origin |
|
|
93
89
|
| `distance` | The distance from the origin to the point, in meters |
|
|
94
|
-
| `triangle` | The index of the hit triangle in its mesh
|
|
95
|
-
| `uv` | Where on the surface the ray hit, in the mesh's first texture coordinates
|
|
90
|
+
| `triangle` | The index of the hit triangle in its mesh. -1 for a sprite, a point or a line |
|
|
91
|
+
| `uv` | Where on the surface the ray hit, in the mesh's first texture coordinates. Give an array of two numbers, as you give `point`, and every raycast fills it. Read `hasUv` first |
|
|
96
92
|
| `hasUv` | True when the hit triangle's mesh has a first texture coordinate set, so `uv` gives where on the surface the ray hit. False for a hit on a sprite, a point or a line, and for a mesh with no such coordinates |
|
|
97
93
|
|
|
98
94
|
`uv` holds where the ray crossed the surface. It blends the three corners' texture coordinates,
|
|
@@ -103,7 +99,9 @@ in-world screen turns a click into a pixel of its image.
|
|
|
103
99
|
|
|
104
100
|
## Rays from the pointer
|
|
105
101
|
|
|
106
|
-
For clicks and hover on objects, `object.on('click', handler)` casts the ray itself. [Pointer events on objects](input.md#pointer-events-on-objects) describes it.
|
|
102
|
+
For clicks and hover on objects, `object.on('click', handler)` casts the ray itself. [Pointer events on objects](input.md#pointer-events-on-objects) describes it.
|
|
103
|
+
|
|
104
|
+
For a ray of your own, such as one that tests only some layers, `camera.screenToRay(x, y, ray)` writes the ray through a point on the canvas. Pass `input.pointer.x` and `input.pointer.y`, and the ray comes from the frame that was on screen at the pointer's event. Over a view from `scene.createView`, cast the ray with `view.screenToRay` instead, and `scene.viewAt(x, y)` finds that view ([Multiple views](../guides/multiple-views.md#picking-in-a-view)).
|
|
107
105
|
|
|
108
106
|
```ts
|
|
109
107
|
const ray = { origin: vec3.create(), direction: vec3.create() }; // made once
|
|
@@ -116,7 +114,9 @@ if (input.wasPressed('Mouse0')) {
|
|
|
116
114
|
|
|
117
115
|
## Batches of rays
|
|
118
116
|
|
|
119
|
-
The call `scene.raycastBatch(rays, options, out)` casts many rays at once, on the job workers. Its `rays` array holds six numbers per ray: its origin, then its direction. Its `out` object holds typed arrays with one entry per ray, or three numbers per ray for points and normals.
|
|
117
|
+
The call `scene.raycastBatch(rays, options, out)` casts many rays at once, on the job workers. Its `rays` array holds six numbers per ray: its origin, then its direction. Its `out` object holds typed arrays with one entry per ray, or three numbers per ray for points and normals.
|
|
118
|
+
|
|
119
|
+
Only `distances` is required, and the call fills each other array that you give. It returns how many rays hit something.
|
|
120
120
|
|
|
121
121
|
```ts
|
|
122
122
|
const COUNT = 1000;
|
|
@@ -146,26 +146,48 @@ scene.pick(240, 180).then((hit) => {
|
|
|
146
146
|
});
|
|
147
147
|
```
|
|
148
148
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
The coordinates stay the mesh's own. A repeated texture reports values past 1, and a material's `uvTransform` does not move them. A ray through the same point finds them, from the camera of the frame that recorded the pick. So a pick and a raycast on one point give one answer. A ray that names another object than the pixel did leaves `hasUv` false. The pick then keeps the object that the pixel showed.
|
|
152
|
-
|
|
153
|
-
A skinned or morphed character draws a different shape than the mesh that the ray tests. So does a custom material that moves its vertices in its shader. Their coordinates can therefore differ from the pose that the frame drew.
|
|
149
|
+
The pick draws each object's id into a small image around the point, then reads the id back. So a pick is exact to the pixel only when every source in the scene can draw into that image.
|
|
154
150
|
|
|
155
|
-
|
|
151
|
+
One sprite, point or line in the scene, one material that blends, uses `transmission` or uses `alphaMode: 'hash'`, or one custom material that masks or has no vertex offset, makes every pick a raycast. That raycast tests triangles: it ignores masks, tests skinned characters in their bind pose, and uses the camera of the frame that last ran. In [hold mode](../guides/testing.md), which runs no frame loop, a pick is a raycast too.
|
|
156
152
|
|
|
157
|
-
|
|
153
|
+
### What a pick finds
|
|
158
154
|
|
|
159
155
|
- Meshes of the engine's materials, on the camera's layers, where they draw opaque.
|
|
160
156
|
- Custom materials with a vertex offset, whose pick builds move each vertex as the surface draws.
|
|
161
157
|
- Each row of an instance batch, named by `object` and `instance`.
|
|
162
158
|
- Skinned and morphed characters, as their last frame's pose places them.
|
|
163
159
|
|
|
164
|
-
|
|
160
|
+
### Texture coordinates
|
|
161
|
+
|
|
162
|
+
A hit carries `uv` and `hasUv`, as a raycast's hit does. `uv` holds where on the surface the pixel landed, in the mesh's first texture coordinates. It blends them across the hit triangle's three corners. `hasUv` says whether the surface has such coordinates. Read `hasUv` first: `uv` holds nothing to read when it is false.
|
|
163
|
+
|
|
164
|
+
The coordinates stay the mesh's own. A repeated texture reports values past 1, and a material's `uvTransform` does not move them.
|
|
165
|
+
|
|
166
|
+
<details>
|
|
167
|
+
<summary>Technical details: how a pick finds its texture coordinates</summary>
|
|
168
|
+
|
|
169
|
+
A ray through the same point finds them, from the camera of the frame that recorded the pick. So a pick and a raycast on one point give one answer. A ray that names another object than the pixel did leaves `hasUv` false. The pick then keeps the object that the pixel showed.
|
|
170
|
+
|
|
171
|
+
</details>
|
|
165
172
|
|
|
166
|
-
|
|
173
|
+
The point is tested at the pixel that the camera draws, not at a projected triangle. A surface thinner than a pixel picks where its pixels are. An engine material with `alphaMode: 'mask'` picks by its mask. So a ray through a cut-out hole finds what lies behind the hole. The frame that records the pick draws it, so the camera of that frame answers. A camera that moves meanwhile can differ from the frame that the click saw.
|
|
167
174
|
|
|
168
|
-
A
|
|
175
|
+
A skinned or morphed character draws a different shape than the mesh that the ray tests. So does a custom material that moves its vertices in its shader. Their coordinates can therefore differ from the pose that the frame drew.
|
|
176
|
+
|
|
177
|
+
### Timing and cost
|
|
178
|
+
|
|
179
|
+
A pick costs one more draw of the camera's opaque objects, one read of four bytes, and one raycast for the texture coordinates. A pick answers in a frame after the one that records it.
|
|
180
|
+
|
|
181
|
+
<details>
|
|
182
|
+
<summary>Technical details: what a pick costs</summary>
|
|
183
|
+
|
|
184
|
+
Picks wait in a queue of their own, because a frame records one read.
|
|
185
|
+
|
|
186
|
+
</details>
|
|
187
|
+
|
|
188
|
+
### When a pick answers null or fails
|
|
189
|
+
|
|
190
|
+
A pick before the first frame answers `null`. A hidden object, an object off the camera's layers, and a pixel that no object covers answer `null` too.
|
|
169
191
|
|
|
170
192
|
A pick that waits for its read when the browser takes the GPU away is rejected with [E1436](../errors/E1436.md). The engine starts a new device, but the frame that recorded the pick drew on the lost one, so the read never lands. Ask for the pick again: the new device answers a new pick. A pick still queued behind it goes to the new device in its turn.
|
|
171
193
|
|
|
@@ -191,7 +213,7 @@ An overlap query tests triangles. A long wall counts only where its surface reac
|
|
|
191
213
|
|
|
192
214
|
## Sprites, points and lines
|
|
193
215
|
|
|
194
|
-
A ray hits [sprites](sprites.md), [points](points.md) and [lines](lines.md) where they draw
|
|
216
|
+
A ray hits [sprites](sprites.md), [points](points.md) and [lines](lines.md) where they draw:
|
|
195
217
|
|
|
196
218
|
| Row | A ray hits it |
|
|
197
219
|
| --- | --- |
|
|
@@ -203,11 +225,13 @@ A ray hits [sprites](sprites.md), [points](points.md) and [lines](lines.md) wher
|
|
|
203
225
|
|
|
204
226
|
A hit's `instance` is the row: the sprite, the point, or the segment. Segment `i` of a strip or a loop joins points `i` and `i + 1`, and the last segment of a loop joins the last point to the first. Segment `i` of a batch of segments joins points `2i` and `2i + 1`. A hit's `triangle` is -1.
|
|
205
227
|
|
|
206
|
-
Sprites face the camera, and sizes in pixels depend on it. So these raycasts need a camera. `scene.raycast` and the other raycasts use the active camera. A pointer event's ray uses the camera of the frame on screen at the event.
|
|
228
|
+
Sprites face the camera, and sizes in pixels depend on it. So these raycasts need a camera. `scene.raycast` and the other raycasts use the active camera. A pointer event's ray uses the camera of the frame on screen at the event.
|
|
229
|
+
|
|
230
|
+
Without an active camera, rays miss sprites, points without `pointThreshold` and lines sized in pixels. A row sized in pixels is hit only between the camera's near and far planes, where the camera draws it.
|
|
207
231
|
|
|
208
|
-
The hit on a sprite or a point's square is the point where the ray crosses it, and its normal faces the camera. A hit near a line, or near a point within a threshold, is the ray's closest point to it
|
|
232
|
+
The hit on a sprite or a point's square is the point where the ray crosses it, and its normal faces the camera. A hit near a line, or near a point within a threshold, is the ray's closest point to it. Its distance is that point's distance along the ray, and its normal points back along the ray. A ray hits a dashed line in its gaps too, and a sprite or a point where its map is clear.
|
|
209
233
|
|
|
210
|
-
`pointThreshold` and `lineThreshold`
|
|
234
|
+
`pointThreshold` and `lineThreshold` make small points and thin lines easier to click. Neither has a default: without one, rays hit what draws.
|
|
211
235
|
|
|
212
236
|
```ts
|
|
213
237
|
// Each star is 3 pixels wide. A click within 0.5 m of a star selects it.
|
|
@@ -226,7 +250,7 @@ Overlap queries do not find sprites, points or lines.
|
|
|
226
250
|
## What queries test
|
|
227
251
|
|
|
228
252
|
- Each object and instance row with a mesh, on the query's layers. Groups, cameras and lights have no mesh. Raycasts also test the sprites, points and line segments in use on the query's layers.
|
|
229
|
-
- Each triangle as its material draws it: front faces only, or both faces for a material with `doubleSided: true`.
|
|
253
|
+
- Each triangle as its material draws it: front faces only, or both faces for a material with `doubleSided: true`.
|
|
230
254
|
- Shown objects only. A hidden object is never hit.
|
|
231
255
|
- The positions of the last frame's update. A move, a new object or a destroy in your `onUpdate` counts from the next frame. In `onLateUpdate`, queries see this frame's positions, but rows of instance batches still have the last frame's positions.
|
|
232
256
|
- Before the first frame, a query applies the objects that `setup` has created and their transforms. A bake that `setup` runs therefore sees the scene as `setup` has built it. Moves that `setup` makes after its first query count from the first frame.
|
|
@@ -251,37 +275,27 @@ A direction can have any length above 0, from 10^-300 to 10^300. The engine make
|
|
|
251
275
|
|
|
252
276
|
## How queries find objects
|
|
253
277
|
|
|
254
|
-
The
|
|
278
|
+
- The first query after a mesh is created builds that mesh's tree. A large mesh can make that first query slow.
|
|
279
|
+
- Static objects are cheap to move. Creating or destroying objects rebuilds the static tree at the next query.
|
|
280
|
+
- Dynamic objects, dynamic batches, sprites, points and lines are rebuilt in each frame that runs a query. A large dynamic batch of particles adds to each such frame. A frame without queries builds nothing.
|
|
281
|
+
- A raycast on layers that hold pixel-sized sprites, points or lines costs more. Keep them on their own layers to keep other raycasts fast.
|
|
282
|
+
- A ray costs about the same in a large scene as in a small one.
|
|
283
|
+
- Objects thousands of kilometers from the origin get the same precision as objects near it.
|
|
255
284
|
|
|
256
|
-
|
|
257
|
-
|
|
285
|
+
<details>
|
|
286
|
+
<summary>Technical details: the query trees</summary>
|
|
258
287
|
|
|
259
|
-
|
|
288
|
+
The engine keeps two levels of trees, in its WebAssembly core. One tree per mesh, over its triangles. Two trees sit over the scene's objects and instance rows. The tree over static objects is built once, and again only after objects are created or destroyed. When a static object moves, the engine adjusts the boxes of its tree instead.
|
|
260
289
|
|
|
261
|
-
The
|
|
290
|
+
The tree over dynamic objects is built again in each frame that runs a query, from all their positions at once. It holds the rows of dynamic batches too, also sprites, points and lines, on every layer.
|
|
262
291
|
|
|
263
|
-
|
|
292
|
+
Each node of a tree has four children, so one SIMD instruction tests a ray against four boxes. A query walks the scene's trees to the objects whose boxes it meets. Then it moves the ray into each object's own space and walks that object's mesh tree. Each object's box comes from its mesh's box, so it holds every triangle.
|
|
264
293
|
|
|
265
|
-
|
|
294
|
+
A three.js `Raycaster` tests each object's bounding sphere in turn, so its rays cost more as the scene grows. The trees hold sprites, points and line segments too. A row sized in pixels takes more room in the world the farther it lies from the camera. A threshold reaches past what a row draws. So when the query's layers hold such rows, the raycast grows each box of the trees as it walks them. A raycast on layers without them costs no more.
|
|
266
295
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
| DOM listeners that raycast for clicks and hover | `object.on('click', handler)` and the other [pointer events on objects](input.md#pointer-events-on-objects) |
|
|
271
|
-
| `raycaster.intersectObjects(scene.children, true)` | `scene.raycastAll(origin, direction, options, hits)` tests the whole scene |
|
|
272
|
-
| `intersects[0]` | `scene.raycast(origin, direction, options, hit)` |
|
|
273
|
-
| `raycaster.far` | `maxDistance` |
|
|
274
|
-
| `raycaster.layers` | `options.layers`, with the same default: layer 0 alone |
|
|
275
|
-
| `raycaster.params.Points.threshold` | `options.pointThreshold`, with no default: without it, a ray hits each point's square |
|
|
276
|
-
| `raycaster.params.Line.threshold` | `options.lineThreshold`, with no default: without it, a ray hits each line within half its width, as `Line2` |
|
|
277
|
-
| `raycaster.camera`, for sprites and `Line2` | The active camera, or the camera of the frame on screen at a pointer event |
|
|
278
|
-
| `intersection.instanceId` | `hit.instance` |
|
|
279
|
-
| `intersection.faceIndex` | `hit.triangle` |
|
|
280
|
-
| `intersection.uv` | `hit.uv`, which `hit.hasUv` says whether to read |
|
|
281
|
-
| `three-mesh-bvh` | Built in: delete its setup |
|
|
282
|
-
| three.js has no pixel pick: its `Raycaster` tests triangles | `scene.pick(x, y)` tests the pixel that the image shows, through the GPU, and returns a promise |
|
|
283
|
-
|
|
284
|
-
three.js tests hidden objects unless you filter them out; null3D never hits them. three.js gives a `Line`'s hit point on the line; null3D gives the point on the ray, as three.js does for `Line2`. three.js's `Line2` ignores `raycaster.far`; null3D's `maxDistance` limits every hit. three.js tests a skinned mesh's animated vertices; null3D tests its bind pose. three.js returns a new array of new objects for each raycast; null3D writes into the objects you pass. three.js tests each object's bounding sphere in turn, so a ray costs more as the scene grows. null3D walks its trees, so a ray costs about the same in a large scene.
|
|
296
|
+
The trees give the same hits as testing every triangle of every object in turn. The engine stores positions relative to grid cells, and each query moves its origin into each cell's frame in 64-bit numbers.
|
|
297
|
+
|
|
298
|
+
</details>
|
|
285
299
|
|
|
286
300
|
## API reference
|
|
287
301
|
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/reference/animation
|
|
3
3
|
title: "Animation: API reference"
|
|
4
|
-
|
|
5
|
-
since: "0.2"
|
|
4
|
+
generated: true
|
|
6
5
|
summary: "Every export of the Animation API, from the engine's doc comments."
|
|
7
6
|
---
|
|
8
7
|
|
|
@@ -43,8 +42,8 @@ Plays an animated object's clips. It fades between them, blends them in layers w
|
|
|
43
42
|
| `readonly timeScale: number` | The rate of the object's animation time: 1 by default, 0 to pause every clip. |
|
|
44
43
|
| `describe(): string` | The object, as error messages name it. |
|
|
45
44
|
| `play(name: string, options?: PlayOptions): void` | Plays a clip. It fades in over `fade` seconds while the other clips of its layer fade out, or with no fade, takes over at once. With a `weight`, it joins the layer's other clips instead. A clip that already plays on the layer keeps its time and fades back in. A clip that played once and reached its end starts again. |
|
|
46
|
-
| `crossFade(name: string, duration: number, options?: PlayOptions): void` | Fades to a clip over `duration` seconds while the layer's other clips fade out,
|
|
47
|
-
| `setWeight(name: string, weight: number): void` | Sets the weight of a clip that plays, 0 or more, on every layer that plays it
|
|
45
|
+
| `crossFade(name: string, duration: number, options?: PlayOptions): void` | Fades to a clip over `duration` seconds while the layer's other clips fade out, and samples them all while the fade runs. It is `play(name, { ...options, fade: duration })`, but it always cross-fades, whatever its `transition`, and a clip with a weight still takes over. |
|
|
46
|
+
| `setWeight(name: string, weight: number): void` | Sets the weight of a clip that plays, 0 or more, on every layer that plays it. A clip at weight 0 leaves the pose but keeps playing, so its time moves on. A fade multiplies the weight. It writes engine memory, so calling it every frame costs nothing. |
|
|
48
47
|
| `playBlend(points: Readonly<Record<string, number>>, options?: BlendOptions): void` | Plays a 1D blend of clips. Each clip counts in full at its point, such as `{ idle: 0, walk: 1.4, run: 4 }` for a blend by speed. Between two points, the two clips around the blend value share it, and `setBlend` moves the value. The clips keep one phase: each clip's time moves at its length over the length of the blend's clips, averaged by their weights. A walk and a run of different lengths then keep their steps together. The layer's other clips fade out over `fade` seconds, as with `play`. |
|
|
49
48
|
| `setBlend(value: number, layer = 0): void` | Sets the blend value of a layer's blend: the clip at that point counts in full, and a value between two points mixes the two clips around it. A value past the first or the last point gives that point's clip. It writes engine memory, so calling it every frame costs nothing. |
|
|
50
49
|
| `stop(name?: string, options?: StopOptions): void` | Stops a clip on every layer, or with no name, every clip, fading out over `fade` seconds. |
|
|
@@ -54,8 +53,8 @@ Plays an animated object's clips. It fades between them, blends them in layers w
|
|
|
54
53
|
| `readonly updateInterval: number` | The frames between two updates of the object's pose. The value 1, the default, updates it in every frame. A larger number samples and composes it once every that many frames, and holds the last pose in between. A far crowd then costs less on the job workers, and, where the skinning pass skips a held pose, on the GPU too. The object's clips keep their real speed. Each update covers the frames that it skipped. |
|
|
55
54
|
| `setUpdateInterval(frames: number): void` | Sets the frames between two updates of the object's pose, a whole number from 1 to 64. The value 1, the default, updates the pose in every frame, which a character near the camera needs. A larger value leaves a far character in the pose of its last update for longer, which steps. Give a crowd's near characters 1 and its far ones more. It writes engine memory, so calling it every frame costs nothing. |
|
|
56
55
|
| `joint(name: string): number` | The index of the joint named `name`, which the joint calls take in place of its name. Look it up once and keep it: an index skips the name lookup in each call. |
|
|
57
|
-
| `setJointRotation(joint: number \| string, rotation: QuatLike, weight = 1): void` | Sets a joint's rotation relative to its parent, as a quaternion `[x, y, z, w]`, on top of the clips. The joint turns from its animated rotation toward this one by `weight`, from 0 to 1. At 1 it takes the rotation
|
|
58
|
-
| `addJointRotation(joint: number \| string, rotation: QuatLike, weight = 1): void` | Turns a joint by a rotation, a quaternion `[x, y, z, w]`, on top of its animated rotation, in the joint's own frame
|
|
56
|
+
| `setJointRotation(joint: number \| string, rotation: QuatLike, weight = 1): void` | Sets a joint's rotation relative to its parent, as a quaternion `[x, y, z, w]`, on top of the clips. The joint turns from its animated rotation toward this one by `weight`, from 0 to 1. At 1 it takes the rotation. The joints below it follow. The rotation holds in every frame until `clearJoint`, so call it again only to change it. It writes engine memory, so calling it every frame costs nothing. |
|
|
57
|
+
| `addJointRotation(joint: number \| string, rotation: QuatLike, weight = 1): void` | Turns a joint by a rotation, a quaternion `[x, y, z, w]`, on top of its animated rotation, in the joint's own frame. `weight`, from 0 to 1, scales the turn. A walking soldier then twists or leans while the clips move it. The turn holds in every frame until `clearJoint`, and calling it every frame costs nothing. |
|
|
59
58
|
| `clearJoint(joint: number \| string): void` | Removes the rotations that `setJointRotation` and `addJointRotation` gave a joint. |
|
|
60
59
|
| `lookAt(target: Vec3Like \| null, options?: LookAtOptions, weight = 1): void` | Turns a chain of joints, such as the spine, neck and head, so that the last one aims at `target`, a point in the world. The engine aims again in each frame from the pose that the clips and the joint rotations give, until `lookAt(null)` stops it. So a soldier keeps its rifle on a target while it walks. `weight`, from 0 to 1, blends the turn with the animated pose. Call it every frame to follow a moving point. The options hold until a call gives others, and a frozen options object is read once, so the call allocates nothing. |
|
|
61
60
|
| `onEvent(name: string, handler: AnimationEventHandler): () => void` | Calls `handler` for each event named `name` that a playing clip reaches: an event in the clip's data, 'loop' when a repeating clip starts again, or 'finished' when a clip that plays once reaches its end. Handlers run on the sketch's thread at the start of the next frame's update, before `onFixedUpdate` and `onUpdate`. Returns a function that removes the handler. |
|
|
@@ -100,10 +99,10 @@ How `Animator.play` plays a clip. A play reads a frozen object once, so a game t
|
|
|
100
99
|
| `loop?: boolean` | True, the default, repeats the clip. False plays it once and holds its last frame. |
|
|
101
100
|
| `speed?: number` | The rate of the clip's time. 1, the default, plays it as made, and 2 twice as fast. A negative rate plays it backward from its end. |
|
|
102
101
|
| `layer?: number` | The layer, a whole number from 0, the default, to 3. Each layer above 0 replaces the pose of the layers below by its weight, on the joints of its mask. |
|
|
103
|
-
| `additive?: boolean` | True adds the clip's change from its first frame to the pose of the layers
|
|
104
|
-
| `time?: number` | Seconds into the clip at which it starts
|
|
105
|
-
| `weight?: number` | The clip's own weight, 0 or more
|
|
106
|
-
| `transition?: 'blend' \| 'inertial'` | How a play with a `fade` switches what its layer plays. `'blend'`, the default, cross-fades the layer's old clips with the new one,
|
|
102
|
+
| `additive?: boolean` | True adds the clip's change from its first frame to the pose of the layers. A breathing or aiming clip then plays on top of a walk. An additive play replaces only the additive clips of its layer, and a plain play only the plain ones. |
|
|
103
|
+
| `time?: number` | Seconds into the clip at which it starts. A repeating clip wraps the time into its length, and a clip that plays once holds it within its length. Without it, a clip starts at its first frame, and a clip that already plays keeps its time. |
|
|
104
|
+
| `weight?: number` | The clip's own weight, 0 or more. A play with a weight joins the other clips of its layer instead of fading them out, so a walk at 0.3 and a run at 0.7 blend. A fade multiplies the weight. Without it, a clip that starts takes 1, and a clip that already plays keeps its weight. |
|
|
105
|
+
| `transition?: 'blend' \| 'inertial'` | How a play with a `fade` switches what its layer plays. `'blend'`, the default, cross-fades the layer's old clips with the new one, and samples both while the fade runs. `'inertial'` samples only the new clip: the pose the layer leaves continues on its path and eases into the new clip, which keeps feet from sliding through a mixed gait. It needs a fade above 0, no `weight`, and a clip already playing on the layer, whose pose it carries on from. A play of a clip that already plays on the layer keeps that clip's time and fades it back in instead, so it is no inertial switch. `crossFade` always cross-fades. |
|
|
107
106
|
|
|
108
107
|
## `PropertyAnimation`
|
|
109
108
|
|
|
@@ -117,7 +116,7 @@ One property's keyframes, playing. `scene.animateProperty` returns one: the engi
|
|
|
117
116
|
| `readonly playing: boolean` | True while the animation runs. |
|
|
118
117
|
| `readonly loop: boolean` | True when the animation repeats, and false when it holds its last key. |
|
|
119
118
|
| `readonly speed: number` | The rate of the animation's time: 1 plays it as made, and a negative rate plays it backward. |
|
|
120
|
-
| `setTime(seconds: number): void` | Sets the animation's time in seconds
|
|
119
|
+
| `setTime(seconds: number): void` | Sets the animation's time in seconds. |
|
|
121
120
|
| `setPaused(paused: boolean): void` | Starts or stops the time, without changing the value that the target holds. |
|
|
122
121
|
| `setLoop(loop: boolean): void` | Repeats the animation, or makes it hold its last key at its end. |
|
|
123
122
|
| `setSpeed(speed: number): void` | Sets the rate of the animation's time: 1 plays it as made, and 2 twice as fast. A negative rate plays it backward. |
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/reference/assets
|
|
3
3
|
title: "Assets: API reference"
|
|
4
|
-
|
|
5
|
-
since: "0.1"
|
|
4
|
+
generated: true
|
|
6
5
|
summary: "Every export of the Assets API, from the engine's doc comments."
|
|
7
6
|
---
|
|
8
7
|
|
|
@@ -19,23 +18,23 @@ Loads files, and textures from image files. Every call runs outside the sketch's
|
|
|
19
18
|
| Member | Description |
|
|
20
19
|
| --- | --- |
|
|
21
20
|
| `loadTexture(url: string \| URL, options: LoadTextureOptions = {}): Promise<Texture>` | Downloads an image file or a KTX2 file, decodes it off the sketch's frames, and makes a texture from it. The browser decodes PNG, JPEG, WebP and AVIF files. A KTX2 file of ETC1S or UASTC data becomes the compressed format that the device supports, with the file's mip levels, and UASTC HDR data becomes BC6H or shared-exponent floats. The first KTX2 file loads the transcoder. The engine keeps the transcoded texels in its cache of derived data, so a later load of a file with the same bytes, on this visit or a later one, skips the transcoder. Throws E1411 when the file does not download, E1413 when a server of another origin does not allow the page to read it, E1412 when the file does not decode or passes a limit of the engine's (a KTX2 file larger than the device's textures, before it transcodes), E1406 when the transcoder does not load, and E1208 for options the engine does not know. |
|
|
22
|
-
| `registerGltfExtension(handler: GltfExtensionHandler): () => void` | Registers a handler for glTF extensions that an add-on reads
|
|
21
|
+
| `registerGltfExtension(handler: GltfExtensionHandler): () => void` | Registers a handler for glTF extensions that an add-on reads. A file that carries one of the handler's extensions hands each primitive that holds one to the handler, and draws the parts that it returns. A file that requires such an extension loads with the handler and fails with E1417 without it. Register the handler before the first load that needs it. Returns a function that unregisters it. Throws E1213 for a handler without a list of extension names or a `load` function, and for one that reads an extension which another handler reads. |
|
|
23
22
|
| `loadGltf(url: string \| URL, options: LoadGltfOptions = {}): Promise<Prefab>` | Downloads a glTF 2.0 model, a `.glb` file or a `.gltf` file with the files it names, and makes a prefab of it: its meshes, materials, textures, lights and nodes, made once, which `scene.instantiate` copies. A worker parses the file off the sketch's frames, and the first call downloads the loader and its worker. The first file with meshopt compression also downloads the meshopt decoder. The loads count for `onProgress`, the files the model names too, and they take files that `preload` downloaded. Throws E1411 when a file does not download, E1413 when a server of another origin does not allow the page to read it, E1416 for a file that is not a glTF model the engine reads or that passes a limit on what one file may decode to, E1417 for a file that requires an extension the engine does not read, E1412 when an image does not decode, E1109 when a mesh does not fit engine memory, and E1406 when the loader or the meshopt decoder does not download. `options.rewriteUrl` checks the addresses that the file names. |
|
|
24
23
|
| `loadImageBitmap(url: string \| URL, options: LoadImageOptions = {}): Promise<ImageBitmap>` | Downloads an image file and decodes it into an `ImageBitmap`, off the sketch's frames. By default it decodes as `loadTexture` does, so `textures.fromImageBitmap` makes the same texture. Throws E1411, E1412 or E1413 as `loadTexture` does. |
|
|
25
|
-
| `loadCubemap(urls: readonly (string \| URL)[]): Promise<Cubemap>` | Downloads six images and makes a `Cubemap` from them, a sky box for `scene.setBackground
|
|
26
|
-
| `loadLut(url: string \| URL): Promise<Lut>` | Downloads a color grading table in a `.cube` or a `.3dl` file and makes a `Lut` from it, for `post.set({ lut })`. It reads
|
|
27
|
-
| `lutFromData(table: LutData): Promise<Lut>` | Makes a color grading table from numbers, for `post.set({ lut })
|
|
28
|
-
| `loadEnvironment(url: string \| URL): Promise<Environment>` | Downloads an environment and makes an `Environment` from it, for `scene.setEnvironment`. It takes a KTX2 file that `bunx |
|
|
29
|
-
| `builtinEnvironment(name: BuiltinEnvironmentName): Promise<Environment>` | Makes a built-in environment: `room`,
|
|
30
|
-
| `skyEnvironment(): Promise<Environment>` | Makes an environment of the scene's sky, the sky that `scene.setBackground({ sky })` draws
|
|
24
|
+
| `loadCubemap(urls: readonly (string \| URL)[]): Promise<Cubemap>` | Downloads six images and makes a `Cubemap` from them, a sky box for `scene.setBackground`: the faces toward +X, -X, +Y, -Y, +Z and -Z, in that order, each square and of one size, at most 2,048 pixels a side. 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. The images decode off the sketch's frames and upload in the frames after the call. A cube map does not light the scene: for light, and for a background that blurs, make an environment with `bunx @null3d/cli assets env`. Throws E1411, E1412 or E1413 as `loadTexture` does, E1412 also when the faces are not square or not of one size, and E1208 when `urls` does not hold six addresses. |
|
|
25
|
+
| `loadLut(url: string \| URL): Promise<Lut>` | Downloads a color grading table in a `.cube` or a `.3dl` file and makes a `Lut` from it, for `post.set({ lut })`. It reads tables of 2 to 256 texels a side. A `.cube` file's domain and title come along; a `.3dl` file's values are whole numbers of the depth that its largest value or its `Mesh` line gives. The first table loads the readers. Throws E1411 or E1413 as `loadTexture` does, E1412 when the file holds no table that the engine reads, and E1406 when the readers do not load. |
|
|
26
|
+
| `lutFromData(table: LutData): Promise<Lut>` | Makes a color grading table from numbers, for `post.set({ lut })`. It takes the numbers in the order of a `.cube` file: three or four per texel, red changing fastest. A file and its numbers make the same table. The first table loads the code that makes it, as `loadLut` does. Throws E1208 when the size is not a whole number from 2 to 256, when `data` does not hold three or four numbers per texel, or holds a number that is not finite, and when a domain is not three numbers whose maximum is above its minimum. Throws E1406 when the code does not load. |
|
|
27
|
+
| `loadEnvironment(url: string \| URL): Promise<Environment>` | Downloads an environment and makes an `Environment` from it, for `scene.setEnvironment`. It takes a KTX2 file that `bunx @null3d/cli assets env` made, the fast path, or an HDR file: a Radiance file (`.hdr`) or an OpenEXR file (`.exr`) of an equirectangular panorama. A KTX2 map's cube texture uploads in the frames after the call, and the scene draws without the environment until it is on the GPU. A worker reads an HDR file, off the sketch's frames. The GPU then filters it for each roughness, with the asset tool's filter, in the next frame, before that frame draws: call it while the scene loads, since a call during play makes one long frame. Light brighter than a 16-bit float keeps its share of the rough reflections and the diffuse light, and the sharpest level stops at 65,408, as in the tool's files. The first file of each kind loads its reader. Throws E1411 or E1413 as `loadTexture` does, E1412 when the file is not one that the engine reads, and E1406 when a reader does not load. |
|
|
28
|
+
| `builtinEnvironment(name: BuiltinEnvironmentName): Promise<Environment>` | Makes a built-in environment: `room`, a white room with boxes and glowing panels, for soft, neutral light with no file of your own. No file downloads: the GPU draws the room into its cube map and filters it for each roughness. It resolves once the code and the shaders that make the map are ready. The next frame then makes the whole map before it draws, so the first frame with the environment already has its light. That frame takes longer, by the map's GPU time: call it while the scene loads, since a call during play makes one long frame. The first one loads the code that makes it, about 12 KB after Brotli. Throws E1213 for a name that no built-in environment has, and E1406 when its code does not download. |
|
|
29
|
+
| `skyEnvironment(): Promise<Environment>` | Makes an environment of the scene's sky, the sky that `scene.setBackground({ sky })` draws. Light it with `scene.setEnvironment`. The map follows the sky: when the sketch moves the sun or changes the air or the clouds, the map refreshes over the next frames, and no call is needed. Until the scene's first sky background, it shows the sky's defaults. The map leaves out the sun's disc: the scene's directional light gives the sun's own light. The GPU draws the sky into the map and filters it for each roughness, and the CPU works out its diffuse light. It resolves once the code and the shaders that make the map are ready, and the next frame makes the whole map before it draws. The first call loads the code that makes environments, about 12 KB after Brotli. Throws E1406 when that code does not download. |
|
|
31
30
|
| `loadLightProbeGrid(url: string \| URL): Promise<LightProbeGridOptions>` | Downloads a probe grid that a tool outside the engine baked, in the [baked light file](../../guides/baked-light-data.md) format, and makes the texture and the placement that `scene.setLightProbeGrid` takes. The grid's coefficients are the four RGB values of L1 spherical harmonics per probe, in the shader's order. The first grid loads the reader, about 2 KB after Brotli. Throws E1411 or E1413 as `loadTexture` does, E1434 when the file is not a probe grid that this engine reads, and E1406 when the reader does not load. |
|
|
32
31
|
| `loadLightMap(url: string \| URL): Promise<LightMapData>` | Downloads a light map that a tool outside the engine baked, in the [baked light file](../../guides/baked-light-data.md) format. It gives the radiance as a texture for a material's `lightMap`, and, for a directional light map, the light's direction at each texel as a second texture for the same material's `lightMapDirection`. The first light map loads the reader, about 2 KB after Brotli. Throws E1411 or E1413 as `loadTexture` does, E1434 when the file is not a light map that this engine reads, and E1406 when the reader does not load. |
|
|
33
32
|
| `lightProbeGridFile(grid: LightProbeGridData): Promise<Uint8Array>` | Makes the file of a probe grid that `bakeProbes` made, in the [baked light file](../../guides/baked-light-data.md) format, as bytes to save or send. The file holds the same values that `loadLightProbeGrid` reads, so a bake in the browser and a bake in another tool give one format. The first call loads the writer, about 2 KB after Brotli. Throws E1108 when the grid's coefficients do not hold 12 numbers for each probe in its counts, or its masks do not hold one number for each probe, and E1406 when the writer does not load. |
|
|
34
33
|
| `loadJson<T = unknown>(url: string \| URL): Promise<T>` | Downloads a JSON file and parses it. Throws E1411 or E1413 as `loadTexture` does, and E1412 when the file is not valid JSON. |
|
|
35
34
|
| `loadBinary(url: string \| URL): Promise<ArrayBuffer>` | Downloads a file as bytes. Throws E1411 or E1413 as `loadTexture` does. |
|
|
36
35
|
| `cache(name: string, version: string \| number): DerivedCache` | A namespace of the cache of derived data: bytes that a sketch or an add-on makes from its inputs, kept in the browser's storage across visits, such as a generated terrain or grown plants. `name` names the producer, such as an add-on's package name. `version` is the version of the bytes it makes: the first call with a new version deletes the entries of the others. Key each entry by every input that the bytes depend on, such as a hash of their content. The calls never reject, and answer no entry when the cache is off or the storage fails, so the caller makes its data again. The same name and version give the same namespace. |
|
|
37
|
-
| `preload(urls: readonly (string \| URL)[]): Promise<void>` | Downloads files ahead of their loads, all at once, and resolves when every one has arrived. The next load of each address takes its file from memory. Pair it with `onProgress` for a loading screen. Throws the error of the first file that fails, as `loadBinary` does. |
|
|
38
|
-
| `onProgress(handler: ProgressHandler): () => void` | Calls `handler` as a download's bytes arrive and when one finishes or fails, with the bytes downloaded so far, the bytes expected so far and the address whose bytes moved, as `ProgressHandler` describes. Loads that take a file that `preload` downloaded report no further. Returns a function that removes the handler. |
|
|
36
|
+
| `preload(urls: readonly (string \| URL)[]): Promise<void>` | Downloads files ahead of their loads, all at once, and resolves when every one has arrived. The next load of each address takes its file from memory. Pair it with `onProgress` for a loading screen. For the files that the setup loads, name them in `defineSketch`'s `downloads` option instead, which starts them sooner. Throws the error of the first file that fails, as `loadBinary` does, and the next load of that file downloads it again. |
|
|
37
|
+
| `onProgress(handler: ProgressHandler): () => void` | Calls `handler` as a download's bytes arrive and when one finishes or fails, with the bytes downloaded so far, the bytes expected so far and the address whose bytes moved, as `ProgressHandler` describes. The files of `defineSketch`'s `downloads` option count too, from before the setup adds the handler. Loads that take a file that `preload` or that option downloaded report no further. Returns a function that removes the handler. |
|
|
39
38
|
|
|
40
39
|
## `BuiltinEnvironmentName`
|
|
41
40
|
|
|
@@ -43,13 +42,13 @@ Loads files, and textures from image files. Every call runs outside the sketch's
|
|
|
43
42
|
type BuiltinEnvironmentName = 'room';
|
|
44
43
|
```
|
|
45
44
|
|
|
46
|
-
The names of the built-in environments that `assets.builtinEnvironment` loads. `room` is
|
|
45
|
+
The names of the built-in environments that `assets.builtinEnvironment` loads. `room` is a white room with six boxes and glowing panels, lit by one point light. It is slightly blurred, and gives soft, neutral light.
|
|
47
46
|
|
|
48
47
|
## `Cubemap`
|
|
49
48
|
|
|
50
49
|
Class `Cubemap`.
|
|
51
50
|
|
|
52
|
-
A cube map of six images, which `assets.loadCubemap` loads, for a sky box behind every object: `scene.setBackground(cubemap)
|
|
51
|
+
A cube map of six images, which `assets.loadCubemap` loads, for a sky box behind every object: `scene.setBackground(cubemap)`. The engine reads the faces as seen from inside the cube, mirrored across x. It does not light the scene: light comes from an environment.
|
|
53
52
|
|
|
54
53
|
| Member | Description |
|
|
55
54
|
| --- | --- |
|
|
@@ -74,7 +73,7 @@ A namespace of the cache of derived data, which `assets.cache` gives: bytes by k
|
|
|
74
73
|
|
|
75
74
|
Class `Environment`.
|
|
76
75
|
|
|
77
|
-
An environment map, which `assets.loadEnvironment` and `assets.builtinEnvironment` load. It holds the light around a scene from every direction, filtered for each roughness, and the diffuse light that it gives. Give it to `scene.setEnvironment`, which lights standard materials with it
|
|
76
|
+
An environment map, which `assets.loadEnvironment` and `assets.builtinEnvironment` load. It holds the light around a scene from every direction, filtered for each roughness, and the diffuse light that it gives. Give it to `scene.setEnvironment`, which lights standard materials with it.
|
|
78
77
|
|
|
79
78
|
| Member | Description |
|
|
80
79
|
| --- | --- |
|
|
@@ -120,7 +119,7 @@ What the loader hands a glTF extension handler for one primitive.
|
|
|
120
119
|
|
|
121
120
|
Interface `GltfExtensionHandler`.
|
|
122
121
|
|
|
123
|
-
A handler for the glTF extensions that an add-on reads
|
|
122
|
+
A handler for the glTF extensions that an add-on reads. Register it with `assets.registerGltfExtension` before the first load of a model that carries the extension.
|
|
124
123
|
|
|
125
124
|
| Member | Description |
|
|
126
125
|
| --- | --- |
|
|
@@ -176,7 +175,7 @@ A light map from `assets.loadLightMap`: its radiance texture, ready for a materi
|
|
|
176
175
|
| `readonly width: number` | The texels across. |
|
|
177
176
|
| `readonly height: number` | The texels down. |
|
|
178
177
|
| `readonly texture: Texture` | The radiance, as a texture that a material takes as `lightMap`. |
|
|
179
|
-
| `readonly direction: Int8Array \| undefined` | Three signed bytes per texel, from -127 to 127
|
|
178
|
+
| `readonly direction: Int8Array \| undefined` | Three signed bytes per texel, from -127 to 127: each axis of the direction times 127. It runs from the same first texel as the radiance, and it is undefined for a light map without a direction. |
|
|
180
179
|
| `readonly directionTexture: Texture \| undefined` | The direction at each texel, in linear color: its red, green and blue map the direction's x, y and z from -1 to 1. It has the radiance's size, format and color space, so the engine reads it through the light map's own texture binding; give it to a material beside the radiance as `lightMapDirection`. It is undefined for a light map without a direction. |
|
|
181
180
|
|
|
182
181
|
## `LightMapEncoding`
|
|
@@ -195,7 +194,7 @@ The options of `assets.loadGltf`.
|
|
|
195
194
|
|
|
196
195
|
| Member | Description |
|
|
197
196
|
| --- | --- |
|
|
198
|
-
| `rewriteUrl?: (address: URL) => URL \| string \| null` | Checks or changes each address that the file names, for a buffer or an image, before it downloads. It gets the address resolved against the file's own, and returns the address to download, or null to refuse the file with E1416. A model that a user uploads can name any address, which the page then requests with its cookies, so a page that loads such models should allow only the addresses it expects.
|
|
197
|
+
| `rewriteUrl?: (address: URL) => URL \| string \| null` | Checks or changes each address that the file names, for a buffer or an image, before it downloads. It gets the address resolved against the file's own, and returns the address to download, or null to refuse the file with E1416. A model that a user uploads can name any address, which the page then requests with its cookies, so a page that loads such models should allow only the addresses it expects. |
|
|
199
198
|
| `maxLevels?: number` | The most levels of detail to load from a file that stores its levels as separate downloads, counting the level in the file itself. A band of a cluster tree counts as a level. The default loads every level, and the loader skips a level that the camera never draws. A page whose objects never come close enough to show the finest level sets 1, or the number of levels that show, and downloads less. A file whose levels are all in the file itself ignores the option. |
|
|
200
199
|
|
|
201
200
|
## `LoadImageOptions`
|
|
@@ -218,14 +217,14 @@ The options of `assets.loadTexture`: how the image decodes, and the texture's op
|
|
|
218
217
|
|
|
219
218
|
| Member | Description |
|
|
220
219
|
| --- | --- |
|
|
221
|
-
| `flipY?: boolean` | True to put the image's top row at v = 1, the top of a plane
|
|
222
|
-
| `premultipliedAlpha?: boolean` | True to store each color multiplied by its alpha
|
|
220
|
+
| `flipY?: boolean` | True to put the image's top row at v = 1, the top of a plane. The default is true. glTF textures use false. A KTX2 file keeps the rows as it holds them, its first row at v = 0: encode it flipped, as `basisu -y_flip` does, for a plane. It takes no `flipY: true`. |
|
|
221
|
+
| `premultipliedAlpha?: boolean` | True to store each color multiplied by its alpha. The default is false. A KTX2 file takes no `premultipliedAlpha: true`. |
|
|
223
222
|
|
|
224
223
|
## `Lut`
|
|
225
224
|
|
|
226
225
|
Class `Lut`.
|
|
227
226
|
|
|
228
|
-
A color grading table, which `assets.loadLut` loads from a file and `assets.lutFromData` makes from numbers. It is a 3D texture that maps each color of the picture to its graded color. Give it to `post.set({ lut })`, which applies it to every pixel after the tone mapping
|
|
227
|
+
A color grading table, which `assets.loadLut` loads from a file and `assets.lutFromData` makes from numbers. It is a 3D texture that maps each color of the picture to its graded color. Give it to `post.set({ lut })`, which applies it to every pixel after the tone mapping.
|
|
229
228
|
|
|
230
229
|
| Member | Description |
|
|
231
230
|
| --- | --- |
|
|
@@ -270,7 +269,7 @@ A model that `assets.loadGltf` loaded: a template whose meshes, materials and te
|
|
|
270
269
|
| `readonly bounds: PrefabBounds` | The bounds of the whole model, around the origin of its copies. |
|
|
271
270
|
| `readonly materials: readonly Material[]` | The model's materials, in the file's order. |
|
|
272
271
|
| `readonly textures: readonly Texture[]` | The model's textures, in the order that its materials first sample them: each material's base color, then its metalness and roughness, its normals, its occlusion and its emission. A texture that an earlier material or slot already samples comes once. `find` gives a node's own textures by slot. |
|
|
273
|
-
| `destroy(): void` | Destroys the model
|
|
272
|
+
| `destroy(): void` | Destroys the model. It frees the GPU memory and the engine data of every mesh, material and texture that the load made, and of its skeleton and animation clips. Destroy the copies that `scene.instantiate` and `scene.createInstances` made first, and the objects that use one of its meshes or materials, in the same frame or before. Throws E1111 while one still does, and E1101 for a model that is destroyed already. Materials of your own that map one of the model's textures draw with their colors alone afterwards. Later calls that pass the model throw E1101. |
|
|
274
273
|
| `readonly clips: readonly string[]` | The names of the model's clips, which a copy's animator plays. |
|
|
275
274
|
| `find(name: string): PrefabNode \| undefined` | The first node with `name`, in the file's order, or undefined when no node has it. The nodes of a copy have the same names, and its `find` gives them. |
|
|
276
275
|
|
|
@@ -332,4 +331,8 @@ Called as a download's bytes arrive and when one finishes or fails. It gets the
|
|
|
332
331
|
function registerGltfExtension(handler: GltfExtensionHandler): () => void
|
|
333
332
|
```
|
|
334
333
|
|
|
335
|
-
Registers a handler for the glTF extensions that an add-on reads, for every sketch of this thread. An add-on calls it once as its module loads, so a page that imports the add-on loads the add-on's files with no other call. Returns a function that unregisters the handler.
|
|
334
|
+
Registers a handler for the glTF extensions that an add-on reads, for every sketch of this thread. An add-on calls it once as its module loads, so a page that imports the add-on loads the add-on's files with no other call. Returns a function that unregisters the handler.
|
|
335
|
+
|
|
336
|
+
A later handler for an extension replaces the earlier one, which a development reload of the add-on's module needs. Two add-ons that read one extension therefore give it to the one that loaded last. A sketch that reads one extension in one scene alone uses `assets.registerGltfExtension` instead.
|
|
337
|
+
|
|
338
|
+
Throws E1213 for a handler without a list of extension names or a `load` function.
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/reference/cameras
|
|
3
3
|
title: "Cameras: API reference"
|
|
4
|
-
|
|
5
|
-
since: "0.1"
|
|
4
|
+
generated: true
|
|
6
5
|
summary: "Every export of the Cameras API, from the engine's doc comments."
|
|
7
6
|
---
|
|
8
7
|
|
|
@@ -23,6 +22,8 @@ An object that the scene can be drawn from. `scene.setActiveCamera` picks the ca
|
|
|
23
22
|
| `readonly far: number` | The distance to the far clipping plane. |
|
|
24
23
|
| `setLayers(mask: number): void` | Sets the layers the camera draws, as a 32-bit mask: it draws the objects whose masks share a layer with it. The default, 1, draws layer 0, where every object starts. |
|
|
25
24
|
| `setNearFar(near: number, far: number): void` | Sets the distances to the near and far clipping planes. |
|
|
25
|
+
| `readonly lensShift: readonly [number, number]` | The lens shift: how far the view sits right of and above the camera's axis, as fractions of the view's width and height. The array is the camera's own and changes with `setLensShift`, so copy it to keep a value. |
|
|
26
|
+
| `setLensShift(x: number, y: number): void` | Moves the view off the camera's axis, as a shift lens on a real camera does: right by `x` times the view's width, and up by `y` times its height. The perspective stays as it is, so the image is a crop of a wider view from the same place. A shift of 0.25 across puts the camera's axis, and a `target` it looks at, a quarter of the width left of the middle. Culling, shadows, picking, `screenToRay`, `worldToScreen`, views and labels all follow the shifted view. The default is no shift. It allocates nothing. |
|
|
26
27
|
| `screenToRay(x: number, y: number, out: Ray): void` | Writes the ray from the camera through a point on the canvas into `out`: `x` and `y` are CSS pixels from the canvas's top-left corner, as `input.pointer` gives them. A perspective ray starts at the camera, and an orthographic ray on the near plane. The direction has length 1. When the point is the position of the pointer or a finger from `input`, the ray uses the camera of the frame that was on screen at that event, if the engine still keeps it. It keeps the last four views, and frames in a row with the same view count as one. So a click during a fast pan picks what the user saw. Any other point uses the camera of the frame that last ran, with its lens as it is now. Objects stay where they are now, so a moving object can be up to a frame of its motion away from where the user saw it. |
|
|
27
28
|
| `worldToScreen(point: Vec3Like, out: Vec3Like): void` | Writes where a point in the world lies on the canvas into `out`: x and y in CSS pixels from the canvas's top-left corner, then the point's depth, its distance in front of the camera along the view. A depth below 0 puts the point behind the camera, where x and y have no meaning. It uses the camera of the frame that last ran, with its lens as it is now, so in `onLateUpdate` it places points where the frame draws them. |
|
|
28
29
|
|
|
@@ -49,13 +50,13 @@ A camera whose view is a box: things keep their size at every distance, as in ma
|
|
|
49
50
|
| `readonly isOrthographic: true` | True: an orthographic camera. |
|
|
50
51
|
| `readonly height: number` | The view's height in world units. |
|
|
51
52
|
| `readonly width: number \| undefined` | The view's width in world units, or undefined when the width follows the canvas's aspect ratio. |
|
|
52
|
-
| `setOrthoHeight(height: number): void` | Sets the view's height in world units. A width that follows the canvas keeps following it. A view made from four edges scales about its center and keeps its shape
|
|
53
|
+
| `setOrthoHeight(height: number): void` | Sets the view's height in world units. A width that follows the canvas keeps following it. A view made from four edges scales about its center and keeps its shape. |
|
|
53
54
|
|
|
54
55
|
## `OrthographicCameraOptions`
|
|
55
56
|
|
|
56
57
|
Interface `OrthographicCameraOptions`, which extends `CameraOptions`.
|
|
57
58
|
|
|
58
|
-
Options for `scene.createOrthographicCamera`. Give `height`, and the width follows the canvas's aspect ratio. Or give all four edges,
|
|
59
|
+
Options for `scene.createOrthographicCamera`. Give `height`, and the width follows the canvas's aspect ratio. Or give all four edges, for a view that keeps its shape on any canvas.
|
|
59
60
|
|
|
60
61
|
| Member | Description |
|
|
61
62
|
| --- | --- |
|
|
@@ -113,6 +114,9 @@ A view of the scene from its own camera, drawn into a rectangle of the canvas af
|
|
|
113
114
|
| `readonly rect: SceneViewRect` | The rectangle of the canvas that the view draws into. |
|
|
114
115
|
| `setCamera(camera: Camera): void` | Draws the view from `camera` from the next frame on. It takes the camera's layers, and follows them when they change. |
|
|
115
116
|
| `setRect(rect: SceneViewRect): void` | Draws the view into `rect` from the next frame on. It allocates nothing, so a sketch can change the rectangle in any frame. Development builds throw E1203 for a number that is not finite, and E1213 for a rectangle outside the canvas. |
|
|
117
|
+
| `screenToRay(x: number, y: number, out: Ray): void` | Writes the ray from the view's camera through a point of the view's image into `out`: `x` and `y` are CSS pixels from the canvas's top-left corner, as `camera.screenToRay` takes them, and as `input.pointer` gives them. The lens takes the shape of the view's rectangle, as the view draws it, so a click on the view's image picks what the view shows. A perspective ray starts at the camera, and an orthographic ray on the near plane. The direction has length 1. It uses the camera of the frame that last ran, with its lens as it is now. A point outside the rectangle gives the ray that the view's lens would give there. `scene.viewAt` finds the view under a point. Development builds throw E1101 for a view that was removed, and E1203 for a number that is not finite. |
|
|
118
|
+
| `worldToScreen(point: Vec3Like, out: Vec3Like): void` | Writes where a point in the world lies in the view's image into `out`: x and y in CSS pixels from the canvas's top-left corner, then the point's depth, its distance in front of the view's camera along the view. A depth below 0 puts the point behind the camera, where x and y have no meaning. The lens takes the shape of the view's rectangle. A point outside the view's sight lands outside the rectangle. Development builds throw E1101 for a view that was removed, and E1203 for a number that is not finite. |
|
|
119
|
+
| `contains(x: number, y: number): boolean` | True when the point (`x`, `y`) in CSS pixels from the canvas's top-left corner lies in the view's rectangle, its left and top edges included. |
|
|
116
120
|
| `destroy(): void` | Removes the view from the next frame on. The camera's view draws the canvas alone again. Development builds throw E1101 for a view that was removed. |
|
|
117
121
|
|
|
118
122
|
## `SceneViewOptions`
|