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,359 @@
|
|
|
1
|
+
// Perspective camera rig that moves freely: a position in world metres (double precision), a heading along the local
|
|
2
|
+
// horizon and a pitch. The up direction is asked from an up source (a `WorldShape`) at the rig's position, so nothing
|
|
3
|
+
// here assumes which axis is up and the same rig serves a flat and a curved world. An optional callback tells the
|
|
4
|
+
// height above the surface; the rig uses it to keep a minimum clearance, to scale its speed and to place the near
|
|
5
|
+
// plane. The renderer sees the rig relative to `origin`, so only a difference of doubles ever becomes a float.
|
|
6
|
+
// Keys and pointer are bound by `bindFreeInput` in platform. Implements `View` for the renderer.
|
|
7
|
+
import { DEG, clamp, cross, dot, normalize } from '../base/math.js';
|
|
8
|
+
export const DEFAULT_FREE = {
|
|
9
|
+
fovYDeg: 50,
|
|
10
|
+
maxPitchDeg: 89,
|
|
11
|
+
turnPerPx: 0.004,
|
|
12
|
+
minClearance: 2,
|
|
13
|
+
followSurface: false,
|
|
14
|
+
speedPerHeight: 1,
|
|
15
|
+
minSpeed: 5,
|
|
16
|
+
maxSpeed: 5000,
|
|
17
|
+
boost: 6,
|
|
18
|
+
inertiaS: 0.12,
|
|
19
|
+
levelMove: false,
|
|
20
|
+
depthRatio: 2000,
|
|
21
|
+
nearPerHeight: 0.25,
|
|
22
|
+
minNear: 0.1,
|
|
23
|
+
};
|
|
24
|
+
const UP_Y = { upAt: () => [0, 1, 0] };
|
|
25
|
+
/**
|
|
26
|
+
* Reference directions in the horizon of `up`: the world −z axis laid into the horizon (heading 0) and the direction a
|
|
27
|
+
* quarter turn to its left (heading 90°). Where up runs along z, the +x axis takes the place of −z.
|
|
28
|
+
*/
|
|
29
|
+
function horizonRef(up) {
|
|
30
|
+
// (−z) − up·((−z)·up)
|
|
31
|
+
let n = [up[0] * up[2], up[1] * up[2], up[2] * up[2] - 1];
|
|
32
|
+
if (n[0] * n[0] + n[1] * n[1] + n[2] * n[2] < 1e-12)
|
|
33
|
+
n = [1 - up[0] * up[0], -up[1] * up[0], -up[2] * up[0]];
|
|
34
|
+
const ahead = normalize(n);
|
|
35
|
+
return [ahead, cross(up, ahead)];
|
|
36
|
+
}
|
|
37
|
+
export class FreeRig {
|
|
38
|
+
setup;
|
|
39
|
+
/** World position of the eye in metres. After writing it directly call `keepClear()`. */
|
|
40
|
+
position = [0, 0, 0];
|
|
41
|
+
/**
|
|
42
|
+
* World position the renderer's space starts at. Every position the `View` contract hands out (`eye`, rays, the
|
|
43
|
+
* cull volume, the matrix) is relative to it. Keep it near the eye and equal to the origin the layers are drawn with.
|
|
44
|
+
*/
|
|
45
|
+
origin = [0, 0, 0];
|
|
46
|
+
/** Pitch in radians; positive looks below the horizon. */
|
|
47
|
+
pitch = 0;
|
|
48
|
+
/** Multiplier of the cruise speed the user controls (see `scaleSpeed`). */
|
|
49
|
+
speedScale = 1;
|
|
50
|
+
/** World velocity in metres per second after the last `move`. */
|
|
51
|
+
velocity = [0, 0, 0];
|
|
52
|
+
/** Height above the surface at the last `keepClear`, NaN without a height callback. */
|
|
53
|
+
clearance = NaN;
|
|
54
|
+
/** Distance in front of the eye that counts as the centre of the view (`metresPerPixel`, `refDepth`). */
|
|
55
|
+
focusDistance = 50;
|
|
56
|
+
/** Height above the surface, or null. May be replaced at any time. */
|
|
57
|
+
heightAbove;
|
|
58
|
+
/** Canvas size in physical pixels and physical pixels per CSS pixel. */
|
|
59
|
+
width = 1;
|
|
60
|
+
height = 1;
|
|
61
|
+
dpr = 1;
|
|
62
|
+
shape;
|
|
63
|
+
/** Unit heading in the local horizon. */
|
|
64
|
+
tangent = [0, 0, -1];
|
|
65
|
+
constructor(setup = {}, options = {}, state) {
|
|
66
|
+
this.setup = { ...DEFAULT_FREE, ...setup };
|
|
67
|
+
this.shape = options.shape ?? UP_Y;
|
|
68
|
+
this.heightAbove = options.heightAbove ?? null;
|
|
69
|
+
this.setState(state ?? {});
|
|
70
|
+
}
|
|
71
|
+
/** Jumps to a state: the velocity is dropped on a new position and the clearance is applied. */
|
|
72
|
+
setState(s) {
|
|
73
|
+
if (s.position) {
|
|
74
|
+
this.position = [s.position[0], s.position[1], s.position[2]];
|
|
75
|
+
this.velocity = [0, 0, 0];
|
|
76
|
+
}
|
|
77
|
+
// After the position: the reference of the heading depends on where up is there.
|
|
78
|
+
if (s.yawDeg !== undefined)
|
|
79
|
+
this.yaw = s.yawDeg * DEG;
|
|
80
|
+
if (s.pitchDeg !== undefined)
|
|
81
|
+
this.pitch = this.clampPitch(s.pitchDeg * DEG);
|
|
82
|
+
this.keepClear();
|
|
83
|
+
}
|
|
84
|
+
state() {
|
|
85
|
+
const p = this.position;
|
|
86
|
+
return { position: [p[0], p[1], p[2]], yawDeg: this.yaw / DEG, pitchDeg: this.pitch / DEG };
|
|
87
|
+
}
|
|
88
|
+
clampPitch(p) {
|
|
89
|
+
const m = Math.min(90, this.setup.maxPitchDeg) * DEG;
|
|
90
|
+
return clamp(p, -m, m);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Unit up at the position. The position may have moved to a place with another up since the heading was stored, so
|
|
94
|
+
* this also lays the heading back into the horizon (the same heading, carried along).
|
|
95
|
+
*/
|
|
96
|
+
up() {
|
|
97
|
+
const up = this.shape.upAt(this.position);
|
|
98
|
+
const t = this.tangent;
|
|
99
|
+
const d = dot(t, up);
|
|
100
|
+
// On a flat world the heading never leaves the horizon and stays bit for bit as it was.
|
|
101
|
+
if (Math.abs(d) > 1e-12) {
|
|
102
|
+
const h = [t[0] - up[0] * d, t[1] - up[1] * d, t[2] - up[2] * d];
|
|
103
|
+
// A heading that ran along the new up has no direction left: take the reference one.
|
|
104
|
+
this.tangent = h[0] * h[0] + h[1] * h[1] + h[2] * h[2] < 1e-12 ? horizonRef(up)[0] : normalize(h);
|
|
105
|
+
}
|
|
106
|
+
return up;
|
|
107
|
+
}
|
|
108
|
+
/** Unit direction of the heading in the local horizon (the view direction without its pitch). */
|
|
109
|
+
headingDir() {
|
|
110
|
+
this.up();
|
|
111
|
+
const t = this.tangent;
|
|
112
|
+
return [t[0], t[1], t[2]];
|
|
113
|
+
}
|
|
114
|
+
/** Heading in radians, measured in the local horizon from the world −z axis; positive turns left. */
|
|
115
|
+
get yaw() {
|
|
116
|
+
const [ahead, left] = horizonRef(this.up());
|
|
117
|
+
return Math.atan2(dot(this.tangent, left), dot(this.tangent, ahead));
|
|
118
|
+
}
|
|
119
|
+
set yaw(a) {
|
|
120
|
+
const [ahead, left] = horizonRef(this.shape.upAt(this.position));
|
|
121
|
+
const c = Math.cos(a);
|
|
122
|
+
const s = Math.sin(a);
|
|
123
|
+
this.tangent = [ahead[0] * c + left[0] * s, ahead[1] * c + left[1] * s, ahead[2] * c + left[2] * s];
|
|
124
|
+
}
|
|
125
|
+
/** View: rotation around the local up in radians. */
|
|
126
|
+
get heading() {
|
|
127
|
+
return this.yaw;
|
|
128
|
+
}
|
|
129
|
+
get tanHalfY() {
|
|
130
|
+
return Math.tan((this.setup.fovYDeg * DEG) / 2);
|
|
131
|
+
}
|
|
132
|
+
/** View: pixel size at `focusDistance` in front of the eye. */
|
|
133
|
+
get metresPerPixel() {
|
|
134
|
+
return this.focusDistance * this.pixelGrowth;
|
|
135
|
+
}
|
|
136
|
+
/** View: metres per pixel gained per metre of depth. */
|
|
137
|
+
get pixelGrowth() {
|
|
138
|
+
return (2 * this.tanHalfY) / this.height;
|
|
139
|
+
}
|
|
140
|
+
/** View: depth of the point `focusDistance` in front of the eye, in the renderer's space. */
|
|
141
|
+
get refDepth() {
|
|
142
|
+
return dot(this.axes().forward, this.eye()) + this.focusDistance;
|
|
143
|
+
}
|
|
144
|
+
/** Screen right, screen up and the view direction, built from the local up, the heading and the pitch. */
|
|
145
|
+
axes() {
|
|
146
|
+
const up = this.up();
|
|
147
|
+
const t = this.tangent;
|
|
148
|
+
const c = Math.cos(this.pitch);
|
|
149
|
+
const s = Math.sin(this.pitch);
|
|
150
|
+
const right = cross(t, up);
|
|
151
|
+
const forward = [t[0] * c - up[0] * s, t[1] * c - up[1] * s, t[2] * c - up[2] * s];
|
|
152
|
+
return { right, forward, up: cross(right, forward) };
|
|
153
|
+
}
|
|
154
|
+
/** The eye in the renderer's space: the world position minus `origin`, subtracted in double precision. With `out` it is written there. */
|
|
155
|
+
eye(out) {
|
|
156
|
+
const p = this.position;
|
|
157
|
+
const o = this.origin;
|
|
158
|
+
if (!out)
|
|
159
|
+
return [p[0] - o[0], p[1] - o[1], p[2] - o[2]];
|
|
160
|
+
out[0] = p[0] - o[0];
|
|
161
|
+
out[1] = p[1] - o[1];
|
|
162
|
+
out[2] = p[2] - o[2];
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* World → clip matrix (the world here is the renderer's space). The far plane encloses the sphere of
|
|
167
|
+
* `depthHalfRange` around `sceneCenter`. The near plane sits at far / `depthRatio`, but no farther than
|
|
168
|
+
* `nearPerHeight` of the height above the surface, so that the surface under a low eye is not cut away.
|
|
169
|
+
*/
|
|
170
|
+
viewProj(sceneCenter, depthHalfRange) {
|
|
171
|
+
const { right: r, up: u, forward: w } = this.axes();
|
|
172
|
+
const eye = this.eye();
|
|
173
|
+
const s = this.setup;
|
|
174
|
+
const dc = dot(w, sceneCenter) - dot(w, eye);
|
|
175
|
+
const far = Math.max(dc + depthHalfRange, 1);
|
|
176
|
+
let ahead = far / s.depthRatio;
|
|
177
|
+
if (Number.isFinite(this.clearance))
|
|
178
|
+
ahead = Math.min(ahead, this.clearance * s.nearPerHeight);
|
|
179
|
+
// A scene that starts farther away than that moves the near plane out to its own start, as nothing is in front of it.
|
|
180
|
+
const near = Math.max(dc - depthHalfRange, Math.min(Math.max(ahead, s.minNear), far / 2));
|
|
181
|
+
const fy = 1 / this.tanHalfY;
|
|
182
|
+
const fx = fy / (this.width / this.height);
|
|
183
|
+
const a = (far + near) / (far - near);
|
|
184
|
+
const b = (-2 * far * near) / (far - near);
|
|
185
|
+
const m = new Float32Array(16);
|
|
186
|
+
const re = dot(r, eye);
|
|
187
|
+
const ue = dot(u, eye);
|
|
188
|
+
const we = dot(w, eye);
|
|
189
|
+
for (let i = 0; i < 3; i++) {
|
|
190
|
+
m[i * 4 + 0] = fx * r[i];
|
|
191
|
+
m[i * 4 + 1] = fy * u[i];
|
|
192
|
+
m[i * 4 + 2] = a * w[i];
|
|
193
|
+
m[i * 4 + 3] = w[i];
|
|
194
|
+
}
|
|
195
|
+
m[12] = -fx * re;
|
|
196
|
+
m[13] = -fy * ue;
|
|
197
|
+
m[14] = -a * we + b;
|
|
198
|
+
m[15] = -we;
|
|
199
|
+
return m;
|
|
200
|
+
}
|
|
201
|
+
/** Direction through a point given in normalised screen coordinates (−1…1, y up). */
|
|
202
|
+
dirAt(sx, sy) {
|
|
203
|
+
const { right, up, forward } = this.axes();
|
|
204
|
+
const ty = this.tanHalfY;
|
|
205
|
+
const tx = ty * (this.width / this.height);
|
|
206
|
+
return normalize([
|
|
207
|
+
forward[0] + right[0] * sx * tx + up[0] * sy * ty,
|
|
208
|
+
forward[1] + right[1] * sx * tx + up[1] * sy * ty,
|
|
209
|
+
forward[2] + right[2] * sx * tx + up[2] * sy * ty,
|
|
210
|
+
]);
|
|
211
|
+
}
|
|
212
|
+
/** View: rays from the eye through the image corners (left-bottom, left-top, right-bottom, right-top). */
|
|
213
|
+
cornerRays() {
|
|
214
|
+
const eye = this.eye();
|
|
215
|
+
const rays = [];
|
|
216
|
+
for (const sx of [-1, 1])
|
|
217
|
+
for (const sy of [-1, 1])
|
|
218
|
+
rays.push({ origin: eye, dir: this.dirAt(sx, sy) });
|
|
219
|
+
return rays;
|
|
220
|
+
}
|
|
221
|
+
/** View: the four side planes through the eye and the plane of the eye itself, normals inward. */
|
|
222
|
+
cullVolume() {
|
|
223
|
+
const eye = this.eye();
|
|
224
|
+
const { forward } = this.axes();
|
|
225
|
+
const d = [this.dirAt(-1, -1), this.dirAt(-1, 1), this.dirAt(1, 1), this.dirAt(1, -1)];
|
|
226
|
+
const planes = [[forward[0], forward[1], forward[2], -dot(forward, eye)]];
|
|
227
|
+
for (let i = 0; i < 4; i++) {
|
|
228
|
+
let n = normalize(cross(d[i], d[(i + 1) % 4]));
|
|
229
|
+
if (dot(n, forward) < 0)
|
|
230
|
+
n = [-n[0], -n[1], -n[2]];
|
|
231
|
+
planes.push([n[0], n[1], n[2], -dot(n, eye)]);
|
|
232
|
+
}
|
|
233
|
+
return { kind: 'frustum', planes };
|
|
234
|
+
}
|
|
235
|
+
/** View: changes whenever the image of a static scene would. */
|
|
236
|
+
key() {
|
|
237
|
+
this.up();
|
|
238
|
+
const p = this.position;
|
|
239
|
+
const o = this.origin;
|
|
240
|
+
const t = this.tangent;
|
|
241
|
+
return `free|${p[0].toFixed(3)},${p[1].toFixed(3)},${p[2].toFixed(3)}|${o[0]},${o[1]},${o[2]}|${t[0].toFixed(5)},${t[1].toFixed(5)},${t[2].toFixed(5)}|${this.pitch.toFixed(5)}|${this.clearance.toFixed(2)}|${this.width}x${this.height}`;
|
|
242
|
+
}
|
|
243
|
+
/** Ray under a screen point in physical pixels from the top-left corner, in the renderer's space. */
|
|
244
|
+
screenRay(px, py) {
|
|
245
|
+
return { origin: this.eye(), dir: this.dirAt((2 * px) / this.width - 1, 1 - (2 * py) / this.height) };
|
|
246
|
+
}
|
|
247
|
+
/** Where a point of the renderer's space lands on the canvas, in physical pixels from the top-left corner. */
|
|
248
|
+
project(p) {
|
|
249
|
+
const { right, up, forward } = this.axes();
|
|
250
|
+
const e = this.eye();
|
|
251
|
+
const v = [p[0] - e[0], p[1] - e[1], p[2] - e[2]];
|
|
252
|
+
const z = dot(forward, v);
|
|
253
|
+
const ty = this.tanHalfY;
|
|
254
|
+
const tx = ty * (this.width / this.height);
|
|
255
|
+
return [((dot(right, v) / (z * tx) + 1) * this.width) / 2, ((1 - dot(up, v) / (z * ty)) * this.height) / 2];
|
|
256
|
+
}
|
|
257
|
+
/** Turns by angles in radians: the heading around the local up (positive turns left), the pitch (positive looks down). */
|
|
258
|
+
turn(yawDelta, pitchDelta) {
|
|
259
|
+
const up = this.up();
|
|
260
|
+
const t = this.tangent;
|
|
261
|
+
const left = cross(up, t);
|
|
262
|
+
const c = Math.cos(yawDelta);
|
|
263
|
+
const s = Math.sin(yawDelta);
|
|
264
|
+
this.tangent = normalize([t[0] * c + left[0] * s, t[1] * c + left[1] * s, t[2] * c + left[2] * s]);
|
|
265
|
+
this.pitch = this.clampPitch(this.pitch + pitchDelta);
|
|
266
|
+
}
|
|
267
|
+
/** Turns by pointer movement in physical pixels: right turns the view right, down turns it down. */
|
|
268
|
+
turnPixels(dx, dy) {
|
|
269
|
+
const k = this.setup.turnPerPx / this.dpr;
|
|
270
|
+
this.turn(-dx * k, dy * k);
|
|
271
|
+
}
|
|
272
|
+
/** Turns the view toward a world position. */
|
|
273
|
+
lookAt(target) {
|
|
274
|
+
const up = this.up();
|
|
275
|
+
const p = this.position;
|
|
276
|
+
const d = normalize([target[0] - p[0], target[1] - p[1], target[2] - p[2]]);
|
|
277
|
+
const rise = dot(d, up);
|
|
278
|
+
const h = [d[0] - up[0] * rise, d[1] - up[1] * rise, d[2] - up[2] * rise];
|
|
279
|
+
// Straight up or down keeps the heading.
|
|
280
|
+
if (h[0] * h[0] + h[1] * h[1] + h[2] * h[2] > 1e-12)
|
|
281
|
+
this.tangent = normalize(h);
|
|
282
|
+
this.pitch = this.clampPitch(-Math.asin(clamp(rise, -1, 1)));
|
|
283
|
+
}
|
|
284
|
+
/** Cruise speed in metres per second at the current height, before the boost. */
|
|
285
|
+
get speed() {
|
|
286
|
+
const s = this.setup;
|
|
287
|
+
const h = this.clearance;
|
|
288
|
+
return (Number.isFinite(h) ? clamp(h * s.speedPerHeight, s.minSpeed, s.maxSpeed) : s.minSpeed) * this.speedScale;
|
|
289
|
+
}
|
|
290
|
+
/** Multiplies the user's speed multiplier, kept within 1/64 … 64. */
|
|
291
|
+
scaleSpeed(factor) {
|
|
292
|
+
this.speedScale = clamp(this.speedScale * factor, 1 / 64, 64);
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Moves for `dt` seconds. The inputs are −1…1: `forward` along the view direction (along the horizon with
|
|
296
|
+
* `levelMove`), `right` along screen right, `up` along the local up. The velocity follows the input with the
|
|
297
|
+
* inertia of the setup. Returns whether the rig is still moving, so the caller knows to draw another frame.
|
|
298
|
+
*/
|
|
299
|
+
move(forward, right, up, dt, boost = false) {
|
|
300
|
+
const upDir = this.up();
|
|
301
|
+
const a = this.axes();
|
|
302
|
+
const along = this.setup.levelMove ? this.tangent : a.forward;
|
|
303
|
+
let dx = along[0] * forward + a.right[0] * right + upDir[0] * up;
|
|
304
|
+
let dy = along[1] * forward + a.right[1] * right + upDir[1] * up;
|
|
305
|
+
let dz = along[2] * forward + a.right[2] * right + upDir[2] * up;
|
|
306
|
+
const len = Math.hypot(dx, dy, dz);
|
|
307
|
+
if (len > 1) {
|
|
308
|
+
dx /= len;
|
|
309
|
+
dy /= len;
|
|
310
|
+
dz /= len;
|
|
311
|
+
}
|
|
312
|
+
const cruise = this.speed;
|
|
313
|
+
const speed = cruise * (boost ? this.setup.boost : 1);
|
|
314
|
+
const tau = this.setup.inertiaS;
|
|
315
|
+
const k = tau > 0 ? 1 - Math.exp(-Math.max(0, dt) / tau) : 1;
|
|
316
|
+
const v = this.velocity;
|
|
317
|
+
v[0] += (dx * speed - v[0]) * k;
|
|
318
|
+
v[1] += (dy * speed - v[1]) * k;
|
|
319
|
+
v[2] += (dz * speed - v[2]) * k;
|
|
320
|
+
// Without input the velocity only decays: below a small fraction of the cruise speed it is rest.
|
|
321
|
+
if (len === 0 && Math.hypot(v[0], v[1], v[2]) < Math.max(1e-4, cruise * 0.02))
|
|
322
|
+
v[0] = v[1] = v[2] = 0;
|
|
323
|
+
if (v[0] === 0 && v[1] === 0 && v[2] === 0)
|
|
324
|
+
return false;
|
|
325
|
+
if (dt > 0) {
|
|
326
|
+
const p = this.position;
|
|
327
|
+
this.position = [p[0] + v[0] * dt, p[1] + v[1] * dt, p[2] + v[2] * dt];
|
|
328
|
+
// Following the surface: the height asked for is the one before the step plus the step's part along up.
|
|
329
|
+
const rise = (v[0] * upDir[0] + v[1] * upDir[1] + v[2] * upDir[2]) * dt;
|
|
330
|
+
this.settle(this.setup.followSurface && Number.isFinite(this.clearance) ? this.clearance + rise : undefined);
|
|
331
|
+
}
|
|
332
|
+
return true;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Reads the height above the surface and, where it is below `minClearance`, lifts the position along the local up.
|
|
336
|
+
* `move` and `setState` call it; call it yourself after writing `position` or when the surface changed.
|
|
337
|
+
*/
|
|
338
|
+
keepClear() {
|
|
339
|
+
this.settle(undefined);
|
|
340
|
+
}
|
|
341
|
+
/** Moves the position along the local up to the height `hold` above the surface, or only up to `minClearance`. */
|
|
342
|
+
settle(hold) {
|
|
343
|
+
if (!this.heightAbove) {
|
|
344
|
+
this.clearance = NaN;
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
let h = this.heightAbove(this.position);
|
|
348
|
+
const want = Math.max(hold ?? h, this.setup.minClearance);
|
|
349
|
+
// A height that is not a number (a callback without an answer there) leaves the position alone.
|
|
350
|
+
if (want !== h && Number.isFinite(want) && Number.isFinite(h)) {
|
|
351
|
+
const up = this.up();
|
|
352
|
+
const lift = want - h;
|
|
353
|
+
const p = this.position;
|
|
354
|
+
this.position = [p[0] + up[0] * lift, p[1] + up[1] * lift, p[2] + up[2] * lift];
|
|
355
|
+
h = want;
|
|
356
|
+
}
|
|
357
|
+
this.clearance = h;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { SteppedOrthoRig } from './camera.ts';
|
|
2
|
+
export type { CameraSetup, ViewState } from './camera.ts';
|
|
3
|
+
export { DEFAULT_ORBIT, PerspectiveOrbitRig } from './orbit.ts';
|
|
4
|
+
export type { OrbitSetup, OrbitState } from './orbit.ts';
|
|
5
|
+
export { OrbitPath, blendOrbitState, writeOrbitState } from './path.ts';
|
|
6
|
+
export type { OrbitKey, OrbitPathOptions } from './path.ts';
|
|
7
|
+
export { DEFAULT_FREE, FreeRig } from './free.ts';
|
|
8
|
+
export type { FreeOptions, FreeSetup, FreeState, HeightAbove, UpSource } from './free.ts';
|
|
9
|
+
export { DEFAULT_FOLLOW, FollowRig } from './follow.ts';
|
|
10
|
+
export type { BoomClearance, FollowOptions, FollowSetup } from './follow.ts';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Layer 5, camera: views, camera rigs and keyframed orbit paths.
|
|
2
|
+
export { SteppedOrthoRig } from './camera.js';
|
|
3
|
+
export { DEFAULT_ORBIT, PerspectiveOrbitRig } from './orbit.js';
|
|
4
|
+
export { OrbitPath, blendOrbitState, writeOrbitState } from './path.js';
|
|
5
|
+
export { DEFAULT_FREE, FreeRig } from './free.js';
|
|
6
|
+
export { DEFAULT_FOLLOW, FollowRig } from './follow.js';
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { OrthoFrame, Vec3 } from '../base/math.ts';
|
|
2
|
+
import type { CullFrustum, Ray, View } from '../base/view.ts';
|
|
3
|
+
export interface OrbitSetup {
|
|
4
|
+
/** Vertical field of view in degrees. */
|
|
5
|
+
fovYDeg: number;
|
|
6
|
+
/** Limits of the pitch above the horizon and of the distance to the target. */
|
|
7
|
+
minPitchDeg: number;
|
|
8
|
+
maxPitchDeg: number;
|
|
9
|
+
minDistance: number;
|
|
10
|
+
maxDistance: number;
|
|
11
|
+
/** Radians of turn per CSS pixel of drag. */
|
|
12
|
+
turnPerPx: number;
|
|
13
|
+
/**
|
|
14
|
+
* Height of the ground under a point (x, z), for keeping the eye above it. Optional: without it nothing is kept
|
|
15
|
+
* and the rig behaves as it always did.
|
|
16
|
+
*/
|
|
17
|
+
groundAt?: ((x: number, z: number) => number) | null;
|
|
18
|
+
/** Least height of the eye over `groundAt`, metres. Default 1. Read only when `groundAt` is set. */
|
|
19
|
+
minEyeHeight?: number;
|
|
20
|
+
}
|
|
21
|
+
export declare const DEFAULT_ORBIT: OrbitSetup;
|
|
22
|
+
export interface OrbitState {
|
|
23
|
+
target: Vec3;
|
|
24
|
+
yawDeg: number;
|
|
25
|
+
pitchDeg: number;
|
|
26
|
+
distance: number;
|
|
27
|
+
}
|
|
28
|
+
export declare class PerspectiveOrbitRig implements View {
|
|
29
|
+
readonly setup: OrbitSetup;
|
|
30
|
+
target: Vec3;
|
|
31
|
+
/** Rotation around the vertical axis in radians; 0 looks toward −z. */
|
|
32
|
+
yaw: number;
|
|
33
|
+
/** Elevation of the view above the horizon in radians (positive looks down). */
|
|
34
|
+
pitch: number;
|
|
35
|
+
distance: number;
|
|
36
|
+
/** Canvas size in physical pixels and physical pixels per CSS pixel. */
|
|
37
|
+
width: number;
|
|
38
|
+
height: number;
|
|
39
|
+
dpr: number;
|
|
40
|
+
/** Scratch of the methods that take `out`, so they allocate nothing themselves. */
|
|
41
|
+
private readonly scratch;
|
|
42
|
+
private readonly scratchVp;
|
|
43
|
+
private readonly scratchEye;
|
|
44
|
+
/** The numbers the last `key` was made from (NaN: none yet) and that key. */
|
|
45
|
+
private readonly keyOf;
|
|
46
|
+
private keyText;
|
|
47
|
+
constructor(setup?: Partial<OrbitSetup>, state?: Partial<OrbitState>);
|
|
48
|
+
setState(s: Partial<OrbitState>): void;
|
|
49
|
+
/**
|
|
50
|
+
* With `setup.groundAt`: raises the pitch (never above `maxPitchDeg`) until the eye stands at least `minEyeHeight`
|
|
51
|
+
* over the ground, the least raise that does it (to a hundredth of a degree). `setState`, `orbitPixels` and `zoomBy`
|
|
52
|
+
* call it; call it yourself when the ground under the eye changed. Returns whether the pitch changed. Allocates
|
|
53
|
+
* nothing; without `groundAt` it does nothing.
|
|
54
|
+
*/
|
|
55
|
+
keepAboveGround(): boolean;
|
|
56
|
+
/** Height of the eye over the ground minus `min` for the pitch `p`, the rest of the state as it is. */
|
|
57
|
+
private eyeClear;
|
|
58
|
+
state(): OrbitState;
|
|
59
|
+
get heading(): number;
|
|
60
|
+
private get tanHalfY();
|
|
61
|
+
/** View: pixel size at the target. */
|
|
62
|
+
get metresPerPixel(): number;
|
|
63
|
+
/** View: metres per pixel gained per metre of depth. */
|
|
64
|
+
get pixelGrowth(): number;
|
|
65
|
+
/** View: depth of the target along the view direction. */
|
|
66
|
+
get refDepth(): number;
|
|
67
|
+
/** View: screen right, screen up and the view direction. With `out` its arrays are written and `out` is returned. */
|
|
68
|
+
axes(out?: OrthoFrame): OrthoFrame;
|
|
69
|
+
/** The eye: the target moved back along the view direction by the distance. With `out` it is written there. */
|
|
70
|
+
eye(out?: Vec3): Vec3;
|
|
71
|
+
/** World → clip matrix. Near and far planes enclose the sphere of `depthHalfRange` around `sceneCenter`. */
|
|
72
|
+
viewProj(sceneCenter: Vec3, depthHalfRange: number, out?: Float32Array): Float32Array;
|
|
73
|
+
/** `dirAt` for the axes `ax`, written into `out` (the same numbers, nothing allocated). */
|
|
74
|
+
private dirInto;
|
|
75
|
+
/** Direction through a point given in normalised screen coordinates (−1…1, y up). */
|
|
76
|
+
private dirAt;
|
|
77
|
+
/**
|
|
78
|
+
* View: rays from the eye through the image corners. Without `out` the four rays share one origin array; with `out`
|
|
79
|
+
* (see `newCornerRays`) each ray's own arrays are written and `out` is returned.
|
|
80
|
+
*/
|
|
81
|
+
cornerRays(out?: Ray[]): Ray[];
|
|
82
|
+
/** View: the four side planes through the eye and the plane of the eye itself, normals inward. */
|
|
83
|
+
cullVolume(): CullFrustum;
|
|
84
|
+
key(): string;
|
|
85
|
+
/** Ray under a screen point in physical pixels from the top-left corner. */
|
|
86
|
+
screenRay(px: number, py: number): Ray;
|
|
87
|
+
/** Where a world point lands on the canvas, in physical pixels from the top-left corner. */
|
|
88
|
+
project(p: Vec3): [number, number];
|
|
89
|
+
/** Drag by physical pixels: horizontal turns around the target, vertical tilts. */
|
|
90
|
+
orbitPixels(dx: number, dy: number): void;
|
|
91
|
+
/** Multiplies the distance to the target (below 1 comes closer). */
|
|
92
|
+
zoomBy(factor: number): void;
|
|
93
|
+
}
|