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,188 @@
|
|
|
1
|
+
// Checks of built geometry without a browser, for a project's own inspection scripts. They read plain numbers only
|
|
2
|
+
// (positions, indices, a height function, a collision world) and allocate freely: run them in a script, not per frame.
|
|
3
|
+
//
|
|
4
|
+
// - `meshParts` splits a mesh into connected parts (shared triangles, or vertices at the same place) with their
|
|
5
|
+
// bounds and their lowest gap over the ground.
|
|
6
|
+
// - `floatingParts` finds the parts that neither reach the ground nor touch, directly or through others, a part that
|
|
7
|
+
// does: something hanging in the air.
|
|
8
|
+
// - `routeClearance` walks a route (x, z points) and reports where it comes closest to a solid of a collision world.
|
|
9
|
+
import { distToSegment } from '../gen-core/geometry.js';
|
|
10
|
+
/** Splits a triangle mesh into connected parts: triangles sharing a vertex, or vertices within `weld` of each other. */
|
|
11
|
+
export function meshParts(positions, indices, o) {
|
|
12
|
+
const stride = o.stride ?? 3;
|
|
13
|
+
const n = Math.floor(positions.length / stride);
|
|
14
|
+
const m = o.transform ?? null;
|
|
15
|
+
const P = new Float64Array(n * 3);
|
|
16
|
+
for (let i = 0; i < n; i++) {
|
|
17
|
+
const x = positions[i * stride];
|
|
18
|
+
const y = positions[i * stride + 1];
|
|
19
|
+
const z = positions[i * stride + 2];
|
|
20
|
+
if (m) {
|
|
21
|
+
P[i * 3] = m[0] * x + m[3] * y + m[6] * z + m[9];
|
|
22
|
+
P[i * 3 + 1] = m[1] * x + m[4] * y + m[7] * z + m[10];
|
|
23
|
+
P[i * 3 + 2] = m[2] * x + m[5] * y + m[8] * z + m[11];
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
P[i * 3] = x;
|
|
27
|
+
P[i * 3 + 1] = y;
|
|
28
|
+
P[i * 3 + 2] = z;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const parent = new Int32Array(n);
|
|
32
|
+
for (let i = 0; i < n; i++)
|
|
33
|
+
parent[i] = i;
|
|
34
|
+
const find = (i) => {
|
|
35
|
+
while (parent[i] !== i)
|
|
36
|
+
i = parent[i] = parent[parent[i]];
|
|
37
|
+
return i;
|
|
38
|
+
};
|
|
39
|
+
const union = (a, b) => {
|
|
40
|
+
const x = find(a);
|
|
41
|
+
const y = find(b);
|
|
42
|
+
if (x !== y)
|
|
43
|
+
parent[x] = y;
|
|
44
|
+
};
|
|
45
|
+
const weld = o.weld ?? 0.01;
|
|
46
|
+
const byPos = new Map();
|
|
47
|
+
for (let i = 0; i < n; i++) {
|
|
48
|
+
const k = `${Math.round(P[i * 3] / weld)},${Math.round(P[i * 3 + 1] / weld)},${Math.round(P[i * 3 + 2] / weld)}`;
|
|
49
|
+
const j = byPos.get(k);
|
|
50
|
+
if (j === undefined)
|
|
51
|
+
byPos.set(k, i);
|
|
52
|
+
else
|
|
53
|
+
union(i, j);
|
|
54
|
+
}
|
|
55
|
+
for (let k = 0; k + 2 < indices.length; k += 3) {
|
|
56
|
+
union(indices[k], indices[k + 1]);
|
|
57
|
+
union(indices[k], indices[k + 2]);
|
|
58
|
+
}
|
|
59
|
+
const used = new Uint8Array(n);
|
|
60
|
+
for (let k = 0; k < indices.length; k++)
|
|
61
|
+
used[indices[k]] = 1;
|
|
62
|
+
const parts = new Map();
|
|
63
|
+
const label = o.label ?? '';
|
|
64
|
+
for (let i = 0; i < n; i++) {
|
|
65
|
+
if (!used[i])
|
|
66
|
+
continue;
|
|
67
|
+
const r = find(i);
|
|
68
|
+
const x = P[i * 3];
|
|
69
|
+
const y = P[i * 3 + 1];
|
|
70
|
+
const z = P[i * 3 + 2];
|
|
71
|
+
let p = parts.get(r);
|
|
72
|
+
if (!p)
|
|
73
|
+
parts.set(r, (p = { label, min: [x, y, z], max: [x, y, z], gap: Infinity, at: [x, z], vertices: 0 }));
|
|
74
|
+
p.vertices++;
|
|
75
|
+
if (x < p.min[0])
|
|
76
|
+
p.min[0] = x;
|
|
77
|
+
if (y < p.min[1])
|
|
78
|
+
p.min[1] = y;
|
|
79
|
+
if (z < p.min[2])
|
|
80
|
+
p.min[2] = z;
|
|
81
|
+
if (x > p.max[0])
|
|
82
|
+
p.max[0] = x;
|
|
83
|
+
if (y > p.max[1])
|
|
84
|
+
p.max[1] = y;
|
|
85
|
+
if (z > p.max[2])
|
|
86
|
+
p.max[2] = z;
|
|
87
|
+
const g = y - o.heightAt(x, z);
|
|
88
|
+
if (g < p.gap) {
|
|
89
|
+
p.gap = g;
|
|
90
|
+
p.at = [x, z];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return [...parts.values()];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The parts that hang in the air: neither reaching the ground (within `groundTolerance`) nor touching (bounds within
|
|
97
|
+
* `touchTolerance`) a part that rests, directly or through a chain of touching parts. Pass the parts of every mesh
|
|
98
|
+
* that may hold another up together.
|
|
99
|
+
*/
|
|
100
|
+
export function floatingParts(parts, o = {}) {
|
|
101
|
+
const tol = o.groundTolerance ?? 0.05;
|
|
102
|
+
const touch = o.touchTolerance ?? 0.02;
|
|
103
|
+
const rests = parts.map((p) => p.gap <= tol);
|
|
104
|
+
const touches = (a, b) => {
|
|
105
|
+
for (let k = 0; k < 3; k++)
|
|
106
|
+
if (a.min[k] > b.max[k] + touch || b.min[k] > a.max[k] + touch)
|
|
107
|
+
return false;
|
|
108
|
+
return true;
|
|
109
|
+
};
|
|
110
|
+
// Spread "rests" over touching parts until nothing changes.
|
|
111
|
+
const queue = [];
|
|
112
|
+
rests.forEach((r, i) => r && queue.push(i));
|
|
113
|
+
while (queue.length > 0) {
|
|
114
|
+
const a = parts[queue.pop()];
|
|
115
|
+
for (let j = 0; j < parts.length; j++) {
|
|
116
|
+
if (rests[j] || !touches(a, parts[j]))
|
|
117
|
+
continue;
|
|
118
|
+
rests[j] = true;
|
|
119
|
+
queue.push(j);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return parts.filter((_, i) => !rests[i]);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The least horizontal distance between a route (x, z pairs) and the sides of the solids of a collision world (the
|
|
126
|
+
* base surface does not count), sampled every `step` along the route.
|
|
127
|
+
*/
|
|
128
|
+
export function routeClearance(world, route, o = {}) {
|
|
129
|
+
const solids = [];
|
|
130
|
+
const lo = o.minY ?? -Infinity;
|
|
131
|
+
const hi = o.maxY ?? Infinity;
|
|
132
|
+
world.forEachSolid((id, s) => {
|
|
133
|
+
if (s.maxY < lo || s.minY > hi)
|
|
134
|
+
return;
|
|
135
|
+
if (o.ignore?.(id, s.tag))
|
|
136
|
+
return;
|
|
137
|
+
solids.push({ id, tag: s.tag, ring: s.outline, x: s.x, z: s.z, r: s.radius });
|
|
138
|
+
});
|
|
139
|
+
const best = { distance: Infinity, x: 0, z: 0, solid: -1, tag: -1 };
|
|
140
|
+
const check = (x, z) => {
|
|
141
|
+
for (const s of solids) {
|
|
142
|
+
let d;
|
|
143
|
+
if (s.ring) {
|
|
144
|
+
const ring = s.ring;
|
|
145
|
+
const n = ring.length / 2;
|
|
146
|
+
d = Infinity;
|
|
147
|
+
let inside = false;
|
|
148
|
+
for (let i = 0, j = n - 1; i < n; j = i++) {
|
|
149
|
+
const ax = ring[j * 2];
|
|
150
|
+
const az = ring[j * 2 + 1];
|
|
151
|
+
const bx = ring[i * 2];
|
|
152
|
+
const bz = ring[i * 2 + 1];
|
|
153
|
+
d = Math.min(d, distToSegment(x, z, ax, az, bx, bz));
|
|
154
|
+
if (bz > z !== az > z && x < ((ax - bx) * (z - bz)) / (az - bz) + bx)
|
|
155
|
+
inside = !inside;
|
|
156
|
+
}
|
|
157
|
+
if (inside)
|
|
158
|
+
d = -d;
|
|
159
|
+
}
|
|
160
|
+
else
|
|
161
|
+
d = Math.hypot(x - s.x, z - s.z) - s.r;
|
|
162
|
+
if (d < best.distance) {
|
|
163
|
+
best.distance = d;
|
|
164
|
+
best.x = x;
|
|
165
|
+
best.z = z;
|
|
166
|
+
best.solid = s.id;
|
|
167
|
+
best.tag = s.tag;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
const n = Math.floor(route.length / 2);
|
|
172
|
+
if (n === 0)
|
|
173
|
+
return best;
|
|
174
|
+
const step = o.step ?? 0.25;
|
|
175
|
+
const segs = o.closed ? n : n - 1;
|
|
176
|
+
for (let k = 0; k < segs; k++) {
|
|
177
|
+
const ax = route[k * 2];
|
|
178
|
+
const az = route[k * 2 + 1];
|
|
179
|
+
const bx = route[((k + 1) % n) * 2];
|
|
180
|
+
const bz = route[((k + 1) % n) * 2 + 1];
|
|
181
|
+
const m = Math.max(1, Math.ceil(Math.hypot(bx - ax, bz - az) / step));
|
|
182
|
+
for (let i = 0; i < m; i++)
|
|
183
|
+
check(ax + ((bx - ax) * i) / m, az + ((bz - az) * i) / m);
|
|
184
|
+
}
|
|
185
|
+
if (!o.closed)
|
|
186
|
+
check(route[(n - 1) * 2], route[(n - 1) * 2 + 1]);
|
|
187
|
+
return best;
|
|
188
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { View } from '../base/view.ts';
|
|
2
|
+
import type { FrameStats, PassName, Renderer } from '../render/index.ts';
|
|
3
|
+
export interface ProfileOptions {
|
|
4
|
+
/** Measured frames per measurement (each preceded by two warm-up frames). Default 20. */
|
|
5
|
+
frames?: number;
|
|
6
|
+
/** Measure the cost of every layer: two measurements per layer. Default true. */
|
|
7
|
+
layers?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Advances the scene by one frame (clocks, animation, layer data) right before a render. When given, the profile
|
|
10
|
+
* also measures `running`: frames while the scene moves, with whatever shadow updates that causes. Its time is
|
|
11
|
+
* part of the measured frame. The other measurements do not call it and render the scene as it stands.
|
|
12
|
+
*/
|
|
13
|
+
step?: (index: number) => void;
|
|
14
|
+
}
|
|
15
|
+
/** Times of one measurement, ms per frame, each frame rendered and waited for. */
|
|
16
|
+
export interface FrameTiming {
|
|
17
|
+
/** Median frame time. */
|
|
18
|
+
ms: number;
|
|
19
|
+
/** Interquartile range: a difference below it is noise. */
|
|
20
|
+
spreadMs: number;
|
|
21
|
+
minMs: number;
|
|
22
|
+
maxMs: number;
|
|
23
|
+
/** Measured frames that drew into the shadow map (`FrameStats.shadowUpdates` > 0). */
|
|
24
|
+
shadowFrames: number;
|
|
25
|
+
/** Mean processor time of `Renderer.render` per frame (`FrameStats.cpuMs`). */
|
|
26
|
+
cpuMs: number;
|
|
27
|
+
}
|
|
28
|
+
/** What a layer does in one group of passes and what it costs there. */
|
|
29
|
+
export interface PassCost {
|
|
30
|
+
/** Triangles and calls the layer counted in one frame. */
|
|
31
|
+
triangles: number;
|
|
32
|
+
drawCalls: number;
|
|
33
|
+
/** Frame time with the layer minus frame time without it, ms. Null when layers were not measured (`ProfileOptions.layers`). */
|
|
34
|
+
ms: number | null;
|
|
35
|
+
}
|
|
36
|
+
export interface LayerProfile {
|
|
37
|
+
/** Position in `Renderer.layers` (the drawing order). */
|
|
38
|
+
index: number;
|
|
39
|
+
/** `Layer.name`, else the class name with the material name when there is one. */
|
|
40
|
+
name: string;
|
|
41
|
+
/** Passes in which the layer counted at least one call (a layer that never calls `DrawContext.count` has none). */
|
|
42
|
+
passes: PassName[];
|
|
43
|
+
/** The main passes (`color` and `overlay`, or `data`), measured with the shadow map kept; includes `prepare`. */
|
|
44
|
+
color: PassCost;
|
|
45
|
+
/** The shadow pass, measured with the shadow map redrawn in every frame. */
|
|
46
|
+
shadow: PassCost;
|
|
47
|
+
}
|
|
48
|
+
export interface FrameProfile {
|
|
49
|
+
/** Graphics device as the browser names it. */
|
|
50
|
+
gpu: string;
|
|
51
|
+
/** Main target in physical pixels and the physical pixels per CSS pixel. */
|
|
52
|
+
width: number;
|
|
53
|
+
height: number;
|
|
54
|
+
dpr: number;
|
|
55
|
+
/** Samples per pixel of the main target (0: no antialiasing). */
|
|
56
|
+
samples: number;
|
|
57
|
+
/** Edge of the shadow map texture and the part of it the fitted map used, pixels. */
|
|
58
|
+
shadowMapEdgePx: number;
|
|
59
|
+
shadowMapPx: number;
|
|
60
|
+
frames: number;
|
|
61
|
+
/** Time of `Device.finish` with nothing pending: contained in every frame time below. */
|
|
62
|
+
syncMs: number;
|
|
63
|
+
/** Only clearing and presenting the main target (no scene; `shadowFrames` and `cpuMs` are 0). */
|
|
64
|
+
empty: FrameTiming;
|
|
65
|
+
/** The current frame, shadow map kept as the renderer keeps it (redrawn only when the scene asks for it). */
|
|
66
|
+
kept: FrameTiming;
|
|
67
|
+
/** The current frame with the shadow map redrawn in every frame. */
|
|
68
|
+
shadow: FrameTiming;
|
|
69
|
+
/** Frames while `step` advances the scene; null without `step`. */
|
|
70
|
+
running: FrameTiming | null;
|
|
71
|
+
/** Statistics of one frame with the shadow map redrawn (main and shadow counts). */
|
|
72
|
+
stats: FrameStats;
|
|
73
|
+
/** One entry per layer in drawing order (empty when layers were not measured and counted). */
|
|
74
|
+
layers: LayerProfile[];
|
|
75
|
+
/** Wall time the whole profile took, ms. */
|
|
76
|
+
profileMs: number;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Measures the current frame of `renderer` from `view` (synchronous; the page is blocked meanwhile, about
|
|
80
|
+
* `frames × (3 + 2 × layers)` frames). Leaves the renderer as it was, with the shadow map marked for a redraw.
|
|
81
|
+
* Throws while the graphics context is lost.
|
|
82
|
+
*/
|
|
83
|
+
export declare function profileFrame(renderer: Renderer, view: View, options?: ProfileOptions): FrameProfile;
|
|
84
|
+
/** The profile as a plain-text table (fixed-width columns). */
|
|
85
|
+
export declare function formatProfile(p: FrameProfile): string;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// Frame profile: what a frame costs on the graphics card at hand, as numbers. Renders the current view synchronously,
|
|
2
|
+
// waits for the graphics after every frame (`Device.finish`) and takes the median frame time of several measurements:
|
|
3
|
+
// the empty frame, the frame with the shadow map kept, the frame with the shadow map redrawn, optionally the animated
|
|
4
|
+
// frame, and per layer the same frames without that layer (`Renderer.probe`). A layer's cost is the difference.
|
|
5
|
+
// Nothing here runs outside a profile; the renderer's normal frame is unchanged.
|
|
6
|
+
const WARMUP_FRAMES = 2;
|
|
7
|
+
/**
|
|
8
|
+
* Measures the current frame of `renderer` from `view` (synchronous; the page is blocked meanwhile, about
|
|
9
|
+
* `frames × (3 + 2 × layers)` frames). Leaves the renderer as it was, with the shadow map marked for a redraw.
|
|
10
|
+
* Throws while the graphics context is lost.
|
|
11
|
+
*/
|
|
12
|
+
export function profileFrame(renderer, view, options = {}) {
|
|
13
|
+
const device = renderer.device;
|
|
14
|
+
if (device.lost)
|
|
15
|
+
throw new Error('profileFrame: the graphics context is lost');
|
|
16
|
+
const frames = Math.max(1, Math.round(options.frames ?? 20));
|
|
17
|
+
const started = performance.now();
|
|
18
|
+
const wall = new Float64Array(frames);
|
|
19
|
+
const measure = (forceShadow, step) => {
|
|
20
|
+
renderer.invalidateShadows();
|
|
21
|
+
for (let i = 0; i < WARMUP_FRAMES; i++) {
|
|
22
|
+
if (forceShadow)
|
|
23
|
+
renderer.invalidateShadows();
|
|
24
|
+
renderer.render(view);
|
|
25
|
+
}
|
|
26
|
+
device.finish();
|
|
27
|
+
let shadowFrames = 0;
|
|
28
|
+
let cpu = 0;
|
|
29
|
+
for (let i = 0; i < frames; i++) {
|
|
30
|
+
const t0 = performance.now();
|
|
31
|
+
step?.(i);
|
|
32
|
+
if (forceShadow)
|
|
33
|
+
renderer.invalidateShadows();
|
|
34
|
+
const st = renderer.render(view);
|
|
35
|
+
device.finish();
|
|
36
|
+
wall[i] = performance.now() - t0;
|
|
37
|
+
if (st.shadowUpdates > 0)
|
|
38
|
+
shadowFrames++;
|
|
39
|
+
cpu += st.cpuMs;
|
|
40
|
+
}
|
|
41
|
+
return timing(wall, shadowFrames, cpu / frames);
|
|
42
|
+
};
|
|
43
|
+
const savedProbe = renderer.probe;
|
|
44
|
+
const savedBounds = renderer.bounds;
|
|
45
|
+
try {
|
|
46
|
+
// The cost of the wait itself, with nothing pending.
|
|
47
|
+
device.finish();
|
|
48
|
+
for (let i = 0; i < frames; i++) {
|
|
49
|
+
const t0 = performance.now();
|
|
50
|
+
device.finish();
|
|
51
|
+
wall[i] = performance.now() - t0;
|
|
52
|
+
}
|
|
53
|
+
const syncMs = timing(wall, 0, 0).ms;
|
|
54
|
+
renderer.probe = null;
|
|
55
|
+
renderer.bounds = null;
|
|
56
|
+
// Without bounds the renderer only clears and presents; its statistics are those of the last real frame.
|
|
57
|
+
const empty = { ...measure(false, null), shadowFrames: 0, cpuMs: 0 };
|
|
58
|
+
renderer.bounds = savedBounds;
|
|
59
|
+
// Counts per layer and pass from one frame with the shadow map redrawn.
|
|
60
|
+
const counts = new Map();
|
|
61
|
+
renderer.probe = {
|
|
62
|
+
drawn(layer, pass, triangles, calls) {
|
|
63
|
+
let byPass = counts.get(layer);
|
|
64
|
+
if (!byPass)
|
|
65
|
+
counts.set(layer, (byPass = new Map()));
|
|
66
|
+
const c = byPass.get(pass) ?? { triangles: 0, calls: 0 };
|
|
67
|
+
c.triangles += triangles;
|
|
68
|
+
c.calls += calls;
|
|
69
|
+
byPass.set(pass, c);
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
renderer.invalidateShadows();
|
|
73
|
+
const stats = { ...renderer.render(view) };
|
|
74
|
+
renderer.probe = null;
|
|
75
|
+
const kept = measure(false, null);
|
|
76
|
+
const shadow = measure(true, null);
|
|
77
|
+
const running = options.step ? measure(false, options.step) : null;
|
|
78
|
+
const layers = [];
|
|
79
|
+
const measureLayers = options.layers ?? true;
|
|
80
|
+
renderer.layers.forEach((layer, index) => {
|
|
81
|
+
const byPass = counts.get(layer);
|
|
82
|
+
const passes = [];
|
|
83
|
+
const color = { triangles: 0, drawCalls: 0, ms: null };
|
|
84
|
+
const shadowCost = { triangles: 0, drawCalls: 0, ms: null };
|
|
85
|
+
for (const [pass, c] of byPass ?? []) {
|
|
86
|
+
if (c.calls > 0)
|
|
87
|
+
passes.push(pass);
|
|
88
|
+
const into = pass === 'shadow' ? shadowCost : color;
|
|
89
|
+
into.triangles += c.triangles;
|
|
90
|
+
into.drawCalls += c.calls;
|
|
91
|
+
}
|
|
92
|
+
// Every layer is measured: a layer that does not count its draws (`DrawContext.count`) still costs time.
|
|
93
|
+
if (measureLayers) {
|
|
94
|
+
renderer.probe = { draws: (l, pass) => l !== layer || pass === 'shadow' };
|
|
95
|
+
color.ms = kept.ms - measure(false, null).ms;
|
|
96
|
+
}
|
|
97
|
+
if (measureLayers) {
|
|
98
|
+
renderer.probe = { draws: (l, pass) => l !== layer || pass !== 'shadow' };
|
|
99
|
+
shadowCost.ms = shadow.ms - measure(true, null).ms;
|
|
100
|
+
}
|
|
101
|
+
renderer.probe = null;
|
|
102
|
+
layers.push({ index, name: layerName(layer), passes, color, shadow: shadowCost });
|
|
103
|
+
});
|
|
104
|
+
return {
|
|
105
|
+
gpu: device.name,
|
|
106
|
+
width: view.width,
|
|
107
|
+
height: view.height,
|
|
108
|
+
dpr: view.dpr,
|
|
109
|
+
samples: device.mainSamples(),
|
|
110
|
+
shadowMapEdgePx: renderer.shadowMapEdgePx,
|
|
111
|
+
shadowMapPx: stats.shadowMapPx,
|
|
112
|
+
frames,
|
|
113
|
+
syncMs,
|
|
114
|
+
empty,
|
|
115
|
+
kept,
|
|
116
|
+
shadow,
|
|
117
|
+
running,
|
|
118
|
+
stats,
|
|
119
|
+
layers,
|
|
120
|
+
profileMs: performance.now() - started,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
finally {
|
|
124
|
+
renderer.probe = savedProbe;
|
|
125
|
+
renderer.bounds = savedBounds;
|
|
126
|
+
// A measurement may have left a layer out of the shadow map: the next frame draws it whole again.
|
|
127
|
+
renderer.invalidateShadows();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/** The profile as a plain-text table (fixed-width columns). */
|
|
131
|
+
export function formatProfile(p) {
|
|
132
|
+
const ms = (v) => (v === null ? '-' : v.toFixed(2));
|
|
133
|
+
const kilo = (v) => (v >= 1e6 ? `${(v / 1e6).toFixed(2)} M` : v >= 1e3 ? `${(v / 1e3).toFixed(1)} k` : String(v));
|
|
134
|
+
const row = (label, t) => `${label.padEnd(24)}${ms(t.ms).padStart(8)}${`±${t.spreadMs.toFixed(2)}`.padStart(9)}${ms(t.minMs).padStart(8)}${ms(t.maxMs).padStart(8)}${`${t.shadowFrames}/${p.frames}`.padStart(9)}${t.cpuMs.toFixed(2).padStart(8)}`;
|
|
135
|
+
const out = [
|
|
136
|
+
`Frame profile ${p.gpu}`,
|
|
137
|
+
`target ${p.width} × ${p.height} px (dpr ${p.dpr}), ${p.samples} samples, shadow map ${p.shadowMapEdgePx} px (used ${p.shadowMapPx}), ${p.frames} frames, wait ${p.syncMs.toFixed(2)} ms, took ${(p.profileMs / 1000).toFixed(1)} s`,
|
|
138
|
+
`main ${kilo(p.stats.triangles)} tris in ${p.stats.drawCalls} calls, shadow ${kilo(p.stats.shadowTriangles)} tris in ${p.stats.shadowDrawCalls} calls`,
|
|
139
|
+
'',
|
|
140
|
+
`${'frame'.padEnd(24)}${'ms'.padStart(8)}${'spread'.padStart(9)}${'min'.padStart(8)}${'max'.padStart(8)}${'shadow'.padStart(9)}${'cpu'.padStart(8)}`,
|
|
141
|
+
row('empty (clear, present)', p.empty),
|
|
142
|
+
row('shadow kept', p.kept),
|
|
143
|
+
row('shadow every frame', p.shadow),
|
|
144
|
+
];
|
|
145
|
+
if (p.running)
|
|
146
|
+
out.push(row('running', p.running));
|
|
147
|
+
if (p.layers.length > 0) {
|
|
148
|
+
out.push('', `${'layer'.padEnd(30)}${'passes'.padEnd(22)}${'color tris'.padStart(11)}${'calls'.padStart(7)}${'ms'.padStart(8)}${'shadow tris'.padStart(13)}${'calls'.padStart(7)}${'ms'.padStart(8)}`);
|
|
149
|
+
for (const l of p.layers) {
|
|
150
|
+
out.push(`${`${l.index} ${l.name}`.slice(0, 29).padEnd(30)}${l.passes.join(',').slice(0, 21).padEnd(22)}${kilo(l.color.triangles).padStart(11)}${String(l.color.drawCalls).padStart(7)}${ms(l.color.ms).padStart(8)}${kilo(l.shadow.triangles).padStart(13)}${String(l.shadow.drawCalls).padStart(7)}${ms(l.shadow.ms).padStart(8)}`);
|
|
151
|
+
}
|
|
152
|
+
out.push(`(layer ms: frame with the layer minus frame without it; color with the shadow map kept, shadow with it redrawn every frame)`);
|
|
153
|
+
}
|
|
154
|
+
return out.join('\n');
|
|
155
|
+
}
|
|
156
|
+
/** `Layer.name`, else the class name, with the material name when the layer has one. */
|
|
157
|
+
function layerName(layer) {
|
|
158
|
+
if (layer.name)
|
|
159
|
+
return layer.name;
|
|
160
|
+
const cls = layer.constructor?.name || 'Layer';
|
|
161
|
+
const material = layer.material?.name;
|
|
162
|
+
return typeof material === 'string' ? `${cls}(${material})` : cls;
|
|
163
|
+
}
|
|
164
|
+
function timing(wall, shadowFrames, cpuMs) {
|
|
165
|
+
const s = Float64Array.from(wall).sort();
|
|
166
|
+
const q = (f) => {
|
|
167
|
+
const x = f * (s.length - 1);
|
|
168
|
+
const i = Math.floor(x);
|
|
169
|
+
const j = Math.min(i + 1, s.length - 1);
|
|
170
|
+
return s[i] + (s[j] - s[i]) * (x - i);
|
|
171
|
+
};
|
|
172
|
+
return { ms: q(0.5), spreadMs: q(0.75) - q(0.25), minMs: s[0], maxMs: s[s.length - 1], shadowFrames, cpuMs };
|
|
173
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CellId } from '../gen-core/cell.ts';
|
|
2
|
+
import type { CellProvider, CellResult } from './providers.ts';
|
|
3
|
+
/** Where cached cells are kept. `get` answers `null` for a key it does not hold; neither call may reject. */
|
|
4
|
+
export interface CellStore {
|
|
5
|
+
get(key: string): Promise<Uint8Array | null>;
|
|
6
|
+
put(key: string, bytes: Uint8Array): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
/** Counters of a cached provider, for a status line. */
|
|
9
|
+
export interface CellCacheStats {
|
|
10
|
+
/** Cells read back from the store, and cells the inner provider had to make. */
|
|
11
|
+
hits: number;
|
|
12
|
+
misses: number;
|
|
13
|
+
/** Stored cells that could not be decoded (they are made again and written over). */
|
|
14
|
+
broken: number;
|
|
15
|
+
/** Bytes read from and written to the store. */
|
|
16
|
+
bytesRead: number;
|
|
17
|
+
bytesWritten: number;
|
|
18
|
+
}
|
|
19
|
+
export declare class CachedCellProvider implements CellProvider {
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly blocking = false;
|
|
22
|
+
readonly stats: CellCacheStats;
|
|
23
|
+
private readonly inner;
|
|
24
|
+
private readonly store;
|
|
25
|
+
private readonly version;
|
|
26
|
+
/** `version` names what the cells were made from; cells stored under another version are not read. */
|
|
27
|
+
constructor(inner: CellProvider, store: CellStore, version: string);
|
|
28
|
+
/** The store key of a cell: the version, then the cell. A store can drop every key without this prefix. */
|
|
29
|
+
get prefix(): string;
|
|
30
|
+
key(cell: CellId): string;
|
|
31
|
+
request(cell: CellId, signal: AbortSignal): Promise<CellResult>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// A provider in front of another one that keeps finished cells in a byte store: a cell asked for a second time (in
|
|
2
|
+
// this visit or a later one) is read back instead of being built again. The store is a port; in a browser it is the
|
|
3
|
+
// byte store of `platform`, in a test a plain map. What is stored are the bytes of the cell format, so a cell from the
|
|
4
|
+
// cache is exactly the cell the inner provider made.
|
|
5
|
+
//
|
|
6
|
+
// The key of a cell holds a caller-given version (whatever its content depends on: the data's fingerprint, the
|
|
7
|
+
// generator's domain version, the world seed), so content made from other data is never read back.
|
|
8
|
+
import { cellKey } from '../gen-core/cell.js';
|
|
9
|
+
import { decodeCell, encodeCell } from './cell-format.js';
|
|
10
|
+
function aborted() {
|
|
11
|
+
const e = new Error('cell request cancelled');
|
|
12
|
+
e.name = 'AbortError';
|
|
13
|
+
return e;
|
|
14
|
+
}
|
|
15
|
+
export class CachedCellProvider {
|
|
16
|
+
name;
|
|
17
|
+
blocking = false;
|
|
18
|
+
stats = { hits: 0, misses: 0, broken: 0, bytesRead: 0, bytesWritten: 0 };
|
|
19
|
+
inner;
|
|
20
|
+
store;
|
|
21
|
+
version;
|
|
22
|
+
/** `version` names what the cells were made from; cells stored under another version are not read. */
|
|
23
|
+
constructor(inner, store, version) {
|
|
24
|
+
this.inner = inner;
|
|
25
|
+
this.store = store;
|
|
26
|
+
this.version = version;
|
|
27
|
+
this.name = `cache (${inner.name})`;
|
|
28
|
+
}
|
|
29
|
+
/** The store key of a cell: the version, then the cell. A store can drop every key without this prefix. */
|
|
30
|
+
get prefix() {
|
|
31
|
+
return `${this.version}/`;
|
|
32
|
+
}
|
|
33
|
+
key(cell) {
|
|
34
|
+
return `${this.prefix}${cellKey(cell)}`;
|
|
35
|
+
}
|
|
36
|
+
async request(cell, signal) {
|
|
37
|
+
const key = this.key(cell);
|
|
38
|
+
const stored = await this.store.get(key);
|
|
39
|
+
if (signal.aborted)
|
|
40
|
+
throw aborted();
|
|
41
|
+
if (stored) {
|
|
42
|
+
try {
|
|
43
|
+
const content = decodeCell(stored);
|
|
44
|
+
this.stats.hits++;
|
|
45
|
+
this.stats.bytesRead += stored.byteLength;
|
|
46
|
+
return { content, bytes: stored, origin: 'file' };
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
this.stats.broken++;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const made = await this.inner.request(cell, signal);
|
|
53
|
+
this.stats.misses++;
|
|
54
|
+
const bytes = made.bytes ?? encodeCell(made.content);
|
|
55
|
+
this.stats.bytesWritten += bytes.byteLength;
|
|
56
|
+
// Not awaited: the cell is drawn while the store writes.
|
|
57
|
+
void this.store.put(key, bytes);
|
|
58
|
+
return made;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CellContent } from '../gen-core/cell.ts';
|
|
2
|
+
export declare const CELL_MAGIC = 826493015;
|
|
3
|
+
export declare const CELL_FORMAT_VERSION = 1;
|
|
4
|
+
/** Format version of a cell that states the hash of its world shape or its error. */
|
|
5
|
+
export declare const CELL_FORMAT_VERSION_SHAPED = 2;
|
|
6
|
+
/** File extension of a baked cell. */
|
|
7
|
+
export declare const CELL_FILE_EXT = ".whc";
|
|
8
|
+
/** Encodes a cell. The same content always gives the same bytes. */
|
|
9
|
+
export declare function encodeCell(c: CellContent): Uint8Array;
|
|
10
|
+
/**
|
|
11
|
+
* Decodes a cell of format 1 or 2. The typed arrays of the result are views into `bytes` (which must start on a
|
|
12
|
+
* 4-byte boundary). A format 2 cell comes back with `shapeHash` and `error` where the file states them.
|
|
13
|
+
*/
|
|
14
|
+
export declare function decodeCell(bytes: Uint8Array): CellContent;
|
|
15
|
+
/**
|
|
16
|
+
* Relative path of a baked cell: `<face>/<level>/<x>/<y>.whc` (coordinates without the offset). With the hash of a
|
|
17
|
+
* world shape (`shapeHash` of gen-core) the path starts with it, as `s<8 hex digits>/`, so cells baked for different
|
|
18
|
+
* shapes never share a file.
|
|
19
|
+
*/
|
|
20
|
+
export declare function cellFilePath(c: {
|
|
21
|
+
face: number;
|
|
22
|
+
level: number;
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
}, shape?: number): string;
|