@margoengine/terrain 0.0.0-stage → 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 (88) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +2366 -2
  4. package/dist/bed-mesh.d.ts +40 -0
  5. package/dist/bed-mesh.js +95 -0
  6. package/dist/blend.d.ts +70 -0
  7. package/dist/blend.js +159 -0
  8. package/dist/colors.d.ts +170 -0
  9. package/dist/deform.d.ts +134 -0
  10. package/dist/deform.js +404 -0
  11. package/dist/displace.d.ts +60 -0
  12. package/dist/displace.js +254 -0
  13. package/dist/dunes.d.ts +86 -0
  14. package/dist/dunes.js +88 -0
  15. package/dist/elevation.d.ts +182 -0
  16. package/dist/elevation.js +155 -0
  17. package/dist/errors-fc4i1pSL.js +7 -0
  18. package/dist/far.d.ts +66 -0
  19. package/dist/far.js +191 -0
  20. package/dist/furrows.d.ts +74 -0
  21. package/dist/furrows.js +157 -0
  22. package/dist/grid.d.ts +14 -0
  23. package/dist/ground-change-settings.d.ts +29 -0
  24. package/dist/ground-change-settings.js +69 -0
  25. package/dist/ground-change.d.ts +227 -0
  26. package/dist/ground-change.js +1412 -0
  27. package/dist/ground-contact-settings.d.ts +27 -0
  28. package/dist/ground-contact-settings.js +22 -0
  29. package/dist/ground-contact.d.ts +91 -0
  30. package/dist/ground-contact.js +241 -0
  31. package/dist/ground-model.d.ts +372 -0
  32. package/dist/hdr-format-DRhzGS7G.js +30 -0
  33. package/dist/height-grid.d.ts +65 -0
  34. package/dist/height-grid.js +74 -0
  35. package/dist/heightfield.d.ts +38 -0
  36. package/dist/holes.d.ts +37 -0
  37. package/dist/holes.js +97 -0
  38. package/dist/imagery.d.ts +109 -0
  39. package/dist/imagery.js +472 -0
  40. package/dist/index.d.ts +408 -0
  41. package/dist/index.js +1 -0
  42. package/dist/layers-pbr.d.ts +78 -0
  43. package/dist/layers-pbr.js +128 -0
  44. package/dist/lighting-layout-CaDtDa5G.js +34 -0
  45. package/dist/lighting-layout.d.ts +5 -0
  46. package/dist/mesh-patch-BThCHCeS.js +21 -0
  47. package/dist/mesh-patch.d.ts +14 -0
  48. package/dist/noise3-sQdnbz4B.js +11 -0
  49. package/dist/noise3.d.ts +3 -0
  50. package/dist/overlays.d.ts +74 -0
  51. package/dist/overlays.js +297 -0
  52. package/dist/planet-complex.d.ts +31 -0
  53. package/dist/planet-craters.d.ts +80 -0
  54. package/dist/planet-rays.d.ts +37 -0
  55. package/dist/planet-recipes.d.ts +84 -0
  56. package/dist/planet-recipes.js +442 -0
  57. package/dist/planet.d.ts +144 -0
  58. package/dist/planet.js +610 -0
  59. package/dist/query.d.ts +150 -0
  60. package/dist/query.js +243 -0
  61. package/dist/relief-lighting.d.ts +53 -0
  62. package/dist/relief-lighting.js +221 -0
  63. package/dist/require-webgpu--tUXPsmA.js +7 -0
  64. package/dist/rock-settings.d.ts +39 -0
  65. package/dist/rock-settings.js +84 -0
  66. package/dist/rock-surface.d.ts +114 -0
  67. package/dist/rock-surface.js +380 -0
  68. package/dist/rocks.d.ts +258 -0
  69. package/dist/rocks.js +488 -0
  70. package/dist/rvt.d.ts +136 -0
  71. package/dist/rvt.js +518 -0
  72. package/dist/scour.d.ts +90 -0
  73. package/dist/scour.js +153 -0
  74. package/dist/sculpt.d.ts +103 -0
  75. package/dist/sculpt.js +361 -0
  76. package/dist/settings-B9BSdnhD.js +72 -0
  77. package/dist/settings.d.ts +81 -0
  78. package/dist/settings.js +152 -0
  79. package/dist/shader.d.ts +176 -0
  80. package/dist/shared/settings.d.ts +89 -0
  81. package/dist/src-Cr7Gm4n0.js +1366 -0
  82. package/dist/stream-window.d.ts +123 -0
  83. package/dist/stream.d.ts +169 -0
  84. package/dist/stream.js +531 -0
  85. package/dist/surface-height.d.ts +16 -0
  86. package/dist/wet-ground.d.ts +82 -0
  87. package/dist/wet-ground.js +147 -0
  88. package/package.json +173 -4
@@ -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, a second attach or a second GroundChange on one terrain, `'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
+ }