@null3d/engine 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/wasm/single/null3d.js +10 -8
- package/dist/wasm/single/null3d_bg.wasm +0 -0
- package/dist/wasm/threaded/null3d.js +10 -8
- package/dist/wasm/threaded/null3d_bg.wasm +0 -0
- package/docs/api/animation.md +96 -24
- package/docs/api/assets.md +99 -29
- package/docs/api/cameras.md +38 -7
- package/docs/api/controls.md +47 -23
- package/docs/api/debug.md +105 -35
- package/docs/api/engine.md +108 -32
- package/docs/api/feature-draws.md +21 -15
- package/docs/api/feature-effects.md +8 -8
- package/docs/api/feature-instances.md +68 -17
- package/docs/api/features.md +68 -37
- package/docs/api/geometry.md +83 -14
- package/docs/api/grass.md +55 -13
- package/docs/api/impostors.md +92 -50
- package/docs/api/input.md +22 -9
- package/docs/api/lights.md +67 -16
- package/docs/api/lines.md +38 -13
- package/docs/api/materials.md +187 -59
- package/docs/api/math.md +6 -6
- package/docs/api/objects.md +40 -15
- package/docs/api/page.md +58 -7
- package/docs/api/particles.md +36 -11
- package/docs/api/points.md +18 -8
- package/docs/api/post.md +57 -23
- package/docs/api/quality.md +36 -16
- package/docs/api/raycast.md +57 -24
- package/docs/api/reference/animation.md +1 -2
- package/docs/api/reference/assets.md +7 -4
- package/docs/api/reference/cameras.md +3 -2
- package/docs/api/reference/controls.md +59 -2
- package/docs/api/reference/debug.md +58 -6
- package/docs/api/reference/engine.md +40 -10
- package/docs/api/reference/feature-draws.md +3 -4
- package/docs/api/reference/feature-effects.md +2 -3
- package/docs/api/reference/feature-instances.md +5 -4
- package/docs/api/reference/features.md +7 -4
- package/docs/api/reference/geometry.md +132 -21
- package/docs/api/reference/grass.md +62 -2
- package/docs/api/reference/impostors.md +120 -16
- package/docs/api/reference/input.md +1 -2
- package/docs/api/reference/lights.md +4 -3
- package/docs/api/reference/lines.md +3 -4
- package/docs/api/reference/materials.md +7 -6
- package/docs/api/reference/math.md +13 -2
- package/docs/api/reference/objects.md +2 -3
- package/docs/api/reference/particles.md +31 -6
- package/docs/api/reference/points.md +2 -3
- package/docs/api/reference/post.md +4 -3
- package/docs/api/reference/quality.md +1 -2
- package/docs/api/reference/raycast.md +1 -2
- package/docs/api/reference/render.md +4 -3
- package/docs/api/reference/scene.md +24 -5
- package/docs/api/reference/sketch.md +11 -11
- package/docs/api/reference/sound.md +33 -2
- package/docs/api/reference/splats.md +42 -3
- package/docs/api/reference/sprites.md +2 -3
- package/docs/api/reference/tasks.md +16 -3
- package/docs/api/reference/terrain.md +26 -5
- package/docs/api/reference/textures.md +1 -2
- package/docs/api/reference/three-compat.md +18 -7
- package/docs/api/reference/time.md +1 -2
- package/docs/api/reference/ui.md +10 -7
- package/docs/api/reference/vertex-draws.md +2 -3
- package/docs/api/reference/water.md +78 -5
- package/docs/api/reference/wind.md +15 -2
- package/docs/api/render.md +67 -25
- package/docs/api/scene.md +129 -36
- package/docs/api/sketch.md +45 -19
- package/docs/api/sound.md +48 -12
- package/docs/api/splats.md +42 -15
- package/docs/api/sprites.md +8 -6
- package/docs/api/tasks.md +31 -22
- package/docs/api/terrain.md +44 -12
- package/docs/api/textures.md +61 -12
- package/docs/api/three-compat.md +15 -7
- package/docs/api/time.md +3 -5
- package/docs/api/ui.md +18 -10
- package/docs/api/vertex-draws.md +13 -12
- package/docs/api/water.md +111 -67
- package/docs/api/wind.md +61 -15
- package/docs/cli/null3d.md +90 -15
- package/docs/concepts/architecture.md +69 -23
- package/docs/concepts/assets.md +57 -16
- package/docs/concepts/backends.md +68 -24
- package/docs/concepts/color-management.md +42 -13
- package/docs/concepts/culling.md +68 -47
- package/docs/concepts/handles.md +14 -5
- package/docs/concepts/instances.md +72 -23
- package/docs/concepts/large-worlds.md +17 -7
- package/docs/concepts/lighting.md +117 -44
- package/docs/concepts/lod.md +128 -33
- package/docs/concepts/materials.md +43 -12
- package/docs/concepts/particle-buffer.md +48 -35
- package/docs/concepts/post-processing.md +77 -14
- package/docs/concepts/quality-preset-tables.md +3 -2
- package/docs/concepts/quality-presets.md +122 -39
- package/docs/concepts/render-graph.md +56 -21
- package/docs/concepts/render-layers.md +9 -5
- package/docs/concepts/shadows.md +96 -25
- package/docs/concepts/static-dynamic.md +22 -7
- package/docs/cookbook/index.md +163 -119
- package/docs/data/threejs-mapping.json +301 -340
- package/docs/errors/E1101.md +23 -5
- package/docs/errors/E1102.md +11 -3
- package/docs/errors/E1103.md +11 -3
- package/docs/errors/E1104.md +11 -3
- package/docs/errors/E1105.md +13 -5
- package/docs/errors/E1106.md +11 -3
- package/docs/errors/E1107.md +15 -5
- package/docs/errors/E1108.md +11 -3
- package/docs/errors/E1109.md +32 -6
- package/docs/errors/E1110.md +23 -5
- package/docs/errors/E1111.md +11 -3
- package/docs/errors/E1112.md +11 -3
- package/docs/errors/E1203.md +12 -4
- package/docs/errors/E1204.md +11 -3
- package/docs/errors/E1205.md +11 -3
- package/docs/errors/E1206.md +28 -6
- package/docs/errors/E1207.md +11 -3
- package/docs/errors/E1208.md +12 -3
- package/docs/errors/E1209.md +11 -3
- package/docs/errors/E1213.md +27 -5
- package/docs/errors/E1214.md +11 -3
- package/docs/errors/E1215.md +31 -6
- package/docs/errors/E1216.md +31 -6
- package/docs/errors/E1217.md +29 -6
- package/docs/errors/E1218.md +22 -6
- package/docs/errors/E1219.md +11 -3
- package/docs/errors/E1220.md +24 -5
- package/docs/errors/E1221.md +24 -5
- package/docs/errors/E1222.md +11 -3
- package/docs/errors/E1223.md +39 -6
- package/docs/errors/E1224.md +11 -3
- package/docs/errors/E1225.md +11 -3
- package/docs/errors/E1301.md +11 -3
- package/docs/errors/E1302.md +11 -3
- package/docs/errors/E1303.md +11 -3
- package/docs/errors/E1304.md +11 -3
- package/docs/errors/E1305.md +13 -3
- package/docs/errors/E1306.md +11 -3
- package/docs/errors/E1307.md +23 -6
- package/docs/errors/E1308.md +31 -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 +11 -3
- package/docs/errors/E1421.md +11 -3
- package/docs/errors/E1422.md +12 -3
- package/docs/errors/E1423.md +12 -3
- package/docs/errors/E1424.md +24 -5
- package/docs/errors/E1425.md +11 -3
- package/docs/errors/E1426.md +11 -3
- package/docs/errors/E1430.md +11 -3
- package/docs/errors/E1431.md +11 -3
- package/docs/errors/E1432.md +11 -3
- package/docs/errors/E1433.md +11 -3
- package/docs/errors/E1434.md +15 -6
- package/docs/errors/E1435.md +11 -3
- package/docs/errors/E1436.md +11 -3
- package/docs/errors/E1437.md +14 -6
- package/docs/errors/E1501.md +41 -6
- package/docs/errors/E1502.md +13 -3
- package/docs/errors/E1503.md +11 -3
- package/docs/errors/E1504.md +11 -3
- package/docs/errors/E1505.md +23 -5
- package/docs/errors/E1506.md +11 -3
- package/docs/errors/index.md +53 -29
- package/docs/getting-started/cdn.md +15 -9
- package/docs/getting-started/first-scene.md +20 -12
- package/docs/getting-started/hosting.md +113 -63
- package/docs/getting-started/install.md +39 -24
- package/docs/getting-started/network-use.md +31 -21
- package/docs/getting-started/project-structure.md +20 -8
- package/docs/getting-started/third-party-notices.md +6 -10
- package/docs/guides/accessibility.md +4 -4
- package/docs/guides/add-ons.md +83 -13
- package/docs/guides/agents.md +13 -14
- package/docs/guides/assets-pipeline.md +294 -72
- package/docs/guides/audio.md +17 -15
- package/docs/guides/baked-light-data.md +44 -23
- package/docs/guides/car-paint.md +37 -31
- package/docs/guides/content-pages.md +86 -29
- package/docs/guides/custom-passes.md +59 -17
- package/docs/guides/custom-shaders.md +54 -37
- package/docs/guides/debugging.md +31 -41
- package/docs/guides/deploying.md +10 -27
- package/docs/guides/deterministic-simulation.md +23 -16
- package/docs/guides/first-use-shaders.md +83 -45
- package/docs/guides/lens-kit.md +29 -26
- package/docs/guides/loading-screens.md +74 -30
- package/docs/guides/multiple-views.md +22 -11
- package/docs/guides/performance.md +188 -37
- package/docs/guides/phones.md +71 -19
- package/docs/guides/physics.md +6 -10
- package/docs/guides/screens.md +41 -29
- package/docs/guides/start-time.md +126 -85
- package/docs/guides/testing.md +137 -98
- package/docs/guides/ui-overlays.md +17 -12
- package/docs/guides/video-textures.md +14 -13
- package/docs/images/api/animation/character.webp +0 -0
- package/docs/images/api/animation/look-at-ring.webp +0 -0
- package/docs/images/api/animation/morph-tulips.webp +0 -0
- package/docs/images/api/animation/skeleton-lines.webp +0 -0
- package/docs/images/api/controls/gizmo-handles.webp +0 -0
- package/docs/images/api/controls/walk-and-fly.webp +0 -0
- package/docs/images/api/debug/debug-shapes.webp +0 -0
- package/docs/images/api/debug/levels-view.webp +0 -0
- package/docs/images/api/engine/transparent-canvas.webp +0 -0
- package/docs/images/api/feature-draws/feature-draw-clouds.webp +0 -0
- package/docs/images/api/feature-instances/compute-instances.webp +0 -0
- package/docs/images/api/feature-instances/instances-shadow.webp +0 -0
- package/docs/images/api/geometry/extra-shapes.webp +0 -0
- package/docs/images/api/geometry/generators.webp +0 -0
- package/docs/images/api/geometry/mesh-arrays.webp +0 -0
- package/docs/images/api/geometry/vertex-updates.webp +0 -0
- package/docs/images/api/grass/grass-grove.webp +0 -0
- package/docs/images/api/grass/grass-presets.webp +0 -0
- package/docs/images/api/grass/grass-shadow.webp +0 -0
- package/docs/images/api/impostors/impostor-handover.webp +0 -0
- package/docs/images/api/impostors/impostor-shadow.webp +0 -0
- package/docs/images/api/impostors/impostors-forest.webp +0 -0
- package/docs/images/api/lights/spot-cookies.webp +0 -0
- package/docs/images/api/lines/lines-lit.webp +0 -0
- package/docs/images/api/lines/lines-widths.webp +0 -0
- package/docs/images/api/materials/coat-and-sheen.webp +0 -0
- package/docs/images/api/materials/decals.webp +0 -0
- package/docs/images/api/materials/iridescence-and-anisotropy.webp +0 -0
- package/docs/images/api/materials/relief.webp +0 -0
- package/docs/images/api/materials/shader-inputs.webp +0 -0
- package/docs/images/api/materials/standard-grid.webp +0 -0
- package/docs/images/api/materials/subsurface.webp +0 -0
- package/docs/images/api/materials/translucency.webp +0 -0
- package/docs/images/api/objects/objects-turntable.webp +0 -0
- package/docs/images/api/particles/campfire.webp +0 -0
- package/docs/images/api/points/galaxy.webp +0 -0
- package/docs/images/api/reference/textures/texture-wrap.webp +0 -0
- package/docs/images/api/render/fullscreen-glow.webp +0 -0
- package/docs/images/api/render/reflection-mirror.webp +0 -0
- package/docs/images/api/render/security-camera.webp +0 -0
- package/docs/images/api/scene/aurora-sky-layer.webp +0 -0
- package/docs/images/api/sound/sound-demo.webp +0 -0
- package/docs/images/api/splats/splats-demo.webp +0 -0
- package/docs/images/api/sprites/sprites-lines.webp +0 -0
- package/docs/images/api/terrain/terrain-demo.webp +0 -0
- package/docs/images/api/textures/canvas-screen.webp +0 -0
- package/docs/images/api/textures/mipmaps.webp +0 -0
- package/docs/images/api/vertex-draws/rain.webp +0 -0
- package/docs/images/api/water/ocean.webp +0 -0
- package/docs/images/api/water/water-demo.webp +0 -0
- package/docs/images/api/water/water-rain.webp +0 -0
- package/docs/images/api/water/waterfall.webp +0 -0
- package/docs/images/concepts/assets/gltf-model.webp +0 -0
- package/docs/images/concepts/color-management/tone-mapped.webp +0 -0
- package/docs/images/concepts/culling/far-from-origin.webp +0 -0
- package/docs/images/concepts/instances/instances.webp +0 -0
- package/docs/images/concepts/instances/per-row-colors.webp +0 -0
- package/docs/images/concepts/large-worlds/large-world.webp +0 -0
- package/docs/images/concepts/lighting/area-lights.webp +0 -0
- package/docs/images/concepts/lighting/atmosphere.webp +0 -0
- package/docs/images/concepts/lighting/environment.webp +0 -0
- package/docs/images/concepts/lighting/light-shafts.webp +0 -0
- package/docs/images/concepts/lighting/reflection-probes.webp +0 -0
- package/docs/images/concepts/lod/forest.webp +0 -0
- package/docs/images/concepts/materials/weighted-transparency.webp +0 -0
- package/docs/images/concepts/post-processing/auto-exposure.webp +0 -0
- package/docs/images/concepts/post-processing/bounce-light.webp +0 -0
- package/docs/images/concepts/post-processing/depth-of-field.webp +0 -0
- package/docs/images/concepts/post-processing/post-effects-alley.webp +0 -0
- package/docs/images/concepts/post-processing/sharpen.webp +0 -0
- package/docs/images/concepts/post-processing/ssr-wet-street.webp +0 -0
- package/docs/images/concepts/render-layers/layers-cottages.webp +0 -0
- package/docs/images/concepts/shadows/hero-shadow.webp +0 -0
- package/docs/images/cookbook/index/picking.webp +0 -0
- package/docs/images/cookbook/index/time-of-day.webp +0 -0
- package/docs/images/errors/E1431/area-lights-no-tables.webp +0 -0
- package/docs/images/guides/custom-passes/reflection-water.webp +0 -0
- package/docs/images/guides/deterministic-simulation/replay-demo.webp +0 -0
- package/docs/images/guides/multiple-views/split-screen.webp +0 -0
- package/docs/images/guides/performance/overdraw-view.webp +0 -0
- package/docs/images/guides/testing/hold-mode-frame.webp +0 -0
- package/docs/images/index/showcase-island.webp +0 -0
- package/docs/images/porting/threejs-shaders/dissolve.webp +0 -0
- package/docs/images/shaders/builtins/builtins.webp +0 -0
- package/docs/images/shaders/surface-functions/custom-surface.webp +0 -0
- package/docs/images/shaders/surface-functions/vertex-offset.webp +0 -0
- package/docs/images/shots.json +2231 -0
- package/docs/index.md +14 -23
- package/docs/moves.json +1 -0
- package/docs/nav.json +300 -0
- package/docs/pages.md +230 -212
- package/docs/porting/react-three-fiber.md +2 -6
- package/docs/porting/threejs-loop-and-threads.md +1 -5
- package/docs/porting/threejs-mapping.md +1248 -234
- package/docs/porting/threejs-materials.md +10 -5
- package/docs/porting/threejs-overview.md +26 -6
- package/docs/porting/threejs-postprocessing.md +2 -6
- package/docs/porting/threejs-shaders.md +16 -14
- package/docs/porting/threejs-unsupported.md +6 -6
- package/docs/porting/verification.md +0 -4
- package/docs/shaders/builtins.md +15 -4
- package/docs/shaders/library.md +9 -6
- package/docs/shaders/surface-functions.md +51 -16
- package/docs/shaders/wgsl-rules.md +12 -5
- package/lib/debug/debug.d.ts +2 -2
- package/lib/debug/draw.d.ts +2 -2
- package/lib/debug/draw.js +8 -4
- package/lib/debug/overlay-look.d.ts +6 -0
- package/lib/debug/overlay-look.js +29 -7
- package/lib/debug/overlay.js +15 -11
- package/lib/debug/stats-options.d.ts +13 -0
- package/lib/debug/stats-panel.d.ts +21 -6
- package/lib/debug/stats-panel.js +80 -13
- package/lib/errors/codes.d.ts +17 -3
- package/lib/errors/codes.js +116 -105
- package/lib/errors/engine-error.js +1 -1
- package/lib/errors/fixes.d.ts +1 -0
- package/lib/errors/fixes.js +19 -18
- package/lib/generated/shader-permutations.d.ts +6 -0
- package/lib/generated/shader-permutations.js +6 -0
- package/lib/gpu/variants.d.ts +8 -2
- package/lib/gpu/variants.js +39 -7
- package/lib/gpu/webgl2/programs.js +1 -1
- package/lib/gpu/webgpu/pipelines.js +13 -13
- package/lib/index.d.ts +1 -1
- package/lib/page/capabilities.d.ts +1 -1
- package/lib/page/engine.d.ts +29 -7
- package/lib/page/engine.js +79 -7
- package/lib/page/label-loop.js +9 -4
- package/lib/page/stats-switch.js +2 -0
- package/lib/page/switches.d.ts +6 -4
- package/lib/page/switches.js +20 -4
- package/lib/scene/baked-light.d.ts +2 -2
- package/lib/scene/fake-call-values.js +2 -2
- package/lib/scene/frame-cameras.d.ts +16 -4
- package/lib/scene/frame-cameras.js +28 -10
- package/lib/scene/gltf.d.ts +1 -1
- package/lib/scene/level-rule.d.ts +6 -5
- package/lib/scene/level-rule.js +2 -2
- package/lib/scene/particles.d.ts +7 -3
- package/lib/scene/particles.js +3 -1
- package/lib/scene/post.d.ts +3 -2
- package/lib/scene/resources.d.ts +15 -9
- package/lib/scene/scene.d.ts +18 -2
- package/lib/scene/scene.js +47 -5
- package/lib/scene/time-of-day.d.ts +10 -5
- package/lib/scene/time-of-day.js +11 -7
- package/lib/shader-artifact.json +1 -1
- package/lib/shared/labels.d.ts +5 -2
- package/lib/shared/labels.js +5 -2
- package/lib/shared/permutation-words.d.ts +8 -0
- package/lib/shared/permutation-words.js +14 -0
- package/lib/shared/recording.d.ts +13 -5
- package/lib/shared/recording.js +31 -10
- package/lib/shared/sketch-data.d.ts +9 -0
- package/lib/shared/sketch-data.js +57 -0
- package/lib/shared/tier.d.ts +9 -0
- package/lib/shared/tier.js +4 -1
- package/lib/shared/version.d.ts +1 -1
- package/lib/shared/version.js +1 -1
- package/lib/sketch/define-sketch.d.ts +16 -7
- package/lib/sketch/define-sketch.js +2 -1
- package/lib/sketch/runner.d.ts +4 -0
- package/lib/sketch/runner.js +5 -0
- package/lib/sketch/ui.js +4 -2
- package/lib/stats.d.ts +1 -0
- package/lib/workers/protocol.d.ts +10 -0
- package/lib/workers/render-worker.js +4 -1
- package/lib/workers/sketch-worker.js +4 -1
- package/package.json +1 -1
package/lib/page/engine.js
CHANGED
|
@@ -15,7 +15,8 @@ import { EngineError, errorFixesReady, errorOfMessage } from '../errors/engine-e
|
|
|
15
15
|
import { messageOf } from '../errors/message.js';
|
|
16
16
|
import { FORMAT_CANVAS, PERMUTATION_HALF } from '../generated/gpu.js';
|
|
17
17
|
import { SHADER_FEATURES } from '../generated/shader-features.js';
|
|
18
|
-
import {
|
|
18
|
+
import { SHIPPED_GPU_PATHS } from '../generated/shader-permutations.js';
|
|
19
|
+
import { recordPermutations, reportPermutations, stopRecordingPermutations } from '../gpu/variants.js';
|
|
19
20
|
import { maxTargetFps, } from '../quality/check.js';
|
|
20
21
|
import { choosePreset, crashLowest, crashTier, deviceKind, gpuOcclusionChoice, memoryPreset, textureMemoryCap, withinTier, } from '../quality/chooser.js';
|
|
21
22
|
import { readDeviceHints } from '../quality/device-hints.js';
|
|
@@ -32,7 +33,10 @@ import { KEY_CODES } from '../shared/key-codes.js';
|
|
|
32
33
|
import { memoryBytes } from '../shared/memory-views.js';
|
|
33
34
|
import { createMetricsBuffer, MetricsReader, threadRoles } from '../shared/metrics.js';
|
|
34
35
|
import { addMeasurementRelease } from '../shared/page-measurement.js';
|
|
36
|
+
import { GPU_PATH_EVENT, PERMUTATION_WORD_EVENT } from '../shared/permutation-words.js';
|
|
37
|
+
import { sketchDataText } from '../shared/sketch-data.js';
|
|
35
38
|
import { clearJobTasks, jobAsker, setJobTasks } from '../shared/task-host.js';
|
|
39
|
+
import { pathOfTier } from '../shared/tier.js';
|
|
36
40
|
import { hearAddonsEarly, onAddonChecked } from '../shared/version.js';
|
|
37
41
|
import { VIDEO_FOLLOW } from '../shared/videos.js';
|
|
38
42
|
import { notifySlot, setWakeByMessage } from '../shared/wake.js';
|
|
@@ -114,11 +118,26 @@ const INSPECT_REPLY_LIMIT_MS = 30_000;
|
|
|
114
118
|
* than waiting for a worker that may never speak.
|
|
115
119
|
*/
|
|
116
120
|
export const RETRY_REPLY_MS = 10_000;
|
|
117
|
-
/**
|
|
118
|
-
|
|
121
|
+
/** The GPU paths whose shaders this build ships, or null for both, as the plugin's build wrote it. */
|
|
122
|
+
const SHIPPED_PATHS = SHIPPED_GPU_PATHS === null ? null : new Set(SHIPPED_GPU_PATHS);
|
|
123
|
+
/** True when this build holds the shaders of `path`. */
|
|
124
|
+
export function shipsPath(path) {
|
|
125
|
+
return SHIPPED_PATHS === null || SHIPPED_PATHS.has(path);
|
|
126
|
+
}
|
|
127
|
+
/** The path that a page's GPU switch draws with, or undefined for the engine's own choice. */
|
|
128
|
+
function pathOfSwitch(wanted) {
|
|
129
|
+
return wanted === 'auto' ? undefined : pathOfTier(wanted === 'webgl2' ? 'webgl2' : 'webgpu');
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Picks the GPU tier from feature tests, never from browser or GPU names. A path whose shaders this
|
|
133
|
+
* build does not ship counts as unavailable, whether or not the browser offers it.
|
|
134
|
+
*/
|
|
135
|
+
export function chooseTier(report, wanted, inWorker, ships = shipsPath) {
|
|
119
136
|
const worker = 'failure' in report.worker ? undefined : report.worker;
|
|
120
|
-
const webgpu =
|
|
121
|
-
|
|
137
|
+
const webgpu = ships('webgpu') &&
|
|
138
|
+
report.webgpu.compatibilityAdapter &&
|
|
139
|
+
(!inWorker || worker?.offscreenWebGPU === true);
|
|
140
|
+
const webgl2 = ships('webgl2') && (inWorker ? worker?.offscreenWebGL2 === true : report.webgl2.available);
|
|
122
141
|
if (wanted === 'webgl2')
|
|
123
142
|
return webgl2 ? { tier: 'webgl2', forceCompat: false } : null;
|
|
124
143
|
if (wanted === 'compat')
|
|
@@ -134,6 +153,38 @@ export function chooseTier(report, wanted, inWorker) {
|
|
|
134
153
|
};
|
|
135
154
|
return webgl2 ? { tier: 'webgl2', forceCompat: false } : null;
|
|
136
155
|
}
|
|
156
|
+
/** The name of a GPU path, as the error messages carry it. */
|
|
157
|
+
function pathName(path) {
|
|
158
|
+
return path === 'webgl2' ? 'WebGL2' : 'WebGPU';
|
|
159
|
+
}
|
|
160
|
+
/** The GPU paths that this build ships, as the error messages carry them. */
|
|
161
|
+
function shippedNames(ships) {
|
|
162
|
+
if (ships('webgpu') && ships('webgl2'))
|
|
163
|
+
return 'WebGPU and WebGL2';
|
|
164
|
+
return ships('webgpu') ? 'WebGPU' : 'WebGL2';
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* The error for a start that found no usable GPU tier. When the build holds the shaders of one path
|
|
168
|
+
* and this start would draw with the other, it names the build's choice (E1308), because no browser
|
|
169
|
+
* or setting can fix that page. Otherwise the browser offers no path the engine can draw with, or
|
|
170
|
+
* none that the page asked for (E1301).
|
|
171
|
+
*/
|
|
172
|
+
export function noTierError(report, requested, inWorker, ships = shipsPath) {
|
|
173
|
+
const named = pathOfSwitch(requested);
|
|
174
|
+
if (named !== undefined && !ships(named))
|
|
175
|
+
return new EngineError('E1308', `this build ships only the ${shippedNames(ships)} shaders, and ?gpu=${requested} asks for ${pathName(named)}. Build the project with both GPU paths, or remove the switch.`);
|
|
176
|
+
if (named !== undefined)
|
|
177
|
+
return new EngineError('E1301', `no usable GPU path for ?gpu=${requested} in this browser.`);
|
|
178
|
+
const worker = 'failure' in report.worker ? undefined : report.worker;
|
|
179
|
+
const offered = report.webgpu.compatibilityAdapter
|
|
180
|
+
? 'webgpu'
|
|
181
|
+
: (inWorker ? worker?.offscreenWebGL2 === true : report.webgl2.available)
|
|
182
|
+
? 'webgl2'
|
|
183
|
+
: undefined;
|
|
184
|
+
if (offered !== undefined && !ships(offered))
|
|
185
|
+
return new EngineError('E1308', `this build ships only the ${shippedNames(ships)} shaders, and this device would draw with ${pathName(offered)}. The Vite plugin's shaders.gpuPaths option left ${pathName(offered)} out. Build the project with both GPU paths, or run the page in a browser that offers ${pathName(ships('webgpu') ? 'webgpu' : 'webgl2')}.`);
|
|
186
|
+
return new EngineError('E1301', `no usable GPU path for ?gpu=${requested} in this browser.`);
|
|
187
|
+
}
|
|
137
188
|
/**
|
|
138
189
|
* True while this page is hidden. A hidden page draws no frames, so a capture's answer comes once
|
|
139
190
|
* the page shows again, however long that takes, and the answer's limit counts only the time the
|
|
@@ -277,6 +328,10 @@ export class EngineWorker {
|
|
|
277
328
|
// frame has built the scene's pipelines.
|
|
278
329
|
this.recording?.answered(reply.role, reply.permutations);
|
|
279
330
|
return;
|
|
331
|
+
case 'permutation':
|
|
332
|
+
if (DEV)
|
|
333
|
+
announcePermutationWord(reply.word);
|
|
334
|
+
return;
|
|
280
335
|
case 'sketch-message':
|
|
281
336
|
events.sketchMessage(reply.name, reply.data);
|
|
282
337
|
return;
|
|
@@ -866,6 +921,7 @@ export async function createEngine(options) {
|
|
|
866
921
|
};
|
|
867
922
|
try {
|
|
868
923
|
checkPreload(options.preload);
|
|
924
|
+
const sketchData = sketchDataText(options.sketchData);
|
|
869
925
|
const hold = holdSeconds(options.hold, switches.hold);
|
|
870
926
|
// A test tool may set a timed script before the page loads. Only hold mode performs it, so a
|
|
871
927
|
// live engine ignores one left on the page.
|
|
@@ -881,7 +937,7 @@ export async function createEngine(options) {
|
|
|
881
937
|
}, () => new EngineError('E1419', 'createEngine() got a canvas that another engine draws on, which has not stopped.'));
|
|
882
938
|
if (canvas.dead)
|
|
883
939
|
throw new EngineError('E1419', `createEngine() got a canvas that no engine can draw on again: ${canvas.dead}.`);
|
|
884
|
-
return await startEngine(options, switches, { hold, holdScript, replay: switches.replay, record: switches.record }, place, canvas, holder, release);
|
|
940
|
+
return await startEngine(options, switches, { hold, holdScript, replay: switches.replay, record: switches.record, sketchData }, place, canvas, holder, release);
|
|
885
941
|
}
|
|
886
942
|
catch (error) {
|
|
887
943
|
release();
|
|
@@ -914,6 +970,16 @@ function placement(options, switches) {
|
|
|
914
970
|
const main = !threaded || (switches.sketchThread ?? options.sketchThread) === 'main';
|
|
915
971
|
return { threaded, sketchThread: main ? 'main' : 'worker' };
|
|
916
972
|
}
|
|
973
|
+
/** Fires the event that hands a permutation word that the page draws with to the dev server. */
|
|
974
|
+
function announcePermutationWord(word) {
|
|
975
|
+
globalThis.dispatchEvent?.(new CustomEvent(PERMUTATION_WORD_EVENT, { detail: word }));
|
|
976
|
+
}
|
|
977
|
+
/** In a development build, tells the dev server the GPU path that this engine draws with. */
|
|
978
|
+
function announceGpuPath(tier) {
|
|
979
|
+
if (!DEV)
|
|
980
|
+
return;
|
|
981
|
+
globalThis.dispatchEvent?.(new CustomEvent(GPU_PATH_EVENT, { detail: pathOfTier(tier) }));
|
|
982
|
+
}
|
|
917
983
|
/**
|
|
918
984
|
* Starts the engine with the page's switches. With a hold time or a replay, it resolves once the
|
|
919
985
|
* last frame is read back, and publishes it.
|
|
@@ -1603,8 +1669,9 @@ async function startEngine(options, switches, modes, { threaded, sketchThread },
|
|
|
1603
1669
|
drawModule ??= loadDrawModule();
|
|
1604
1670
|
}
|
|
1605
1671
|
if (!choice)
|
|
1606
|
-
throw
|
|
1672
|
+
throw noTierError(report, requested, renderThread !== 'main');
|
|
1607
1673
|
tier = choice.tier;
|
|
1674
|
+
announceGpuPath(tier);
|
|
1608
1675
|
const { forceCompat } = choice;
|
|
1609
1676
|
// Where the page draws, it moves the label elements right after each frame it draws.
|
|
1610
1677
|
const labels = new PageLabels(views, renderThread === 'main');
|
|
@@ -1717,6 +1784,9 @@ async function startEngine(options, switches, modes, { threaded, sketchThread },
|
|
|
1717
1784
|
globalThis.__null3dStopRecording = stopRecording;
|
|
1718
1785
|
if (recording && renderThread === 'main')
|
|
1719
1786
|
recordPermutations();
|
|
1787
|
+
// The dev server compares each word that the page draws with against the project's list.
|
|
1788
|
+
if (DEV && renderThread === 'main')
|
|
1789
|
+
reportPermutations(announcePermutationWord);
|
|
1720
1790
|
// What the thread that draws needs besides its canvas, whichever thread that is.
|
|
1721
1791
|
const rendererSetup = {
|
|
1722
1792
|
tier,
|
|
@@ -2017,6 +2087,7 @@ async function startEngine(options, switches, modes, { threaded, sketchThread },
|
|
|
2017
2087
|
...senders,
|
|
2018
2088
|
pageUrl: pageUrl ?? sketchUrl,
|
|
2019
2089
|
sketchUrl,
|
|
2090
|
+
data: modes.sketchData,
|
|
2020
2091
|
maxTargetFps: maxTarget,
|
|
2021
2092
|
threads: engineThreads,
|
|
2022
2093
|
twoStepProbe: DEV && switches.twoStep,
|
|
@@ -2063,6 +2134,7 @@ async function startEngine(options, switches, modes, { threaded, sketchThread },
|
|
|
2063
2134
|
...handoff,
|
|
2064
2135
|
sketchUrl,
|
|
2065
2136
|
pageUrl: pageUrl ?? sketchUrl,
|
|
2137
|
+
data: modes.sketchData,
|
|
2066
2138
|
keyCodes: KEY_CODES,
|
|
2067
2139
|
jobWorkers,
|
|
2068
2140
|
capabilities,
|
package/lib/page/label-loop.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// scene: it sits in a container of its own, which holds the camera's perspective and turn, and its
|
|
12
12
|
// transform is the element's world matrix. The browser then turns it as it turns the scene.
|
|
13
13
|
import { controlLabels, Slot } from '../shared/control.js';
|
|
14
|
-
import { CAMERA_CENTER_X, CAMERA_CENTER_Y, CAMERA_HALF_HEIGHT, CAMERA_ORTHO, GENERATION_SHIFT, LABEL_SHOWN, LABEL_STATE, LABEL_WORDS, LABEL_X, LABEL_Y, LABEL3D_STATE, LABEL3D_WORDS, labelSequence, PRESENTED_TABLE, presentedCount, presentedCount3d, presentedFrame, presentedTable3d, TABLE_3D, } from '../shared/labels.js';
|
|
14
|
+
import { CAMERA_CENTER_X, CAMERA_CENTER_Y, CAMERA_FLOATS, CAMERA_HALF_HEIGHT, CAMERA_ORTHO, CAMERA_SHIFT_X, CAMERA_SHIFT_Y, GENERATION_SHIFT, LABEL_SHOWN, LABEL_STATE, LABEL_WORDS, LABEL_X, LABEL_Y, LABEL3D_STATE, LABEL3D_WORDS, labelSequence, PRESENTED_TABLE, presentedCount, presentedCount3d, presentedFrame, presentedTable3d, TABLE_3D, } from '../shared/labels.js';
|
|
15
15
|
/** How many times an update reads the labels again when the thread that draws changed them meanwhile. */
|
|
16
16
|
const READ_TRIES = 3;
|
|
17
17
|
/** The smallest move, in CSS pixels, that moves a screen label's element. */
|
|
@@ -23,7 +23,7 @@ const STATE_Y = 1;
|
|
|
23
23
|
const STATE_SHOWN = 2;
|
|
24
24
|
const STATE_MATRIX = 3;
|
|
25
25
|
/** The camera record that the containers show, then the canvas size they were made for. */
|
|
26
|
-
const CAMERA_STATE =
|
|
26
|
+
const CAMERA_STATE = CAMERA_FLOATS + 2;
|
|
27
27
|
/** The smallest number of a matrix that counts as zero, so a turn of the camera writes no noise. */
|
|
28
28
|
const EPSILON = 1e-10;
|
|
29
29
|
/** The bound elements, and the loop that moves them. */
|
|
@@ -406,10 +406,15 @@ export function cameraTransform(camera, width, height) {
|
|
|
406
406
|
`${number(camera[1])},${number(-camera[4])},${number(camera[7])},0,` +
|
|
407
407
|
`${number(camera[2])},${number(-camera[5])},${number(camera[8])},0,` +
|
|
408
408
|
`${number(tx)},${number(-ty)},${number(tz)},1)`;
|
|
409
|
-
const
|
|
409
|
+
const lens = camera[CAMERA_ORTHO] !== 0
|
|
410
410
|
? `scale(${number(focal)}) translate(${number(-camera[CAMERA_CENTER_X])}px,${number(camera[CAMERA_CENTER_Y])}px) `
|
|
411
411
|
: `perspective(${number(focal)}px) translateZ(${number(focal)}px) `;
|
|
412
|
-
|
|
412
|
+
// A lens shift moves the whole image after the projection, left and down for a view shifted
|
|
413
|
+
// right and up.
|
|
414
|
+
const shiftX = camera[CAMERA_SHIFT_X] * width;
|
|
415
|
+
const shiftY = camera[CAMERA_SHIFT_Y] * height;
|
|
416
|
+
const shift = shiftX === 0 && shiftY === 0 ? '' : `translate(${number(-shiftX)}px,${number(shiftY)}px) `;
|
|
417
|
+
return `${shift}${lens}${matrix} translate(${number(width / 2)}px,${number(height / 2)}px)`;
|
|
413
418
|
}
|
|
414
419
|
/** A number as CSS takes it, with the noise of a turn that did not move it set to zero. */
|
|
415
420
|
function number(value) {
|
package/lib/page/stats-switch.js
CHANGED
|
@@ -27,6 +27,8 @@ export class StatsSwitch {
|
|
|
27
27
|
if (show !== true) {
|
|
28
28
|
if (show.collapsed !== undefined)
|
|
29
29
|
this.options.collapsed = show.collapsed;
|
|
30
|
+
if (show.corner !== undefined)
|
|
31
|
+
this.options.corner = show.corner;
|
|
30
32
|
this.overlay?.configure(show);
|
|
31
33
|
}
|
|
32
34
|
this.load ??= import('../debug/overlay.js');
|
package/lib/page/switches.d.ts
CHANGED
|
@@ -34,8 +34,9 @@ export type LatencyMode = 'pipelined' | 'low';
|
|
|
34
34
|
export type SketchThread = 'worker' | 'main';
|
|
35
35
|
/**
|
|
36
36
|
* How the GPU path stores depth. In `reversed` depth, the near plane stores 1 and the far plane 0,
|
|
37
|
-
* in a 32-bit float depth buffer. That keeps depth precise far from the camera.
|
|
38
|
-
*
|
|
37
|
+
* in a 32-bit float depth buffer. That keeps depth precise far from the camera.
|
|
38
|
+
*
|
|
39
|
+
* WebGPU always draws it. WebGL2 draws it where the browser has the `EXT_clip_control` extension, which gives
|
|
39
40
|
* WebGL2 the depth range from 0 to 1 that WebGPU has. The `reversed-gl` mode keeps the same
|
|
40
41
|
* order, but in WebGL2's own depth range from -1 to 1, which loses most of the precision. In
|
|
41
42
|
* `standard` depth, the near plane stores 0 and the far plane 1.
|
|
@@ -311,8 +312,9 @@ export interface Switches {
|
|
|
311
312
|
view: string | undefined;
|
|
312
313
|
/**
|
|
313
314
|
* True when a bare ?stats or ?stats=on shows the stats overlay, false when ?stats=off hides it,
|
|
314
|
-
*
|
|
315
|
-
*
|
|
315
|
+
* and undefined without the switch. Options when the switch names a start state, `collapsed` or
|
|
316
|
+
* `open`, a corner, `top-right` or `bottom-right`, or one of each with a comma between, such as
|
|
317
|
+
* ?stats=collapsed,bottom-right. It wins over the page's option.
|
|
316
318
|
*/
|
|
317
319
|
stats: StatsRequest | undefined;
|
|
318
320
|
/**
|
package/lib/page/switches.js
CHANGED
|
@@ -55,11 +55,27 @@ function oneOf(value, allowed) {
|
|
|
55
55
|
function onOff(value) {
|
|
56
56
|
return value === 'on' ? true : value === 'off' ? false : undefined;
|
|
57
57
|
}
|
|
58
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* ?stats: on for a bare switch or `on`, off for `off`, or options from a comma-separated list of a
|
|
60
|
+
* start state, `collapsed` or `open`, and a corner, `top-right` or `bottom-right`. A word that none
|
|
61
|
+
* of these is leaves the switch out.
|
|
62
|
+
*/
|
|
59
63
|
function statsSwitch(value) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
if (value === '')
|
|
65
|
+
return true;
|
|
66
|
+
const on = onOff(value);
|
|
67
|
+
if (on !== undefined || value === null)
|
|
68
|
+
return on;
|
|
69
|
+
const options = {};
|
|
70
|
+
for (const word of value.split(',')) {
|
|
71
|
+
if (word === 'collapsed' || word === 'open')
|
|
72
|
+
options.collapsed = word === 'collapsed';
|
|
73
|
+
else if (word === 'top-right' || word === 'bottom-right')
|
|
74
|
+
options.corner = word;
|
|
75
|
+
else
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
return options;
|
|
63
79
|
}
|
|
64
80
|
/** A number above 0, or undefined for a missing or unusable value. */
|
|
65
81
|
function positive(value) {
|
|
@@ -26,7 +26,7 @@ export interface BakedLightMap {
|
|
|
26
26
|
* little-endian half floats. Rows run along v from the first texel at u = 0, v = 0.
|
|
27
27
|
*/
|
|
28
28
|
readonly radiance: Uint8Array;
|
|
29
|
-
/** Three signed bytes per texel, each axis
|
|
29
|
+
/** Three signed bytes per texel, each axis times 127, or undefined without one. */
|
|
30
30
|
readonly direction: Int8Array | undefined;
|
|
31
31
|
}
|
|
32
32
|
/** A baked light file that this engine reads. */
|
|
@@ -45,7 +45,7 @@ export interface LightMapData {
|
|
|
45
45
|
/** The radiance, as a texture that a material takes as `lightMap`. */
|
|
46
46
|
readonly texture: Texture;
|
|
47
47
|
/**
|
|
48
|
-
* Three signed bytes per texel, from -127 to 127
|
|
48
|
+
* Three signed bytes per texel, from -127 to 127: each axis of the direction times 127. It runs
|
|
49
49
|
* from the same first texel as the radiance, and it is undefined for a light map without a
|
|
50
50
|
* direction.
|
|
51
51
|
*/
|
|
@@ -11,8 +11,8 @@ const READS = {
|
|
|
11
11
|
setBatchBounds: 1,
|
|
12
12
|
setMaterialValue: 3,
|
|
13
13
|
setMaterialValues: 4,
|
|
14
|
-
setPerspectiveCamera:
|
|
15
|
-
setOrthographicCamera:
|
|
14
|
+
setPerspectiveCamera: 5,
|
|
15
|
+
setOrthographicCamera: 8,
|
|
16
16
|
addSceneView: 4,
|
|
17
17
|
setSceneViewRect: 4,
|
|
18
18
|
setLightColor: 3,
|
|
@@ -49,7 +49,13 @@ export declare const LENS_CENTER_Y = 4;
|
|
|
49
49
|
/** The distances along the view to the near and far planes. */
|
|
50
50
|
export declare const LENS_NEAR = 5;
|
|
51
51
|
export declare const LENS_FAR = 6;
|
|
52
|
-
|
|
52
|
+
/**
|
|
53
|
+
* The lens shift: how far the view sits right of and above the camera's axis, or an orthographic
|
|
54
|
+
* view's center, as fractions of the view's width and height.
|
|
55
|
+
*/
|
|
56
|
+
export declare const LENS_SHIFT_X = 7;
|
|
57
|
+
export declare const LENS_SHIFT_Y = 8;
|
|
58
|
+
export declare const LENS_FLOATS = 9;
|
|
53
59
|
/** The cameras of the last frames, and the math of rays and projections from them. */
|
|
54
60
|
export declare class FrameCameras {
|
|
55
61
|
private readonly core;
|
|
@@ -153,10 +159,10 @@ export declare class FrameCameras {
|
|
|
153
159
|
* A camera's projection, made once and used for many points. The first 9 numbers are the inverse
|
|
154
160
|
* of the 3 × 3 part of the camera's world matrix, row by row, then the camera's position. Then come
|
|
155
161
|
* half the view's width and height (one unit in front of a perspective camera, or across an
|
|
156
|
-
* orthographic view), 1 for an orthographic lens or 0, the orthographic view's center,
|
|
157
|
-
* distances to the near and far planes.
|
|
162
|
+
* orthographic view), 1 for an orthographic lens or 0, the orthographic view's center, the
|
|
163
|
+
* distances to the near and far planes, and the lens shift.
|
|
158
164
|
*/
|
|
159
|
-
export declare const VIEW_FLOATS =
|
|
165
|
+
export declare const VIEW_FLOATS = 21;
|
|
160
166
|
export declare const VIEW_SCALE_Y = 13;
|
|
161
167
|
/** 1 in a view that `viewOf` wrote for an orthographic lens, or 0. */
|
|
162
168
|
export declare const VIEW_ORTHO = 14;
|
|
@@ -166,6 +172,12 @@ export declare const VIEW_CENTER_Y = 16;
|
|
|
166
172
|
/** The distances to the near and far planes in a view that `viewOf` wrote. */
|
|
167
173
|
export declare const VIEW_NEAR = 17;
|
|
168
174
|
export declare const VIEW_FAR = 18;
|
|
175
|
+
/**
|
|
176
|
+
* The lens shift in a view that `viewOf` wrote, as fractions of the view's width and height. It moves
|
|
177
|
+
* the image by twice that fraction in normalized device coordinates.
|
|
178
|
+
*/
|
|
179
|
+
export declare const VIEW_SHIFT_X = 19;
|
|
180
|
+
export declare const VIEW_SHIFT_Y = 20;
|
|
169
181
|
/**
|
|
170
182
|
* Writes where `point` lies for the camera of `view` into `out`: x and y in normalized device
|
|
171
183
|
* coordinates, from -1 to 1 across the canvas with y up, then the distance in front of the camera
|
|
@@ -27,7 +27,13 @@ export const LENS_CENTER_Y = 4;
|
|
|
27
27
|
/** The distances along the view to the near and far planes. */
|
|
28
28
|
export const LENS_NEAR = 5;
|
|
29
29
|
export const LENS_FAR = 6;
|
|
30
|
-
|
|
30
|
+
/**
|
|
31
|
+
* The lens shift: how far the view sits right of and above the camera's axis, or an orthographic
|
|
32
|
+
* view's center, as fractions of the view's width and height.
|
|
33
|
+
*/
|
|
34
|
+
export const LENS_SHIFT_X = 7;
|
|
35
|
+
export const LENS_SHIFT_Y = 8;
|
|
36
|
+
export const LENS_FLOATS = 9;
|
|
31
37
|
/** The views whose cameras the ring keeps. */
|
|
32
38
|
const RING_VIEWS = 4;
|
|
33
39
|
/** The frames of an entry that holds no frame yet. */
|
|
@@ -301,10 +307,10 @@ function sameView(ring, at, view) {
|
|
|
301
307
|
* A camera's projection, made once and used for many points. The first 9 numbers are the inverse
|
|
302
308
|
* of the 3 × 3 part of the camera's world matrix, row by row, then the camera's position. Then come
|
|
303
309
|
* half the view's width and height (one unit in front of a perspective camera, or across an
|
|
304
|
-
* orthographic view), 1 for an orthographic lens or 0, the orthographic view's center,
|
|
305
|
-
* distances to the near and far planes.
|
|
310
|
+
* orthographic view), 1 for an orthographic lens or 0, the orthographic view's center, the
|
|
311
|
+
* distances to the near and far planes, and the lens shift.
|
|
306
312
|
*/
|
|
307
|
-
export const VIEW_FLOATS =
|
|
313
|
+
export const VIEW_FLOATS = 21;
|
|
308
314
|
const VIEW_POSITION = 9;
|
|
309
315
|
/** Half the view's width and height in a view that `viewOf` wrote. */
|
|
310
316
|
const VIEW_SCALE_X = 12;
|
|
@@ -317,6 +323,12 @@ export const VIEW_CENTER_Y = 16;
|
|
|
317
323
|
/** The distances to the near and far planes in a view that `viewOf` wrote. */
|
|
318
324
|
export const VIEW_NEAR = 17;
|
|
319
325
|
export const VIEW_FAR = 18;
|
|
326
|
+
/**
|
|
327
|
+
* The lens shift in a view that `viewOf` wrote, as fractions of the view's width and height. It moves
|
|
328
|
+
* the image by twice that fraction in normalized device coordinates.
|
|
329
|
+
*/
|
|
330
|
+
export const VIEW_SHIFT_X = 19;
|
|
331
|
+
export const VIEW_SHIFT_Y = 20;
|
|
320
332
|
/** Writes the projection of the camera of the entry at `at` into `view`. */
|
|
321
333
|
function writeView(e, at, view) {
|
|
322
334
|
const m = at + MATRIX;
|
|
@@ -350,6 +362,8 @@ function writeView(e, at, view) {
|
|
|
350
362
|
view[VIEW_CENTER_Y] = e[lens + LENS_CENTER_Y];
|
|
351
363
|
view[VIEW_NEAR] = e[lens + LENS_NEAR];
|
|
352
364
|
view[VIEW_FAR] = e[lens + LENS_FAR];
|
|
365
|
+
view[VIEW_SHIFT_X] = e[lens + LENS_SHIFT_X];
|
|
366
|
+
view[VIEW_SHIFT_Y] = e[lens + LENS_SHIFT_Y];
|
|
353
367
|
}
|
|
354
368
|
/**
|
|
355
369
|
* Writes where `point` lies for the camera of `view` into `out`: x and y in normalized device
|
|
@@ -366,13 +380,16 @@ export function projectPoint(view, point, out) {
|
|
|
366
380
|
const lz = view[6] * px + view[7] * py + view[8] * pz;
|
|
367
381
|
const sx = view[VIEW_SCALE_X];
|
|
368
382
|
const sy = view[VIEW_SCALE_Y];
|
|
383
|
+
// A lens shift moves the whole image, after the perspective division.
|
|
384
|
+
const shiftX = 2 * view[VIEW_SHIFT_X];
|
|
385
|
+
const shiftY = 2 * view[VIEW_SHIFT_Y];
|
|
369
386
|
if (view[VIEW_ORTHO] !== 0) {
|
|
370
|
-
out[0] = (lx - view[VIEW_CENTER_X]) / sx;
|
|
371
|
-
out[1] = (ly - view[VIEW_CENTER_Y]) / sy;
|
|
387
|
+
out[0] = (lx - view[VIEW_CENTER_X]) / sx - shiftX;
|
|
388
|
+
out[1] = (ly - view[VIEW_CENTER_Y]) / sy - shiftY;
|
|
372
389
|
}
|
|
373
390
|
else {
|
|
374
|
-
out[0] = lx / (-lz * sx);
|
|
375
|
-
out[1] = ly / (-lz * sy);
|
|
391
|
+
out[0] = lx / (-lz * sx) - shiftX;
|
|
392
|
+
out[1] = ly / (-lz * sy) - shiftY;
|
|
376
393
|
}
|
|
377
394
|
out[2] = -lz;
|
|
378
395
|
}
|
|
@@ -448,9 +465,10 @@ function writeRay(e, at, point, out) {
|
|
|
448
465
|
const y = point[1];
|
|
449
466
|
const width = e[at + CSS_WIDTH];
|
|
450
467
|
const height = e[at + CSS_HEIGHT];
|
|
451
|
-
const ndcX = width > 0 ? (x / width) * 2 - 1 : 0;
|
|
452
|
-
const ndcY = height > 0 ? 1 - (y / height) * 2 : 0;
|
|
453
468
|
const lens = at + LENS;
|
|
469
|
+
// A lens shift moves the view right and up, so a point of the canvas sees that much further.
|
|
470
|
+
const ndcX = (width > 0 ? (x / width) * 2 - 1 : 0) + 2 * e[lens + LENS_SHIFT_X];
|
|
471
|
+
const ndcY = (height > 0 ? 1 - (y / height) * 2 : 0) + 2 * e[lens + LENS_SHIFT_Y];
|
|
454
472
|
writeScaleX(e, at, rayScale, 0);
|
|
455
473
|
const sx = ndcX * rayScale[0];
|
|
456
474
|
const sy = ndcY * e[lens + LENS_HALF_HEIGHT];
|
package/lib/scene/gltf.d.ts
CHANGED
|
@@ -92,7 +92,7 @@ export declare function fileLevelMeasure(errors: readonly number[] | undefined,
|
|
|
92
92
|
};
|
|
93
93
|
/** One band of a tree of cluster patches, as a stage file holds it. */
|
|
94
94
|
export interface StageBand {
|
|
95
|
-
/** Each patch's bounding sphere: its
|
|
95
|
+
/** Each patch's bounding sphere: its center, then its radius. */
|
|
96
96
|
bounds: Float32Array;
|
|
97
97
|
/** Each patch's first index, count, parent's place plus one, and error's bits. */
|
|
98
98
|
records: Uint32Array;
|
|
@@ -22,8 +22,9 @@ export interface LevelView {
|
|
|
22
22
|
*/
|
|
23
23
|
readonly orthographic?: boolean;
|
|
24
24
|
/**
|
|
25
|
-
* The source's threshold bias, as Godot's `lod_bias`:
|
|
26
|
-
*
|
|
25
|
+
* The source's threshold bias, as the inverse of Godot's `lod_bias`: a Godot bias of 2 is
|
|
26
|
+
* about a null3D bias of 0.5. Above 1 switches every level nearer, so coarser levels draw, and
|
|
27
|
+
* below 1 keeps its detail. The default is 1.
|
|
27
28
|
*/
|
|
28
29
|
readonly bias?: number;
|
|
29
30
|
}
|
|
@@ -41,13 +42,13 @@ export type LevelSwitch = {
|
|
|
41
42
|
readonly coverage: number;
|
|
42
43
|
};
|
|
43
44
|
/**
|
|
44
|
-
* A source's world bounds about the camera: the
|
|
45
|
+
* A source's world bounds about the camera: the center of its bounding sphere relative to the
|
|
45
46
|
* camera, and the sphere's radius.
|
|
46
47
|
*
|
|
47
48
|
* @category api/geometry
|
|
48
49
|
*/
|
|
49
50
|
export interface LevelBounds {
|
|
50
|
-
/** The bounding sphere's
|
|
51
|
+
/** The bounding sphere's center, relative to the camera. */
|
|
51
52
|
readonly centre: readonly [number, number, number];
|
|
52
53
|
/** The bounding sphere's radius, in meters. */
|
|
53
54
|
readonly radius: number;
|
|
@@ -96,7 +97,7 @@ export declare function levelSwitchDistance(view: LevelView, level: LevelSwitch,
|
|
|
96
97
|
* point for the other measures.
|
|
97
98
|
*
|
|
98
99
|
* @param view The view that measures the source.
|
|
99
|
-
* @param bounds The source's bounds, with the
|
|
100
|
+
* @param bounds The source's bounds, with the center relative to the camera.
|
|
100
101
|
* @returns The two distances, in meters.
|
|
101
102
|
* @category api/geometry
|
|
102
103
|
*/
|
package/lib/scene/level-rule.js
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* @category api/geometry
|
|
27
27
|
*/
|
|
28
28
|
export const LEAST_LEVEL_DISTANCE = 1e-3;
|
|
29
|
-
/** The share of the bounds' radius that an error's distance takes off the distance to the
|
|
29
|
+
/** The share of the bounds' radius that an error's distance takes off the distance to the center. */
|
|
30
30
|
const ERROR_RADIUS_SHARE = 0.5;
|
|
31
31
|
/** The multiple of the distance to the nearest point that caps an error's distance. */
|
|
32
32
|
const ERROR_NEAREST_SHARE = 2;
|
|
@@ -84,7 +84,7 @@ export function levelSwitchDistance(view, level, scale, radius = 0) {
|
|
|
84
84
|
* point for the other measures.
|
|
85
85
|
*
|
|
86
86
|
* @param view The view that measures the source.
|
|
87
|
-
* @param bounds The source's bounds, with the
|
|
87
|
+
* @param bounds The source's bounds, with the center relative to the camera.
|
|
88
88
|
* @returns The two distances, in meters.
|
|
89
89
|
* @category api/geometry
|
|
90
90
|
*/
|
package/lib/scene/particles.d.ts
CHANGED
|
@@ -198,8 +198,10 @@ export interface ParticleBufferOptions extends ParticleValues {
|
|
|
198
198
|
/**
|
|
199
199
|
* Where an emitter's particles are born, in its own space, and which way they set off. A `point`
|
|
200
200
|
* emits at the emitter, along `direction`. A `sphere` emits inside a ball of `radius`, or on its
|
|
201
|
-
* surface with `surface`, and sends particles outward.
|
|
202
|
-
*
|
|
201
|
+
* surface with `surface`, and sends particles outward.
|
|
202
|
+
*
|
|
203
|
+
* A `cone` emits on a disc of `radius` across the emitter's +y axis. It sends particles up within
|
|
204
|
+
* `angle` radians of that axis. A `box` emits
|
|
203
205
|
* inside a box of `size`, centered on the emitter, along `direction`. A `disc` emits on a disc of
|
|
204
206
|
* `radius` across the +y axis, along `direction`.
|
|
205
207
|
*
|
|
@@ -294,7 +296,9 @@ export interface ParticleEmitterOptions {
|
|
|
294
296
|
* particles add-on's emitters write records into it. Write a particle's record once, when it is
|
|
295
297
|
* born, with `write`, or write a frame's births in one call with `writeRecords`. The GPU moves it
|
|
296
298
|
* and changes its look as it ages, as the buffer's values say. It stops drawing the particle at
|
|
297
|
-
* the end of its lifetime.
|
|
299
|
+
* the end of its lifetime.
|
|
300
|
+
*
|
|
301
|
+
* Once per frame, write the buffer's time and the records the GPU reads
|
|
298
302
|
* into `frame`, and call `commit`. Every call takes typed arrays and whole numbers, so a frame's
|
|
299
303
|
* calls allocate nothing.
|
|
300
304
|
*
|
package/lib/scene/particles.js
CHANGED
|
@@ -202,7 +202,9 @@ const NO_FLOAT64 = new Float64Array(0);
|
|
|
202
202
|
* particles add-on's emitters write records into it. Write a particle's record once, when it is
|
|
203
203
|
* born, with `write`, or write a frame's births in one call with `writeRecords`. The GPU moves it
|
|
204
204
|
* and changes its look as it ages, as the buffer's values say. It stops drawing the particle at
|
|
205
|
-
* the end of its lifetime.
|
|
205
|
+
* the end of its lifetime.
|
|
206
|
+
*
|
|
207
|
+
* Once per frame, write the buffer's time and the records the GPU reads
|
|
206
208
|
* into `frame`, and call `commit`. Every call takes typed arrays and whole numbers, so a frame's
|
|
207
209
|
* calls allocate nothing.
|
|
208
210
|
*
|
package/lib/scene/post.d.ts
CHANGED
|
@@ -17,8 +17,9 @@ export type { GradingSettings, SplitToningSettings, WhiteBalanceSettings, } from
|
|
|
17
17
|
* AgX, the curve of Blender and Filament. The `'agx-punchy'` curve is AgX with Filament's punchy
|
|
18
18
|
* look, which adds contrast and color. The `'neutral'` curve is Khronos PBR Neutral, which keeps
|
|
19
19
|
* base colors as they are until they near white. The `'aces'` curve is a fit of the ACES filmic
|
|
20
|
-
* curve, which first scales the color by 1 / 0.6 and shifts the hues of bright colors.
|
|
21
|
-
*
|
|
20
|
+
* curve, which first scales the color by 1 / 0.6 and shifts the hues of bright colors.
|
|
21
|
+
*
|
|
22
|
+
* The value `'none'` clips the exposed color at 1.
|
|
22
23
|
*
|
|
23
24
|
* @category api/post
|
|
24
25
|
*/
|
package/lib/scene/resources.d.ts
CHANGED
|
@@ -7,9 +7,11 @@ import type { TextureValues, UniformValues } from './wgsl-uniforms.js';
|
|
|
7
7
|
* A lower level of detail of a mesh: a simpler mesh that draws in the base mesh's place. Give its
|
|
8
8
|
* `error`, the `distance` at which it switches in, or the screen `coverage` under which it draws.
|
|
9
9
|
* A level with a measured error, which the asset tool writes, changes the picture by under a pixel
|
|
10
|
-
* at a small threshold and switches at once.
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* at a small threshold and switches at once.
|
|
11
|
+
*
|
|
12
|
+
* When the governor raises the threshold above about one and a half pixels, that switch shows, and
|
|
13
|
+
* such a level then fades too. A level given by a distance, by a coverage or by a hand-set error
|
|
14
|
+
* fades over a short band, so its switch does not pop.
|
|
13
15
|
*
|
|
14
16
|
* @category api/geometry
|
|
15
17
|
*/
|
|
@@ -110,8 +112,10 @@ export interface BuildLevelsOptions {
|
|
|
110
112
|
* The levels of detail that a mesh made in code plans on its own. By default it plans them the
|
|
111
113
|
* first time the scene draws it, when it holds `geometry.automaticLevelTriangles` triangles or
|
|
112
114
|
* more, or when it holds at least `geometry.automaticCopyTriangles` triangles and its copies hold `geometry.automaticDrawnTriangles` together; `false` plans none,
|
|
113
|
-
* and `true` or options plan them when the mesh is made, at any size.
|
|
114
|
-
*
|
|
115
|
+
* and `true` or options plan them when the mesh is made, at any size.
|
|
116
|
+
*
|
|
117
|
+
* `'pieces'` plans no lower levels, and sorts a mesh of 32,768 triangles or more into pieces by
|
|
118
|
+
* space at its first draw, as
|
|
115
119
|
* a merged far cell or a large ground whose levels come from elsewhere gains from.
|
|
116
120
|
*
|
|
117
121
|
* @category api/geometry
|
|
@@ -764,8 +768,10 @@ export interface MaterialOptions {
|
|
|
764
768
|
/**
|
|
765
769
|
* How a material uses its alpha: its opacity, times its base color map's alpha, and times its
|
|
766
770
|
* mesh's vertex alpha with `vertexColors`. The `opaque` mode ignores the alpha. The `mask` mode
|
|
767
|
-
* draws nothing where the alpha falls below `alphaCutoff`, and draws the rest opaque.
|
|
768
|
-
*
|
|
771
|
+
* draws nothing where the alpha falls below `alphaCutoff`, and draws the rest opaque.
|
|
772
|
+
*
|
|
773
|
+
* The `hash` mode draws each point of the surface opaque or not at all, by a pattern that stays on
|
|
774
|
+
* the mesh.
|
|
769
775
|
* The alpha then sets how much of the surface draws. The `blend` mode blends the surface over what
|
|
770
776
|
* lies behind it. Blended objects draw after the opaque ones, farthest first.
|
|
771
777
|
*
|
|
@@ -1083,8 +1089,8 @@ export interface StandardMaps {
|
|
|
1083
1089
|
/**
|
|
1084
1090
|
* The thickness of the volume under the surface, in green, in linear color. Its green
|
|
1085
1091
|
* multiplies `thickness`. Only a material created with `transmission` takes it. It keeps a row
|
|
1086
|
-
* slot of its own and samples the specular color map's texture array at its own layer, so
|
|
1087
|
-
* specular color map
|
|
1092
|
+
* slot of its own and samples the specular color map's texture array at its own layer, so it
|
|
1093
|
+
* takes no specular color map, whose sRGB texture never shares that array. A material with
|
|
1088
1094
|
* layers keeps it unless a layer map fills that slot: the sheen's maps and an anisotropy map do.
|
|
1089
1095
|
*/
|
|
1090
1096
|
thicknessMap?: Texture;
|
package/lib/scene/scene.d.ts
CHANGED
|
@@ -833,8 +833,9 @@ export declare class Mesh extends Object3D {
|
|
|
833
833
|
*/
|
|
834
834
|
setRenderOrder(order: number): void;
|
|
835
835
|
/**
|
|
836
|
-
* Raises or lowers the threshold that picks this mesh's levels of detail, as
|
|
837
|
-
* `lod_bias
|
|
836
|
+
* Raises or lowers the threshold that picks this mesh's levels of detail, as the inverse of
|
|
837
|
+
* Godot's `lod_bias`: a Godot bias of 2 is about a null3D bias of 0.5. A bias above 1 makes
|
|
838
|
+
* every switch happen nearer, so the object draws
|
|
838
839
|
* coarser levels. A bias below 1 keeps its detail, which a hero object wants. The bias
|
|
839
840
|
* multiplies the threshold of the level switches and of the distance at which the object
|
|
840
841
|
* hides, so both move by the same factor. The default is 1. The object's mesh needs levels
|
|
@@ -882,6 +883,21 @@ export declare abstract class Camera extends Object3D {
|
|
|
882
883
|
setLayers(mask: number): void;
|
|
883
884
|
/** Sets the distances to the near and far clipping planes. */
|
|
884
885
|
setNearFar(near: number, far: number): void;
|
|
886
|
+
/**
|
|
887
|
+
* The lens shift: how far the view sits right of and above the camera's axis, as fractions of the
|
|
888
|
+
* view's width and height. The array is the camera's own and changes with `setLensShift`, so
|
|
889
|
+
* copy it to keep a value.
|
|
890
|
+
*/
|
|
891
|
+
get lensShift(): readonly [number, number];
|
|
892
|
+
/**
|
|
893
|
+
* Moves the view off the camera's axis, as a shift lens on a real camera does: right by `x`
|
|
894
|
+
* times the view's width, and up by `y` times its height. The perspective stays as it is, so the
|
|
895
|
+
* image is a crop of a wider view from the same place. A shift of 0.25 across puts the camera's
|
|
896
|
+
* axis, and a `target` it looks at, a quarter of the width left of the middle. Culling,
|
|
897
|
+
* shadows, picking, `screenToRay`, `worldToScreen`, views and labels all follow the shifted
|
|
898
|
+
* view. The default is no shift. It allocates nothing.
|
|
899
|
+
*/
|
|
900
|
+
setLensShift(x: number, y: number): void;
|
|
885
901
|
/**
|
|
886
902
|
* Writes the ray from the camera through a point on the canvas into `out`: `x` and `y` are CSS
|
|
887
903
|
* pixels from the canvas's top-left corner, as `input.pointer` gives them. A perspective ray
|