@threenative/terrain 0.1.6 → 0.1.8

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 (127) hide show
  1. package/AGENT_GUIDE.md +19 -4
  2. package/dist/editor/index.d.ts +160 -5
  3. package/dist/editor/index.js +3783 -1406
  4. package/dist/editor/server.d.ts +2 -2
  5. package/dist/editor/server.js +555 -121
  6. package/dist/editor/worker.d.ts +33 -1
  7. package/dist/editor/worker.js +444 -110
  8. package/dist/export.d.ts +11 -9
  9. package/dist/export.js +22 -34
  10. package/dist/index.d.ts +727 -73
  11. package/dist/index.js +2434 -553
  12. package/dist/kit.d.ts +56 -0
  13. package/dist/kit.js +2524 -0
  14. package/dist/mcp/cook-child.d.ts +2 -0
  15. package/dist/mcp/cook-child.js +3705 -0
  16. package/dist/mcp/server.d.ts +7 -0
  17. package/dist/mcp/server.js +3279 -0
  18. package/dist/{server-ByM2hmYJ.d.ts → server-C8Ydr_IM.d.ts} +3 -2
  19. package/dist/starter.d.ts +143 -0
  20. package/dist/starter.js +1030 -0
  21. package/dist/{terrain-gPnkCU6S.d.ts → terrain-B3DkduPw.d.ts} +3 -2
  22. package/dist/three.d.ts +1 -1
  23. package/dist/{types-Ant8-Axc.d.ts → types-CPYAc9vo.d.ts} +13 -4
  24. package/dist/world-package-B7KGYIou.d.ts +94 -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 +114 -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 +77 -1
  33. package/starter/coastal/bake.mjs +4 -116
  34. package/starter/coastal/biome.data.json +135 -0
  35. package/starter/coastal/heightmap.r16 +0 -0
  36. package/starter/coastal/recipe.json +3 -66051
  37. package/starter/coastal/sea.ts +49 -16
  38. package/starter/coastal/world.ts +53 -318
  39. package/starter/desert/README.md +77 -1
  40. package/starter/desert/bake.mjs +4 -116
  41. package/starter/desert/biome.data.json +114 -0
  42. package/starter/desert/heightmap.r16 +0 -0
  43. package/starter/desert/recipe.json +3 -66051
  44. package/starter/desert/world.ts +45 -293
  45. package/starter/forest/README.md +84 -4
  46. package/starter/forest/assets.json +32 -0
  47. package/starter/forest/bake.mjs +6 -116
  48. package/starter/forest/biome.data.json +150 -0
  49. package/starter/forest/heightmap.r16 +0 -0
  50. package/starter/forest/recipe.json +192 -4428
  51. package/starter/forest/sky.ts +11 -0
  52. package/starter/forest/water.ts +30 -20
  53. package/starter/forest/world.ts +86 -322
  54. package/starter/tundra/README.md +77 -1
  55. package/starter/tundra/bake.mjs +4 -116
  56. package/starter/tundra/biome.data.json +131 -0
  57. package/starter/tundra/heightmap.r16 +0 -0
  58. package/starter/tundra/recipe.json +18 -66066
  59. package/starter/tundra/world.ts +65 -319
  60. package/starter-assets.json +6 -0
  61. package/{starter-assets/credits.json → starter-credits.json} +12 -105
  62. package/starter-assets/bark_brown_02/bark_brown_02_diff_1k.jpg +0 -0
  63. package/starter-assets/bark_brown_02/bark_brown_02_nor_gl_1k.jpg +0 -0
  64. package/starter-assets/bark_brown_02/bark_brown_02_rough_1k.jpg +0 -0
  65. package/starter-assets/boulder_01/boulder-mid.glb +0 -0
  66. package/starter-assets/boulder_01/boulder-near.glb +0 -0
  67. package/starter-assets/cliff_side/cliff_side_ao_1k.jpg +0 -0
  68. package/starter-assets/cliff_side/cliff_side_diff_1k.jpg +0 -0
  69. package/starter-assets/cliff_side/cliff_side_nor_gl_1k.jpg +0 -0
  70. package/starter-assets/cliff_side/cliff_side_rough_1k.jpg +0 -0
  71. package/starter-assets/fern_02/fern_02_alpha_512.png +0 -0
  72. package/starter-assets/fern_02/fern_02_diff_512.jpg +0 -0
  73. package/starter-assets/fern_02/fern_02_nor_gl_512.jpg +0 -0
  74. package/starter-assets/fir_tree_01/fir-b-lod1.glb +0 -0
  75. package/starter-assets/fir_tree_01/fir-b-lod2.glb +0 -0
  76. package/starter-assets/fir_tree_01/fir-c-lod1.glb +0 -0
  77. package/starter-assets/fir_tree_01/fir-c-lod2.glb +0 -0
  78. package/starter-assets/fir_tree_01/fir_tree_01_twig_arm_1k.jpg +0 -0
  79. package/starter-assets/fir_tree_01/fir_tree_01_twig_diff_1k.jpg +0 -0
  80. package/starter-assets/fir_tree_01/fir_tree_01_twig_nor_gl_1k.jpg +0 -0
  81. package/starter-assets/forest_ground_04/forest_ground_04_ao_1k.jpg +0 -0
  82. package/starter-assets/forest_ground_04/forest_ground_04_diff_1k.jpg +0 -0
  83. package/starter-assets/forest_ground_04/forest_ground_04_nor_gl_1k.jpg +0 -0
  84. package/starter-assets/forest_ground_04/forest_ground_04_rough_1k.jpg +0 -0
  85. package/starter-assets/forest_leaves_02/forest_leaves_02_arm_512.jpg +0 -0
  86. package/starter-assets/forest_leaves_02/forest_leaves_02_diff_512.jpg +0 -0
  87. package/starter-assets/forest_leaves_02/forest_leaves_02_nor_gl_512.jpg +0 -0
  88. package/starter-assets/grass_medium_02/grass_medium_02_alpha_512.png +0 -0
  89. package/starter-assets/grass_medium_02/grass_medium_02_diff_512.jpg +0 -0
  90. package/starter-assets/grass_medium_02/grass_medium_02_nor_gl_512.jpg +0 -0
  91. package/starter-assets/hdri/kloofendal_48d_partly_cloudy_1k.hdr +0 -0
  92. package/starter-assets/leafy_grass/leafy_grass_ao_1k.jpg +0 -0
  93. package/starter-assets/leafy_grass/leafy_grass_diff_1k.jpg +0 -0
  94. package/starter-assets/leafy_grass/leafy_grass_nor_gl_1k.jpg +0 -0
  95. package/starter-assets/leafy_grass/leafy_grass_rough_1k.jpg +0 -0
  96. package/starter-assets/lichen_rock/lichen_rock_arm_512.jpg +0 -0
  97. package/starter-assets/lichen_rock/lichen_rock_diff_512.jpg +0 -0
  98. package/starter-assets/lichen_rock/lichen_rock_nor_gl_512.jpg +0 -0
  99. package/starter-assets/mossy_rock/mossy_rock_ao_1k.jpg +0 -0
  100. package/starter-assets/mossy_rock/mossy_rock_diff_1k.jpg +0 -0
  101. package/starter-assets/mossy_rock/mossy_rock_nor_gl_1k.jpg +0 -0
  102. package/starter-assets/mossy_rock/mossy_rock_rough_1k.jpg +0 -0
  103. package/starter-assets/needle-atlas.png +0 -0
  104. package/starter-assets/needle-surface.png +0 -0
  105. package/starter-assets/river_small_rocks/river_small_rocks_arm_512.jpg +0 -0
  106. package/starter-assets/river_small_rocks/river_small_rocks_diff_512.jpg +0 -0
  107. package/starter-assets/river_small_rocks/river_small_rocks_nor_gl_512.jpg +0 -0
  108. package/starter-assets/rock_boulder_dry/rock_boulder_dry_arm_512.jpg +0 -0
  109. package/starter-assets/rock_boulder_dry/rock_boulder_dry_diff_512.jpg +0 -0
  110. package/starter-assets/rock_boulder_dry/rock_boulder_dry_nor_gl_512.jpg +0 -0
  111. package/starter-assets/rocks/boulder-mid.glb +0 -0
  112. package/starter-assets/rocks/boulder-near.glb +0 -0
  113. package/starter-assets/rocks/boulder-prep.json +0 -37
  114. package/starter-assets/rocks/rock01-mid.glb +0 -0
  115. package/starter-assets/rocks/rock01-near.glb +0 -0
  116. package/starter-assets/rocks/rock01-prep.json +0 -37
  117. package/starter-assets/rocks/rock04-mid.glb +0 -0
  118. package/starter-assets/rocks/rock04-near.glb +0 -0
  119. package/starter-assets/rocks/rock04-prep.json +0 -37
  120. package/starter-assets/sand_01/sand_01_ao_1k.jpg +0 -0
  121. package/starter-assets/sand_01/sand_01_diff_1k.jpg +0 -0
  122. package/starter-assets/sand_01/sand_01_nor_gl_1k.jpg +0 -0
  123. package/starter-assets/sand_01/sand_01_rough_1k.jpg +0 -0
  124. package/starter-assets/snow_02/snow_02_ao_1k.jpg +0 -0
  125. package/starter-assets/snow_02/snow_02_diff_1k.jpg +0 -0
  126. package/starter-assets/snow_02/snow_02_nor_gl_1k.jpg +0 -0
  127. package/starter-assets/snow_02/snow_02_rough_1k.jpg +0 -0
package/dist/index.d.ts CHANGED
@@ -1,6 +1,609 @@
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-B3DkduPw.js';
2
+ export { L as LayerPatch, O as OperationOptions, P as PatchCommand, a as TerrainEvaluator } from './terrain-B3DkduPw.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-CPYAc9vo.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-CPYAc9vo.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-B7KGYIou.js';
7
+ export { b as bakeWorldPackage } from './world-package-B7KGYIou.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
+ * What a biome's one ordered stream runs on: its cover model, its seed, and the places it keeps open.
181
+ *
182
+ * The numbers here are the game's, not the row's: a stream is one sequence of draws for the whole
183
+ * biome, so the seed and the clearing discs belong to the biome and not to a species.
184
+ */
185
+ interface ICoverSpec {
186
+ readonly ground: CoverGround;
187
+ /** The seed one ordered stream starts from. */
188
+ readonly seed: number;
189
+ /** The most candidates a stand's loop draws before it settles for what it has. */
190
+ readonly attempts: number;
191
+ /** Radius at the widest point of the game's biggest stone, which normalizes a cobble's scale. */
192
+ readonly stoneRadius: number;
193
+ /** Circles kept clear, `[x, z, radius]`: the places a player walks. */
194
+ readonly clearings: readonly (readonly [number, number, number])[];
195
+ }
196
+ /** A ground layer's band, as fractions of the measured height range. */
197
+ interface ILayerInfo {
198
+ /** The ground layer this band feeds; the game resolves the name to its own material. */
199
+ readonly layer: string;
200
+ readonly from: number;
201
+ readonly to: number;
202
+ /** Snow: the steepness it starts to shed at, and the steepness it is gone by. */
203
+ readonly shedFrom?: number;
204
+ readonly shedTo?: number;
205
+ }
206
+ /** One water body: a river's ribbon, a lake's footprint, or the ocean the world stands in. */
207
+ interface IBiomeWaterBody {
208
+ readonly kind: "river" | "lake" | "ocean";
209
+ /** River: its ribbon width, in metres. */
210
+ readonly width?: number;
211
+ /** Lake: the radius of its footprint, in metres. */
212
+ readonly radius?: number;
213
+ /** River: how far it cuts below its banks. */
214
+ readonly depth?: number;
215
+ /** Ocean: the sea level the world floods to. */
216
+ readonly level?: number;
217
+ }
218
+ /**
219
+ * The baked bundle a biome's world is read from: the file under the game's `world/` folder.
220
+ *
221
+ * A bundle holds one world or several: two biomes generated from the same DEM share one file, so a
222
+ * world is named by the file and the key it sits under, not by a branch in the loader.
223
+ */
224
+ interface IBakeBundle {
225
+ /** File stem under `world/`, without its extension. */
226
+ readonly file: string;
227
+ /** The key this biome's world sits under when the file holds several, else null. */
228
+ readonly key: string | null;
229
+ }
230
+ /** Where the world puts the player, the launch camera and its dense detail. */
231
+ interface ISpawnSpec {
232
+ /** World x and z the player starts at. */
233
+ readonly at: readonly [number, number];
234
+ /** Metres the launch camera stands back and up from the spawn. */
235
+ readonly cameraOffset: readonly [number, number, number];
236
+ /** World x and z the dense ground cover is placed around: a meadow is a place, not a texture. */
237
+ readonly focus: readonly [number, number];
238
+ }
239
+ interface IBiomeSpec {
240
+ /** The name of the look the game grades this biome under; the package reads no colour. */
241
+ readonly look: string;
242
+ readonly bake: IBakeBundle;
243
+ readonly landform: LandformKind;
244
+ readonly sizeMeters: number;
245
+ readonly seed: number;
246
+ /**
247
+ * How the rows place: `ordered` runs every generator from one stream in one fixed order, `seeded`
248
+ * runs each rule from its own seed. `ordered` carries the game's own counts; `seeded` is the
249
+ * package's own sampler.
250
+ */
251
+ readonly stream: "ordered" | "seeded";
252
+ /** The cover a stream runs on: its model, its seed and the discs it keeps clear. */
253
+ readonly cover: ICoverSpec;
254
+ readonly foliage: readonly IFoliageType[];
255
+ readonly grass: readonly IGrassType[];
256
+ readonly layers: readonly ILayerInfo[];
257
+ readonly water: readonly IBiomeWaterBody[];
258
+ readonly spawn: ISpawnSpec;
259
+ /** The species that live here, by asset id: the pack resolves each to its own art. */
260
+ readonly species: readonly string[];
261
+ /** The words a request may use for this biome; its own name comes first. */
262
+ readonly aliases: readonly string[];
263
+ }
264
+ /**
265
+ * One biome file, checked field by field. The file is `biome.data.json`: `biome.json` is Biome's own
266
+ * configuration name, and a data file called that is parsed as a project config and fails the lint.
267
+ * @situation read a biome's rules from `starter/<biome>/biome.data.json` before a game or a cook uses them
268
+ * @constraint The file carries no appearance; colours, materials and shading stay game source
269
+ * @example const spec = validateBiome(JSON.parse(text), "forest");
270
+ * @requires npm i @threenative/terrain
271
+ */
272
+ declare function validateBiome(spec: unknown, name: string): IBiomeSpec;
273
+
274
+ /**
275
+ * A biome's band rows resolved once against the world they are about.
276
+ *
277
+ * The values in `biome.data.json` are fractions of the measured height range: the same numbers make
278
+ * a 40 m valley and a 900 m massif, and a world with a different crop of the same landform reads the
279
+ * same bands. Resolving them here keeps one owner of the numbers (the biome file) and one owner of
280
+ * the measurement (this function), so a game reads bands instead of repeating the arithmetic.
281
+ */
282
+ interface IMeasuredBands {
283
+ /** Lowest and highest sample, metres. Equal when the field is flat; the bands then collapse onto it. */
284
+ readonly elevationRange: readonly [number, number];
285
+ /** Each ground layer's band in metres, keyed by its row, in the order the file lists it. */
286
+ readonly bands: Readonly<Record<string, readonly [number, number]>>;
287
+ /** The `snow` row's band, when the biome has one. */
288
+ readonly snowBand: readonly [number, number] | null;
289
+ /**
290
+ * The `snow` row's slope interval, in degrees: snow starts to shed at the first and is gone by the
291
+ * second. `null` when the row has no shed rule.
292
+ */
293
+ readonly snowShed: readonly [number, number] | null;
294
+ }
295
+ /**
296
+ * Resolve a biome's fraction bands against this world's own height samples.
297
+ * @requires npm i -D @threenative/terrain
298
+ * @situation turn a biome file's height fractions into the metres a world actually measured
299
+ * @constraint samples are finite and at least one; a flat field resolves every band onto its one height
300
+ * @example const bands = measureBands(spec.layers, state.height);
301
+ */
302
+ declare function measureBands(layers: readonly ILayerInfo[], heights: ArrayLike<number>): IMeasuredBands;
303
+
304
+ /**
305
+ * A value-noise field, 0..1, as the numbers that shape it.
306
+ *
307
+ * Every per-biome field the placement rules read — a stand's density, a mat plain's cover, the
308
+ * drift a blade grows on — is this one formula: a floor plus two octaves of value noise. A field is
309
+ * therefore a value a biome carries, not a branch that picks a function: a sixth biome tunes the
310
+ * floor, the gains and the frequencies, and the code that samples it does not change.
311
+ */
312
+ interface ICoverField {
313
+ /** The weight the field stands at where the noise is zero. */
314
+ readonly base: number;
315
+ /** Octaves, low frequency first: how much of it lands in the sum, and where it is sampled. */
316
+ readonly octaves: readonly {
317
+ /** How much of this octave's noise lands in the sum. */
318
+ readonly gain: number;
319
+ /** Metres⁻¹ the field is sampled at: a small frequency gives broad patches. */
320
+ readonly frequency: number;
321
+ /** The field's own seed axis, so two octaves do not line up. */
322
+ readonly offset: number;
323
+ }[];
324
+ }
325
+ /**
326
+ * A field's weight at (x, z), clamped to 0..1.
327
+ *
328
+ * @requires npm i -D @threenative/terrain
329
+ * @situation sample the stand field a biome's trees and cover thin on
330
+ * @situation measure the drift a biome's blades grow by, or the mat field its cover follows
331
+ * @constraint the field is a value, so two worlds sample the same formula with their own numbers
332
+ * @example const stand = fieldWeight(STAND_FIELD, x, z);
333
+ */
334
+ declare function fieldWeight(field: ICoverField, x: number, z: number): number;
335
+ /**
336
+ * The stand field: where the wood closes and where it opens. Two octaves of value noise rather than
337
+ * a sum of sines, whose stripes read as "Tree Tree Tree" from the air.
338
+ */
339
+ declare const STAND_FIELD: ICoverField;
340
+ /** The mat field a mat plain is measured by: lichen mats, thicker and finer than a stand's patches. */
341
+ declare const MATS_FIELD: ICoverField;
342
+
343
+ /**
344
+ * The ordered scatter: one stream of draws, in one fixed order, for a biome whose rules are code.
345
+ *
346
+ * A biome that says `"stream": "ordered"` does not place one rule at a time from a seed per rule. It
347
+ * runs fifteen generators — a stand loop, an understorey, clumped ground cover, three grids, a tide
348
+ * line, a river walk, a detail disc and a cobbled bed — and draws every candidate from one
349
+ * `createRandom` stream in that order. The order IS the rule: change one draw and every later
350
+ * placement moves. So this file is the generator, copied line for line from the game that graded it
351
+ * (Strata's `examples/strata-terrain-preview/src/render/scatter.ts` at `5afb42b1c`), and its look and
352
+ * tuning numbers are read from the biome's rows instead of from the game's look.
353
+ *
354
+ * What stays in code is the algorithm's own structure: the cell of the spacing grid, the understorey
355
+ * loop's count, the candidate budget of each grid, the detail disc's two radii. A number here is the
356
+ * shape of the rule, not the look of a biome; a number in a row is the look.
357
+ *
358
+ * The four stages the PRD names are these generators' four jobs, in order: `surfaceSample` draws a
359
+ * candidate, `densityFilter` refuses it on slope, water, height, meadow weight and the stand field,
360
+ * `selfPrune` keeps its spacing against the accepted ones, and `meshSpawn` stamps the asset with its
361
+ * yaw, scale and normal.
362
+ */
363
+ /** The cover drift a biome's blades grow on, read from its grass row. */
364
+ interface ICoverFieldDrift {
365
+ /** The value-noise field the drift is measured on. */
366
+ readonly field: ICoverField;
367
+ /** Metres⁻¹ the field is sampled at, in x and z: a small frequency drifts in broad patches. */
368
+ readonly frequency: readonly [number, number];
369
+ /** The share of the cover that stands everywhere. */
370
+ readonly amplitude: number;
371
+ /** How much of the cover rides the field above that floor. */
372
+ readonly offset: number;
373
+ /** The field weight the drift is gone at, and the weight over which it reaches full. */
374
+ readonly band: readonly [number, number];
375
+ }
376
+ /** The two fields a drift can name: a wood's stands, or a mat plain's mats. */
377
+ type CoverFieldName = "stand" | "mats";
378
+ /** Every number one biome's ordered generators read: its tree row, its grass row and its cover. */
379
+ interface IOrderedScatterRules {
380
+ /** The species a stand is made of. */
381
+ readonly treeAsset: "spruce" | "sapling";
382
+ /** How many trees the rule accepts. */
383
+ readonly treeCount: number;
384
+ /** Metres a trunk keeps from its neighbour at a closed stand core (first) and in the open. */
385
+ readonly treeSpacing: readonly [number, number];
386
+ /** Whether the tree's spacing follows the stand mask, or is the same everywhere. */
387
+ readonly treeStands: boolean;
388
+ /** Degrees: a tree will not stand on ground steeper than this. */
389
+ readonly treeSlopeLimit: number;
390
+ /** Metres above the playable floor a tree stops, where the treeline is below the peaks. */
391
+ readonly treeHeightCeiling: number | null;
392
+ /** The ground cover's grid cell, in metres. */
393
+ readonly grassCell: number;
394
+ /** How much of the ground this world covers; 0 leaves the bare rock bare. */
395
+ readonly grassDensity: number;
396
+ /** Degrees: the meadow runs out here, over the next `grassSlopeFalloff` degrees. */
397
+ readonly grassSlopeLimit: number;
398
+ readonly grassSlopeFalloff: number;
399
+ /** Metres above the waterline a plant stands at. */
400
+ readonly grassWaterMargin: number;
401
+ /** A beach that thins over `waterline + waterMargin`, over `width` metres; absent on dry worlds. */
402
+ readonly grassBeach: readonly [number, number] | null;
403
+ /** Ground height, and the metres it takes to fade, that keep a meadow off the peaks. */
404
+ readonly grassHeight: readonly [number, number] | null;
405
+ /** The mat field's band the cover thins on, `[threshold, span]`; null on ground without mats. */
406
+ readonly grassMats: readonly [number, number] | null;
407
+ /** Metres between plants in the dense detail disc around a place the player stands. */
408
+ readonly grassDetailSpacing: number;
409
+ /** The least meadow weight, 0..1, a tree accepts. */
410
+ readonly treeGrassThreshold: number;
411
+ /** The least stand-field weight, 0..1, a tree accepts. */
412
+ readonly treeStandThreshold: number;
413
+ /** The ground the row was graded on: which of the four cover models the generators run. */
414
+ readonly ground: "wood" | "crag" | "mesa" | "mats";
415
+ /** The seed the one ordered stream starts from. */
416
+ readonly seed: number;
417
+ /** The most candidates a stand's loop draws before it settles for what it has. */
418
+ readonly attempts: number;
419
+ /** The cover drift a blade grows on: the field, its sampling and the band it fades over. */
420
+ readonly drift: ICoverFieldDrift;
421
+ /** A blade's scale where the ground is dry, and the share of it the draw adds. */
422
+ readonly bladeScale: number;
423
+ readonly bladeJitter: number;
424
+ /** The chance a grass cell also grows a scrub, and the scrub's own scale band. */
425
+ readonly scrubChance: number;
426
+ readonly scrubScale: number;
427
+ readonly scrubJitter: number;
428
+ /** Whether a grass cell also grows the odd bush. */
429
+ readonly scrubBush: boolean;
430
+ /** Whether blades grow tall on the wet sand of a shore. */
431
+ readonly shoreGround: boolean;
432
+ /** Whether the rivers' beds and banks are dressed with cobbles. */
433
+ readonly cobbledBed: boolean;
434
+ /** Radius at the widest point of the game's biggest stone, which normalizes a cobble's scale. */
435
+ readonly stoneRadius: number;
436
+ }
437
+ /**
438
+ * A biome's rows as the ordered generators read them.
439
+ *
440
+ * The rule is short and shared; only these numbers differ between a wood, a barren shoulder, a dune
441
+ * field and a tundra, so the biome file names them rather than the code. A biome whose tree is not
442
+ * one this generator has art for fails here, naming the species, rather than planting nothing.
443
+ * @requires npm i -D @threenative/terrain
444
+ * @situation run a biome file's rows through the ordered scatter
445
+ * @constraint the file carries one foliage row, one grass row and a cover block
446
+ * @example const rules = orderedScatterRules(spec);
447
+ */
448
+ declare function orderedScatterRules(spec: IBiomeSpec): IOrderedScatterRules;
449
+ /** A field the placement rule reads: the world's baked transport and sampled geometry. */
450
+ interface IOrderedScatterField {
451
+ readonly erosion?: IErosionMaps;
452
+ readonly field: Heightfield;
453
+ readonly resolution: number;
454
+ readonly size: number;
455
+ readonly waterLevel: number | null;
456
+ /** The rows the generators run, resolved from the biome file. */
457
+ readonly rules: IOrderedScatterRules;
458
+ /** The biome file itself: the water bodies its rivers are read from. */
459
+ readonly spec: IBiomeSpec;
460
+ /** Still water: nothing grows below a lake's level inside its reach. */
461
+ readonly rivers?: readonly {
462
+ readonly points: readonly (readonly number[])[];
463
+ readonly width: number;
464
+ }[];
465
+ readonly lakes?: readonly {
466
+ readonly at: readonly number[];
467
+ readonly radius: number;
468
+ readonly level: number;
469
+ }[];
470
+ }
471
+ /** Every placement, for one world, from one ordered stream. */
472
+ interface IOrderedScatter {
473
+ readonly placements: IPlacement[];
474
+ /** How many of each prop was accepted, for the report and the playtest's own state. */
475
+ readonly counts: Record<string, number>;
476
+ }
477
+ /**
478
+ * Every placement, for one world, from one seed: the game's own rule set, in its own draw order.
479
+ * @requires npm i -D @threenative/terrain
480
+ * @situation bake a biome that says `"stream": "ordered"`
481
+ * @constraint `data.rules` is the biome's rows, and `data.field` the ground they were graded on
482
+ * @example const { placements, counts } = scatterProps(data, focus, clearings);
483
+ */
484
+ declare function scatterProps(data: IOrderedScatterField, focus: {
485
+ x: number;
486
+ z: number;
487
+ }, clearings?: readonly (readonly [number, number, number])[]): IOrderedScatter;
488
+
489
+ /**
490
+ * The four stages a scatter runs, named after the PCG elements that do each one
491
+ * (`UPCGSurfaceSamplerSettings`, `UPCGDensityFilterSettings`, `UPCGSelfPruningSettings`,
492
+ * `UPCGStaticMeshSpawnerSettings`; UE 5.8.3). In this package they are the fields of
493
+ * `IScatterParams`, evaluated by `Terrain.evaluate()` in this order:
494
+ *
495
+ * - `surfaceSample` — `count`, `seed`, `offsetY`: where a candidate lands.
496
+ * - `densityFilter` — `minSlope`/`maxSlope`, `minHeight`/`maxHeight`, `avoidWater`, `mask`: whether
497
+ * the ground there accepts one.
498
+ * - `selfPrune` — `minDistance`: whether it is too close to one already accepted.
499
+ * - `meshSpawn` — `asset`, `scale`, `alignToNormal`: what is stamped, and how.
500
+ *
501
+ * A bake needs no second scatter engine: this function receives the placements those stages
502
+ * produced and turns them into the world package a game streams.
503
+ */
504
+ type IBakeBiomeStage = "surfaceSample" | "densityFilter" | "selfPrune" | "meshSpawn";
505
+ declare const BAKE_BIOME_STAGES: readonly IBakeBiomeStage[];
506
+ interface IBakeBiomeOptions extends Omit<IBakeWorldPackageOptions, "assets"> {
507
+ /** The evaluated recipe: heights, splat and the placements the scatter stages accepted. */
508
+ readonly state: ITerrainState;
509
+ /** The biome the bake is for. Validated here, so an inline spec fails closed at the bake. */
510
+ readonly spec: IBiomeSpec;
511
+ /**
512
+ * Every asset an instance may reference, `glb`, bounds and its levels. An unknown one fails.
513
+ * Absent, the bake writes no package and hands the instances back: a game that keeps its own
514
+ * container for now reads `scatter` instead of a streamed package.
515
+ */
516
+ readonly assets?: Readonly<Record<string, IWorldPackageAsset>>;
517
+ /** How the rows place. Defaults to the biome file's own `stream`. */
518
+ readonly stream?: "ordered" | "seeded";
519
+ }
520
+ interface IBakedBiome {
521
+ /** The streamed package, or null when the call named no assets to write one. */
522
+ readonly package: IBakedWorldPackage | null;
523
+ /** The biome's band rows resolved against this state's own height range. */
524
+ readonly bands: IMeasuredBands;
525
+ /** Placements the bake made, one row per asset. */
526
+ readonly placements: readonly {
527
+ readonly asset: string;
528
+ readonly count: number;
529
+ }[];
530
+ /** The ordered stream's instances, in draw order; null when the rows ran on their own seeds. */
531
+ readonly scatter: IOrderedScatter | null;
532
+ }
533
+ /**
534
+ * Bake one biome: the recipe's evaluated state and the world package it streams.
535
+ *
536
+ * This is the composition `terrain_generate` and a game's build script both call, so the file layout
537
+ * a player streams is decided in one place. The biome is validated first — an inline spec from a
538
+ * request is checked here, not trusted — and the package's own placement runs are checked against
539
+ * the state they came from, so a bake can never ship a cell list that lost instances.
540
+ * @requires npm i -D @threenative/terrain
541
+ * @situation bake one biome's world package from an evaluated recipe and a biome file
542
+ * @constraint every instance's asset must be in `assets`; every instance must land in exactly one cell run
543
+ * @example const baked = bakeBiome({ state: terrain.evaluate(), spec: validateBiome(json, "savanna"), assets });
544
+ */
545
+ declare function bakeBiome(options: IBakeBiomeOptions): IBakedBiome;
546
+
547
+ /**
548
+ * The far field: spruce on the collar past the playable square, by a rule of densities.
549
+ *
550
+ * The bake plants the square; a game draws its whole valley, so the ground past the edge would read
551
+ * as a bare lawn around one block of trees. This places the far stand on the drawn collar by the
552
+ * rules UE's procedural foliage applies per foliage type, each a density in 0..1 multiplied together
553
+ * (UE 5.8.3: altitude, slope, water, stands and spacing; `InstancedFoliage.cpp`, `FoliageEdMode.cpp`
554
+ * and `ProceduralFoliageTile.cpp`, cited on each test below). Every number is the biome row's `far`
555
+ * block, so a sixth biome tunes its own collar without a branch here.
556
+ *
557
+ * The mechanism is the package's; the game supplies its collar, its treeline band and its cameras.
558
+ */
559
+ /** What a far-field tree is: the tessellated collar and the layer the game draws it on. */
560
+ interface IFarFieldOptions {
561
+ readonly size: number;
562
+ readonly resolution: number;
563
+ /** The world's far collar, as drawn. */
564
+ readonly collar: HeightfieldCollar;
565
+ /** The measured treeline band, metres (`IWorldBiome.heightBands.treeline`). */
566
+ readonly treeline: readonly [number, number];
567
+ /** The biome's far-field row: spacing, fades, reach and seed. */
568
+ readonly rules: IFarFieldRule;
569
+ /** The asset a far tree is stamped as, and the layer a game's streaming buckets it under. */
570
+ readonly asset: string;
571
+ readonly layer: string;
572
+ readonly rivers?: readonly {
573
+ readonly points: readonly (readonly number[])[];
574
+ readonly width: number;
575
+ }[];
576
+ readonly lakes?: readonly {
577
+ readonly at: readonly number[];
578
+ readonly radius: number;
579
+ readonly level: number;
580
+ }[];
581
+ /** Circles kept open, [x, z, radius]: the vista's meadow. */
582
+ readonly clear?: readonly (readonly [number, number, number])[];
583
+ }
584
+ /**
585
+ * The collar's height at any (x, z), and a way to raise one of its per-vertex attributes at a
586
+ * placement: both read the collar's own quad grid, so a lane that reshapes the collar moves the
587
+ * trees with it.
588
+ *
589
+ * @requires npm i -D @threenative/terrain
590
+ * @situation plant a far field on a drawn collar and paint the canopy its crowns cover
591
+ * @constraint the collar decides where a tree stands; this sampler never resamples the square
592
+ * @example const sampler = collarSampler(collar); const height = sampler.at(x, z);
593
+ */
594
+ declare function collarSampler(collar: HeightfieldCollar): {
595
+ at: (x: number, z: number) => number | null;
596
+ paint: (attribute: BufferAttribute, x: number, z: number, value: number) => void;
597
+ };
598
+ /**
599
+ * Far-field placements on the collar; also paints the collar's `canopy` attribute under each crown.
600
+ *
601
+ * @requires npm i -D @threenative/terrain
602
+ * @situation plant the stand past a game's playable square, out to the drawn collar
603
+ * @constraint the row's `far` block decides every density; the caller supplies the collar and layer
604
+ * @example const trees = farForestPlacements({ size, resolution, collar, treeline, rules, asset, layer });
605
+ */
606
+ declare function farForestPlacements(options: IFarFieldOptions): IPlacement[];
4
607
 
5
608
  /** The eight splat channels, in channel order. Index 0 is the default base channel. */
6
609
  declare const MATERIAL_IDS: readonly MaterialId[];
@@ -23,6 +626,28 @@ declare const Mask: Readonly<{
23
626
  not: (mask: IMask) => IMask;
24
627
  }>;
25
628
 
629
+ interface ITerrainStats {
630
+ /** Highest minus lowest height, metres. */
631
+ readonly relief: number;
632
+ /** (mean - min) / (max - min): about 0.5 for an evenly dissected massif, low for peaks over wide flats. */
633
+ readonly hypsometricIntegral: number;
634
+ /** Slope percentiles in degrees from central differences. */
635
+ readonly slopeP50: number;
636
+ readonly slopeP90: number;
637
+ /** Channel length per area, km/km^2: cells draining at least 0.1 km^2, after depression filling. */
638
+ readonly drainageDensity: number;
639
+ /** Excess kurtosis of the Laplacian: smooth blobs are near 0, sharp ridges and gullies are heavy-tailed. */
640
+ readonly curvatureKurtosis: number;
641
+ }
642
+ /**
643
+ * Landform statistics used to calibrate generators against real DEMs.
644
+ * @requires npm i @threenative/terrain
645
+ * @situation compare generated terrain with a USGS or SRTM crop on the same footprint
646
+ * @constraint square grids only; compare crops of equal spacing, because slope and curvature depend on it
647
+ * @example const stats = terrainStats(state.height, state.resolution, state.size);
648
+ */
649
+ declare function terrainStats(height: ArrayLike<number>, n: number, size: number): ITerrainStats;
650
+
26
651
  /** Bilinear world-space height query. It is not the rendered or collidable triangle surface. */
27
652
  /**
28
653
  * Bilinear query of canonical height samples; triangle sampling is a separate contract.
@@ -211,93 +836,122 @@ declare function encodeZIP(files: readonly IExportFile[]): Uint8Array<ArrayBuffe
211
836
  * @constraint authoring data only; the game owns appearance, physics and rendering
212
837
  * @example const terrain = new Terrain({ resolution: 17 }); const file = await makeExport(terrain.evaluate(), terrain.toJSON(), "project");
213
838
  */
839
+ declare function makeExport(state: ITerrainState | null, recipe: ITerrainDocument, kind: "project"): Promise<IExportArchive>;
214
840
  declare function makeExport(state: ITerrainState, recipe: ITerrainDocument, kind: ExportKind): Promise<IExportArchive>;
215
841
 
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;
228
- }
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;
842
+ /**
843
+ * The streamed prop worlds one bake writes, and what each one holds.
844
+ *
845
+ * A prop package is the same container as a world package (`world-package.ts`): eight float32 per
846
+ * placement, cells of a fixed size, and one run per asset inside a cell. What it adds is the split
847
+ * into streamed worlds. The game draws its placements in more than one `WorldCells` because reach
848
+ * and shadow policy differ between a horizon-canopy tree and a shadowless blade of grass, and the
849
+ * far field and the vista meadow answer a query flag. This module turns labelled placements into
850
+ * those worlds, so the bake writes them and the game loads them, and neither side owns the grouping.
851
+ */
852
+ /** Which streamed world a record draws in, for a loader that answers a query flag before it loads. */
853
+ type IPropBucketKind = "local" | "far" | "meadow";
854
+ /** One placement, the streamed world it belongs to, and how far it may draw. */
855
+ interface IPropBucketEntry {
856
+ readonly placement: IPlacement;
857
+ /** The streamed world's name, e.g. `local:true`. Two entries of one name share every container field. */
858
+ readonly bucket: string;
859
+ /** Metres at which the record may be culled; `Number.POSITIVE_INFINITY` keeps every cell resident. */
860
+ readonly reach: number;
861
+ /**
862
+ * The model the record draws, when it is not the placement's asset alone: the game's
863
+ * `asset:variant` key, with a shape suffix when one scale cannot carry the placement. The run a
864
+ * record sits in names it, and the loader's asset table is keyed by it.
865
+ */
866
+ readonly key?: string;
867
+ /** Defaults to `local`. A bucket that names two kinds fails the compile. */
868
+ readonly kind?: IPropBucketKind;
235
869
  }
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;
870
+ /** One streamed prop world: its container, its per-record reach, and its per-record placement ID. */
871
+ interface IPropBucketPackage {
872
+ readonly bucket: string;
873
+ readonly kind: IPropBucketKind;
874
+ readonly extent: IWorldPackageManifest["extent"];
257
875
  readonly cells: readonly {
258
876
  readonly x: number;
259
877
  readonly z: number;
260
878
  readonly runs: readonly IWorldPackageRun[];
261
879
  }[];
880
+ /** Eight float32 per record: position, quaternion, uniform scale. */
881
+ readonly placements: Uint8Array;
882
+ /** One float32 per record, in record order. */
883
+ readonly reach: Float32Array;
884
+ /** One placement ID per record, in record order. The game's `variantFor` hashes it. */
885
+ readonly ids: readonly string[];
262
886
  }
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"]>>;
887
+ interface IPropPackage {
888
+ readonly cellSize: number;
889
+ readonly buckets: readonly IPropBucketPackage[];
268
890
  }
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. */
891
+ interface ICompilePropBucketsOptions {
892
+ /** Metres per streamed cell. Defaults to 128. */
273
893
  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
- };
894
+ /**
895
+ * The extent every bucket includes before its own placements widen it, e.g. the world square.
896
+ * Without it a bucket spans exactly its own placements.
897
+ */
898
+ readonly bounds?: IWorldPackageManifest["extent"];
281
899
  }
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. */
900
+ /** The cell size the game streams props in: 128 m, coarse enough that admission jobs stay bounded. */
901
+ declare const PROP_CELL_SIZE = 128;
902
+ /**
903
+ * Group placements into their streamed worlds and write each world's cells and records.
904
+ *
905
+ * The order is the streamed one: cells sorted by `x` then `z`, assets sorted by name inside a cell,
906
+ * and records in the order the entries arrived inside a run. Same-cell, same-asset placements keep
907
+ * their input order, so a re-run of a seeded bake reproduces the buffer byte for byte.
908
+ *
909
+ * @requires npm i -D @threenative/terrain
910
+ * @situation bake the prop worlds a game streams, once, instead of compiling them at load
911
+ * @constraint headless; the caller decides every placement, its streamed world, its reach and its pose
912
+ * @example const pkg = compilePropBuckets(entries, { bounds });
913
+ * @override cellSize and the base extent; the bucket, reach and kind of every entry
914
+ */
915
+ declare function compilePropBuckets(entries: readonly IPropBucketEntry[], options?: ICompilePropBucketsOptions): IPropPackage;
916
+ /**
917
+ * The asset a package run names.
918
+ *
919
+ * A prop run names the model it draws, `asset:variant[@shape]`; a container written by
920
+ * `bakeWorldPackage` names the asset alone. Both reduce to the asset here, which is what a count, a
921
+ * material or a placement's own `asset` field holds.
922
+ *
923
+ * @requires npm i -D @threenative/terrain
924
+ * @situation count one species across a world's prop buckets, or name the asset a run draws
925
+ * @example const asset = propAssetOf("spruce:2"); // "spruce"
926
+ */
927
+ declare function propAssetOf(modelKey: string): string;
928
+ /** The files one bake writes for a world's prop package: its bucket list and each bucket's three files. */
929
+ interface IPropPackageFiles {
930
+ readonly manifest: Uint8Array;
286
931
  readonly files: Readonly<Record<string, Uint8Array>>;
287
932
  }
288
933
  /**
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.
934
+ * A path under `world/` that no bucket name can break: `local:true` becomes `local-true`.
935
+ *
936
+ * The bucket's own name is kept in the manifest, so this rename is only a file-system concern.
937
+ *
938
+ * @requires npm i -D @threenative/terrain
939
+ * @situation name one of a bucket's three files without a bucket key that breaks a path
940
+ * @example const file = propPackageFile("forest", "local:true", "props.bin"); // "forest.local-true.props.bin"
941
+ */
942
+ declare function propPackageFile(world: string, bucket: string, suffix: string): string;
943
+ /**
944
+ * Write a compiled package as the manifest the game fetches and one set of files per bucket.
945
+ *
946
+ * The manifest names the files rather than embedding them, so a loader fetches only the buckets its
947
+ * query flags keep (`?farForest=on` keeps the far field, `?meadow=off` drops the vista cover).
293
948
  *
294
949
  * @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
950
+ * @situation write a compiled package to disk: one manifest and three files per streamed world
951
+ * @constraint the manifest names the files; nothing here touches a file system
952
+ * @example const { manifest, files } = propPackageFiles(pkg, "forest");
299
953
  */
300
- declare function bakeWorldPackage(state: ITerrainState, options: IBakeWorldPackageOptions): IBakedWorldPackage;
954
+ declare function propPackageFiles(pkg: IPropPackage, world: string): IPropPackageFiles;
301
955
 
302
956
  /**
303
957
  * A spatial index for water proximity: river segments, river stations and lake shores.
@@ -332,4 +986,4 @@ interface ISegmentIndex<T> {
332
986
  */
333
987
  declare function createSegmentIndex<T>(segments: readonly IWaterSegment<T>[], cellSize: number): ISegmentIndex<T>;
334
988
 
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 };
989
+ 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 IMeasuredBands, type IOrderedScatter, type IOrderedScatterField, type IOrderedScatterRules, IPlacement, IPlacementOverride, type IPropBucketEntry, type IPropBucketKind, type IPropBucketPackage, type IPropPackage, type IPropPackageFiles, IRaw16Options, ISampledGrid, type ISegmentIndex, type ISpawnSpec, ITerrainConfig, ITerrainDocument, ITerrainState, type ITerrainStats, 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, decodeRAW16, encodeGLB, encodeHeightPNG, encodeRAW16, encodeSplatPNGs, encodeZIP, farForestPlacements, fieldWeight, gradientAt, landform, landformBackdrop, makeExport, measureBands, orderedScatterRules, propAssetOf, propPackageFile, propPackageFiles, sampleHeight, scatterProps, slopeAtIndex, slopeQuantile, splinePoints, terrainStats, validateBiome, validateDocument, validatePlacementOverrides };