wallhammer-web 0.0.0-stage → 0.4.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 +21 -0
- package/README.md +88 -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,69 @@
|
|
|
1
|
+
import type { Vec3 } from '../base/math.ts';
|
|
2
|
+
import type { RadialUp } from '../base/up.ts';
|
|
3
|
+
import type { CellId, WorldPos, WorldShape } from '../gen-core/cell.ts';
|
|
4
|
+
/** A sphere of six quadtrees. Faces: 0 +x, 1 −x, 2 +y, 3 −y, 4 +z, 5 −z. */
|
|
5
|
+
export declare class SphereWorld implements WorldShape {
|
|
6
|
+
readonly name = "sphere";
|
|
7
|
+
/** Radius of the base sphere in metres. */
|
|
8
|
+
readonly radiusM: number;
|
|
9
|
+
/** Centre of the sphere in world metres. */
|
|
10
|
+
readonly centerM: WorldPos;
|
|
11
|
+
/** The same as a description of "up" for a renderer (`RendererOptions.radialUp`). */
|
|
12
|
+
readonly radial: RadialUp;
|
|
13
|
+
readonly hashKey: string;
|
|
14
|
+
private readonly footprints;
|
|
15
|
+
constructor(radiusM: number, center?: WorldPos);
|
|
16
|
+
/**
|
|
17
|
+
* Edge of a cell of this level along the base sphere: a quarter of the circumference for a whole face. It is the
|
|
18
|
+
* longest edge a cell of the level has (the edges through the face's middle); toward the corners edges shrink to
|
|
19
|
+
* about three quarters of it.
|
|
20
|
+
*/
|
|
21
|
+
edgeM(level: number): number;
|
|
22
|
+
/** Unit direction from the centre to a world position (+y at the centre itself). */
|
|
23
|
+
directionOf(p: WorldPos): Vec3;
|
|
24
|
+
/** Height of a world position above the base sphere. */
|
|
25
|
+
altitude(p: WorldPos): number;
|
|
26
|
+
/** World position `heightM` above the base sphere, on the line from the centre through `p`. */
|
|
27
|
+
atHeight(p: WorldPos, heightM?: number): WorldPos;
|
|
28
|
+
/**
|
|
29
|
+
* How far under the sphere the flat triangles of a grid can dip: a cell of `level` drawn with `quads` intervals
|
|
30
|
+
* along its edge has its vertices on the sphere and its triangles a little inside it. Lower the radius of a horizon
|
|
31
|
+
* occluder by the drop of the coarsest level that is drawn (see `horizonHidden`).
|
|
32
|
+
*/
|
|
33
|
+
facetDropM(level: number, quads: number): number;
|
|
34
|
+
cellAt(p: WorldPos, level: number): CellId;
|
|
35
|
+
origin(c: CellId): WorldPos;
|
|
36
|
+
toLocal(c: CellId, p: WorldPos): Vec3;
|
|
37
|
+
toWorld(c: CellId, local: readonly [number, number, number]): WorldPos;
|
|
38
|
+
distanceM(c: CellId, p: WorldPos): number;
|
|
39
|
+
center(c: CellId): WorldPos;
|
|
40
|
+
/** Cells of `level` within `reachM`, face by face, each face in the order of its quadtree. `Infinity` gives them all. */
|
|
41
|
+
cellsNear(p: WorldPos, reachM: number, level: number): CellId[];
|
|
42
|
+
/**
|
|
43
|
+
* Cells sharing an edge or a corner. A cell at a corner of the cube has seven: three faces meet there, and no cell
|
|
44
|
+
* lies diagonally across the corner.
|
|
45
|
+
*/
|
|
46
|
+
neighbours(c: CellId): CellId[];
|
|
47
|
+
parent(c: CellId): CellId | null;
|
|
48
|
+
children(c: CellId): CellId[];
|
|
49
|
+
upAt(p: WorldPos): Vec3;
|
|
50
|
+
/** The point of the base sphere under `p`, in metres from the centre: what 3D noise is evaluated at. */
|
|
51
|
+
noiseDomain(p: WorldPos): [number, number, number];
|
|
52
|
+
private footprint;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* True when nothing of a body can be seen because the sphere's own bulge is in the way: the test for culling by the
|
|
56
|
+
* horizon. All it needs is distances, so it is cheap and never hides something that shows.
|
|
57
|
+
*
|
|
58
|
+
* - `eye`: the viewer relative to the sphere's centre.
|
|
59
|
+
* - `occluderRadiusM`: radius of the sphere that hides things. It must lie under everything that is drawn, so use the
|
|
60
|
+
* base radius plus the lowest height the content can have; a larger one cuts holes at the horizon.
|
|
61
|
+
* - `nearestM`: distance from the viewer to the nearest point of the body (to its bounding box, say).
|
|
62
|
+
* - `maxRadiusM`: the largest distance from the centre any point of the body has (its highest point).
|
|
63
|
+
*
|
|
64
|
+
* A point at radius r can be seen at most `√(|eye|² − R²) + √(r² − R²)` away: the viewer's distance to the horizon
|
|
65
|
+
* plus the point's own. A body whose nearest point is farther than that for its highest point is hidden as a whole.
|
|
66
|
+
*/
|
|
67
|
+
export declare function horizonHidden(eye: readonly [number, number, number], occluderRadiusM: number, nearestM: number, maxRadiusM: number): boolean;
|
|
68
|
+
/** The largest distance from a centre that any point of an axis-aligned box has (it is always at a corner). */
|
|
69
|
+
export declare function boxMaxRadius(min: readonly [number, number, number], max: readonly [number, number, number], center: readonly [number, number, number]): number;
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
// A world wrapped round a point: the sphere implementation of the world shape port, and the test that hides what
|
|
2
|
+
// lies behind the sphere's own horizon.
|
|
3
|
+
//
|
|
4
|
+
// The sphere is a cube blown up (gen-core, cube-sphere): six faces, each the root of a quadtree of cells. A cell id
|
|
5
|
+
// carries the face (0–5), the level, and the cell's indices on the face, both from 0 to 2^level − 1. Streaming,
|
|
6
|
+
// tickets and budgets work on it unchanged, because they ask the shape for every fact of place.
|
|
7
|
+
//
|
|
8
|
+
// - Cell-local axes are the world's axes. A cell's origin is the middle of its footprint on the base sphere; content
|
|
9
|
+
// is relative to it, so numbers stay small at any level, and nothing has to be rotated between a cell and the world.
|
|
10
|
+
// - "Up" points away from the centre. Heights are measured from the base sphere of `radiusM`.
|
|
11
|
+
// - Distances are measured along the base sphere, as the port asks.
|
|
12
|
+
//
|
|
13
|
+
// Everything here is reproducible arithmetic (the trigonometry of base), so the same camera path asks for the same
|
|
14
|
+
// cells on every machine.
|
|
15
|
+
import { detAsin, detAtan2 } from '../base/trig.js';
|
|
16
|
+
import { cellId, cellKey } from '../gen-core/cell.js';
|
|
17
|
+
import { CUBE_FACE_AXES, cubeDirection, cubeDirectionWarped, cubeFaceOf, cubeGrid, cubeNeighbour, cubeWarp } from '../gen-core/cube-sphere.js';
|
|
18
|
+
const HALF_PI = 1.5707963267948966;
|
|
19
|
+
/** Cells whose corner directions are remembered between calls. */
|
|
20
|
+
const CORNER_CACHE = 4096;
|
|
21
|
+
/** A sphere of six quadtrees. Faces: 0 +x, 1 −x, 2 +y, 3 −y, 4 +z, 5 −z. */
|
|
22
|
+
export class SphereWorld {
|
|
23
|
+
name = 'sphere';
|
|
24
|
+
/** Radius of the base sphere in metres. */
|
|
25
|
+
radiusM;
|
|
26
|
+
/** Centre of the sphere in world metres. */
|
|
27
|
+
centerM;
|
|
28
|
+
/** The same as a description of "up" for a renderer (`RendererOptions.radialUp`). */
|
|
29
|
+
radial;
|
|
30
|
+
hashKey;
|
|
31
|
+
footprints = new Map();
|
|
32
|
+
constructor(radiusM, center = [0, 0, 0]) {
|
|
33
|
+
if (!(radiusM > 0))
|
|
34
|
+
throw new Error(`SphereWorld: radius must be positive, got ${radiusM}`);
|
|
35
|
+
this.radiusM = radiusM;
|
|
36
|
+
this.centerM = [center[0], center[1], center[2]];
|
|
37
|
+
this.radial = { center: this.centerM, radiusM };
|
|
38
|
+
this.hashKey = `sphere:tan:${radiusM}:${center[0]},${center[1]},${center[2]}`;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Edge of a cell of this level along the base sphere: a quarter of the circumference for a whole face. It is the
|
|
42
|
+
* longest edge a cell of the level has (the edges through the face's middle); toward the corners edges shrink to
|
|
43
|
+
* about three quarters of it.
|
|
44
|
+
*/
|
|
45
|
+
edgeM(level) {
|
|
46
|
+
return (HALF_PI * this.radiusM) / 2 ** level;
|
|
47
|
+
}
|
|
48
|
+
/** Unit direction from the centre to a world position (+y at the centre itself). */
|
|
49
|
+
directionOf(p) {
|
|
50
|
+
const x = p[0] - this.centerM[0];
|
|
51
|
+
const y = p[1] - this.centerM[1];
|
|
52
|
+
const z = p[2] - this.centerM[2];
|
|
53
|
+
const l = Math.sqrt(x * x + y * y + z * z);
|
|
54
|
+
return l > 0 ? [x / l, y / l, z / l] : [0, 1, 0];
|
|
55
|
+
}
|
|
56
|
+
/** Height of a world position above the base sphere. */
|
|
57
|
+
altitude(p) {
|
|
58
|
+
const x = p[0] - this.centerM[0];
|
|
59
|
+
const y = p[1] - this.centerM[1];
|
|
60
|
+
const z = p[2] - this.centerM[2];
|
|
61
|
+
return Math.sqrt(x * x + y * y + z * z) - this.radiusM;
|
|
62
|
+
}
|
|
63
|
+
/** World position `heightM` above the base sphere, on the line from the centre through `p`. */
|
|
64
|
+
atHeight(p, heightM = 0) {
|
|
65
|
+
const d = this.directionOf(p);
|
|
66
|
+
const r = this.radiusM + heightM;
|
|
67
|
+
return [this.centerM[0] + d[0] * r, this.centerM[1] + d[1] * r, this.centerM[2] + d[2] * r];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* How far under the sphere the flat triangles of a grid can dip: a cell of `level` drawn with `quads` intervals
|
|
71
|
+
* along its edge has its vertices on the sphere and its triangles a little inside it. Lower the radius of a horizon
|
|
72
|
+
* occluder by the drop of the coarsest level that is drawn (see `horizonHidden`).
|
|
73
|
+
*/
|
|
74
|
+
facetDropM(level, quads) {
|
|
75
|
+
// Half the diagonal of a quad, as an angle; 1 − cos a is at most a² / 2.
|
|
76
|
+
const a = (HALF_PI / 2 ** level / quads) * Math.SQRT1_2;
|
|
77
|
+
return (this.radiusM * a * a) / 2;
|
|
78
|
+
}
|
|
79
|
+
cellAt(p, level) {
|
|
80
|
+
const n = 2 ** level;
|
|
81
|
+
const { face, s, t } = cubeFaceOf(this.directionOf(p));
|
|
82
|
+
const x = Math.min(n - 1, Math.max(0, Math.floor(((s + 1) / 2) * n)));
|
|
83
|
+
const y = Math.min(n - 1, Math.max(0, Math.floor(((t + 1) / 2) * n)));
|
|
84
|
+
return cellId(face, level, x, y);
|
|
85
|
+
}
|
|
86
|
+
origin(c) {
|
|
87
|
+
return this.center(c);
|
|
88
|
+
}
|
|
89
|
+
toLocal(c, p) {
|
|
90
|
+
const o = this.center(c);
|
|
91
|
+
return [Math.fround(p[0] - o[0]), Math.fround(p[1] - o[1]), Math.fround(p[2] - o[2])];
|
|
92
|
+
}
|
|
93
|
+
toWorld(c, local) {
|
|
94
|
+
const o = this.center(c);
|
|
95
|
+
return [o[0] + local[0], o[1] + local[1], o[2] + local[2]];
|
|
96
|
+
}
|
|
97
|
+
distanceM(c, p) {
|
|
98
|
+
const f = this.footprint(c);
|
|
99
|
+
const d = this.directionOf(p);
|
|
100
|
+
const a = CUBE_FACE_AXES[c.face];
|
|
101
|
+
const along = d[0] * a.n[0] + d[1] * a.n[1] + d[2] * a.n[2];
|
|
102
|
+
if (along > 0) {
|
|
103
|
+
const pu = (d[0] * a.u[0] + d[1] * a.u[1] + d[2] * a.u[2]) / along;
|
|
104
|
+
const pv = (d[0] * a.v[0] + d[1] * a.v[1] + d[2] * a.v[2]) / along;
|
|
105
|
+
if (pu >= f.wu0 && pu <= f.wu1 && pv >= f.wv0 && pv <= f.wv1)
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
|
108
|
+
// Outside: the nearest point lies on one of the four edges, each an arc of a great circle.
|
|
109
|
+
const k = f.corners;
|
|
110
|
+
let best = Infinity;
|
|
111
|
+
for (let e = 0; e < 4; e++) {
|
|
112
|
+
const i = e * 3;
|
|
113
|
+
const j = ((e + 1) % 4) * 3;
|
|
114
|
+
const angle = arcDistance(d[0], d[1], d[2], k[i], k[i + 1], k[i + 2], k[j], k[j + 1], k[j + 2]);
|
|
115
|
+
if (angle < best)
|
|
116
|
+
best = angle;
|
|
117
|
+
}
|
|
118
|
+
return best * this.radiusM;
|
|
119
|
+
}
|
|
120
|
+
center(c) {
|
|
121
|
+
const n = 2 * 2 ** c.level;
|
|
122
|
+
const d = cubeDirection(c.face, cubeGrid(2 * c.x + 1, n), cubeGrid(2 * c.y + 1, n));
|
|
123
|
+
const r = this.radiusM;
|
|
124
|
+
return [this.centerM[0] + d[0] * r, this.centerM[1] + d[1] * r, this.centerM[2] + d[2] * r];
|
|
125
|
+
}
|
|
126
|
+
/** Cells of `level` within `reachM`, face by face, each face in the order of its quadtree. `Infinity` gives them all. */
|
|
127
|
+
cellsNear(p, reachM, level) {
|
|
128
|
+
const out = [];
|
|
129
|
+
// A cell's footprint lies inside its parent's, so a parent out of reach has no child in reach.
|
|
130
|
+
const slack = this.radiusM * 1e-9;
|
|
131
|
+
const visit = (c) => {
|
|
132
|
+
if (reachM < Infinity && this.distanceM(c, p) > reachM + slack)
|
|
133
|
+
return;
|
|
134
|
+
if (c.level === level) {
|
|
135
|
+
out.push(c);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
for (const child of this.children(c))
|
|
139
|
+
visit(child);
|
|
140
|
+
};
|
|
141
|
+
for (let face = 0; face < 6; face++)
|
|
142
|
+
visit(cellId(face, 0, 0, 0));
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Cells sharing an edge or a corner. A cell at a corner of the cube has seven: three faces meet there, and no cell
|
|
147
|
+
* lies diagonally across the corner.
|
|
148
|
+
*/
|
|
149
|
+
neighbours(c) {
|
|
150
|
+
const out = [];
|
|
151
|
+
for (let dy = -1; dy <= 1; dy++) {
|
|
152
|
+
for (let dx = -1; dx <= 1; dx++) {
|
|
153
|
+
if (dx === 0 && dy === 0)
|
|
154
|
+
continue;
|
|
155
|
+
const n = cubeNeighbour(c.face, c.level, c.x, c.y, dx, dy);
|
|
156
|
+
if (n)
|
|
157
|
+
out.push(cellId(n.face, c.level, n.x, n.y));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return out;
|
|
161
|
+
}
|
|
162
|
+
parent(c) {
|
|
163
|
+
if (c.level === 0)
|
|
164
|
+
return null;
|
|
165
|
+
return cellId(c.face, c.level - 1, Math.floor(c.x / 2), Math.floor(c.y / 2));
|
|
166
|
+
}
|
|
167
|
+
children(c) {
|
|
168
|
+
const l = c.level + 1;
|
|
169
|
+
const x = c.x * 2;
|
|
170
|
+
const y = c.y * 2;
|
|
171
|
+
return [cellId(c.face, l, x, y), cellId(c.face, l, x + 1, y), cellId(c.face, l, x, y + 1), cellId(c.face, l, x + 1, y + 1)];
|
|
172
|
+
}
|
|
173
|
+
upAt(p) {
|
|
174
|
+
return this.directionOf(p);
|
|
175
|
+
}
|
|
176
|
+
/** The point of the base sphere under `p`, in metres from the centre: what 3D noise is evaluated at. */
|
|
177
|
+
noiseDomain(p) {
|
|
178
|
+
const d = this.directionOf(p);
|
|
179
|
+
return [d[0] * this.radiusM, d[1] * this.radiusM, d[2] * this.radiusM];
|
|
180
|
+
}
|
|
181
|
+
footprint(c) {
|
|
182
|
+
const key = cellKey(c);
|
|
183
|
+
let f = this.footprints.get(key);
|
|
184
|
+
if (f)
|
|
185
|
+
return f;
|
|
186
|
+
const n = 2 ** c.level;
|
|
187
|
+
const wu0 = cubeWarp(cubeGrid(c.x, n));
|
|
188
|
+
const wu1 = cubeWarp(cubeGrid(c.x + 1, n));
|
|
189
|
+
const wv0 = cubeWarp(cubeGrid(c.y, n));
|
|
190
|
+
const wv1 = cubeWarp(cubeGrid(c.y + 1, n));
|
|
191
|
+
const corners = new Float64Array(12);
|
|
192
|
+
const d = [0, 0, 0];
|
|
193
|
+
const put = (i, wu, wv) => {
|
|
194
|
+
cubeDirectionWarped(c.face, wu, wv, d);
|
|
195
|
+
corners.set(d, i * 3);
|
|
196
|
+
};
|
|
197
|
+
put(0, wu0, wv0);
|
|
198
|
+
put(1, wu1, wv0);
|
|
199
|
+
put(2, wu1, wv1);
|
|
200
|
+
put(3, wu0, wv1);
|
|
201
|
+
f = { wu0, wu1, wv0, wv1, corners };
|
|
202
|
+
// The cache only saves work; what it returns does not depend on what it holds.
|
|
203
|
+
if (this.footprints.size >= CORNER_CACHE)
|
|
204
|
+
this.footprints.clear();
|
|
205
|
+
this.footprints.set(key, f);
|
|
206
|
+
return f;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/** Angle between two unit vectors, exact for small angles too. */
|
|
210
|
+
function angleBetween(ax, ay, az, bx, by, bz) {
|
|
211
|
+
const cx = ay * bz - az * by;
|
|
212
|
+
const cy = az * bx - ax * bz;
|
|
213
|
+
const cz = ax * by - ay * bx;
|
|
214
|
+
return detAtan2(Math.sqrt(cx * cx + cy * cy + cz * cz), ax * bx + ay * by + az * bz);
|
|
215
|
+
}
|
|
216
|
+
/** Angle from unit direction p to the nearest point of the arc of a great circle from a to b (unit, less than half a turn apart). */
|
|
217
|
+
function arcDistance(px, py, pz, ax, ay, az, bx, by, bz) {
|
|
218
|
+
// Normal of the arc's plane.
|
|
219
|
+
let nx = ay * bz - az * by;
|
|
220
|
+
let ny = az * bx - ax * bz;
|
|
221
|
+
let nz = ax * by - ay * bx;
|
|
222
|
+
const nl = Math.sqrt(nx * nx + ny * ny + nz * nz);
|
|
223
|
+
if (nl > 0) {
|
|
224
|
+
nx /= nl;
|
|
225
|
+
ny /= nl;
|
|
226
|
+
nz /= nl;
|
|
227
|
+
const off = px * nx + py * ny + pz * nz;
|
|
228
|
+
// p dropped onto the plane; it lies over the arc when it is on b's side of a and on a's side of b.
|
|
229
|
+
const qx = px - off * nx;
|
|
230
|
+
const qy = py - off * ny;
|
|
231
|
+
const qz = pz - off * nz;
|
|
232
|
+
const fromA = (ay * qz - az * qy) * nx + (az * qx - ax * qz) * ny + (ax * qy - ay * qx) * nz;
|
|
233
|
+
const toB = (qy * bz - qz * by) * nx + (qz * bx - qx * bz) * ny + (qx * by - qy * bx) * nz;
|
|
234
|
+
if (fromA >= 0 && toB >= 0)
|
|
235
|
+
return detAsin(Math.min(1, Math.abs(off)));
|
|
236
|
+
}
|
|
237
|
+
return Math.min(angleBetween(px, py, pz, ax, ay, az), angleBetween(px, py, pz, bx, by, bz));
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* True when nothing of a body can be seen because the sphere's own bulge is in the way: the test for culling by the
|
|
241
|
+
* horizon. All it needs is distances, so it is cheap and never hides something that shows.
|
|
242
|
+
*
|
|
243
|
+
* - `eye`: the viewer relative to the sphere's centre.
|
|
244
|
+
* - `occluderRadiusM`: radius of the sphere that hides things. It must lie under everything that is drawn, so use the
|
|
245
|
+
* base radius plus the lowest height the content can have; a larger one cuts holes at the horizon.
|
|
246
|
+
* - `nearestM`: distance from the viewer to the nearest point of the body (to its bounding box, say).
|
|
247
|
+
* - `maxRadiusM`: the largest distance from the centre any point of the body has (its highest point).
|
|
248
|
+
*
|
|
249
|
+
* A point at radius r can be seen at most `√(|eye|² − R²) + √(r² − R²)` away: the viewer's distance to the horizon
|
|
250
|
+
* plus the point's own. A body whose nearest point is farther than that for its highest point is hidden as a whole.
|
|
251
|
+
*/
|
|
252
|
+
export function horizonHidden(eye, occluderRadiusM, nearestM, maxRadiusM) {
|
|
253
|
+
const r2 = occluderRadiusM * occluderRadiusM;
|
|
254
|
+
const e2 = eye[0] * eye[0] + eye[1] * eye[1] + eye[2] * eye[2];
|
|
255
|
+
// A viewer inside the hiding sphere sees through it: hide nothing.
|
|
256
|
+
if (!(e2 > r2))
|
|
257
|
+
return false;
|
|
258
|
+
const far = Math.sqrt(e2 - r2) + Math.sqrt(Math.max(0, maxRadiusM * maxRadiusM - r2));
|
|
259
|
+
return nearestM > far;
|
|
260
|
+
}
|
|
261
|
+
/** The largest distance from a centre that any point of an axis-aligned box has (it is always at a corner). */
|
|
262
|
+
export function boxMaxRadius(min, max, center) {
|
|
263
|
+
let r2 = 0;
|
|
264
|
+
for (let i = 0; i < 3; i++) {
|
|
265
|
+
const a = Math.abs(min[i] - center[i]);
|
|
266
|
+
const b = Math.abs(max[i] - center[i]);
|
|
267
|
+
const m = a > b ? a : b;
|
|
268
|
+
r2 += m * m;
|
|
269
|
+
}
|
|
270
|
+
return Math.sqrt(r2);
|
|
271
|
+
}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import type { CellId, WorldPos, WorldShape } from '../gen-core/cell.ts';
|
|
2
|
+
/** Cell states of the design. MACRO, LAYOUT and CONTENT are passed inside one job here; ACTIVE is not used. */
|
|
3
|
+
export declare const CELL_STATES: readonly ['NONE', 'MACRO', 'LAYOUT', 'CONTENT', 'MESHED', 'RESIDENT', 'ACTIVE'];
|
|
4
|
+
export type CellState = (typeof CELL_STATES)[number];
|
|
5
|
+
/** Ticket kinds of the design. */
|
|
6
|
+
export type TicketKind = 'player' | 'predict' | 'camera' | 'travel' | 'tool';
|
|
7
|
+
export interface Ticket {
|
|
8
|
+
/** Stable name; tickets are processed in the order of their ids. */
|
|
9
|
+
id: string;
|
|
10
|
+
kind: TicketKind;
|
|
11
|
+
/** Where the ticket stands (world metres, double). */
|
|
12
|
+
center: WorldPos;
|
|
13
|
+
/** Height of the viewer above the ground, added to the horizontal distance (0 = on the ground). */
|
|
14
|
+
altitude?: number;
|
|
15
|
+
/** Base level: 0 for the viewer, 1 for a predicted point (tighter rings). */
|
|
16
|
+
base: number;
|
|
17
|
+
/**
|
|
18
|
+
* Direction of view or travel; cells in front of it are fetched first. Two numbers are [x, z] on a flat world,
|
|
19
|
+
* three are a world direction (the manager compares it with the direction to a cell across "up" at the ticket).
|
|
20
|
+
*/
|
|
21
|
+
dir?: readonly [number, number] | readonly [number, number, number];
|
|
22
|
+
/**
|
|
23
|
+
* Pixels that one radian covers on the viewer's screen (`pixelsPerRadian`). Used only by selection by screen-space
|
|
24
|
+
* error; a ticket without it uses the configured default.
|
|
25
|
+
*/
|
|
26
|
+
pixelsPerRadian?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Selection by screen-space error only: the ticket loads its cells but does not change what is drawn. Cells it alone
|
|
29
|
+
* asks for are fetched and kept ready on the CPU; they replace their parent on the screen only once a ticket without
|
|
30
|
+
* this flag wants them. For a predicted point ahead of the viewer: the levels on the screen then depend on the
|
|
31
|
+
* viewer alone, which the blend between levels needs (a cell split far from the viewer would show its parent's
|
|
32
|
+
* shape without the parent's own blend, a step). The coarsest cells near it are wanted as for any ticket.
|
|
33
|
+
* Default off.
|
|
34
|
+
*/
|
|
35
|
+
preload?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Selection by screen-space error. A cell is replaced by its children while its error, seen from a ticket, covers
|
|
39
|
+
* more than `maxErrorPx` pixels. The error of a cell is `errorPerEdge` × its edge, so the split distance is
|
|
40
|
+
* `errorPerEdge × pixelsPerRadian / maxErrorPx` edges (it replaces `splitLevel`; `prefetch` and `hysteresis` keep
|
|
41
|
+
* their share of it). A cell that reports a smaller measured error (`CellContent.error`) is split later or never.
|
|
42
|
+
*/
|
|
43
|
+
export interface ScreenErrorConfig {
|
|
44
|
+
/** Largest error left on the screen, in pixels. */
|
|
45
|
+
maxErrorPx: number;
|
|
46
|
+
/** Error of a cell as a share of its edge (for a regular grid about an eighth of the vertex spacing ÷ edge). */
|
|
47
|
+
errorPerEdge: number;
|
|
48
|
+
/** A measured error never counts as less than this share of the edge (content finer than the geometry). Default 0. */
|
|
49
|
+
minErrorPerEdge?: number;
|
|
50
|
+
/** Pixels per radian for tickets that do not state it. */
|
|
51
|
+
pixelsPerRadian: number;
|
|
52
|
+
/**
|
|
53
|
+
* Budget of cells: the most cells wanted on the GPU at once. When the plan is larger, the detail is lowered as a
|
|
54
|
+
* whole (the split distance shrinks in steps of 2^¼) until it fits; it comes back when there is room again.
|
|
55
|
+
*/
|
|
56
|
+
maxCells?: number;
|
|
57
|
+
}
|
|
58
|
+
/** Pixels that one radian covers at the middle of a perspective view: `viewportHeightPx / (2 · tan(fovY / 2))`. */
|
|
59
|
+
export declare function pixelsPerRadian(viewportHeightPx: number, fovYRad: number): number;
|
|
60
|
+
export interface StreamingConfig {
|
|
61
|
+
shape: WorldShape;
|
|
62
|
+
/** Only cells of this face are streamed. Without it every face the shape reports near a ticket is. */
|
|
63
|
+
face?: number;
|
|
64
|
+
/** Coarsest and finest quadtree level that is streamed. */
|
|
65
|
+
rootLevel: number;
|
|
66
|
+
leafLevel: number;
|
|
67
|
+
/** Roots are wanted while their ticket level is at most this. */
|
|
68
|
+
rootRange: number;
|
|
69
|
+
/** A cell is replaced by its children while its ticket level is at most this. */
|
|
70
|
+
splitLevel: number;
|
|
71
|
+
/** Children of cells within `splitLevel + prefetch` are fetched to the CPU ahead of need (0 = no prefetch). */
|
|
72
|
+
prefetch: number;
|
|
73
|
+
/** A cell keeps its GPU data while its parent is within `splitLevel + hysteresis`. */
|
|
74
|
+
hysteresis: number;
|
|
75
|
+
/** Most requests in flight at once (generation and loading together). */
|
|
76
|
+
maxInFlight: number;
|
|
77
|
+
/** CPU and GPU bytes the streamed cells may hold together. */
|
|
78
|
+
memoryBudgetBytes: number;
|
|
79
|
+
/** Selection by screen-space error with a budget of cells. Default off: levels follow `splitLevel`. */
|
|
80
|
+
screenError?: ScreenErrorConfig;
|
|
81
|
+
/**
|
|
82
|
+
* Ceiling of GPU bytes, default off. The streamed cells may hold this many bytes on the GPU minus `gpuReserveBytes`
|
|
83
|
+
* (what everything else holds). Over the ceiling, cells leave the GPU: first those kept only by hysteresis, the
|
|
84
|
+
* ones wanted longest ago first, then wanted cells from the least urgent (the finest and farthest), so the coarse
|
|
85
|
+
* cover stays. Cells kept only by hysteresis also leave when the waiting uploads would not fit beside them. An
|
|
86
|
+
* upload that still does not fit waits, and its parent stays drawn in its place.
|
|
87
|
+
*/
|
|
88
|
+
gpuBudgetBytes?: number;
|
|
89
|
+
}
|
|
90
|
+
export declare const DEFAULT_STREAMING: Omit<StreamingConfig, 'shape' | 'face'>;
|
|
91
|
+
export interface CellRequest {
|
|
92
|
+
cell: CellId;
|
|
93
|
+
key: string;
|
|
94
|
+
epoch: number;
|
|
95
|
+
}
|
|
96
|
+
/** What the execution part should do after a step. Every list is in a deterministic order. */
|
|
97
|
+
export interface StreamingActions {
|
|
98
|
+
/** Start these jobs (generation or loading). */
|
|
99
|
+
requests: CellRequest[];
|
|
100
|
+
/** Abort these jobs; their results will be dropped anyway. */
|
|
101
|
+
cancels: CellRequest[];
|
|
102
|
+
/** Cells that are MESHED and wanted on the GPU, most urgent first. Upload within the budget and call `resident`. */
|
|
103
|
+
uploads: CellId[];
|
|
104
|
+
/** Release the GPU data of these cells (they fall back to MESHED). */
|
|
105
|
+
releases: CellId[];
|
|
106
|
+
/** Forget these cells completely (GPU and CPU data). */
|
|
107
|
+
evictions: CellId[];
|
|
108
|
+
}
|
|
109
|
+
export interface StreamingCounters {
|
|
110
|
+
step: number;
|
|
111
|
+
/** Cells per state (tracked cells only). */
|
|
112
|
+
states: Record<CellState, number>;
|
|
113
|
+
inFlight: number;
|
|
114
|
+
/** Wanted cells still waiting for a free slot. */
|
|
115
|
+
queued: number;
|
|
116
|
+
wanted: number;
|
|
117
|
+
drawn: number;
|
|
118
|
+
/** Wanted roots with nothing to draw (only right after a jump or at start). */
|
|
119
|
+
holes: number;
|
|
120
|
+
cpuBytes: number;
|
|
121
|
+
gpuBytes: number;
|
|
122
|
+
requested: number;
|
|
123
|
+
completed: number;
|
|
124
|
+
cancelled: number;
|
|
125
|
+
stale: number;
|
|
126
|
+
failed: number;
|
|
127
|
+
evicted: number;
|
|
128
|
+
settled: boolean;
|
|
129
|
+
/** Share of the full split distance in use: 1, or less while the budget of cells holds the detail down. */
|
|
130
|
+
detail: number;
|
|
131
|
+
}
|
|
132
|
+
export declare class StreamingManager {
|
|
133
|
+
readonly config: StreamingConfig;
|
|
134
|
+
private readonly cells;
|
|
135
|
+
private tickets;
|
|
136
|
+
private plan;
|
|
137
|
+
private drawnList;
|
|
138
|
+
private holes;
|
|
139
|
+
private stepNo;
|
|
140
|
+
/** Source of epochs. World-wide and never reused, so a result from before a cell was forgotten can never match. */
|
|
141
|
+
private epochSeq;
|
|
142
|
+
private totals;
|
|
143
|
+
/** Steps the budget of cells has lowered the detail by (selection by screen-space error only). */
|
|
144
|
+
private detailStep;
|
|
145
|
+
/** A cell changed state since the last plan and the plan depends on states (selection by screen-space error). */
|
|
146
|
+
private planStale;
|
|
147
|
+
/** Every request issued, as `step:key`, for determinism checks. Cleared by `clearLog`. */
|
|
148
|
+
readonly log: string[];
|
|
149
|
+
/** Cancels and evictions `refresh` decided between steps; handed out with the next `update`. */
|
|
150
|
+
private pendingCancels;
|
|
151
|
+
private pendingEvictions;
|
|
152
|
+
private refreshTotal;
|
|
153
|
+
constructor(config: StreamingConfig);
|
|
154
|
+
/** Ticket level of a cell: the minimum over tickets of base + distance / edge. */
|
|
155
|
+
ticketLevel(cell: CellId, tickets?: readonly Ticket[]): number;
|
|
156
|
+
/**
|
|
157
|
+
* The ticket the image is drawn for: the one with the lowest base (the first by id among equals), or null without
|
|
158
|
+
* tickets. A ticket that only preloads counts only when there is no other. The blend between levels is measured
|
|
159
|
+
* from it.
|
|
160
|
+
*/
|
|
161
|
+
viewer(): Ticket | null;
|
|
162
|
+
/**
|
|
163
|
+
* Split distance of a ticket in cell edges: a cell is replaced by its children while its ticket level is at most
|
|
164
|
+
* this. `splitLevel`, or with selection by screen-space error the distance at which the error covers the tolerance.
|
|
165
|
+
*/
|
|
166
|
+
splitDistance(t: Ticket): number;
|
|
167
|
+
/**
|
|
168
|
+
* Distances from the viewer between which a cell of `level` blends from its own shape (at `startM` and nearer) into
|
|
169
|
+
* its parent's (at `endM` and farther), in the metric of the ticket level: distance along the surface combined with
|
|
170
|
+
* the viewer's altitude. `endM` is where the parent stops being split, so a cell that has just replaced its parent
|
|
171
|
+
* shows the parent's shape. Null when there is nothing to blend into (the coarsest level, no viewer).
|
|
172
|
+
*
|
|
173
|
+
* The blend is free of jumps when the split distance is at least 2.02 edges: a cell must be back in its own shape
|
|
174
|
+
* over its whole footprint (√2 edges across) before it is split, and the blend still needs 15 % of the way to run.
|
|
175
|
+
* Below that the blend is squeezed into the last 15 % and small steps remain, which the skirt of the cell covers.
|
|
176
|
+
*
|
|
177
|
+
* The ranges assume a parent that is split at the full split distance. A parent whose measured error is smaller is
|
|
178
|
+
* split nearer (selection by screen-space error), where its children are already in their own shape: they replace
|
|
179
|
+
* it with a step of up to the tolerance on the screen. Content that must not show that step reports the full error.
|
|
180
|
+
*/
|
|
181
|
+
morphRange(level: number): {
|
|
182
|
+
startM: number;
|
|
183
|
+
endM: number;
|
|
184
|
+
} | null;
|
|
185
|
+
/** Decides what is wanted for the given tickets, then returns the work to do. One call per frame (or step). */
|
|
186
|
+
update(tickets: readonly Ticket[]): StreamingActions;
|
|
187
|
+
/**
|
|
188
|
+
* A job finished. Returns false when the result is stale (old epoch) or nobody waits for it any more. `errorM` is
|
|
189
|
+
* the content's measured error (`CellContent.error`), used by selection by screen-space error.
|
|
190
|
+
*/
|
|
191
|
+
complete(req: CellRequest, cpuBytes: number, errorM?: number): boolean;
|
|
192
|
+
/** A job failed or was aborted. A cell that keeps failing is retried no sooner than its next request round. */
|
|
193
|
+
fail(req: CellRequest): void;
|
|
194
|
+
/** The execution part uploaded a MESHED cell. */
|
|
195
|
+
resident(cell: CellId, gpuBytes: number): void;
|
|
196
|
+
/**
|
|
197
|
+
* The execution part swapped the GPU data of a RESIDENT cell for the new content `complete` accepted after a
|
|
198
|
+
* `refresh`. The cell stays RESIDENT and drawn throughout.
|
|
199
|
+
*/
|
|
200
|
+
swapped(cell: CellId, gpuBytes: number): void;
|
|
201
|
+
/**
|
|
202
|
+
* The content of these cells is out of date. Returns how many tracked cells it touched:
|
|
203
|
+
* - a job in flight is cancelled (its late result is stale) and the cell is requested again by the usual rules;
|
|
204
|
+
* - a MESHED cell is forgotten (state NONE, listed in the next step's `evictions`) and built again when wanted;
|
|
205
|
+
* - a RESIDENT cell stays drawn with its old content; the next step requests it ahead of every other candidate
|
|
206
|
+
* (within `maxInFlight`), and when its new content arrives `complete` leaves it RESIDENT for the swap. A second
|
|
207
|
+
* call during a refresh restarts the job.
|
|
208
|
+
* Cells that are not tracked, or NONE with no job, are left alone.
|
|
209
|
+
*/
|
|
210
|
+
refresh(cells: Iterable<CellId>): number;
|
|
211
|
+
/** Cells drawn with out-of-date content that wait for their new content, and all cells `refresh` has touched. */
|
|
212
|
+
refreshes(): {
|
|
213
|
+
pending: number;
|
|
214
|
+
total: number;
|
|
215
|
+
};
|
|
216
|
+
/** State of a cell (NONE when it is not tracked). */
|
|
217
|
+
state(cell: CellId): CellState;
|
|
218
|
+
/** Cells to draw this frame: the cover of the wanted quadtree, parents standing in for children not yet resident. */
|
|
219
|
+
drawn(): readonly CellId[];
|
|
220
|
+
/** True when every wanted cell is RESIDENT: the image is complete and depends only on the tickets. */
|
|
221
|
+
get settled(): boolean;
|
|
222
|
+
/**
|
|
223
|
+
* True when a cell was loaded since the last `update` and the next one may therefore want more (selection by
|
|
224
|
+
* screen-space error descends only below loaded cells). The caller should run another step.
|
|
225
|
+
*/
|
|
226
|
+
get stale(): boolean;
|
|
227
|
+
/** Wanted cells (target RESIDENT), in a deterministic order. */
|
|
228
|
+
wanted(): CellId[];
|
|
229
|
+
counters(): StreamingCounters;
|
|
230
|
+
clearLog(): void;
|
|
231
|
+
private sortedRecords;
|
|
232
|
+
/** The wanted quadtree: roots near the tickets, split while the ticket level allows it. */
|
|
233
|
+
private planCells;
|
|
234
|
+
/** The coarsest wanted cells: those the shape reports near a ticket whose ticket level is within `rootRange`. */
|
|
235
|
+
private planRoots;
|
|
236
|
+
/** Share of the full split distance after the budget lowered the detail by `step` steps. */
|
|
237
|
+
private detailScale;
|
|
238
|
+
/**
|
|
239
|
+
* Ticket level of a cell divided by the ticket's split distance, the minimum over tickets: at most 1 where the cell
|
|
240
|
+
* is close enough to be split. `scale` is the share of the full split distance in use. `preload` picks the tickets:
|
|
241
|
+
* all of them (undefined), only those that load without changing the image (true) or only the others (false).
|
|
242
|
+
*/
|
|
243
|
+
private relativeLevel;
|
|
244
|
+
/**
|
|
245
|
+
* Share of the split distance at which a loaded cell is really split: 1 without a measured error, less when the
|
|
246
|
+
* measured error is smaller than the assumed one (a flat cell is split later, a cell without error never).
|
|
247
|
+
*/
|
|
248
|
+
private errorShare;
|
|
249
|
+
/** The level a record is ordered by when the plan does not list it. */
|
|
250
|
+
private planLevel;
|
|
251
|
+
/**
|
|
252
|
+
* The wanted quadtree by screen-space error, within the budget of cells. Lowers the detail step by step while the
|
|
253
|
+
* plan is over the budget and raises it again once the next finer plan fits with room to spare.
|
|
254
|
+
*/
|
|
255
|
+
private planByScreenError;
|
|
256
|
+
private planAtDetail;
|
|
257
|
+
/** Is the cell still close enough to keep its GPU data (hysteresis)? */
|
|
258
|
+
private withinKeepBand;
|
|
259
|
+
/** Lexicographic priority, smaller first (see the design's job order). */
|
|
260
|
+
private priority;
|
|
261
|
+
/**
|
|
262
|
+
* 0 = straight ahead of a ticket's direction … 3 = behind it. Cells without a directed ticket get 1. Both the
|
|
263
|
+
* direction and the way to the cell's middle are taken across "up" at the ticket, so height plays no part.
|
|
264
|
+
*/
|
|
265
|
+
private facingBucket;
|
|
266
|
+
private enforceBudget;
|
|
267
|
+
/**
|
|
268
|
+
* GPU bytes held by everything that is not a streamed cell (textures, other meshes, targets). The execution part
|
|
269
|
+
* sets it from what the device reports; it only matters with `gpuBudgetBytes`.
|
|
270
|
+
*/
|
|
271
|
+
gpuReserveBytes: number;
|
|
272
|
+
private gpuTotals;
|
|
273
|
+
/** With `gpuBudgetBytes`: cells taken off the GPU to get under the ceiling, and uploads that had to wait (per step). */
|
|
274
|
+
gpuPressure(): {
|
|
275
|
+
released: number;
|
|
276
|
+
deferred: number;
|
|
277
|
+
};
|
|
278
|
+
/**
|
|
279
|
+
* The execution part lost every GPU object (a lost graphics context): cells on the GPU are MESHED again, so the
|
|
280
|
+
* next step lists them as uploads and they are made again from their CPU data.
|
|
281
|
+
*/
|
|
282
|
+
dropResident(): void;
|
|
283
|
+
/** A cell with out-of-date content leaves the GPU: its job is cancelled and it is forgotten (state NONE). */
|
|
284
|
+
private forgetRefreshing;
|
|
285
|
+
private enforceGpuCeiling;
|
|
286
|
+
/** Drawing cover of the wanted quadtree. */
|
|
287
|
+
private computeCover;
|
|
288
|
+
}
|