@adatechnology/game-destruction-three 1.0.0 → 1.1.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/README.md +8 -0
- package/dist/index.d.ts +26 -5
- package/dist/index.global.js +741 -125
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +611 -100
- package/dist/index.js.map +1 -1
- package/dist/worker-kinds.d.ts +16 -0
- package/dist/worker-kinds.js +40 -2
- package/dist/worker-kinds.js.map +1 -1
- package/package.json +12 -12
package/dist/worker-kinds.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/worker-kinds.ts","../src/engine-ground-job.ts","../src/engine-ground-collision.ts","../src/engine-ground-step.ts","../src/engine-ground-ring.ts","../src/engine-ground-reach.ts","../src/engine-ground-solid.ts","../src/engine-ground.ts","../src/static-part-job.ts"],"sourcesContent":["import { WORKER_KIND_DEFAULTS, WORKER_KIND_ID } from '@adatechnology/game-contracts'\nimport type { TaskKind } from '@adatechnology/game-contracts'\n\nimport { computeGroundTile, jobTransferOf, transferOf } from './engine-ground-job'\nimport type { GroundTileJob, GroundTileResult } from './engine-ground-job'\nimport type { StaticSolid } from './engine-statics'\nimport { measureStaticPart, staticSolidsTransfer } from './static-part-job'\nimport type { StaticPartJob } from './static-part-job'\n\n/**\n * The engine's ground tiles as a task kind of the worker coordinator (`destruction.ground-tiles`, CLAUDE.md §14): a tile is a pure function\n * of the samples and the band read at the update it was asked for, so the worker and the main thread give the same bits. The engine's\n * `GroundSchedule` applies it at its update whatever the worker does (`createCoordinatorGroundPort`). No three.js here: a game's worker file\n * imports it from `@adatechnology/game-destruction-three/worker-kinds`.\n */\nexport const groundTilesKind: TaskKind<GroundTileJob, GroundTileResult> = Object.freeze({\n id: WORKER_KIND_ID.GROUND_TILES,\n kind: 'task' as const,\n ...WORKER_KIND_DEFAULTS[WORKER_KIND_ID.GROUND_TILES],\n run: computeGroundTile,\n transferOutput: transferOf,\n // the schedule posts copies from its pool and keeps the job for its own fallback: the samples and band (or the patch) go over without a structured clone, and come back with the answer\n transferInput: jobTransferOf,\n transferAwaitedInput: true,\n // no `warmup`: the engine warms its port with a real tile when the renderer is made (`GroundSchedule.warm`)\n})\n\n/** A cube, the first job each worker runs (`warm`). */\nconst WARM_PART: StaticPartJob = {\n points: new Float64Array([-0.5, -0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, -0.5, 0.5, -0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, 0.5, 0.5, 0.5, -0.5, 0.5, 0.5]),\n matrix: new Float64Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]),\n position: [0, 0, 0],\n quaternion: [0, 0, 0, 1],\n scale: [1, 1, 1],\n found: new Uint32Array(0),\n from: 0,\n}\n\n/**\n * The fixed colliders measured from what is drawn (`destruction.static-colliders`, lane `build`, CLAUDE.md §14): a part of a house, a table, a wall measured anew is a\n * pure function of its vertices, its triangles and its world matrix (`measureStaticPart`), so the worker and the main thread give the same bits. The renderer hands its\n * parts to it when it has a coordinator (`RendererOptions.workers`); the object waits for the answer as a part out of turns waits for the next update.\n */\nexport const staticCollidersKind: TaskKind<StaticPartJob, StaticSolid[]> = Object.freeze({\n id: WORKER_KIND_ID.STATIC_COLLIDERS,\n kind: 'task' as const,\n ...WORKER_KIND_DEFAULTS[WORKER_KIND_ID.STATIC_COLLIDERS],\n run: measureStaticPart,\n transferOutput: staticSolidsTransfer,\n warmup: WARM_PART,\n})\n","import { cellCoordinate, heightPatchGrid } from '@adatechnology/game-terrain'\nimport type { HeightPatch } from '@adatechnology/game-terrain'\n\nimport { GROUND_CELL, readGround, sampleCount, shapeGround } from './engine-ground'\nimport type { GroundGrid, GroundTile } from './engine-ground'\nimport { SOLID_RING } from './engine-ground-ring'\nimport { NO_SOLID, buildSolidVolume } from './engine-ground-solid'\n\n/**\n * A tile of the engine's ground as plain data, so it can be made off the main thread (`engine-ground-port`): the main thread reads the tile's samples and the band of ground\n * past its edges its solid may read (`readGroundBand`), and the tile is a pure function of those (`computeGroundTile`), the same bits wherever it runs. Nothing here calls back\n * into the host: a worker has no `groundAt`.\n */\n\n/** What a tile is made from: its samples (`readGround`) and the band past its edges (`readGroundBand`), both read on the main thread at the frame it was asked for. */\nexport interface GroundTileJob {\n readonly id: number\n readonly x0: number\n readonly z0: number\n readonly size: number\n /** Whether the tile collided on the coarse field before (`collisionFieldOf`). */\n readonly wasCoarse: boolean\n /** Empty in a patch job (`patch`), whose samples and band are made where the tile is. */\n readonly samples: Float64Array\n readonly band: Float64Array\n /**\n * The terrain's vertices under the tile and its ring (`readGroundPatch`), in place of the samples and the band: about 26 x 26 numbers instead of 60 000. The tile is made from\n * the samples and band the patch gives (`heightPatchGrid`, the terrain's own blend), the same bits as read from the terrain on the main thread.\n */\n readonly patch?: HeightPatch\n}\n\n/** A tile made from a job, as arrays that cross threads; `samples` and `band` are the job's own, handed back for the next job. */\nexport interface GroundTileResult {\n readonly id: number\n readonly cells: number\n readonly collisionCells: number\n readonly level: number | null\n readonly heights: Float32Array\n readonly collision: Float32Array\n readonly boxes: Float64Array\n readonly solid: Float64Array\n readonly ring: Float64Array\n readonly samples: Float64Array\n readonly band: Float64Array\n /** A patch job's vertex heights, handed back for the next job. */\n readonly patch?: Float64Array\n}\n\n/** How many read cells the ring past a tile of `cells` cells of side `cell` is wide (`createGroundRing`). */\nconst ringOf = (cell: number): number => Math.round(SOLID_RING / cell)\n\n/** The length of the band of a tile of `size` m: one height per half cell over the tile and its ring (`GroundSource`). */\nexport const bandLength = (size: number): number => {\n const n = Math.round(size / GROUND_CELL)\n const width = 2 * (n + 2 * ringOf(size / n)) + 1\n return width * width\n}\n\n// the lattice of a band read through the grid, kept between reads (one at a time)\nlet lineX = new Float64Array(0)\nlet lineZ = new Float64Array(0)\nlet sideOut = new Float64Array(0)\n\n/**\n * Reads into `band` the ground past the tile's edges, as far as its solid may read it (`SOLID_RING`) and on the edges themselves: every half cell `(a, b)` with `a` or `b` on or\n * past an edge, at the very point the ring asks `groundAt` for (`x0 + (a / 2) * cell`). Through `grid` in four strips, else a call each. The tile's inside is left as it was.\n */\nexport const readGroundBand = (groundAt: (x: number, z: number) => number, band: Float64Array, x0: number, z0: number, size: number, grid?: GroundGrid): void => {\n const n = Math.round(size / GROUND_CELL)\n const cell = size / n\n const r = ringOf(cell)\n const lo = -2 * r\n const hi = 2 * n + 2 * r\n const width = hi - lo + 1\n const xAt = (a: number): number => x0 + (a / 2) * cell\n const zAt = (b: number): number => z0 + (b / 2) * cell\n if (!grid) {\n for (let b = lo; b <= hi; b++) {\n for (let a = lo; a <= hi; a++) {\n if (a > 0 && a < 2 * n && b > 0 && b < 2 * n) continue\n band[(b - lo) * width + a - lo] = groundAt(xAt(a), zAt(b))\n }\n }\n return\n }\n const strip = 2 * r + 1\n const middle = 2 * n - 1\n if (lineX.length < width) lineX = new Float64Array(width)\n if (lineZ.length < width) lineZ = new Float64Array(width)\n if (sideOut.length < strip * middle) sideOut = new Float64Array(strip * middle)\n for (let a = lo; a <= hi; a++) lineX[a - lo] = xAt(a)\n const xs = lineX.subarray(0, width)\n // the rows under the tile and over it, whole: straight into the band\n for (const from of [lo, 2 * n]) {\n for (let k = 0; k < strip; k++) lineZ[k] = zAt(from + k)\n grid(xs, lineZ.subarray(0, strip), band.subarray((from - lo) * width, (from - lo + strip) * width))\n }\n // the columns left and right of it, between those rows\n for (let k = 0; k < middle; k++) lineZ[k] = zAt(1 + k)\n const zs = lineZ.subarray(0, middle)\n for (const from of [lo, 2 * n]) {\n grid(lineX.subarray(from - lo, from - lo + strip), zs, sideOut)\n for (let k = 0; k < middle; k++) for (let i = 0; i < strip; i++) band[(1 + k - lo) * width + from - lo + i] = sideOut[k * strip + i]!\n }\n}\n\n/** The host's terrain as vertex heights under a rectangle (min x, max x, min z, max z), or null where it cannot (`Terrain.heightPatch` is one); written into `into` when long enough. */\nexport type GroundPatchRead = (minX: number, maxX: number, minZ: number, maxZ: number, into?: Float64Array) => HeightPatch | null\n\n/**\n * The terrain's vertices under the tile at (x0, z0) and its ring, the rectangle every sample and band point lies in (the band's own outermost points, as `readGroundBand` computes\n * them); null where the host has none (a tile crossing the terrain's bounds, where its `baseHeight` answers): that tile is read as before.\n */\nexport const readGroundPatch = (read: GroundPatchRead, x0: number, z0: number, size: number, into?: Float64Array): HeightPatch | null => {\n const n = Math.round(size / GROUND_CELL)\n const cell = size / n\n const r = ringOf(cell)\n const lo = -2 * r\n const hi = 2 * n + 2 * r\n return read(x0 + (lo / 2) * cell, x0 + (hi / 2) * cell, z0 + (lo / 2) * cell, z0 + (hi / 2) * cell, into)\n}\n\n/** The cell of `latticePatchRead`'s ground (m): a terrain's usual one. */\nconst LATTICE_CELL = 0.1\n\n/**\n * A `GroundPatchRead` of any ground as a terrain would hold it: `ground` sampled at the vertices of a `LATTICE_CELL` lattice laid a metre and more around each rectangle asked,\n * the patch found with the terrain's own cell rule (`cellCoordinate`). For the warm job of a patch tile, which has no terrain: whatever the tile size and ring are, its patch\n * covers them, as a real one does.\n */\nexport const latticePatchRead = (ground: (x: number, z: number) => number): GroundPatchRead => (minX, maxX, minZ, maxZ, into) => {\n const originX = Math.floor(minX) - 1\n const originZ = Math.floor(minZ) - 1\n const columns = Math.ceil((maxX - originX) / LATTICE_CELL) + 2\n const rows = Math.ceil((maxZ - originZ) / LATTICE_CELL) + 2\n const column0 = cellCoordinate(minX, originX, columns, LATTICE_CELL) | 0\n const row0 = cellCoordinate(minZ, originZ, rows, LATTICE_CELL) | 0\n const width = (cellCoordinate(maxX, originX, columns, LATTICE_CELL) | 0) + 2 - column0\n const depth = (cellCoordinate(maxZ, originZ, rows, LATTICE_CELL) | 0) + 2 - row0\n const heights = into && into.length >= width * depth ? into : new Float64Array(width * depth)\n for (let j = 0; j < depth; j++) for (let i = 0; i < width; i++) heights[j * width + i] = ground(originX + (column0 + i) * LATTICE_CELL, originZ + (row0 + j) * LATTICE_CELL)\n return { cellSize: LATTICE_CELL, originX, originZ, columns, rows, column0, row0, width, depth, heights }\n}\n\nconst NO_GROUND = (): number => {\n throw new Error('engine-ground-job: a patch job reads its patch only')\n}\n// the patch the grid below reads, and the samples and band a patch job is made into, kept between jobs (one at a time) so a job makes no arrays for them\nlet gridPatch: HeightPatch | null = null\nconst patchGrid: GroundGrid = (xs, zs, out) => heightPatchGrid(gridPatch as HeightPatch, xs, zs, out)\nlet patchSamples = new Float64Array(0)\nlet patchBand = new Float64Array(0)\n\n/** The samples and band of a patch job, read from its patch through the same lattices `readGround` and `readGroundBand` read the terrain at (module scratch: not reentrant). */\nconst groundOfPatch = (job: GroundTileJob, patch: HeightPatch): { samples: Float64Array; band: Float64Array } => {\n const count = sampleCount(Math.round(job.size / GROUND_CELL))\n if (patchSamples.length !== count) patchSamples = new Float64Array(count)\n if (patchBand.length !== bandLength(job.size)) patchBand = new Float64Array(bandLength(job.size))\n gridPatch = patch\n readGround(NO_GROUND, patchSamples, job.x0, job.z0, job.size, undefined, patchGrid)\n readGroundBand(NO_GROUND, patchBand, job.x0, job.z0, job.size, patchGrid)\n gridPatch = null\n return { samples: patchSamples, band: patchBand }\n}\n\n/**\n * The tile a job makes: `shapeGround` of its samples and, under a height field, its solid over the band (both made from its patch first, in a patch job). Pure of the job.\n * Not reentrant: a patch job's samples and band, and `readGround`'s lattice, are module scratch (one job at a time per thread, as a worker and the schedule run them).\n */\nexport const computeGroundTile = (job: GroundTileJob): GroundTileResult => {\n const { samples, band } = job.patch ? groundOfPatch(job, job.patch) : job\n const t = shapeGround(samples, job.x0, job.z0, job.size, null, job.wasCoarse)\n const solid = t.level === null ? buildSolidVolume(t.heights, t.cells, job.x0, job.z0, job.size / t.cells, band, t.cells / t.collisionCells) : NO_SOLID\n return {\n id: job.id, cells: t.cells, collisionCells: t.collisionCells, level: t.level, heights: t.heights, collision: t.collision,\n boxes: Float64Array.from(t.boxes), solid: Float64Array.from(solid.boxes), ring: Float64Array.from(solid.ring), samples: job.samples, band: job.band,\n ...(job.patch ? { patch: job.patch.heights } : {}),\n }\n}\n\n/** Each buffer of the arrays once, none empty (an empty one may be shared, and a buffer transferred twice throws). */\nconst buffersOf = (arrays: ReadonlyArray<Float32Array | Float64Array | undefined>): ArrayBuffer[] => {\n const out: ArrayBuffer[] = []\n for (const array of arrays) {\n const buffer = array?.buffer as ArrayBuffer | undefined\n if (buffer && buffer.byteLength > 0 && !out.includes(buffer)) out.push(buffer)\n }\n return out\n}\n\n/** The buffers a result hands over, each once and none empty (a height field may be its own collision field). */\nexport const transferOf = (r: GroundTileResult): ArrayBuffer[] => buffersOf([r.heights, r.collision, r.boxes, r.solid, r.ring, r.samples, r.band, r.patch])\n\n/** The buffers a job hands over: its samples and band, or its patch. */\nexport const jobTransferOf = (job: GroundTileJob): ArrayBuffer[] => buffersOf([job.samples, job.band, job.patch?.heights])\n\n/** The tile a result stands for, over the samples the main thread keeps for the tile (none for a patch tile, which keeps its patch instead). */\nexport const tileOfResult = (r: GroundTileResult, samples: Float64Array | null, patch?: HeightPatch): GroundTile => ({\n heights: r.heights, cells: r.cells, collision: r.collision, collisionCells: r.collisionCells, boxes: r.boxes,\n solid: r.level === null ? { boxes: r.solid, ring: r.ring } : NO_SOLID, level: r.level, samples, ...(patch ? { patch } : {}),\n})\n","/**\n * The engine collides with a tile's ground at a coarser grid than the tile is read at, as Unreal's \"Simple Collision\" mip level 1 does: every second corner of the 2.5 cm\n * grid, so a 5 cm height field. The read grid stays where the steps are found and the solid under the ground is made; the engine's narrow phase meets a quarter of the\n * triangles under a piece (the frame after a blast was mostly a piece resting on 2.5 cm triangles, T3.8ah). Owner decision 2026-11-17. The collision surface is off the drawn\n * ground by the bend of the ground across one of its cells: a tile keeps the coarse field only where that, with the engine's own 8 bit steps, is within 5 mm everywhere\n * on it, and has no step (`collisionFieldOf`); else it collides at the read grid.\n */\nexport const GROUND_COLLISION_CELL = 0.05\n\n/** The most (m) the collision surface may be off the drawn ground anywhere on a tile for the tile to collide at `GROUND_COLLISION_CELL` (the owner's bound). */\nexport const COLLISION_TOLERANCE = 0.005\n/**\n * A tile on the read grid goes to the coarse field only under this (m): one near the bound does not change field at every change of its ground (the bound stays hard). Not\n * lower: a room crater tile is 4.47 mm off at 5 cm, and a piece rests on it the frame after the blast.\n */\nexport const COLLISION_ENTER = 0.0045\n/** Samples a side of the engine's height field blocks (`game-physics-jolt` `HEIGHT_BLOCK`): each block's heights are 8 bit steps of its own range. */\nconst ENGINE_BLOCK = 4\n\n/** How many read cells (of `readCell` m, `cells` a side) a collision cell would span: 1 keeps the read grid (a collision cell that does not divide the tile). */\nexport const coarseStep = (cells: number, readCell: number): number => {\n const k = Math.max(1, Math.round(GROUND_COLLISION_CELL / readCell))\n return cells % k === 0 ? k : 1\n}\n\n/** A tile's collision field: every `step`-th corner of its read heights (1: the heights themselves). */\nexport interface CollisionField {\n readonly step: number\n readonly field: Float32Array\n}\n\n/**\n * A tile's collision field: the coarse one (`GROUND_COLLISION_CELL`) when the tile has no step boxes (a step's edge is between read corners, and a coarser field ramps or grooves\n * across it: 14 cm by a terrace's wall) and the coarse surface, on either diagonal and with the engine's 8 bit steps, is within `COLLISION_TOLERANCE` of the drawn ground at\n * every read corner (both are flat between them); within `COLLISION_ENTER` when the tile was on the read grid before (`wasCoarse` false: a fresh tile is one); else the read\n * grid itself.\n */\nexport const collisionFieldOf = (heights: Float32Array, cells: number, readCell: number, hasSteps: boolean, wasCoarse = false): CollisionField => {\n const k = coarseStep(cells, readCell)\n const fine = { step: 1, field: heights }\n if (k === 1 || hasSteps || heights.length === 0) return fine\n const m = cells + 1\n const get = (p: number, q: number): number => heights[q * m + p]!\n let off = 0\n for (let q = 0; q <= cells; q++) {\n for (let p = 0; p <= cells; p++) {\n collisionBoth(get, p, q, k)\n const h = heights[q * m + p]!\n off = Math.max(off, h - both[0]!, both[1]! - h)\n }\n }\n const field = collisionOf(heights, cells, k)\n return off + quantumOf(field, cells / k) <= (wasCoarse ? COLLISION_TOLERANCE : COLLISION_ENTER) ? { step: k, field } : fine\n}\n\n/** The most the engine's 8 bit heights may be off the field's own, over its blocks: half a step of a block's range. */\nconst quantumOf = (field: Float32Array, cells: number): number => {\n const m = cells + 1\n let most = 0\n for (let bj = 0; bj < cells; bj += ENGINE_BLOCK) {\n for (let bi = 0; bi < cells; bi += ENGINE_BLOCK) {\n let lo = Infinity, hi = -Infinity\n for (let j = bj; j <= Math.min(cells, bj + ENGINE_BLOCK); j++) {\n for (let i = bi; i <= Math.min(cells, bi + ENGINE_BLOCK); i++) {\n lo = Math.min(lo, field[j * m + i]!)\n hi = Math.max(hi, field[j * m + i]!)\n }\n }\n most = Math.max(most, (hi - lo) / 510)\n }\n }\n return most\n}\n\n/** The collision field of a tile's heights (`(cells + 1)^2`, x fastest): every `k`-th corner, `(cells / k + 1)^2` of them. */\nexport const collisionOf = (heights: Float32Array, cells: number, k: number): Float32Array => {\n if (k === 1) return heights\n const m = cells + 1\n const n = cells / k + 1\n const out = new Float32Array(n * n)\n for (let j = 0; j < n; j++) for (let i = 0; i < n; i++) out[j * n + i] = heights[j * k * m + i * k]!\n return out\n}\n\n/**\n * The collision surface at the read corner (`p`, `q`) (any integers: past the tile too), from `get` of the corners on the collision grid (multiples of `k`): the lower of the\n * two ways the engine may cut the collision cell into triangles, so whichever it uses is no lower than this.\n */\nexport const collisionAt = (get: (p: number, q: number) => number, p: number, q: number, k: number): number => {\n collisionBoth(get, p, q, k)\n return both[0]!\n}\n\n/** Where `collisionBoth` writes, the lower then the higher (one array for the module: no array per corner). */\nconst both = new Float64Array(2)\n\n/** The collision surface at the read corner (`p`, `q`) on the two ways a collision cell may be cut, into `both`: the lower then the higher. */\nconst collisionBoth = (get: (p: number, q: number) => number, p: number, q: number, k: number): void => {\n const p0 = Math.floor(p / k) * k, q0 = Math.floor(q / k) * k\n const u = (p - p0) / k, v = (q - q0) / k\n if (u === 0 && v === 0) {\n both[0] = both[1] = get(p0, q0)\n return\n }\n // on a collision cell's edge only that edge's corners are asked for (the tile's last row and column have no cell past them)\n const p1 = u === 0 ? p0 : p0 + k, q1 = v === 0 ? q0 : q0 + k\n const h00 = get(p0, q0), h10 = get(p1, q0), h01 = get(p0, q1), h11 = get(p1, q1)\n // the diagonal from (0, 0) to (1, 1), and the one from (1, 0) to (0, 1)\n const main = u >= v ? h00 + u * (h10 - h00) + v * (h11 - h10) : h00 + v * (h01 - h00) + u * (h11 - h01)\n const cross = u + v <= 1 ? h00 + u * (h10 - h00) + v * (h01 - h00) : h11 + (1 - u) * (h01 - h11) + (1 - v) * (h10 - h11)\n both[0] = Math.min(main, cross)\n both[1] = Math.max(main, cross)\n}\n\n/**\n * A tile's read heights lowered, corner by corner, to the collision surface where it is lower: a grid nothing over which (taken flat between corners, as the engine takes\n * both surfaces) rises over either surface. What must stay under the ground (the solid under it, §12) is made over this.\n */\nexport const underBoth = (heights: Float32Array, cells: number, k: number): Float32Array => {\n if (k === 1) return heights\n const m = cells + 1\n const get = (p: number, q: number): number => heights[q * m + p]!\n const out = new Float32Array(m * m)\n for (let q = 0; q <= cells; q++) for (let p = 0; p <= cells; p++) out[q * m + p] = Math.min(heights[q * m + p]!, collisionAt(get, p, q, k))\n return out\n}\n","/** How far (m) a sample may leave its cell's corners before the cell counts as holding a step. */\nexport const STEP_TOLERANCE = 0.005\n\n/**\n * Whether a cell holds a step, from its nine samples in `s`: the corners (x0 z0, x1 z0, x0 z1, x1 z1), the centre, and the middles of its edges (z0, z1, x0, x1). A step\n * moves the centre or an edge's middle off its corners. The one test the tile (`engine-ground`) and the ring past it (`engine-ground-ring`) make, so both see the same cells.\n */\nconst off = (a: number, b: number): boolean => Math.abs(a - b) > STEP_TOLERANCE\n\nexport const holdsStep = (s: ArrayLike<number>): boolean => {\n const c00 = s[0]!, c10 = s[1]!, c01 = s[2]!, c11 = s[3]!\n return off(s[4]!, (c00 + c10 + c01 + c11) / 4) || off(s[5]!, (c00 + c10) / 2) || off(s[6]!, (c01 + c11) / 2) || off(s[7]!, (c00 + c01) / 2) || off(s[8]!, (c10 + c11) / 2)\n}\n","import { collisionAt } from './engine-ground-collision'\nimport { holdsStep } from './engine-ground-step'\n\n/**\n * The ground a tile's solid reads around the tile: its own heights inside, and past its edges, as far as `SOLID_RING`, the ground the neighbour tile is made from (`groundAt`),\n * read only where a block of the solid reaches and once each. Every sample read past the edge is kept (`read`): the solid depends on them, so a change there makes it again.\n */\n\n/**\n * How far (m) past its tile's edges a block of the solid may reach: a cell of overlap, the skew of a top turned about both axes (a cell or two at the edge's block sizes), and a\n * box at least 15 cm deep at any slope (`engine-ground-solid` caps the depth of a box that would lean further). The host's changes this close to a tile make its solid again.\n */\nexport const SOLID_RING = 0.2\n/** One cell's nine samples, for `holdsStep`. */\nconst nine = new Float64Array(9)\n\n/**\n * Where the ring reads the ground past the tile's edges: the host's `groundAt`, or a band read ahead of time (`engine-ground-job` `readGroundBand`), one height per half cell\n * `(a, b)` at `(b + 2 * ring) * width + a + 2 * ring` (`width` = `2 * (cells + 2 * ring) + 1`), each the very height `groundAt` answers there. A worker has no `groundAt`.\n */\nexport type GroundSource = ((x: number, z: number) => number) | Float64Array\n\nexport interface GroundRing {\n /** How many cells the ring is wide. */\n readonly cells: number\n /** The four corners (`(i, j)`, `(i + 1, j)`, `(i, j + 1)`, `(i + 1, j + 1)`) of a cell past the tile's edge into `out`; a cell holding a step (`holdsStep`, as the neighbour builds it) has its lowest of nine samples at all four. */\n cell(i: number, j: number, out: Float64Array): void\n /** The samples read past the edge: x, z and height, three numbers each. */\n readonly read: number[]\n}\n\n// the samples and cells read for the ring being made, marked by the build they belong to (one at a time), so a ring costs no new arrays\nlet build = 0\nlet heldSamples = new Float64Array(0)\nlet sampleBuild = new Uint32Array(0)\nlet heldCells = new Float64Array(0)\nlet cellBuild = new Uint32Array(0)\n\n/**\n * `heights` are the tile's own (already under its collision field), `fieldStep` how many read cells a neighbour's coarse collision cell spans: past the edge a corner is the lower of\n * the ground there and that coarse field at it (the neighbour collides with it or with the ground itself).\n */\nexport const createGroundRing = (heights: Float32Array, cells: number, x0: number, z0: number, cell: number, groundAt: GroundSource, fieldStep = 1): GroundRing => {\n const band = typeof groundAt === 'function' ? null : groundAt\n const ring = Math.round(SOLID_RING / cell)\n const m = cells + 1\n const width = 2 * (cells + 2 * ring) + 1\n const across = cells + 2 * ring\n if (sampleBuild.length < width * width) {\n heldSamples = new Float64Array(width * width)\n sampleBuild = new Uint32Array(width * width)\n }\n if (cellBuild.length < across * across) {\n heldCells = new Float64Array(4 * across * across)\n cellBuild = new Uint32Array(across * across)\n }\n const mark = ++build\n const read: number[] = []\n /** The ground at the half cell (`a` / 2, `b` / 2): the tile's own height at its corners, the neighbour's ground elsewhere. */\n const half = (a: number, b: number): number => {\n if (a % 2 === 0 && b % 2 === 0 && a >= 0 && b >= 0 && a <= 2 * cells && b <= 2 * cells) return heights[(b / 2) * m + a / 2]!\n const key = (b + 2 * ring) * width + a + 2 * ring\n if (sampleBuild[key] === mark) return heldSamples[key]!\n const x = x0 + (a / 2) * cell\n const z = z0 + (b / 2) * cell\n const h = band === null ? (groundAt as (x: number, z: number) => number)(x, z) : band[key]!\n heldSamples[key] = h\n sampleBuild[key] = mark\n read.push(x, z, h)\n return h\n }\n /** The ground at the read corner (`p`, `q`). */\n const fine = (p: number, q: number): number => half(2 * p, 2 * q)\n return {\n cells: ring,\n read,\n cell(i, j, out) {\n const key = (j + ring) * across + i + ring\n if (cellBuild[key] !== mark) {\n const a = 2 * i, b = 2 * j\n nine[0] = half(a, b)\n nine[1] = half(a + 2, b)\n nine[2] = half(a, b + 2)\n nine[3] = half(a + 2, b + 2)\n nine[4] = half(a + 1, b + 1)\n nine[5] = half(a + 1, b)\n nine[6] = half(a + 1, b + 2)\n nine[7] = half(a, b + 1)\n nine[8] = half(a + 2, b + 1)\n // a cell the neighbour builds as a step: where the step runs in it is not known, so the ground there is no lower than its lowest sample\n const step = holdsStep(nine)\n let floor = Infinity\n for (let k = 0; k < 9; k++) floor = Math.min(floor, nine[k]!)\n const corner = (p: number, q: number, h: number): number => (fieldStep === 1 ? h : Math.min(h, collisionAt(fine, p, q, fieldStep)))\n const c00 = corner(i, j, nine[0]!), c10 = corner(i + 1, j, nine[1]!), c01 = corner(i, j + 1, nine[2]!), c11 = corner(i + 1, j + 1, nine[3]!)\n heldCells[4 * key] = step ? floor : c00\n heldCells[4 * key + 1] = step ? floor : c10\n heldCells[4 * key + 2] = step ? floor : c01\n heldCells[4 * key + 3] = step ? floor : c11\n cellBuild[key] = mark\n }\n for (let k = 0; k < 4; k++) out[k] = heldCells[4 * key + k]!\n },\n }\n}\n","import type { GroundRing } from './engine-ground-ring'\n\n/**\n * How far a turned box rises above the ground, over every column it has a point in, its leaning sides as much as its top: what it must be lowered by to be under the ground\n * everywhere (§12). The ground between a cell's corners is flat (the engine's two triangles, or bilinear), so a plane rises over it the most at a corner.\n * - Its top: the top's plane over every corner under the top's extent.\n * - Its sides, which lean uphill under the top: the box is its top slid down along -n, so where the ground over the box's shadow is nowhere steeper than the top's slope\n * allows (1 / its slope), no point of it is further over the ground than its top is. Else every cell of the shadow: a column's highest point is under each face that\n * looks up (the top, and the uphill side of each tilted axis), so over a cell under the lowest of those planes, found from the top down over a pyramid of planes under the\n * tile's ground (a block of cells whose plane is above every plane of the box over it is skipped whole).\n * - Past the tile's edges, every cell of the shadow there, over the ring's ground (`engine-ground-ring`).\n */\n\n/** A box: its centre, axes (x, y, z: the y axis is the normal of its top) and half sizes. */\nexport interface ReachBox {\n readonly c: ArrayLike<number>\n readonly axes: ReadonlyArray<ArrayLike<number>>\n readonly half: ArrayLike<number>\n}\n\n/**\n * Under each block of 2^l by 2^l cells (l from 1 up to one block over the whole tile), a plane no sample of the block is under: the block's corner slopes, lowered to its\n * lowest sample. Three numbers a block (its height at the block's first corner, and its slopes along x and z per cell), made when first asked for: over a slope or a\n * crater's wall the plane follows the ground, so a box whose planes are under it there is skipped whole.\n */\nexport interface LowPyramid {\n readonly heights: Float32Array\n readonly cells: number\n readonly sizes: readonly number[]\n readonly planes: readonly Float64Array[]\n /** The square of the steepest the ground is (m per m, any way) over each block: a cell's from its edges (its two triangles, or bilinear, are no steeper), a block's the steepest of its four. */\n readonly steepest: readonly Float64Array[]\n}\n\nexport const buildLowPyramid = (heights: Float32Array, cells: number, cell: number): LowPyramid => {\n const m = cells + 1\n const first = new Float64Array(cells * cells)\n for (let j = 0; j < cells; j++) {\n for (let i = 0; i < cells; i++) {\n const h00 = heights[j * m + i]!, h10 = heights[j * m + i + 1]!, h01 = heights[(j + 1) * m + i]!, h11 = heights[(j + 1) * m + i + 1]!\n const dx = Math.max(Math.abs(h10 - h00), Math.abs(h11 - h01)), dz = Math.max(Math.abs(h01 - h00), Math.abs(h11 - h10))\n first[j * cells + i] = (dx * dx + dz * dz) / (cell * cell)\n }\n }\n const sizes: number[] = [cells]\n const planes: Float64Array[] = [new Float64Array(0)]\n const steepest: Float64Array[] = [first]\n for (let s = 2; s < 2 * cells; s *= 2) {\n const below = steepest[steepest.length - 1]!\n const n = sizes[sizes.length - 1]!\n const k = Math.ceil(cells / s)\n const level = new Float64Array(k * k)\n for (let j = 0; j < n; j++) for (let i = 0; i < n; i++) level[(j >> 1) * k + (i >> 1)] = Math.max(level[(j >> 1) * k + (i >> 1)]!, below[j * n + i]!)\n sizes.push(k)\n planes.push(new Float64Array(3 * k * k).fill(NaN))\n steepest.push(level)\n }\n return { heights, cells, sizes, planes, steepest }\n}\n\n/** Whether the ground is steeper than `limit` (m per m) anywhere over the cells `ia`..`ib` (not included) by `ja`..`jb`. */\n// the question `steeperOver` is asking, for `visit` (one at a time)\nlet steepPyramid: LowPyramid | null = null\nlet steepSquare = 0\nlet steepIa = 0, steepIb = 0, steepJa = 0, steepJb = 0\n\nconst visit = (l: number, bi: number, bj: number): boolean => {\n const pyramid = steepPyramid!\n if (pyramid.steepest[l]![bj * pyramid.sizes[l]! + bi]! <= steepSquare) return false\n const s = 1 << l\n const a = bi * s, c = bj * s\n const b = Math.min(pyramid.cells, a + s), d = Math.min(pyramid.cells, c + s)\n if (a >= steepIb || b <= steepIa || c >= steepJb || d <= steepJa) return false\n if (l === 0) return true\n for (let dj = 0; dj < 2; dj++) for (let di = 0; di < 2; di++) if (visit(l - 1, 2 * bi + di, 2 * bj + dj)) return true\n return false\n}\n\nconst steeperOver = (pyramid: LowPyramid, ia: number, ib: number, ja: number, jb: number, limit: number): boolean => {\n steepPyramid = pyramid\n steepSquare = limit * limit\n steepIa = ia\n steepIb = ib\n steepJa = ja\n steepJb = jb\n const steeper = visit(pyramid.sizes.length - 1, 0, 0)\n // the last pyramid is not kept past the call (§8)\n steepPyramid = null\n return steeper\n}\n\n/** Where the plane under the block (`bi`, `bj`) of level `l` is in `pyramid.planes[l]`, made now if it was not. */\nconst planeUnder = (pyramid: LowPyramid, l: number, bi: number, bj: number): number => {\n const level = pyramid.planes[l]!\n const at = 3 * (bj * pyramid.sizes[l]! + bi)\n if (!Number.isNaN(level[at]!)) return at\n const { heights, cells } = pyramid\n const m = cells + 1\n const s = 1 << l\n const ia = bi * s, ja = bj * s, ib = Math.min(cells, ia + s), jb = Math.min(cells, ja + s)\n const h00 = heights[ja * m + ia]!, h10 = heights[ja * m + ib]!, h01 = heights[jb * m + ia]!, h11 = heights[jb * m + ib]!\n const sx = (h10 - h00 + h11 - h01) / 2 / (ib - ia), sz = (h01 - h00 + h11 - h10) / 2 / (jb - ja)\n let under = 0\n for (let j = ja; j <= jb; j++) for (let i = ia; i <= ib; i++) under = Math.min(under, heights[j * m + i]! - (h00 + sx * (i - ia) + sz * (j - ja)))\n level[at] = h00 + under\n level[at + 1] = sx\n level[at + 2] = sz\n return at\n}\n\nexport interface ReachTile {\n readonly heights: Float32Array\n readonly cells: number\n readonly x0: number\n readonly z0: number\n readonly cell: number\n readonly pyramid: LowPyramid\n readonly ring: GroundRing\n}\n\nexport interface Reach {\n /** The most the box rises over the ground of the tile's cells (0 when it is nowhere above), and over the ring's cells past its edges. */\n readonly tile: number\n readonly ring: number\n}\n\nconst corner4 = new Float64Array(4)\n/** A block whose bound is within this (m) of the most found is skipped: the heights are 32 bit floats, and a plane through them is that close to a plane under them. */\nconst PRUNE_SLACK = 1e-6\n// one box at a time: its planes (a, bx, bz each), the directions of its shadow's sides (x, z each) and its extent along each (low, high)\nconst planes = new Float64Array(9)\nconst dirs = new Float64Array(10)\nconst spans = new Float64Array(10)\nlet planeCount = 0\nlet dirCount = 0\n\n/** Whether the rectangle and the box's shadow are apart along one of its sides' directions. */\nconst apart = (xa: number, xb: number, za: number, zb: number): boolean => {\n for (let d = 0; d < dirCount; d += 2) {\n const dx = dirs[d]!, dz = dirs[d + 1]!\n const lo = (dx > 0 ? xa * dx : xb * dx) + (dz > 0 ? za * dz : zb * dz)\n const hi = (dx > 0 ? xb * dx : xa * dx) + (dz > 0 ? zb * dz : za * dz)\n if (hi < spans[d]! - 1e-9 || lo > spans[d + 1]! + 1e-9) return true\n }\n return false\n}\n\n/** The least, over the box's planes, of the most each rises over the four corner heights (`corner4`) of the rectangle. */\nconst over = (xa: number, xb: number, za: number, zb: number): number => {\n let best = Infinity\n for (let p = 0; p < planeCount; p += 3) {\n const a = planes[p]!, bx = planes[p + 1]!, bz = planes[p + 2]!\n const most = Math.max(a + bx * xa + bz * za - corner4[0]!, a + bx * xb + bz * za - corner4[1]!, a + bx * xa + bz * zb - corner4[2]!, a + bx * xb + bz * zb - corner4[3]!)\n if (most < best) best = most\n }\n return best\n}\n\n// the tile and box `search` walks (one at a time): the top's own extent in cells (from, to along x, then z), and the most found so far\nlet searchTile: ReachTile | null = null\nconst searchTop = new Int32Array(4)\nlet searchMost = 0\n\n/** The cell (`ia`, `ja`): its corners, and how far the box rises over them. */\nconst leaf = (ia: number, ja: number): void => {\n const { heights, cells, x0, z0, cell } = searchTile!\n const m = cells + 1\n const xa = x0 + ia * cell, za = z0 + ja * cell\n corner4[0] = heights[ja * m + ia]!\n corner4[1] = heights[ja * m + ia + 1]!\n corner4[2] = heights[(ja + 1) * m + ia]!\n corner4[3] = heights[(ja + 1) * m + ia + 1]!\n const e = over(xa, xa + cell, za, za + cell)\n if (e > searchMost) searchMost = e\n}\n\n/** The block (`bi`, `bj`) of level `l`, skipped when the box is apart from it or no higher over its low plane than the most found already, else its four. */\nconst search = (l: number, bi: number, bj: number): void => {\n const { cells, x0, z0, cell, pyramid } = searchTile!\n const s = 1 << l\n const ia = bi * s, ja = bj * s\n if (ia >= cells || ja >= cells) return\n const ib = Math.min(cells, ia + s), jb = Math.min(cells, ja + s)\n if (ia >= searchTop[0]! && ib <= searchTop[1]! && ja >= searchTop[2]! && jb <= searchTop[3]!) return\n const xa = x0 + ia * cell, xb = x0 + ib * cell, za = z0 + ja * cell, zb = z0 + jb * cell\n if (apart(xa, xb, za, zb)) return\n if (l === 0) return leaf(ia, ja)\n const level = pyramid.planes[l]!\n const at = planeUnder(pyramid, l, bi, bj)\n const h = level[at]!, sx = level[at + 1]!, sz = level[at + 2]!\n corner4[0] = h\n corner4[1] = h + sx * (ib - ia)\n corner4[2] = h + sz * (jb - ja)\n corner4[3] = h + sx * (ib - ia) + sz * (jb - ja)\n if (over(xa, xb, za, zb) <= searchMost + PRUNE_SLACK) return\n for (let dj = 0; dj < 2; dj++) for (let di = 0; di < 2; di++) search(l - 1, 2 * bi + di, 2 * bj + dj)\n}\n\nexport const reachOf = (box: ReachBox, t: ReachTile): Reach => {\n const { heights, cells, x0, z0, cell, pyramid, ring } = t\n const m = cells + 1\n // the planes over the box's columns, y <= a + bx x + bz z: one per axis, the face of it that looks up\n planeCount = 0\n for (let k = 0; k < 3; k++) {\n const a = box.axes[k]!\n if (Math.abs(a[1]!) < 1e-9) continue\n const bx = -a[0]! / a[1]!, bz = -a[2]! / a[1]!\n planes[planeCount++] = box.c[1]! + box.half[k]! / Math.abs(a[1]!) - bx * box.c[0]! - bz * box.c[2]!\n planes[planeCount++] = bx\n planes[planeCount++] = bz\n }\n // the box's shadow as a convex polygon: its extent along x, z and across each axis seen from above\n dirs[0] = 1\n dirs[1] = 0\n dirs[2] = 0\n dirs[3] = 1\n dirCount = 4\n for (const a of box.axes) {\n const l = Math.hypot(a[0]!, a[2]!)\n if (l < 1e-9) continue\n dirs[dirCount++] = -a[2]! / l\n dirs[dirCount++] = a[0]! / l\n }\n for (let d = 0; d < dirCount; d += 2) {\n const dx = dirs[d]!, dz = dirs[d + 1]!\n let r = 0\n for (let k = 0; k < 3; k++) r += box.half[k]! * Math.abs(box.axes[k]![0]! * dx + box.axes[k]![2]! * dz)\n const mid = box.c[0]! * dx + box.c[2]! * dz\n spans[d] = mid - r\n spans[d + 1] = mid + r\n }\n let inTile = 0\n // under the top's own extent, the top's plane over every corner (each cell's most is at a corner): the most found there skips most of the rest\n const n = box.axes[1]!, ax = box.axes[0]!, az = box.axes[2]!\n const tx = box.c[0]! + n[0]! * box.half[1]!, ty = box.c[1]! + n[1]! * box.half[1]!, tz = box.c[2]! + n[2]! * box.half[1]!\n const rx = box.half[0]! * Math.abs(ax[0]!) + box.half[2]! * Math.abs(az[0]!), rz = box.half[0]! * Math.abs(ax[2]!) + box.half[2]! * Math.abs(az[2]!)\n const ta = Math.max(0, Math.floor((tx - rx - x0) / cell)), tb = Math.min(cells, Math.ceil((tx + rx - x0) / cell))\n const sa = Math.max(0, Math.floor((tz - rz - z0) / cell)), sb = Math.min(cells, Math.ceil((tz + rz - z0) / cell))\n const bx = -n[0]! / n[1]!, bz = -n[2]! / n[1]!\n for (let j = sa; j <= sb; j++) {\n for (let i = ta; i <= tb; i++) {\n const e = ty + bx * (x0 + i * cell - tx) + bz * (z0 + j * cell - tz) - heights[j * m + i]!\n if (e > inTile) inTile = e\n }\n }\n // the box is its top slid down along -n: a point of it a slide s from the top at q stands s n_y under the top, over ground at most s |n_h| (the steepest) under q's.\n // Where the ground is nowhere steeper than 1 / (its top's slope), no point of the box is further over the ground than its top over its own extent (all in the tile)\n const ia = Math.floor((spans[0]! - x0) / cell), ib = Math.ceil((spans[1]! - x0) / cell)\n const ja = Math.floor((spans[2]! - z0) / cell), jb = Math.ceil((spans[3]! - z0) / cell)\n const within = ia >= 0 && ja >= 0 && ib <= cells && jb <= cells\n if (within && !steeperOver(pyramid, ia, ib, ja, jb, n[1]! / Math.max(1e-12, Math.hypot(n[0]!, n[2]!)))) return { tile: inTile, ring: 0 }\n searchTile = t\n searchTop[0] = ta\n searchTop[1] = tb\n searchTop[2] = sa\n searchTop[3] = sb\n searchMost = inTile\n // else every cell of its shadow, from the level whose blocks are as wide as the shadow's extent along x and z, over the (at most four) of them it covers\n const ua = Math.max(0, ia), ub = Math.min(cells, ib), va = Math.max(0, ja), vb = Math.min(cells, jb)\n if (ua < ub && va < vb) {\n let l = 0\n while (1 << l < Math.max(ub - ua, vb - va) && l < pyramid.sizes.length - 1) l++\n for (let bj = va >> l; bj <= (vb - 1) >> l; bj++) for (let bi = ua >> l; bi <= (ub - 1) >> l; bi++) search(l, bi, bj)\n }\n inTile = searchMost\n // the last tile (and the host's ground its ring holds) is not kept past the call (§8)\n searchTile = null\n // past the edges: the ring's cells the shadow's extent reaches\n let inRing = 0\n const r = ring.cells\n if (within) return { tile: inTile, ring: 0 }\n for (let j = Math.max(-r, ja); j < Math.min(cells + r, jb); j++) {\n const across = j >= 0 && j < cells\n for (let i = Math.max(-r, ia); i < Math.min(cells + r, ib); i++) {\n // over the tile, along the row: on to its far edge\n if (across && i >= 0 && i < cells) i = cells\n if (i >= Math.min(cells + r, ib)) break\n const xa = x0 + i * cell, za = z0 + j * cell\n if (apart(xa, xa + cell, za, za + cell)) continue\n ring.cell(i, j, corner4)\n const e = over(xa, xa + cell, za, za + cell)\n if (e > inRing) inRing = e\n }\n }\n return { tile: inTile, ring: inRing }\n}\n","import { coarseStep, underBoth } from './engine-ground-collision'\nimport { createGroundRing } from './engine-ground-ring'\nimport type { GroundSource } from './engine-ground-ring'\nimport { buildLowPyramid, reachOf } from './engine-ground-reach'\n\n/**\n * The solid under a height field. Jolt's height field is a surface: a body that ends up wholly below it (ground raised under a sleeping piece, a piece that\n * tunnelled) has nothing to push it out and falls for good. Under the surface of a tile there are blocks, from the lowest ground of the tile less `SOLID_DEPTH`\n * up to a top close under the surface and never above it (§12). A block is split until a plane through its corners is within `SOLID_RELIEF` of the surface or it is\n * `SOLID_MIN_CELLS` cells wide. A level block is a box topped at its lowest ground less `SOLID_MARGIN`; a sloped block is one box turned to its corner plane, its top that\n * plane over the block and a cell past it each way (turned boxes side by side lean apart under their tops: what is pushed out sideways meets the next one), lowered by the\n * most any point of it, top or leaning side, rises over the ground under it (`engine-ground-reach`) and `SOLID_MARGIN`. Where it reaches past the tile, the ground there is\n * the neighbour's (`engine-ground-ring`), read up to `SOLID_RING` out; a box that would lean further is made shallower. Under each turned box is its block's upright box\n * (topped at the block's lowest ground less `SOLID_MARGIN`): turned boxes side by side part under their tops, and what slips between them rests on it, its top no further\n * under the ground than the block's relief and its own size.\n * Every block is boxes: a sloped one used to be a prism (a convex hull each), and a crater tile's 400 hulls were most of the frame after the blast (T3.8ag).\n */\n\n/** How far (m) under the lowest corner of its tile the solid goes. */\nexport const SOLID_DEPTH = 0.5\n/** How far (m) under the surface a block's top may be before the block is split, unless it is already `SOLID_MIN_CELLS` cells wide. */\nconst SOLID_RELIEF = 0.005\nconst SOLID_MIN_CELLS = 3\n/**\n * A top is this far (m) under the lowest ground it stands for: 2 mm put the solid in the contacts of what rests on the surface and the bowl's seed 18 gained 4 cm. The engine\n * holds a height field's samples in 8 bit steps of each 4-sample block's range, up to half a step off (range / 510: 0.15 mm on a 0.75 slope at 2.5 cm, 0.3 mm at 5 cm), well\n * inside this margin.\n */\nexport const SOLID_MARGIN = 0.005\n/** The thinnest (m) a turned box is made; where that would lean past the ring, the block is split, or (at its smallest) left to its upright box. */\nconst SOLID_THINNEST = 0.05\n/** How much (m) more a block's box must be lowered for the ground past the tile than for its own before the block is split, so a fold at the seam lowers a narrow box only. */\nconst SEAM_SPLIT = 0.01\n/** Numbers per block in `SolidVolume.boxes`. */\nexport const SOLID_STRIDE = 10\n\nexport interface SolidVolume {\n /** The blocks: centre x, y, z, half x, y, z and turn x, y, z, w (`SOLID_STRIDE` numbers each); the box's own y is the normal of its top. */\n readonly boxes: readonly number[] | Float64Array\n /** The ground read past the tile's edges, x, z and height each (`engine-ground-ring`): the blocks are made again when one of these changes. */\n readonly ring: readonly number[] | Float64Array\n}\n\nexport const NO_SOLID: SolidVolume = { boxes: [], ring: [] }\n\n/** The unit vector along (x, y, z), into `out`. */\nconst unitInto = (out: Float64Array, x: number, y: number, z: number): Float64Array => {\n const l = Math.hypot(x, y, z)\n out[0] = x / l\n out[1] = y / l\n out[2] = z / l\n return out\n}\n\n// one block at a time: its corner plane's slopes, and the box the reach is asked about (filled in place, no arrays per block)\nconst slopes = new Float64Array(2)\nconst reachAxes = [new Float64Array(3), new Float64Array(3), new Float64Array(3)] as const\nconst reachBox = { c: new Float64Array(3), axes: [reachAxes[0], reachAxes[1], reachAxes[2]], half: new Float64Array(3) }\n\n/** The quaternion of the turn whose columns are the axes `a` (x), `b` (y) and `c` (z). */\nconst quatOfAxes = (a: ArrayLike<number>, b: ArrayLike<number>, c: ArrayLike<number>): [number, number, number, number] => {\n const m00 = a[0]!, m10 = a[1]!, m20 = a[2]!, m01 = b[0]!, m11 = b[1]!, m21 = b[2]!, m02 = c[0]!, m12 = c[1]!, m22 = c[2]!\n const trace = m00 + m11 + m22\n if (trace > 0) {\n const s = 0.5 / Math.sqrt(trace + 1)\n return [(m21 - m12) * s, (m02 - m20) * s, (m10 - m01) * s, 0.25 / s]\n }\n if (m00 > m11 && m00 > m22) {\n const s = 2 * Math.sqrt(1 + m00 - m11 - m22)\n return [0.25 * s, (m01 + m10) / s, (m02 + m20) / s, (m21 - m12) / s]\n }\n if (m11 > m22) {\n const s = 2 * Math.sqrt(1 + m11 - m00 - m22)\n return [(m01 + m10) / s, 0.25 * s, (m12 + m21) / s, (m02 - m20) / s]\n }\n const s = 2 * Math.sqrt(1 + m22 - m00 - m11)\n return [(m02 + m20) / s, (m12 + m21) / s, 0.25 * s, (m10 - m01) / s]\n}\n\n/** How thick (m) a box whose bottom moves by `lean` per metre of thickness may be and stay within `lo`..`hi`, its top spanning `low`..`high` (no thickness when the top does not fit). */\nconst thickWithin = (lean: number, low: number, high: number, lo: number, hi: number): number => {\n if (low < lo || high > hi) return -Infinity\n return lean > 1e-12 ? (hi - high) / lean : lean < -1e-12 ? (low - lo) / -lean : Infinity\n}\n\n/**\n * The blocks under a tile of `cells` cells of side `cell` from (`x0`, `z0`), over its `read` heights (`(cells + 1)^2`, x fastest) and the engine's coarser collision field of\n * them (`step`: every how many corners it is), and the ground around it (`groundAt`, read only past the tile's edges, up to `SOLID_RING`, and its collision field there too).\n */\nexport const buildSolidVolume = (read: Float32Array, cells: number, x0: number, z0: number, cell: number, groundAt: GroundSource, step = 1): SolidVolume => {\n // under the drawn ground and the engine's collision field (every `step`-th corner, `engine-ground-collision`) both, whichever is lower at each corner\n const heights = underBoth(read, cells, step)\n const m = cells + 1\n let low = Infinity\n for (const h of heights) low = Math.min(low, h)\n const bottom = low - SOLID_DEPTH\n const boxes: number[] = []\n // past the edge, under the neighbour's coarse field too, whichever it collides with\n const ring = createGroundRing(heights, cells, x0, z0, cell, groundAt, coarseStep(cells, cell))\n const reachTile = { heights, cells, x0, z0, cell, pyramid: buildLowPyramid(heights, cells, cell), ring }\n const outer = ring.cells * cell\n const loX = x0 - outer, hiX = x0 + cells * cell + outer, loZ = z0 - outer, hiZ = z0 + cells * cell + outer\n const at = (i: number, j: number): number => heights[j * m + i]!\n /** The slopes (per cell) of the plane through the block's corners, into `slopes` (x then z). */\n const slopesOf = (i0: number, j0: number, i1: number, j1: number): void => {\n slopes[0] = (at(i1, j0) - at(i0, j0) + at(i1, j1) - at(i0, j1)) / 2 / (i1 - i0)\n slopes[1] = (at(i0, j1) - at(i0, j0) + at(i1, j1) - at(i1, j0)) / 2 / (j1 - j0)\n }\n\n /** How far the surface rises above the plane through the block's corners lowered to its lowest sample: the block is split while it is more. */\n const planeGap = (i0: number, j0: number, i1: number, j1: number): number => {\n slopesOf(i0, j0, i1, j1)\n const sx = slopes[0]!, sz = slopes[1]!\n let least = Infinity\n let most = -Infinity\n for (let j = j0; j <= j1; j++) {\n for (let i = i0; i <= i1; i++) {\n const above = at(i, j) - (at(i0, j0) + sx * (i - i0) + sz * (j - j0))\n if (above < least) least = above\n if (above > most) most = above\n }\n }\n return most - least\n }\n\n /** A level block: an upright box topped at its lowest ground less `SOLID_MARGIN`. */\n const level = (i0: number, j0: number, i1: number, j1: number, least: number): void => {\n const top = least - SOLID_MARGIN\n boxes.push(x0 + ((i0 + i1) / 2) * cell, (top + bottom) / 2, z0 + ((j0 + j1) / 2) * cell, ((i1 - i0) * cell) / 2, (top - bottom) / 2, ((j1 - j0) * cell) / 2, 0, 0, 0, 1)\n }\n\n /**\n * A sloped block: one box turned to the plane through its corners, its top the rectangle on that plane over the block and a cell past it each way, down to under the\n * solid's bottom, lowered by the most it rises over the ground anywhere (`reachOf`) and `SOLID_MARGIN`. A box that would lean past the ring is made as deep as stays in\n * it (the block's upright box is under it); a box lowered by more than the block's relief is the upright box alone. False when the block should be split instead: its box would not\n * fit the ring, or the ground past the tile lowers it much more than its own.\n */\n const sloped = (i0: number, j0: number, i1: number, j1: number, least: number, most: number): boolean => {\n const span = Math.max(i1 - i0, j1 - j0)\n slopesOf(i0, j0, i1, j1)\n const gx = slopes[0]! / cell\n const gz = slopes[1]! / cell\n const ox = x0 + i0 * cell\n const oz = z0 + j0 * cell\n const base = at(i0, j0)\n // the box's axes, in the scratch the reach reads them from: n the normal of its top, ax along x up the slope, az across both\n const n = unitInto(reachAxes[1]!, -gx, 1, -gz)\n const ax = unitInto(reachAxes[0]!, 1, gx, 0)\n const az = reachAxes[2]!\n az[0] = ax[1]! * n[2]! - ax[2]! * n[1]!\n az[1] = ax[2]! * n[0]! - ax[0]! * n[2]!\n az[2] = ax[0]! * n[1]! - ax[1]! * n[0]!\n const xa = ox, xb = x0 + i1 * cell, za = oz, zb = z0 + j1 * cell\n const cx = (xa + xb) / 2, cz = (za + zb) / 2, cy = base + gx * (cx - ox) + gz * (cz - oz)\n let hx = 0\n let hz = 0\n for (let a = 0; a < 2; a++) {\n const x = a === 0 ? xa : xb\n for (let b = 0; b < 2; b++) {\n const z = b === 0 ? za : zb\n const d0 = x - cx, d1 = base + gx * (x - ox) + gz * (z - oz) - cy, d2 = z - cz\n hx = Math.max(hx, Math.abs(d0 * ax[0]! + d1 * ax[1]! + d2 * ax[2]!))\n hz = Math.max(hz, Math.abs(d0 * az[0]! + d1 * az[1]! + d2 * az[2]!))\n }\n }\n hx += cell\n hz += cell\n let minX = Infinity, maxX = -Infinity, minZ = Infinity, maxZ = -Infinity, highest = -Infinity\n for (let a = 0; a < 2; a++) {\n const su = a === 0 ? -1 : 1\n for (let b = 0; b < 2; b++) {\n const sw = b === 0 ? -1 : 1\n const qx = cx + su * hx * ax[0] + sw * hz * az[0]\n const qz = cz + su * hx * ax[2] + sw * hz * az[2]\n minX = Math.min(minX, qx)\n maxX = Math.max(maxX, qx)\n minZ = Math.min(minZ, qz)\n maxZ = Math.max(maxZ, qz)\n highest = Math.max(highest, cy + su * hx * ax[1] + sw * hz * az[1])\n }\n }\n // deep enough that its bottom face is under the solid's bottom everywhere (a box made only as deep as its block's upright box let what it pushed out the bottom through:\n // 17 of the 48 boxes of the push-up sweep fell, as with a730b5450's slab), unless its bottom would lean (uphill: by -n per metre of thickness) past the ring\n const deep = (highest - bottom) / n[1]\n const fits = Math.min(thickWithin(-n[0], minX, maxX, loX, hiX), thickWithin(-n[2], minZ, maxZ, loZ, hiZ))\n const thick = Math.max(SOLID_THINNEST, Math.min(deep, fits))\n if (fits < thick) {\n if (span > SOLID_MIN_CELLS) return false\n level(i0, j0, i1, j1, least)\n return true\n }\n const hy = thick / 2\n const centre = reachBox.c\n centre[0] = cx - n[0]! * hy\n centre[1] = cy - n[1]! * hy\n centre[2] = cz - n[2]! * hy\n reachBox.half[0] = hx\n reachBox.half[1] = hy\n reachBox.half[2] = hz\n const reach = reachOf(reachBox, reachTile)\n if (reach.ring > reach.tile + SEAM_SPLIT && span > SOLID_MIN_CELLS) return false\n const drop = SOLID_MARGIN + Math.max(reach.tile, reach.ring)\n // lowered further than the block's own relief, its top would be further under the ground than the upright box's\n if (drop - SOLID_MARGIN >= most - least) {\n level(i0, j0, i1, j1, least)\n return true\n }\n // and under it the block's upright box: what slips between two turned boxes (they part under their tops; a cell's overlap closes only so deep) rests on it, no\n // further under the ground than the block's relief\n level(i0, j0, i1, j1, least)\n const q = quatOfAxes(ax, n, az)\n boxes.push(centre[0]!, centre[1]! - drop, centre[2]!, hx, hy, hz, q[0], q[1], q[2], q[3])\n return true\n }\n\n const fill = (i0: number, j0: number, i1: number, j1: number): void => {\n let least = Infinity\n let most = -Infinity\n for (let j = j0; j <= j1; j++) {\n for (let i = i0; i <= i1; i++) {\n const h = at(i, j)\n if (h < least) least = h\n if (h > most) most = h\n }\n }\n if (most - least <= SOLID_RELIEF) return level(i0, j0, i1, j1, least)\n const span = Math.max(i1 - i0, j1 - j0)\n if ((planeGap(i0, j0, i1, j1) > SOLID_RELIEF && span > SOLID_MIN_CELLS) || !sloped(i0, j0, i1, j1, least, most)) {\n // in halves (a side under two cells stays whole), x's halves first\n const im = i1 - i0 < 2 ? i1 : (i0 + i1) >> 1\n const jm = j1 - j0 < 2 ? j1 : (j0 + j1) >> 1\n for (let a = i0; a < i1; a = im) {\n const b = a === i0 ? im : i1\n for (let d = j0; d < j1; d = jm) {\n const e = d === j0 ? jm : j1\n fill(a, d, b, e)\n if (e === j1) break\n }\n if (b === i1) break\n }\n }\n }\n fill(0, 0, cells, cells)\n return { boxes, ring: ring.read }\n}\n\n/** The same blocks. */\nexport const sameSolid = (a: SolidVolume, b: SolidVolume): boolean => same(a.boxes, b.boxes)\n\n/** The same numbers, in order (plain or typed arrays alike). */\nexport const sameNumbers = (a: ArrayLike<number>, b: ArrayLike<number>): boolean => {\n if (a.length !== b.length) return false\n for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false\n return true\n}\n\nconst same = sameNumbers\n","import type { HeightPatch } from '@adatechnology/game-terrain'\n\nimport { NO_SOLID, buildSolidVolume } from './engine-ground-solid'\nimport type { SolidVolume } from './engine-ground-solid'\nimport { collisionFieldOf } from './engine-ground-collision'\nimport { holdsStep } from './engine-ground-step'\n\n/**\n * The ground a physics engine stands the pieces on, one tile of `groundAt` at a time: a height field over the cell corners for what is smooth, and solid boxes\n * for the cells a hard step runs through (a crater's rim, a terraced slope) and the cells around them. A box's top is its cell's centre height and its\n * sides are vertical, so a step keeps its edge (within half a cell of where it is) instead of a ramp one cell wide; under the boxes the height field is lowered so\n * it does not ramp up through them. A level tile is one slab, solid below.\n *\n * Why not triangles: the step-keeping triangle mesh this replaces was one-sided (a thin piece pressed half through a triangle fell through for good) and had to be\n * made again, as a new body, for every change, which threw away the engine's contact cache. A height field of the same tile is made in about 0.3 ms and can be\n * swapped on the same body (`EnginePieces`), so the pieces on it keep their contacts.\n *\n * The tile is read at `GROUND_CELL`; the engine collides with every second corner of it, a 5 cm field (`engine-ground-collision`, owner decision 2026-11-17), and the solid\n * under it stays under both.\n */\n\n/** Cells of a tile (m), as Rapier's spike measured good enough for a 4 cm plate. */\nexport const GROUND_CELL = 0.025\n/** How far (m) under the lowest ground around them the step boxes go, and how far the height field drops under them. */\nconst BOX_DEPTH = 0.05\nconst UNDER_BOX = 0.01\n\nexport interface GroundTile {\n /** Corner heights, `(cells + 1)^2`, x fastest: `heights[iz * (cells + 1) + ix]`. Empty when the tile is level. */\n readonly heights: Float32Array\n readonly cells: number\n /** The height field the engine collides with (`engine-ground-collision`): every `cells / collisionCells`-th corner of `heights`, `(collisionCells + 1)^2`. Empty when level. */\n readonly collision: Float32Array\n readonly collisionCells: number\n /** The step boxes: centre x, y, z and half x, y, z, six numbers each (a typed array when the tile came from a worker, `engine-ground-job`). */\n readonly boxes: readonly number[] | Float64Array\n /** The solid under the height field (`engine-ground-solid`); none when the tile is level (a slab is solid already). */\n readonly solid: SolidVolume\n /** The height of a level tile (every sample equal), or null. */\n readonly level: number | null\n /** Every sample read, to tell whether the ground changed since; null for a tile proved level from the terrain's own bounds (`flatTile`), whose samples were never read. */\n readonly samples: Float64Array | null\n /** The terrain's vertices the tile was made from (`readGroundPatch`; its samples are then null): what tells whether the ground changed since. */\n readonly patch?: HeightPatch\n}\n\nconst NO_HEIGHTS = new Float32Array(0)\n/** One cell's nine samples, for `holdsStep`. */\nconst cellSamples = new Float64Array(9)\n\n/** The tile of a level `size` at `level`, laid without a sample read: the caller has proved, from the ground's own data, that every sample there is `level` (to 1e-9, as `shapeGround` calls level). */\nexport const flatTile = (level: number, size: number): GroundTile => ({ heights: NO_HEIGHTS, cells: Math.round(size / GROUND_CELL), collision: NO_HEIGHTS, collisionCells: 0, boxes: [], solid: NO_SOLID, level, samples: null })\n\n/** A rectangle of the ground, world x and z. */\nexport interface GroundRect {\n readonly minX: number\n readonly maxX: number\n readonly minZ: number\n readonly maxZ: number\n}\n\n/**\n * The four series of samples of a tile, one after the other in `samples`: the corners, the cells' centres, the middles of the edges along x and those along z.\n * `ox` and `oz` are where the series sits in a cell (0 or half), `width` and `rows` how many samples it has along x and along z.\n */\nconst seriesOf = (n: number): ReadonlyArray<{ offset: number; width: number; rows: number; ox: number; oz: number }> => {\n const m = n + 1\n return [\n { offset: 0, width: m, rows: m, ox: 0, oz: 0 },\n { offset: m * m, width: n, rows: n, ox: 0.5, oz: 0.5 },\n { offset: m * m + n * n, width: n, rows: m, ox: 0.5, oz: 0 },\n { offset: m * m + n * n + n * m, width: m, rows: n, ox: 0, oz: 0.5 },\n ]\n}\n\n/** The `samples` array of a tile of `n` cells. */\nexport const sampleCount = (n: number): number => (n + 1) * (n + 1) + n * n + 2 * n * (n + 1)\n\n/**\n * The ground over a lattice in one pass: the height at (`xs[i]`, `zs[j]`) into `out[j * xs.length + i]`, to the bit what the tile's `groundAt` answers at each point\n * (`Terrain.heightGrid` is one). A tile reads its 26 000 samples through it instead of a call each.\n */\nexport type GroundGrid = (xs: ArrayLike<number>, zs: ArrayLike<number>, out: Float64Array) => void\n\n// the points a grid read asks for and what it answers, kept between reads (one at a time) so a read does not make them again\nlet seriesX = new Float64Array(0)\nlet seriesZ = new Float64Array(0)\nlet seriesHeights = new Float64Array(0)\n\n/**\n * Reads the ground of the tile at (x0, z0) into `samples`: every sample, or only those a rectangle reaches (a sample a cell outside it is read too, so what the\n * rectangle's edge touches is not left old). True when a sample read differs from the one held. A crater in a corner of a tile asks `groundAt` for the corner.\n * With a `grid` each series is read in one pass over its own points, each the one `groundAt` would be asked for (`x0 + (i + ox) * c`), so the same heights.\n * Not reentrant: the points are module scratch, so neither reader may read a tile in turn.\n */\nexport const readGround = (groundAt: (x: number, z: number) => number, samples: Float64Array, x0: number, z0: number, size: number, rect?: GroundRect, grid?: GroundGrid): boolean => {\n const n = Math.round(size / GROUND_CELL)\n const c = size / n\n let changed = false\n for (const { offset, width, rows, ox, oz } of seriesOf(n)) {\n const i0 = rect ? Math.max(0, Math.floor((rect.minX - x0) / c - ox)) : 0\n const i1 = rect ? Math.min(width - 1, Math.ceil((rect.maxX - x0) / c - ox)) : width - 1\n const j0 = rect ? Math.max(0, Math.floor((rect.minZ - z0) / c - oz)) : 0\n const j1 = rect ? Math.min(rows - 1, Math.ceil((rect.maxZ - z0) / c - oz)) : rows - 1\n if (i0 > i1 || j0 > j1) continue\n if (!grid) {\n for (let j = j0; j <= j1; j++) {\n for (let i = i0; i <= i1; i++) {\n const h = groundAt(x0 + (i + ox) * c, z0 + (j + oz) * c)\n if (samples[offset + j * width + i] !== h) changed = true\n samples[offset + j * width + i] = h\n }\n }\n continue\n }\n const across = i1 - i0 + 1\n const along = j1 - j0 + 1\n if (seriesX.length < across) seriesX = new Float64Array(across)\n if (seriesZ.length < along) seriesZ = new Float64Array(along)\n if (seriesHeights.length < across * along) seriesHeights = new Float64Array(across * along)\n for (let i = 0; i < across; i++) seriesX[i] = x0 + (i0 + i + ox) * c\n for (let j = 0; j < along; j++) seriesZ[j] = z0 + (j0 + j + oz) * c\n grid(seriesX.subarray(0, across), seriesZ.subarray(0, along), seriesHeights)\n for (let j = 0; j < along; j++) {\n const from = j * across\n const to = offset + (j0 + j) * width + i0\n if (!changed) {\n for (let i = 0; i < across; i++) {\n if (samples[to + i] !== seriesHeights[from + i]) {\n changed = true\n break\n }\n }\n }\n samples.set(seriesHeights.subarray(from, from + across), to)\n }\n }\n return changed\n}\n\nexport const buildGroundTile = (groundAt: (x: number, z: number) => number, x0: number, z0: number, size: number, withSolid = true, grid?: GroundGrid): GroundTile => {\n const samples = new Float64Array(sampleCount(Math.round(size / GROUND_CELL)))\n readGround(groundAt, samples, x0, z0, size, undefined, grid)\n return shapeGround(samples, x0, z0, size, withSolid ? groundAt : null)\n}\n\n/**\n * The tile the samples make: level, or its height field, step boxes and (given the ground, which it reads past the tile's edges; else `NO_SOLID`, for a caller that may\n * not need it) the solid under it. Pure of the samples (and that ground), so a tile made from samples patched in place is the one made from all of them read again, but\n * for its collision field near the bound, which keeps the coarse one it had (`wasCoarse`, `collisionFieldOf`).\n */\nexport const shapeGround = (samples: Float64Array, x0: number, z0: number, size: number, solidGround: ((x: number, z: number) => number) | null, wasCoarse = false): GroundTile => {\n const n = Math.round(size / GROUND_CELL)\n const c = size / n\n const m = n + 1\n const [cornerSeries, centreSeries, midXSeries, midZSeries] = seriesOf(n)\n const corners = samples.subarray(cornerSeries!.offset, centreSeries!.offset)\n const centres = samples.subarray(centreSeries!.offset, midXSeries!.offset)\n const midX = samples.subarray(midXSeries!.offset, midZSeries!.offset)\n const midZ = samples.subarray(midZSeries!.offset)\n let low = Infinity\n let high = -Infinity\n for (const h of samples) {\n low = Math.min(low, h)\n high = Math.max(high, h)\n }\n if (high - low < 1e-9) return { heights: new Float32Array(0), cells: n, collision: NO_HEIGHTS, collisionCells: 0, boxes: [], solid: NO_SOLID, level: high, samples }\n const corner = (i: number, j: number): number => corners[j * m + i]\n // a cell whose centre or an edge's middle leaves its corners holds a step; it and the cells around it become boxes\n const mask = new Uint8Array(n * n)\n for (let j = 0; j < n; j++) {\n for (let i = 0; i < n; i++) {\n cellSamples[0] = corner(i, j)\n cellSamples[1] = corner(i + 1, j)\n cellSamples[2] = corner(i, j + 1)\n cellSamples[3] = corner(i + 1, j + 1)\n cellSamples[4] = centres[j * n + i]\n cellSamples[5] = midX[j * n + i]\n cellSamples[6] = midX[(j + 1) * n + i]\n cellSamples[7] = midZ[j * m + i]\n cellSamples[8] = midZ[j * m + i + 1]\n if (!holdsStep(cellSamples)) continue\n for (let dj = -1; dj <= 1; dj++) for (let di = -1; di <= 1; di++) if (i + di >= 0 && j + dj >= 0 && i + di < n && j + dj < n) mask[(j + dj) * n + i + di] = 1\n }\n }\n const heights = new Float32Array(m * m)\n for (let j = 0; j <= n; j++) {\n for (let i = 0; i <= n; i++) {\n // a corner whose four cells are all boxes goes under the lowest of them\n let inside = true\n let least = corner(i, j)\n for (let dj = -1; dj <= 0 && inside; dj++) for (let di = -1; di <= 0; di++) {\n const ii = i + di, jj = j + dj\n if (ii < 0 || jj < 0 || ii >= n || jj >= n || !mask[jj * n + ii]) {\n inside = false\n break\n }\n least = Math.min(least, centres[jj * n + ii], corner(ii, jj), corner(ii + 1, jj), corner(ii, jj + 1), corner(ii + 1, jj + 1))\n }\n heights[j * m + i] = inside ? least - UNDER_BOX : corner(i, j)\n }\n }\n // the boxes: runs along x of masked cells at one height, down to under the lowest ground around them\n const boxes: number[] = []\n for (let j = 0; j < n; j++) {\n let i = 0\n while (i < n) {\n if (!mask[j * n + i]) {\n i++\n continue\n }\n const top = centres[j * n + i]\n let end = i + 1\n while (end < n && mask[j * n + end] && Math.abs(centres[j * n + end] - top) < 0.001) end++\n let bottom = top\n for (let k = Math.max(0, i - 1); k <= Math.min(n, end + 1); k++) for (let jj = Math.max(0, j - 1); jj <= Math.min(n, j + 2); jj++) bottom = Math.min(bottom, corner(k, jj))\n bottom -= BOX_DEPTH\n boxes.push(x0 + ((i + end) / 2) * c, (top + bottom) / 2, z0 + (j + 0.5) * c, ((end - i) * c) / 2, (top - bottom) / 2, c / 2)\n i = end\n }\n }\n const { step, field } = collisionFieldOf(heights, n, c, boxes.length > 0, wasCoarse)\n return { heights, cells: n, collision: field, collisionCells: n / step, boxes, solid: solidGround ? buildSolidVolume(heights, n, x0, z0, c, solidGround, step) : NO_SOLID, level: null, samples }\n}\n","import { fitOrientedBox, hugs } from '@adatechnology/game-shapes'\nimport type { OrientedBox } from '@adatechnology/game-shapes'\n\nimport type { StaticSolid } from './engine-statics'\n\n/** A box fits a drawn part when each of its eight corners has a vertex within this (m): a box drawn is a box held, a cylinder or a chamfered post is not. */\nconst FIT = 0.01\n/** A box holds a part only when the part's own triangles lie in each of its faces and cover at least this share of the face (a raised panel leaves its edge short, a frame leaves most of it open): a door frame (two posts and a lintel) has a box's eight corners and none of its faces. */\nconst FILL = 0.5\n/** The thinnest half (m) a drawn plane (a sheet with no thickness) is held by. */\nconst MIN_HALF = 0.005\n/** A part whose every side is under this (m) is collapsed to a point (hidden by its host): nothing is drawn there. */\nconst COLLAPSED = 0.002\n/** A face of a box under this area (m²) is a plane's edge: it has nothing to cover. */\nconst MIN_FACE = 1e-6\n\ntype Points = ArrayLike<number>\n\n/**\n * One fixed drawn part to measure (`measureStaticPart`): plain arrays, so it crosses to a worker (`destruction.static-colliders`). The main thread reads the vertices,\n * the triangles and the mesh's world matrix (with three's own `decompose` of it); the measuring is here.\n */\nexport interface StaticPartJob {\n /** The part's vertices in the mesh's frame, three numbers each, with what another drawing collapses there already collapsed. */\n readonly points: Float64Array\n /** The mesh's world matrix (16 numbers, column major). */\n readonly matrix: Float64Array\n /** The world matrix decomposed (three's `Matrix4.decompose`): position, quaternion (x, y, z, w) and scale. */\n readonly position: readonly [number, number, number]\n readonly quaternion: readonly [number, number, number, number]\n readonly scale: readonly [number, number, number]\n /** The triangles of the part as vertex numbers of the host (three each), `from` its first vertex. */\n readonly found: Uint32Array\n readonly from: number\n}\n\nconst IDENTITY = [1, 0, 0, 0, 1, 0, 0, 0, 1]\n\n/** The axes (three rows of 3) of a box turned by the quaternion. */\nconst axesOfQuat = (x: number, y: number, z: number, w: number): number[] => [\n 1 - 2 * (y * y + z * z), 2 * (x * y + z * w), 2 * (x * z - y * w),\n 2 * (x * y - z * w), 1 - 2 * (x * x + z * z), 2 * (y * z + x * w),\n 2 * (x * z + y * w), 2 * (y * z - x * w), 1 - 2 * (x * x + y * y),\n]\n\n/** The point turned by the unit quaternion, in the very operations of three's `Vector3.applyQuaternion` (r160), so the numbers are the same bits. */\nconst turn = (vx: number, vy: number, vz: number, q: readonly [number, number, number, number]): [number, number, number] => {\n const [qx, qy, qz, qw] = q\n const tx = 2 * (qy * vz - qz * vy)\n const ty = 2 * (qz * vx - qx * vz)\n const tz = 2 * (qx * vy - qy * vx)\n return [vx + qw * tx + qy * tz - qz * ty, vy + qw * ty + qz * tx - qx * tz, vz + qw * tz + qx * ty - qy * tx]\n}\n\n/**\n * What a fixed drawn part collides as, in world space, for an engine: one box turned as drawn where a box fits it (every corner has a vertex within `FIT` and its\n * triangles cover its faces), else the box turned to fit the world vertices where that one fits, else the triangles as drawn (`mesh`, static only). A part collapsed to\n * a point is nothing (`CLAUDE.md` §12). A pure function of the job: the worker and the main thread give the same bits (`staticCollidersKind`).\n */\nexport function measureStaticPart(job: StaticPartJob): StaticSolid[] {\n const { points, matrix, position: pos, quaternion: quat, scale, found, from } = job\n const low = [Infinity, Infinity, Infinity]\n const high = [-Infinity, -Infinity, -Infinity]\n for (let i = 0; i < points.length; i += 3) {\n for (let k = 0; k < 3; k++) {\n const v = points[i + k]\n if (v < low[k]) low[k] = v\n if (v > high[k]) high[k] = v\n }\n }\n const size = [high[0] - low[0], high[1] - low[1], high[2] - low[2]]\n const s = [Math.abs(scale[0]), Math.abs(scale[1]), Math.abs(scale[2])]\n if (Math.max(size[0] * s[0], size[1] * s[1], size[2] * s[2]) < COLLAPSED) return []\n const centre = [(low[0] + high[0]) / 2, (low[1] + high[1]) / 2, (low[2] + high[2]) / 2]\n const half = [size[0] / 2, size[1] / 2, size[2] / 2]\n // the box of the geometry in its own frame, turned by the mesh: the drawn box of a wall, a table top, a beam\n const straight = { center: centre, half, axes: IDENTITY, tolerance: [FIT / s[0], FIT / s[1], FIT / s[2]] }\n if (hugs(points, straight) && fillsFaces(points, found, from, straight)) {\n const [cx, cy, cz] = turn(centre[0] * scale[0], centre[1] * scale[1], centre[2] * scale[2], quat)\n return [{ center: [cx + pos[0], cy + pos[1], cz + pos[2]], half: [Math.max(MIN_HALF, half[0] * s[0]), Math.max(MIN_HALF, half[1] * s[1]), Math.max(MIN_HALF, half[2] * s[2])], rotation: [quat[0], quat[1], quat[2], quat[3]] }]\n }\n const world = new Float64Array(points.length)\n const e = matrix\n for (let i = 0; i < points.length; i += 3) {\n const x = points[i], y = points[i + 1], z = points[i + 2]\n world[i] = e[0] * x + e[4] * y + e[8] * z + e[12]\n world[i + 1] = e[1] * x + e[5] * y + e[9] * z + e[13]\n world[i + 2] = e[2] * x + e[6] * y + e[10] * z + e[14]\n }\n const turned = fitOrientedBox(world as unknown as number[])\n if (turned && fitsTurned(world, turned) && fillsFaces(world, found, from, turnedBox(turned))) return [turned]\n return [trimeshOf(world, from, found)]\n}\n\n/** The buffers of a measured part to transfer back (the triangles of a trimesh). */\nexport const staticSolidsTransfer = (solids: readonly StaticSolid[]): ArrayBuffer[] => {\n const out: ArrayBuffer[] = []\n for (const solid of solids) if (solid.mesh) out.push(solid.mesh.vertices.buffer as ArrayBuffer, solid.mesh.indices.buffer as ArrayBuffer)\n return out\n}\n\ntype FitBox = { readonly center: readonly number[]; readonly half: readonly number[]; readonly axes: readonly number[]; readonly tolerance: readonly number[] }\n\nconst turnedBox = (box: OrientedBox): FitBox => ({ center: box.center, half: box.half, axes: axesOfQuat(box.rotation[0], box.rotation[1], box.rotation[2], box.rotation[3]), tolerance: [FIT, FIT, FIT] })\n\nconst fitsTurned = (world: Points, box: OrientedBox): boolean => hugs(world, turnedBox(box))\n\n/** The area of the triangle a, b, c (box frame, three numbers each). */\nconst areaOf = (a: ArrayLike<number>, b: ArrayLike<number>, c: ArrayLike<number>): number => {\n const ux = b[0] - a[0], uy = b[1] - a[1], uz = b[2] - a[2]\n const vx = c[0] - a[0], vy = c[1] - a[1], vz = c[2] - a[2]\n return Math.hypot(uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx) / 2\n}\n\n/** Whether the part's triangles (`found`: vertex numbers of the host, `from` the first of the part) cover each face of the box that has an area: what a box that fits holds is the part, not the air in it. */\nconst fillsFaces = (points: Points, found: ArrayLike<number>, from: number, box: FitBox): boolean => {\n if (found.length === 0) return true\n const covered = [0, 0, 0, 0, 0, 0]\n const frame = [new Float64Array(3), new Float64Array(3), new Float64Array(3)]\n const a = box.axes\n for (let i = 0; i + 2 < found.length; i += 3) {\n for (let v = 0; v < 3; v++) {\n const at = (found[i + v] - from) * 3\n const dx = points[at] - box.center[0], dy = points[at + 1] - box.center[1], dz = points[at + 2] - box.center[2]\n for (let k = 0; k < 3; k++) frame[v][k] = dx * a[k * 3] + dy * a[k * 3 + 1] + dz * a[k * 3 + 2]\n }\n let area = -1\n for (let k = 0; k < 3; k++) for (let side = 0; side < 2; side++) {\n const face = side ? box.half[k] : -box.half[k]\n if (Math.abs(frame[0][k] - face) > box.tolerance[k] || Math.abs(frame[1][k] - face) > box.tolerance[k] || Math.abs(frame[2][k] - face) > box.tolerance[k]) continue\n if (area < 0) area = areaOf(frame[0], frame[1], frame[2])\n covered[k * 2 + side] += area\n }\n }\n for (let k = 0; k < 3; k++) {\n const area = 4 * box.half[(k + 1) % 3] * box.half[(k + 2) % 3]\n if (area < MIN_FACE) continue\n if (covered[k * 2] < area * FILL || covered[k * 2 + 1] < area * FILL) return false\n }\n return true\n}\n\n/** The triangles of the part in world space (its vertices and the triangles of the geometry that start in its range), with the box around them as the box of the solid. */\nconst trimeshOf = (world: Float64Array, from: number, found: ArrayLike<number>): StaticSolid => {\n const indices = new Uint32Array(found.length)\n for (let i = 0; i < found.length; i++) indices[i] = found[i] - from\n const lo = [Infinity, Infinity, Infinity]\n const hi = [-Infinity, -Infinity, -Infinity]\n for (let i = 0; i < world.length; i += 3) {\n for (let k = 0; k < 3; k++) {\n lo[k] = Math.min(lo[k], world[i + k])\n hi[k] = Math.max(hi[k], world[i + k])\n }\n }\n return {\n center: [(lo[0] + hi[0]) / 2, (lo[1] + hi[1]) / 2, (lo[2] + hi[2]) / 2],\n half: [Math.max(MIN_HALF, (hi[0] - lo[0]) / 2), Math.max(MIN_HALF, (hi[1] - lo[1]) / 2), Math.max(MIN_HALF, (hi[2] - lo[2]) / 2)],\n rotation: [0, 0, 0, 1],\n mesh: { vertices: new Float32Array(world), indices },\n }\n}\n"],"mappings":";AAAA,SAAS,sBAAsB,sBAAsB;;;ACArD,SAAS,gBAAgB,uBAAuB;;;ACOzC,IAAM,wBAAwB;AAG9B,IAAM,sBAAsB;AAK5B,IAAM,kBAAkB;AAE/B,IAAM,eAAe;AAGd,IAAM,aAAa,CAAC,OAAe,aAA6B;AACrE,QAAM,IAAI,KAAK,IAAI,GAAG,KAAK,MAAM,wBAAwB,QAAQ,CAAC;AAClE,SAAO,QAAQ,MAAM,IAAI,IAAI;AAC/B;AAcO,IAAM,mBAAmB,CAAC,SAAuB,OAAe,UAAkB,UAAmB,YAAY,UAA0B;AAChJ,QAAM,IAAI,WAAW,OAAO,QAAQ;AACpC,QAAM,OAAO,EAAE,MAAM,GAAG,OAAO,QAAQ;AACvC,MAAI,MAAM,KAAK,YAAY,QAAQ,WAAW,EAAG,QAAO;AACxD,QAAM,IAAI,QAAQ;AAClB,QAAM,MAAM,CAAC,GAAW,MAAsB,QAAQ,IAAI,IAAI,CAAC;AAC/D,MAAIA,OAAM;AACV,WAAS,IAAI,GAAG,KAAK,OAAO,KAAK;AAC/B,aAAS,IAAI,GAAG,KAAK,OAAO,KAAK;AAC/B,oBAAc,KAAK,GAAG,GAAG,CAAC;AAC1B,YAAM,IAAI,QAAQ,IAA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/engine-ground-collision.ts","../src/engine-ground-step.ts","../src/engine-ground-ring.ts","../src/engine-ground-reach.ts","../src/engine-ground-solid.ts","../src/engine-ground.ts","../src/static-part-job.ts","../src/built-solids.ts"],"sourcesContent":["import { WORKER_KIND_DEFAULTS, WORKER_KIND_ID } from '@adatechnology/game-contracts'\nimport type { TaskKind } from '@adatechnology/game-contracts'\n\nimport { computeGroundTile, jobTransferOf, transferOf } from './engine-ground-job'\nimport type { GroundTileJob, GroundTileResult } from './engine-ground-job'\nimport type { StaticSolid } from './engine-statics'\nimport { measureStaticPart, staticSolidsTransfer } from './static-part-job'\nimport type { StaticPartJob } from './static-part-job'\n\n/**\n * The engine's ground tiles as a task kind of the worker coordinator (`destruction.ground-tiles`, CLAUDE.md §14): a tile is a pure function\n * of the samples and the band read at the update it was asked for, so the worker and the main thread give the same bits. The engine's\n * `GroundSchedule` applies it at its update whatever the worker does (`createCoordinatorGroundPort`). No three.js here: a game's worker file\n * imports it from `@adatechnology/game-destruction-three/worker-kinds`.\n */\nexport const groundTilesKind: TaskKind<GroundTileJob, GroundTileResult> = Object.freeze({\n id: WORKER_KIND_ID.GROUND_TILES,\n kind: 'task' as const,\n ...WORKER_KIND_DEFAULTS[WORKER_KIND_ID.GROUND_TILES],\n run: computeGroundTile,\n transferOutput: transferOf,\n // the schedule posts copies from its pool and keeps the job for its own fallback: the samples and band (or the patch) go over without a structured clone, and come back with the answer\n transferInput: jobTransferOf,\n transferAwaitedInput: true,\n // no `warmup`: the engine warms its port with a real tile when the renderer is made (`GroundSchedule.warm`)\n})\n\n/** A cube, the first job each worker runs (`warm`). */\nconst WARM_PART: StaticPartJob = {\n points: new Float64Array([-0.5, -0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, -0.5, 0.5, -0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, 0.5, 0.5, 0.5, -0.5, 0.5, 0.5]),\n matrix: new Float64Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]),\n position: [0, 0, 0],\n quaternion: [0, 0, 0, 1],\n scale: [1, 1, 1],\n found: new Uint32Array(0),\n from: 0,\n}\n\n/**\n * The fixed colliders measured from what is drawn (`destruction.static-colliders`, lane `build`, CLAUDE.md §14): a part of a house, a table, a wall measured anew is a\n * pure function of its vertices, its triangles and its world matrix (`measureStaticPart`), so the worker and the main thread give the same bits. The renderer hands its\n * parts to it when it has a coordinator (`RendererOptions.workers`); the object waits for the answer as a part out of turns waits for the next update.\n */\nexport const staticCollidersKind: TaskKind<StaticPartJob, StaticSolid[]> = Object.freeze({\n id: WORKER_KIND_ID.STATIC_COLLIDERS,\n kind: 'task' as const,\n ...WORKER_KIND_DEFAULTS[WORKER_KIND_ID.STATIC_COLLIDERS],\n run: measureStaticPart,\n transferOutput: staticSolidsTransfer,\n warmup: WARM_PART,\n})\n","import { cellCoordinate, heightPatchGrid } from '@adatechnology/game-terrain'\nimport type { HeightPatch } from '@adatechnology/game-terrain'\n\nimport { GROUND_CELL, readGround, sampleCount, shapeGround } from './engine-ground'\nimport type { GroundGrid, GroundTile } from './engine-ground'\nimport { SOLID_RING } from './engine-ground-ring'\nimport { NO_SOLID, buildSolidVolume } from './engine-ground-solid'\n\n/**\n * A tile of the engine's ground as plain data, so it can be made off the main thread (`engine-ground-port`): the main thread reads the tile's samples and the band of ground\n * past its edges its solid may read (`readGroundBand`), and the tile is a pure function of those (`computeGroundTile`), the same bits wherever it runs. Nothing here calls back\n * into the host: a worker has no `groundAt`.\n */\n\n/** What a tile is made from: its samples (`readGround`) and the band past its edges (`readGroundBand`), both read on the main thread at the frame it was asked for. */\nexport interface GroundTileJob {\n readonly id: number\n readonly x0: number\n readonly z0: number\n readonly size: number\n /** Whether the tile collided on the coarse field before (`collisionFieldOf`). */\n readonly wasCoarse: boolean\n /** Empty in a patch job (`patch`), whose samples and band are made where the tile is. */\n readonly samples: Float64Array\n readonly band: Float64Array\n /**\n * The terrain's vertices under the tile and its ring (`readGroundPatch`), in place of the samples and the band: about 26 x 26 numbers instead of 60 000. The tile is made from\n * the samples and band the patch gives (`heightPatchGrid`, the terrain's own blend), the same bits as read from the terrain on the main thread.\n */\n readonly patch?: HeightPatch\n}\n\n/** A tile made from a job, as arrays that cross threads; `samples` and `band` are the job's own, handed back for the next job. */\nexport interface GroundTileResult {\n readonly id: number\n readonly cells: number\n readonly collisionCells: number\n readonly level: number | null\n readonly heights: Float32Array\n readonly collision: Float32Array\n readonly boxes: Float64Array\n readonly solid: Float64Array\n readonly ring: Float64Array\n readonly samples: Float64Array\n readonly band: Float64Array\n /** A patch job's vertex heights, handed back for the next job. */\n readonly patch?: Float64Array\n}\n\n/** How many read cells the ring past a tile of `cells` cells of side `cell` is wide (`createGroundRing`). */\nconst ringOf = (cell: number): number => Math.round(SOLID_RING / cell)\n\n/** The length of the band of a tile of `size` m: one height per half cell over the tile and its ring (`GroundSource`). */\nexport const bandLength = (size: number): number => {\n const n = Math.round(size / GROUND_CELL)\n const width = 2 * (n + 2 * ringOf(size / n)) + 1\n return width * width\n}\n\n// the lattice of a band read through the grid, kept between reads (one at a time)\nlet lineX = new Float64Array(0)\nlet lineZ = new Float64Array(0)\nlet sideOut = new Float64Array(0)\n\n/**\n * Reads into `band` the ground past the tile's edges, as far as its solid may read it (`SOLID_RING`) and on the edges themselves: every half cell `(a, b)` with `a` or `b` on or\n * past an edge, at the very point the ring asks `groundAt` for (`x0 + (a / 2) * cell`). Through `grid` in four strips, else a call each. The tile's inside is left as it was.\n */\nexport const readGroundBand = (groundAt: (x: number, z: number) => number, band: Float64Array, x0: number, z0: number, size: number, grid?: GroundGrid): void => {\n const n = Math.round(size / GROUND_CELL)\n const cell = size / n\n const r = ringOf(cell)\n const lo = -2 * r\n const hi = 2 * n + 2 * r\n const width = hi - lo + 1\n const xAt = (a: number): number => x0 + (a / 2) * cell\n const zAt = (b: number): number => z0 + (b / 2) * cell\n if (!grid) {\n for (let b = lo; b <= hi; b++) {\n for (let a = lo; a <= hi; a++) {\n if (a > 0 && a < 2 * n && b > 0 && b < 2 * n) continue\n band[(b - lo) * width + a - lo] = groundAt(xAt(a), zAt(b))\n }\n }\n return\n }\n const strip = 2 * r + 1\n const middle = 2 * n - 1\n if (lineX.length < width) lineX = new Float64Array(width)\n if (lineZ.length < width) lineZ = new Float64Array(width)\n if (sideOut.length < strip * middle) sideOut = new Float64Array(strip * middle)\n for (let a = lo; a <= hi; a++) lineX[a - lo] = xAt(a)\n const xs = lineX.subarray(0, width)\n // the rows under the tile and over it, whole: straight into the band\n for (const from of [lo, 2 * n]) {\n for (let k = 0; k < strip; k++) lineZ[k] = zAt(from + k)\n grid(xs, lineZ.subarray(0, strip), band.subarray((from - lo) * width, (from - lo + strip) * width))\n }\n // the columns left and right of it, between those rows\n for (let k = 0; k < middle; k++) lineZ[k] = zAt(1 + k)\n const zs = lineZ.subarray(0, middle)\n for (const from of [lo, 2 * n]) {\n grid(lineX.subarray(from - lo, from - lo + strip), zs, sideOut)\n for (let k = 0; k < middle; k++) for (let i = 0; i < strip; i++) band[(1 + k - lo) * width + from - lo + i] = sideOut[k * strip + i]!\n }\n}\n\n/** The host's terrain as vertex heights under a rectangle (min x, max x, min z, max z), or null where it cannot (`Terrain.heightPatch` is one); written into `into` when long enough. */\nexport type GroundPatchRead = (minX: number, maxX: number, minZ: number, maxZ: number, into?: Float64Array) => HeightPatch | null\n\n/**\n * The terrain's vertices under the tile at (x0, z0) and its ring, the rectangle every sample and band point lies in (the band's own outermost points, as `readGroundBand` computes\n * them); null where the host has none (a tile crossing the terrain's bounds, where its `baseHeight` answers): that tile is read as before.\n */\nexport const readGroundPatch = (read: GroundPatchRead, x0: number, z0: number, size: number, into?: Float64Array): HeightPatch | null => {\n const n = Math.round(size / GROUND_CELL)\n const cell = size / n\n const r = ringOf(cell)\n const lo = -2 * r\n const hi = 2 * n + 2 * r\n return read(x0 + (lo / 2) * cell, x0 + (hi / 2) * cell, z0 + (lo / 2) * cell, z0 + (hi / 2) * cell, into)\n}\n\n/** The cell of `latticePatchRead`'s ground (m): a terrain's usual one. */\nconst LATTICE_CELL = 0.1\n\n/**\n * A `GroundPatchRead` of any ground as a terrain would hold it: `ground` sampled at the vertices of a `LATTICE_CELL` lattice laid a metre and more around each rectangle asked,\n * the patch found with the terrain's own cell rule (`cellCoordinate`). For the warm job of a patch tile, which has no terrain: whatever the tile size and ring are, its patch\n * covers them, as a real one does.\n */\nexport const latticePatchRead = (ground: (x: number, z: number) => number): GroundPatchRead => (minX, maxX, minZ, maxZ, into) => {\n const originX = Math.floor(minX) - 1\n const originZ = Math.floor(minZ) - 1\n const columns = Math.ceil((maxX - originX) / LATTICE_CELL) + 2\n const rows = Math.ceil((maxZ - originZ) / LATTICE_CELL) + 2\n const column0 = cellCoordinate(minX, originX, columns, LATTICE_CELL) | 0\n const row0 = cellCoordinate(minZ, originZ, rows, LATTICE_CELL) | 0\n const width = (cellCoordinate(maxX, originX, columns, LATTICE_CELL) | 0) + 2 - column0\n const depth = (cellCoordinate(maxZ, originZ, rows, LATTICE_CELL) | 0) + 2 - row0\n const heights = into && into.length >= width * depth ? into : new Float64Array(width * depth)\n for (let j = 0; j < depth; j++) for (let i = 0; i < width; i++) heights[j * width + i] = ground(originX + (column0 + i) * LATTICE_CELL, originZ + (row0 + j) * LATTICE_CELL)\n return { cellSize: LATTICE_CELL, originX, originZ, columns, rows, column0, row0, width, depth, heights }\n}\n\nconst NO_GROUND = (): number => {\n throw new Error('engine-ground-job: a patch job reads its patch only')\n}\n// the patch the grid below reads, and the samples and band a patch job is made into, kept between jobs (one at a time) so a job makes no arrays for them\nlet gridPatch: HeightPatch | null = null\nconst patchGrid: GroundGrid = (xs, zs, out) => heightPatchGrid(gridPatch as HeightPatch, xs, zs, out)\nlet patchSamples = new Float64Array(0)\nlet patchBand = new Float64Array(0)\n\n/** The samples and band of a patch job, read from its patch through the same lattices `readGround` and `readGroundBand` read the terrain at (module scratch: not reentrant). */\nconst groundOfPatch = (job: GroundTileJob, patch: HeightPatch): { samples: Float64Array; band: Float64Array } => {\n const count = sampleCount(Math.round(job.size / GROUND_CELL))\n if (patchSamples.length !== count) patchSamples = new Float64Array(count)\n if (patchBand.length !== bandLength(job.size)) patchBand = new Float64Array(bandLength(job.size))\n gridPatch = patch\n readGround(NO_GROUND, patchSamples, job.x0, job.z0, job.size, undefined, patchGrid)\n readGroundBand(NO_GROUND, patchBand, job.x0, job.z0, job.size, patchGrid)\n gridPatch = null\n return { samples: patchSamples, band: patchBand }\n}\n\n/**\n * The tile a job makes: `shapeGround` of its samples and, under a height field, its solid over the band (both made from its patch first, in a patch job). Pure of the job.\n * Not reentrant: a patch job's samples and band, and `readGround`'s lattice, are module scratch (one job at a time per thread, as a worker and the schedule run them).\n */\nexport const computeGroundTile = (job: GroundTileJob): GroundTileResult => {\n const { samples, band } = job.patch ? groundOfPatch(job, job.patch) : job\n const t = shapeGround(samples, job.x0, job.z0, job.size, null, job.wasCoarse)\n const solid = t.level === null ? buildSolidVolume(t.heights, t.cells, job.x0, job.z0, job.size / t.cells, band, t.cells / t.collisionCells) : NO_SOLID\n return {\n id: job.id, cells: t.cells, collisionCells: t.collisionCells, level: t.level, heights: t.heights, collision: t.collision,\n boxes: Float64Array.from(t.boxes), solid: Float64Array.from(solid.boxes), ring: Float64Array.from(solid.ring), samples: job.samples, band: job.band,\n ...(job.patch ? { patch: job.patch.heights } : {}),\n }\n}\n\n/** Each buffer of the arrays once, none empty (an empty one may be shared, and a buffer transferred twice throws). */\nconst buffersOf = (arrays: ReadonlyArray<Float32Array | Float64Array | undefined>): ArrayBuffer[] => {\n const out: ArrayBuffer[] = []\n for (const array of arrays) {\n const buffer = array?.buffer as ArrayBuffer | undefined\n if (buffer && buffer.byteLength > 0 && !out.includes(buffer)) out.push(buffer)\n }\n return out\n}\n\n/** The buffers a result hands over, each once and none empty (a height field may be its own collision field). */\nexport const transferOf = (r: GroundTileResult): ArrayBuffer[] => buffersOf([r.heights, r.collision, r.boxes, r.solid, r.ring, r.samples, r.band, r.patch])\n\n/** The buffers a job hands over: its samples and band, or its patch. */\nexport const jobTransferOf = (job: GroundTileJob): ArrayBuffer[] => buffersOf([job.samples, job.band, job.patch?.heights])\n\n/** The tile a result stands for, over the samples the main thread keeps for the tile (none for a patch tile, which keeps its patch instead). */\nexport const tileOfResult = (r: GroundTileResult, samples: Float64Array | null, patch?: HeightPatch): GroundTile => ({\n heights: r.heights, cells: r.cells, collision: r.collision, collisionCells: r.collisionCells, boxes: r.boxes,\n solid: r.level === null ? { boxes: r.solid, ring: r.ring } : NO_SOLID, level: r.level, samples, ...(patch ? { patch } : {}),\n})\n","/**\n * The engine collides with a tile's ground at a coarser grid than the tile is read at, as Unreal's \"Simple Collision\" mip level 1 does: every second corner of the 2.5 cm\n * grid, so a 5 cm height field. The read grid stays where the steps are found and the solid under the ground is made; the engine's narrow phase meets a quarter of the\n * triangles under a piece (the frame after a blast was mostly a piece resting on 2.5 cm triangles, T3.8ah). Owner decision 2026-11-17. The collision surface is off the drawn\n * ground by the bend of the ground across one of its cells: a tile keeps the coarse field only where that, with the engine's own 8 bit steps, is within 5 mm everywhere\n * on it, and has no step (`collisionFieldOf`); else it collides at the read grid.\n */\nexport const GROUND_COLLISION_CELL = 0.05\n\n/** The most (m) the collision surface may be off the drawn ground anywhere on a tile for the tile to collide at `GROUND_COLLISION_CELL` (the owner's bound). */\nexport const COLLISION_TOLERANCE = 0.005\n/**\n * A tile on the read grid goes to the coarse field only under this (m): one near the bound does not change field at every change of its ground (the bound stays hard). Not\n * lower: a room crater tile is 4.47 mm off at 5 cm, and a piece rests on it the frame after the blast.\n */\nexport const COLLISION_ENTER = 0.0045\n/** Samples a side of the engine's height field blocks (`game-physics-jolt` `HEIGHT_BLOCK`): each block's heights are 8 bit steps of its own range. */\nconst ENGINE_BLOCK = 4\n\n/** How many read cells (of `readCell` m, `cells` a side) a collision cell would span: 1 keeps the read grid (a collision cell that does not divide the tile). */\nexport const coarseStep = (cells: number, readCell: number): number => {\n const k = Math.max(1, Math.round(GROUND_COLLISION_CELL / readCell))\n return cells % k === 0 ? k : 1\n}\n\n/** A tile's collision field: every `step`-th corner of its read heights (1: the heights themselves). */\nexport interface CollisionField {\n readonly step: number\n readonly field: Float32Array\n}\n\n/**\n * A tile's collision field: the coarse one (`GROUND_COLLISION_CELL`) when the tile has no step boxes (a step's edge is between read corners, and a coarser field ramps or grooves\n * across it: 14 cm by a terrace's wall) and the coarse surface, on either diagonal and with the engine's 8 bit steps, is within `COLLISION_TOLERANCE` of the drawn ground at\n * every read corner (both are flat between them); within `COLLISION_ENTER` when the tile was on the read grid before (`wasCoarse` false: a fresh tile is one); else the read\n * grid itself.\n */\nexport const collisionFieldOf = (heights: Float32Array, cells: number, readCell: number, hasSteps: boolean, wasCoarse = false): CollisionField => {\n const k = coarseStep(cells, readCell)\n const fine = { step: 1, field: heights }\n if (k === 1 || hasSteps || heights.length === 0) return fine\n const m = cells + 1\n const get = (p: number, q: number): number => heights[q * m + p]!\n let off = 0\n for (let q = 0; q <= cells; q++) {\n for (let p = 0; p <= cells; p++) {\n collisionBoth(get, p, q, k)\n const h = heights[q * m + p]!\n off = Math.max(off, h - both[0]!, both[1]! - h)\n }\n }\n const field = collisionOf(heights, cells, k)\n return off + quantumOf(field, cells / k) <= (wasCoarse ? COLLISION_TOLERANCE : COLLISION_ENTER) ? { step: k, field } : fine\n}\n\n/** The most the engine's 8 bit heights may be off the field's own, over its blocks: half a step of a block's range. */\nconst quantumOf = (field: Float32Array, cells: number): number => {\n const m = cells + 1\n let most = 0\n for (let bj = 0; bj < cells; bj += ENGINE_BLOCK) {\n for (let bi = 0; bi < cells; bi += ENGINE_BLOCK) {\n let lo = Infinity, hi = -Infinity\n for (let j = bj; j <= Math.min(cells, bj + ENGINE_BLOCK); j++) {\n for (let i = bi; i <= Math.min(cells, bi + ENGINE_BLOCK); i++) {\n lo = Math.min(lo, field[j * m + i]!)\n hi = Math.max(hi, field[j * m + i]!)\n }\n }\n most = Math.max(most, (hi - lo) / 510)\n }\n }\n return most\n}\n\n/** The collision field of a tile's heights (`(cells + 1)^2`, x fastest): every `k`-th corner, `(cells / k + 1)^2` of them. */\nexport const collisionOf = (heights: Float32Array, cells: number, k: number): Float32Array => {\n if (k === 1) return heights\n const m = cells + 1\n const n = cells / k + 1\n const out = new Float32Array(n * n)\n for (let j = 0; j < n; j++) for (let i = 0; i < n; i++) out[j * n + i] = heights[j * k * m + i * k]!\n return out\n}\n\n/**\n * The collision surface at the read corner (`p`, `q`) (any integers: past the tile too), from `get` of the corners on the collision grid (multiples of `k`): the lower of the\n * two ways the engine may cut the collision cell into triangles, so whichever it uses is no lower than this.\n */\nexport const collisionAt = (get: (p: number, q: number) => number, p: number, q: number, k: number): number => {\n collisionBoth(get, p, q, k)\n return both[0]!\n}\n\n/** Where `collisionBoth` writes, the lower then the higher (one array for the module: no array per corner). */\nconst both = new Float64Array(2)\n\n/** The collision surface at the read corner (`p`, `q`) on the two ways a collision cell may be cut, into `both`: the lower then the higher. */\nconst collisionBoth = (get: (p: number, q: number) => number, p: number, q: number, k: number): void => {\n const p0 = Math.floor(p / k) * k, q0 = Math.floor(q / k) * k\n const u = (p - p0) / k, v = (q - q0) / k\n if (u === 0 && v === 0) {\n both[0] = both[1] = get(p0, q0)\n return\n }\n // on a collision cell's edge only that edge's corners are asked for (the tile's last row and column have no cell past them)\n const p1 = u === 0 ? p0 : p0 + k, q1 = v === 0 ? q0 : q0 + k\n const h00 = get(p0, q0), h10 = get(p1, q0), h01 = get(p0, q1), h11 = get(p1, q1)\n // the diagonal from (0, 0) to (1, 1), and the one from (1, 0) to (0, 1)\n const main = u >= v ? h00 + u * (h10 - h00) + v * (h11 - h10) : h00 + v * (h01 - h00) + u * (h11 - h01)\n const cross = u + v <= 1 ? h00 + u * (h10 - h00) + v * (h01 - h00) : h11 + (1 - u) * (h01 - h11) + (1 - v) * (h10 - h11)\n both[0] = Math.min(main, cross)\n both[1] = Math.max(main, cross)\n}\n\n/**\n * A tile's read heights lowered, corner by corner, to the collision surface where it is lower: a grid nothing over which (taken flat between corners, as the engine takes\n * both surfaces) rises over either surface. What must stay under the ground (the solid under it, §12) is made over this.\n */\nexport const underBoth = (heights: Float32Array, cells: number, k: number): Float32Array => {\n if (k === 1) return heights\n const m = cells + 1\n const get = (p: number, q: number): number => heights[q * m + p]!\n const out = new Float32Array(m * m)\n for (let q = 0; q <= cells; q++) for (let p = 0; p <= cells; p++) out[q * m + p] = Math.min(heights[q * m + p]!, collisionAt(get, p, q, k))\n return out\n}\n","/** How far (m) a sample may leave its cell's corners before the cell counts as holding a step. */\nexport const STEP_TOLERANCE = 0.005\n\n/**\n * Whether a cell holds a step, from its nine samples in `s`: the corners (x0 z0, x1 z0, x0 z1, x1 z1), the centre, and the middles of its edges (z0, z1, x0, x1). A step\n * moves the centre or an edge's middle off its corners. The one test the tile (`engine-ground`) and the ring past it (`engine-ground-ring`) make, so both see the same cells.\n */\nconst off = (a: number, b: number): boolean => Math.abs(a - b) > STEP_TOLERANCE\n\nexport const holdsStep = (s: ArrayLike<number>): boolean => {\n const c00 = s[0]!, c10 = s[1]!, c01 = s[2]!, c11 = s[3]!\n return off(s[4]!, (c00 + c10 + c01 + c11) / 4) || off(s[5]!, (c00 + c10) / 2) || off(s[6]!, (c01 + c11) / 2) || off(s[7]!, (c00 + c01) / 2) || off(s[8]!, (c10 + c11) / 2)\n}\n","import { collisionAt } from './engine-ground-collision'\nimport { holdsStep } from './engine-ground-step'\n\n/**\n * The ground a tile's solid reads around the tile: its own heights inside, and past its edges, as far as `SOLID_RING`, the ground the neighbour tile is made from (`groundAt`),\n * read only where a block of the solid reaches and once each. Every sample read past the edge is kept (`read`): the solid depends on them, so a change there makes it again.\n */\n\n/**\n * How far (m) past its tile's edges a block of the solid may reach: a cell of overlap, the skew of a top turned about both axes (a cell or two at the edge's block sizes), and a\n * box at least 15 cm deep at any slope (`engine-ground-solid` caps the depth of a box that would lean further). The host's changes this close to a tile make its solid again.\n */\nexport const SOLID_RING = 0.2\n/** One cell's nine samples, for `holdsStep`. */\nconst nine = new Float64Array(9)\n\n/**\n * Where the ring reads the ground past the tile's edges: the host's `groundAt`, or a band read ahead of time (`engine-ground-job` `readGroundBand`), one height per half cell\n * `(a, b)` at `(b + 2 * ring) * width + a + 2 * ring` (`width` = `2 * (cells + 2 * ring) + 1`), each the very height `groundAt` answers there. A worker has no `groundAt`.\n */\nexport type GroundSource = ((x: number, z: number) => number) | Float64Array\n\nexport interface GroundRing {\n /** How many cells the ring is wide. */\n readonly cells: number\n /** The four corners (`(i, j)`, `(i + 1, j)`, `(i, j + 1)`, `(i + 1, j + 1)`) of a cell past the tile's edge into `out`; a cell holding a step (`holdsStep`, as the neighbour builds it) has its lowest of nine samples at all four. */\n cell(i: number, j: number, out: Float64Array): void\n /** The samples read past the edge: x, z and height, three numbers each. */\n readonly read: number[]\n}\n\n// the samples and cells read for the ring being made, marked by the build they belong to (one at a time), so a ring costs no new arrays\nlet build = 0\nlet heldSamples = new Float64Array(0)\nlet sampleBuild = new Uint32Array(0)\nlet heldCells = new Float64Array(0)\nlet cellBuild = new Uint32Array(0)\n\n/**\n * `heights` are the tile's own (already under its collision field), `fieldStep` how many read cells a neighbour's coarse collision cell spans: past the edge a corner is the lower of\n * the ground there and that coarse field at it (the neighbour collides with it or with the ground itself).\n */\nexport const createGroundRing = (heights: Float32Array, cells: number, x0: number, z0: number, cell: number, groundAt: GroundSource, fieldStep = 1): GroundRing => {\n const band = typeof groundAt === 'function' ? null : groundAt\n const ring = Math.round(SOLID_RING / cell)\n const m = cells + 1\n const width = 2 * (cells + 2 * ring) + 1\n const across = cells + 2 * ring\n if (sampleBuild.length < width * width) {\n heldSamples = new Float64Array(width * width)\n sampleBuild = new Uint32Array(width * width)\n }\n if (cellBuild.length < across * across) {\n heldCells = new Float64Array(4 * across * across)\n cellBuild = new Uint32Array(across * across)\n }\n const mark = ++build\n const read: number[] = []\n /** The ground at the half cell (`a` / 2, `b` / 2): the tile's own height at its corners, the neighbour's ground elsewhere. */\n const half = (a: number, b: number): number => {\n if (a % 2 === 0 && b % 2 === 0 && a >= 0 && b >= 0 && a <= 2 * cells && b <= 2 * cells) return heights[(b / 2) * m + a / 2]!\n const key = (b + 2 * ring) * width + a + 2 * ring\n if (sampleBuild[key] === mark) return heldSamples[key]!\n const x = x0 + (a / 2) * cell\n const z = z0 + (b / 2) * cell\n const h = band === null ? (groundAt as (x: number, z: number) => number)(x, z) : band[key]!\n heldSamples[key] = h\n sampleBuild[key] = mark\n read.push(x, z, h)\n return h\n }\n /** The ground at the read corner (`p`, `q`). */\n const fine = (p: number, q: number): number => half(2 * p, 2 * q)\n return {\n cells: ring,\n read,\n cell(i, j, out) {\n const key = (j + ring) * across + i + ring\n if (cellBuild[key] !== mark) {\n const a = 2 * i, b = 2 * j\n nine[0] = half(a, b)\n nine[1] = half(a + 2, b)\n nine[2] = half(a, b + 2)\n nine[3] = half(a + 2, b + 2)\n nine[4] = half(a + 1, b + 1)\n nine[5] = half(a + 1, b)\n nine[6] = half(a + 1, b + 2)\n nine[7] = half(a, b + 1)\n nine[8] = half(a + 2, b + 1)\n // a cell the neighbour builds as a step: where the step runs in it is not known, so the ground there is no lower than its lowest sample\n const step = holdsStep(nine)\n let floor = Infinity\n for (let k = 0; k < 9; k++) floor = Math.min(floor, nine[k]!)\n const corner = (p: number, q: number, h: number): number => (fieldStep === 1 ? h : Math.min(h, collisionAt(fine, p, q, fieldStep)))\n const c00 = corner(i, j, nine[0]!), c10 = corner(i + 1, j, nine[1]!), c01 = corner(i, j + 1, nine[2]!), c11 = corner(i + 1, j + 1, nine[3]!)\n heldCells[4 * key] = step ? floor : c00\n heldCells[4 * key + 1] = step ? floor : c10\n heldCells[4 * key + 2] = step ? floor : c01\n heldCells[4 * key + 3] = step ? floor : c11\n cellBuild[key] = mark\n }\n for (let k = 0; k < 4; k++) out[k] = heldCells[4 * key + k]!\n },\n }\n}\n","import type { GroundRing } from './engine-ground-ring'\n\n/**\n * How far a turned box rises above the ground, over every column it has a point in, its leaning sides as much as its top: what it must be lowered by to be under the ground\n * everywhere (§12). The ground between a cell's corners is flat (the engine's two triangles, or bilinear), so a plane rises over it the most at a corner.\n * - Its top: the top's plane over every corner under the top's extent.\n * - Its sides, which lean uphill under the top: the box is its top slid down along -n, so where the ground over the box's shadow is nowhere steeper than the top's slope\n * allows (1 / its slope), no point of it is further over the ground than its top is. Else every cell of the shadow: a column's highest point is under each face that\n * looks up (the top, and the uphill side of each tilted axis), so over a cell under the lowest of those planes, found from the top down over a pyramid of planes under the\n * tile's ground (a block of cells whose plane is above every plane of the box over it is skipped whole).\n * - Past the tile's edges, every cell of the shadow there, over the ring's ground (`engine-ground-ring`).\n */\n\n/** A box: its centre, axes (x, y, z: the y axis is the normal of its top) and half sizes. */\nexport interface ReachBox {\n readonly c: ArrayLike<number>\n readonly axes: ReadonlyArray<ArrayLike<number>>\n readonly half: ArrayLike<number>\n}\n\n/**\n * Under each block of 2^l by 2^l cells (l from 1 up to one block over the whole tile), a plane no sample of the block is under: the block's corner slopes, lowered to its\n * lowest sample. Three numbers a block (its height at the block's first corner, and its slopes along x and z per cell), made when first asked for: over a slope or a\n * crater's wall the plane follows the ground, so a box whose planes are under it there is skipped whole.\n */\nexport interface LowPyramid {\n readonly heights: Float32Array\n readonly cells: number\n readonly sizes: readonly number[]\n readonly planes: readonly Float64Array[]\n /** The square of the steepest the ground is (m per m, any way) over each block: a cell's from its edges (its two triangles, or bilinear, are no steeper), a block's the steepest of its four. */\n readonly steepest: readonly Float64Array[]\n}\n\nexport const buildLowPyramid = (heights: Float32Array, cells: number, cell: number): LowPyramid => {\n const m = cells + 1\n const first = new Float64Array(cells * cells)\n for (let j = 0; j < cells; j++) {\n for (let i = 0; i < cells; i++) {\n const h00 = heights[j * m + i]!, h10 = heights[j * m + i + 1]!, h01 = heights[(j + 1) * m + i]!, h11 = heights[(j + 1) * m + i + 1]!\n const dx = Math.max(Math.abs(h10 - h00), Math.abs(h11 - h01)), dz = Math.max(Math.abs(h01 - h00), Math.abs(h11 - h10))\n first[j * cells + i] = (dx * dx + dz * dz) / (cell * cell)\n }\n }\n const sizes: number[] = [cells]\n const planes: Float64Array[] = [new Float64Array(0)]\n const steepest: Float64Array[] = [first]\n for (let s = 2; s < 2 * cells; s *= 2) {\n const below = steepest[steepest.length - 1]!\n const n = sizes[sizes.length - 1]!\n const k = Math.ceil(cells / s)\n const level = new Float64Array(k * k)\n for (let j = 0; j < n; j++) for (let i = 0; i < n; i++) level[(j >> 1) * k + (i >> 1)] = Math.max(level[(j >> 1) * k + (i >> 1)]!, below[j * n + i]!)\n sizes.push(k)\n planes.push(new Float64Array(3 * k * k).fill(NaN))\n steepest.push(level)\n }\n return { heights, cells, sizes, planes, steepest }\n}\n\n/** Whether the ground is steeper than `limit` (m per m) anywhere over the cells `ia`..`ib` (not included) by `ja`..`jb`. */\n// the question `steeperOver` is asking, for `visit` (one at a time)\nlet steepPyramid: LowPyramid | null = null\nlet steepSquare = 0\nlet steepIa = 0, steepIb = 0, steepJa = 0, steepJb = 0\n\nconst visit = (l: number, bi: number, bj: number): boolean => {\n const pyramid = steepPyramid!\n if (pyramid.steepest[l]![bj * pyramid.sizes[l]! + bi]! <= steepSquare) return false\n const s = 1 << l\n const a = bi * s, c = bj * s\n const b = Math.min(pyramid.cells, a + s), d = Math.min(pyramid.cells, c + s)\n if (a >= steepIb || b <= steepIa || c >= steepJb || d <= steepJa) return false\n if (l === 0) return true\n for (let dj = 0; dj < 2; dj++) for (let di = 0; di < 2; di++) if (visit(l - 1, 2 * bi + di, 2 * bj + dj)) return true\n return false\n}\n\nconst steeperOver = (pyramid: LowPyramid, ia: number, ib: number, ja: number, jb: number, limit: number): boolean => {\n steepPyramid = pyramid\n steepSquare = limit * limit\n steepIa = ia\n steepIb = ib\n steepJa = ja\n steepJb = jb\n const steeper = visit(pyramid.sizes.length - 1, 0, 0)\n // the last pyramid is not kept past the call (§8)\n steepPyramid = null\n return steeper\n}\n\n/** Where the plane under the block (`bi`, `bj`) of level `l` is in `pyramid.planes[l]`, made now if it was not. */\nconst planeUnder = (pyramid: LowPyramid, l: number, bi: number, bj: number): number => {\n const level = pyramid.planes[l]!\n const at = 3 * (bj * pyramid.sizes[l]! + bi)\n if (!Number.isNaN(level[at]!)) return at\n const { heights, cells } = pyramid\n const m = cells + 1\n const s = 1 << l\n const ia = bi * s, ja = bj * s, ib = Math.min(cells, ia + s), jb = Math.min(cells, ja + s)\n const h00 = heights[ja * m + ia]!, h10 = heights[ja * m + ib]!, h01 = heights[jb * m + ia]!, h11 = heights[jb * m + ib]!\n const sx = (h10 - h00 + h11 - h01) / 2 / (ib - ia), sz = (h01 - h00 + h11 - h10) / 2 / (jb - ja)\n let under = 0\n for (let j = ja; j <= jb; j++) for (let i = ia; i <= ib; i++) under = Math.min(under, heights[j * m + i]! - (h00 + sx * (i - ia) + sz * (j - ja)))\n level[at] = h00 + under\n level[at + 1] = sx\n level[at + 2] = sz\n return at\n}\n\nexport interface ReachTile {\n readonly heights: Float32Array\n readonly cells: number\n readonly x0: number\n readonly z0: number\n readonly cell: number\n readonly pyramid: LowPyramid\n readonly ring: GroundRing\n}\n\nexport interface Reach {\n /** The most the box rises over the ground of the tile's cells (0 when it is nowhere above), and over the ring's cells past its edges. */\n readonly tile: number\n readonly ring: number\n}\n\nconst corner4 = new Float64Array(4)\n/** A block whose bound is within this (m) of the most found is skipped: the heights are 32 bit floats, and a plane through them is that close to a plane under them. */\nconst PRUNE_SLACK = 1e-6\n// one box at a time: its planes (a, bx, bz each), the directions of its shadow's sides (x, z each) and its extent along each (low, high)\nconst planes = new Float64Array(9)\nconst dirs = new Float64Array(10)\nconst spans = new Float64Array(10)\nlet planeCount = 0\nlet dirCount = 0\n\n/** Whether the rectangle and the box's shadow are apart along one of its sides' directions. */\nconst apart = (xa: number, xb: number, za: number, zb: number): boolean => {\n for (let d = 0; d < dirCount; d += 2) {\n const dx = dirs[d]!, dz = dirs[d + 1]!\n const lo = (dx > 0 ? xa * dx : xb * dx) + (dz > 0 ? za * dz : zb * dz)\n const hi = (dx > 0 ? xb * dx : xa * dx) + (dz > 0 ? zb * dz : za * dz)\n if (hi < spans[d]! - 1e-9 || lo > spans[d + 1]! + 1e-9) return true\n }\n return false\n}\n\n/** The least, over the box's planes, of the most each rises over the four corner heights (`corner4`) of the rectangle. */\nconst over = (xa: number, xb: number, za: number, zb: number): number => {\n let best = Infinity\n for (let p = 0; p < planeCount; p += 3) {\n const a = planes[p]!, bx = planes[p + 1]!, bz = planes[p + 2]!\n const most = Math.max(a + bx * xa + bz * za - corner4[0]!, a + bx * xb + bz * za - corner4[1]!, a + bx * xa + bz * zb - corner4[2]!, a + bx * xb + bz * zb - corner4[3]!)\n if (most < best) best = most\n }\n return best\n}\n\n// the tile and box `search` walks (one at a time): the top's own extent in cells (from, to along x, then z), and the most found so far\nlet searchTile: ReachTile | null = null\nconst searchTop = new Int32Array(4)\nlet searchMost = 0\n\n/** The cell (`ia`, `ja`): its corners, and how far the box rises over them. */\nconst leaf = (ia: number, ja: number): void => {\n const { heights, cells, x0, z0, cell } = searchTile!\n const m = cells + 1\n const xa = x0 + ia * cell, za = z0 + ja * cell\n corner4[0] = heights[ja * m + ia]!\n corner4[1] = heights[ja * m + ia + 1]!\n corner4[2] = heights[(ja + 1) * m + ia]!\n corner4[3] = heights[(ja + 1) * m + ia + 1]!\n const e = over(xa, xa + cell, za, za + cell)\n if (e > searchMost) searchMost = e\n}\n\n/** The block (`bi`, `bj`) of level `l`, skipped when the box is apart from it or no higher over its low plane than the most found already, else its four. */\nconst search = (l: number, bi: number, bj: number): void => {\n const { cells, x0, z0, cell, pyramid } = searchTile!\n const s = 1 << l\n const ia = bi * s, ja = bj * s\n if (ia >= cells || ja >= cells) return\n const ib = Math.min(cells, ia + s), jb = Math.min(cells, ja + s)\n if (ia >= searchTop[0]! && ib <= searchTop[1]! && ja >= searchTop[2]! && jb <= searchTop[3]!) return\n const xa = x0 + ia * cell, xb = x0 + ib * cell, za = z0 + ja * cell, zb = z0 + jb * cell\n if (apart(xa, xb, za, zb)) return\n if (l === 0) return leaf(ia, ja)\n const level = pyramid.planes[l]!\n const at = planeUnder(pyramid, l, bi, bj)\n const h = level[at]!, sx = level[at + 1]!, sz = level[at + 2]!\n corner4[0] = h\n corner4[1] = h + sx * (ib - ia)\n corner4[2] = h + sz * (jb - ja)\n corner4[3] = h + sx * (ib - ia) + sz * (jb - ja)\n if (over(xa, xb, za, zb) <= searchMost + PRUNE_SLACK) return\n for (let dj = 0; dj < 2; dj++) for (let di = 0; di < 2; di++) search(l - 1, 2 * bi + di, 2 * bj + dj)\n}\n\nexport const reachOf = (box: ReachBox, t: ReachTile): Reach => {\n const { heights, cells, x0, z0, cell, pyramid, ring } = t\n const m = cells + 1\n // the planes over the box's columns, y <= a + bx x + bz z: one per axis, the face of it that looks up\n planeCount = 0\n for (let k = 0; k < 3; k++) {\n const a = box.axes[k]!\n if (Math.abs(a[1]!) < 1e-9) continue\n const bx = -a[0]! / a[1]!, bz = -a[2]! / a[1]!\n planes[planeCount++] = box.c[1]! + box.half[k]! / Math.abs(a[1]!) - bx * box.c[0]! - bz * box.c[2]!\n planes[planeCount++] = bx\n planes[planeCount++] = bz\n }\n // the box's shadow as a convex polygon: its extent along x, z and across each axis seen from above\n dirs[0] = 1\n dirs[1] = 0\n dirs[2] = 0\n dirs[3] = 1\n dirCount = 4\n for (const a of box.axes) {\n const l = Math.hypot(a[0]!, a[2]!)\n if (l < 1e-9) continue\n dirs[dirCount++] = -a[2]! / l\n dirs[dirCount++] = a[0]! / l\n }\n for (let d = 0; d < dirCount; d += 2) {\n const dx = dirs[d]!, dz = dirs[d + 1]!\n let r = 0\n for (let k = 0; k < 3; k++) r += box.half[k]! * Math.abs(box.axes[k]![0]! * dx + box.axes[k]![2]! * dz)\n const mid = box.c[0]! * dx + box.c[2]! * dz\n spans[d] = mid - r\n spans[d + 1] = mid + r\n }\n let inTile = 0\n // under the top's own extent, the top's plane over every corner (each cell's most is at a corner): the most found there skips most of the rest\n const n = box.axes[1]!, ax = box.axes[0]!, az = box.axes[2]!\n const tx = box.c[0]! + n[0]! * box.half[1]!, ty = box.c[1]! + n[1]! * box.half[1]!, tz = box.c[2]! + n[2]! * box.half[1]!\n const rx = box.half[0]! * Math.abs(ax[0]!) + box.half[2]! * Math.abs(az[0]!), rz = box.half[0]! * Math.abs(ax[2]!) + box.half[2]! * Math.abs(az[2]!)\n const ta = Math.max(0, Math.floor((tx - rx - x0) / cell)), tb = Math.min(cells, Math.ceil((tx + rx - x0) / cell))\n const sa = Math.max(0, Math.floor((tz - rz - z0) / cell)), sb = Math.min(cells, Math.ceil((tz + rz - z0) / cell))\n const bx = -n[0]! / n[1]!, bz = -n[2]! / n[1]!\n for (let j = sa; j <= sb; j++) {\n for (let i = ta; i <= tb; i++) {\n const e = ty + bx * (x0 + i * cell - tx) + bz * (z0 + j * cell - tz) - heights[j * m + i]!\n if (e > inTile) inTile = e\n }\n }\n // the box is its top slid down along -n: a point of it a slide s from the top at q stands s n_y under the top, over ground at most s |n_h| (the steepest) under q's.\n // Where the ground is nowhere steeper than 1 / (its top's slope), no point of the box is further over the ground than its top over its own extent (all in the tile)\n const ia = Math.floor((spans[0]! - x0) / cell), ib = Math.ceil((spans[1]! - x0) / cell)\n const ja = Math.floor((spans[2]! - z0) / cell), jb = Math.ceil((spans[3]! - z0) / cell)\n const within = ia >= 0 && ja >= 0 && ib <= cells && jb <= cells\n if (within && !steeperOver(pyramid, ia, ib, ja, jb, n[1]! / Math.max(1e-12, Math.hypot(n[0]!, n[2]!)))) return { tile: inTile, ring: 0 }\n searchTile = t\n searchTop[0] = ta\n searchTop[1] = tb\n searchTop[2] = sa\n searchTop[3] = sb\n searchMost = inTile\n // else every cell of its shadow, from the level whose blocks are as wide as the shadow's extent along x and z, over the (at most four) of them it covers\n const ua = Math.max(0, ia), ub = Math.min(cells, ib), va = Math.max(0, ja), vb = Math.min(cells, jb)\n if (ua < ub && va < vb) {\n let l = 0\n while (1 << l < Math.max(ub - ua, vb - va) && l < pyramid.sizes.length - 1) l++\n for (let bj = va >> l; bj <= (vb - 1) >> l; bj++) for (let bi = ua >> l; bi <= (ub - 1) >> l; bi++) search(l, bi, bj)\n }\n inTile = searchMost\n // the last tile (and the host's ground its ring holds) is not kept past the call (§8)\n searchTile = null\n // past the edges: the ring's cells the shadow's extent reaches\n let inRing = 0\n const r = ring.cells\n if (within) return { tile: inTile, ring: 0 }\n for (let j = Math.max(-r, ja); j < Math.min(cells + r, jb); j++) {\n const across = j >= 0 && j < cells\n for (let i = Math.max(-r, ia); i < Math.min(cells + r, ib); i++) {\n // over the tile, along the row: on to its far edge\n if (across && i >= 0 && i < cells) i = cells\n if (i >= Math.min(cells + r, ib)) break\n const xa = x0 + i * cell, za = z0 + j * cell\n if (apart(xa, xa + cell, za, za + cell)) continue\n ring.cell(i, j, corner4)\n const e = over(xa, xa + cell, za, za + cell)\n if (e > inRing) inRing = e\n }\n }\n return { tile: inTile, ring: inRing }\n}\n","import { coarseStep, underBoth } from './engine-ground-collision'\nimport { createGroundRing } from './engine-ground-ring'\nimport type { GroundSource } from './engine-ground-ring'\nimport { buildLowPyramid, reachOf } from './engine-ground-reach'\n\n/**\n * The solid under a height field. Jolt's height field is a surface: a body that ends up wholly below it (ground raised under a sleeping piece, a piece that\n * tunnelled) has nothing to push it out and falls for good. Under the surface of a tile there are blocks, from the lowest ground of the tile less `SOLID_DEPTH`\n * up to a top close under the surface and never above it (§12). A block is split until a plane through its corners is within `SOLID_RELIEF` of the surface or it is\n * `SOLID_MIN_CELLS` cells wide. A level block is a box topped at its lowest ground less `SOLID_MARGIN`; a sloped block is one box turned to its corner plane, its top that\n * plane over the block and a cell past it each way (turned boxes side by side lean apart under their tops: what is pushed out sideways meets the next one), lowered by the\n * most any point of it, top or leaning side, rises over the ground under it (`engine-ground-reach`) and `SOLID_MARGIN`. Where it reaches past the tile, the ground there is\n * the neighbour's (`engine-ground-ring`), read up to `SOLID_RING` out; a box that would lean further is made shallower. Under each turned box is its block's upright box\n * (topped at the block's lowest ground less `SOLID_MARGIN`): turned boxes side by side part under their tops, and what slips between them rests on it, its top no further\n * under the ground than the block's relief and its own size.\n * Every block is boxes: a sloped one used to be a prism (a convex hull each), and a crater tile's 400 hulls were most of the frame after the blast (T3.8ag).\n */\n\n/** How far (m) under the lowest corner of its tile the solid goes. */\nexport const SOLID_DEPTH = 0.5\n/** How far (m) under the surface a block's top may be before the block is split, unless it is already `SOLID_MIN_CELLS` cells wide. */\nconst SOLID_RELIEF = 0.005\nconst SOLID_MIN_CELLS = 3\n/**\n * A top is this far (m) under the lowest ground it stands for: 2 mm put the solid in the contacts of what rests on the surface and the bowl's seed 18 gained 4 cm. The engine\n * holds a height field's samples in 8 bit steps of each 4-sample block's range, up to half a step off (range / 510: 0.15 mm on a 0.75 slope at 2.5 cm, 0.3 mm at 5 cm), well\n * inside this margin.\n */\nexport const SOLID_MARGIN = 0.005\n/** The thinnest (m) a turned box is made; where that would lean past the ring, the block is split, or (at its smallest) left to its upright box. */\nconst SOLID_THINNEST = 0.05\n/** How much (m) more a block's box must be lowered for the ground past the tile than for its own before the block is split, so a fold at the seam lowers a narrow box only. */\nconst SEAM_SPLIT = 0.01\n/** Numbers per block in `SolidVolume.boxes`. */\nexport const SOLID_STRIDE = 10\n\nexport interface SolidVolume {\n /** The blocks: centre x, y, z, half x, y, z and turn x, y, z, w (`SOLID_STRIDE` numbers each); the box's own y is the normal of its top. */\n readonly boxes: readonly number[] | Float64Array\n /** The ground read past the tile's edges, x, z and height each (`engine-ground-ring`): the blocks are made again when one of these changes. */\n readonly ring: readonly number[] | Float64Array\n}\n\nexport const NO_SOLID: SolidVolume = { boxes: [], ring: [] }\n\n/** The unit vector along (x, y, z), into `out`. */\nconst unitInto = (out: Float64Array, x: number, y: number, z: number): Float64Array => {\n const l = Math.hypot(x, y, z)\n out[0] = x / l\n out[1] = y / l\n out[2] = z / l\n return out\n}\n\n// one block at a time: its corner plane's slopes, and the box the reach is asked about (filled in place, no arrays per block)\nconst slopes = new Float64Array(2)\nconst reachAxes = [new Float64Array(3), new Float64Array(3), new Float64Array(3)] as const\nconst reachBox = { c: new Float64Array(3), axes: [reachAxes[0], reachAxes[1], reachAxes[2]], half: new Float64Array(3) }\n\n/** The quaternion of the turn whose columns are the axes `a` (x), `b` (y) and `c` (z). */\nconst quatOfAxes = (a: ArrayLike<number>, b: ArrayLike<number>, c: ArrayLike<number>): [number, number, number, number] => {\n const m00 = a[0]!, m10 = a[1]!, m20 = a[2]!, m01 = b[0]!, m11 = b[1]!, m21 = b[2]!, m02 = c[0]!, m12 = c[1]!, m22 = c[2]!\n const trace = m00 + m11 + m22\n if (trace > 0) {\n const s = 0.5 / Math.sqrt(trace + 1)\n return [(m21 - m12) * s, (m02 - m20) * s, (m10 - m01) * s, 0.25 / s]\n }\n if (m00 > m11 && m00 > m22) {\n const s = 2 * Math.sqrt(1 + m00 - m11 - m22)\n return [0.25 * s, (m01 + m10) / s, (m02 + m20) / s, (m21 - m12) / s]\n }\n if (m11 > m22) {\n const s = 2 * Math.sqrt(1 + m11 - m00 - m22)\n return [(m01 + m10) / s, 0.25 * s, (m12 + m21) / s, (m02 - m20) / s]\n }\n const s = 2 * Math.sqrt(1 + m22 - m00 - m11)\n return [(m02 + m20) / s, (m12 + m21) / s, 0.25 * s, (m10 - m01) / s]\n}\n\n/** How thick (m) a box whose bottom moves by `lean` per metre of thickness may be and stay within `lo`..`hi`, its top spanning `low`..`high` (no thickness when the top does not fit). */\nconst thickWithin = (lean: number, low: number, high: number, lo: number, hi: number): number => {\n if (low < lo || high > hi) return -Infinity\n return lean > 1e-12 ? (hi - high) / lean : lean < -1e-12 ? (low - lo) / -lean : Infinity\n}\n\n/**\n * The blocks under a tile of `cells` cells of side `cell` from (`x0`, `z0`), over its `read` heights (`(cells + 1)^2`, x fastest) and the engine's coarser collision field of\n * them (`step`: every how many corners it is), and the ground around it (`groundAt`, read only past the tile's edges, up to `SOLID_RING`, and its collision field there too).\n */\nexport const buildSolidVolume = (read: Float32Array, cells: number, x0: number, z0: number, cell: number, groundAt: GroundSource, step = 1): SolidVolume => {\n // under the drawn ground and the engine's collision field (every `step`-th corner, `engine-ground-collision`) both, whichever is lower at each corner\n const heights = underBoth(read, cells, step)\n const m = cells + 1\n let low = Infinity\n for (const h of heights) low = Math.min(low, h)\n const bottom = low - SOLID_DEPTH\n const boxes: number[] = []\n // past the edge, under the neighbour's coarse field too, whichever it collides with\n const ring = createGroundRing(heights, cells, x0, z0, cell, groundAt, coarseStep(cells, cell))\n const reachTile = { heights, cells, x0, z0, cell, pyramid: buildLowPyramid(heights, cells, cell), ring }\n const outer = ring.cells * cell\n const loX = x0 - outer, hiX = x0 + cells * cell + outer, loZ = z0 - outer, hiZ = z0 + cells * cell + outer\n const at = (i: number, j: number): number => heights[j * m + i]!\n /** The slopes (per cell) of the plane through the block's corners, into `slopes` (x then z). */\n const slopesOf = (i0: number, j0: number, i1: number, j1: number): void => {\n slopes[0] = (at(i1, j0) - at(i0, j0) + at(i1, j1) - at(i0, j1)) / 2 / (i1 - i0)\n slopes[1] = (at(i0, j1) - at(i0, j0) + at(i1, j1) - at(i1, j0)) / 2 / (j1 - j0)\n }\n\n /** How far the surface rises above the plane through the block's corners lowered to its lowest sample: the block is split while it is more. */\n const planeGap = (i0: number, j0: number, i1: number, j1: number): number => {\n slopesOf(i0, j0, i1, j1)\n const sx = slopes[0]!, sz = slopes[1]!\n let least = Infinity\n let most = -Infinity\n for (let j = j0; j <= j1; j++) {\n for (let i = i0; i <= i1; i++) {\n const above = at(i, j) - (at(i0, j0) + sx * (i - i0) + sz * (j - j0))\n if (above < least) least = above\n if (above > most) most = above\n }\n }\n return most - least\n }\n\n /** A level block: an upright box topped at its lowest ground less `SOLID_MARGIN`. */\n const level = (i0: number, j0: number, i1: number, j1: number, least: number): void => {\n const top = least - SOLID_MARGIN\n boxes.push(x0 + ((i0 + i1) / 2) * cell, (top + bottom) / 2, z0 + ((j0 + j1) / 2) * cell, ((i1 - i0) * cell) / 2, (top - bottom) / 2, ((j1 - j0) * cell) / 2, 0, 0, 0, 1)\n }\n\n /**\n * A sloped block: one box turned to the plane through its corners, its top the rectangle on that plane over the block and a cell past it each way, down to under the\n * solid's bottom, lowered by the most it rises over the ground anywhere (`reachOf`) and `SOLID_MARGIN`. A box that would lean past the ring is made as deep as stays in\n * it (the block's upright box is under it); a box lowered by more than the block's relief is the upright box alone. False when the block should be split instead: its box would not\n * fit the ring, or the ground past the tile lowers it much more than its own.\n */\n const sloped = (i0: number, j0: number, i1: number, j1: number, least: number, most: number): boolean => {\n const span = Math.max(i1 - i0, j1 - j0)\n slopesOf(i0, j0, i1, j1)\n const gx = slopes[0]! / cell\n const gz = slopes[1]! / cell\n const ox = x0 + i0 * cell\n const oz = z0 + j0 * cell\n const base = at(i0, j0)\n // the box's axes, in the scratch the reach reads them from: n the normal of its top, ax along x up the slope, az across both\n const n = unitInto(reachAxes[1]!, -gx, 1, -gz)\n const ax = unitInto(reachAxes[0]!, 1, gx, 0)\n const az = reachAxes[2]!\n az[0] = ax[1]! * n[2]! - ax[2]! * n[1]!\n az[1] = ax[2]! * n[0]! - ax[0]! * n[2]!\n az[2] = ax[0]! * n[1]! - ax[1]! * n[0]!\n const xa = ox, xb = x0 + i1 * cell, za = oz, zb = z0 + j1 * cell\n const cx = (xa + xb) / 2, cz = (za + zb) / 2, cy = base + gx * (cx - ox) + gz * (cz - oz)\n let hx = 0\n let hz = 0\n for (let a = 0; a < 2; a++) {\n const x = a === 0 ? xa : xb\n for (let b = 0; b < 2; b++) {\n const z = b === 0 ? za : zb\n const d0 = x - cx, d1 = base + gx * (x - ox) + gz * (z - oz) - cy, d2 = z - cz\n hx = Math.max(hx, Math.abs(d0 * ax[0]! + d1 * ax[1]! + d2 * ax[2]!))\n hz = Math.max(hz, Math.abs(d0 * az[0]! + d1 * az[1]! + d2 * az[2]!))\n }\n }\n hx += cell\n hz += cell\n let minX = Infinity, maxX = -Infinity, minZ = Infinity, maxZ = -Infinity, highest = -Infinity\n for (let a = 0; a < 2; a++) {\n const su = a === 0 ? -1 : 1\n for (let b = 0; b < 2; b++) {\n const sw = b === 0 ? -1 : 1\n const qx = cx + su * hx * ax[0] + sw * hz * az[0]\n const qz = cz + su * hx * ax[2] + sw * hz * az[2]\n minX = Math.min(minX, qx)\n maxX = Math.max(maxX, qx)\n minZ = Math.min(minZ, qz)\n maxZ = Math.max(maxZ, qz)\n highest = Math.max(highest, cy + su * hx * ax[1] + sw * hz * az[1])\n }\n }\n // deep enough that its bottom face is under the solid's bottom everywhere (a box made only as deep as its block's upright box let what it pushed out the bottom through:\n // 17 of the 48 boxes of the push-up sweep fell, as with a730b5450's slab), unless its bottom would lean (uphill: by -n per metre of thickness) past the ring\n const deep = (highest - bottom) / n[1]\n const fits = Math.min(thickWithin(-n[0], minX, maxX, loX, hiX), thickWithin(-n[2], minZ, maxZ, loZ, hiZ))\n const thick = Math.max(SOLID_THINNEST, Math.min(deep, fits))\n if (fits < thick) {\n if (span > SOLID_MIN_CELLS) return false\n level(i0, j0, i1, j1, least)\n return true\n }\n const hy = thick / 2\n const centre = reachBox.c\n centre[0] = cx - n[0]! * hy\n centre[1] = cy - n[1]! * hy\n centre[2] = cz - n[2]! * hy\n reachBox.half[0] = hx\n reachBox.half[1] = hy\n reachBox.half[2] = hz\n const reach = reachOf(reachBox, reachTile)\n if (reach.ring > reach.tile + SEAM_SPLIT && span > SOLID_MIN_CELLS) return false\n const drop = SOLID_MARGIN + Math.max(reach.tile, reach.ring)\n // lowered further than the block's own relief, its top would be further under the ground than the upright box's\n if (drop - SOLID_MARGIN >= most - least) {\n level(i0, j0, i1, j1, least)\n return true\n }\n // and under it the block's upright box: what slips between two turned boxes (they part under their tops; a cell's overlap closes only so deep) rests on it, no\n // further under the ground than the block's relief\n level(i0, j0, i1, j1, least)\n const q = quatOfAxes(ax, n, az)\n boxes.push(centre[0]!, centre[1]! - drop, centre[2]!, hx, hy, hz, q[0], q[1], q[2], q[3])\n return true\n }\n\n const fill = (i0: number, j0: number, i1: number, j1: number): void => {\n let least = Infinity\n let most = -Infinity\n for (let j = j0; j <= j1; j++) {\n for (let i = i0; i <= i1; i++) {\n const h = at(i, j)\n if (h < least) least = h\n if (h > most) most = h\n }\n }\n if (most - least <= SOLID_RELIEF) return level(i0, j0, i1, j1, least)\n const span = Math.max(i1 - i0, j1 - j0)\n if ((planeGap(i0, j0, i1, j1) > SOLID_RELIEF && span > SOLID_MIN_CELLS) || !sloped(i0, j0, i1, j1, least, most)) {\n // in halves (a side under two cells stays whole), x's halves first\n const im = i1 - i0 < 2 ? i1 : (i0 + i1) >> 1\n const jm = j1 - j0 < 2 ? j1 : (j0 + j1) >> 1\n for (let a = i0; a < i1; a = im) {\n const b = a === i0 ? im : i1\n for (let d = j0; d < j1; d = jm) {\n const e = d === j0 ? jm : j1\n fill(a, d, b, e)\n if (e === j1) break\n }\n if (b === i1) break\n }\n }\n }\n fill(0, 0, cells, cells)\n return { boxes, ring: ring.read }\n}\n\n/** The same blocks. */\nexport const sameSolid = (a: SolidVolume, b: SolidVolume): boolean => same(a.boxes, b.boxes)\n\n/** The same numbers, in order (plain or typed arrays alike). */\nexport const sameNumbers = (a: ArrayLike<number>, b: ArrayLike<number>): boolean => {\n if (a.length !== b.length) return false\n for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false\n return true\n}\n\nconst same = sameNumbers\n","import type { HeightPatch } from '@adatechnology/game-terrain'\n\nimport { NO_SOLID, buildSolidVolume } from './engine-ground-solid'\nimport type { SolidVolume } from './engine-ground-solid'\nimport { collisionFieldOf } from './engine-ground-collision'\nimport { holdsStep } from './engine-ground-step'\n\n/**\n * The ground a physics engine stands the pieces on, one tile of `groundAt` at a time: a height field over the cell corners for what is smooth, and solid boxes\n * for the cells a hard step runs through (a crater's rim, a terraced slope) and the cells around them. A box's top is its cell's centre height and its\n * sides are vertical, so a step keeps its edge (within half a cell of where it is) instead of a ramp one cell wide; under the boxes the height field is lowered so\n * it does not ramp up through them. A level tile is one slab, solid below.\n *\n * Why not triangles: the step-keeping triangle mesh this replaces was one-sided (a thin piece pressed half through a triangle fell through for good) and had to be\n * made again, as a new body, for every change, which threw away the engine's contact cache. A height field of the same tile is made in about 0.3 ms and can be\n * swapped on the same body (`EnginePieces`), so the pieces on it keep their contacts.\n *\n * The tile is read at `GROUND_CELL`; the engine collides with every second corner of it, a 5 cm field (`engine-ground-collision`, owner decision 2026-11-17), and the solid\n * under it stays under both.\n */\n\n/** Cells of a tile (m), as Rapier's spike measured good enough for a 4 cm plate. */\nexport const GROUND_CELL = 0.025\n/** How far (m) under the lowest ground around them the step boxes go, and how far the height field drops under them. */\nconst BOX_DEPTH = 0.05\nconst UNDER_BOX = 0.01\n\nexport interface GroundTile {\n /** Corner heights, `(cells + 1)^2`, x fastest: `heights[iz * (cells + 1) + ix]`. Empty when the tile is level. */\n readonly heights: Float32Array\n readonly cells: number\n /** The height field the engine collides with (`engine-ground-collision`): every `cells / collisionCells`-th corner of `heights`, `(collisionCells + 1)^2`. Empty when level. */\n readonly collision: Float32Array\n readonly collisionCells: number\n /** The step boxes: centre x, y, z and half x, y, z, six numbers each (a typed array when the tile came from a worker, `engine-ground-job`). */\n readonly boxes: readonly number[] | Float64Array\n /** The solid under the height field (`engine-ground-solid`); none when the tile is level (a slab is solid already). */\n readonly solid: SolidVolume\n /** The height of a level tile (every sample equal), or null. */\n readonly level: number | null\n /** Every sample read, to tell whether the ground changed since; null for a tile proved level from the terrain's own bounds (`flatTile`), whose samples were never read. */\n readonly samples: Float64Array | null\n /** The terrain's vertices the tile was made from (`readGroundPatch`; its samples are then null): what tells whether the ground changed since. */\n readonly patch?: HeightPatch\n}\n\nconst NO_HEIGHTS = new Float32Array(0)\n/** One cell's nine samples, for `holdsStep`. */\nconst cellSamples = new Float64Array(9)\n\n/** The tile of a level `size` at `level`, laid without a sample read: the caller has proved, from the ground's own data, that every sample there is `level` (to 1e-9, as `shapeGround` calls level). */\nexport const flatTile = (level: number, size: number): GroundTile => ({ heights: NO_HEIGHTS, cells: Math.round(size / GROUND_CELL), collision: NO_HEIGHTS, collisionCells: 0, boxes: [], solid: NO_SOLID, level, samples: null })\n\n/** A rectangle of the ground, world x and z. */\nexport interface GroundRect {\n readonly minX: number\n readonly maxX: number\n readonly minZ: number\n readonly maxZ: number\n}\n\n/**\n * The four series of samples of a tile, one after the other in `samples`: the corners, the cells' centres, the middles of the edges along x and those along z.\n * `ox` and `oz` are where the series sits in a cell (0 or half), `width` and `rows` how many samples it has along x and along z.\n */\nconst seriesOf = (n: number): ReadonlyArray<{ offset: number; width: number; rows: number; ox: number; oz: number }> => {\n const m = n + 1\n return [\n { offset: 0, width: m, rows: m, ox: 0, oz: 0 },\n { offset: m * m, width: n, rows: n, ox: 0.5, oz: 0.5 },\n { offset: m * m + n * n, width: n, rows: m, ox: 0.5, oz: 0 },\n { offset: m * m + n * n + n * m, width: m, rows: n, ox: 0, oz: 0.5 },\n ]\n}\n\n/** The `samples` array of a tile of `n` cells. */\nexport const sampleCount = (n: number): number => (n + 1) * (n + 1) + n * n + 2 * n * (n + 1)\n\n/**\n * The ground over a lattice in one pass: the height at (`xs[i]`, `zs[j]`) into `out[j * xs.length + i]`, to the bit what the tile's `groundAt` answers at each point\n * (`Terrain.heightGrid` is one). A tile reads its 26 000 samples through it instead of a call each.\n */\nexport type GroundGrid = (xs: ArrayLike<number>, zs: ArrayLike<number>, out: Float64Array) => void\n\n// the points a grid read asks for and what it answers, kept between reads (one at a time) so a read does not make them again\nlet seriesX = new Float64Array(0)\nlet seriesZ = new Float64Array(0)\nlet seriesHeights = new Float64Array(0)\n\n/**\n * Reads the ground of the tile at (x0, z0) into `samples`: every sample, or only those a rectangle reaches (a sample a cell outside it is read too, so what the\n * rectangle's edge touches is not left old). True when a sample read differs from the one held. A crater in a corner of a tile asks `groundAt` for the corner.\n * With a `grid` each series is read in one pass over its own points, each the one `groundAt` would be asked for (`x0 + (i + ox) * c`), so the same heights.\n * Not reentrant: the points are module scratch, so neither reader may read a tile in turn.\n */\nexport const readGround = (groundAt: (x: number, z: number) => number, samples: Float64Array, x0: number, z0: number, size: number, rect?: GroundRect, grid?: GroundGrid): boolean => {\n const n = Math.round(size / GROUND_CELL)\n const c = size / n\n let changed = false\n for (const { offset, width, rows, ox, oz } of seriesOf(n)) {\n const i0 = rect ? Math.max(0, Math.floor((rect.minX - x0) / c - ox)) : 0\n const i1 = rect ? Math.min(width - 1, Math.ceil((rect.maxX - x0) / c - ox)) : width - 1\n const j0 = rect ? Math.max(0, Math.floor((rect.minZ - z0) / c - oz)) : 0\n const j1 = rect ? Math.min(rows - 1, Math.ceil((rect.maxZ - z0) / c - oz)) : rows - 1\n if (i0 > i1 || j0 > j1) continue\n if (!grid) {\n for (let j = j0; j <= j1; j++) {\n for (let i = i0; i <= i1; i++) {\n const h = groundAt(x0 + (i + ox) * c, z0 + (j + oz) * c)\n if (samples[offset + j * width + i] !== h) changed = true\n samples[offset + j * width + i] = h\n }\n }\n continue\n }\n const across = i1 - i0 + 1\n const along = j1 - j0 + 1\n if (seriesX.length < across) seriesX = new Float64Array(across)\n if (seriesZ.length < along) seriesZ = new Float64Array(along)\n if (seriesHeights.length < across * along) seriesHeights = new Float64Array(across * along)\n for (let i = 0; i < across; i++) seriesX[i] = x0 + (i0 + i + ox) * c\n for (let j = 0; j < along; j++) seriesZ[j] = z0 + (j0 + j + oz) * c\n grid(seriesX.subarray(0, across), seriesZ.subarray(0, along), seriesHeights)\n for (let j = 0; j < along; j++) {\n const from = j * across\n const to = offset + (j0 + j) * width + i0\n if (!changed) {\n for (let i = 0; i < across; i++) {\n if (samples[to + i] !== seriesHeights[from + i]) {\n changed = true\n break\n }\n }\n }\n samples.set(seriesHeights.subarray(from, from + across), to)\n }\n }\n return changed\n}\n\nexport const buildGroundTile = (groundAt: (x: number, z: number) => number, x0: number, z0: number, size: number, withSolid = true, grid?: GroundGrid): GroundTile => {\n const samples = new Float64Array(sampleCount(Math.round(size / GROUND_CELL)))\n readGround(groundAt, samples, x0, z0, size, undefined, grid)\n return shapeGround(samples, x0, z0, size, withSolid ? groundAt : null)\n}\n\n/**\n * The tile the samples make: level, or its height field, step boxes and (given the ground, which it reads past the tile's edges; else `NO_SOLID`, for a caller that may\n * not need it) the solid under it. Pure of the samples (and that ground), so a tile made from samples patched in place is the one made from all of them read again, but\n * for its collision field near the bound, which keeps the coarse one it had (`wasCoarse`, `collisionFieldOf`).\n */\nexport const shapeGround = (samples: Float64Array, x0: number, z0: number, size: number, solidGround: ((x: number, z: number) => number) | null, wasCoarse = false): GroundTile => {\n const n = Math.round(size / GROUND_CELL)\n const c = size / n\n const m = n + 1\n const [cornerSeries, centreSeries, midXSeries, midZSeries] = seriesOf(n)\n const corners = samples.subarray(cornerSeries!.offset, centreSeries!.offset)\n const centres = samples.subarray(centreSeries!.offset, midXSeries!.offset)\n const midX = samples.subarray(midXSeries!.offset, midZSeries!.offset)\n const midZ = samples.subarray(midZSeries!.offset)\n let low = Infinity\n let high = -Infinity\n for (const h of samples) {\n low = Math.min(low, h)\n high = Math.max(high, h)\n }\n if (high - low < 1e-9) return { heights: new Float32Array(0), cells: n, collision: NO_HEIGHTS, collisionCells: 0, boxes: [], solid: NO_SOLID, level: high, samples }\n const corner = (i: number, j: number): number => corners[j * m + i]\n // a cell whose centre or an edge's middle leaves its corners holds a step; it and the cells around it become boxes\n const mask = new Uint8Array(n * n)\n for (let j = 0; j < n; j++) {\n for (let i = 0; i < n; i++) {\n cellSamples[0] = corner(i, j)\n cellSamples[1] = corner(i + 1, j)\n cellSamples[2] = corner(i, j + 1)\n cellSamples[3] = corner(i + 1, j + 1)\n cellSamples[4] = centres[j * n + i]\n cellSamples[5] = midX[j * n + i]\n cellSamples[6] = midX[(j + 1) * n + i]\n cellSamples[7] = midZ[j * m + i]\n cellSamples[8] = midZ[j * m + i + 1]\n if (!holdsStep(cellSamples)) continue\n for (let dj = -1; dj <= 1; dj++) for (let di = -1; di <= 1; di++) if (i + di >= 0 && j + dj >= 0 && i + di < n && j + dj < n) mask[(j + dj) * n + i + di] = 1\n }\n }\n const heights = new Float32Array(m * m)\n for (let j = 0; j <= n; j++) {\n for (let i = 0; i <= n; i++) {\n // a corner whose four cells are all boxes goes under the lowest of them\n let inside = true\n let least = corner(i, j)\n for (let dj = -1; dj <= 0 && inside; dj++) for (let di = -1; di <= 0; di++) {\n const ii = i + di, jj = j + dj\n if (ii < 0 || jj < 0 || ii >= n || jj >= n || !mask[jj * n + ii]) {\n inside = false\n break\n }\n least = Math.min(least, centres[jj * n + ii], corner(ii, jj), corner(ii + 1, jj), corner(ii, jj + 1), corner(ii + 1, jj + 1))\n }\n heights[j * m + i] = inside ? least - UNDER_BOX : corner(i, j)\n }\n }\n // the boxes: runs along x of masked cells at one height, down to under the lowest ground around them\n const boxes: number[] = []\n for (let j = 0; j < n; j++) {\n let i = 0\n while (i < n) {\n if (!mask[j * n + i]) {\n i++\n continue\n }\n const top = centres[j * n + i]\n let end = i + 1\n while (end < n && mask[j * n + end] && Math.abs(centres[j * n + end] - top) < 0.001) end++\n let bottom = top\n for (let k = Math.max(0, i - 1); k <= Math.min(n, end + 1); k++) for (let jj = Math.max(0, j - 1); jj <= Math.min(n, j + 2); jj++) bottom = Math.min(bottom, corner(k, jj))\n bottom -= BOX_DEPTH\n boxes.push(x0 + ((i + end) / 2) * c, (top + bottom) / 2, z0 + (j + 0.5) * c, ((end - i) * c) / 2, (top - bottom) / 2, c / 2)\n i = end\n }\n }\n const { step, field } = collisionFieldOf(heights, n, c, boxes.length > 0, wasCoarse)\n return { heights, cells: n, collision: field, collisionCells: n / step, boxes, solid: solidGround ? buildSolidVolume(heights, n, x0, z0, c, solidGround, step) : NO_SOLID, level: null, samples }\n}\n","import { fitOrientedBox, hugs } from '@adatechnology/game-shapes'\nimport type { OrientedBox } from '@adatechnology/game-shapes'\n\nimport { isRoundSolid } from './built-solids'\nimport type { BuiltSolid } from './built-solids'\nimport type { StaticSolid } from './engine-statics'\n\n/** A box fits a drawn part when each of its eight corners has a vertex within this (m): a box drawn is a box held, a cylinder or a chamfered post is not. */\nconst FIT = 0.01\n/** A box holds a part only when the part's own triangles lie in each of its faces and cover at least this share of the face (a raised panel leaves its edge short, a frame leaves most of it open): a door frame (two posts and a lintel) has a box's eight corners and none of its faces. */\nconst FILL = 0.5\n/** A box holds a part only when the part's triangles enclose at least this share of the box: boards round the air (a kennel, a crate, a cabinet drawn as one part) have a box's corners and cover its faces, and what is inside them is not theirs. */\nconst SOLID = 0.5\n/** The thinnest half (m) a drawn plane (a sheet with no thickness) is held by. */\nconst MIN_HALF = 0.005\n/** A part whose every side is under this (m) is collapsed to a point (hidden by its host): nothing is drawn there. */\nconst COLLAPSED = 0.002\n/** A face of a box under this area (m²) is a plane's edge: it has nothing to cover. */\nconst MIN_FACE = 1e-6\n\ntype Points = ArrayLike<number>\n\n/**\n * One fixed drawn part to measure (`measureStaticPart`): plain arrays, so it crosses to a worker (`destruction.static-colliders`). The main thread reads the vertices,\n * the triangles and the mesh's world matrix (with three's own `decompose` of it); the measuring is here.\n */\nexport interface StaticPartJob {\n /** The part's vertices in the mesh's frame, three numbers each, with what another drawing collapses there already collapsed. */\n readonly points: Float64Array\n /** The mesh's world matrix (16 numbers, column major). */\n readonly matrix: Float64Array\n /** The world matrix decomposed (three's `Matrix4.decompose`): position, quaternion (x, y, z, w) and scale. */\n readonly position: readonly [number, number, number]\n readonly quaternion: readonly [number, number, number, number]\n readonly scale: readonly [number, number, number]\n /** The triangles of the part as vertex numbers of the host (three each), `from` its first vertex. */\n readonly found: Uint32Array\n readonly from: number\n /** The solids the mesh was built from (`builtSolidsOf`), in the mesh's frame: with them the part is those boxes, and nothing is measured. */\n readonly solids?: readonly BuiltSolid[]\n}\n\nconst IDENTITY = [1, 0, 0, 0, 1, 0, 0, 0, 1]\n\n/** The axes (three rows of 3) of a box turned by the quaternion. */\nconst axesOfQuat = (x: number, y: number, z: number, w: number): number[] => [\n 1 - 2 * (y * y + z * z), 2 * (x * y + z * w), 2 * (x * z - y * w),\n 2 * (x * y - z * w), 1 - 2 * (x * x + z * z), 2 * (y * z + x * w),\n 2 * (x * z + y * w), 2 * (y * z - x * w), 1 - 2 * (x * x + y * y),\n]\n\n/** The point turned by the unit quaternion, in the very operations of three's `Vector3.applyQuaternion` (r160), so the numbers are the same bits. */\nconst turn = (vx: number, vy: number, vz: number, q: readonly [number, number, number, number]): [number, number, number] => {\n const [qx, qy, qz, qw] = q\n const tx = 2 * (qy * vz - qz * vy)\n const ty = 2 * (qz * vx - qx * vz)\n const tz = 2 * (qx * vy - qy * vx)\n return [vx + qw * tx + qy * tz - qz * ty, vy + qw * ty + qz * tx - qx * tz, vz + qw * tz + qx * ty - qy * tx]\n}\n\n/**\n * What a fixed drawn part collides as, in world space, for an engine: one box turned as drawn where a box fits it (every corner has a vertex within `FIT`, its\n * triangles cover its faces and enclose `SOLID` of it), else the box turned to fit the world vertices where that one fits, else the triangles as drawn (`mesh`, static only). A part collapsed to\n * a point is nothing (`CLAUDE.md` §12). A pure function of the job: the worker and the main thread give the same bits (`staticCollidersKind`).\n */\nexport function measureStaticPart(job: StaticPartJob): StaticSolid[] {\n const { points, matrix, position: pos, quaternion: quat, scale, found, from } = job\n const low = [Infinity, Infinity, Infinity]\n const high = [-Infinity, -Infinity, -Infinity]\n for (let i = 0; i < points.length; i += 3) {\n for (let k = 0; k < 3; k++) {\n const v = points[i + k]\n if (v < low[k]) low[k] = v\n if (v > high[k]) high[k] = v\n }\n }\n const size = [high[0] - low[0], high[1] - low[1], high[2] - low[2]]\n const s = [Math.abs(scale[0]), Math.abs(scale[1]), Math.abs(scale[2])]\n if (Math.max(size[0] * s[0], size[1] * s[1], size[2] * s[2]) < COLLAPSED) return []\n // what the builder drew, box by box (spec 019): the part is that, turned and put where the mesh is\n if (job.solids && job.solids.length > 0) return job.solids.map((solid) => builtSolidIn(solid, pos, quat, scale))\n const centre = [(low[0] + high[0]) / 2, (low[1] + high[1]) / 2, (low[2] + high[2]) / 2]\n const half = [size[0] / 2, size[1] / 2, size[2] / 2]\n // the box of the geometry in its own frame, turned by the mesh: the drawn box of a wall, a table top, a beam\n const straight = { center: centre, half, axes: IDENTITY, tolerance: [FIT / s[0], FIT / s[1], FIT / s[2]] }\n if (hugs(points, straight) && fillsFaces(points, found, from, straight) && fillsVolume(points, found, from, straight)) {\n const [cx, cy, cz] = turn(centre[0] * scale[0], centre[1] * scale[1], centre[2] * scale[2], quat)\n return [{ center: [cx + pos[0], cy + pos[1], cz + pos[2]], half: [Math.max(MIN_HALF, half[0] * s[0]), Math.max(MIN_HALF, half[1] * s[1]), Math.max(MIN_HALF, half[2] * s[2])], rotation: [quat[0], quat[1], quat[2], quat[3]] }]\n }\n const world = new Float64Array(points.length)\n const e = matrix\n for (let i = 0; i < points.length; i += 3) {\n const x = points[i], y = points[i + 1], z = points[i + 2]\n world[i] = e[0] * x + e[4] * y + e[8] * z + e[12]\n world[i + 1] = e[1] * x + e[5] * y + e[9] * z + e[13]\n world[i + 2] = e[2] * x + e[6] * y + e[10] * z + e[14]\n }\n const turned = fitOrientedBox(world as unknown as number[])\n if (turned && fitsTurned(world, turned) && fillsFaces(world, found, from, turnedBox(turned)) && fillsVolume(world, found, from, turnedBox(turned))) return [turned]\n return [trimeshOf(world, from, found)]\n}\n\n/** A solid of the mesh (its frame) as a box of the world: carried by the mesh's place, turn and scale. A turned solid keeps its shape under one scale only, so the mean of the three stands for a mesh scaled unevenly. */\nconst builtSolidIn = (solid: BuiltSolid, pos: readonly number[], quat: readonly [number, number, number, number], scale: readonly number[]): StaticSolid => {\n const [cx, cy, cz] = turn(solid.center[0] * scale[0], solid.center[1] * scale[1], solid.center[2] * scale[2], quat)\n const [ax, ay, az, aw] = quat\n const [bx, by, bz, bw] = solid.rotation\n const turned = Math.abs(bw) < 1 - 1e-9\n const even = (Math.abs(scale[0]) + Math.abs(scale[1]) + Math.abs(scale[2])) / 3\n const s = turned ? [even, even, even] : [Math.abs(scale[0]), Math.abs(scale[1]), Math.abs(scale[2])]\n return {\n ...(isRoundSolid(solid) && Math.abs(s[0] - s[2]) <= 1e-9 ? { round: true as const } : {}),\n center: [cx + pos[0], cy + pos[1], cz + pos[2]],\n half: [Math.max(MIN_HALF, solid.half[0] * s[0]), Math.max(MIN_HALF, solid.half[1] * s[1]), Math.max(MIN_HALF, solid.half[2] * s[2])],\n // the mesh's turn, then the solid's own\n rotation: [aw * bx + ax * bw + ay * bz - az * by, aw * by - ax * bz + ay * bw + az * bx, aw * bz + ax * by - ay * bx + az * bw, aw * bw - ax * bx - ay * by - az * bz],\n }\n}\n\n/** The buffers of a measured part to transfer back (the triangles of a trimesh). */\nexport const staticSolidsTransfer = (solids: readonly StaticSolid[]): ArrayBuffer[] => {\n const out: ArrayBuffer[] = []\n for (const solid of solids) if (solid.mesh) out.push(solid.mesh.vertices.buffer as ArrayBuffer, solid.mesh.indices.buffer as ArrayBuffer)\n return out\n}\n\ntype FitBox = { readonly center: readonly number[]; readonly half: readonly number[]; readonly axes: readonly number[]; readonly tolerance: readonly number[] }\n\nconst turnedBox = (box: OrientedBox): FitBox => ({ center: box.center, half: box.half, axes: axesOfQuat(box.rotation[0], box.rotation[1], box.rotation[2], box.rotation[3]), tolerance: [FIT, FIT, FIT] })\n\nconst fitsTurned = (world: Points, box: OrientedBox): boolean => hugs(world, turnedBox(box))\n\n/** The area of the triangle a, b, c (box frame, three numbers each). */\nconst areaOf = (a: ArrayLike<number>, b: ArrayLike<number>, c: ArrayLike<number>): number => {\n const ux = b[0] - a[0], uy = b[1] - a[1], uz = b[2] - a[2]\n const vx = c[0] - a[0], vy = c[1] - a[1], vz = c[2] - a[2]\n return Math.hypot(uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx) / 2\n}\n\n/** Whether the part's triangles (`found`: vertex numbers of the host, `from` the first of the part) cover each face of the box that has an area: what a box that fits holds is the part, not the air in it. */\nconst fillsFaces = (points: Points, found: ArrayLike<number>, from: number, box: FitBox): boolean => {\n if (found.length === 0) return true\n const covered = [0, 0, 0, 0, 0, 0]\n const frame = [new Float64Array(3), new Float64Array(3), new Float64Array(3)]\n const a = box.axes\n for (let i = 0; i + 2 < found.length; i += 3) {\n for (let v = 0; v < 3; v++) {\n const at = (found[i + v] - from) * 3\n const dx = points[at] - box.center[0], dy = points[at + 1] - box.center[1], dz = points[at + 2] - box.center[2]\n for (let k = 0; k < 3; k++) frame[v][k] = dx * a[k * 3] + dy * a[k * 3 + 1] + dz * a[k * 3 + 2]\n }\n let area = -1\n for (let k = 0; k < 3; k++) for (let side = 0; side < 2; side++) {\n const face = side ? box.half[k] : -box.half[k]\n if (Math.abs(frame[0][k] - face) > box.tolerance[k] || Math.abs(frame[1][k] - face) > box.tolerance[k] || Math.abs(frame[2][k] - face) > box.tolerance[k]) continue\n if (area < 0) area = areaOf(frame[0], frame[1], frame[2])\n covered[k * 2 + side] += area\n }\n }\n for (let k = 0; k < 3; k++) {\n const area = 4 * box.half[(k + 1) % 3] * box.half[(k + 2) % 3]\n if (area < MIN_FACE) continue\n if (covered[k * 2] < area * FILL || covered[k * 2 + 1] < area * FILL) return false\n }\n return true\n}\n\n/**\n * Whether the part's triangles enclose at least `SOLID` of the box (the volume they close about the box's centre, whichever way the mesh is wound): a hollow thing covers the\n * faces of the box around it and holds only its boards. A sheet with no thickness encloses nothing and neither does its box: it is held as before.\n */\nconst fillsVolume = (points: Points, found: ArrayLike<number>, from: number, box: FitBox): boolean => {\n if (found.length === 0) return true\n const whole = 8 * box.half[0] * box.half[1] * box.half[2]\n if (!(whole > 0)) return true\n const [cx, cy, cz] = box.center\n let six = 0\n for (let i = 0; i + 2 < found.length; i += 3) {\n const a = (found[i] - from) * 3, b = (found[i + 1] - from) * 3, c = (found[i + 2] - from) * 3\n const ax = points[a] - cx, ay = points[a + 1] - cy, az = points[a + 2] - cz\n const bx = points[b] - cx, by = points[b + 1] - cy, bz = points[b + 2] - cz\n const dx = points[c] - cx, dy = points[c + 1] - cy, dz = points[c + 2] - cz\n six += ax * (by * dz - bz * dy) + ay * (bz * dx - bx * dz) + az * (bx * dy - by * dx)\n }\n return Math.abs(six) / 6 >= whole * SOLID\n}\n\n/** The triangles of the part in world space (its vertices and the triangles of the geometry that start in its range), with the box around them as the box of the solid. */\nconst trimeshOf = (world: Float64Array, from: number, found: ArrayLike<number>): StaticSolid => {\n const indices = new Uint32Array(found.length)\n for (let i = 0; i < found.length; i++) indices[i] = found[i] - from\n const lo = [Infinity, Infinity, Infinity]\n const hi = [-Infinity, -Infinity, -Infinity]\n for (let i = 0; i < world.length; i += 3) {\n for (let k = 0; k < 3; k++) {\n lo[k] = Math.min(lo[k], world[i + k])\n hi[k] = Math.max(hi[k], world[i + k])\n }\n }\n return {\n center: [(lo[0] + hi[0]) / 2, (lo[1] + hi[1]) / 2, (lo[2] + hi[2]) / 2],\n half: [Math.max(MIN_HALF, (hi[0] - lo[0]) / 2), Math.max(MIN_HALF, (hi[1] - lo[1]) / 2), Math.max(MIN_HALF, (hi[2] - lo[2]) / 2)],\n rotation: [0, 0, 0, 1],\n mesh: { vertices: new Float32Array(world), indices },\n }\n}\n","/**\n * One solid a mesh was built from (spec 019): its own box in the mesh's space, turned as it was drawn (`rotation`: x, y, z, w). The builder of the mesh lists them in\n * `userData.solids` (`ShapeSolid` of game-shapes, by the mesh api of game-interactables-three): the piece is then held by what was drawn, with no vertex read back.\n */\nexport interface BuiltSolid {\n readonly center: readonly [number, number, number]\n readonly half: readonly [number, number, number]\n readonly rotation: readonly [number, number, number, number]\n /** What drew it (`'box'`, `'cylinder'`...): a cylinder is held as a cylinder along its own y. */\n readonly kind?: string\n}\n\nconst numbers = (value: unknown, count: number): value is readonly number[] => Array.isArray(value) && value.length === count && value.every((v) => typeof v === 'number' && Number.isFinite(v))\n\nconst isBuiltSolid = (value: unknown): value is BuiltSolid => {\n if (typeof value !== 'object' || value === null) return false\n const solid = value as { center?: unknown; half?: unknown; rotation?: unknown; kind?: unknown }\n return numbers(solid.center, 3) && numbers(solid.half, 3) && numbers(solid.rotation, 4) && (solid.kind === undefined || typeof solid.kind === 'string')\n}\n\n/**\n * The solids a mesh says it was built from, or null when it says none (a house, a vehicle, a mesh made by hand: those are measured from what is drawn). The list comes\n * from another package through `userData`, so it is read as data: one entry that is not a solid and the whole list is not used.\n */\nexport const builtSolidsOf = (mesh: { readonly userData: Record<string, unknown> }): readonly BuiltSolid[] | null => {\n const list = mesh.userData.solids\n if (!Array.isArray(list) || list.length === 0 || !list.every(isBuiltSolid)) return null\n return list\n}\n\n/** How far apart (a share of the larger) the two halves across a cylinder may be for it to be held as a round cylinder (an oval or a cone stays a box). */\nconst ROUND_SIDES = 0.05\n\n/** Whether a solid is a straight round cylinder along its own y: drawn as one, with the two halves across it alike. */\nexport const isRoundSolid = (solid: { readonly half: readonly number[]; readonly kind?: string }): boolean =>\n solid.kind === 'cylinder' && Math.abs(solid.half[0]! - solid.half[2]!) <= ROUND_SIDES * Math.max(solid.half[0]!, solid.half[2]!)\n"],"mappings":";AAAA,SAAS,sBAAsB,sBAAsB;;;ACArD,SAAS,gBAAgB,uBAAuB;;;ACOzC,IAAM,wBAAwB;AAG9B,IAAM,sBAAsB;AAK5B,IAAM,kBAAkB;AAE/B,IAAM,eAAe;AAGd,IAAM,aAAa,CAAC,OAAe,aAA6B;AACrE,QAAM,IAAI,KAAK,IAAI,GAAG,KAAK,MAAM,wBAAwB,QAAQ,CAAC;AAClE,SAAO,QAAQ,MAAM,IAAI,IAAI;AAC/B;AAcO,IAAM,mBAAmB,CAAC,SAAuB,OAAe,UAAkB,UAAmB,YAAY,UAA0B;AAChJ,QAAM,IAAI,WAAW,OAAO,QAAQ;AACpC,QAAM,OAAO,EAAE,MAAM,GAAG,OAAO,QAAQ;AACvC,MAAI,MAAM,KAAK,YAAY,QAAQ,WAAW,EAAG,QAAO;AACxD,QAAM,IAAI,QAAQ;AAClB,QAAM,MAAM,CAAC,GAAW,MAAsB,QAAQ,IAAI,IAAI,CAAC;AAC/D,MAAIA,OAAM;AACV,WAAS,IAAI,GAAG,KAAK,OAAO,KAAK;AAC/B,a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