wallhammer-web 0.0.0-stage → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +92 -2
- package/dist/base/data.d.ts +67 -0
- package/dist/base/data.js +10 -0
- package/dist/base/destructible.d.ts +167 -0
- package/dist/base/destructible.js +47 -0
- package/dist/base/env-slot.d.ts +101 -0
- package/dist/base/env-slot.js +8 -0
- package/dist/base/frames.d.ts +138 -0
- package/dist/base/frames.js +459 -0
- package/dist/base/index.d.ts +21 -0
- package/dist/base/index.js +11 -0
- package/dist/base/mat34.d.ts +46 -0
- package/dist/base/mat34.js +173 -0
- package/dist/base/material.d.ts +87 -0
- package/dist/base/material.js +6 -0
- package/dist/base/math.d.ts +27 -0
- package/dist/base/math.js +60 -0
- package/dist/base/progress.d.ts +38 -0
- package/dist/base/progress.js +81 -0
- package/dist/base/rig.d.ts +177 -0
- package/dist/base/rig.js +97 -0
- package/dist/base/trig.d.ts +29 -0
- package/dist/base/trig.js +169 -0
- package/dist/base/up.d.ts +26 -0
- package/dist/base/up.js +40 -0
- package/dist/base/view.d.ts +128 -0
- package/dist/base/view.js +136 -0
- package/dist/camera/camera.d.ts +99 -0
- package/dist/camera/camera.js +228 -0
- package/dist/camera/follow.d.ts +120 -0
- package/dist/camera/follow.js +320 -0
- package/dist/camera/free.d.ts +153 -0
- package/dist/camera/free.js +359 -0
- package/dist/camera/index.d.ts +10 -0
- package/dist/camera/index.js +6 -0
- package/dist/camera/orbit.d.ts +93 -0
- package/dist/camera/orbit.js +261 -0
- package/dist/camera/path.d.ts +48 -0
- package/dist/camera/path.js +179 -0
- package/dist/core/ballistic.d.ts +66 -0
- package/dist/core/ballistic.js +104 -0
- package/dist/core/bodies.d.ts +77 -0
- package/dist/core/bodies.js +125 -0
- package/dist/core/clock.d.ts +37 -0
- package/dist/core/clock.js +87 -0
- package/dist/core/cover-fade.d.ts +14 -0
- package/dist/core/cover-fade.js +38 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.js +8 -0
- package/dist/core/kepler.d.ts +74 -0
- package/dist/core/kepler.js +108 -0
- package/dist/core/level-fade.d.ts +66 -0
- package/dist/core/level-fade.js +123 -0
- package/dist/core/palette.d.ts +15 -0
- package/dist/core/palette.js +47 -0
- package/dist/env/atmosphere.d.ts +129 -0
- package/dist/env/atmosphere.js +707 -0
- package/dist/env/cloud-field.d.ts +44 -0
- package/dist/env/cloud-field.js +111 -0
- package/dist/env/environment.d.ts +217 -0
- package/dist/env/environment.js +441 -0
- package/dist/env/frame-block.d.ts +29 -0
- package/dist/env/frame-block.js +152 -0
- package/dist/env/glsl.d.ts +35 -0
- package/dist/env/glsl.js +246 -0
- package/dist/env/index.d.ts +13 -0
- package/dist/env/index.js +9 -0
- package/dist/env/sky.d.ts +48 -0
- package/dist/env/sky.js +227 -0
- package/dist/env/sun.d.ts +31 -0
- package/dist/env/sun.js +42 -0
- package/dist/gen-arch/build.d.ts +17 -0
- package/dist/gen-arch/build.js +414 -0
- package/dist/gen-arch/damage/damaged.d.ts +44 -0
- package/dist/gen-arch/damage/damaged.js +1119 -0
- package/dist/gen-arch/damage/fall-material.d.ts +10 -0
- package/dist/gen-arch/damage/fall-material.js +47 -0
- package/dist/gen-arch/damage/fall.d.ts +78 -0
- package/dist/gen-arch/damage/fall.js +797 -0
- package/dist/gen-arch/damage/rubble.d.ts +22 -0
- package/dist/gen-arch/damage/rubble.js +188 -0
- package/dist/gen-arch/index.d.ts +25 -0
- package/dist/gen-arch/index.js +16 -0
- package/dist/gen-arch/interior/interior-plan.d.ts +114 -0
- package/dist/gen-arch/interior/interior-plan.js +615 -0
- package/dist/gen-arch/interior/interior.d.ts +97 -0
- package/dist/gen-arch/interior/interior.js +966 -0
- package/dist/gen-arch/structure/building-shader.d.ts +25 -0
- package/dist/gen-arch/structure/building-shader.js +946 -0
- package/dist/gen-arch/structure/buildings.d.ts +248 -0
- package/dist/gen-arch/structure/buildings.js +294 -0
- package/dist/gen-arch/structure/dims.d.ts +77 -0
- package/dist/gen-arch/structure/dims.js +39 -0
- package/dist/gen-arch/structure/distant.d.ts +62 -0
- package/dist/gen-arch/structure/distant.js +316 -0
- package/dist/gen-arch/structure/env-slots.d.ts +18 -0
- package/dist/gen-arch/structure/env-slots.js +47 -0
- package/dist/gen-arch/structure/facade.d.ts +193 -0
- package/dist/gen-arch/structure/facade.js +159 -0
- package/dist/gen-arch/structure/parts.d.ts +31 -0
- package/dist/gen-arch/structure/parts.js +69 -0
- package/dist/gen-arch/structure/roof.d.ts +76 -0
- package/dist/gen-arch/structure/roof.js +568 -0
- package/dist/gen-arch/structure/structure-material.d.ts +23 -0
- package/dist/gen-arch/structure/structure-material.js +55 -0
- package/dist/gen-arch/structure/writer.d.ts +94 -0
- package/dist/gen-arch/structure/writer.js +195 -0
- package/dist/gen-core/cell.d.ts +138 -0
- package/dist/gen-core/cell.js +150 -0
- package/dist/gen-core/cube-sphere.d.ts +57 -0
- package/dist/gen-core/cube-sphere.js +159 -0
- package/dist/gen-core/field.d.ts +55 -0
- package/dist/gen-core/field.js +154 -0
- package/dist/gen-core/geometry.d.ts +31 -0
- package/dist/gen-core/geometry.js +231 -0
- package/dist/gen-core/hash.d.ts +18 -0
- package/dist/gen-core/hash.js +58 -0
- package/dist/gen-core/height-field.d.ts +33 -0
- package/dist/gen-core/height-field.js +137 -0
- package/dist/gen-core/index.d.ts +22 -0
- package/dist/gen-core/index.js +17 -0
- package/dist/gen-core/instance-cells.d.ts +37 -0
- package/dist/gen-core/instance-cells.js +72 -0
- package/dist/gen-core/near-scatter.d.ts +56 -0
- package/dist/gen-core/near-scatter.js +120 -0
- package/dist/gen-core/noise.d.ts +23 -0
- package/dist/gen-core/noise.js +72 -0
- package/dist/gen-core/occupancy.d.ts +21 -0
- package/dist/gen-core/occupancy.js +104 -0
- package/dist/gen-core/sphere-patch.d.ts +138 -0
- package/dist/gen-core/sphere-patch.js +544 -0
- package/dist/gen-core/strip-surface.d.ts +34 -0
- package/dist/gen-core/strip-surface.js +246 -0
- package/dist/gen-core/strip.d.ts +102 -0
- package/dist/gen-core/strip.js +817 -0
- package/dist/gen-ground/env-slots.d.ts +48 -0
- package/dist/gen-ground/env-slots.js +78 -0
- package/dist/gen-ground/ground.d.ts +78 -0
- package/dist/gen-ground/ground.js +208 -0
- package/dist/gen-ground/index.d.ts +9 -0
- package/dist/gen-ground/index.js +7 -0
- package/dist/gen-ground/markings.d.ts +46 -0
- package/dist/gen-ground/markings.js +124 -0
- package/dist/gen-ground/materials.d.ts +18 -0
- package/dist/gen-ground/materials.js +22 -0
- package/dist/gen-ground/terrain-shader.d.ts +5 -0
- package/dist/gen-ground/terrain-shader.js +151 -0
- package/dist/gen-mesh/bare-shapes.d.ts +194 -0
- package/dist/gen-mesh/bare-shapes.js +596 -0
- package/dist/gen-mesh/bisect-surface.d.ts +47 -0
- package/dist/gen-mesh/bisect-surface.js +261 -0
- package/dist/gen-mesh/box.d.ts +18 -0
- package/dist/gen-mesh/box.js +2 -0
- package/dist/gen-mesh/cell-morph-mesh.d.ts +52 -0
- package/dist/gen-mesh/cell-morph-mesh.js +258 -0
- package/dist/gen-mesh/cell-surface-mesh.d.ts +32 -0
- package/dist/gen-mesh/cell-surface-mesh.js +140 -0
- package/dist/gen-mesh/chunk-mesh.d.ts +25 -0
- package/dist/gen-mesh/chunk-mesh.js +112 -0
- package/dist/gen-mesh/drape-mesh.d.ts +36 -0
- package/dist/gen-mesh/drape-mesh.js +98 -0
- package/dist/gen-mesh/height-field-mesh.d.ts +14 -0
- package/dist/gen-mesh/height-field-mesh.js +98 -0
- package/dist/gen-mesh/index.d.ts +26 -0
- package/dist/gen-mesh/index.js +15 -0
- package/dist/gen-mesh/line-mesh.d.ts +25 -0
- package/dist/gen-mesh/line-mesh.js +62 -0
- package/dist/gen-mesh/mesh-builder.d.ts +115 -0
- package/dist/gen-mesh/mesh-builder.js +315 -0
- package/dist/gen-mesh/packed-mesh.d.ts +53 -0
- package/dist/gen-mesh/packed-mesh.js +205 -0
- package/dist/gen-mesh/prism-mesh.d.ts +33 -0
- package/dist/gen-mesh/prism-mesh.js +176 -0
- package/dist/gen-mesh/rig-mesh.d.ts +9 -0
- package/dist/gen-mesh/rig-mesh.js +135 -0
- package/dist/gen-mesh/strip-mesh.d.ts +45 -0
- package/dist/gen-mesh/strip-mesh.js +258 -0
- package/dist/gen-plan/drain.d.ts +58 -0
- package/dist/gen-plan/drain.js +270 -0
- package/dist/gen-plan/grid.d.ts +37 -0
- package/dist/gen-plan/grid.js +182 -0
- package/dist/gen-plan/horizon.d.ts +50 -0
- package/dist/gen-plan/horizon.js +185 -0
- package/dist/gen-plan/index.d.ts +15 -0
- package/dist/gen-plan/index.js +13 -0
- package/dist/gen-plan/line-tiles.d.ts +35 -0
- package/dist/gen-plan/line-tiles.js +190 -0
- package/dist/gen-plan/lines.d.ts +31 -0
- package/dist/gen-plan/lines.js +183 -0
- package/dist/gen-plan/plots.d.ts +40 -0
- package/dist/gen-plan/plots.js +282 -0
- package/dist/gen-plan/route.d.ts +55 -0
- package/dist/gen-plan/route.js +297 -0
- package/dist/gen-plan/sites.d.ts +32 -0
- package/dist/gen-plan/sites.js +209 -0
- package/dist/gen-tex/code-stamp.d.ts +31 -0
- package/dist/gen-tex/code-stamp.js +137 -0
- package/dist/gen-tex/index.d.ts +7 -0
- package/dist/gen-tex/index.js +5 -0
- package/dist/gen-tex/light-horizon.d.ts +47 -0
- package/dist/gen-tex/light-horizon.js +180 -0
- package/dist/gen-tex/textures.d.ts +8 -0
- package/dist/gen-tex/textures.js +49 -0
- package/dist/gen-tex/value-textures.d.ts +46 -0
- package/dist/gen-tex/value-textures.js +102 -0
- package/dist/gen-vegetation/env-slots.d.ts +20 -0
- package/dist/gen-vegetation/env-slots.js +29 -0
- package/dist/gen-vegetation/index.d.ts +8 -0
- package/dist/gen-vegetation/index.js +7 -0
- package/dist/gen-vegetation/materials.d.ts +7 -0
- package/dist/gen-vegetation/materials.js +17 -0
- package/dist/gen-vegetation/planting.d.ts +170 -0
- package/dist/gen-vegetation/planting.js +363 -0
- package/dist/gen-vegetation/tree-shader.d.ts +23 -0
- package/dist/gen-vegetation/tree-shader.js +229 -0
- package/dist/gen-vegetation/trees.d.ts +59 -0
- package/dist/gen-vegetation/trees.js +329 -0
- package/dist/gpu/device.d.ts +286 -0
- package/dist/gpu/device.js +1157 -0
- package/dist/gpu/gl.d.ts +134 -0
- package/dist/gpu/gl.js +276 -0
- package/dist/gpu/index.d.ts +4 -0
- package/dist/gpu/index.js +3 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +13 -0
- package/dist/motion/graph.d.ts +244 -0
- package/dist/motion/graph.js +739 -0
- package/dist/motion/index.d.ts +8 -0
- package/dist/motion/index.js +8 -0
- package/dist/motion/pose-ops.d.ts +30 -0
- package/dist/motion/pose-ops.js +232 -0
- package/dist/motion/reach.d.ts +45 -0
- package/dist/motion/reach.js +264 -0
- package/dist/motion/skeleton.d.ts +49 -0
- package/dist/motion/skeleton.js +99 -0
- package/dist/platform/byte-store.d.ts +21 -0
- package/dist/platform/byte-store.js +137 -0
- package/dist/platform/canvas.d.ts +29 -0
- package/dist/platform/canvas.js +76 -0
- package/dist/platform/context-loss.d.ts +8 -0
- package/dist/platform/context-loss.js +17 -0
- package/dist/platform/free-input.d.ts +51 -0
- package/dist/platform/free-input.js +100 -0
- package/dist/platform/index.d.ts +18 -0
- package/dist/platform/index.js +10 -0
- package/dist/platform/input.d.ts +48 -0
- package/dist/platform/input.js +117 -0
- package/dist/platform/keys.d.ts +12 -0
- package/dist/platform/keys.js +29 -0
- package/dist/platform/loop.d.ts +41 -0
- package/dist/platform/loop.js +84 -0
- package/dist/platform/walk-input.d.ts +74 -0
- package/dist/platform/walk-input.js +226 -0
- package/dist/platform/worker.d.ts +51 -0
- package/dist/platform/worker.js +170 -0
- package/dist/render/bone-instances.d.ts +24 -0
- package/dist/render/bone-instances.js +74 -0
- package/dist/render/cells.d.ts +70 -0
- package/dist/render/cells.js +144 -0
- package/dist/render/glsl.d.ts +66 -0
- package/dist/render/glsl.js +173 -0
- package/dist/render/index.d.ts +26 -0
- package/dist/render/index.js +16 -0
- package/dist/render/instance-sets.d.ts +97 -0
- package/dist/render/instance-sets.js +241 -0
- package/dist/render/near-instances.d.ts +75 -0
- package/dist/render/near-instances.js +219 -0
- package/dist/render/particles.d.ts +63 -0
- package/dist/render/particles.js +215 -0
- package/dist/render/pieces.d.ts +57 -0
- package/dist/render/pieces.js +151 -0
- package/dist/render/point-lights.d.ts +97 -0
- package/dist/render/point-lights.js +243 -0
- package/dist/render/renderer.d.ts +447 -0
- package/dist/render/renderer.js +1100 -0
- package/dist/render/rig.d.ts +74 -0
- package/dist/render/rig.js +576 -0
- package/dist/render/shadow-areas.d.ts +49 -0
- package/dist/render/shadow-areas.js +125 -0
- package/dist/render/shadow-glsl.d.ts +12 -0
- package/dist/render/shadow-glsl.js +146 -0
- package/dist/render/transient.d.ts +61 -0
- package/dist/render/transient.js +213 -0
- package/dist/render/value-glsl.d.ts +17 -0
- package/dist/render/value-glsl.js +208 -0
- package/dist/render/value-layers.d.ts +180 -0
- package/dist/render/value-layers.js +333 -0
- package/dist/runtime/atmosphere.d.ts +37 -0
- package/dist/runtime/atmosphere.js +304 -0
- package/dist/runtime/cloud-shell.d.ts +29 -0
- package/dist/runtime/cloud-shell.js +158 -0
- package/dist/runtime/engine.d.ts +155 -0
- package/dist/runtime/engine.js +305 -0
- package/dist/runtime/environment-link.d.ts +22 -0
- package/dist/runtime/environment-link.js +49 -0
- package/dist/runtime/index.d.ts +13 -0
- package/dist/runtime/index.js +12 -0
- package/dist/runtime/precipitation-glsl.d.ts +2 -0
- package/dist/runtime/precipitation-glsl.js +70 -0
- package/dist/runtime/precipitation.d.ts +11 -0
- package/dist/runtime/precipitation.js +78 -0
- package/dist/runtime/sky.d.ts +30 -0
- package/dist/runtime/sky.js +114 -0
- package/dist/runtime/streaming.d.ts +245 -0
- package/dist/runtime/streaming.js +602 -0
- package/dist/sim/agenda.d.ts +167 -0
- package/dist/sim/agenda.js +425 -0
- package/dist/sim/bytes.d.ts +34 -0
- package/dist/sim/bytes.js +125 -0
- package/dist/sim/destruction/apply.d.ts +59 -0
- package/dist/sim/destruction/apply.js +243 -0
- package/dist/sim/destruction/cell-states.d.ts +54 -0
- package/dist/sim/destruction/cell-states.js +198 -0
- package/dist/sim/destruction/index.d.ts +11 -0
- package/dist/sim/destruction/index.js +10 -0
- package/dist/sim/destruction/int-geometry.d.ts +17 -0
- package/dist/sim/destruction/int-geometry.js +131 -0
- package/dist/sim/destruction/pick.d.ts +13 -0
- package/dist/sim/destruction/pick.js +59 -0
- package/dist/sim/destruction/rubble.d.ts +8 -0
- package/dist/sim/destruction/rubble.js +159 -0
- package/dist/sim/destruction/state.d.ts +15 -0
- package/dist/sim/destruction/state.js +83 -0
- package/dist/sim/destruction/structure.d.ts +30 -0
- package/dist/sim/destruction/structure.js +139 -0
- package/dist/sim/events.d.ts +37 -0
- package/dist/sim/events.js +106 -0
- package/dist/sim/fixed.d.ts +21 -0
- package/dist/sim/fixed.js +64 -0
- package/dist/sim/flow-probe.d.ts +58 -0
- package/dist/sim/flow-probe.js +158 -0
- package/dist/sim/flow.d.ts +257 -0
- package/dist/sim/flow.js +967 -0
- package/dist/sim/index.d.ts +28 -0
- package/dist/sim/index.js +20 -0
- package/dist/sim/interlock.d.ts +47 -0
- package/dist/sim/interlock.js +252 -0
- package/dist/sim/movers.d.ts +228 -0
- package/dist/sim/movers.js +1083 -0
- package/dist/sim/nav.d.ts +72 -0
- package/dist/sim/nav.js +292 -0
- package/dist/sim/paths.d.ts +80 -0
- package/dist/sim/paths.js +197 -0
- package/dist/sim/regions.d.ts +87 -0
- package/dist/sim/regions.js +517 -0
- package/dist/sim/simulation.d.ts +114 -0
- package/dist/sim/simulation.js +291 -0
- package/dist/sim/states.d.ts +23 -0
- package/dist/sim/states.js +54 -0
- package/dist/sim/table.d.ts +49 -0
- package/dist/sim/table.js +126 -0
- package/dist/sim/zones.d.ts +11 -0
- package/dist/sim/zones.js +196 -0
- package/dist/tools/collision-lines.d.ts +12 -0
- package/dist/tools/collision-lines.js +50 -0
- package/dist/tools/data-view-glsl.d.ts +3 -0
- package/dist/tools/data-view-glsl.js +63 -0
- package/dist/tools/data-view-layers.d.ts +20 -0
- package/dist/tools/data-view-layers.js +60 -0
- package/dist/tools/debug-view.d.ts +30 -0
- package/dist/tools/debug-view.js +4 -0
- package/dist/tools/index.d.ts +10 -0
- package/dist/tools/index.js +7 -0
- package/dist/tools/mesh-checks.d.ts +67 -0
- package/dist/tools/mesh-checks.js +188 -0
- package/dist/tools/profile.d.ts +85 -0
- package/dist/tools/profile.js +173 -0
- package/dist/world/cell-cache.d.ts +32 -0
- package/dist/world/cell-cache.js +60 -0
- package/dist/world/cell-format.d.ts +25 -0
- package/dist/world/cell-format.js +232 -0
- package/dist/world/collide.d.ts +192 -0
- package/dist/world/collide.js +822 -0
- package/dist/world/index.d.ts +16 -0
- package/dist/world/index.js +12 -0
- package/dist/world/mesh-solids.d.ts +48 -0
- package/dist/world/mesh-solids.js +169 -0
- package/dist/world/pick.d.ts +34 -0
- package/dist/world/pick.js +177 -0
- package/dist/world/providers.d.ts +66 -0
- package/dist/world/providers.js +83 -0
- package/dist/world/sphere.d.ts +69 -0
- package/dist/world/sphere.js +271 -0
- package/dist/world/streaming.d.ts +288 -0
- package/dist/world/streaming.js +801 -0
- package/dist/world/walker.d.ts +145 -0
- package/dist/world/walker.js +502 -0
- package/docs/architecture.md +111 -0
- package/docs/cameras.md +302 -0
- package/docs/concepts.md +123 -0
- package/docs/destruction.md +127 -0
- package/docs/frames.md +199 -0
- package/docs/generators.md +575 -0
- package/docs/getting-started.md +123 -0
- package/docs/headless.md +50 -0
- package/docs/motion.md +160 -0
- package/docs/planet.md +152 -0
- package/docs/recipes.md +521 -0
- package/docs/reference.md +364 -0
- package/docs/rendering.md +823 -0
- package/docs/rigs.md +203 -0
- package/docs/simulation.md +235 -0
- package/docs/streaming.md +590 -0
- package/docs/system.md +166 -0
- package/docs/tools.md +175 -0
- package/docs/walking.md +262 -0
- package/package.json +131 -3
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { raycastHeightField, raycastPrisms } from './pick.ts';
|
|
2
|
+
export type { Prism } from './pick.ts';
|
|
3
|
+
export { CollisionWorld, newRayHit, newSlideResult } from './collide.ts';
|
|
4
|
+
export type { CollisionWorldOptions, RayHit, SlideResult, SolidInfo, SolidOptions } from './collide.ts';
|
|
5
|
+
export { addMeshSolid, convexHullXZ, meshCylinderFootprint, meshPrismFootprint } from './mesh-solids.ts';
|
|
6
|
+
export type { MeshCylinderFootprint, MeshFootprintOptions, MeshPrismFootprint } from './mesh-solids.ts';
|
|
7
|
+
export { DEFAULT_WALKER, WALKER_STATE_BYTES, Walker, newWalkIntent } from './walker.ts';
|
|
8
|
+
export type { ByteSink, ByteSource, WalkIntent, WalkerSetup, WalkerSimState } from './walker.ts';
|
|
9
|
+
export { CELL_FILE_EXT, CELL_FORMAT_VERSION, CELL_FORMAT_VERSION_SHAPED, CELL_MAGIC, cellFilePath, decodeCell, encodeCell } from './cell-format.ts';
|
|
10
|
+
export { FileCellProvider, GeneratorCellProvider } from './providers.ts';
|
|
11
|
+
export type { BytesFetcher, CellEdits, CellGenerator, CellOrigin, CellProvider, CellResult, EditableCellGenerator } from './providers.ts';
|
|
12
|
+
export { CELL_STATES, DEFAULT_STREAMING, StreamingManager, pixelsPerRadian } from './streaming.ts';
|
|
13
|
+
export type { CellRequest, CellState, ScreenErrorConfig, StreamingActions, StreamingConfig, StreamingCounters, Ticket, TicketKind } from './streaming.ts';
|
|
14
|
+
export { SphereWorld, boxMaxRadius, horizonHidden } from './sphere.ts';
|
|
15
|
+
export { CachedCellProvider } from './cell-cache.ts';
|
|
16
|
+
export type { CellCacheStats, CellStore } from './cell-cache.ts';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Layer 5, world: spatial queries over a built scene (picking against height fields and prisms, the collision world and a walker over it)
|
|
2
|
+
// and world streaming: the streaming manager (cell states, tickets, epochs, levels of detail, budgets), the provider port with a generator
|
|
3
|
+
// and a file implementation, and the binary cell format they share.
|
|
4
|
+
export { raycastHeightField, raycastPrisms } from './pick.js';
|
|
5
|
+
export { CollisionWorld, newRayHit, newSlideResult } from './collide.js';
|
|
6
|
+
export { addMeshSolid, convexHullXZ, meshCylinderFootprint, meshPrismFootprint } from './mesh-solids.js';
|
|
7
|
+
export { DEFAULT_WALKER, WALKER_STATE_BYTES, Walker, newWalkIntent } from './walker.js';
|
|
8
|
+
export { CELL_FILE_EXT, CELL_FORMAT_VERSION, CELL_FORMAT_VERSION_SHAPED, CELL_MAGIC, cellFilePath, decodeCell, encodeCell } from './cell-format.js';
|
|
9
|
+
export { FileCellProvider, GeneratorCellProvider } from './providers.js';
|
|
10
|
+
export { CELL_STATES, DEFAULT_STREAMING, StreamingManager, pixelsPerRadian } from './streaming.js';
|
|
11
|
+
export { SphereWorld, boxMaxRadius, horizonHidden } from './sphere.js';
|
|
12
|
+
export { CachedCellProvider } from './cell-cache.js';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { CollisionWorld, SolidOptions } from './collide.ts';
|
|
2
|
+
export interface MeshFootprintOptions {
|
|
3
|
+
/** Numbers per vertex in `positions`, the position being the first three. Default 3. */
|
|
4
|
+
stride?: number;
|
|
5
|
+
/** Only these vertices count (a triangle list or any list of vertex indices). Default every vertex. */
|
|
6
|
+
indices?: ArrayLike<number> | null;
|
|
7
|
+
/** First and end vertex to take (a group in a shared buffer). Default the whole buffer. Ignored with `indices`. */
|
|
8
|
+
from?: number;
|
|
9
|
+
to?: number;
|
|
10
|
+
/** Mesh space → world: 12 numbers, linear part column by column then the translation. Default none. */
|
|
11
|
+
transform?: ArrayLike<number> | null;
|
|
12
|
+
/** Only vertices at most this far above the lowest one shape the outline (overhangs left out). Default all. */
|
|
13
|
+
below?: number;
|
|
14
|
+
/** Grows (positive) or shrinks (negative) the outline, metres. Default 0. */
|
|
15
|
+
grow?: number;
|
|
16
|
+
/** Outline points are rounded to this grid before the hull, metres (0: exact). Default 0.05. */
|
|
17
|
+
snap?: number;
|
|
18
|
+
}
|
|
19
|
+
/** An upright prism over a convex outline (x, z pairs, counter-clockwise in the x, z plane), from `minY` to `maxY`. */
|
|
20
|
+
export interface MeshPrismFootprint {
|
|
21
|
+
outline: number[];
|
|
22
|
+
minY: number;
|
|
23
|
+
maxY: number;
|
|
24
|
+
}
|
|
25
|
+
/** An upright cylinder around (x, z), from `minY` to `maxY`. */
|
|
26
|
+
export interface MeshCylinderFootprint {
|
|
27
|
+
x: number;
|
|
28
|
+
z: number;
|
|
29
|
+
radius: number;
|
|
30
|
+
minY: number;
|
|
31
|
+
maxY: number;
|
|
32
|
+
}
|
|
33
|
+
/** Convex hull of x, z pairs (monotone chain), counter-clockwise in the x, z plane (x the first axis, z the second), without collinear points. */
|
|
34
|
+
export declare function convexHullXZ(points: ArrayLike<number>): number[];
|
|
35
|
+
/** The mesh's footprint as a prism over the convex hull of its vertices; null when it has fewer than three outline points. */
|
|
36
|
+
export declare function meshPrismFootprint(positions: ArrayLike<number>, o?: MeshFootprintOptions): MeshPrismFootprint | null;
|
|
37
|
+
/**
|
|
38
|
+
* The mesh's footprint as a cylinder: centred on the centroid of the hull's corners, its radius reaching the farthest
|
|
39
|
+
* outline point (plus `grow`). Null for an empty mesh.
|
|
40
|
+
*/
|
|
41
|
+
export declare function meshCylinderFootprint(positions: ArrayLike<number>, o?: MeshFootprintOptions): MeshCylinderFootprint | null;
|
|
42
|
+
/**
|
|
43
|
+
* Adds the mesh's footprint to a collision world as a prism (default) or a cylinder. Returns the solid's id, or −1
|
|
44
|
+
* when the mesh gives no footprint.
|
|
45
|
+
*/
|
|
46
|
+
export declare function addMeshSolid(world: CollisionWorld, positions: ArrayLike<number>, o?: MeshFootprintOptions & SolidOptions & {
|
|
47
|
+
shape?: 'prism' | 'cylinder';
|
|
48
|
+
}): number;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// Collision solids from a mesh: the outline of a mesh seen from above, as an upright prism (the convex hull of its
|
|
2
|
+
// vertices in x, z) or an upright cylinder (around the centre of that hull), from its lowest to its highest vertex.
|
|
3
|
+
// For compact things whose solid is roughly their footprint. Build time only: these functions allocate.
|
|
4
|
+
//
|
|
5
|
+
// The mesh is plain numbers: positions (x, y, z per vertex, or `stride` numbers per vertex with the position first),
|
|
6
|
+
// optional indices (only the vertices they name count) and an optional 3 × 4 transform (`Mat34` of base) into the
|
|
7
|
+
// world. `below` leaves out what stands higher than that over the lowest vertex (an overhang the body may pass under).
|
|
8
|
+
/** The world points of the mesh, the lowest and highest y and the x, z pairs of the outline candidates. */
|
|
9
|
+
function gather(positions, o) {
|
|
10
|
+
const stride = o.stride ?? 3;
|
|
11
|
+
const n = Math.floor(positions.length / stride);
|
|
12
|
+
const m = o.transform ?? null;
|
|
13
|
+
const pts = [];
|
|
14
|
+
const visit = (i) => {
|
|
15
|
+
if (i < 0 || i >= n)
|
|
16
|
+
return;
|
|
17
|
+
const k = i * stride;
|
|
18
|
+
const x = positions[k];
|
|
19
|
+
const y = positions[k + 1];
|
|
20
|
+
const z = positions[k + 2];
|
|
21
|
+
if (m)
|
|
22
|
+
pts.push(m[0] * x + m[3] * y + m[6] * z + m[9], m[1] * x + m[4] * y + m[7] * z + m[10], m[2] * x + m[5] * y + m[8] * z + m[11]);
|
|
23
|
+
else
|
|
24
|
+
pts.push(x, y, z);
|
|
25
|
+
};
|
|
26
|
+
if (o.indices) {
|
|
27
|
+
const seen = new Set();
|
|
28
|
+
for (let k = 0; k < o.indices.length; k++) {
|
|
29
|
+
const i = o.indices[k];
|
|
30
|
+
if (seen.has(i))
|
|
31
|
+
continue;
|
|
32
|
+
seen.add(i);
|
|
33
|
+
visit(i);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const to = Math.min(o.to ?? n, n);
|
|
38
|
+
for (let i = Math.max(0, o.from ?? 0); i < to; i++)
|
|
39
|
+
visit(i);
|
|
40
|
+
}
|
|
41
|
+
if (pts.length === 0)
|
|
42
|
+
return null;
|
|
43
|
+
let lo = Infinity;
|
|
44
|
+
let hi = -Infinity;
|
|
45
|
+
for (let k = 1; k < pts.length; k += 3) {
|
|
46
|
+
lo = Math.min(lo, pts[k]);
|
|
47
|
+
hi = Math.max(hi, pts[k]);
|
|
48
|
+
}
|
|
49
|
+
const cut = o.below !== undefined ? lo + o.below : Infinity;
|
|
50
|
+
const snap = o.snap ?? 0.05;
|
|
51
|
+
const seen = new Set();
|
|
52
|
+
const xz = [];
|
|
53
|
+
for (let k = 0; k < pts.length; k += 3) {
|
|
54
|
+
if (pts[k + 1] > cut)
|
|
55
|
+
continue;
|
|
56
|
+
const x = snap > 0 ? Math.round(pts[k] / snap) * snap : pts[k];
|
|
57
|
+
const z = snap > 0 ? Math.round(pts[k + 2] / snap) * snap : pts[k + 2];
|
|
58
|
+
const key = `${x},${z}`;
|
|
59
|
+
if (seen.has(key))
|
|
60
|
+
continue;
|
|
61
|
+
seen.add(key);
|
|
62
|
+
xz.push(x, z);
|
|
63
|
+
}
|
|
64
|
+
return { xz, minY: lo, maxY: hi };
|
|
65
|
+
}
|
|
66
|
+
/** Convex hull of x, z pairs (monotone chain), counter-clockwise in the x, z plane (x the first axis, z the second), without collinear points. */
|
|
67
|
+
export function convexHullXZ(points) {
|
|
68
|
+
const idx = [];
|
|
69
|
+
for (let i = 0; i * 2 + 1 < points.length; i++)
|
|
70
|
+
idx.push(i);
|
|
71
|
+
const X = (i) => points[i * 2];
|
|
72
|
+
const Z = (i) => points[i * 2 + 1];
|
|
73
|
+
idx.sort((a, b) => X(a) - X(b) || Z(a) - Z(b));
|
|
74
|
+
if (idx.length < 3)
|
|
75
|
+
return idx.flatMap((i) => [X(i), Z(i)]);
|
|
76
|
+
const cross = (o, a, b) => (X(a) - X(o)) * (Z(b) - Z(o)) - (Z(a) - Z(o)) * (X(b) - X(o));
|
|
77
|
+
const lower = [];
|
|
78
|
+
for (const q of idx) {
|
|
79
|
+
while (lower.length >= 2 && cross(lower[lower.length - 2], lower[lower.length - 1], q) <= 0)
|
|
80
|
+
lower.pop();
|
|
81
|
+
lower.push(q);
|
|
82
|
+
}
|
|
83
|
+
const upper = [];
|
|
84
|
+
for (let k = idx.length - 1; k >= 0; k--) {
|
|
85
|
+
const q = idx[k];
|
|
86
|
+
while (upper.length >= 2 && cross(upper[upper.length - 2], upper[upper.length - 1], q) <= 0)
|
|
87
|
+
upper.pop();
|
|
88
|
+
upper.push(q);
|
|
89
|
+
}
|
|
90
|
+
return lower
|
|
91
|
+
.slice(0, -1)
|
|
92
|
+
.concat(upper.slice(0, -1))
|
|
93
|
+
.flatMap((i) => [X(i), Z(i)]);
|
|
94
|
+
}
|
|
95
|
+
/** Moves every corner of a convex outline outward from its centroid by `d` (a cheap offset for small d). */
|
|
96
|
+
function growConvex(hull, d) {
|
|
97
|
+
const n = hull.length / 2;
|
|
98
|
+
let cx = 0;
|
|
99
|
+
let cz = 0;
|
|
100
|
+
for (let i = 0; i < n; i++) {
|
|
101
|
+
cx += hull[i * 2];
|
|
102
|
+
cz += hull[i * 2 + 1];
|
|
103
|
+
}
|
|
104
|
+
cx /= n;
|
|
105
|
+
cz /= n;
|
|
106
|
+
const out = [];
|
|
107
|
+
for (let i = 0; i < n; i++) {
|
|
108
|
+
const ex = hull[i * 2] - cx;
|
|
109
|
+
const ez = hull[i * 2 + 1] - cz;
|
|
110
|
+
const l = Math.hypot(ex, ez) || 1;
|
|
111
|
+
out.push(hull[i * 2] + (ex / l) * d, hull[i * 2 + 1] + (ez / l) * d);
|
|
112
|
+
}
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
/** The mesh's footprint as a prism over the convex hull of its vertices; null when it has fewer than three outline points. */
|
|
116
|
+
export function meshPrismFootprint(positions, o = {}) {
|
|
117
|
+
const g = gather(positions, o);
|
|
118
|
+
if (!g)
|
|
119
|
+
return null;
|
|
120
|
+
const hull = convexHullXZ(g.xz);
|
|
121
|
+
if (hull.length < 6)
|
|
122
|
+
return null;
|
|
123
|
+
return { outline: o.grow ? growConvex(hull, o.grow) : hull, minY: g.minY, maxY: g.maxY };
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The mesh's footprint as a cylinder: centred on the centroid of the hull's corners, its radius reaching the farthest
|
|
127
|
+
* outline point (plus `grow`). Null for an empty mesh.
|
|
128
|
+
*/
|
|
129
|
+
export function meshCylinderFootprint(positions, o = {}) {
|
|
130
|
+
const g = gather(positions, o);
|
|
131
|
+
if (!g)
|
|
132
|
+
return null;
|
|
133
|
+
const hull = convexHullXZ(g.xz);
|
|
134
|
+
const n = hull.length / 2;
|
|
135
|
+
let cx = 0;
|
|
136
|
+
let cz = 0;
|
|
137
|
+
for (let i = 0; i < n; i++) {
|
|
138
|
+
cx += hull[i * 2];
|
|
139
|
+
cz += hull[i * 2 + 1];
|
|
140
|
+
}
|
|
141
|
+
cx /= n;
|
|
142
|
+
cz /= n;
|
|
143
|
+
let r = 0;
|
|
144
|
+
for (let i = 0; i < n; i++)
|
|
145
|
+
r = Math.max(r, Math.hypot(hull[i * 2] - cx, hull[i * 2 + 1] - cz));
|
|
146
|
+
r += o.grow ?? 0;
|
|
147
|
+
if (!(r > 0))
|
|
148
|
+
return null;
|
|
149
|
+
return { x: cx, z: cz, radius: r, minY: g.minY, maxY: g.maxY };
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Adds the mesh's footprint to a collision world as a prism (default) or a cylinder. Returns the solid's id, or −1
|
|
153
|
+
* when the mesh gives no footprint.
|
|
154
|
+
*/
|
|
155
|
+
export function addMeshSolid(world, positions, o = {}) {
|
|
156
|
+
const solid = {};
|
|
157
|
+
if (o.standable !== undefined)
|
|
158
|
+
solid.standable = o.standable;
|
|
159
|
+
if (o.blocksSight !== undefined)
|
|
160
|
+
solid.blocksSight = o.blocksSight;
|
|
161
|
+
if (o.tag !== undefined)
|
|
162
|
+
solid.tag = o.tag;
|
|
163
|
+
if (o.shape === 'cylinder') {
|
|
164
|
+
const c = meshCylinderFootprint(positions, o);
|
|
165
|
+
return c ? world.addCylinder(c.x, c.z, c.radius, c.minY, c.maxY, solid) : -1;
|
|
166
|
+
}
|
|
167
|
+
const p = meshPrismFootprint(positions, o);
|
|
168
|
+
return p ? world.addPrism(p.outline, p.minY, p.maxY, solid) : -1;
|
|
169
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Ring } from '../gen-core/geometry.ts';
|
|
2
|
+
import type { HeightField } from '../gen-core/height-field.ts';
|
|
3
|
+
/** Vertical prism: footprint extruded from `minY` to `maxY`. Rough solid shape for the query of what is under the cursor. */
|
|
4
|
+
export interface Prism {
|
|
5
|
+
rings: Ring[];
|
|
6
|
+
minY: number;
|
|
7
|
+
maxY: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Smallest ray parameter t in [tMin, tMax) at which the ray meets the prism over `rings` (top face, side walls and,
|
|
11
|
+
* with `withBottom`, the bottom face), or Infinity. `minX`…`maxZ` is the footprint's rectangle for a quick rejection.
|
|
12
|
+
* With `normal` the unit normal of the face hit, turned against the ray, is written to it. Internal to `world`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function rayPrism(ox: number, oy: number, oz: number, dx: number, dy: number, dz: number, rings: Ring[], minY: number, maxY: number, minX: number, maxX: number, minZ: number, maxZ: number, tMin: number, tMax: number, withBottom: boolean, normal: Float64Array | null): number;
|
|
15
|
+
/**
|
|
16
|
+
* First passage of a ray from above to below a surface y = heightAt(x, z) between t0 and t1: steps of `stepT`
|
|
17
|
+
* along the ray, the passage refined by bisection. A passage where `inside` (when given) is false at both step ends
|
|
18
|
+
* or at the refined point is skipped. Returns the parameter of the passage, or NaN. Internal to `world`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function marchSurface(heightAt: (x: number, z: number) => number, ox: number, oy: number, oz: number, dx: number, dy: number, dz: number, t0: number, t1: number, stepT: number, inside: ((t: number) => boolean) | null): number;
|
|
21
|
+
/**
|
|
22
|
+
* The first prism the ray hits, counted from the camera (smallest parameter t, even negative: the ray is a whole line).
|
|
23
|
+
* The top face and side walls are used. A sloped top is flat here at its highest point, which is enough for picking.
|
|
24
|
+
*/
|
|
25
|
+
export declare function raycastPrisms(origin: readonly [number, number, number], dir: readonly [number, number, number], prisms: readonly Prism[]): {
|
|
26
|
+
index: number;
|
|
27
|
+
t: number;
|
|
28
|
+
point: [number, number, number];
|
|
29
|
+
} | null;
|
|
30
|
+
/**
|
|
31
|
+
* Where a ray first hits the height field from above, or `null` when it misses the field's extent.
|
|
32
|
+
* Steps along the ray between the highest and lowest point and refines the intersection by bisection.
|
|
33
|
+
*/
|
|
34
|
+
export declare function raycastHeightField(field: HeightField, origin: readonly [number, number, number], dir: readonly [number, number, number]): [number, number, number] | null;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// Picking: what a ray (typically from `camera.screenRay`) hits first. Rough solids are enough here.
|
|
2
|
+
// The two ray tests below (`rayPrism`, `marchSurface`) are shared with the collision world (`collide.ts`); they take
|
|
3
|
+
// plain numbers and allocate nothing, the exported picking functions wrap them.
|
|
4
|
+
import { pointInRings } from '../gen-core/geometry.js';
|
|
5
|
+
/**
|
|
6
|
+
* Smallest ray parameter t in [tMin, tMax) at which the ray meets the prism over `rings` (top face, side walls and,
|
|
7
|
+
* with `withBottom`, the bottom face), or Infinity. `minX`…`maxZ` is the footprint's rectangle for a quick rejection.
|
|
8
|
+
* With `normal` the unit normal of the face hit, turned against the ray, is written to it. Internal to `world`.
|
|
9
|
+
*/
|
|
10
|
+
export function rayPrism(ox, oy, oz, dx, dy, dz, rings, minY, maxY, minX, maxX, minZ, maxZ, tMin, tMax, withBottom, normal) {
|
|
11
|
+
// Quick rejection: rectangle around the footprint against the ray segment between the prism heights.
|
|
12
|
+
const ta = Math.abs(dy) > 1e-9 ? (maxY - oy) / dy : -1e9;
|
|
13
|
+
const tb = Math.abs(dy) > 1e-9 ? (minY - oy) / dy : 1e9;
|
|
14
|
+
const xa = ox + dx * ta;
|
|
15
|
+
const xb = ox + dx * tb;
|
|
16
|
+
const za = oz + dz * ta;
|
|
17
|
+
const zb = oz + dz * tb;
|
|
18
|
+
if (Math.max(xa, xb) < minX || Math.min(xa, xb) > maxX || Math.max(za, zb) < minZ || Math.min(za, zb) > maxZ)
|
|
19
|
+
return Infinity;
|
|
20
|
+
let best = tMax;
|
|
21
|
+
let face = 0; // 0 none, 1 top, 2 bottom, 3 side
|
|
22
|
+
let nx = 0;
|
|
23
|
+
let nz = 0;
|
|
24
|
+
// Top face.
|
|
25
|
+
if (ta >= tMin && ta < best && pointInRings(xa, za, rings)) {
|
|
26
|
+
best = ta;
|
|
27
|
+
face = 1;
|
|
28
|
+
}
|
|
29
|
+
if (withBottom && Math.abs(dy) > 1e-9 && tb >= tMin && tb < best && pointInRings(xb, zb, rings)) {
|
|
30
|
+
best = tb;
|
|
31
|
+
face = 2;
|
|
32
|
+
}
|
|
33
|
+
// Side walls: intersection of the ray's projection onto the x-z plane with the edge, and a height check.
|
|
34
|
+
for (const ring of rings) {
|
|
35
|
+
const n = ring.length / 2;
|
|
36
|
+
for (let i = 0, j = n - 1; i < n; j = i++) {
|
|
37
|
+
const ax = ring[j * 2];
|
|
38
|
+
const az = ring[j * 2 + 1];
|
|
39
|
+
const ex = ring[i * 2] - ax;
|
|
40
|
+
const ez = ring[i * 2 + 1] - az;
|
|
41
|
+
const den = dx * ez - dz * ex;
|
|
42
|
+
if (Math.abs(den) < 1e-12)
|
|
43
|
+
continue;
|
|
44
|
+
const t = ((ax - ox) * ez - (az - oz) * ex) / den;
|
|
45
|
+
const u = ((ax - ox) * dz - (az - oz) * dx) / den;
|
|
46
|
+
if (u < 0 || u > 1 || t >= best || t < tMin)
|
|
47
|
+
continue;
|
|
48
|
+
const y = oy + dy * t;
|
|
49
|
+
if (y < minY || y > maxY)
|
|
50
|
+
continue;
|
|
51
|
+
best = t;
|
|
52
|
+
face = 3;
|
|
53
|
+
nx = ez;
|
|
54
|
+
nz = -ex;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (face === 0)
|
|
58
|
+
return Infinity;
|
|
59
|
+
if (normal) {
|
|
60
|
+
if (face === 3) {
|
|
61
|
+
const len = Math.sqrt(nx * nx + nz * nz);
|
|
62
|
+
nx /= len;
|
|
63
|
+
nz /= len;
|
|
64
|
+
if (nx * dx + nz * dz > 0) {
|
|
65
|
+
nx = -nx;
|
|
66
|
+
nz = -nz;
|
|
67
|
+
}
|
|
68
|
+
normal[0] = nx;
|
|
69
|
+
normal[1] = 0;
|
|
70
|
+
normal[2] = nz;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
// A horizontal face: its normal points against the vertical part of the ray.
|
|
74
|
+
normal[0] = 0;
|
|
75
|
+
normal[1] = dy > 0 ? -1 : 1;
|
|
76
|
+
normal[2] = 0;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return best;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* First passage of a ray from above to below a surface y = heightAt(x, z) between t0 and t1: steps of `stepT`
|
|
83
|
+
* along the ray, the passage refined by bisection. A passage where `inside` (when given) is false at both step ends
|
|
84
|
+
* or at the refined point is skipped. Returns the parameter of the passage, or NaN. Internal to `world`.
|
|
85
|
+
*/
|
|
86
|
+
export function marchSurface(heightAt, ox, oy, oz, dx, dy, dz, t0, t1, stepT, inside) {
|
|
87
|
+
let prevT = t0;
|
|
88
|
+
let prev = oy + dy * t0 - heightAt(ox + dx * t0, oz + dz * t0);
|
|
89
|
+
for (let t = t0 + stepT; t <= t1 + stepT; t += stepT) {
|
|
90
|
+
const cur = oy + dy * t - heightAt(ox + dx * t, oz + dz * t);
|
|
91
|
+
if (prev >= 0 && cur < 0 && (inside === null || inside(prevT) || inside(t))) {
|
|
92
|
+
let lo = prevT;
|
|
93
|
+
let hi = t;
|
|
94
|
+
for (let k = 0; k < 30; k++) {
|
|
95
|
+
const mid = (lo + hi) / 2;
|
|
96
|
+
if (oy + dy * mid - heightAt(ox + dx * mid, oz + dz * mid) >= 0)
|
|
97
|
+
lo = mid;
|
|
98
|
+
else
|
|
99
|
+
hi = mid;
|
|
100
|
+
}
|
|
101
|
+
const th = (lo + hi) / 2;
|
|
102
|
+
if (inside !== null && !inside(th))
|
|
103
|
+
return NaN;
|
|
104
|
+
return th;
|
|
105
|
+
}
|
|
106
|
+
prevT = t;
|
|
107
|
+
prev = cur;
|
|
108
|
+
}
|
|
109
|
+
return NaN;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The first prism the ray hits, counted from the camera (smallest parameter t, even negative: the ray is a whole line).
|
|
113
|
+
* The top face and side walls are used. A sloped top is flat here at its highest point, which is enough for picking.
|
|
114
|
+
*/
|
|
115
|
+
export function raycastPrisms(origin, dir, prisms) {
|
|
116
|
+
const [ox, oy, oz] = origin;
|
|
117
|
+
const [dx, dy, dz] = dir;
|
|
118
|
+
let best = Infinity;
|
|
119
|
+
let bestIndex = -1;
|
|
120
|
+
prisms.forEach((p, index) => {
|
|
121
|
+
let minX = Infinity;
|
|
122
|
+
let maxX = -Infinity;
|
|
123
|
+
let minZ = Infinity;
|
|
124
|
+
let maxZ = -Infinity;
|
|
125
|
+
const outer = p.rings[0];
|
|
126
|
+
if (!outer)
|
|
127
|
+
return;
|
|
128
|
+
for (let i = 0; i < outer.length; i += 2) {
|
|
129
|
+
minX = Math.min(minX, outer[i]);
|
|
130
|
+
maxX = Math.max(maxX, outer[i]);
|
|
131
|
+
minZ = Math.min(minZ, outer[i + 1]);
|
|
132
|
+
maxZ = Math.max(maxZ, outer[i + 1]);
|
|
133
|
+
}
|
|
134
|
+
const t = rayPrism(ox, oy, oz, dx, dy, dz, p.rings, p.minY, p.maxY, minX, maxX, minZ, maxZ, -Infinity, best, false, null);
|
|
135
|
+
if (t < best) {
|
|
136
|
+
best = t;
|
|
137
|
+
bestIndex = index;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
if (bestIndex < 0)
|
|
141
|
+
return null;
|
|
142
|
+
return { index: bestIndex, t: best, point: [ox + dx * best, oy + dy * best, oz + dz * best] };
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Where a ray first hits the height field from above, or `null` when it misses the field's extent.
|
|
146
|
+
* Steps along the ray between the highest and lowest point and refines the intersection by bisection.
|
|
147
|
+
*/
|
|
148
|
+
export function raycastHeightField(field, origin, dir) {
|
|
149
|
+
const [ox, oy, oz] = origin;
|
|
150
|
+
const [dx, dy, dz] = dir;
|
|
151
|
+
const inside = (t) => {
|
|
152
|
+
const x = ox + dx * t;
|
|
153
|
+
const z = oz + dz * t;
|
|
154
|
+
return x >= 0 && z >= 0 && x <= field.sizeX && z <= field.sizeZ;
|
|
155
|
+
};
|
|
156
|
+
// Ray segment between the highest and the lowest point of the field.
|
|
157
|
+
let t0;
|
|
158
|
+
let t1;
|
|
159
|
+
if (Math.abs(dy) < 1e-9) {
|
|
160
|
+
t0 = -1e5;
|
|
161
|
+
t1 = 1e5;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
const ta = (field.maxY + 0.01 - oy) / dy;
|
|
165
|
+
const tb = (field.minY - 0.01 - oy) / dy;
|
|
166
|
+
t0 = Math.min(ta, tb);
|
|
167
|
+
t1 = Math.max(ta, tb);
|
|
168
|
+
}
|
|
169
|
+
const horiz = Math.hypot(dx, dz);
|
|
170
|
+
const stepT = horiz > 1e-9 ? (field.step * 0.4) / horiz : (t1 - t0) / 4;
|
|
171
|
+
const th = marchSurface((x, z) => field.heightAt(x, z), ox, oy, oz, dx, dy, dz, t0, t1, stepT, inside);
|
|
172
|
+
if (Number.isNaN(th))
|
|
173
|
+
return null;
|
|
174
|
+
const x = ox + dx * th;
|
|
175
|
+
const z = oz + dz * th;
|
|
176
|
+
return [x, field.heightAt(x, z), z];
|
|
177
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { CellContent, CellId } from '../gen-core/cell.ts';
|
|
2
|
+
/** A pure generator: world seed and cell in, content out. It reads nothing else (no clock, no files, no globals). */
|
|
3
|
+
export type CellGenerator = (seed: number, cell: CellId) => CellContent;
|
|
4
|
+
/**
|
|
5
|
+
* A pure generator that also takes edits: opaque text of what changed in the cell since it was generated (the content
|
|
6
|
+
* decides its form). Absent or '' means the cell as generated, the same bytes as the call without it. The content is a
|
|
7
|
+
* function of (seed, cell, edits) alone. A separate type, so generators whose own optional third argument means
|
|
8
|
+
* something else stay plain `CellGenerator`s.
|
|
9
|
+
*/
|
|
10
|
+
export type EditableCellGenerator = (seed: number, cell: CellId, edits?: string) => CellContent;
|
|
11
|
+
/** Source of the edits text of a cell for a provider; '' when nothing changed there. Read when a request starts. */
|
|
12
|
+
export type CellEdits = (cell: CellId) => string;
|
|
13
|
+
/** Where a finished request came from (Luanti-style emerge origins). */
|
|
14
|
+
export type CellOrigin = 'generated' | 'file' | 'memory';
|
|
15
|
+
export interface CellResult {
|
|
16
|
+
content: CellContent;
|
|
17
|
+
/** The encoded bytes the content was decoded from, when there were any (a worker or a file). */
|
|
18
|
+
bytes: Uint8Array | null;
|
|
19
|
+
origin: CellOrigin;
|
|
20
|
+
}
|
|
21
|
+
export interface CellProvider {
|
|
22
|
+
readonly name: string;
|
|
23
|
+
/**
|
|
24
|
+
* True when `request` does its work synchronously on the calling thread. The execution part then calls it only
|
|
25
|
+
* within the frame's time budget.
|
|
26
|
+
*/
|
|
27
|
+
readonly blocking: boolean;
|
|
28
|
+
/** Content of a cell. Rejects with an `AbortError`-named error when the signal fires first. */
|
|
29
|
+
request(cell: CellId, signal: AbortSignal): Promise<CellResult>;
|
|
30
|
+
}
|
|
31
|
+
/** Runs a pure generator on the calling thread. */
|
|
32
|
+
export declare class GeneratorCellProvider implements CellProvider {
|
|
33
|
+
readonly name = "generator (main thread)";
|
|
34
|
+
readonly blocking = true;
|
|
35
|
+
readonly seed: number;
|
|
36
|
+
private readonly generate;
|
|
37
|
+
private readonly edits;
|
|
38
|
+
/** With `edits`, a cell whose edits text is not empty is generated with it; every other call is `generate(seed, cell)`. */
|
|
39
|
+
constructor(seed: number, generate: CellGenerator);
|
|
40
|
+
constructor(seed: number, generate: EditableCellGenerator, edits?: CellEdits);
|
|
41
|
+
/** Synchronous core, also used by bakers and tests. */
|
|
42
|
+
generateNow(cell: CellId): CellContent;
|
|
43
|
+
/** Encoded bytes of a cell, exactly what a worker or a baked file hands over. */
|
|
44
|
+
bytes(cell: CellId): Uint8Array;
|
|
45
|
+
request(cell: CellId, signal: AbortSignal): Promise<CellResult>;
|
|
46
|
+
private run;
|
|
47
|
+
}
|
|
48
|
+
/** Fetches bytes of a URL; rejects on a missing file. A browser passes `fetchBytes` from platform. */
|
|
49
|
+
export type BytesFetcher = (url: string, signal: AbortSignal) => Promise<ArrayBuffer>;
|
|
50
|
+
/**
|
|
51
|
+
* Reads pre-baked cells (`<baseUrl>/<face>/<level>/<x>/<y>.whc`) through a fetch function. With `shapeHash` (the hash
|
|
52
|
+
* of the world shape, `shapeHash` of gen-core) the files are read from `<baseUrl>/s<hash>/…` and a file that states
|
|
53
|
+
* another shape is rejected.
|
|
54
|
+
*/
|
|
55
|
+
export declare class FileCellProvider implements CellProvider {
|
|
56
|
+
readonly name: string;
|
|
57
|
+
readonly blocking = false;
|
|
58
|
+
readonly baseUrl: string;
|
|
59
|
+
readonly shapeHash: number | undefined;
|
|
60
|
+
private readonly fetch;
|
|
61
|
+
constructor(baseUrl: string, fetch: BytesFetcher, options?: {
|
|
62
|
+
shapeHash?: number;
|
|
63
|
+
});
|
|
64
|
+
url(cell: CellId): string;
|
|
65
|
+
request(cell: CellId, signal: AbortSignal): Promise<CellResult>;
|
|
66
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// The provider port (Wallhammer Zero `gen_provider` / `asset_provider`): where the content of a cell comes from.
|
|
2
|
+
// A cell can come from a generator or from a pre-baked file in the same format; the streaming manager does not know
|
|
3
|
+
// which. The level of detail is the cell's quadtree level, so `request(cell)` names both the place and the detail.
|
|
4
|
+
//
|
|
5
|
+
// Implementations here are plain logic and run in Node: a generator on the calling thread (the fallback for headless
|
|
6
|
+
// runs and tests, and for browsers without workers) and a file provider over any fetch function. The worker-backed
|
|
7
|
+
// generator lives in `runtime`, because workers belong to `platform`.
|
|
8
|
+
//
|
|
9
|
+
// Edits: a generator provider may get a source of edits text per cell (`CellEdits`) and hands a non-empty text to the
|
|
10
|
+
// generator as its third argument. The file provider and the cache (cell-cache.ts) know nothing of edits.
|
|
11
|
+
import { decodeCell, encodeCell, cellFilePath } from './cell-format.js';
|
|
12
|
+
function aborted() {
|
|
13
|
+
const e = new Error('cell request cancelled');
|
|
14
|
+
e.name = 'AbortError';
|
|
15
|
+
return e;
|
|
16
|
+
}
|
|
17
|
+
/** Runs a pure generator on the calling thread. */
|
|
18
|
+
export class GeneratorCellProvider {
|
|
19
|
+
name = 'generator (main thread)';
|
|
20
|
+
blocking = true;
|
|
21
|
+
seed;
|
|
22
|
+
generate;
|
|
23
|
+
edits;
|
|
24
|
+
constructor(seed, generate, edits) {
|
|
25
|
+
this.seed = seed;
|
|
26
|
+
this.generate = generate;
|
|
27
|
+
this.edits = edits;
|
|
28
|
+
}
|
|
29
|
+
/** Synchronous core, also used by bakers and tests. */
|
|
30
|
+
generateNow(cell) {
|
|
31
|
+
return this.run(cell);
|
|
32
|
+
}
|
|
33
|
+
/** Encoded bytes of a cell, exactly what a worker or a baked file hands over. */
|
|
34
|
+
bytes(cell) {
|
|
35
|
+
return encodeCell(this.run(cell));
|
|
36
|
+
}
|
|
37
|
+
request(cell, signal) {
|
|
38
|
+
if (signal.aborted)
|
|
39
|
+
return Promise.reject(aborted());
|
|
40
|
+
try {
|
|
41
|
+
return Promise.resolve({ content: this.run(cell), bytes: null, origin: 'generated' });
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
return Promise.reject(e);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
run(cell) {
|
|
48
|
+
const text = this.edits ? this.edits(cell) : '';
|
|
49
|
+
return text ? this.generate(this.seed, cell, text) : this.generate(this.seed, cell);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Reads pre-baked cells (`<baseUrl>/<face>/<level>/<x>/<y>.whc`) through a fetch function. With `shapeHash` (the hash
|
|
54
|
+
* of the world shape, `shapeHash` of gen-core) the files are read from `<baseUrl>/s<hash>/…` and a file that states
|
|
55
|
+
* another shape is rejected.
|
|
56
|
+
*/
|
|
57
|
+
export class FileCellProvider {
|
|
58
|
+
name;
|
|
59
|
+
blocking = false;
|
|
60
|
+
baseUrl;
|
|
61
|
+
shapeHash;
|
|
62
|
+
fetch;
|
|
63
|
+
constructor(baseUrl, fetch, options = {}) {
|
|
64
|
+
this.baseUrl = baseUrl.replace(/\/+$/, '');
|
|
65
|
+
this.fetch = fetch;
|
|
66
|
+
this.shapeHash = options.shapeHash;
|
|
67
|
+
this.name = `files (${this.baseUrl})`;
|
|
68
|
+
}
|
|
69
|
+
url(cell) {
|
|
70
|
+
return `${this.baseUrl}/${cellFilePath(cell, this.shapeHash)}`;
|
|
71
|
+
}
|
|
72
|
+
async request(cell, signal) {
|
|
73
|
+
const buf = await this.fetch(this.url(cell), signal);
|
|
74
|
+
if (signal.aborted)
|
|
75
|
+
throw aborted();
|
|
76
|
+
const bytes = new Uint8Array(buf);
|
|
77
|
+
const content = decodeCell(bytes);
|
|
78
|
+
if (this.shapeHash !== undefined && content.shapeHash !== this.shapeHash) {
|
|
79
|
+
throw new Error(`cell file ${this.url(cell)} was built for another world shape (${content.shapeHash ?? 'none'}, expected ${this.shapeHash})`);
|
|
80
|
+
}
|
|
81
|
+
return { content, bytes, origin: 'file' };
|
|
82
|
+
}
|
|
83
|
+
}
|