@threenative/terrain 0.1.9 → 0.1.12

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 (243) hide show
  1. package/README.md +40 -59
  2. package/THIRD_PARTY_NOTICES.md +2 -1
  3. package/dist/bake-DJ5cxg0C.d.ts +82 -0
  4. package/dist/editor/index.d.ts +4 -4
  5. package/dist/editor/index.js +130 -128
  6. package/dist/editor/server.d.ts +2 -2
  7. package/dist/editor/server.js +38 -35
  8. package/dist/editor/worker.d.ts +1 -1
  9. package/dist/editor/worker.js +101 -101
  10. package/dist/export.d.ts +1 -1
  11. package/dist/index.d.ts +156 -273
  12. package/dist/index.js +562 -378
  13. package/dist/kit-world.d.ts +107 -0
  14. package/dist/kit-world.js +5134 -0
  15. package/dist/kit.d.ts +21 -4
  16. package/dist/kit.js +337 -223
  17. package/dist/mcp/cook-child.js +1963 -1543
  18. package/dist/mcp/server.js +716 -429
  19. package/dist/prop-package-Dwz0EWoB.d.ts +141 -0
  20. package/dist/{server-B5RdvEAC.d.ts → server-LnFwY8sr.d.ts} +1 -1
  21. package/dist/starter.d.ts +1142 -7
  22. package/dist/starter.js +2102 -120
  23. package/dist/{terrain-CAEaW0mQ.d.ts → terrain-DYCyAOCJ.d.ts} +1 -1
  24. package/dist/three.d.ts +1 -1
  25. package/dist/three.js +1 -1
  26. package/dist/{types-BpH00qsx.d.ts → types-kpI0C4hW.d.ts} +1 -1
  27. package/dist/{world-package-B8QgHjAQ.d.ts → world-package-DqJC3-Nn.d.ts} +2 -2
  28. package/docs/authoring/editor.md +73 -0
  29. package/docs/authoring/new-environment.md +97 -0
  30. package/docs/authoring/recipes.md +97 -0
  31. package/docs/authoring/world-export.md +66 -0
  32. package/package.json +24 -8
  33. package/starter/alpine/README.md +22 -12
  34. package/starter/alpine/bake.mjs +14 -1
  35. package/starter/alpine/biome.data.json +187 -25
  36. package/starter/alpine/heightmap.r16 +0 -0
  37. package/starter/alpine/playerRig.ts +89 -0
  38. package/starter/alpine/recipe.json +169 -15
  39. package/starter/alpine/render/bakedFile.ts +17 -0
  40. package/starter/alpine/render/benchmark.ts +77 -0
  41. package/starter/alpine/render/biomeData.ts +14 -0
  42. package/starter/alpine/render/biomes.ts +687 -0
  43. package/starter/alpine/render/ground/cover.ts +565 -0
  44. package/starter/alpine/render/ground/horizon.ts +219 -0
  45. package/starter/alpine/render/ground/palette.d.ts +1 -0
  46. package/starter/alpine/render/ground/palette.js +11 -0
  47. package/starter/alpine/render/ground/scatter.ts +104 -0
  48. package/starter/alpine/render/ground/terrain.ts +1860 -0
  49. package/starter/alpine/render/kitAssets.ts +28 -0
  50. package/starter/alpine/render/loading.ts +354 -0
  51. package/starter/alpine/render/lookKnobs.ts +37 -0
  52. package/starter/alpine/render/orbitCamera.ts +155 -0
  53. package/starter/alpine/render/props/farForest.ts +94 -0
  54. package/starter/alpine/render/props/pack.ts +1114 -0
  55. package/starter/alpine/render/props/prepared.ts +225 -0
  56. package/starter/alpine/render/props/propMaterials.ts +1239 -0
  57. package/starter/alpine/render/props/propProgress.ts +2 -0
  58. package/starter/alpine/render/props/propWorld.ts +105 -0
  59. package/starter/alpine/render/props/props.ts +633 -0
  60. package/starter/alpine/render/props/spruce.ts +440 -0
  61. package/starter/alpine/render/sky/atmosphere.ts +329 -0
  62. package/starter/alpine/render/sky/sky.ts +382 -0
  63. package/starter/alpine/render/texturePreparation.ts +135 -0
  64. package/starter/alpine/render/water/river.ts +1132 -0
  65. package/starter/alpine/render/worldNames.ts +6 -0
  66. package/starter/alpine/scene.ts +715 -0
  67. package/starter/alpine/sceneProps.ts +561 -0
  68. package/starter/alpine/sceneState.ts +33 -0
  69. package/starter/alpine/world/terrainAssets.ts +145 -0
  70. package/starter/alpine/world/walkBand.ts +47 -0
  71. package/starter/alpine/world/water.ts +74 -0
  72. package/starter/alpine/worlds.ts +13 -0
  73. package/starter/arbor/wind.ts +84 -0
  74. package/starter/coastal/README.md +26 -25
  75. package/starter/coastal/assets.json +10 -0
  76. package/starter/coastal/bake.mjs +14 -1
  77. package/starter/coastal/biome.data.json +18 -3
  78. package/starter/coastal/playerRig.ts +89 -0
  79. package/starter/coastal/recipe.json +220 -18
  80. package/starter/coastal/render/bakedFile.ts +17 -0
  81. package/starter/coastal/render/benchmark.ts +81 -0
  82. package/starter/coastal/render/biomeData.ts +14 -0
  83. package/starter/coastal/render/biomes.ts +678 -0
  84. package/starter/coastal/render/ground/cover.ts +565 -0
  85. package/starter/coastal/render/ground/horizon.ts +219 -0
  86. package/starter/coastal/render/ground/palette.d.ts +1 -0
  87. package/starter/coastal/render/ground/palette.js +11 -0
  88. package/starter/coastal/render/ground/scatter.ts +104 -0
  89. package/starter/coastal/render/ground/terrain.ts +1829 -0
  90. package/starter/coastal/render/kitAssets.ts +28 -0
  91. package/starter/coastal/render/loading.ts +354 -0
  92. package/starter/coastal/render/lookKnobs.ts +37 -0
  93. package/starter/coastal/render/orbitCamera.ts +155 -0
  94. package/starter/coastal/render/props/farForest.ts +94 -0
  95. package/starter/coastal/render/props/pack.ts +1109 -0
  96. package/starter/coastal/render/props/prepared.ts +225 -0
  97. package/starter/coastal/render/props/propMaterials.ts +1239 -0
  98. package/starter/coastal/render/props/propProgress.ts +2 -0
  99. package/starter/coastal/render/props/propWorld.ts +105 -0
  100. package/starter/coastal/render/props/props.ts +633 -0
  101. package/starter/coastal/render/props/spruce.ts +440 -0
  102. package/starter/coastal/render/sky/atmosphere.ts +329 -0
  103. package/starter/coastal/render/sky/sky.ts +382 -0
  104. package/starter/coastal/render/texturePreparation.ts +135 -0
  105. package/starter/coastal/render/water/ocean.ts +284 -0
  106. package/starter/coastal/render/water/river.ts +1132 -0
  107. package/starter/coastal/render/worldNames.ts +6 -0
  108. package/starter/coastal/scene.ts +740 -0
  109. package/starter/coastal/sceneProps.ts +559 -0
  110. package/starter/coastal/sceneState.ts +33 -0
  111. package/starter/coastal/world/terrainAssets.ts +151 -0
  112. package/starter/coastal/world/walkBand.ts +47 -0
  113. package/starter/coastal/world/water.ts +74 -0
  114. package/starter/coastal/worlds.ts +13 -0
  115. package/starter/desert/README.md +51 -23
  116. package/starter/desert/bake-flora.mjs +142 -0
  117. package/starter/desert/bake-rocks.mjs +291 -0
  118. package/starter/desert/bake.mjs +14 -1
  119. package/starter/desert/biome.data.json +24 -12
  120. package/starter/desert/playerRig.ts +89 -0
  121. package/starter/desert/recipe.json +63 -16
  122. package/starter/desert/render/bakedFile.ts +17 -0
  123. package/starter/desert/render/benchmark.ts +79 -0
  124. package/starter/desert/render/biomeData.ts +14 -0
  125. package/starter/desert/render/biomes.ts +660 -0
  126. package/starter/desert/render/ground/cover.ts +565 -0
  127. package/starter/desert/render/ground/debris.ts +136 -0
  128. package/starter/desert/render/ground/horizon.ts +219 -0
  129. package/starter/desert/render/ground/palette.d.ts +1 -0
  130. package/starter/desert/render/ground/palette.js +11 -0
  131. package/starter/desert/render/ground/scatter.ts +104 -0
  132. package/starter/desert/render/ground/terrain.ts +1854 -0
  133. package/starter/desert/render/kitAssets.ts +28 -0
  134. package/starter/desert/render/loading.ts +354 -0
  135. package/starter/desert/render/lookKnobs.ts +37 -0
  136. package/starter/desert/render/orbitCamera.ts +155 -0
  137. package/starter/desert/render/props/farForest.ts +96 -0
  138. package/starter/desert/render/props/formations.ts +630 -0
  139. package/starter/desert/render/props/pack.ts +1195 -0
  140. package/starter/desert/render/props/prepared.ts +225 -0
  141. package/starter/desert/render/props/propMaterials.ts +1255 -0
  142. package/starter/desert/render/props/propProgress.ts +2 -0
  143. package/starter/desert/render/props/propWorld.ts +105 -0
  144. package/starter/desert/render/props/props.ts +624 -0
  145. package/starter/desert/render/props/spruce.ts +440 -0
  146. package/starter/desert/render/sand.ts +581 -0
  147. package/starter/desert/render/sky/atmosphere.ts +329 -0
  148. package/starter/desert/render/sky/sky.ts +382 -0
  149. package/starter/desert/render/texturePreparation.ts +135 -0
  150. package/starter/desert/render/water/river.ts +1132 -0
  151. package/starter/desert/render/worldNames.ts +6 -0
  152. package/starter/desert/scene.ts +748 -0
  153. package/starter/desert/sceneProps.ts +562 -0
  154. package/starter/desert/sceneState.ts +33 -0
  155. package/starter/desert/world/terrainAssets.ts +162 -0
  156. package/starter/desert/world/walkBand.ts +47 -0
  157. package/starter/desert/world/water.ts +74 -0
  158. package/starter/desert/worlds.ts +13 -0
  159. package/starter/forest/README.md +59 -116
  160. package/starter/forest/assets.json +14 -14
  161. package/starter/forest/bake.mjs +26 -4
  162. package/starter/forest/playerRig.ts +89 -0
  163. package/starter/forest/recipe.json +233 -43
  164. package/starter/forest/render/bakedFile.ts +17 -0
  165. package/starter/forest/render/benchmark.ts +77 -0
  166. package/starter/forest/render/biomeData.ts +14 -0
  167. package/starter/forest/render/biomes.ts +637 -0
  168. package/starter/forest/render/ground/cover.ts +565 -0
  169. package/starter/forest/render/ground/horizon.ts +219 -0
  170. package/starter/forest/render/ground/palette.d.ts +1 -0
  171. package/starter/forest/render/ground/palette.js +11 -0
  172. package/starter/forest/render/ground/scatter.ts +104 -0
  173. package/starter/forest/render/ground/terrain.ts +1796 -0
  174. package/starter/forest/render/kitAssets.ts +28 -0
  175. package/starter/forest/render/loading.ts +354 -0
  176. package/starter/forest/render/lookKnobs.ts +37 -0
  177. package/starter/forest/render/orbitCamera.ts +155 -0
  178. package/starter/forest/render/props/farForest.ts +94 -0
  179. package/starter/forest/render/props/pack.ts +1078 -0
  180. package/starter/forest/render/props/prepared.ts +226 -0
  181. package/starter/forest/render/props/propMaterials.ts +1247 -0
  182. package/starter/forest/render/props/propProgress.ts +2 -0
  183. package/starter/forest/render/props/propWorld.ts +105 -0
  184. package/starter/forest/render/props/props.ts +624 -0
  185. package/starter/forest/render/props/spruce.ts +440 -0
  186. package/starter/forest/render/sky/atmosphere.ts +329 -0
  187. package/starter/forest/render/sky/sky.ts +382 -0
  188. package/starter/forest/render/texturePreparation.ts +135 -0
  189. package/starter/forest/render/water/river.ts +1132 -0
  190. package/starter/forest/render/worldNames.ts +6 -0
  191. package/starter/forest/scene.ts +715 -0
  192. package/starter/forest/sceneProps.ts +559 -0
  193. package/starter/forest/sceneState.ts +33 -0
  194. package/starter/forest/surface.json +2 -2
  195. package/starter/forest/world/terrainAssets.ts +158 -0
  196. package/starter/forest/world/walkBand.ts +47 -0
  197. package/starter/forest/world/water.ts +74 -0
  198. package/starter/forest/worlds.ts +13 -0
  199. package/starter/tundra/README.md +35 -14
  200. package/starter/tundra/bake.mjs +14 -1
  201. package/starter/tundra/biome.data.json +6 -6
  202. package/starter/tundra/playerRig.ts +89 -0
  203. package/starter/tundra/recipe.json +111 -110
  204. package/starter/tundra/render/bakedFile.ts +17 -0
  205. package/starter/tundra/render/benchmark.ts +79 -0
  206. package/starter/tundra/render/biomeData.ts +14 -0
  207. package/starter/tundra/render/biomes.ts +714 -0
  208. package/starter/tundra/render/ground/cover.ts +565 -0
  209. package/starter/tundra/render/ground/horizon.ts +219 -0
  210. package/starter/tundra/render/ground/palette.d.ts +1 -0
  211. package/starter/tundra/render/ground/palette.js +11 -0
  212. package/starter/tundra/render/ground/scatter.ts +104 -0
  213. package/starter/tundra/render/ground/terrain.ts +1874 -0
  214. package/starter/tundra/render/kitAssets.ts +28 -0
  215. package/starter/tundra/render/loading.ts +354 -0
  216. package/starter/tundra/render/lookKnobs.ts +37 -0
  217. package/starter/tundra/render/orbitCamera.ts +155 -0
  218. package/starter/tundra/render/props/farForest.ts +96 -0
  219. package/starter/tundra/render/props/pack.ts +1088 -0
  220. package/starter/tundra/render/props/prepared.ts +225 -0
  221. package/starter/tundra/render/props/propMaterials.ts +1247 -0
  222. package/starter/tundra/render/props/propProgress.ts +2 -0
  223. package/starter/tundra/render/props/propWorld.ts +105 -0
  224. package/starter/tundra/render/props/props.ts +624 -0
  225. package/starter/tundra/render/props/spruce.ts +440 -0
  226. package/starter/tundra/render/sky/atmosphere.ts +329 -0
  227. package/starter/tundra/render/sky/sky.ts +382 -0
  228. package/starter/tundra/render/texturePreparation.ts +135 -0
  229. package/starter/tundra/render/water/river.ts +1132 -0
  230. package/starter/tundra/render/worldNames.ts +6 -0
  231. package/starter/tundra/scene.ts +715 -0
  232. package/starter/tundra/sceneProps.ts +559 -0
  233. package/starter/tundra/sceneState.ts +33 -0
  234. package/starter/tundra/world/terrainAssets.ts +159 -0
  235. package/starter/tundra/world/walkBand.ts +47 -0
  236. package/starter/tundra/world/water.ts +74 -0
  237. package/starter/tundra/worlds.ts +13 -0
  238. package/starter-assets.json +4 -4
  239. package/starter-credits.json +901 -15
  240. package/AGENT_GUIDE.md +0 -209
  241. package/starter/forest/sky.ts +0 -38
  242. package/starter/forest/water.ts +0 -257
  243. package/starter/forest/world.ts +0 -182
@@ -2,10 +2,12 @@
2
2
  import { createHash } from 'crypto';
3
3
  import { realpathSync } from 'fs';
4
4
  import { readFile, mkdir, writeFile, rm, lstat, realpath, readdir, stat, cp, rename } from 'fs/promises';
5
+ import { createRequire } from 'module';
5
6
  import { resolve, relative, join, sep, isAbsolute, basename, dirname } from 'path';
6
7
  import { createInterface } from 'readline';
7
8
  import { fileURLToPath } from 'url';
8
9
  import { spawn } from 'child_process';
10
+ import 'os';
9
11
 
10
12
  function childExecArgv(execArgv) {
11
13
  const out = [];
@@ -37,7 +39,7 @@ function runIsolated({
37
39
  new IsolatedKillError("runIsolated: child was cancelled before it started.")
38
40
  );
39
41
  }
40
- return new Promise((resolve3, reject) => {
42
+ return new Promise((resolve4, reject) => {
41
43
  const child = spawn(command, [...args], {
42
44
  detached: process.platform !== "win32",
43
45
  stdio: ["ignore", "pipe", "pipe"]
@@ -52,7 +54,7 @@ function runIsolated({
52
54
  clearTimeout(timer);
53
55
  signal?.removeEventListener("abort", onAbort);
54
56
  if (error !== void 0) reject(error);
55
- else resolve3(result);
57
+ else resolve4(result);
56
58
  };
57
59
  const stop = (reason) => {
58
60
  killed ??= new IsolatedKillError(reason);
@@ -86,55 +88,6 @@ function runIsolated({
86
88
  });
87
89
  }
88
90
 
89
- // src/core/kits.ts
90
- var TERRAIN_KITS = ["forest", "coastal", "alpine", "desert", "tundra"];
91
-
92
- // src/core/biome-words.ts
93
- var BIOME_WORDS = {
94
- alpine: [
95
- "alpine",
96
- "mountain",
97
- "mountains",
98
- "snowy",
99
- "peaks",
100
- "alps",
101
- "glacier",
102
- "glaciers",
103
- "snow"
104
- ],
105
- coastal: [
106
- "coastal",
107
- "beach",
108
- "coast",
109
- "sea",
110
- "ocean",
111
- "tropical",
112
- "shore",
113
- "lagoon",
114
- "fjord",
115
- "fjords"
116
- ],
117
- desert: ["desert", "dune", "dunes", "sand", "canyon", "canyons", "arid", "badlands", "mesa"],
118
- forest: [
119
- "forest",
120
- "pine",
121
- "pines",
122
- "woods",
123
- "woodland",
124
- "spruce",
125
- "fir",
126
- "trees",
127
- "jungle",
128
- "rainforest",
129
- "grove"
130
- ],
131
- tundra: ["tundra", "arctic", "ice", "frozen", "permafrost", "glacial"]
132
- };
133
- var BIOME_WORD_ROWS = TERRAIN_KITS.map((kit) => [kit, BIOME_WORDS[kit]]);
134
- function biomeWordList() {
135
- return BIOME_WORD_ROWS.map(([kit, words]) => `${kit} (${words.slice(1).join(", ")})`).join("; ");
136
- }
137
-
138
91
  // src/core/math.ts
139
92
  var clamp = (x, a = 0, b = 1) => Math.max(a, Math.min(b, x));
140
93
  var lerp = (a, b, t) => a + (b - a) * t;
@@ -290,6 +243,104 @@ function splinePoints(points, step = 3, smooth = true) {
290
243
  return out;
291
244
  }
292
245
 
246
+ // src/core/masks.ts
247
+ var MATERIAL_IDS = Object.freeze([
248
+ "grass",
249
+ "dirt",
250
+ "rock",
251
+ "snow",
252
+ "sand",
253
+ "mud",
254
+ "road",
255
+ "moss"
256
+ ]);
257
+ var range = (v, min, max, fade = 0) => fade > 0 ? smoothstep(min - fade, min, v) * (1 - smoothstep(max, max + fade, v)) : Number(v >= min && v <= max);
258
+ function compileMask(mask, s) {
259
+ if (!mask || mask.type === "all") return () => 1;
260
+ switch (mask.type) {
261
+ case "none":
262
+ return () => 0;
263
+ case "circle": {
264
+ const centre = mask.at;
265
+ return (i, x, z) => falloff(
266
+ Math.hypot(x - centre[0], z - centre[1]),
267
+ mask.radius,
268
+ mask.falloff ?? 0.6
269
+ );
270
+ }
271
+ case "rectangle": {
272
+ const centre = mask.at;
273
+ const rad = (mask.rotation ?? 0) * Math.PI / 180;
274
+ const c = Math.cos(rad);
275
+ const sn = Math.sin(rad);
276
+ const size = Array.isArray(mask.size) ? mask.size : [mask.size, mask.size];
277
+ return (i, x, z) => {
278
+ const dx = x - centre[0];
279
+ const dz = z - centre[1];
280
+ return falloff(
281
+ Math.max(
282
+ Math.abs(dx * c + dz * sn) / (size[0] / 2),
283
+ Math.abs(-dx * sn + dz * c) / (size[1] / 2)
284
+ ),
285
+ 1,
286
+ mask.falloff ?? 0.2
287
+ );
288
+ };
289
+ }
290
+ case "height":
291
+ return (i) => range(s.height[i], mask.min ?? -1e9, mask.max ?? 1e9, mask.fade);
292
+ case "slope":
293
+ return (i) => range(slopeAtIndex(s, i), mask.min ?? 0, mask.max ?? 90, mask.fade);
294
+ case "noise":
295
+ return (i, x, z) => smoothstep(
296
+ (mask.threshold ?? 0.5) - (mask.fade ?? 0.15),
297
+ (mask.threshold ?? 0.5) + (mask.fade ?? 0.15),
298
+ noise2(x / mask.scale, z / mask.scale, mask.seed ?? s.seed) * 0.5 + 0.5
299
+ );
300
+ case "biome": {
301
+ const field = s.biomes[mask.name];
302
+ return (i) => field?.[i] ?? 0;
303
+ }
304
+ case "material": {
305
+ const channel = MATERIAL_IDS.indexOf(mask.name);
306
+ if (channel < 0) throw Error(`Unknown material: ${String(mask.name)}`);
307
+ return (i) => s.splat[i * 8 + channel];
308
+ }
309
+ case "not": {
310
+ const inner = compileMask(mask.mask, s);
311
+ return (i, x, z) => 1 - inner(i, x, z);
312
+ }
313
+ case "and": {
314
+ const inner = (mask.masks ?? []).map((entry2) => compileMask(entry2, s));
315
+ return (i, x, z) => inner.reduce((value, sample) => value * sample(i, x, z), 1);
316
+ }
317
+ case "or": {
318
+ const inner = (mask.masks ?? []).map((entry2) => compileMask(entry2, s));
319
+ return (i, x, z) => 1 - inner.reduce((value, sample) => value * (1 - sample(i, x, z)), 1);
320
+ }
321
+ default:
322
+ throw Error(`Unknown mask: ${String(mask.type)}`);
323
+ }
324
+ }
325
+ function rasterMask(mask, s) {
326
+ if (!mask || mask.type === "all") return null;
327
+ const out = new Float32Array(s.height.length);
328
+ const sample = compileMask(mask, s);
329
+ for (let z = 0; z < s.resolution; z += 1) {
330
+ for (let x = 0; x < s.resolution; x += 1) {
331
+ const i = z * s.resolution + x;
332
+ out[i] = clamp(sample(i, world(s, x), world(s, z)));
333
+ }
334
+ }
335
+ return out;
336
+ }
337
+ function paintWeights(s, i, channel, weight) {
338
+ const w = clamp(weight);
339
+ const base = i * 8;
340
+ for (let c = 0; c < 8; c += 1)
341
+ s.splat[base + c] = s.splat[base + c] * (1 - w) + (c === channel ? w : 0);
342
+ }
343
+
293
344
  // src/core/erosion.ts
294
345
  function thermal(height, n, size, { iterations = 20, talus = 32, rate = 0.22 } = {}, observations) {
295
346
  if (!Number.isInteger(n) || n < 2)
@@ -916,104 +967,6 @@ function gully(height, n, size, { iterations = 200, capacity = 0.05, rain = 5e-4
916
967
  return Float32Array.from(h, (surface, i) => surface + sediment[i]);
917
968
  }
918
969
 
919
- // src/core/masks.ts
920
- var MATERIAL_IDS = Object.freeze([
921
- "grass",
922
- "dirt",
923
- "rock",
924
- "snow",
925
- "sand",
926
- "mud",
927
- "road",
928
- "moss"
929
- ]);
930
- var range = (v, min, max, fade = 0) => fade > 0 ? smoothstep(min - fade, min, v) * (1 - smoothstep(max, max + fade, v)) : Number(v >= min && v <= max);
931
- function compileMask(mask, s) {
932
- if (!mask || mask.type === "all") return () => 1;
933
- switch (mask.type) {
934
- case "none":
935
- return () => 0;
936
- case "circle": {
937
- const centre = mask.at;
938
- return (i, x, z) => falloff(
939
- Math.hypot(x - centre[0], z - centre[1]),
940
- mask.radius,
941
- mask.falloff ?? 0.6
942
- );
943
- }
944
- case "rectangle": {
945
- const centre = mask.at;
946
- const rad = (mask.rotation ?? 0) * Math.PI / 180;
947
- const c = Math.cos(rad);
948
- const sn = Math.sin(rad);
949
- const size = Array.isArray(mask.size) ? mask.size : [mask.size, mask.size];
950
- return (i, x, z) => {
951
- const dx = x - centre[0];
952
- const dz = z - centre[1];
953
- return falloff(
954
- Math.max(
955
- Math.abs(dx * c + dz * sn) / (size[0] / 2),
956
- Math.abs(-dx * sn + dz * c) / (size[1] / 2)
957
- ),
958
- 1,
959
- mask.falloff ?? 0.2
960
- );
961
- };
962
- }
963
- case "height":
964
- return (i) => range(s.height[i], mask.min ?? -1e9, mask.max ?? 1e9, mask.fade);
965
- case "slope":
966
- return (i) => range(slopeAtIndex(s, i), mask.min ?? 0, mask.max ?? 90, mask.fade);
967
- case "noise":
968
- return (i, x, z) => smoothstep(
969
- (mask.threshold ?? 0.5) - (mask.fade ?? 0.15),
970
- (mask.threshold ?? 0.5) + (mask.fade ?? 0.15),
971
- noise2(x / mask.scale, z / mask.scale, mask.seed ?? s.seed) * 0.5 + 0.5
972
- );
973
- case "biome": {
974
- const field = s.biomes[mask.name];
975
- return (i) => field?.[i] ?? 0;
976
- }
977
- case "material": {
978
- const channel = MATERIAL_IDS.indexOf(mask.name);
979
- if (channel < 0) throw Error(`Unknown material: ${String(mask.name)}`);
980
- return (i) => s.splat[i * 8 + channel];
981
- }
982
- case "not": {
983
- const inner = compileMask(mask.mask, s);
984
- return (i, x, z) => 1 - inner(i, x, z);
985
- }
986
- case "and": {
987
- const inner = (mask.masks ?? []).map((entry2) => compileMask(entry2, s));
988
- return (i, x, z) => inner.reduce((value, sample) => value * sample(i, x, z), 1);
989
- }
990
- case "or": {
991
- const inner = (mask.masks ?? []).map((entry2) => compileMask(entry2, s));
992
- return (i, x, z) => 1 - inner.reduce((value, sample) => value * (1 - sample(i, x, z)), 1);
993
- }
994
- default:
995
- throw Error(`Unknown mask: ${String(mask.type)}`);
996
- }
997
- }
998
- function rasterMask(mask, s) {
999
- if (!mask || mask.type === "all") return null;
1000
- const out = new Float32Array(s.height.length);
1001
- const sample = compileMask(mask, s);
1002
- for (let z = 0; z < s.resolution; z += 1) {
1003
- for (let x = 0; x < s.resolution; x += 1) {
1004
- const i = z * s.resolution + x;
1005
- out[i] = clamp(sample(i, world(s, x), world(s, z)));
1006
- }
1007
- }
1008
- return out;
1009
- }
1010
- function paintWeights(s, i, channel, weight) {
1011
- const w = clamp(weight);
1012
- const base = i * 8;
1013
- for (let c = 0; c < 8; c += 1)
1014
- s.splat[base + c] = s.splat[base + c] * (1 - w) + (c === channel ? w : 0);
1015
- }
1016
-
1017
970
  // src/core/scree.ts
1018
971
  var NEIGHBOURS = [
1019
972
  [-1, -1],
@@ -2635,7 +2588,7 @@ var Terrain = class _Terrain {
2635
2588
  }
2636
2589
  };
2637
2590
 
2638
- // src/core/presets.ts
2591
+ // src/ground/presets.ts
2639
2592
  var LANDFORMS = {
2640
2593
  alpine: {
2641
2594
  summary: "Glacier-cut granite peaks: steep headwalls, sharp ar\xEAtes, dendritic gullies.",
@@ -2679,7 +2632,7 @@ var LANDFORMS = {
2679
2632
  }
2680
2633
  };
2681
2634
 
2682
- // src/core/biome.ts
2635
+ // src/biome/biome.ts
2683
2636
  var SPEC_FIELDS = [
2684
2637
  "look",
2685
2638
  "bake",
@@ -2728,8 +2681,11 @@ var FOLIAGE_FIELDS = [
2728
2681
  "stands",
2729
2682
  "grassThreshold",
2730
2683
  "standThreshold",
2731
- "far"
2684
+ "far",
2685
+ "scale",
2686
+ "mask"
2732
2687
  ];
2688
+ var FOLIAGE_REQUIRED = FOLIAGE_FIELDS.filter((name) => name !== "scale" && name !== "mask");
2733
2689
  var FAR_FIELDS = [
2734
2690
  "cell",
2735
2691
  "spacing",
@@ -2927,7 +2883,7 @@ function cover(value, biome) {
2927
2883
  };
2928
2884
  }
2929
2885
  function foliage(value, biome, field) {
2930
- const row = closed(value, biome, field, FOLIAGE_FIELDS);
2886
+ const row = closed(value, biome, field, FOLIAGE_FIELDS, FOLIAGE_REQUIRED);
2931
2887
  const height = row.height === null ? null : pair(row.height, biome, `${field}.height`);
2932
2888
  return {
2933
2889
  species: text(row.species, biome, `${field}.species`),
@@ -2939,9 +2895,19 @@ function foliage(value, biome, field) {
2939
2895
  stands: flag(row.stands, biome, `${field}.stands`),
2940
2896
  grassThreshold: share(row.grassThreshold, biome, `${field}.grassThreshold`),
2941
2897
  standThreshold: share(row.standThreshold, biome, `${field}.standThreshold`),
2942
- far: far(row.far, biome, `${field}.far`)
2898
+ far: far(row.far, biome, `${field}.far`),
2899
+ ...row.scale === void 0 ? {} : { scale: pair(row.scale, biome, `${field}.scale`) },
2900
+ ...row.mask === void 0 ? {} : { mask: standMask(row.mask, biome, `${field}.mask`) }
2943
2901
  };
2944
2902
  }
2903
+ function standMask(value, biome, field) {
2904
+ try {
2905
+ validateMask(value);
2906
+ } catch (error) {
2907
+ fail2(biome, field, error.message);
2908
+ }
2909
+ return value;
2910
+ }
2945
2911
  function grass(value, biome, field) {
2946
2912
  const row = closed(value, biome, field, GRASS_FIELDS);
2947
2913
  const density = count(row.density, biome, `${field}.density`);
@@ -3058,111 +3024,13 @@ function validateBiome(spec, name) {
3058
3024
  };
3059
3025
  }
3060
3026
 
3061
- // src/core/request-words.ts
3062
- var LANDFORM_WORD_ROWS = [
3063
- // First: a volcano is the more specific shape, so "a volcanic island" is a volcano in the sea.
3064
- ["volcanic", ["volcano", "volcanoes", "volcanic"]],
3065
- ["alpine", ["alpine", "alps", "mountain", "mountains", "peaks"]],
3066
- ["temperateMountains", ["foothills", "valley", "valleys"]],
3067
- ["rollingHills", ["hill", "hills", "rolling"]],
3068
- ["desertMesa", ["butte", "buttes", "canyon", "canyons", "mesa", "mesas"]],
3069
- [
3070
- "coastalCliffs",
3071
- ["cliff", "cliffs", "coast", "coastal", "fjord", "fjords", "island", "islands"]
3072
- ],
3073
- ["tundra", ["arctic", "tundra"]]
3074
- ];
3075
- var WATER_WORD_ROWS = [
3076
- [{ kind: "river", width: 5.32 }, ["creek", "creeks", "river", "rivers", "stream", "streams"]],
3077
- [{ kind: "lake", radius: 105 }, ["lake", "lakes", "pond", "ponds"]],
3078
- [
3079
- { kind: "ocean", level: 1.5 },
3080
- ["fjord", "fjords", "island", "islands", "ocean", "oceans", "sea", "seas"]
3081
- ]
3082
- ];
3083
- var LANDFORM_BIOME = {
3084
- alpine: "alpine",
3085
- temperateMountains: "forest",
3086
- rollingHills: "forest",
3087
- desertMesa: "desert",
3088
- coastalCliffs: "coastal",
3089
- tundra: "tundra",
3090
- volcanic: "alpine"
3091
- };
3092
- var DEFAULT_BIOME = "forest";
3093
- var FEATURE_WORD_ROWS = [
3094
- ["canyon", ["canyon", "canyons", "gorge", "gorges", "ravine", "ravines"]],
3095
- ["fjord", ["fjord", "fjords", "inlet", "inlets"]]
3096
- ];
3097
- var SIZE_WORD_ROWS = [
3098
- [2, ["big", "huge", "large"]],
3099
- [0.5, ["small", "tiny"]]
3100
- ];
3101
- var BIOME_OWN = {
3102
- alpine: { landform: "alpine", sizeMeters: 512, water: [] },
3103
- coastal: { landform: "coastalCliffs", sizeMeters: 512, water: [{ kind: "ocean", level: 1.5 }] },
3104
- desert: { landform: "desertMesa", sizeMeters: 512, water: [] },
3105
- forest: {
3106
- landform: "temperateMountains",
3107
- sizeMeters: 512,
3108
- water: [
3109
- { kind: "river", width: 5.32 },
3110
- { kind: "lake", radius: 105 }
3111
- ]
3112
- },
3113
- tundra: {
3114
- landform: "tundra",
3115
- sizeMeters: 512,
3116
- water: [
3117
- { kind: "river", width: 5.32 },
3118
- { kind: "river", width: 3.04 },
3119
- { kind: "lake", radius: 34 },
3120
- { kind: "lake", radius: 46 }
3121
- ]
3122
- }
3123
- };
3124
- var REQUEST_STOP_WORDS = /* @__PURE__ */ new Set([
3125
- "a",
3126
- "an",
3127
- "and",
3128
- "create",
3129
- "for",
3130
- "game",
3131
- "in",
3132
- "like",
3133
- "make",
3134
- "me",
3135
- "of",
3136
- "on",
3137
- "some",
3138
- "terrain",
3139
- "the",
3140
- "with",
3141
- "world"
3142
- ]);
3143
- var BACKDROP_WORDS = [
3144
- "under",
3145
- "below",
3146
- "beneath",
3147
- "behind",
3148
- "among",
3149
- "beside"
3150
- ];
3151
- var REQUEST_KNOWN_WORDS = /* @__PURE__ */ new Set([
3152
- ...[
3153
- ...BIOME_WORD_ROWS,
3154
- ...LANDFORM_WORD_ROWS,
3155
- ...WATER_WORD_ROWS,
3156
- ...SIZE_WORD_ROWS,
3157
- ...FEATURE_WORD_ROWS
3158
- ].flatMap(([, names]) => names),
3159
- ...BACKDROP_WORDS
3160
- ]);
3027
+ // src/biome/kits.ts
3028
+ var TERRAIN_KITS = ["forest", "coastal", "alpine", "desert", "tundra"];
3161
3029
 
3162
- // src/core/surveys.ts
3163
- var TILES = "AWS Terrain Tiles (github.com/tilezen/joerd, Mapzen terrain tiles).";
3164
- var USGS_3DEP = "United States 3DEP (formerly NED) terrain data courtesy of the U.S. Geological Survey.";
3165
- var SRTM = "SRTM data courtesy of the U.S. Geological Survey.";
3030
+ // src/ground/surveys.ts
3031
+ var TILES = "Terrain tiles \xA9 Mapterhorn (https://mapterhorn.com/attribution), built from open elevation data; the producers and licences of its sources are listed there.";
3032
+ var USGS_3DEP = "United States 3DEP terrain data, U.S. Geological Survey (public domain, U.S. Government work).";
3033
+ var COPERNICUS = "Copernicus GLO-30 DEM, \xA9 DLR e.V. 2010-2014 and \xA9 Airbus Defence and Space GmbH 2014-2018, provided under COPERNICUS by the European Union and ESA; all rights reserved.";
3166
3034
  var MASSIFS = {
3167
3035
  temperateMountains: [
3168
3036
  {
@@ -3170,7 +3038,6 @@ var MASSIFS = {
3170
3038
  lat: 40.2549,
3171
3039
  lon: -105.6101,
3172
3040
  extentMeters: 4400,
3173
- zoom: 12,
3174
3041
  attribution: `${USGS_3DEP} ${TILES}`
3175
3042
  }
3176
3043
  ],
@@ -3180,7 +3047,6 @@ var MASSIFS = {
3180
3047
  lat: 43.7455,
3181
3048
  lon: -110.8024,
3182
3049
  extentMeters: 3600,
3183
- zoom: 12,
3184
3050
  attribution: `${USGS_3DEP} ${TILES}`
3185
3051
  },
3186
3052
  {
@@ -3188,13 +3054,11 @@ var MASSIFS = {
3188
3054
  lat: 39.0708,
3189
3055
  lon: -106.989,
3190
3056
  extentMeters: 3600,
3191
- zoom: 12,
3192
3057
  attribution: `${USGS_3DEP} ${TILES}`
3193
3058
  }
3194
3059
  ]
3195
3060
  };
3196
3061
  var LOCATION_EXTENT_METERS = 6e3;
3197
- var LOCATION_ZOOM = 12;
3198
3062
  var finite = (value, axis) => {
3199
3063
  if (!Number.isFinite(value))
3200
3064
  throw new TypeError(`ground.location.${axis} must be a finite number.`);
@@ -3212,141 +3076,396 @@ function locationSurvey(lat, lon) {
3212
3076
  lat: latitude,
3213
3077
  lon: longitude,
3214
3078
  extentMeters: LOCATION_EXTENT_METERS,
3215
- zoom: LOCATION_ZOOM,
3216
- attribution: `${SRTM} ${TILES}`
3079
+ attribution: `${COPERNICUS} ${TILES}`
3217
3080
  };
3218
3081
  }
3082
+ function isRecord(value) {
3083
+ return typeof value === "object" && value !== null && !Array.isArray(value);
3084
+ }
3085
+ function closedRecord(input, tool, fields) {
3086
+ if (!isRecord(input)) throw new TypeError(`${tool}: arguments must be an object.`);
3087
+ for (const key of Object.keys(input)) {
3088
+ if (!fields.includes(key)) throw new TypeError(`${tool}: unknown field '${key}'.`);
3089
+ }
3090
+ return input;
3091
+ }
3092
+ function relativeDirectory(out) {
3093
+ if (typeof out !== "string" || out.trim() === "" || isAbsolute(out) || out.split(/[\\/]/).includes("..")) {
3094
+ throw new TypeError("terrain_generate: out must be a relative directory inside the project.");
3095
+ }
3096
+ return out;
3097
+ }
3098
+ function parseGround(value, tool) {
3099
+ if (value === void 0) return void 0;
3100
+ if (value === "procedural") return "procedural";
3101
+ const forms = `${tool}: ground must be "procedural", { heightmap } or { location }.`;
3102
+ if (!isRecord(value)) throw new TypeError(forms);
3103
+ for (const key of Object.keys(value)) {
3104
+ if (!["heightmap", "location", "min", "max"].includes(key)) {
3105
+ throw new TypeError(`${tool}: ground field '${key}' is not a ground source.`);
3106
+ }
3107
+ }
3108
+ const { heightmap, location, min, max } = value;
3109
+ if (heightmap !== void 0) {
3110
+ if (typeof heightmap !== "string" || !/\.(png|r16)$/iu.test(heightmap)) {
3111
+ throw new TypeError(`${tool}: ground.heightmap must name a .png or .r16 file.`);
3112
+ }
3113
+ if (min === void 0 !== (max === void 0)) {
3114
+ throw new TypeError(`${tool}: ground.heightmap needs min and max together, in metres.`);
3115
+ }
3116
+ if (min !== void 0 && max !== void 0) {
3117
+ if (typeof min !== "number" || typeof max !== "number" || !Number.isFinite(min) || !Number.isFinite(max))
3118
+ throw new TypeError(`${tool}: ground.heightmap min and max must be finite metres.`);
3119
+ if (max <= min) throw new TypeError(`${tool}: ground.heightmap max must exceed min.`);
3120
+ return { heightmap, min, max };
3121
+ }
3122
+ return { heightmap };
3123
+ }
3124
+ if (location !== void 0) {
3125
+ if (!isRecord(location) || Object.keys(location).some((key) => !["lat", "lon"].includes(key))) {
3126
+ throw new TypeError(`${tool}: ground.location must be { lat, lon }.`);
3127
+ }
3128
+ const { lat, lon } = location;
3129
+ if (typeof lat !== "number" || typeof lon !== "number") {
3130
+ throw new TypeError(`${tool}: ground.location lat and lon must be numbers.`);
3131
+ }
3132
+ locationSurvey(lat, lon);
3133
+ return { location: { lat, lon } };
3134
+ }
3135
+ throw new TypeError(forms);
3136
+ }
3219
3137
 
3220
- // src/mcp/tools.ts
3221
- var PATCH_OPS = ["upsert", "update", "remove", "move", "toggle"];
3222
- var GROUND_SCHEMA = {
3223
- description: 'Where the ground comes from. "procedural" keeps the landform preset\'s own noise; { heightmap } names a 16-bit grayscale PNG or a square .r16 file (min and max in metres, needed when the file carries no range); { location } cuts a survey at that latitude and longitude. Omitted, a landform preset is grounded on the real survey its kind names, and the result reports it as `ground` with its attribution.',
3224
- anyOf: [
3225
- { type: "string", enum: ["procedural"] },
3226
- {
3227
- type: "object",
3228
- properties: {
3229
- heightmap: {
3230
- type: "string",
3231
- description: "Path to a .png or .r16 height file, relative to the project."
3232
- },
3233
- min: { type: "number", description: "Lowest elevation in the file, metres." },
3234
- max: { type: "number", description: "Highest elevation in the file, metres." }
3235
- },
3236
- required: ["heightmap"],
3237
- additionalProperties: false
3138
+ // src/request/biome-words.ts
3139
+ var BIOME_WORDS = {
3140
+ alpine: [
3141
+ "alpine",
3142
+ "mountain",
3143
+ "mountains",
3144
+ "snowy",
3145
+ "peaks",
3146
+ "alps",
3147
+ "glacier",
3148
+ "glaciers",
3149
+ "snow"
3150
+ ],
3151
+ coastal: [
3152
+ "coastal",
3153
+ "beach",
3154
+ "coast",
3155
+ "sea",
3156
+ "ocean",
3157
+ "tropical",
3158
+ "shore",
3159
+ "lagoon",
3160
+ "fjord",
3161
+ "fjords"
3162
+ ],
3163
+ desert: ["desert", "dune", "dunes", "sand", "canyon", "canyons", "arid", "badlands", "mesa"],
3164
+ forest: [
3165
+ "forest",
3166
+ "pine",
3167
+ "pines",
3168
+ "woods",
3169
+ "woodland",
3170
+ "spruce",
3171
+ "fir",
3172
+ "trees",
3173
+ "jungle",
3174
+ "rainforest",
3175
+ "grove"
3176
+ ],
3177
+ tundra: ["tundra", "arctic", "ice", "frozen", "permafrost", "glacial"]
3178
+ };
3179
+ var BIOME_WORD_ROWS = TERRAIN_KITS.map((kit) => [kit, BIOME_WORDS[kit]]);
3180
+ function biomeWordList() {
3181
+ return BIOME_WORD_ROWS.map(([kit, words]) => `${kit} (${words.slice(1).join(", ")})`).join("; ");
3182
+ }
3183
+
3184
+ // src/request/ecoregions.ts
3185
+ var FAR = {
3186
+ cell: 6,
3187
+ spacing: [6.5, 13],
3188
+ spacingAt: [150, 1500],
3189
+ slope: [36, 46],
3190
+ meadowSlope: [12, 24],
3191
+ reach: 2300,
3192
+ treelineJitter: 30,
3193
+ stand: [0.26, 0.4],
3194
+ impostor: 110
3195
+ };
3196
+ var CLEARINGS = { type: "noise", scale: 90, threshold: 0.4, seed: 466600, fade: 0.06 };
3197
+ function canopyRow(species2, density, farSeed, scale = [0.55, 1], mask = {
3198
+ type: "and",
3199
+ masks: [CLEARINGS, { type: "noise", scale: 120, threshold: 0.44, seed: farSeed, fade: 0.24 }]
3200
+ }) {
3201
+ return {
3202
+ species: species2,
3203
+ density,
3204
+ slope: [0, 32],
3205
+ height: null,
3206
+ spacing: [3.2, 6.4],
3207
+ collision: "trunk",
3208
+ stands: true,
3209
+ grassThreshold: 0.3,
3210
+ standThreshold: 0.16,
3211
+ far: { ...FAR, seed: farSeed },
3212
+ scale,
3213
+ mask
3214
+ };
3215
+ }
3216
+ var ECOREGION_ROWS = [
3217
+ {
3218
+ id: "european-broadleaf",
3219
+ // "beech" alone stays a tree word (`TREE_WORD_ROWS`): only a region word selects this row.
3220
+ words: ["european", "europe"],
3221
+ kit: "forest",
3222
+ site: {
3223
+ name: "Hainich National Park, Thuringia, Germany",
3224
+ lat: 51.0833,
3225
+ lon: 10.4667,
3226
+ extentMeters: 3e3,
3227
+ attribution: `${COPERNICUS} ${TILES}`
3228
+ // measured: 305..483 m over its 3 km, and 380..423 m at the world's own 512 m (a beech wood's
3229
+ // floor: 5.8 degrees at the 90th percentile, no hydro-flattened water)
3238
3230
  },
3239
- {
3240
- type: "object",
3241
- properties: {
3242
- location: {
3243
- type: "object",
3244
- properties: { lat: { type: "number" }, lon: { type: "number" } },
3245
- required: ["lat", "lon"],
3246
- additionalProperties: false
3247
- }
3248
- },
3249
- required: ["location"],
3250
- additionalProperties: false
3231
+ canopy: ["fir", "fir-c"],
3232
+ overrides: {
3233
+ // The European beech forest's own mix: beech dominant, sessile oak and silver birch among it,
3234
+ // each at two seeds so no two trees of a species are the same bake.
3235
+ foliage: [
3236
+ canopyRow("arbor:beech@11", 900, 466611),
3237
+ canopyRow("arbor:beech@12", 900, 466612),
3238
+ canopyRow("arbor:oak@13", 650, 466613),
3239
+ canopyRow("arbor:oak@14", 650, 466614),
3240
+ canopyRow("arbor:birch@15", 450, 466615),
3241
+ canopyRow("arbor:birch@16", 450, 466616),
3242
+ // Beech regeneration: the young beech a closed beech wood grows in its own light gaps, so the
3243
+ // clearings fill with saplings (the kit's `firs-young` band, at the same scale).
3244
+ canopyRow("arbor:beech@20", 700, 466620, [0.2, 0.45], { type: "not", mask: CLEARINGS })
3245
+ ]
3251
3246
  }
3252
- ]
3253
- };
3254
- var TERRAIN_TOOLS = [
3247
+ },
3255
3248
  {
3256
- name: "terrain_generate",
3257
- description: "Choose from a request, an explicit kit or a biome and cook one editable starter terrain kit (forest, coastal, alpine, desert or tundra) into a world.glb; `biome` names a starter or one of its alias words, or carries an inline IBiomeSpec whose own landform, size and seed build the ground; `landform` swaps the ground for one of the seven shape presets (alpine, temperateMountains, rollingHills, desertMesa, coastalCliffs, tundra, volcanic) and keeps the kit's surface and assets; `water` replaces the water bodies the biome declares and changes the cooked world: an ocean row floods to its level, a river or lake row re-shapes the recipe's own river or lake in order (width or radius), a recipe layer with no row is removed, and a river or lake row with no layer to take it fails. A `request`'s words also decide the landform (mountains, hills, mesa, cliffs, volcano), the water (river, lake, island, ocean), the features carved into any ground (canyon, gorge, ravine: a steep cut across it; fjord, inlet: a sea inlet into the land) and the size (huge, small: the biome's own size scaled); an explicit `landform`, `water` or `sizeMeters` wins over a word. A landform preset's ground is a real survey of the place its kind names, fetched from the AWS terrain tiles, resampled onto the recipe's grid, cooked with the attribution its source requires, and reported as `ground`; the preset's erosion and grain still run on top of it. `ground` replaces that choice: \"procedural\" cooks the preset's own noise, { heightmap } reads a 16-bit grayscale PNG or a square .r16 grid, { location } cuts a survey at a latitude and longitude. An alpine or temperateMountains world on a survey also writes ring.json, its survey continued to ten times the world's size with one real whole mountain from that range past the square, reported as `backdrop`; `backdrop: \"none\"` cooks none. The result's `decided` names each choice with the word behind it or `argument`, and `unused` lists the request words that named nothing. A request that names only a starter (no shape, water, feature, size, seed or ground of its own) is that starter as shipped, judged and measured, reported as `source: \"catalog:<kit>\"`; anything else is `\"cooked\"`. The reply's `seed` is the seed the world was cooked with: pass another `seed` for a variation of the same request. A request repeated in the same project is copied from its cook cache (`node_modules/.cache/threenative-terrain`) and reported as `cache: \"hit\"`. Returns the kit as recipe, the biome it bakes, the water bodies the cooked world floods, measured from the evaluated state as `water.json` records them, its band rows resolved against the cooked heights (`bands`), the world.glb, recipe.json and world.json paths, triangles, instances and draws measured from the produced GLB's default scene, and a ctx.assets.model load snippet. triangles counts every instance of the LOD0 default scene in full, before distance LOD and culling, instances sums the EXT_mesh_gpu_instancing instances, and draws counts primitives across instanced and non-instanced meshes, an instanced primitive counting once.",
3258
- inputSchema: {
3259
- type: "object",
3260
- properties: {
3261
- kit: { type: "string", enum: [...TERRAIN_KITS] },
3262
- biome: {
3263
- description: "A starter biome's name or alias word (forest, woods, beach, ...), or an inline IBiomeSpec object; a spec cooks with `kit`'s surface and assets, forest's when kit is absent.",
3264
- anyOf: [{ type: "string", minLength: 1 }, { type: "object" }]
3265
- },
3266
- landform: { type: "string", enum: Object.keys(LANDFORMS) },
3267
- request: {
3268
- type: "string",
3269
- minLength: 1,
3270
- description: "What the world should be, in any words: a biome, a landform (mountains, hills, canyon, volcano, fjord, ...), water (river, lake, sea, ...) and a size (huge, small); an explicit argument wins over a word. A request with no biome word takes the biome its sea or shape suits, else the forest; `decided` names the word behind each choice and `unused` the words that named nothing. A real place's name is not geocoded: pass its latitude and longitude as `ground: { location }` to cook that place's survey."
3271
- },
3272
- sizeMeters: { type: "number", exclusiveMinimum: 0 },
3273
- seed: { type: "integer" },
3274
- water: {
3275
- type: "array",
3276
- items: { type: "object" },
3277
- description: "IBiomeWaterBody rows that replace the biome's declared water: river (width), lake (radius), ocean (level)."
3278
- },
3279
- ground: GROUND_SCHEMA,
3280
- backdrop: {
3281
- type: "string",
3282
- enum: ["none"],
3283
- description: `"none" cooks no far ring. Omitted, an alpine or temperateMountains world on a survey gets ring.json: its survey continued to ten times the world's size, with one real whole mountain (a seeded pick, pose and height) standing past the playable square.`
3284
- },
3285
- out: {
3286
- type: "string",
3287
- description: "Relative directory under the project's assets.source that must not exist yet; the default is assets.source/worlds/<kit>."
3288
- }
3289
- },
3290
- anyOf: [{ required: ["request"] }, { required: ["kit"] }, { required: ["biome"] }],
3291
- additionalProperties: false
3249
+ id: "boreal",
3250
+ words: ["boreal", "taiga", "nordic", "scandinavian"],
3251
+ kit: "forest",
3252
+ site: {
3253
+ name: "Oulanka National Park, Kuusamo, Finland",
3254
+ lat: 66.36221,
3255
+ lon: 29.3167,
3256
+ extentMeters: 3e3,
3257
+ attribution: `${COPERNICUS} ${TILES}`
3258
+ // measured: 144..325 m over its 3 km, and 177..253 m at 512 m (a spruce stand: 15.4 degrees at
3259
+ // the 90th percentile, 0.6 % hydro-flattened water). Moved 500 m south of the old centre
3260
+ // (66.3667, 29.3167), whose 512 m crop was 8.5 % flattened river and lake water on Mapterhorn data.
3261
+ },
3262
+ canopy: ["fir", "fir-c"],
3263
+ overrides: {
3264
+ // The boreal mix of the kit's own stand: Norway spruce with downy birch and aspen, two bakes each.
3265
+ foliage: [
3266
+ canopyRow("arbor:spruce@21", 1e3, 466621),
3267
+ canopyRow("arbor:spruce@22", 1e3, 466622),
3268
+ canopyRow("arbor:birch@23", 600, 466623),
3269
+ canopyRow("arbor:birch@24", 600, 466624),
3270
+ canopyRow("arbor:aspen@25", 400, 466625),
3271
+ canopyRow("arbor:aspen@26", 400, 466626)
3272
+ ]
3292
3273
  }
3293
3274
  },
3294
3275
  {
3295
- name: "terrain_biome_new",
3296
- description: "Make a new biome from a shipped one and cook it: copies the base biome's biome.data.json into <assets.source>/biomes/<name>/, applies the overrides, validates the file with validateBiome, then cooks it with the base kit's surface and assets and the biome's own landform preset. One call writes only under <assets.source>/biomes/<name>/, its cooked world included. Its ground comes from the biome's landform, the real survey that kind names unless `ground` names another source. Returns the same cook result as terrain_generate plus the biome file path and the biome's resolved `bands`. No code changes anywhere: the biome is data.",
3297
- inputSchema: {
3298
- type: "object",
3299
- properties: {
3300
- from: { type: "string", enum: [...TERRAIN_KITS] },
3301
- name: {
3302
- type: "string",
3303
- pattern: "^[a-z][a-z0-9-]{0,31}$",
3304
- description: "The new biome's folder and look name; lowercase, no spaces."
3305
- },
3306
- overrides: {
3307
- type: "object",
3308
- description: "IBiomeSpec fields to change on the base file (landform, foliage, grass, layers, water, spawn, species, aliases, bake). An unknown field fails."
3309
- },
3310
- ground: GROUND_SCHEMA,
3311
- out: {
3312
- type: "string",
3313
- description: "Relative directory under the project's assets.source that must not exist yet; the default is assets.source/biomes/<name>/world."
3314
- }
3315
- },
3316
- required: ["from", "name"],
3317
- additionalProperties: false
3276
+ id: "mediterranean",
3277
+ words: ["mediterranean", "tuscan"],
3278
+ kit: "desert",
3279
+ site: {
3280
+ name: "Val d'Orcia, Tuscany, Italy",
3281
+ lat: 43.0667,
3282
+ lon: 11.6167,
3283
+ extentMeters: 3e3,
3284
+ attribution: `${COPERNICUS} ${TILES}`
3285
+ // measured: 276..436 m over its 3 km, and 328..403 m at 512 m (a clay hillside with its olive
3286
+ // and cypress: 17.6 degrees at the 90th percentile)
3287
+ },
3288
+ // The desert kit ships no tree art of its own, so there is no authored canopy to replace.
3289
+ canopy: [],
3290
+ overrides: {
3291
+ // The Mediterranean hill's own three: olive, Italian cypress and downy oak, two bakes each.
3292
+ foliage: [
3293
+ canopyRow("arbor:olive@31", 500, 466631),
3294
+ canopyRow("arbor:olive@32", 500, 466632),
3295
+ canopyRow("arbor:cypress@33", 350, 466633),
3296
+ canopyRow("arbor:cypress@34", 350, 466634),
3297
+ canopyRow("arbor:oak@35", 300, 466635),
3298
+ canopyRow("arbor:oak@36", 300, 466636)
3299
+ ]
3300
+ }
3301
+ },
3302
+ {
3303
+ id: "pacific-northwest",
3304
+ // Two words, matched as the phrase a request writes them in; "pacific" and "northwest" alone
3305
+ // name nothing, so "a pacific island" stays the coastal world it is.
3306
+ words: ["pacific northwest", "cascadia"],
3307
+ kit: "forest",
3308
+ site: {
3309
+ name: "Humptulips valley, Olympic National Forest, Washington",
3310
+ lat: 47.19775,
3311
+ lon: -123.88678,
3312
+ extentMeters: 3e3,
3313
+ attribution: `${USGS_3DEP} ${TILES}`
3314
+ // measured: 52..212 m over its 3 km, and 96..163 m at 512 m (a Douglas-fir valley floor: 25.9
3315
+ // degrees at the 90th percentile, under the 28 the floor accepts). Moved 1 km north-east of the
3316
+ // old centre (47.2, -123.9), whose 512 m crop read 31.0 degrees on Mapterhorn's lidar.
3317
+ },
3318
+ canopy: ["fir", "fir-c"],
3319
+ overrides: {
3320
+ // The coastal rainforest's own three: Douglas-fir, western redcedar and bigleaf maple.
3321
+ foliage: [
3322
+ canopyRow("arbor:douglasfir@41", 900, 466641),
3323
+ canopyRow("arbor:douglasfir@42", 900, 466642),
3324
+ canopyRow("arbor:redcedar@43", 550, 466643),
3325
+ canopyRow("arbor:redcedar@44", 550, 466644),
3326
+ canopyRow("arbor:bigleafmaple@45", 350, 466645),
3327
+ canopyRow("arbor:bigleafmaple@46", 350, 466646)
3328
+ ]
3318
3329
  }
3330
+ }
3331
+ ];
3332
+ var ECOREGION_WORDS = ECOREGION_ROWS.flatMap(
3333
+ (row) => row.words.flatMap((word) => word.split(" "))
3334
+ );
3335
+
3336
+ // src/request/request-words.ts
3337
+ var LANDFORM_WORD_ROWS = [
3338
+ // First: a volcano is the more specific shape, so "a volcanic island" is a volcano in the sea.
3339
+ ["volcanic", ["volcano", "volcanoes", "volcanic"]],
3340
+ ["alpine", ["alpine", "alps", "mountain", "mountains", "peaks"]],
3341
+ ["temperateMountains", ["foothills", "valley", "valleys"]],
3342
+ ["rollingHills", ["hill", "hills", "rolling"]],
3343
+ ["desertMesa", ["butte", "buttes", "canyon", "canyons", "mesa", "mesas"]],
3344
+ [
3345
+ "coastalCliffs",
3346
+ ["cliff", "cliffs", "coast", "coastal", "fjord", "fjords", "island", "islands"]
3347
+ ],
3348
+ ["tundra", ["arctic", "tundra"]]
3349
+ ];
3350
+ var WATER_WORD_ROWS = [
3351
+ [{ kind: "river", width: 5.32 }, ["creek", "creeks", "river", "rivers", "stream", "streams"]],
3352
+ [{ kind: "lake", radius: 105 }, ["lake", "lakes", "pond", "ponds"]],
3353
+ [
3354
+ { kind: "ocean", level: 0 },
3355
+ ["fjord", "fjords", "island", "islands", "ocean", "oceans", "sea", "seas"]
3356
+ ]
3357
+ ];
3358
+ var LANDFORM_BIOME = {
3359
+ alpine: "alpine",
3360
+ temperateMountains: "forest",
3361
+ rollingHills: "forest",
3362
+ desertMesa: "desert",
3363
+ coastalCliffs: "coastal",
3364
+ tundra: "tundra",
3365
+ volcanic: "alpine"
3366
+ };
3367
+ var TREE_WORD_ROWS = [
3368
+ ["oak", ["oak", "oaks"]],
3369
+ ["beech", ["beech"]],
3370
+ ["birch", ["birch", "birches"]],
3371
+ ["aspen", ["aspen", "aspens"]],
3372
+ ["redcedar", ["cedar", "cedars"]],
3373
+ ["bigleafmaple", ["maple", "maples"]],
3374
+ ["cypress", ["cypress", "cypresses"]],
3375
+ ["olive", ["olive", "olives"]],
3376
+ ["acacia", ["acacia", "acacias"]],
3377
+ ["baobab", ["baobab", "baobabs"]],
3378
+ ["coconut", ["coconut", "palm", "palms"]],
3379
+ ["banana", ["banana", "bananas"]],
3380
+ ["sakura", ["sakura", "cherry", "blossom"]],
3381
+ ["ginkgo", ["ginkgo"]],
3382
+ ["bamboo", ["bamboo"]],
3383
+ ["saguaro", ["saguaro", "cactus", "cacti"]],
3384
+ ["joshua", ["joshua"]],
3385
+ ["jacaranda", ["jacaranda"]]
3386
+ ];
3387
+ var DEFAULT_BIOME = "forest";
3388
+ var FEATURE_WORD_ROWS = [
3389
+ ["canyon", ["canyon", "canyons", "gorge", "gorges", "ravine", "ravines"]],
3390
+ ["fjord", ["fjord", "fjords", "inlet", "inlets"]]
3391
+ ];
3392
+ var SIZE_WORD_ROWS = [
3393
+ [2, ["big", "huge", "large"]],
3394
+ [0.5, ["small", "tiny"]]
3395
+ ];
3396
+ var BIOME_OWN = {
3397
+ alpine: { landform: "alpine", sizeMeters: 512, water: [] },
3398
+ // The coast stands at its real sea level (0 m, Sand Beach, Acadia) and the survey's flattened
3399
+ // lagoon behind the beach is a lake over a lowered bed, as `starter/coastal/biome.data.json` says.
3400
+ coastal: {
3401
+ landform: "coastalCliffs",
3402
+ sizeMeters: 512,
3403
+ water: [
3404
+ { kind: "ocean", level: 0 },
3405
+ { kind: "lake", radius: 150 }
3406
+ ]
3319
3407
  },
3320
- {
3321
- name: "terrain_patch",
3322
- description: "Apply editor commands (upsert, update, remove, move, toggle) to a terrain recipe and return the edited recipe.",
3323
- inputSchema: {
3324
- type: "object",
3325
- properties: {
3326
- recipe: { type: "object" },
3327
- commands: { type: "array", items: { type: "object" } }
3328
- },
3329
- required: ["recipe", "commands"],
3330
- additionalProperties: false
3331
- }
3408
+ desert: { landform: "desertMesa", sizeMeters: 512, water: [] },
3409
+ forest: {
3410
+ landform: "temperateMountains",
3411
+ sizeMeters: 512,
3412
+ water: [
3413
+ { kind: "river", width: 5.32 },
3414
+ { kind: "lake", radius: 105 }
3415
+ ]
3416
+ },
3417
+ tundra: {
3418
+ landform: "tundra",
3419
+ sizeMeters: 512,
3420
+ water: [
3421
+ { kind: "river", width: 5.32 },
3422
+ { kind: "river", width: 3.04 },
3423
+ { kind: "lake", radius: 34 },
3424
+ { kind: "lake", radius: 46 }
3425
+ ]
3332
3426
  }
3427
+ };
3428
+ var REQUEST_STOP_WORDS = /* @__PURE__ */ new Set([
3429
+ "a",
3430
+ "an",
3431
+ "and",
3432
+ "create",
3433
+ "for",
3434
+ "game",
3435
+ "in",
3436
+ "like",
3437
+ "make",
3438
+ "me",
3439
+ "of",
3440
+ "on",
3441
+ "some",
3442
+ "terrain",
3443
+ "the",
3444
+ "with",
3445
+ "world"
3446
+ ]);
3447
+ var BACKDROP_WORDS = [
3448
+ "under",
3449
+ "below",
3450
+ "beneath",
3451
+ "behind",
3452
+ "among",
3453
+ "beside"
3333
3454
  ];
3334
- function isRecord(value) {
3335
- return typeof value === "object" && value !== null && !Array.isArray(value);
3336
- }
3337
- function closedRecord(input, tool, fields) {
3338
- if (!isRecord(input)) throw new TypeError(`${tool}: arguments must be an object.`);
3339
- for (const key of Object.keys(input)) {
3340
- if (!fields.includes(key)) throw new TypeError(`${tool}: unknown field '${key}'.`);
3341
- }
3342
- return input;
3343
- }
3344
- function relativeDirectory(out) {
3345
- if (typeof out !== "string" || out.trim() === "" || isAbsolute(out) || out.split(/[\\/]/).includes("..")) {
3346
- throw new TypeError("terrain_generate: out must be a relative directory inside the project.");
3347
- }
3348
- return out;
3349
- }
3455
+ var REQUEST_KNOWN_WORDS = /* @__PURE__ */ new Set([
3456
+ ...[
3457
+ ...BIOME_WORD_ROWS,
3458
+ ...LANDFORM_WORD_ROWS,
3459
+ ...WATER_WORD_ROWS,
3460
+ ...SIZE_WORD_ROWS,
3461
+ ...FEATURE_WORD_ROWS,
3462
+ ...TREE_WORD_ROWS
3463
+ ].flatMap(([, names]) => names),
3464
+ ...ECOREGION_WORDS,
3465
+ ...BACKDROP_WORDS
3466
+ ]);
3467
+
3468
+ // src/request/generate-request.ts
3350
3469
  var GENERATE_FIELDS = [
3351
3470
  "request",
3352
3471
  "kit",
@@ -3359,7 +3478,6 @@ var GENERATE_FIELDS = [
3359
3478
  "backdrop",
3360
3479
  "out"
3361
3480
  ];
3362
- var BIOME_NEW_FIELDS = ["from", "name", "overrides", "ground", "out"];
3363
3481
  var LANDFORM_KINDS2 = Object.keys(LANDFORMS);
3364
3482
  function parseBiomeArgument(biome) {
3365
3483
  if (biome === void 0) return {};
@@ -3400,45 +3518,6 @@ function parseWater(water2) {
3400
3518
  }
3401
3519
  return water2;
3402
3520
  }
3403
- function parseGround(value, tool) {
3404
- if (value === void 0) return void 0;
3405
- if (value === "procedural") return "procedural";
3406
- const forms = `${tool}: ground must be "procedural", { heightmap } or { location }.`;
3407
- if (!isRecord(value)) throw new TypeError(forms);
3408
- for (const key of Object.keys(value)) {
3409
- if (!["heightmap", "location", "min", "max"].includes(key)) {
3410
- throw new TypeError(`${tool}: ground field '${key}' is not a ground source.`);
3411
- }
3412
- }
3413
- const { heightmap, location, min, max } = value;
3414
- if (heightmap !== void 0) {
3415
- if (typeof heightmap !== "string" || !/\.(png|r16)$/iu.test(heightmap)) {
3416
- throw new TypeError(`${tool}: ground.heightmap must name a .png or .r16 file.`);
3417
- }
3418
- if (min === void 0 !== (max === void 0)) {
3419
- throw new TypeError(`${tool}: ground.heightmap needs min and max together, in metres.`);
3420
- }
3421
- if (min !== void 0 && max !== void 0) {
3422
- if (typeof min !== "number" || typeof max !== "number" || !Number.isFinite(min) || !Number.isFinite(max))
3423
- throw new TypeError(`${tool}: ground.heightmap min and max must be finite metres.`);
3424
- if (max <= min) throw new TypeError(`${tool}: ground.heightmap max must exceed min.`);
3425
- return { heightmap, min, max };
3426
- }
3427
- return { heightmap };
3428
- }
3429
- if (location !== void 0) {
3430
- if (!isRecord(location) || Object.keys(location).some((key) => !["lat", "lon"].includes(key))) {
3431
- throw new TypeError(`${tool}: ground.location must be { lat, lon }.`);
3432
- }
3433
- const { lat, lon } = location;
3434
- if (typeof lat !== "number" || typeof lon !== "number") {
3435
- throw new TypeError(`${tool}: ground.location lat and lon must be numbers.`);
3436
- }
3437
- locationSurvey(lat, lon);
3438
- return { location: { lat, lon } };
3439
- }
3440
- throw new TypeError(forms);
3441
- }
3442
3521
  function backdropWordAt(words, word) {
3443
3522
  const at = words.indexOf(word);
3444
3523
  const before = words[at - 1] === "the" ? words[at - 2] : words[at - 1];
@@ -3451,6 +3530,28 @@ function rowHit(rows, words) {
3451
3530
  }
3452
3531
  return void 0;
3453
3532
  }
3533
+ function ecoregionHit(words) {
3534
+ const request = ` ${words.join(" ")} `;
3535
+ for (const row of ECOREGION_ROWS) {
3536
+ const word = row.words.find((candidate) => request.includes(` ${candidate} `));
3537
+ if (word !== void 0) return { row, word };
3538
+ }
3539
+ return void 0;
3540
+ }
3541
+ function canopyFirst(overrides, preset) {
3542
+ const foliage2 = overrides.foliage;
3543
+ const first = foliage2?.[0];
3544
+ if (foliage2 === void 0 || first === void 0) return overrides;
3545
+ const is = (row) => row.species.split("@")[0] === `arbor:${preset}`;
3546
+ const named = foliage2.filter(is);
3547
+ return {
3548
+ ...overrides,
3549
+ foliage: [
3550
+ ...named.length > 0 ? named : [{ ...first, species: `arbor:${preset}` }],
3551
+ ...foliage2.filter((row) => !is(row))
3552
+ ]
3553
+ };
3554
+ }
3454
3555
  function declaredWater(rows, row) {
3455
3556
  return rows.some(
3456
3557
  (own) => own.kind === row.kind && own.width === row.width && own.radius === row.radius && own.level === row.level
@@ -3468,6 +3569,7 @@ function parseGenerateRequest(input) {
3468
3569
  const words = typeof request === "string" ? request.toLowerCase().split(/[^a-z]+/u) : [];
3469
3570
  const { kit: biomeKit, spec } = parseBiomeArgument(args.biome);
3470
3571
  const biomeWord = rowHit(BIOME_WORD_ROWS, words);
3572
+ const regionHit = spec === void 0 ? ecoregionHit(words) : void 0;
3471
3573
  const arguedKit = args.kit ?? biomeKit;
3472
3574
  let inferred;
3473
3575
  if (arguedKit === void 0 && spec === void 0 && biomeWord === void 0) {
@@ -3481,7 +3583,7 @@ function parseGenerateRequest(input) {
3481
3583
  inferred = { kit: LANDFORM_BIOME[shape.row], word: shape.word };
3482
3584
  }
3483
3585
  const kit = arguedKit ?? // A spec carries no appearance, so it cooks with the forest starter's surface and assets.
3484
- (spec === void 0 ? biomeWord?.row ?? inferred?.kit ?? DEFAULT_BIOME : "forest");
3586
+ (spec === void 0 ? biomeWord?.row ?? regionHit?.row.kit ?? inferred?.kit ?? DEFAULT_BIOME : "forest");
3485
3587
  if (typeof kit !== "string" || !TERRAIN_KITS.includes(kit)) {
3486
3588
  throw new TypeError(
3487
3589
  `terrain_generate: kit must be one of ${TERRAIN_KITS.join(", ")}. Words a request may use: ${biomeWordList()}.`
@@ -3561,6 +3663,8 @@ function parseGenerateRequest(input) {
3561
3663
  if (groundArgument !== void 0) {
3562
3664
  parsed.ground = groundArgument;
3563
3665
  ground = { value: groundArgument, source: "argument" };
3666
+ } else if (regionHit !== void 0) {
3667
+ ground = { value: "survey", source: { word: regionHit.word } };
3564
3668
  } else {
3565
3669
  ground = { value: presetKind === void 0 ? "starter" : "survey", source: "default" };
3566
3670
  }
@@ -3570,12 +3674,28 @@ function parseGenerateRequest(input) {
3570
3674
  throw new TypeError('terrain_generate: backdrop must be "none" when given.');
3571
3675
  parsed.backdrop = "none";
3572
3676
  backdrop = { value: "none", source: "argument" };
3677
+ } else if (regionHit !== void 0) {
3678
+ parsed.backdrop = "none";
3679
+ backdrop = { value: "none", source: { word: regionHit.word } };
3573
3680
  } else {
3574
3681
  const surveyed = ground.value === "survey" || typeof ground.value === "object" && "location" in ground.value;
3575
3682
  const range2 = parsed.backdropRange ?? presetKind;
3576
3683
  const mountain = range2 !== void 0 && MASSIFS[range2] !== void 0;
3577
3684
  backdrop = { value: surveyed && mountain ? "massif" : "none", source: "default" };
3578
3685
  }
3686
+ const treeWord = spec === void 0 ? rowHit(TREE_WORD_ROWS, words) : void 0;
3687
+ let tree = { value: null, source: "default" };
3688
+ if (treeWord !== void 0) {
3689
+ if (regionHit === void 0) parsed.treeSpecies = `arbor:${treeWord.row}`;
3690
+ tree = { value: `arbor:${treeWord.row}`, source: { word: treeWord.word } };
3691
+ }
3692
+ if (regionHit !== void 0) {
3693
+ const row = regionHit.row;
3694
+ parsed.region = {
3695
+ ...row,
3696
+ overrides: treeWord === void 0 ? row.overrides : canopyFirst(row.overrides, treeWord.row)
3697
+ };
3698
+ }
3579
3699
  if (seed !== void 0) {
3580
3700
  if (typeof seed !== "number" || !Number.isSafeInteger(seed)) {
3581
3701
  throw new TypeError("terrain_generate: seed must be a safe integer.");
@@ -3586,6 +3706,7 @@ function parseGenerateRequest(input) {
3586
3706
  let biomeSource = "default";
3587
3707
  if (arguedKit !== void 0) biomeSource = "argument";
3588
3708
  else if (biomeWord !== void 0) biomeSource = { word: biomeWord.word };
3709
+ else if (regionHit !== void 0) biomeSource = { word: regionHit.word };
3589
3710
  else if (inferred !== void 0) biomeSource = { word: inferred.word };
3590
3711
  return {
3591
3712
  input: parsed,
@@ -3596,7 +3717,9 @@ function parseGenerateRequest(input) {
3596
3717
  sizeMeters: size,
3597
3718
  features,
3598
3719
  ground,
3599
- backdrop
3720
+ backdrop,
3721
+ tree,
3722
+ region: regionHit === void 0 ? { value: null, source: "default" } : { value: regionHit.row.id, source: { word: regionHit.word } }
3600
3723
  },
3601
3724
  // What is left is what the tool could not act on: a retry names a word, not a guess.
3602
3725
  unused: [...new Set(words)].filter(
@@ -3604,6 +3727,154 @@ function parseGenerateRequest(input) {
3604
3727
  )
3605
3728
  };
3606
3729
  }
3730
+ var ARBOR_TREE_IDS = [
3731
+ "oak",
3732
+ "beech",
3733
+ "birch",
3734
+ "spruce",
3735
+ "scotspine",
3736
+ "blackspruce",
3737
+ "aspen",
3738
+ "douglasfir",
3739
+ "redcedar",
3740
+ "bigleafmaple",
3741
+ "cypress",
3742
+ "olive",
3743
+ "stonepine",
3744
+ "acacia",
3745
+ "baobab",
3746
+ "coconut",
3747
+ "banana",
3748
+ "kapok",
3749
+ "sakura",
3750
+ "jmaple",
3751
+ "ginkgo",
3752
+ "bamboo",
3753
+ "saguaro",
3754
+ "joshua",
3755
+ "fanpalm",
3756
+ "araucaria",
3757
+ "ipe",
3758
+ "jacaranda"
3759
+ ];
3760
+
3761
+ // src/mcp/tools.ts
3762
+ var ARBOR_SPECIES_NOTE = `A species named \`arbor:<preset>[@seed]\` (for example arbor:oak@7) is a procedural Arbor tree the cook bakes and scatters; needs npm i -D @threenative/procedural-environment; set the row's far.impostor beyond 190 m, past the tree's last LOD. Presets: ${ARBOR_TREE_IDS.join(", ")}.`;
3763
+ var ECOREGION_NOTE = `A region word (${ECOREGION_ROWS.map((row) => row.words[0]).join(", ")}) cooks that region's own world: the row's real survey as the ground, its plant community as the canopy (several species, each baked at more than one seed), and the starter's own surface, understorey and water, reported as \`decided.region\`.`;
3764
+ var PATCH_OPS = ["upsert", "update", "remove", "move", "toggle"];
3765
+ var GROUND_SCHEMA = {
3766
+ description: 'Where the ground comes from. "procedural" keeps the landform preset\'s own noise; { heightmap } names a 16-bit grayscale PNG or a square .r16 file (min and max in metres, needed when the file carries no range); { location } cuts a survey at that latitude and longitude. Omitted, a landform preset is grounded on the real survey its kind names, and the result reports it as `ground` with its attribution.',
3767
+ anyOf: [
3768
+ { type: "string", enum: ["procedural"] },
3769
+ {
3770
+ type: "object",
3771
+ properties: {
3772
+ heightmap: {
3773
+ type: "string",
3774
+ description: "Path to a .png or .r16 height file, relative to the project."
3775
+ },
3776
+ min: { type: "number", description: "Lowest elevation in the file, metres." },
3777
+ max: { type: "number", description: "Highest elevation in the file, metres." }
3778
+ },
3779
+ required: ["heightmap"],
3780
+ additionalProperties: false
3781
+ },
3782
+ {
3783
+ type: "object",
3784
+ properties: {
3785
+ location: {
3786
+ type: "object",
3787
+ properties: { lat: { type: "number" }, lon: { type: "number" } },
3788
+ required: ["lat", "lon"],
3789
+ additionalProperties: false
3790
+ }
3791
+ },
3792
+ required: ["location"],
3793
+ additionalProperties: false
3794
+ }
3795
+ ]
3796
+ };
3797
+ var TERRAIN_TOOLS = [
3798
+ {
3799
+ name: "terrain_generate",
3800
+ description: `Choose from a request, an explicit kit or a biome and cook one editable starter terrain kit (forest, coastal, alpine, desert or tundra) into a world.glb; \`biome\` names a starter or one of its alias words, or carries an inline IBiomeSpec whose own landform, size and seed build the ground; \`landform\` swaps the ground for one of the seven shape presets (alpine, temperateMountains, rollingHills, desertMesa, coastalCliffs, tundra, volcanic) and keeps the kit's surface and assets; \`water\` replaces the water bodies the biome declares and changes the cooked world: an ocean row floods to its level, a river or lake row re-shapes the recipe's own river or lake in order (width or radius), a recipe layer with no row is removed, and a river or lake row with no layer to take it fails. A \`request\`'s words also decide the landform (mountains, hills, mesa, cliffs, volcano), the water (river, lake, island, ocean), the features carved into any ground (canyon, gorge, ravine: a steep cut across it; fjord, inlet: a sea inlet into the land) and the size (huge, small: the biome's own size scaled); an explicit \`landform\`, \`water\` or \`sizeMeters\` wins over a word. ${ECOREGION_NOTE} It keeps the starter's understorey, stones, road and water and replaces its canopy. A landform preset's ground is a real survey of the place its kind names, fetched from the Mapterhorn terrain tiles at the finest zoom its grid needs and the site has (the reply names the zoom and its metres per pixel), resampled onto the recipe's grid, cooked with the attribution its source requires, and reported as \`ground\`; the preset's erosion and grain still run on top of it. \`ground\` replaces that choice: "procedural" cooks the preset's own noise, { heightmap } reads a 16-bit grayscale PNG or a square .r16 grid, { location } cuts a survey at a latitude and longitude. An alpine or temperateMountains world on a survey also writes ring.json, its survey continued to ten times the world's size with one real whole mountain from that range past the square, reported as \`backdrop\`; \`backdrop: "none"\` cooks none. The result's \`decided\` names each choice with the word behind it or \`argument\`, and \`unused\` lists the request words that named nothing. A request that names only a starter (no shape, water, feature, size, seed or ground of its own) is that starter as shipped, judged and measured, reported as \`source: "catalog:<kit>"\`; anything else is \`"cooked"\`. The reply's \`seed\` is the seed the world was cooked with: pass another \`seed\` for a variation of the same request. A request repeated in the same project is copied from its cook cache (\`node_modules/.cache/threenative-terrain\`) and reported as \`cache: "hit"\`. Returns the kit as recipe, the biome it bakes, the water bodies the cooked world floods, measured from the evaluated state as \`water.json\` records them, its band rows resolved against the cooked heights (\`bands\`), the world.glb, recipe.json and world.json paths, triangles, instances and draws measured from the produced GLB's default scene, a ctx.assets.model load snippet, and \`grass\`: the lines that grow the biome's grass rows as a streamed, swaying GrassField3D on the cooked ground through grassFieldFromBiome (null when the biome has no grass row; the blade and material come from the game's src/render/grass.ts). triangles counts every instance of the LOD0 default scene in full, before distance LOD and culling, instances sums the EXT_mesh_gpu_instancing instances, and draws counts primitives across instanced and non-instanced meshes, an instanced primitive counting once.`,
3801
+ inputSchema: {
3802
+ type: "object",
3803
+ properties: {
3804
+ kit: { type: "string", enum: [...TERRAIN_KITS] },
3805
+ biome: {
3806
+ description: `A starter biome's name or alias word (forest, woods, beach, ...), or an inline IBiomeSpec object; a spec cooks with \`kit\`'s surface and assets, forest's when kit is absent. ${ARBOR_SPECIES_NOTE}`,
3807
+ anyOf: [{ type: "string", minLength: 1 }, { type: "object" }]
3808
+ },
3809
+ landform: { type: "string", enum: Object.keys(LANDFORMS) },
3810
+ request: {
3811
+ type: "string",
3812
+ minLength: 1,
3813
+ description: `What the world should be, in any words: a biome, a landform (mountains, hills, canyon, volcano, fjord, ...), water (river, lake, sea, ...) and a size (huge, small); an explicit argument wins over a word. A request with no biome word takes the biome its sea or shape suits, else the forest; \`decided\` names the word behind each choice and \`unused\` the words that named nothing. A tree word (oak, birch, aspen, cedar, maple, cypress, olive, acacia, baobab, palm, bamboo, cactus, ...) cooks that Arbor species in place of the kit's tree and is reported as \`decided.tree\`; a spec's own species rows win, and in a region request the word moves that species to the first canopy row and the community stays. ${ECOREGION_NOTE} \`kit\`, \`biome\` and \`ground\` still win over it. A real place's name is not geocoded: pass its latitude and longitude as \`ground: { location }\` to cook that place's survey.`
3814
+ },
3815
+ sizeMeters: { type: "number", exclusiveMinimum: 0 },
3816
+ seed: { type: "integer" },
3817
+ water: {
3818
+ type: "array",
3819
+ items: { type: "object" },
3820
+ description: "IBiomeWaterBody rows that replace the biome's declared water: river (width), lake (radius), ocean (level)."
3821
+ },
3822
+ ground: GROUND_SCHEMA,
3823
+ backdrop: {
3824
+ type: "string",
3825
+ enum: ["none"],
3826
+ description: `"none" cooks no far ring. Omitted, an alpine or temperateMountains world on a survey gets ring.json: its survey continued to ten times the world's size, with one real whole mountain (a seeded pick, pose and height) standing past the playable square.`
3827
+ },
3828
+ out: {
3829
+ type: "string",
3830
+ description: "Relative directory under the project's assets.source that must not exist yet; the default is assets.source/worlds/<kit>."
3831
+ }
3832
+ },
3833
+ anyOf: [{ required: ["request"] }, { required: ["kit"] }, { required: ["biome"] }],
3834
+ additionalProperties: false
3835
+ }
3836
+ },
3837
+ {
3838
+ name: "terrain_biome_new",
3839
+ description: "Make a new biome from a shipped one and cook it: copies the base biome's biome.data.json into <assets.source>/biomes/<name>/, applies the overrides, validates the file with validateBiome, then cooks it with the base kit's surface and assets and the biome's own landform preset. One call writes only under <assets.source>/biomes/<name>/, its cooked world included. Its ground comes from the biome's landform, the real survey that kind names unless `ground` names another source. Returns the same cook result as terrain_generate plus the biome file path and the biome's resolved `bands`. No code changes anywhere: the biome is data.",
3840
+ inputSchema: {
3841
+ type: "object",
3842
+ properties: {
3843
+ from: { type: "string", enum: [...TERRAIN_KITS] },
3844
+ name: {
3845
+ type: "string",
3846
+ pattern: "^[a-z][a-z0-9-]{0,31}$",
3847
+ description: "The new biome's folder and look name; lowercase, no spaces."
3848
+ },
3849
+ overrides: {
3850
+ type: "object",
3851
+ description: `IBiomeSpec fields to change on the base file (landform, foliage, grass, layers, water, spawn, species, aliases, bake). An unknown field fails. ${ARBOR_SPECIES_NOTE}`
3852
+ },
3853
+ ground: GROUND_SCHEMA,
3854
+ out: {
3855
+ type: "string",
3856
+ description: "Relative directory under the project's assets.source that must not exist yet; the default is assets.source/biomes/<name>/world."
3857
+ }
3858
+ },
3859
+ required: ["from", "name"],
3860
+ additionalProperties: false
3861
+ }
3862
+ },
3863
+ {
3864
+ name: "terrain_patch",
3865
+ description: "Apply editor commands (upsert, update, remove, move, toggle) to a terrain recipe and return the edited recipe.",
3866
+ inputSchema: {
3867
+ type: "object",
3868
+ properties: {
3869
+ recipe: { type: "object" },
3870
+ commands: { type: "array", items: { type: "object" } }
3871
+ },
3872
+ required: ["recipe", "commands"],
3873
+ additionalProperties: false
3874
+ }
3875
+ }
3876
+ ];
3877
+ var BIOME_NEW_FIELDS = ["from", "name", "overrides", "ground", "out"];
3607
3878
  function parseBiomeNewInput(input) {
3608
3879
  const args = closedRecord(input, "terrain_biome_new", BIOME_NEW_FIELDS);
3609
3880
  const from = args.from;
@@ -3821,10 +4092,26 @@ async function cookCached(request, out) {
3821
4092
  const { out: _out, projectRoot, ...inputs } = request;
3822
4093
  const starter = new URL(`../../starter/${request.kit}/`, import.meta.url);
3823
4094
  const starterFiles = await readdir(starter).catch(() => []);
4095
+ const arbor = new URL("../../starter/arbor/", import.meta.url);
4096
+ const arborFiles = await readdir(arbor).catch(() => []);
4097
+ const bakePackage = (() => {
4098
+ try {
4099
+ return [
4100
+ createRequire(join(projectRoot, "package.json")).resolve(
4101
+ "@threenative/procedural-environment/package.json"
4102
+ )
4103
+ ];
4104
+ } catch {
4105
+ return [];
4106
+ }
4107
+ })();
3824
4108
  const stamps = await Promise.all(
3825
- [COOK_CHILD, ...starterFiles.map((f) => fileURLToPath(new URL(f, starter)))].map(
3826
- async (file) => `${file}:${(await stat(file)).mtimeMs}`
3827
- )
4109
+ [
4110
+ COOK_CHILD,
4111
+ ...starterFiles.map((f) => fileURLToPath(new URL(f, starter))),
4112
+ ...arborFiles.map((f) => fileURLToPath(new URL(f, arbor))),
4113
+ ...bakePackage
4114
+ ].map(async (file) => `${file}:${(await stat(file)).mtimeMs}`)
3828
4115
  );
3829
4116
  const key = createHash("sha256").update(JSON.stringify({ inputs, version: SERVER_VERSION, stamps })).digest("hex").slice(0, 32);
3830
4117
  const dir = join(projectRoot, "node_modules", ".cache", "threenative-terrain", key);