@margoengine/terrain 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +1808 -3
- package/dist/blend.d.ts +70 -0
- package/dist/blend.js +159 -0
- package/dist/colors.d.ts +164 -0
- package/dist/deform.d.ts +103 -0
- package/dist/deform.js +322 -0
- package/dist/displace.d.ts +60 -0
- package/dist/displace.js +254 -0
- package/dist/dunes.d.ts +86 -0
- package/dist/dunes.js +88 -0
- package/dist/errors-fc4i1pSL.js +7 -0
- package/dist/grid.d.ts +11 -0
- package/dist/ground-change-settings.d.ts +29 -0
- package/dist/ground-change-settings.js +69 -0
- package/dist/ground-change.d.ts +227 -0
- package/dist/ground-change.js +1291 -0
- package/dist/ground-model.d.ts +290 -0
- package/dist/hdr-format-DRhzGS7G.js +30 -0
- package/dist/height-grid.d.ts +65 -0
- package/dist/height-grid.js +74 -0
- package/dist/heightfield.d.ts +38 -0
- package/dist/holes.d.ts +37 -0
- package/dist/holes.js +97 -0
- package/dist/imagery.d.ts +109 -0
- package/dist/imagery.js +472 -0
- package/dist/index.d.ts +297 -0
- package/dist/index.js +1 -0
- package/dist/layers-pbr.d.ts +78 -0
- package/dist/layers-pbr.js +128 -0
- package/dist/lighting-layout-CaDtDa5G.js +34 -0
- package/dist/lighting-layout.d.ts +5 -0
- package/dist/mesh-patch-BThCHCeS.js +21 -0
- package/dist/mesh-patch.d.ts +14 -0
- package/dist/noise3-sQdnbz4B.js +11 -0
- package/dist/noise3.d.ts +3 -0
- package/dist/overlays.d.ts +74 -0
- package/dist/overlays.js +297 -0
- package/dist/planet-craters.d.ts +55 -0
- package/dist/planet-recipes.d.ts +75 -0
- package/dist/planet-recipes.js +216 -0
- package/dist/planet.d.ts +139 -0
- package/dist/planet.js +602 -0
- package/dist/query.d.ts +150 -0
- package/dist/query.js +243 -0
- package/dist/relief-lighting.d.ts +46 -0
- package/dist/relief-lighting.js +208 -0
- package/dist/require-webgpu--tUXPsmA.js +7 -0
- package/dist/rock-settings.d.ts +39 -0
- package/dist/rock-settings.js +84 -0
- package/dist/rock-surface.d.ts +111 -0
- package/dist/rock-surface.js +368 -0
- package/dist/rocks.d.ts +258 -0
- package/dist/rocks.js +488 -0
- package/dist/rvt.d.ts +136 -0
- package/dist/rvt.js +518 -0
- package/dist/sculpt.d.ts +103 -0
- package/dist/sculpt.js +361 -0
- package/dist/settings-B9BSdnhD.js +72 -0
- package/dist/settings.d.ts +81 -0
- package/dist/settings.js +152 -0
- package/dist/shader.d.ts +61 -0
- package/dist/shared/settings.d.ts +89 -0
- package/dist/src-C6dtSaAb.js +1155 -0
- package/dist/stream.d.ts +100 -0
- package/dist/stream.js +339 -0
- package/dist/surface-height.d.ts +16 -0
- package/dist/wet-ground.d.ts +82 -0
- package/dist/wet-ground.js +147 -0
- package/package.json +148 -6
package/dist/dunes.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/** Dune kinds: ridges across the wind where sand is plentiful, isolated crescents where it is scarce (Werner 1995). */
|
|
2
|
+
export type DuneType = 'transverse' | 'barchan';
|
|
3
|
+
/** Options for {@link duneField}. Lengths in metres, angles in degrees. */
|
|
4
|
+
export interface DuneFieldOptions {
|
|
5
|
+
/** Cells along x and z (the grid has `width * depth` heights, row by row along x). */
|
|
6
|
+
readonly width: number;
|
|
7
|
+
readonly depth: number;
|
|
8
|
+
/** Metres between neighbouring heights. Default 1. */
|
|
9
|
+
readonly cellSize?: number;
|
|
10
|
+
/** World x and z of the first height. Default 0, 0. */
|
|
11
|
+
readonly origin?: readonly [number, number];
|
|
12
|
+
/** Direction the wind blows toward, degrees from +x toward +z. Default 90 (toward +z). */
|
|
13
|
+
readonly wind?: number;
|
|
14
|
+
readonly type?: DuneType;
|
|
15
|
+
/** Crest height in metres. Default 4. */
|
|
16
|
+
readonly height?: number;
|
|
17
|
+
/** Crest-to-crest spacing along the wind (transverse) or mean distance between dunes (barchan). Default 70. */
|
|
18
|
+
readonly spacing?: number;
|
|
19
|
+
/** Steepest windward slope in degrees, 3 to 20. Default 12 (Sauermann et al. 2001). */
|
|
20
|
+
readonly stoss?: number;
|
|
21
|
+
/** Slip face slope, the angle of repose of dry sand, 25 to 36 degrees. Default 32 (Bagnold 1941). */
|
|
22
|
+
readonly lee?: number;
|
|
23
|
+
/** How much crests wander and vary, 0 to 1. Default 0.35. */
|
|
24
|
+
readonly irregularity?: number;
|
|
25
|
+
/** Seed of the crest noise. Default 1. */
|
|
26
|
+
readonly seed?: number;
|
|
27
|
+
/** Metres over which each brink is rounded (see {@link duneProfile}). Default 0, a sharp brink. */
|
|
28
|
+
readonly round?: number;
|
|
29
|
+
/** Heights to build the dunes on (metres, the grid's layout); default flat 0. */
|
|
30
|
+
readonly base?: Float32Array;
|
|
31
|
+
/** Share of dune height per world point, 0 to 1 (no dunes where 0, as on wet sand). Default 1 everywhere. */
|
|
32
|
+
readonly amount?: (x: number, z: number) => number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Height of one dune profile `p` metres downwind of its windward toe: a half cosine up the stoss side (steepest slope
|
|
36
|
+
* `tanStoss` at its middle, level at the crest), then the slip face at `tanLee` down to the floor, its toe rounded over
|
|
37
|
+
* `toe` metres. `round` (metres, default 0) rounds the brink over that length, as on old dunes whose crest the wind
|
|
38
|
+
* has blunted: a parabola level where it leaves the stoss side and meeting the slip face at its slope. 0 outside.
|
|
39
|
+
*/
|
|
40
|
+
export declare function duneProfile(p: number, height: number, tanStoss: number, tanLee: number, toe?: number, round?: number): number;
|
|
41
|
+
/** Lengths of a dune of `height`: windward side, slip face and their sum, in metres. */
|
|
42
|
+
export declare function duneLengths(height: number, stoss?: number, lee?: number): {
|
|
43
|
+
stoss: number;
|
|
44
|
+
lee: number;
|
|
45
|
+
total: number;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* A height field of wind-built dunes, row by row along x (`width` heights a row, `depth` rows), added to `base`.
|
|
49
|
+
* Transverse: ridges across the wind every `spacing` metres with wandering, varying crests; a ridge that would not fit
|
|
50
|
+
* its spacing at full height is lowered so its windward side and slip face fit. Barchan: crescents one per `spacing`
|
|
51
|
+
* cell with horns pointing downwind, width about 11 heights (Hersen et al. 2002).
|
|
52
|
+
* @throws RangeError for a bad size, an angle outside its range or a height of 0 or less.
|
|
53
|
+
*/
|
|
54
|
+
export declare function duneField(options: DuneFieldOptions): Float32Array;
|
|
55
|
+
/**
|
|
56
|
+
* One barchan of crest height `height` centred (crest) at u = 0, v = 0: a stoss side rising along the wind, a slip face
|
|
57
|
+
* at `tanLee` whose brink curves downwind toward the horns, and horns trailing downwind at the sides. Width about 11
|
|
58
|
+
* heights, as Hersen et al. 2002 measured.
|
|
59
|
+
*/
|
|
60
|
+
export declare function barchan(u: number, v: number, height: number, tanStoss: number, tanLee: number, round?: number): number;
|
|
61
|
+
/** Options for {@link duneHill}. Lengths in metres, angles in degrees. */
|
|
62
|
+
export interface DuneHillOptions {
|
|
63
|
+
/** World x and z of the crest. */
|
|
64
|
+
readonly crest: readonly [number, number];
|
|
65
|
+
/** Crest height above the floor. */
|
|
66
|
+
readonly height: number;
|
|
67
|
+
/** Direction the wind blows toward, degrees from +x toward +z, as {@link DuneFieldOptions.wind}. Default 90. */
|
|
68
|
+
readonly wind?: number;
|
|
69
|
+
/** Half the hill's width across the wind; the crest falls off to its ends as a raised cosine. Default 5 heights. */
|
|
70
|
+
readonly halfWidth?: number;
|
|
71
|
+
/** Steepest windward slope, 3 to 20 degrees. Default 12. */
|
|
72
|
+
readonly stoss?: number;
|
|
73
|
+
/** Slip face slope, 20 to 36 degrees (a lower value for an old face that has slumped and settled). Default 30. */
|
|
74
|
+
readonly lee?: number;
|
|
75
|
+
/** Metres over which the brink is rounded. Default a third of the height. */
|
|
76
|
+
readonly round?: number;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Height at world (x, z) of one big isolated dune: a long windward side, a rounded crest and a steeper lee face, its
|
|
80
|
+
* crest falling off to the ends across the wind. The shape the hills of a coastal dune field take when the wind comes
|
|
81
|
+
* mostly from one side (Bagnold 1941; Sauermann, Kroy and Herrmann 2001); add it to a {@link duneField} or real heights.
|
|
82
|
+
* @throws RangeError for a height of 0 or less or an angle outside its range.
|
|
83
|
+
*/
|
|
84
|
+
export declare function duneHill(x: number, z: number, options: DuneHillOptions): number;
|
|
85
|
+
/** Steepest slope in degrees of a height grid around cell (i, j), from central differences. */
|
|
86
|
+
export declare function slopeAt(heights: Float32Array, width: number, i: number, j: number, cellSize?: number): number;
|
package/dist/dunes.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
//#region src/dunes.ts
|
|
2
|
+
var e = (e, t) => {
|
|
3
|
+
let n = Math.imul(e ^ Math.imul(t, 2654435761), 2246822507);
|
|
4
|
+
return n ^= n >>> 13, n = Math.imul(n, 3266489909), n ^= n >>> 16, (n >>> 0) / 4294967296;
|
|
5
|
+
};
|
|
6
|
+
function t(t, n) {
|
|
7
|
+
let r = Math.floor(t), i = t - r, a = i * i * (3 - 2 * i);
|
|
8
|
+
return (e(r, n) * (1 - a) + e(r + 1, n) * a) * 2 - 1;
|
|
9
|
+
}
|
|
10
|
+
function n(t, n, r) {
|
|
11
|
+
let i = Math.floor(t), a = Math.floor(n), o = t - i, s = n - a, c = o * o * (3 - 2 * o), l = s * s * (3 - 2 * s), u = (t, n) => e(Math.imul(t, 73856093) ^ Math.imul(n, 19349663), r), d = u(i, a) * (1 - c) + u(i + 1, a) * c, f = u(i, a + 1) * (1 - c) + u(i + 1, a + 1) * c;
|
|
12
|
+
return (d * (1 - l) + f * l) * 2 - 1;
|
|
13
|
+
}
|
|
14
|
+
function r(e, t, n, r, i = .6, a = 0) {
|
|
15
|
+
if (t <= 0 || e <= 0) return 0;
|
|
16
|
+
let o = t * Math.PI / (2 * n), s = Math.max(0, Math.min(a / 2, o / 2, t / r / 2)), c = o - s, l = (e) => t * (1 - Math.cos(Math.PI * e / o)) / 2;
|
|
17
|
+
if (e <= c) return l(e);
|
|
18
|
+
let u = l(c), d = s > 0 ? t * Math.PI / (2 * o) * Math.sin(Math.PI * c / o) : 0, f = s > 0 ? (d + r) / (4 * s) : 0, p = u + s * (d - r);
|
|
19
|
+
if (e < o + s) return u + d * (e - c) - f * (e - c) ** 2;
|
|
20
|
+
let m = p - (e - o - s) * r, h = i * r / 2;
|
|
21
|
+
if (m >= h) return m;
|
|
22
|
+
let g = h - m;
|
|
23
|
+
return g >= 2 * h ? 0 : (2 * h - g) * (2 * h - g) / (4 * h);
|
|
24
|
+
}
|
|
25
|
+
function i(e, t = 12, n = 32) {
|
|
26
|
+
let r = e * Math.PI / (2 * Math.tan(t * Math.PI / 180)), i = e / Math.tan(n * Math.PI / 180);
|
|
27
|
+
return {
|
|
28
|
+
stoss: r,
|
|
29
|
+
lee: i,
|
|
30
|
+
total: r + i
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function a(a) {
|
|
34
|
+
let { width: s, depth: c } = a, l = a.cellSize ?? 1, [u, d] = a.origin ?? [0, 0], f = a.type ?? "transverse", p = a.height ?? 4, m = a.spacing ?? 70, h = a.stoss ?? 12, g = a.lee ?? 32, _ = a.irregularity ?? .35, v = a.seed ?? 1, y = a.round ?? 0;
|
|
35
|
+
if (!(y >= 0)) throw RangeError("duneField: round is out of range; pass 0 or more metres.");
|
|
36
|
+
if (!Number.isInteger(s) || !Number.isInteger(c) || s < 2 || c < 2 || s * c > 1 << 26) throw RangeError("duneField: width and depth are wrong; pass integers of 2 or more (at most 67,108,864 heights).");
|
|
37
|
+
if (!(l > 0) || !(p > 0) || !(m > 0)) throw RangeError("duneField: cellSize, height and spacing must be above 0.");
|
|
38
|
+
if (!(h >= 3 && h <= 20)) throw RangeError("duneField: stoss is out of range; pass a windward slope of 3 to 20 degrees.");
|
|
39
|
+
if (!(g >= 25 && g <= 36)) throw RangeError("duneField: lee is out of range; pass an angle of repose of 25 to 36 degrees.");
|
|
40
|
+
if (!(_ >= 0 && _ <= 1)) throw RangeError("duneField: irregularity is out of range; pass 0 to 1.");
|
|
41
|
+
if (f !== "transverse" && f !== "barchan") throw RangeError("duneField: unknown type; pass 'transverse' or 'barchan'.");
|
|
42
|
+
if (a.base && a.base.length !== s * c) throw RangeError("duneField: base must hold width * depth heights.");
|
|
43
|
+
let b = a.base ? Float32Array.from(a.base) : new Float32Array(s * c), x = (a.wind ?? 90) * Math.PI / 180, S = [Math.cos(x), Math.sin(x)], C = [-S[1], S[0]], w = Math.tan(h * Math.PI / 180), T = Math.tan(g * Math.PI / 180);
|
|
44
|
+
for (let x = 0; x < c; x++) for (let c = 0; c < s; c++) {
|
|
45
|
+
let E = u + c * l, D = d + x * l, O = E * S[0] + D * S[1], k = E * C[0] + D * C[1], A = a.amount ? Math.min(1, Math.max(0, a.amount(E, D))) : 1;
|
|
46
|
+
if (A <= 0) continue;
|
|
47
|
+
let j = 0;
|
|
48
|
+
if (f === "transverse") {
|
|
49
|
+
let e = Math.floor(O / m);
|
|
50
|
+
for (let n = e - 1; n <= e + 1; n++) {
|
|
51
|
+
let e = _ * .25 * m * t(k / (2.5 * m) + n * 7.31, v), a = p * (1 + _ * .6 * t(k / (1.7 * m) + n * 3.77, v + 1)), o = Math.min(a, m / i(1, h, g).total), { stoss: s } = i(o, h, g), c = n * m + e - s;
|
|
52
|
+
j = Math.max(j, r(O - c, o, w, T, .6, y));
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
let t = Math.floor(O / m), n = Math.floor(k / m);
|
|
56
|
+
for (let r = t - 1; r <= t + 1; r++) for (let t = n - 1; t <= n + 1; t++) {
|
|
57
|
+
let n = Math.imul(r, 92837111) ^ Math.imul(t, 689287499);
|
|
58
|
+
if (e(n, v + 2) < .35 * _) continue;
|
|
59
|
+
let i = p * (1 + _ * .5 * (e(n, v + 3) * 2 - 1)), a = (r + .5 + _ * .3 * (e(n, v + 4) - .5)) * m, s = (t + .5 + _ * .3 * (e(n, v + 5) - .5)) * m;
|
|
60
|
+
j = Math.max(j, o(O - a, k - s, i, w, T, y));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
j += p * .06 * _ * n(E / (.3 * m), D / (.3 * m), v + 9), b[x * s + c] += Math.max(0, j) * A;
|
|
64
|
+
}
|
|
65
|
+
return b;
|
|
66
|
+
}
|
|
67
|
+
function o(e, t, n, i, a, o = 0) {
|
|
68
|
+
let s = 5.5 * n, c = t / s;
|
|
69
|
+
if (Math.abs(c) >= 1) return 0;
|
|
70
|
+
let l = n * (1 - c * c) ** 1.5, u = 1.2 * n * c * c * (s / n) * .5, d = r(e - u + l * Math.PI / (2 * i), l, i, a, .6, o), f = 1 - Math.min(1, Math.abs(Math.abs(c) - .72) / .22), p = n * .3 * f * f * (3 - 2 * f);
|
|
71
|
+
return p > 0 && e > u && (d = Math.max(d, p * Math.max(0, 1 - (e - u) / (4 * n)))), d;
|
|
72
|
+
}
|
|
73
|
+
function s(e, t, n) {
|
|
74
|
+
let i = n.height, a = n.stoss ?? 12, o = n.lee ?? 30, s = n.halfWidth ?? 5 * i;
|
|
75
|
+
if (!(i > 0) || !(s > 0)) throw RangeError("duneHill: height and halfWidth must be above 0; pass metres.");
|
|
76
|
+
if (!(a >= 3 && a <= 20)) throw RangeError("duneHill: stoss is out of range; pass 3 to 20 degrees.");
|
|
77
|
+
if (!(o >= 20 && o <= 36)) throw RangeError("duneHill: lee is out of range; pass 20 to 36 degrees.");
|
|
78
|
+
let c = (n.wind ?? 90) * Math.PI / 180, l = e - n.crest[0], u = t - n.crest[1], d = l * Math.cos(c) + u * Math.sin(c), f = -l * Math.sin(c) + u * Math.cos(c), p = Math.min(1, Math.abs(f) / s), m = i * (1 + Math.cos(Math.PI * p)) / 2;
|
|
79
|
+
if (m <= 0) return 0;
|
|
80
|
+
let h = Math.tan(a * Math.PI / 180);
|
|
81
|
+
return r(d + m * Math.PI / (2 * h), m, h, Math.tan(o * Math.PI / 180), .6, (n.round ?? i / 3) * m / i);
|
|
82
|
+
}
|
|
83
|
+
function c(e, t, n, r, i = 1) {
|
|
84
|
+
let a = e.length / t, o = (n, r) => e[Math.min(a - 1, Math.max(0, r)) * t + Math.min(t - 1, Math.max(0, n))], s = (o(n + 1, r) - o(n - 1, r)) / (2 * i), c = (o(n, r + 1) - o(n, r - 1)) / (2 * i);
|
|
85
|
+
return Math.atan(Math.hypot(s, c)) * 180 / Math.PI;
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
export { o as barchan, a as duneField, s as duneHill, i as duneLengths, r as duneProfile, c as slopeAt };
|
package/dist/grid.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fixed clipmap grid `Terrain` draws: `(resolution + 1)²` XZ vertices centred on the origin (one unit apart) and
|
|
3
|
+
* two triangle index lists: `center`, every cell (the finest level), and `ring`, the cells outside the middle
|
|
4
|
+
* half-by-half block (three quarters of the grid, drawn by every coarser level).
|
|
5
|
+
* @throws RangeError unless `resolution` is a multiple of 4 from 8 to 256.
|
|
6
|
+
*/
|
|
7
|
+
export declare function clipmapGrid(resolution: number): {
|
|
8
|
+
vertices: Float32Array;
|
|
9
|
+
center: Uint32Array;
|
|
10
|
+
ring: Uint32Array;
|
|
11
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type SettingRow } from './shared/settings.js';
|
|
2
|
+
import type { GroundChange, GroundLook } from './ground-change.js';
|
|
3
|
+
/** A colour value: linear RGB. */
|
|
4
|
+
export type GroundSettingColor = readonly [number, number, number];
|
|
5
|
+
/** One value of a setting: a number, a colour, or null where `nullable`. */
|
|
6
|
+
export type GroundSettingValue = number | GroundSettingColor | null;
|
|
7
|
+
/** Values by setting name; a name left out takes its default. */
|
|
8
|
+
export type GroundSettingValues = Readonly<Record<string, GroundSettingValue>>;
|
|
9
|
+
/** The panel a setting sits in. */
|
|
10
|
+
export type GroundSettingGroup = 'colors' | 'lava' | 'wet';
|
|
11
|
+
/** One control: the shared row shape with the ground change's groups. */
|
|
12
|
+
export interface GroundSetting extends SettingRow {
|
|
13
|
+
readonly group: GroundSettingGroup;
|
|
14
|
+
readonly default: GroundSettingValue;
|
|
15
|
+
}
|
|
16
|
+
/** Every ground change look control, in panel order. Defaults are the values GroundChange uses without the option. */
|
|
17
|
+
export declare const GROUND_CHANGE_SETTINGS: readonly GroundSetting[];
|
|
18
|
+
/** The rows that can change every frame (all of them). */
|
|
19
|
+
export declare const GROUND_CHANGE_LIVE_SETTINGS: readonly GroundSetting[];
|
|
20
|
+
/** Every setting at its default, as a fresh object to edit (a slider panel's state). */
|
|
21
|
+
export declare function groundChangeSettingDefaults(): Record<string, GroundSettingValue>;
|
|
22
|
+
/** The look the given setting values make (names left out keep the change's current look). */
|
|
23
|
+
export declare function groundLookOf(values: GroundSettingValues): GroundLook;
|
|
24
|
+
/**
|
|
25
|
+
* Sets the given rows on `change` (names left out keep their current value); a number for `wet.rain` holds it against
|
|
26
|
+
* the weather, null hands it back. Nothing is rebuilt.
|
|
27
|
+
* @throws TypeError for an unknown name; RangeError for a value out of range.
|
|
28
|
+
*/
|
|
29
|
+
export declare function applyGroundChangeSettings(change: GroundChange, values?: GroundSettingValues): void;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, t as s } from "./settings-B9BSdnhD.js";
|
|
2
|
+
//#region src/ground-change-settings.ts
|
|
3
|
+
var c = (e, t, n) => i(e, "colors", t, 0, 1, n), l = (e, t, n, r, i, o, s, c) => a(e, t, n, r, i, o, s, c), u = [
|
|
4
|
+
c("soil.color", [
|
|
5
|
+
.3,
|
|
6
|
+
.21,
|
|
7
|
+
.13
|
|
8
|
+
], "Freshly cut soil in gullies, cut banks, scour holes and slide scars."),
|
|
9
|
+
c("mud.color", [
|
|
10
|
+
.24,
|
|
11
|
+
.2,
|
|
12
|
+
.15
|
|
13
|
+
], "Flood mud before wet darkening."),
|
|
14
|
+
c("ash.color", [
|
|
15
|
+
.36,
|
|
16
|
+
.35,
|
|
17
|
+
.34
|
|
18
|
+
], "Fallen volcanic ash."),
|
|
19
|
+
c("char.color", [
|
|
20
|
+
.025,
|
|
21
|
+
.022,
|
|
22
|
+
.02
|
|
23
|
+
], "Fresh char on burned ground (albedo about 0.02 to 0.04)."),
|
|
24
|
+
c("ashen.color", [
|
|
25
|
+
.5,
|
|
26
|
+
.49,
|
|
27
|
+
.47
|
|
28
|
+
], "White ash that char ages into after a hot burn."),
|
|
29
|
+
c("lava.color", [
|
|
30
|
+
.04,
|
|
31
|
+
.036,
|
|
32
|
+
.034
|
|
33
|
+
], "Cooled lava rock (dark basalt)."),
|
|
34
|
+
l("lava.glow", "lava", 12, 0, 100, .1, "", "Brightness of glowing lava at full heat, as linear radiance (the sun is about 1)."),
|
|
35
|
+
l("lava.cracks", "lava", .7, 0, 1, .01, "", "How much a cooling flow glows only through the cracks of its crust: 0 evenly, 1 cracks only."),
|
|
36
|
+
l("lava.crackSize", "lava", .8, .05, 100, .05, "m", "Width of the crust plates between the glowing cracks."),
|
|
37
|
+
l("wet.darkening", "wet", .55, 0, 1, .01, "", "Albedo of fully wet mud, soil or ash (1 is no darkening)."),
|
|
38
|
+
l("wet.gloss", "wet", .5, 0, 1, .01, "", "Share by which wet ground is smoother (shinier)."),
|
|
39
|
+
{ ...o(l("wet.rain", "wet", 0, 0, 1, .01, "", "Wetness from rain on all cut soil, mud and ash, 0 dry to 1 soaked. Null follows the weather."), "rainRate") }
|
|
40
|
+
], d = e(u), f = r(u);
|
|
41
|
+
function p() {
|
|
42
|
+
return t(u);
|
|
43
|
+
}
|
|
44
|
+
var m = {
|
|
45
|
+
"soil.color": "soil",
|
|
46
|
+
"mud.color": "mud",
|
|
47
|
+
"ash.color": "ash",
|
|
48
|
+
"char.color": "char",
|
|
49
|
+
"ashen.color": "ashen",
|
|
50
|
+
"lava.color": "lava",
|
|
51
|
+
"lava.glow": "glow",
|
|
52
|
+
"lava.cracks": "cracks",
|
|
53
|
+
"lava.crackSize": "crackSize",
|
|
54
|
+
"wet.darkening": "wetDarkening",
|
|
55
|
+
"wet.gloss": "wetGloss",
|
|
56
|
+
"wet.rain": "rain"
|
|
57
|
+
};
|
|
58
|
+
function h(e) {
|
|
59
|
+
s(f, e, "ground change", "the rows in @margoengine/terrain/ground-change-settings");
|
|
60
|
+
let t = {};
|
|
61
|
+
for (let [n, r] of Object.entries(e)) t[m[n]] = Array.isArray(r) ? [...r] : r;
|
|
62
|
+
return t;
|
|
63
|
+
}
|
|
64
|
+
function g(e, t = {}) {
|
|
65
|
+
let r = h(t);
|
|
66
|
+
e.setLook(r), "rain" in r && n(e.look, "rain", r.rain !== null);
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { d as GROUND_CHANGE_LIVE_SETTINGS, u as GROUND_CHANGE_SETTINGS, g as applyGroundChangeSettings, p as groundChangeSettingDefaults, h as groundLookOf };
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
import type { EngineKernel, Mesh } from '@margoengine/core';
|
|
3
|
+
import { type Engine, type EnginePlugin, type FrameGraph } from '@margoengine/core/extension';
|
|
4
|
+
import type { HeightField } from '@margoengine/math';
|
|
5
|
+
import type { Terrain, TerrainLighting } from './index.js';
|
|
6
|
+
import { type GroundCover, type GroundEvent } from './ground-model.js';
|
|
7
|
+
export * from './ground-model.js';
|
|
8
|
+
type Color = readonly [number, number, number];
|
|
9
|
+
/**
|
|
10
|
+
* The grid the change is computed on: the heightfield mesh's (`heightfieldGeometry` options), or a terrain's heightmap
|
|
11
|
+
* (left out with a `Terrain`: its `origin`, `size` and heightmap texels).
|
|
12
|
+
*/
|
|
13
|
+
export interface GroundGrid {
|
|
14
|
+
/** World XZ extent, each above 0. */
|
|
15
|
+
size: readonly [number, number];
|
|
16
|
+
/** World XZ of the minimum corner. Default centred on the origin (`-size / 2`), as `heightfieldGeometry`. */
|
|
17
|
+
origin?: readonly [number, number];
|
|
18
|
+
/**
|
|
19
|
+
* Cells per side, an integer 1 to 4,096 (vertices: resolution + 1 per side), or [along X, along Z]. Default 192, as
|
|
20
|
+
* `heightfieldGeometry`.
|
|
21
|
+
*/
|
|
22
|
+
resolution?: number | readonly [number, number];
|
|
23
|
+
}
|
|
24
|
+
/** How the covers look; every field is live (`setLook`, or `applyGroundChangeSettings`). Colours are linear RGB. */
|
|
25
|
+
export interface GroundLook {
|
|
26
|
+
/** Freshly cut soil. Default [0.3, 0.21, 0.13]. */
|
|
27
|
+
soil?: Color;
|
|
28
|
+
/** Wet flood mud (before wet darkening). Default [0.24, 0.2, 0.15]. */
|
|
29
|
+
mud?: Color;
|
|
30
|
+
/** Fallen ash. Default [0.36, 0.35, 0.34]. */
|
|
31
|
+
ash?: Color;
|
|
32
|
+
/** Fresh char. Default [0.025, 0.022, 0.02]. */
|
|
33
|
+
char?: Color;
|
|
34
|
+
/** Char whitened to ash. Default [0.5, 0.49, 0.47]. */
|
|
35
|
+
ashen?: Color;
|
|
36
|
+
/** Cooled lava rock. Default [0.04, 0.036, 0.034]. */
|
|
37
|
+
lava?: Color;
|
|
38
|
+
/** Brightness of lava's glow at full heat (linear radiance over the sun's 1), 0 to 100. Default 12. */
|
|
39
|
+
glow?: number;
|
|
40
|
+
/** How much a cooling flow glows only in its cracks, 0 (evenly) to 1. Default 0.7. */
|
|
41
|
+
cracks?: number;
|
|
42
|
+
/** World size of the crust plates between the cracks, metres above 0. Default 0.8. */
|
|
43
|
+
crackSize?: number;
|
|
44
|
+
/** Albedo of fully wet ground (1 is no darkening), 0 to 1. Default 0.55. */
|
|
45
|
+
wetDarkening?: number;
|
|
46
|
+
/** Share by which wet ground is smoother, 0 to 1. Default 0.5. */
|
|
47
|
+
wetGloss?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Wetness of all cut soil, mud and ash from rain, 0 to 1, or null to follow the weather (a `WeatherDrive` writes its
|
|
50
|
+
* rain here). Default null (dry until a weather drives it).
|
|
51
|
+
*/
|
|
52
|
+
rain?: number | null;
|
|
53
|
+
}
|
|
54
|
+
/** {@link GroundChange} settings. Invalid values throw RangeError. */
|
|
55
|
+
export interface GroundChangeOptions extends GroundLook {
|
|
56
|
+
/**
|
|
57
|
+
* The grid; with a mesh it must be the one the mesh was built on. With a `Terrain` leave it out (the heightmap's
|
|
58
|
+
* texels over the terrain's `origin` and `size`) or give that same grid.
|
|
59
|
+
*/
|
|
60
|
+
grid?: GroundGrid;
|
|
61
|
+
/** Events to start with. Default none. */
|
|
62
|
+
events?: readonly GroundEvent[];
|
|
63
|
+
/**
|
|
64
|
+
* Base heights when there is no mesh: a height function, or (resolution + 1)^2 heights row by row from the minimum
|
|
65
|
+
* corner (x fastest). With a mesh the base is the mesh's own vertex heights, with a `Terrain` its heightmap's (read
|
|
66
|
+
* back once; give no `base`). Default 0 everywhere.
|
|
67
|
+
*/
|
|
68
|
+
base?: HeightField | Float32Array;
|
|
69
|
+
/** Film seconds to start at, 0 or more. Default 0. */
|
|
70
|
+
time?: number;
|
|
71
|
+
/** A clock read every frame instead of adding frame deltas (a shot's time). Default none. */
|
|
72
|
+
clock?: () => number;
|
|
73
|
+
/** Shadows whose cached still map re-renders when the ground moves (`Shadows` from `@margoengine/shadows`). */
|
|
74
|
+
shadows?: {
|
|
75
|
+
invalidate(): void;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/** A rectangle of grid vertices, inclusive. */
|
|
79
|
+
export interface GroundRect {
|
|
80
|
+
readonly x0: number;
|
|
81
|
+
readonly z0: number;
|
|
82
|
+
readonly x1: number;
|
|
83
|
+
readonly z1: number;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* What {@link GroundChange.scatterGround} returns: spread into `Scatter` options (`@margoengine/scatter`) so its plants
|
|
87
|
+
* follow the changed ground.
|
|
88
|
+
*/
|
|
89
|
+
export interface GroundScatterMaps {
|
|
90
|
+
/** `r32float` ground heights in metres (base plus change), one texel per grid vertex; undefined until attached. */
|
|
91
|
+
readonly heightmap: () => GPUTexture | undefined;
|
|
92
|
+
/** `r8unorm` share of plants kept: 1 on untouched ground, 0 under fresh soil, mud, ash, char or lava. */
|
|
93
|
+
readonly densityMap: () => GPUTexture | undefined;
|
|
94
|
+
/** World `[minX, minZ, maxX, maxZ]` the two maps cover (half a cell past the grid, as Scatter reads texel centres). */
|
|
95
|
+
readonly bounds: readonly [number, number, number, number];
|
|
96
|
+
}
|
|
97
|
+
/** What {@link GroundChange.sample} returns. */
|
|
98
|
+
export interface GroundSample extends GroundCover {
|
|
99
|
+
/** Ground height: the base plus the change. */
|
|
100
|
+
height: number;
|
|
101
|
+
/** The change from the base, metres (negative where cut). */
|
|
102
|
+
change: number;
|
|
103
|
+
}
|
|
104
|
+
/** The look every option takes when left out. */
|
|
105
|
+
export declare const GROUND_LOOK_DEFAULTS: Readonly<Required<GroundLook>>;
|
|
106
|
+
/**
|
|
107
|
+
* Ground that changes over film time: events (gully, bank, scour, slide, mud, ash, lava, burn, crater) change a heightfield
|
|
108
|
+
* mesh's or a clipmap terrain's heights and colours each frame, the same at any time however it is reached.
|
|
109
|
+
* `GroundChange.attach(engine, mesh, options)` for a mesh made by `heightfieldGeometry` on the same grid;
|
|
110
|
+
* `GroundChange.attach(engine, terrain, options)` for an attached `Terrain` (an `r32float` heightmap with COPY_SRC and
|
|
111
|
+
* COPY_DST usage); `new GroundChange(options)` alone is the CPU model (`sample`, `heights`, `update`). WebGPU (and the
|
|
112
|
+
* WebGL2 compatibility layer) only.
|
|
113
|
+
* @throws RangeError for an option or event out of range; TypeError for a mesh that is not on the grid or a heightmap
|
|
114
|
+
* of the wrong format, usage or size; MargoError `'unsupported'` on a WebGL engine, `'state'` for a terrain not yet
|
|
115
|
+
* attached, `'attached'` for a target of another engine or a second attach, `'disposed'` after `dispose()`.
|
|
116
|
+
*/
|
|
117
|
+
export declare class GroundChange implements EnginePlugin, TerrainLighting {
|
|
118
|
+
#private;
|
|
119
|
+
readonly options: GroundChangeOptions;
|
|
120
|
+
readonly name: string;
|
|
121
|
+
disposed: boolean;
|
|
122
|
+
/** Vertices along X: resolution + 1. */
|
|
123
|
+
readonly side: number;
|
|
124
|
+
/** Vertices along X and along Z. */
|
|
125
|
+
readonly sides: readonly [number, number];
|
|
126
|
+
readonly origin: readonly [number, number];
|
|
127
|
+
readonly size: readonly [number, number];
|
|
128
|
+
/** The look the shader reads; `rain` is written by a `WeatherDrive` while not held. Change it with `setLook`. */
|
|
129
|
+
readonly look: Required<GroundLook>;
|
|
130
|
+
/**
|
|
131
|
+
* `target`: the heightfield mesh or attached `Terrain` to change once the plugin is used by its engine (`attach`
|
|
132
|
+
* passes it).
|
|
133
|
+
*/
|
|
134
|
+
constructor(options: GroundChangeOptions, target?: Mesh | Terrain);
|
|
135
|
+
/**
|
|
136
|
+
* Attaches to a heightfield mesh (made by `heightfieldGeometry` on `options.grid`) or to a `Terrain` already attached
|
|
137
|
+
* to `engine` (`grid` left out: the heightmap's texels).
|
|
138
|
+
*/
|
|
139
|
+
static attach(engine: EngineKernel, target: Mesh | Terrain, options?: GroundChangeOptions): GroundChange;
|
|
140
|
+
/**
|
|
141
|
+
* Resolves once the base heights are known: at once for a mesh or the CPU model, after the heightmap's one read back
|
|
142
|
+
* for a terrain (until then frames draw the base ground and `sample` reads a base of 0).
|
|
143
|
+
*/
|
|
144
|
+
get ready(): Promise<void>;
|
|
145
|
+
/** Adds an event; returns its id for `remove`. @throws RangeError or TypeError for a bad event. */
|
|
146
|
+
add(event: GroundEvent): number;
|
|
147
|
+
/** Removes an event by id; the ground it changed goes back. Returns whether it was there. */
|
|
148
|
+
remove(id: number): boolean;
|
|
149
|
+
/** Removes every event. */
|
|
150
|
+
clear(): void;
|
|
151
|
+
/** The events, in the order they apply (by start time, then as added). */
|
|
152
|
+
get events(): readonly GroundEvent[];
|
|
153
|
+
/** Film seconds the ground shows (after the next `update` or frame). */
|
|
154
|
+
get time(): number;
|
|
155
|
+
/** Sets the film time outright, 0 to 1e9. */
|
|
156
|
+
setTime(seconds: number): this;
|
|
157
|
+
/** Moves the film time by `delta` seconds (0 or less moves nothing): the CPU part of a frame, for `seek`. */
|
|
158
|
+
advanceTime(delta: number): void;
|
|
159
|
+
onPreUpdate(delta: number): void;
|
|
160
|
+
/** Changes the look; a field left out keeps its value, `rain: null` hands the rain back to the weather. */
|
|
161
|
+
setLook(look: GroundLook): void;
|
|
162
|
+
/** Calls `listener` with each rectangle of grid vertices the ground changed in; returns an unsubscribe. */
|
|
163
|
+
onChange(listener: (rect: GroundRect) => void): () => void;
|
|
164
|
+
/**
|
|
165
|
+
* Brings the CPU grid to `time`: recomputes the vertices the events active between the time it last showed and now
|
|
166
|
+
* can touch. Returns the rectangle it recomputed, or undefined when nothing could change. Frames call it.
|
|
167
|
+
*/
|
|
168
|
+
update(): GroundRect | undefined;
|
|
169
|
+
/** The change from the base at each grid vertex (metres), row by row from the minimum corner, as of the last update. */
|
|
170
|
+
get change(): Float32Array;
|
|
171
|
+
/** The base heights (the mesh's heights at attach, or `base`). */
|
|
172
|
+
get base(): Float32Array;
|
|
173
|
+
/** Ground heights at each grid vertex, base plus change, as of the last update (a new array). */
|
|
174
|
+
get heights(): Float32Array;
|
|
175
|
+
/**
|
|
176
|
+
* The covers at each grid vertex as of the last update: `rgba8` bytes of mud, ash, char and lava (`surface`) and of
|
|
177
|
+
* heat, wetness, fresh soil and ash whitening (`state`), the textures the shader reads.
|
|
178
|
+
*/
|
|
179
|
+
get covers(): {
|
|
180
|
+
readonly surface: Uint8Array;
|
|
181
|
+
readonly state: Uint8Array;
|
|
182
|
+
};
|
|
183
|
+
/** The two cover textures while attached (`rgba8unorm`, one texel per grid vertex). */
|
|
184
|
+
get textures(): {
|
|
185
|
+
readonly surface?: GPUTexture;
|
|
186
|
+
readonly state?: GPUTexture;
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* The ground at world (x, z) and film time `t` (default the current time), worked exactly from the events: the base
|
|
190
|
+
* there (bilinear between grid vertices) plus every event's change, and the covers. For placing people and props.
|
|
191
|
+
*/
|
|
192
|
+
sample(x: number, z: number, t?: number): GroundSample;
|
|
193
|
+
setup(engine: Engine): void;
|
|
194
|
+
registerPasses(graph: FrameGraph): void;
|
|
195
|
+
/**
|
|
196
|
+
* Maps that make a `Scatter` or `GrassScatter` (`@margoengine/scatter`) follow the changed ground: spread them into
|
|
197
|
+
* its options (`{...change.scatterGround(), area, center: [cx, 0, cz]}`). Plants stand on the changed heights, rising
|
|
198
|
+
* and sinking with the ground, and are kept by the density map only where the ground keeps its own cover: a gully,
|
|
199
|
+
* scour or slide scar is bare, mud, ash and lava bury them and a burn scar is burned clear, in step with the covers.
|
|
200
|
+
* The maps live while the change is attached (a new pair after device restoration); on a terrain await `ready` first.
|
|
201
|
+
*/
|
|
202
|
+
scatterGround(): GroundScatterMaps;
|
|
203
|
+
/**
|
|
204
|
+
* The covers plants that survive stand in, for `PlantStates` (`@margoengine/scatter/states`, its `ground` source):
|
|
205
|
+
* an `rgba8unorm` texture of mud, ash, char and wetness at each grid vertex, over the same rectangle as
|
|
206
|
+
* {@link GroundChange.scatterGround}, so a plant left standing at the edge of a burn scar is charred and scorched and
|
|
207
|
+
* one at the edge of a mud cover carries the water mark. Lives while the change is attached (a new one after device
|
|
208
|
+
* restoration).
|
|
209
|
+
*/
|
|
210
|
+
plantCovers(): {
|
|
211
|
+
covers: () => GPUTexture | undefined;
|
|
212
|
+
bounds: readonly [number, number, number, number];
|
|
213
|
+
};
|
|
214
|
+
/** The terrain lighting effect's engine (`TerrainLighting`). */
|
|
215
|
+
get owner(): Engine | undefined;
|
|
216
|
+
/** The terrain lighting group entries the patched shader reads (`TerrainLighting`): the covers and the look. */
|
|
217
|
+
bindings(): GPUBindGroupEntry[];
|
|
218
|
+
/**
|
|
219
|
+
* The terrain's lit shader with the covers laid over `terrainColor`, wet ground glossier, lava's glow added to its
|
|
220
|
+
* light and, where the normals come from a normal map, those tilted by the change's slope (`TerrainLighting`).
|
|
221
|
+
*/
|
|
222
|
+
shader(source: string, group: number): string;
|
|
223
|
+
onDeviceRestored(engine: Engine): void;
|
|
224
|
+
/** Detaches: the mesh gets its base heights and normals back, a terrain its heightmap. */
|
|
225
|
+
dispose(): void;
|
|
226
|
+
[Symbol.dispose]: () => void;
|
|
227
|
+
}
|