@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
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import type { EngineKernel } from '@margoengine/core';
3
3
  import { type Engine, type EnginePlugin, type FrameGraph, type PassContext } from '@margoengine/core/extension';
4
4
  export { clipmapGrid } from './grid.js';
5
- export { TerrainColors, wetSandAfter, type SandSurface, type TerrainColorOptions, type TerrainLook, type TerrainLookUpdate, } from './colors.js';
5
+ export { DRY_SAND, TerrainColors, wetSandAfter, type SandSurface, type TerrainColorOptions, type TerrainLook, type TerrainLookUpdate, } from './colors.js';
6
6
  export { heightfield, heightfieldGeometry, TerrainHeightmap, type HeightField, type HeightfieldOptions, } from './heightfield.js';
7
7
  type TerrainPassContext = Extract<PassContext, {
8
8
  backend: 'webgpu';
@@ -38,6 +38,27 @@ export interface TerrainTextures {
38
38
  * (`@margoengine/terrain/holes`) makes and edits one. Without it the shaders and bindings are unchanged. Default: none.
39
39
  */
40
40
  holes?: GPUTexture;
41
+ /**
42
+ * Optional rock structure over the heightmap's bounds, read with `TerrainOptions.rock`: one `rgba8unorm` 2D texture of
43
+ * any size, sampled bilinearly. R is drainage, 0 to 1 (gullies and couloirs are carved along it), G loose debris such
44
+ * as talus fans below rock walls, 0 to 1. `@margoengine/biomes/hydrology` `drainageStructure` makes the values from a
45
+ * height grid. Without `rock` it is not read. Default: none (rock draws ledges and facets only).
46
+ */
47
+ structure?: GPUTexture;
48
+ /** More data the terrain's shaders read, such as a stream's far ring (`TerrainStreamOptions.far`). Default: none. */
49
+ source?: TerrainSource;
50
+ }
51
+ /**
52
+ * Data added to every terrain shader (colour, capture, shadow, occluder and surface-height passes alike), in bind group
53
+ * 0 after the terrain's own bindings. `@margoengine/terrain/far` makes one for a streamed terrain.
54
+ */
55
+ export interface TerrainSource {
56
+ /** The layout entries, bound from `binding` on. */
57
+ entries(binding: number): GPUBindGroupLayoutEntry[];
58
+ /** The resources of those entries, in binding order. */
59
+ resources(): GPUBindingResource[];
60
+ /** Returns `code`, a terrain shader, reading the data bound from `binding` on. */
61
+ shader(code: string, binding: number): string;
41
62
  }
42
63
  /** A splat rule: where layer i's texture shows. Rules blend smoothly around their bounds; layer 0 is the fallback. */
43
64
  export interface TerrainLayer {
@@ -50,8 +71,10 @@ export interface TerrainLayer {
50
71
  /**
51
72
  * Relief from the layer's own texture, 0 to 1: its luma becomes a height of up to `bump` halves of one texture repeat
52
73
  * (2 m at scale 0.25), and the shading normal follows that height's slope (derivative bump mapping, Mikkelsen 2010).
53
- * No extra texture samples; the mips flatten it with distance, and its slope falls once a pixel covers over 1/64 of a
54
- * repeat on the ground. Default 0 (no bump).
74
+ * Where a pixel covers less than 1/128 of a repeat (3 cm at `scale` 0.25) the height is the layer's 128-texel mip
75
+ * through a cubic filter (16 texel loads a projection), so a magnified texture draws no speckle or facets. The mips
76
+ * flatten it with distance, and its slope falls once a pixel covers over 1/64 of a repeat on the ground.
77
+ * Default 0 (no bump).
55
78
  */
56
79
  bump?: number;
57
80
  /**
@@ -118,6 +141,75 @@ export interface TerrainOptions {
118
141
  * overlays, sculpt) stay in world coordinates. Default: none (the shaders, uniforms and rules stay as they were).
119
142
  */
120
143
  floatingOrigin?: TerrainOrigin;
144
+ /**
145
+ * With `TerrainTextures.weights` only: resolves layers that share a texel into patches with crisp edges instead of
146
+ * their average, the way an alpine slope is turf, scree and rock side by side. Each layer gets its own value noise
147
+ * of `size`-metre cells (default 14) times `contrast` (0 to 1, default 0.6) added to its weight, and only the layers
148
+ * near the highest sum show (height-based splatting); weights of 0 and 1 stay as painted, and far ground, where a
149
+ * pixel covers a cell, hands back to the painted weights. Default: none (the shader is unchanged).
150
+ * @example
151
+ * Terrain.attach(engine, { ...options, patches: { size: 18, contrast: 0.7 } });
152
+ */
153
+ patches?: TerrainPatches;
154
+ /**
155
+ * Structure for bare rock at 10 to 100 m, where the heightmap draws a steep face as one smooth plane: ledges along
156
+ * beds, jointed facets that catch and lose the light, and (with `TerrainTextures.structure`) gullies carved along the
157
+ * drainage with debris fans below. Shading only: the normal and the colour's tone change, the heights do not. Every
158
+ * part fades in between `slope` degrees and fades out where a pixel covers a good share of it. Default: none (the
159
+ * shader is unchanged).
160
+ * @example
161
+ * Terrain.attach(engine, { ...options, rock: { strata: 8, facets: 20 } });
162
+ */
163
+ rock?: TerrainRock;
164
+ }
165
+ /** `TerrainOptions.patches`. */
166
+ export interface TerrainPatches {
167
+ /** Patch cell in metres, 0.5 to 10,000. Default 14. */
168
+ readonly size?: number;
169
+ /** How far each layer's noise lifts it over the others, above 0 to 1. Default 0.6. */
170
+ readonly contrast?: number;
171
+ /**
172
+ * 0 to 1: displaces the patch noise by a broader noise and adds an octave of 3.3 cells, so patches come in clusters
173
+ * and strands of several sizes rather than one blob size. Default 0.
174
+ */
175
+ readonly warp?: number;
176
+ /**
177
+ * Metres of height per contour band, 0 (none) or 0.5 to 1,000: patches stretch along the contours (turf banks, gravel
178
+ * strips). Default 0.
179
+ */
180
+ readonly terraces?: number;
181
+ }
182
+ /** `TerrainOptions.rock`. Every field has a default. */
183
+ export interface TerrainRock {
184
+ /** Slope in degrees where the structure fades in, [start, full], 0 <= start < full <= 90. Default [28, 44]. */
185
+ readonly slope?: readonly [number, number];
186
+ /** Bed thickness in metres for ledges, 0 (none) or 0.5 to 500. Default 9. */
187
+ readonly strata?: number;
188
+ /** How far beds step into benches and risers, 0 to 1. Default 0.6. */
189
+ readonly ledges?: number;
190
+ /** Tilt of the beds: metres of rise per metre along x and z, each -4 to 4. Default [0, 0] (level beds). */
191
+ readonly dip?: readonly [number, number];
192
+ /** Joint block size in metres, 0 (none) or 0.5 to 500. Default 18. */
193
+ readonly facets?: number;
194
+ /** How far a block's face tilts from the slope, 0 to 1. Default 0.45. */
195
+ readonly relief?: number;
196
+ /** Gully depth in metres along `TerrainTextures.structure`'s drainage, 0 to 100. Default 6. */
197
+ readonly gullies?: number;
198
+ /** Tone variation between beds and blocks and in gullies, 0 to 1. Default 0.35. */
199
+ readonly tone?: number;
200
+ /**
201
+ * Relief in metres of the 5 to 50 m ground forms (felsenmeer, turf banks, solifluction lobes, frost hummocks) shaded
202
+ * into gentle ground below `slope`'s start, where a heightmap of several metres a texel is smooth and a repeating
203
+ * layer texture reads as streaks at grazing angles; 0 to 10. Three octaves of 48, 20 and 8 m tilt the shading
204
+ * normal and shade their crests and hollows, each fading out as the pixel's footprint nears its wavelength. Default 0
205
+ * (none).
206
+ */
207
+ readonly undulation?: number;
208
+ /**
209
+ * The layer (index) that benches, gully floors below the faces and `structure` debris fans take, with
210
+ * `TerrainTextures.weights`. Default: none.
211
+ */
212
+ readonly debris?: number;
121
213
  }
122
214
  /** What `setCapture` takes: `@margoengine/post` SSR's material capture hook (its `SSRCapture`), declared here so terrain
123
215
  * does not import post. */
@@ -171,7 +263,8 @@ export declare class Terrain implements EnginePlugin {
171
263
  private layout?;
172
264
  private shadowPipeline?;
173
265
  /** Reversed-depth variant of the shadow pipeline for local light maps, built on first use. */
174
- private localShadowPipeline?;
266
+ /** The local shadow pipelines: reversed depth (`greater`) at 0, forward (`less-equal`) at 1. */
267
+ private localShadowPipelines;
175
268
  private shadowModule?;
176
269
  private ringGroup?;
177
270
  private occluder?;
@@ -193,6 +286,9 @@ export declare class Terrain implements EnginePlugin {
193
286
  private readonly shiftValues;
194
287
  /** The shift the layer rules were last written with, and the scratch eye and ring plan of `prepare`. */
195
288
  private readonly rulesShift;
289
+ /** The world eye the layer rules' `eyeWrap` was last written for (NaN: never), and the local eye of `prepare`. */
290
+ private readonly rulesEye;
291
+ private readonly eyeLocal;
196
292
  private readonly eye;
197
293
  private anchoredEye?;
198
294
  private capturedSurface?;
@@ -227,8 +323,8 @@ export declare class Terrain implements EnginePlugin {
227
323
  setup(engine: Engine): void;
228
324
  /**
229
325
  * The layer rules: 8 floats a layer; 12 with `bump` or `macro` (surfaceStruct: bump metres per unit of luma, macro,
230
- * macro scale); with `floatingOrigin` 8 more (originShader: `wrap` and `tone` per axis) and the height bounds less the
231
- * shift's Y, as positions reach the shader local.
326
+ * macro scale); with `floatingOrigin` 16 more (originShader: `wrap` and `tone` per axis for the shift, `eyeWrap` and
327
+ * `eyeTone` for the eye) and the height bounds less the shift's Y, as positions reach the shader local.
232
328
  */
233
329
  private ruleData;
234
330
  registerPasses(graph: FrameGraph): void;
@@ -246,8 +342,17 @@ export declare class Terrain implements EnginePlugin {
246
342
  } | undefined;
247
343
  /** The terrain's own shader (with `roughness`, when given) and its edge and hole tests, before any effect. */
248
344
  private base;
249
- /** With `TerrainTextures.holes`: declares the mask after the weights and tint and adds its test to the edge test. */
345
+ /**
346
+ * With `TerrainTextures.holes`: declares the mask after the weights and tint and adds its test to the edge test. With
347
+ * `TerrainTextures.source`: its shader additions, after the mask's binding.
348
+ */
250
349
  private clip;
350
+ /** The group-0 binding of `TerrainTextures.holes`: after the weights and tint. */
351
+ private holesBinding;
352
+ /** The first group-0 binding after the weights, tint, holes and structure: where a `source` binds. */
353
+ private sourceBinding;
354
+ /** `TerrainOptions.rock` resolved for the shader (the structure texture binds before any source), or undefined. */
355
+ private rockShader;
251
356
  /** Whether any layer sets `bump` or `macro`; without, the shader and rules are what they were before both. */
252
357
  private surface;
253
358
  private drawRings;
@@ -262,6 +367,8 @@ export declare class Terrain implements EnginePlugin {
262
367
  /** `mode` 'capture': draws the terrain into the capture hook's pass (`setCapture`); `color` and `depth` are unused (the
263
368
  * hook's pass has its own). Does nothing without a hook or after disposal. */
264
369
  draw(c: TerrainPassContext, mode: 'capture', color?: GPUTextureView, depth?: GPUTextureView): void;
370
+ /** Whether `camera`'s matrix or eye differs, as float32, from the one the rings were prepared with. */
371
+ private otherCamera;
265
372
  private lightingGroup;
266
373
  /**
267
374
  * Draws the terrain's depth with the frame's camera into an occluder pass of @margoengine/culling
@@ -279,13 +386,17 @@ export declare class Terrain implements EnginePlugin {
279
386
  }): void;
280
387
  /**
281
388
  * Casts the terrain into a point, spot, directional or area light's map of clustered `LocalShadows` (pass the
282
- * terrain to `LocalShadows.add`). Reversed depth (`greater`), one uniform set per ring and layer, made on first use.
389
+ * terrain to `LocalShadows.add`) or of Clustered's integrated `shadows` maps (`addShadowCaster`). The depth test is
390
+ * the draw's `depthCompare`: `greater` (reversed depth, LocalShadows and the default) or `less-equal` (the integrated
391
+ * maps). One uniform set per ring, layer and depth convention, made on first use, so both systems' layers of one
392
+ * frame never share one.
283
393
  */
284
- drawLocalShadow({ context, pass, matrix, layer, }: {
394
+ drawLocalShadow({ context, pass, matrix, layer, depthCompare, }: {
285
395
  context: TerrainPassContext;
286
396
  pass: GPURenderPassEncoder;
287
397
  matrix: Float32Array;
288
398
  layer: number;
399
+ depthCompare?: 'greater' | 'less-equal';
289
400
  }): void;
290
401
  /** Writes `values` to `buffer` unless the buffer already holds exactly these bits (compared bit for bit, so -0 and NaN count). */
291
402
  private upload;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { t as Terrain, o as TerrainColors, r as TerrainHeightmap, c as clipmapGrid, i as heightfield, a as heightfieldGeometry, n as planRings, s as wetSandAfter } from "./src-C6dtSaAb.js";
1
+ export { o as DRY_SAND, t as Terrain, s as TerrainColors, r as TerrainHeightmap, l as clipmapGrid, i as heightfield, a as heightfieldGeometry, n as planRings, c as wetSandAfter } from "./src-Cr7Gm4n0.js";
@@ -1,10 +1,10 @@
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 e=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
3
+ const e=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
4
  import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
5
5
  import { MargoError as t } from "@margoengine/math/errors";
6
6
  //#region src/layers-pbr.ts
7
- var n = 90, r = 0, i = class i {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
7
+ var n = 90, r = 0, i = class i {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
8
8
  constructor(e, t) {
9
9
  this.terrain = e, this.options = t, this.name = "terrain-materials:" + r++, this.disposed = !1, this.entries = [], this.cache = /* @__PURE__ */ new Map();
10
10
  let n = e?.options?.layers?.length;
@@ -12,7 +12,7 @@ var n = 90, r = 0, i = class i {coreRequirement=__margoCoreRequirement("0.1.0",i
12
12
  let i = t.heightBlend ?? .5, a = t.layers ?? [];
13
13
  if (!(i >= 0 && i <= 1) || !Array.isArray(a) || a.length > n || !a.every((e) => (e.normal ?? 1) >= 0 && (e.normal ?? 1) <= 2 && (e.occlusion ?? 1) >= 0 && (e.occlusion ?? 1) <= 1 && (e.roughness ?? 1) >= 0 && (e.roughness ?? 1) <= 2)) throw RangeError("Invalid terrain materials; give heightBlend 0..1 and at most one entry per terrain layer with normal 0..2, occlusion 0..1 and roughness 0..2.");
14
14
  }
15
- static attach(t, n, r) {__margoAssertCore(t,__margoCoreRequirement("0.1.0",import.meta.url));
15
+ static attach(t, n, r) {__margoAssertCore(t,__margoCoreRequirement("1.0.0",import.meta.url));
16
16
  let a = new i(n, r);
17
17
  return e(t).use(a), a;
18
18
  }
@@ -58,14 +58,14 @@ var n = 90, r = 0, i = class i {coreRequirement=__margoCoreRequirement("0.1.0",i
58
58
  shader(e, n) {
59
59
  let r = n + e, i = this.cache.get(r);
60
60
  if (i) return i;
61
- let a = "@fragment fn fragment(i:Output)->@location(0) vec4f {", s = "let n=normalize(i.normal);let base=terrainColor(i.position,n);", c = "let n=terrainBump(i.position,terrainN);", l = "let weight=smoothstep(", u = "let weight=packed[layer/4u][layer%4u];if(weight<=0.0){continue;}", d = "+base*frame.radiance.w";
61
+ let a = "@fragment fn fragment(i:Output)->@location(0) vec4f {", s = "let n=normalize(i.normal);let base=terrainColor(i.position,n);", c = "let n=terrainRock(i.position,normalize(i.normal));let base=terrainColor(i.position,normalize(i.normal))*terrainRockShade;", l = "let n=terrainBump(i.position,terrainN);", u = "let weight=smoothstep(", d = "let weight=packed[layer/4u][layer%4u];if(weight<=0.0){continue;}", f = "+base*frame.radiance.w*frame.ambient.rgb";
62
62
  if ([
63
63
  a,
64
- d,
64
+ f,
65
65
  "total+=weight;"
66
- ].some((t) => e.split(t).length !== 2) || e.includes(s) === e.includes(c) || e.includes(l) === e.includes(u)) throw new t("unsupported", "Terrain materials need the terrain's own lit shader; attach them before any effect that replaces it");
67
- let f = "i.material.x=terrainPbrRoughness(i.material.x);", p = o(n), m = (e.includes("wrap:vec4f") ? p.split("position*s,").join("(position+layerRules[layer].wrap.xyz)*s,") : p) + e.replace(a, "fn terrainPbrShade(terrainIn:Output)->vec4f {var i=terrainIn;").replace(s, `let terrainN0=normalize(i.normal);let base=terrainColor(i.position,terrainN0);let n=terrainPbrNormal(terrainN0);${f}`).replace(c, `let n=terrainPbrNormal(terrainBump(i.position,terrainN));${f}`).replace(l, "let weight=terrainPbrHeight(position,projection,dx,dy,layer)*smoothstep(").replace(u, "let painted=packed[layer/4u][layer%4u];if(painted<=0.0){continue;}let weight=painted*terrainPbrHeight(position,projection,dx,dy,layer);").replace("total+=weight;", "total+=weight;terrainPbrLayer(position,projection,dx,dy,layer,weight);").replace(d, d + "*terrainPbrOcclusion()");
68
- return m += `\n${a}return terrainPbrShade(i);}\n`, this.cache.size >= 16 && this.cache.clear(), this.cache.set(r, m), m;
66
+ ].some((t) => e.split(t).length !== 2) || (e.includes(s) || e.includes(c)) === e.includes(l) || e.includes(u) === e.includes(d)) throw new t("unsupported", "Terrain materials need the terrain's own lit shader; attach them before any effect that replaces it");
67
+ let p = "i.material.x=terrainPbrRoughness(i.material.x);", m = o(n), h = (e.includes("wrap:vec4f") ? m.split("position*s,").join("(position+layerRules[layer].wrap.xyz)*s,") : m) + e.replace(a, "fn terrainPbrShade(terrainIn:Output)->vec4f {var i=terrainIn;").replace(s, `let terrainN0=normalize(i.normal);let base=terrainColor(i.position,terrainN0);let n=terrainPbrNormal(terrainN0);${p}`).replace(c, `let terrainN0=terrainRock(i.position,normalize(i.normal));let base=terrainColor(i.position,normalize(i.normal))*terrainRockShade;let n=terrainPbrNormal(terrainN0);${p}`).replace(l, `let n=terrainPbrNormal(terrainBump(i.position,terrainN));${p}`).replace(u, "let weight=terrainPbrHeight(position,projection,dx,dy,layer)*smoothstep(").replace(d, "let painted=packed[layer/4u][layer%4u];if(painted<=0.0){continue;}let weight=painted*terrainPbrHeight(position,projection,dx,dy,layer);").replace("total+=weight;", "total+=weight;terrainPbrLayer(position,projection,dx,dy,layer,weight);").replace(f, f + "*terrainPbrOcclusion()");
68
+ return h += `\n${a}return terrainPbrShade(i);}\n`, this.cache.size >= 16 && this.cache.clear(), this.cache.set(r, h), h;
69
69
  }
70
70
  onDeviceRestored(e) {
71
71
  this.release(), this.setup(e);
package/dist/overlays.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 "./errors-fc4i1pSL.js";
5
5
  import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
6
6
  //#region src/overlays.ts
@@ -119,7 +119,7 @@ function o(e, t) {
119
119
  };
120
120
  return u(e), i;
121
121
  }
122
- var s = 0, c = class n {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
122
+ var s = 0, c = class n {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
123
123
  #e;
124
124
  #t;
125
125
  #n;
@@ -136,7 +136,7 @@ var s = 0, c = class n {coreRequirement=__margoCoreRequirement("0.1.0",import.me
136
136
  binding: t.binding ?? 120
137
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
138
  }
139
- static attach(e, r, i = {}) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
139
+ static attach(e, r, i = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
140
140
  let a = new n(r, i);
141
141
  return t(e).use(a), a;
142
142
  }
@@ -0,0 +1,31 @@
1
+ /** The Moon's transition diameter in metres: where Pike's simple and complex depth laws meet. */
2
+ export declare const LUNAR_TRANSITION = 10583;
3
+ /** The shape of one crater: lengths in metres, widths as fractions of the radius. */
4
+ export interface CraterShape {
5
+ /** Rim crest to floor. */ depth: number;
6
+ /** Rim crest above the surrounding ground, before the ejecta blanket. */ rim: number;
7
+ /** Fraction of the radius that is flat floor. */ floor: number;
8
+ /** Central peak height above the floor; 0 for none. */ peak: number;
9
+ /** Central peak base radius as a fraction of the crater radius. */ peakWidth: number;
10
+ /** Strength of the wall terraces, 0 for a smooth wall. */ terraces: number;
11
+ /** Radial width of the outermost terrace as a fraction of the wall's width. */ step: number;
12
+ }
13
+ export interface ShapeLaws {
14
+ depthRatio: number;
15
+ rimRatio: number;
16
+ floor: number;
17
+ transition: number;
18
+ peaks: number;
19
+ terraces: number;
20
+ }
21
+ /**
22
+ * Pike's simple laws up to the transition diameter, his complex laws past it. Another body's transition rescales the
23
+ * lunar laws about it: a crater is shaped like the lunar crater the same multiple past the Moon's transition.
24
+ */
25
+ export declare function craterShape(diameter: number, laws: ShapeLaws, out: CraterShape): CraterShape;
26
+ /**
27
+ * Height inside the rim of a crater (`s` the distance from its centre over its radius, below 1): `floorHeight` on the
28
+ * floor, `crest` at the rim, with the shape's peak and terraces. (u, v, w) is the sample in lengths of 0.12 crater
29
+ * diameters, offset per crater: the noise that makes walls and peaks irregular. The floor and rim heights are exact.
30
+ */
31
+ export declare function craterInterior(s: number, floorHeight: number, crest: number, shape: CraterShape, u: number, v: number, w: number): number;
@@ -1,4 +1,6 @@
1
+ import { type RayedCrater } from './planet-rays.js';
1
2
  import type { PlanetHeight } from './planet.js';
3
+ export type { RayedCrater } from './planet-rays.js';
2
4
  /** `craterField` options. Every one is optional. */
3
5
  export interface CraterFieldOptions {
4
6
  /** Radius in metres of the planet the field is for, above 0. Default 6,371,000; pass the planet's own radius. */
@@ -15,14 +17,30 @@ export interface CraterFieldOptions {
15
17
  exponent?: number;
16
18
  /** An integer. Default 1. Another seed makes another population. */
17
19
  seed?: number;
18
- /** Depth coefficient: depth = depthRatio * D^1.01 with D in kilometres (Pike 1977), 0 or more. Default 0.196. */
20
+ /** Depth coefficient: rim crest to floor = depthRatio * D^1.01 with D in kilometres (Pike 1977), 0 or more. Default 0.196. */
19
21
  depthRatio?: number;
20
22
  /** Rim height coefficient: rim = rimRatio * D^1.01 with D in kilometres, 0 or more. Default 0.036. */
21
23
  rimRatio?: number;
22
- /** Deepest a crater gets, in metres, above 0. Default 3,400 (Pike 1977); larger craters are scaled down, not clipped. */
24
+ /** Deepest a floor gets below the surrounding ground, in metres, above 0. Default 3,400 (Pike 1977); larger craters are scaled down, not clipped. */
23
25
  maxDepth?: number;
24
- /** Fraction of a crater's radius that is flat floor, 0 to below 1. Default 0. */
26
+ /** Fraction of a crater's radius that is flat floor, 0 to below 1. Default 0. Complex craters have at least Pike's. */
25
27
  floor?: number;
28
+ /**
29
+ * Rim diameter in metres past which craters are complex (flat floor, central peak, terraces, shallower for their
30
+ * size), above 0. Default 10,583, the Moon's (Pike 1977); Infinity keeps every crater a simple bowl.
31
+ */
32
+ transition?: number;
33
+ /** Scale of the central peaks of complex craters, 0 (none) or more. Default 1 (Pike 1977's height). */
34
+ peaks?: number;
35
+ /** Strength of the wall terraces of complex craters, 0 (smooth walls) to 1. Default 1. */
36
+ terraces?: number;
37
+ /**
38
+ * Young craters with bright rays and secondary crater chains: a count, an integer 0 to 64 placed by the seed, or the
39
+ * craters themselves (at most 64, the last the youngest). Default 0. They are younger than every other crater.
40
+ */
41
+ rayed?: number | readonly RayedCrater[];
42
+ /** Smallest and largest diameter in metres of counted rayed craters. Default [radius / 60, radius / 16]. */
43
+ rayedSize?: readonly [number, number];
26
44
  /** Add the ejecta blanket (McGetchin et al. 1973) beyond the rim. Default true. */
27
45
  ejecta?: boolean;
28
46
  /** 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. */
@@ -46,6 +64,13 @@ export interface CraterField extends PlanetHeight {
46
64
  * At most about 27 cells times the octaves of diameter are read, whatever the planet's size.
47
65
  */
48
66
  craters(x: number, y: number, z: number, detail?: number): PlanetCrater[];
67
+ /** The young craters that have rays, oldest first, centres as unit directions. */
68
+ readonly rayed: readonly RayedCrater[];
69
+ /**
70
+ * Fresh bright ground at a direction, 0 (none) to 1: halos and rays of the rayed craters. Pass it to
71
+ * `PlanetTerrain`'s `brightness`.
72
+ */
73
+ readonly brightness: PlanetHeight;
49
74
  }
50
75
  /**
51
76
  * Craters for a planet's ground, heights in metres relative to the undisturbed surface (bowls below 0, rims and ejecta
@@ -0,0 +1,37 @@
1
+ /** A young crater with rays. */
2
+ export interface RayedCrater {
3
+ /** Direction of the centre from the planet's centre (any non-zero length). */
4
+ readonly x: number;
5
+ readonly y: number;
6
+ readonly z: number;
7
+ /** Rim diameter in metres. */
8
+ readonly diameter: number;
9
+ }
10
+ interface Ray {
11
+ azimuth: number;
12
+ length: number;
13
+ halfWidth: number;
14
+ strength: number;
15
+ along: Float64Array;
16
+ across: Float64Array;
17
+ size: Float64Array;
18
+ largest: number;
19
+ reach: number;
20
+ }
21
+ export interface RaySystem extends RayedCrater {
22
+ readonly rays: readonly Ray[];
23
+ readonly east: readonly [number, number, number];
24
+ readonly north: readonly [number, number, number];
25
+ /** Cosine of the angle past which nothing of the system reaches. */
26
+ readonly limit: number;
27
+ }
28
+ /** The rays and secondary chains of one young crater on a planet of `radius` metres. Deterministic for `next`. */
29
+ export declare function raySystem(crater: RayedCrater, radius: number, next: () => number): RaySystem;
30
+ /**
31
+ * The ground after the system's secondary chains cut it: `previous` metres in, the new height out. Secondaries under
32
+ * twice `detail` are left out.
33
+ */
34
+ export declare function secondaryHeight(system: RaySystem, radius: number, x: number, y: number, z: number, detail: number, previous: number, depthRatio: number, rimRatio: number, blend: number): number;
35
+ /** Fresh bright material at the sample from one system, 0 (none) to 1: the halo around the crater and its rays. */
36
+ export declare function rayBrightness(system: RaySystem, radius: number, x: number, y: number, z: number): number;
37
+ export {};
@@ -1,6 +1,6 @@
1
1
  import type { PlanetHeight } from './planet.js';
2
2
  export { craterField } from './planet-craters.js';
3
- export type { CraterField, CraterFieldOptions, PlanetCrater } from './planet-craters.js';
3
+ export type { CraterField, CraterFieldOptions, PlanetCrater, RayedCrater } from './planet-craters.js';
4
4
  /** `ridgeNoise` options. Every one is optional. */
5
5
  export interface RidgeNoiseOptions {
6
6
  /** Planet radius in metres, above 0. Default 6,371,000. */
@@ -63,6 +63,15 @@ export type PlanetPresetName = 'moon' | 'mars' | 'asteroid' | 'ice';
63
63
  * @throws RangeError for an unknown name.
64
64
  */
65
65
  export declare function planetPresetRadius(name: PlanetPresetName): number;
66
+ /**
67
+ * The crater rays that go with `planetPreset` of the same name and options, for `PlanetTerrain`'s `brightness`: 0 to 1.
68
+ * The Moon has 6 rayed craters; the other presets have none and give 0 everywhere.
69
+ * @throws RangeError on an invalid name, radius or seed.
70
+ */
71
+ export declare function planetPresetBrightness(name: PlanetPresetName, options?: {
72
+ radius?: number;
73
+ seed?: number;
74
+ }): PlanetHeight;
66
75
  /**
67
76
  * A ready ground: `'moon'` (old cratered highlands), `'mars'` (fewer, softer craters on ridged uplands), `'asteroid'`
68
77
  * (crowded craters on a lumpy body) or `'ice'` (shallow craters and warped ridges). `radius` defaults to the body's own;