@adatechnology/game-terrain 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/index.d.ts +121 -2
- package/dist/index.global.js +375 -7
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +375 -7
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@ terrain.heightAt(x, z) // what things stand on
|
|
|
20
20
|
- **What comes out**: soft ground heaps a rim and throws clods that land and join the height field, so they can be walked over; rigid material throws chips that stay as rubble. Loose ground slides to its angle of repose.
|
|
21
21
|
- **Fire**: `fire` of each material says how black it gets and whether it burns away and spreads: turf and wood char and carry the fire, concrete only soots.
|
|
22
22
|
- **Feet** (`footing` of a material): `footAt` is the height a foot stands at, `walkFactorAt` what is left of the speed, `press` the print it leaves (`createFootprints` keeps the trail of a walker, a wheel presses with `kind: 'rut'`).
|
|
23
|
+
- **Rolling** (`rolling` of a material, C_rr): how much the ground holds back a round thing rolling on it — sand and mud 0.3, turf 0.15, soil and gravel 0.08, asphalt and concrete 0.015 (sources in `catalog.ts`). A host hands it to the pieces (`RendererOptions.terrainRollingAt` of `game-destruction-three`): `(x, z) => terrain.rollingAt(x, z)` (the exposed material's, without building a column).
|
|
23
24
|
- **Decals** (`decals()`): marks with no depth, under `budget.maxDecals`: cracks of a brittle crust (`cracks`), splats where the pieces of a wet ground land (`splats`), prints and ruts, rings on water.
|
|
24
25
|
- **Pieces** (`units` of a material): cobbles and pavers are not dug. A blow adds to the joules each piece has taken, and past `looseJoules` the piece comes off its bed whole and is thrown, showing the sand under it.
|
|
25
26
|
- **Loose stones** (`scatters`): gravel throws stones that stay as loose stones instead of joining the height field.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
import { GroundLayout, Hit, GroundLoss, DestructibleImpl } from '@adatechnology/game-contracts';
|
|
2
|
-
export { GroundLayout, GroundZone } from '@adatechnology/game-contracts';
|
|
2
|
+
export { GroundExcavation, GroundLayout, GroundZone } from '@adatechnology/game-contracts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The ground's blend as pure functions of numbers, shared by `Terrain.heightAt`, `Terrain.heightGrid` and `heightPatchGrid`: the same code reads the terrain on the main
|
|
6
|
+
* thread and a copy of its vertices anywhere else (a worker has no terrain), so the heights agree to the bit.
|
|
7
|
+
*/
|
|
8
|
+
/** Where `v` falls along an axis of `count` cells of `cellSize` from `origin`, in cells, held inside the last cell: its whole part is the cell, the rest the blend across it. */
|
|
9
|
+
declare const cellCoordinate: (v: number, origin: number, count: number, cellSize: number) => number;
|
|
10
|
+
/** The blend of two heights, `t` of the way from `near` to `far` (the one step every blend of the ground is made of). */
|
|
11
|
+
declare const blendHeights: (near: number, far: number, t: number) => number;
|
|
12
|
+
/**
|
|
13
|
+
* The terrain's vertex heights (`base - dug + loose`, as `heightAt` reads them) over a block of its cells, with what places them in the terrain: plain numbers, so a worker
|
|
14
|
+
* can read the ground from them (`heightPatchGrid`) and answer what `heightGrid` does there, to the bit. Made by `Terrain.heightPatch`.
|
|
15
|
+
*/
|
|
16
|
+
interface HeightPatch {
|
|
17
|
+
readonly cellSize: number;
|
|
18
|
+
/** The terrain's first vertex (its bounds' min x and z) and its cells along x and z: where a point's cell is found, with its clamps. */
|
|
19
|
+
readonly originX: number;
|
|
20
|
+
readonly originZ: number;
|
|
21
|
+
readonly columns: number;
|
|
22
|
+
readonly rows: number;
|
|
23
|
+
/** The patch's first vertex (column and row of the terrain) and how many vertices it has along x and along z. */
|
|
24
|
+
readonly column0: number;
|
|
25
|
+
readonly row0: number;
|
|
26
|
+
readonly width: number;
|
|
27
|
+
readonly depth: number;
|
|
28
|
+
/** The heights, `width` per row, rows from `row0`: `heights[(row - row0) * width + column - column0]` (the array may be longer). */
|
|
29
|
+
readonly heights: Float64Array;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The ground over a lattice from a patch: the height at (`xs[i]`, `zs[j]`) into `out[j * xs.length + i]`, to the bit what the terrain's `heightGrid` answers there (the same
|
|
33
|
+
* cell, clamps and blends, on the same vertex heights). Every point must lie inside the terrain and over the patch's cells (`Terrain.heightPatch` of a rectangle holding
|
|
34
|
+
* them): one that does not throws. Not reentrant (module scratch).
|
|
35
|
+
*/
|
|
36
|
+
declare function heightPatchGrid(patch: HeightPatch, xs: ArrayLike<number>, zs: ArrayLike<number>, out: Float64Array): void;
|
|
37
|
+
/** Whether two patches hold the same vertices at the same heights (the ground they read is the same, to the bit, wherever both reach). */
|
|
38
|
+
declare const samePatch: (a: HeightPatch, b: HeightPatch) => boolean;
|
|
3
39
|
|
|
4
40
|
/** The blows that remove ground. Fire and heat char it instead (`TerrainMaterial.fire`). */
|
|
5
41
|
type TerrainBlow = 'ballistic' | 'blunt' | 'slash' | 'explosive';
|
|
@@ -33,6 +69,11 @@ interface TerrainMaterial {
|
|
|
33
69
|
readonly rimShare?: number;
|
|
34
70
|
/** Steepest slope in degrees it holds; loose ground slides until it is back to it. */
|
|
35
71
|
readonly reposeDegrees?: number;
|
|
72
|
+
/** A shovel digs it: `effort` is how hard a shovelful is against loose soil (1); a material without it (concrete, stone, asphalt) is not dug by hand. */
|
|
73
|
+
readonly dig?: {
|
|
74
|
+
readonly effort: number;
|
|
75
|
+
readonly closes?: boolean;
|
|
76
|
+
};
|
|
36
77
|
readonly fire?: TerrainFireResponse;
|
|
37
78
|
/** Linear rgb, 0..1, of the material where it is exposed. */
|
|
38
79
|
readonly color: readonly [number, number, number];
|
|
@@ -44,6 +85,16 @@ interface TerrainMaterial {
|
|
|
44
85
|
readonly breach?: TerrainBreachResponse;
|
|
45
86
|
/** What a foot does on it. */
|
|
46
87
|
readonly footing?: TerrainFooting;
|
|
88
|
+
/**
|
|
89
|
+
* Its rolling resistance (C_rr) to a round thing rolling on it (a can, a rod, a casing): the moment C_rr x weight x radius that slows the roll. Soft ground (sand, mud,
|
|
90
|
+
* grass) gives under the roller and holds it back far more than a hard one (asphalt, concrete). Left out: the host's default (a hard floor).
|
|
91
|
+
*/
|
|
92
|
+
readonly rolling?: number;
|
|
93
|
+
/**
|
|
94
|
+
* Its rolling damping (1/s): the share of its spin a round thing rolling on it loses per second on top of `rolling`, from what drags more the faster it rolls (grass
|
|
95
|
+
* blades, ploughed sand). Added to the roller's own. Left out: the host's default (a hard floor).
|
|
96
|
+
*/
|
|
97
|
+
readonly rollingDamping?: number;
|
|
47
98
|
/** Liquid (of the fluids catalogue) a blow on it throws up. */
|
|
48
99
|
readonly splash?: string;
|
|
49
100
|
/** Its pieces do not join the ground where they land: they stay as loose stones. */
|
|
@@ -190,6 +241,45 @@ interface TerrainOptions {
|
|
|
190
241
|
*/
|
|
191
242
|
readonly onGroundLoss?: (loss: GroundLoss) => void;
|
|
192
243
|
}
|
|
244
|
+
/** A shovelful (`Terrain.dig`): the blade's footprint at (x, z), how deep it goes in, where the earth is thrown (a heap on the ground there). */
|
|
245
|
+
interface TerrainDig {
|
|
246
|
+
readonly x: number;
|
|
247
|
+
readonly z: number;
|
|
248
|
+
/** Width and length of the blade's bite, metres (default 0.3 x 0.3). */
|
|
249
|
+
readonly size?: readonly [number, number];
|
|
250
|
+
/** How deep one shovelful goes, metres (default 0.2). */
|
|
251
|
+
readonly depth?: number;
|
|
252
|
+
/** Where the earth lands: heaped round this point. Without it, it is lost (carried away). */
|
|
253
|
+
readonly dump?: {
|
|
254
|
+
readonly x: number;
|
|
255
|
+
readonly z: number;
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
/** What a shovelful took. */
|
|
259
|
+
interface TerrainDigResult {
|
|
260
|
+
/** Cubic metres taken out (and heaped at `dump`). */
|
|
261
|
+
readonly volume: number;
|
|
262
|
+
/** The material dug (the one at the bite's centre). */
|
|
263
|
+
readonly material: string;
|
|
264
|
+
/** How hard it was against loose soil (1): a shovelful of it takes that much longer. 0 when nothing was dug. */
|
|
265
|
+
readonly effort: number;
|
|
266
|
+
/** The material that stopped the blade (concrete, stone...), when it could not dig; `water` where the ground is under water. */
|
|
267
|
+
readonly refused?: string;
|
|
268
|
+
/** The blade lifted it but the hole closed behind it (mud): nothing changed. */
|
|
269
|
+
readonly closes?: true;
|
|
270
|
+
}
|
|
271
|
+
/** Earth thrown back into a hole (`Terrain.fill`): taken from the heap round `from`, laid into the hole at (x, z), at most `volume`. */
|
|
272
|
+
interface TerrainFill {
|
|
273
|
+
readonly x: number;
|
|
274
|
+
readonly z: number;
|
|
275
|
+
readonly size?: readonly [number, number];
|
|
276
|
+
readonly from: {
|
|
277
|
+
readonly x: number;
|
|
278
|
+
readonly z: number;
|
|
279
|
+
readonly radius: number;
|
|
280
|
+
};
|
|
281
|
+
readonly volume: number;
|
|
282
|
+
}
|
|
193
283
|
/** What is missing under a disc of the ground (`Terrain.voidUnder`). */
|
|
194
284
|
interface TerrainVoid {
|
|
195
285
|
/** Metres under the untouched surface at the deepest vertex. */
|
|
@@ -356,11 +446,36 @@ interface Terrain {
|
|
|
356
446
|
setLayout(layout: GroundLayout): void;
|
|
357
447
|
/** Height at (x, z) as things stand on it. */
|
|
358
448
|
heightAt(x: number, z: number): number;
|
|
449
|
+
/**
|
|
450
|
+
* `heightAt` over a grid, in one pass: the height at (`xs[i]`, `zs[j]`) into `out[j * xs.length + i]`, to the bit what `heightAt` answers there (the same cell, blend and
|
|
451
|
+
* vertices; past the terrain, the host's `baseHeight`). For a reader of many points on a lattice (a physics engine's ground tile), which saves a call per point.
|
|
452
|
+
* Not reentrant: it keeps its scratch between calls, so a `baseHeight` must not call it back.
|
|
453
|
+
*/
|
|
454
|
+
heightGrid(xs: ArrayLike<number>, zs: ArrayLike<number>, out: Float64Array): void;
|
|
455
|
+
/**
|
|
456
|
+
* The vertex heights under a rectangle (the cells `heightGrid` reads for any point in it), as plain numbers a worker can read the ground from (`heightPatchGrid`, to the
|
|
457
|
+
* bit what `heightGrid` answers there); null when the rectangle is not wholly inside the terrain (past it the host's `baseHeight` answers). Writes into `into` when it is
|
|
458
|
+
* long enough, else a new array. A 2.4 m square at 10 cm cells is 26 x 26 numbers.
|
|
459
|
+
*/
|
|
460
|
+
heightPatch(minX: number, maxX: number, minZ: number, maxZ: number, into?: Float64Array): HeightPatch | null;
|
|
461
|
+
/**
|
|
462
|
+
* The lowest and the highest `heightAt` can answer over the rectangle, exact bounds (the height between vertices is a blend of the four around it, so no
|
|
463
|
+
* point is under the lowest or over the highest vertex of the cells the rectangle covers); null when the rectangle is not wholly inside the terrain, where the ground is the
|
|
464
|
+
* host's `baseHeight` and no bound is known. Costs the vertices the rectangle covers, not a read per sample.
|
|
465
|
+
*/
|
|
466
|
+
heightRange(minX: number, maxX: number, minZ: number, maxZ: number): {
|
|
467
|
+
readonly low: number;
|
|
468
|
+
readonly high: number;
|
|
469
|
+
} | null;
|
|
359
470
|
/** Height of vertex (column, row). */
|
|
360
471
|
vertexHeight(column: number, row: number): number;
|
|
361
472
|
/** Material exposed at a vertex. */
|
|
362
473
|
vertexMaterial(column: number, row: number): TerrainMaterial;
|
|
363
474
|
columnAt(x: number, z: number): TerrainColumn;
|
|
475
|
+
/** The rolling resistance (`TerrainMaterial.rolling`) of the material exposed at (x, z), as `columnAt` reads it, without building the column; undefined: the host's default. */
|
|
476
|
+
rollingAt(x: number, z: number): number | undefined;
|
|
477
|
+
/** The rolling damping (`TerrainMaterial.rollingDamping`) of the material exposed at (x, z), read as `rollingAt`; undefined: the host's default. */
|
|
478
|
+
rollingDampingAt(x: number, z: number): number | undefined;
|
|
364
479
|
contains(x: number, z: number): boolean;
|
|
365
480
|
/** First point of the ground along a ray, or null. */
|
|
366
481
|
raycast(origin: readonly number[], direction: readonly number[], maxDistance: number): {
|
|
@@ -370,6 +485,10 @@ interface Terrain {
|
|
|
370
485
|
} | null;
|
|
371
486
|
/** A blow at (x, z). `energy` in joules, `direction` where it travels (it throws the pieces back along it). */
|
|
372
487
|
strike(blow: TerrainBlow, spec: TerrainStrike): TerrainBlowResult;
|
|
488
|
+
/** A shovelful at (x, z): takes the earth down through what a shovel digs, stops at what it does not (concrete, rock), heaps it at `dump`. */
|
|
489
|
+
dig(spec: TerrainDig): TerrainDigResult;
|
|
490
|
+
/** Earth thrown back from a heap into a hole: fills what was dug first, then heaps. Returns the cubic metres moved. */
|
|
491
|
+
fill(spec: TerrainFill): number;
|
|
373
492
|
/** A flame over a disc for `seconds`. */
|
|
374
493
|
burn(spec: {
|
|
375
494
|
x: number;
|
|
@@ -521,4 +640,4 @@ interface WaterLift {
|
|
|
521
640
|
/** Archimedes on a body in a liquid: what it displaces lifts it, so a light log floats and a concrete block goes to the bed. */
|
|
522
641
|
declare function waterLift(params: WaterLiftParams): WaterLift;
|
|
523
642
|
|
|
524
|
-
export { CRACK_REFERENCE_JOULES, type CrackSegment, DEFAULT_BAR_DIAMETER, DEFAULT_BAR_YIELD_JOULES, DEFAULT_BAR_YIELD_PA, DEFAULT_PROFILE, DEFAULT_TERRAIN_BUDGET, type Footprints, GROUND_LOSS_MIN_DEPTH, SLIDE_LOSS_MIN_LOWERING, TERRAIN_MATERIALS, TERRAIN_PATTERNS, TERRAIN_PROFILES, type Terrain, type TerrainBlow, type TerrainBlowResponse, type TerrainBlowResult, type TerrainBreachResponse, type TerrainBudget, type TerrainChunk, type TerrainColumn, type TerrainCrack, type TerrainCrackResponse, type TerrainDebris, type TerrainDebrisKind, type TerrainDecal, type TerrainDecalKind, type TerrainFireResponse, type TerrainFooting, type TerrainImplOptions, type TerrainLoad, type TerrainMark, type TerrainMaterial, type TerrainOptions, type TerrainPattern, type TerrainProfile, type TerrainRegion, type TerrainSnapshot, type TerrainStats, type TerrainStratum, type TerrainStrike, type TerrainUnits, type TerrainVoid, type TerrainWater, type TerrainWaterHere, VOID_MIN_DEPTH, type WaterLift, type WaterLiftParams, crackLines, createFootprints, createTerrain, createTerrainImpl, waterLift };
|
|
643
|
+
export { CRACK_REFERENCE_JOULES, type CrackSegment, DEFAULT_BAR_DIAMETER, DEFAULT_BAR_YIELD_JOULES, DEFAULT_BAR_YIELD_PA, DEFAULT_PROFILE, DEFAULT_TERRAIN_BUDGET, type Footprints, GROUND_LOSS_MIN_DEPTH, type HeightPatch, SLIDE_LOSS_MIN_LOWERING, TERRAIN_MATERIALS, TERRAIN_PATTERNS, TERRAIN_PROFILES, type Terrain, type TerrainBlow, type TerrainBlowResponse, type TerrainBlowResult, type TerrainBreachResponse, type TerrainBudget, type TerrainChunk, type TerrainColumn, type TerrainCrack, type TerrainCrackResponse, type TerrainDebris, type TerrainDebrisKind, type TerrainDecal, type TerrainDecalKind, type TerrainDig, type TerrainDigResult, type TerrainFill, type TerrainFireResponse, type TerrainFooting, type TerrainImplOptions, type TerrainLoad, type TerrainMark, type TerrainMaterial, type TerrainOptions, type TerrainPattern, type TerrainProfile, type TerrainRegion, type TerrainSnapshot, type TerrainStats, type TerrainStratum, type TerrainStrike, type TerrainUnits, type TerrainVoid, type TerrainWater, type TerrainWaterHere, VOID_MIN_DEPTH, type WaterLift, type WaterLiftParams, blendHeights, cellCoordinate, crackLines, createFootprints, createTerrain, createTerrainImpl, heightPatchGrid, samePatch, waterLift };
|