@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,258 @@
1
+ import { Geometry } from '@margoengine/core';
2
+ /** A heightfield to place rock on: world heights on a regular grid. */
3
+ export interface RockGround {
4
+ /** World heights, `resolution[0] * resolution[1]` of them, x fastest. */
5
+ readonly heights: ArrayLike<number>;
6
+ /** Samples along x and z, integers 3 to 8,193. */
7
+ readonly resolution: readonly [number, number];
8
+ /** World x and z of the first sample. Default [0, 0]. */
9
+ readonly origin?: readonly [number, number];
10
+ /** World extent from the first sample to the last along x and z, above 0 (a `Terrain`'s `size`). */
11
+ readonly size: readonly [number, number];
12
+ }
13
+ /** Where to look for rock; every option is checked and a bad value throws RangeError. */
14
+ export interface RockSiteOptions {
15
+ /** Seed of every random choice, an unsigned 32-bit integer. Default 1. */
16
+ seed?: number;
17
+ /** World height of the sea (or lake) surface. Default 0. */
18
+ seaLevel?: number;
19
+ /** Ground at least this steep, degrees 20 to 85, can hold a cliff. Default 50. */
20
+ cliffSlope?: number;
21
+ /** Local relief (highest less lowest ground within `reliefRadius`) a cliff needs, metres, 0.5 to 5,000. Default 8. */
22
+ cliffRelief?: number;
23
+ /** Radius of the relief window, metres, above 0. Default 16. */
24
+ reliefRadius?: number;
25
+ /** Width of one cliff piece along the face, metres, 2 to 500; pieces are placed 0.75 of it apart, so they overlap. Default 24. */
26
+ cliffWidth?: number;
27
+ /** Most cliff pieces, integer 0 to 4,096. Default 64. */
28
+ maxCliffs?: number;
29
+ /** Most sea rocks (stacks and skerries), integer 0 to 4,096. Default 32. */
30
+ seaRocks?: number;
31
+ /** Water depth range a sea rock stands in, metres [shallowest, deepest], 0 to 1,000. Default [1, 15]. */
32
+ seaRockDepth?: readonly [number, number];
33
+ /** Farthest a sea rock stands from land, metres, above 0. Default 80. */
34
+ shoreDistance?: number;
35
+ /** Least distance between two sea rocks, metres, above 0. Default 14. */
36
+ seaRockSpacing?: number;
37
+ /** Fallen boulders at the foot of each cliff piece, integer 0 to 64. Default 3. */
38
+ boulders?: number;
39
+ }
40
+ /** One cliff piece: a band of steep ground with its foot, crest and the way it faces. */
41
+ export interface CliffSite {
42
+ readonly kind: 'cliff';
43
+ /** World point on the face at mid height. */
44
+ readonly position: readonly [number, number, number];
45
+ /** Horizontal unit vector the face looks along (down the slope). */
46
+ readonly facing: readonly [number, number];
47
+ /** World x and z of the foot and of the crest along `facing`. */
48
+ readonly foot: readonly [number, number];
49
+ readonly crest: readonly [number, number];
50
+ /** Ground height at the foot and at the crest. */
51
+ readonly base: number;
52
+ readonly top: number;
53
+ /** Width along the face, metres. */
54
+ readonly width: number;
55
+ /** Ground slope where it was found, degrees, and the local relief there, metres. */
56
+ readonly slope: number;
57
+ readonly relief: number;
58
+ }
59
+ /** A rock standing in the water: a tall stack off a cliffed headland, or a low skerry. */
60
+ export interface SeaRockSite {
61
+ readonly kind: 'stack' | 'skerry';
62
+ /** World x, bed height and z. */
63
+ readonly position: readonly [number, number, number];
64
+ /** Radius at the foot, metres, and the world height of its top. */
65
+ readonly radius: number;
66
+ readonly top: number;
67
+ /** World height of the sea it stands in (the notch is cut there). */
68
+ readonly seaLevel: number;
69
+ }
70
+ /** A block fallen from a cliff, lying on the ground at its foot. */
71
+ export interface BoulderSite {
72
+ readonly kind: 'boulder';
73
+ /** World x, ground height and z. */
74
+ readonly position: readonly [number, number, number];
75
+ readonly radius: number;
76
+ /** Index of the cliff in `RockSites.cliffs` it fell from. */
77
+ readonly cliff: number;
78
+ }
79
+ /** What `findRockSites` found, plus the slope and relief grids it measured (same layout as the heights). */
80
+ export interface RockSites {
81
+ readonly cliffs: readonly CliffSite[];
82
+ readonly seaRocks: readonly SeaRockSite[];
83
+ readonly boulders: readonly BoulderSite[];
84
+ /** Slope per sample, degrees. */
85
+ readonly slope: Float32Array;
86
+ /** Local relief per sample, metres. */
87
+ readonly relief: Float32Array;
88
+ }
89
+ /** Shape of a cliff piece; every option is checked and a bad value throws RangeError. */
90
+ export interface CliffOptions {
91
+ /** Grid spacing of the polygonizer, metres, 0.05 to 20 (any size: a large piece is built in blocks of 127 cells). Default 0.5. */
92
+ cell?: number;
93
+ /** How far the top of the face leans out past its foot, metres, 0 to 100. Default 2.5. */
94
+ overhang?: number;
95
+ /**
96
+ * How far the face stands in front of the heightfield, metres, 0 to 20, measured at the bottom of its deepest crack, soft
97
+ * bed and bump, so the smooth slope never shows through. Default 0.6.
98
+ */
99
+ proud?: number;
100
+ /** Rock kept behind the face, metres, 0.5 to 200. Default 6. */
101
+ thickness?: number;
102
+ /** Bed thickness of the strata, metres, 0 (massive rock) to 100. Default 1.4. */
103
+ strata?: number;
104
+ /** How far hard beds stand out of soft ones, metres, 0 to 20. Default 0.5. */
105
+ ledges?: number;
106
+ /** Tilt of the beds along the face, degrees -60 to 60. Default 0. */
107
+ dip?: number;
108
+ /** Spacing of the vertical joints, metres, 0 (none) to 200. Default 3. */
109
+ joints?: number;
110
+ /** Depth of a joint crack, metres, 0 to 20. Default 0.35. */
111
+ crackDepth?: number;
112
+ /** Size of the rough bumps over the whole face, metres, 0 to 20. Default 0.35. */
113
+ roughness?: number;
114
+ /** How deep the piece goes into the ground at its foot, metres, 0 to 50. Default 1.5. */
115
+ embed?: number;
116
+ /** Seed, an unsigned 32-bit integer. Default 1. */
117
+ seed?: number;
118
+ }
119
+ /** Shape of a stack or skerry; every option is checked and a bad value throws RangeError. */
120
+ export interface SeaRockOptions {
121
+ /** Grid spacing, metres, 0.05 to 20. Default: radius / 12, at least 0.1. */
122
+ cell?: number;
123
+ /** Depth of the wave-cut notch at the sea surface, metres, 0 to 20 (at most 0.45 of the radius is cut). Default 0.6. */
124
+ notchDepth?: number;
125
+ /** Height of the notch, metres, 0.1 to 20 (the wave and tide band). Default 1.2. */
126
+ notchHeight?: number;
127
+ /** How much narrower the top is than the foot, 0 to 0.9. Default 0.25 (a skerry 0.5). */
128
+ taper?: number;
129
+ /** Bed thickness, metres, 0 to 100. Default 0.9. */
130
+ strata?: number;
131
+ /** How far hard beds stand out, metres, 0 to 20. Default 0.25. */
132
+ ledges?: number;
133
+ /** Vertical joints around the rock, integer 0 to 64. Default 7. */
134
+ joints?: number;
135
+ /** Depth of a joint crack, metres, 0 to 20. Default 0.25. */
136
+ crackDepth?: number;
137
+ /** Lumpiness of the outline, 0 to 1 of the radius. Default 0.22. */
138
+ lobes?: number;
139
+ /** Size of the rough bumps, metres, 0 to 20. Default 0.25. */
140
+ roughness?: number;
141
+ /** How deep the rock goes into the bed, metres, 0 to 50. Default 1. */
142
+ embed?: number;
143
+ /** Seed, an unsigned 32-bit integer. Default 1. */
144
+ seed?: number;
145
+ }
146
+ /** Shape of a fallen boulder; every option is checked and a bad value throws RangeError. */
147
+ export interface BoulderOptions {
148
+ /** Grid spacing, metres, 0.02 to 10. Default: radius / 10, at least 0.04. */
149
+ cell?: number;
150
+ /** Fracture planes that cut the block, integer 4 to 32. Default 9. */
151
+ facets?: number;
152
+ /** How rounded its edges are, 0 (sharp) to 1. Default 0.18. */
153
+ rounding?: number;
154
+ /** Rough bumps as a share of the radius, 0 to 0.5. Default 0.06. */
155
+ roughness?: number;
156
+ /** Share of the radius buried in the ground, 0 to 0.9. Default 0.3. */
157
+ embed?: number;
158
+ /** Seed, an unsigned 32-bit integer. Default 1. */
159
+ seed?: number;
160
+ }
161
+ /** A built rock: its geometry around `position` (set the mesh there), and the site it was built for. */
162
+ export interface RockMesh<S = CliffSite | SeaRockSite | BoulderSite> {
163
+ readonly geometry: Geometry;
164
+ readonly position: readonly [number, number, number];
165
+ readonly site: S;
166
+ }
167
+ /** The options of `buildRocks`. */
168
+ export interface BuildRocksOptions {
169
+ cliff?: CliffOptions;
170
+ seaRock?: SeaRockOptions;
171
+ boulder?: BoulderOptions;
172
+ }
173
+ /** A checked ground and its bilinear height at any world x, z (clamped to the grid). */
174
+ export interface GroundSampler {
175
+ readonly nx: number;
176
+ readonly nz: number;
177
+ readonly ox: number;
178
+ readonly oz: number;
179
+ readonly dx: number;
180
+ readonly dz: number;
181
+ at(i: number, j: number): number;
182
+ height(x: number, z: number): number;
183
+ }
184
+ /**
185
+ * Checks `ground` and returns its sampler: `height(x, z)` is bilinear between the four samples around (x, z), clamped to
186
+ * the grid's edge outside it.
187
+ * @throws RangeError for a resolution, size or origin out of range, a heights array of the wrong length or a height
188
+ * that is not finite.
189
+ */
190
+ export declare function rockGround(ground: RockGround): GroundSampler;
191
+ /** Highest less lowest height within a box of half sides `rx`, `rz` samples about each sample (edges clamped). */
192
+ export declare function localRelief(ground: RockGround, rx: number, rz: number): Float32Array;
193
+ /**
194
+ * Finds where rock belongs on `ground`: cliff pieces on steep ground of high local relief (each with its foot, crest
195
+ * and facing found by walking down and up the slope until it eases to half the cliff slope), stacks and skerries in
196
+ * shallow water near the shore (stacks off cliffed coast, after Sunamura 1992), and boulders fallen to each cliff's foot
197
+ * (bigger ones further out, Kirkby and Statham 1975). The same ground and options always give the same sites.
198
+ * @throws RangeError for a ground or option out of range.
199
+ * @example const sites = findRockSites({ heights, resolution: [513, 513], size: [1024, 1024] }, { seaLevel: 0 });
200
+ */
201
+ export declare function findRockSites(ground: RockGround, options?: RockSiteOptions): RockSites;
202
+ /** A rock's signed distance field and the box it is polygonized in. */
203
+ export interface RockField {
204
+ /** Signed distance in local (u, y, v): below 0 inside the rock. */
205
+ sd(u: number, y: number, v: number): number;
206
+ lo: [number, number, number];
207
+ hi: [number, number, number];
208
+ cell: number;
209
+ /** Local (u, y, v) to the geometry's frame (x, y, z about `position`): u along (frame[0], frame[1]) in x and z, v along (frame[2], frame[3]), y less frame[4]. */
210
+ frame: [number, number, number, number, number];
211
+ }
212
+ /**
213
+ * The signed distance field of a cliff piece in its local frame (u along the face, y world height, v out of the face;
214
+ * below 0 inside the rock) and the box it lives in. The face is the ground's own crossing of each height along the
215
+ * facing, moved `proud` out, leaning `overhang` out over its top third, stepped by the strata and cut by joints.
216
+ */
217
+ export declare function cliffField(site: CliffSite, ground: RockGround, options?: CliffOptions): RockField;
218
+ /**
219
+ * Builds a cliff piece as a closed mesh around its site's mid-face `position`: the face stands `proud` in front of the
220
+ * heightfield (so the smooth slope never shows), leans `overhang` out over its top third, steps in strata ledges and is
221
+ * cut by joint cracks. Fade its foot into the ground with `TerrainBlend` and shade it with `RockSurface`.
222
+ * @throws RangeError for a site that is not a cliff, a ground or option out of range, or a piece over 64 million samples.
223
+ * @example const rock = buildCliff(sites.cliffs[0], ground, { overhang: 4 });
224
+ * engine.createMesh().setGeometry(rock.geometry).setPosition(rock.position);
225
+ */
226
+ export declare function buildCliff(site: CliffSite, ground: RockGround, options?: CliffOptions): RockMesh<CliffSite>;
227
+ /**
228
+ * The signed distance field of a stack or skerry about its site (u = x, v = z less the site's; y world height): a
229
+ * lumpy tapering column with a wave-cut notch at the sea surface (a band `notchHeight` high centred a tenth of it above
230
+ * still water, Trenhaile 1987), strata ledges, joints around it and a rounded top.
231
+ */
232
+ export declare function seaRockField(site: SeaRockSite, options?: SeaRockOptions): RockField;
233
+ /**
234
+ * Builds a stack or skerry as a closed mesh about its site's `position` (x, bed height, z). Its notch sits at the sea
235
+ * surface it was found in (`site.seaLevel`).
236
+ * @throws RangeError for a site that is not a sea rock or an option out of range.
237
+ * @example for (const s of sites.seaRocks) { const r = buildSeaRock(s); engine.createMesh().setGeometry(r.geometry).setPosition(r.position); }
238
+ */
239
+ export declare function buildSeaRock(site: SeaRockSite, options?: SeaRockOptions): RockMesh<SeaRockSite>;
240
+ /**
241
+ * The signed distance field of a boulder about its centre. The seed varies the proportions, joint orientation and
242
+ * fracture planes. The bed face and principal joints keep broad faces between the rounded edges.
243
+ */
244
+ export declare function boulderField(site: BoulderSite, options?: BoulderOptions): RockField;
245
+ /**
246
+ * Builds a boulder as a closed mesh about its centre, which lies `embed` of its radius above the ground point of its site
247
+ * (so that much of it is buried).
248
+ * @throws RangeError for a site that is not a boulder or an option out of range.
249
+ */
250
+ export declare function buildBoulder(site: BoulderSite, options?: BoulderOptions): RockMesh<BoulderSite>;
251
+ /**
252
+ * Builds every site `findRockSites` found: cliffs, then sea rocks, then boulders, in the sites' order.
253
+ * @throws RangeError as the single builders do.
254
+ * @example
255
+ * const sites = findRockSites(ground, { seaLevel: 0 });
256
+ * for (const rock of buildRocks(sites, ground)) engine.createMesh().setGeometry(rock.geometry).setPosition(rock.position);
257
+ */
258
+ export declare function buildRocks(sites: RockSites, ground: RockGround, options?: BuildRocksOptions): RockMesh[];