@margoengine/terrain 0.1.0 → 1.0.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.
Files changed (52) hide show
  1. package/LICENSE +201 -201
  2. package/NOTICE +4 -4
  3. package/README.md +2367 -1808
  4. package/dist/bed-mesh.d.ts +40 -0
  5. package/dist/bed-mesh.js +95 -0
  6. package/dist/blend.js +4 -4
  7. package/dist/colors.d.ts +6 -0
  8. package/dist/deform.d.ts +41 -10
  9. package/dist/deform.js +169 -87
  10. package/dist/displace.js +4 -4
  11. package/dist/elevation.d.ts +182 -0
  12. package/dist/elevation.js +155 -0
  13. package/dist/far.d.ts +66 -0
  14. package/dist/far.js +191 -0
  15. package/dist/furrows.d.ts +74 -0
  16. package/dist/furrows.js +157 -0
  17. package/dist/grid.d.ts +6 -3
  18. package/dist/ground-change.d.ts +1 -1
  19. package/dist/ground-change.js +232 -111
  20. package/dist/ground-contact-settings.d.ts +27 -0
  21. package/dist/ground-contact-settings.js +22 -0
  22. package/dist/ground-contact.d.ts +91 -0
  23. package/dist/ground-contact.js +241 -0
  24. package/dist/ground-model.d.ts +83 -1
  25. package/dist/imagery.js +4 -4
  26. package/dist/index.d.ts +120 -9
  27. package/dist/index.js +1 -1
  28. package/dist/layers-pbr.js +9 -9
  29. package/dist/overlays.js +4 -4
  30. package/dist/planet-complex.d.ts +31 -0
  31. package/dist/planet-craters.d.ts +28 -3
  32. package/dist/planet-rays.d.ts +37 -0
  33. package/dist/planet-recipes.d.ts +10 -1
  34. package/dist/planet-recipes.js +341 -115
  35. package/dist/planet.d.ts +5 -0
  36. package/dist/planet.js +112 -104
  37. package/dist/relief-lighting.d.ts +7 -0
  38. package/dist/relief-lighting.js +36 -23
  39. package/dist/rock-surface.d.ts +3 -0
  40. package/dist/rock-surface.js +28 -16
  41. package/dist/rvt.js +5 -5
  42. package/dist/scour.d.ts +90 -0
  43. package/dist/scour.js +153 -0
  44. package/dist/sculpt.js +4 -4
  45. package/dist/shader.d.ts +120 -5
  46. package/dist/shared/settings.d.ts +89 -89
  47. package/dist/{src-C6dtSaAb.js → src-Cr7Gm4n0.js} +359 -148
  48. package/dist/stream-window.d.ts +123 -0
  49. package/dist/stream.d.ts +95 -26
  50. package/dist/stream.js +440 -248
  51. package/dist/wet-ground.js +4 -4
  52. package/package.json +175 -148
@@ -0,0 +1,27 @@
1
+ import { type SettingRow } from './shared/settings.js';
2
+ import type { TerrainGroundContact } from './ground-contact.js';
3
+ /** A colour value: linear RGB. */
4
+ export type GroundContactSettingColor = readonly [number, number, number];
5
+ /** One value of a setting: a number or a colour. */
6
+ export type GroundContactSettingValue = number | GroundContactSettingColor;
7
+ /** Values by setting name; a name left out keeps the effect's current value. */
8
+ export type GroundContactSettingValues = Readonly<Record<string, GroundContactSettingValue>>;
9
+ /** The panel a setting sits in. */
10
+ export type GroundContactSettingGroup = 'contact';
11
+ /** One control: the shared row shape with the ground contact's group. */
12
+ export interface GroundContactSetting extends SettingRow {
13
+ readonly group: GroundContactSettingGroup;
14
+ readonly default: GroundContactSettingValue;
15
+ }
16
+ /** Every ground contact look control, in panel order. Defaults are the values the effect uses without the option. */
17
+ export declare const GROUND_CONTACT_SETTINGS: readonly GroundContactSetting[];
18
+ /** The rows that can change every frame (all of them). */
19
+ export declare const GROUND_CONTACT_LIVE_SETTINGS: readonly GroundContactSetting[];
20
+ /** Every setting at its default, as a fresh object to edit (a slider panel's state). */
21
+ export declare function groundContactSettingDefaults(): Record<string, GroundContactSettingValue>;
22
+ /**
23
+ * Sets the given rows on `contact` (names left out keep their current value). Nothing is rebuilt.
24
+ * @throws TypeError for an unknown name; RangeError for a value out of range.
25
+ * @example applyGroundContactSettings(view.groundContact, { 'contact.soil': 0.6 });
26
+ */
27
+ export declare function applyGroundContactSettings(contact: TerrainGroundContact, values?: GroundContactSettingValues): void;
@@ -0,0 +1,22 @@
1
+ import { a as e, c as t, l as n, n as r, o as i, t as a } from "./settings-B9BSdnhD.js";
2
+ //#region src/ground-contact-settings.ts
3
+ var o = (e, t) => i(e, "contact", 1, 0, 1, .01, "", t), s = [
4
+ r("contact.color", "contact", [
5
+ .1,
6
+ .08,
7
+ .055
8
+ ], 0, 1, "Linear RGB albedo of the soil and litter at the feet of trunks and stones."),
9
+ o("contact.soil", "How far the ground turns to the soil colour where the soil weight is full (0 leaves it)."),
10
+ o("contact.occlusion", "How much of the sky light lost at a foot is taken (0 takes none).")
11
+ ], c = e(s), l = n(s);
12
+ function u() {
13
+ return t(s);
14
+ }
15
+ function d(e, t = {}) {
16
+ a(l, t, "ground contact", "the rows in @margoengine/terrain/ground-contact-settings");
17
+ let n = {};
18
+ for (let [e, r] of Object.entries(t)) n[e.slice(8)] = r;
19
+ e.setLook(n);
20
+ }
21
+ //#endregion
22
+ export { c as GROUND_CONTACT_LIVE_SETTINGS, s as GROUND_CONTACT_SETTINGS, d as applyGroundContactSettings, u as groundContactSettingDefaults };
@@ -0,0 +1,91 @@
1
+ /// <reference lib="esnext.disposable" preserve="true" />
2
+ import { type Engine, type EnginePlugin } from '@margoengine/core/extension';
3
+ import type { EngineKernel } from '@margoengine/core';
4
+ import type { Terrain, TerrainLighting } from './index.js';
5
+ /** The look of ground contact; every field is live. */
6
+ export interface GroundContactLook {
7
+ /** Linear RGB albedo of the soil and litter at the feet, 0-1. Default [0.1, 0.08, 0.055]. */
8
+ color?: readonly [number, number, number];
9
+ /** How far the ground turns to `color` where the soil weight is full, 0-1. Default 1. */
10
+ soil?: number;
11
+ /** How much of the sky light lost at a foot is taken, 0-1. Default 1. */
12
+ occlusion?: number;
13
+ }
14
+ /** Options of {@link TerrainGroundContact.attach}. */
15
+ export interface GroundContactOptions extends GroundContactLook {
16
+ /** Metres a mask texel covers, 0.05 to 4. Default 0.2. */
17
+ texel?: number;
18
+ /** Mask texels a side, an integer 64 to 4096 (2 bytes each). Default 1024: 205 m around the camera. */
19
+ resolution?: number;
20
+ /** The first of the three lighting-group bindings the effect declares. Default 124. */
21
+ binding?: number;
22
+ }
23
+ /** The baked mask: red the soil weight and green the sky lost, over a world rectangle with row 0 at `minZ`. */
24
+ export interface GroundContactMask {
25
+ /** rg8unorm. Borrowed: `dispose()` frees it. */
26
+ readonly texture: GPUTexture;
27
+ /** `[minX, minZ, maxX, maxZ]`, world metres. */
28
+ readonly bounds: readonly [number, number, number, number];
29
+ }
30
+ /** A footprint's kind: 0 a trunk (soil that thins outward), 1 a stone (a narrow ring). */
31
+ export type FootprintKind = 0 | 1;
32
+ /**
33
+ * The soil weight and the sky lost, both 0-1, `d` metres from the centre of a footprint of radius `r`; returns
34
+ * `[0, 0]` from 4 radii out.
35
+ * @example footprintAt(0.4, 0.4, 1)[1]; // 0.354, a stone's sky loss one radius from its centre
36
+ */
37
+ export declare function footprintAt(d: number, r: number, kind: FootprintKind): [soil: number, loss: number];
38
+ /**
39
+ * Bakes footprints (flat `[x, z, radius, kind, ...]` lists) into an rg8 mask of `size` x `size` texels of `texel`
40
+ * metres whose first corner is `origin`: soil weights take the largest, sky losses combine as independent occluders.
41
+ * `out` (2 bytes a texel) is cleared and returned.
42
+ */
43
+ export declare function bakeGroundContact(lists: Iterable<ArrayLike<number>>, origin: readonly [number, number], size: number, texel: number, out?: Uint8Array): Uint8Array;
44
+ /**
45
+ * Soil, litter and contact shade on a clipmap {@link Terrain} around the objects standing on it:
46
+ * `const contact = TerrainGroundContact.attach(engine, terrain)`, then `contact.set('rocks', [x, z, radius, 1])`.
47
+ * WebGPU (and the WebGL2 compatibility layer).
48
+ * @throws TypeError for a missing terrain; RangeError for an option, a look or a footprint out of range.
49
+ * @throws MargoError `'disposed'` after `dispose()`, `'unsupported'` when the terrain's shader has no lit ambient term.
50
+ */
51
+ export declare class TerrainGroundContact implements EnginePlugin, TerrainLighting, Disposable {
52
+ #private;
53
+ readonly name: string;
54
+ /** Whether the effect has been disposed. */
55
+ disposed: boolean;
56
+ readonly texel: number;
57
+ readonly resolution: number;
58
+ readonly binding: number;
59
+ /** The current look (live; change it with `setLook`). */
60
+ readonly look: Required<GroundContactLook>;
61
+ constructor(terrain: Terrain, options?: GroundContactOptions);
62
+ /** Attaches ground contact to `terrain` on `engine`. */
63
+ static attach(engine: EngineKernel, terrain: Terrain, options?: GroundContactOptions): TerrainGroundContact;
64
+ /** Sets any of `color`, `soil` and `occlusion` (others keep theirs); nothing is rebuilt. */
65
+ setLook(look: GroundContactLook): void;
66
+ /**
67
+ * Holds the footprints of `key`, replacing its last: flat `[x, z, radius, kind, ...]`, world metres, kind 0 a trunk
68
+ * or 1 a stone. An empty list removes the key. The list is copied.
69
+ */
70
+ set(key: string, footprints: ArrayLike<number>): void;
71
+ /** Forgets the footprints of `key`. */
72
+ remove(key: string): void;
73
+ /** The footprints held under all keys. */
74
+ get count(): number;
75
+ get owner(): Engine | undefined;
76
+ setup(engine: Engine): void;
77
+ onDeviceRestored(engine: Engine): void;
78
+ /**
79
+ * The mask as it stands for this frame, re-centred and rebaked first when the camera or the footprints moved; undefined
80
+ * before the effect is attached. Ground cover reads it to open around the feet:
81
+ * `clearingMap(() => contact.mask())` of `@margoengine/scatter/clearing-map`.
82
+ */
83
+ mask(): GroundContactMask | undefined;
84
+ /** The lighting group entries, after re-centring and rebaking the mask when the camera or the footprints moved. */
85
+ bindings(): GPUBindGroupEntry[];
86
+ /** The terrain's lit shader with soil on `terrainColor` and the sky light lost taken from the ambient term. */
87
+ shader(source: string, group: number): string;
88
+ /** Detaches from the terrain (its shader returns to what it was) and frees the mask. */
89
+ dispose(): void;
90
+ [Symbol.dispose](): void;
91
+ }
@@ -0,0 +1,241 @@
1
+ // @margo/core-built 1.0.0
2
+ import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
+ const t=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
+ import { t as e } from "./require-webgpu--tUXPsmA.js";
5
+ import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
6
+ import { MargoError as n } from "@margoengine/math/errors";
7
+ //#region src/ground-contact.ts
8
+ var r = [
9
+ .1,
10
+ .08,
11
+ .055
12
+ ], i = "fn terrainColor(position:vec3f,normal:vec3f)->vec3f {", a = "+base*frame.radiance.w*frame.ambient.rgb", o = /let linear=/g, s = (e, t, n) => {
13
+ let r = Math.min(1, Math.max(0, (n - e) / (t - e)));
14
+ return r * r * (3 - 2 * r);
15
+ };
16
+ function c(e, t, n) {
17
+ if (!(t > 0) || !(e < 4 * t + .3)) return [0, 0];
18
+ let r = e / t, i = Math.max(0, e - t), a = (n === 0 ? .6 : 1) / (1 + r * r) ** 1.5 * (1 - s(3.5, 4, r)), o = n === 0 ? Math.exp(-i / (1.1 * t)) * (1 - s(2.5 * t, 3 * t, i)) : .75 * Math.exp(-Math.max(0, i - Math.max(.06, .25 * t)) / Math.max(.05, .35 * t)) * (1 - s(3, 4, r));
19
+ return [o < 1 / 255 ? 0 : o, a];
20
+ }
21
+ function l(e, t, n, r, i = new Uint8Array(n * n * 2)) {
22
+ i.fill(0);
23
+ for (let a of e) for (let e = 0; e + 3 < a.length; e += 4) {
24
+ let o = a[e] - t[0], s = a[e + 1] - t[1], l = a[e + 2], u = +!!a[e + 3], d = Math.max(l, r * .5), f = Math.min(1, l / d), p = 4 * d + .3, m = Math.max(0, Math.floor((o - p) / r)), h = Math.min(n - 1, Math.ceil((o + p) / r)), g = Math.max(0, Math.floor((s - p) / r)), _ = Math.min(n - 1, Math.ceil((s + p) / r));
25
+ for (let e = g; e <= _; e++) for (let t = m; t <= h; t++) {
26
+ let [a, l] = c(Math.hypot((t + .5) * r - o, (e + .5) * r - s), d, u), p = (e * n + t) * 2, m = Math.round(a * f * 255);
27
+ m > i[p] && (i[p] = m), l > 0 && (i[p + 1] = Math.round(255 - (255 - i[p + 1]) * (1 - l * f)));
28
+ }
29
+ }
30
+ return i;
31
+ }
32
+ var u = 0, d = class s {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
33
+ #e;
34
+ #t;
35
+ #n;
36
+ #r;
37
+ #i;
38
+ #a;
39
+ #o;
40
+ #s;
41
+ #c;
42
+ #l;
43
+ #u;
44
+ #d;
45
+ #f;
46
+ #p;
47
+ #m;
48
+ #h;
49
+ constructor(e, t = {}) {
50
+ if (this.name = "ground-contact:" + u++, this.disposed = !1, this.look = {
51
+ color: r,
52
+ soil: 1,
53
+ occlusion: 1
54
+ }, this.#e = /* @__PURE__ */ new Map(), this.#c = [], this.#u = /* @__PURE__ */ new Float32Array(8), this.#p = !0, this.#m = !0, this.#h = /* @__PURE__ */ new Map(), !e || typeof e.addLighting != "function") throw TypeError("TerrainGroundContact needs a clipmap Terrain (@margoengine/terrain)");
55
+ let { texel: n = .2, resolution: i = 1024, binding: a = 124 } = t;
56
+ if (!(Number.isFinite(n) && n >= .05 && n <= 4)) throw RangeError("TerrainGroundContact texel must be 0.05 to 4 metres");
57
+ if (!Number.isInteger(i) || i < 64 || i > 4096) throw RangeError("TerrainGroundContact resolution must be an integer 64 to 4096");
58
+ if (!Number.isInteger(a) || a < 0 || a > 997) throw RangeError("TerrainGroundContact binding must be an integer 0 to 997");
59
+ this.#t = e;
60
+ let o = e.options?.origin;
61
+ this.#n = [o?.[0] ?? 0, o?.[1] ?? 0], this.texel = n, this.resolution = i, this.binding = a, this.setLook(t);
62
+ }
63
+ static attach(e, n, r = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
64
+ let i = new s(n, r);
65
+ return t(e).use(i), i;
66
+ }
67
+ setLook(e) {
68
+ this.#g();
69
+ let t = { ...this.look };
70
+ if (e.color !== void 0) {
71
+ if (e.color.length !== 3 || !e.color.every((e) => Number.isFinite(e) && e >= 0 && e <= 1)) throw RangeError("TerrainGroundContact color must be a linear RGB of 0-1");
72
+ t.color = [
73
+ e.color[0],
74
+ e.color[1],
75
+ e.color[2]
76
+ ];
77
+ }
78
+ for (let n of ["soil", "occlusion"]) {
79
+ let r = e[n];
80
+ if (r !== void 0) {
81
+ if (!(typeof r == "number" && r >= 0 && r <= 1)) throw RangeError(`TerrainGroundContact ${n} must be a number from 0 to 1`);
82
+ t[n] = r;
83
+ }
84
+ }
85
+ Object.assign(this.look, t), this.#m = !0;
86
+ }
87
+ set(e, t) {
88
+ this.#g();
89
+ let n = t?.length;
90
+ if (typeof e != "string" || !Number.isInteger(n) || n % 4 != 0) throw RangeError("TerrainGroundContact.set needs a key and a flat [x, z, radius, kind, ...] list");
91
+ if (!n) return this.remove(e);
92
+ let r = Float32Array.from(t), i = [
93
+ Infinity,
94
+ Infinity,
95
+ -Infinity,
96
+ -Infinity
97
+ ];
98
+ for (let e = 0; e < n; e += 4) {
99
+ let [t, n, a] = [
100
+ r[e],
101
+ r[e + 1],
102
+ r[e + 2]
103
+ ];
104
+ if (!Number.isFinite(t) || !Number.isFinite(n) || !(a >= 0 && a <= 100)) throw RangeError("TerrainGroundContact footprints need finite x and z and a radius of 0 to 100 m");
105
+ let o = 4 * Math.max(a, this.texel) + .3;
106
+ i[0] = Math.min(i[0], t - o), i[1] = Math.min(i[1], n - o), i[2] = Math.max(i[2], t + o), i[3] = Math.max(i[3], n + o);
107
+ }
108
+ let a = this.#e.get(e);
109
+ this.#e.set(e, {
110
+ list: r,
111
+ box: i
112
+ }), (this.#_(i) || a && this.#_(a.box)) && (this.#p = !0);
113
+ }
114
+ remove(e) {
115
+ let t = this.#e.get(e);
116
+ t && (this.#e.delete(e), this.#_(t.box) && (this.#p = !0));
117
+ }
118
+ get count() {
119
+ let e = 0;
120
+ for (let { list: t } of this.#e.values()) e += t.length / 4;
121
+ return e;
122
+ }
123
+ #g() {
124
+ if (this.disposed) throw new n("disposed", "This TerrainGroundContact was disposed; attach a new one");
125
+ }
126
+ #_(e) {
127
+ let t = this.#f;
128
+ if (!t) return !0;
129
+ let n = this.texel * this.resolution;
130
+ return e[2] > t[0] && e[0] < t[0] + n && e[3] > t[1] && e[1] < t[1] + n;
131
+ }
132
+ get owner() {
133
+ return this.#r;
134
+ }
135
+ setup(t) {
136
+ e(t, "TerrainGroundContact"), this.#g(), this.#r = t, this.#v(t.gpu), this.#i ??= this.#t.addLighting(this);
137
+ }
138
+ onDeviceRestored(e) {
139
+ this.#v(e.gpu);
140
+ }
141
+ #v(e) {
142
+ let t = this.resolution;
143
+ this.#a = e.createBuffer({
144
+ size: 32,
145
+ usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
146
+ }), this.#o = e.createTexture({
147
+ size: [t, t],
148
+ format: "rg8unorm",
149
+ usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST
150
+ }), this.#s = e.createSampler({
151
+ minFilter: "linear",
152
+ magFilter: "linear"
153
+ }), this.#c = [
154
+ {
155
+ binding: this.binding,
156
+ resource: this.#o.createView()
157
+ },
158
+ {
159
+ binding: this.binding + 1,
160
+ resource: this.#s
161
+ },
162
+ {
163
+ binding: this.binding + 2,
164
+ resource: { buffer: this.#a }
165
+ }
166
+ ], this.#p = this.#m = !0;
167
+ }
168
+ mask() {
169
+ if (this.#y()) return this.#l;
170
+ }
171
+ bindings() {
172
+ return this.#y() ? this.#c : [];
173
+ }
174
+ #y() {
175
+ let e = this.#r?.gpu;
176
+ if (!e || !this.#o || !this.#a) return !1;
177
+ let t = this.texel * this.resolution, n = this.#r.camera.position, r = Math.max(1, this.resolution >> 3) * this.texel, i = Math.round((n[0] - t / 2) / r) * r, a = Math.round((n[2] - t / 2) / r) * r, o = this.#f;
178
+ (!o || Math.abs(i - o[0]) > r * 1.5 || Math.abs(a - o[1]) > r * 1.5) && (this.#f = [i, a], this.#p = this.#m = !0);
179
+ let s = this.#f, c = this.#l;
180
+ if ((!c || c.texture !== this.#o || c.bounds[0] !== s[0] || c.bounds[1] !== s[1]) && (this.#l = {
181
+ texture: this.#o,
182
+ bounds: [
183
+ s[0],
184
+ s[1],
185
+ s[0] + t,
186
+ s[1] + t
187
+ ]
188
+ }), this.#p) {
189
+ let t = [];
190
+ for (let e of this.#e.values()) this.#_(e.box) && t.push(e.list);
191
+ this.#d = l(t, s, this.resolution, this.texel, this.#d), e.queue.writeTexture({ texture: this.#o }, this.#d, { bytesPerRow: this.resolution * 2 }, [this.resolution, this.resolution]), this.#p = !1;
192
+ }
193
+ if (this.#m) {
194
+ let n = this.look, [r, i] = this.#n;
195
+ this.#u.set([
196
+ s[0] - r,
197
+ s[1] - i,
198
+ 1 / t,
199
+ n.soil,
200
+ ...n.color,
201
+ n.occlusion
202
+ ]), e.queue.writeBuffer(this.#a, 0, this.#u), this.#m = !1;
203
+ }
204
+ return !0;
205
+ }
206
+ shader(e, t) {
207
+ let r = t + e, s = this.#h.get(r);
208
+ if (s) return s;
209
+ if (e.split(i).length !== 2 || e.split(a).length !== 2 || [...e.matchAll(o)].length !== 1) throw new n("unsupported", "TerrainGroundContact needs the terrain's lit shader with its terrainColor and ambient term");
210
+ let c = "_c" + this.name.slice(this.name.indexOf(":") + 1), l = this.binding, u = `
211
+ @group(${t}) @binding(${l}) var contactMask${c}:texture_2d<f32>;
212
+ @group(${t}) @binding(${l + 1}) var contactSampler${c}:sampler;
213
+ @group(${t}) @binding(${l + 2}) var<uniform> contactLook${c}:array<vec4f,2>;
214
+ fn contactHash${c}(c:vec2i)->f32 {let u=bitcast<vec2u>(c);var x=(u.x*0x8da6b343u)^(u.y*0xd8163841u);x=(x^(x>>16u))*0x7feb352du;x=(x^(x>>15u))*0x846ca68bu;return f32(x^(x>>16u))/4294967296.0;}
215
+ fn contactNoise${c}(p:vec2f)->f32 {let c=vec2i(floor(p));let f=fract(p);let t=f*f*(3.0-2.0*f);
216
+ return mix(mix(contactHash${c}(c),contactHash${c}(c+vec2i(1,0)),t.x),mix(contactHash${c}(c+vec2i(0,1)),contactHash${c}(c+vec2i(1,1)),t.x),t.y);}
217
+ fn contactAt${c}(p:vec2f)->vec2f {
218
+ let L=contactLook${c}[0];let uv=(p-L.xy)*L.z;let inside=all(uv>=vec2f(0))&&all(uv<=vec2f(1));
219
+ let m=textureSampleLevel(contactMask${c},contactSampler${c},uv,0.0).rg;return select(vec2f(0),m,inside);
220
+ }
221
+ `, d = `
222
+ ${i}
223
+ let under=terrainColorBare${c}(position,normal);let p=position.xz-frame.map.xy;
224
+ let ragged=vec2f(contactNoise${c}(p*3.1),contactNoise${c}(p*3.1+17.0))-0.5;
225
+ let weight=clamp(contactAt${c}(p+ragged*0.24).x*(0.55+0.9*contactNoise${c}(p*7.3)),0.0,1.0)*contactLook${c}[0].w;
226
+ return mix(under,contactLook${c}[1].rgb*(0.65+0.7*contactNoise${c}(p*23.0)),weight);
227
+ }`, f = u + e.replace(i, `fn terrainColorBare${c}(position:vec3f,normal:vec3f)->vec3f {`).replace(o, `let contactSky${c}=1.0-contactAt${c}(i.position.xz-frame.map.xy).y*contactLook${c}[1].w;let linear=`).replace(a, `${a}*contactSky${c}`) + d;
228
+ return this.#h.size >= 16 && this.#h.clear(), this.#h.set(r, f), f;
229
+ }
230
+ dispose() {
231
+ if (this.disposed) return;
232
+ this.disposed = !0, this.#i?.(), this.#i = void 0, this.#a?.destroy(), this.#o?.destroy(), this.#a = this.#o = void 0, this.#l = void 0, this.#c = [], this.#e.clear(), this.#h.clear(), this.#d = void 0;
233
+ let e = this.#r;
234
+ this.#r = void 0, this.#t = void 0, e?.sceneOf(this)?.removePlugin(this.name);
235
+ }
236
+ [Symbol.dispose]() {
237
+ this.dispose();
238
+ }
239
+ };
240
+ //#endregion
241
+ export { d as TerrainGroundContact, l as bakeGroundContact, c as footprintAt };
@@ -207,9 +207,74 @@ export interface CraterEvent extends Timed {
207
207
  domeSpread?: number;
208
208
  /** Volume of the ejecta blanket over the bowl's, 0 to 1.5. Default 0.7. */
209
209
  ejecta?: number;
210
+ /**
211
+ * The blanket's share by direction: 3 to 360 weights 0 or more (not all 0) for equal sectors from +X toward +Z, the
212
+ * first centred on +X, such as the mass a crater's ejecta landed with in each (EARTH-06's `ejectaBlocks`). Scaled to a
213
+ * mean of 1 and read linearly between sector centres, in place of the noise rays. Default: noise rays.
214
+ */
215
+ rays?: readonly number[];
216
+ /**
217
+ * Whether to scatter noise secondary pits over the blanket (true), or leave them to crater events of their own (false,
218
+ * as when the secondaries come from the blocks' strikes). Default true.
219
+ */
220
+ pits?: boolean;
221
+ /**
222
+ * Whether to raise noise blocks of thrown-back cap rock on the floor, walls and rim (true), or leave the blocks to be
223
+ * drawn as rocks of their own (false, as when they come from the crater's thrown blocks). Default true.
224
+ */
225
+ blocks?: boolean;
226
+ }
227
+ /** One crater of a {@link CratersEvent}. */
228
+ export interface SmallCrater {
229
+ center: GroundPoint;
230
+ /** Film seconds it starts, 0 or more. */
231
+ start: number;
232
+ /** Bowl radius and depth below the old ground, metres above 0. */
233
+ radius: number;
234
+ depth: number;
235
+ /** Seconds it takes to open, above 0. Default 0.5. */
236
+ duration?: number;
237
+ }
238
+ /**
239
+ * A field of small craters each opening at its own time, such as the secondary craters a crater's blocks dig where they
240
+ * land (EARTH-06's `impactCrater` of each `blockLanding`): each a paraboloid bowl with its lip and an ejecta blanket thinning
241
+ * as (r / R)^-3 to 5 R, as the crater event's, without its dome. Thousands are cheap: each point reads only the craters
242
+ * near it.
243
+ */
244
+ export interface CratersEvent extends Timed {
245
+ kind: 'craters';
246
+ /** 1 to 200,000 craters. */
247
+ craters: readonly SmallCrater[];
248
+ /** Volume of each blanket over its bowl's, 0 to 1.5. Default 0.8 (Holsapple's ejecta of a strike's crater). */
249
+ ejecta?: number;
250
+ }
251
+ /**
252
+ * A deposit laid from a grid of mass per area, such as the dust a plume drops (ATMO-06's `depositField`): its thickness
253
+ * the mass over the layer's bulk density, falling at a steady rate over `duration`, coloured by `cover` where it is
254
+ * thick (full at 4 mm): grey like fallen ash, or the fresh soil of the earth it was thrown from.
255
+ */
256
+ export interface FallEvent extends Timed {
257
+ kind: 'fall';
258
+ /** The grid: `columns` by `rows` cells over `width` by `depth` m centred on `centre`, vertex (r, c) at r + (rows + 1) c. */
259
+ grid: {
260
+ columns: number;
261
+ rows: number;
262
+ width: number;
263
+ depth: number;
264
+ centre: GroundPoint;
265
+ };
266
+ /** kg/m^2 at each of the (columns + 1) (rows + 1) vertices, 0 or more. */
267
+ mass: ArrayLike<number>;
268
+ /** The laid layer's bulk density, kg/m^3, above 0. Default 1,680 (Mercia Mudstone's median dry density, BGS RR/01/02). */
269
+ density?: number;
270
+ /**
271
+ * What the layer looks like: `'ash'` (the ash cover, a volcano's or a fire's) or `'soil'` (the fresh soil cover, for the
272
+ * earth a crater threw up). Default `'ash'`.
273
+ */
274
+ cover?: 'ash' | 'soil';
210
275
  }
211
276
  /** Every event the ground can take. */
212
- export type GroundEvent = GullyEvent | BankEvent | ScourEvent | SlideEvent | MudEvent | AshEvent | LavaEvent | BurnEvent | CraterEvent;
277
+ export type GroundEvent = FallEvent | CratersEvent | GullyEvent | BankEvent | ScourEvent | SlideEvent | MudEvent | AshEvent | LavaEvent | BurnEvent | CraterEvent;
213
278
  /** The kinds of {@link GroundEvent}. */
214
279
  export type GroundEventKind = GroundEvent['kind'];
215
280
  /** Default seconds per kind. */
@@ -258,6 +323,23 @@ export interface ResolvedEvent {
258
323
  readonly dir?: readonly [number, number];
259
324
  /** A lava event's per-point arrival, width, thickness and glow (each one value per path point). */
260
325
  readonly profile?: LavaProfile;
326
+ /** A crater's blanket share by sector, scaled to a mean of 1. */
327
+ readonly rays?: Float64Array;
328
+ /** A craters event's craters (x, z, start, radius, depth, duration, six numbers each) and the buckets that find them. */
329
+ readonly field?: CraterField;
330
+ /** A fall event's laid thickness at each grid vertex, m. */
331
+ readonly thickness?: Float64Array;
332
+ }
333
+ /** A craters event's index: craters by bucket of a square grid, each bucket holding the craters whose blankets reach it. */
334
+ export interface CraterField {
335
+ readonly craters: Float64Array;
336
+ readonly origin: readonly [number, number];
337
+ readonly cell: number;
338
+ readonly columns: number;
339
+ readonly rows: number;
340
+ /** Start of each bucket's list in `members` (rows x columns + 1 offsets). */
341
+ readonly offsets: Uint32Array;
342
+ readonly members: Uint32Array;
261
343
  }
262
344
  /** Per-point values of a lava event along its path. */
263
345
  export interface LavaProfile {
package/dist/imagery.js CHANGED
@@ -1,6 +1,6 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
- const t=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
3
+ const t=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
4
  import { t as e } from "./require-webgpu--tUXPsmA.js";
5
5
  import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
6
6
  import { MargoError as n } from "@margoengine/math/errors";
@@ -100,7 +100,7 @@ function u(e, t, n = 64, r = 1, i = 0, a = !0) {
100
100
  }
101
101
  return [...o.values()].sort((e, t) => e.level - t.level || e.y - t.y || e.x - t.x);
102
102
  }
103
- var d = 0, f = class i {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
103
+ var d = 0, f = class i {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
104
104
  #e;
105
105
  #t;
106
106
  #n;
@@ -137,7 +137,7 @@ var d = 0, f = class i {coreRequirement=__margoCoreRequirement("0.1.0",import.me
137
137
  automatic: t.automatic ?? !0
138
138
  }, !s(this.#t.maxLayers, 1, 8) || !s(this.#t.maxTiles, 4, 256) || !s(this.#t.concurrency, 1, 16)) throw RangeError("Invalid imagery capacity; give maxLayers 1..8, maxTiles 4..256 and concurrency 1..16.");
139
139
  }
140
- static attach(e, n, r = {}) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
140
+ static attach(e, n, r = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
141
141
  let a = new i(n, r);
142
142
  return t(e).use(a), a;
143
143
  }