@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/lib/shared/labels.js
CHANGED
|
@@ -45,7 +45,8 @@ export const LABEL3D_STATE = 12;
|
|
|
45
45
|
* The frame's camera, as the page needs it to build the perspective that turns a 3D label's matrix
|
|
46
46
|
* into a place on the canvas: the inverse of its world matrix's 3 × 3 part, row by row; the camera's
|
|
47
47
|
* position; half the view's height at one unit in front of a perspective camera, or across an
|
|
48
|
-
* orthographic view; 1 for an orthographic lens;
|
|
48
|
+
* orthographic view; 1 for an orthographic lens; that view's center; and the lens shift, as fractions
|
|
49
|
+
* of the view's width and height.
|
|
49
50
|
*/
|
|
50
51
|
export const CAMERA_ROTATION = 0;
|
|
51
52
|
export const CAMERA_POSITION = 9;
|
|
@@ -53,7 +54,9 @@ export const CAMERA_HALF_HEIGHT = 12;
|
|
|
53
54
|
export const CAMERA_ORTHO = 13;
|
|
54
55
|
export const CAMERA_CENTER_X = 14;
|
|
55
56
|
export const CAMERA_CENTER_Y = 15;
|
|
56
|
-
export const
|
|
57
|
+
export const CAMERA_SHIFT_X = 16;
|
|
58
|
+
export const CAMERA_SHIFT_Y = 17;
|
|
59
|
+
export const CAMERA_FLOATS = 18;
|
|
57
60
|
/** The header's words, before the tables. */
|
|
58
61
|
const SEQUENCE = 0;
|
|
59
62
|
const FRAME = 1;
|
package/lib/shared/metrics.d.ts
CHANGED
|
@@ -44,6 +44,20 @@ export declare const RING_RECORDS = 1024;
|
|
|
44
44
|
* would time the same phase every time, and skip or always catch the frames that draw it.
|
|
45
45
|
*/
|
|
46
46
|
export declare const SAMPLED_EVERY = 11;
|
|
47
|
+
/**
|
|
48
|
+
* The steps of the start of the thread that draws, in the order that the header keeps their epoch
|
|
49
|
+
* times, in ms:
|
|
50
|
+
*
|
|
51
|
+
* - `request`: the page's message after the probe arrived, and the thread started the downloads of
|
|
52
|
+
* its renderers and shader files, and on WebGPU the request for its device.
|
|
53
|
+
* - `adapter`: its WebGPU adapter arrived.
|
|
54
|
+
* - `device`: its WebGPU device arrived.
|
|
55
|
+
* - `shaders`: the shader file of its device arrived.
|
|
56
|
+
* - `init`: the core and the thread's setup arrived from the page.
|
|
57
|
+
* - `renderer`: its first renderer was built, so its frame loop could start.
|
|
58
|
+
*/
|
|
59
|
+
export declare const DRAWING_STEPS: readonly ["request", "adapter", "device", "shaders", "init", "renderer"];
|
|
60
|
+
export type DrawingStep = (typeof DRAWING_STEPS)[number];
|
|
47
61
|
/** A metrics buffer with rings for the sketch, render and GPU roles and each job worker. */
|
|
48
62
|
export declare function createMetricsBuffer(shared: boolean, jobWorkers: number, capacity?: number): ArrayBufferLike;
|
|
49
63
|
/**
|
|
@@ -64,6 +78,20 @@ export declare function memoryFigures(buffer: ArrayBufferLike): Float64Array;
|
|
|
64
78
|
* uses and has used at most, and all are 0 until the page asks for a report.
|
|
65
79
|
*/
|
|
66
80
|
export declare function memoryAreaFigures(buffer: ArrayBufferLike): Float64Array;
|
|
81
|
+
/**
|
|
82
|
+
* The epoch times of the steps of the start of the thread that draws, in the order of
|
|
83
|
+
* `DRAWING_STEPS`. The thread notes its first steps before the page has handed it the metrics
|
|
84
|
+
* buffer, and writes them there once it has it. Each step keeps its first time, so the renderer that
|
|
85
|
+
* a GPU loss replaces moves no step.
|
|
86
|
+
*/
|
|
87
|
+
export declare class DrawingSteps {
|
|
88
|
+
private readonly times;
|
|
89
|
+
private header;
|
|
90
|
+
/** Notes the time of `step`, once. */
|
|
91
|
+
mark(step: DrawingStep): void;
|
|
92
|
+
/** Writes the times noted so far into the header of `buffer`, and each later one as it comes. */
|
|
93
|
+
publish(buffer: ArrayBufferLike): void;
|
|
94
|
+
}
|
|
67
95
|
/** The display's refresh rate in hertz, as the thread that draws measured it, or 0 before then. */
|
|
68
96
|
export declare function refreshRate(buffer: ArrayBufferLike): number;
|
|
69
97
|
/** Writes one role's records. Only one thread writes a given ring. */
|
|
@@ -143,6 +171,11 @@ export declare class FrameRecorder {
|
|
|
143
171
|
* waited for.
|
|
144
172
|
*/
|
|
145
173
|
markFirstFrame(drawMs: number): void;
|
|
174
|
+
/**
|
|
175
|
+
* True once the GPU has finished the first frame, as the thread that draws records it. It reads
|
|
176
|
+
* the time without returning it, so a check in each frame allocates nothing.
|
|
177
|
+
*/
|
|
178
|
+
get firstFrameDone(): boolean;
|
|
146
179
|
/**
|
|
147
180
|
* Records, once per engine, when the sketch's setup function started, as epoch milliseconds, so
|
|
148
181
|
* the page can time a scene that is still growing.
|
|
@@ -199,6 +232,11 @@ export declare class MetricsReader {
|
|
|
199
232
|
get setupStart(): number;
|
|
200
233
|
/** Milliseconds that the sketch's setup function took, or null while it runs. */
|
|
201
234
|
get setupMs(): number | null;
|
|
235
|
+
/**
|
|
236
|
+
* Epoch milliseconds at which the thread that draws reached `step` of its start, or 0 before it
|
|
237
|
+
* did, or where it takes no such step.
|
|
238
|
+
*/
|
|
239
|
+
drawingStep(step: DrawingStep): number;
|
|
202
240
|
/**
|
|
203
241
|
* Epoch milliseconds at which the first frame's pipelines started to build, or 0 before the
|
|
204
242
|
* thread that draws first checked that frame.
|
package/lib/shared/metrics.js
CHANGED
|
@@ -141,7 +141,29 @@ const AREA_VALUES = MEMORY_AREA_COUNT * MEMORY_AREA_VALUES;
|
|
|
141
141
|
const SETUP_START = MEMORY_AREAS + AREA_VALUES;
|
|
142
142
|
/** Float64 index of the time, in ms, that the sketch's setup function took, or 0 until it ends. */
|
|
143
143
|
const SETUP_MS = SETUP_START + 1;
|
|
144
|
-
|
|
144
|
+
/**
|
|
145
|
+
* The steps of the start of the thread that draws, in the order that the header keeps their epoch
|
|
146
|
+
* times, in ms:
|
|
147
|
+
*
|
|
148
|
+
* - `request`: the page's message after the probe arrived, and the thread started the downloads of
|
|
149
|
+
* its renderers and shader files, and on WebGPU the request for its device.
|
|
150
|
+
* - `adapter`: its WebGPU adapter arrived.
|
|
151
|
+
* - `device`: its WebGPU device arrived.
|
|
152
|
+
* - `shaders`: the shader file of its device arrived.
|
|
153
|
+
* - `init`: the core and the thread's setup arrived from the page.
|
|
154
|
+
* - `renderer`: its first renderer was built, so its frame loop could start.
|
|
155
|
+
*/
|
|
156
|
+
export const DRAWING_STEPS = [
|
|
157
|
+
'request',
|
|
158
|
+
'adapter',
|
|
159
|
+
'device',
|
|
160
|
+
'shaders',
|
|
161
|
+
'init',
|
|
162
|
+
'renderer',
|
|
163
|
+
];
|
|
164
|
+
/** Float64 index of the epoch time of the first step of the start of the thread that draws. */
|
|
165
|
+
const DRAWING_START = SETUP_MS + 1;
|
|
166
|
+
const HEADER_WORDS = 2 * (DRAWING_START + DRAWING_STEPS.length);
|
|
145
167
|
const WRITTEN = HEADER_WORDS;
|
|
146
168
|
function recordsStart(rings) {
|
|
147
169
|
return Math.ceil((HEADER_WORDS + rings) / RECORD_WORDS) * RECORD_WORDS;
|
|
@@ -216,6 +238,31 @@ export function memoryFigures(buffer) {
|
|
|
216
238
|
export function memoryAreaFigures(buffer) {
|
|
217
239
|
return new Float64Array(buffer, MEMORY_AREAS * 8, AREA_VALUES);
|
|
218
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* The epoch times of the steps of the start of the thread that draws, in the order of
|
|
243
|
+
* `DRAWING_STEPS`. The thread notes its first steps before the page has handed it the metrics
|
|
244
|
+
* buffer, and writes them there once it has it. Each step keeps its first time, so the renderer that
|
|
245
|
+
* a GPU loss replaces moves no step.
|
|
246
|
+
*/
|
|
247
|
+
export class DrawingSteps {
|
|
248
|
+
times = new Float64Array(DRAWING_STEPS.length);
|
|
249
|
+
header;
|
|
250
|
+
/** Notes the time of `step`, once. */
|
|
251
|
+
mark(step) {
|
|
252
|
+
const k = DRAWING_STEPS.indexOf(step);
|
|
253
|
+
if (this.times[k] !== 0)
|
|
254
|
+
return;
|
|
255
|
+
const now = performance.timeOrigin + performance.now();
|
|
256
|
+
this.times[k] = now;
|
|
257
|
+
if (this.header)
|
|
258
|
+
this.header[DRAWING_START + k] = now;
|
|
259
|
+
}
|
|
260
|
+
/** Writes the times noted so far into the header of `buffer`, and each later one as it comes. */
|
|
261
|
+
publish(buffer) {
|
|
262
|
+
this.header = new Float64Array(buffer, 0, HEADER_WORDS / 2);
|
|
263
|
+
this.header.set(this.times, DRAWING_START);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
219
266
|
/** The display's refresh rate in hertz, as the thread that draws measured it, or 0 before then. */
|
|
220
267
|
export function refreshRate(buffer) {
|
|
221
268
|
return new Float64Array(buffer, 0, HEADER_WORDS / 2)[REFRESH_HZ];
|
|
@@ -372,6 +419,13 @@ export class FrameRecorder {
|
|
|
372
419
|
times[FIRST_FRAME_PIPELINES] = words[this.at + COUNTERS + Counter.Pipelines];
|
|
373
420
|
times[FIRST_DRAW] = drawMs;
|
|
374
421
|
}
|
|
422
|
+
/**
|
|
423
|
+
* True once the GPU has finished the first frame, as the thread that draws records it. It reads
|
|
424
|
+
* the time without returning it, so a check in each frame allocates nothing.
|
|
425
|
+
*/
|
|
426
|
+
get firstFrameDone() {
|
|
427
|
+
return this.views.times[FIRST_FRAME_DONE] > 0;
|
|
428
|
+
}
|
|
375
429
|
/**
|
|
376
430
|
* Records, once per engine, when the sketch's setup function started, as epoch milliseconds, so
|
|
377
431
|
* the page can time a scene that is still growing.
|
|
@@ -466,6 +520,13 @@ export class MetricsReader {
|
|
|
466
520
|
const ms = this.views.times[SETUP_MS];
|
|
467
521
|
return ms > 0 ? ms : null;
|
|
468
522
|
}
|
|
523
|
+
/**
|
|
524
|
+
* Epoch milliseconds at which the thread that draws reached `step` of its start, or 0 before it
|
|
525
|
+
* did, or where it takes no such step.
|
|
526
|
+
*/
|
|
527
|
+
drawingStep(step) {
|
|
528
|
+
return this.views.times[DRAWING_START + DRAWING_STEPS.indexOf(step)];
|
|
529
|
+
}
|
|
469
530
|
/**
|
|
470
531
|
* Epoch milliseconds at which the first frame's pipelines started to build, or 0 before the
|
|
471
532
|
* thread that draws first checked that frame.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// The permutation words that a page draws with, on the dev server. In a development build, the
|
|
2
|
+
// thread that draws hands each word to the page once, without the bits that a device fixes, and
|
|
3
|
+
// the engine fires an event with it on the page's global object. The null3D Vite plugin's client
|
|
4
|
+
// module sends the word to the dev server, which compares it with the project's shader list and
|
|
5
|
+
// warns about a word that the list lacks. The file imports nothing, so the plugin's tests read it
|
|
6
|
+
// too.
|
|
7
|
+
/** The event on the page's global object that carries a word that the page draws with. */
|
|
8
|
+
export const PERMUTATION_WORD_EVENT = 'null3d:permutation';
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/** The file's first four bytes, which name the format. */
|
|
2
2
|
export declare const RECORDING_MAGIC = 1311982674;
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* The format's version, which a reader refuses when it is newer than its own. Version 2 adds the
|
|
5
|
+
* sketch's start data; a reader takes version 1 as a recording without it.
|
|
6
|
+
*/
|
|
7
|
+
export declare const RECORDING_VERSION = 2;
|
|
5
8
|
/** The most sketch time that a recording keeps, in seconds. */
|
|
6
9
|
export declare const MAX_RECORDING_SECONDS = 600;
|
|
7
10
|
/** The numbers of one event, as the recording stores them side by side: type, code, flags, id,
|
|
@@ -33,6 +36,8 @@ export interface ReplayProgram {
|
|
|
33
36
|
fixedRate: number;
|
|
34
37
|
/** The sketch's address when it was recorded, for a message about a different scene. */
|
|
35
38
|
sketch: string;
|
|
39
|
+
/** The start data that the sketch had, as JSON text, or undefined when it had none. */
|
|
40
|
+
data?: string;
|
|
36
41
|
/** True when the recording stopped at its limit before the session ended. */
|
|
37
42
|
stopped: boolean;
|
|
38
43
|
/** Each frame's step in seconds, which sums to the frame's sketch time. */
|
|
@@ -83,14 +88,17 @@ export declare class Recorder {
|
|
|
83
88
|
private growFrames;
|
|
84
89
|
private growEvents;
|
|
85
90
|
/**
|
|
86
|
-
* The file's bytes: the session's seed, the statistics that a replay needs, the
|
|
87
|
-
* the keys that the input used, and each frame's step with the input
|
|
91
|
+
* The file's bytes: the session's seed, the statistics that a replay needs, the sketch's start
|
|
92
|
+
* data, the dictionary of the keys that the input used, and each frame's step with the input
|
|
93
|
+
* that the sketch read.
|
|
88
94
|
*
|
|
89
|
-
* @param header The fixed rate of the sketch's fixed updates,
|
|
95
|
+
* @param header The fixed rate of the sketch's fixed updates, the sketch's address, and its
|
|
96
|
+
* start data as JSON text.
|
|
90
97
|
*/
|
|
91
98
|
encode(header: {
|
|
92
99
|
fixedRate: number;
|
|
93
100
|
sketch: string;
|
|
101
|
+
data?: string;
|
|
94
102
|
}): Uint8Array;
|
|
95
103
|
}
|
|
96
104
|
/**
|
package/lib/shared/recording.js
CHANGED
|
@@ -2,16 +2,21 @@
|
|
|
2
2
|
// a small binary file that replays on another machine to the same frames. The file holds the time
|
|
3
3
|
// of every frame as a step, delta-coded, and a dictionary of the keys that the input used. Replay
|
|
4
4
|
// runs the frames from the first one, with the sketch's setup as it started, so a session on a
|
|
5
|
-
// phone reproduces on a computer.
|
|
5
|
+
// phone reproduces on a computer. The file keeps the start data that the page gave the sketch, so
|
|
6
|
+
// the replay's setup reads the same data.
|
|
6
7
|
//
|
|
7
8
|
// The recorder lives on the sketch's thread, so it records what the sketch read, not what the page
|
|
8
9
|
// sent. A frame with no input costs sixteen bytes in its frame arrays and nine in the file: the
|
|
9
10
|
// step's eight-byte number and a one-byte count.
|
|
10
11
|
import { EVENT_KEY_DOWN, EVENT_KEY_UP } from './control.js';
|
|
12
|
+
import { MAX_SKETCH_DATA_BYTES } from './sketch-data.js';
|
|
11
13
|
/** The file's first four bytes, which name the format. */
|
|
12
14
|
export const RECORDING_MAGIC = 0x4e334452;
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
+
/**
|
|
16
|
+
* The format's version, which a reader refuses when it is newer than its own. Version 2 adds the
|
|
17
|
+
* sketch's start data; a reader takes version 1 as a recording without it.
|
|
18
|
+
*/
|
|
19
|
+
export const RECORDING_VERSION = 2;
|
|
15
20
|
/** The most sketch time that a recording keeps, in seconds. */
|
|
16
21
|
export const MAX_RECORDING_SECONDS = 600;
|
|
17
22
|
/** The most frames and input records that a recording keeps, so a broken page cannot exhaust memory. */
|
|
@@ -19,6 +24,8 @@ const MAX_FRAMES = 2_000_000;
|
|
|
19
24
|
const MAX_EVENTS = 1_000_000;
|
|
20
25
|
/** The flag that marks a recording that stopped at its limit before the session ended. */
|
|
21
26
|
const FLAG_STOPPED = 1;
|
|
27
|
+
/** The flag that marks a recording whose header holds the sketch's start data. */
|
|
28
|
+
const FLAG_DATA = 2;
|
|
22
29
|
/** The numbers of one event, as the recording stores them side by side: type, code, flags, id,
|
|
23
30
|
* buttons, x and y. */
|
|
24
31
|
export const EVENT_STRIDE = 7;
|
|
@@ -262,19 +269,23 @@ export class Recorder {
|
|
|
262
269
|
this.events = events;
|
|
263
270
|
}
|
|
264
271
|
/**
|
|
265
|
-
* The file's bytes: the session's seed, the statistics that a replay needs, the
|
|
266
|
-
* the keys that the input used, and each frame's step with the input
|
|
272
|
+
* The file's bytes: the session's seed, the statistics that a replay needs, the sketch's start
|
|
273
|
+
* data, the dictionary of the keys that the input used, and each frame's step with the input
|
|
274
|
+
* that the sketch read.
|
|
267
275
|
*
|
|
268
|
-
* @param header The fixed rate of the sketch's fixed updates,
|
|
276
|
+
* @param header The fixed rate of the sketch's fixed updates, the sketch's address, and its
|
|
277
|
+
* start data as JSON text.
|
|
269
278
|
*/
|
|
270
279
|
encode(header) {
|
|
271
|
-
const out = new ByteWriter(64 + this.frameCount * 8);
|
|
280
|
+
const out = new ByteWriter(64 + (header.data?.length ?? 0) + this.frameCount * 8);
|
|
272
281
|
out.u32(RECORDING_MAGIC);
|
|
273
282
|
out.u8(RECORDING_VERSION);
|
|
274
|
-
out.u8(this.stopped ? FLAG_STOPPED : 0);
|
|
283
|
+
out.u8((this.stopped ? FLAG_STOPPED : 0) | (header.data === undefined ? 0 : FLAG_DATA));
|
|
275
284
|
out.u16(header.fixedRate);
|
|
276
285
|
out.u32(this.seed);
|
|
277
286
|
out.text(header.sketch);
|
|
287
|
+
if (header.data !== undefined)
|
|
288
|
+
out.text(header.data);
|
|
278
289
|
out.varint(this.keyNames.length);
|
|
279
290
|
for (const name of this.keyNames)
|
|
280
291
|
out.text(name);
|
|
@@ -313,12 +324,21 @@ export function decodeRecording(bytes) {
|
|
|
313
324
|
if (bytes.length < 4 || reader.u32() !== RECORDING_MAGIC)
|
|
314
325
|
throw new RecordingError('the file is not a null3D recording: it does not start with the format marker. Save the recording again, or ask for a new one.');
|
|
315
326
|
const version = reader.u8();
|
|
316
|
-
if (version
|
|
317
|
-
throw new RecordingError(`the file holds recording version ${version}, and this engine reads
|
|
327
|
+
if (version < 1 || version > RECORDING_VERSION)
|
|
328
|
+
throw new RecordingError(`the file holds recording version ${version}, and this engine reads versions 1 to ${RECORDING_VERSION}. Replay it with the engine that recorded it, or with a newer one.`);
|
|
318
329
|
const flags = reader.u8();
|
|
319
330
|
const fixedRate = whole(reader.u16(), 'the fixed step rate', 1, 1000);
|
|
320
331
|
const seed = reader.u32();
|
|
321
332
|
const sketch = reader.text(4096);
|
|
333
|
+
const data = (flags & FLAG_DATA) === 0 ? undefined : reader.text(MAX_SKETCH_DATA_BYTES);
|
|
334
|
+
if (data !== undefined) {
|
|
335
|
+
try {
|
|
336
|
+
JSON.parse(data);
|
|
337
|
+
}
|
|
338
|
+
catch {
|
|
339
|
+
throw new RecordingError("the file's start data for the sketch is not JSON text. Download it again, or record a new session.");
|
|
340
|
+
}
|
|
341
|
+
}
|
|
322
342
|
const keyCount = whole(reader.varint(), 'the dictionary of keys', 0, 512);
|
|
323
343
|
const keyNames = [];
|
|
324
344
|
for (let k = 0; k < keyCount; k++)
|
|
@@ -367,6 +387,7 @@ export function decodeRecording(bytes) {
|
|
|
367
387
|
seed,
|
|
368
388
|
fixedRate,
|
|
369
389
|
sketch,
|
|
390
|
+
data,
|
|
370
391
|
stopped: (flags & FLAG_STOPPED) !== 0,
|
|
371
392
|
steps,
|
|
372
393
|
starts,
|
package/lib/shared/run-task.js
CHANGED
|
@@ -54,7 +54,13 @@ export function runTask(task, input, transfer = NO_TRANSFER) {
|
|
|
54
54
|
if (loaded)
|
|
55
55
|
return loaded.runTaskWithError(task, input, transfer, engineError);
|
|
56
56
|
taskStarted();
|
|
57
|
-
|
|
57
|
+
if (!loader) {
|
|
58
|
+
// The loader's file imports the thread's list of helper workers, which the bundler can put
|
|
59
|
+
// in a file of its own. A worker finds that file only once the loader's has arrived, so it
|
|
60
|
+
// is asked for here, beside the loader, rather than one round trip after it.
|
|
61
|
+
import('./helper-workers.js').catch(() => { });
|
|
62
|
+
loader = import('./tasks.js');
|
|
63
|
+
}
|
|
58
64
|
const answer = loader.then((module) => {
|
|
59
65
|
loaded = module;
|
|
60
66
|
return module.runTaskWithError(task, input, transfer, engineError);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** The most bytes that the start data takes as JSON text, in UTF-8. */
|
|
2
|
+
export declare const MAX_SKETCH_DATA_BYTES = 65536;
|
|
3
|
+
/**
|
|
4
|
+
* The JSON text of `data`, or undefined for no data. Plain objects, arrays, strings, finite numbers,
|
|
5
|
+
* booleans and null pass, and a property whose value is undefined is left out, as JSON leaves it.
|
|
6
|
+
* Any other value fails with E1213, which names where it sits: JSON would change it or drop it, so
|
|
7
|
+
* the sketch and a replay would see other data than the page gave.
|
|
8
|
+
*/
|
|
9
|
+
export declare function sketchDataText(data: unknown): string | undefined;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// The start data that a page gives its sketch: plain JSON data, which travels to the sketch's thread
|
|
2
|
+
// as one string in the start message and which a recording keeps as the same text. The sketch's
|
|
3
|
+
// thread parses the text once, so the sketch gets its own copy on every thread.
|
|
4
|
+
import { EngineError } from '../errors/engine-error.js';
|
|
5
|
+
/** The most bytes that the start data takes as JSON text, in UTF-8. */
|
|
6
|
+
export const MAX_SKETCH_DATA_BYTES = 65_536;
|
|
7
|
+
/**
|
|
8
|
+
* The JSON text of `data`, or undefined for no data. Plain objects, arrays, strings, finite numbers,
|
|
9
|
+
* booleans and null pass, and a property whose value is undefined is left out, as JSON leaves it.
|
|
10
|
+
* Any other value fails with E1213, which names where it sits: JSON would change it or drop it, so
|
|
11
|
+
* the sketch and a replay would see other data than the page gave.
|
|
12
|
+
*/
|
|
13
|
+
export function sketchDataText(data) {
|
|
14
|
+
if (data === undefined)
|
|
15
|
+
return undefined;
|
|
16
|
+
checkValue(data, 'sketchData', new Set());
|
|
17
|
+
const text = JSON.stringify(data);
|
|
18
|
+
const bytes = new TextEncoder().encode(text).length;
|
|
19
|
+
if (bytes > MAX_SKETCH_DATA_BYTES)
|
|
20
|
+
throw new EngineError('E1213', `createEngine() got sketchData of ${bytes.toLocaleString('en')} bytes as JSON, over the limit of ${MAX_SKETCH_DATA_BYTES.toLocaleString('en')}. Pass a small start state, and load larger data in the sketch as a file.`);
|
|
21
|
+
return text;
|
|
22
|
+
}
|
|
23
|
+
/** Throws E1213 when `value`, at `path` in the data, is not plain JSON data. */
|
|
24
|
+
function checkValue(value, path, parents) {
|
|
25
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean')
|
|
26
|
+
return;
|
|
27
|
+
if (typeof value === 'number') {
|
|
28
|
+
if (Number.isFinite(value))
|
|
29
|
+
return;
|
|
30
|
+
refuse(path, String(value));
|
|
31
|
+
}
|
|
32
|
+
if (typeof value !== 'object')
|
|
33
|
+
refuse(path, `a ${typeof value}`);
|
|
34
|
+
if (parents.has(value))
|
|
35
|
+
refuse(path, 'an object that holds it');
|
|
36
|
+
parents.add(value);
|
|
37
|
+
if (Array.isArray(value)) {
|
|
38
|
+
for (let index = 0; index < value.length; index++) {
|
|
39
|
+
const item = value[index];
|
|
40
|
+
if (item === undefined)
|
|
41
|
+
refuse(`${path}[${index}]`, 'undefined');
|
|
42
|
+
checkValue(item, `${path}[${index}]`, parents);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const prototype = Object.getPrototypeOf(value);
|
|
47
|
+
if (prototype !== Object.prototype && prototype !== null)
|
|
48
|
+
refuse(path, `a ${value.constructor?.name ?? 'class instance'}`);
|
|
49
|
+
for (const [key, item] of Object.entries(value))
|
|
50
|
+
if (item !== undefined)
|
|
51
|
+
checkValue(item, `${path}.${key}`, parents);
|
|
52
|
+
}
|
|
53
|
+
parents.delete(value);
|
|
54
|
+
}
|
|
55
|
+
function refuse(path, what) {
|
|
56
|
+
throw new EngineError('E1213', `createEngine() got sketchData where ${path} is ${what}. sketchData takes plain JSON data: objects, arrays, strings, finite numbers, booleans and null.`);
|
|
57
|
+
}
|
|
@@ -8,5 +8,17 @@ export declare function tasksPending(): number;
|
|
|
8
8
|
export declare function planStarted(label: string): number;
|
|
9
9
|
/** Stops counting the level plan with number `plan`, once its levels are in or it ended. */
|
|
10
10
|
export declare function planEnded(plan: number): void;
|
|
11
|
+
/**
|
|
12
|
+
* Resolves when the level plan with number `plan` may hand over its levels: at once, unless hold
|
|
13
|
+
* mode holds the plans back. Then it resolves once hold mode has let the plans go and every plan
|
|
14
|
+
* that started before this one has ended.
|
|
15
|
+
*/
|
|
16
|
+
export declare function planTurn(plan: number): Promise<void>;
|
|
17
|
+
/** Holds every plan's levels back from now on, until `releasePlans`, as hold mode asks. */
|
|
18
|
+
export declare function holdPlans(): void;
|
|
19
|
+
/** Lets the plans that hold mode held back hand over their levels, one at a time in their order. */
|
|
20
|
+
export declare function releasePlans(): void;
|
|
21
|
+
/** Ends hold mode's hold on the plans: each plan hands over its levels as it answers again. */
|
|
22
|
+
export declare function endPlanHold(): void;
|
|
11
23
|
/** The labels of the level plans that wait. */
|
|
12
24
|
export declare function plansPending(): string[];
|
|
@@ -4,11 +4,22 @@
|
|
|
4
4
|
// plans of meshes made in code count as tasks too, each with a label that names its mesh, so a
|
|
5
5
|
// held frame can wait for them all the way and say which meshes still plan. The count is the
|
|
6
6
|
// thread's, so the tasks that the sketch's own copy of the engine runs count too.
|
|
7
|
+
//
|
|
8
|
+
// Hold mode also holds the plans' levels back until it lets them go, and then lets one plan hand
|
|
9
|
+
// over its levels at a time, in the order the plans started. A plan answers whenever its job
|
|
10
|
+
// worker finishes, and the meshes of its levels take their places in engine memory as it hands
|
|
11
|
+
// them over, so plans that handed over as they answered would leave the scene's meshes in another
|
|
12
|
+
// order on each run.
|
|
7
13
|
/** The key of the thread's count on its global object. */
|
|
8
14
|
const PENDING = Symbol.for('null3d.pendingTasks');
|
|
9
15
|
const thread = globalThis;
|
|
10
16
|
/** The thread's count. The first copy of this module in the thread makes it. */
|
|
11
|
-
const pending = thread[PENDING] ?? {
|
|
17
|
+
const pending = thread[PENDING] ?? {
|
|
18
|
+
tasks: 0,
|
|
19
|
+
plans: new Map(),
|
|
20
|
+
lastPlan: 0,
|
|
21
|
+
turns: new Map(),
|
|
22
|
+
};
|
|
12
23
|
thread[PENDING] = pending;
|
|
13
24
|
/** Counts a task that waits for its answer. */
|
|
14
25
|
export function taskStarted() {
|
|
@@ -34,6 +45,55 @@ export function planStarted(label) {
|
|
|
34
45
|
export function planEnded(plan) {
|
|
35
46
|
if (pending.plans.delete(plan))
|
|
36
47
|
taskEnded();
|
|
48
|
+
pending.turns.delete(plan);
|
|
49
|
+
nextTurn();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Resolves when the level plan with number `plan` may hand over its levels: at once, unless hold
|
|
53
|
+
* mode holds the plans back. Then it resolves once hold mode has let the plans go and every plan
|
|
54
|
+
* that started before this one has ended.
|
|
55
|
+
*/
|
|
56
|
+
export function planTurn(plan) {
|
|
57
|
+
if (pending.released === undefined)
|
|
58
|
+
return Promise.resolve();
|
|
59
|
+
return new Promise((resolve) => {
|
|
60
|
+
pending.turns.set(plan, resolve);
|
|
61
|
+
nextTurn();
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/** Holds every plan's levels back from now on, until `releasePlans`, as hold mode asks. */
|
|
65
|
+
export function holdPlans() {
|
|
66
|
+
pending.released = false;
|
|
67
|
+
}
|
|
68
|
+
/** Lets the plans that hold mode held back hand over their levels, one at a time in their order. */
|
|
69
|
+
export function releasePlans() {
|
|
70
|
+
if (pending.released === false)
|
|
71
|
+
pending.released = true;
|
|
72
|
+
nextTurn();
|
|
73
|
+
}
|
|
74
|
+
/** Ends hold mode's hold on the plans: each plan hands over its levels as it answers again. */
|
|
75
|
+
export function endPlanHold() {
|
|
76
|
+
pending.released = undefined;
|
|
77
|
+
const waiting = [...pending.turns.values()];
|
|
78
|
+
pending.turns.clear();
|
|
79
|
+
for (const turn of waiting)
|
|
80
|
+
turn();
|
|
81
|
+
}
|
|
82
|
+
/** Gives the turn to the oldest plan that is still pending, once it waits for it. */
|
|
83
|
+
function nextTurn() {
|
|
84
|
+
if (pending.released !== true)
|
|
85
|
+
return;
|
|
86
|
+
let oldest;
|
|
87
|
+
for (const plan of pending.plans.keys())
|
|
88
|
+
if (oldest === undefined || plan < oldest)
|
|
89
|
+
oldest = plan;
|
|
90
|
+
if (oldest === undefined)
|
|
91
|
+
return;
|
|
92
|
+
const turn = pending.turns.get(oldest);
|
|
93
|
+
if (!turn)
|
|
94
|
+
return;
|
|
95
|
+
pending.turns.delete(oldest);
|
|
96
|
+
turn();
|
|
37
97
|
}
|
|
38
98
|
/** The labels of the level plans that wait. */
|
|
39
99
|
export function plansPending() {
|