@null3d/engine 0.0.0-stage → 0.1.0
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/LICENSE-APACHE +176 -0
- package/LICENSE-MIT +21 -0
- package/README.md +108 -2
- package/THIRD-PARTY-NOTICES.txt +637 -0
- package/dist/wasm/single/null3d.js +3972 -0
- package/dist/wasm/single/null3d_bg.wasm +0 -0
- package/dist/wasm/threaded/null3d.js +3988 -0
- package/dist/wasm/threaded/null3d_bg.wasm +0 -0
- package/docs/api/animation.md +492 -0
- package/docs/api/assets.md +400 -0
- package/docs/api/cameras.md +161 -0
- package/docs/api/controls.md +319 -0
- package/docs/api/debug.md +450 -0
- package/docs/api/engine.md +254 -0
- package/docs/api/feature-draws.md +172 -0
- package/docs/api/feature-effects.md +137 -0
- package/docs/api/feature-instances.md +154 -0
- package/docs/api/features.md +323 -0
- package/docs/api/geometry.md +307 -0
- package/docs/api/grass.md +114 -0
- package/docs/api/impostors.md +274 -0
- package/docs/api/input.md +238 -0
- package/docs/api/lights.md +266 -0
- package/docs/api/lines.md +163 -0
- package/docs/api/materials.md +875 -0
- package/docs/api/math.md +129 -0
- package/docs/api/objects.md +155 -0
- package/docs/api/page.md +97 -0
- package/docs/api/particles.md +205 -0
- package/docs/api/points.md +130 -0
- package/docs/api/post.md +494 -0
- package/docs/api/quality.md +200 -0
- package/docs/api/raycast.md +269 -0
- package/docs/api/reference/animation.md +158 -0
- package/docs/api/reference/assets.md +335 -0
- package/docs/api/reference/cameras.md +138 -0
- package/docs/api/reference/controls.md +463 -0
- package/docs/api/reference/debug.md +586 -0
- package/docs/api/reference/engine.md +647 -0
- package/docs/api/reference/feature-draws.md +94 -0
- package/docs/api/reference/feature-effects.md +32 -0
- package/docs/api/reference/feature-instances.md +63 -0
- package/docs/api/reference/features.md +361 -0
- package/docs/api/reference/geometry.md +856 -0
- package/docs/api/reference/grass.md +131 -0
- package/docs/api/reference/impostors.md +368 -0
- package/docs/api/reference/input.md +121 -0
- package/docs/api/reference/lights.md +257 -0
- package/docs/api/reference/lines.md +84 -0
- package/docs/api/reference/materials.md +375 -0
- package/docs/api/reference/math.md +229 -0
- package/docs/api/reference/objects.md +103 -0
- package/docs/api/reference/particles.md +336 -0
- package/docs/api/reference/points.md +57 -0
- package/docs/api/reference/post.md +244 -0
- package/docs/api/reference/quality.md +213 -0
- package/docs/api/reference/raycast.md +94 -0
- package/docs/api/reference/render.md +238 -0
- package/docs/api/reference/scene.md +543 -0
- package/docs/api/reference/sketch.md +125 -0
- package/docs/api/reference/sound.md +203 -0
- package/docs/api/reference/splats.md +214 -0
- package/docs/api/reference/sprites.md +71 -0
- package/docs/api/reference/tasks.md +92 -0
- package/docs/api/reference/terrain.md +161 -0
- package/docs/api/reference/textures.md +153 -0
- package/docs/api/reference/three-compat.md +60 -0
- package/docs/api/reference/time.md +25 -0
- package/docs/api/reference/ui.md +52 -0
- package/docs/api/reference/vertex-draws.md +55 -0
- package/docs/api/reference/water.md +430 -0
- package/docs/api/reference/wind.md +106 -0
- package/docs/api/render.md +499 -0
- package/docs/api/scene.md +606 -0
- package/docs/api/sketch.md +231 -0
- package/docs/api/sound.md +169 -0
- package/docs/api/splats.md +264 -0
- package/docs/api/sprites.md +169 -0
- package/docs/api/tasks.md +106 -0
- package/docs/api/terrain.md +118 -0
- package/docs/api/textures.md +272 -0
- package/docs/api/three-compat.md +102 -0
- package/docs/api/time.md +134 -0
- package/docs/api/ui.md +134 -0
- package/docs/api/vertex-draws.md +171 -0
- package/docs/api/water.md +486 -0
- package/docs/api/wind.md +375 -0
- package/docs/cli/null3d.md +603 -0
- package/docs/concepts/architecture.md +174 -0
- package/docs/concepts/assets.md +128 -0
- package/docs/concepts/backends.md +197 -0
- package/docs/concepts/color-management.md +134 -0
- package/docs/concepts/culling.md +227 -0
- package/docs/concepts/handles.md +93 -0
- package/docs/concepts/instances.md +285 -0
- package/docs/concepts/large-worlds.md +126 -0
- package/docs/concepts/lighting.md +587 -0
- package/docs/concepts/lod.md +241 -0
- package/docs/concepts/materials.md +128 -0
- package/docs/concepts/particle-buffer.md +201 -0
- package/docs/concepts/post-processing.md +420 -0
- package/docs/concepts/quality-preset-tables.md +94 -0
- package/docs/concepts/quality-presets.md +341 -0
- package/docs/concepts/render-graph.md +222 -0
- package/docs/concepts/render-layers.md +111 -0
- package/docs/concepts/shadows.md +448 -0
- package/docs/concepts/static-dynamic.md +113 -0
- package/docs/cookbook/index.md +664 -0
- package/docs/data/threejs-mapping.json +2152 -0
- package/docs/errors/E1101.md +23 -0
- package/docs/errors/E1102.md +23 -0
- package/docs/errors/E1103.md +23 -0
- package/docs/errors/E1104.md +23 -0
- package/docs/errors/E1105.md +23 -0
- package/docs/errors/E1106.md +23 -0
- package/docs/errors/E1107.md +23 -0
- package/docs/errors/E1108.md +23 -0
- package/docs/errors/E1109.md +23 -0
- package/docs/errors/E1110.md +23 -0
- package/docs/errors/E1111.md +23 -0
- package/docs/errors/E1112.md +23 -0
- package/docs/errors/E1203.md +23 -0
- package/docs/errors/E1204.md +23 -0
- package/docs/errors/E1205.md +23 -0
- package/docs/errors/E1206.md +23 -0
- package/docs/errors/E1207.md +23 -0
- package/docs/errors/E1208.md +23 -0
- package/docs/errors/E1209.md +23 -0
- package/docs/errors/E1213.md +23 -0
- package/docs/errors/E1214.md +23 -0
- package/docs/errors/E1215.md +23 -0
- package/docs/errors/E1216.md +23 -0
- package/docs/errors/E1217.md +23 -0
- package/docs/errors/E1218.md +23 -0
- package/docs/errors/E1219.md +23 -0
- package/docs/errors/E1220.md +23 -0
- package/docs/errors/E1221.md +23 -0
- package/docs/errors/E1222.md +23 -0
- package/docs/errors/E1223.md +23 -0
- package/docs/errors/E1224.md +23 -0
- package/docs/errors/E1225.md +23 -0
- package/docs/errors/E1301.md +23 -0
- package/docs/errors/E1302.md +23 -0
- package/docs/errors/E1303.md +23 -0
- package/docs/errors/E1304.md +23 -0
- package/docs/errors/E1305.md +23 -0
- package/docs/errors/E1306.md +23 -0
- package/docs/errors/E1307.md +23 -0
- package/docs/errors/E1401.md +23 -0
- package/docs/errors/E1402.md +23 -0
- package/docs/errors/E1403.md +23 -0
- package/docs/errors/E1404.md +23 -0
- package/docs/errors/E1405.md +23 -0
- package/docs/errors/E1406.md +23 -0
- package/docs/errors/E1407.md +23 -0
- package/docs/errors/E1408.md +23 -0
- package/docs/errors/E1409.md +23 -0
- package/docs/errors/E1410.md +23 -0
- package/docs/errors/E1411.md +23 -0
- package/docs/errors/E1412.md +23 -0
- package/docs/errors/E1413.md +23 -0
- package/docs/errors/E1414.md +23 -0
- package/docs/errors/E1415.md +23 -0
- package/docs/errors/E1416.md +23 -0
- package/docs/errors/E1417.md +23 -0
- package/docs/errors/E1418.md +23 -0
- package/docs/errors/E1419.md +23 -0
- package/docs/errors/E1420.md +23 -0
- package/docs/errors/E1421.md +23 -0
- package/docs/errors/E1422.md +23 -0
- package/docs/errors/E1423.md +23 -0
- package/docs/errors/E1424.md +23 -0
- package/docs/errors/E1425.md +23 -0
- package/docs/errors/E1426.md +23 -0
- package/docs/errors/E1430.md +23 -0
- package/docs/errors/E1431.md +23 -0
- package/docs/errors/E1432.md +23 -0
- package/docs/errors/E1433.md +23 -0
- package/docs/errors/E1434.md +23 -0
- package/docs/errors/E1435.md +23 -0
- package/docs/errors/E1436.md +23 -0
- package/docs/errors/E1437.md +23 -0
- package/docs/errors/E1501.md +23 -0
- package/docs/errors/E1502.md +23 -0
- package/docs/errors/E1503.md +23 -0
- package/docs/errors/E1504.md +23 -0
- package/docs/errors/E1505.md +23 -0
- package/docs/errors/E1506.md +23 -0
- package/docs/errors/index.md +93 -0
- package/docs/getting-started/cdn.md +235 -0
- package/docs/getting-started/first-scene.md +129 -0
- package/docs/getting-started/hosting.md +400 -0
- package/docs/getting-started/install.md +112 -0
- package/docs/getting-started/network-use.md +96 -0
- package/docs/getting-started/project-structure.md +78 -0
- package/docs/getting-started/third-party-notices.md +94 -0
- package/docs/guides/accessibility.md +96 -0
- package/docs/guides/add-ons.md +160 -0
- package/docs/guides/agents.md +77 -0
- package/docs/guides/assets-pipeline.md +505 -0
- package/docs/guides/audio.md +148 -0
- package/docs/guides/baked-light-data.md +176 -0
- package/docs/guides/car-paint.md +121 -0
- package/docs/guides/content-pages.md +238 -0
- package/docs/guides/custom-passes.md +586 -0
- package/docs/guides/custom-shaders.md +293 -0
- package/docs/guides/debugging.md +236 -0
- package/docs/guides/deploying.md +115 -0
- package/docs/guides/deterministic-simulation.md +226 -0
- package/docs/guides/first-use-shaders.md +57 -0
- package/docs/guides/lens-kit.md +134 -0
- package/docs/guides/loading-screens.md +263 -0
- package/docs/guides/multiple-views.md +122 -0
- package/docs/guides/performance.md +405 -0
- package/docs/guides/phones.md +138 -0
- package/docs/guides/physics.md +202 -0
- package/docs/guides/screens.md +125 -0
- package/docs/guides/start-time.md +328 -0
- package/docs/guides/testing.md +245 -0
- package/docs/guides/ui-overlays.md +182 -0
- package/docs/guides/video-textures.md +110 -0
- package/docs/index.md +49 -0
- package/docs/pages.md +242 -0
- package/docs/porting/react-three-fiber.md +238 -0
- package/docs/porting/threejs-loop-and-threads.md +229 -0
- package/docs/porting/threejs-mapping.md +297 -0
- package/docs/porting/threejs-materials.md +222 -0
- package/docs/porting/threejs-overview.md +228 -0
- package/docs/porting/threejs-postprocessing.md +256 -0
- package/docs/porting/threejs-shaders.md +308 -0
- package/docs/porting/threejs-unsupported.md +91 -0
- package/docs/porting/verification.md +191 -0
- package/docs/shaders/builtins.md +129 -0
- package/docs/shaders/library.md +1374 -0
- package/docs/shaders/surface-functions.md +626 -0
- package/docs/shaders/wgsl-rules.md +126 -0
- package/levels/pieces.d.ts +178 -0
- package/levels/pieces.js +759 -0
- package/levels/planner.d.ts +126 -0
- package/levels/planner.js +682 -0
- package/lib/debug/channel.d.ts +103 -0
- package/lib/debug/channel.js +269 -0
- package/lib/debug/debug.d.ts +180 -0
- package/lib/debug/debug.js +4 -0
- package/lib/debug/draw.d.ts +146 -0
- package/lib/debug/draw.js +719 -0
- package/lib/debug/frame-target.d.ts +11 -0
- package/lib/debug/frame-target.js +31 -0
- package/lib/debug/inspector.d.ts +60 -0
- package/lib/debug/inspector.js +475 -0
- package/lib/debug/overlay-look.d.ts +162 -0
- package/lib/debug/overlay-look.js +1365 -0
- package/lib/debug/overlay.d.ts +68 -0
- package/lib/debug/overlay.js +195 -0
- package/lib/debug/page-meters.d.ts +139 -0
- package/lib/debug/page-meters.js +267 -0
- package/lib/debug/sketch-debug.d.ts +41 -0
- package/lib/debug/sketch-debug.js +86 -0
- package/lib/debug/stats-options.d.ts +15 -0
- package/lib/debug/stats-options.js +3 -0
- package/lib/debug/stats-panel.d.ts +94 -0
- package/lib/debug/stats-panel.js +123 -0
- package/lib/debug/stats-text.d.ts +169 -0
- package/lib/debug/stats-text.js +126 -0
- package/lib/debug/stats.d.ts +195 -0
- package/lib/debug/stats.js +252 -0
- package/lib/debug/view-names.d.ts +15 -0
- package/lib/debug/view-names.js +22 -0
- package/lib/errors/checks.d.ts +24 -0
- package/lib/errors/checks.js +38 -0
- package/lib/errors/codes.d.ts +15 -0
- package/lib/errors/codes.js +489 -0
- package/lib/errors/core-failure.d.ts +19 -0
- package/lib/errors/core-failure.js +127 -0
- package/lib/errors/engine-error-core.d.ts +21 -0
- package/lib/errors/engine-error-core.js +39 -0
- package/lib/errors/engine-error.d.ts +38 -0
- package/lib/errors/engine-error.js +132 -0
- package/lib/errors/fixes.d.ts +89 -0
- package/lib/errors/fixes.js +86 -0
- package/lib/errors/message.d.ts +4 -0
- package/lib/errors/message.js +10 -0
- package/lib/generated/core.d.ts +657 -0
- package/lib/generated/core.js +659 -0
- package/lib/generated/gpu.d.ts +412 -0
- package/lib/generated/gpu.js +414 -0
- package/lib/generated/shader-features.d.ts +8 -0
- package/lib/generated/shader-permutations.d.ts +6 -0
- package/lib/generated/shader-permutations.js +9 -0
- package/lib/generated/shaders-environment-glsl.d.ts +11 -0
- package/lib/generated/shaders-environment-wgsl.d.ts +11 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-coverage-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-coverage.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-displacement-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-displacement.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-hash-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-hash.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-lod-fade-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-lod-fade.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-displacement-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-displacement.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-lod-fade-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-lod-fade.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-hash-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-hash.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-hash-and-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-hash-and-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-hash-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-hash-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-hash-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-hash-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-hash-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-hash-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-hash-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-hash.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-lod-fade-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-lod-fade-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-lod-fade-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-lod-fade-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-lod-fade-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-lod-fade.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-morph-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-morph-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-morph-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-morph-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-morph-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-morph-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-morph-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-morph-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-row-values-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-row-values-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-row-values-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-row-values-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-skinning-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-skinning-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-skinning-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-skinning-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-skinning-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-skinning-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-bump.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-displacement-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-displacement.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-lod-fade-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-lod-fade.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-hash-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-hash.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-hash-and-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-hash-and-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-hash-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-hash-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-hash-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-hash-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-hash-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-hash.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-lod-fade-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-lod-fade-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-lod-fade-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-lod-fade.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-morph-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-morph-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-morph-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-morph-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-morph-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-morph-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-row-values-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-row-values-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-skinning-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-skinning-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-skinning-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-skinning-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement-and-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement-and-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-lod-fade-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-lod-fade-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-lod-fade-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-lod-fade-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-lod-fade-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-lod-fade.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-morph-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-morph-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-morph-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-morph-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-morph-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-morph-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-row-values-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-row-values-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-skinning-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-skinning-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-skinning-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-skinning-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-coverage.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-hash-and-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-hash-and-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-hash-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-hash-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-hash-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-hash-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-hash-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-hash-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-hash-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-hash.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-moment-and-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-moment-and-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-moment-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-moment-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-moment-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-moment-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-moment-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-moment-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-moment-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-moment.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-morph-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-morph-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-morph-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-morph-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-morph-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-morph-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-morph-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-morph-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-row-values-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-row-values-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-row-values-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-row-values-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-skinning-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-skinning-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-skinning-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-skinning-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-skinning-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-skinning-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-displacement.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-morph-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-morph-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-morph-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-morph-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-row-values-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-row-values-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-skinning-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-skinning-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-hash-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-hash.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-lines.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-lod-fade-and-row-values-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-lod-fade-and-row-values-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-lod-fade-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-lod-fade-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-lod-fade-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-lod-fade-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-lod-fade-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-lod-fade.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-morph-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-morph-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-morph-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-morph-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-row-values-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-row-values-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-skinning-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-skinning-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-moment-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-moment.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-skinning-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-skinning-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-skinning-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-skinning-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-skinning-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-skinning-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-row-values-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-row-values-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-row-values-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-row-values-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-skinning-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-skinning-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-skinning-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-skinning-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-skinning-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-skinning-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-area-lights-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-coverage-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-coverage.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-displacement-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-displacement.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-hash-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-hash.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-lod-fade-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-lod-fade.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-displacement-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-displacement.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-lod-fade-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-lod-fade.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coverage-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-coverage.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-hash-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-hash.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-displacement-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-displacement.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-hash-and-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-hash-and-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-hash-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-hash-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-hash-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-hash-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-hash-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-hash-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-hash-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-hash.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-lod-fade-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-lod-fade-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-lod-fade-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-lod-fade-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-lod-fade-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-lod-fade.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-morph-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-morph-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-morph-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-morph-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-morph-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-morph-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-morph-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-morph-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-row-values-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-row-values-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-row-values-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-row-values-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-skinning-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-skinning-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-skinning-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-skinning-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-skinning-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-skinning-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-bump-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-coat-sheen-and-coverage-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-coat-sheen-and-coverage.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-coat-sheen-and-displacement-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-coat-sheen-and-displacement.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-coat-sheen-and-hash-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-coat-sheen-and-hash.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-coat-sheen-and-lod-fade-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-coat-sheen-and-lod-fade.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-coat-sheen-and-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-coat-sheen-and-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-coat-sheen-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-coat-sheen-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-coat-sheen-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-coat-sheen-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-coat-sheen-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-coat-sheen-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-coat-sheen-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-coat-sheen-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-coverage-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-coverage.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-cutout.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-decals-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-decals.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-displacement-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-displacement.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-hash-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-hash.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-lod-fade-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-lod-fade.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-moment-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-moment.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-morph-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-morph.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-motion.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-picking.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-probe-grid-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-probe-grid.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-row-values.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-skinning.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-sprites.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-subsurface-half.d.ts +3 -0
- package/lib/generated/shaders-glsl-combos-subsurface.d.ts +3 -0
- package/lib/generated/shaders-probe-glsl.d.ts +11 -0
- package/lib/generated/shaders-probe-wgsl.d.ts +11 -0
- package/lib/generated/shaders-sky-volume-env-glsl.d.ts +11 -0
- package/lib/generated/shaders-sky-volume-env-wgsl.d.ts +11 -0
- package/lib/generated/shaders-sky-volume-panorama-glsl.d.ts +11 -0
- package/lib/generated/shaders-sky-volume-panorama-wgsl.d.ts +11 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-bump-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-bump.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-coat-sheen-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-coat-sheen.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-coverage-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-coverage.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-displacement-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-displacement.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-hash-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-hash.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-instance-index-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-instance-index.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-lines.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-lod-fade-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-lod-fade.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-moment-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-moment.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-row-values.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-skinning.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-translucency-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-translucency.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-transmission-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-transmission.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-weighted-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-area-lights-and-weighted.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-bump-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-bump.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-coat-sheen-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-coat-sheen.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-coverage-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-coverage.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-cutout.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-decals-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-decals.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-displacement-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-displacement.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-hash-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-hash.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-instance-index-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-instance-index.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-lod-fade-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-lod-fade.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-moment-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-moment.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-motion.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-picking.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-probe-grid-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-probe-grid.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-row-values-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-row-values.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-skinning-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-skinning.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-sprites.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-subsurface-half.d.ts +3 -0
- package/lib/generated/shaders-wgsl-combos-subsurface.d.ts +3 -0
- package/lib/generated/shaders.d.ts +1146 -0
- package/lib/gpu/canvas-release.d.ts +20 -0
- package/lib/gpu/canvas-release.js +67 -0
- package/lib/gpu/completion.d.ts +35 -0
- package/lib/gpu/completion.js +256 -0
- package/lib/gpu/device-shaders.d.ts +69 -0
- package/lib/gpu/device-shaders.js +177 -0
- package/lib/gpu/early-builds.d.ts +68 -0
- package/lib/gpu/early-builds.js +158 -0
- package/lib/gpu/effect-join.d.ts +83 -0
- package/lib/gpu/effect-join.js +134 -0
- package/lib/gpu/effect-joiner.d.ts +14 -0
- package/lib/gpu/effect-joiner.js +165 -0
- package/lib/gpu/environment-steps.d.ts +135 -0
- package/lib/gpu/environment-steps.js +210 -0
- package/lib/gpu/environment-words.d.ts +14 -0
- package/lib/gpu/environment-words.js +19 -0
- package/lib/gpu/environment.d.ts +4 -0
- package/lib/gpu/environment.js +8 -0
- package/lib/gpu/float-bits.d.ts +2 -0
- package/lib/gpu/float-bits.js +9 -0
- package/lib/gpu/line-vertices.d.ts +1 -0
- package/lib/gpu/line-vertices.js +14 -0
- package/lib/gpu/memory.d.ts +19 -0
- package/lib/gpu/memory.js +50 -0
- package/lib/gpu/particle-records.d.ts +1 -0
- package/lib/gpu/particle-records.js +15 -0
- package/lib/gpu/pipeline-name.d.ts +6 -0
- package/lib/gpu/pipeline-name.js +23 -0
- package/lib/gpu/probe-steps.d.ts +22 -0
- package/lib/gpu/probe-steps.js +43 -0
- package/lib/gpu/readback.d.ts +32 -0
- package/lib/gpu/readback.js +163 -0
- package/lib/gpu/variants.d.ts +16 -0
- package/lib/gpu/variants.js +67 -0
- package/lib/gpu/vertex-format.d.ts +46 -0
- package/lib/gpu/vertex-format.js +111 -0
- package/lib/gpu/webgl2/backend.d.ts +714 -0
- package/lib/gpu/webgl2/backend.js +2964 -0
- package/lib/gpu/webgl2/call-timing.d.ts +34 -0
- package/lib/gpu/webgl2/call-timing.js +143 -0
- package/lib/gpu/webgl2/context.d.ts +31 -0
- package/lib/gpu/webgl2/context.js +111 -0
- package/lib/gpu/webgl2/depth.d.ts +25 -0
- package/lib/gpu/webgl2/depth.js +30 -0
- package/lib/gpu/webgl2/environment.d.ts +65 -0
- package/lib/gpu/webgl2/environment.js +572 -0
- package/lib/gpu/webgl2/gpu-timer.d.ts +25 -0
- package/lib/gpu/webgl2/gpu-timer.js +93 -0
- package/lib/gpu/webgl2/probes.d.ts +38 -0
- package/lib/gpu/webgl2/probes.js +117 -0
- package/lib/gpu/webgl2/programs.d.ts +238 -0
- package/lib/gpu/webgl2/programs.js +487 -0
- package/lib/gpu/webgpu/backend.d.ts +460 -0
- package/lib/gpu/webgpu/backend.js +1812 -0
- package/lib/gpu/webgpu/buffer-reads.d.ts +42 -0
- package/lib/gpu/webgpu/buffer-reads.js +95 -0
- package/lib/gpu/webgpu/culled-counts.d.ts +79 -0
- package/lib/gpu/webgpu/culled-counts.js +259 -0
- package/lib/gpu/webgpu/draw-path-probe.d.ts +37 -0
- package/lib/gpu/webgpu/draw-path-probe.js +187 -0
- package/lib/gpu/webgpu/environment.d.ts +36 -0
- package/lib/gpu/webgpu/environment.js +735 -0
- package/lib/gpu/webgpu/first-pass.d.ts +13 -0
- package/lib/gpu/webgpu/first-pass.js +61 -0
- package/lib/gpu/webgpu/gpu-timer.d.ts +67 -0
- package/lib/gpu/webgpu/gpu-timer.js +328 -0
- package/lib/gpu/webgpu/indirect-arguments.d.ts +42 -0
- package/lib/gpu/webgpu/indirect-arguments.js +156 -0
- package/lib/gpu/webgpu/pipelines.d.ts +264 -0
- package/lib/gpu/webgpu/pipelines.js +2013 -0
- package/lib/gpu/webgpu/probes.d.ts +27 -0
- package/lib/gpu/webgpu/probes.js +190 -0
- package/lib/gpu/webgpu/reusable.d.ts +74 -0
- package/lib/gpu/webgpu/reusable.js +212 -0
- package/lib/gpu/webgpu/staging.d.ts +79 -0
- package/lib/gpu/webgpu/staging.js +238 -0
- package/lib/gpu/webgpu/upload-routes.d.ts +55 -0
- package/lib/gpu/webgpu/upload-routes.js +128 -0
- package/lib/index.d.ts +121 -0
- package/lib/index.js +54 -0
- package/lib/math/color.d.ts +18 -0
- package/lib/math/color.js +71 -0
- package/lib/math/create-math.d.ts +101 -0
- package/lib/math/create-math.js +207 -0
- package/lib/math/hex.d.ts +8 -0
- package/lib/math/hex.js +38 -0
- package/lib/math/index.d.ts +2 -0
- package/lib/math/index.js +11 -0
- package/lib/math/mat4.d.ts +22 -0
- package/lib/math/mat4.js +206 -0
- package/lib/math/math.d.ts +16 -0
- package/lib/math/math.js +42 -0
- package/lib/math/namespaces/math.d.ts +7 -0
- package/lib/math/namespaces/math.js +14 -0
- package/lib/math/namespaces/quat.d.ts +20 -0
- package/lib/math/namespaces/quat.js +30 -0
- package/lib/math/namespaces/vec3.d.ts +4 -0
- package/lib/math/namespaces/vec3.js +8 -0
- package/lib/math/quat.d.ts +36 -0
- package/lib/math/quat.js +224 -0
- package/lib/math/random.d.ts +16 -0
- package/lib/math/random.js +57 -0
- package/lib/math/types.d.ts +43 -0
- package/lib/math/types.js +4 -0
- package/lib/math/vec3.d.ts +43 -0
- package/lib/math/vec3.js +187 -0
- package/lib/page/abortable.d.ts +2 -0
- package/lib/page/abortable.js +19 -0
- package/lib/page/browser-check.d.ts +8 -0
- package/lib/page/browser-check.js +23 -0
- package/lib/page/canvas-watch.d.ts +34 -0
- package/lib/page/canvas-watch.js +141 -0
- package/lib/page/capabilities.d.ts +201 -0
- package/lib/page/capabilities.js +409 -0
- package/lib/page/check-store.d.ts +54 -0
- package/lib/page/check-store.js +169 -0
- package/lib/page/display.d.ts +2 -0
- package/lib/page/display.js +25 -0
- package/lib/page/early-core.d.ts +1 -0
- package/lib/page/early-core.js +23 -0
- package/lib/page/engine.d.ts +942 -0
- package/lib/page/engine.js +2459 -0
- package/lib/page/first-frame.d.ts +16 -0
- package/lib/page/first-frame.js +35 -0
- package/lib/page/frame-stats.d.ts +402 -0
- package/lib/page/frame-stats.js +389 -0
- package/lib/page/gamepads.d.ts +37 -0
- package/lib/page/gamepads.js +123 -0
- package/lib/page/held-input.d.ts +19 -0
- package/lib/page/held-input.js +54 -0
- package/lib/page/hold.d.ts +186 -0
- package/lib/page/hold.js +49 -0
- package/lib/page/input-ring.d.ts +13 -0
- package/lib/page/input-ring.js +25 -0
- package/lib/page/input.d.ts +6 -0
- package/lib/page/input.js +159 -0
- package/lib/page/isolation-check.d.ts +14 -0
- package/lib/page/isolation-check.js +21 -0
- package/lib/page/label-loop.d.ts +80 -0
- package/lib/page/label-loop.js +417 -0
- package/lib/page/labels.d.ts +56 -0
- package/lib/page/labels.js +102 -0
- package/lib/page/limits.d.ts +321 -0
- package/lib/page/limits.js +323 -0
- package/lib/page/loader.d.ts +78 -0
- package/lib/page/loader.js +149 -0
- package/lib/page/main-thread.d.ts +10 -0
- package/lib/page/main-thread.js +41 -0
- package/lib/page/memory-pool.d.ts +26 -0
- package/lib/page/memory-pool.js +69 -0
- package/lib/page/ownership.d.ts +65 -0
- package/lib/page/ownership.js +166 -0
- package/lib/page/permutation-recording.d.ts +26 -0
- package/lib/page/permutation-recording.js +32 -0
- package/lib/page/pipeline-store.d.ts +25 -0
- package/lib/page/pipeline-store.js +84 -0
- package/lib/page/pointer-lock.d.ts +14 -0
- package/lib/page/pointer-lock.js +60 -0
- package/lib/page/preferences.d.ts +2 -0
- package/lib/page/preferences.js +11 -0
- package/lib/page/record-button.d.ts +5 -0
- package/lib/page/record-button.js +60 -0
- package/lib/page/start-marker.d.ts +47 -0
- package/lib/page/start-marker.js +119 -0
- package/lib/page/stats-switch.d.ts +16 -0
- package/lib/page/stats-switch.js +38 -0
- package/lib/page/stop-jobs.d.ts +37 -0
- package/lib/page/stop-jobs.js +87 -0
- package/lib/page/switches.d.ts +347 -0
- package/lib/page/switches.js +150 -0
- package/lib/page/videos.d.ts +70 -0
- package/lib/page/videos.js +244 -0
- package/lib/quality/budget.d.ts +14 -0
- package/lib/quality/budget.js +25 -0
- package/lib/quality/check.d.ts +119 -0
- package/lib/quality/check.js +84 -0
- package/lib/quality/chooser.d.ts +98 -0
- package/lib/quality/chooser.js +108 -0
- package/lib/quality/device-hints.d.ts +8 -0
- package/lib/quality/device-hints.js +18 -0
- package/lib/quality/governor.d.ts +571 -0
- package/lib/quality/governor.js +1293 -0
- package/lib/quality/preset-docs.d.ts +402 -0
- package/lib/quality/preset-docs.js +179 -0
- package/lib/quality/presets.d.ts +821 -0
- package/lib/quality/presets.js +678 -0
- package/lib/render/direct-loop.d.ts +4 -0
- package/lib/render/direct-loop.js +52 -0
- package/lib/render/draw.d.ts +66 -0
- package/lib/render/draw.js +111 -0
- package/lib/render/load-draw.d.ts +12 -0
- package/lib/render/load-draw.js +18 -0
- package/lib/render/loop.d.ts +241 -0
- package/lib/render/loop.js +566 -0
- package/lib/render/loss.d.ts +53 -0
- package/lib/render/loss.js +127 -0
- package/lib/render/pacer.d.ts +24 -0
- package/lib/render/pacer.js +51 -0
- package/lib/render/recovery.d.ts +82 -0
- package/lib/render/recovery.js +160 -0
- package/lib/render/refresh.d.ts +38 -0
- package/lib/render/refresh.js +111 -0
- package/lib/render/renderer.d.ts +192 -0
- package/lib/render/renderer.js +295 -0
- package/lib/render/scene-renderer.d.ts +135 -0
- package/lib/render/scene-renderer.js +216 -0
- package/lib/render/shader-salt.d.ts +5 -0
- package/lib/render/shader-salt.js +31 -0
- package/lib/render/webgl2-renderers.d.ts +11 -0
- package/lib/render/webgl2-renderers.js +227 -0
- package/lib/render/webgpu-renderers.d.ts +10 -0
- package/lib/render/webgpu-renderers.js +254 -0
- package/lib/scene/addon-debug-views.d.ts +30 -0
- package/lib/scene/addon-debug-views.js +63 -0
- package/lib/scene/animation.d.ts +547 -0
- package/lib/scene/animation.js +1425 -0
- package/lib/scene/area-light-tables.d.ts +32 -0
- package/lib/scene/area-light-tables.js +89 -0
- package/lib/scene/assets.d.ts +375 -0
- package/lib/scene/assets.js +736 -0
- package/lib/scene/background.d.ts +238 -0
- package/lib/scene/background.js +470 -0
- package/lib/scene/baked-light.d.ts +60 -0
- package/lib/scene/baked-light.js +300 -0
- package/lib/scene/builtin-environments.d.ts +36 -0
- package/lib/scene/builtin-environments.js +43 -0
- package/lib/scene/chunk-rows.d.ts +81 -0
- package/lib/scene/chunk-rows.js +146 -0
- package/lib/scene/color.d.ts +22 -0
- package/lib/scene/color.js +45 -0
- package/lib/scene/derived-cache.d.ts +139 -0
- package/lib/scene/derived-cache.js +547 -0
- package/lib/scene/downloads.d.ts +2 -0
- package/lib/scene/downloads.js +371 -0
- package/lib/scene/effects.d.ts +193 -0
- package/lib/scene/effects.js +476 -0
- package/lib/scene/environment-file.d.ts +22 -0
- package/lib/scene/environment-file.js +81 -0
- package/lib/scene/environment.d.ts +57 -0
- package/lib/scene/environment.js +131 -0
- package/lib/scene/fake-call-values.d.ts +8 -0
- package/lib/scene/fake-call-values.js +51 -0
- package/lib/scene/feature-draws.d.ts +169 -0
- package/lib/scene/feature-draws.js +269 -0
- package/lib/scene/feature-effects.d.ts +42 -0
- package/lib/scene/feature-effects.js +155 -0
- package/lib/scene/feature-host.d.ts +129 -0
- package/lib/scene/feature-host.js +299 -0
- package/lib/scene/feature-instances.d.ts +130 -0
- package/lib/scene/feature-instances.js +326 -0
- package/lib/scene/features.d.ts +412 -0
- package/lib/scene/features.js +550 -0
- package/lib/scene/file-limits.d.ts +70 -0
- package/lib/scene/file-limits.js +224 -0
- package/lib/scene/fog.d.ts +101 -0
- package/lib/scene/fog.js +148 -0
- package/lib/scene/frame-cameras.d.ts +175 -0
- package/lib/scene/frame-cameras.js +492 -0
- package/lib/scene/gltf-animation.d.ts +129 -0
- package/lib/scene/gltf-animation.js +887 -0
- package/lib/scene/gltf-draco.d.ts +9 -0
- package/lib/scene/gltf-draco.js +224 -0
- package/lib/scene/gltf-extensions.d.ts +31 -0
- package/lib/scene/gltf-extensions.js +92 -0
- package/lib/scene/gltf-json.d.ts +49 -0
- package/lib/scene/gltf-json.js +94 -0
- package/lib/scene/gltf-math.d.ts +16 -0
- package/lib/scene/gltf-math.js +129 -0
- package/lib/scene/gltf-meshopt.d.ts +3 -0
- package/lib/scene/gltf-meshopt.js +48 -0
- package/lib/scene/gltf-parse.d.ts +600 -0
- package/lib/scene/gltf-parse.js +1854 -0
- package/lib/scene/gltf.d.ts +189 -0
- package/lib/scene/gltf.js +1589 -0
- package/lib/scene/grade-table.d.ts +9 -0
- package/lib/scene/grade-table.js +23 -0
- package/lib/scene/grade-task.d.ts +12 -0
- package/lib/scene/grade-task.js +11 -0
- package/lib/scene/grading.d.ts +110 -0
- package/lib/scene/grading.js +142 -0
- package/lib/scene/half-float.d.ts +4 -0
- package/lib/scene/half-float.js +42 -0
- package/lib/scene/ktx2-cache.d.ts +32 -0
- package/lib/scene/ktx2-cache.js +62 -0
- package/lib/scene/ktx2-file.d.ts +57 -0
- package/lib/scene/ktx2-file.js +207 -0
- package/lib/scene/ktx2-transcode.d.ts +15 -0
- package/lib/scene/ktx2-transcode.js +94 -0
- package/lib/scene/ktx2.d.ts +42 -0
- package/lib/scene/ktx2.js +179 -0
- package/lib/scene/lens.d.ts +61 -0
- package/lib/scene/lens.js +101 -0
- package/lib/scene/level-meshopt.d.ts +20 -0
- package/lib/scene/level-meshopt.js +122 -0
- package/lib/scene/level-pieces.d.ts +24 -0
- package/lib/scene/level-pieces.js +138 -0
- package/lib/scene/level-rule.d.ts +120 -0
- package/lib/scene/level-rule.js +130 -0
- package/lib/scene/level-words.d.ts +19 -0
- package/lib/scene/level-words.js +34 -0
- package/lib/scene/levels-task.d.ts +51 -0
- package/lib/scene/levels-task.js +132 -0
- package/lib/scene/light-images.d.ts +36 -0
- package/lib/scene/light-images.js +88 -0
- package/lib/scene/light-probes.d.ts +240 -0
- package/lib/scene/light-probes.js +644 -0
- package/lib/scene/lines.d.ts +188 -0
- package/lib/scene/lines.js +257 -0
- package/lib/scene/lut-files.d.ts +41 -0
- package/lib/scene/lut-files.js +399 -0
- package/lib/scene/lut.d.ts +55 -0
- package/lib/scene/lut.js +47 -0
- package/lib/scene/memory.d.ts +72 -0
- package/lib/scene/memory.js +159 -0
- package/lib/scene/mesh-arrays.d.ts +110 -0
- package/lib/scene/mesh-arrays.js +701 -0
- package/lib/scene/mesh-levels.d.ts +10 -0
- package/lib/scene/mesh-levels.js +52 -0
- package/lib/scene/namespaces.d.ts +125 -0
- package/lib/scene/namespaces.js +313 -0
- package/lib/scene/panorama-files.d.ts +71 -0
- package/lib/scene/panorama-files.js +1103 -0
- package/lib/scene/panorama.d.ts +23 -0
- package/lib/scene/panorama.js +108 -0
- package/lib/scene/particles.d.ts +452 -0
- package/lib/scene/particles.js +814 -0
- package/lib/scene/pass-reads.d.ts +70 -0
- package/lib/scene/pass-reads.js +220 -0
- package/lib/scene/picks.d.ts +69 -0
- package/lib/scene/picks.js +208 -0
- package/lib/scene/pointer-events.d.ts +202 -0
- package/lib/scene/pointer-events.js +500 -0
- package/lib/scene/post.d.ts +567 -0
- package/lib/scene/post.js +928 -0
- package/lib/scene/prefab.d.ts +109 -0
- package/lib/scene/prefab.js +166 -0
- package/lib/scene/probes.d.ts +71 -0
- package/lib/scene/probes.js +169 -0
- package/lib/scene/property-animation.d.ts +160 -0
- package/lib/scene/property-animation.js +276 -0
- package/lib/scene/queries.d.ts +176 -0
- package/lib/scene/queries.js +393 -0
- package/lib/scene/render.d.ts +487 -0
- package/lib/scene/render.js +829 -0
- package/lib/scene/resources.d.ts +1598 -0
- package/lib/scene/resources.js +2843 -0
- package/lib/scene/rotation.d.ts +6 -0
- package/lib/scene/rotation.js +12 -0
- package/lib/scene/scene.d.ts +1858 -0
- package/lib/scene/scene.js +4680 -0
- package/lib/scene/serial-loads.d.ts +29 -0
- package/lib/scene/serial-loads.js +68 -0
- package/lib/scene/shader-preloads.d.ts +74 -0
- package/lib/scene/shader-preloads.js +116 -0
- package/lib/scene/shader-templates.d.ts +60 -0
- package/lib/scene/shader-templates.js +156 -0
- package/lib/scene/sprites.d.ts +262 -0
- package/lib/scene/sprites.js +292 -0
- package/lib/scene/stale-calls-scenario.d.ts +20 -0
- package/lib/scene/stale-calls-scenario.js +175 -0
- package/lib/scene/textures.d.ts +323 -0
- package/lib/scene/textures.js +953 -0
- package/lib/scene/time-of-day.d.ts +145 -0
- package/lib/scene/time-of-day.js +644 -0
- package/lib/scene/unmarked-writes.d.ts +118 -0
- package/lib/scene/unmarked-writes.js +283 -0
- package/lib/scene/unread-extensions-scenario.d.ts +6 -0
- package/lib/scene/unread-extensions-scenario.js +26 -0
- package/lib/scene/vertex-draws.d.ts +82 -0
- package/lib/scene/vertex-draws.js +85 -0
- package/lib/scene/wgsl-uniforms.d.ts +167 -0
- package/lib/scene/wgsl-uniforms.js +12 -0
- package/lib/shader-artifact.json +1 -0
- package/lib/shared/await-later.d.ts +5 -0
- package/lib/shared/await-later.js +10 -0
- package/lib/shared/control.d.ts +94 -0
- package/lib/shared/control.js +150 -0
- package/lib/shared/core-sources.d.ts +2 -0
- package/lib/shared/core-sources.js +7 -0
- package/lib/shared/core.d.ts +1254 -0
- package/lib/shared/core.js +381 -0
- package/lib/shared/counter.d.ts +52 -0
- package/lib/shared/counter.js +55 -0
- package/lib/shared/dev.d.ts +8 -0
- package/lib/shared/dev.js +13 -0
- package/lib/shared/feature-stats.d.ts +16 -0
- package/lib/shared/feature-stats.js +27 -0
- package/lib/shared/frame-image.d.ts +13 -0
- package/lib/shared/frame-image.js +32 -0
- package/lib/shared/gpu-clock.d.ts +14 -0
- package/lib/shared/gpu-clock.js +38 -0
- package/lib/shared/gpu-counter.d.ts +12 -0
- package/lib/shared/gpu-counter.js +15 -0
- package/lib/shared/gpu-scope.d.ts +14 -0
- package/lib/shared/gpu-scope.js +104 -0
- package/lib/shared/helper-workers.d.ts +4 -0
- package/lib/shared/helper-workers.js +23 -0
- package/lib/shared/images.d.ts +255 -0
- package/lib/shared/images.js +450 -0
- package/lib/shared/import-once.d.ts +6 -0
- package/lib/shared/import-once.js +19 -0
- package/lib/shared/key-codes.d.ts +2 -0
- package/lib/shared/key-codes.js +69 -0
- package/lib/shared/labels.d.ts +94 -0
- package/lib/shared/labels.js +172 -0
- package/lib/shared/memory-area.d.ts +6 -0
- package/lib/shared/memory-area.js +21 -0
- package/lib/shared/memory-figure.d.ts +14 -0
- package/lib/shared/memory-figure.js +18 -0
- package/lib/shared/memory-views.d.ts +48 -0
- package/lib/shared/memory-views.js +90 -0
- package/lib/shared/metrics.d.ts +353 -0
- package/lib/shared/metrics.js +799 -0
- package/lib/shared/page-measurement.d.ts +9 -0
- package/lib/shared/page-measurement.js +37 -0
- package/lib/shared/phase.d.ts +17 -0
- package/lib/shared/phase.js +20 -0
- package/lib/shared/policy.d.ts +20 -0
- package/lib/shared/policy.js +46 -0
- package/lib/shared/recording.d.ts +100 -0
- package/lib/shared/recording.js +378 -0
- package/lib/shared/role.d.ts +10 -0
- package/lib/shared/role.js +13 -0
- package/lib/shared/run-task.d.ts +39 -0
- package/lib/shared/run-task.js +69 -0
- package/lib/shared/slot.d.ts +218 -0
- package/lib/shared/slot.js +221 -0
- package/lib/shared/software.d.ts +24 -0
- package/lib/shared/software.js +22 -0
- package/lib/shared/stats.d.ts +62 -0
- package/lib/shared/stats.js +86 -0
- package/lib/shared/task-failure.d.ts +24 -0
- package/lib/shared/task-failure.js +36 -0
- package/lib/shared/task-host.d.ts +42 -0
- package/lib/shared/task-host.js +60 -0
- package/lib/shared/task-load-error.d.ts +10 -0
- package/lib/shared/task-load-error.js +13 -0
- package/lib/shared/task-modules.d.ts +2 -0
- package/lib/shared/task-modules.js +8 -0
- package/lib/shared/task-pending.d.ts +24 -0
- package/lib/shared/task-pending.js +101 -0
- package/lib/shared/tasks.d.ts +54 -0
- package/lib/shared/tasks.js +426 -0
- package/lib/shared/tier.d.ts +7 -0
- package/lib/shared/tier.js +3 -0
- package/lib/shared/version.d.ts +72 -0
- package/lib/shared/version.js +103 -0
- package/lib/shared/videos.d.ts +15 -0
- package/lib/shared/videos.js +11 -0
- package/lib/shared/wake.d.ts +38 -0
- package/lib/shared/wake.js +76 -0
- package/lib/shared/wasm-limits.d.ts +13 -0
- package/lib/shared/wasm-limits.js +75 -0
- package/lib/shared/wasm.d.ts +34 -0
- package/lib/shared/wasm.js +151 -0
- package/lib/shared/webkit.d.ts +33 -0
- package/lib/shared/webkit.js +59 -0
- package/lib/shared/wgsl-updates.d.ts +9 -0
- package/lib/shared/wgsl-updates.js +8 -0
- package/lib/shared/worker-start.d.ts +56 -0
- package/lib/shared/worker-start.js +186 -0
- package/lib/sketch/clock.d.ts +61 -0
- package/lib/sketch/clock.js +98 -0
- package/lib/sketch/define-sketch.d.ts +269 -0
- package/lib/sketch/define-sketch.js +103 -0
- package/lib/sketch/input-off-scenario.d.ts +7 -0
- package/lib/sketch/input-off-scenario.js +24 -0
- package/lib/sketch/input-off.d.ts +16 -0
- package/lib/sketch/input-off.js +38 -0
- package/lib/sketch/input.d.ts +243 -0
- package/lib/sketch/input.js +554 -0
- package/lib/sketch/preset-check.d.ts +42 -0
- package/lib/sketch/preset-check.js +120 -0
- package/lib/sketch/quality.d.ts +392 -0
- package/lib/sketch/quality.js +355 -0
- package/lib/sketch/random.d.ts +13 -0
- package/lib/sketch/random.js +25 -0
- package/lib/sketch/runner.d.ts +574 -0
- package/lib/sketch/runner.js +2159 -0
- package/lib/sketch/ui.d.ts +94 -0
- package/lib/sketch/ui.js +391 -0
- package/lib/stats.d.ts +4 -0
- package/lib/stats.js +8 -0
- package/lib/workers/drawing-host.d.ts +24 -0
- package/lib/workers/drawing-host.js +48 -0
- package/lib/workers/gltf-worker.d.ts +35 -0
- package/lib/workers/gltf-worker.js +210 -0
- package/lib/workers/job-worker.d.ts +1 -0
- package/lib/workers/job-worker.js +102 -0
- package/lib/workers/panorama-worker.d.ts +15 -0
- package/lib/workers/panorama-worker.js +21 -0
- package/lib/workers/probe-worker.d.ts +34 -0
- package/lib/workers/probe-worker.js +58 -0
- package/lib/workers/protocol.d.ts +377 -0
- package/lib/workers/protocol.js +57 -0
- package/lib/workers/render-worker.d.ts +1 -0
- package/lib/workers/render-worker.js +103 -0
- package/lib/workers/sketch-worker.d.ts +1 -0
- package/lib/workers/sketch-worker.js +295 -0
- package/lib/workers/task-worker.d.ts +1 -0
- package/lib/workers/task-worker.js +5 -0
- package/lib/workers/tasks.d.ts +65 -0
- package/lib/workers/tasks.js +85 -0
- package/package.json +106 -5
- package/vendor/basis/LICENSE +201 -0
- package/vendor/basis/LICENSE-zstd +30 -0
- package/vendor/basis/NOTICE +15 -0
- package/vendor/basis/basis_transcoder.d.mts +36 -0
- package/vendor/basis/basis_transcoder.mjs +2 -0
- package/vendor/basis/basis_transcoder.wasm +0 -0
- package/vendor/draco/LICENSE +252 -0
- package/vendor/draco/draco_decoder_gltf.wasm +0 -0
- package/vendor/draco/draco_wasm_wrapper_gltf.d.ts +71 -0
- package/vendor/draco/draco_wasm_wrapper_gltf.js +116 -0
- package/vendor/ltc/LICENSE +31 -0
- package/vendor/ltc/area-light-tables.bin +0 -0
- package/vendor/meshopt/LICENSE.md +21 -0
- package/vendor/meshopt/meshopt_clusterizer.wasm +0 -0
- package/vendor/meshopt/meshopt_decoder.wasm +0 -0
- package/vendor/meshopt/meshopt_encoder.wasm +0 -0
- package/vendor/meshopt/meshopt_simplifier.wasm +0 -0
|
@@ -0,0 +1,4680 @@
|
|
|
1
|
+
// The scene API: objects with transforms, cameras, lights and instance batches. Setters write
|
|
2
|
+
// straight into engine memory. Structural changes (create, destroy, reparent, visibility, layers,
|
|
3
|
+
// flags) go into the command ring as 16-byte records, which the engine applies when the next frame
|
|
4
|
+
// starts.
|
|
5
|
+
import { checkLayers, checkLive, checkNumber, checkVector, DEV, } from '../errors/checks.js';
|
|
6
|
+
import { QUEUED_CHANGE } from '../errors/core-failure.js';
|
|
7
|
+
import { EngineError } from '../errors/engine-error.js';
|
|
8
|
+
import { reasonOf } from '../errors/message.js';
|
|
9
|
+
import * as C from '../generated/core.js';
|
|
10
|
+
import { compose as composeMatrix, copy as copyMatrix, decompose, identity as identityMatrix, multiply as multiplyMatrices, } from '../math/mat4.js';
|
|
11
|
+
import { fromEuler as quaternionFromEuler, rotateX, rotateY, rotateZ, rotationTo, } from '../math/namespaces/quat.js';
|
|
12
|
+
import { transformQuat } from '../math/vec3.js';
|
|
13
|
+
import { rowLimitWarning } from '../page/limits.js';
|
|
14
|
+
import { controlViews, createControlBuffer, nextFrame } from '../shared/control.js';
|
|
15
|
+
import { importOnce } from '../shared/import-once.js';
|
|
16
|
+
import { Cubemap, isAtmosphereBackground, isSkyBackground, SceneBackground, SceneSkyLayer, } from './background.js';
|
|
17
|
+
import { linearColor, writeLinearColor } from './color.js';
|
|
18
|
+
import { Environment, SceneEnvironment } from './environment.js';
|
|
19
|
+
import { setSceneFog } from './fog.js';
|
|
20
|
+
import { FrameCameras, LENS_CENTER_X, LENS_CENTER_Y, LENS_FAR, LENS_FLOATS, LENS_HALF_HEIGHT, LENS_HALF_WIDTH, LENS_NEAR, LENS_ORTHO, } from './frame-cameras.js';
|
|
21
|
+
import { checkFov, checkNearFar, checkOrthographicSize, checkSize, DEFAULT_FAR, DEFAULT_FOV, DEFAULT_NEAR, HALF_SENSOR_MM, newCamera, orthographicView, setViewHeight, } from './lens.js';
|
|
22
|
+
import { SceneLightProbeGrid } from './light-probes.js';
|
|
23
|
+
import { ScenePicks } from './picks.js';
|
|
24
|
+
import { PointerEvents, } from './pointer-events.js';
|
|
25
|
+
import { ReflectionProbes, } from './probes.js';
|
|
26
|
+
import { PROPERTY_CAMERA_FAR, PROPERTY_CAMERA_FOV, PROPERTY_CAMERA_HEIGHT, PROPERTY_CAMERA_NEAR, PROPERTY_LIGHT_ANGLE, PROPERTY_LIGHT_COLOR, PROPERTY_LIGHT_DECAY, PROPERTY_LIGHT_INTENSITY, PROPERTY_LIGHT_PENUMBRA, PROPERTY_LIGHT_RANGE, PROPERTY_MATERIAL, PROPERTY_POSITION, PROPERTY_ROTATION, PROPERTY_SCALE, PROPERTY_VISIBLE, PropertyAnimation, PropertySystem, } from './property-animation.js';
|
|
27
|
+
import { SceneQueries, } from './queries.js';
|
|
28
|
+
import { Material, materialValueComponents, } from './resources.js';
|
|
29
|
+
import { quaternionLookAt } from './rotation.js';
|
|
30
|
+
import { ShaderTemplates } from './shader-templates.js';
|
|
31
|
+
import { Texture } from './textures.js';
|
|
32
|
+
import { UnmarkedRows, UnmarkedWrites } from './unmarked-writes.js';
|
|
33
|
+
import { VertexDraw } from './vertex-draws.js';
|
|
34
|
+
const SLOT_MASK = (1 << C.HANDLE_SLOT_BITS) - 1;
|
|
35
|
+
/** The bit of the ids that custom materials read for the rows of instance batches, above every slot. */
|
|
36
|
+
const BATCH_SHADER_ID = 1 << C.HANDLE_SLOT_BITS;
|
|
37
|
+
/**
|
|
38
|
+
* A view of the scene from its own camera, drawn into a rectangle of the canvas after the
|
|
39
|
+
* camera's view: a split screen or a picture in picture. `scene.createView` makes it.
|
|
40
|
+
* `scene.activeCamera` still draws the whole canvas first, and the view's image covers its
|
|
41
|
+
* rectangle. The engine culls the scene for the view on its own, and draws it once more, at the
|
|
42
|
+
* rectangle's pixels.
|
|
43
|
+
*
|
|
44
|
+
* @category api/cameras
|
|
45
|
+
*/
|
|
46
|
+
export class SceneView {
|
|
47
|
+
scene;
|
|
48
|
+
/** @internal Its place in the engine core's list of views, or 0 once removed. */
|
|
49
|
+
place;
|
|
50
|
+
cameraValue;
|
|
51
|
+
rectValue;
|
|
52
|
+
/** @internal */
|
|
53
|
+
constructor(scene, place, camera, rect) {
|
|
54
|
+
this.scene = scene;
|
|
55
|
+
this.place = place;
|
|
56
|
+
this.cameraValue = camera;
|
|
57
|
+
this.rectValue = [rect[0], rect[1], rect[2], rect[3]];
|
|
58
|
+
}
|
|
59
|
+
/** True until `destroy` removes the view. */
|
|
60
|
+
get live() {
|
|
61
|
+
return this.place > 0;
|
|
62
|
+
}
|
|
63
|
+
/** The camera that the view draws from. */
|
|
64
|
+
get camera() {
|
|
65
|
+
return this.cameraValue;
|
|
66
|
+
}
|
|
67
|
+
/** The rectangle of the canvas that the view draws into. */
|
|
68
|
+
get rect() {
|
|
69
|
+
return this.rectValue;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Draws the view from `camera` from the next frame on. It takes the camera's layers, and
|
|
73
|
+
* follows them when they change.
|
|
74
|
+
*/
|
|
75
|
+
setCamera(camera) {
|
|
76
|
+
const call = 'setCamera';
|
|
77
|
+
if (DEV) {
|
|
78
|
+
checkViewCamera(call, camera);
|
|
79
|
+
checkViewLive(call, this);
|
|
80
|
+
}
|
|
81
|
+
this.cameraValue = camera;
|
|
82
|
+
this.scene.setPassCamera(this.place, camera, undefined);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Draws the view into `rect` from the next frame on. It allocates nothing, so a sketch can
|
|
86
|
+
* change the rectangle in any frame. Development builds throw E1203 for a number that is not
|
|
87
|
+
* finite, and E1213 for a rectangle outside the canvas.
|
|
88
|
+
*/
|
|
89
|
+
setRect(rect) {
|
|
90
|
+
const call = 'setRect';
|
|
91
|
+
if (DEV) {
|
|
92
|
+
checkViewLive(call, this);
|
|
93
|
+
checkViewRect(call, rect);
|
|
94
|
+
}
|
|
95
|
+
const values = this.scene.core.callValues();
|
|
96
|
+
const own = this.rectValue;
|
|
97
|
+
own[0] = values[0] = rect[0];
|
|
98
|
+
own[1] = values[1] = rect[1];
|
|
99
|
+
own[2] = values[2] = rect[2];
|
|
100
|
+
own[3] = values[3] = rect[3];
|
|
101
|
+
this.scene.core.check(this.scene.core.glue.setSceneViewRect(this.place), call, undefined, true);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Writes the ray from the view's camera through a point of the view's image into `out`: `x` and
|
|
105
|
+
* `y` are CSS pixels from the canvas's top-left corner, as `camera.screenToRay` takes them, and
|
|
106
|
+
* as `input.pointer` gives them. The lens takes the shape of the view's rectangle, as the view
|
|
107
|
+
* draws it, so a click on the view's image picks what the view shows. A perspective ray starts
|
|
108
|
+
* at the camera, and an orthographic ray on the near plane. The direction has length 1.
|
|
109
|
+
*
|
|
110
|
+
* It uses the camera of the frame that last ran, with its lens as it is now. A point outside
|
|
111
|
+
* the rectangle gives the ray that the view's lens would give there. `scene.viewAt` finds the
|
|
112
|
+
* view under a point. Development builds throw E1101 for a view that was removed, and E1203 for
|
|
113
|
+
* a number that is not finite.
|
|
114
|
+
*/
|
|
115
|
+
screenToRay(x, y, out) {
|
|
116
|
+
const call = 'screenToRay';
|
|
117
|
+
if (DEV) {
|
|
118
|
+
checkViewLive(call, this);
|
|
119
|
+
checkNumber(call, 'x', x, this.cameraValue);
|
|
120
|
+
checkNumber(call, 'y', y, this.cameraValue);
|
|
121
|
+
}
|
|
122
|
+
this.scene.frameCameras.viewRay(this.cameraValue, this.rectValue, x, y, out, call);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Writes where a point in the world lies in the view's image into `out`: x and y in CSS pixels
|
|
126
|
+
* from the canvas's top-left corner, then the point's depth, its distance in front of the
|
|
127
|
+
* view's camera along the view. A depth below 0 puts the point behind the camera, where x and
|
|
128
|
+
* y have no meaning. The lens takes the shape of the view's rectangle. A point outside the
|
|
129
|
+
* view's sight lands outside the rectangle. Development builds throw E1101 for a view that was
|
|
130
|
+
* removed, and E1203 for a number that is not finite.
|
|
131
|
+
*/
|
|
132
|
+
worldToScreen(point, out) {
|
|
133
|
+
const call = 'worldToScreen';
|
|
134
|
+
if (DEV) {
|
|
135
|
+
checkViewLive(call, this);
|
|
136
|
+
checkVector(call, this.cameraValue, point[0], point[1], point[2]);
|
|
137
|
+
}
|
|
138
|
+
this.scene.frameCameras.viewToScreen(this.cameraValue, this.rectValue, point, out, call);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* True when the point (`x`, `y`) in CSS pixels from the canvas's top-left corner lies in the
|
|
142
|
+
* view's rectangle, its left and top edges included.
|
|
143
|
+
*/
|
|
144
|
+
contains(x, y) {
|
|
145
|
+
return this.scene.viewHolds(this.rectValue, x, y);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Removes the view from the next frame on. The camera's view draws the canvas alone again.
|
|
149
|
+
* Development builds throw E1101 for a view that was removed.
|
|
150
|
+
*/
|
|
151
|
+
destroy() {
|
|
152
|
+
const call = 'destroy';
|
|
153
|
+
if (DEV)
|
|
154
|
+
checkViewLive(call, this);
|
|
155
|
+
this.scene.core.check(this.scene.core.glue.removeSceneView(this.place), call, undefined, true);
|
|
156
|
+
this.scene.setPassCamera(this.place, undefined, undefined);
|
|
157
|
+
this.scene.forgetView(this);
|
|
158
|
+
this.place = 0;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/** Throws E1203 or E1213 for a camera or a rectangle that `scene.createView` does not take. */
|
|
162
|
+
/**
|
|
163
|
+
* The flags of an object's `occluder` option: a blocker on both paths for true, no occluder on
|
|
164
|
+
* WebGPU for false, and none for an option left out, which lets WebGPU choose.
|
|
165
|
+
*/
|
|
166
|
+
function occluderFlags(occluder) {
|
|
167
|
+
if (occluder === undefined)
|
|
168
|
+
return 0;
|
|
169
|
+
return occluder ? C.FLAG_OCCLUDER : C.FLAG_NOT_OCCLUDER;
|
|
170
|
+
}
|
|
171
|
+
function checkViewOptions(options, call) {
|
|
172
|
+
if (typeof options !== 'object' || options === null)
|
|
173
|
+
throw new EngineError('E1213', `${call}() got ${String(options)}, which is not options.`);
|
|
174
|
+
checkViewCamera(call, options.camera);
|
|
175
|
+
if (options.rect === undefined)
|
|
176
|
+
throw new EngineError('E1213', `${call}() got no rect.`);
|
|
177
|
+
checkViewRect(call, options.rect);
|
|
178
|
+
}
|
|
179
|
+
/** Throws E1213 for a value that is not a live camera of the engine. */
|
|
180
|
+
function checkViewCamera(call, camera) {
|
|
181
|
+
if (typeof camera?.sendLens !== 'function')
|
|
182
|
+
throw new EngineError('E1213', `${call}() got no camera. Give the camera that the view draws from.`);
|
|
183
|
+
checkLive(call, camera, true);
|
|
184
|
+
}
|
|
185
|
+
/** Throws E1203 or E1213 for a rectangle that a view does not take. */
|
|
186
|
+
function checkViewRect(call, rect) {
|
|
187
|
+
const outside = (values) => new EngineError('E1213', `${call}() got the rect [${values.join(', ')}]; it takes [x, y, width, height] as fractions of the canvas from 0 to 1, with a width and a height above 0, inside the canvas.`);
|
|
188
|
+
if (!Array.isArray(rect) || rect.length !== 4)
|
|
189
|
+
throw outside(Array.isArray(rect) ? rect : [rect]);
|
|
190
|
+
const [x, y, width, height] = rect;
|
|
191
|
+
for (const value of [x, y, width, height])
|
|
192
|
+
if (!Number.isFinite(value))
|
|
193
|
+
throw new EngineError('E1203', `${call}() got ${String(value)} in the rect. Its numbers must be finite.`);
|
|
194
|
+
if (x < 0 || y < 0)
|
|
195
|
+
throw outside(rect);
|
|
196
|
+
if (!(width > 0) || !(height > 0))
|
|
197
|
+
throw outside(rect);
|
|
198
|
+
if (x + width > 1 || y + height > 1)
|
|
199
|
+
throw outside(rect);
|
|
200
|
+
}
|
|
201
|
+
/** Throws E1101 for a view that `destroy` removed. */
|
|
202
|
+
function checkViewLive(call, view) {
|
|
203
|
+
if (!view.live)
|
|
204
|
+
throw new EngineError('E1101', `${call}() was called on a view that was removed. Make a new view with scene.createView().`);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* The candela of one lumen of a point or spot light, by kind, as three.js's `power` and Filament
|
|
208
|
+
* convert them: a point light spreads its lumens over the whole sphere, 4π steradians, and a spot
|
|
209
|
+
* light over π, whatever its cone, so a narrower cone keeps the light's brightness.
|
|
210
|
+
*/
|
|
211
|
+
const CANDELA_PER_LUMEN = {
|
|
212
|
+
[C.LIGHT_KIND_POINT]: 1 / (4 * Math.PI),
|
|
213
|
+
[C.LIGHT_KIND_SPOT]: 1 / Math.PI,
|
|
214
|
+
};
|
|
215
|
+
/** The unit that each kind of light takes besides three.js's own. */
|
|
216
|
+
const LIGHT_UNITS = {
|
|
217
|
+
[C.LIGHT_KIND_DIRECTIONAL]: 'lux',
|
|
218
|
+
[C.LIGHT_KIND_POINT]: 'lumen',
|
|
219
|
+
[C.LIGHT_KIND_SPOT]: 'lumen',
|
|
220
|
+
[C.LIGHT_KIND_HEMISPHERE]: 'lux',
|
|
221
|
+
[C.LIGHT_KIND_AMBIENT]: 'lux',
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* The factor that turns an intensity in `unit` into three.js's unit for a light of `kind`: candela
|
|
225
|
+
* for point and spot lights, and lux for the others. Without a unit, or in lux, the factor is 1.
|
|
226
|
+
*/
|
|
227
|
+
function intensityScale(kind, unit) {
|
|
228
|
+
return unit === 'lumen' ? (CANDELA_PER_LUMEN[kind] ?? 1) : 1;
|
|
229
|
+
}
|
|
230
|
+
/** The numbers of a light's options, and their codes in the light table. */
|
|
231
|
+
const LIGHT_NUMBERS = [
|
|
232
|
+
['intensity', C.LIGHT_VALUE_INTENSITY],
|
|
233
|
+
['range', C.LIGHT_VALUE_RANGE],
|
|
234
|
+
['decay', C.LIGHT_VALUE_DECAY],
|
|
235
|
+
['angle', C.LIGHT_VALUE_ANGLE],
|
|
236
|
+
['penumbra', C.LIGHT_VALUE_PENUMBRA],
|
|
237
|
+
['width', C.LIGHT_VALUE_WIDTH],
|
|
238
|
+
['height', C.LIGHT_VALUE_HEIGHT],
|
|
239
|
+
['length', C.LIGHT_VALUE_WIDTH],
|
|
240
|
+
['radius', C.LIGHT_VALUE_RADIUS],
|
|
241
|
+
];
|
|
242
|
+
/**
|
|
243
|
+
* Each light number's name, lowest and highest value, and its range in words, by its code, for the
|
|
244
|
+
* development checks.
|
|
245
|
+
*/
|
|
246
|
+
const LIGHT_LIMITS = {
|
|
247
|
+
[C.LIGHT_VALUE_INTENSITY]: ['intensity', -Infinity, Infinity, 'a finite number'],
|
|
248
|
+
[C.LIGHT_VALUE_RANGE]: ['range', Number.MIN_VALUE, Number.MAX_VALUE, 'above 0'],
|
|
249
|
+
[C.LIGHT_VALUE_DECAY]: ['decay', 0, Number.MAX_VALUE, 'at least 0'],
|
|
250
|
+
[C.LIGHT_VALUE_ANGLE]: ['angle', Number.MIN_VALUE, Math.PI / 2, 'above 0 and at most π/2'],
|
|
251
|
+
[C.LIGHT_VALUE_PENUMBRA]: ['penumbra', 0, 1, 'from 0 to 1'],
|
|
252
|
+
[C.LIGHT_VALUE_SHADOW_BIAS]: ['shadow bias', 0, Number.MAX_VALUE, 'at least 0'],
|
|
253
|
+
[C.LIGHT_VALUE_SHADOW_NORMAL_BIAS]: ['shadow normal bias', 0, Number.MAX_VALUE, 'at least 0'],
|
|
254
|
+
[C.LIGHT_VALUE_SHADOW_INTENSITY]: ['shadow intensity', 0, 1, 'from 0 to 1'],
|
|
255
|
+
[C.LIGHT_VALUE_SHADOW_CASCADES]: ['shadow cascades', 1, 4, 'a whole number from 1 to 4'],
|
|
256
|
+
[C.LIGHT_VALUE_SHADOW_MAP_SIZE]: [
|
|
257
|
+
'shadow map size',
|
|
258
|
+
256,
|
|
259
|
+
4096,
|
|
260
|
+
'256, 512, 1,024, 2,048 or 4,096',
|
|
261
|
+
],
|
|
262
|
+
[C.LIGHT_VALUE_SHADOW_DISTANCE]: [
|
|
263
|
+
'shadow distance',
|
|
264
|
+
Number.MIN_VALUE,
|
|
265
|
+
Number.MAX_VALUE,
|
|
266
|
+
'above 0',
|
|
267
|
+
],
|
|
268
|
+
[C.LIGHT_VALUE_SHADOW_CONTACT]: ['contact shadow distance', 0, Number.MAX_VALUE, 'at least 0'],
|
|
269
|
+
[C.LIGHT_VALUE_HERO_SIZE]: ['hero shadow tile size', 1024, 4096, '1,024, 2,048 or 4,096'],
|
|
270
|
+
[C.LIGHT_VALUE_WIDTH]: ['width or length', Number.MIN_VALUE, Number.MAX_VALUE, 'above 0'],
|
|
271
|
+
[C.LIGHT_VALUE_HEIGHT]: ['height', Number.MIN_VALUE, Number.MAX_VALUE, 'above 0'],
|
|
272
|
+
[C.LIGHT_VALUE_RADIUS]: ['radius', Number.MIN_VALUE, Number.MAX_VALUE, 'above 0'],
|
|
273
|
+
};
|
|
274
|
+
/** The options of a directional light's shadows, and their codes in the light table. */
|
|
275
|
+
const SHADOW_NUMBERS = [
|
|
276
|
+
['cascades', C.LIGHT_VALUE_SHADOW_CASCADES],
|
|
277
|
+
['mapSize', C.LIGHT_VALUE_SHADOW_MAP_SIZE],
|
|
278
|
+
['bias', C.LIGHT_VALUE_SHADOW_BIAS],
|
|
279
|
+
['normalBias', C.LIGHT_VALUE_SHADOW_NORMAL_BIAS],
|
|
280
|
+
['distance', C.LIGHT_VALUE_SHADOW_DISTANCE],
|
|
281
|
+
['contactDistance', C.LIGHT_VALUE_SHADOW_CONTACT],
|
|
282
|
+
['heroTileSize', C.LIGHT_VALUE_HERO_SIZE],
|
|
283
|
+
['intensity', C.LIGHT_VALUE_SHADOW_INTENSITY],
|
|
284
|
+
];
|
|
285
|
+
/** The direction a new directional or spot light points: straight down. */
|
|
286
|
+
const DOWN = [0, -1, 0];
|
|
287
|
+
/** The axis that a light's light travels along before the light turns: -Z, as a camera looks. */
|
|
288
|
+
const LIGHT_AXIS = [0, 0, -1];
|
|
289
|
+
/** The point (0, 0, 0), for objects created without a position. */
|
|
290
|
+
const ORIGIN = [0, 0, 0];
|
|
291
|
+
/**
|
|
292
|
+
* Writes `value` at `i` as a whole number of cells in `cells` and the rest in `rest`, as the engine
|
|
293
|
+
* core splits a 64-bit position: the nearest whole number of cells, so the rest is about half a
|
|
294
|
+
* cell long at most, and a 32-bit float holds it to 0.03 mm or better.
|
|
295
|
+
*/
|
|
296
|
+
/**
|
|
297
|
+
* The position that `writePosition` passes on as an array, made once: a caller's numbers go into it,
|
|
298
|
+
* and the write reads them by index.
|
|
299
|
+
*/
|
|
300
|
+
const POSITION = new Float64Array(3);
|
|
301
|
+
function splitPosition(rest, cells, i, value) {
|
|
302
|
+
const cell = Math.floor(value / C.CELL_SIZE + 0.5);
|
|
303
|
+
cells[i] = cell;
|
|
304
|
+
rest[i] = value - cell * C.CELL_SIZE;
|
|
305
|
+
}
|
|
306
|
+
/** The views of the per-slot arrays and the command ring, as the memory is now. */
|
|
307
|
+
function sceneViews(core) {
|
|
308
|
+
const { glue } = core;
|
|
309
|
+
const rows = glue.sceneCapacity() + 1;
|
|
310
|
+
const cells = glue.sceneArrays(C.SCENE_FIELD_POSITION_CELLS);
|
|
311
|
+
const ringCapacity = glue.commandRing(C.RING_FIELD_CAPACITY);
|
|
312
|
+
return {
|
|
313
|
+
positions: core.f32(glue.sceneArrays(C.SCENE_FIELD_POSITIONS), rows * 3),
|
|
314
|
+
positionCells: cells ? core.i32(cells, rows * 3) : undefined,
|
|
315
|
+
rotations: core.f32(glue.sceneArrays(C.SCENE_FIELD_ROTATIONS), rows * 4),
|
|
316
|
+
scales: core.f32(glue.sceneArrays(C.SCENE_FIELD_SCALES), rows * 3),
|
|
317
|
+
radii: core.f32(glue.sceneArrays(C.SCENE_FIELD_LOCAL_RADII), rows),
|
|
318
|
+
centers: core.f32(glue.sceneArrays(C.SCENE_FIELD_LOCAL_CENTERS), rows * 3),
|
|
319
|
+
dirty: core.u32(glue.sceneArrays(C.SCENE_FIELD_DIRTY_WORDS), Math.ceil(rows / 32)),
|
|
320
|
+
ringCapacity,
|
|
321
|
+
records: core.u32(glue.commandRing(C.RING_FIELD_RECORDS), ringCapacity * C.COMMAND_WORDS),
|
|
322
|
+
writeIndex: core.u32(glue.commandRing(C.RING_FIELD_WRITE_INDEX), 1),
|
|
323
|
+
readIndex: core.u32(glue.commandRing(C.RING_FIELD_READ_INDEX), 1),
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* A node in the scene: position, rotation and scale, a parent, visibility.
|
|
328
|
+
*
|
|
329
|
+
* @category api/objects
|
|
330
|
+
*/
|
|
331
|
+
export class Object3D {
|
|
332
|
+
scene;
|
|
333
|
+
handle;
|
|
334
|
+
name;
|
|
335
|
+
/** @internal */
|
|
336
|
+
destroyedFrame = -1;
|
|
337
|
+
/**
|
|
338
|
+
* @internal The row of the scene arrays that the object's calls read and write: its slot, or,
|
|
339
|
+
* once it is destroyed, row 0, which no object has. So a call on a destroyed object never
|
|
340
|
+
* reaches the object that takes its slot, in any build, and costs nothing more.
|
|
341
|
+
*/
|
|
342
|
+
row;
|
|
343
|
+
/**
|
|
344
|
+
* @internal The object's parent, as its create options or its last `setParent` gave it. A
|
|
345
|
+
* destroyed parent leaves the object a root, as in the engine core. `attachTo` sets it.
|
|
346
|
+
*/
|
|
347
|
+
parentObject = null;
|
|
348
|
+
/**
|
|
349
|
+
* @internal The objects whose `parentObject` this object is, from its first child on, so
|
|
350
|
+
* `scene.clone` walks a tree without a pass over the scene. Destroyed children leave it.
|
|
351
|
+
*/
|
|
352
|
+
childObjects;
|
|
353
|
+
/** @internal The object's flags (`FLAG_*`), as its create options and its setters gave them. */
|
|
354
|
+
flags = C.FLAG_VISIBLE;
|
|
355
|
+
/** @internal The object's layer mask, as its create options and `setLayers` gave it. */
|
|
356
|
+
layerMask = C.LAYERS_DEFAULT;
|
|
357
|
+
/** @internal The object's animator, when a model with animations created the object. */
|
|
358
|
+
animation;
|
|
359
|
+
/** @internal The object's pointer event handlers, from its first `on`. */
|
|
360
|
+
pointerListeners = undefined;
|
|
361
|
+
/** @internal */
|
|
362
|
+
constructor(
|
|
363
|
+
/** @internal */ scene,
|
|
364
|
+
/**
|
|
365
|
+
* @internal The object's handle. Once the object is destroyed, it holds a generation that the
|
|
366
|
+
* core never gives a live object, so a later call never reaches another object in its slot.
|
|
367
|
+
*/
|
|
368
|
+
handle,
|
|
369
|
+
/** The name from the create options, or an empty string. */
|
|
370
|
+
name) {
|
|
371
|
+
this.scene = scene;
|
|
372
|
+
this.handle = handle;
|
|
373
|
+
this.name = name;
|
|
374
|
+
this.row = handle & SLOT_MASK;
|
|
375
|
+
}
|
|
376
|
+
/** @internal */
|
|
377
|
+
get slot() {
|
|
378
|
+
return this.handle & SLOT_MASK;
|
|
379
|
+
}
|
|
380
|
+
/** @internal Cameras and lights point their -Z axis where they look; other objects +Z. */
|
|
381
|
+
get looksDownMinusZ() {
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
/** @internal The object's name in quotes, or "an object", as error messages show it. */
|
|
385
|
+
get label() {
|
|
386
|
+
return this.name ? `"${this.name}"` : 'an object';
|
|
387
|
+
}
|
|
388
|
+
/** The object's name and slot, as error messages show them. */
|
|
389
|
+
describe() {
|
|
390
|
+
return `${this.label} (slot ${this.slot})`;
|
|
391
|
+
}
|
|
392
|
+
/** Sets the position relative to the parent. */
|
|
393
|
+
setPosition(x, y, z) {
|
|
394
|
+
if (DEV) {
|
|
395
|
+
checkLive('setPosition', this);
|
|
396
|
+
checkVector('setPosition', this, x, y, z);
|
|
397
|
+
}
|
|
398
|
+
this.scene.writePosition(this.row, x, y, z);
|
|
399
|
+
this.scene.markDirty(this.row);
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Sets the position and, when `rotation` is given, the rotation (a quaternion, x y z w), each
|
|
403
|
+
* from an array of numbers. A caller that keeps a pose in arrays of its own writes it this way:
|
|
404
|
+
* passing an array crosses the call without a number, where a number passed to a setter that
|
|
405
|
+
* the browser does not inline becomes an object of its own. The controls write a camera's pose
|
|
406
|
+
* so in every frame.
|
|
407
|
+
*/
|
|
408
|
+
setPose(position, rotation) {
|
|
409
|
+
if (DEV) {
|
|
410
|
+
checkLive('setPose', this);
|
|
411
|
+
checkVector('setPose', this, position[0], position[1], position[2]);
|
|
412
|
+
if (rotation)
|
|
413
|
+
checkVector('setPose', this, rotation[0], rotation[1], rotation[2], rotation[3]);
|
|
414
|
+
}
|
|
415
|
+
const { scene } = this;
|
|
416
|
+
if (rotation) {
|
|
417
|
+
const r = scene.views.rotations;
|
|
418
|
+
const i = this.row * 4;
|
|
419
|
+
r[i] = rotation[0];
|
|
420
|
+
r[i + 1] = rotation[1];
|
|
421
|
+
r[i + 2] = rotation[2];
|
|
422
|
+
r[i + 3] = rotation[3];
|
|
423
|
+
}
|
|
424
|
+
scene.writePositionFrom(this.row, position);
|
|
425
|
+
scene.markDirty(this.row);
|
|
426
|
+
}
|
|
427
|
+
/** Sets the rotation as a quaternion (x, y, z, w). */
|
|
428
|
+
setRotation(x, y, z, w) {
|
|
429
|
+
if (DEV) {
|
|
430
|
+
checkLive('setRotation', this);
|
|
431
|
+
checkVector('setRotation', this, x, y, z, w);
|
|
432
|
+
}
|
|
433
|
+
const r = this.scene.views.rotations;
|
|
434
|
+
const i = this.row * 4;
|
|
435
|
+
r[i] = x;
|
|
436
|
+
r[i + 1] = y;
|
|
437
|
+
r[i + 2] = z;
|
|
438
|
+
r[i + 3] = w;
|
|
439
|
+
this.scene.markDirty(this.row);
|
|
440
|
+
}
|
|
441
|
+
/** Sets the rotation from Euler angles in radians, turned about the axes in `order`. */
|
|
442
|
+
setRotationEuler(x, y, z, order = 'XYZ') {
|
|
443
|
+
if (DEV) {
|
|
444
|
+
checkLive('setRotationEuler', this);
|
|
445
|
+
checkVector('setRotationEuler', this, x, y, z);
|
|
446
|
+
}
|
|
447
|
+
const r = this.scene.views.rotations;
|
|
448
|
+
const i = this.row * 4;
|
|
449
|
+
quaternionFromEuler(this.scene.scratch, x, y, z, order);
|
|
450
|
+
r.set(this.scene.scratch, i);
|
|
451
|
+
this.scene.markDirty(this.row);
|
|
452
|
+
}
|
|
453
|
+
/** Sets the scale on each axis. */
|
|
454
|
+
setScale(x, y, z) {
|
|
455
|
+
if (DEV) {
|
|
456
|
+
checkLive('setScale', this);
|
|
457
|
+
checkVector('setScale', this, x, y, z);
|
|
458
|
+
}
|
|
459
|
+
const s = this.scene.views.scales;
|
|
460
|
+
const i = this.row * 3;
|
|
461
|
+
s[i] = x;
|
|
462
|
+
s[i + 1] = y;
|
|
463
|
+
s[i + 2] = z;
|
|
464
|
+
this.scene.markDirty(this.row);
|
|
465
|
+
}
|
|
466
|
+
/** Turns the object toward a point. It assumes the object's parents are not rotated. */
|
|
467
|
+
lookAt(x, y, z) {
|
|
468
|
+
if (DEV) {
|
|
469
|
+
checkLive('lookAt', this);
|
|
470
|
+
checkVector('lookAt', this, x, y, z);
|
|
471
|
+
}
|
|
472
|
+
const eye = this.scene.eye;
|
|
473
|
+
this.scene.readPosition(this.row, eye);
|
|
474
|
+
const target = this.scene.target;
|
|
475
|
+
target[0] = x;
|
|
476
|
+
target[1] = y;
|
|
477
|
+
target[2] = z;
|
|
478
|
+
quaternionLookAt(this.scene.scratch, eye, target, this.looksDownMinusZ);
|
|
479
|
+
this.scene.views.rotations.set(this.scene.scratch, this.row * 4);
|
|
480
|
+
this.scene.markDirty(this.row);
|
|
481
|
+
}
|
|
482
|
+
/** Turns the object by `angle` radians about its own X axis. */
|
|
483
|
+
rotateX(angle) {
|
|
484
|
+
this.turn('rotateX', rotateX, angle);
|
|
485
|
+
}
|
|
486
|
+
/** Turns the object by `angle` radians about its own Y axis. */
|
|
487
|
+
rotateY(angle) {
|
|
488
|
+
this.turn('rotateY', rotateY, angle);
|
|
489
|
+
}
|
|
490
|
+
/** Turns the object by `angle` radians about its own Z axis. */
|
|
491
|
+
rotateZ(angle) {
|
|
492
|
+
this.turn('rotateZ', rotateZ, angle);
|
|
493
|
+
}
|
|
494
|
+
/** Turns the object's rotation with one of the quaternion helpers' turns about its own axes. */
|
|
495
|
+
turn(call, by, angle) {
|
|
496
|
+
if (DEV) {
|
|
497
|
+
checkLive(call, this);
|
|
498
|
+
checkNumber(call, 'angle', angle, this);
|
|
499
|
+
}
|
|
500
|
+
const q = this.scene.scratch;
|
|
501
|
+
this.scene.readRotation(this.row, q);
|
|
502
|
+
by(q, q, angle);
|
|
503
|
+
this.scene.views.rotations.set(q, this.row * 4);
|
|
504
|
+
this.scene.markDirty(this.row);
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Moves the object by (x, y, z) along its own axes. The object's rotation turns the vector, and
|
|
508
|
+
* its scale leaves it as it is, so `translate(0, 0, -1)` moves a camera 1 m forward.
|
|
509
|
+
*/
|
|
510
|
+
translate(x, y, z) {
|
|
511
|
+
if (DEV) {
|
|
512
|
+
checkLive('translate', this);
|
|
513
|
+
checkVector('translate', this, x, y, z);
|
|
514
|
+
}
|
|
515
|
+
const { scene } = this;
|
|
516
|
+
const q = scene.scratch;
|
|
517
|
+
scene.readRotation(this.row, q);
|
|
518
|
+
const v = scene.eye;
|
|
519
|
+
v[0] = x;
|
|
520
|
+
v[1] = y;
|
|
521
|
+
v[2] = z;
|
|
522
|
+
transformQuat(v, v, q);
|
|
523
|
+
const p = scene.target;
|
|
524
|
+
scene.readPosition(this.row, p);
|
|
525
|
+
scene.writePosition(this.row, p[0] + v[0], p[1] + v[1], p[2] + v[2]);
|
|
526
|
+
scene.markDirty(this.row);
|
|
527
|
+
}
|
|
528
|
+
/** Copies the position relative to the parent into `out`. */
|
|
529
|
+
getPosition(out) {
|
|
530
|
+
if (DEV)
|
|
531
|
+
checkLive('getPosition', this);
|
|
532
|
+
this.scene.readPosition(this.row, out);
|
|
533
|
+
}
|
|
534
|
+
/** Copies the rotation relative to the parent into `out`, as a quaternion (x, y, z, w). */
|
|
535
|
+
getRotation(out) {
|
|
536
|
+
if (DEV)
|
|
537
|
+
checkLive('getRotation', this);
|
|
538
|
+
this.scene.readRotation(this.row, out);
|
|
539
|
+
}
|
|
540
|
+
/** Copies the world position of the frame that last ran into `out`. */
|
|
541
|
+
getWorldPosition(out) {
|
|
542
|
+
if (DEV)
|
|
543
|
+
checkLive('getWorldPosition', this);
|
|
544
|
+
const m = this.scene.worldMatrix(this, 'getWorldPosition');
|
|
545
|
+
out[0] = m[3];
|
|
546
|
+
out[1] = m[7];
|
|
547
|
+
out[2] = m[11];
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Copies the world rotation of the frame that last ran into `out`, as a quaternion (x, y, z, w).
|
|
551
|
+
* It is the rotation part of the world matrix, which `mat4.decompose` splits off.
|
|
552
|
+
*/
|
|
553
|
+
getWorldQuaternion(out) {
|
|
554
|
+
if (DEV)
|
|
555
|
+
checkLive('getWorldQuaternion', this);
|
|
556
|
+
const { scene } = this;
|
|
557
|
+
const m = scene.worldColumns(this, 'getWorldQuaternion');
|
|
558
|
+
decompose(scene.eye, out, scene.target, m);
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Copies the world matrix of the frame that last ran into `out`: 16 numbers, column by column,
|
|
562
|
+
* as `mat4` holds them. Its translation keeps full precision far from the origin when `out` is
|
|
563
|
+
* a plain array or a `Float64Array`.
|
|
564
|
+
*/
|
|
565
|
+
getWorldMatrix(out) {
|
|
566
|
+
if (DEV)
|
|
567
|
+
checkLive('getWorldMatrix', this);
|
|
568
|
+
copyMatrix(out, this.scene.worldColumns(this, 'getWorldMatrix'));
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Moves the object under another, or to the root with null, from the next frame. By default it
|
|
572
|
+
* keeps its position, rotation and scale relative to the parent, so its place in the world
|
|
573
|
+
* changes with the new parent. With `keepWorld: true` it keeps its place in the world instead.
|
|
574
|
+
*/
|
|
575
|
+
setParent(parent, options) {
|
|
576
|
+
if (DEV) {
|
|
577
|
+
checkLive('setParent', this);
|
|
578
|
+
if (parent) {
|
|
579
|
+
checkLive('setParent', parent, true);
|
|
580
|
+
if (parent.scene !== this.scene)
|
|
581
|
+
throw new EngineError('E1103', `setParent() got ${parent.describe()}, which is not from this engine.`);
|
|
582
|
+
if (parent === this)
|
|
583
|
+
throw new EngineError('E1104', `setParent() would put ${this.describe()} under itself.`);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
const keep = options?.keepWorld ? C.COMMAND_KEEP_WORLD : 0;
|
|
587
|
+
this.scene.command(C.COMMAND_SET_PARENT, this.handle, parent?.handle ?? 0, keep, 'setParent');
|
|
588
|
+
this.attachTo(parent);
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* The object's parent, or null for a root object. A destroyed parent leaves the object a
|
|
592
|
+
* root object.
|
|
593
|
+
*/
|
|
594
|
+
getParent() {
|
|
595
|
+
if (DEV)
|
|
596
|
+
checkLive('getParent', this);
|
|
597
|
+
return this.liveParent;
|
|
598
|
+
}
|
|
599
|
+
/** @internal Records `parent` as the object's parent, in both objects. */
|
|
600
|
+
attachTo(parent) {
|
|
601
|
+
this.parentObject?.childObjects?.delete(this);
|
|
602
|
+
this.parentObject = parent;
|
|
603
|
+
if (parent) {
|
|
604
|
+
parent.childObjects ??= new Set();
|
|
605
|
+
parent.childObjects.add(this);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
/** @internal The live parent, or null for a root. */
|
|
609
|
+
get liveParent() {
|
|
610
|
+
const parent = this.parentObject;
|
|
611
|
+
return parent && parent.destroyedFrame === -1 ? parent : null;
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* @internal A new wrapper of the same kind for the object with `handle`, with the settings that
|
|
615
|
+
* live on the wrapper, for `scene.clone`.
|
|
616
|
+
*/
|
|
617
|
+
twin(handle) {
|
|
618
|
+
const kind = this.constructor;
|
|
619
|
+
return new kind(this.scene, handle, this.name);
|
|
620
|
+
}
|
|
621
|
+
/** @internal Sets or clears flags on the wrapper's copy of the object's flags. */
|
|
622
|
+
keepFlag(flag, on) {
|
|
623
|
+
this.flags = on ? this.flags | flag : this.flags & ~flag;
|
|
624
|
+
}
|
|
625
|
+
/** Hides or shows the object and everything under it. */
|
|
626
|
+
setVisible(visible) {
|
|
627
|
+
if (DEV)
|
|
628
|
+
checkLive('setVisible', this);
|
|
629
|
+
this.scene.command(C.COMMAND_SET_VISIBLE, this.handle, visible ? 1 : 0, 0, 'setVisible');
|
|
630
|
+
this.keepFlag(C.FLAG_VISIBLE, visible);
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Puts the object on the layers of a 32-bit mask: bit n puts it on layer n, so `1 << 2` is
|
|
634
|
+
* layer 2 and `0b101` is layers 0 and 2. A camera draws the object only when their masks share
|
|
635
|
+
* a layer. The object's children keep their own layers. A new mask needs no rebuild.
|
|
636
|
+
*/
|
|
637
|
+
setLayers(mask) {
|
|
638
|
+
if (DEV) {
|
|
639
|
+
checkLive('setLayers', this);
|
|
640
|
+
checkLayers('setLayers', mask, this);
|
|
641
|
+
}
|
|
642
|
+
this.scene.command(C.COMMAND_SET_LAYERS, this.handle, mask >>> 0, 0, 'setLayers');
|
|
643
|
+
this.layerMask = mask >>> 0;
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* The object's layer mask, as `setLayers` or its create options set it: bit n puts it on layer
|
|
647
|
+
* n.
|
|
648
|
+
*/
|
|
649
|
+
getLayers() {
|
|
650
|
+
if (DEV)
|
|
651
|
+
checkLive('getLayers', this);
|
|
652
|
+
return this.layerMask;
|
|
653
|
+
}
|
|
654
|
+
/** Makes the object dynamic or static from the next frame. See `NodeOptions.dynamic`. */
|
|
655
|
+
setDynamic(dynamic) {
|
|
656
|
+
if (DEV) {
|
|
657
|
+
checkLive('setDynamic', this);
|
|
658
|
+
this.scene.unmarkedWrites?.watch(this, !dynamic);
|
|
659
|
+
}
|
|
660
|
+
this.scene.command(C.COMMAND_SET_DYNAMIC, this.handle, dynamic ? 1 : 0, 0, 'setDynamic');
|
|
661
|
+
this.keepFlag(C.FLAG_DYNAMIC, dynamic);
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* The object's animator, which plays the clips of the model that created the object. An object
|
|
665
|
+
* without animation clips has none, and the call throws.
|
|
666
|
+
*/
|
|
667
|
+
animator() {
|
|
668
|
+
if (DEV)
|
|
669
|
+
checkLive('animator', this);
|
|
670
|
+
if (this.animation === undefined)
|
|
671
|
+
throw new EngineError('E1218', `animator() was called on ${this.describe()}, which has no animation clips.`);
|
|
672
|
+
return this.animation;
|
|
673
|
+
}
|
|
674
|
+
/** Removes the object at the next frame. Its children become roots. */
|
|
675
|
+
destroy() {
|
|
676
|
+
if (DEV) {
|
|
677
|
+
checkLive('destroy', this);
|
|
678
|
+
this.scene.unmarkedWrites?.watch(this, false);
|
|
679
|
+
}
|
|
680
|
+
this.animation?.release();
|
|
681
|
+
this.scene.forgetListeners(this);
|
|
682
|
+
// The core checks the handle's generation, so a second destroy frees no other object, even
|
|
683
|
+
// once the slot's generations have come round.
|
|
684
|
+
this.scene.command(C.COMMAND_DESTROY, this.handle, 0, 0, 'destroy');
|
|
685
|
+
this.destroyedFrame = this.scene.frame;
|
|
686
|
+
this.row = 0;
|
|
687
|
+
this.parentObject?.childObjects?.delete(this);
|
|
688
|
+
this.scene.forget(this);
|
|
689
|
+
this.handle |= C.HANDLE_DEAD_GENERATION << C.HANDLE_SLOT_BITS;
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* Calls `handler` for each pointer event of `type` on the object: 'click', 'pointerdown',
|
|
693
|
+
* 'pointerup', 'pointermove', 'pointerenter' or 'pointerleave'. An event on a child goes on to
|
|
694
|
+
* its parents, so a handler on a model's group hears clicks on all its parts. The engine casts
|
|
695
|
+
* a ray from the frame that was on screen at each event, against objects where they are now.
|
|
696
|
+
* Handlers run on the sketch's thread at the start of the next frame, before `onUpdate`.
|
|
697
|
+
*/
|
|
698
|
+
on(type, handler) {
|
|
699
|
+
if (DEV)
|
|
700
|
+
checkLive('on', this);
|
|
701
|
+
this.scene.pointerEvents.add(this, type, handler);
|
|
702
|
+
}
|
|
703
|
+
/** Removes a handler that `on` added for events of `type`. */
|
|
704
|
+
off(type, handler) {
|
|
705
|
+
this.scene.pointerEvents.remove(this, type, handler);
|
|
706
|
+
}
|
|
707
|
+
/** @internal The parent that the object's pointer events go on to. */
|
|
708
|
+
pointerParent() {
|
|
709
|
+
return this.liveParent;
|
|
710
|
+
}
|
|
711
|
+
/** @internal Sets or clears one of the object's flags from the next frame. */
|
|
712
|
+
setFlag(call, flag, on) {
|
|
713
|
+
if (DEV)
|
|
714
|
+
checkLive(call, this);
|
|
715
|
+
this.scene.command(C.COMMAND_SET_FLAGS, this.handle, flag, on ? flag : 0, call);
|
|
716
|
+
this.keepFlag(flag, on);
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* Replaces the object's bounding sphere, which culling and the light's hero shadow test, with a
|
|
720
|
+
* sphere of your own: `center` relative to the object's origin, and `radius`, both before the
|
|
721
|
+
* object's scale. Use it when a shader moves vertices outside a mesh's sphere. A mesh takes its
|
|
722
|
+
* mesh's sphere at first, and `setMesh` gives that back; a group has none, so it needs a sphere
|
|
723
|
+
* of its own wherever one is read, as the hero shadow that names it reads it.
|
|
724
|
+
*/
|
|
725
|
+
setBounds(center, radius) {
|
|
726
|
+
const x = center[0];
|
|
727
|
+
const y = center[1];
|
|
728
|
+
const z = center[2];
|
|
729
|
+
if (DEV) {
|
|
730
|
+
checkLive('setBounds', this);
|
|
731
|
+
checkVector('setBounds', this, x, y, z);
|
|
732
|
+
checkNumber('setBounds', 'radius', radius, this);
|
|
733
|
+
if (radius < 0)
|
|
734
|
+
throw new EngineError('E1108', `setBounds() got the radius ${radius} on ${this.describe()}, below 0.`);
|
|
735
|
+
}
|
|
736
|
+
this.scene.writeBounds(this.row, x, y, z, radius);
|
|
737
|
+
if (DEV)
|
|
738
|
+
this.scene.unmarkedWrites?.boundsWritten(this);
|
|
739
|
+
this.setFlag('setBounds', C.FLAG_CUSTOM_BOUNDS, true);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* An empty node, for hierarchy.
|
|
744
|
+
*
|
|
745
|
+
* @category api/objects
|
|
746
|
+
*/
|
|
747
|
+
export class Group extends Object3D {
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* The group that holds a copy of a model, which `scene.instantiate` returns. Its children are the
|
|
751
|
+
* copies of the file's root nodes.
|
|
752
|
+
*
|
|
753
|
+
* @category api/scene
|
|
754
|
+
*/
|
|
755
|
+
export class PrefabInstance extends Group {
|
|
756
|
+
/** @internal The copy's objects: this group, then one for each node, in the file's order. */
|
|
757
|
+
objects = [];
|
|
758
|
+
/**
|
|
759
|
+
* The instance batches of the nodes with instancing of their own, as the file gives them. Their
|
|
760
|
+
* rows are placed in the world when the copy is created, and they do not move with the group.
|
|
761
|
+
*/
|
|
762
|
+
batches = [];
|
|
763
|
+
/**
|
|
764
|
+
* The copy's first object with `name`, in the file's order, which is not destroyed, or
|
|
765
|
+
* undefined. It searches the copy's objects, so call it at setup.
|
|
766
|
+
*/
|
|
767
|
+
find(name) {
|
|
768
|
+
for (const object of this.objects)
|
|
769
|
+
if (object !== this && object.name === name && object.destroyedFrame === -1)
|
|
770
|
+
return object;
|
|
771
|
+
return undefined;
|
|
772
|
+
}
|
|
773
|
+
/**
|
|
774
|
+
* Removes the whole copy at the next frame: this group, every object that the copy created and
|
|
775
|
+
* that is not destroyed yet, and its instance batches. Objects that the sketch put under the
|
|
776
|
+
* copy later become roots, as children of any destroyed object do.
|
|
777
|
+
*/
|
|
778
|
+
destroy() {
|
|
779
|
+
super.destroy();
|
|
780
|
+
for (const object of this.objects)
|
|
781
|
+
if (object !== this && object.destroyedFrame < 0)
|
|
782
|
+
object.destroy();
|
|
783
|
+
for (const batch of this.batches)
|
|
784
|
+
if (batch.destroyedFrame < 0)
|
|
785
|
+
batch.destroy();
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Outlines every mesh of the copy, or stops, as `Mesh.setOutlined` does for one mesh: the
|
|
789
|
+
* whole model takes one outline. The copy's instance batches take none.
|
|
790
|
+
*/
|
|
791
|
+
setOutlined(outlined) {
|
|
792
|
+
for (const object of this.objects)
|
|
793
|
+
if (object instanceof Mesh && object.destroyedFrame < 0)
|
|
794
|
+
object.setOutlined(outlined);
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* A drawn object: a mesh and a material.
|
|
799
|
+
*
|
|
800
|
+
* @category api/objects
|
|
801
|
+
*/
|
|
802
|
+
export class Mesh extends Object3D {
|
|
803
|
+
/** @internal The shape, as the create options or `setMesh` gave it. */
|
|
804
|
+
mesh;
|
|
805
|
+
/** @internal The material, as the create options or `setMaterial` gave it. */
|
|
806
|
+
material;
|
|
807
|
+
/** @internal The render order, as `setRenderOrder` gave it. */
|
|
808
|
+
renderOrder = 0;
|
|
809
|
+
/** @internal The bias of the threshold that picks the levels, as `setLevelBias` gave it. */
|
|
810
|
+
levelBias = 1;
|
|
811
|
+
/** @internal The distances between which the mesh draws, as `setDrawRange` gave them. */
|
|
812
|
+
drawRange = [0, Number.POSITIVE_INFINITY];
|
|
813
|
+
/** @internal The mesh's block of morph weights in the engine core, plus one, or 0 for none. */
|
|
814
|
+
morphBlock = 0;
|
|
815
|
+
/** @internal The place of the block's first weight in the core's table of morph weights. */
|
|
816
|
+
morphFirst = 0;
|
|
817
|
+
/** @internal The weights that the block holds: the mesh's morph targets, or 0. */
|
|
818
|
+
morphCount = 0;
|
|
819
|
+
/**
|
|
820
|
+
* @internal The first joint of the model's skeleton that animates the weights, or -1 when no
|
|
821
|
+
* clip of the model animates them.
|
|
822
|
+
*/
|
|
823
|
+
morphJoint = -1;
|
|
824
|
+
/**
|
|
825
|
+
* The number that a custom material's WGSL reads as `object.id` for this mesh. No other live
|
|
826
|
+
* mesh or batch has it. Pass it to a uniform to pick out this mesh in a shader. It is 0 once the
|
|
827
|
+
* mesh is destroyed.
|
|
828
|
+
*/
|
|
829
|
+
get shaderId() {
|
|
830
|
+
return this.row;
|
|
831
|
+
}
|
|
832
|
+
/** @internal */
|
|
833
|
+
twin(handle) {
|
|
834
|
+
const twin = super.twin(handle);
|
|
835
|
+
twin.mesh = this.mesh;
|
|
836
|
+
twin.material = this.material;
|
|
837
|
+
twin.renderOrder = this.renderOrder;
|
|
838
|
+
twin.levelBias = this.levelBias;
|
|
839
|
+
twin.drawRange = this.drawRange;
|
|
840
|
+
twin.morphJoint = this.morphJoint;
|
|
841
|
+
return twin;
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Sets how far the mesh moves toward one of its morph targets, from the next frame: 0 keeps
|
|
845
|
+
* the target's shape out, 1 adds all of it, and other numbers scale it. `target` is the target's
|
|
846
|
+
* number, from 0, or its name. A clip that animates the weight blends its own value with this
|
|
847
|
+
* one while it plays, and this one holds when no clip moves it. A WebGL2 device draws a
|
|
848
|
+
* preset's count of each mesh's largest weights (the `morphTargets` quality setting). Throws
|
|
849
|
+
* E1218 for a target that the mesh does not have, and E1203 for a weight that is not a finite
|
|
850
|
+
* number.
|
|
851
|
+
*/
|
|
852
|
+
setMorphWeight(target, weight) {
|
|
853
|
+
const k = this.morphIndex('setMorphWeight', target);
|
|
854
|
+
if (DEV)
|
|
855
|
+
checkNumber('setMorphWeight', 'weight', weight, this);
|
|
856
|
+
this.scene.morphWeights()[this.morphFirst + k] = weight;
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* The weight of one of the mesh's morph targets, as `setMorphWeight` or the model's file set
|
|
860
|
+
* it, without what a playing clip adds. Throws E1218 for a target that the mesh does not have.
|
|
861
|
+
*/
|
|
862
|
+
getMorphWeight(target) {
|
|
863
|
+
return this.scene.morphWeights()[this.morphFirst + this.morphIndex('getMorphWeight', target)];
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* The number of the morph target that `target` names. A whole number below the target count
|
|
867
|
+
* takes the short path, which the browser can inline into a sketch's frame code.
|
|
868
|
+
*/
|
|
869
|
+
morphIndex(call, target) {
|
|
870
|
+
return typeof target === 'number' && target >>> 0 === target && target < this.morphCount
|
|
871
|
+
? target
|
|
872
|
+
: this.morphTarget(call, target);
|
|
873
|
+
}
|
|
874
|
+
/** The number of a morph target that `target` names, or E1218 when the mesh lacks it. */
|
|
875
|
+
morphTarget(call, target) {
|
|
876
|
+
if (DEV)
|
|
877
|
+
checkLive(call, this);
|
|
878
|
+
const names = this.mesh?.morphTargetNames ?? [];
|
|
879
|
+
const k = typeof target === 'string' ? names.indexOf(target) : target;
|
|
880
|
+
if (Number.isInteger(k) && k >= 0 && k < this.morphCount)
|
|
881
|
+
return k;
|
|
882
|
+
const has = this.morphCount === 0
|
|
883
|
+
? 'which has no morph targets'
|
|
884
|
+
: `which has ${this.morphCount} morph targets${names.length > 0 ? `: ${names.join(', ')}` : ''}`;
|
|
885
|
+
throw new EngineError('E1218', `${call}() got ${typeof target === 'string' ? `"${target}"` : target}, which names no morph target of ${this.describe()}, ${has}.`);
|
|
886
|
+
}
|
|
887
|
+
/** Removes the object at the next frame, and frees its morph weights. Its children become roots. */
|
|
888
|
+
destroy() {
|
|
889
|
+
super.destroy();
|
|
890
|
+
this.scene.releaseMorph(this);
|
|
891
|
+
}
|
|
892
|
+
/** Changes the material from the next frame. */
|
|
893
|
+
setMaterial(material) {
|
|
894
|
+
if (DEV) {
|
|
895
|
+
checkLive('setMaterial', this);
|
|
896
|
+
checkSameEngine('setMaterial', 'material', material.core, this.scene);
|
|
897
|
+
}
|
|
898
|
+
// A displaced material moves vertices past the mesh's sphere, so the bounds grow to hold them.
|
|
899
|
+
const margin = material.boundsMargin;
|
|
900
|
+
const { mesh } = this;
|
|
901
|
+
const own = this.flags & C.FLAG_CUSTOM_BOUNDS;
|
|
902
|
+
if (mesh && !own && margin !== (this.material?.boundsMargin ?? 0)) {
|
|
903
|
+
const [x, y, z] = mesh.center;
|
|
904
|
+
this.scene.writeBounds(this.row, x, y, z, mesh.radius + margin);
|
|
905
|
+
if (DEV)
|
|
906
|
+
this.scene.unmarkedWrites?.boundsWritten(this);
|
|
907
|
+
}
|
|
908
|
+
this.scene.command(C.COMMAND_SET_MATERIAL, this.handle, material.id, 0, 'setMaterial');
|
|
909
|
+
// A copy that drew with a material that draws the base level alone was not counted.
|
|
910
|
+
const counted = this.material !== undefined && !this.material.wholeOnly;
|
|
911
|
+
this.material = material;
|
|
912
|
+
mesh?.drawnWith(material, counted ? 0 : 1, 'setMaterial');
|
|
913
|
+
}
|
|
914
|
+
/**
|
|
915
|
+
* Changes the shape from the next frame. The mesh's bounds replace the object's, so call
|
|
916
|
+
* `setBounds` again after this when the object needs bounds of its own.
|
|
917
|
+
*/
|
|
918
|
+
setMesh(mesh) {
|
|
919
|
+
if (DEV) {
|
|
920
|
+
checkLive('setMesh', this);
|
|
921
|
+
checkSameEngine('setMesh', 'mesh', mesh.core, this.scene);
|
|
922
|
+
}
|
|
923
|
+
const [x, y, z] = mesh.center;
|
|
924
|
+
this.scene.writeBounds(this.row, x, y, z, mesh.radius + (this.material?.boundsMargin ?? 0));
|
|
925
|
+
if (DEV)
|
|
926
|
+
this.scene.unmarkedWrites?.boundsWritten(this);
|
|
927
|
+
this.scene.command(C.COMMAND_SET_MESH, this.handle, mesh.id, 0, 'setMesh');
|
|
928
|
+
this.mesh = mesh;
|
|
929
|
+
if (this.material)
|
|
930
|
+
mesh.drawnWith(this.material, 1, 'setMesh');
|
|
931
|
+
this.keepFlag(C.FLAG_CUSTOM_BOUNDS, false);
|
|
932
|
+
// A mesh of as many morph targets keeps its weights; another gets weights of its own.
|
|
933
|
+
if (mesh.morphTargets !== this.morphCount) {
|
|
934
|
+
this.scene.releaseMorph(this);
|
|
935
|
+
const block = this.scene.makeMorph(this, mesh, undefined, 'setMesh');
|
|
936
|
+
if (block !== 0)
|
|
937
|
+
this.scene.command(C.COMMAND_SET_MORPH, this.handle, block, 0, 'setMesh');
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* Makes the mesh cast the shadows of the lights that cast them, or stop. The default is false.
|
|
942
|
+
* A change rebuilds the engine's tables of what it draws, as a new material does.
|
|
943
|
+
*/
|
|
944
|
+
setCastShadows(cast) {
|
|
945
|
+
this.setFlag('setCastShadows', C.FLAG_CAST_SHADOWS, cast);
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* Makes shadows fall on the mesh, or stop. The default is false. Unlit materials show no
|
|
949
|
+
* shadows. A change rebuilds the engine's tables of what it draws, as a new material does.
|
|
950
|
+
*/
|
|
951
|
+
setReceiveShadows(receive) {
|
|
952
|
+
this.setFlag('setReceiveShadows', C.FLAG_RECEIVE_SHADOWS, receive);
|
|
953
|
+
}
|
|
954
|
+
/**
|
|
955
|
+
* Draws an outline around the mesh, or stops. The outline shows while `post.set({ outline })`
|
|
956
|
+
* turns outlines on, and every outlined mesh takes its settings. The default is false. A change
|
|
957
|
+
* rebuilds the engine's tables of what it draws, as a new material does.
|
|
958
|
+
*/
|
|
959
|
+
setOutlined(outlined) {
|
|
960
|
+
this.setFlag('setOutlined', C.FLAG_OUTLINED, outlined);
|
|
961
|
+
}
|
|
962
|
+
/**
|
|
963
|
+
* Makes the mesh block the view, or keeps it from blocking. On WebGL2, while the
|
|
964
|
+
* `softwareOcclusion` quality setting is on, the job workers draw each blocker into a small
|
|
965
|
+
* depth buffer every frame, and the engine skips every object that lies wholly behind the
|
|
966
|
+
* blockers. Only meshes marked true block there, and the meshes of a model file that the asset
|
|
967
|
+
* tool gave blockers. Mark large, solid meshes that hide much of the scene, such as buildings
|
|
968
|
+
* and walls, whose mesh has at most 4,096 triangles. A mesh that the asset tool gave a blocker
|
|
969
|
+
* draws that blocker instead, a few boxes inside the mesh, whatever the mesh's own size. A
|
|
970
|
+
* blocker's mesh must lie inside what the object draws, as the object's own mesh does. On WebGPU,
|
|
971
|
+
* while the `gpuOcclusion` setting is on, every opaque mesh may block without a mark: the GPU
|
|
972
|
+
* draws the depth of those that showed in the last frame and look large on the screen, and
|
|
973
|
+
* skips every object wholly behind them. False keeps the mesh from blocking there too. Objects
|
|
974
|
+
* that blend, cut holes with an alpha mask or use a custom material never block, whatever this
|
|
975
|
+
* says, nor do skinned ones on WebGL2. A change needs no rebuild of the engine's tables.
|
|
976
|
+
*/
|
|
977
|
+
setOccluder(occluder) {
|
|
978
|
+
const call = 'setOccluder';
|
|
979
|
+
if (DEV)
|
|
980
|
+
checkLive(call, this);
|
|
981
|
+
const mask = C.FLAG_OCCLUDER | C.FLAG_NOT_OCCLUDER;
|
|
982
|
+
const value = occluder ? C.FLAG_OCCLUDER : C.FLAG_NOT_OCCLUDER;
|
|
983
|
+
this.scene.command(C.COMMAND_SET_FLAGS, this.handle, mask, value, call);
|
|
984
|
+
this.keepFlag(C.FLAG_OCCLUDER, occluder);
|
|
985
|
+
this.keepFlag(C.FLAG_NOT_OCCLUDER, !occluder);
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* Sets the order in which the mesh draws among blended objects, lower first. Objects of one
|
|
989
|
+
* order draw farthest first. The default is 0. The engine orders opaque and masked objects
|
|
990
|
+
* itself.
|
|
991
|
+
*/
|
|
992
|
+
setRenderOrder(order) {
|
|
993
|
+
if (DEV) {
|
|
994
|
+
checkLive('setRenderOrder', this);
|
|
995
|
+
checkNumber('setRenderOrder', 'order', order, this);
|
|
996
|
+
}
|
|
997
|
+
const bits = this.scene.floatBits(order);
|
|
998
|
+
this.scene.command(C.COMMAND_SET_RENDER_ORDER, this.handle, bits, 0, 'setRenderOrder');
|
|
999
|
+
this.renderOrder = order;
|
|
1000
|
+
}
|
|
1001
|
+
/**
|
|
1002
|
+
* Raises or lowers the threshold that picks this mesh's levels of detail, as Godot's
|
|
1003
|
+
* `lod_bias` does. A bias above 1 makes every switch happen nearer, so the object draws
|
|
1004
|
+
* coarser levels. A bias below 1 keeps its detail, which a hero object wants. The bias
|
|
1005
|
+
* multiplies the threshold of the level switches and of the distance at which the object
|
|
1006
|
+
* hides, so both move by the same factor. The default is 1. The object's mesh needs levels
|
|
1007
|
+
* (`setLevels`). A change rebuilds the engine's tables of what it draws, as a new material
|
|
1008
|
+
* does. Throws E1108 for a bias that is not a number above 0.
|
|
1009
|
+
*/
|
|
1010
|
+
setLevelBias(bias) {
|
|
1011
|
+
if (DEV) {
|
|
1012
|
+
checkLive('setLevelBias', this);
|
|
1013
|
+
checkNumber('setLevelBias', 'bias', bias, this);
|
|
1014
|
+
if (bias <= 0)
|
|
1015
|
+
throw new EngineError('E1108', `setLevelBias() got ${bias} on ${this.describe()}, not a number above 0.`);
|
|
1016
|
+
}
|
|
1017
|
+
const bits = this.scene.floatBits(bias);
|
|
1018
|
+
this.scene.command(C.COMMAND_SET_LEVEL_BIAS, this.handle, bits, 0, 'setLevelBias');
|
|
1019
|
+
this.levelBias = bias;
|
|
1020
|
+
}
|
|
1021
|
+
/**
|
|
1022
|
+
* Sets the distances between which the mesh draws, as Godot's visibility range and Bevy's
|
|
1023
|
+
* `VisibilityRange` do: nothing nearer than `start`, which is 0 for none, and nothing past
|
|
1024
|
+
* `end`, which is `Infinity` for none. Each edge fades over a short band, so a mesh that fades
|
|
1025
|
+
* in or out does not pop. A mesh whose bounds leave the range costs no draw at all. The
|
|
1026
|
+
* default draws at every distance. The `lodFade` quality setting turns the bands off on Low.
|
|
1027
|
+
* Throws E1108 for a range that is not two numbers with 0 <= start < end.
|
|
1028
|
+
*/
|
|
1029
|
+
setDrawRange(start, end) {
|
|
1030
|
+
if (DEV) {
|
|
1031
|
+
checkLive('setDrawRange', this);
|
|
1032
|
+
checkNumber('setDrawRange', 'start', start, this);
|
|
1033
|
+
checkNumber('setDrawRange', 'end', end, this);
|
|
1034
|
+
if (!(start >= 0 && start < end))
|
|
1035
|
+
throw new EngineError('E1108', `setDrawRange() got ${start} and ${end} on ${this.describe()}, not a start at or above 0 and below the end.`);
|
|
1036
|
+
}
|
|
1037
|
+
this.scene.command(C.COMMAND_SET_DRAW_RANGE, this.handle, this.scene.floatBits(start), this.scene.floatBits(end), 'setDrawRange');
|
|
1038
|
+
this.drawRange = [start, end];
|
|
1039
|
+
}
|
|
1040
|
+
/**
|
|
1041
|
+
* With false, the engine draws the mesh even where its bounds are out of view. The default is
|
|
1042
|
+
* true. For vertices that a shader moves, larger bounds from `setBounds` cost less.
|
|
1043
|
+
*/
|
|
1044
|
+
setFrustumCulled(culled) {
|
|
1045
|
+
this.setFlag('setFrustumCulled', C.FLAG_UNCULLED, !culled);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
/** Throws E1103 when a mesh or a material comes from another engine. Call it inside `if (DEV)`. */
|
|
1049
|
+
function checkSameEngine(call, kind, core, scene) {
|
|
1050
|
+
if (core !== scene.core)
|
|
1051
|
+
throw new EngineError('E1103', `${call}() got a ${kind} that is not from this engine.`);
|
|
1052
|
+
}
|
|
1053
|
+
/** What a material's shading draws besides a mesh, or undefined for a material that draws meshes. */
|
|
1054
|
+
function batchOnlyShading(shading) {
|
|
1055
|
+
if (shading === C.SHADING_SPRITE)
|
|
1056
|
+
return 'sprite';
|
|
1057
|
+
if (shading === C.SHADING_LINE || shading === C.SHADING_LINE_LIT)
|
|
1058
|
+
return 'line';
|
|
1059
|
+
if (shading === C.SHADING_PARTICLE)
|
|
1060
|
+
return 'particle';
|
|
1061
|
+
return undefined;
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
* An object that the scene can be drawn from. `scene.setActiveCamera` picks the camera that the
|
|
1065
|
+
* canvas shows. A camera is a `PerspectiveCamera` or an `OrthographicCamera`, and
|
|
1066
|
+
* `isOrthographic` tells them apart.
|
|
1067
|
+
*
|
|
1068
|
+
* @category api/cameras
|
|
1069
|
+
*/
|
|
1070
|
+
export class Camera extends Object3D {
|
|
1071
|
+
nearPlane;
|
|
1072
|
+
farPlane;
|
|
1073
|
+
/** @internal The layers of the objects the camera draws. */
|
|
1074
|
+
layers = C.LAYERS_DEFAULT;
|
|
1075
|
+
/** @internal The lens as the frame cameras keep it, which `updateLens` writes. */
|
|
1076
|
+
lens = new Float64Array(LENS_FLOATS);
|
|
1077
|
+
/** @internal */
|
|
1078
|
+
constructor(scene, handle, name, nearPlane, farPlane) {
|
|
1079
|
+
super(scene, handle, name);
|
|
1080
|
+
this.nearPlane = nearPlane;
|
|
1081
|
+
this.farPlane = farPlane;
|
|
1082
|
+
}
|
|
1083
|
+
get looksDownMinusZ() {
|
|
1084
|
+
return true;
|
|
1085
|
+
}
|
|
1086
|
+
/** The distance to the near clipping plane. */
|
|
1087
|
+
get near() {
|
|
1088
|
+
return this.nearPlane;
|
|
1089
|
+
}
|
|
1090
|
+
/** The distance to the far clipping plane. */
|
|
1091
|
+
get far() {
|
|
1092
|
+
return this.farPlane;
|
|
1093
|
+
}
|
|
1094
|
+
/**
|
|
1095
|
+
* Sets the layers the camera draws, as a 32-bit mask: it draws the objects whose masks share a
|
|
1096
|
+
* layer with it. The default, 1, draws layer 0, where every object starts.
|
|
1097
|
+
*/
|
|
1098
|
+
setLayers(mask) {
|
|
1099
|
+
super.setLayers(mask);
|
|
1100
|
+
this.layers = mask >>> 0;
|
|
1101
|
+
this.scene.lensChanged(this);
|
|
1102
|
+
}
|
|
1103
|
+
/** Sets the distances to the near and far clipping planes. */
|
|
1104
|
+
setNearFar(near, far) {
|
|
1105
|
+
if (DEV) {
|
|
1106
|
+
checkLive('setNearFar', this);
|
|
1107
|
+
checkNearFar('setNearFar', near, far, !this.isOrthographic, this);
|
|
1108
|
+
}
|
|
1109
|
+
this.nearPlane = near;
|
|
1110
|
+
this.farPlane = far;
|
|
1111
|
+
this.scene.lensChanged(this);
|
|
1112
|
+
}
|
|
1113
|
+
/**
|
|
1114
|
+
* Writes the ray from the camera through a point on the canvas into `out`: `x` and `y` are CSS
|
|
1115
|
+
* pixels from the canvas's top-left corner, as `input.pointer` gives them. A perspective ray
|
|
1116
|
+
* starts at the camera, and an orthographic ray on the near plane. The direction has length 1.
|
|
1117
|
+
*
|
|
1118
|
+
* When the point is the position of the pointer or a finger from `input`, the ray uses the
|
|
1119
|
+
* camera of the frame that was on screen at that event, if the engine still keeps it. It keeps
|
|
1120
|
+
* the last four views, and frames in a row with the same view count as one. So a click during
|
|
1121
|
+
* a fast pan picks what the user saw. Any other point uses the camera of the
|
|
1122
|
+
* frame that last ran, with its lens as it is now. Objects stay where they are now, so a moving
|
|
1123
|
+
* object can be up to a frame of its motion away from where the user saw it.
|
|
1124
|
+
*/
|
|
1125
|
+
screenToRay(x, y, out) {
|
|
1126
|
+
if (DEV) {
|
|
1127
|
+
checkLive('screenToRay', this);
|
|
1128
|
+
checkNumber('screenToRay', 'x', x, this);
|
|
1129
|
+
checkNumber('screenToRay', 'y', y, this);
|
|
1130
|
+
}
|
|
1131
|
+
this.scene.frameCameras.screenToRay(this, x, y, out, 'screenToRay');
|
|
1132
|
+
}
|
|
1133
|
+
/**
|
|
1134
|
+
* Writes where a point in the world lies on the canvas into `out`: x and y in CSS pixels from the
|
|
1135
|
+
* canvas's top-left corner, then the point's depth, its distance in front of the camera along the
|
|
1136
|
+
* view. A depth below 0 puts the point behind the camera, where x and y have no meaning. It uses
|
|
1137
|
+
* the camera of the frame that last ran, with its lens as it is now, so in `onLateUpdate` it
|
|
1138
|
+
* places points where the frame draws them.
|
|
1139
|
+
*/
|
|
1140
|
+
worldToScreen(point, out) {
|
|
1141
|
+
if (DEV) {
|
|
1142
|
+
checkLive('worldToScreen', this);
|
|
1143
|
+
checkVector('worldToScreen', this, point[0], point[1], point[2]);
|
|
1144
|
+
}
|
|
1145
|
+
this.scene.frameCameras.worldToScreen(this, point, out, 'worldToScreen');
|
|
1146
|
+
}
|
|
1147
|
+
/** @internal Writes the lens into `lens`, after each change of its values. */
|
|
1148
|
+
updateLens() {
|
|
1149
|
+
const lens = this.lens;
|
|
1150
|
+
this.writeLensShape(lens);
|
|
1151
|
+
lens[LENS_NEAR] = this.nearPlane;
|
|
1152
|
+
lens[LENS_FAR] = this.farPlane;
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
/**
|
|
1156
|
+
* A camera that shows near things larger than far things, as the eye does.
|
|
1157
|
+
*
|
|
1158
|
+
* @category api/cameras
|
|
1159
|
+
*/
|
|
1160
|
+
export class PerspectiveCamera extends Camera {
|
|
1161
|
+
verticalFov;
|
|
1162
|
+
/** False: a perspective camera. */
|
|
1163
|
+
isOrthographic = false;
|
|
1164
|
+
/** @internal */
|
|
1165
|
+
constructor(scene, handle, name, verticalFov, near, far) {
|
|
1166
|
+
super(scene, handle, name, near, far);
|
|
1167
|
+
this.verticalFov = verticalFov;
|
|
1168
|
+
this.updateLens();
|
|
1169
|
+
}
|
|
1170
|
+
/** The vertical field of view in degrees. */
|
|
1171
|
+
get fov() {
|
|
1172
|
+
return this.verticalFov;
|
|
1173
|
+
}
|
|
1174
|
+
/** Sets the vertical field of view in degrees. */
|
|
1175
|
+
setFov(degrees) {
|
|
1176
|
+
if (DEV) {
|
|
1177
|
+
checkLive('setFov', this);
|
|
1178
|
+
checkFov('setFov', degrees, this);
|
|
1179
|
+
}
|
|
1180
|
+
this.verticalFov = degrees;
|
|
1181
|
+
this.scene.lensChanged(this);
|
|
1182
|
+
}
|
|
1183
|
+
/**
|
|
1184
|
+
* The focal length in millimeters of a lens with this field of view on a full-frame sensor, 24
|
|
1185
|
+
* mm tall. The default field of view of 50 degrees is about 25.7 mm.
|
|
1186
|
+
*/
|
|
1187
|
+
get focalLength() {
|
|
1188
|
+
return HALF_SENSOR_MM / Math.tan((this.verticalFov * Math.PI) / 360);
|
|
1189
|
+
}
|
|
1190
|
+
/**
|
|
1191
|
+
* Sets the field of view of a lens of `millimeters` on a full-frame sensor, 24 mm tall, as a
|
|
1192
|
+
* photographer picks a lens: 24 is wide, 50 normal and 85 a portrait lens. Depth of field takes
|
|
1193
|
+
* the same focal length unless its settings give another. Throws E1108 for a length that is not
|
|
1194
|
+
* above 0.
|
|
1195
|
+
*/
|
|
1196
|
+
setFocalLength(millimeters) {
|
|
1197
|
+
if (DEV)
|
|
1198
|
+
checkSize('setFocalLength', 'focal length', millimeters, this);
|
|
1199
|
+
this.setFov((360 / Math.PI) * Math.atan(HALF_SENSOR_MM / millimeters));
|
|
1200
|
+
}
|
|
1201
|
+
/** @internal */
|
|
1202
|
+
writeLensShape(lens) {
|
|
1203
|
+
lens[LENS_ORTHO] = 0;
|
|
1204
|
+
lens[LENS_HALF_HEIGHT] = Math.tan((this.verticalFov * Math.PI) / 360);
|
|
1205
|
+
lens[LENS_HALF_WIDTH] = 0;
|
|
1206
|
+
lens[LENS_CENTER_X] = 0;
|
|
1207
|
+
lens[LENS_CENTER_Y] = 0;
|
|
1208
|
+
}
|
|
1209
|
+
/** @internal */
|
|
1210
|
+
twin(handle) {
|
|
1211
|
+
const twin = new PerspectiveCamera(this.scene, handle, this.name, this.verticalFov, this.near, this.far);
|
|
1212
|
+
twin.layers = this.layers;
|
|
1213
|
+
return twin;
|
|
1214
|
+
}
|
|
1215
|
+
/** @internal */
|
|
1216
|
+
sendLens(core, target = C.CAMERA_TARGET_VIEW, layers = this.layers) {
|
|
1217
|
+
const values = core.callValues();
|
|
1218
|
+
values[0] = this.verticalFov;
|
|
1219
|
+
values[1] = this.near;
|
|
1220
|
+
values[2] = this.far;
|
|
1221
|
+
core.glue.setPerspectiveCamera(this.handle, layers, target);
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
/**
|
|
1225
|
+
* A camera whose view is a box: things keep their size at every distance, as in maps and
|
|
1226
|
+
* isometric games.
|
|
1227
|
+
*
|
|
1228
|
+
* @category api/cameras
|
|
1229
|
+
*/
|
|
1230
|
+
export class OrthographicCamera extends Camera {
|
|
1231
|
+
view;
|
|
1232
|
+
/** True: an orthographic camera. */
|
|
1233
|
+
isOrthographic = true;
|
|
1234
|
+
/** @internal */
|
|
1235
|
+
constructor(scene, handle, name,
|
|
1236
|
+
/** @internal The view's box across the camera's axis. */ view, near, far) {
|
|
1237
|
+
super(scene, handle, name, near, far);
|
|
1238
|
+
this.view = view;
|
|
1239
|
+
this.updateLens();
|
|
1240
|
+
}
|
|
1241
|
+
/** The view's height in world units. */
|
|
1242
|
+
get height() {
|
|
1243
|
+
return this.view.height;
|
|
1244
|
+
}
|
|
1245
|
+
/**
|
|
1246
|
+
* The view's width in world units, or undefined when the width follows the canvas's aspect
|
|
1247
|
+
* ratio.
|
|
1248
|
+
*/
|
|
1249
|
+
get width() {
|
|
1250
|
+
return this.view.width > 0 ? this.view.width : undefined;
|
|
1251
|
+
}
|
|
1252
|
+
/**
|
|
1253
|
+
* Sets the view's height in world units. A width that follows the canvas keeps following it.
|
|
1254
|
+
* A view made from four edges scales about its center and keeps its shape.
|
|
1255
|
+
*/
|
|
1256
|
+
setOrthoHeight(height) {
|
|
1257
|
+
if (DEV) {
|
|
1258
|
+
checkLive('setOrthoHeight', this);
|
|
1259
|
+
checkSize('setOrthoHeight', 'height', height, this);
|
|
1260
|
+
}
|
|
1261
|
+
setViewHeight(this.view, height);
|
|
1262
|
+
this.scene.lensChanged(this);
|
|
1263
|
+
}
|
|
1264
|
+
/** @internal */
|
|
1265
|
+
writeLensShape(lens) {
|
|
1266
|
+
const view = this.view;
|
|
1267
|
+
lens[LENS_ORTHO] = 1;
|
|
1268
|
+
lens[LENS_HALF_HEIGHT] = view.height / 2;
|
|
1269
|
+
lens[LENS_HALF_WIDTH] = view.width / 2;
|
|
1270
|
+
lens[LENS_CENTER_X] = view.centerX;
|
|
1271
|
+
lens[LENS_CENTER_Y] = view.centerY;
|
|
1272
|
+
}
|
|
1273
|
+
/** @internal */
|
|
1274
|
+
twin(handle) {
|
|
1275
|
+
const twin = new OrthographicCamera(this.scene, handle, this.name, { ...this.view }, this.near, this.far);
|
|
1276
|
+
twin.layers = this.layers;
|
|
1277
|
+
return twin;
|
|
1278
|
+
}
|
|
1279
|
+
/** @internal */
|
|
1280
|
+
sendLens(core, target = C.CAMERA_TARGET_VIEW, layers = this.layers) {
|
|
1281
|
+
const { view } = this;
|
|
1282
|
+
const values = core.callValues();
|
|
1283
|
+
values[0] = view.height;
|
|
1284
|
+
values[1] = view.width;
|
|
1285
|
+
values[2] = view.centerX;
|
|
1286
|
+
values[3] = view.centerY;
|
|
1287
|
+
values[4] = this.near;
|
|
1288
|
+
values[5] = this.far;
|
|
1289
|
+
core.glue.setOrthographicCamera(this.handle, layers, target);
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
/**
|
|
1293
|
+
* A light: a scene object that lights the objects around it. Each kind of light has a class of its
|
|
1294
|
+
* own. Setters allocate nothing, colors included, so `onUpdate` can animate lights.
|
|
1295
|
+
*
|
|
1296
|
+
* @category api/lights
|
|
1297
|
+
*/
|
|
1298
|
+
export class Light extends Object3D {
|
|
1299
|
+
/**
|
|
1300
|
+
* @internal The light's row in the engine's light table, or 0, which holds no light, once the
|
|
1301
|
+
* light is destroyed. The core then refuses its calls, so they never reach the light that
|
|
1302
|
+
* takes the row.
|
|
1303
|
+
*/
|
|
1304
|
+
id = 0;
|
|
1305
|
+
/** @internal The light's color in linear RGB, before the intensity scales it. */
|
|
1306
|
+
linear = new Float64Array([1, 1, 1]);
|
|
1307
|
+
/**
|
|
1308
|
+
* @internal What an intensity in the light's unit is in three.js's unit: 1, or the candela of
|
|
1309
|
+
* one lumen for a point or spot light in lumens. It sits in a typed array so a per-frame
|
|
1310
|
+
* `setIntensity` reads it without boxing a number.
|
|
1311
|
+
*/
|
|
1312
|
+
unitScale = new Float64Array(1).fill(1);
|
|
1313
|
+
/**
|
|
1314
|
+
* @internal The picture that `setImage` or `setMap` set and that is not written yet, if any, so
|
|
1315
|
+
* a task that writes it can tell whether a later call has replaced it.
|
|
1316
|
+
*/
|
|
1317
|
+
pendingImage = null;
|
|
1318
|
+
get looksDownMinusZ() {
|
|
1319
|
+
return true;
|
|
1320
|
+
}
|
|
1321
|
+
/** @internal */
|
|
1322
|
+
twin(handle) {
|
|
1323
|
+
const twin = super.twin(handle);
|
|
1324
|
+
const { core } = this.scene;
|
|
1325
|
+
twin.id = core.checkGrowth(core.glue.copyLight(this.id, handle), 'clone', this.label);
|
|
1326
|
+
twin.linear.set(this.linear);
|
|
1327
|
+
twin.unitScale[0] = this.unitScale[0];
|
|
1328
|
+
return twin;
|
|
1329
|
+
}
|
|
1330
|
+
/** Sets the color. It allocates nothing, so a sketch can change the color in every frame. */
|
|
1331
|
+
setColor(color) {
|
|
1332
|
+
this.paint('setColor', C.LIGHT_COLOR_MAIN, color);
|
|
1333
|
+
}
|
|
1334
|
+
/** Sets the factor that scales the color, in the unit that the light was created with. */
|
|
1335
|
+
setIntensity(intensity) {
|
|
1336
|
+
this.scene.core.callValues()[0] = intensity * this.unitScale[0];
|
|
1337
|
+
this.write('setIntensity', C.LIGHT_VALUE_INTENSITY);
|
|
1338
|
+
}
|
|
1339
|
+
/** Removes the light at the next frame. Its children become roots. */
|
|
1340
|
+
destroy() {
|
|
1341
|
+
const { id } = this;
|
|
1342
|
+
super.destroy();
|
|
1343
|
+
if (id === 0)
|
|
1344
|
+
return;
|
|
1345
|
+
this.id = 0;
|
|
1346
|
+
const { core } = this.scene;
|
|
1347
|
+
core.check(core.glue.destroyLight(id), 'destroy', this.label, true);
|
|
1348
|
+
}
|
|
1349
|
+
/** @internal Sets one of the light's colors, by its code in the light table. */
|
|
1350
|
+
paint(call, which, color) {
|
|
1351
|
+
if (DEV)
|
|
1352
|
+
checkLive(call, this);
|
|
1353
|
+
const { core } = this.scene;
|
|
1354
|
+
const rgb = writeLinearColor(core.callValues(), color, call);
|
|
1355
|
+
if (which === C.LIGHT_COLOR_MAIN) {
|
|
1356
|
+
const { linear } = this;
|
|
1357
|
+
linear[0] = rgb[0];
|
|
1358
|
+
linear[1] = rgb[1];
|
|
1359
|
+
linear[2] = rgb[2];
|
|
1360
|
+
}
|
|
1361
|
+
core.glue.setLightColor(this.id, which);
|
|
1362
|
+
}
|
|
1363
|
+
/** @internal Sets each of the shadow settings that `shadow` gives. */
|
|
1364
|
+
shadow(call, shadow) {
|
|
1365
|
+
for (const [key, which] of SHADOW_NUMBERS) {
|
|
1366
|
+
const value = shadow[key];
|
|
1367
|
+
if (value === undefined)
|
|
1368
|
+
continue;
|
|
1369
|
+
// The light table's 0 means 'auto', the automatic distance.
|
|
1370
|
+
if (DEV &&
|
|
1371
|
+
key === 'distance' &&
|
|
1372
|
+
typeof value === 'number' &&
|
|
1373
|
+
Number.isFinite(value) &&
|
|
1374
|
+
!(value > 0))
|
|
1375
|
+
throw new EngineError('E1108', `${call}() got the shadow distance ${value} on ${this.describe()}, which must be above 0 or 'auto'.`);
|
|
1376
|
+
this.writeValue(call, which, value === 'auto' ? 0 : value);
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* @internal Sets one of the light's numbers, by its code in the light table, from the call
|
|
1381
|
+
* value: a per-frame setter writes the number into the call values in its own small body and
|
|
1382
|
+
* calls this with no number, so no fraction crosses a call that the browser may not inline.
|
|
1383
|
+
*/
|
|
1384
|
+
write(call, which) {
|
|
1385
|
+
this.applyLightValue(call, which, this.scene.core.callValues()[0]);
|
|
1386
|
+
}
|
|
1387
|
+
/**
|
|
1388
|
+
* @internal Sets one of the light's numbers from `value`: creating a light, its shadow settings
|
|
1389
|
+
* and its copy pass the number itself.
|
|
1390
|
+
*/
|
|
1391
|
+
writeValue(call, which, value) {
|
|
1392
|
+
this.scene.core.callValues()[0] = value;
|
|
1393
|
+
this.applyLightValue(call, which, value);
|
|
1394
|
+
}
|
|
1395
|
+
/** @internal Checks one of the light's numbers and passes it to the core. */
|
|
1396
|
+
applyLightValue(call, which, value) {
|
|
1397
|
+
const { core } = this.scene;
|
|
1398
|
+
if (DEV) {
|
|
1399
|
+
checkLive(call, this);
|
|
1400
|
+
const limits = LIGHT_LIMITS[which];
|
|
1401
|
+
// A required setting that the options left out arrives as undefined, which the range
|
|
1402
|
+
// test below reports in the light's own terms.
|
|
1403
|
+
if (typeof value === 'number')
|
|
1404
|
+
checkNumber(call, limits[0], value, this);
|
|
1405
|
+
// The shadow distance 0 is 'auto', and it stands in for the default.
|
|
1406
|
+
const auto = which === C.LIGHT_VALUE_SHADOW_DISTANCE && value === 0;
|
|
1407
|
+
// Cascades are whole, and map and tile sizes are powers of two.
|
|
1408
|
+
const whole = which === C.LIGHT_VALUE_SHADOW_CASCADES
|
|
1409
|
+
? Number.isInteger(value)
|
|
1410
|
+
: (which !== C.LIGHT_VALUE_SHADOW_MAP_SIZE && which !== C.LIGHT_VALUE_HERO_SIZE) ||
|
|
1411
|
+
(value & (value - 1)) === 0;
|
|
1412
|
+
if (!auto && !(value !== undefined && value >= limits[1] && value <= limits[2] && whole))
|
|
1413
|
+
throw new EngineError('E1108', `${call}() got the ${limits[0]} ${value} on ${this.describe()}, which must be ${limits[3]}.`);
|
|
1414
|
+
}
|
|
1415
|
+
core.glue.setLightValue(this.id, which);
|
|
1416
|
+
}
|
|
1417
|
+
/**
|
|
1418
|
+
* @internal Turns the light so that its light travels along (x, y, z), relative to its parent.
|
|
1419
|
+
*/
|
|
1420
|
+
aim(call, x, y, z) {
|
|
1421
|
+
if (DEV) {
|
|
1422
|
+
checkLive(call, this);
|
|
1423
|
+
checkVector(call, this, x, y, z);
|
|
1424
|
+
if (x === 0 && y === 0 && z === 0)
|
|
1425
|
+
throw new EngineError('E1108', `${call}() got the direction (0, 0, 0) on ${this.describe()}, which points nowhere.`);
|
|
1426
|
+
}
|
|
1427
|
+
const { scene } = this;
|
|
1428
|
+
const d = scene.target;
|
|
1429
|
+
const k = 1 / (Math.sqrt(x * x + y * y + z * z) || 1);
|
|
1430
|
+
d[0] = x * k;
|
|
1431
|
+
d[1] = y * k;
|
|
1432
|
+
d[2] = z * k;
|
|
1433
|
+
rotationTo(scene.scratch, LIGHT_AXIS, d);
|
|
1434
|
+
scene.views.rotations.set(scene.scratch, this.row * 4);
|
|
1435
|
+
scene.markDirty(this.row);
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
/**
|
|
1439
|
+
* Light from one direction, like sunlight. It travels along the light's -Z axis, which
|
|
1440
|
+
* `setDirection`, `lookAt` and the light's parents turn. Its position does not matter.
|
|
1441
|
+
*
|
|
1442
|
+
* Up to four directional lights light surfaces at once. The first one created casts the shadows,
|
|
1443
|
+
* when `castShadows` is on, and up to three more light as fill and rim lights, without shadows.
|
|
1444
|
+
* A fifth directional light gives no light.
|
|
1445
|
+
*
|
|
1446
|
+
* @category api/lights
|
|
1447
|
+
*/
|
|
1448
|
+
export class DirectionalLight extends Light {
|
|
1449
|
+
/** Turns the light so that its light travels along (x, y, z), relative to its parent. */
|
|
1450
|
+
setDirection(x, y, z) {
|
|
1451
|
+
this.aim('setDirection', x, y, z);
|
|
1452
|
+
}
|
|
1453
|
+
/**
|
|
1454
|
+
* Makes the light cast shadows, or stop. The default is false. The first directional light
|
|
1455
|
+
* created casts them.
|
|
1456
|
+
*/
|
|
1457
|
+
setCastShadows(cast) {
|
|
1458
|
+
this.setFlag('setCastShadows', C.FLAG_CAST_SHADOWS, cast);
|
|
1459
|
+
}
|
|
1460
|
+
/**
|
|
1461
|
+
* Gives `hero` its own shadow map, or takes it away with `null`. The map is a tile of the
|
|
1462
|
+
* shadow atlas, fitted tightly to the object along the light, so its shadow keeps far finer
|
|
1463
|
+
* texels than the cascades give it. Surfaces near the object read that tile in place of the
|
|
1464
|
+
* cascades. The object casts shadows; its light is this light.
|
|
1465
|
+
*
|
|
1466
|
+
* `tileSize` gives the tile's texels on each side, 1,024, 2,048 or 4,096. Leaving it out keeps
|
|
1467
|
+
* the light's value, which starts as the quality preset's `heroTileSize`.
|
|
1468
|
+
*/
|
|
1469
|
+
setHeroShadow(hero, tileSize) {
|
|
1470
|
+
if (DEV) {
|
|
1471
|
+
checkLive('setHeroShadow', this);
|
|
1472
|
+
if (hero !== null) {
|
|
1473
|
+
if (!(hero instanceof Object3D))
|
|
1474
|
+
throw new EngineError('E1213', `setHeroShadow() got ${String(hero)}, which is not an object. Give an object that casts shadows, or null.`);
|
|
1475
|
+
checkLive('setHeroShadow', hero, true);
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
if (tileSize !== undefined)
|
|
1479
|
+
this.writeValue('setHeroShadow', C.LIGHT_VALUE_HERO_SIZE, tileSize);
|
|
1480
|
+
const { core } = this.scene;
|
|
1481
|
+
const object = hero === null ? 0 : hero.handle >>> 0;
|
|
1482
|
+
// The core's light setters report nothing the page can act on, like every other one here.
|
|
1483
|
+
core.glue.setLightHero(this.id, object);
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* Changes how the light's shadows draw. Settings that `shadow` leaves out keep their values. A
|
|
1487
|
+
* new cascade count or map size makes the shadow map again, so set them at setup.
|
|
1488
|
+
*/
|
|
1489
|
+
setShadow(shadow) {
|
|
1490
|
+
this.shadow('setShadow', shadow);
|
|
1491
|
+
}
|
|
1492
|
+
/** @internal Sets each of the shadow settings that `shadow` gives, the hero among them. */
|
|
1493
|
+
shadow(call, shadow) {
|
|
1494
|
+
super.shadow(call, shadow);
|
|
1495
|
+
const hero = shadow.hero;
|
|
1496
|
+
if (hero !== undefined)
|
|
1497
|
+
this.setHeroShadow(hero);
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
/**
|
|
1501
|
+
* Light from a point in every direction, which fades with distance and ends at its range.
|
|
1502
|
+
*
|
|
1503
|
+
* @category api/lights
|
|
1504
|
+
*/
|
|
1505
|
+
export class PointLight extends Light {
|
|
1506
|
+
/** Sets the distance in meters where the light ends, above 0. */
|
|
1507
|
+
setRange(range) {
|
|
1508
|
+
this.scene.core.callValues()[0] = range;
|
|
1509
|
+
this.write('setRange', C.LIGHT_VALUE_RANGE);
|
|
1510
|
+
}
|
|
1511
|
+
/** Sets how fast the light fades with distance, at least 0: 2 is the physical rate. */
|
|
1512
|
+
setDecay(decay) {
|
|
1513
|
+
this.scene.core.callValues()[0] = decay;
|
|
1514
|
+
this.write('setDecay', C.LIGHT_VALUE_DECAY);
|
|
1515
|
+
}
|
|
1516
|
+
/**
|
|
1517
|
+
* Makes the light cast shadows, or stop. The default is false. Point lights cast them where the
|
|
1518
|
+
* quality preset's `pointLightShadows` is on, and each takes six tiles of `shadowTiles`.
|
|
1519
|
+
*/
|
|
1520
|
+
setCastShadows(cast) {
|
|
1521
|
+
this.setFlag('setCastShadows', C.FLAG_CAST_SHADOWS, cast);
|
|
1522
|
+
}
|
|
1523
|
+
/** Changes how the light's shadows draw. Settings that `shadow` leaves out keep their values. */
|
|
1524
|
+
setShadow(shadow) {
|
|
1525
|
+
this.shadow('setShadow', shadow);
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
/**
|
|
1529
|
+
* Light from a point in a cone, which fades with distance and ends at its range. The cone points
|
|
1530
|
+
* along the light's -Z axis, which `setDirection`, `lookAt` and the light's parents turn.
|
|
1531
|
+
*
|
|
1532
|
+
* @category api/lights
|
|
1533
|
+
*/
|
|
1534
|
+
export class SpotLight extends Light {
|
|
1535
|
+
/** @internal The texture that `setMap` gave the light and that is not copied yet, so a later picture cancels it. */
|
|
1536
|
+
pendingTexture = null;
|
|
1537
|
+
/** Sets the distance in meters where the light ends, above 0. */
|
|
1538
|
+
setRange(range) {
|
|
1539
|
+
this.scene.core.callValues()[0] = range;
|
|
1540
|
+
this.write('setRange', C.LIGHT_VALUE_RANGE);
|
|
1541
|
+
}
|
|
1542
|
+
/** Sets how fast the light fades with distance, at least 0: 2 is the physical rate. */
|
|
1543
|
+
setDecay(decay) {
|
|
1544
|
+
this.scene.core.callValues()[0] = decay;
|
|
1545
|
+
this.write('setDecay', C.LIGHT_VALUE_DECAY);
|
|
1546
|
+
}
|
|
1547
|
+
/** Sets the angle in radians from the light's direction to the edge of its cone: up to π/2. */
|
|
1548
|
+
setAngle(angle) {
|
|
1549
|
+
this.scene.core.callValues()[0] = angle;
|
|
1550
|
+
this.write('setAngle', C.LIGHT_VALUE_ANGLE);
|
|
1551
|
+
}
|
|
1552
|
+
/** Sets the part of the cone, from 0 to 1, over which the light fades out toward the edge. */
|
|
1553
|
+
setPenumbra(penumbra) {
|
|
1554
|
+
this.scene.core.callValues()[0] = penumbra;
|
|
1555
|
+
this.write('setPenumbra', C.LIGHT_VALUE_PENUMBRA);
|
|
1556
|
+
}
|
|
1557
|
+
/**
|
|
1558
|
+
* Projects a picture over the light's cone, such as a window frame, a gobo pattern or a
|
|
1559
|
+
* projected photograph, or `null` to go back to one color. The color and intensity tint it.
|
|
1560
|
+
* The picture fills the square around the cone: a circle in its middle lands on the cone's
|
|
1561
|
+
* edge, where the light ends. The picture's top row lies along the world's up, so rolling the
|
|
1562
|
+
* light about its own axis leaves the picture as it is. The engine keeps the picture's detail
|
|
1563
|
+
* up to 512 texels a side, so a small gobo costs less memory than a detailed photograph. Give
|
|
1564
|
+
* sRGB pixels, or a texture that the engine copies once: a texture larger than 512 texels a
|
|
1565
|
+
* side is reduced, and one that changes every frame, such as a video's or a render pass's,
|
|
1566
|
+
* throws E1112, because the copy would show a single frame. A surface far from the light shows
|
|
1567
|
+
* the picture blurred. Up to 32 lights show pictures at once, and rectangle and spot lights
|
|
1568
|
+
* share those places. A new picture takes up to a few tens of milliseconds, so set it at setup
|
|
1569
|
+
* or now and then, not in every frame.
|
|
1570
|
+
*/
|
|
1571
|
+
setMap(map) {
|
|
1572
|
+
const call = 'setMap';
|
|
1573
|
+
if (DEV)
|
|
1574
|
+
checkLive(call, this);
|
|
1575
|
+
if (map instanceof Texture) {
|
|
1576
|
+
checkMapTexture(call, map, this);
|
|
1577
|
+
this.pendingImage = null;
|
|
1578
|
+
this.pendingTexture = map;
|
|
1579
|
+
writeLightTexture(this, map, call);
|
|
1580
|
+
return;
|
|
1581
|
+
}
|
|
1582
|
+
this.pendingTexture = null;
|
|
1583
|
+
if (map !== null && DEV)
|
|
1584
|
+
checkLightImage(call, map, this);
|
|
1585
|
+
this.pendingImage = map;
|
|
1586
|
+
writeLightImage(this, map, call);
|
|
1587
|
+
}
|
|
1588
|
+
/** @internal A copy starts without the picture, which `setMap` gives it. */
|
|
1589
|
+
twin(handle) {
|
|
1590
|
+
const twin = super.twin(handle);
|
|
1591
|
+
twin.writeValue('twin', C.LIGHT_VALUE_IMAGE, 0);
|
|
1592
|
+
return twin;
|
|
1593
|
+
}
|
|
1594
|
+
/** Removes the light at the next frame, and frees its picture's place. */
|
|
1595
|
+
destroy() {
|
|
1596
|
+
this.pendingImage = null;
|
|
1597
|
+
this.pendingTexture = null;
|
|
1598
|
+
if (this.id !== 0)
|
|
1599
|
+
this.scene.core.glue.removeLightImage(this.id);
|
|
1600
|
+
super.destroy();
|
|
1601
|
+
}
|
|
1602
|
+
/** Turns the light so that its light travels along (x, y, z), relative to its parent. */
|
|
1603
|
+
setDirection(x, y, z) {
|
|
1604
|
+
this.aim('setDirection', x, y, z);
|
|
1605
|
+
}
|
|
1606
|
+
/**
|
|
1607
|
+
* Makes the light cast shadows, or stop. The default is false. The quality preset's
|
|
1608
|
+
* `shadowTiles` caps the lights that cast them at once: the lights that look largest from the
|
|
1609
|
+
* camera cast them first.
|
|
1610
|
+
*/
|
|
1611
|
+
setCastShadows(cast) {
|
|
1612
|
+
this.setFlag('setCastShadows', C.FLAG_CAST_SHADOWS, cast);
|
|
1613
|
+
}
|
|
1614
|
+
/** Changes how the light's shadows draw. Settings that `shadow` leaves out keep their values. */
|
|
1615
|
+
setShadow(shadow) {
|
|
1616
|
+
this.shadow('setShadow', shadow);
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
/**
|
|
1620
|
+
* Light from the sky above and the ground below, which fades from one color to the other with the
|
|
1621
|
+
* way a surface faces. The sky lies along the light's +Y axis. `setColor` sets the sky color.
|
|
1622
|
+
*
|
|
1623
|
+
* @category api/lights
|
|
1624
|
+
*/
|
|
1625
|
+
export class HemisphereLight extends Light {
|
|
1626
|
+
/** Sets the ground color. It allocates nothing. */
|
|
1627
|
+
setGroundColor(color) {
|
|
1628
|
+
this.paint('setGroundColor', C.LIGHT_COLOR_GROUND, color);
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
/**
|
|
1632
|
+
* Light that reaches every surface equally.
|
|
1633
|
+
*
|
|
1634
|
+
* @category api/lights
|
|
1635
|
+
*/
|
|
1636
|
+
export class AmbientLight extends Light {
|
|
1637
|
+
}
|
|
1638
|
+
/**
|
|
1639
|
+
* Light from a rectangle of even brightness, such as a window, a screen or a studio panel. Its
|
|
1640
|
+
* light leaves the side that its -Z axis points to, and ends at its range. Surfaces show its whole
|
|
1641
|
+
* shape in their highlights, and soft light near it. Its intensity is the rectangle's brightness
|
|
1642
|
+
* in nits. It casts no shadows.
|
|
1643
|
+
*
|
|
1644
|
+
* @category api/lights
|
|
1645
|
+
*/
|
|
1646
|
+
export class RectAreaLight extends Light {
|
|
1647
|
+
/** Sets the distance in meters from the light's middle where its light ends, above 0. */
|
|
1648
|
+
setRange(range) {
|
|
1649
|
+
this.scene.core.callValues()[0] = range;
|
|
1650
|
+
this.write('setRange', C.LIGHT_VALUE_RANGE);
|
|
1651
|
+
}
|
|
1652
|
+
/** Sets the width along the light's X axis and the height along its Y axis, in meters. */
|
|
1653
|
+
setSize(width, height) {
|
|
1654
|
+
const values = this.scene.core.callValues();
|
|
1655
|
+
values[0] = width;
|
|
1656
|
+
this.write('setSize', C.LIGHT_VALUE_WIDTH);
|
|
1657
|
+
values[0] = height;
|
|
1658
|
+
this.write('setSize', C.LIGHT_VALUE_HEIGHT);
|
|
1659
|
+
}
|
|
1660
|
+
/** Turns the light so that its light leaves along (x, y, z), relative to its parent. */
|
|
1661
|
+
setDirection(x, y, z) {
|
|
1662
|
+
this.aim('setDirection', x, y, z);
|
|
1663
|
+
}
|
|
1664
|
+
/**
|
|
1665
|
+
* Shows a picture over the light's area, such as a shop window or a screen, or `null` to go back
|
|
1666
|
+
* to one color. The color and intensity tint it. The light gives out its intensity times the
|
|
1667
|
+
* picture's average color, so a mostly dark picture lights little around it. The picture's top
|
|
1668
|
+
* row lies along the light's +Y axis, and it reads the right way round from the lit side. The
|
|
1669
|
+
* engine keeps the picture's detail up to 512 texels a side, so shiny surfaces show it sharp
|
|
1670
|
+
* and rough ones blurred. Up to 32 lights show pictures at once. A new picture allocates and
|
|
1671
|
+
* takes up to a few tens of milliseconds, so set it at setup or now and then, not in every
|
|
1672
|
+
* frame.
|
|
1673
|
+
*/
|
|
1674
|
+
setImage(image) {
|
|
1675
|
+
const call = 'setImage';
|
|
1676
|
+
if (DEV)
|
|
1677
|
+
checkLive(call, this);
|
|
1678
|
+
if (image !== null && DEV)
|
|
1679
|
+
checkLightImage(call, image, this);
|
|
1680
|
+
this.pendingImage = image;
|
|
1681
|
+
writeLightImage(this, image, call);
|
|
1682
|
+
}
|
|
1683
|
+
/** @internal A copy starts without the picture, which `setImage` gives it. */
|
|
1684
|
+
twin(handle) {
|
|
1685
|
+
const twin = super.twin(handle);
|
|
1686
|
+
twin.writeValue('twin', C.LIGHT_VALUE_IMAGE, 0);
|
|
1687
|
+
return twin;
|
|
1688
|
+
}
|
|
1689
|
+
/** Removes the light at the next frame, and frees its picture's place. */
|
|
1690
|
+
destroy() {
|
|
1691
|
+
this.pendingImage = null;
|
|
1692
|
+
if (this.id !== 0)
|
|
1693
|
+
this.scene.core.glue.removeLightImage(this.id);
|
|
1694
|
+
super.destroy();
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
/**
|
|
1698
|
+
* Writes `image` into the light tables for `light`, or frees its place for `null`. The resampler
|
|
1699
|
+
* loads on first use, so a page that sets no picture downloads none of it. The light keeps the
|
|
1700
|
+
* pixels; a task writes them, which `imagesSettled` waits for.
|
|
1701
|
+
*/
|
|
1702
|
+
function writeLightImage(light, image, call) {
|
|
1703
|
+
const { scene } = light;
|
|
1704
|
+
const { core } = scene;
|
|
1705
|
+
if (image === null) {
|
|
1706
|
+
core.check(core.glue.removeLightImage(light.id), call, light.label, true);
|
|
1707
|
+
return;
|
|
1708
|
+
}
|
|
1709
|
+
const id = light.id;
|
|
1710
|
+
scene.queueImage(import('./light-images.js').then(({ lightImageSize, lightImageHalves, prepareLightImage }) => {
|
|
1711
|
+
if (light.id !== id || light.pendingImage !== image)
|
|
1712
|
+
return;
|
|
1713
|
+
const size = lightImageSize(image.width, image.height);
|
|
1714
|
+
const at = core.checkGrowth(core.glue.lightImage(id, size), call, light.label);
|
|
1715
|
+
prepareLightImage(image, core.view(Uint16Array, at, lightImageHalves(size)), size);
|
|
1716
|
+
core.check(core.glue.finishLightImage(id), call, light.label, true);
|
|
1717
|
+
}));
|
|
1718
|
+
}
|
|
1719
|
+
/** Throws E1108 for pixels whose size or data a light's image cannot take. */
|
|
1720
|
+
function checkLightImage(call, image, light) {
|
|
1721
|
+
const { width, height, data } = image;
|
|
1722
|
+
const whole = (n) => Number.isInteger(n) && n > 0;
|
|
1723
|
+
if (!whole(width) || !whole(height) || !data || data.length < width * height * 4)
|
|
1724
|
+
throw new EngineError('E1108', `${call}() got an image of ${width} x ${height} pixels with ${data?.length ?? 0} bytes on ${light.describe()}, which needs a whole width and height above 0 and 4 bytes per pixel.`);
|
|
1725
|
+
}
|
|
1726
|
+
/**
|
|
1727
|
+
* Gives `light` a picture whose texels come from `texture`: the resampler picks the image's size
|
|
1728
|
+
* from the texture's, and a task asks the frame builder for the copy, which `imagesSettled` waits
|
|
1729
|
+
* for. The frame builder copies once, when the texture's texels reach the GPU.
|
|
1730
|
+
*/
|
|
1731
|
+
function writeLightTexture(light, texture, call) {
|
|
1732
|
+
const { scene } = light;
|
|
1733
|
+
const { core } = scene;
|
|
1734
|
+
const id = light.id;
|
|
1735
|
+
scene.queueImage(import('./light-images.js').then(({ lightImageSize }) => {
|
|
1736
|
+
if (light.id !== id || light.pendingTexture !== texture || !texture.live)
|
|
1737
|
+
return;
|
|
1738
|
+
const size = lightImageSize(texture.width, texture.height);
|
|
1739
|
+
core.check(core.glue.setLightMapTexture(id, texture.handle, size), call, light.label, true);
|
|
1740
|
+
}));
|
|
1741
|
+
}
|
|
1742
|
+
/** Throws E1112 for a texture that a spot light's map cannot copy into its image. */
|
|
1743
|
+
function checkMapTexture(call, texture, light) {
|
|
1744
|
+
if (!texture.live)
|
|
1745
|
+
throw new EngineError('E1112', `${call}() got a texture that texture.destroy() destroyed on ${light.describe()}. Give a live texture.`);
|
|
1746
|
+
if (texture.pass || texture.video)
|
|
1747
|
+
throw new EngineError('E1112', `${call}() got a texture that changes every frame on ${light.describe()}, which a spot light's map copies once. Give a still texture, such as one that assets.loadTexture loaded.`);
|
|
1748
|
+
if (texture.depth !== 1)
|
|
1749
|
+
throw new EngineError('E1112', `${call}() got a texture of ${texture.depth} layers on ${light.describe()}, which a spot light's map cannot project. Give a 2D texture.`);
|
|
1750
|
+
if (texture.droppedLevels > 0)
|
|
1751
|
+
throw new EngineError('E1112', `${call}() got a texture whose largest mip levels the texture memory budget dropped on ${light.describe()}, so it has no picture to copy. Free texture memory, or give another texture.`);
|
|
1752
|
+
}
|
|
1753
|
+
/**
|
|
1754
|
+
* Light from a glowing tube, such as a neon or fluorescent tube, in every direction around it,
|
|
1755
|
+
* out to its range. The tube runs along the light's -Z axis. Its intensity is the tube's
|
|
1756
|
+
* brightness in nits, as for a rectangle light. It casts no shadows.
|
|
1757
|
+
*
|
|
1758
|
+
* @category api/lights
|
|
1759
|
+
*/
|
|
1760
|
+
export class TubeLight extends Light {
|
|
1761
|
+
/** Sets the distance in meters from the tube's middle where its light ends, above 0. */
|
|
1762
|
+
setRange(range) {
|
|
1763
|
+
this.scene.core.callValues()[0] = range;
|
|
1764
|
+
this.write('setRange', C.LIGHT_VALUE_RANGE);
|
|
1765
|
+
}
|
|
1766
|
+
/** Sets the tube's length along the light's -Z axis and its radius, in meters. */
|
|
1767
|
+
setSize(length, radius) {
|
|
1768
|
+
const values = this.scene.core.callValues();
|
|
1769
|
+
values[0] = length;
|
|
1770
|
+
this.write('setSize', C.LIGHT_VALUE_WIDTH);
|
|
1771
|
+
values[0] = radius;
|
|
1772
|
+
this.write('setSize', C.LIGHT_VALUE_RADIUS);
|
|
1773
|
+
}
|
|
1774
|
+
/** Turns the tube so that it runs along (x, y, z), relative to its parent. */
|
|
1775
|
+
setDirection(x, y, z) {
|
|
1776
|
+
this.aim('setDirection', x, y, z);
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
/**
|
|
1780
|
+
* Many copies of one mesh and material. Write rows straight into the typed arrays; a dynamic batch
|
|
1781
|
+
* updates every row every frame, and a static batch updates the rows you mark dirty.
|
|
1782
|
+
*
|
|
1783
|
+
* @category api/scene
|
|
1784
|
+
*/
|
|
1785
|
+
export class InstanceBatch {
|
|
1786
|
+
scene;
|
|
1787
|
+
id;
|
|
1788
|
+
count;
|
|
1789
|
+
own;
|
|
1790
|
+
parts;
|
|
1791
|
+
uses;
|
|
1792
|
+
generation = -1;
|
|
1793
|
+
rows;
|
|
1794
|
+
/** @internal */
|
|
1795
|
+
destroyedFrame = -1;
|
|
1796
|
+
/** @internal The batch's pointer event handlers, from its first `on`. */
|
|
1797
|
+
pointerListeners = undefined;
|
|
1798
|
+
/**
|
|
1799
|
+
* @internal The sprite, point or line batch whose rows this batch holds, which hits and pointer
|
|
1800
|
+
* events name in its place.
|
|
1801
|
+
*/
|
|
1802
|
+
face = undefined;
|
|
1803
|
+
/** @internal The rows that draw, from the first. */
|
|
1804
|
+
activeRows;
|
|
1805
|
+
/** @internal */
|
|
1806
|
+
constructor(scene,
|
|
1807
|
+
/** @internal */ id,
|
|
1808
|
+
/** The number of rows: the batch's capacity. */
|
|
1809
|
+
count, own = NO_ROW_VALUES,
|
|
1810
|
+
/** @internal The batches of a model's other meshes, which read this batch's rows. */
|
|
1811
|
+
parts = [],
|
|
1812
|
+
/** @internal The meshes and materials that the batch and its parts draw. */
|
|
1813
|
+
uses = NO_USES) {
|
|
1814
|
+
this.scene = scene;
|
|
1815
|
+
this.id = id;
|
|
1816
|
+
this.count = count;
|
|
1817
|
+
this.own = own;
|
|
1818
|
+
this.parts = parts;
|
|
1819
|
+
this.uses = uses;
|
|
1820
|
+
this.activeRows = count;
|
|
1821
|
+
scene.core.holdViews(this);
|
|
1822
|
+
}
|
|
1823
|
+
/** Forgets the row arrays, which the next read makes again. */
|
|
1824
|
+
dropViews() {
|
|
1825
|
+
if (this.generation === -1)
|
|
1826
|
+
return;
|
|
1827
|
+
this.generation = -1;
|
|
1828
|
+
this.rows = NO_ROWS;
|
|
1829
|
+
}
|
|
1830
|
+
/** @internal The batch, as error messages name it. */
|
|
1831
|
+
describe() {
|
|
1832
|
+
return `${this.face ? 'a sprite or point batch' : 'an instance batch'} of ${this.count} rows`;
|
|
1833
|
+
}
|
|
1834
|
+
/**
|
|
1835
|
+
* The number that a custom material's WGSL reads as `object.id` for every row of the batch.
|
|
1836
|
+
* No other live batch or mesh has it. The WGSL tells the rows apart by `input.instance`.
|
|
1837
|
+
*/
|
|
1838
|
+
get shaderId() {
|
|
1839
|
+
return BATCH_SHADER_ID | (this.id & SLOT_MASK);
|
|
1840
|
+
}
|
|
1841
|
+
/**
|
|
1842
|
+
* The row arrays, made again after the engine's memory grew. Sketches read rows every frame, so
|
|
1843
|
+
* this check creates no closure: one would allocate on each call until the browser optimizes
|
|
1844
|
+
* the code.
|
|
1845
|
+
*/
|
|
1846
|
+
views() {
|
|
1847
|
+
if (this.generation !== this.scene.core.generation)
|
|
1848
|
+
this.makeViews();
|
|
1849
|
+
return this.rows;
|
|
1850
|
+
}
|
|
1851
|
+
makeViews() {
|
|
1852
|
+
const { core } = this.scene;
|
|
1853
|
+
if (this.own.ranges)
|
|
1854
|
+
core.check(core.glue.reserveBatchRanges(this.id), 'instance arrays', 'an instance batch');
|
|
1855
|
+
const address = (field) => core.check(core.glue.batchArrays(this.id, field), 'instance arrays', 'an instance batch');
|
|
1856
|
+
this.rows = {
|
|
1857
|
+
positions: core.f32(address(C.BATCH_FIELD_POSITIONS), this.count * 3),
|
|
1858
|
+
rotations: core.f32(address(C.BATCH_FIELD_ROTATIONS), this.count * 4),
|
|
1859
|
+
scales: core.f32(address(C.BATCH_FIELD_SCALES), this.count * 3),
|
|
1860
|
+
colors: this.own.colors ? core.f32(address(C.BATCH_FIELD_COLORS), this.count * 4) : undefined,
|
|
1861
|
+
values: this.own.values ? core.f32(address(C.BATCH_FIELD_VALUES), this.count * 4) : undefined,
|
|
1862
|
+
ranges: this.own.ranges ? core.f32(address(C.BATCH_FIELD_RANGES), this.count * 2) : undefined,
|
|
1863
|
+
};
|
|
1864
|
+
this.generation = core.generation;
|
|
1865
|
+
}
|
|
1866
|
+
/** Positions, 3 floats per row. */
|
|
1867
|
+
get positions() {
|
|
1868
|
+
return this.views().positions;
|
|
1869
|
+
}
|
|
1870
|
+
/** Rotations as quaternions (x, y, z, w), 4 floats per row. */
|
|
1871
|
+
get rotations() {
|
|
1872
|
+
return this.views().rotations;
|
|
1873
|
+
}
|
|
1874
|
+
/** Scales, 3 floats per row. */
|
|
1875
|
+
get scales() {
|
|
1876
|
+
return this.views().scales;
|
|
1877
|
+
}
|
|
1878
|
+
/**
|
|
1879
|
+
* Linear RGBA colors, 4 floats per row, when the batch was created with `colors`. Each multiplies
|
|
1880
|
+
* its row's base color and opacity.
|
|
1881
|
+
*/
|
|
1882
|
+
get colors() {
|
|
1883
|
+
return this.views().colors;
|
|
1884
|
+
}
|
|
1885
|
+
/**
|
|
1886
|
+
* The rows' own values, 4 floats per row, when the batch was created with `values`. A custom
|
|
1887
|
+
* material's WGSL reads its row's as `object.values`.
|
|
1888
|
+
*/
|
|
1889
|
+
get values() {
|
|
1890
|
+
return this.views().values;
|
|
1891
|
+
}
|
|
1892
|
+
/**
|
|
1893
|
+
* The rows' distance ranges, two floats per row: the start distance at `2i` and the end
|
|
1894
|
+
* distance at `2i + 1`, when the batch was created with `ranges`. A row draws between them,
|
|
1895
|
+
* with a fade at each edge. `setDrawRange` sets every row's, and a later write to this array
|
|
1896
|
+
* changes one row. Write it at setup: the engine reads it when it next rebuilds its draw
|
|
1897
|
+
* tables, which `setDrawRange` and a new object or batch make.
|
|
1898
|
+
*/
|
|
1899
|
+
get ranges() {
|
|
1900
|
+
return this.views().ranges;
|
|
1901
|
+
}
|
|
1902
|
+
/**
|
|
1903
|
+
* Sets the distances between which every row draws, as `Mesh.setDrawRange` does for one mesh:
|
|
1904
|
+
* nothing nearer than `start`, which is 0 for none, and nothing past `end`, which is
|
|
1905
|
+
* `Infinity` for none. The rows take a fade at each edge. A batch created with `ranges` gets
|
|
1906
|
+
* the same range in its own array. Throws E1108 for a range that is not two numbers with
|
|
1907
|
+
* 0 <= start < end.
|
|
1908
|
+
*/
|
|
1909
|
+
setDrawRange(start, end) {
|
|
1910
|
+
if (DEV) {
|
|
1911
|
+
checkNumber('setDrawRange', 'start', start, this);
|
|
1912
|
+
checkNumber('setDrawRange', 'end', end, this);
|
|
1913
|
+
if (!(start >= 0 && start < end))
|
|
1914
|
+
throw new EngineError('E1108', `setDrawRange() got ${start} and ${end} on ${this.describe()}, not a start at or above 0 and below the end.`);
|
|
1915
|
+
}
|
|
1916
|
+
const { core } = this.scene;
|
|
1917
|
+
const values = core.callValues();
|
|
1918
|
+
values[0] = start;
|
|
1919
|
+
values[1] = end;
|
|
1920
|
+
core.check(core.glue.setBatchDrawRange(this.id), 'setDrawRange', undefined, true);
|
|
1921
|
+
for (const part of this.parts)
|
|
1922
|
+
core.glue.setBatchDrawRange(part);
|
|
1923
|
+
}
|
|
1924
|
+
/**
|
|
1925
|
+
* Keeps every row of the batch whatever a camera's frustum says, or culls its rows again. An
|
|
1926
|
+
* add-on whose own cull or count decides what draws marks its batch unculled. A change
|
|
1927
|
+
* recomputes the rows' bounds, so make it at setup.
|
|
1928
|
+
*/
|
|
1929
|
+
setFrustumCulled(culled) {
|
|
1930
|
+
const { core } = this.scene;
|
|
1931
|
+
core.check(core.glue.setBatchUnculled(this.id, !culled), 'setFrustumCulled', undefined, true);
|
|
1932
|
+
}
|
|
1933
|
+
/**
|
|
1934
|
+
* Makes the writer that packs chunks of rows into this batch's rows, for an add-on whose rows
|
|
1935
|
+
* arrive as chunks. The writer stores each chunk once when it arrives, then packs the chosen
|
|
1936
|
+
* prefix of each into the rows in the core's memory, so a frame copies no rows through the
|
|
1937
|
+
* sketch's heap. The batch must own its rows' transforms: a pack on a part of a model, or on a
|
|
1938
|
+
* sprite or line batch, writes nothing. The code loads on first use.
|
|
1939
|
+
*
|
|
1940
|
+
* @category api/scene
|
|
1941
|
+
*/
|
|
1942
|
+
async createChunkRows() {
|
|
1943
|
+
const { ChunkRowWriter } = await loadChunkRows('createChunkRows');
|
|
1944
|
+
return new ChunkRowWriter(this.scene.core, this);
|
|
1945
|
+
}
|
|
1946
|
+
/** Draws only the first `count` rows. */
|
|
1947
|
+
setActiveCount(count) {
|
|
1948
|
+
const { core } = this.scene;
|
|
1949
|
+
core.check(core.glue.setBatchActiveCount(this.id, count), 'setActiveCount', undefined, true);
|
|
1950
|
+
this.activeRows = count;
|
|
1951
|
+
}
|
|
1952
|
+
/**
|
|
1953
|
+
* Makes every row's bounding sphere, which culling tests, hold the sphere of `radius` meters
|
|
1954
|
+
* around the row's origin, in place of the mesh's own sphere. Each sphere keeps the mesh's
|
|
1955
|
+
* center (`mesh.center`), so its radius grows by that center's distance from the origin. A
|
|
1956
|
+
* vertex shader that carries rows away from their origins, such as traffic along a lane, needs
|
|
1957
|
+
* this: the engine culls a row moved beyond the mesh's own sphere while it is still on the
|
|
1958
|
+
* screen. A later change of the mesh's radius, which a displaced material makes, replaces it.
|
|
1959
|
+
* Every row is marked for update, and the call builds the engine's draw tables again, so make it
|
|
1960
|
+
* at setup. Throws E1203 for a value that is not a finite number, and E1108 for 0 or below.
|
|
1961
|
+
*/
|
|
1962
|
+
setBoundingRadius(radius) {
|
|
1963
|
+
if (DEV) {
|
|
1964
|
+
checkNumber('setBoundingRadius', 'radius', radius, this);
|
|
1965
|
+
if (radius <= 0)
|
|
1966
|
+
throw new EngineError('E1108', `setBoundingRadius() got the radius ${radius} on ${this.describe()}, not a number above 0.`);
|
|
1967
|
+
}
|
|
1968
|
+
const { core } = this.scene;
|
|
1969
|
+
core.callValues()[0] = radius;
|
|
1970
|
+
core.check(core.glue.setBatchBounds(this.id), 'setBoundingRadius', undefined, true);
|
|
1971
|
+
}
|
|
1972
|
+
/**
|
|
1973
|
+
* Puts every row on the layers of a 32-bit mask, as `Object3D.setLayers` does for one object. A
|
|
1974
|
+
* new mask needs no rebuild.
|
|
1975
|
+
*/
|
|
1976
|
+
setLayers(mask) {
|
|
1977
|
+
if (DEV)
|
|
1978
|
+
checkLayers('setLayers', mask);
|
|
1979
|
+
const { core } = this.scene;
|
|
1980
|
+
core.check(core.glue.setBatchLayers(this.id, mask >>> 0), 'setLayers', undefined, true);
|
|
1981
|
+
for (const part of this.parts)
|
|
1982
|
+
core.glue.setBatchLayers(part, mask >>> 0);
|
|
1983
|
+
}
|
|
1984
|
+
/**
|
|
1985
|
+
* Makes every row cast the shadows of the lights that cast them, or stop, as
|
|
1986
|
+
* `Object3D.setCastShadows` does for a mesh. The default is false. A change rebuilds the
|
|
1987
|
+
* engine's tables of what it draws.
|
|
1988
|
+
*/
|
|
1989
|
+
setCastShadows(cast) {
|
|
1990
|
+
this.setShadowBit('setCastShadows', C.FLAG_CAST_SHADOWS, cast);
|
|
1991
|
+
}
|
|
1992
|
+
/**
|
|
1993
|
+
* Makes shadows fall on every row, or stop, as `Object3D.setReceiveShadows` does for a mesh. The
|
|
1994
|
+
* default is false. Unlit materials show no shadows. A change rebuilds the engine's tables of
|
|
1995
|
+
* what it draws.
|
|
1996
|
+
*/
|
|
1997
|
+
setReceiveShadows(receive) {
|
|
1998
|
+
this.setShadowBit('setReceiveShadows', C.FLAG_RECEIVE_SHADOWS, receive);
|
|
1999
|
+
}
|
|
2000
|
+
/**
|
|
2001
|
+
* Lets every row hide what lies behind it in GPU occlusion culling on WebGPU, or keeps every row
|
|
2002
|
+
* from it. Rows of an opaque mesh may hide others by default, when they look large enough on the
|
|
2003
|
+
* screen. Rows never block on WebGL2. A change rebuilds the engine's tables of what it draws.
|
|
2004
|
+
*/
|
|
2005
|
+
setOccluder(occluder) {
|
|
2006
|
+
this.setShadowBit('setOccluder', C.FLAG_NOT_OCCLUDER, !occluder);
|
|
2007
|
+
}
|
|
2008
|
+
shadowBits = 0;
|
|
2009
|
+
setShadowBit(call, bit, on) {
|
|
2010
|
+
const bits = on ? this.shadowBits | bit : this.shadowBits & ~bit;
|
|
2011
|
+
const { core } = this.scene;
|
|
2012
|
+
core.check(core.glue.setBatchShadows(this.id, bits), call, undefined, true);
|
|
2013
|
+
for (const part of this.parts)
|
|
2014
|
+
core.glue.setBatchShadows(part, bits);
|
|
2015
|
+
this.shadowBits = bits;
|
|
2016
|
+
}
|
|
2017
|
+
/**
|
|
2018
|
+
* Calls `handler` for each pointer event of `type` on a row of the batch, as `Object3D.on` does.
|
|
2019
|
+
* The event's `instance` names the row.
|
|
2020
|
+
*/
|
|
2021
|
+
on(type, handler) {
|
|
2022
|
+
this.listen(this, type, handler);
|
|
2023
|
+
}
|
|
2024
|
+
/** Removes a handler that `on` added for events of `type`. */
|
|
2025
|
+
off(type, handler) {
|
|
2026
|
+
this.unlisten(this, type, handler);
|
|
2027
|
+
}
|
|
2028
|
+
/**
|
|
2029
|
+
* @internal Adds `handler` for events of `type` on `target`: this batch, or the sprite, point or
|
|
2030
|
+
* line batch whose rows it holds.
|
|
2031
|
+
*/
|
|
2032
|
+
listen(target, type, handler) {
|
|
2033
|
+
if (DEV)
|
|
2034
|
+
checkLive('on', { destroyedFrame: this.destroyedFrame, describe: () => 'a batch' });
|
|
2035
|
+
this.scene.pointerEvents.add(target, type, handler);
|
|
2036
|
+
}
|
|
2037
|
+
/** @internal Removes a handler that `listen` added. */
|
|
2038
|
+
unlisten(target, type, handler) {
|
|
2039
|
+
this.scene.pointerEvents.remove(target, type, handler);
|
|
2040
|
+
}
|
|
2041
|
+
/** @internal A batch has no parent for its pointer events to go on to. */
|
|
2042
|
+
pointerParent() {
|
|
2043
|
+
return null;
|
|
2044
|
+
}
|
|
2045
|
+
/** @internal Places the origin that the rows of the batch and of its parts are relative to. */
|
|
2046
|
+
setOrigin([x, y, z], call) {
|
|
2047
|
+
const { core } = this.scene;
|
|
2048
|
+
const values = core.callValues();
|
|
2049
|
+
values[0] = x;
|
|
2050
|
+
values[1] = y;
|
|
2051
|
+
values[2] = z;
|
|
2052
|
+
core.check(core.glue.setBatchOrigin(this.id), call, undefined, true);
|
|
2053
|
+
for (const part of this.parts)
|
|
2054
|
+
core.glue.setBatchOrigin(part);
|
|
2055
|
+
}
|
|
2056
|
+
/** Marks rows of a static batch to update and upload. */
|
|
2057
|
+
markDirty(start = 0, count = this.count - start) {
|
|
2058
|
+
const { core } = this.scene;
|
|
2059
|
+
core.check(core.glue.markBatchDirty(this.id, start, count), 'markDirty', undefined, true);
|
|
2060
|
+
}
|
|
2061
|
+
/**
|
|
2062
|
+
* Removes the batch and frees its rows. Its typed arrays are not valid after this: another
|
|
2063
|
+
* batch can take their memory.
|
|
2064
|
+
*/
|
|
2065
|
+
destroy() {
|
|
2066
|
+
const { core } = this.scene;
|
|
2067
|
+
core.checkGrowth(core.glue.destroyBatch(this.id, this.scene.frame), 'destroy', undefined, true);
|
|
2068
|
+
for (const part of this.parts)
|
|
2069
|
+
core.glue.destroyBatch(part, this.scene.frame);
|
|
2070
|
+
if (DEV) {
|
|
2071
|
+
this.scene.countBatchRows(-this.count * (1 + this.parts.length));
|
|
2072
|
+
this.scene.unmarkedRows?.forget(this);
|
|
2073
|
+
}
|
|
2074
|
+
this.scene.forgetListeners(this);
|
|
2075
|
+
if (this.face)
|
|
2076
|
+
this.scene.forgetListeners(this.face);
|
|
2077
|
+
this.destroyedFrame = this.scene.frame;
|
|
2078
|
+
// The next read of the arrays asks the core for them again, and the core refuses a
|
|
2079
|
+
// destroyed batch.
|
|
2080
|
+
this.generation = -1;
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
/** @internal An instance batch with neither colors nor values. */
|
|
2084
|
+
export const NO_ROW_VALUES = { colors: false, values: false, ranges: false };
|
|
2085
|
+
/** The row arrays that an instance batch's options ask for. */
|
|
2086
|
+
function rowValueArrays(options) {
|
|
2087
|
+
const colors = options.colors ?? false;
|
|
2088
|
+
const values = options.values ?? false;
|
|
2089
|
+
const ranges = options.ranges ?? false;
|
|
2090
|
+
return colors || values || ranges ? { colors, values, ranges } : NO_ROW_VALUES;
|
|
2091
|
+
}
|
|
2092
|
+
const NO_USES = { meshes: [], materials: [] };
|
|
2093
|
+
/** A view of no floats, which objects keep in place of views that they dropped. */
|
|
2094
|
+
const NO_FLOATS = new Float32Array(0);
|
|
2095
|
+
/** The row arrays of a batch that dropped its views, until its next read makes them again. */
|
|
2096
|
+
const NO_ROWS = {
|
|
2097
|
+
positions: NO_FLOATS,
|
|
2098
|
+
rotations: NO_FLOATS,
|
|
2099
|
+
scales: NO_FLOATS,
|
|
2100
|
+
colors: undefined,
|
|
2101
|
+
values: undefined,
|
|
2102
|
+
ranges: undefined,
|
|
2103
|
+
};
|
|
2104
|
+
/** The row fields of an instance batch, which the check of unmarked row writes hashes. */
|
|
2105
|
+
const MESH_ROW_FIELDS = [
|
|
2106
|
+
[C.BATCH_FIELD_POSITIONS, 3],
|
|
2107
|
+
[C.BATCH_FIELD_ROTATIONS, 4],
|
|
2108
|
+
[C.BATCH_FIELD_SCALES, 3],
|
|
2109
|
+
];
|
|
2110
|
+
/** The row fields of an instance batch with the row arrays of `own`. */
|
|
2111
|
+
const meshRowFields = (own) => [
|
|
2112
|
+
...MESH_ROW_FIELDS,
|
|
2113
|
+
...(own.colors ? [[C.BATCH_FIELD_COLORS, 4]] : []),
|
|
2114
|
+
...(own.values ? [[C.BATCH_FIELD_VALUES, 4]] : []),
|
|
2115
|
+
];
|
|
2116
|
+
/** The row fields of a sprite or point batch. */
|
|
2117
|
+
const SPRITE_ROW_FIELDS = [
|
|
2118
|
+
[C.BATCH_FIELD_POSITIONS, 3],
|
|
2119
|
+
[C.BATCH_FIELD_SIZES, 2],
|
|
2120
|
+
[C.BATCH_FIELD_ROTATIONS, 1],
|
|
2121
|
+
[C.BATCH_FIELD_COLORS, 4],
|
|
2122
|
+
[C.BATCH_FIELD_FRAMES, 1],
|
|
2123
|
+
];
|
|
2124
|
+
/** The class of each kind of light that a model's node can create, by the core's light kind. */
|
|
2125
|
+
const LIGHT_CLASSES = {
|
|
2126
|
+
[C.LIGHT_KIND_DIRECTIONAL]: DirectionalLight,
|
|
2127
|
+
[C.LIGHT_KIND_POINT]: PointLight,
|
|
2128
|
+
[C.LIGHT_KIND_SPOT]: SpotLight,
|
|
2129
|
+
[C.LIGHT_KIND_RECT]: RectAreaLight,
|
|
2130
|
+
[C.LIGHT_KIND_TUBE]: TubeLight,
|
|
2131
|
+
};
|
|
2132
|
+
/**
|
|
2133
|
+
* The modules that the scene imports on first use, each shared by every call, so calls that wait for
|
|
2134
|
+
* one together go on in the order they were made.
|
|
2135
|
+
*/
|
|
2136
|
+
const spriteCode = importOnce(() => import('./sprites.js'));
|
|
2137
|
+
const chunkRowCode = importOnce(() => import('./chunk-rows.js'));
|
|
2138
|
+
const particleCode = importOnce(() => import('./particles.js'));
|
|
2139
|
+
const lineCode = importOnce(() => import('./lines.js'));
|
|
2140
|
+
const featureInstanceCode = importOnce(() => import('./feature-instances.js'));
|
|
2141
|
+
const featureDrawCode = importOnce(() => import('./feature-draws.js'));
|
|
2142
|
+
/** Imports the sprite code, which a page downloads with its first sprite batch, or throws E1406. */
|
|
2143
|
+
async function loadSprites(call) {
|
|
2144
|
+
try {
|
|
2145
|
+
return await spriteCode();
|
|
2146
|
+
}
|
|
2147
|
+
catch (error) {
|
|
2148
|
+
throw new EngineError('E1406', `the sprite code did not download for ${call}(): ${reasonOf(error)}.`);
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
/** Imports the chunked-row code, which a page downloads with its first chunked batch, or throws E1406. */
|
|
2152
|
+
async function loadChunkRows(call) {
|
|
2153
|
+
try {
|
|
2154
|
+
return await chunkRowCode();
|
|
2155
|
+
}
|
|
2156
|
+
catch (error) {
|
|
2157
|
+
throw new EngineError('E1406', `the chunked row code did not download for ${call}(): ${reasonOf(error)}.`);
|
|
2158
|
+
}
|
|
2159
|
+
}
|
|
2160
|
+
/** Imports the particle code, which a page downloads with its first particle buffer, or throws E1406. */
|
|
2161
|
+
async function loadParticles(call) {
|
|
2162
|
+
try {
|
|
2163
|
+
return await particleCode();
|
|
2164
|
+
}
|
|
2165
|
+
catch (error) {
|
|
2166
|
+
throw new EngineError('E1406', `the particle code did not download for ${call}(): ${reasonOf(error)}.`);
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
/** Imports the line code, which a page downloads with its first line batch, or throws E1406. */
|
|
2170
|
+
async function loadLines(call) {
|
|
2171
|
+
try {
|
|
2172
|
+
return await lineCode();
|
|
2173
|
+
}
|
|
2174
|
+
catch (error) {
|
|
2175
|
+
throw new EngineError('E1406', `the line code did not download for ${call}(): ${reasonOf(error)}.`);
|
|
2176
|
+
}
|
|
2177
|
+
}
|
|
2178
|
+
/** Imports the instance adapter, which a page downloads with its first instance draw, or throws E1406. */
|
|
2179
|
+
async function loadFeatureInstances(call) {
|
|
2180
|
+
try {
|
|
2181
|
+
return await featureInstanceCode();
|
|
2182
|
+
}
|
|
2183
|
+
catch (error) {
|
|
2184
|
+
throw new EngineError('E1406', `the feature instance code did not download for ${call}(): ${reasonOf(error)}.`);
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
/** Imports the draw adapter, which a page downloads with its first feature draw, or throws E1406. */
|
|
2188
|
+
async function loadFeatureDraws(call) {
|
|
2189
|
+
try {
|
|
2190
|
+
return await featureDrawCode();
|
|
2191
|
+
}
|
|
2192
|
+
catch (error) {
|
|
2193
|
+
throw new EngineError('E1406', `the feature draw code did not download for ${call}(): ${reasonOf(error)}.`);
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
/** The segments that each line mode makes of a number of points. */
|
|
2197
|
+
const LINE_SEGMENTS = {
|
|
2198
|
+
segments: (points) => Math.floor(points / 2),
|
|
2199
|
+
strip: (points) => Math.max(points - 1, 0),
|
|
2200
|
+
loop: (points) => (points >= 2 ? points : 0),
|
|
2201
|
+
};
|
|
2202
|
+
/**
|
|
2203
|
+
* The number of points of `scene.createLines`, after checking that they make a line: whole points,
|
|
2204
|
+
* at least one segment, and one color for each point. Throws E1217 for an unknown mode and E1206
|
|
2205
|
+
* for points or colors that make no line, and in development builds, for numbers that are not
|
|
2206
|
+
* finite.
|
|
2207
|
+
*/
|
|
2208
|
+
function linePoints(call, mode, positions, colors) {
|
|
2209
|
+
if (!Object.hasOwn(LINE_SEGMENTS, mode))
|
|
2210
|
+
throw new EngineError('E1217', `${call}() got the mode ${JSON.stringify(mode)}; it takes 'segments', 'strip' or 'loop'.`);
|
|
2211
|
+
const points = positions.length / 3;
|
|
2212
|
+
const bad = (problem) => new EngineError('E1206', `${call}() got ${problem}.`);
|
|
2213
|
+
if (!Number.isInteger(points) || LINE_SEGMENTS[mode](points) < 1)
|
|
2214
|
+
throw bad(`${positions.length} numbers in positions; a ${mode} line takes 3 numbers per point, and at least 2 points`);
|
|
2215
|
+
if (mode === 'segments' && points % 2 !== 0)
|
|
2216
|
+
throw bad(`${points} points for segments, which join points in pairs`);
|
|
2217
|
+
if (colors && colors.length !== positions.length)
|
|
2218
|
+
throw bad(`${colors.length} numbers in colors for ${points} points, not ${positions.length}`);
|
|
2219
|
+
checkFinitePoints(call, positions, colors);
|
|
2220
|
+
return points;
|
|
2221
|
+
}
|
|
2222
|
+
/**
|
|
2223
|
+
* The points of `scene.createPoints`'s arrays: 3 numbers per point in `positions`, and 3 or 4 in
|
|
2224
|
+
* `colors`. Throws E1206 for arrays that make no points.
|
|
2225
|
+
*/
|
|
2226
|
+
function pointCount(call, positions, colors) {
|
|
2227
|
+
const points = positions.length / 3;
|
|
2228
|
+
if (!Number.isInteger(points) || points < 1)
|
|
2229
|
+
throw new EngineError('E1206', `${call}() got ${positions.length} numbers in positions; points take 3 numbers each, and at least 1 point.`);
|
|
2230
|
+
if (colors && colors.length !== points * 3 && colors.length !== points * 4)
|
|
2231
|
+
throw new EngineError('E1206', `${call}() got ${colors.length} numbers in colors for ${points} points, not ${points * 3} or ${points * 4}.`);
|
|
2232
|
+
checkFinitePoints(call, positions, colors);
|
|
2233
|
+
return points;
|
|
2234
|
+
}
|
|
2235
|
+
/** Development builds: throws E1206 for a number of `positions` or `colors` that is not finite. */
|
|
2236
|
+
function checkFinitePoints(call, positions, colors) {
|
|
2237
|
+
if (!DEV)
|
|
2238
|
+
return;
|
|
2239
|
+
for (const [name, values] of [
|
|
2240
|
+
['positions', positions],
|
|
2241
|
+
['colors', colors ?? []],
|
|
2242
|
+
])
|
|
2243
|
+
for (let k = 0; k < values.length; k++)
|
|
2244
|
+
if (!Number.isFinite(values[k]))
|
|
2245
|
+
throw new EngineError('E1206', `${call}() got ${values[k]} at index ${k} of ${name}.`);
|
|
2246
|
+
}
|
|
2247
|
+
/** Development builds: throws E1203 for a `name` value that is not finite, and E1108 for one not above 0. */
|
|
2248
|
+
function checkPositive(call, name, value) {
|
|
2249
|
+
if (!DEV)
|
|
2250
|
+
return;
|
|
2251
|
+
if (!Number.isFinite(value))
|
|
2252
|
+
throw new EngineError('E1203', `${call}() got ${value} for ${name}.`);
|
|
2253
|
+
if (!(value > 0))
|
|
2254
|
+
throw new EngineError('E1108', `${call}() got the ${name} ${value}; it takes a number above 0.`);
|
|
2255
|
+
}
|
|
2256
|
+
/** The checks of line batches' calls, which the line code takes from the scene. */
|
|
2257
|
+
const LINE_CHECKS = {
|
|
2258
|
+
width(width, call) {
|
|
2259
|
+
checkPositive(call, 'width', width);
|
|
2260
|
+
},
|
|
2261
|
+
values(values, call) {
|
|
2262
|
+
if (!DEV)
|
|
2263
|
+
return;
|
|
2264
|
+
for (const key of ['dashSize', 'gapSize', 'dashScale', 'dashOffset']) {
|
|
2265
|
+
const value = values[key];
|
|
2266
|
+
if (value === undefined)
|
|
2267
|
+
continue;
|
|
2268
|
+
if (!Number.isFinite(value))
|
|
2269
|
+
throw new EngineError('E1203', `${call}() got ${value} for ${key}.`);
|
|
2270
|
+
if (key !== 'dashOffset' && value < 0)
|
|
2271
|
+
throw new EngineError('E1108', `${call}() got the ${key} ${value}; it takes 0 or more.`);
|
|
2272
|
+
}
|
|
2273
|
+
},
|
|
2274
|
+
};
|
|
2275
|
+
/** The checks of a point batch's later calls. */
|
|
2276
|
+
const POINT_CHECKS = {
|
|
2277
|
+
size(size, call) {
|
|
2278
|
+
checkPositive(call, 'size', size);
|
|
2279
|
+
},
|
|
2280
|
+
};
|
|
2281
|
+
/**
|
|
2282
|
+
* The transform of a model's copy: the position, rotation and scale of `options`, with the position
|
|
2283
|
+
* at full precision.
|
|
2284
|
+
*/
|
|
2285
|
+
function rootTransform(options) {
|
|
2286
|
+
const transform = new Float64Array([0, 0, 0, 0, 0, 0, 1, 1, 1, 1]);
|
|
2287
|
+
if (options.position)
|
|
2288
|
+
transform.set(options.position, 0);
|
|
2289
|
+
if (options.rotation)
|
|
2290
|
+
transform.set(options.rotation, 3);
|
|
2291
|
+
if (options.scale)
|
|
2292
|
+
transform.set(options.scale, 7);
|
|
2293
|
+
return transform;
|
|
2294
|
+
}
|
|
2295
|
+
/**
|
|
2296
|
+
* @internal The scene API's checks and errors, which code that loads on first use, such as the
|
|
2297
|
+
* animator, takes from the scene. That code imports no engine module but constants, so a bundle
|
|
2298
|
+
* never moves these modules into a file of their own, which every page would download at its start.
|
|
2299
|
+
*/
|
|
2300
|
+
export const SCENE_CHECKS = {
|
|
2301
|
+
// Code that takes these calls them in development builds only, so release builds hold none.
|
|
2302
|
+
checkLive: DEV ? checkLive : () => { },
|
|
2303
|
+
checkNumber: DEV ? checkNumber : () => { },
|
|
2304
|
+
error: (code, message) => new EngineError(code, message),
|
|
2305
|
+
};
|
|
2306
|
+
/** The color that a property write fills for a material or a light, shared by every write. */
|
|
2307
|
+
const PROPERTY_COLOR = [0, 0, 0];
|
|
2308
|
+
/** The values of a hold script's step, shared by every step: a rotation takes the most, at four. */
|
|
2309
|
+
const SCRIPT_VALUES = new Float32Array(4);
|
|
2310
|
+
/** The value that a property had before a hold script wrote it, which a full-weight write ignores. */
|
|
2311
|
+
const SCRIPT_BASE = new Float32Array(4);
|
|
2312
|
+
/** The smallest positive value that a light's range, a camera's planes and its view take. */
|
|
2313
|
+
const SMALLEST = 1e-6;
|
|
2314
|
+
/** `value` kept between `low` and `high`: a key's curve can overshoot the values that a setter takes. */
|
|
2315
|
+
function between(value, low, high = Infinity) {
|
|
2316
|
+
return value < low ? low : value > high ? high : value;
|
|
2317
|
+
}
|
|
2318
|
+
/**
|
|
2319
|
+
* Writes a value that a property track sampled into its target, mixed by `weight` with the value
|
|
2320
|
+
* that the target held before any clip moved it, which is the binding's base. It keeps a value
|
|
2321
|
+
* within what the target takes, because a cubic key can overshoot, and writes nothing for a value
|
|
2322
|
+
* that is not a number or for a target that was destroyed. It allocates nothing, so a track writes
|
|
2323
|
+
* a value in every frame.
|
|
2324
|
+
*/
|
|
2325
|
+
function writeProperty(target, binding, values, at, weight) {
|
|
2326
|
+
const { what, base } = binding;
|
|
2327
|
+
const rest = 1 - weight;
|
|
2328
|
+
/** The number of component `c`, mixed with the base, or the base for one that is no number. */
|
|
2329
|
+
const mixed = (c) => {
|
|
2330
|
+
const value = values[at + c] * weight + base[c] * rest;
|
|
2331
|
+
return Number.isFinite(value) ? value : base[c];
|
|
2332
|
+
};
|
|
2333
|
+
/** The color of components 0 to 2, each between 0 and 1. */
|
|
2334
|
+
const color = () => {
|
|
2335
|
+
PROPERTY_COLOR[0] = between(mixed(0), 0, 1);
|
|
2336
|
+
PROPERTY_COLOR[1] = between(mixed(1), 0, 1);
|
|
2337
|
+
PROPERTY_COLOR[2] = between(mixed(2), 0, 1);
|
|
2338
|
+
return PROPERTY_COLOR;
|
|
2339
|
+
};
|
|
2340
|
+
if (what === PROPERTY_MATERIAL) {
|
|
2341
|
+
const material = target;
|
|
2342
|
+
if (!material.live)
|
|
2343
|
+
return;
|
|
2344
|
+
if (binding.components === 2) {
|
|
2345
|
+
// A pair is where a map sits on the texture coordinates: one map's, or every map's.
|
|
2346
|
+
if (binding.name === 'uvOffset' || binding.name === 'uvScale')
|
|
2347
|
+
material.writeUvPair(binding.name, mixed(0), mixed(1), binding.slot);
|
|
2348
|
+
return;
|
|
2349
|
+
}
|
|
2350
|
+
if (binding.components === 1)
|
|
2351
|
+
material.writeUniform(binding.name, mixed(0));
|
|
2352
|
+
else
|
|
2353
|
+
material.writeUniform(binding.name, color());
|
|
2354
|
+
return;
|
|
2355
|
+
}
|
|
2356
|
+
const object = target;
|
|
2357
|
+
if (object.destroyedFrame !== -1)
|
|
2358
|
+
return;
|
|
2359
|
+
switch (what) {
|
|
2360
|
+
case PROPERTY_LIGHT_INTENSITY:
|
|
2361
|
+
target.setIntensity(between(mixed(0), 0));
|
|
2362
|
+
return;
|
|
2363
|
+
case PROPERTY_LIGHT_COLOR:
|
|
2364
|
+
target.setColor(color());
|
|
2365
|
+
return;
|
|
2366
|
+
case PROPERTY_LIGHT_RANGE:
|
|
2367
|
+
target.setRange(between(mixed(0), SMALLEST));
|
|
2368
|
+
return;
|
|
2369
|
+
case PROPERTY_LIGHT_DECAY:
|
|
2370
|
+
target.setDecay(between(mixed(0), 0));
|
|
2371
|
+
return;
|
|
2372
|
+
case PROPERTY_LIGHT_ANGLE:
|
|
2373
|
+
target.setAngle(between(mixed(0), SMALLEST, Math.PI / 2));
|
|
2374
|
+
return;
|
|
2375
|
+
case PROPERTY_LIGHT_PENUMBRA:
|
|
2376
|
+
target.setPenumbra(between(mixed(0), 0, 1));
|
|
2377
|
+
return;
|
|
2378
|
+
case PROPERTY_CAMERA_FOV:
|
|
2379
|
+
target.setFov(between(mixed(0), 1e-3, 179.999));
|
|
2380
|
+
return;
|
|
2381
|
+
case PROPERTY_CAMERA_NEAR: {
|
|
2382
|
+
// The near plane stays below the far one, and above 0.
|
|
2383
|
+
const camera = target;
|
|
2384
|
+
camera.setNearFar(between(mixed(0), SMALLEST, camera.far), camera.far);
|
|
2385
|
+
return;
|
|
2386
|
+
}
|
|
2387
|
+
case PROPERTY_CAMERA_FAR: {
|
|
2388
|
+
const camera = target;
|
|
2389
|
+
camera.setNearFar(camera.near, between(mixed(0), camera.near * 1.001));
|
|
2390
|
+
return;
|
|
2391
|
+
}
|
|
2392
|
+
case PROPERTY_CAMERA_HEIGHT:
|
|
2393
|
+
target.setOrthoHeight(between(mixed(0), SMALLEST));
|
|
2394
|
+
return;
|
|
2395
|
+
case PROPERTY_POSITION:
|
|
2396
|
+
object.setPosition(mixed(0), mixed(1), mixed(2));
|
|
2397
|
+
return;
|
|
2398
|
+
case PROPERTY_ROTATION: {
|
|
2399
|
+
const x = mixed(0);
|
|
2400
|
+
const y = mixed(1);
|
|
2401
|
+
const z = mixed(2);
|
|
2402
|
+
const w = mixed(3);
|
|
2403
|
+
const length = Math.hypot(x, y, z, w);
|
|
2404
|
+
if (length === 0)
|
|
2405
|
+
object.setRotation(0, 0, 0, 1);
|
|
2406
|
+
else
|
|
2407
|
+
object.setRotation(x / length, y / length, z / length, w / length);
|
|
2408
|
+
return;
|
|
2409
|
+
}
|
|
2410
|
+
case PROPERTY_SCALE:
|
|
2411
|
+
object.setScale(mixed(0), mixed(1), mixed(2));
|
|
2412
|
+
return;
|
|
2413
|
+
case PROPERTY_VISIBLE:
|
|
2414
|
+
object.setVisible(mixed(0) >= 0.5);
|
|
2415
|
+
return;
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
/** The properties of a light, by the name that a path gives them. */
|
|
2419
|
+
const LIGHT_PATHS = new Map([
|
|
2420
|
+
['intensity', { what: PROPERTY_LIGHT_INTENSITY, name: '', components: 1 }],
|
|
2421
|
+
['color', { what: PROPERTY_LIGHT_COLOR, name: '', components: 3 }],
|
|
2422
|
+
['range', { what: PROPERTY_LIGHT_RANGE, name: '', components: 1 }],
|
|
2423
|
+
['decay', { what: PROPERTY_LIGHT_DECAY, name: '', components: 1 }],
|
|
2424
|
+
['angle', { what: PROPERTY_LIGHT_ANGLE, name: '', components: 1 }],
|
|
2425
|
+
['penumbra', { what: PROPERTY_LIGHT_PENUMBRA, name: '', components: 1 }],
|
|
2426
|
+
]);
|
|
2427
|
+
/** The properties of a camera, by the name that a path gives them. */
|
|
2428
|
+
const CAMERA_PATHS = new Map([
|
|
2429
|
+
['fov', { what: PROPERTY_CAMERA_FOV, name: '', components: 1 }],
|
|
2430
|
+
['near', { what: PROPERTY_CAMERA_NEAR, name: '', components: 1 }],
|
|
2431
|
+
['far', { what: PROPERTY_CAMERA_FAR, name: '', components: 1 }],
|
|
2432
|
+
['height', { what: PROPERTY_CAMERA_HEIGHT, name: '', components: 1 }],
|
|
2433
|
+
]);
|
|
2434
|
+
/** The properties of an object, by the name that a path gives them. */
|
|
2435
|
+
const OBJECT_PATHS = new Map([
|
|
2436
|
+
['position', { what: PROPERTY_POSITION, name: '', components: 3 }],
|
|
2437
|
+
['rotation', { what: PROPERTY_ROTATION, name: '', components: 4 }],
|
|
2438
|
+
['scale', { what: PROPERTY_SCALE, name: '', components: 3 }],
|
|
2439
|
+
['visible', { what: PROPERTY_VISIBLE, name: '', components: 1 }],
|
|
2440
|
+
]);
|
|
2441
|
+
/** A list of names for a message, such as "a, b and c". */
|
|
2442
|
+
function listNames(names) {
|
|
2443
|
+
const all = [...names];
|
|
2444
|
+
return all.length < 2 ? (all[0] ?? 'none') : `${all.slice(0, -1).join(', ')} and ${all.at(-1)}`;
|
|
2445
|
+
}
|
|
2446
|
+
/** The properties of a target that has none of its own, such as a plain object. */
|
|
2447
|
+
const NO_OWN_PATHS = new Map();
|
|
2448
|
+
/** The light properties that a directional light lacks, and the ones that only a spot light has. */
|
|
2449
|
+
const LIGHT_RANGE_PATHS = new Set([
|
|
2450
|
+
PROPERTY_LIGHT_RANGE,
|
|
2451
|
+
PROPERTY_LIGHT_DECAY,
|
|
2452
|
+
]);
|
|
2453
|
+
const SPOT_PATHS = new Set([PROPERTY_LIGHT_ANGLE, PROPERTY_LIGHT_PENUMBRA]);
|
|
2454
|
+
/**
|
|
2455
|
+
* The property that `path` names on `target`: `'light.intensity'` or `'intensity'` for a light,
|
|
2456
|
+
* `'camera.fov'` or `'fov'` for a camera, `'material.opacity'` or `'opacity'` for a material, and
|
|
2457
|
+
* `'position'`, `'rotation'`, `'scale'` or `'visible'` for any object. Throws E1218 for a path that
|
|
2458
|
+
* the target does not take. `call` names the call in the message, such as a hold script's step.
|
|
2459
|
+
*/
|
|
2460
|
+
function propertyPath(target, path, error, call = 'animateProperty') {
|
|
2461
|
+
const dot = path.indexOf('.');
|
|
2462
|
+
const head = dot > 0 ? path.slice(0, dot) : '';
|
|
2463
|
+
const name = dot > 0 ? path.slice(dot + 1) : path;
|
|
2464
|
+
if (target instanceof Material) {
|
|
2465
|
+
const components = materialValueComponents(name);
|
|
2466
|
+
if (components > 0 && (head === 'material' || head === ''))
|
|
2467
|
+
return { what: PROPERTY_MATERIAL, name, components };
|
|
2468
|
+
throw error(`${call}() got "${path}" on a material, which it does not take. A material animates the values that setUniform takes, such as "opacity" and "color", with or without the "material." prefix.`);
|
|
2469
|
+
}
|
|
2470
|
+
const kind = target instanceof Light ? 'light' : target instanceof Camera ? 'camera' : '';
|
|
2471
|
+
const own = kind === 'light' ? LIGHT_PATHS : kind === 'camera' ? CAMERA_PATHS : NO_OWN_PATHS;
|
|
2472
|
+
const found = head === '' || head === 'object'
|
|
2473
|
+
? (OBJECT_PATHS.get(name) ?? (head === '' ? own.get(name) : undefined))
|
|
2474
|
+
: head === kind
|
|
2475
|
+
? own.get(name)
|
|
2476
|
+
: undefined;
|
|
2477
|
+
// A light or a camera takes only the values of its own kind: a directional light has no range,
|
|
2478
|
+
// and a perspective camera has no view height.
|
|
2479
|
+
const otherKind = target instanceof OrthographicCamera
|
|
2480
|
+
? found?.what === PROPERTY_CAMERA_FOV
|
|
2481
|
+
: target instanceof PerspectiveCamera
|
|
2482
|
+
? found?.what === PROPERTY_CAMERA_HEIGHT
|
|
2483
|
+
: target instanceof DirectionalLight
|
|
2484
|
+
? LIGHT_RANGE_PATHS.has(found?.what ?? -1)
|
|
2485
|
+
: target instanceof Light && !(target instanceof SpotLight)
|
|
2486
|
+
? SPOT_PATHS.has(found?.what ?? -1)
|
|
2487
|
+
: false;
|
|
2488
|
+
if (found !== undefined && !otherKind)
|
|
2489
|
+
return found;
|
|
2490
|
+
const where = kind === '' ? target.describe() : `${target.describe()}, a ${kind}`;
|
|
2491
|
+
if (otherKind)
|
|
2492
|
+
throw error(`${call}() got "${path}" on ${where}, which this kind of ${kind} does not have.`);
|
|
2493
|
+
const accepted = [
|
|
2494
|
+
...(kind === '' ? [] : [...own.keys()].map((key) => `${kind}.${key}`)),
|
|
2495
|
+
...[...OBJECT_PATHS.keys()].map((key) => (kind === '' ? key : `object.${key}`)),
|
|
2496
|
+
];
|
|
2497
|
+
throw error(`${call}() got "${path}" on ${where}, which it does not take. It animates ${listNames(accepted)}.`);
|
|
2498
|
+
}
|
|
2499
|
+
/**
|
|
2500
|
+
* The scene: every object, the active camera, the lights and the background.
|
|
2501
|
+
*
|
|
2502
|
+
* @category api/scene
|
|
2503
|
+
*/
|
|
2504
|
+
export class Scene {
|
|
2505
|
+
core;
|
|
2506
|
+
time;
|
|
2507
|
+
webgl2;
|
|
2508
|
+
warmUpScene;
|
|
2509
|
+
cameras;
|
|
2510
|
+
makers;
|
|
2511
|
+
pointerInput;
|
|
2512
|
+
/** @internal The scene API's checks and errors, for code that loads on first use. */
|
|
2513
|
+
checks = SCENE_CHECKS;
|
|
2514
|
+
viewsGeneration = -1;
|
|
2515
|
+
currentViews;
|
|
2516
|
+
activeCamera;
|
|
2517
|
+
/** The camera that fits the shadow cascades in place of the active camera, for debugging. */
|
|
2518
|
+
shadowCamera;
|
|
2519
|
+
/** @internal The area lights' tables, which load with the first rectangle or tube light. */
|
|
2520
|
+
areaTables;
|
|
2521
|
+
/** @internal The load of the area lights' tables' code and their download, once started. */
|
|
2522
|
+
areaTablesLoad;
|
|
2523
|
+
/** @internal The area lights' tables' failure before the code arrived, once: the frame loop reports it. */
|
|
2524
|
+
areaTablesFailure;
|
|
2525
|
+
/** @internal The tasks that write the pictures that `RectAreaLight.setImage` and `SpotLight.setMap` set. */
|
|
2526
|
+
imageTasks = new Set();
|
|
2527
|
+
/** @internal The picture that failed to write, once: the frame loop reports it. */
|
|
2528
|
+
imageFailure;
|
|
2529
|
+
/** @internal The draws that answer each frame whether their feature is ready. */
|
|
2530
|
+
readiness = [];
|
|
2531
|
+
/** @internal Starts the area lights' tables' load, once, which loads their code on first use. */
|
|
2532
|
+
loadAreaTables() {
|
|
2533
|
+
this.areaTablesLoad ??= import('./area-light-tables.js').then(({ AreaLightTables }) => {
|
|
2534
|
+
const tables = new AreaLightTables(this.core);
|
|
2535
|
+
this.areaTables = tables;
|
|
2536
|
+
tables.load();
|
|
2537
|
+
return tables;
|
|
2538
|
+
});
|
|
2539
|
+
}
|
|
2540
|
+
/** @internal Settles when the area lights' tables have loaded, or at once when none started. */
|
|
2541
|
+
async areaTablesSettled() {
|
|
2542
|
+
const load = this.areaTablesLoad;
|
|
2543
|
+
if (!load)
|
|
2544
|
+
return;
|
|
2545
|
+
const tables = await load.catch((error) => {
|
|
2546
|
+
this.areaTablesFailure =
|
|
2547
|
+
error instanceof EngineError ? error : new EngineError('E1431', String(error));
|
|
2548
|
+
return undefined;
|
|
2549
|
+
});
|
|
2550
|
+
await tables?.settled();
|
|
2551
|
+
}
|
|
2552
|
+
/** @internal The area lights' tables' failure, once: the frame loop reports it. */
|
|
2553
|
+
takeAreaTablesFailure() {
|
|
2554
|
+
const failure = this.areaTablesFailure ?? this.areaTables?.takeFailure();
|
|
2555
|
+
this.areaTablesFailure = undefined;
|
|
2556
|
+
if (failure === undefined)
|
|
2557
|
+
return undefined;
|
|
2558
|
+
if (failure instanceof EngineError)
|
|
2559
|
+
return failure;
|
|
2560
|
+
return new EngineError('E1431', `the area lights' tables did not load from ${failure.url}: ${failure.error instanceof Error ? failure.error.message : String(failure.error)}`);
|
|
2561
|
+
}
|
|
2562
|
+
/** @internal Settles when every picture that `setImage` or `setMap` set has been written to engine memory. */
|
|
2563
|
+
async imagesSettled() {
|
|
2564
|
+
while (this.imageTasks.size > 0)
|
|
2565
|
+
await Promise.all(this.imageTasks);
|
|
2566
|
+
}
|
|
2567
|
+
/** @internal Queues a picture's write, which loads its resampler on first use. */
|
|
2568
|
+
queueImage(task) {
|
|
2569
|
+
const settled = task.catch((error) => {
|
|
2570
|
+
this.imageFailure = error;
|
|
2571
|
+
});
|
|
2572
|
+
this.imageTasks.add(settled);
|
|
2573
|
+
void settled.finally(() => this.imageTasks.delete(settled));
|
|
2574
|
+
}
|
|
2575
|
+
/** @internal The picture that failed to write, once: the frame loop reports it. */
|
|
2576
|
+
takeImageFailure() {
|
|
2577
|
+
const failure = this.imageFailure;
|
|
2578
|
+
this.imageFailure = undefined;
|
|
2579
|
+
return failure;
|
|
2580
|
+
}
|
|
2581
|
+
/**
|
|
2582
|
+
* The camera of each scene pass's view, by the view's place, with the pass's own layers, or
|
|
2583
|
+
* undefined to follow the camera's.
|
|
2584
|
+
*/
|
|
2585
|
+
passCameras = [];
|
|
2586
|
+
/** The views of the canvas that `createView` made and that still live, for `viewAt`. */
|
|
2587
|
+
canvasViews = [];
|
|
2588
|
+
/** @internal Scratch arrays, so rotations and reads allocate nothing. */
|
|
2589
|
+
scratch = new Float32Array(4);
|
|
2590
|
+
/** @internal */
|
|
2591
|
+
eye = new Float64Array(3);
|
|
2592
|
+
/** @internal */
|
|
2593
|
+
target = new Float64Array(3);
|
|
2594
|
+
/** A world matrix, whose translation keeps 64-bit precision far from the origin. */
|
|
2595
|
+
matrix = new Float64Array(C.CORE_MATRIX_FLOATS);
|
|
2596
|
+
/** The same world matrix as 16 numbers, column by column. */
|
|
2597
|
+
columns = new Float64Array(16);
|
|
2598
|
+
/** A 32-bit float and its bits, for commands that carry a float. */
|
|
2599
|
+
float = new Float32Array(1);
|
|
2600
|
+
floatWord = new Uint32Array(this.float.buffer);
|
|
2601
|
+
/**
|
|
2602
|
+
* The live objects with each name: the object itself, or the objects with a name that several
|
|
2603
|
+
* share, in the order of their creation.
|
|
2604
|
+
*/
|
|
2605
|
+
names = new Map();
|
|
2606
|
+
/** The object that each slot holds, or last held, which queries name by slot. */
|
|
2607
|
+
objectSlots = [];
|
|
2608
|
+
/** The batch that each batch slot holds, or last held, which queries name by id. */
|
|
2609
|
+
batchSlots = [];
|
|
2610
|
+
/** The quad meshes of sprite batches, by their center, which batches with one center share. */
|
|
2611
|
+
spriteQuads = new Map();
|
|
2612
|
+
/** @internal The particle buffers in the scene. */
|
|
2613
|
+
particleBuffers = 0;
|
|
2614
|
+
/** @internal The draws that make their own vertices. */
|
|
2615
|
+
vertexDraws = 0;
|
|
2616
|
+
/** The one triangle that particle buffers' objects draw with, made with the first buffer. */
|
|
2617
|
+
particleMesh;
|
|
2618
|
+
/** The one triangle that such draws' objects hold, made with the first draw. */
|
|
2619
|
+
vertexDrawMesh;
|
|
2620
|
+
/** The segment mesh of line batches, which every line batch shares, made with the first. */
|
|
2621
|
+
lineMesh;
|
|
2622
|
+
/** Raycasts and overlap queries, made on the first query. */
|
|
2623
|
+
sceneQueries;
|
|
2624
|
+
/** GPU picking's queries, made on the first pick. */
|
|
2625
|
+
scenePicks;
|
|
2626
|
+
/** The ray and hit that a pick's raycast reuses. */
|
|
2627
|
+
pickRay;
|
|
2628
|
+
pickHit;
|
|
2629
|
+
/** The point of a pick's ray, in CSS pixels, which the ray's math reads from an array. */
|
|
2630
|
+
pickPoint;
|
|
2631
|
+
/** The command batches that the world took before the runner's first frame, or -1. */
|
|
2632
|
+
settledCommands = -1;
|
|
2633
|
+
/** The environment's values in the core, made on the first `setEnvironment`. */
|
|
2634
|
+
sceneEnvironment;
|
|
2635
|
+
/** The light probe grid's values in the core, made on the first `setLightProbeGrid`. */
|
|
2636
|
+
sceneProbeGrid;
|
|
2637
|
+
/** The background's values in the core, made on the first `setBackground`. */
|
|
2638
|
+
sceneBackground;
|
|
2639
|
+
/** The add-on's layer over the background, made on the first `setSkyLayer`. */
|
|
2640
|
+
skyLayer;
|
|
2641
|
+
/** True while the fog is volumetric. */
|
|
2642
|
+
fogVolume = false;
|
|
2643
|
+
/** Pointer events on objects, made on the first `on`. */
|
|
2644
|
+
objectEvents;
|
|
2645
|
+
/** Rows of the live instance batches, which development builds count. */
|
|
2646
|
+
batchRows = 0;
|
|
2647
|
+
/** @internal The batches of command records published so far, which tests count. */
|
|
2648
|
+
commandBatches = 0;
|
|
2649
|
+
warnedPastPortable = false;
|
|
2650
|
+
/** @internal The scene's animated objects, from the first model with animations on. */
|
|
2651
|
+
animations;
|
|
2652
|
+
/** @internal The scene's property animations, from the first animated property. */
|
|
2653
|
+
properties;
|
|
2654
|
+
/** @internal True once an object has morph weights, so each frame's animation step runs. */
|
|
2655
|
+
morphed = false;
|
|
2656
|
+
/** The core's table of morph weights, made again after the engine's memory grew. */
|
|
2657
|
+
morphTable = NO_FLOATS;
|
|
2658
|
+
morphGeneration = -1;
|
|
2659
|
+
/** @internal */
|
|
2660
|
+
constructor(
|
|
2661
|
+
/** @internal */ core, time,
|
|
2662
|
+
/** True when the engine draws with WebGL2, whose devices draw fewer rows than WebGPU's. */
|
|
2663
|
+
webgl2, warmUpScene = () => Promise.resolve(),
|
|
2664
|
+
/** The cameras of the last frames, which the sketch runner gives; tests get a stand-in. */
|
|
2665
|
+
cameras,
|
|
2666
|
+
/**
|
|
2667
|
+
* What sprite and line batches make their meshes and materials with, which the sketch runner
|
|
2668
|
+
* gives.
|
|
2669
|
+
*/
|
|
2670
|
+
makers,
|
|
2671
|
+
/** The input reader, whose pointer events reach objects' handlers. */
|
|
2672
|
+
pointerInput) {
|
|
2673
|
+
this.core = core;
|
|
2674
|
+
this.time = time;
|
|
2675
|
+
this.webgl2 = webgl2;
|
|
2676
|
+
this.warmUpScene = warmUpScene;
|
|
2677
|
+
this.cameras = cameras;
|
|
2678
|
+
this.makers = makers;
|
|
2679
|
+
this.pointerInput = pointerInput;
|
|
2680
|
+
if (DEV) {
|
|
2681
|
+
this.unmarkedWrites = new UnmarkedWrites(this);
|
|
2682
|
+
this.unmarkedRows = new UnmarkedRows(core);
|
|
2683
|
+
}
|
|
2684
|
+
core.holdViews(this);
|
|
2685
|
+
}
|
|
2686
|
+
/** Forgets the views of the scene's arrays and of the morph weights. */
|
|
2687
|
+
dropViews() {
|
|
2688
|
+
this.currentViews = undefined;
|
|
2689
|
+
this.morphGeneration = -1;
|
|
2690
|
+
this.morphTable = NO_FLOATS;
|
|
2691
|
+
}
|
|
2692
|
+
/** @internal The cameras of the last frames, for `screenToRay` and `worldToScreen`. */
|
|
2693
|
+
get frameCameras() {
|
|
2694
|
+
this.cameras ??= new FrameCameras(this.core, controlViews(createControlBuffer(false)), {
|
|
2695
|
+
frameAt: () => -1,
|
|
2696
|
+
});
|
|
2697
|
+
return this.cameras;
|
|
2698
|
+
}
|
|
2699
|
+
/** @internal Pointer events on objects, made on the first call. */
|
|
2700
|
+
get pointerEvents() {
|
|
2701
|
+
this.objectEvents ??= new PointerEvents({ pick: (frame, numbers, ray) => this.pickForEvent(frame, numbers, ray) }, this.pointerInput);
|
|
2702
|
+
return this.objectEvents;
|
|
2703
|
+
}
|
|
2704
|
+
/**
|
|
2705
|
+
* Casts the ray of a pointer event from the camera of engine frame `frame`, or from the active
|
|
2706
|
+
* camera as it stands when the ring no longer holds the frame, on the camera's layers.
|
|
2707
|
+
*/
|
|
2708
|
+
pickForEvent(frame, numbers, ray) {
|
|
2709
|
+
const camera = this.activeCamera;
|
|
2710
|
+
const live = camera !== undefined && camera.destroyedFrame === -1 ? camera : undefined;
|
|
2711
|
+
const layers = this.frameCameras.frameRay(frame, numbers, ray, live);
|
|
2712
|
+
return layers < 0 ? null : this.queries.pick(ray, layers, numbers);
|
|
2713
|
+
}
|
|
2714
|
+
/** @internal Calls the handlers of the pointer events that the input of this frame brought. */
|
|
2715
|
+
dispatchPointerEvents(report) {
|
|
2716
|
+
this.objectEvents?.dispatch(report);
|
|
2717
|
+
}
|
|
2718
|
+
/** @internal Removes the pointer event handlers of an object or a batch that is destroyed. */
|
|
2719
|
+
forgetListeners(target) {
|
|
2720
|
+
if (target.pointerListeners !== undefined)
|
|
2721
|
+
this.objectEvents?.forget(target);
|
|
2722
|
+
}
|
|
2723
|
+
/**
|
|
2724
|
+
* @internal Keeps the active camera of engine frame `frame`, which drew on a canvas of `width`
|
|
2725
|
+
* by `height` device pixels, so rays from that frame's input use it. The engine's count includes
|
|
2726
|
+
* the frames that ran no sketch code, such as the setup's.
|
|
2727
|
+
*/
|
|
2728
|
+
keepFrameCamera(frame, width, height) {
|
|
2729
|
+
this.frameCameras.record(frame, this.activeCamera, width, height);
|
|
2730
|
+
}
|
|
2731
|
+
/** @internal */
|
|
2732
|
+
get frame() {
|
|
2733
|
+
return this.time.frame;
|
|
2734
|
+
}
|
|
2735
|
+
/** @internal The camera that the canvas shows, which each frame draws from. */
|
|
2736
|
+
get shownCamera() {
|
|
2737
|
+
return this.activeCamera;
|
|
2738
|
+
}
|
|
2739
|
+
/** @internal */
|
|
2740
|
+
get views() {
|
|
2741
|
+
if (this.viewsGeneration !== this.core.generation || !this.currentViews) {
|
|
2742
|
+
this.currentViews = sceneViews(this.core);
|
|
2743
|
+
this.viewsGeneration = this.core.generation;
|
|
2744
|
+
}
|
|
2745
|
+
return this.currentViews;
|
|
2746
|
+
}
|
|
2747
|
+
/**
|
|
2748
|
+
* @internal Writes the position of the object in `slot` from an array that holds it, relative to
|
|
2749
|
+
* its parent. A caller that keeps a pose in an array writes it this way: the numbers stay in the
|
|
2750
|
+
* array, where a number passed to a call that the browser does not inline becomes an object.
|
|
2751
|
+
*/
|
|
2752
|
+
writePositionFrom(slot, position) {
|
|
2753
|
+
const { positions, positionCells } = this.views;
|
|
2754
|
+
const i = slot * 3;
|
|
2755
|
+
const x = position[0];
|
|
2756
|
+
const y = position[1];
|
|
2757
|
+
const z = position[2];
|
|
2758
|
+
if (positionCells === undefined) {
|
|
2759
|
+
positions[i] = x;
|
|
2760
|
+
positions[i + 1] = y;
|
|
2761
|
+
positions[i + 2] = z;
|
|
2762
|
+
return;
|
|
2763
|
+
}
|
|
2764
|
+
splitPosition(positions, positionCells, i, x);
|
|
2765
|
+
splitPosition(positions, positionCells, i + 1, y);
|
|
2766
|
+
splitPosition(positions, positionCells, i + 2, z);
|
|
2767
|
+
}
|
|
2768
|
+
/**
|
|
2769
|
+
* @internal Writes the position of the object in `slot`, relative to its parent. In large-world
|
|
2770
|
+
* mode it splits each number into whole cells and a rest of about half a cell at most, so the
|
|
2771
|
+
* 32-bit rest keeps the number's full precision.
|
|
2772
|
+
*/
|
|
2773
|
+
writePosition(slot, x, y, z) {
|
|
2774
|
+
// The numbers go into the array this file keeps, so the write below takes none of them: a
|
|
2775
|
+
// number passed to a call that the browser does not inline becomes an object of its own.
|
|
2776
|
+
POSITION[0] = x;
|
|
2777
|
+
POSITION[1] = y;
|
|
2778
|
+
POSITION[2] = z;
|
|
2779
|
+
this.writePositionFrom(slot, POSITION);
|
|
2780
|
+
}
|
|
2781
|
+
/** @internal Copies the position of the object in `slot`, relative to its parent, into `out`. */
|
|
2782
|
+
readPosition(slot, out) {
|
|
2783
|
+
const { positions, positionCells } = this.views;
|
|
2784
|
+
const i = slot * 3;
|
|
2785
|
+
out[0] = positions[i];
|
|
2786
|
+
out[1] = positions[i + 1];
|
|
2787
|
+
out[2] = positions[i + 2];
|
|
2788
|
+
if (positionCells === undefined)
|
|
2789
|
+
return;
|
|
2790
|
+
out[0] = out[0] + positionCells[i] * C.CELL_SIZE;
|
|
2791
|
+
out[1] = out[1] + positionCells[i + 1] * C.CELL_SIZE;
|
|
2792
|
+
out[2] = out[2] + positionCells[i + 2] * C.CELL_SIZE;
|
|
2793
|
+
}
|
|
2794
|
+
/** @internal Flags a static object for recomputation. */
|
|
2795
|
+
markDirty(slot) {
|
|
2796
|
+
const dirty = this.views.dirty;
|
|
2797
|
+
dirty[slot >>> 5] = dirty[slot >>> 5] | (1 << (slot & 31));
|
|
2798
|
+
}
|
|
2799
|
+
/** @internal Appends a command record for the next frame. */
|
|
2800
|
+
command(op, handle, a, b, call) {
|
|
2801
|
+
const write = this.reserveCommands(1, call);
|
|
2802
|
+
this.writeCommand(write, op, handle, a, b);
|
|
2803
|
+
this.publishCommands(write + 1);
|
|
2804
|
+
}
|
|
2805
|
+
/**
|
|
2806
|
+
* The ring's write index, after a check that `count` more records fit. Throws E1102 when they
|
|
2807
|
+
* do not, before anything is written.
|
|
2808
|
+
*/
|
|
2809
|
+
reserveCommands(count, call) {
|
|
2810
|
+
const v = this.views;
|
|
2811
|
+
const write = Atomics.load(v.writeIndex, 0);
|
|
2812
|
+
const read = Atomics.load(v.readIndex, 0);
|
|
2813
|
+
if (((write - read) >>> 0) + count > v.ringCapacity)
|
|
2814
|
+
throw new EngineError('E1102', `${call}() failed: the command ring holds ${v.ringCapacity} changes for the next frame, and it has no room for ${count} more.`);
|
|
2815
|
+
return write;
|
|
2816
|
+
}
|
|
2817
|
+
/** Writes a record at write index `at`, which the next publish makes visible. */
|
|
2818
|
+
writeCommand(at, op, handle, a, b) {
|
|
2819
|
+
const v = this.views;
|
|
2820
|
+
const i = (at & (v.ringCapacity - 1)) * C.COMMAND_WORDS;
|
|
2821
|
+
v.records[i] = op;
|
|
2822
|
+
v.records[i + 1] = handle;
|
|
2823
|
+
v.records[i + 2] = a;
|
|
2824
|
+
v.records[i + 3] = b;
|
|
2825
|
+
}
|
|
2826
|
+
/** Makes the records up to write index `end` visible to the core, as one batch. */
|
|
2827
|
+
publishCommands(end) {
|
|
2828
|
+
Atomics.store(this.views.writeIndex, 0, end >>> 0);
|
|
2829
|
+
this.commandBatches++;
|
|
2830
|
+
}
|
|
2831
|
+
/** @internal The world matrix of the frame that last ran: 12 numbers, row by row. */
|
|
2832
|
+
worldMatrix(object, call) {
|
|
2833
|
+
// The core's error adds the slot to the object's name.
|
|
2834
|
+
this.core.check(this.core.readWorldMatrix(object.handle, this.matrix), call, object.label, true);
|
|
2835
|
+
return this.matrix;
|
|
2836
|
+
}
|
|
2837
|
+
/** @internal The world matrix of the frame that last ran: 16 numbers, column by column. */
|
|
2838
|
+
worldColumns(object, call) {
|
|
2839
|
+
const m = this.worldMatrix(object, call);
|
|
2840
|
+
const out = this.columns;
|
|
2841
|
+
for (let row = 0; row < 3; row++)
|
|
2842
|
+
for (let column = 0; column < 4; column++)
|
|
2843
|
+
out[column * 4 + row] = m[row * 4 + column];
|
|
2844
|
+
out[3] = 0;
|
|
2845
|
+
out[7] = 0;
|
|
2846
|
+
out[11] = 0;
|
|
2847
|
+
out[15] = 1;
|
|
2848
|
+
return out;
|
|
2849
|
+
}
|
|
2850
|
+
/** @internal Copies the rotation of the object in `slot` into `out`. */
|
|
2851
|
+
readRotation(slot, out) {
|
|
2852
|
+
const r = this.views.rotations;
|
|
2853
|
+
const i = slot * 4;
|
|
2854
|
+
out[0] = r[i];
|
|
2855
|
+
out[1] = r[i + 1];
|
|
2856
|
+
out[2] = r[i + 2];
|
|
2857
|
+
out[3] = r[i + 3];
|
|
2858
|
+
}
|
|
2859
|
+
/** @internal Copies the scale of the object in `slot` into `out`. */
|
|
2860
|
+
readScale(slot, out) {
|
|
2861
|
+
const s = this.views.scales;
|
|
2862
|
+
const i = slot * 3;
|
|
2863
|
+
out[0] = s[i];
|
|
2864
|
+
out[1] = s[i + 1];
|
|
2865
|
+
out[2] = s[i + 2];
|
|
2866
|
+
}
|
|
2867
|
+
/**
|
|
2868
|
+
* @internal Writes a value that a hold script's `set` step names, at once, with the property
|
|
2869
|
+
* paths of `animateProperty`. Throws E1218 for a target that was destroyed, a path that the
|
|
2870
|
+
* object does not take, and a count of values that the path does not take.
|
|
2871
|
+
*/
|
|
2872
|
+
setScriptPath(target, path, values) {
|
|
2873
|
+
const fail = (detail) => {
|
|
2874
|
+
throw this.checks.error('E1218', detail);
|
|
2875
|
+
};
|
|
2876
|
+
if (target.destroyedFrame !== -1)
|
|
2877
|
+
fail(`set() got ${target.describe()}, which was destroyed.`);
|
|
2878
|
+
const property = propertyPath(target, path, fail, 'set');
|
|
2879
|
+
if (values.length !== property.components)
|
|
2880
|
+
fail(`set() got ${values.length} ${values.length === 1 ? 'value' : 'values'} for "${path}" on ${target.describe()}, which takes ${property.components}.`);
|
|
2881
|
+
const at = SCRIPT_VALUES;
|
|
2882
|
+
for (let k = 0; k < property.components; k++)
|
|
2883
|
+
at[k] = values[k];
|
|
2884
|
+
SCRIPT_BASE.fill(0);
|
|
2885
|
+
writeProperty(target, {
|
|
2886
|
+
what: property.what,
|
|
2887
|
+
name: property.name,
|
|
2888
|
+
components: property.components,
|
|
2889
|
+
base: SCRIPT_BASE,
|
|
2890
|
+
}, at, 0, 1);
|
|
2891
|
+
}
|
|
2892
|
+
/**
|
|
2893
|
+
* @internal The value that a hold script's `dump` step reads, with the property paths of
|
|
2894
|
+
* `animateProperty`: the object's position, rotation, scale or visible flag, a camera's lens
|
|
2895
|
+
* values, or a light's color. Throws E1218 for a target that was destroyed, a path that the
|
|
2896
|
+
* object does not take, or a value that the engine does not keep to read back.
|
|
2897
|
+
*/
|
|
2898
|
+
readScriptPath(target, path) {
|
|
2899
|
+
const fail = (detail) => {
|
|
2900
|
+
throw this.checks.error('E1218', detail);
|
|
2901
|
+
};
|
|
2902
|
+
if (target.destroyedFrame !== -1)
|
|
2903
|
+
fail(`dump() got ${target.describe()}, which was destroyed.`);
|
|
2904
|
+
const property = propertyPath(target, path, fail, 'dump');
|
|
2905
|
+
const out = new Array(property.components).fill(0);
|
|
2906
|
+
const read = SCRIPT_VALUES;
|
|
2907
|
+
switch (property.what) {
|
|
2908
|
+
case PROPERTY_POSITION:
|
|
2909
|
+
this.readPosition(target.row, read);
|
|
2910
|
+
break;
|
|
2911
|
+
case PROPERTY_ROTATION:
|
|
2912
|
+
this.readRotation(target.row, read);
|
|
2913
|
+
break;
|
|
2914
|
+
case PROPERTY_SCALE:
|
|
2915
|
+
this.readScale(target.row, read);
|
|
2916
|
+
break;
|
|
2917
|
+
case PROPERTY_VISIBLE:
|
|
2918
|
+
read[0] = (target.flags & C.FLAG_VISIBLE) !== 0 ? 1 : 0;
|
|
2919
|
+
break;
|
|
2920
|
+
case PROPERTY_CAMERA_FOV:
|
|
2921
|
+
read[0] = target.fov;
|
|
2922
|
+
break;
|
|
2923
|
+
case PROPERTY_CAMERA_NEAR:
|
|
2924
|
+
read[0] = target.near;
|
|
2925
|
+
break;
|
|
2926
|
+
case PROPERTY_CAMERA_FAR:
|
|
2927
|
+
read[0] = target.far;
|
|
2928
|
+
break;
|
|
2929
|
+
case PROPERTY_CAMERA_HEIGHT:
|
|
2930
|
+
read[0] = target.height;
|
|
2931
|
+
break;
|
|
2932
|
+
case PROPERTY_LIGHT_COLOR:
|
|
2933
|
+
read.set(target.linear);
|
|
2934
|
+
break;
|
|
2935
|
+
default:
|
|
2936
|
+
fail(`dump() cannot read "${path}" on ${target.describe()}, which the engine does not keep. It reads position, rotation, scale, visible, a light's color, and a camera's fov, near, far and height.`);
|
|
2937
|
+
}
|
|
2938
|
+
for (let k = 0; k < property.components; k++)
|
|
2939
|
+
out[k] = read[k];
|
|
2940
|
+
return out;
|
|
2941
|
+
}
|
|
2942
|
+
/**
|
|
2943
|
+
* @internal Up to `limit` names in the scene that contain `text`, in the order the objects were
|
|
2944
|
+
* created, or the first names when none contains it. A message about a name that found no object
|
|
2945
|
+
* shows them, so the wrong name in a script or a call is easy to fix.
|
|
2946
|
+
*/
|
|
2947
|
+
nearNames(text, limit = 3) {
|
|
2948
|
+
const wanted = text.toLowerCase();
|
|
2949
|
+
const close = [];
|
|
2950
|
+
const all = [];
|
|
2951
|
+
for (const name of this.names.keys()) {
|
|
2952
|
+
if (name === '')
|
|
2953
|
+
continue;
|
|
2954
|
+
if (all.length < limit)
|
|
2955
|
+
all.push(name);
|
|
2956
|
+
if (close.length < limit && name.toLowerCase().includes(wanted))
|
|
2957
|
+
close.push(name);
|
|
2958
|
+
}
|
|
2959
|
+
return close.length > 0 ? close : all;
|
|
2960
|
+
}
|
|
2961
|
+
/**
|
|
2962
|
+
* @internal The core's table of morph weights. Sketches set weights every frame, so the check
|
|
2963
|
+
* stays small enough for the browser to inline into their code.
|
|
2964
|
+
*/
|
|
2965
|
+
morphWeights() {
|
|
2966
|
+
if (this.morphGeneration !== this.core.generation)
|
|
2967
|
+
this.morphView();
|
|
2968
|
+
return this.morphTable;
|
|
2969
|
+
}
|
|
2970
|
+
morphView() {
|
|
2971
|
+
const { core } = this;
|
|
2972
|
+
this.morphTable = core.f32(core.glue.morphWeightsAddress(), C.MORPH_MAX_WEIGHTS);
|
|
2973
|
+
this.morphGeneration = core.generation;
|
|
2974
|
+
}
|
|
2975
|
+
/**
|
|
2976
|
+
* @internal Gives `mesh` a block of morph weights for `geometry`'s targets, which start at
|
|
2977
|
+
* `weights` or at 0, and returns the block's id plus one for its `SET_MORPH` command, or 0 for
|
|
2978
|
+
* a geometry without morph targets.
|
|
2979
|
+
*/
|
|
2980
|
+
makeMorph(mesh, geometry, weights, call) {
|
|
2981
|
+
const count = geometry.morphTargets;
|
|
2982
|
+
if (!count)
|
|
2983
|
+
return 0;
|
|
2984
|
+
const { core } = this;
|
|
2985
|
+
const block = core.checkGrowth(core.glue.createMorphWeights(count), call, mesh.label);
|
|
2986
|
+
this.morphed = true;
|
|
2987
|
+
mesh.morphBlock = block;
|
|
2988
|
+
mesh.morphFirst = core.glue.morphWeightsFirst(block - 1);
|
|
2989
|
+
mesh.morphCount = count;
|
|
2990
|
+
this.morphView();
|
|
2991
|
+
if (weights)
|
|
2992
|
+
for (let k = 0; k < count; k++)
|
|
2993
|
+
this.morphTable[mesh.morphFirst + k] = weights[k] ?? 0;
|
|
2994
|
+
return block;
|
|
2995
|
+
}
|
|
2996
|
+
/** @internal The weights of `mesh`'s block, copied, or none for a mesh without one. */
|
|
2997
|
+
morphWeightsOf(mesh) {
|
|
2998
|
+
if (mesh.morphBlock === 0)
|
|
2999
|
+
return undefined;
|
|
3000
|
+
return this.morphWeights().slice(mesh.morphFirst, mesh.morphFirst + mesh.morphCount);
|
|
3001
|
+
}
|
|
3002
|
+
/** @internal Frees `mesh`'s block of morph weights, if it has one. */
|
|
3003
|
+
releaseMorph(mesh) {
|
|
3004
|
+
if (mesh.morphBlock === 0)
|
|
3005
|
+
return;
|
|
3006
|
+
this.core.glue.destroyMorphWeights(mesh.morphBlock - 1);
|
|
3007
|
+
mesh.morphBlock = 0;
|
|
3008
|
+
mesh.morphCount = 0;
|
|
3009
|
+
}
|
|
3010
|
+
/**
|
|
3011
|
+
* @internal Writes the local bounding sphere of the object in `slot`. The command that follows
|
|
3012
|
+
* makes the engine recompute the object.
|
|
3013
|
+
*/
|
|
3014
|
+
writeBounds(slot, x, y, z, radius) {
|
|
3015
|
+
const { centers, radii } = this.views;
|
|
3016
|
+
centers[slot * 3] = x;
|
|
3017
|
+
centers[slot * 3 + 1] = y;
|
|
3018
|
+
centers[slot * 3 + 2] = z;
|
|
3019
|
+
radii[slot] = radius;
|
|
3020
|
+
}
|
|
3021
|
+
/** @internal The bits of `value` as a 32-bit float, for a command's argument. */
|
|
3022
|
+
floatBits(value) {
|
|
3023
|
+
this.float[0] = value;
|
|
3024
|
+
return this.floatWord[0];
|
|
3025
|
+
}
|
|
3026
|
+
/**
|
|
3027
|
+
* Adds a new object to the index of slots that queries read, and to the index of names after
|
|
3028
|
+
* those with its name.
|
|
3029
|
+
*/
|
|
3030
|
+
remember(object) {
|
|
3031
|
+
this.objectSlots[object.slot] = object;
|
|
3032
|
+
const { name } = object;
|
|
3033
|
+
if (!name)
|
|
3034
|
+
return;
|
|
3035
|
+
const known = this.names.get(name);
|
|
3036
|
+
if (known === undefined)
|
|
3037
|
+
this.names.set(name, object);
|
|
3038
|
+
else if (known instanceof Set)
|
|
3039
|
+
known.add(object);
|
|
3040
|
+
else
|
|
3041
|
+
this.names.set(name, new Set([known, object]));
|
|
3042
|
+
}
|
|
3043
|
+
/**
|
|
3044
|
+
* @internal Visits each live object whose mesh has lower levels of detail, until `visit`
|
|
3045
|
+
* returns false. The debug view of levels draws their culling spheres, so it reads the objects
|
|
3046
|
+
* that have such a sphere of their own.
|
|
3047
|
+
*/
|
|
3048
|
+
forEachLevelMesh(visit) {
|
|
3049
|
+
for (const object of this.objectSlots) {
|
|
3050
|
+
if (object === undefined || object.destroyedFrame !== -1)
|
|
3051
|
+
continue;
|
|
3052
|
+
if (!(object instanceof Mesh) || object.mesh === undefined)
|
|
3053
|
+
continue;
|
|
3054
|
+
if (object.mesh.levels.length === 0)
|
|
3055
|
+
continue;
|
|
3056
|
+
if (!visit(object))
|
|
3057
|
+
return;
|
|
3058
|
+
}
|
|
3059
|
+
}
|
|
3060
|
+
/** Adds a new batch to the index that queries read, by the slot of each of its core batches. */
|
|
3061
|
+
rememberBatch(batch) {
|
|
3062
|
+
this.batchSlots[batch.id & SLOT_MASK] = batch;
|
|
3063
|
+
for (const part of batch.parts)
|
|
3064
|
+
this.batchSlots[part & SLOT_MASK] = batch;
|
|
3065
|
+
}
|
|
3066
|
+
/**
|
|
3067
|
+
* @internal The frame that the sketch ran last, and whether hold mode steps the frames, which a
|
|
3068
|
+
* mesh reads to make its planned levels one a frame.
|
|
3069
|
+
*/
|
|
3070
|
+
get pace() {
|
|
3071
|
+
return this.time;
|
|
3072
|
+
}
|
|
3073
|
+
/**
|
|
3074
|
+
* @internal The first live object or instance batch that uses one of `meshes` or `materials`,
|
|
3075
|
+
* or whose animator plays `rig`, as error messages describe it, or undefined when none does.
|
|
3076
|
+
* It looks at every object and batch, so destroys call it, never the frame loop.
|
|
3077
|
+
*/
|
|
3078
|
+
userOf(meshes, materials = new Set(), rig) {
|
|
3079
|
+
for (const object of this.objectSlots) {
|
|
3080
|
+
if (object === undefined || object.destroyedFrame !== -1)
|
|
3081
|
+
continue;
|
|
3082
|
+
if (rig !== undefined && object.animation?.rig === rig && object.animation.instance !== 0)
|
|
3083
|
+
return object.describe();
|
|
3084
|
+
if (!(object instanceof Mesh))
|
|
3085
|
+
continue;
|
|
3086
|
+
const { mesh, material } = object;
|
|
3087
|
+
if ((mesh && meshes.has(mesh)) || (material && materials.has(material)))
|
|
3088
|
+
return object.describe();
|
|
3089
|
+
}
|
|
3090
|
+
for (const batch of this.batchSlots) {
|
|
3091
|
+
if (batch === undefined || batch.destroyedFrame !== -1)
|
|
3092
|
+
continue;
|
|
3093
|
+
const { uses } = batch;
|
|
3094
|
+
if (uses.meshes.some((m) => meshes.has(m)) || uses.materials.some((m) => materials.has(m)))
|
|
3095
|
+
return 'an instance batch';
|
|
3096
|
+
}
|
|
3097
|
+
return undefined;
|
|
3098
|
+
}
|
|
3099
|
+
/** @internal Takes a destroyed object out of the index of names. */
|
|
3100
|
+
forget(object) {
|
|
3101
|
+
const { name } = object;
|
|
3102
|
+
const known = this.names.get(name);
|
|
3103
|
+
if (known === object)
|
|
3104
|
+
this.names.delete(name);
|
|
3105
|
+
else if (known instanceof Set) {
|
|
3106
|
+
known.delete(object);
|
|
3107
|
+
if (known.size === 0)
|
|
3108
|
+
this.names.delete(name);
|
|
3109
|
+
}
|
|
3110
|
+
}
|
|
3111
|
+
/**
|
|
3112
|
+
* The first object created with `name` that is not destroyed, or undefined when no object has
|
|
3113
|
+
* the name. It looks the name up in an index, so its cost does not grow with the scene. Call it
|
|
3114
|
+
* at setup and keep the object it returns.
|
|
3115
|
+
*/
|
|
3116
|
+
find(name) {
|
|
3117
|
+
const known = this.names.get(name);
|
|
3118
|
+
return known instanceof Set ? known.values().next().value : known;
|
|
3119
|
+
}
|
|
3120
|
+
/**
|
|
3121
|
+
* Every object of the scene that is not destroyed, in the order of their slots, as a new array.
|
|
3122
|
+
* The in-page inspector lists the scene with it. It walks the whole scene and allocates, so call
|
|
3123
|
+
* it from tools and setup code, never in every frame.
|
|
3124
|
+
*/
|
|
3125
|
+
listObjects() {
|
|
3126
|
+
const objects = [];
|
|
3127
|
+
for (const object of this.objectSlots)
|
|
3128
|
+
if (object !== undefined && object.destroyedFrame === -1)
|
|
3129
|
+
objects.push(object);
|
|
3130
|
+
return objects;
|
|
3131
|
+
}
|
|
3132
|
+
/** @internal The live object in `slot`, or undefined. */
|
|
3133
|
+
objectAt(slot) {
|
|
3134
|
+
const object = this.objectSlots[slot];
|
|
3135
|
+
return object !== undefined && object.destroyedFrame === -1 ? object : undefined;
|
|
3136
|
+
}
|
|
3137
|
+
/**
|
|
3138
|
+
* @internal Counts the rows of batches as they are created and destroyed, and warns once when
|
|
3139
|
+
* the scene passes the limit that every device of the engine's GPU path draws.
|
|
3140
|
+
*/
|
|
3141
|
+
countBatchRows(change) {
|
|
3142
|
+
this.batchRows += change;
|
|
3143
|
+
if (this.warnedPastPortable)
|
|
3144
|
+
return;
|
|
3145
|
+
// The core counts every scene slot, used or not, toward the limit.
|
|
3146
|
+
const sources = this.core.glue.sceneCapacity() + 1 + this.batchRows;
|
|
3147
|
+
const warning = rowLimitWarning(sources, this.webgl2);
|
|
3148
|
+
if (warning === undefined)
|
|
3149
|
+
return;
|
|
3150
|
+
this.warnedPastPortable = true;
|
|
3151
|
+
console.warn(warning);
|
|
3152
|
+
}
|
|
3153
|
+
/** @internal */
|
|
3154
|
+
lensChanged(camera) {
|
|
3155
|
+
camera.updateLens();
|
|
3156
|
+
if (camera === this.activeCamera)
|
|
3157
|
+
camera.sendLens(this.core);
|
|
3158
|
+
if (camera === this.shadowCamera)
|
|
3159
|
+
camera.sendLens(this.core, C.CAMERA_TARGET_SHADOWS);
|
|
3160
|
+
const passes = this.passCameras;
|
|
3161
|
+
for (let place = 1; place < passes.length; place++) {
|
|
3162
|
+
const pass = passes[place];
|
|
3163
|
+
if (pass?.camera === camera)
|
|
3164
|
+
camera.sendLens(this.core, C.CAMERA_TARGET_PASS_VIEWS + place, pass.layers);
|
|
3165
|
+
}
|
|
3166
|
+
}
|
|
3167
|
+
/**
|
|
3168
|
+
* @internal Draws the view of the scene pass at `place` from `camera`, with `layers`, or the
|
|
3169
|
+
* camera's layers without them; or forgets the view's camera with `undefined`.
|
|
3170
|
+
*/
|
|
3171
|
+
setPassCamera(place, camera, layers) {
|
|
3172
|
+
if (camera === undefined) {
|
|
3173
|
+
this.passCameras[place] = undefined;
|
|
3174
|
+
return;
|
|
3175
|
+
}
|
|
3176
|
+
this.passCameras[place] = { camera, layers };
|
|
3177
|
+
camera.sendLens(this.core, C.CAMERA_TARGET_PASS_VIEWS + place, layers);
|
|
3178
|
+
}
|
|
3179
|
+
/**
|
|
3180
|
+
* @internal Fits the main directional light's shadow cascades to `camera` in place of the active
|
|
3181
|
+
* camera, or to the active camera again without one, for `debug.shadowCamera`.
|
|
3182
|
+
*/
|
|
3183
|
+
setShadowCamera(camera) {
|
|
3184
|
+
this.shadowCamera = camera;
|
|
3185
|
+
if (camera)
|
|
3186
|
+
camera.sendLens(this.core, C.CAMERA_TARGET_SHADOWS);
|
|
3187
|
+
else
|
|
3188
|
+
this.core.glue.clearShadowCamera();
|
|
3189
|
+
}
|
|
3190
|
+
/**
|
|
3191
|
+
* Creates an object of class `kind` from the next frame: its slot with the transform of
|
|
3192
|
+
* `options`, its create command with `flags` besides visibility and `dynamic`, its layers, the
|
|
3193
|
+
* material `material` names when it is not 0, and its wrapper, built with any further
|
|
3194
|
+
* constructor arguments, which the index of names learns. It checks that the command ring has
|
|
3195
|
+
* room for every record before it reserves the slot, and publishes the records at once, so a
|
|
3196
|
+
* failure leaves nothing behind.
|
|
3197
|
+
*/
|
|
3198
|
+
create(kind, options, mesh, radius, flags, material, call, center, ...extra) {
|
|
3199
|
+
const { layers } = options;
|
|
3200
|
+
if (DEV) {
|
|
3201
|
+
if (options.parent)
|
|
3202
|
+
checkLive(call, options.parent, true);
|
|
3203
|
+
if (layers !== undefined)
|
|
3204
|
+
checkLayers(call, layers);
|
|
3205
|
+
}
|
|
3206
|
+
const layered = layers !== undefined && layers >>> 0 !== C.LAYERS_DEFAULT;
|
|
3207
|
+
let write = this.reserveCommands(1 + (layered ? 1 : 0) + (material ? 1 : 0), call);
|
|
3208
|
+
const handle = this.core.checkGrowth(this.core.glue.reserveObject(), call, options.name);
|
|
3209
|
+
const slot = handle & SLOT_MASK;
|
|
3210
|
+
const v = this.views;
|
|
3211
|
+
const [x, y, z] = options.position ?? ORIGIN;
|
|
3212
|
+
this.writePosition(slot, x, y, z);
|
|
3213
|
+
v.rotations.set(options.rotation ?? [0, 0, 0, 1], slot * 4);
|
|
3214
|
+
v.scales.set(options.scale ?? [1, 1, 1], slot * 3);
|
|
3215
|
+
this.writeBounds(slot, center[0], center[1], center[2], radius);
|
|
3216
|
+
const all = flags | C.FLAG_VISIBLE | (options.dynamic ? C.FLAG_DYNAMIC : 0);
|
|
3217
|
+
const parent = options.parent?.handle ?? 0;
|
|
3218
|
+
this.writeCommand(write++, C.COMMAND_CREATE | (all << 8), handle, parent, mesh);
|
|
3219
|
+
if (layered)
|
|
3220
|
+
this.writeCommand(write++, C.COMMAND_SET_LAYERS, handle, layers >>> 0, 0);
|
|
3221
|
+
if (material)
|
|
3222
|
+
this.writeCommand(write++, C.COMMAND_SET_MATERIAL, handle, material, 0);
|
|
3223
|
+
this.publishCommands(write);
|
|
3224
|
+
const object = new kind(this, handle, options.name ?? '', ...extra);
|
|
3225
|
+
object.attachTo(options.parent ?? null);
|
|
3226
|
+
object.flags = all;
|
|
3227
|
+
object.layerMask = (layers ?? C.LAYERS_DEFAULT) >>> 0;
|
|
3228
|
+
this.remember(object);
|
|
3229
|
+
if (DEV)
|
|
3230
|
+
this.unmarkedWrites?.watch(object, !options.dynamic);
|
|
3231
|
+
return object;
|
|
3232
|
+
}
|
|
3233
|
+
/** An empty node, for hierarchy. */
|
|
3234
|
+
createGroup(options = {}) {
|
|
3235
|
+
return this.create(Group, options, C.CORE_NO_MESH, 0, 0, 0, 'createGroup', ORIGIN);
|
|
3236
|
+
}
|
|
3237
|
+
/** A drawn object. It is static unless `dynamic: true`. */
|
|
3238
|
+
createMesh(options) {
|
|
3239
|
+
const { mesh, material } = options;
|
|
3240
|
+
if (DEV) {
|
|
3241
|
+
checkSameEngine('createMesh', 'mesh', mesh.core, this);
|
|
3242
|
+
checkSameEngine('createMesh', 'material', material.core, this);
|
|
3243
|
+
}
|
|
3244
|
+
const flags = (options.castShadows ? C.FLAG_CAST_SHADOWS : 0) |
|
|
3245
|
+
(options.receiveShadows ? C.FLAG_RECEIVE_SHADOWS : 0) |
|
|
3246
|
+
occluderFlags(options.occluder);
|
|
3247
|
+
const object = this.create(Mesh, options, mesh.id, mesh.radius + material.boundsMargin, flags, material.id, 'createMesh', mesh.center);
|
|
3248
|
+
object.mesh = mesh;
|
|
3249
|
+
object.material = material;
|
|
3250
|
+
mesh.drawnWith(material, 1, 'createMesh');
|
|
3251
|
+
const block = this.makeMorph(object, mesh, undefined, 'createMesh');
|
|
3252
|
+
if (block !== 0)
|
|
3253
|
+
this.command(C.COMMAND_SET_MORPH, object.handle, block, 0, 'createMesh');
|
|
3254
|
+
return object;
|
|
3255
|
+
}
|
|
3256
|
+
/**
|
|
3257
|
+
* Creates the objects of a model that `assets.loadGltf` loaded, under one new group that
|
|
3258
|
+
* `options` places, and returns that group. All the objects are created with one batch of
|
|
3259
|
+
* commands, and every copy shares the model's meshes, materials and textures. The group's
|
|
3260
|
+
* `find` gives the copy's object of a node, by the node's name. A model with clips or skins
|
|
3261
|
+
* gives the group an animator, which plays the clips: `copy.animator().play('Walk')`. Throws
|
|
3262
|
+
* E1102 when the scene, the animation table or the batch table has no room for the copy. Then
|
|
3263
|
+
* no part of the copy stays. `destroy()` on the group removes the whole copy.
|
|
3264
|
+
*/
|
|
3265
|
+
instantiate(prefab, options = {}) {
|
|
3266
|
+
const call = 'instantiate';
|
|
3267
|
+
prefab.checkLive(call);
|
|
3268
|
+
const { template } = prefab;
|
|
3269
|
+
if (DEV) {
|
|
3270
|
+
checkSameEngine(call, 'model', prefab.core, this);
|
|
3271
|
+
if (options.parent)
|
|
3272
|
+
checkLive(call, options.parent, true);
|
|
3273
|
+
if (options.layers !== undefined)
|
|
3274
|
+
checkLayers(call, options.layers);
|
|
3275
|
+
}
|
|
3276
|
+
const extra = (options.castShadows ? C.FLAG_CAST_SHADOWS : 0) |
|
|
3277
|
+
(options.receiveShadows ? C.FLAG_RECEIVE_SHADOWS : 0) |
|
|
3278
|
+
occluderFlags(options.occluder);
|
|
3279
|
+
const root = {
|
|
3280
|
+
...template[0],
|
|
3281
|
+
name: options.name ?? template[0]?.name ?? '',
|
|
3282
|
+
transform: rootTransform(options),
|
|
3283
|
+
flags: C.FLAG_VISIBLE | (options.dynamic ? C.FLAG_DYNAMIC : 0),
|
|
3284
|
+
layers: (options.layers ?? C.LAYERS_DEFAULT) >>> 0,
|
|
3285
|
+
root: true,
|
|
3286
|
+
};
|
|
3287
|
+
const cleared = options.occluder === false ? C.FLAG_OCCLUDER : 0;
|
|
3288
|
+
// Layers reach every object of the copy and its batches, as the shadow flags reach every mesh.
|
|
3289
|
+
const nodes = options.layers === undefined
|
|
3290
|
+
? template
|
|
3291
|
+
: template.map((node) => ({ ...node, layers: root.layers }));
|
|
3292
|
+
const objects = this.createNodes(nodes, call, options.parent ?? null, root, extra, cleared);
|
|
3293
|
+
const instance = objects[0];
|
|
3294
|
+
instance.objects = objects;
|
|
3295
|
+
const batches = [];
|
|
3296
|
+
try {
|
|
3297
|
+
prefab.animate(objects);
|
|
3298
|
+
for (const spec of prefab.instancing)
|
|
3299
|
+
batches.push(this.placeInstancing(instance, spec, call, options));
|
|
3300
|
+
}
|
|
3301
|
+
catch (error) {
|
|
3302
|
+
// The animation table or the batch table is full: the copy goes whole, so the sketch
|
|
3303
|
+
// holds no part of it that it cannot reach.
|
|
3304
|
+
instance.batches = batches;
|
|
3305
|
+
instance.destroy();
|
|
3306
|
+
throw error;
|
|
3307
|
+
}
|
|
3308
|
+
instance.batches = batches;
|
|
3309
|
+
return instance;
|
|
3310
|
+
}
|
|
3311
|
+
/**
|
|
3312
|
+
* Animates one value of a light, a camera, a material or an object from keyframes, such as a
|
|
3313
|
+
* lamp that pulses or a color that changes, and returns an object that controls it. The engine
|
|
3314
|
+
* writes the value in each frame, so the sketch has no update call to make. A glTF file
|
|
3315
|
+
* animates the same kinds of value with its `KHR_animation_pointer` channels.
|
|
3316
|
+
*
|
|
3317
|
+
* `path` names the value. A light takes `'light.intensity'`, `'light.color'`, `'light.range'`,
|
|
3318
|
+
* `'light.decay'`, `'light.angle'` or `'light.penumbra'`; a camera takes `'camera.fov'` (in
|
|
3319
|
+
* degrees), `'camera.near'`, `'camera.far'` or `'camera.height'` (for an orthographic camera);
|
|
3320
|
+
* a material takes the values that `setUniform` takes, such as `'material.opacity'` or
|
|
3321
|
+
* `'material.color'`; and every object takes `'position'`, `'rotation'`, `'scale'` or
|
|
3322
|
+
* `'visible'`. The prefix is optional, so `'intensity'` and `'position'` work too.
|
|
3323
|
+
*
|
|
3324
|
+
* Every object that uses the material changes with it, and an animation that writes every
|
|
3325
|
+
* frame allocates nothing. `setTime` places the animation at a time; a frozen keyframes object
|
|
3326
|
+
* is read once. Throws E1218 for a path that the target does not take, or for keyframes that
|
|
3327
|
+
* do not fit the value's numbers per key.
|
|
3328
|
+
*
|
|
3329
|
+
* @category api/animation
|
|
3330
|
+
*/
|
|
3331
|
+
animateProperty(target, path, keyframes) {
|
|
3332
|
+
const call = 'animateProperty';
|
|
3333
|
+
const fail = (detail) => {
|
|
3334
|
+
throw this.checks.error('E1218', detail);
|
|
3335
|
+
};
|
|
3336
|
+
if (DEV) {
|
|
3337
|
+
if (target === null || typeof target !== 'object')
|
|
3338
|
+
fail(`${call}() got no target.`);
|
|
3339
|
+
if (target instanceof Material) {
|
|
3340
|
+
checkSameEngine(call, 'material', target.core, this);
|
|
3341
|
+
if (!target.live)
|
|
3342
|
+
fail(`${call}() got a material that was destroyed.`);
|
|
3343
|
+
}
|
|
3344
|
+
else
|
|
3345
|
+
checkLive(call, target, true);
|
|
3346
|
+
}
|
|
3347
|
+
const property = propertyPath(target, path, fail);
|
|
3348
|
+
const { times, values } = keyframes;
|
|
3349
|
+
const interpolation = keyframes.interpolation ?? 'linear';
|
|
3350
|
+
if (DEV) {
|
|
3351
|
+
if (interpolation !== 'linear' && interpolation !== 'step' && interpolation !== 'cubic')
|
|
3352
|
+
fail(`${call}() got the interpolation ${String(interpolation)}; it takes 'linear', 'step' or 'cubic'.`);
|
|
3353
|
+
if (times.length === 0)
|
|
3354
|
+
fail(`${call}() got no keys for "${path}". Name at least one.`);
|
|
3355
|
+
// A cubic key holds an in-tangent, the value and an out-tangent for each value.
|
|
3356
|
+
const parts = interpolation === 'cubic' ? 3 : 1;
|
|
3357
|
+
const perKey = property.components * parts;
|
|
3358
|
+
if (values.length !== times.length * perKey)
|
|
3359
|
+
fail(`${call}() got ${values.length} values for ${times.length} keys of "${path}", which takes ${perKey} ${perKey === 1 ? 'value' : 'values'} per key.`);
|
|
3360
|
+
let previous = -Infinity;
|
|
3361
|
+
for (let k = 0; k < times.length; k++) {
|
|
3362
|
+
const time = times[k];
|
|
3363
|
+
if (!Number.isFinite(time) || time < previous)
|
|
3364
|
+
fail(`${call}() got the key times of "${path}", which must be numbers from 0 up that never fall back.`);
|
|
3365
|
+
previous = time;
|
|
3366
|
+
}
|
|
3367
|
+
for (let k = 0; k < values.length; k++)
|
|
3368
|
+
if (!Number.isFinite(values[k]))
|
|
3369
|
+
fail(`${call}() got a value that is not a number.`);
|
|
3370
|
+
const { speed, time } = keyframes;
|
|
3371
|
+
if (speed !== undefined)
|
|
3372
|
+
checkNumber(call, 'speed', speed, target);
|
|
3373
|
+
if (time !== undefined)
|
|
3374
|
+
checkNumber(call, 'time', time, target);
|
|
3375
|
+
}
|
|
3376
|
+
const system = this.propertySystem();
|
|
3377
|
+
const { what, name, components } = property;
|
|
3378
|
+
const binding = { what, name, components, base: new Float32Array(components) };
|
|
3379
|
+
const track = {
|
|
3380
|
+
binding: 0,
|
|
3381
|
+
interpolation,
|
|
3382
|
+
times: Float32Array.from(times),
|
|
3383
|
+
values: Float32Array.from(values),
|
|
3384
|
+
};
|
|
3385
|
+
const animation = new PropertyAnimation(system, target, binding, track, keyframes);
|
|
3386
|
+
system.add(animation);
|
|
3387
|
+
return animation;
|
|
3388
|
+
}
|
|
3389
|
+
/** @internal The scene's property animations, which the first one makes. */
|
|
3390
|
+
propertySystem() {
|
|
3391
|
+
this.properties ??= new PropertySystem(writeProperty);
|
|
3392
|
+
return this.properties;
|
|
3393
|
+
}
|
|
3394
|
+
/**
|
|
3395
|
+
* Copies an object and every object below it, with their meshes, materials, lights, cameras
|
|
3396
|
+
* and settings, and returns the copy of the object. The copy has the same parent, so it starts
|
|
3397
|
+
* in the same place. The copies are created with one batch of commands. An animated object's
|
|
3398
|
+
* copy gets an animator of its own, with no clip playing, which moves the copies of its meshes.
|
|
3399
|
+
* Instance batches are not objects, so they are not copied. Throws E1102 when the scene or the
|
|
3400
|
+
* animation table has no room for the copies. Then no copy stays.
|
|
3401
|
+
*/
|
|
3402
|
+
clone(object) {
|
|
3403
|
+
const call = 'clone';
|
|
3404
|
+
if (DEV)
|
|
3405
|
+
checkLive(call, object);
|
|
3406
|
+
const nodes = this.subtree(object);
|
|
3407
|
+
const objects = this.createNodes(nodes, call, object.liveParent);
|
|
3408
|
+
const copy = objects[0];
|
|
3409
|
+
if (copy instanceof PrefabInstance)
|
|
3410
|
+
copy.objects = objects;
|
|
3411
|
+
// Animated objects in the tree give their copies animators, which skin the copied meshes.
|
|
3412
|
+
const copies = new Map(nodes.map((node, k) => [node.source, objects[k]]));
|
|
3413
|
+
try {
|
|
3414
|
+
for (const [source, made] of copies)
|
|
3415
|
+
source.animation?.copyTo(made, copies);
|
|
3416
|
+
}
|
|
3417
|
+
catch (error) {
|
|
3418
|
+
// The animation table is full: the copies go, so the sketch holds none it cannot reach.
|
|
3419
|
+
for (const made of objects)
|
|
3420
|
+
if (made.destroyedFrame < 0)
|
|
3421
|
+
made.destroy();
|
|
3422
|
+
throw error;
|
|
3423
|
+
}
|
|
3424
|
+
return copy;
|
|
3425
|
+
}
|
|
3426
|
+
/**
|
|
3427
|
+
* The objects at and below `object` as template nodes, parents first, each with its object as
|
|
3428
|
+
* the source of its copy. It walks each object's children, so it visits only the tree.
|
|
3429
|
+
*/
|
|
3430
|
+
subtree(object) {
|
|
3431
|
+
const order = [object];
|
|
3432
|
+
const parents = [-1];
|
|
3433
|
+
for (let k = 0; k < order.length; k++)
|
|
3434
|
+
for (const child of order[k].childObjects ?? [])
|
|
3435
|
+
if (child.destroyedFrame < 0) {
|
|
3436
|
+
order.push(child);
|
|
3437
|
+
parents.push(k);
|
|
3438
|
+
}
|
|
3439
|
+
const v = this.views;
|
|
3440
|
+
return order.map((each, k) => {
|
|
3441
|
+
const row = each.row;
|
|
3442
|
+
const transform = new Float64Array(10);
|
|
3443
|
+
this.readPosition(row, transform);
|
|
3444
|
+
transform.set(v.rotations.subarray(row * 4, row * 4 + 4), 3);
|
|
3445
|
+
transform.set(v.scales.subarray(row * 3, row * 3 + 3), 7);
|
|
3446
|
+
const mesh = each instanceof Mesh ? each : undefined;
|
|
3447
|
+
const bounds = new Float32Array(4);
|
|
3448
|
+
bounds.set(v.centers.subarray(row * 3, row * 3 + 3));
|
|
3449
|
+
bounds[3] = v.radii[row];
|
|
3450
|
+
return {
|
|
3451
|
+
name: each.name,
|
|
3452
|
+
parent: parents[k],
|
|
3453
|
+
transform,
|
|
3454
|
+
mesh: mesh?.mesh,
|
|
3455
|
+
material: mesh?.material,
|
|
3456
|
+
flags: each.flags,
|
|
3457
|
+
layers: each.layerMask,
|
|
3458
|
+
renderOrder: mesh?.renderOrder ?? 0,
|
|
3459
|
+
levelBias: mesh?.levelBias ?? 1,
|
|
3460
|
+
bounds,
|
|
3461
|
+
source: each,
|
|
3462
|
+
};
|
|
3463
|
+
});
|
|
3464
|
+
}
|
|
3465
|
+
/**
|
|
3466
|
+
* Creates an object for each template node, with one core call that reserves their slots and
|
|
3467
|
+
* one batch of command records, and returns them in the nodes' order. A node whose parent is -1
|
|
3468
|
+
* goes under `parent`. `root`, when given, takes the place of the first node, `extra` adds
|
|
3469
|
+
* flags to every node with a mesh, and `cleared` takes flags away from them. Throws E1102 before it creates anything when the scene or
|
|
3470
|
+
* the command ring has no room.
|
|
3471
|
+
*/
|
|
3472
|
+
createNodes(nodes, call, parent, root, extra = 0, cleared = 0) {
|
|
3473
|
+
const count = nodes.length;
|
|
3474
|
+
const node = (k) => (k === 0 && root ? root : nodes[k]);
|
|
3475
|
+
let records = 0;
|
|
3476
|
+
for (let k = 0; k < count; k++) {
|
|
3477
|
+
const { mesh, layers, renderOrder, levelBias } = node(k);
|
|
3478
|
+
records += 1 + (mesh ? 1 : 0) + (layers !== C.LAYERS_DEFAULT ? 1 : 0);
|
|
3479
|
+
if (mesh && mesh.morphTargets > 0)
|
|
3480
|
+
records++;
|
|
3481
|
+
if (renderOrder !== 0)
|
|
3482
|
+
records++;
|
|
3483
|
+
if (levelBias !== 1)
|
|
3484
|
+
records++;
|
|
3485
|
+
}
|
|
3486
|
+
let write = this.reserveCommands(records, call);
|
|
3487
|
+
const { core } = this;
|
|
3488
|
+
const at = core.checkGrowth(core.glue.reserveObjects(count), call);
|
|
3489
|
+
const handles = core.u32(at, count).slice();
|
|
3490
|
+
const objects = [];
|
|
3491
|
+
for (let k = 0; k < count; k++) {
|
|
3492
|
+
// A light's creation below can grow the memory, so each node takes the views anew.
|
|
3493
|
+
const v = this.views;
|
|
3494
|
+
const n = node(k);
|
|
3495
|
+
const handle = handles[k];
|
|
3496
|
+
const slot = handle & SLOT_MASK;
|
|
3497
|
+
const t = n.transform;
|
|
3498
|
+
this.writePosition(slot, t[0], t[1], t[2]);
|
|
3499
|
+
for (let i = 0; i < 3; i++)
|
|
3500
|
+
v.scales[slot * 3 + i] = t[7 + i];
|
|
3501
|
+
for (let i = 0; i < 4; i++)
|
|
3502
|
+
v.rotations[slot * 4 + i] = t[3 + i];
|
|
3503
|
+
const flags = n.mesh ? (n.flags | extra) & ~cleared : n.flags;
|
|
3504
|
+
const bounds = n.bounds;
|
|
3505
|
+
if (bounds && flags & C.FLAG_CUSTOM_BOUNDS) {
|
|
3506
|
+
for (let i = 0; i < 3; i++)
|
|
3507
|
+
v.centers[slot * 3 + i] = bounds[i];
|
|
3508
|
+
v.radii[slot] = bounds[3];
|
|
3509
|
+
}
|
|
3510
|
+
else {
|
|
3511
|
+
const center = n.mesh?.center ?? ORIGIN;
|
|
3512
|
+
for (let i = 0; i < 3; i++)
|
|
3513
|
+
v.centers[slot * 3 + i] = center[i];
|
|
3514
|
+
v.radii[slot] = (n.mesh?.radius ?? 0) + (n.material?.boundsMargin ?? 0);
|
|
3515
|
+
}
|
|
3516
|
+
const up = n.parent < 0 ? (parent?.handle ?? 0) : handles[n.parent];
|
|
3517
|
+
const mesh = n.mesh?.id ?? C.CORE_NO_MESH;
|
|
3518
|
+
this.writeCommand(write++, C.COMMAND_CREATE | (flags << 8), handle, up, mesh);
|
|
3519
|
+
if (n.mesh && n.material)
|
|
3520
|
+
this.writeCommand(write++, C.COMMAND_SET_MATERIAL, handle, n.material.id, 0);
|
|
3521
|
+
if (n.layers !== C.LAYERS_DEFAULT)
|
|
3522
|
+
this.writeCommand(write++, C.COMMAND_SET_LAYERS, handle, n.layers, 0);
|
|
3523
|
+
if (n.renderOrder !== 0) {
|
|
3524
|
+
const bits = this.floatBits(n.renderOrder);
|
|
3525
|
+
this.writeCommand(write++, C.COMMAND_SET_RENDER_ORDER, handle, bits, 0);
|
|
3526
|
+
}
|
|
3527
|
+
if (n.levelBias !== 1) {
|
|
3528
|
+
const bits = this.floatBits(n.levelBias);
|
|
3529
|
+
this.writeCommand(write++, C.COMMAND_SET_LEVEL_BIAS, handle, bits, 0);
|
|
3530
|
+
}
|
|
3531
|
+
const object = this.makeObject(n, handle, call);
|
|
3532
|
+
if (n.mesh && n.mesh.morphTargets > 0) {
|
|
3533
|
+
const source = n.source;
|
|
3534
|
+
const weights = source ? this.morphWeightsOf(source) : n.morph?.weights;
|
|
3535
|
+
const block = this.makeMorph(object, n.mesh, weights, call);
|
|
3536
|
+
this.writeCommand(write++, C.COMMAND_SET_MORPH, handle, block, 0);
|
|
3537
|
+
if (n.morph)
|
|
3538
|
+
object.morphJoint = n.morph.joint;
|
|
3539
|
+
}
|
|
3540
|
+
object.attachTo(n.parent < 0 ? parent : objects[n.parent]);
|
|
3541
|
+
object.flags = flags;
|
|
3542
|
+
object.layerMask = n.layers;
|
|
3543
|
+
objects.push(object);
|
|
3544
|
+
}
|
|
3545
|
+
this.publishCommands(write);
|
|
3546
|
+
for (const object of objects) {
|
|
3547
|
+
this.remember(object);
|
|
3548
|
+
if (DEV)
|
|
3549
|
+
this.unmarkedWrites?.watch(object, (object.flags & C.FLAG_DYNAMIC) === 0);
|
|
3550
|
+
}
|
|
3551
|
+
return objects;
|
|
3552
|
+
}
|
|
3553
|
+
/** The wrapper of a new object for a template node, with the light row that a light needs. */
|
|
3554
|
+
makeObject(node, handle, call) {
|
|
3555
|
+
const { name, light } = node;
|
|
3556
|
+
if (node.root)
|
|
3557
|
+
return new PrefabInstance(this, handle, name);
|
|
3558
|
+
if (node.source)
|
|
3559
|
+
return node.source.twin(handle);
|
|
3560
|
+
if (light) {
|
|
3561
|
+
const kind = LIGHT_CLASSES[light.kind];
|
|
3562
|
+
const object = new kind(this, handle, name);
|
|
3563
|
+
const { core } = this;
|
|
3564
|
+
object.id = core.checkGrowth(core.glue.createLight(handle, light.kind), call, name);
|
|
3565
|
+
object.linear.set(light.color);
|
|
3566
|
+
const values = core.callValues();
|
|
3567
|
+
values.set(light.color);
|
|
3568
|
+
core.glue.setLightColor(object.id, C.LIGHT_COLOR_MAIN);
|
|
3569
|
+
for (const [which, value] of light.values) {
|
|
3570
|
+
values[0] = value;
|
|
3571
|
+
core.glue.setLightValue(object.id, which);
|
|
3572
|
+
}
|
|
3573
|
+
return object;
|
|
3574
|
+
}
|
|
3575
|
+
if (!node.mesh)
|
|
3576
|
+
return new Group(this, handle, name);
|
|
3577
|
+
const mesh = new Mesh(this, handle, name);
|
|
3578
|
+
mesh.mesh = node.mesh;
|
|
3579
|
+
mesh.material = node.material;
|
|
3580
|
+
mesh.renderOrder = node.renderOrder;
|
|
3581
|
+
mesh.levelBias = node.levelBias;
|
|
3582
|
+
return mesh;
|
|
3583
|
+
}
|
|
3584
|
+
/**
|
|
3585
|
+
* The instance batch of a node of a model with instancing of its own. Each row takes its
|
|
3586
|
+
* transform from the file, after the node's place in the world when the copy is created. The
|
|
3587
|
+
* node's place is the batch's origin, so the rows keep their precision far from the world's
|
|
3588
|
+
* origin. The copy's layers and shadow options reach every row.
|
|
3589
|
+
*/
|
|
3590
|
+
placeInstancing(instance, spec, call, { layers, castShadows, receiveShadows, occluder }) {
|
|
3591
|
+
const v = this.views;
|
|
3592
|
+
const world = identityMatrix(new Float64Array(16));
|
|
3593
|
+
const local = new Float64Array(16);
|
|
3594
|
+
const position = [0, 0, 0];
|
|
3595
|
+
const rotation = [0, 0, 0, 1];
|
|
3596
|
+
const scale = [1, 1, 1];
|
|
3597
|
+
const trs = (p, q, s, row) => composeMatrix(local, p, q.subarray(row * 4, row * 4 + 4), s.subarray(row * 3, row * 3 + 3));
|
|
3598
|
+
let object = instance.objects[spec.node];
|
|
3599
|
+
while (object) {
|
|
3600
|
+
this.readPosition(object.row, position);
|
|
3601
|
+
multiplyMatrices(world, trs(position, v.rotations, v.scales, object.row), world);
|
|
3602
|
+
object = object.liveParent;
|
|
3603
|
+
}
|
|
3604
|
+
const origin = [world[12], world[13], world[14]];
|
|
3605
|
+
const batch = this.createParts(spec.parts, spec.count, { origin, layers, castShadows, receiveShadows, occluder }, call);
|
|
3606
|
+
const { positions, rotations, scales } = batch;
|
|
3607
|
+
for (let r = 0; r < spec.count; r++) {
|
|
3608
|
+
trs(spec.positions.subarray(r * 3, r * 3 + 3), spec.rotations, spec.scales, r);
|
|
3609
|
+
decompose(position, rotation, scale, multiplyMatrices(local, world, local));
|
|
3610
|
+
for (let k = 0; k < 3; k++)
|
|
3611
|
+
position[k] = position[k] - origin[k];
|
|
3612
|
+
positions.set(position, r * 3);
|
|
3613
|
+
rotations.set(rotation, r * 4);
|
|
3614
|
+
scales.set(scale, r * 3);
|
|
3615
|
+
}
|
|
3616
|
+
batch.markDirty();
|
|
3617
|
+
return batch;
|
|
3618
|
+
}
|
|
3619
|
+
/**
|
|
3620
|
+
* One instance batch for each part of a model, which share one set of rows: the first part owns
|
|
3621
|
+
* them, and the others read them.
|
|
3622
|
+
*/
|
|
3623
|
+
createParts(parts, count, options, call) {
|
|
3624
|
+
const { core } = this;
|
|
3625
|
+
const own = rowValueArrays(options);
|
|
3626
|
+
const ids = [];
|
|
3627
|
+
try {
|
|
3628
|
+
for (const part of parts)
|
|
3629
|
+
ids.push(core.checkGrowth(core.glue.createBatchPart(ids[0] ?? 0, count, options.dynamic ?? false, own !== NO_ROW_VALUES, part.mesh.id, part.material.id, part.matrix), call));
|
|
3630
|
+
}
|
|
3631
|
+
catch (error) {
|
|
3632
|
+
for (const id of ids.reverse())
|
|
3633
|
+
core.glue.destroyBatch(id, this.frame);
|
|
3634
|
+
throw error;
|
|
3635
|
+
}
|
|
3636
|
+
if (DEV)
|
|
3637
|
+
this.countBatchRows(count * ids.length);
|
|
3638
|
+
const uses = { meshes: parts.map((p) => p.mesh), materials: parts.map((p) => p.material) };
|
|
3639
|
+
const batch = new InstanceBatch(this, ids[0], count, own, ids.slice(1), uses);
|
|
3640
|
+
this.rememberBatch(batch);
|
|
3641
|
+
if (DEV && !options.dynamic)
|
|
3642
|
+
this.unmarkedRows?.watch(batch, meshRowFields(own));
|
|
3643
|
+
if (options.layers !== undefined)
|
|
3644
|
+
batch.setLayers(options.layers);
|
|
3645
|
+
if (options.castShadows)
|
|
3646
|
+
batch.setCastShadows(true);
|
|
3647
|
+
if (options.receiveShadows)
|
|
3648
|
+
batch.setReceiveShadows(true);
|
|
3649
|
+
if (options.occluder === false)
|
|
3650
|
+
batch.setOccluder(false);
|
|
3651
|
+
if (options.origin)
|
|
3652
|
+
batch.setOrigin(options.origin, call);
|
|
3653
|
+
return batch;
|
|
3654
|
+
}
|
|
3655
|
+
createInstances(source, count, options = {}) {
|
|
3656
|
+
const call = 'createInstances';
|
|
3657
|
+
const { core } = this;
|
|
3658
|
+
const { layers } = options;
|
|
3659
|
+
if (DEV && layers !== undefined)
|
|
3660
|
+
checkLayers(call, layers);
|
|
3661
|
+
if ('template' in source) {
|
|
3662
|
+
source.checkLive(call);
|
|
3663
|
+
const problem = source.instancing.length > 0
|
|
3664
|
+
? 'has instancing of its own. Use scene.instantiate for it'
|
|
3665
|
+
: source.parts.length === 0
|
|
3666
|
+
? 'has no meshes'
|
|
3667
|
+
: undefined;
|
|
3668
|
+
if (problem)
|
|
3669
|
+
throw new EngineError('E1417', `${call}() got ${source.describe()}, which ${problem}.`);
|
|
3670
|
+
if (DEV && source.parts.some((part) => part.bindPose))
|
|
3671
|
+
console.warn(`${call}() draws the skinned meshes of ${source.describe()} in their bind pose, because their rest pose differs from it and batches do not skin. Use scene.instantiate to draw them at rest.`);
|
|
3672
|
+
return this.createParts(source.parts, count, options, call);
|
|
3673
|
+
}
|
|
3674
|
+
const mesh = source;
|
|
3675
|
+
const material = options.material;
|
|
3676
|
+
const own = rowValueArrays(options);
|
|
3677
|
+
const id = core.checkGrowth(core.glue.createBatch(count, options.dynamic ?? false, own !== NO_ROW_VALUES, mesh.id, material.id), call);
|
|
3678
|
+
if (DEV)
|
|
3679
|
+
this.countBatchRows(count);
|
|
3680
|
+
const batch = new InstanceBatch(this, id, count, own, [], {
|
|
3681
|
+
meshes: [mesh],
|
|
3682
|
+
materials: [material],
|
|
3683
|
+
});
|
|
3684
|
+
mesh.drawnWith(material, count, call);
|
|
3685
|
+
this.rememberBatch(batch);
|
|
3686
|
+
if (DEV && !options.dynamic)
|
|
3687
|
+
this.unmarkedRows?.watch(batch, meshRowFields(own));
|
|
3688
|
+
batch.setActiveCount(count);
|
|
3689
|
+
if (layers !== undefined)
|
|
3690
|
+
batch.setLayers(layers);
|
|
3691
|
+
if (options.castShadows)
|
|
3692
|
+
batch.setCastShadows(true);
|
|
3693
|
+
if (options.receiveShadows)
|
|
3694
|
+
batch.setReceiveShadows(true);
|
|
3695
|
+
if (options.occluder === false)
|
|
3696
|
+
batch.setOccluder(false);
|
|
3697
|
+
if (options.origin)
|
|
3698
|
+
batch.setOrigin(options.origin, call);
|
|
3699
|
+
return batch;
|
|
3700
|
+
}
|
|
3701
|
+
/**
|
|
3702
|
+
* Many sprites in one batch: quads that face the camera. Typed arrays give each sprite its
|
|
3703
|
+
* position, size, rotation, color and atlas frame, as an instance batch's arrays give its rows.
|
|
3704
|
+
* Sprites blend by default, and blended sprites draw back to front with the other blended
|
|
3705
|
+
* objects. The first call downloads the sprite code. Throws E1108 for an atlas side that is not
|
|
3706
|
+
* a whole number from 1 to 2048, E1203 for a center that is not two finite numbers, and E1406
|
|
3707
|
+
* when the sprite code does not download.
|
|
3708
|
+
*/
|
|
3709
|
+
async createSprites(options) {
|
|
3710
|
+
const call = 'createSprites';
|
|
3711
|
+
const { columns = 1, rows = 1 } = options.atlas ?? {};
|
|
3712
|
+
for (const [name, side] of [
|
|
3713
|
+
['columns', columns],
|
|
3714
|
+
['rows', rows],
|
|
3715
|
+
])
|
|
3716
|
+
if (!Number.isInteger(side) || side < 1 || side > C.SPRITE_MAX_ATLAS_SIDE)
|
|
3717
|
+
throw new EngineError('E1108', `${call}() got ${side} atlas ${name}. An atlas has from 1 to ${C.SPRITE_MAX_ATLAS_SIDE} whole ${name}.`);
|
|
3718
|
+
const { center } = options;
|
|
3719
|
+
if (DEV && center && !(Number.isFinite(center[0]) && Number.isFinite(center[1])))
|
|
3720
|
+
throw new EngineError('E1203', `${call}() got [${center}] for center.`);
|
|
3721
|
+
const [, batch] = await this.spriteBatch(call, options.count, options, [columns, rows], false);
|
|
3722
|
+
return batch;
|
|
3723
|
+
}
|
|
3724
|
+
/**
|
|
3725
|
+
* Many points in one batch: squares that face the camera, all of one size. Each point is a
|
|
3726
|
+
* sprite: typed arrays give each point its position and color, as an instance batch's arrays
|
|
3727
|
+
* give its rows. Sizes above one pixel work on every GPU path. Points are opaque by default, and
|
|
3728
|
+
* blended points draw back to front with the other blended objects. The first call downloads
|
|
3729
|
+
* the sprite code. Throws E1206 for points or colors that make no points, E1108 for a size that
|
|
3730
|
+
* is not above 0, E1203 for a size that is not finite, and E1406 when the sprite code does not
|
|
3731
|
+
* download.
|
|
3732
|
+
*/
|
|
3733
|
+
async createPoints(options) {
|
|
3734
|
+
const call = 'createPoints';
|
|
3735
|
+
const { positions, colors, size = 1 } = options;
|
|
3736
|
+
const count = pointCount(call, positions, colors);
|
|
3737
|
+
POINT_CHECKS.size(size, call);
|
|
3738
|
+
const [sprites, batch, instances] = await this.spriteBatch(call, count, options, [1, 1], true);
|
|
3739
|
+
const points = sprites.pointBatch(batch, POINT_CHECKS, positions, colors, size);
|
|
3740
|
+
instances.face = points;
|
|
3741
|
+
return points;
|
|
3742
|
+
}
|
|
3743
|
+
/**
|
|
3744
|
+
* An add-on's own kind of draw, declared by a feature description with the kind `'draw'`: its
|
|
3745
|
+
* WGSL, its vertex data, its uniforms and the description's frame point, band and order. The
|
|
3746
|
+
* engine draws the object on every GPU path and in every thread mode, as it draws the scene's
|
|
3747
|
+
* other objects, and sorts a blended draw among the transparent pass's objects. The first call
|
|
3748
|
+
* downloads the draw adapter.
|
|
3749
|
+
*
|
|
3750
|
+
* The description names the frame point: `'opaque'` with an opaque or masked material,
|
|
3751
|
+
* `'transparent'` with a blended one, or `'resolve'` with a blended one that blends after the
|
|
3752
|
+
* transparent pass's objects. With MSAA, a draw at `'resolve'` blends its surfaces back to
|
|
3753
|
+
* front in a layer of one sample per pixel, which the engine then blends over the scene, so
|
|
3754
|
+
* many overlapping surfaces, such as Gaussian splats, cost one blend per pixel instead of one
|
|
3755
|
+
* per sample. Its surfaces show in front of every object of the transparent pass, and other
|
|
3756
|
+
* views draw them in their own transparent pass. The band and order place a blended draw among
|
|
3757
|
+
* the pass's objects. The adapter records in the main view alone, so a description with
|
|
3758
|
+
* another view throws E1223. The description's `reads`, `writes`, `outputs` and `provides`
|
|
3759
|
+
* stay with the feature registry: this draw draws no scene resource.
|
|
3760
|
+
*
|
|
3761
|
+
* Throws E1223 for a description that is not a draw the adapter can place, E1215, E1216 and
|
|
3762
|
+
* E1217 for WGSL and values that `materials.shader` refuses, E1206 for vertex data that makes no
|
|
3763
|
+
* mesh, and E1406 when the adapter does not download.
|
|
3764
|
+
*/
|
|
3765
|
+
async addFeatureDraw(description, options) {
|
|
3766
|
+
const call = 'addFeatureDraw';
|
|
3767
|
+
const { makers } = this;
|
|
3768
|
+
if (!makers)
|
|
3769
|
+
throw new Error(`${call}() needs a scene that the engine made`);
|
|
3770
|
+
const draws = await loadFeatureDraws(call);
|
|
3771
|
+
return draws.createFeatureDraw(description, options, {
|
|
3772
|
+
geometry: makers.geometry,
|
|
3773
|
+
materials: makers.materials,
|
|
3774
|
+
createMesh: (mesh, material, place) => this.createMesh({ mesh, material, ...place }),
|
|
3775
|
+
createInstances: (mesh, count, options) => this.createInstances(mesh, count, options),
|
|
3776
|
+
fail: (detail) => new EngineError('E1223', detail),
|
|
3777
|
+
}, call);
|
|
3778
|
+
}
|
|
3779
|
+
/**
|
|
3780
|
+
* An add-on's own kind of draw, repeated once for each row of an instance batch, declared by a
|
|
3781
|
+
* feature description with the kind `'draw'`. It takes the options of `addFeatureDraw` and a
|
|
3782
|
+
* number of copies; each row of `draw.batch` places one copy and brings its own color and four
|
|
3783
|
+
* values. The engine culls and sorts the rows in each view as it does a batch's, so a blended
|
|
3784
|
+
* draw of many copies draws back to front on both GPU paths.
|
|
3785
|
+
*
|
|
3786
|
+
* Throws E1223 for a description that the adapter cannot place, for a place that belongs to one
|
|
3787
|
+
* object, or for a count that is not a whole number from 1 up, E1215, E1216 and E1217 for WGSL
|
|
3788
|
+
* and values that `materials.shader` refuses, E1206 for vertex data that makes no mesh, and
|
|
3789
|
+
* E1406 when the adapter does not download.
|
|
3790
|
+
*/
|
|
3791
|
+
async addFeatureInstances(description, options) {
|
|
3792
|
+
const call = 'addFeatureInstances';
|
|
3793
|
+
const { makers } = this;
|
|
3794
|
+
if (!makers)
|
|
3795
|
+
throw new Error(`${call}() needs a scene that the engine made`);
|
|
3796
|
+
// A batch of feature instances takes its rows in chunks, and its first `createChunkRows`
|
|
3797
|
+
// comes right after this call. Its code, which is small, downloads beside the draw adapter
|
|
3798
|
+
// rather than one round trip after it. A failure waits for the call that needs the code.
|
|
3799
|
+
import('./chunk-rows.js').catch(() => { });
|
|
3800
|
+
const draws = await loadFeatureDraws(call);
|
|
3801
|
+
return draws.createFeatureInstances(description, options, {
|
|
3802
|
+
geometry: makers.geometry,
|
|
3803
|
+
materials: makers.materials,
|
|
3804
|
+
createMesh: (mesh, material, place) => this.createMesh({ mesh, material, ...place }),
|
|
3805
|
+
createInstances: (mesh, count, options) => this.createInstances(mesh, count, options),
|
|
3806
|
+
fail: (detail) => new EngineError('E1223', detail),
|
|
3807
|
+
}, call);
|
|
3808
|
+
}
|
|
3809
|
+
/**
|
|
3810
|
+
* An add-on's own kind of draw whose instance count the GPU writes: the description places it,
|
|
3811
|
+
* the options give its one shape, its shader and the most instances that it holds, and the
|
|
3812
|
+
* add-on fills its per-instance data. On WebGPU the draw reads the add-on's instance buffer and
|
|
3813
|
+
* the count word that its compute pass writes; the engine copies the count into the indirect
|
|
3814
|
+
* draw each frame. WebGL2 has no compute, so the page sets the instances and the count on the
|
|
3815
|
+
* CPU, which draws the same picture.
|
|
3816
|
+
*
|
|
3817
|
+
* The description names the frame point `'opaque'` and the main view alone. The draw is
|
|
3818
|
+
* unculled: the add-on's own cull or count decides what draws. The first call downloads the
|
|
3819
|
+
* adapter.
|
|
3820
|
+
*
|
|
3821
|
+
* Throws E1223 for a description that the adapter cannot place or a capacity that it cannot
|
|
3822
|
+
* take, E1215, E1216 and E1217 for WGSL and values that `materials.shader` refuses, E1206 for
|
|
3823
|
+
* vertex data that makes no mesh, and E1406 when the adapter does not download. A draw that
|
|
3824
|
+
* arrives after the first frame on a device that draws directly fails the frame with E1506:
|
|
3825
|
+
* create it in the setup, and await this call there.
|
|
3826
|
+
*/
|
|
3827
|
+
async addComputeInstances(description, options) {
|
|
3828
|
+
const call = 'addComputeInstances';
|
|
3829
|
+
const { makers, core } = this;
|
|
3830
|
+
if (!makers)
|
|
3831
|
+
throw new Error(`${call}() needs a scene that the engine made`);
|
|
3832
|
+
const draws = await loadFeatureInstances(call);
|
|
3833
|
+
return draws.createComputeInstances(description, options, {
|
|
3834
|
+
webgl2: this.webgl2,
|
|
3835
|
+
core,
|
|
3836
|
+
geometry: makers.geometry,
|
|
3837
|
+
materials: makers.materials,
|
|
3838
|
+
createMesh: (mesh, material, place) => this.createMesh({ mesh, material, ...place }),
|
|
3839
|
+
createBatch: (mesh, material, count) => this.createInstances(mesh, count, { material }),
|
|
3840
|
+
watchReady: (poll) => this.watchReady(poll),
|
|
3841
|
+
fail: (detail) => new EngineError('E1223', detail),
|
|
3842
|
+
}, call);
|
|
3843
|
+
}
|
|
3844
|
+
/**
|
|
3845
|
+
* @internal Asks `poll` before each frame's work, and forgets it when the returned function is
|
|
3846
|
+
* called. A feature-instance draw reports each frame whether its feature's `ready` callback
|
|
3847
|
+
* says that it draws.
|
|
3848
|
+
*/
|
|
3849
|
+
watchReady(poll) {
|
|
3850
|
+
this.readiness.push(poll);
|
|
3851
|
+
return () => {
|
|
3852
|
+
const at = this.readiness.indexOf(poll);
|
|
3853
|
+
if (at >= 0)
|
|
3854
|
+
this.readiness.splice(at, 1);
|
|
3855
|
+
};
|
|
3856
|
+
}
|
|
3857
|
+
/**
|
|
3858
|
+
* @internal Asks each feature draw whether it draws now. The sketch's thread calls it before
|
|
3859
|
+
* the frame's commands, so a feature that stops drawing takes no room in that frame.
|
|
3860
|
+
*/
|
|
3861
|
+
pollReadiness() {
|
|
3862
|
+
const polls = this.readiness;
|
|
3863
|
+
for (let k = 0; k < polls.length; k++)
|
|
3864
|
+
polls[k]?.();
|
|
3865
|
+
}
|
|
3866
|
+
/**
|
|
3867
|
+
* Downloads the sprite code on first use, and creates a sprite batch of `count` rows with the
|
|
3868
|
+
* look, layers and origin of `options` and an atlas of `columns` by `rows` frames. A batch of
|
|
3869
|
+
* `points` is opaque when the options give no alpha mode, and sprites blend. Returns the batch
|
|
3870
|
+
* and the instance batch that holds its rows.
|
|
3871
|
+
*/
|
|
3872
|
+
async spriteBatch(call, count, options, [columns, rows], points) {
|
|
3873
|
+
const alphaMode = points ? 'opaque' : 'blend';
|
|
3874
|
+
const { core, makers } = this;
|
|
3875
|
+
const { layers } = options;
|
|
3876
|
+
if (DEV && layers !== undefined)
|
|
3877
|
+
checkLayers(call, layers);
|
|
3878
|
+
if (!makers)
|
|
3879
|
+
throw new Error(`${call}() needs a scene that the engine made`);
|
|
3880
|
+
makers.materials.shaders.need('sprites');
|
|
3881
|
+
const sprites = await loadSprites(call);
|
|
3882
|
+
const parts = sprites.spriteParts(makers, this.spriteQuads, options, [columns, rows], alphaMode, call);
|
|
3883
|
+
const id = core.checkGrowth(core.glue.createSpriteBatch(count, options.dynamic ?? false, parts.mesh.id, parts.material.id, columns, rows, options.sizeAttenuation === false, points), call);
|
|
3884
|
+
if (DEV)
|
|
3885
|
+
this.countBatchRows(count);
|
|
3886
|
+
const instances = new InstanceBatch(this, id, count, NO_ROW_VALUES, [], {
|
|
3887
|
+
meshes: [parts.mesh],
|
|
3888
|
+
materials: [parts.material],
|
|
3889
|
+
});
|
|
3890
|
+
this.rememberBatch(instances);
|
|
3891
|
+
if (DEV && !options.dynamic)
|
|
3892
|
+
this.unmarkedRows?.watch(instances, SPRITE_ROW_FIELDS);
|
|
3893
|
+
if (options.origin)
|
|
3894
|
+
instances.setOrigin(options.origin, call);
|
|
3895
|
+
const batch = new sprites.SpriteBatch(core, id, count, parts.material, instances);
|
|
3896
|
+
instances.face = batch;
|
|
3897
|
+
if (layers !== undefined)
|
|
3898
|
+
batch.setLayers(layers);
|
|
3899
|
+
return [sprites, batch, instances];
|
|
3900
|
+
}
|
|
3901
|
+
/**
|
|
3902
|
+
* A draw that has a custom material and a vertex count but no mesh data: its shader makes every
|
|
3903
|
+
* vertex of every copy from `@builtin(vertex_index)` and `@builtin(instance_index)`, so a draw
|
|
3904
|
+
* of 50,000 rain streaks uploads nothing in a frame. The draw's object gives its place, its
|
|
3905
|
+
* layers and the sphere that culls it. The engine writes no uniforms for its WGSL, so
|
|
3906
|
+
* `frame.time` moves its shapes.
|
|
3907
|
+
*
|
|
3908
|
+
* The draw blends, so it draws in the transparent pass. The options take every option of
|
|
3909
|
+
* `materials.shader` but the maps: a draw's WGSL declares no texture. The draw's culling sphere
|
|
3910
|
+
* holds every shape, or a shape that leaves it stops drawing. A draw that uses the camera's
|
|
3911
|
+
* position, such as rain around the camera, reads it in its WGSL, and `null3d::wrap` wraps a
|
|
3912
|
+
* position relative to the camera into a box.
|
|
3913
|
+
*
|
|
3914
|
+
* Throws E1108 for a count or a sphere that the draw cannot take, or when the scene holds the
|
|
3915
|
+
* most draws already, E1215 for WGSL that the plugin did not compile as a draw shader, and
|
|
3916
|
+
* E1217 for a texture or an alpha mode that a draw does not take.
|
|
3917
|
+
*/
|
|
3918
|
+
createVertexDraw(options) {
|
|
3919
|
+
const call = 'createVertexDraw';
|
|
3920
|
+
const { makers, core } = this;
|
|
3921
|
+
const { shader, vertices, instances, bounds, position, rotation, scale, layers, alphaMode, ...materialOptions } = options;
|
|
3922
|
+
if (!makers)
|
|
3923
|
+
throw new Error(`${call}() needs a scene that the engine made`);
|
|
3924
|
+
// A draw computes its vertices, so its WGSL has the draw shader's entry points, which the
|
|
3925
|
+
// plugin compiles as a custom material that reads no vertex buffer.
|
|
3926
|
+
if (typeof shader !== 'object' || shader.kind !== 'material' || shader.meshless !== true)
|
|
3927
|
+
throw new EngineError('E1215', `${call}() got WGSL that is not a draw shader. Give it one @vertex entry point that takes the vertex and instance indices, as @builtin(vertex_index) and @builtin(instance_index), and one @fragment entry point.`);
|
|
3928
|
+
if (alphaMode !== undefined && alphaMode !== 'blend')
|
|
3929
|
+
throw new EngineError('E1217', `${call}() got the alpha mode '${alphaMode}'. A draw blends, so its material draws in the transparent pass, where its sphere culls it.`);
|
|
3930
|
+
if (materialOptions.blending === 'weighted')
|
|
3931
|
+
throw new EngineError('E1217', `${call}() got the weighted blending. A draw blends in the transparent pass, so it takes 'normal', 'additive' or 'multiply'.`);
|
|
3932
|
+
const mostVertices = C.VERTEX_DRAW_MAX_VERTICES;
|
|
3933
|
+
const mostInstances = C.VERTEX_DRAW_MAX_INSTANCES;
|
|
3934
|
+
if (!Number.isInteger(vertices) || vertices < 1 || vertices > mostVertices)
|
|
3935
|
+
throw new EngineError('E1108', `${call}() got ${vertices} vertices. A draw makes from 1 to ${mostVertices} vertices for each copy.`);
|
|
3936
|
+
if (!Number.isInteger(instances) || instances < 1 || instances > mostInstances)
|
|
3937
|
+
throw new EngineError('E1108', `${call}() got ${instances} copies. A draw makes from 1 to ${mostInstances} copies of its shape.`);
|
|
3938
|
+
if (bounds === undefined || !(bounds.radius > 0) || !Number.isFinite(bounds.radius))
|
|
3939
|
+
throw new EngineError('E1108', `${call}() got the sphere radius ${bounds?.radius}. Give the bounds, with the radius that holds every shape of the draw, above 0.`);
|
|
3940
|
+
if (DEV && layers !== undefined)
|
|
3941
|
+
checkLayers(call, layers);
|
|
3942
|
+
if (this.vertexDraws >= C.VERTEX_DRAW_MAX_DRAWS)
|
|
3943
|
+
throw new EngineError('E1108', `${call}() found ${C.VERTEX_DRAW_MAX_DRAWS} draws in the scene, the most it holds. Destroy one first.`);
|
|
3944
|
+
const material = makers.materials.shader({
|
|
3945
|
+
...materialOptions,
|
|
3946
|
+
// The check above narrowed the value to an object; the option keeps the caller's type.
|
|
3947
|
+
wgsl: shader,
|
|
3948
|
+
alphaMode: 'blend',
|
|
3949
|
+
});
|
|
3950
|
+
this.vertexDrawMesh ??= makers.geometry.fromArrays({
|
|
3951
|
+
positions: new Float32Array([0, 0, 0, 0, 0, 0, 0, 0, 0]),
|
|
3952
|
+
normals: new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1]),
|
|
3953
|
+
indices: [0, 1, 2],
|
|
3954
|
+
});
|
|
3955
|
+
const object = this.createMesh({
|
|
3956
|
+
mesh: this.vertexDrawMesh,
|
|
3957
|
+
material,
|
|
3958
|
+
position,
|
|
3959
|
+
rotation,
|
|
3960
|
+
scale,
|
|
3961
|
+
layers,
|
|
3962
|
+
});
|
|
3963
|
+
let id;
|
|
3964
|
+
try {
|
|
3965
|
+
id = core.checkGrowth(core.glue.createVertexDraw(object.slot, vertices, instances), call);
|
|
3966
|
+
}
|
|
3967
|
+
catch (error) {
|
|
3968
|
+
object.destroy();
|
|
3969
|
+
throw error;
|
|
3970
|
+
}
|
|
3971
|
+
this.vertexDraws++;
|
|
3972
|
+
const draw = new VertexDraw(core, id, object, material, call, vertices, instances);
|
|
3973
|
+
return draw.setBounds(bounds.center ?? [0, 0, 0], bounds.radius);
|
|
3974
|
+
}
|
|
3975
|
+
/**
|
|
3976
|
+
* A particle buffer: a scene object that draws a quad for each live particle, which the GPU
|
|
3977
|
+
* moves and colors at the particle's age in closed form. The `@null3d/particles` add-on's
|
|
3978
|
+
* emitters fill it; use the add-on rather than this call. The first call downloads the particle
|
|
3979
|
+
* code. Throws E1108 for a capacity that is not a whole number from 1 to 4,194,304, or when the
|
|
3980
|
+
* scene holds 256 particle buffers already, and E1406 when the particle code does not download.
|
|
3981
|
+
*/
|
|
3982
|
+
async createParticleBuffer(options) {
|
|
3983
|
+
const call = 'createParticleBuffer';
|
|
3984
|
+
const { core, makers } = this;
|
|
3985
|
+
const { capacity, layers } = options;
|
|
3986
|
+
if (!Number.isInteger(capacity) || capacity < 1 || capacity > C.PARTICLE_MAX_RECORDS)
|
|
3987
|
+
throw new EngineError('E1108', `${call}() got the capacity ${capacity}. A particle buffer holds from 1 to ${C.PARTICLE_MAX_RECORDS} whole particles.`);
|
|
3988
|
+
if (DEV && layers !== undefined)
|
|
3989
|
+
checkLayers(call, layers);
|
|
3990
|
+
if (!makers)
|
|
3991
|
+
throw new Error(`${call}() needs a scene that the engine made`);
|
|
3992
|
+
if (this.particleBuffers >= C.PARTICLE_MAX_SYSTEMS)
|
|
3993
|
+
throw new EngineError('E1108', `${call}() found ${C.PARTICLE_MAX_SYSTEMS} particle buffers in the scene, the most it holds. Destroy one first.`);
|
|
3994
|
+
makers.materials.shaders.need('particles');
|
|
3995
|
+
const particles = await loadParticles(call);
|
|
3996
|
+
const additive = options.blending !== 'normal';
|
|
3997
|
+
const material = makers.materials.create(C.SHADING_PARTICLE, {
|
|
3998
|
+
alphaMode: 'blend',
|
|
3999
|
+
blending: additive ? 'additive' : 'normal',
|
|
4000
|
+
depthWrite: false,
|
|
4001
|
+
doubleSided: true,
|
|
4002
|
+
forceSinglePass: true,
|
|
4003
|
+
map: options.map,
|
|
4004
|
+
}, `${call}.material`);
|
|
4005
|
+
this.particleMesh ??= makers.geometry.fromArrays({
|
|
4006
|
+
positions: new Float32Array([0, 0, 0, 0, 0, 0, 0, 0, 0]),
|
|
4007
|
+
normals: new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1]),
|
|
4008
|
+
indices: [0, 1, 2],
|
|
4009
|
+
});
|
|
4010
|
+
const object = this.createMesh({ mesh: this.particleMesh, material, layers });
|
|
4011
|
+
let id;
|
|
4012
|
+
try {
|
|
4013
|
+
id = core.checkGrowth(core.glue.createParticles(object.slot, capacity), call);
|
|
4014
|
+
}
|
|
4015
|
+
catch (error) {
|
|
4016
|
+
object.destroy();
|
|
4017
|
+
throw error;
|
|
4018
|
+
}
|
|
4019
|
+
this.particleBuffers++;
|
|
4020
|
+
const linear = (color) => linearColor(color, call);
|
|
4021
|
+
const buffer = new particles.ParticleBuffer(core, id, capacity, object, additive, linear);
|
|
4022
|
+
buffer.reset(options);
|
|
4023
|
+
return buffer;
|
|
4024
|
+
}
|
|
4025
|
+
/**
|
|
4026
|
+
* Lines of any width in one batch: strips, loops or separate segments. Each segment between two
|
|
4027
|
+
* points draws as a quad with round ends that faces the camera, `width` CSS pixels wide, or
|
|
4028
|
+
* world units wide with `worldUnits`. A typed array gives each point its position and color, as
|
|
4029
|
+
* an instance batch's arrays give its rows. The first call downloads the line code. Throws E1206
|
|
4030
|
+
* for points or colors that make no line, E1217 for an unknown mode, E1108 for a width that is
|
|
4031
|
+
* not positive or a dash or gap below 0, E1203 for a value that is not finite, and E1406 when the
|
|
4032
|
+
* line code does not download.
|
|
4033
|
+
*/
|
|
4034
|
+
async createLines(options) {
|
|
4035
|
+
const call = 'createLines';
|
|
4036
|
+
const { core, makers } = this;
|
|
4037
|
+
const { positions, colors, layers, mode = 'strip', width = 1 } = options;
|
|
4038
|
+
if (DEV && layers !== undefined)
|
|
4039
|
+
checkLayers(call, layers);
|
|
4040
|
+
const points = linePoints(call, mode, positions, colors);
|
|
4041
|
+
LINE_CHECKS.width(width, call);
|
|
4042
|
+
LINE_CHECKS.values(options, call);
|
|
4043
|
+
if (DEV && options.blending === 'weighted')
|
|
4044
|
+
throw new EngineError('E1217', `${call}() got the 'weighted' blending, which lines do not take. Give them the 'normal' blending, which draws back to front.`);
|
|
4045
|
+
if (!makers)
|
|
4046
|
+
throw new Error(`${call}() needs a scene that the engine made`);
|
|
4047
|
+
makers.materials.shaders.need('lines');
|
|
4048
|
+
const lines = await loadLines(call);
|
|
4049
|
+
const parts = lines.lineParts(makers, core, this.lineMesh, options, LINE_CHECKS, call);
|
|
4050
|
+
this.lineMesh = parts.mesh;
|
|
4051
|
+
const id = core.checkGrowth(core.glue.createLineBatch(points, options.dynamic ?? false, parts.mesh.id, parts.material.id, lines.modeCode(mode), width, options.worldUnits ?? false, options.dashed ?? false), call);
|
|
4052
|
+
const rows = LINE_SEGMENTS[mode](points);
|
|
4053
|
+
if (DEV)
|
|
4054
|
+
this.countBatchRows(rows);
|
|
4055
|
+
const instances = new InstanceBatch(this, id, rows, NO_ROW_VALUES, [], {
|
|
4056
|
+
meshes: [parts.mesh],
|
|
4057
|
+
materials: [],
|
|
4058
|
+
});
|
|
4059
|
+
this.rememberBatch(instances);
|
|
4060
|
+
if (options.origin)
|
|
4061
|
+
instances.setOrigin(options.origin, call);
|
|
4062
|
+
const batch = new lines.LineBatch(core, id, points, parts.material, instances, LINE_CHECKS);
|
|
4063
|
+
instances.face = batch;
|
|
4064
|
+
batch.positions.set(positions);
|
|
4065
|
+
if (colors)
|
|
4066
|
+
batch.colors.set(colors);
|
|
4067
|
+
if (layers !== undefined)
|
|
4068
|
+
batch.setLayers(layers);
|
|
4069
|
+
return batch;
|
|
4070
|
+
}
|
|
4071
|
+
/** A perspective camera; `fov` is vertical, in degrees. Cameras are dynamic by default. */
|
|
4072
|
+
createPerspectiveCamera(options = {}) {
|
|
4073
|
+
const call = 'createPerspectiveCamera';
|
|
4074
|
+
const { fov = DEFAULT_FOV, near = DEFAULT_NEAR, far = DEFAULT_FAR } = options;
|
|
4075
|
+
if (DEV) {
|
|
4076
|
+
const camera = newCamera(options.name);
|
|
4077
|
+
checkFov(call, fov, camera);
|
|
4078
|
+
checkNearFar(call, near, far, true, camera);
|
|
4079
|
+
}
|
|
4080
|
+
return this.createCamera(PerspectiveCamera, options, call, fov, near, far);
|
|
4081
|
+
}
|
|
4082
|
+
/**
|
|
4083
|
+
* An orthographic camera, whose view is a box: things keep their size at every distance. Give
|
|
4084
|
+
* `height`, and the width follows the canvas, or give `left`, `right`, `top` and `bottom`.
|
|
4085
|
+
* Cameras are dynamic by default.
|
|
4086
|
+
*/
|
|
4087
|
+
createOrthographicCamera(options = {}) {
|
|
4088
|
+
const call = 'createOrthographicCamera';
|
|
4089
|
+
const { near = DEFAULT_NEAR, far = DEFAULT_FAR } = options;
|
|
4090
|
+
if (DEV) {
|
|
4091
|
+
const camera = newCamera(options.name);
|
|
4092
|
+
checkOrthographicSize(call, options, camera);
|
|
4093
|
+
checkNearFar(call, near, far, false, camera);
|
|
4094
|
+
}
|
|
4095
|
+
const view = orthographicView(options);
|
|
4096
|
+
return this.createCamera(OrthographicCamera, options, call, view, near, far);
|
|
4097
|
+
}
|
|
4098
|
+
/**
|
|
4099
|
+
* Creates a camera of the given class with its lens settings, dynamic unless the options say
|
|
4100
|
+
* otherwise, gives it the options' layers to draw, and turns it toward the options' target.
|
|
4101
|
+
*/
|
|
4102
|
+
createCamera(kind, options, call, ...lens) {
|
|
4103
|
+
const node = { dynamic: true, ...options };
|
|
4104
|
+
// A view reads its camera's world transform even below a hidden object.
|
|
4105
|
+
const camera = this.create(kind, node, C.CORE_NO_MESH, 0, C.FLAG_TRACKED, 0, call, ORIGIN, ...lens);
|
|
4106
|
+
camera.layers = (options.layers ?? C.LAYERS_DEFAULT) >>> 0;
|
|
4107
|
+
if (options.target)
|
|
4108
|
+
camera.lookAt(...options.target);
|
|
4109
|
+
return camera;
|
|
4110
|
+
}
|
|
4111
|
+
/** Draws the scene from this camera. */
|
|
4112
|
+
setActiveCamera(camera) {
|
|
4113
|
+
this.activeCamera = camera;
|
|
4114
|
+
this.lensChanged(camera);
|
|
4115
|
+
}
|
|
4116
|
+
/**
|
|
4117
|
+
* Draws the scene again from `camera`, into the rectangle of the canvas that `rect` gives,
|
|
4118
|
+
* after the camera's view and in the same frame: a split screen or a picture in picture. The
|
|
4119
|
+
* view draws the scene once more at the rectangle's pixels, with its own culling, so its cost
|
|
4120
|
+
* follows the rectangle's area. It draws the sun and its shadows as the camera's view does,
|
|
4121
|
+
* which costs nothing more, the background and the fog. Its objects take no ambient occlusion
|
|
4122
|
+
* or screen-space reflections, which shade the camera's view; the camera's volumetric fog and
|
|
4123
|
+
* outline reach the whole image, a view's rectangle included. An object whose material shows a
|
|
4124
|
+
* render pass's texture does not draw in a view.
|
|
4125
|
+
*
|
|
4126
|
+
* The camera's view still draws the whole canvas first, so a split screen that covers the
|
|
4127
|
+
* canvas draws the scene one more time than it needs for its two halves. The scene and its
|
|
4128
|
+
* passes share 32 views, the camera's included.
|
|
4129
|
+
*
|
|
4130
|
+
* Throws E1501 when the 32 views are in use. Development builds throw E1213 for a camera or a
|
|
4131
|
+
* rectangle that a view does not take, and E1203 for a number that is not finite.
|
|
4132
|
+
*/
|
|
4133
|
+
createView(options) {
|
|
4134
|
+
const call = 'createView';
|
|
4135
|
+
if (DEV)
|
|
4136
|
+
checkViewOptions(options, call);
|
|
4137
|
+
const { camera, rect } = options;
|
|
4138
|
+
const values = this.core.callValues();
|
|
4139
|
+
values[0] = rect[0];
|
|
4140
|
+
values[1] = rect[1];
|
|
4141
|
+
values[2] = rect[2];
|
|
4142
|
+
values[3] = rect[3];
|
|
4143
|
+
const place = this.core.check(this.core.glue.addSceneView(), call);
|
|
4144
|
+
const view = new SceneView(this, place, camera, rect);
|
|
4145
|
+
this.setPassCamera(place, camera, undefined);
|
|
4146
|
+
this.canvasViews.push(view);
|
|
4147
|
+
return view;
|
|
4148
|
+
}
|
|
4149
|
+
/**
|
|
4150
|
+
* The view whose image covers the point (`x`, `y`) in CSS pixels from the canvas's top-left
|
|
4151
|
+
* corner, or undefined where only the camera's view shows. Where views overlap, it gives the one
|
|
4152
|
+
* on top, which the engine draws last. Pass the view to `view.screenToRay` to pick in it, and
|
|
4153
|
+
* use `camera.screenToRay` when it gives undefined. It allocates nothing.
|
|
4154
|
+
*/
|
|
4155
|
+
viewAt(x, y) {
|
|
4156
|
+
const views = this.canvasViews;
|
|
4157
|
+
let found;
|
|
4158
|
+
for (let index = 0; index < views.length; index++) {
|
|
4159
|
+
const view = views[index];
|
|
4160
|
+
if ((found === undefined || view.place > found.place) && view.contains(x, y))
|
|
4161
|
+
found = view;
|
|
4162
|
+
}
|
|
4163
|
+
return found;
|
|
4164
|
+
}
|
|
4165
|
+
/** @internal True when the point in CSS pixels lies in `rect`, as fractions of the canvas. */
|
|
4166
|
+
viewHolds(rect, x, y) {
|
|
4167
|
+
return this.frameCameras.holds(rect, x, y);
|
|
4168
|
+
}
|
|
4169
|
+
/** @internal Takes a view that `view.destroy` removed off the list that `viewAt` reads. */
|
|
4170
|
+
forgetView(view) {
|
|
4171
|
+
const index = this.canvasViews.indexOf(view);
|
|
4172
|
+
if (index >= 0)
|
|
4173
|
+
this.canvasViews.splice(index, 1);
|
|
4174
|
+
}
|
|
4175
|
+
/**
|
|
4176
|
+
* Creates a light of class `kind` from the next frame: its object, its row in the light table,
|
|
4177
|
+
* and the values of `options`. A directional or spot light turns to its target or direction.
|
|
4178
|
+
*/
|
|
4179
|
+
createLight(kind, type, options, call) {
|
|
4180
|
+
const { intensityUnit } = options;
|
|
4181
|
+
if (DEV && intensityUnit !== undefined && intensityUnit !== LIGHT_UNITS[type])
|
|
4182
|
+
throw new EngineError('E1213', `${call}() got the intensity unit ${JSON.stringify(intensityUnit)}, and this light takes only '${LIGHT_UNITS[type]}'.`);
|
|
4183
|
+
const flags = options.castShadows ? C.FLAG_CAST_SHADOWS : 0;
|
|
4184
|
+
const light = this.create(kind, options, C.CORE_NO_MESH, 0, flags, 0, call, ORIGIN);
|
|
4185
|
+
const { core } = this;
|
|
4186
|
+
try {
|
|
4187
|
+
light.id = core.checkGrowth(core.glue.createLight(light.handle, type), call, options.name);
|
|
4188
|
+
}
|
|
4189
|
+
catch (error) {
|
|
4190
|
+
// The object has no light row, so it goes before the sketch could reach it.
|
|
4191
|
+
light.destroy();
|
|
4192
|
+
throw error;
|
|
4193
|
+
}
|
|
4194
|
+
light.unitScale[0] = intensityScale(type, intensityUnit);
|
|
4195
|
+
if (options.color !== undefined)
|
|
4196
|
+
light.paint(call, C.LIGHT_COLOR_MAIN, options.color);
|
|
4197
|
+
const area = type === C.LIGHT_KIND_RECT || type === C.LIGHT_KIND_TUBE;
|
|
4198
|
+
const ranged = type === C.LIGHT_KIND_POINT || type === C.LIGHT_KIND_SPOT || area;
|
|
4199
|
+
if (area)
|
|
4200
|
+
this.loadAreaTables();
|
|
4201
|
+
for (const [key, which] of LIGHT_NUMBERS) {
|
|
4202
|
+
const value = options[key];
|
|
4203
|
+
if (which === C.LIGHT_VALUE_INTENSITY) {
|
|
4204
|
+
// An intensity in another unit, even the default of 1, is that unit's.
|
|
4205
|
+
if (value !== undefined || light.unitScale[0] !== 1)
|
|
4206
|
+
light.writeValue(call, which, (value ?? 1) * light.unitScale[0]);
|
|
4207
|
+
}
|
|
4208
|
+
else if (value !== undefined || (ranged && which === C.LIGHT_VALUE_RANGE))
|
|
4209
|
+
light.writeValue(call, which, value);
|
|
4210
|
+
}
|
|
4211
|
+
if (options.shadow)
|
|
4212
|
+
light.shadow(call, options.shadow);
|
|
4213
|
+
if (type === C.LIGHT_KIND_DIRECTIONAL || type === C.LIGHT_KIND_SPOT || area) {
|
|
4214
|
+
if (options.target)
|
|
4215
|
+
light.lookAt(...options.target);
|
|
4216
|
+
else if (options.direction || !options.rotation)
|
|
4217
|
+
light.aim(call, ...(options.direction ?? DOWN));
|
|
4218
|
+
}
|
|
4219
|
+
return light;
|
|
4220
|
+
}
|
|
4221
|
+
/** Light from one direction, like sunlight: `direction` is the way it travels. */
|
|
4222
|
+
createDirectionalLight(options = {}) {
|
|
4223
|
+
return this.createLight(DirectionalLight, C.LIGHT_KIND_DIRECTIONAL, options, 'createDirectionalLight');
|
|
4224
|
+
}
|
|
4225
|
+
/** Light from a point in every direction, out to `range` meters, which it needs. */
|
|
4226
|
+
createPointLight(options) {
|
|
4227
|
+
return this.createLight(PointLight, C.LIGHT_KIND_POINT, options, 'createPointLight');
|
|
4228
|
+
}
|
|
4229
|
+
/** Light from a point in a cone, out to `range` meters, which it needs. */
|
|
4230
|
+
createSpotLight(options) {
|
|
4231
|
+
const light = this.createLight(SpotLight, C.LIGHT_KIND_SPOT, options, 'createSpotLight');
|
|
4232
|
+
if (options.map)
|
|
4233
|
+
light.setMap(options.map);
|
|
4234
|
+
return light;
|
|
4235
|
+
}
|
|
4236
|
+
/**
|
|
4237
|
+
* Light from a rectangle, `width` by `height` meters, out to `range` meters, which it needs. Its
|
|
4238
|
+
* light leaves along `direction`.
|
|
4239
|
+
*/
|
|
4240
|
+
createRectAreaLight(options) {
|
|
4241
|
+
const light = this.createLight(RectAreaLight, C.LIGHT_KIND_RECT, options, 'createRectAreaLight');
|
|
4242
|
+
if (options.image)
|
|
4243
|
+
light.setImage(options.image);
|
|
4244
|
+
return light;
|
|
4245
|
+
}
|
|
4246
|
+
/** Light from a tube, `length` meters along `direction`, out to `range` meters, which it needs. */
|
|
4247
|
+
createTubeLight(options) {
|
|
4248
|
+
return this.createLight(TubeLight, C.LIGHT_KIND_TUBE, options, 'createTubeLight');
|
|
4249
|
+
}
|
|
4250
|
+
/** Light from the sky above and the ground below. */
|
|
4251
|
+
createHemisphereLight(options = {}) {
|
|
4252
|
+
const call = 'createHemisphereLight';
|
|
4253
|
+
const light = this.createLight(HemisphereLight, C.LIGHT_KIND_HEMISPHERE, { ...options, color: options.skyColor }, call);
|
|
4254
|
+
if (options.groundColor !== undefined)
|
|
4255
|
+
light.paint(call, C.LIGHT_COLOR_GROUND, options.groundColor);
|
|
4256
|
+
return light;
|
|
4257
|
+
}
|
|
4258
|
+
/** Light on every surface, from no direction. */
|
|
4259
|
+
createAmbientLight(options = {}) {
|
|
4260
|
+
return this.createLight(AmbientLight, C.LIGHT_KIND_AMBIENT, options, 'createAmbientLight');
|
|
4261
|
+
}
|
|
4262
|
+
/**
|
|
4263
|
+
* What the camera shows behind every object: a color, a texture, an environment from
|
|
4264
|
+
* `assets.loadEnvironment` or `assets.builtinEnvironment`, a cube map from `assets.loadCubemap`,
|
|
4265
|
+
* the analytic sky with `{ sky: { sunPosition } }`, or the physical sky with
|
|
4266
|
+
* `{ atmosphere: { sunPosition } }`, whose air also hazes distant objects. A texture fills the
|
|
4267
|
+
* view and stretches to its shape. An environment or a cube map surrounds the scene, and
|
|
4268
|
+
* `options` give its intensity, rotation and, for an environment, its blur. The color set before
|
|
4269
|
+
* shows until a texture's texels are on the GPU, and again if the texture is destroyed. A color
|
|
4270
|
+
* takes the place of any other background. Exposure and tone mapping change the background with
|
|
4271
|
+
* the rest of the scene. Without a background, the canvas shows black, or the page behind it on
|
|
4272
|
+
* a transparent canvas. Settings are values, not shader builds, and the call allocates nothing,
|
|
4273
|
+
* so a sketch can move the sky's sun or turn a cube map every frame. Throws E1204 for a color
|
|
4274
|
+
* it cannot read, E1203 for a number that is not finite, E1108 for a number out of its range,
|
|
4275
|
+
* E1213 for an option that the background does not take, and E1101 for a texture, an
|
|
4276
|
+
* environment or a cube map that was destroyed.
|
|
4277
|
+
*/
|
|
4278
|
+
setBackground(background, options) {
|
|
4279
|
+
// No closure here: one that reads `this` would make every call allocate a context.
|
|
4280
|
+
this.sceneBackground ??= new SceneBackground(this.core, this.makers?.materials.shaders);
|
|
4281
|
+
if (background instanceof Texture ||
|
|
4282
|
+
background instanceof Environment ||
|
|
4283
|
+
background instanceof Cubemap ||
|
|
4284
|
+
isSkyBackground(background) ||
|
|
4285
|
+
isAtmosphereBackground(background)) {
|
|
4286
|
+
this.sceneBackground.set(background, options);
|
|
4287
|
+
return;
|
|
4288
|
+
}
|
|
4289
|
+
writeLinearColor(this.core.callValues(), background, 'setBackground');
|
|
4290
|
+
this.core.glue.setBackground();
|
|
4291
|
+
this.sceneBackground.clear();
|
|
4292
|
+
}
|
|
4293
|
+
/**
|
|
4294
|
+
* Draws an add-on's sky layer over the background, under every object: the top of a sky, such
|
|
4295
|
+
* as an aurora, a second layer of clouds or a space backdrop. The description is a feature
|
|
4296
|
+
* description ([Add-on feature descriptions](../features.md)): it names the feature and
|
|
4297
|
+
* records at the background point, as a draw, provides the sky, and draws in the main view, the
|
|
4298
|
+
* scene passes and the reflections. The layer's WGSL, compiled by the null3D Vite plugin,
|
|
4299
|
+
* declares `fn skyLayer(input: SkyLayerInput) -> SkyLayer`. The engine gives it the fragment's
|
|
4300
|
+
* direction in the world, the core sky's cloud coverage, density, elevation and scale, the
|
|
4301
|
+
* sketch time and the share of the sun that the layer hides, and it blends what the layer
|
|
4302
|
+
* returns over the sky by the layer's coverage and opacity. A layer that hides part of the sun
|
|
4303
|
+
* also dims the disc and glow that the core sky draws, through `sun`. The layer draws in the
|
|
4304
|
+
* main view, in scene passes and in reflections, and draws nothing where the background draws
|
|
4305
|
+
* nothing, as in a debug view. A second call replaces the layer.
|
|
4306
|
+
*
|
|
4307
|
+
* Throws E1223 for a description that the engine cannot place, E1215 for WGSL that the plugin
|
|
4308
|
+
* did not compile as a sky layer, E1203 for a number that is not finite, and E1108 for a number
|
|
4309
|
+
* out of its range.
|
|
4310
|
+
*/
|
|
4311
|
+
setSkyLayer(description, options) {
|
|
4312
|
+
this.skyLayer ??= new SceneSkyLayer(this.core, this.makers?.materials.shaderTemplates ?? new ShaderTemplates());
|
|
4313
|
+
this.skyLayer.install(description, options, 'setSkyLayer');
|
|
4314
|
+
return this.skyLayer;
|
|
4315
|
+
}
|
|
4316
|
+
/**
|
|
4317
|
+
* Removes the sky layer that `setSkyLayer` installed, from the next frame on, and gives the
|
|
4318
|
+
* core sky its full sun back. A call with no layer installed does nothing.
|
|
4319
|
+
*/
|
|
4320
|
+
clearSkyLayer() {
|
|
4321
|
+
this.skyLayer?.clear();
|
|
4322
|
+
}
|
|
4323
|
+
/**
|
|
4324
|
+
* Sets the layers whose objects decals mark, as a 32-bit mask as `setLayers` takes. An object
|
|
4325
|
+
* that is also on a layer outside the mask shows no decals, so a character on a layer of its own
|
|
4326
|
+
* walks through a puddle clean. Such objects draw a second time after the decals, over their own
|
|
4327
|
+
* pixels, in each frame that has decals. The default is every layer.
|
|
4328
|
+
*/
|
|
4329
|
+
setDecalLayers(mask) {
|
|
4330
|
+
if (DEV)
|
|
4331
|
+
checkLayers('setDecalLayers', mask);
|
|
4332
|
+
this.core.glue.setDecalLayers(mask >>> 0);
|
|
4333
|
+
}
|
|
4334
|
+
/** The material that every mesh of the main pass draws with, or null while each uses its own. */
|
|
4335
|
+
overrideMaterialValue = null;
|
|
4336
|
+
/**
|
|
4337
|
+
* Draws every mesh and instance batch of the main pass with this material in place of its own,
|
|
4338
|
+
* or with their own materials with null. Each object keeps its mesh, its place and its
|
|
4339
|
+
* instances, so a batch draws every row with it, and every camera view draws with it, the scene
|
|
4340
|
+
* passes among them. Sprites, points, lines and particle systems keep their own materials, and
|
|
4341
|
+
* the shadow maps keep each object's material, so a masked object still cuts its shadow. A
|
|
4342
|
+
* change rebuilds the engine's draw tables in the next frame; after that it adds no draw call
|
|
4343
|
+
* and builds no pipeline. Throws E1224 for a sprite, point or line material, E1101 for a
|
|
4344
|
+
* material that is destroyed, and E1103 for a material of another engine.
|
|
4345
|
+
*/
|
|
4346
|
+
get overrideMaterial() {
|
|
4347
|
+
return this.overrideMaterialValue;
|
|
4348
|
+
}
|
|
4349
|
+
set overrideMaterial(material) {
|
|
4350
|
+
if (material === this.overrideMaterialValue)
|
|
4351
|
+
return;
|
|
4352
|
+
const { glue } = this.core;
|
|
4353
|
+
if (material === null) {
|
|
4354
|
+
this.core.check(glue.setOverrideMaterial(0), 'scene.overrideMaterial', undefined, true);
|
|
4355
|
+
this.overrideMaterialValue = null;
|
|
4356
|
+
return;
|
|
4357
|
+
}
|
|
4358
|
+
if (DEV)
|
|
4359
|
+
checkSameEngine('overrideMaterial', 'material', material.core, this);
|
|
4360
|
+
const batchOnly = batchOnlyShading(material.shading);
|
|
4361
|
+
if (batchOnly !== undefined)
|
|
4362
|
+
throw new EngineError('E1224', `scene.overrideMaterial got a ${batchOnly} material. It takes a material that draws meshes, from materials.standard(), materials.unlit(), materials.shader() or materials.decal().`);
|
|
4363
|
+
this.core.check(glue.setOverrideMaterial(material.id), 'scene.overrideMaterial', undefined, true);
|
|
4364
|
+
this.overrideMaterialValue = material;
|
|
4365
|
+
}
|
|
4366
|
+
/**
|
|
4367
|
+
* Lights the scene with an environment from `assets.loadEnvironment` or
|
|
4368
|
+
* `assets.builtinEnvironment`, or with none for null. Standard materials reflect it, sharply
|
|
4369
|
+
* when smooth and blurred when rough, and take its diffuse light, each times its `envIntensity`.
|
|
4370
|
+
* The scene draws without a file's environment until its map is on the GPU. The built-in room's
|
|
4371
|
+
* map is whole in the first frame that uses it. It allocates nothing, so a sketch can turn the
|
|
4372
|
+
* environment every frame. Throws E1203 for a number that is not finite, E1108 for a negative
|
|
4373
|
+
* intensity, E1213 for a value that is not an environment, and E1101 for an environment that
|
|
4374
|
+
* was destroyed.
|
|
4375
|
+
*/
|
|
4376
|
+
setEnvironment(environment, options) {
|
|
4377
|
+
this.sceneEnvironment ??= new SceneEnvironment(this.core);
|
|
4378
|
+
this.sceneEnvironment.set(environment, options);
|
|
4379
|
+
}
|
|
4380
|
+
/** @internal What reflection probes need from the sketch, which the sketch runner gives. */
|
|
4381
|
+
probeHost;
|
|
4382
|
+
/** The scene's reflection probes, made with the first. */
|
|
4383
|
+
reflectionProbes;
|
|
4384
|
+
/**
|
|
4385
|
+
* Makes a reflection probe: the scene around a point, which the engine captures on the GPU and
|
|
4386
|
+
* filters for each roughness, as an environment's map. It lights the surfaces inside its box in
|
|
4387
|
+
* place of the environment, with reflections that meet the box's sides, as a room's walls or a
|
|
4388
|
+
* street's houses stand. A probe captures in a frame soon after it is made, and frames before
|
|
4389
|
+
* that draw with the environment. A scene has at most 16 probes. Their captures take 6 of the
|
|
4390
|
+
* 32 views that the scene and its passes share. Throws E1430 past those limits, E1203 for a
|
|
4391
|
+
* number that is not finite, E1108 for a negative blend or intensity or a box whose min does not
|
|
4392
|
+
* lie below its max, and E1213 for an option that probes do not take.
|
|
4393
|
+
*/
|
|
4394
|
+
createReflectionProbe(options) {
|
|
4395
|
+
this.reflectionProbes ??= new ReflectionProbes(this.core, this.probeHost ?? { sendGenerator: () => { }, floatTargets: true, time: this.time });
|
|
4396
|
+
return this.reflectionProbes.create(options, 'scene.createReflectionProbe');
|
|
4397
|
+
}
|
|
4398
|
+
/**
|
|
4399
|
+
* Lights the scene with a grid of irradiance probes, or with none for null. The grid's light
|
|
4400
|
+
* takes the place of the environment's diffuse light where `environmentWeight` says so, so
|
|
4401
|
+
* light that changes with a surface's place, bounced from colored walls or sky, reaches it.
|
|
4402
|
+
* The probes' coefficients come from a 3D texture that `LightProbeGridData.toTexture` packs
|
|
4403
|
+
* and uploads, from `bakeProbes` or from a grid baked elsewhere.
|
|
4404
|
+
* Throws the errors that `scene.setEnvironment` throws for a value out of range, E1213 for
|
|
4405
|
+
* something that is not a texture, and E1101 for a texture that was destroyed.
|
|
4406
|
+
*/
|
|
4407
|
+
setLightProbeGrid(grid) {
|
|
4408
|
+
this.sceneProbeGrid ??= new SceneLightProbeGrid(this.core);
|
|
4409
|
+
this.sceneProbeGrid.set(grid);
|
|
4410
|
+
}
|
|
4411
|
+
/**
|
|
4412
|
+
* Fog over every object, by each object's straight-line distance from the camera along a curve:
|
|
4413
|
+
* exponential by default, exponential squared or linear. The fog can thin with height and glow
|
|
4414
|
+
* toward the main directional light. With `volumetric`, the sun and the point and spot lights
|
|
4415
|
+
* light the fog through their shadows. Null removes the fog. The background takes the share of
|
|
4416
|
+
* the fog that `background` gives, none by default, and a material created with `fog: false`
|
|
4417
|
+
* keeps its color. Throws E1108 for an unknown curve or a
|
|
4418
|
+
* value out of its range, and E1203 for a value that is not finite. The call allocates nothing,
|
|
4419
|
+
* so a sketch can change the fog in every frame.
|
|
4420
|
+
*/
|
|
4421
|
+
setFog(fog) {
|
|
4422
|
+
this.fogVolume = setSceneFog(this.core, fog);
|
|
4423
|
+
if (this.fogVolume)
|
|
4424
|
+
this.makers?.materials.shaders.need('fog_volume');
|
|
4425
|
+
}
|
|
4426
|
+
/** @internal True while the scene's fog is volumetric, which needs HDR color. */
|
|
4427
|
+
get needsHdr() {
|
|
4428
|
+
return this.fogVolume;
|
|
4429
|
+
}
|
|
4430
|
+
/**
|
|
4431
|
+
* The raycasts and overlap queries, made on the first call. The closures that they take live in
|
|
4432
|
+
* a method of their own: one in the getter would make each call allocate a context.
|
|
4433
|
+
*/
|
|
4434
|
+
get queries() {
|
|
4435
|
+
return this.sceneQueries ?? this.makeQueries();
|
|
4436
|
+
}
|
|
4437
|
+
/** Makes the raycasts and overlap queries. */
|
|
4438
|
+
makeQueries() {
|
|
4439
|
+
this.sceneQueries = new SceneQueries(this.core, this.queryTargets(), () => this.settleWorld());
|
|
4440
|
+
return this.sceneQueries;
|
|
4441
|
+
}
|
|
4442
|
+
/**
|
|
4443
|
+
* The objects and batches that queries and picks name by their ids, and the cameras that their
|
|
4444
|
+
* rays read.
|
|
4445
|
+
*/
|
|
4446
|
+
queryTargets() {
|
|
4447
|
+
return {
|
|
4448
|
+
objectAt: (slot) => this.objectSlots[slot],
|
|
4449
|
+
batchAt: (id) => {
|
|
4450
|
+
const batch = this.batchSlots[id & SLOT_MASK];
|
|
4451
|
+
return batch && (batch.id === id || batch.parts.includes(id)) ? batch : undefined;
|
|
4452
|
+
},
|
|
4453
|
+
writeCamera: (input) => {
|
|
4454
|
+
const camera = this.activeCamera;
|
|
4455
|
+
const live = camera !== undefined && camera.destroyedFrame === -1 ? camera : undefined;
|
|
4456
|
+
this.frameCameras.queryCamera(live, input);
|
|
4457
|
+
},
|
|
4458
|
+
writeRayCamera: (input) => this.frameCameras.rayCamera(input),
|
|
4459
|
+
};
|
|
4460
|
+
}
|
|
4461
|
+
/** GPU picking's queries, made on the first pick. */
|
|
4462
|
+
get picks() {
|
|
4463
|
+
if (!this.scenePicks) {
|
|
4464
|
+
this.scenePicks = new ScenePicks(this.core, this.queryTargets(), (x, y, frame) => this.pickByRay(x, y, frame));
|
|
4465
|
+
}
|
|
4466
|
+
return this.scenePicks;
|
|
4467
|
+
}
|
|
4468
|
+
/**
|
|
4469
|
+
* Finds the object that the camera draws at a point of the canvas, or `null` where it draws
|
|
4470
|
+
* nothing there. `x` and `y` are CSS pixels from the canvas's top-left corner, as
|
|
4471
|
+
* `camera.screenToRay` takes them, and the point is tested at the pixel that the camera draws,
|
|
4472
|
+
* not at a projected triangle: a cut-out material's holes and a surface thinner than a pixel
|
|
4473
|
+
* answer as the image shows them.
|
|
4474
|
+
*
|
|
4475
|
+
* A hit carries `uv`, where on the surface the pixel landed in the mesh's first texture
|
|
4476
|
+
* coordinates, blended across its triangle's three corners as a raycast's `uv` is, and `hasUv`,
|
|
4477
|
+
* which says whether to read it. A ray from the camera of the frame that recorded the pick
|
|
4478
|
+
* finds them from the same point, so the two ways of asking agree. A skinned or morphed
|
|
4479
|
+
* character, and a custom material that offsets its vertices, draws a different shape than the
|
|
4480
|
+
* mesh that the ray tests, so its coordinates can differ from the pose it drew.
|
|
4481
|
+
*
|
|
4482
|
+
* The answer arrives one or more frames later, through a promise, and a pick in every frame
|
|
4483
|
+
* waits in a queue of its own. The frame that records the pick draws it, so the camera of that
|
|
4484
|
+
* frame answers, and a camera that moves between the click and the frame can differ from the
|
|
4485
|
+
* frame that the click saw. A scene with a source that the id target cannot hold, such as a
|
|
4486
|
+
* custom material without a vertex offset, a blended surface or a sprite, answers with a
|
|
4487
|
+
* raycast instead, which tests triangles and so ignores alpha masks.
|
|
4488
|
+
*/
|
|
4489
|
+
pick(x, y) {
|
|
4490
|
+
if (DEV) {
|
|
4491
|
+
if (!Number.isFinite(x))
|
|
4492
|
+
throw new EngineError('E1203', `pick() got ${x} for x.`);
|
|
4493
|
+
if (!Number.isFinite(y))
|
|
4494
|
+
throw new EngineError('E1203', `pick() got ${y} for y.`);
|
|
4495
|
+
}
|
|
4496
|
+
return this.picks.pick(x, y);
|
|
4497
|
+
}
|
|
4498
|
+
/** @internal Answers each pick whose read landed, at the end of a frame. */
|
|
4499
|
+
pollPicks(slots) {
|
|
4500
|
+
this.scenePicks?.poll(slots);
|
|
4501
|
+
}
|
|
4502
|
+
/** @internal Gives the picks the engine's control block, when the frame loop starts. */
|
|
4503
|
+
attachPickControl(slots) {
|
|
4504
|
+
this.picks.attach(slots);
|
|
4505
|
+
}
|
|
4506
|
+
/** @internal Fails the picks that wait, when the engine stops. */
|
|
4507
|
+
stopPicks() {
|
|
4508
|
+
this.scenePicks?.stop();
|
|
4509
|
+
}
|
|
4510
|
+
/**
|
|
4511
|
+
* Casts a ray through a point of the canvas: with the camera of `frame`, or with the camera as
|
|
4512
|
+
* it stands and the frame of the point's input event when `frame` is -1. Answers a pick that the
|
|
4513
|
+
* GPU pass cannot draw, and finds the texture coordinates of a pixel that it did pick.
|
|
4514
|
+
*/
|
|
4515
|
+
pickByRay(x, y, frame) {
|
|
4516
|
+
const active = this.activeCamera;
|
|
4517
|
+
const live = active !== undefined && active.destroyedFrame === -1 ? active : undefined;
|
|
4518
|
+
// The ray and hit are made once, when the first pick needs them.
|
|
4519
|
+
if (!this.pickRay)
|
|
4520
|
+
this.pickRay = { origin: [0, 0, 0], direction: [0, 0, 0] };
|
|
4521
|
+
if (!this.pickHit) {
|
|
4522
|
+
this.pickHit = {
|
|
4523
|
+
object: null,
|
|
4524
|
+
instance: -1,
|
|
4525
|
+
point: [0, 0, 0],
|
|
4526
|
+
normal: [0, 0, 0],
|
|
4527
|
+
uv: [0, 0],
|
|
4528
|
+
hasUv: false,
|
|
4529
|
+
distance: 0,
|
|
4530
|
+
triangle: -1,
|
|
4531
|
+
};
|
|
4532
|
+
}
|
|
4533
|
+
const ray = this.pickRay;
|
|
4534
|
+
const hit = this.pickHit;
|
|
4535
|
+
let layers;
|
|
4536
|
+
if (frame < 0) {
|
|
4537
|
+
if (live === undefined)
|
|
4538
|
+
return null;
|
|
4539
|
+
live.screenToRay(x, y, ray);
|
|
4540
|
+
layers = live.layers;
|
|
4541
|
+
}
|
|
4542
|
+
else {
|
|
4543
|
+
if (!this.pickPoint)
|
|
4544
|
+
this.pickPoint = new Float64Array(2);
|
|
4545
|
+
const point = this.pickPoint;
|
|
4546
|
+
point[0] = x;
|
|
4547
|
+
point[1] = y;
|
|
4548
|
+
// A frame that the ring no longer holds answers no coordinates, rather than aim a camera
|
|
4549
|
+
// that has moved at the pixel that the older frame showed.
|
|
4550
|
+
layers = this.frameCameras.frameRay(frame, point, ray, undefined);
|
|
4551
|
+
if (layers < 0)
|
|
4552
|
+
return null;
|
|
4553
|
+
}
|
|
4554
|
+
// A camera that has not drawn cannot project the point, so the frame it would have answered
|
|
4555
|
+
// showed nothing there.
|
|
4556
|
+
if (!Number.isFinite(ray.direction[0]))
|
|
4557
|
+
return null;
|
|
4558
|
+
if (!Number.isFinite(ray.direction[1]))
|
|
4559
|
+
return null;
|
|
4560
|
+
if (!Number.isFinite(ray.direction[2]))
|
|
4561
|
+
return null;
|
|
4562
|
+
if (!this.raycast(ray.origin, ray.direction, { layers }, hit) || hit.object === null) {
|
|
4563
|
+
return null;
|
|
4564
|
+
}
|
|
4565
|
+
const uv = hit.uv;
|
|
4566
|
+
return {
|
|
4567
|
+
object: hit.object,
|
|
4568
|
+
instance: hit.instance,
|
|
4569
|
+
uv: [uv?.[0] ?? Number.NaN, uv?.[1] ?? Number.NaN],
|
|
4570
|
+
hasUv: hit.hasUv === true,
|
|
4571
|
+
};
|
|
4572
|
+
}
|
|
4573
|
+
/**
|
|
4574
|
+
* Brings the scene's world output up to date before a query that runs before the runner's
|
|
4575
|
+
* first frame, as a bake in a sketch's setup does: the commands that the sketch queued apply,
|
|
4576
|
+
* and the transforms and instance batches update, as at the start of the frame that the
|
|
4577
|
+
* runner would record next. The query then finds everything that the sketch has built so
|
|
4578
|
+
* far. After the first frame the runner keeps the world current, and this costs a compare.
|
|
4579
|
+
*
|
|
4580
|
+
* A settle with no new command since the last one is skipped: a bake casts many batches of
|
|
4581
|
+
* rays, and only the objects that setup added since the last settle matter. Moves that setup
|
|
4582
|
+
* makes after the first query count from the first frame, as moves in a frame count from the
|
|
4583
|
+
* next.
|
|
4584
|
+
*/
|
|
4585
|
+
settleWorld() {
|
|
4586
|
+
if (this.time.frame !== 0)
|
|
4587
|
+
return;
|
|
4588
|
+
const commands = this.commandBatches;
|
|
4589
|
+
if (this.settledCommands === commands)
|
|
4590
|
+
return;
|
|
4591
|
+
this.settledCommands = commands;
|
|
4592
|
+
if (DEV) {
|
|
4593
|
+
// As the runner checks before each transform update, before the dirty bits go.
|
|
4594
|
+
const unmarked = this.unmarkedWrites?.check();
|
|
4595
|
+
if (unmarked)
|
|
4596
|
+
throw unmarked;
|
|
4597
|
+
}
|
|
4598
|
+
const { core } = this;
|
|
4599
|
+
const { glue } = core;
|
|
4600
|
+
const frame = nextFrame(this.time.frame);
|
|
4601
|
+
core.checkGrowth(glue.beginFrame(frame, 0, 0), QUEUED_CHANGE, undefined, true);
|
|
4602
|
+
core.checkGrowth(glue.updateTransforms(), 'the first query', undefined, true);
|
|
4603
|
+
core.checkGrowth(glue.updateBatches(frame), 'the first query', undefined, true);
|
|
4604
|
+
}
|
|
4605
|
+
/**
|
|
4606
|
+
* Casts a ray from `origin` along `direction`, and writes its closest hit into `hit`. Returns
|
|
4607
|
+
* true on a hit. On a miss it sets `hit.object` to null and leaves the other fields as they
|
|
4608
|
+
* were. The direction needs no unit length. The ray tests the triangles of objects and
|
|
4609
|
+
* instance rows on the layers of `options.layers`, as their materials draw them: front faces,
|
|
4610
|
+
* or both faces for a double-sided material. Queries see the scene as the last frame's update
|
|
4611
|
+
* left it, so a move, a new object or a destroy in this frame counts from the next frame, or
|
|
4612
|
+
* from `onLateUpdate`. A query before the first frame, as a bake in a sketch's setup, first
|
|
4613
|
+
* applies the changes queued so far and updates them, so it sees what the setup has built.
|
|
4614
|
+
* Create `hit` and `options` once and pass them each time.
|
|
4615
|
+
*/
|
|
4616
|
+
raycast(origin, direction, options, hit) {
|
|
4617
|
+
return this.queries.raycast(origin, direction, options, hit);
|
|
4618
|
+
}
|
|
4619
|
+
/**
|
|
4620
|
+
* True when a ray from `origin` along `direction` hits anything on the layers of
|
|
4621
|
+
* `options.layers`. It stops at the first hit it finds, so it is faster than `raycast`: use it
|
|
4622
|
+
* for line-of-sight checks.
|
|
4623
|
+
*/
|
|
4624
|
+
raycastAny(origin, direction, options) {
|
|
4625
|
+
return this.queries.raycastAny(origin, direction, options);
|
|
4626
|
+
}
|
|
4627
|
+
/**
|
|
4628
|
+
* Casts a ray as `raycast` does, writes every hit into `hits` nearest first, one hit for each
|
|
4629
|
+
* triangle that the ray crosses, and returns how many. It fills the first entries of `hits`,
|
|
4630
|
+
* adds hit objects when the array is too short, and leaves the entries after the hits as they
|
|
4631
|
+
* were.
|
|
4632
|
+
*/
|
|
4633
|
+
raycastAll(origin, direction, options, hits) {
|
|
4634
|
+
return this.queries.raycastAll(origin, direction, options, hits);
|
|
4635
|
+
}
|
|
4636
|
+
/**
|
|
4637
|
+
* Casts many rays at once on the job workers, and writes each one's closest hit into `out`.
|
|
4638
|
+
* `rays` holds six numbers per ray: its origin, then its direction. Returns how many rays hit
|
|
4639
|
+
* something. A miss writes -1 as its distance.
|
|
4640
|
+
*/
|
|
4641
|
+
raycastBatch(rays, options, out) {
|
|
4642
|
+
return this.queries.raycastBatch(rays, options, out);
|
|
4643
|
+
}
|
|
4644
|
+
/**
|
|
4645
|
+
* Casts many rays as `raycastBatch` does, but tests both faces of every triangle and writes 1
|
|
4646
|
+
* for each ray that met the back of a surface and 0 for one that met the front. The light probe
|
|
4647
|
+
* bake reads it to find the probes that lie inside geometry.
|
|
4648
|
+
*
|
|
4649
|
+
* @internal
|
|
4650
|
+
*/
|
|
4651
|
+
raycastBatchFaces(rays, options, out, backFacing) {
|
|
4652
|
+
return this.queries.raycastBatchFaces(rays, options, out, backFacing);
|
|
4653
|
+
}
|
|
4654
|
+
/**
|
|
4655
|
+
* Finds the objects and instance rows on the layers of `options.layers` that have a triangle
|
|
4656
|
+
* within `radius` meters of `center`, writes them into `out`, and returns how many. It fills
|
|
4657
|
+
* `out` as `raycastAll` fills its hits, in no set order.
|
|
4658
|
+
*/
|
|
4659
|
+
overlapSphere(center, radius, options, out) {
|
|
4660
|
+
return this.queries.overlapSphere(center, radius, options, out);
|
|
4661
|
+
}
|
|
4662
|
+
/**
|
|
4663
|
+
* Finds the objects and instance rows on the layers of `options.layers` that have a triangle
|
|
4664
|
+
* inside the box from `min` to `max` or crossing it, as `overlapSphere` does. The box's sides
|
|
4665
|
+
* lie along the world's axes.
|
|
4666
|
+
*/
|
|
4667
|
+
overlapBox(min, max, options, out) {
|
|
4668
|
+
return this.queries.overlapBox(min, max, options, out);
|
|
4669
|
+
}
|
|
4670
|
+
/**
|
|
4671
|
+
* Builds every GPU pipeline that the scene needs as it stands, and resolves once they are all
|
|
4672
|
+
* built. Hidden objects count too. After the first frame, an object whose pipeline is still
|
|
4673
|
+
* building draws nothing, so create a loading stage's objects hidden, warm up, then show them.
|
|
4674
|
+
* The first frame waits for its pipelines anyway. In the setup, a warm-up draws that frame once
|
|
4675
|
+
* they are built, before the setup goes on.
|
|
4676
|
+
*/
|
|
4677
|
+
warmUp() {
|
|
4678
|
+
return this.warmUpScene();
|
|
4679
|
+
}
|
|
4680
|
+
}
|