@threenative/terrain 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/AGENT_GUIDE.md +19 -4
  2. package/dist/editor/index.d.ts +160 -5
  3. package/dist/editor/index.js +3783 -1406
  4. package/dist/editor/server.d.ts +2 -2
  5. package/dist/editor/server.js +555 -121
  6. package/dist/editor/worker.d.ts +33 -1
  7. package/dist/editor/worker.js +444 -110
  8. package/dist/export.d.ts +11 -9
  9. package/dist/export.js +22 -34
  10. package/dist/index.d.ts +727 -73
  11. package/dist/index.js +2434 -553
  12. package/dist/kit.d.ts +56 -0
  13. package/dist/kit.js +2524 -0
  14. package/dist/mcp/cook-child.d.ts +2 -0
  15. package/dist/mcp/cook-child.js +3705 -0
  16. package/dist/mcp/server.d.ts +7 -0
  17. package/dist/mcp/server.js +3279 -0
  18. package/dist/{server-ByM2hmYJ.d.ts → server-C8Ydr_IM.d.ts} +3 -2
  19. package/dist/starter.d.ts +143 -0
  20. package/dist/starter.js +1030 -0
  21. package/dist/{terrain-gPnkCU6S.d.ts → terrain-B3DkduPw.d.ts} +3 -2
  22. package/dist/three.d.ts +1 -1
  23. package/dist/{types-Ant8-Axc.d.ts → types-CPYAc9vo.d.ts} +13 -4
  24. package/dist/world-package-B7KGYIou.d.ts +94 -0
  25. package/package.json +28 -6
  26. package/starter/alpine/README.md +77 -1
  27. package/starter/alpine/bake.mjs +4 -116
  28. package/starter/alpine/biome.data.json +114 -0
  29. package/starter/alpine/heightmap.r16 +0 -0
  30. package/starter/alpine/recipe.json +3 -66051
  31. package/starter/alpine/world.ts +45 -293
  32. package/starter/coastal/README.md +77 -1
  33. package/starter/coastal/bake.mjs +4 -116
  34. package/starter/coastal/biome.data.json +135 -0
  35. package/starter/coastal/heightmap.r16 +0 -0
  36. package/starter/coastal/recipe.json +3 -66051
  37. package/starter/coastal/sea.ts +49 -16
  38. package/starter/coastal/world.ts +53 -318
  39. package/starter/desert/README.md +77 -1
  40. package/starter/desert/bake.mjs +4 -116
  41. package/starter/desert/biome.data.json +114 -0
  42. package/starter/desert/heightmap.r16 +0 -0
  43. package/starter/desert/recipe.json +3 -66051
  44. package/starter/desert/world.ts +45 -293
  45. package/starter/forest/README.md +84 -4
  46. package/starter/forest/assets.json +32 -0
  47. package/starter/forest/bake.mjs +6 -116
  48. package/starter/forest/biome.data.json +150 -0
  49. package/starter/forest/heightmap.r16 +0 -0
  50. package/starter/forest/recipe.json +192 -4428
  51. package/starter/forest/sky.ts +11 -0
  52. package/starter/forest/water.ts +30 -20
  53. package/starter/forest/world.ts +86 -322
  54. package/starter/tundra/README.md +77 -1
  55. package/starter/tundra/bake.mjs +4 -116
  56. package/starter/tundra/biome.data.json +131 -0
  57. package/starter/tundra/heightmap.r16 +0 -0
  58. package/starter/tundra/recipe.json +18 -66066
  59. package/starter/tundra/world.ts +65 -319
  60. package/starter-assets.json +6 -0
  61. package/{starter-assets/credits.json → starter-credits.json} +12 -105
  62. package/starter-assets/bark_brown_02/bark_brown_02_diff_1k.jpg +0 -0
  63. package/starter-assets/bark_brown_02/bark_brown_02_nor_gl_1k.jpg +0 -0
  64. package/starter-assets/bark_brown_02/bark_brown_02_rough_1k.jpg +0 -0
  65. package/starter-assets/boulder_01/boulder-mid.glb +0 -0
  66. package/starter-assets/boulder_01/boulder-near.glb +0 -0
  67. package/starter-assets/cliff_side/cliff_side_ao_1k.jpg +0 -0
  68. package/starter-assets/cliff_side/cliff_side_diff_1k.jpg +0 -0
  69. package/starter-assets/cliff_side/cliff_side_nor_gl_1k.jpg +0 -0
  70. package/starter-assets/cliff_side/cliff_side_rough_1k.jpg +0 -0
  71. package/starter-assets/fern_02/fern_02_alpha_512.png +0 -0
  72. package/starter-assets/fern_02/fern_02_diff_512.jpg +0 -0
  73. package/starter-assets/fern_02/fern_02_nor_gl_512.jpg +0 -0
  74. package/starter-assets/fir_tree_01/fir-b-lod1.glb +0 -0
  75. package/starter-assets/fir_tree_01/fir-b-lod2.glb +0 -0
  76. package/starter-assets/fir_tree_01/fir-c-lod1.glb +0 -0
  77. package/starter-assets/fir_tree_01/fir-c-lod2.glb +0 -0
  78. package/starter-assets/fir_tree_01/fir_tree_01_twig_arm_1k.jpg +0 -0
  79. package/starter-assets/fir_tree_01/fir_tree_01_twig_diff_1k.jpg +0 -0
  80. package/starter-assets/fir_tree_01/fir_tree_01_twig_nor_gl_1k.jpg +0 -0
  81. package/starter-assets/forest_ground_04/forest_ground_04_ao_1k.jpg +0 -0
  82. package/starter-assets/forest_ground_04/forest_ground_04_diff_1k.jpg +0 -0
  83. package/starter-assets/forest_ground_04/forest_ground_04_nor_gl_1k.jpg +0 -0
  84. package/starter-assets/forest_ground_04/forest_ground_04_rough_1k.jpg +0 -0
  85. package/starter-assets/forest_leaves_02/forest_leaves_02_arm_512.jpg +0 -0
  86. package/starter-assets/forest_leaves_02/forest_leaves_02_diff_512.jpg +0 -0
  87. package/starter-assets/forest_leaves_02/forest_leaves_02_nor_gl_512.jpg +0 -0
  88. package/starter-assets/grass_medium_02/grass_medium_02_alpha_512.png +0 -0
  89. package/starter-assets/grass_medium_02/grass_medium_02_diff_512.jpg +0 -0
  90. package/starter-assets/grass_medium_02/grass_medium_02_nor_gl_512.jpg +0 -0
  91. package/starter-assets/hdri/kloofendal_48d_partly_cloudy_1k.hdr +0 -0
  92. package/starter-assets/leafy_grass/leafy_grass_ao_1k.jpg +0 -0
  93. package/starter-assets/leafy_grass/leafy_grass_diff_1k.jpg +0 -0
  94. package/starter-assets/leafy_grass/leafy_grass_nor_gl_1k.jpg +0 -0
  95. package/starter-assets/leafy_grass/leafy_grass_rough_1k.jpg +0 -0
  96. package/starter-assets/lichen_rock/lichen_rock_arm_512.jpg +0 -0
  97. package/starter-assets/lichen_rock/lichen_rock_diff_512.jpg +0 -0
  98. package/starter-assets/lichen_rock/lichen_rock_nor_gl_512.jpg +0 -0
  99. package/starter-assets/mossy_rock/mossy_rock_ao_1k.jpg +0 -0
  100. package/starter-assets/mossy_rock/mossy_rock_diff_1k.jpg +0 -0
  101. package/starter-assets/mossy_rock/mossy_rock_nor_gl_1k.jpg +0 -0
  102. package/starter-assets/mossy_rock/mossy_rock_rough_1k.jpg +0 -0
  103. package/starter-assets/needle-atlas.png +0 -0
  104. package/starter-assets/needle-surface.png +0 -0
  105. package/starter-assets/river_small_rocks/river_small_rocks_arm_512.jpg +0 -0
  106. package/starter-assets/river_small_rocks/river_small_rocks_diff_512.jpg +0 -0
  107. package/starter-assets/river_small_rocks/river_small_rocks_nor_gl_512.jpg +0 -0
  108. package/starter-assets/rock_boulder_dry/rock_boulder_dry_arm_512.jpg +0 -0
  109. package/starter-assets/rock_boulder_dry/rock_boulder_dry_diff_512.jpg +0 -0
  110. package/starter-assets/rock_boulder_dry/rock_boulder_dry_nor_gl_512.jpg +0 -0
  111. package/starter-assets/rocks/boulder-mid.glb +0 -0
  112. package/starter-assets/rocks/boulder-near.glb +0 -0
  113. package/starter-assets/rocks/boulder-prep.json +0 -37
  114. package/starter-assets/rocks/rock01-mid.glb +0 -0
  115. package/starter-assets/rocks/rock01-near.glb +0 -0
  116. package/starter-assets/rocks/rock01-prep.json +0 -37
  117. package/starter-assets/rocks/rock04-mid.glb +0 -0
  118. package/starter-assets/rocks/rock04-near.glb +0 -0
  119. package/starter-assets/rocks/rock04-prep.json +0 -37
  120. package/starter-assets/sand_01/sand_01_ao_1k.jpg +0 -0
  121. package/starter-assets/sand_01/sand_01_diff_1k.jpg +0 -0
  122. package/starter-assets/sand_01/sand_01_nor_gl_1k.jpg +0 -0
  123. package/starter-assets/sand_01/sand_01_rough_1k.jpg +0 -0
  124. package/starter-assets/snow_02/snow_02_ao_1k.jpg +0 -0
  125. package/starter-assets/snow_02/snow_02_diff_1k.jpg +0 -0
  126. package/starter-assets/snow_02/snow_02_nor_gl_1k.jpg +0 -0
  127. package/starter-assets/snow_02/snow_02_rough_1k.jpg +0 -0
@@ -1,118 +1,6 @@
1
- // Bakes this folder's recipe into a self-contained world package. Run it once from your game
2
- // project, then serve the folder it writes:
3
- // node src/terrain/tundra/bake.mjs [--assets <dir>] [--out <dir>]
4
- // The engine's `WorldCells` streams `world/world.json` and `loadTerrainSplat` textures its ground;
5
- // the game never evaluates terrain at runtime.
6
- import { copyFile, mkdir, readFile, writeFile } from "node:fs/promises";
7
- import { dirname, join, resolve } from "node:path";
8
- import { fileURLToPath } from "node:url";
9
- import { Terrain, applyPlacementOverrides, bakeWorldPackage } from "@threenative/terrain";
1
+ // Run with [--assets <dir>] [--out <dir>]; defaults to installed assets and ./world.
2
+ import { bakeKit } from "@threenative/terrain/kit";
10
3
 
11
- const here = dirname(fileURLToPath(import.meta.url));
12
-
13
- /** `--key value` after the script; `--assets` and `--out` default as noted below. */
14
- function flag(name, fallback) {
15
- const at = process.argv.indexOf(`--${name}`);
16
- return at === -1 ? fallback : resolve(process.argv[at + 1] ?? "");
17
- }
18
-
19
- // The installed kit ships its models and textures beside the package manifest, so a copied kit
20
- // finds them without asking the game for a path. `--assets` overrides that for a local checkout.
21
- const installed = dirname(fileURLToPath(import.meta.resolve("@threenative/terrain/package.json")));
22
- const assetsDir = flag("assets", join(installed, "starter-assets"));
23
- const outDir = flag("out", join(here, "world"));
24
-
25
- const recipe = JSON.parse(await readFile(join(here, "recipe.json"), "utf8"));
26
- const assetTable = JSON.parse(await readFile(join(here, "assets.json"), "utf8"));
27
- const surface = JSON.parse(await readFile(join(here, "surface.json"), "utf8"));
28
-
29
- const state = applyPlacementOverrides(
30
- Terrain.fromJSON(recipe.recipe).evaluate(),
31
- recipe.placementOverrides ?? {},
32
- );
33
-
34
- const assets = Object.fromEntries(
35
- Object.entries(assetTable).map(([id, spec]) => [
36
- id,
37
- {
38
- bounds: spec.bounds,
39
- glb: `models/${spec.near.split("/").at(-1)}`,
40
- ...(spec.mid
41
- ? { lods: [{ distance: spec.midDistance, glb: `models/${spec.mid.split("/").at(-1)}` }] }
42
- : {}),
43
- maxDistance: spec.maxDistance,
44
- },
45
- ]),
46
- );
47
-
48
- const started = performance.now();
49
- const { manifest, splat, files } = bakeWorldPackage(state, {
50
- assets,
51
- layers: { table: "terrain-table.json" },
4
+ await bakeKit(import.meta.url, {
5
+ sky: "hdri/kloofendal_48d_partly_cloudy_1k.hdr",
52
6
  });
53
- const written = new Map();
54
-
55
- async function write(relative, bytes) {
56
- await mkdir(join(outDir, dirname(relative)), { recursive: true });
57
- await writeFile(join(outDir, relative), bytes);
58
- written.set(relative, bytes.length ?? bytes.byteLength);
59
- }
60
-
61
- async function copy(from, to) {
62
- await mkdir(join(outDir, dirname(to)), { recursive: true });
63
- await copyFile(join(assetsDir, from), join(outDir, to));
64
- written.set(to, (await readFile(join(outDir, to))).byteLength);
65
- }
66
-
67
- await write("world.json", `${JSON.stringify(manifest, null, 2)}\n`);
68
- // The lake and river the generator evaluated, so the game draws the water the bake shaped.
69
- const round = (value) => Math.round(value * 1_000) / 1_000;
70
- await write(
71
- "water.json",
72
- `${JSON.stringify(
73
- {
74
- lakes: state.waters.map((lake) => ({
75
- id: lake.id,
76
- at: lake.at,
77
- radius: lake.radius,
78
- level: lake.level,
79
- })),
80
- rivers: state.rivers.map((river) => ({
81
- id: river.id,
82
- width: round(river.width),
83
- points: river.points.map((point) => point.map(round)),
84
- })),
85
- },
86
- null,
87
- 2,
88
- )}\n`,
89
- );
90
- for (const [name, bytes] of Object.entries(files)) await write(name, bytes);
91
- for (const spec of Object.values(assetTable)) {
92
- await copy(spec.near, `models/${spec.near.split("/").at(-1)}`);
93
- if (spec.mid) await copy(spec.mid, `models/${spec.mid.split("/").at(-1)}`);
94
- }
95
- // The sky the props are lit by (CC0 Poly Haven Kloofendal); world.ts gives it to their materials.
96
- await copy("hdri/kloofendal_48d_partly_cloudy_1k.hdr", "sky.hdr");
97
- for (const layer of [surface.base, ...surface.layers]) {
98
- const source = surface.sources[layer.id];
99
- await copy(source.diff, `${surface.textures}/${layer.id}_diff.jpg`);
100
- await copy(source.nrm, `${surface.textures}/${layer.id}_nrm.jpg`);
101
- }
102
- // `sources` is the bake's own lookup: the runtime reads only base/layers/splat/textures.
103
- await write(
104
- "terrain-table.json",
105
- `${JSON.stringify({ ...surface, splat, textures: "textures" }, null, 2)}\n`,
106
- );
107
-
108
- const perAsset = {};
109
- for (const cell of manifest.cells)
110
- for (const run of cell.runs) perAsset[run.asset] = (perAsset[run.asset] ?? 0) + run.count;
111
- const total = [...written.values()].reduce((sum, bytes) => sum + bytes, 0);
112
- console.log(
113
- `${Object.entries(perAsset)
114
- .map(([asset, count]) => `${asset} ${String(count)}`)
115
- .join(", ")} placements; ${[...written]
116
- .map(([name, bytes]) => `${name} ${String(bytes)} B`)
117
- .join(", ")}; ${String(total)} B total; ${Math.round(performance.now() - started)} ms`,
118
- );
@@ -0,0 +1,131 @@
1
+ {
2
+ "look": "tundra",
3
+ "bake": {
4
+ "file": "tundra",
5
+ "key": null
6
+ },
7
+ "landform": "tundra",
8
+ "sizeMeters": 512,
9
+ "seed": 131,
10
+ "stream": "ordered",
11
+ "cover": {
12
+ "ground": "mats",
13
+ "seed": 466468,
14
+ "attempts": 80000,
15
+ "stoneRadius": 1.9,
16
+ "clearings": [[166, 180, 10]]
17
+ },
18
+ "foliage": [
19
+ {
20
+ "species": "sapling",
21
+ "density": 55,
22
+ "slope": [0, 32],
23
+ "height": null,
24
+ "spacing": [3.4, 3.4],
25
+ "collision": "trunk",
26
+ "stands": false,
27
+ "grassThreshold": 0.18,
28
+ "standThreshold": 0.42,
29
+ "far": null
30
+ }
31
+ ],
32
+ "grass": [
33
+ {
34
+ "species": "grass",
35
+ "density": 1,
36
+ "slope": [0, 30],
37
+ "height": null,
38
+ "spacing": 1.8,
39
+ "slopeFalloff": 22,
40
+ "heightFalloff": 28,
41
+ "mats": [0.47, 0.3],
42
+ "waterMargin": 7.5,
43
+ "beach": null,
44
+ "detailSpacing": 0.5,
45
+ "drift": {
46
+ "field": "mats",
47
+ "frequency": [1, 1],
48
+ "offset": 0,
49
+ "amplitude": 1,
50
+ "band": [0.45, 0.3]
51
+ },
52
+ "bladeScale": 0.45,
53
+ "bladeJitter": 0.3,
54
+ "scrubChance": 0.22,
55
+ "scrubScale": 0.55,
56
+ "scrubJitter": 0.5,
57
+ "scrubBush": true,
58
+ "shoreGround": false,
59
+ "cobbledBed": false
60
+ }
61
+ ],
62
+ "layers": [
63
+ {
64
+ "layer": "alpine",
65
+ "from": 0.6,
66
+ "to": 1.2
67
+ },
68
+ {
69
+ "layer": "rock",
70
+ "from": 0.06,
71
+ "to": 1.25
72
+ },
73
+ {
74
+ "layer": "treeline",
75
+ "from": 6.5,
76
+ "to": 10
77
+ },
78
+ {
79
+ "layer": "cap",
80
+ "from": 14,
81
+ "to": 17
82
+ },
83
+ {
84
+ "layer": "desertRock",
85
+ "from": 0.18,
86
+ "to": 0.48
87
+ },
88
+ {
89
+ "layer": "alpineRock",
90
+ "from": 0.06,
91
+ "to": 0.14
92
+ },
93
+ {
94
+ "layer": "alpineHollow",
95
+ "from": 0.05,
96
+ "to": 0.12
97
+ },
98
+ {
99
+ "layer": "snow",
100
+ "from": 0.15,
101
+ "to": 0.45,
102
+ "shedFrom": 0.04,
103
+ "shedTo": 0.22
104
+ }
105
+ ],
106
+ "water": [
107
+ {
108
+ "kind": "river",
109
+ "width": 5.32
110
+ },
111
+ {
112
+ "kind": "river",
113
+ "width": 3.04
114
+ },
115
+ {
116
+ "kind": "lake",
117
+ "radius": 34
118
+ },
119
+ {
120
+ "kind": "lake",
121
+ "radius": 46
122
+ }
123
+ ],
124
+ "spawn": {
125
+ "at": [180, 160],
126
+ "cameraOffset": [28, 24, 42],
127
+ "focus": [150, 160]
128
+ },
129
+ "species": ["boulder", "bush", "riverrock", "sapling", "scree", "scrub"],
130
+ "aliases": ["tundra", "arctic", "ice"]
131
+ }
Binary file