@threenative/terrain 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/editor/index.d.ts +63 -5
- package/dist/editor/index.js +323 -6
- package/dist/editor/server.d.ts +2 -2
- package/dist/editor/server.js +198 -4
- package/dist/editor/worker.d.ts +1 -1
- package/dist/editor/worker.js +199 -5
- package/dist/export.d.ts +1 -1
- package/dist/index.d.ts +146 -7
- package/dist/index.js +638 -39
- package/dist/kit.d.ts +3 -2
- package/dist/kit.js +198 -4
- package/dist/mcp/cook-child.js +1766 -125
- package/dist/mcp/server.js +728 -37
- package/dist/{server-C8Ydr_IM.d.ts → server-B5RdvEAC.d.ts} +1 -1
- package/dist/starter.d.ts +1 -1
- package/dist/starter.js +2 -1
- package/dist/{terrain-B3DkduPw.d.ts → terrain-CAEaW0mQ.d.ts} +1 -1
- package/dist/three.d.ts +1 -1
- package/dist/{types-CPYAc9vo.d.ts → types-BpH00qsx.d.ts} +10 -3
- package/dist/{world-package-B7KGYIou.d.ts → world-package-B8QgHjAQ.d.ts} +9 -50
- package/package.json +5 -5
- package/starter/alpine/biome.data.json +22 -2
- package/starter/alpine/world.ts +1 -1
- package/starter/coastal/README.md +5 -2
- package/starter/coastal/assets.json +2 -1
- package/starter/coastal/biome.data.json +23 -2
- package/starter/coastal/sea.ts +2 -50
- package/starter/desert/biome.data.json +12 -2
- package/starter/desert/world.ts +1 -1
- package/starter/forest/README.md +1 -1
- package/starter/forest/assets.json +2 -1
- package/starter/forest/biome.data.json +37 -14
- package/starter/forest/water.ts +9 -28
- package/starter/forest/world.ts +6 -1
- package/starter/tundra/biome.data.json +12 -2
- package/starter/tundra/water.ts +9 -28
- package/starter/tundra/world.ts +1 -1
package/dist/mcp/server.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { createHash } from 'crypto';
|
|
2
3
|
import { realpathSync } from 'fs';
|
|
3
|
-
import { readFile, mkdir, writeFile, rm, lstat, realpath, readdir } from 'fs/promises';
|
|
4
|
+
import { readFile, mkdir, writeFile, rm, lstat, realpath, readdir, stat, cp, rename } from 'fs/promises';
|
|
4
5
|
import { resolve, relative, join, sep, isAbsolute, basename, dirname } from 'path';
|
|
5
6
|
import { createInterface } from 'readline';
|
|
6
7
|
import { fileURLToPath } from 'url';
|
|
@@ -90,11 +91,44 @@ var TERRAIN_KITS = ["forest", "coastal", "alpine", "desert", "tundra"];
|
|
|
90
91
|
|
|
91
92
|
// src/core/biome-words.ts
|
|
92
93
|
var BIOME_WORDS = {
|
|
93
|
-
alpine: [
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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"]
|
|
98
132
|
};
|
|
99
133
|
var BIOME_WORD_ROWS = TERRAIN_KITS.map((kit) => [kit, BIOME_WORDS[kit]]);
|
|
100
134
|
function biomeWordList() {
|
|
@@ -742,6 +776,146 @@ function fluvial(height, n, size, {
|
|
|
742
776
|
return Float32Array.from(h);
|
|
743
777
|
}
|
|
744
778
|
|
|
779
|
+
// src/core/gully.ts
|
|
780
|
+
var STEP_SECONDS = 0.1;
|
|
781
|
+
var FLUX_KEEP = 0.99;
|
|
782
|
+
var DISSOLVE = 0.3;
|
|
783
|
+
var DEPOSIT = 0.02;
|
|
784
|
+
var EVAPORATE = 0.05;
|
|
785
|
+
var DEPTH_REF = 0.01;
|
|
786
|
+
var DEPTH_MAX = 0.3;
|
|
787
|
+
var MIN_TILT = 0.05;
|
|
788
|
+
var GRAVITY = 9.81;
|
|
789
|
+
var MAX_ITERATIONS = 200;
|
|
790
|
+
function gully(height, n, size, { iterations = 200, capacity = 0.05, rain = 5e-4 } = {}) {
|
|
791
|
+
if (!Number.isInteger(n) || n < 2)
|
|
792
|
+
throw new RangeError("Gully erosion requires grid resolution n >= 2");
|
|
793
|
+
if (!Number.isInteger(iterations) || iterations < 0 || iterations > MAX_ITERATIONS)
|
|
794
|
+
throw new RangeError(`Gully erosion iterations must be between 0 and ${MAX_ITERATIONS}`);
|
|
795
|
+
if (!Number.isFinite(capacity) || capacity < 0 || capacity > 1e6)
|
|
796
|
+
throw new RangeError("Gully erosion capacity must be between 0 and 1000000");
|
|
797
|
+
if (!Number.isFinite(rain) || rain < 0 || rain > 1)
|
|
798
|
+
throw new RangeError("Gully erosion rain must be between 0 and 1 metres per step");
|
|
799
|
+
const total = n * n;
|
|
800
|
+
let h = Float64Array.from(height);
|
|
801
|
+
let hTmp = new Float64Array(total);
|
|
802
|
+
const water2 = new Float64Array(total);
|
|
803
|
+
const waterBefore = new Float64Array(total);
|
|
804
|
+
const speed = new Float64Array(total);
|
|
805
|
+
const sediment = new Float64Array(total);
|
|
806
|
+
const sedTmp = new Float64Array(total);
|
|
807
|
+
const fluxL = new Float64Array(total);
|
|
808
|
+
const fluxR = new Float64Array(total);
|
|
809
|
+
const fluxT = new Float64Array(total);
|
|
810
|
+
const fluxB = new Float64Array(total);
|
|
811
|
+
const cell = size / (n - 1);
|
|
812
|
+
const cellArea = cell * cell;
|
|
813
|
+
const gain = STEP_SECONDS * GRAVITY * cell;
|
|
814
|
+
const evaporateKeep = Math.max(1 - EVAPORATE * STEP_SECONDS, 0);
|
|
815
|
+
const share2 = (flow, depth) => depth > 0 ? flow * STEP_SECONDS / (depth * cellArea) : 0;
|
|
816
|
+
for (let step = 0; step < iterations; step += 1) {
|
|
817
|
+
for (let z = 0; z < n; z += 1) {
|
|
818
|
+
for (let x = 0; x < n; x += 1) {
|
|
819
|
+
const i = z * n + x;
|
|
820
|
+
const depth = water2[i] + rain;
|
|
821
|
+
const surface = h[i] + depth;
|
|
822
|
+
const ground = h[i];
|
|
823
|
+
const left = x > 0 ? h[i - 1] + water2[i - 1] + rain : ground;
|
|
824
|
+
const right = x < n - 1 ? h[i + 1] + water2[i + 1] + rain : ground;
|
|
825
|
+
const top = z > 0 ? h[i - n] + water2[i - n] + rain : ground;
|
|
826
|
+
const bottom = z < n - 1 ? h[i + n] + water2[i + n] + rain : ground;
|
|
827
|
+
let l = fluxL[i] * FLUX_KEEP + gain * (surface - left);
|
|
828
|
+
let r = fluxR[i] * FLUX_KEEP + gain * (surface - right);
|
|
829
|
+
let t = fluxT[i] * FLUX_KEEP + gain * (surface - top);
|
|
830
|
+
let b = fluxB[i] * FLUX_KEEP + gain * (surface - bottom);
|
|
831
|
+
if (l < 0) l = 0;
|
|
832
|
+
if (r < 0) r = 0;
|
|
833
|
+
if (t < 0) t = 0;
|
|
834
|
+
if (b < 0) b = 0;
|
|
835
|
+
const sum = l + r + t + b;
|
|
836
|
+
if (sum > 0) {
|
|
837
|
+
const keep = Math.min(1, depth * cellArea / (sum * STEP_SECONDS));
|
|
838
|
+
l *= keep;
|
|
839
|
+
r *= keep;
|
|
840
|
+
t *= keep;
|
|
841
|
+
b *= keep;
|
|
842
|
+
}
|
|
843
|
+
fluxL[i] = l;
|
|
844
|
+
fluxR[i] = r;
|
|
845
|
+
fluxT[i] = t;
|
|
846
|
+
fluxB[i] = b;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
for (let z = 0; z < n; z += 1) {
|
|
850
|
+
for (let x = 0; x < n; x += 1) {
|
|
851
|
+
const i = z * n + x;
|
|
852
|
+
const inL = x > 0 ? fluxR[i - 1] : 0;
|
|
853
|
+
const inR = x < n - 1 ? fluxL[i + 1] : 0;
|
|
854
|
+
const inT = z > 0 ? fluxB[i - n] : 0;
|
|
855
|
+
const inB = z < n - 1 ? fluxT[i + n] : 0;
|
|
856
|
+
const before = water2[i] + rain;
|
|
857
|
+
const after = Math.max(
|
|
858
|
+
0,
|
|
859
|
+
before + STEP_SECONDS * (inL + inR + inT + inB - fluxL[i] - fluxR[i] - fluxT[i] - fluxB[i]) / cellArea
|
|
860
|
+
);
|
|
861
|
+
const depth = 0.5 * (before + after);
|
|
862
|
+
const acrossX = inL - fluxL[i] + fluxR[i] - inR;
|
|
863
|
+
const acrossZ = inT - fluxT[i] + fluxB[i] - inB;
|
|
864
|
+
speed[i] = depth > 1e-4 ? Math.sqrt(acrossX * acrossX + acrossZ * acrossZ) * 0.5 / (cell * depth) : 0;
|
|
865
|
+
water2[i] = after;
|
|
866
|
+
waterBefore[i] = before;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
for (let z = 0; z < n; z += 1) {
|
|
870
|
+
for (let x = 0; x < n; x += 1) {
|
|
871
|
+
const i = z * n + x;
|
|
872
|
+
const gx = (h[z * n + Math.min(x + 1, n - 1)] - h[z * n + Math.max(x - 1, 0)]) / (2 * cell);
|
|
873
|
+
const gy = (h[Math.min(z + 1, n - 1) * n + x] - h[Math.max(z - 1, 0) * n + x]) / (2 * cell);
|
|
874
|
+
const squared = gx * gx + gy * gy;
|
|
875
|
+
const sine = Math.max(Math.sqrt(squared / (1 + squared)), MIN_TILT);
|
|
876
|
+
const depth = water2[i];
|
|
877
|
+
const transport = capacity * sine * speed[i] * Math.min(depth / DEPTH_REF, 1) * Math.max(1 - depth / DEPTH_MAX, 0);
|
|
878
|
+
let surface = h[i];
|
|
879
|
+
let load = sediment[i];
|
|
880
|
+
if (transport > load) {
|
|
881
|
+
const cut = DISSOLVE * (transport - load);
|
|
882
|
+
surface -= cut;
|
|
883
|
+
load += cut;
|
|
884
|
+
} else {
|
|
885
|
+
const drop = DEPOSIT * (load - transport);
|
|
886
|
+
surface += drop;
|
|
887
|
+
load -= drop;
|
|
888
|
+
}
|
|
889
|
+
hTmp[i] = surface;
|
|
890
|
+
sedTmp[i] = load;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
const passed = h;
|
|
894
|
+
h = hTmp;
|
|
895
|
+
hTmp = passed;
|
|
896
|
+
for (let z = 0; z < n; z += 1) {
|
|
897
|
+
for (let x = 0; x < n; x += 1) {
|
|
898
|
+
const i = z * n + x;
|
|
899
|
+
let load = sedTmp[i] * (1 - share2(
|
|
900
|
+
fluxL[i] + fluxR[i] + fluxT[i] + fluxB[i],
|
|
901
|
+
waterBefore[i]
|
|
902
|
+
));
|
|
903
|
+
if (x > 0)
|
|
904
|
+
load += sedTmp[i - 1] * share2(fluxR[i - 1], waterBefore[i - 1]);
|
|
905
|
+
if (x < n - 1)
|
|
906
|
+
load += sedTmp[i + 1] * share2(fluxL[i + 1], waterBefore[i + 1]);
|
|
907
|
+
if (z > 0)
|
|
908
|
+
load += sedTmp[i - n] * share2(fluxB[i - n], waterBefore[i - n]);
|
|
909
|
+
if (z < n - 1)
|
|
910
|
+
load += sedTmp[i + n] * share2(fluxT[i + n], waterBefore[i + n]);
|
|
911
|
+
sediment[i] = load;
|
|
912
|
+
water2[i] = water2[i] * evaporateKeep;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
return Float32Array.from(h, (surface, i) => surface + sediment[i]);
|
|
917
|
+
}
|
|
918
|
+
|
|
745
919
|
// src/core/masks.ts
|
|
746
920
|
var MATERIAL_IDS = Object.freeze([
|
|
747
921
|
"grass",
|
|
@@ -840,6 +1014,57 @@ function paintWeights(s, i, channel, weight) {
|
|
|
840
1014
|
s.splat[base + c] = s.splat[base + c] * (1 - w) + (c === channel ? w : 0);
|
|
841
1015
|
}
|
|
842
1016
|
|
|
1017
|
+
// src/core/scree.ts
|
|
1018
|
+
var NEIGHBOURS = [
|
|
1019
|
+
[-1, -1],
|
|
1020
|
+
[0, -1],
|
|
1021
|
+
[1, -1],
|
|
1022
|
+
[-1, 0],
|
|
1023
|
+
[1, 0],
|
|
1024
|
+
[-1, 1],
|
|
1025
|
+
[0, 1],
|
|
1026
|
+
[1, 1]
|
|
1027
|
+
];
|
|
1028
|
+
var DISTANCE = Float64Array.from(NEIGHBOURS, ([dx, dz]) => Math.hypot(dx, dz));
|
|
1029
|
+
var MAX_ITERATIONS2 = 200;
|
|
1030
|
+
function scree(height, n, size, { iterations = 200, talus = 35, rate = 0.05 } = {}) {
|
|
1031
|
+
if (!Number.isInteger(n) || n < 2)
|
|
1032
|
+
throw new RangeError("Scree slide requires grid resolution n >= 2");
|
|
1033
|
+
if (!Number.isInteger(iterations) || iterations < 0 || iterations > MAX_ITERATIONS2)
|
|
1034
|
+
throw new RangeError(`Scree slide iterations must be between 0 and ${MAX_ITERATIONS2}`);
|
|
1035
|
+
if (!Number.isFinite(talus) || talus < 0 || talus > 89.9)
|
|
1036
|
+
throw new RangeError("Scree slide talus must be between 0 and 89.9 degrees");
|
|
1037
|
+
if (!Number.isFinite(rate) || rate < 0 || rate > 1)
|
|
1038
|
+
throw new RangeError("Scree slide rate must be between 0 and 1");
|
|
1039
|
+
const cell = size / (n - 1);
|
|
1040
|
+
const limit = Float64Array.from(DISTANCE, (d) => Math.tan(talus * Math.PI / 180) * cell * d);
|
|
1041
|
+
let source = Float64Array.from(height);
|
|
1042
|
+
let target = new Float64Array(source.length);
|
|
1043
|
+
for (let k = 0; k < iterations; k += 1) {
|
|
1044
|
+
for (let z = 0; z < n; z += 1) {
|
|
1045
|
+
for (let x = 0; x < n; x += 1) {
|
|
1046
|
+
const i = z * n + x;
|
|
1047
|
+
const here = source[i];
|
|
1048
|
+
let received = 0;
|
|
1049
|
+
for (let d = 0; d < 8; d += 1) {
|
|
1050
|
+
const nx = x + NEIGHBOURS[d][0];
|
|
1051
|
+
const nz = z + NEIGHBOURS[d][1];
|
|
1052
|
+
if (nx < 0 || nz < 0 || nx >= n || nz >= n) continue;
|
|
1053
|
+
const other = source[nz * n + nx];
|
|
1054
|
+
const gap = limit[d];
|
|
1055
|
+
if (other - here > gap) received += other - here - gap;
|
|
1056
|
+
else if (here - other > gap) received -= here - other - gap;
|
|
1057
|
+
}
|
|
1058
|
+
target[i] = here + rate * received;
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
const swap = source;
|
|
1062
|
+
source = target;
|
|
1063
|
+
target = swap;
|
|
1064
|
+
}
|
|
1065
|
+
return Float32Array.from(source);
|
|
1066
|
+
}
|
|
1067
|
+
|
|
843
1068
|
// src/core/operations.ts
|
|
844
1069
|
var OPERATION_TYPES = Object.freeze([
|
|
845
1070
|
"noise",
|
|
@@ -1275,7 +1500,7 @@ function applyOperation(s, layer2) {
|
|
|
1275
1500
|
evaporation: p.evaporation
|
|
1276
1501
|
},
|
|
1277
1502
|
observations
|
|
1278
|
-
) : thermal(s.height, n, s.size, p, observations);
|
|
1503
|
+
) : p.method === "gully" ? gully(s.height, n, s.size, p) : p.method === "scree" ? scree(s.height, n, s.size, p) : thermal(s.height, n, s.size, p, observations);
|
|
1279
1504
|
let influence = mask;
|
|
1280
1505
|
if (p.at || p.points) influence = brushWeights(s, p, mask, seed);
|
|
1281
1506
|
for (let i = 0; i < s.height.length; i += 1) {
|
|
@@ -1429,6 +1654,7 @@ function finalizeState(s) {
|
|
|
1429
1654
|
}
|
|
1430
1655
|
const wet = (i, x, z, h) => {
|
|
1431
1656
|
if (s.waters.some((water2) => water2.mask[i])) return true;
|
|
1657
|
+
if (s.waters.some((water2) => water2.kind === "ocean" && h < water2.level + 0.35)) return true;
|
|
1432
1658
|
for (const river of s.rivers) {
|
|
1433
1659
|
const half = river.width / 2;
|
|
1434
1660
|
for (let k = 1; k < river.points.length; k += 1) {
|
|
@@ -1599,7 +1825,8 @@ var PARAMS = Object.freeze({
|
|
|
1599
1825
|
"capacity",
|
|
1600
1826
|
"erosion",
|
|
1601
1827
|
"deposition",
|
|
1602
|
-
"evaporation"
|
|
1828
|
+
"evaporation",
|
|
1829
|
+
"rain"
|
|
1603
1830
|
],
|
|
1604
1831
|
terrace: ["step", "softness", "strength", "offset"],
|
|
1605
1832
|
materials: ["base", "rules", "reset"],
|
|
@@ -1907,7 +2134,8 @@ function validateLayer(layer2) {
|
|
|
1907
2134
|
"rate",
|
|
1908
2135
|
"value",
|
|
1909
2136
|
"waterWidth",
|
|
1910
|
-
"maxGrade"
|
|
2137
|
+
"maxGrade",
|
|
2138
|
+
"rain"
|
|
1911
2139
|
])
|
|
1912
2140
|
if (params[key] !== void 0) num(params[key], key, 0, 1);
|
|
1913
2141
|
if (params.spacing !== void 0) num(params.spacing, "spacing", 0.01, 2);
|
|
@@ -1963,7 +2191,7 @@ function validateLayer(layer2) {
|
|
|
1963
2191
|
}
|
|
1964
2192
|
}
|
|
1965
2193
|
if (params.method !== void 0)
|
|
1966
|
-
enumeration(params.method, "method", ["thermal", "hydraulic", "fluvial"]);
|
|
2194
|
+
enumeration(params.method, "method", ["thermal", "hydraulic", "fluvial", "gully", "scree"]);
|
|
1967
2195
|
if (params.mode !== void 0) enumeration(params.mode, "mode", ["fbm", "ridged", "billow"]);
|
|
1968
2196
|
if (params.shape !== void 0)
|
|
1969
2197
|
enumeration(
|
|
@@ -2468,7 +2696,24 @@ var SPEC_FIELDS = [
|
|
|
2468
2696
|
"species",
|
|
2469
2697
|
"aliases"
|
|
2470
2698
|
];
|
|
2471
|
-
var COVER_FIELDS = [
|
|
2699
|
+
var COVER_FIELDS = [
|
|
2700
|
+
"ground",
|
|
2701
|
+
"seed",
|
|
2702
|
+
"attempts",
|
|
2703
|
+
"stoneRadius",
|
|
2704
|
+
"clearings",
|
|
2705
|
+
"understorey"
|
|
2706
|
+
];
|
|
2707
|
+
var UNDERSTOREY_FIELDS = [
|
|
2708
|
+
"attempts",
|
|
2709
|
+
"litter",
|
|
2710
|
+
"fern",
|
|
2711
|
+
"bush",
|
|
2712
|
+
"flower",
|
|
2713
|
+
"deadfall",
|
|
2714
|
+
"shade",
|
|
2715
|
+
"shadeRadius"
|
|
2716
|
+
];
|
|
2472
2717
|
var COVER_GROUNDS = ["wood", "crag", "mesa", "mats"];
|
|
2473
2718
|
var STREAMS = ["ordered", "seeded"];
|
|
2474
2719
|
var DRIFT_FIELDS = ["field", "frequency", "offset", "amplitude", "band"];
|
|
@@ -2655,6 +2900,19 @@ function clearing(value, biome, field) {
|
|
|
2655
2900
|
if (radius <= 0) fail2(biome, `${field}[2]`, "must be greater than 0");
|
|
2656
2901
|
return [x, z, radius];
|
|
2657
2902
|
}
|
|
2903
|
+
function understorey(value, biome) {
|
|
2904
|
+
const row = closed(value, biome, "cover.understorey", UNDERSTOREY_FIELDS);
|
|
2905
|
+
return {
|
|
2906
|
+
attempts: whole(row.attempts, biome, "cover.understorey.attempts"),
|
|
2907
|
+
litter: count(row.litter, biome, "cover.understorey.litter"),
|
|
2908
|
+
fern: count(row.fern, biome, "cover.understorey.fern"),
|
|
2909
|
+
bush: count(row.bush, biome, "cover.understorey.bush"),
|
|
2910
|
+
flower: count(row.flower, biome, "cover.understorey.flower"),
|
|
2911
|
+
deadfall: count(row.deadfall, biome, "cover.understorey.deadfall"),
|
|
2912
|
+
shade: share(row.shade, biome, "cover.understorey.shade"),
|
|
2913
|
+
shadeRadius: count(row.shadeRadius, biome, "cover.understorey.shadeRadius")
|
|
2914
|
+
};
|
|
2915
|
+
}
|
|
2658
2916
|
function cover(value, biome) {
|
|
2659
2917
|
const row = closed(value, biome, "cover", COVER_FIELDS);
|
|
2660
2918
|
const clearings = row.clearings;
|
|
@@ -2664,7 +2922,8 @@ function cover(value, biome) {
|
|
|
2664
2922
|
seed: whole(row.seed, biome, "cover.seed"),
|
|
2665
2923
|
attempts: whole(row.attempts, biome, "cover.attempts", 1),
|
|
2666
2924
|
stoneRadius: positive(row.stoneRadius, biome, "cover.stoneRadius"),
|
|
2667
|
-
clearings: clearings.map((entry2, index) => clearing(entry2, biome, `cover.clearings[${index}]`))
|
|
2925
|
+
clearings: clearings.map((entry2, index) => clearing(entry2, biome, `cover.clearings[${index}]`)),
|
|
2926
|
+
understorey: understorey(row.understorey, biome)
|
|
2668
2927
|
};
|
|
2669
2928
|
}
|
|
2670
2929
|
function foliage(value, biome, field) {
|
|
@@ -2799,12 +3058,203 @@ function validateBiome(spec, name) {
|
|
|
2799
3058
|
};
|
|
2800
3059
|
}
|
|
2801
3060
|
|
|
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
|
+
]);
|
|
3161
|
+
|
|
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.";
|
|
3166
|
+
var MASSIFS = {
|
|
3167
|
+
temperateMountains: [
|
|
3168
|
+
{
|
|
3169
|
+
name: "Longs Peak and Mount Meeker, Rocky Mountain National Park, Colorado",
|
|
3170
|
+
lat: 40.2549,
|
|
3171
|
+
lon: -105.6101,
|
|
3172
|
+
extentMeters: 4400,
|
|
3173
|
+
zoom: 12,
|
|
3174
|
+
attribution: `${USGS_3DEP} ${TILES}`
|
|
3175
|
+
}
|
|
3176
|
+
],
|
|
3177
|
+
alpine: [
|
|
3178
|
+
{
|
|
3179
|
+
name: "Grand Teton and the Cathedral Group, Wyoming",
|
|
3180
|
+
lat: 43.7455,
|
|
3181
|
+
lon: -110.8024,
|
|
3182
|
+
extentMeters: 3600,
|
|
3183
|
+
zoom: 12,
|
|
3184
|
+
attribution: `${USGS_3DEP} ${TILES}`
|
|
3185
|
+
},
|
|
3186
|
+
{
|
|
3187
|
+
name: "Maroon Bells, Elk Mountains, Colorado",
|
|
3188
|
+
lat: 39.0708,
|
|
3189
|
+
lon: -106.989,
|
|
3190
|
+
extentMeters: 3600,
|
|
3191
|
+
zoom: 12,
|
|
3192
|
+
attribution: `${USGS_3DEP} ${TILES}`
|
|
3193
|
+
}
|
|
3194
|
+
]
|
|
3195
|
+
};
|
|
3196
|
+
var LOCATION_EXTENT_METERS = 6e3;
|
|
3197
|
+
var LOCATION_ZOOM = 12;
|
|
3198
|
+
var finite = (value, axis) => {
|
|
3199
|
+
if (!Number.isFinite(value))
|
|
3200
|
+
throw new TypeError(`ground.location.${axis} must be a finite number.`);
|
|
3201
|
+
return value;
|
|
3202
|
+
};
|
|
3203
|
+
function locationSurvey(lat, lon) {
|
|
3204
|
+
const latitude = finite(lat, "lat");
|
|
3205
|
+
const longitude = finite(lon, "lon");
|
|
3206
|
+
if (Math.abs(latitude) > 90)
|
|
3207
|
+
throw new RangeError("ground.location.lat must be between -90 and 90.");
|
|
3208
|
+
if (Math.abs(longitude) > 180)
|
|
3209
|
+
throw new RangeError("ground.location.lon must be between -180 and 180.");
|
|
3210
|
+
return {
|
|
3211
|
+
name: `${latitude}, ${longitude}`,
|
|
3212
|
+
lat: latitude,
|
|
3213
|
+
lon: longitude,
|
|
3214
|
+
extentMeters: LOCATION_EXTENT_METERS,
|
|
3215
|
+
zoom: LOCATION_ZOOM,
|
|
3216
|
+
attribution: `${SRTM} ${TILES}`
|
|
3217
|
+
};
|
|
3218
|
+
}
|
|
3219
|
+
|
|
2802
3220
|
// src/mcp/tools.ts
|
|
2803
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
|
|
3238
|
+
},
|
|
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
|
|
3251
|
+
}
|
|
3252
|
+
]
|
|
3253
|
+
};
|
|
2804
3254
|
var TERRAIN_TOOLS = [
|
|
2805
3255
|
{
|
|
2806
3256
|
name: "terrain_generate",
|
|
2807
|
-
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. 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.",
|
|
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.",
|
|
2808
3258
|
inputSchema: {
|
|
2809
3259
|
type: "object",
|
|
2810
3260
|
properties: {
|
|
@@ -2814,7 +3264,11 @@ var TERRAIN_TOOLS = [
|
|
|
2814
3264
|
anyOf: [{ type: "string", minLength: 1 }, { type: "object" }]
|
|
2815
3265
|
},
|
|
2816
3266
|
landform: { type: "string", enum: Object.keys(LANDFORMS) },
|
|
2817
|
-
request: {
|
|
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
|
+
},
|
|
2818
3272
|
sizeMeters: { type: "number", exclusiveMinimum: 0 },
|
|
2819
3273
|
seed: { type: "integer" },
|
|
2820
3274
|
water: {
|
|
@@ -2822,6 +3276,12 @@ var TERRAIN_TOOLS = [
|
|
|
2822
3276
|
items: { type: "object" },
|
|
2823
3277
|
description: "IBiomeWaterBody rows that replace the biome's declared water: river (width), lake (radius), ocean (level)."
|
|
2824
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
|
+
},
|
|
2825
3285
|
out: {
|
|
2826
3286
|
type: "string",
|
|
2827
3287
|
description: "Relative directory under the project's assets.source that must not exist yet; the default is assets.source/worlds/<kit>."
|
|
@@ -2833,7 +3293,7 @@ var TERRAIN_TOOLS = [
|
|
|
2833
3293
|
},
|
|
2834
3294
|
{
|
|
2835
3295
|
name: "terrain_biome_new",
|
|
2836
|
-
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. 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.",
|
|
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.",
|
|
2837
3297
|
inputSchema: {
|
|
2838
3298
|
type: "object",
|
|
2839
3299
|
properties: {
|
|
@@ -2847,6 +3307,7 @@ var TERRAIN_TOOLS = [
|
|
|
2847
3307
|
type: "object",
|
|
2848
3308
|
description: "IBiomeSpec fields to change on the base file (landform, foliage, grass, layers, water, spawn, species, aliases, bake). An unknown field fails."
|
|
2849
3309
|
},
|
|
3310
|
+
ground: GROUND_SCHEMA,
|
|
2850
3311
|
out: {
|
|
2851
3312
|
type: "string",
|
|
2852
3313
|
description: "Relative directory under the project's assets.source that must not exist yet; the default is assets.source/biomes/<name>/world."
|
|
@@ -2894,9 +3355,11 @@ var GENERATE_FIELDS = [
|
|
|
2894
3355
|
"sizeMeters",
|
|
2895
3356
|
"seed",
|
|
2896
3357
|
"water",
|
|
3358
|
+
"ground",
|
|
3359
|
+
"backdrop",
|
|
2897
3360
|
"out"
|
|
2898
3361
|
];
|
|
2899
|
-
var BIOME_NEW_FIELDS = ["from", "name", "overrides", "out"];
|
|
3362
|
+
var BIOME_NEW_FIELDS = ["from", "name", "overrides", "ground", "out"];
|
|
2900
3363
|
var LANDFORM_KINDS2 = Object.keys(LANDFORMS);
|
|
2901
3364
|
function parseBiomeArgument(biome) {
|
|
2902
3365
|
if (biome === void 0) return {};
|
|
@@ -2918,6 +3381,18 @@ function parseBiomeArgument(biome) {
|
|
|
2918
3381
|
"terrain_generate: biome must be a starter name, an alias word or a biome spec object."
|
|
2919
3382
|
);
|
|
2920
3383
|
}
|
|
3384
|
+
function parseLandform(value) {
|
|
3385
|
+
if (value === void 0) return void 0;
|
|
3386
|
+
if (!LANDFORM_KINDS2.includes(value))
|
|
3387
|
+
throw new TypeError(`terrain_generate: landform must be one of ${LANDFORM_KINDS2.join(", ")}.`);
|
|
3388
|
+
return value;
|
|
3389
|
+
}
|
|
3390
|
+
function parseSize(value) {
|
|
3391
|
+
if (value === void 0) return void 0;
|
|
3392
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0)
|
|
3393
|
+
throw new TypeError("terrain_generate: sizeMeters must be a positive finite number.");
|
|
3394
|
+
return value;
|
|
3395
|
+
}
|
|
2921
3396
|
function parseWater(water2) {
|
|
2922
3397
|
if (water2 === void 0) return void 0;
|
|
2923
3398
|
if (!Array.isArray(water2) || water2.some((body) => !isRecord(body))) {
|
|
@@ -2925,35 +3400,181 @@ function parseWater(water2) {
|
|
|
2925
3400
|
}
|
|
2926
3401
|
return water2;
|
|
2927
3402
|
}
|
|
2928
|
-
function
|
|
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
|
+
function backdropWordAt(words, word) {
|
|
3443
|
+
const at = words.indexOf(word);
|
|
3444
|
+
const before = words[at - 1] === "the" ? words[at - 2] : words[at - 1];
|
|
3445
|
+
return before !== void 0 && BACKDROP_WORDS.includes(before);
|
|
3446
|
+
}
|
|
3447
|
+
function rowHit(rows, words) {
|
|
3448
|
+
for (const [row, names] of rows) {
|
|
3449
|
+
const word = words.find((candidate) => names.includes(candidate));
|
|
3450
|
+
if (word !== void 0) return { row, word };
|
|
3451
|
+
}
|
|
3452
|
+
return void 0;
|
|
3453
|
+
}
|
|
3454
|
+
function declaredWater(rows, row) {
|
|
3455
|
+
return rows.some(
|
|
3456
|
+
(own) => own.kind === row.kind && own.width === row.width && own.radius === row.radius && own.level === row.level
|
|
3457
|
+
);
|
|
3458
|
+
}
|
|
3459
|
+
function parseGenerateRequest(input) {
|
|
2929
3460
|
const args = closedRecord(input, "terrain_generate", GENERATE_FIELDS);
|
|
2930
3461
|
const { request, sizeMeters, seed, out } = args;
|
|
2931
3462
|
if (request !== void 0 && (typeof request !== "string" || request.trim() === "")) {
|
|
2932
3463
|
throw new TypeError("terrain_generate: request must be a non-empty string.");
|
|
2933
3464
|
}
|
|
3465
|
+
if (request === void 0 && args.kit === void 0 && args.biome === void 0) {
|
|
3466
|
+
throw new TypeError("terrain_generate: give a request, a kit or a biome.");
|
|
3467
|
+
}
|
|
2934
3468
|
const words = typeof request === "string" ? request.toLowerCase().split(/[^a-z]+/u) : [];
|
|
2935
3469
|
const { kit: biomeKit, spec } = parseBiomeArgument(args.biome);
|
|
2936
|
-
const
|
|
2937
|
-
|
|
3470
|
+
const biomeWord = rowHit(BIOME_WORD_ROWS, words);
|
|
3471
|
+
const arguedKit = args.kit ?? biomeKit;
|
|
3472
|
+
let inferred;
|
|
3473
|
+
if (arguedKit === void 0 && spec === void 0 && biomeWord === void 0) {
|
|
3474
|
+
const sea = rowHit(
|
|
3475
|
+
WATER_WORD_ROWS.filter(([row]) => row.kind === "ocean"),
|
|
3476
|
+
words
|
|
3477
|
+
);
|
|
3478
|
+
const shape = rowHit(LANDFORM_WORD_ROWS, words);
|
|
3479
|
+
if (sea !== void 0) inferred = { kit: "coastal", word: sea.word };
|
|
3480
|
+
else if (shape !== void 0 && !backdropWordAt(words, shape.word))
|
|
3481
|
+
inferred = { kit: LANDFORM_BIOME[shape.row], word: shape.word };
|
|
3482
|
+
}
|
|
3483
|
+
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");
|
|
2938
3485
|
if (typeof kit !== "string" || !TERRAIN_KITS.includes(kit)) {
|
|
2939
3486
|
throw new TypeError(
|
|
2940
|
-
|
|
3487
|
+
`terrain_generate: kit must be one of ${TERRAIN_KITS.join(", ")}. Words a request may use: ${biomeWordList()}.`
|
|
2941
3488
|
);
|
|
2942
3489
|
}
|
|
2943
3490
|
const parsed = { kit };
|
|
2944
3491
|
if (spec !== void 0) parsed.spec = spec;
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
parsed.landform =
|
|
3492
|
+
const own = BIOME_OWN[kit];
|
|
3493
|
+
const landformArgument = parseLandform(args.landform);
|
|
3494
|
+
const landformWord = rowHit(LANDFORM_WORD_ROWS, words);
|
|
3495
|
+
let landform;
|
|
3496
|
+
if (landformArgument !== void 0) {
|
|
3497
|
+
parsed.landform = landformArgument;
|
|
3498
|
+
landform = { value: landformArgument, source: "argument" };
|
|
3499
|
+
} else if (spec !== void 0) {
|
|
3500
|
+
landform = { value: spec.landform, source: "argument" };
|
|
3501
|
+
} else if (landformWord === void 0) {
|
|
3502
|
+
landform = { value: null, source: "default" };
|
|
3503
|
+
} else if (backdropWordAt(words, landformWord.word)) {
|
|
3504
|
+
parsed.landform = own.landform;
|
|
3505
|
+
parsed.backdropRange = landformWord.row;
|
|
3506
|
+
landform = { value: own.landform, source: "default" };
|
|
3507
|
+
} else {
|
|
3508
|
+
landform = { value: landformWord.row, source: { word: landformWord.word } };
|
|
3509
|
+
if (landformWord.row !== own.landform) parsed.landform = landformWord.row;
|
|
3510
|
+
}
|
|
3511
|
+
const waterWord = rowHit(WATER_WORD_ROWS, words);
|
|
3512
|
+
const waterArgument = parseWater(args.water);
|
|
3513
|
+
let water2;
|
|
3514
|
+
if (waterArgument !== void 0) {
|
|
3515
|
+
parsed.water = waterArgument;
|
|
3516
|
+
water2 = { value: waterArgument, source: "argument" };
|
|
3517
|
+
} else if (spec !== void 0) {
|
|
3518
|
+
water2 = { value: spec.water, source: "argument" };
|
|
3519
|
+
} else if (waterWord === void 0) {
|
|
3520
|
+
water2 = { value: null, source: "default" };
|
|
3521
|
+
} else {
|
|
3522
|
+
const bodies = WATER_WORD_ROWS.filter(([, names]) => words.some((w) => names.includes(w))).map(
|
|
3523
|
+
([row]) => row
|
|
3524
|
+
);
|
|
3525
|
+
if (parsed.landform === void 0 && bodies.every((row) => declaredWater(own.water, row))) {
|
|
3526
|
+
water2 = { value: own.water, source: { word: waterWord.word } };
|
|
3527
|
+
} else {
|
|
3528
|
+
parsed.water = bodies;
|
|
3529
|
+
water2 = { value: parsed.water, source: { word: waterWord.word } };
|
|
3530
|
+
}
|
|
3531
|
+
}
|
|
3532
|
+
const sizeArgument = parseSize(sizeMeters);
|
|
3533
|
+
const sizeWord = rowHit(SIZE_WORD_ROWS, words);
|
|
3534
|
+
let size;
|
|
3535
|
+
if (sizeArgument !== void 0) {
|
|
3536
|
+
parsed.sizeMeters = sizeArgument;
|
|
3537
|
+
size = { value: sizeArgument, source: "argument" };
|
|
3538
|
+
} else if (spec !== void 0) {
|
|
3539
|
+
size = { value: spec.sizeMeters, source: "argument" };
|
|
3540
|
+
} else if (sizeWord === void 0) {
|
|
3541
|
+
size = { value: null, source: "default" };
|
|
3542
|
+
} else {
|
|
3543
|
+
parsed.sizeMeters = Math.round(own.sizeMeters * sizeWord.row);
|
|
3544
|
+
size = { value: parsed.sizeMeters, source: { word: sizeWord.word } };
|
|
3545
|
+
}
|
|
3546
|
+
const featureHits = FEATURE_WORD_ROWS.flatMap(([feature, names]) => {
|
|
3547
|
+
const word = words.find((w) => names.includes(w));
|
|
3548
|
+
return word === void 0 ? [] : [{ feature, word }];
|
|
3549
|
+
});
|
|
3550
|
+
let features = { value: [], source: "default" };
|
|
3551
|
+
if (featureHits.length > 0) {
|
|
3552
|
+
parsed.features = featureHits.map((hit) => hit.feature);
|
|
3553
|
+
features = {
|
|
3554
|
+
value: parsed.features,
|
|
3555
|
+
source: { word: featureHits[0].word }
|
|
3556
|
+
};
|
|
2951
3557
|
}
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
parsed.
|
|
3558
|
+
const groundArgument = parseGround(args.ground, "terrain_generate");
|
|
3559
|
+
const presetKind = parsed.landform ?? (spec === void 0 ? void 0 : spec.landform);
|
|
3560
|
+
let ground;
|
|
3561
|
+
if (groundArgument !== void 0) {
|
|
3562
|
+
parsed.ground = groundArgument;
|
|
3563
|
+
ground = { value: groundArgument, source: "argument" };
|
|
3564
|
+
} else {
|
|
3565
|
+
ground = { value: presetKind === void 0 ? "starter" : "survey", source: "default" };
|
|
3566
|
+
}
|
|
3567
|
+
let backdrop;
|
|
3568
|
+
if (args.backdrop !== void 0) {
|
|
3569
|
+
if (args.backdrop !== "none")
|
|
3570
|
+
throw new TypeError('terrain_generate: backdrop must be "none" when given.');
|
|
3571
|
+
parsed.backdrop = "none";
|
|
3572
|
+
backdrop = { value: "none", source: "argument" };
|
|
3573
|
+
} else {
|
|
3574
|
+
const surveyed = ground.value === "survey" || typeof ground.value === "object" && "location" in ground.value;
|
|
3575
|
+
const range2 = parsed.backdropRange ?? presetKind;
|
|
3576
|
+
const mountain = range2 !== void 0 && MASSIFS[range2] !== void 0;
|
|
3577
|
+
backdrop = { value: surveyed && mountain ? "massif" : "none", source: "default" };
|
|
2957
3578
|
}
|
|
2958
3579
|
if (seed !== void 0) {
|
|
2959
3580
|
if (typeof seed !== "number" || !Number.isSafeInteger(seed)) {
|
|
@@ -2961,10 +3582,27 @@ function parseGenerateInput(input) {
|
|
|
2961
3582
|
}
|
|
2962
3583
|
parsed.seed = seed;
|
|
2963
3584
|
}
|
|
2964
|
-
const water2 = parseWater(args.water);
|
|
2965
|
-
if (water2 !== void 0) parsed.water = water2;
|
|
2966
3585
|
if (out !== void 0) parsed.out = relativeDirectory(out);
|
|
2967
|
-
|
|
3586
|
+
let biomeSource = "default";
|
|
3587
|
+
if (arguedKit !== void 0) biomeSource = "argument";
|
|
3588
|
+
else if (biomeWord !== void 0) biomeSource = { word: biomeWord.word };
|
|
3589
|
+
else if (inferred !== void 0) biomeSource = { word: inferred.word };
|
|
3590
|
+
return {
|
|
3591
|
+
input: parsed,
|
|
3592
|
+
decided: {
|
|
3593
|
+
biome: { value: kit, source: biomeSource },
|
|
3594
|
+
landform,
|
|
3595
|
+
water: water2,
|
|
3596
|
+
sizeMeters: size,
|
|
3597
|
+
features,
|
|
3598
|
+
ground,
|
|
3599
|
+
backdrop
|
|
3600
|
+
},
|
|
3601
|
+
// What is left is what the tool could not act on: a retry names a word, not a guess.
|
|
3602
|
+
unused: [...new Set(words)].filter(
|
|
3603
|
+
(word) => word.length >= 3 && !REQUEST_STOP_WORDS.has(word) && !REQUEST_KNOWN_WORDS.has(word)
|
|
3604
|
+
)
|
|
3605
|
+
};
|
|
2968
3606
|
}
|
|
2969
3607
|
function parseBiomeNewInput(input) {
|
|
2970
3608
|
const args = closedRecord(input, "terrain_biome_new", BIOME_NEW_FIELDS);
|
|
@@ -2983,6 +3621,8 @@ function parseBiomeNewInput(input) {
|
|
|
2983
3621
|
throw new TypeError("terrain_biome_new: overrides must be an object.");
|
|
2984
3622
|
const parsed = { from, name };
|
|
2985
3623
|
if (overrides !== void 0) parsed.overrides = { ...overrides };
|
|
3624
|
+
const ground = parseGround(args.ground, "terrain_biome_new");
|
|
3625
|
+
if (ground !== void 0) parsed.ground = ground;
|
|
2986
3626
|
if (args.out !== void 0) parsed.out = relativeDirectory(args.out);
|
|
2987
3627
|
return parsed;
|
|
2988
3628
|
}
|
|
@@ -3175,10 +3815,48 @@ async function cookInChild(request, out) {
|
|
|
3175
3815
|
});
|
|
3176
3816
|
return child.stdout.trim().split("\n").at(-1) ?? "";
|
|
3177
3817
|
}
|
|
3818
|
+
var CACHED_OUT = "@@TN_TERRAIN_OUT@@";
|
|
3819
|
+
var CACHED_URL = "@@TN_TERRAIN_URL@@";
|
|
3820
|
+
async function cookCached(request, out) {
|
|
3821
|
+
const { out: _out, projectRoot, ...inputs } = request;
|
|
3822
|
+
const starter = new URL(`../../starter/${request.kit}/`, import.meta.url);
|
|
3823
|
+
const starterFiles = await readdir(starter).catch(() => []);
|
|
3824
|
+
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
|
+
)
|
|
3828
|
+
);
|
|
3829
|
+
const key = createHash("sha256").update(JSON.stringify({ inputs, version: SERVER_VERSION, stamps })).digest("hex").slice(0, 32);
|
|
3830
|
+
const dir = join(projectRoot, "node_modules", ".cache", "threenative-terrain", key);
|
|
3831
|
+
const shown = relative(realpathSync(projectRoot), out).split(sep).join("/");
|
|
3832
|
+
const url = relative(request.assetSource, out).split(sep).join("/");
|
|
3833
|
+
const stored = await readFile(join(dir, "reply.json"), "utf8").catch(() => void 0);
|
|
3834
|
+
if (stored !== void 0) {
|
|
3835
|
+
await cp(join(dir, "world"), out, { recursive: true });
|
|
3836
|
+
return {
|
|
3837
|
+
text: stored.replaceAll(CACHED_OUT, shown).replaceAll(CACHED_URL, url),
|
|
3838
|
+
cache: "hit"
|
|
3839
|
+
};
|
|
3840
|
+
}
|
|
3841
|
+
const text2 = await cookInChild(request, out);
|
|
3842
|
+
const staging = `${dir}.${String(process.pid)}`;
|
|
3843
|
+
try {
|
|
3844
|
+
await cp(out, join(staging, "world"), { recursive: true });
|
|
3845
|
+
await writeFile(
|
|
3846
|
+
join(staging, "reply.json"),
|
|
3847
|
+
text2.replaceAll(shown, CACHED_OUT).replaceAll(url, CACHED_URL)
|
|
3848
|
+
);
|
|
3849
|
+
await rename(staging, dir);
|
|
3850
|
+
} catch (error) {
|
|
3851
|
+
await rm(staging, { recursive: true, force: true });
|
|
3852
|
+
console.error(`terrain: cook cache not written: ${error.message}`);
|
|
3853
|
+
}
|
|
3854
|
+
return { text: text2, cache: "miss" };
|
|
3855
|
+
}
|
|
3178
3856
|
async function callTool(name, args) {
|
|
3179
3857
|
try {
|
|
3180
3858
|
if (name === "terrain_generate") {
|
|
3181
|
-
const input =
|
|
3859
|
+
const { input, decided, unused } = parseGenerateRequest(args);
|
|
3182
3860
|
const projectRoot = process.cwd();
|
|
3183
3861
|
const assetSource = await resolveAssetSource(projectRoot);
|
|
3184
3862
|
const out = await resolveOutput(
|
|
@@ -3186,7 +3864,12 @@ async function callTool(name, args) {
|
|
|
3186
3864
|
input.out ?? relative(projectRoot, join(assetSource, "worlds", input.kit)),
|
|
3187
3865
|
assetSource
|
|
3188
3866
|
);
|
|
3189
|
-
|
|
3867
|
+
const { text: text2, cache } = await cookCached({ ...input, out, projectRoot, assetSource }, out);
|
|
3868
|
+
const { kit, out: _out, ...own } = input;
|
|
3869
|
+
const source = Object.keys(own).length === 0 ? `catalog:${kit}` : "cooked";
|
|
3870
|
+
return toolResult(
|
|
3871
|
+
JSON.stringify({ ...JSON.parse(text2), source, cache, decided, unused })
|
|
3872
|
+
);
|
|
3190
3873
|
}
|
|
3191
3874
|
if (name === "terrain_biome_new") {
|
|
3192
3875
|
const input = parseBiomeNewInput(args);
|
|
@@ -3216,7 +3899,15 @@ async function callTool(name, args) {
|
|
|
3216
3899
|
let text2;
|
|
3217
3900
|
try {
|
|
3218
3901
|
text2 = await cookInChild(
|
|
3219
|
-
{
|
|
3902
|
+
{
|
|
3903
|
+
assetSource,
|
|
3904
|
+
biome: input.name,
|
|
3905
|
+
kit: input.from,
|
|
3906
|
+
out,
|
|
3907
|
+
projectRoot,
|
|
3908
|
+
spec,
|
|
3909
|
+
ground: input.ground
|
|
3910
|
+
},
|
|
3220
3911
|
out
|
|
3221
3912
|
);
|
|
3222
3913
|
} catch (error) {
|