@threenative/terrain 0.1.7 → 0.1.9

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 (129) hide show
  1. package/AGENT_GUIDE.md +19 -4
  2. package/dist/editor/index.d.ts +218 -5
  3. package/dist/editor/index.js +4093 -1399
  4. package/dist/editor/server.d.ts +2 -2
  5. package/dist/editor/server.js +752 -124
  6. package/dist/editor/worker.d.ts +33 -1
  7. package/dist/editor/worker.js +642 -114
  8. package/dist/export.d.ts +11 -9
  9. package/dist/export.js +22 -34
  10. package/dist/index.d.ts +866 -73
  11. package/dist/index.js +3003 -523
  12. package/dist/kit.d.ts +57 -0
  13. package/dist/kit.js +2718 -0
  14. package/dist/mcp/cook-child.d.ts +2 -0
  15. package/dist/mcp/cook-child.js +5346 -0
  16. package/dist/mcp/server.d.ts +7 -0
  17. package/dist/mcp/server.js +3970 -0
  18. package/dist/{server-ByM2hmYJ.d.ts → server-B5RdvEAC.d.ts} +3 -2
  19. package/dist/starter.d.ts +143 -0
  20. package/dist/starter.js +1031 -0
  21. package/dist/{terrain-gPnkCU6S.d.ts → terrain-CAEaW0mQ.d.ts} +3 -2
  22. package/dist/three.d.ts +1 -1
  23. package/dist/{types-Ant8-Axc.d.ts → types-BpH00qsx.d.ts} +20 -4
  24. package/dist/world-package-B8QgHjAQ.d.ts +53 -0
  25. package/package.json +28 -6
  26. package/starter/alpine/README.md +77 -1
  27. package/starter/alpine/bake.mjs +4 -116
  28. package/starter/alpine/biome.data.json +134 -0
  29. package/starter/alpine/heightmap.r16 +0 -0
  30. package/starter/alpine/recipe.json +3 -66051
  31. package/starter/alpine/world.ts +45 -293
  32. package/starter/coastal/README.md +82 -3
  33. package/starter/coastal/assets.json +2 -1
  34. package/starter/coastal/bake.mjs +4 -116
  35. package/starter/coastal/biome.data.json +156 -0
  36. package/starter/coastal/heightmap.r16 +0 -0
  37. package/starter/coastal/recipe.json +3 -66051
  38. package/starter/coastal/sea.ts +51 -66
  39. package/starter/coastal/world.ts +53 -318
  40. package/starter/desert/README.md +77 -1
  41. package/starter/desert/bake.mjs +4 -116
  42. package/starter/desert/biome.data.json +124 -0
  43. package/starter/desert/heightmap.r16 +0 -0
  44. package/starter/desert/recipe.json +3 -66051
  45. package/starter/desert/world.ts +45 -293
  46. package/starter/forest/README.md +85 -5
  47. package/starter/forest/assets.json +34 -1
  48. package/starter/forest/bake.mjs +6 -116
  49. package/starter/forest/biome.data.json +173 -0
  50. package/starter/forest/heightmap.r16 +0 -0
  51. package/starter/forest/recipe.json +192 -4428
  52. package/starter/forest/sky.ts +11 -0
  53. package/starter/forest/water.ts +39 -48
  54. package/starter/forest/world.ts +92 -323
  55. package/starter/tundra/README.md +77 -1
  56. package/starter/tundra/bake.mjs +4 -116
  57. package/starter/tundra/biome.data.json +141 -0
  58. package/starter/tundra/heightmap.r16 +0 -0
  59. package/starter/tundra/recipe.json +18 -66066
  60. package/starter/tundra/water.ts +9 -28
  61. package/starter/tundra/world.ts +65 -319
  62. package/starter-assets.json +6 -0
  63. package/{starter-assets/credits.json → starter-credits.json} +12 -105
  64. package/starter-assets/bark_brown_02/bark_brown_02_diff_1k.jpg +0 -0
  65. package/starter-assets/bark_brown_02/bark_brown_02_nor_gl_1k.jpg +0 -0
  66. package/starter-assets/bark_brown_02/bark_brown_02_rough_1k.jpg +0 -0
  67. package/starter-assets/boulder_01/boulder-mid.glb +0 -0
  68. package/starter-assets/boulder_01/boulder-near.glb +0 -0
  69. package/starter-assets/cliff_side/cliff_side_ao_1k.jpg +0 -0
  70. package/starter-assets/cliff_side/cliff_side_diff_1k.jpg +0 -0
  71. package/starter-assets/cliff_side/cliff_side_nor_gl_1k.jpg +0 -0
  72. package/starter-assets/cliff_side/cliff_side_rough_1k.jpg +0 -0
  73. package/starter-assets/fern_02/fern_02_alpha_512.png +0 -0
  74. package/starter-assets/fern_02/fern_02_diff_512.jpg +0 -0
  75. package/starter-assets/fern_02/fern_02_nor_gl_512.jpg +0 -0
  76. package/starter-assets/fir_tree_01/fir-b-lod1.glb +0 -0
  77. package/starter-assets/fir_tree_01/fir-b-lod2.glb +0 -0
  78. package/starter-assets/fir_tree_01/fir-c-lod1.glb +0 -0
  79. package/starter-assets/fir_tree_01/fir-c-lod2.glb +0 -0
  80. package/starter-assets/fir_tree_01/fir_tree_01_twig_arm_1k.jpg +0 -0
  81. package/starter-assets/fir_tree_01/fir_tree_01_twig_diff_1k.jpg +0 -0
  82. package/starter-assets/fir_tree_01/fir_tree_01_twig_nor_gl_1k.jpg +0 -0
  83. package/starter-assets/forest_ground_04/forest_ground_04_ao_1k.jpg +0 -0
  84. package/starter-assets/forest_ground_04/forest_ground_04_diff_1k.jpg +0 -0
  85. package/starter-assets/forest_ground_04/forest_ground_04_nor_gl_1k.jpg +0 -0
  86. package/starter-assets/forest_ground_04/forest_ground_04_rough_1k.jpg +0 -0
  87. package/starter-assets/forest_leaves_02/forest_leaves_02_arm_512.jpg +0 -0
  88. package/starter-assets/forest_leaves_02/forest_leaves_02_diff_512.jpg +0 -0
  89. package/starter-assets/forest_leaves_02/forest_leaves_02_nor_gl_512.jpg +0 -0
  90. package/starter-assets/grass_medium_02/grass_medium_02_alpha_512.png +0 -0
  91. package/starter-assets/grass_medium_02/grass_medium_02_diff_512.jpg +0 -0
  92. package/starter-assets/grass_medium_02/grass_medium_02_nor_gl_512.jpg +0 -0
  93. package/starter-assets/hdri/kloofendal_48d_partly_cloudy_1k.hdr +0 -0
  94. package/starter-assets/leafy_grass/leafy_grass_ao_1k.jpg +0 -0
  95. package/starter-assets/leafy_grass/leafy_grass_diff_1k.jpg +0 -0
  96. package/starter-assets/leafy_grass/leafy_grass_nor_gl_1k.jpg +0 -0
  97. package/starter-assets/leafy_grass/leafy_grass_rough_1k.jpg +0 -0
  98. package/starter-assets/lichen_rock/lichen_rock_arm_512.jpg +0 -0
  99. package/starter-assets/lichen_rock/lichen_rock_diff_512.jpg +0 -0
  100. package/starter-assets/lichen_rock/lichen_rock_nor_gl_512.jpg +0 -0
  101. package/starter-assets/mossy_rock/mossy_rock_ao_1k.jpg +0 -0
  102. package/starter-assets/mossy_rock/mossy_rock_diff_1k.jpg +0 -0
  103. package/starter-assets/mossy_rock/mossy_rock_nor_gl_1k.jpg +0 -0
  104. package/starter-assets/mossy_rock/mossy_rock_rough_1k.jpg +0 -0
  105. package/starter-assets/needle-atlas.png +0 -0
  106. package/starter-assets/needle-surface.png +0 -0
  107. package/starter-assets/river_small_rocks/river_small_rocks_arm_512.jpg +0 -0
  108. package/starter-assets/river_small_rocks/river_small_rocks_diff_512.jpg +0 -0
  109. package/starter-assets/river_small_rocks/river_small_rocks_nor_gl_512.jpg +0 -0
  110. package/starter-assets/rock_boulder_dry/rock_boulder_dry_arm_512.jpg +0 -0
  111. package/starter-assets/rock_boulder_dry/rock_boulder_dry_diff_512.jpg +0 -0
  112. package/starter-assets/rock_boulder_dry/rock_boulder_dry_nor_gl_512.jpg +0 -0
  113. package/starter-assets/rocks/boulder-mid.glb +0 -0
  114. package/starter-assets/rocks/boulder-near.glb +0 -0
  115. package/starter-assets/rocks/boulder-prep.json +0 -37
  116. package/starter-assets/rocks/rock01-mid.glb +0 -0
  117. package/starter-assets/rocks/rock01-near.glb +0 -0
  118. package/starter-assets/rocks/rock01-prep.json +0 -37
  119. package/starter-assets/rocks/rock04-mid.glb +0 -0
  120. package/starter-assets/rocks/rock04-near.glb +0 -0
  121. package/starter-assets/rocks/rock04-prep.json +0 -37
  122. package/starter-assets/sand_01/sand_01_ao_1k.jpg +0 -0
  123. package/starter-assets/sand_01/sand_01_diff_1k.jpg +0 -0
  124. package/starter-assets/sand_01/sand_01_nor_gl_1k.jpg +0 -0
  125. package/starter-assets/sand_01/sand_01_rough_1k.jpg +0 -0
  126. package/starter-assets/snow_02/snow_02_ao_1k.jpg +0 -0
  127. package/starter-assets/snow_02/snow_02_diff_1k.jpg +0 -0
  128. package/starter-assets/snow_02/snow_02_nor_gl_1k.jpg +0 -0
  129. package/starter-assets/snow_02/snow_02_rough_1k.jpg +0 -0
package/dist/index.d.ts CHANGED
@@ -1,6 +1,646 @@
1
- export { L as LayerPatch, O as OperationOptions, P as PatchCommand, T as Terrain, a as TerrainEvaluator } from './terrain-gPnkCU6S.js';
2
- import { M as MaterialId, a as IMask, i as ISampledGrid, O as OperationType, d as ITerrainDocument, I as ITerrainState, j as IBakeMeshOptions, g as IBakedMesh, k as IBakeTerrainOptions, l as IBakedTerrain, h as IPlacementOverride, m as IDecodeHeightPngOptions, n as IDecodeRaw16Options, o as IHeightRange, p as IRaw16Options, q as IExportFile, E as ExportKind, r as IExportArchive } from './types-Ant8-Axc.js';
3
- export { s as IBiomeParams, t as IBrushParams, u as IClearParams, f as ICopyRegionOptions, v as IDecodedHeightPng, w as IErodeParams, x as IErosionMaps, e as IEvaluateOptions, y as IFlattenParams, z as IGradeParams, A as IGrid, B as IHeightData, C as IHeightPngMetadata, D as IHeightmapParams, F as ILayer, G as IMaterialRule, H as IMaterialsParams, J as INoiseParams, K as IPaintParams, N as IPasteParams, P as IPlacement, Q as IRampParams, R as IRiver, S as IRiverParams, T as IRoadParams, U as IScatterClear, V as IScatterParams, W as IScatterRule, X as ISculptParams, Y as ISmoothParams, Z as ISplatPng, _ as IStampParams, $ as ITerraceParams, c as ITerrainConfig, a0 as ITerrainInspection, a1 as IWaterBody, a2 as IWaterParams, a3 as IWaterRule, L as Layer, b as LayerParams, a4 as MaskSampler, a5 as MaskType, a6 as SplinePoint } from './types-Ant8-Axc.js';
1
+ import { T as Terrain } from './terrain-CAEaW0mQ.js';
2
+ export { L as LayerPatch, O as OperationOptions, P as PatchCommand, a as TerrainEvaluator } from './terrain-CAEaW0mQ.js';
3
+ import { e as ITerrainConfig, j as IPlacement, k as IErosionMaps, I as ITerrainState, M as MaterialId, c as IMask, l as ISampledGrid, O as OperationType, b as ITerrainDocument, m as IBakeMeshOptions, h as IBakedMesh, n as IBakeTerrainOptions, o as IBakedTerrain, i as IPlacementOverride, p as IDecodeHeightPngOptions, q as IDecodeRaw16Options, r as IHeightRange, s as IRaw16Options, t as IExportFile, a as IExportArchive, E as ExportKind } from './types-BpH00qsx.js';
4
+ export { u as IBiomeParams, v as IBrushParams, w as IClearParams, g as ICopyRegionOptions, x as IDecodedHeightPng, y as IErodeParams, f as IEvaluateOptions, z as IFlattenParams, A as IGradeParams, B as IGrid, C as IHeightData, D as IHeightPngMetadata, F as IHeightmapParams, G as ILayer, H as IMaterialRule, J as IMaterialsParams, K as INoiseParams, N as IPaintParams, P as IPasteParams, Q as IRampParams, R as IRiver, S as IRiverParams, T as IRoadParams, U as IScatterClear, V as IScatterParams, W as IScatterRule, X as ISculptParams, Y as ISmoothParams, Z as ISplatPng, _ as IStampParams, $ as ITerraceParams, a0 as ITerrainInspection, a1 as IWaterBody, a2 as IWaterParams, a3 as IWaterRule, L as Layer, d as LayerParams, a4 as MaskSampler, a5 as MaskType, a6 as SplinePoint } from './types-BpH00qsx.js';
5
+ import { Heightfield, HeightfieldCollar } from '@threenative/core/world';
6
+ import { c as IBakeWorldPackageOptions, I as IWorldPackageAsset, d as IBakedWorldPackage, a as IWorldPackageManifest, e as IWorldPackageRun } from './world-package-B8QgHjAQ.js';
7
+ export { b as bakeWorldPackage } from './world-package-B8QgHjAQ.js';
8
+ import { BufferAttribute } from 'three';
9
+
10
+ type LandformKind = "alpine" | "temperateMountains" | "rollingHills" | "desertMesa" | "coastalCliffs" | "tundra" | "volcanic";
11
+ interface ILandformOptions extends Partial<ITerrainConfig> {
12
+ /** Highest minus lowest height in metres. Defaults to the kind's real ratio times `size`. */
13
+ relief?: number;
14
+ }
15
+ interface ILandformInfo {
16
+ readonly summary: string;
17
+ /** Default relief as a fraction of the world size. */
18
+ readonly reliefRatio: number;
19
+ /** Where the shape comes from: a public-domain DEM the repo carries, or a cited landscape. */
20
+ readonly reference: string;
21
+ /** Measured DEM statistics (5 km, 513 samples), when the repo carries that DEM; `terrainStats` fields. */
22
+ readonly target?: {
23
+ readonly slopeP50: number;
24
+ readonly slopeP90: number;
25
+ readonly hypsometricIntegral: number;
26
+ readonly curvatureKurtosis: number;
27
+ };
28
+ }
29
+ /**
30
+ * Shape-only presets. Each names its reference landscape so a calibration can be repeated; no
31
+ * material, colour or texture is chosen here. Targets were measured with `terrainStats` on the
32
+ * 1/3 arc-second USGS 3DEP crops in `examples/strata-terrain-preview/scripts/dem` (public domain).
33
+ */
34
+ declare const LANDFORMS: Readonly<Record<LandformKind, ILandformInfo>>;
35
+ /**
36
+ * One call, one landscape: a calibrated layer recipe for a kind of environment.
37
+ * @requires npm i @threenative/terrain
38
+ * @situation start an open world, a distant backdrop or a mountain level from a kind of place
39
+ * @constraint returns an ordinary `Terrain`: add roads, rivers, scatter or more layers, then `evaluate()` in a build script
40
+ * @constraint shape only; materials, colours and textures belong to the game
41
+ * @constraint calibrated at size 5000, resolution 513; other sizes keep the same slopes and scale the relief with `size`
42
+ * @example const terrain = landform("alpine", { size: 5000, resolution: 513, seed: 4 }); const state = terrain.evaluate();
43
+ * @override `relief` is the highest-minus-lowest height in metres before the finishing passes shave a few percent; `size`, `resolution` and `seed` as in `Terrain`
44
+ */
45
+ declare function landform(kind: LandformKind, options?: ILandformOptions): Terrain;
46
+ interface ILandformBackdrop {
47
+ readonly size: number;
48
+ readonly resolution: number;
49
+ /** Row-major metres, centre sample at `centerHeight`. */
50
+ readonly heights: Float32Array;
51
+ }
52
+ interface IBackdropOptions extends Partial<ITerrainConfig> {
53
+ /** Highest minus lowest height of the returned window, metres. Defaults to the kind's ratio times `size`. */
54
+ relief?: number;
55
+ /** Elevation of the centre sample, metres: the game's own ground height where the backdrop meets it. */
56
+ centerHeight?: number;
57
+ }
58
+ /**
59
+ * Distant mountains around a playable area: a landform window with a valley floor at its centre.
60
+ * @requires npm i @threenative/terrain
61
+ * @situation add a mountain backdrop around a playable area that the game's detail terrain covers
62
+ * @constraint resolution up to 513: the window is cut from a world twice as wide at the same spacing; build script only
63
+ * @constraint shape only; the game places, colours and fades it
64
+ * @example const { size, resolution, heights } = landformBackdrop("temperateMountains", { seed: 7, centerHeight: 13 });
65
+ * @override `relief` and `centerHeight` in metres; `size`, `resolution` and `seed` as in `landform`
66
+ */
67
+ declare function landformBackdrop(kind: LandformKind, options?: IBackdropOptions): ILandformBackdrop;
68
+
69
+ /**
70
+ * A biome as a data file: the rules one world grows by, and no appearance at all.
71
+ *
72
+ * A biome says which landform and seed it was generated from, which baked bundle its world is read
73
+ * from, which trees, grass and ground bands it holds, which water it floods, where it puts the
74
+ * player and the detail, the words a request may use for it, and the *name* of the look it is graded
75
+ * under. It carries no colour, no material and
76
+ * no shading: those stay game source, and the game resolves `look` to its own preset. A sixth biome
77
+ * is therefore a new file beside the five, not a new branch in the code that reads them.
78
+ *
79
+ * Every field is required, so a mistyped or missing one fails rather than falling back to a default
80
+ * (`validateBiome`).
81
+ */
82
+ /** Where the far field past the playable square is planted, and where it stops. */
83
+ interface IFarFieldRule {
84
+ /** Candidate grid, metres: at most one tree per cell. */
85
+ readonly cell: number;
86
+ /** Mean spacing just past the edge, and at the far reach. */
87
+ readonly spacing: readonly [number, number];
88
+ /** Metres past the square's edge where the near spacing starts, and where the far one is reached. */
89
+ readonly spacingAt: readonly [number, number];
90
+ /** Slope fade, degrees, and the gentler slopes a meadow clearing fades out over. */
91
+ readonly slope: readonly [number, number];
92
+ readonly meadowSlope: readonly [number, number];
93
+ /** Chevron distance from the origin beyond which nothing is planted. */
94
+ readonly reach: number;
95
+ /** How far the treeline wanders with noise, metres. */
96
+ readonly treelineJitter: number;
97
+ /** Stand-noise threshold band: the square plants above its own `standThreshold`. */
98
+ readonly stand: readonly [number, number];
99
+ /** The far field's own seed: it draws from one stream of its own, never the bake's. */
100
+ readonly seed: number;
101
+ /** Metres at which a far tree becomes the engine's whole-asset impostor. */
102
+ readonly impostor: number;
103
+ }
104
+ /** One species a biome plants, and the ground it accepts. `species` is the asset the game resolves. */
105
+ interface IFoliageType {
106
+ readonly species: string;
107
+ /** How many of them the rule accepts. */
108
+ readonly density: number;
109
+ /** Degrees, inclusive. */
110
+ readonly slope: readonly [number, number];
111
+ /** Metres above the world's floor, or null for no limit. */
112
+ readonly height: readonly [number, number] | null;
113
+ /** Metres between instances, at the tightest and the loosest. */
114
+ readonly spacing: readonly [number, number];
115
+ /** What a placement stops the player with. */
116
+ readonly collision: "none" | "trunk" | "hull";
117
+ /** The spacing follows the stand field, a closed core packing tighter than an open edge. */
118
+ readonly stands: boolean;
119
+ /** The least meadow weight, 0..1, a spot must carry for this species to stand on it. */
120
+ readonly grassThreshold: number;
121
+ /** The least stand-field weight, 0..1, a spot must carry for this species to stand on it. */
122
+ readonly standThreshold: number;
123
+ readonly far: IFarFieldRule | null;
124
+ }
125
+ /** One ground-cover species and the ground it accepts, on a grid of `spacing` metres. */
126
+ interface IGrassType {
127
+ readonly species: string;
128
+ /** How much of that ground it covers, 0..1. */
129
+ readonly density: number;
130
+ readonly slope: readonly [number, number];
131
+ readonly height: readonly [number, number] | null;
132
+ readonly spacing: number;
133
+ /** Degrees past `slope[1]` the meadow runs out over. */
134
+ readonly slopeFalloff: number;
135
+ /** Metres over which the cover fades out at the `height` ceiling. */
136
+ readonly heightFalloff: number;
137
+ /**
138
+ * The mat field's band, `[threshold, span]`: the weight the cover is gone at and the weight over
139
+ * which it reaches full, on the field a mat plain is measured by. Null on ground without mats.
140
+ */
141
+ readonly mats: readonly [number, number] | null;
142
+ /** Metres above the waterline a plant stands at. */
143
+ readonly waterMargin: number;
144
+ /** A beach that thins over the waterline, over `width` metres; null on a shore with none. */
145
+ readonly beach: readonly [number, number] | null;
146
+ /** Metres between plants in the dense detail disc around a place the player stands. */
147
+ readonly detailSpacing: number;
148
+ /** The drift this cover grows on: the field it reads and the band it fades over. */
149
+ readonly drift: ICoverDriftRow;
150
+ /** A blade's scale where the ground is dry, and the share of it the draw adds. */
151
+ readonly bladeScale: number;
152
+ readonly bladeJitter: number;
153
+ /** The chance a grass cell also grows a scrub, and the scrub's own scale band. */
154
+ readonly scrubChance: number;
155
+ readonly scrubScale: number;
156
+ readonly scrubJitter: number;
157
+ /** Whether a grass cell also grows the odd bush. */
158
+ readonly scrubBush: boolean;
159
+ /** Whether blades grow tall on the wet sand of a shore. */
160
+ readonly shoreGround: boolean;
161
+ /** Whether the rivers' beds and banks are dressed with cobbles. */
162
+ readonly cobbledBed: boolean;
163
+ }
164
+ /** The ground model an ordered biome's generators run: a wood, a crag, a dune field or a mat plain. */
165
+ type CoverGround = "wood" | "crag" | "mesa" | "mats";
166
+ /** The drift a biome's ground cover grows on: one value-noise field, sampled at these numbers. */
167
+ interface ICoverDriftRow {
168
+ /** The field the drift is measured on: a wood's stands, or a mat plain's mats. */
169
+ readonly field: "stand" | "mats";
170
+ /** Metres⁻¹ the field is sampled at, in x and z: a small frequency drifts in broad patches. */
171
+ readonly frequency: readonly [number, number];
172
+ /** The share of the cover that stands everywhere. */
173
+ readonly offset: number;
174
+ /** How much of the cover rides the field above that floor. */
175
+ readonly amplitude: number;
176
+ /** The field weight the drift is gone at, and the weight over which it reaches full. */
177
+ readonly band: readonly [number, number];
178
+ }
179
+ /**
180
+ * The understorey: the layer a closed wood carries under its canopy, and how thick it grows.
181
+ *
182
+ * A wood is the only ground that grows one today, but its numbers are the file's, not the code's: a
183
+ * woodland that wants more bracken, more thicket or more needle litter edits its own row.
184
+ */
185
+ interface IUnderstoreySpec {
186
+ /** How many candidates the understorey's loop draws; zero plants the layer not at all. */
187
+ readonly attempts: number;
188
+ /** A multiplier on the chance of each placement: 1 is the layer the wood was graded on. */
189
+ readonly litter: number;
190
+ readonly fern: number;
191
+ readonly bush: number;
192
+ /** The meadow flowers of the light gaps, which this stream plants as poppies. */
193
+ readonly flower: number;
194
+ /** Fallen wood under a closed stand: boughs and logs. 0 grows none. */
195
+ readonly deadfall: number;
196
+ /** The share of ground-cover candidates dropped under a crown, 0 to 1. */
197
+ readonly shade: number;
198
+ /** How far from a trunk its crown shades the ground, in metres. */
199
+ readonly shadeRadius: number;
200
+ }
201
+ /**
202
+ * What a biome's one ordered stream runs on: its cover model, its seed, and the places it keeps open.
203
+ *
204
+ * The numbers here are the game's, not the row's: a stream is one sequence of draws for the whole
205
+ * biome, so the seed and the clearing discs belong to the biome and not to a species.
206
+ */
207
+ interface ICoverSpec {
208
+ readonly ground: CoverGround;
209
+ /** The seed one ordered stream starts from. */
210
+ readonly seed: number;
211
+ /** The most candidates a stand's loop draws before it settles for what it has. */
212
+ readonly attempts: number;
213
+ /** Radius at the widest point of the game's biggest stone, which normalizes a cobble's scale. */
214
+ readonly stoneRadius: number;
215
+ /** Circles kept clear, `[x, z, radius]`: the places a player walks. */
216
+ readonly clearings: readonly (readonly [number, number, number])[];
217
+ /** The layer under a closed wood's canopy: how many draws, and how thick each one grows. */
218
+ readonly understorey: IUnderstoreySpec;
219
+ }
220
+ /** A ground layer's band, as fractions of the measured height range. */
221
+ interface ILayerInfo {
222
+ /** The ground layer this band feeds; the game resolves the name to its own material. */
223
+ readonly layer: string;
224
+ readonly from: number;
225
+ readonly to: number;
226
+ /** Snow: the steepness it starts to shed at, and the steepness it is gone by. */
227
+ readonly shedFrom?: number;
228
+ readonly shedTo?: number;
229
+ }
230
+ /** One water body: a river's ribbon, a lake's footprint, or the ocean the world stands in. */
231
+ interface IBiomeWaterBody {
232
+ readonly kind: "river" | "lake" | "ocean";
233
+ /** River: its ribbon width, in metres. */
234
+ readonly width?: number;
235
+ /** Lake: the radius of its footprint, in metres. */
236
+ readonly radius?: number;
237
+ /** River: how far it cuts below its banks. */
238
+ readonly depth?: number;
239
+ /** Ocean: the sea level the world floods to. */
240
+ readonly level?: number;
241
+ }
242
+ /**
243
+ * The baked bundle a biome's world is read from: the file under the game's `world/` folder.
244
+ *
245
+ * A bundle holds one world or several: two biomes generated from the same DEM share one file, so a
246
+ * world is named by the file and the key it sits under, not by a branch in the loader.
247
+ */
248
+ interface IBakeBundle {
249
+ /** File stem under `world/`, without its extension. */
250
+ readonly file: string;
251
+ /** The key this biome's world sits under when the file holds several, else null. */
252
+ readonly key: string | null;
253
+ }
254
+ /** Where the world puts the player, the launch camera and its dense detail. */
255
+ interface ISpawnSpec {
256
+ /** World x and z the player starts at. */
257
+ readonly at: readonly [number, number];
258
+ /** Metres the launch camera stands back and up from the spawn. */
259
+ readonly cameraOffset: readonly [number, number, number];
260
+ /** World x and z the dense ground cover is placed around: a meadow is a place, not a texture. */
261
+ readonly focus: readonly [number, number];
262
+ }
263
+ interface IBiomeSpec {
264
+ /** The name of the look the game grades this biome under; the package reads no colour. */
265
+ readonly look: string;
266
+ readonly bake: IBakeBundle;
267
+ readonly landform: LandformKind;
268
+ readonly sizeMeters: number;
269
+ readonly seed: number;
270
+ /**
271
+ * How the rows place: `ordered` runs every generator from one stream in one fixed order, `seeded`
272
+ * runs each rule from its own seed. `ordered` carries the game's own counts; `seeded` is the
273
+ * package's own sampler.
274
+ */
275
+ readonly stream: "ordered" | "seeded";
276
+ /** The cover a stream runs on: its model, its seed and the discs it keeps clear. */
277
+ readonly cover: ICoverSpec;
278
+ readonly foliage: readonly IFoliageType[];
279
+ readonly grass: readonly IGrassType[];
280
+ readonly layers: readonly ILayerInfo[];
281
+ readonly water: readonly IBiomeWaterBody[];
282
+ readonly spawn: ISpawnSpec;
283
+ /** The species that live here, by asset id: the pack resolves each to its own art. */
284
+ readonly species: readonly string[];
285
+ /** The words a request may use for this biome; its own name comes first. */
286
+ readonly aliases: readonly string[];
287
+ }
288
+ /**
289
+ * One biome file, checked field by field. The file is `biome.data.json`: `biome.json` is Biome's own
290
+ * configuration name, and a data file called that is parsed as a project config and fails the lint.
291
+ * @situation read a biome's rules from `starter/<biome>/biome.data.json` before a game or a cook uses them
292
+ * @constraint The file carries no appearance; colours, materials and shading stay game source
293
+ * @example const spec = validateBiome(JSON.parse(text), "forest");
294
+ * @requires npm i @threenative/terrain
295
+ */
296
+ declare function validateBiome(spec: unknown, name: string): IBiomeSpec;
297
+
298
+ /**
299
+ * A biome's band rows resolved once against the world they are about.
300
+ *
301
+ * The values in `biome.data.json` are fractions of the measured height range: the same numbers make
302
+ * a 40 m valley and a 900 m massif, and a world with a different crop of the same landform reads the
303
+ * same bands. Resolving them here keeps one owner of the numbers (the biome file) and one owner of
304
+ * the measurement (this function), so a game reads bands instead of repeating the arithmetic.
305
+ */
306
+ interface IMeasuredBands {
307
+ /** Lowest and highest sample, metres. Equal when the field is flat; the bands then collapse onto it. */
308
+ readonly elevationRange: readonly [number, number];
309
+ /** Each ground layer's band in metres, keyed by its row, in the order the file lists it. */
310
+ readonly bands: Readonly<Record<string, readonly [number, number]>>;
311
+ /** The `snow` row's band, when the biome has one. */
312
+ readonly snowBand: readonly [number, number] | null;
313
+ /**
314
+ * The `snow` row's slope interval, in degrees: snow starts to shed at the first and is gone by the
315
+ * second. `null` when the row has no shed rule.
316
+ */
317
+ readonly snowShed: readonly [number, number] | null;
318
+ }
319
+ /**
320
+ * Resolve a biome's fraction bands against this world's own height samples.
321
+ * @requires npm i -D @threenative/terrain
322
+ * @situation turn a biome file's height fractions into the metres a world actually measured
323
+ * @constraint samples are finite and at least one; a flat field resolves every band onto its one height
324
+ * @example const bands = measureBands(spec.layers, state.height);
325
+ */
326
+ declare function measureBands(layers: readonly ILayerInfo[], heights: ArrayLike<number>): IMeasuredBands;
327
+
328
+ /**
329
+ * A value-noise field, 0..1, as the numbers that shape it.
330
+ *
331
+ * Every per-biome field the placement rules read — a stand's density, a mat plain's cover, the
332
+ * drift a blade grows on — is this one formula: a floor plus two octaves of value noise. A field is
333
+ * therefore a value a biome carries, not a branch that picks a function: a sixth biome tunes the
334
+ * floor, the gains and the frequencies, and the code that samples it does not change.
335
+ */
336
+ interface ICoverField {
337
+ /** The weight the field stands at where the noise is zero. */
338
+ readonly base: number;
339
+ /** Octaves, low frequency first: how much of it lands in the sum, and where it is sampled. */
340
+ readonly octaves: readonly {
341
+ /** How much of this octave's noise lands in the sum. */
342
+ readonly gain: number;
343
+ /** Metres⁻¹ the field is sampled at: a small frequency gives broad patches. */
344
+ readonly frequency: number;
345
+ /** The field's own seed axis, so two octaves do not line up. */
346
+ readonly offset: number;
347
+ }[];
348
+ }
349
+ /**
350
+ * A field's weight at (x, z), clamped to 0..1.
351
+ *
352
+ * @requires npm i -D @threenative/terrain
353
+ * @situation sample the stand field a biome's trees and cover thin on
354
+ * @situation measure the drift a biome's blades grow by, or the mat field its cover follows
355
+ * @constraint the field is a value, so two worlds sample the same formula with their own numbers
356
+ * @example const stand = fieldWeight(STAND_FIELD, x, z);
357
+ */
358
+ declare function fieldWeight(field: ICoverField, x: number, z: number): number;
359
+ /**
360
+ * The stand field: where the wood closes and where it opens. Two octaves of value noise rather than
361
+ * a sum of sines, whose stripes read as "Tree Tree Tree" from the air.
362
+ */
363
+ declare const STAND_FIELD: ICoverField;
364
+ /** The mat field a mat plain is measured by: lichen mats, thicker and finer than a stand's patches. */
365
+ declare const MATS_FIELD: ICoverField;
366
+
367
+ /**
368
+ * The ordered scatter: one stream of draws, in one fixed order, for a biome whose rules are code.
369
+ *
370
+ * A biome that says `"stream": "ordered"` does not place one rule at a time from a seed per rule. It
371
+ * runs fifteen generators — a stand loop, an understorey, clumped ground cover, three grids, a tide
372
+ * line, a river walk, a detail disc and a cobbled bed — and draws every candidate from one
373
+ * `createRandom` stream in that order. The order IS the rule: change one draw and every later
374
+ * placement moves. So this file is the generator, copied line for line from the game that graded it
375
+ * (Strata's `examples/strata-terrain-preview/src/render/scatter.ts` at `5afb42b1c`), and its look and
376
+ * tuning numbers are read from the biome's rows instead of from the game's look.
377
+ *
378
+ * What stays in code is the algorithm's own structure: the cell of the spacing grid, the understorey
379
+ * loop's count, the candidate budget of each grid, the detail disc's two radii. A number here is the
380
+ * shape of the rule, not the look of a biome; a number in a row is the look.
381
+ *
382
+ * The four stages the PRD names are these generators' four jobs, in order: `surfaceSample` draws a
383
+ * candidate, `densityFilter` refuses it on slope, water, height, meadow weight and the stand field,
384
+ * `selfPrune` keeps its spacing against the accepted ones, and `meshSpawn` stamps the asset with its
385
+ * yaw, scale and normal.
386
+ */
387
+ /** The cover drift a biome's blades grow on, read from its grass row. */
388
+ interface ICoverFieldDrift {
389
+ /** The value-noise field the drift is measured on. */
390
+ readonly field: ICoverField;
391
+ /** Metres⁻¹ the field is sampled at, in x and z: a small frequency drifts in broad patches. */
392
+ readonly frequency: readonly [number, number];
393
+ /** The share of the cover that stands everywhere. */
394
+ readonly amplitude: number;
395
+ /** How much of the cover rides the field above that floor. */
396
+ readonly offset: number;
397
+ /** The field weight the drift is gone at, and the weight over which it reaches full. */
398
+ readonly band: readonly [number, number];
399
+ }
400
+ /** The two fields a drift can name: a wood's stands, or a mat plain's mats. */
401
+ type CoverFieldName = "stand" | "mats";
402
+ /** Every number one biome's ordered generators read: its tree row, its grass row and its cover. */
403
+ interface IOrderedScatterRules {
404
+ /** The species a stand is made of. */
405
+ readonly treeAsset: "spruce" | "sapling";
406
+ /** How many trees the rule accepts. */
407
+ readonly treeCount: number;
408
+ /** Metres a trunk keeps from its neighbour at a closed stand core (first) and in the open. */
409
+ readonly treeSpacing: readonly [number, number];
410
+ /** Whether the tree's spacing follows the stand mask, or is the same everywhere. */
411
+ readonly treeStands: boolean;
412
+ /** Degrees: a tree will not stand on ground steeper than this. */
413
+ readonly treeSlopeLimit: number;
414
+ /** Metres above the playable floor a tree stops, where the treeline is below the peaks. */
415
+ readonly treeHeightCeiling: number | null;
416
+ /** The ground cover's grid cell, in metres. */
417
+ readonly grassCell: number;
418
+ /** How much of the ground this world covers; 0 leaves the bare rock bare. */
419
+ readonly grassDensity: number;
420
+ /** Degrees: the meadow runs out here, over the next `grassSlopeFalloff` degrees. */
421
+ readonly grassSlopeLimit: number;
422
+ readonly grassSlopeFalloff: number;
423
+ /** Metres above the waterline a plant stands at. */
424
+ readonly grassWaterMargin: number;
425
+ /** A beach that thins over `waterline + waterMargin`, over `width` metres; absent on dry worlds. */
426
+ readonly grassBeach: readonly [number, number] | null;
427
+ /** Ground height, and the metres it takes to fade, that keep a meadow off the peaks. */
428
+ readonly grassHeight: readonly [number, number] | null;
429
+ /** The mat field's band the cover thins on, `[threshold, span]`; null on ground without mats. */
430
+ readonly grassMats: readonly [number, number] | null;
431
+ /** Metres between plants in the dense detail disc around a place the player stands. */
432
+ readonly grassDetailSpacing: number;
433
+ /** The least meadow weight, 0..1, a tree accepts. */
434
+ readonly treeGrassThreshold: number;
435
+ /** The least stand-field weight, 0..1, a tree accepts. */
436
+ readonly treeStandThreshold: number;
437
+ /** The ground the row was graded on: which of the four cover models the generators run. */
438
+ readonly ground: "wood" | "crag" | "mesa" | "mats";
439
+ /** The seed the one ordered stream starts from. */
440
+ readonly seed: number;
441
+ /** The most candidates a stand's loop draws before it settles for what it has. */
442
+ readonly attempts: number;
443
+ /** The cover drift a blade grows on: the field, its sampling and the band it fades over. */
444
+ readonly drift: ICoverFieldDrift;
445
+ /** A blade's scale where the ground is dry, and the share of it the draw adds. */
446
+ readonly bladeScale: number;
447
+ readonly bladeJitter: number;
448
+ /** The chance a grass cell also grows a scrub, and the scrub's own scale band. */
449
+ readonly scrubChance: number;
450
+ readonly scrubScale: number;
451
+ readonly scrubJitter: number;
452
+ /** Whether a grass cell also grows the odd bush. */
453
+ readonly scrubBush: boolean;
454
+ /** Whether blades grow tall on the wet sand of a shore. */
455
+ readonly shoreGround: boolean;
456
+ /** Whether the rivers' beds and banks are dressed with cobbles. */
457
+ readonly cobbledBed: boolean;
458
+ /** Radius at the widest point of the game's biggest stone, which normalizes a cobble's scale. */
459
+ readonly stoneRadius: number;
460
+ /** The layer under a closed wood's canopy: how many candidates, and a multiplier per placement. */
461
+ readonly understorey: IUnderstoreySpec;
462
+ }
463
+ /**
464
+ * A biome's rows as the ordered generators read them.
465
+ *
466
+ * The rule is short and shared; only these numbers differ between a wood, a barren shoulder, a dune
467
+ * field and a tundra, so the biome file names them rather than the code. A biome whose tree is not
468
+ * one this generator has art for fails here, naming the species, rather than planting nothing.
469
+ * @requires npm i -D @threenative/terrain
470
+ * @situation run a biome file's rows through the ordered scatter
471
+ * @constraint the file carries one foliage row, one grass row and a cover block
472
+ * @example const rules = orderedScatterRules(spec);
473
+ */
474
+ declare function orderedScatterRules(spec: IBiomeSpec): IOrderedScatterRules;
475
+ /** A field the placement rule reads: the world's baked transport and sampled geometry. */
476
+ interface IOrderedScatterField {
477
+ readonly erosion?: IErosionMaps;
478
+ readonly field: Heightfield;
479
+ readonly resolution: number;
480
+ readonly size: number;
481
+ readonly waterLevel: number | null;
482
+ /** The rows the generators run, resolved from the biome file. */
483
+ readonly rules: IOrderedScatterRules;
484
+ /** The biome file itself: the water bodies its rivers are read from. */
485
+ readonly spec: IBiomeSpec;
486
+ /** Still water: nothing grows below a lake's level inside its reach. */
487
+ readonly rivers?: readonly {
488
+ readonly points: readonly (readonly number[])[];
489
+ readonly width: number;
490
+ }[];
491
+ readonly lakes?: readonly {
492
+ readonly at: readonly number[];
493
+ readonly radius: number;
494
+ readonly level: number;
495
+ }[];
496
+ }
497
+ /** Every placement, for one world, from one ordered stream. */
498
+ interface IOrderedScatter {
499
+ readonly placements: IPlacement[];
500
+ /** How many of each prop was accepted, for the report and the playtest's own state. */
501
+ readonly counts: Record<string, number>;
502
+ }
503
+ /**
504
+ * Every placement, for one world, from one seed: the game's own rule set, in its own draw order.
505
+ * @requires npm i -D @threenative/terrain
506
+ * @situation bake a biome that says `"stream": "ordered"`
507
+ * @constraint `data.rules` is the biome's rows, and `data.field` the ground they were graded on
508
+ * @example const { placements, counts } = scatterProps(data, focus, clearings);
509
+ */
510
+ declare function scatterProps(data: IOrderedScatterField, focus: {
511
+ x: number;
512
+ z: number;
513
+ }, clearings?: readonly (readonly [number, number, number])[]): IOrderedScatter;
514
+
515
+ /**
516
+ * The four stages a scatter runs, named after the PCG elements that do each one
517
+ * (`UPCGSurfaceSamplerSettings`, `UPCGDensityFilterSettings`, `UPCGSelfPruningSettings`,
518
+ * `UPCGStaticMeshSpawnerSettings`; UE 5.8.3). In this package they are the fields of
519
+ * `IScatterParams`, evaluated by `Terrain.evaluate()` in this order:
520
+ *
521
+ * - `surfaceSample` — `count`, `seed`, `offsetY`: where a candidate lands.
522
+ * - `densityFilter` — `minSlope`/`maxSlope`, `minHeight`/`maxHeight`, `avoidWater`, `mask`: whether
523
+ * the ground there accepts one.
524
+ * - `selfPrune` — `minDistance`: whether it is too close to one already accepted.
525
+ * - `meshSpawn` — `asset`, `scale`, `alignToNormal`: what is stamped, and how.
526
+ *
527
+ * A bake needs no second scatter engine: this function receives the placements those stages
528
+ * produced and turns them into the world package a game streams.
529
+ */
530
+ type IBakeBiomeStage = "surfaceSample" | "densityFilter" | "selfPrune" | "meshSpawn";
531
+ declare const BAKE_BIOME_STAGES: readonly IBakeBiomeStage[];
532
+ interface IBakeBiomeOptions extends Omit<IBakeWorldPackageOptions, "assets"> {
533
+ /** The evaluated recipe: heights, splat and the placements the scatter stages accepted. */
534
+ readonly state: ITerrainState;
535
+ /** The biome the bake is for. Validated here, so an inline spec fails closed at the bake. */
536
+ readonly spec: IBiomeSpec;
537
+ /**
538
+ * Every asset an instance may reference, `glb`, bounds and its levels. An unknown one fails.
539
+ * Absent, the bake writes no package and hands the instances back: a game that keeps its own
540
+ * container for now reads `scatter` instead of a streamed package.
541
+ */
542
+ readonly assets?: Readonly<Record<string, IWorldPackageAsset>>;
543
+ /** How the rows place. Defaults to the biome file's own `stream`. */
544
+ readonly stream?: "ordered" | "seeded";
545
+ }
546
+ interface IBakedBiome {
547
+ /** The streamed package, or null when the call named no assets to write one. */
548
+ readonly package: IBakedWorldPackage | null;
549
+ /** The biome's band rows resolved against this state's own height range. */
550
+ readonly bands: IMeasuredBands;
551
+ /** Placements the bake made, one row per asset. */
552
+ readonly placements: readonly {
553
+ readonly asset: string;
554
+ readonly count: number;
555
+ }[];
556
+ /** The ordered stream's instances, in draw order; null when the rows ran on their own seeds. */
557
+ readonly scatter: IOrderedScatter | null;
558
+ }
559
+ /**
560
+ * Bake one biome: the recipe's evaluated state and the world package it streams.
561
+ *
562
+ * This is the composition `terrain_generate` and a game's build script both call, so the file layout
563
+ * a player streams is decided in one place. The biome is validated first — an inline spec from a
564
+ * request is checked here, not trusted — and the package's own placement runs are checked against
565
+ * the state they came from, so a bake can never ship a cell list that lost instances.
566
+ * @requires npm i -D @threenative/terrain
567
+ * An agent does not write this call to get a world: the `threenative-terrain` MCP tool
568
+ * `terrain_generate` takes the request in words ("a pine forest under snowy mountains with a river",
569
+ * "a volcanic island", or `ground: { location }` for a real place) and cooks the world.glb,
570
+ * recipe.json and world.json a game loads with `ctx.assets.model`.
571
+ * @situation bake one biome's world package from an evaluated recipe and a biome file
572
+ * @situation generate terrain with mountains, hills, a river, a lake or an island from a request in words
573
+ * @situation generate a landscape or open world map for a game
574
+ * @situation procedural terrain for a level: a volcanic island, a mountain valley or a coast
575
+ * @situation make a canyon, a volcano, a fjord, a desert, a tundra or a forest world
576
+ * @situation cook the real terrain of a place on Earth from its latitude and longitude
577
+ * @constraint every instance's asset must be in `assets`; every instance must land in exactly one cell run
578
+ * @example const baked = bakeBiome({ state: terrain.evaluate(), spec: validateBiome(json, "savanna"), assets });
579
+ */
580
+ declare function bakeBiome(options: IBakeBiomeOptions): IBakedBiome;
581
+
582
+ /**
583
+ * The far field: spruce on the collar past the playable square, by a rule of densities.
584
+ *
585
+ * The bake plants the square; a game draws its whole valley, so the ground past the edge would read
586
+ * as a bare lawn around one block of trees. This places the far stand on the drawn collar by the
587
+ * rules UE's procedural foliage applies per foliage type, each a density in 0..1 multiplied together
588
+ * (UE 5.8.3: altitude, slope, water, stands and spacing; `InstancedFoliage.cpp`, `FoliageEdMode.cpp`
589
+ * and `ProceduralFoliageTile.cpp`, cited on each test below). Every number is the biome row's `far`
590
+ * block, so a sixth biome tunes its own collar without a branch here.
591
+ *
592
+ * The mechanism is the package's; the game supplies its collar, its treeline band and its cameras.
593
+ */
594
+ /** What a far-field tree is: the tessellated collar and the layer the game draws it on. */
595
+ interface IFarFieldOptions {
596
+ readonly size: number;
597
+ readonly resolution: number;
598
+ /** The world's far collar, as drawn. */
599
+ readonly collar: HeightfieldCollar;
600
+ /** The measured treeline band, metres (`IWorldBiome.heightBands.treeline`). */
601
+ readonly treeline: readonly [number, number];
602
+ /** The biome's far-field row: spacing, fades, reach and seed. */
603
+ readonly rules: IFarFieldRule;
604
+ /** The asset a far tree is stamped as, and the layer a game's streaming buckets it under. */
605
+ readonly asset: string;
606
+ readonly layer: string;
607
+ readonly rivers?: readonly {
608
+ readonly points: readonly (readonly number[])[];
609
+ readonly width: number;
610
+ }[];
611
+ readonly lakes?: readonly {
612
+ readonly at: readonly number[];
613
+ readonly radius: number;
614
+ readonly level: number;
615
+ }[];
616
+ /** Circles kept open, [x, z, radius]: the vista's meadow. */
617
+ readonly clear?: readonly (readonly [number, number, number])[];
618
+ /** The sea's surface height, metres, when the world has one: no tree stands under it. */
619
+ readonly seaLevel?: number | null;
620
+ }
621
+ /**
622
+ * The collar's height at any (x, z), and a way to raise one of its per-vertex attributes at a
623
+ * placement: both read the collar's own quad grid, so a lane that reshapes the collar moves the
624
+ * trees with it.
625
+ *
626
+ * @requires npm i -D @threenative/terrain
627
+ * @situation plant a far field on a drawn collar and paint the canopy its crowns cover
628
+ * @constraint the collar decides where a tree stands; this sampler never resamples the square
629
+ * @example const sampler = collarSampler(collar); const height = sampler.at(x, z);
630
+ */
631
+ declare function collarSampler(collar: HeightfieldCollar): {
632
+ at: (x: number, z: number) => number | null;
633
+ paint: (attribute: BufferAttribute, x: number, z: number, value: number) => void;
634
+ };
635
+ /**
636
+ * Far-field placements on the collar; also paints the collar's `canopy` attribute under each crown.
637
+ *
638
+ * @requires npm i -D @threenative/terrain
639
+ * @situation plant the stand past a game's playable square, out to the drawn collar
640
+ * @constraint the row's `far` block decides every density; the caller supplies the collar and layer
641
+ * @example const trees = farForestPlacements({ size, resolution, collar, treeline, rules, asset, layer });
642
+ */
643
+ declare function farForestPlacements(options: IFarFieldOptions): IPlacement[];
4
644
 
5
645
  /** The eight splat channels, in channel order. Index 0 is the default base channel. */
6
646
  declare const MATERIAL_IDS: readonly MaterialId[];
@@ -23,6 +663,107 @@ declare const Mask: Readonly<{
23
663
  not: (mask: IMask) => IMask;
24
664
  }>;
25
665
 
666
+ /** A whole mountain cut from a survey, foot to foot: row-major, north row first, +X east. */
667
+ interface IMassifTile {
668
+ readonly id: string;
669
+ /** Side of the square in metres. */
670
+ readonly size: number;
671
+ /** Vertices per side. */
672
+ readonly resolution: number;
673
+ readonly heights: ArrayLike<number>;
674
+ }
675
+ interface IPlaceMassifOptions {
676
+ /** Picks the tile from a list, the pose, the mirror and the height. One seed is one mountain. */
677
+ readonly seed: number;
678
+ readonly tile: IMassifTile | readonly IMassifTile[];
679
+ /** World x and z of the summit. Default: a seeded point on `bearing` and `distance`. */
680
+ readonly at?: readonly [number, number];
681
+ /** Degrees from +X toward +Z the summit may stand on. Default: all round. */
682
+ readonly bearing?: readonly [number, number];
683
+ /** Metres from the world centre to the summit. Default: from half the tile to the world edge. */
684
+ readonly distance?: readonly [number, number];
685
+ /** Summit height above the ground it stands on, in metres. Default: the tile's own, x 0.85 to 1.15. */
686
+ readonly height?: readonly [number, number];
687
+ /** Summit elevation in world metres; wins over `height`, so a world's relief stays bounded. */
688
+ readonly top?: readonly [number, number];
689
+ /**
690
+ * Degrees from +X toward +Z the steepest wall faces, within 20 degrees. Default: toward the centre.
691
+ * A wall facing away from the sun is lit by the sky alone and shows little of its rock.
692
+ */
693
+ readonly face?: number;
694
+ /** Half side of the centre square the massif leaves untouched (the playable ground). Default 320. */
695
+ readonly keepOut?: number;
696
+ /** Layer id. Default `massif`. */
697
+ readonly id?: string;
698
+ }
699
+ /** Where the seed stood the mountain, and its heights at the tile's own spacing for relief maps. */
700
+ interface IMassifPlacement {
701
+ readonly tile: string;
702
+ readonly at: readonly [number, number];
703
+ /** Degrees the tile turned, counter-clockwise from +X toward +Z. */
704
+ readonly rotation: number;
705
+ readonly mirror: boolean;
706
+ /** Summit height above its ground, in metres. */
707
+ readonly height: number;
708
+ /** World-aligned final heights over the footprint at the tile's spacing, clipped to the world. */
709
+ readonly detail: {
710
+ readonly origin: readonly [number, number];
711
+ readonly spacing: number;
712
+ readonly columns: number;
713
+ readonly rows: number;
714
+ readonly heights: Float32Array;
715
+ };
716
+ }
717
+ /**
718
+ * A tile's mountain above its own foot: the heights minus a smooth surface through its border, so
719
+ * its edge is exactly zero and stands on any ground with no wall or ramp. Signed: a valley inside
720
+ * the mountain cuts below the foot, as it does in the survey.
721
+ * @requires npm i -D @threenative/terrain
722
+ * @situation measure how tall a surveyed mountain stands above the valley floor around it
723
+ * @constraint the tile must cover the whole mountain; a summit crop lifts as a cone
724
+ * @example const lifted = liftMassif({ id: "hill", size: 400, resolution: 3, heights: [0, 0, 0, 0, 90, 0, 0, 0, 0] });
725
+ */
726
+ declare function liftMassif(tile: IMassifTile): Float32Array;
727
+ /**
728
+ * Stands one surveyed mountain behind a world, chosen and posed by a seed: the tile from a list, a
729
+ * point on a bearing and distance, a turn that faces its steepest wall to the centre within 20
730
+ * degrees, a mirror and a summit height. It stands on the host's own foot (a smooth surface through
731
+ * the host under its border), replacing the host's hills inside its square, and leaves the centre
732
+ * square untouched. Appends one `heightmap` layer; the placement carries the tile-spacing heights a
733
+ * relief map reads.
734
+ * @requires npm i -D @threenative/terrain
735
+ * @situation put a real-shaped mountain behind a generated world, a different one per seed
736
+ * @constraint the tile must be a whole mountain whose border is valley floor; erosion after it carves the survey
737
+ * @example const { terrain, placement } = placeMassif(new Terrain({ size: 5000, resolution: 129 }), { seed: 3, tile: { id: "cone", size: 2000, resolution: 3, heights: [0, 0, 0, 0, 900, 0, 0, 0, 0] } });
738
+ * @override `at`, `bearing`, `distance`, `height`, `top`, `face` and `keepOut` on the same call
739
+ */
740
+ declare function placeMassif(terrain: Terrain, options: IPlaceMassifOptions): {
741
+ terrain: Terrain;
742
+ placement: IMassifPlacement;
743
+ };
744
+
745
+ interface ITerrainStats {
746
+ /** Highest minus lowest height, metres. */
747
+ readonly relief: number;
748
+ /** (mean - min) / (max - min): about 0.5 for an evenly dissected massif, low for peaks over wide flats. */
749
+ readonly hypsometricIntegral: number;
750
+ /** Slope percentiles in degrees from central differences. */
751
+ readonly slopeP50: number;
752
+ readonly slopeP90: number;
753
+ /** Channel length per area, km/km^2: cells draining at least 0.1 km^2, after depression filling. */
754
+ readonly drainageDensity: number;
755
+ /** Excess kurtosis of the Laplacian: smooth blobs are near 0, sharp ridges and gullies are heavy-tailed. */
756
+ readonly curvatureKurtosis: number;
757
+ }
758
+ /**
759
+ * Landform statistics used to calibrate generators against real DEMs.
760
+ * @requires npm i @threenative/terrain
761
+ * @situation compare generated terrain with a USGS or SRTM crop on the same footprint
762
+ * @constraint square grids only; compare crops of equal spacing, because slope and curvature depend on it
763
+ * @example const stats = terrainStats(state.height, state.resolution, state.size);
764
+ */
765
+ declare function terrainStats(height: ArrayLike<number>, n: number, size: number): ITerrainStats;
766
+
26
767
  /** Bilinear world-space height query. It is not the rendered or collidable triangle surface. */
27
768
  /**
28
769
  * Bilinear query of canonical height samples; triangle sampling is a separate contract.
@@ -211,93 +952,145 @@ declare function encodeZIP(files: readonly IExportFile[]): Uint8Array<ArrayBuffe
211
952
  * @constraint authoring data only; the game owns appearance, physics and rendering
212
953
  * @example const terrain = new Terrain({ resolution: 17 }); const file = await makeExport(terrain.evaluate(), terrain.toJSON(), "project");
213
954
  */
955
+ declare function makeExport(state: ITerrainState | null, recipe: ITerrainDocument, kind: "project"): Promise<IExportArchive>;
214
956
  declare function makeExport(state: ITerrainState, recipe: ITerrainDocument, kind: ExportKind): Promise<IExportArchive>;
215
957
 
216
- /** One streamed asset: its LOD0 model, its authored bounds and the levels it swaps to. */
217
- interface IWorldPackageAsset {
218
- readonly glb: string;
219
- readonly bounds: {
220
- readonly min: readonly [number, number, number];
221
- readonly max: readonly [number, number, number];
222
- };
223
- readonly lods?: readonly {
224
- readonly glb: string;
225
- readonly distance: number;
226
- }[];
227
- readonly maxDistance?: number;
958
+ /**
959
+ * The streamed prop worlds one bake writes, and what each one holds.
960
+ *
961
+ * A prop package is the same container as a world package (`world-package.ts`): eight float32 per
962
+ * placement, cells of a fixed size, and one run per asset inside a cell. What it adds is the split
963
+ * into streamed worlds. The game draws its placements in more than one `WorldCells` because reach
964
+ * and shadow policy differ between a horizon-canopy tree and a shadowless blade of grass, and the
965
+ * far field and the vista meadow answer a query flag. This module turns labelled placements into
966
+ * those worlds, so the bake writes them and the game loads them, and neither side owns the grouping.
967
+ */
968
+ /** Which streamed world a record draws in, for a loader that answers a query flag before it loads. */
969
+ type IPropBucketKind = "local" | "far" | "meadow";
970
+ /** One placement, the streamed world it belongs to, and how far it may draw. */
971
+ interface IPropBucketEntry {
972
+ readonly placement: IPlacement;
973
+ /** The streamed world's name, e.g. `local:true`. Two entries of one name share every container field. */
974
+ readonly bucket: string;
975
+ /** Metres at which the record may be culled; `Number.POSITIVE_INFINITY` keeps every cell resident. */
976
+ readonly reach: number;
977
+ /**
978
+ * The model the record draws, when it is not the placement's asset alone: the game's
979
+ * `asset:variant` key, with a shape suffix when one scale cannot carry the placement. The run a
980
+ * record sits in names it, and the loader's asset table is keyed by it.
981
+ */
982
+ readonly key?: string;
983
+ /** Defaults to `local`. A bucket that names two kinds fails the compile. */
984
+ readonly kind?: IPropBucketKind;
228
985
  }
229
- /** One cell's contiguous run of placement records, eight float32 values each. */
230
- interface IWorldPackageRun {
231
- readonly asset: string;
232
- /** Record offset into the placement buffer, not a byte offset. */
233
- readonly offset: number;
234
- readonly count: number;
235
- }
236
- /** The `world.json` contract, declared here so this addon needs no `@threenative/core` import. */
237
- interface IWorldPackageManifest {
238
- readonly version: 1;
239
- readonly extent: {
240
- readonly minX: number;
241
- readonly minZ: number;
242
- readonly sizeX: number;
243
- readonly sizeZ: number;
244
- };
245
- readonly cellSize: number;
246
- readonly terrain: {
247
- readonly heightmap: string;
248
- readonly columns: number;
249
- readonly rows: number;
250
- readonly spacing: number;
251
- readonly heightMin: number;
252
- readonly heightMax: number;
253
- readonly layers?: Readonly<Record<string, string>>;
254
- };
255
- readonly assets: Readonly<Record<string, IWorldPackageAsset>>;
256
- readonly placements: string;
986
+ /** One streamed prop world: its container, its per-record reach, and its per-record placement ID. */
987
+ interface IPropBucketPackage {
988
+ readonly bucket: string;
989
+ readonly kind: IPropBucketKind;
990
+ readonly extent: IWorldPackageManifest["extent"];
257
991
  readonly cells: readonly {
258
992
  readonly x: number;
259
993
  readonly z: number;
260
994
  readonly runs: readonly IWorldPackageRun[];
261
995
  }[];
996
+ /** Eight float32 per record: position, quaternion, uniform scale. */
997
+ readonly placements: Uint8Array;
998
+ /** One float32 per record, in record order. */
999
+ readonly reach: Float32Array;
1000
+ /** One placement ID per record, in record order. The game's `variantFor` hashes it. */
1001
+ readonly ids: readonly string[];
262
1002
  }
263
- /** The splat layout to copy into a terrain table: eight material masks in two RGBA8 planes. */
264
- interface IWorldPackageSplat {
265
- readonly size: number;
266
- readonly planes: number;
267
- readonly masks: Readonly<Record<string, readonly [number, "r" | "g" | "b" | "a"]>>;
1003
+ interface IPropPackage {
1004
+ readonly cellSize: number;
1005
+ readonly buckets: readonly IPropBucketPackage[];
268
1006
  }
269
- interface IBakeWorldPackageOptions {
270
- /** Every asset any instance may reference. An instance outside this set fails the bake. */
271
- readonly assets: Readonly<Record<string, IWorldPackageAsset>>;
272
- /** Metres per streamed cell. Defaults to 64. */
1007
+ interface ICompilePropBucketsOptions {
1008
+ /** Metres per streamed cell. Defaults to 128. */
273
1009
  readonly cellSize?: number;
274
- /** Extra `terrain.layers` entries, e.g. `{ table: "terrain-table.json" }`. */
275
- readonly layers?: Readonly<Record<string, string>>;
276
- readonly names?: {
277
- readonly heightmap?: string;
278
- readonly placements?: string;
279
- readonly splat?: string;
280
- };
1010
+ /**
1011
+ * The extent every bucket includes before its own placements widen it, e.g. the world square.
1012
+ * Without it a bucket spans exactly its own placements.
1013
+ */
1014
+ readonly bounds?: IWorldPackageManifest["extent"];
1015
+ }
1016
+ /** The cell size the game streams props in: 128 m, coarse enough that admission jobs stay bounded. */
1017
+ declare const PROP_CELL_SIZE = 128;
1018
+ /**
1019
+ * Group placements into their streamed worlds and write each world's cells and records.
1020
+ *
1021
+ * The order is the streamed one: cells sorted by `x` then `z`, assets sorted by name inside a cell,
1022
+ * and records in the order the entries arrived inside a run. Same-cell, same-asset placements keep
1023
+ * their input order, so a re-run of a seeded bake reproduces the buffer byte for byte.
1024
+ *
1025
+ * @requires npm i -D @threenative/terrain
1026
+ * @situation bake the prop worlds a game streams, once, instead of compiling them at load
1027
+ * @constraint headless; the caller decides every placement, its streamed world, its reach and its pose
1028
+ * @example const pkg = compilePropBuckets(entries, { bounds });
1029
+ * @override cellSize and the base extent; the bucket, reach and kind of every entry
1030
+ */
1031
+ declare function compilePropBuckets(entries: readonly IPropBucketEntry[], options?: ICompilePropBucketsOptions): IPropPackage;
1032
+ /**
1033
+ * The asset a package run names.
1034
+ *
1035
+ * A prop run names the model it draws, `asset:variant[@shape]`; a container written by
1036
+ * `bakeWorldPackage` names the asset alone. Both reduce to the asset here, which is what a count, a
1037
+ * material or a placement's own `asset` field holds.
1038
+ *
1039
+ * @requires npm i -D @threenative/terrain
1040
+ * @situation count one species across a world's prop buckets, or name the asset a run draws
1041
+ * @example const asset = propAssetOf("spruce:2"); // "spruce"
1042
+ */
1043
+ declare function propAssetOf(modelKey: string): string;
1044
+ /** One record of a compiled prop bucket, in record order. */
1045
+ interface IPropBucketRecord {
1046
+ readonly id: string;
1047
+ /** The model the record draws, as its run names it (`spruce:2`, or with a shape suffix). */
1048
+ readonly key: string;
1049
+ /** The asset alone, `propAssetOf(key)`. */
1050
+ readonly asset: string;
1051
+ readonly position: readonly [number, number, number];
1052
+ readonly quaternion: readonly [number, number, number, number];
1053
+ readonly scale: number;
1054
+ readonly reach: number;
281
1055
  }
282
- interface IBakedWorldPackage {
283
- readonly manifest: IWorldPackageManifest;
284
- readonly splat: IWorldPackageSplat;
285
- /** The three binary files, keyed by the manifest names that point at them. */
1056
+ /**
1057
+ * The records of one compiled prop bucket, read back in record order: the inverse of
1058
+ * `compilePropBuckets`, so a loader that fetched a bake's files gets each record's ID, model,
1059
+ * pose and reach without re-deriving the container layout.
1060
+ *
1061
+ * @requires npm i -D @threenative/terrain
1062
+ * @situation read a baked prop bucket back into placements to ground them on this machine's terrain
1063
+ * @constraint throws `TN_PROP_BUCKET_INVALID` when the record buffer, the IDs and the runs disagree
1064
+ * @example for (const record of decodePropBucket(bucket)) pose(record.key, record.position, record.quaternion);
1065
+ */
1066
+ declare function decodePropBucket(bucket: IPropBucketPackage): IPropBucketRecord[];
1067
+ /** The files one bake writes for a world's prop package: its bucket list and each bucket's three files. */
1068
+ interface IPropPackageFiles {
1069
+ readonly manifest: Uint8Array;
286
1070
  readonly files: Readonly<Record<string, Uint8Array>>;
287
1071
  }
288
1072
  /**
289
- * Bake an evaluated terrain into the engine's world package: a `world.json` manifest, a uint16
290
- * heightmap, a splat mask array, a placement buffer of eight float32 per instance, and the square
291
- * cells that stream them. The encodings and row orders are the ones the Blender recipe
292
- * `export_world.py` writes, so one runtime streams both without a second reader.
1073
+ * A path under `world/` that no bucket name can break: `local:true` becomes `local-true`.
1074
+ *
1075
+ * The bucket's own name is kept in the manifest, so this rename is only a file-system concern.
1076
+ *
1077
+ * @requires npm i -D @threenative/terrain
1078
+ * @situation name one of a bucket's three files without a bucket key that breaks a path
1079
+ * @example const file = propPackageFile("forest", "local:true", "props.bin"); // "forest.local-true.props.bin"
1080
+ */
1081
+ declare function propPackageFile(world: string, bucket: string, suffix: string): string;
1082
+ /**
1083
+ * Write a compiled package as the manifest the game fetches and one set of files per bucket.
1084
+ *
1085
+ * The manifest names the files rather than embedding them, so a loader fetches only the buckets its
1086
+ * query flags keep (`?farForest=on` keeps the far field, `?meadow=off` drops the vista cover).
293
1087
  *
294
1088
  * @requires npm i -D @threenative/terrain
295
- * @situation hand an evaluated Strata terrain to a game without a Blender round trip
296
- * @constraint headless authoring; no three, no DOM, and nothing here decides how the world looks
297
- * @example const { manifest, files } = bakeWorldPackage(state, { assets });
298
- * @override every asset path, bound, LOD distance and cell size comes from the caller's options
1089
+ * @situation write a compiled package to disk: one manifest and three files per streamed world
1090
+ * @constraint the manifest names the files; nothing here touches a file system
1091
+ * @example const { manifest, files } = propPackageFiles(pkg, "forest");
299
1092
  */
300
- declare function bakeWorldPackage(state: ITerrainState, options: IBakeWorldPackageOptions): IBakedWorldPackage;
1093
+ declare function propPackageFiles(pkg: IPropPackage, world: string): IPropPackageFiles;
301
1094
 
302
1095
  /**
303
1096
  * A spatial index for water proximity: river segments, river stations and lake shores.
@@ -332,4 +1125,4 @@ interface ISegmentIndex<T> {
332
1125
  */
333
1126
  declare function createSegmentIndex<T>(segments: readonly IWaterSegment<T>[], cellSize: number): ISegmentIndex<T>;
334
1127
 
335
- export { ExportKind, IBakeMeshOptions, IBakeTerrainOptions, IBakedMesh, IBakedTerrain, IDecodeHeightPngOptions, IDecodeRaw16Options, IExportArchive, IExportFile, IHeightRange, IMask, IPlacementOverride, IRaw16Options, ISampledGrid, type ISegmentIndex, ITerrainDocument, ITerrainState, type IWaterSegment, MATERIAL_IDS, Mask, MaterialId, OperationType, PARAMS, RESOLUTIONS, applyPlacementOverrides, bakeMesh, bakeTerrain, bakeWorldPackage, createSegmentIndex, decodeHeightPNG, decodeRAW16, encodeGLB, encodeHeightPNG, encodeRAW16, encodeSplatPNGs, encodeZIP, gradientAt, makeExport, sampleHeight, slopeAtIndex, slopeQuantile, splinePoints, validateDocument, validatePlacementOverrides };
1128
+ export { BAKE_BIOME_STAGES, type CoverFieldName, type CoverGround, ExportKind, type IBackdropOptions, type IBakeBiomeOptions, type IBakeBiomeStage, IBakeMeshOptions, IBakeTerrainOptions, type IBakedBiome, IBakedMesh, IBakedTerrain, type IBiomeSpec, type IBiomeWaterBody, type ICompilePropBucketsOptions, type ICoverDriftRow, type ICoverField, type ICoverFieldDrift, type ICoverSpec, IDecodeHeightPngOptions, IDecodeRaw16Options, IErosionMaps, IExportArchive, IExportFile, type IFarFieldOptions, type IFarFieldRule, type IFoliageType, type IGrassType, IHeightRange, type ILandformBackdrop, type ILandformInfo, type ILandformOptions, type ILayerInfo, IMask, type IMassifPlacement, type IMassifTile, type IMeasuredBands, type IOrderedScatter, type IOrderedScatterField, type IOrderedScatterRules, type IPlaceMassifOptions, IPlacement, IPlacementOverride, type IPropBucketEntry, type IPropBucketKind, type IPropBucketPackage, type IPropBucketRecord, type IPropPackage, type IPropPackageFiles, IRaw16Options, ISampledGrid, type ISegmentIndex, type ISpawnSpec, ITerrainConfig, ITerrainDocument, ITerrainState, type ITerrainStats, type IUnderstoreySpec, type IWaterSegment, LANDFORMS, type LandformKind, MATERIAL_IDS, MATS_FIELD, Mask, MaterialId, OperationType, PARAMS, PROP_CELL_SIZE, RESOLUTIONS, STAND_FIELD, Terrain, applyPlacementOverrides, bakeBiome, bakeMesh, bakeTerrain, collarSampler, compilePropBuckets, createSegmentIndex, decodeHeightPNG, decodePropBucket, decodeRAW16, encodeGLB, encodeHeightPNG, encodeRAW16, encodeSplatPNGs, encodeZIP, farForestPlacements, fieldWeight, gradientAt, landform, landformBackdrop, liftMassif, makeExport, measureBands, orderedScatterRules, placeMassif, propAssetOf, propPackageFile, propPackageFiles, sampleHeight, scatterProps, slopeAtIndex, slopeQuantile, splinePoints, terrainStats, validateBiome, validateDocument, validatePlacementOverrides };