wallhammer-web 0.0.0-stage → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +92 -2
- package/dist/base/data.d.ts +67 -0
- package/dist/base/data.js +10 -0
- package/dist/base/destructible.d.ts +167 -0
- package/dist/base/destructible.js +47 -0
- package/dist/base/env-slot.d.ts +101 -0
- package/dist/base/env-slot.js +8 -0
- package/dist/base/frames.d.ts +138 -0
- package/dist/base/frames.js +459 -0
- package/dist/base/index.d.ts +21 -0
- package/dist/base/index.js +11 -0
- package/dist/base/mat34.d.ts +46 -0
- package/dist/base/mat34.js +173 -0
- package/dist/base/material.d.ts +87 -0
- package/dist/base/material.js +6 -0
- package/dist/base/math.d.ts +27 -0
- package/dist/base/math.js +60 -0
- package/dist/base/progress.d.ts +38 -0
- package/dist/base/progress.js +81 -0
- package/dist/base/rig.d.ts +177 -0
- package/dist/base/rig.js +97 -0
- package/dist/base/trig.d.ts +29 -0
- package/dist/base/trig.js +169 -0
- package/dist/base/up.d.ts +26 -0
- package/dist/base/up.js +40 -0
- package/dist/base/view.d.ts +128 -0
- package/dist/base/view.js +136 -0
- package/dist/camera/camera.d.ts +99 -0
- package/dist/camera/camera.js +228 -0
- package/dist/camera/follow.d.ts +120 -0
- package/dist/camera/follow.js +320 -0
- package/dist/camera/free.d.ts +153 -0
- package/dist/camera/free.js +359 -0
- package/dist/camera/index.d.ts +10 -0
- package/dist/camera/index.js +6 -0
- package/dist/camera/orbit.d.ts +93 -0
- package/dist/camera/orbit.js +261 -0
- package/dist/camera/path.d.ts +48 -0
- package/dist/camera/path.js +179 -0
- package/dist/core/ballistic.d.ts +66 -0
- package/dist/core/ballistic.js +104 -0
- package/dist/core/bodies.d.ts +77 -0
- package/dist/core/bodies.js +125 -0
- package/dist/core/clock.d.ts +37 -0
- package/dist/core/clock.js +87 -0
- package/dist/core/cover-fade.d.ts +14 -0
- package/dist/core/cover-fade.js +38 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.js +8 -0
- package/dist/core/kepler.d.ts +74 -0
- package/dist/core/kepler.js +108 -0
- package/dist/core/level-fade.d.ts +66 -0
- package/dist/core/level-fade.js +123 -0
- package/dist/core/palette.d.ts +15 -0
- package/dist/core/palette.js +47 -0
- package/dist/env/atmosphere.d.ts +129 -0
- package/dist/env/atmosphere.js +707 -0
- package/dist/env/cloud-field.d.ts +44 -0
- package/dist/env/cloud-field.js +111 -0
- package/dist/env/environment.d.ts +217 -0
- package/dist/env/environment.js +441 -0
- package/dist/env/frame-block.d.ts +29 -0
- package/dist/env/frame-block.js +152 -0
- package/dist/env/glsl.d.ts +35 -0
- package/dist/env/glsl.js +246 -0
- package/dist/env/index.d.ts +13 -0
- package/dist/env/index.js +9 -0
- package/dist/env/sky.d.ts +48 -0
- package/dist/env/sky.js +227 -0
- package/dist/env/sun.d.ts +31 -0
- package/dist/env/sun.js +42 -0
- package/dist/gen-arch/build.d.ts +17 -0
- package/dist/gen-arch/build.js +414 -0
- package/dist/gen-arch/damage/damaged.d.ts +44 -0
- package/dist/gen-arch/damage/damaged.js +1119 -0
- package/dist/gen-arch/damage/fall-material.d.ts +10 -0
- package/dist/gen-arch/damage/fall-material.js +47 -0
- package/dist/gen-arch/damage/fall.d.ts +78 -0
- package/dist/gen-arch/damage/fall.js +797 -0
- package/dist/gen-arch/damage/rubble.d.ts +22 -0
- package/dist/gen-arch/damage/rubble.js +188 -0
- package/dist/gen-arch/index.d.ts +25 -0
- package/dist/gen-arch/index.js +16 -0
- package/dist/gen-arch/interior/interior-plan.d.ts +114 -0
- package/dist/gen-arch/interior/interior-plan.js +615 -0
- package/dist/gen-arch/interior/interior.d.ts +97 -0
- package/dist/gen-arch/interior/interior.js +966 -0
- package/dist/gen-arch/structure/building-shader.d.ts +25 -0
- package/dist/gen-arch/structure/building-shader.js +946 -0
- package/dist/gen-arch/structure/buildings.d.ts +248 -0
- package/dist/gen-arch/structure/buildings.js +294 -0
- package/dist/gen-arch/structure/dims.d.ts +77 -0
- package/dist/gen-arch/structure/dims.js +39 -0
- package/dist/gen-arch/structure/distant.d.ts +62 -0
- package/dist/gen-arch/structure/distant.js +316 -0
- package/dist/gen-arch/structure/env-slots.d.ts +18 -0
- package/dist/gen-arch/structure/env-slots.js +47 -0
- package/dist/gen-arch/structure/facade.d.ts +193 -0
- package/dist/gen-arch/structure/facade.js +159 -0
- package/dist/gen-arch/structure/parts.d.ts +31 -0
- package/dist/gen-arch/structure/parts.js +69 -0
- package/dist/gen-arch/structure/roof.d.ts +76 -0
- package/dist/gen-arch/structure/roof.js +568 -0
- package/dist/gen-arch/structure/structure-material.d.ts +23 -0
- package/dist/gen-arch/structure/structure-material.js +55 -0
- package/dist/gen-arch/structure/writer.d.ts +94 -0
- package/dist/gen-arch/structure/writer.js +195 -0
- package/dist/gen-core/cell.d.ts +138 -0
- package/dist/gen-core/cell.js +150 -0
- package/dist/gen-core/cube-sphere.d.ts +57 -0
- package/dist/gen-core/cube-sphere.js +159 -0
- package/dist/gen-core/field.d.ts +55 -0
- package/dist/gen-core/field.js +154 -0
- package/dist/gen-core/geometry.d.ts +31 -0
- package/dist/gen-core/geometry.js +231 -0
- package/dist/gen-core/hash.d.ts +18 -0
- package/dist/gen-core/hash.js +58 -0
- package/dist/gen-core/height-field.d.ts +33 -0
- package/dist/gen-core/height-field.js +137 -0
- package/dist/gen-core/index.d.ts +22 -0
- package/dist/gen-core/index.js +17 -0
- package/dist/gen-core/instance-cells.d.ts +37 -0
- package/dist/gen-core/instance-cells.js +72 -0
- package/dist/gen-core/near-scatter.d.ts +56 -0
- package/dist/gen-core/near-scatter.js +120 -0
- package/dist/gen-core/noise.d.ts +23 -0
- package/dist/gen-core/noise.js +72 -0
- package/dist/gen-core/occupancy.d.ts +21 -0
- package/dist/gen-core/occupancy.js +104 -0
- package/dist/gen-core/sphere-patch.d.ts +138 -0
- package/dist/gen-core/sphere-patch.js +544 -0
- package/dist/gen-core/strip-surface.d.ts +34 -0
- package/dist/gen-core/strip-surface.js +246 -0
- package/dist/gen-core/strip.d.ts +102 -0
- package/dist/gen-core/strip.js +817 -0
- package/dist/gen-ground/env-slots.d.ts +48 -0
- package/dist/gen-ground/env-slots.js +78 -0
- package/dist/gen-ground/ground.d.ts +78 -0
- package/dist/gen-ground/ground.js +208 -0
- package/dist/gen-ground/index.d.ts +9 -0
- package/dist/gen-ground/index.js +7 -0
- package/dist/gen-ground/markings.d.ts +46 -0
- package/dist/gen-ground/markings.js +124 -0
- package/dist/gen-ground/materials.d.ts +18 -0
- package/dist/gen-ground/materials.js +22 -0
- package/dist/gen-ground/terrain-shader.d.ts +5 -0
- package/dist/gen-ground/terrain-shader.js +151 -0
- package/dist/gen-mesh/bare-shapes.d.ts +194 -0
- package/dist/gen-mesh/bare-shapes.js +596 -0
- package/dist/gen-mesh/bisect-surface.d.ts +47 -0
- package/dist/gen-mesh/bisect-surface.js +261 -0
- package/dist/gen-mesh/box.d.ts +18 -0
- package/dist/gen-mesh/box.js +2 -0
- package/dist/gen-mesh/cell-morph-mesh.d.ts +52 -0
- package/dist/gen-mesh/cell-morph-mesh.js +258 -0
- package/dist/gen-mesh/cell-surface-mesh.d.ts +32 -0
- package/dist/gen-mesh/cell-surface-mesh.js +140 -0
- package/dist/gen-mesh/chunk-mesh.d.ts +25 -0
- package/dist/gen-mesh/chunk-mesh.js +112 -0
- package/dist/gen-mesh/drape-mesh.d.ts +36 -0
- package/dist/gen-mesh/drape-mesh.js +98 -0
- package/dist/gen-mesh/height-field-mesh.d.ts +14 -0
- package/dist/gen-mesh/height-field-mesh.js +98 -0
- package/dist/gen-mesh/index.d.ts +26 -0
- package/dist/gen-mesh/index.js +15 -0
- package/dist/gen-mesh/line-mesh.d.ts +25 -0
- package/dist/gen-mesh/line-mesh.js +62 -0
- package/dist/gen-mesh/mesh-builder.d.ts +115 -0
- package/dist/gen-mesh/mesh-builder.js +315 -0
- package/dist/gen-mesh/packed-mesh.d.ts +53 -0
- package/dist/gen-mesh/packed-mesh.js +205 -0
- package/dist/gen-mesh/prism-mesh.d.ts +33 -0
- package/dist/gen-mesh/prism-mesh.js +176 -0
- package/dist/gen-mesh/rig-mesh.d.ts +9 -0
- package/dist/gen-mesh/rig-mesh.js +135 -0
- package/dist/gen-mesh/strip-mesh.d.ts +45 -0
- package/dist/gen-mesh/strip-mesh.js +258 -0
- package/dist/gen-plan/drain.d.ts +58 -0
- package/dist/gen-plan/drain.js +270 -0
- package/dist/gen-plan/grid.d.ts +37 -0
- package/dist/gen-plan/grid.js +182 -0
- package/dist/gen-plan/horizon.d.ts +50 -0
- package/dist/gen-plan/horizon.js +185 -0
- package/dist/gen-plan/index.d.ts +15 -0
- package/dist/gen-plan/index.js +13 -0
- package/dist/gen-plan/line-tiles.d.ts +35 -0
- package/dist/gen-plan/line-tiles.js +190 -0
- package/dist/gen-plan/lines.d.ts +31 -0
- package/dist/gen-plan/lines.js +183 -0
- package/dist/gen-plan/plots.d.ts +40 -0
- package/dist/gen-plan/plots.js +282 -0
- package/dist/gen-plan/route.d.ts +55 -0
- package/dist/gen-plan/route.js +297 -0
- package/dist/gen-plan/sites.d.ts +32 -0
- package/dist/gen-plan/sites.js +209 -0
- package/dist/gen-tex/code-stamp.d.ts +31 -0
- package/dist/gen-tex/code-stamp.js +137 -0
- package/dist/gen-tex/index.d.ts +7 -0
- package/dist/gen-tex/index.js +5 -0
- package/dist/gen-tex/light-horizon.d.ts +47 -0
- package/dist/gen-tex/light-horizon.js +180 -0
- package/dist/gen-tex/textures.d.ts +8 -0
- package/dist/gen-tex/textures.js +49 -0
- package/dist/gen-tex/value-textures.d.ts +46 -0
- package/dist/gen-tex/value-textures.js +102 -0
- package/dist/gen-vegetation/env-slots.d.ts +20 -0
- package/dist/gen-vegetation/env-slots.js +29 -0
- package/dist/gen-vegetation/index.d.ts +8 -0
- package/dist/gen-vegetation/index.js +7 -0
- package/dist/gen-vegetation/materials.d.ts +7 -0
- package/dist/gen-vegetation/materials.js +17 -0
- package/dist/gen-vegetation/planting.d.ts +170 -0
- package/dist/gen-vegetation/planting.js +363 -0
- package/dist/gen-vegetation/tree-shader.d.ts +23 -0
- package/dist/gen-vegetation/tree-shader.js +229 -0
- package/dist/gen-vegetation/trees.d.ts +59 -0
- package/dist/gen-vegetation/trees.js +329 -0
- package/dist/gpu/device.d.ts +286 -0
- package/dist/gpu/device.js +1157 -0
- package/dist/gpu/gl.d.ts +134 -0
- package/dist/gpu/gl.js +276 -0
- package/dist/gpu/index.d.ts +4 -0
- package/dist/gpu/index.js +3 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +13 -0
- package/dist/motion/graph.d.ts +244 -0
- package/dist/motion/graph.js +739 -0
- package/dist/motion/index.d.ts +8 -0
- package/dist/motion/index.js +8 -0
- package/dist/motion/pose-ops.d.ts +30 -0
- package/dist/motion/pose-ops.js +232 -0
- package/dist/motion/reach.d.ts +45 -0
- package/dist/motion/reach.js +264 -0
- package/dist/motion/skeleton.d.ts +49 -0
- package/dist/motion/skeleton.js +99 -0
- package/dist/platform/byte-store.d.ts +21 -0
- package/dist/platform/byte-store.js +137 -0
- package/dist/platform/canvas.d.ts +29 -0
- package/dist/platform/canvas.js +76 -0
- package/dist/platform/context-loss.d.ts +8 -0
- package/dist/platform/context-loss.js +17 -0
- package/dist/platform/free-input.d.ts +51 -0
- package/dist/platform/free-input.js +100 -0
- package/dist/platform/index.d.ts +18 -0
- package/dist/platform/index.js +10 -0
- package/dist/platform/input.d.ts +48 -0
- package/dist/platform/input.js +117 -0
- package/dist/platform/keys.d.ts +12 -0
- package/dist/platform/keys.js +29 -0
- package/dist/platform/loop.d.ts +41 -0
- package/dist/platform/loop.js +84 -0
- package/dist/platform/walk-input.d.ts +74 -0
- package/dist/platform/walk-input.js +226 -0
- package/dist/platform/worker.d.ts +51 -0
- package/dist/platform/worker.js +170 -0
- package/dist/render/bone-instances.d.ts +24 -0
- package/dist/render/bone-instances.js +74 -0
- package/dist/render/cells.d.ts +70 -0
- package/dist/render/cells.js +144 -0
- package/dist/render/glsl.d.ts +66 -0
- package/dist/render/glsl.js +173 -0
- package/dist/render/index.d.ts +26 -0
- package/dist/render/index.js +16 -0
- package/dist/render/instance-sets.d.ts +97 -0
- package/dist/render/instance-sets.js +241 -0
- package/dist/render/near-instances.d.ts +75 -0
- package/dist/render/near-instances.js +219 -0
- package/dist/render/particles.d.ts +63 -0
- package/dist/render/particles.js +215 -0
- package/dist/render/pieces.d.ts +57 -0
- package/dist/render/pieces.js +151 -0
- package/dist/render/point-lights.d.ts +97 -0
- package/dist/render/point-lights.js +243 -0
- package/dist/render/renderer.d.ts +447 -0
- package/dist/render/renderer.js +1100 -0
- package/dist/render/rig.d.ts +74 -0
- package/dist/render/rig.js +576 -0
- package/dist/render/shadow-areas.d.ts +49 -0
- package/dist/render/shadow-areas.js +125 -0
- package/dist/render/shadow-glsl.d.ts +12 -0
- package/dist/render/shadow-glsl.js +146 -0
- package/dist/render/transient.d.ts +61 -0
- package/dist/render/transient.js +213 -0
- package/dist/render/value-glsl.d.ts +17 -0
- package/dist/render/value-glsl.js +208 -0
- package/dist/render/value-layers.d.ts +180 -0
- package/dist/render/value-layers.js +333 -0
- package/dist/runtime/atmosphere.d.ts +37 -0
- package/dist/runtime/atmosphere.js +304 -0
- package/dist/runtime/cloud-shell.d.ts +29 -0
- package/dist/runtime/cloud-shell.js +158 -0
- package/dist/runtime/engine.d.ts +155 -0
- package/dist/runtime/engine.js +305 -0
- package/dist/runtime/environment-link.d.ts +22 -0
- package/dist/runtime/environment-link.js +49 -0
- package/dist/runtime/index.d.ts +13 -0
- package/dist/runtime/index.js +12 -0
- package/dist/runtime/precipitation-glsl.d.ts +2 -0
- package/dist/runtime/precipitation-glsl.js +70 -0
- package/dist/runtime/precipitation.d.ts +11 -0
- package/dist/runtime/precipitation.js +78 -0
- package/dist/runtime/sky.d.ts +30 -0
- package/dist/runtime/sky.js +114 -0
- package/dist/runtime/streaming.d.ts +245 -0
- package/dist/runtime/streaming.js +602 -0
- package/dist/sim/agenda.d.ts +167 -0
- package/dist/sim/agenda.js +425 -0
- package/dist/sim/bytes.d.ts +34 -0
- package/dist/sim/bytes.js +125 -0
- package/dist/sim/destruction/apply.d.ts +59 -0
- package/dist/sim/destruction/apply.js +243 -0
- package/dist/sim/destruction/cell-states.d.ts +54 -0
- package/dist/sim/destruction/cell-states.js +198 -0
- package/dist/sim/destruction/index.d.ts +11 -0
- package/dist/sim/destruction/index.js +10 -0
- package/dist/sim/destruction/int-geometry.d.ts +17 -0
- package/dist/sim/destruction/int-geometry.js +131 -0
- package/dist/sim/destruction/pick.d.ts +13 -0
- package/dist/sim/destruction/pick.js +59 -0
- package/dist/sim/destruction/rubble.d.ts +8 -0
- package/dist/sim/destruction/rubble.js +159 -0
- package/dist/sim/destruction/state.d.ts +15 -0
- package/dist/sim/destruction/state.js +83 -0
- package/dist/sim/destruction/structure.d.ts +30 -0
- package/dist/sim/destruction/structure.js +139 -0
- package/dist/sim/events.d.ts +37 -0
- package/dist/sim/events.js +106 -0
- package/dist/sim/fixed.d.ts +21 -0
- package/dist/sim/fixed.js +64 -0
- package/dist/sim/flow-probe.d.ts +58 -0
- package/dist/sim/flow-probe.js +158 -0
- package/dist/sim/flow.d.ts +257 -0
- package/dist/sim/flow.js +967 -0
- package/dist/sim/index.d.ts +28 -0
- package/dist/sim/index.js +20 -0
- package/dist/sim/interlock.d.ts +47 -0
- package/dist/sim/interlock.js +252 -0
- package/dist/sim/movers.d.ts +228 -0
- package/dist/sim/movers.js +1083 -0
- package/dist/sim/nav.d.ts +72 -0
- package/dist/sim/nav.js +292 -0
- package/dist/sim/paths.d.ts +80 -0
- package/dist/sim/paths.js +197 -0
- package/dist/sim/regions.d.ts +87 -0
- package/dist/sim/regions.js +517 -0
- package/dist/sim/simulation.d.ts +114 -0
- package/dist/sim/simulation.js +291 -0
- package/dist/sim/states.d.ts +23 -0
- package/dist/sim/states.js +54 -0
- package/dist/sim/table.d.ts +49 -0
- package/dist/sim/table.js +126 -0
- package/dist/sim/zones.d.ts +11 -0
- package/dist/sim/zones.js +196 -0
- package/dist/tools/collision-lines.d.ts +12 -0
- package/dist/tools/collision-lines.js +50 -0
- package/dist/tools/data-view-glsl.d.ts +3 -0
- package/dist/tools/data-view-glsl.js +63 -0
- package/dist/tools/data-view-layers.d.ts +20 -0
- package/dist/tools/data-view-layers.js +60 -0
- package/dist/tools/debug-view.d.ts +30 -0
- package/dist/tools/debug-view.js +4 -0
- package/dist/tools/index.d.ts +10 -0
- package/dist/tools/index.js +7 -0
- package/dist/tools/mesh-checks.d.ts +67 -0
- package/dist/tools/mesh-checks.js +188 -0
- package/dist/tools/profile.d.ts +85 -0
- package/dist/tools/profile.js +173 -0
- package/dist/world/cell-cache.d.ts +32 -0
- package/dist/world/cell-cache.js +60 -0
- package/dist/world/cell-format.d.ts +25 -0
- package/dist/world/cell-format.js +232 -0
- package/dist/world/collide.d.ts +192 -0
- package/dist/world/collide.js +822 -0
- package/dist/world/index.d.ts +16 -0
- package/dist/world/index.js +12 -0
- package/dist/world/mesh-solids.d.ts +48 -0
- package/dist/world/mesh-solids.js +169 -0
- package/dist/world/pick.d.ts +34 -0
- package/dist/world/pick.js +177 -0
- package/dist/world/providers.d.ts +66 -0
- package/dist/world/providers.js +83 -0
- package/dist/world/sphere.d.ts +69 -0
- package/dist/world/sphere.js +271 -0
- package/dist/world/streaming.d.ts +288 -0
- package/dist/world/streaming.js +801 -0
- package/dist/world/walker.d.ts +145 -0
- package/dist/world/walker.js +502 -0
- package/docs/architecture.md +111 -0
- package/docs/cameras.md +302 -0
- package/docs/concepts.md +123 -0
- package/docs/destruction.md +127 -0
- package/docs/frames.md +199 -0
- package/docs/generators.md +575 -0
- package/docs/getting-started.md +123 -0
- package/docs/headless.md +50 -0
- package/docs/motion.md +160 -0
- package/docs/planet.md +152 -0
- package/docs/recipes.md +521 -0
- package/docs/reference.md +364 -0
- package/docs/rendering.md +823 -0
- package/docs/rigs.md +203 -0
- package/docs/simulation.md +235 -0
- package/docs/streaming.md +590 -0
- package/docs/system.md +166 -0
- package/docs/tools.md +175 -0
- package/docs/walking.md +262 -0
- package/package.json +131 -3
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// Conflict zones of the `lanes` collision mode: where segments of two paths on different lanes come closer than a
|
|
2
|
+
// clearance (a smaller one for segments side by side), both stretches belong to one zone, and stretches that touch along a path or are linked through other
|
|
3
|
+
// paths merge into the same zone (a whole junction becomes one zone). Entities on the same lane are left to
|
|
4
|
+
// following; a zone is what following cannot see: paths that cut, merge or turn across each other.
|
|
5
|
+
//
|
|
6
|
+
// Built once from the paths of a network, in a fixed order (path id, segment, sample), so the zones are the same on
|
|
7
|
+
// every machine. Geometry is done in floating point on millimetre inputs with IEEE operations only (no
|
|
8
|
+
// transcendental functions), the result is whole millimetres.
|
|
9
|
+
const CELL = 16000;
|
|
10
|
+
const STEP = 250;
|
|
11
|
+
/** Stretches on one path closer than this merge (mm). */
|
|
12
|
+
const MERGE = 1000;
|
|
13
|
+
function segDist2(x, z, s) {
|
|
14
|
+
const dx = s.bx - s.ax;
|
|
15
|
+
const dz = s.bz - s.az;
|
|
16
|
+
const l2 = dx * dx + dz * dz;
|
|
17
|
+
let t = l2 > 0 ? ((x - s.ax) * dx + (z - s.az) * dz) / l2 : 0;
|
|
18
|
+
t = t < 0 ? 0 : t > 1 ? 1 : t;
|
|
19
|
+
const px = s.ax + dx * t - x;
|
|
20
|
+
const pz = s.az + dz * t - z;
|
|
21
|
+
return px * px + pz * pz;
|
|
22
|
+
}
|
|
23
|
+
/** The part of segment `a` (mm from its start) within `c` of segment `b`, or null. */
|
|
24
|
+
function near(a, b, c) {
|
|
25
|
+
let lo = -1;
|
|
26
|
+
let hi = -1;
|
|
27
|
+
const c2 = c * c;
|
|
28
|
+
for (let t = 0;; t += STEP) {
|
|
29
|
+
const u = Math.min(t, a.len);
|
|
30
|
+
const k = a.len > 0 ? u / a.len : 0;
|
|
31
|
+
const x = a.ax + (a.bx - a.ax) * k;
|
|
32
|
+
const z = a.az + (a.bz - a.az) * k;
|
|
33
|
+
if (segDist2(x, z, b) < c2) {
|
|
34
|
+
if (lo < 0)
|
|
35
|
+
lo = u;
|
|
36
|
+
hi = u;
|
|
37
|
+
}
|
|
38
|
+
if (u >= a.len)
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
return lo < 0 ? null : [lo, hi];
|
|
42
|
+
}
|
|
43
|
+
/** Segments whose directions are within about 18 degrees of each other or of the opposite (cos² > 0.9). */
|
|
44
|
+
function parallel(a, b) {
|
|
45
|
+
const ax = a.bx - a.ax;
|
|
46
|
+
const az = a.bz - a.az;
|
|
47
|
+
const bx = b.bx - b.ax;
|
|
48
|
+
const bz = b.bz - b.az;
|
|
49
|
+
const dot = ax * bx + az * bz;
|
|
50
|
+
return dot * dot > 0.9 * (ax * ax + az * az) * (bx * bx + bz * bz);
|
|
51
|
+
}
|
|
52
|
+
export function buildZoneIntervals(paths, clearance, parallelClearance = clearance) {
|
|
53
|
+
const segs = [];
|
|
54
|
+
paths.forEach((p, pi) => {
|
|
55
|
+
const n = p.xs.length;
|
|
56
|
+
for (let s = 0; s < p.segments; s++) {
|
|
57
|
+
const b = (s + 1) % n;
|
|
58
|
+
segs.push({
|
|
59
|
+
path: p.id,
|
|
60
|
+
pi,
|
|
61
|
+
ax: Math.round(p.xs[s] * 1000),
|
|
62
|
+
az: Math.round(p.zs[s] * 1000),
|
|
63
|
+
bx: Math.round(p.xs[b] * 1000),
|
|
64
|
+
bz: Math.round(p.zs[b] * 1000),
|
|
65
|
+
s0: p.segStart[s],
|
|
66
|
+
len: p.segStart[s + 1] - p.segStart[s],
|
|
67
|
+
lane: p.segLane[s],
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
// Segments into grid cells by their box swollen by the clearance.
|
|
72
|
+
const grid = new Map();
|
|
73
|
+
const key = (cx, cz) => (cx + 0x8000) * 0x10000 + (cz + 0x8000);
|
|
74
|
+
segs.forEach((s, i) => {
|
|
75
|
+
const x0 = Math.floor((Math.min(s.ax, s.bx) - clearance) / CELL);
|
|
76
|
+
const x1 = Math.floor((Math.max(s.ax, s.bx) + clearance) / CELL);
|
|
77
|
+
const z0 = Math.floor((Math.min(s.az, s.bz) - clearance) / CELL);
|
|
78
|
+
const z1 = Math.floor((Math.max(s.az, s.bz) + clearance) / CELL);
|
|
79
|
+
for (let cx = x0; cx <= x1; cx++) {
|
|
80
|
+
for (let cz = z0; cz <= z1; cz++) {
|
|
81
|
+
const k = key(cx, cz);
|
|
82
|
+
const list = grid.get(k);
|
|
83
|
+
if (list)
|
|
84
|
+
list.push(i);
|
|
85
|
+
else
|
|
86
|
+
grid.set(k, [i]);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
// Stretches found, as union-find nodes.
|
|
91
|
+
const st = [];
|
|
92
|
+
const parent = [];
|
|
93
|
+
const find = (a) => {
|
|
94
|
+
while (parent[a] !== a) {
|
|
95
|
+
parent[a] = parent[parent[a]];
|
|
96
|
+
a = parent[a];
|
|
97
|
+
}
|
|
98
|
+
return a;
|
|
99
|
+
};
|
|
100
|
+
const union = (a, b) => {
|
|
101
|
+
const ra = find(a);
|
|
102
|
+
const rb = find(b);
|
|
103
|
+
if (ra !== rb)
|
|
104
|
+
parent[Math.max(ra, rb)] = Math.min(ra, rb);
|
|
105
|
+
};
|
|
106
|
+
const seen = new Set();
|
|
107
|
+
const keys = [...grid.keys()].sort((a, b) => a - b);
|
|
108
|
+
for (const k of keys) {
|
|
109
|
+
const list = grid.get(k);
|
|
110
|
+
for (let x = 0; x < list.length; x++) {
|
|
111
|
+
for (let y = x + 1; y < list.length; y++) {
|
|
112
|
+
const i = Math.min(list[x], list[y]);
|
|
113
|
+
const j = Math.max(list[x], list[y]);
|
|
114
|
+
const pair = i * segs.length + j;
|
|
115
|
+
if (seen.has(pair))
|
|
116
|
+
continue;
|
|
117
|
+
seen.add(pair);
|
|
118
|
+
const a = segs[i];
|
|
119
|
+
const b = segs[j];
|
|
120
|
+
if (a.lane === b.lane)
|
|
121
|
+
continue;
|
|
122
|
+
if (a.pi === b.pi) {
|
|
123
|
+
// Neighbours along one path are always close: only far parts of a path conflict with each other.
|
|
124
|
+
const p = paths[a.pi];
|
|
125
|
+
let gap = Math.max(b.s0 - (a.s0 + a.len), a.s0 - (b.s0 + b.len));
|
|
126
|
+
if (p.loop)
|
|
127
|
+
gap = Math.min(gap, p.length - (Math.max(a.s0 + a.len, b.s0 + b.len) - Math.min(a.s0, b.s0)));
|
|
128
|
+
if (gap < 4 * clearance)
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const cl = parallel(a, b) ? Math.min(clearance, parallelClearance) : clearance;
|
|
132
|
+
const na = near(a, b, cl);
|
|
133
|
+
if (!na)
|
|
134
|
+
continue;
|
|
135
|
+
const nb = near(b, a, cl) ?? [0, 0];
|
|
136
|
+
const ia = st.length;
|
|
137
|
+
st.push({ pi: a.pi, s0: a.s0 + na[0], s1: a.s0 + na[1] });
|
|
138
|
+
parent.push(ia);
|
|
139
|
+
st.push({ pi: b.pi, s0: b.s0 + nb[0], s1: b.s0 + nb[1] });
|
|
140
|
+
parent.push(ia + 1);
|
|
141
|
+
union(ia, ia + 1);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Stretches that overlap or nearly touch on one path are one zone.
|
|
146
|
+
const perPath = new Map();
|
|
147
|
+
st.forEach((s, i) => {
|
|
148
|
+
const list = perPath.get(s.pi);
|
|
149
|
+
if (list)
|
|
150
|
+
list.push(i);
|
|
151
|
+
else
|
|
152
|
+
perPath.set(s.pi, [i]);
|
|
153
|
+
});
|
|
154
|
+
for (const list of perPath.values()) {
|
|
155
|
+
list.sort((a, b) => st[a].s0 - st[b].s0 || a - b);
|
|
156
|
+
let end = -Infinity;
|
|
157
|
+
let last = -1;
|
|
158
|
+
for (const i of list) {
|
|
159
|
+
if (last >= 0 && st[i].s0 <= end + MERGE)
|
|
160
|
+
union(last, i);
|
|
161
|
+
if (st[i].s1 > end || last < 0) {
|
|
162
|
+
end = Math.max(end, st[i].s1);
|
|
163
|
+
}
|
|
164
|
+
last = i;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// Zone numbers in order of first appearance (input path order, then along the path).
|
|
168
|
+
const zoneOf = new Map();
|
|
169
|
+
const byPath = new Map();
|
|
170
|
+
const pis = [...perPath.keys()].sort((a, b) => a - b);
|
|
171
|
+
for (const pi of pis) {
|
|
172
|
+
const list = perPath.get(pi);
|
|
173
|
+
const s0 = [];
|
|
174
|
+
const s1 = [];
|
|
175
|
+
const zone = [];
|
|
176
|
+
for (const i of list) {
|
|
177
|
+
const root = find(i);
|
|
178
|
+
let z = zoneOf.get(root);
|
|
179
|
+
if (z === undefined) {
|
|
180
|
+
z = zoneOf.size;
|
|
181
|
+
zoneOf.set(root, z);
|
|
182
|
+
}
|
|
183
|
+
const k = s0.length - 1;
|
|
184
|
+
// Merge with the previous stretch of the same zone when they overlap or touch.
|
|
185
|
+
if (k >= 0 && zone[k] === z && st[i].s0 <= s1[k] + MERGE)
|
|
186
|
+
s1[k] = Math.max(s1[k], st[i].s1);
|
|
187
|
+
else {
|
|
188
|
+
s0.push(st[i].s0);
|
|
189
|
+
s1.push(st[i].s1);
|
|
190
|
+
zone.push(z);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
byPath.set(paths[pi].id, { s0: Int32Array.from(s0), s1: Int32Array.from(s1), zone: Int32Array.from(zone) });
|
|
194
|
+
}
|
|
195
|
+
return { byPath, count: zoneOf.size };
|
|
196
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MeshData } from '../base/data.ts';
|
|
2
|
+
import type { CollisionWorld, SolidInfo } from '../world/collide.ts';
|
|
3
|
+
export interface CollisionLinesOptions {
|
|
4
|
+
/** Which solids to draw. Default all. */
|
|
5
|
+
select?: (info: SolidInfo, id: number) => boolean;
|
|
6
|
+
/** Segments of a cylinder's circle. Default 16. */
|
|
7
|
+
segments?: number;
|
|
8
|
+
/** Bottoms deeper than this are drawn at it (a solid that reaches far below the base). Default −Infinity. */
|
|
9
|
+
floorY?: number;
|
|
10
|
+
}
|
|
11
|
+
/** The solids of `world` as lines. Built once per call (it allocates); rebuild after adding or removing solids. */
|
|
12
|
+
export declare function collisionLines(world: CollisionWorld, o?: CollisionLinesOptions): MeshData;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Wireframe of the solids of a collision world, for a debugging overlay: each prism as its outline at the bottom and
|
|
2
|
+
// at the top joined by its upright edges, each cylinder as two circles joined by four upright lines. One line mesh
|
|
3
|
+
// (`LINE_LAYOUT`, primitive 'lines'); draw it with any line material, for example `LINE_VS` and `LINE_FS`.
|
|
4
|
+
import { spaceLineMesh } from '../gen-mesh/line-mesh.js';
|
|
5
|
+
/** The solids of `world` as lines. Built once per call (it allocates); rebuild after adding or removing solids. */
|
|
6
|
+
export function collisionLines(world, o = {}) {
|
|
7
|
+
const segments = Math.max(3, Math.floor(o.segments ?? 16));
|
|
8
|
+
const floorY = o.floorY ?? -Infinity;
|
|
9
|
+
const paths = [];
|
|
10
|
+
world.forEachSolid((id, info) => {
|
|
11
|
+
if (o.select && !o.select(info, id))
|
|
12
|
+
return;
|
|
13
|
+
const lo = Math.max(info.minY, floorY);
|
|
14
|
+
const hi = info.maxY;
|
|
15
|
+
let ring;
|
|
16
|
+
let uprights;
|
|
17
|
+
if (info.kind === 'prism' && info.outline) {
|
|
18
|
+
ring = info.outline;
|
|
19
|
+
uprights = 1;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const r = new Float64Array(segments * 2);
|
|
23
|
+
for (let k = 0; k < segments; k++) {
|
|
24
|
+
const a = (k / segments) * Math.PI * 2;
|
|
25
|
+
r[k * 2] = info.x + Math.cos(a) * info.radius;
|
|
26
|
+
r[k * 2 + 1] = info.z + Math.sin(a) * info.radius;
|
|
27
|
+
}
|
|
28
|
+
ring = r;
|
|
29
|
+
// Four upright lines round a circle are enough to read it as a cylinder.
|
|
30
|
+
uprights = Math.max(1, Math.floor(segments / 4));
|
|
31
|
+
}
|
|
32
|
+
const n = ring.length >> 1;
|
|
33
|
+
const bottom = new Float64Array(n * 3);
|
|
34
|
+
const top = new Float64Array(n * 3);
|
|
35
|
+
for (let k = 0; k < n; k++) {
|
|
36
|
+
const x = ring[k * 2];
|
|
37
|
+
const z = ring[k * 2 + 1];
|
|
38
|
+
bottom[k * 3] = x;
|
|
39
|
+
bottom[k * 3 + 1] = lo;
|
|
40
|
+
bottom[k * 3 + 2] = z;
|
|
41
|
+
top[k * 3] = x;
|
|
42
|
+
top[k * 3 + 1] = hi;
|
|
43
|
+
top[k * 3 + 2] = z;
|
|
44
|
+
if (k % uprights === 0)
|
|
45
|
+
paths.push({ points: [x, lo, z, x, hi, z] });
|
|
46
|
+
}
|
|
47
|
+
paths.push({ points: bottom, closed: true }, { points: top, closed: true });
|
|
48
|
+
});
|
|
49
|
+
return spaceLineMesh(paths);
|
|
50
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const DATA_TERRAIN_FS = "#include <header>\nuniform usampler2D u_classes;\nuniform sampler2D u_colors;\nuniform float u_classStep;\nuniform vec3 u_earth;\nuniform usampler2D u_mask;\nuniform int u_maskOn;\nuniform vec3 u_maskColor;\nuniform float u_hatchM;\nuniform float u_maskOpacity;\nin vec3 v_world;\nin vec3 v_normal;\nflat in float v_kind;\nout vec4 o_color;\nvoid main() {\n if (v_kind > 0.5) {\n o_color = vec4(u_earth * 0.6, 1.0);\n return;\n }\n ivec2 size = textureSize(u_classes, 0);\n ivec2 p = clamp(ivec2(floor(v_world.xz / u_classStep)), ivec2(0), size - 1);\n int c = int(texelFetch(u_classes, p, 0).r);\n vec3 col = texelFetch(u_colors, ivec2(c, 0), 0).rgb;\n if (u_maskOn > 0) {\n uint m = texelFetch(u_mask, p, 0).r;\n if (m > 0u) {\n // Hatch lines in world space, antialiased by their screen footprint.\n float a = (v_world.x + v_world.z) / u_hatchM;\n float w = max(fwidth(a), 1e-4);\n float d = abs(fract(a) - 0.5);\n float line = 1.0 - smoothstep(0.38 - w, 0.38 + w, 0.5 - d);\n if (m > 1u) {\n float b = (v_world.x - v_world.z) / u_hatchM;\n float wb = max(fwidth(b), 1e-4);\n float db = abs(fract(b) - 0.5);\n line = max(line, 1.0 - smoothstep(0.38 - wb, 0.38 + wb, 0.5 - db));\n }\n col = mix(col, u_maskColor, line * u_maskOpacity);\n // Outline: a neighbouring raster pixel outside the mask.\n ivec2 hi = size - 1;\n bool edge = texelFetch(u_mask, clamp(p + ivec2(1, 0), ivec2(0), hi), 0).r == 0u ||\n texelFetch(u_mask, clamp(p - ivec2(1, 0), ivec2(0), hi), 0).r == 0u ||\n texelFetch(u_mask, clamp(p + ivec2(0, 1), ivec2(0), hi), 0).r == 0u ||\n texelFetch(u_mask, clamp(p - ivec2(0, 1), ivec2(0), hi), 0).r == 0u;\n if (edge) col = u_maskColor;\n }\n }\n o_color = vec4(col, 1.0);\n}";
|
|
2
|
+
export declare const LINE_VS = "#include <header>\nin vec3 a_pos;\nvoid main() {\n gl_Position = u_viewProj * vec4(a_pos, 1.0);\n}";
|
|
3
|
+
export declare const LINE_FS = "#version 300 es\nprecision highp float;\nuniform vec3 u_color;\nout vec4 o_color;\nvoid main() {\n o_color = vec4(u_color, 1.0);\n}";
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Data view: ground coloured by surface class (nearest raster pixel, no filtering or light)
|
|
2
|
+
// and single-colour lines over it.
|
|
3
|
+
export const DATA_TERRAIN_FS = /* glsl */ `#include <header>
|
|
4
|
+
uniform usampler2D u_classes;
|
|
5
|
+
uniform sampler2D u_colors;
|
|
6
|
+
uniform float u_classStep;
|
|
7
|
+
uniform vec3 u_earth;
|
|
8
|
+
uniform usampler2D u_mask;
|
|
9
|
+
uniform int u_maskOn;
|
|
10
|
+
uniform vec3 u_maskColor;
|
|
11
|
+
uniform float u_hatchM;
|
|
12
|
+
uniform float u_maskOpacity;
|
|
13
|
+
in vec3 v_world;
|
|
14
|
+
in vec3 v_normal;
|
|
15
|
+
flat in float v_kind;
|
|
16
|
+
out vec4 o_color;
|
|
17
|
+
void main() {
|
|
18
|
+
if (v_kind > 0.5) {
|
|
19
|
+
o_color = vec4(u_earth * 0.6, 1.0);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
ivec2 size = textureSize(u_classes, 0);
|
|
23
|
+
ivec2 p = clamp(ivec2(floor(v_world.xz / u_classStep)), ivec2(0), size - 1);
|
|
24
|
+
int c = int(texelFetch(u_classes, p, 0).r);
|
|
25
|
+
vec3 col = texelFetch(u_colors, ivec2(c, 0), 0).rgb;
|
|
26
|
+
if (u_maskOn > 0) {
|
|
27
|
+
uint m = texelFetch(u_mask, p, 0).r;
|
|
28
|
+
if (m > 0u) {
|
|
29
|
+
// Hatch lines in world space, antialiased by their screen footprint.
|
|
30
|
+
float a = (v_world.x + v_world.z) / u_hatchM;
|
|
31
|
+
float w = max(fwidth(a), 1e-4);
|
|
32
|
+
float d = abs(fract(a) - 0.5);
|
|
33
|
+
float line = 1.0 - smoothstep(0.38 - w, 0.38 + w, 0.5 - d);
|
|
34
|
+
if (m > 1u) {
|
|
35
|
+
float b = (v_world.x - v_world.z) / u_hatchM;
|
|
36
|
+
float wb = max(fwidth(b), 1e-4);
|
|
37
|
+
float db = abs(fract(b) - 0.5);
|
|
38
|
+
line = max(line, 1.0 - smoothstep(0.38 - wb, 0.38 + wb, 0.5 - db));
|
|
39
|
+
}
|
|
40
|
+
col = mix(col, u_maskColor, line * u_maskOpacity);
|
|
41
|
+
// Outline: a neighbouring raster pixel outside the mask.
|
|
42
|
+
ivec2 hi = size - 1;
|
|
43
|
+
bool edge = texelFetch(u_mask, clamp(p + ivec2(1, 0), ivec2(0), hi), 0).r == 0u ||
|
|
44
|
+
texelFetch(u_mask, clamp(p - ivec2(1, 0), ivec2(0), hi), 0).r == 0u ||
|
|
45
|
+
texelFetch(u_mask, clamp(p + ivec2(0, 1), ivec2(0), hi), 0).r == 0u ||
|
|
46
|
+
texelFetch(u_mask, clamp(p - ivec2(0, 1), ivec2(0), hi), 0).r == 0u;
|
|
47
|
+
if (edge) col = u_maskColor;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
o_color = vec4(col, 1.0);
|
|
51
|
+
}`;
|
|
52
|
+
export const LINE_VS = /* glsl */ `#include <header>
|
|
53
|
+
in vec3 a_pos;
|
|
54
|
+
void main() {
|
|
55
|
+
gl_Position = u_viewProj * vec4(a_pos, 1.0);
|
|
56
|
+
}`;
|
|
57
|
+
export const LINE_FS = /* glsl */ `#version 300 es
|
|
58
|
+
precision highp float;
|
|
59
|
+
uniform vec3 u_color;
|
|
60
|
+
out vec4 o_color;
|
|
61
|
+
void main() {
|
|
62
|
+
o_color = vec4(u_color, 1.0);
|
|
63
|
+
}`;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { RGB } from '../base/math.ts';
|
|
2
|
+
import { MeshLayer } from '../render/index.ts';
|
|
3
|
+
import type { Layer, Renderer } from '../render/index.ts';
|
|
4
|
+
import type { DataViewSetup } from './debug-view.ts';
|
|
5
|
+
export interface DataViewOptions {
|
|
6
|
+
/** Vertex shader of the ground mesh. It must pass `v_world`, `v_normal` and `flat v_kind` (> 0.5 = side skirt). May use includes. */
|
|
7
|
+
groundVs: string;
|
|
8
|
+
groundAttribs: Record<string, number>;
|
|
9
|
+
/** Colour of the side skirt (drawn at 60 %). */
|
|
10
|
+
skirt: RGB;
|
|
11
|
+
}
|
|
12
|
+
export declare class DataView {
|
|
13
|
+
/** `null` = nothing to draw. */
|
|
14
|
+
setup: DataViewSetup | null;
|
|
15
|
+
/** The ground in class colours. Its `mesh` is the ground mesh of the scene. */
|
|
16
|
+
readonly ground: MeshLayer;
|
|
17
|
+
/** Lines over everything, without a depth test. Register it after all other layers of the data pass. */
|
|
18
|
+
readonly lines: Layer;
|
|
19
|
+
constructor(renderer: Renderer, o: DataViewOptions);
|
|
20
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Layers of the data view: the ground in flat class colours (data pass) and single-colour lines over everything.
|
|
2
|
+
import { MeshLayer } from '../render/index.js';
|
|
3
|
+
import { DATA_TERRAIN_FS, LINE_FS, LINE_VS } from './data-view-glsl.js';
|
|
4
|
+
/** Texture units used by the data ground. */
|
|
5
|
+
const CLASS_UNIT = 2;
|
|
6
|
+
const COLOR_UNIT = 3;
|
|
7
|
+
const MASK_UNIT = 4;
|
|
8
|
+
export class DataView {
|
|
9
|
+
/** `null` = nothing to draw. */
|
|
10
|
+
setup = null;
|
|
11
|
+
/** The ground in class colours. Its `mesh` is the ground mesh of the scene. */
|
|
12
|
+
ground;
|
|
13
|
+
/** Lines over everything, without a depth test. Register it after all other layers of the data pass. */
|
|
14
|
+
lines;
|
|
15
|
+
constructor(renderer, o) {
|
|
16
|
+
const material = renderer.material({ name: 'data view', attribs: o.groundAttribs, passes: { data: { vs: o.groundVs, fs: DATA_TERRAIN_FS } } });
|
|
17
|
+
this.ground = new MeshLayer({
|
|
18
|
+
material,
|
|
19
|
+
passes: ['data'],
|
|
20
|
+
bind: (p, ctx) => {
|
|
21
|
+
const dv = this.setup;
|
|
22
|
+
if (!dv)
|
|
23
|
+
return;
|
|
24
|
+
ctx.device.texture(CLASS_UNIT, dv.classes);
|
|
25
|
+
ctx.device.texture(COLOR_UNIT, dv.colors);
|
|
26
|
+
p.int('u_classes', CLASS_UNIT);
|
|
27
|
+
p.int('u_colors', COLOR_UNIT);
|
|
28
|
+
p.float('u_classStep', dv.classStep);
|
|
29
|
+
p.vec3v('u_earth', o.skirt);
|
|
30
|
+
// Without a mask the unit still gets an integer texture, so the sampler type always matches.
|
|
31
|
+
ctx.device.texture(MASK_UNIT, dv.mask ? dv.mask.texture : dv.classes);
|
|
32
|
+
p.int('u_mask', MASK_UNIT);
|
|
33
|
+
p.int('u_maskOn', dv.mask ? 1 : 0);
|
|
34
|
+
if (dv.mask) {
|
|
35
|
+
p.vec3('u_maskColor', dv.mask.color[0], dv.mask.color[1], dv.mask.color[2]);
|
|
36
|
+
p.float('u_hatchM', dv.mask.hatchM);
|
|
37
|
+
p.float('u_maskOpacity', dv.mask.opacity);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
const line = renderer.device.program('data view lines', renderer.resolve(LINE_VS), LINE_FS, { a_pos: 0 });
|
|
42
|
+
this.lines = {
|
|
43
|
+
draw: (ctx) => {
|
|
44
|
+
const dv = this.setup;
|
|
45
|
+
if (ctx.pass !== 'data' || !dv)
|
|
46
|
+
return;
|
|
47
|
+
ctx.device.setState({ depthTest: false });
|
|
48
|
+
ctx.device.use(line);
|
|
49
|
+
for (const set of dv.lines) {
|
|
50
|
+
line.vec3('u_color', set.color[0], set.color[1], set.color[2]);
|
|
51
|
+
drawLines(ctx, set.mesh);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function drawLines(ctx, mesh) {
|
|
58
|
+
ctx.device.draw(mesh);
|
|
59
|
+
ctx.count(0);
|
|
60
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { RGB } from '../base/math.ts';
|
|
2
|
+
import type { Mesh, Texture } from '../gpu/index.ts';
|
|
3
|
+
/** What the data view draws. Assigned to `DataView.setup`, `null` turns it off. */
|
|
4
|
+
export interface DataViewSetup {
|
|
5
|
+
/** Class raster as an unsigned integer texture (`codeTexture`). Pixel (0, 0) is at x = 0, z = 0. */
|
|
6
|
+
classes: Texture;
|
|
7
|
+
/** Pixel size of the class raster in metres. */
|
|
8
|
+
classStep: number;
|
|
9
|
+
/** Colours by class code (`colorTable`). */
|
|
10
|
+
colors: Texture;
|
|
11
|
+
/** Lines over the surface, each set in its own colour (`lineMesh`). Drawn without a depth test, always on top. */
|
|
12
|
+
lines: {
|
|
13
|
+
mesh: Mesh;
|
|
14
|
+
color: RGB;
|
|
15
|
+
}[];
|
|
16
|
+
/** Optional mask over the class colours. `null` or missing = none. */
|
|
17
|
+
mask?: DataViewMask | null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Mask drawn over the class colours: an unsigned integer texture on the same grid as `classes`.
|
|
21
|
+
* Value 0 = nothing, 1 = diagonal hatch, 2 and more = cross-hatch. The edge of the masked area gets a solid outline.
|
|
22
|
+
*/
|
|
23
|
+
export interface DataViewMask {
|
|
24
|
+
texture: Texture;
|
|
25
|
+
color: RGB;
|
|
26
|
+
/** Distance of hatch lines in metres. */
|
|
27
|
+
hatchM: number;
|
|
28
|
+
/** Opacity of the hatch lines, 0–1. The outline is always opaque. */
|
|
29
|
+
opacity: number;
|
|
30
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// Data view for debugging: a surface in flat false colours by class code, without light and shadows,
|
|
2
|
+
// with outlines over it. The engine does not know what the codes mean: the app supplies codes, colours and lines
|
|
3
|
+
// (`codeTexture`, `colorTable` from gen-tex and `lineMesh` from gen-mesh, uploaded with the renderer).
|
|
4
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type { DataViewMask, DataViewSetup } from './debug-view.ts';
|
|
2
|
+
export { DataView } from './data-view-layers.ts';
|
|
3
|
+
export type { DataViewOptions } from './data-view-layers.ts';
|
|
4
|
+
export { DATA_TERRAIN_FS, LINE_FS, LINE_VS } from './data-view-glsl.ts';
|
|
5
|
+
export { formatProfile, profileFrame } from './profile.ts';
|
|
6
|
+
export type { FrameProfile, FrameTiming, LayerProfile, PassCost, ProfileOptions } from './profile.ts';
|
|
7
|
+
export { collisionLines } from './collision-lines.ts';
|
|
8
|
+
export type { CollisionLinesOptions } from './collision-lines.ts';
|
|
9
|
+
export { floatingParts, meshParts, routeClearance } from './mesh-checks.ts';
|
|
10
|
+
export type { FloatingOptions, MeshPart, MeshPartsOptions, RouteClearance, RouteClearanceOptions } from './mesh-checks.ts';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Layer 7, tools: debugging aids. The data view (flat class colours, outlines), the frame profile, the wireframe of a collision world
|
|
2
|
+
// and checks of built geometry without a browser (parts hanging in the air, route clearance from solids).
|
|
3
|
+
export { DataView } from './data-view-layers.js';
|
|
4
|
+
export { DATA_TERRAIN_FS, LINE_FS, LINE_VS } from './data-view-glsl.js';
|
|
5
|
+
export { formatProfile, profileFrame } from './profile.js';
|
|
6
|
+
export { collisionLines } from './collision-lines.js';
|
|
7
|
+
export { floatingParts, meshParts, routeClearance } from './mesh-checks.js';
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { CollisionWorld } from '../world/collide.ts';
|
|
2
|
+
/** One connected part of a mesh. */
|
|
3
|
+
export interface MeshPart {
|
|
4
|
+
/** The caller's name for the mesh it came from. */
|
|
5
|
+
label: string;
|
|
6
|
+
/** Bounds in world space. */
|
|
7
|
+
min: [number, number, number];
|
|
8
|
+
max: [number, number, number];
|
|
9
|
+
/** Lowest height of a vertex over the ground (negative: below it). */
|
|
10
|
+
gap: number;
|
|
11
|
+
/** x, z of that vertex. */
|
|
12
|
+
at: [number, number];
|
|
13
|
+
vertices: number;
|
|
14
|
+
}
|
|
15
|
+
export interface MeshPartsOptions {
|
|
16
|
+
/** Height of the ground under a point. */
|
|
17
|
+
heightAt(x: number, z: number): number;
|
|
18
|
+
/** Name carried by every part (default ''). */
|
|
19
|
+
label?: string;
|
|
20
|
+
/** Numbers per vertex in `positions`, the position being the first three. Default 3. */
|
|
21
|
+
stride?: number;
|
|
22
|
+
/** Mesh space → world: 12 numbers, linear part column by column then the translation (an instance record). */
|
|
23
|
+
transform?: ArrayLike<number> | null;
|
|
24
|
+
/** Vertices closer than this count as one place (parts that only share a position are one), metres. Default 0.01. */
|
|
25
|
+
weld?: number;
|
|
26
|
+
}
|
|
27
|
+
/** Splits a triangle mesh into connected parts: triangles sharing a vertex, or vertices within `weld` of each other. */
|
|
28
|
+
export declare function meshParts(positions: ArrayLike<number>, indices: ArrayLike<number>, o: MeshPartsOptions): MeshPart[];
|
|
29
|
+
export interface FloatingOptions {
|
|
30
|
+
/** A part whose lowest vertex is at most this high over the ground rests on it, metres. Default 0.05. */
|
|
31
|
+
groundTolerance?: number;
|
|
32
|
+
/** Two parts whose bounds come this close touch, metres. Default 0.02. */
|
|
33
|
+
touchTolerance?: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The parts that hang in the air: neither reaching the ground (within `groundTolerance`) nor touching (bounds within
|
|
37
|
+
* `touchTolerance`) a part that rests, directly or through a chain of touching parts. Pass the parts of every mesh
|
|
38
|
+
* that may hold another up together.
|
|
39
|
+
*/
|
|
40
|
+
export declare function floatingParts(parts: readonly MeshPart[], o?: FloatingOptions): MeshPart[];
|
|
41
|
+
/** Where a route comes closest to a solid. */
|
|
42
|
+
export interface RouteClearance {
|
|
43
|
+
/** Horizontal distance from the route to the solid's side (0 or less: the route enters it), metres; Infinity: no solid. */
|
|
44
|
+
distance: number;
|
|
45
|
+
/** The route point. */
|
|
46
|
+
x: number;
|
|
47
|
+
z: number;
|
|
48
|
+
/** The solid's id and tag (−1: none). */
|
|
49
|
+
solid: number;
|
|
50
|
+
tag: number;
|
|
51
|
+
}
|
|
52
|
+
export interface RouteClearanceOptions {
|
|
53
|
+
/** The route is a closed loop. Default false. */
|
|
54
|
+
closed?: boolean;
|
|
55
|
+
/** Spacing of the points checked along the route, metres. Default 0.25. */
|
|
56
|
+
step?: number;
|
|
57
|
+
/** Only solids that overlap this height span count (the body that walks the route). Default all. */
|
|
58
|
+
minY?: number;
|
|
59
|
+
maxY?: number;
|
|
60
|
+
/** Solids left out (for example the thing that drives the route). */
|
|
61
|
+
ignore?: (id: number, tag: number) => boolean;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The least horizontal distance between a route (x, z pairs) and the sides of the solids of a collision world (the
|
|
65
|
+
* base surface does not count), sampled every `step` along the route.
|
|
66
|
+
*/
|
|
67
|
+
export declare function routeClearance(world: CollisionWorld, route: ArrayLike<number>, o?: RouteClearanceOptions): RouteClearance;
|