@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.
Files changed (71) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +1808 -3
  4. package/dist/blend.d.ts +70 -0
  5. package/dist/blend.js +159 -0
  6. package/dist/colors.d.ts +164 -0
  7. package/dist/deform.d.ts +103 -0
  8. package/dist/deform.js +322 -0
  9. package/dist/displace.d.ts +60 -0
  10. package/dist/displace.js +254 -0
  11. package/dist/dunes.d.ts +86 -0
  12. package/dist/dunes.js +88 -0
  13. package/dist/errors-fc4i1pSL.js +7 -0
  14. package/dist/grid.d.ts +11 -0
  15. package/dist/ground-change-settings.d.ts +29 -0
  16. package/dist/ground-change-settings.js +69 -0
  17. package/dist/ground-change.d.ts +227 -0
  18. package/dist/ground-change.js +1291 -0
  19. package/dist/ground-model.d.ts +290 -0
  20. package/dist/hdr-format-DRhzGS7G.js +30 -0
  21. package/dist/height-grid.d.ts +65 -0
  22. package/dist/height-grid.js +74 -0
  23. package/dist/heightfield.d.ts +38 -0
  24. package/dist/holes.d.ts +37 -0
  25. package/dist/holes.js +97 -0
  26. package/dist/imagery.d.ts +109 -0
  27. package/dist/imagery.js +472 -0
  28. package/dist/index.d.ts +297 -0
  29. package/dist/index.js +1 -0
  30. package/dist/layers-pbr.d.ts +78 -0
  31. package/dist/layers-pbr.js +128 -0
  32. package/dist/lighting-layout-CaDtDa5G.js +34 -0
  33. package/dist/lighting-layout.d.ts +5 -0
  34. package/dist/mesh-patch-BThCHCeS.js +21 -0
  35. package/dist/mesh-patch.d.ts +14 -0
  36. package/dist/noise3-sQdnbz4B.js +11 -0
  37. package/dist/noise3.d.ts +3 -0
  38. package/dist/overlays.d.ts +74 -0
  39. package/dist/overlays.js +297 -0
  40. package/dist/planet-craters.d.ts +55 -0
  41. package/dist/planet-recipes.d.ts +75 -0
  42. package/dist/planet-recipes.js +216 -0
  43. package/dist/planet.d.ts +139 -0
  44. package/dist/planet.js +602 -0
  45. package/dist/query.d.ts +150 -0
  46. package/dist/query.js +243 -0
  47. package/dist/relief-lighting.d.ts +46 -0
  48. package/dist/relief-lighting.js +208 -0
  49. package/dist/require-webgpu--tUXPsmA.js +7 -0
  50. package/dist/rock-settings.d.ts +39 -0
  51. package/dist/rock-settings.js +84 -0
  52. package/dist/rock-surface.d.ts +111 -0
  53. package/dist/rock-surface.js +368 -0
  54. package/dist/rocks.d.ts +258 -0
  55. package/dist/rocks.js +488 -0
  56. package/dist/rvt.d.ts +136 -0
  57. package/dist/rvt.js +518 -0
  58. package/dist/sculpt.d.ts +103 -0
  59. package/dist/sculpt.js +361 -0
  60. package/dist/settings-B9BSdnhD.js +72 -0
  61. package/dist/settings.d.ts +81 -0
  62. package/dist/settings.js +152 -0
  63. package/dist/shader.d.ts +61 -0
  64. package/dist/shared/settings.d.ts +89 -0
  65. package/dist/src-C6dtSaAb.js +1155 -0
  66. package/dist/stream.d.ts +100 -0
  67. package/dist/stream.js +339 -0
  68. package/dist/surface-height.d.ts +16 -0
  69. package/dist/wet-ground.d.ts +82 -0
  70. package/dist/wet-ground.js +147 -0
  71. package/package.json +148 -6
@@ -0,0 +1,74 @@
1
+ /// <reference lib="esnext.disposable" preserve="true" />
2
+ import type { EngineKernel } from '@margoengine/core';
3
+ import { type Engine, type EnginePlugin } from '@margoengine/core/extension';
4
+ import type { TerrainLighting } from './index.js';
5
+ import type { TerrainVirtualTexture } from './rvt.js';
6
+ /** A position on a terrain's world XZ plane, in metres. */
7
+ export type TerrainOverlayPosition = readonly [number, number];
8
+ /** Linear-light fill or stroke style. */
9
+ export interface TerrainOverlayStyle {
10
+ /** Linear straight RGBA in 0..1. Default [1,0.25,0,1]. */ color?: readonly [number, number, number, number];
11
+ /** Stroke width (or Point diameter) in world metres, above zero. Default 2. */ width?: number;
12
+ }
13
+ /** Fixed resource and filter options. */
14
+ export interface TerrainOverlayOptions {
15
+ /** Maximum independent primitives, 1..65536. Default 4096. */ maxPrimitives?: number;
16
+ /** Maximum line/polygon segments, 1..1048576. Default 65536. */ maxSegments?: number;
17
+ /** Half-width of the edge filter in cache texels, 0..2. Default 0.5. */ antialias?: number;
18
+ /** Distinct storage binding when sharing an RVT with other collections. Default 120. */ binding?: number;
19
+ }
20
+ /** RFC 7946 feature information passed to the style function. */
21
+ export interface TerrainOverlayFeature {
22
+ /** GeoJSON type. */ type: 'Feature';
23
+ /** Optional feature identifier. */ id?: string | number;
24
+ /** User properties. */ properties: Readonly<Record<string, unknown>> | null;
25
+ /** RFC 7946 geometry, or null. */ geometry: unknown;
26
+ }
27
+ /** Projection and styling for an imported GeoJSON object, feature, or collection. */
28
+ export interface TerrainOverlayGeoJSONOptions {
29
+ /** Converts RFC 7946 longitude, latitude (degrees) to this terrain's local world XZ metres. Required. */
30
+ project: (position: readonly number[]) => TerrainOverlayPosition;
31
+ /** A common style, or per-feature style. Geometry-only inputs receive a feature with null properties. */
32
+ style?: TerrainOverlayStyle | ((feature: TerrainOverlayFeature) => TerrainOverlayStyle);
33
+ }
34
+ /** Ground-clamped metre-width strokes, filled polygons with holes and projected GeoJSON, baked through an RVT. */
35
+ export declare class TerrainOverlays implements EnginePlugin, TerrainLighting, Disposable {
36
+ #private;
37
+ private readonly rvt;
38
+ readonly name: string;
39
+ /** Owning engine while attached. */ owner?: Engine;
40
+ /** Whether the collection has been disposed. */ disposed: boolean;
41
+ constructor(rvt: TerrainVirtualTexture, options?: TerrainOverlayOptions);
42
+ /** Attaches to an RVT on the same engine. The RVT and terrain remain borrowed. */
43
+ static attach(engine: EngineKernel, rvt: TerrainVirtualTexture, options?: TerrainOverlayOptions): TerrainOverlays;
44
+ /** Number of user overlays; one GeoJSON collection is one overlay with many primitives. */ get length(): number;
45
+ /** Stable IDs in bottom-to-top paint order. */ get order(): readonly number[];
46
+ /** Adds a round-cap/round-join polyline with width in metres. A single position draws a round point. */
47
+ addPolyline(points: readonly TerrainOverlayPosition[], style?: TerrainOverlayStyle): number;
48
+ /** Adds a filled polygon: first ring is exterior, subsequent rings are holes; open direct rings close automatically. */
49
+ addPolygon(rings: readonly (readonly TerrainOverlayPosition[])[], style?: TerrainOverlayStyle): number;
50
+ /** Adds any RFC 7946 geometry or feature collection, projecting degrees to terrain metres and ignoring altitude. */
51
+ addGeoJSON(input: unknown, options: TerrainOverlayGeoJSONOptions): number;
52
+ /** Replaces a stroke live, retaining its ID and paint order. */
53
+ setPolyline(id: number, points: readonly TerrainOverlayPosition[], style?: TerrainOverlayStyle): void;
54
+ /** Replaces a filled polygon live, retaining its ID and paint order. */
55
+ setPolygon(id: number, rings: readonly (readonly TerrainOverlayPosition[])[], style?: TerrainOverlayStyle): void;
56
+ /** Reprojects/replaces a GeoJSON overlay atomically; invalid input preserves the previous drawing. */
57
+ setGeoJSON(id: number, input: unknown, options: TerrainOverlayGeoJSONOptions): void;
58
+ /** Changes every primitive's color/width in one overlay without changing its positions. */
59
+ setStyle(id: number, style: TerrainOverlayStyle): void;
60
+ /** Removes an overlay and invalidates its previous painted footprint. */
61
+ remove(id: number): boolean;
62
+ /** Moves an overlay in bottom-to-top paint order. */
63
+ move(id: number, index: number): void;
64
+ setup(engine: Engine): void;
65
+ /** Read-only storage used by the RVT bake and its steep/far fallback. */
66
+ bindings(): GPUBindGroupEntry[];
67
+ /** Paints the actual RVT surface and the uncached fallback with identical segment-distance/even-odd coverage. */
68
+ shader(source: string, group: number): string;
69
+ /** Reuploads retained vector data without replacing the borrowed RVT or its registration. */
70
+ onDeviceRestored(engine: Engine): void;
71
+ /** Removes its RVT provider and scene registration, destroys owned storage, and retains the borrowed terrain/RVT. */
72
+ dispose(): void;
73
+ [Symbol.dispose](): void;
74
+ }
@@ -0,0 +1,297 @@
1
+ // @margo/core-built 0.1.0
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);
4
+ import { t as e } from "./errors-fc4i1pSL.js";
5
+ import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
6
+ //#region src/overlays.ts
7
+ var n = (e) => !!e && typeof e == "object" && !Array.isArray(e);
8
+ function r(e) {
9
+ if (!Array.isArray(e) || e.length !== 2 || !e.every((e) => Number.isFinite(e) && Number.isFinite(Math.fround(e)))) throw RangeError("Invalid overlay position; give two finite world XZ coordinates representable as float32.");
10
+ return [e[0], e[1]];
11
+ }
12
+ function i(e = {}) {
13
+ let t = e.color ?? [
14
+ 1,
15
+ .25,
16
+ 0,
17
+ 1
18
+ ], n = e.width ?? 2;
19
+ if (!Array.isArray(t) || t.length !== 4 || !t.every((e) => Number.isFinite(e) && e >= 0 && e <= 1) || !Number.isFinite(n) || !Number.isFinite(Math.fround(n)) || n <= 0) throw RangeError("Invalid overlay style; give linear RGBA channels 0..1 and width in metres above zero.");
20
+ return {
21
+ color: [
22
+ t[0],
23
+ t[1],
24
+ t[2],
25
+ t[3]
26
+ ],
27
+ width: n
28
+ };
29
+ }
30
+ function a(e, t, n) {
31
+ if (!Array.isArray(e) || !e.length) throw TypeError("Invalid overlay paths; give at least one line or polygon ring.");
32
+ let a = i(n), o = [], s = Infinity, c = Infinity, l = -Infinity, u = -Infinity;
33
+ for (let n of e) {
34
+ if (!Array.isArray(n) || n.length < (t ? 3 : 1)) throw RangeError("Invalid overlay path; give at least three polygon vertices or one point.");
35
+ let e = n.map(r);
36
+ for (let [t, n] of e) s = Math.min(s, t), c = Math.min(c, n), l = Math.max(l, t), u = Math.max(u, n);
37
+ let i = e.length > 1 && e[0][0] === e.at(-1)[0] && e[0][1] === e.at(-1)[1], a = t && !i ? e.length : Math.max(1, e.length - 1);
38
+ for (let t = 0; t < a; t++) {
39
+ let n = e[t], r = e[(t + 1) % e.length];
40
+ o.push([
41
+ n[0],
42
+ n[1],
43
+ r[0],
44
+ r[1]
45
+ ]);
46
+ }
47
+ }
48
+ return {
49
+ ...a,
50
+ polygon: t,
51
+ segments: o,
52
+ bounds: [
53
+ s,
54
+ c,
55
+ l,
56
+ u
57
+ ]
58
+ };
59
+ }
60
+ function o(e, t) {
61
+ if (typeof t?.project != "function") throw TypeError("GeoJSON needs a projection; pass project(longitudeLatitude) returning local XZ metres.");
62
+ let i = [], o = (e) => {
63
+ if (!Array.isArray(e) || e.length < 2 || !e.every((e) => typeof e == "number" && Number.isFinite(e)) || e[0] < -180 || e[0] > 180 || e[1] < -90 || e[1] > 90) throw RangeError("Invalid GeoJSON position; give finite longitude -180..180 and latitude -90..90, with optional altitude.");
64
+ return r(t.project([...e]));
65
+ }, s = (e, t) => {
66
+ if (!Array.isArray(e) || e.length < (t ? 4 : 2)) throw RangeError("Invalid GeoJSON path; give two line positions or four positions in a closed ring.");
67
+ if (t) {
68
+ let t = e[0], n = e.at(-1);
69
+ if (!Array.isArray(t) || !Array.isArray(n) || t.length !== n.length || !t.every((e, t) => e === n[t])) throw RangeError("Open GeoJSON polygon ring; repeat the first position at the end.");
70
+ }
71
+ return e.map(o);
72
+ }, c = (e) => {
73
+ if (!Array.isArray(e)) throw TypeError("Invalid GeoJSON coordinates; supply an array.");
74
+ return e;
75
+ }, l = (e, t) => {
76
+ if (!n(e) || typeof e.type != "string") throw TypeError("Invalid GeoJSON geometry; supply a standard geometry object.");
77
+ let r = e.coordinates;
78
+ switch (e.type) {
79
+ case "Point":
80
+ i.push(a([[o(r)]], !1, t));
81
+ break;
82
+ case "MultiPoint":
83
+ for (let e of c(r)) i.push(a([[o(e)]], !1, t));
84
+ break;
85
+ case "LineString":
86
+ c(r).length && i.push(a([s(r, !1)], !1, t));
87
+ break;
88
+ case "MultiLineString":
89
+ for (let e of c(r)) i.push(a([s(e, !1)], !1, t));
90
+ break;
91
+ case "Polygon":
92
+ c(r).length && i.push(a(c(r).map((e) => s(e, !0)), !0, t));
93
+ break;
94
+ case "MultiPolygon":
95
+ for (let e of c(r)) c(e).length && i.push(a(c(e).map((e) => s(e, !0)), !0, t));
96
+ break;
97
+ case "GeometryCollection":
98
+ for (let n of c(e.geometries)) l(n, t);
99
+ break;
100
+ default: throw TypeError("Unsupported GeoJSON geometry; supply Point, LineString, Polygon, their Multi forms or GeometryCollection.");
101
+ }
102
+ }, u = (e) => {
103
+ if (!n(e)) throw TypeError("Invalid GeoJSON input; supply a geometry, Feature or FeatureCollection object.");
104
+ if (e.type === "FeatureCollection") for (let t of c(e.features)) {
105
+ if (!n(t) || t.type !== "Feature") throw TypeError("Invalid GeoJSON features; use Feature objects in a FeatureCollection.");
106
+ u(t);
107
+ }
108
+ else {
109
+ let r = e.type === "Feature" ? e : {
110
+ type: "Feature",
111
+ properties: null,
112
+ geometry: e
113
+ };
114
+ if (r.properties !== null && !n(r.properties)) throw TypeError("Invalid GeoJSON properties; give an object or null.");
115
+ if (r.geometry === null) return;
116
+ let i = typeof t.style == "function" ? t.style(r) : t.style ?? {};
117
+ l(r.geometry, i);
118
+ }
119
+ };
120
+ return u(e), i;
121
+ }
122
+ var s = 0, c = class n {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
123
+ #e;
124
+ #t;
125
+ #n;
126
+ #r;
127
+ #i;
128
+ #a;
129
+ #o;
130
+ constructor(e, t = {}) {
131
+ if (this.rvt = e, this.name = "terrain-overlays:" + s++, this.disposed = !1, this.#t = /* @__PURE__ */ new Map(), this.#n = 0, this.#o = /* @__PURE__ */ new Map(), !e || typeof e.addSurface != "function" || typeof e.invalidate != "function") throw TypeError("Invalid overlay target; pass a TerrainVirtualTexture with surface support.");
132
+ if (this.#e = {
133
+ maxPrimitives: t.maxPrimitives ?? 4096,
134
+ maxSegments: t.maxSegments ?? 65536,
135
+ antialias: t.antialias ?? .5,
136
+ binding: t.binding ?? 120
137
+ }, !Number.isInteger(this.#e.maxPrimitives) || this.#e.maxPrimitives < 1 || this.#e.maxPrimitives > 65536 || !Number.isInteger(this.#e.maxSegments) || this.#e.maxSegments < 1 || this.#e.maxSegments > 1048576 || !Number.isFinite(this.#e.antialias) || !(this.#e.antialias >= 0 && this.#e.antialias <= 2) || !Number.isInteger(this.#e.binding) || this.#e.binding < 0 || this.#e.binding >= 1e3) throw RangeError("Invalid overlay limits; give maxPrimitives 1..65536, maxSegments 1..1048576, antialias 0..2 and binding 0..999.");
138
+ }
139
+ static attach(e, r, i = {}) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
140
+ let a = new n(r, i);
141
+ return t(e).use(a), a;
142
+ }
143
+ get length() {
144
+ return this.#t.size;
145
+ }
146
+ get order() {
147
+ return [...this.#t.keys()];
148
+ }
149
+ #s() {
150
+ if (this.disposed) throw e("disposed", "Terrain overlays are disposed; attach a new collection.");
151
+ }
152
+ #c(e) {
153
+ let t = this.#t.get(e);
154
+ if (!t) throw RangeError("Unknown overlay ID; use an ID returned by addPolyline, addPolygon or addGeoJSON.");
155
+ return t;
156
+ }
157
+ #l(e, t, n) {
158
+ this.#s();
159
+ let r = n ? this.#c(e) : [], i = [...this.#t].filter(([t]) => t !== e).flatMap(([, e]) => e).concat(t), a = i.reduce((e, t) => e + t.segments.length, 0);
160
+ if (i.length > this.#e.maxPrimitives || a > this.#e.maxSegments) throw RangeError("Overlay resource budget exceeded; remove primitives or raise maxPrimitives/maxSegments within device limits.");
161
+ let o = (1 + i.length * 3 + a) * 16;
162
+ if (this.#r && o > this.#r.limits.maxStorageBufferBindingSize) throw RangeError("Overlay storage exceeds device limits; reduce the geometry.");
163
+ return this.#t.set(e, t), n || this.#n++, this.#d(), this.#u(r), this.#u(t), e;
164
+ }
165
+ addPolyline(e, t = {}) {
166
+ return this.#l(this.#n, [a([e], !1, t)], !1);
167
+ }
168
+ addPolygon(e, t = {}) {
169
+ return this.#l(this.#n, [a(e, !0, t)], !1);
170
+ }
171
+ addGeoJSON(e, t) {
172
+ return this.#l(this.#n, o(e, t), !1);
173
+ }
174
+ setPolyline(e, t, n = {}) {
175
+ this.#l(e, [a([t], !1, n)], !0);
176
+ }
177
+ setPolygon(e, t, n = {}) {
178
+ this.#l(e, [a(t, !0, n)], !0);
179
+ }
180
+ setGeoJSON(e, t, n) {
181
+ this.#l(e, o(t, n), !0);
182
+ }
183
+ setStyle(e, t) {
184
+ let n = this.#c(e).map((e) => ({
185
+ ...e,
186
+ ...i({
187
+ color: e.color,
188
+ width: e.width,
189
+ ...t
190
+ })
191
+ }));
192
+ this.#l(e, n, !0);
193
+ }
194
+ remove(e) {
195
+ this.#s();
196
+ let t = this.#t.get(e);
197
+ return t ? (this.#t.delete(e), this.#d(), this.#u(t), !0) : !1;
198
+ }
199
+ move(e, t) {
200
+ this.#s();
201
+ let n = this.#c(e);
202
+ if (!Number.isInteger(t) || t < 0 || t >= this.length) throw RangeError("Invalid overlay order; use an index in 0..length-1.");
203
+ let r = [...this.#t].filter(([t]) => t !== e);
204
+ r.splice(t, 0, [e, n]), this.#t.clear();
205
+ for (let [e, t] of r) this.#t.set(e, t);
206
+ this.#d();
207
+ for (let [, e] of r) this.#u(e);
208
+ }
209
+ #u(e) {
210
+ let t = this.rvt.texel * 2 ** (this.rvt.levels - 1) * this.#e.antialias;
211
+ for (let n of e) {
212
+ let e = (n.polygon ? 0 : n.width / 2) + t, r = n.bounds;
213
+ this.rvt.invalidate(r[0] - e, r[1] - e, r[2] + e, r[3] + e);
214
+ }
215
+ }
216
+ #d() {
217
+ if (!this.#r) return;
218
+ let e = [...this.#t.values()].flat(), t = e.reduce((e, t) => e + t.segments.length, 0), n = new Float32Array((1 + e.length * 3 + t) * 4);
219
+ n.set([
220
+ e.length,
221
+ this.#e.antialias,
222
+ 0,
223
+ 0
224
+ ]);
225
+ let r = 1 + e.length * 3, i = this.rvt.terrain?.anchor, a = i?.[0] ?? 0, o = i?.[1] ?? 0, s = (e) => i ? [
226
+ e[0] - a,
227
+ e[1] - o,
228
+ e[2] - a,
229
+ e[3] - o
230
+ ] : e;
231
+ if (e.forEach((e, t) => {
232
+ let i = (1 + t * 3) * 4;
233
+ n.set(s(e.bounds), i), n.set(e.color, i + 4), n.set([
234
+ r,
235
+ e.segments.length,
236
+ +!!e.polygon,
237
+ e.width / 2
238
+ ], i + 8);
239
+ for (let t of e.segments) n.set(s(t), r * 4), r++;
240
+ }), n.byteLength > this.#r.limits.maxStorageBufferBindingSize) throw RangeError("Overlay storage exceeds device limits; reduce primitives or segments.");
241
+ if (!this.#i || this.#i.size < n.byteLength) {
242
+ let e = this.#r.createBuffer({
243
+ size: n.byteLength,
244
+ usage: 136
245
+ });
246
+ this.#i?.destroy(), this.#i = e;
247
+ }
248
+ this.#r.queue.writeBuffer(this.#i, 0, n);
249
+ }
250
+ setup(t) {
251
+ if (this.#s(), !t.gpu) throw e("unsupported", "Terrain overlays require a GPU device; attach to a GPU engine.");
252
+ if (this.rvt.disposed || this.rvt.owner && this.rvt.owner !== t) throw e("attached", "Terrain overlays require a live RVT on the same engine; attach them together.");
253
+ this.owner = t, this.#r = t.gpu, this.#d(), this.#a ??= this.rvt.addSurface(this);
254
+ }
255
+ bindings() {
256
+ return this.#i ? [{
257
+ binding: this.#e.binding,
258
+ resource: { buffer: this.#i }
259
+ }] : [];
260
+ }
261
+ shader(t, n) {
262
+ let r = n + t, i = this.#o.get(r);
263
+ if (i) return i;
264
+ let a = "terrainOverlay" + this.#e.binding, o = "return terrainSurfaceColor;";
265
+ if (!t.includes(o)) throw e("unsupported", "Overlay shader needs the RVT bake or reader fallback; attach through TerrainVirtualTexture.addSurface.");
266
+ let s = t.replace(o, `terrainSurfaceColor=${a}(terrainSurfaceColor,position,footprint);${o}`), c = `@group(${n}) @binding(${this.#e.binding}) var<storage,read> ${a}Data:array<vec4f>;
267
+ fn ${a}(color:vec3f,p:vec2f,footprint:f32)->vec3f {
268
+ var result=color;let header=${a}Data[0];let aa=max(footprint*header.y,0.000001);
269
+ for(var k=0u;k<u32(header.x);k++){
270
+ let box=${a}Data[1u+k*3u];let style=${a}Data[2u+k*3u];let rule=${a}Data[3u+k*3u];
271
+ let margin=select(rule.w,0.0,rule.z>0.5)+aa;
272
+ if(any(p<box.xy-vec2f(margin))||any(p>box.zw+vec2f(margin))||style.a<=0.0){continue;}
273
+ var distance=3.402823e38;var inside=false;
274
+ for(var j=0u;j<u32(rule.y);j++){
275
+ let edge=${a}Data[u32(rule.x)+j];let a=edge.xy;let b=edge.zw;let delta=b-a;
276
+ let t=clamp(dot(p-a,delta)/max(dot(delta,delta),1e-30),0.0,1.0);distance=min(distance,length(p-a-t*delta));
277
+ if((a.y>p.y)!=(b.y>p.y)){let crossing=a.x+(p.y-a.y)*(b.x-a.x)/(b.y-a.y);if(p.x<crossing){inside=!inside;}}
278
+ }
279
+ var signedDistance=distance-rule.w;
280
+ if(rule.z>0.5){signedDistance=select(distance,-distance,inside);}
281
+ var coverage=select(0.0,1.0,signedDistance<=0.0);if(header.y>0.0){coverage=1.0-smoothstep(-aa,aa,signedDistance);}result=mix(result,style.rgb,style.a*coverage);
282
+ }return result;
283
+ }\n` + s;
284
+ return this.#o.set(r, c), c;
285
+ }
286
+ onDeviceRestored(e) {
287
+ this.#i?.destroy(), this.#i = void 0, this.setup(e), this.rvt.invalidate();
288
+ }
289
+ dispose() {
290
+ this.disposed || (this.disposed = !0, this.#a?.(), this.#a = void 0, this.#i?.destroy(), this.#i = void 0, this.#r = void 0, this.#o.clear(), this.#t.clear(), this.owner?.sceneOf(this)?.removePlugin(this.name), this.owner = void 0);
291
+ }
292
+ [Symbol.dispose]() {
293
+ this.dispose();
294
+ }
295
+ };
296
+ //#endregion
297
+ export { c as TerrainOverlays };
@@ -0,0 +1,55 @@
1
+ import type { PlanetHeight } from './planet.js';
2
+ /** `craterField` options. Every one is optional. */
3
+ export interface CraterFieldOptions {
4
+ /** Radius in metres of the planet the field is for, above 0. Default 6,371,000; pass the planet's own radius. */
5
+ radius?: number;
6
+ /** Craters of diameter `dMin` or more per million square kilometres, 0 or more. Default 1,000. Excludes `count`. */
7
+ density?: number;
8
+ /** Craters of diameter `dMin` or more on the whole planet, 0 or more; instead of `density`. */
9
+ count?: number;
10
+ /** Smallest diameter in metres, above 0. Default `radius / 20,000`. */
11
+ dMin?: number;
12
+ /** Largest diameter in metres, above `dMin` and at most `radius`. Default `radius / 4`. */
13
+ dMax?: number;
14
+ /** Cumulative size exponent: craters with diameter at least D number about D^-exponent, 1 to 3. Default 2 (Neukum et al. 2001). */
15
+ exponent?: number;
16
+ /** An integer. Default 1. Another seed makes another population. */
17
+ seed?: number;
18
+ /** Depth coefficient: depth = depthRatio * D^1.01 with D in kilometres (Pike 1977), 0 or more. Default 0.196. */
19
+ depthRatio?: number;
20
+ /** Rim height coefficient: rim = rimRatio * D^1.01 with D in kilometres, 0 or more. Default 0.036. */
21
+ rimRatio?: number;
22
+ /** Deepest a crater gets, in metres, above 0. Default 3,400 (Pike 1977); larger craters are scaled down, not clipped. */
23
+ maxDepth?: number;
24
+ /** Fraction of a crater's radius that is flat floor, 0 to below 1. Default 0. */
25
+ floor?: number;
26
+ /** Add the ejecta blanket (McGetchin et al. 1973) beyond the rim. Default true. */
27
+ ejecta?: boolean;
28
+ /** Width, as a fraction of the radius beyond the rim, over which a younger crater fades into what was there, 0 to 1. Default 0.15. */
29
+ blend?: number;
30
+ }
31
+ /** A crater that shapes a sample point. */
32
+ export interface PlanetCrater {
33
+ /** Unit direction of the centre from the planet's centre. */
34
+ readonly x: number;
35
+ readonly y: number;
36
+ readonly z: number;
37
+ /** Rim diameter in metres. */
38
+ readonly diameter: number;
39
+ /** 0 (oldest) to 1 (youngest): a younger crater cuts an older one. */
40
+ readonly age: number;
41
+ }
42
+ /** A {@link PlanetHeight} that can also list the craters that shape a point. */
43
+ export interface CraterField extends PlanetHeight {
44
+ /**
45
+ * The craters whose rim diameter is at least twice `detail` and whose ejecta reach the direction (x, y, z), oldest first.
46
+ * At most about 27 cells times the octaves of diameter are read, whatever the planet's size.
47
+ */
48
+ craters(x: number, y: number, z: number, detail?: number): PlanetCrater[];
49
+ }
50
+ /**
51
+ * Craters for a planet's ground, heights in metres relative to the undisturbed surface (bowls below 0, rims and ejecta
52
+ * above). Combine it with a base ground through `combine`. Deterministic for a seed; a sample reads only the cells near it.
53
+ * @throws RangeError on an invalid option, or when the density puts more than 256 craters in a lattice cell.
54
+ */
55
+ export declare function craterField(options?: CraterFieldOptions): CraterField;
@@ -0,0 +1,75 @@
1
+ import type { PlanetHeight } from './planet.js';
2
+ export { craterField } from './planet-craters.js';
3
+ export type { CraterField, CraterFieldOptions, PlanetCrater } from './planet-craters.js';
4
+ /** `ridgeNoise` options. Every one is optional. */
5
+ export interface RidgeNoiseOptions {
6
+ /** Planet radius in metres, above 0. Default 6,371,000. */
7
+ radius?: number;
8
+ /** Largest height in metres, 0 or more. The result is between 0 and `relief`. Default 8,000. */
9
+ relief?: number;
10
+ /** Octaves, an integer 1 to 24; octaves finer than twice the `detail` asked for are left out. Default 6. */
11
+ octaves?: number;
12
+ /** How strongly a ridge in one octave lets the next octave show, 0 or more. Default 2 (Musgrave et al. 1989). */
13
+ gain?: number;
14
+ /** Cycles of the first octave around the planet's circumference, above 0. Default 2. */
15
+ frequency?: number;
16
+ /** An integer. Default 1. */
17
+ seed?: number;
18
+ }
19
+ /**
20
+ * Ridged multifractal noise on the sphere: sharp crests that taper into valleys, 0 to `relief` metres. Octave k has an
21
+ * amplitude of `relief / 2^k` relative to the first; the sum is scaled so it never exceeds `relief`.
22
+ * @throws RangeError on an invalid option.
23
+ */
24
+ export declare function ridgeNoise(options?: RidgeNoiseOptions): PlanetHeight;
25
+ /** `domainWarp` options. Every one is optional. */
26
+ export interface DomainWarpOptions {
27
+ /** Planet radius in metres, above 0. Default 6,371,000. */
28
+ radius?: number;
29
+ /** Largest shift of the ground along each axis in metres, 0 or more (sqrt(3) times it at most in all). Default 100,000. */
30
+ amplitude?: number;
31
+ /** Cycles of the warp around the planet's circumference, above 0. Default 8. */
32
+ frequency?: number;
33
+ /** 1, or 2 to warp by a noise that is itself warped. Default 1. */
34
+ levels?: 1 | 2;
35
+ /** An integer. Default 1. */
36
+ seed?: number;
37
+ }
38
+ /**
39
+ * Reads `base` at positions moved sideways by noise, so straight features bend and craters stretch (Perlin and Hoffert
40
+ * 1989). Heights are unchanged in size; only where they come from moves. Each axis moves by at most `amplitude`
41
+ * metres, so a point moves at most sqrt(3) times `amplitude`, with one level or two (the second level only reads the
42
+ * noise at the warped point).
43
+ * @throws TypeError on an invalid option.
44
+ */
45
+ export declare function domainWarp(base: PlanetHeight, options?: DomainWarpOptions): PlanetHeight;
46
+ /** `combine` options. */
47
+ export interface CombineOptions {
48
+ /** `'add'` sums the heights, `'max'` takes the highest, `'smoothMax'` takes the highest with rounded joins. Default `'add'`. */
49
+ mode?: 'add' | 'max' | 'smoothMax';
50
+ /** Width in metres of the `'smoothMax'` join, 0 or more. Default 100. */
51
+ smooth?: number;
52
+ }
53
+ /**
54
+ * Merges ground functions into one. With `'smoothMax'` more than two fold left to right, so the order matters.
55
+ * @throws TypeError or RangeError on an invalid argument.
56
+ */
57
+ export declare function combine(heights: readonly PlanetHeight[], options?: CombineOptions): PlanetHeight;
58
+ /** A body a preset is made for. */
59
+ export type PlanetPresetName = 'moon' | 'mars' | 'asteroid' | 'ice';
60
+ /**
61
+ * The radius in metres a preset is made for (the Moon, Mars, a 10 km asteroid, Europa): pass it as `radius` to the
62
+ * planet and to `planetPreset`.
63
+ * @throws RangeError for an unknown name.
64
+ */
65
+ export declare function planetPresetRadius(name: PlanetPresetName): number;
66
+ /**
67
+ * A ready ground: `'moon'` (old cratered highlands), `'mars'` (fewer, softer craters on ridged uplands), `'asteroid'`
68
+ * (crowded craters on a lumpy body) or `'ice'` (shallow craters and warped ridges). `radius` defaults to the body's own;
69
+ * give the same one to `PlanetTerrain`. Looks are authored, not fits to data.
70
+ * @throws RangeError on an invalid name, radius or seed.
71
+ */
72
+ export declare function planetPreset(name: PlanetPresetName, options?: {
73
+ radius?: number;
74
+ seed?: number;
75
+ }): PlanetHeight;