@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
@@ -0,0 +1,162 @@
1
+ // Every starter file this game can ask for, in one table.
2
+ //
3
+ // The names live here and nowhere else so that replacing the starter art is one edit in one file:
4
+ // a game that ships its own models and maps rewrites these paths, or points them at a directory it
5
+ // owns, and nothing under `packages/terrain` changes. Nothing in this file loads anything — the
6
+ // loaders in `src/render/` ask for the paths, and a path that is absent leaves the surface on its
7
+ // own colours rather than failing the world.
8
+ //
9
+ // Two kinds of entry, and the difference is the caller's: a `map` is a PBR image the game binds,
10
+ // and a `model` is a placement asset a variant resolves to. Neither carries a scale, a material or
11
+ // a role decision; those are the render modules' business.
12
+
13
+ /** The surfaces that can cover ground. Order is the blend order in `src/render/ground/terrain.ts`. */
14
+ export type LayerKey = "grass" | "dirt" | "rock" | "moss" | "sand" | "snow";
15
+
16
+ /**
17
+ * One ground layer's PBR images: an albedo, and relief where the surface shows it.
18
+ *
19
+ * The ground material samples 16 textures at most; the starter spends them with normals on four
20
+ * layers (not sand or snow), so a replacement that gives all six a normal map is refused by WebGPU.
21
+ */
22
+ export interface IGroundMaps {
23
+ readonly diffuse: string;
24
+ readonly normal?: string;
25
+ /** Only the portable export reads these two; the runtime ground derives its own. */
26
+ readonly occlusion?: string;
27
+ readonly roughness?: string;
28
+ }
29
+
30
+ /** The ground's layers, and the file each one draws with. */
31
+ export const GROUND_MAPS: Record<LayerKey, IGroundMaps> = {
32
+ // The mesa look draws its flats with the `grass` slot: Poly Haven's aerial beach, 30 m of sand
33
+ // the wind has rippled. Its colour is a plain grey-tan the biome's `grassTint` turns red; its
34
+ // normal map is the ripples. The red_sand scan it replaces was one flat tone with no relief, so
35
+ // the dunes drew as blurred paint at every resolution.
36
+ // Gravel pavement is the dirt: Poly Haven's rocky trail, red-brown grit strewn with pebbles.
37
+ dirt: {
38
+ diffuse: "rocky_trail_02/rocky_trail_02_diff_1k.jpg",
39
+ normal: "rocky_trail_02/rocky_trail_02_nor_gl_1k.jpg",
40
+ },
41
+ grass: {
42
+ diffuse: "aerial_beach_01/aerial_beach_01_diff_2k.jpg",
43
+ normal: "aerial_beach_01/aerial_beach_01_nor_gl_2k.jpg",
44
+ },
45
+ moss: {
46
+ diffuse: "cliff_side/cliff_side_diff_1k.jpg",
47
+ normal: "cliff_side/cliff_side_nor_gl_1k.jpg",
48
+ },
49
+ rock: {
50
+ diffuse: "cliff_side/cliff_side_diff_1k.jpg",
51
+ normal: "cliff_side/cliff_side_nor_gl_1k.jpg",
52
+ },
53
+ sand: { diffuse: "aerial_beach_01/aerial_beach_01_diff_2k.jpg" },
54
+ snow: { diffuse: "snow_02/snow_02_diff_1k.jpg" },
55
+ };
56
+
57
+ /** Metres one ground tile spans, per layer. The size of a pattern, not of the file. */
58
+ export const GROUND_TILE: Record<LayerKey, number> = {
59
+ dirt: 2.4,
60
+ // The scan spans 30 m; at 7 m its ripples stand 12-25 cm apart, as wind ripples do.
61
+ grass: 7,
62
+ moss: 3.6,
63
+ rock: 3.8,
64
+ sand: 7,
65
+ snow: 12,
66
+ };
67
+
68
+ /** The cliffs' rock face: Poly Haven's `rock_face` (CC0), dark cracked plates. */
69
+ export const ROCKFACE_MAPS: IGroundMaps = {
70
+ diffuse: "rock_face/rock_face_diff_1k.jpg",
71
+ normal: "rock_face/rock_face_nor_gl_1k.jpg",
72
+ };
73
+
74
+ /** One mapped prop surface's albedo, tangent-space normal and roughness. */
75
+ export interface ISurfaceMaps {
76
+ readonly diffuse: string;
77
+ readonly normal: string;
78
+ readonly roughness: string;
79
+ }
80
+
81
+ /** CC0 dry stone for beach and desert props; ARM uses AO in R and roughness in G. */
82
+ export const DRY_STONE_MAPS = {
83
+ diffuse: "rock_boulder_dry/rock_boulder_dry_diff_512.jpg",
84
+ normal: "rock_boulder_dry/rock_boulder_dry_nor_gl_512.jpg",
85
+ arm: "rock_boulder_dry/rock_boulder_dry_arm_512.jpg",
86
+ } as const;
87
+
88
+ /** The bark and stone the props bind, and the soil the bases of both fade into. */
89
+ export const PROP_MAPS: Record<"bark" | "stone", ISurfaceMaps> = {
90
+ bark: {
91
+ diffuse: "bark_brown_02/bark_brown_02_diff_1k.jpg",
92
+ normal: "bark_brown_02/bark_brown_02_nor_gl_1k.jpg",
93
+ roughness: "bark_brown_02/bark_brown_02_rough_1k.jpg",
94
+ },
95
+ stone: {
96
+ diffuse: "mossy_rock/mossy_rock_diff_1k.jpg",
97
+ normal: "mossy_rock/mossy_rock_nor_gl_1k.jpg",
98
+ roughness: "mossy_rock/mossy_rock_rough_1k.jpg",
99
+ },
100
+ };
101
+
102
+ /** The forest floor the props' bases blend into. */
103
+ export const SOIL_MAP = "forest_ground_04/forest_ground_04_diff_1k.jpg";
104
+
105
+ /** The generated needle atlas, and the relief it carries in RG with occlusion in B. */
106
+ export const NEEDLE_ATLAS = "needle-atlas.png";
107
+ export const NEEDLE_SURFACE = "needle-surface.png";
108
+
109
+ /** The prepared fir's twig atlas: colour, tangent-space normal, and the packed arms map. */
110
+ export const FIR_MAPS = {
111
+ arms: "fir_tree_01/fir_tree_01_twig_arm_1k.jpg",
112
+ normal: "fir_tree_01/fir_tree_01_twig_nor_gl_1k.jpg",
113
+ surface: "fir_tree_01/fir_tree_01_twig_diff_1k.jpg",
114
+ } as const;
115
+
116
+ /**
117
+ * Poly Haven's `tree_small_02` (CC0), grown to forest height as leaf cards: two silhouettes, each a
118
+ * `-near.glb` and a `-mid.glb` (`scripts/prep/prep-polyhaven-broadleaf.py`).
119
+ */
120
+ export const BROADLEAF_TREES = ["tree_small_02/broadleaf", "tree_small_02/broadleaf-b"] as const;
121
+
122
+ /** The fern's own atlas: a photographed frond and its separate cut-out alpha. */
123
+ export const FERN_MAPS = {
124
+ alpha: "fern_02/fern_02_alpha_512.png",
125
+ diffuse: "fern_02/fern_02_diff_512.jpg",
126
+ } as const;
127
+
128
+ /** One prepared placement file: what it is, which variant it fills, and which detail level it is. */
129
+ export interface IPreparedFile {
130
+ readonly asset: string;
131
+ readonly level: number;
132
+ readonly path: string;
133
+ readonly variant: number;
134
+ }
135
+
136
+ /**
137
+ * The prepared files, in the order they are asked for.
138
+ *
139
+ * **Nothing on this list any more.** The three CC0 rocks and the two prepared firs were replaced by
140
+ * the licensed Landscape Pro species in `src/render/props/pack.ts` — real photoscanned stone at 7,178
141
+ * triangles where the CC0 set's were 1–2k, and real pines where the fir's crown measured 0.3% of
142
+ * its own silhouette at the tree budget (`credits.json` has that number, and it is why the starter
143
+ * kept its procedural spruce). The list and its loader stay because they are how the next source is
144
+ * measured, and because a prepared file that is not there is not an error: this map is empty on CI,
145
+ * on a fresh clone and in a review, and the procedural variants are what draw there.
146
+ *
147
+ * A species that IS added back comes in as one entry per detail level, because a variant with a near
148
+ * level and no mid level is a variant whose middle distance pops. Three rocks at both of their levels
149
+ * was six draws for stone the eye cannot tell apart at meadow distance, against the starter's
150
+ * twenty-four-draw ceiling for the whole meadow — which is the trade this list now records.
151
+ */
152
+ export const PREPARED: readonly IPreparedFile[] = [
153
+ // The committed fallback's stone: two photoscanned CC0 rocks at both levels. Where the licensed
154
+ // pack loaded, its boulders take these same indices 1 and 2 (the pack's parts are merged after these), so
155
+ // this only draws on CI, on a fresh clone and in a review — which is the starter that ships, and
156
+ // a procedural lump there is the wrong first impression. Two, not three: three at two levels put
157
+ // the pack-less meadow one draw over its ceiling.
158
+ { asset: "boulder", level: 0, path: "rocks/rock01-near.glb", variant: 1 },
159
+ { asset: "boulder", level: 1, path: "rocks/rock01-mid.glb", variant: 1 },
160
+ { asset: "boulder", level: 0, path: "rocks/boulder-near.glb", variant: 2 },
161
+ { asset: "boulder", level: 1, path: "rocks/boulder-mid.glb", variant: 2 },
162
+ ];
@@ -0,0 +1,47 @@
1
+ import type { IHeightfieldCollarWalk } from "@threenative/core/world";
2
+
3
+ /**
4
+ * Triangle pairs a slice spans: the survey's 1024-sample perimeter makes eight rings 16 384
5
+ * triangles, about one frame's worth of collider build behind the loading curtain.
6
+ */
7
+ const RINGS_PER_SLICE = 8;
8
+
9
+ /** One fixed trimesh's worth of the walk band: its own vertices, and indices rebased onto them. */
10
+ export interface IWalkBandSlice {
11
+ /** Vertex triples at the collar's own heights: a view of the drawn buffer, not a resample. */
12
+ readonly vertices: Float32Array;
13
+ /** The triangles of the rings this slice covers, addressing `vertices` from zero. */
14
+ readonly indices: Uint32Array;
15
+ }
16
+
17
+ /**
18
+ * The walk band's drawn triangles, cut into per-ring groups that each become one fixed body.
19
+ *
20
+ * The collar builds `walk` as a ring grid, so the triangles of ring `r` are one contiguous run of
21
+ * its index buffer and they address the two rings either side of it: every slice is a view of the
22
+ * buffers the collar already drew, and nothing is rebuilt. The last ring of a slice is the first
23
+ * ring of the next one — the same heights, duplicated into both — because two bodies that met over
24
+ * a gap instead of a shared edge would be a hole a foot falls through.
25
+ */
26
+ export function walkBandSlices(band: IHeightfieldCollarWalk, perimeter: number): IWalkBandSlice[] {
27
+ const index = band.geometry.getIndex();
28
+ if (index === null)
29
+ throw new Error("TN_WALK_BAND_INDEX: the collar's walk band has no index buffer.");
30
+ const positions = band.geometry.getAttribute("position").array;
31
+ const indices = index.array;
32
+ if (!(positions instanceof Float32Array) || !(indices instanceof Uint32Array))
33
+ throw new Error("TN_WALK_BAND_BUFFER: the collar's walk band is not a Float32/Uint32 grid.");
34
+ const rings = indices.length / (perimeter * 6);
35
+ const slices: IWalkBandSlice[] = [];
36
+ for (let ring = 0; ring < rings; ring += RINGS_PER_SLICE) {
37
+ const last = Math.min(ring + RINGS_PER_SLICE, rings);
38
+ const base = ring * perimeter;
39
+ slices.push({
40
+ // Rings `ring` to `last` inclusive: one more than the triangle pairs, so both bodies own the seam.
41
+ vertices: positions.subarray(base * 3, (last + 1) * perimeter * 3),
42
+ // Rebasing copies, because this runs over a view of the collar's drawn triangles.
43
+ indices: indices.subarray(base * 6, last * perimeter * 6).map((vertex) => vertex - base),
44
+ });
45
+ }
46
+ return slices;
47
+ }
@@ -0,0 +1,74 @@
1
+ import { type Heightfield, type IWaterOcean, WaterBodies } from "@threenative/core/world";
2
+ import {
3
+ type IBakedLake,
4
+ type IBakedRiver,
5
+ LAKE_REACH,
6
+ RIVER_FLOW_MPS,
7
+ } from "../render/water/river.js";
8
+
9
+ /**
10
+ * The baked water rows as the one mechanism reads them, and the queries the swimmer asks.
11
+ *
12
+ * A river stands at its spline's own heights across `WATER_RIBBON_REACH` widths of its bed, and
13
+ * carries the flow its ripples are drawn at. A lake stands level over the waterline its basin
14
+ * measures, `LAKE_REACH` times out, capped at the radius its biome row names. A sea stands at its
15
+ * level out to the reach of its drawn surface. One store answers the drawn geometry and the swimmer,
16
+ * so the height a player swims at and the flow that carries them cannot disagree.
17
+ */
18
+ export function waterBodies(
19
+ rivers: readonly IBakedRiver[],
20
+ lakes: readonly IBakedLake[],
21
+ field: Heightfield,
22
+ sea?: IWaterOcean,
23
+ ): WaterBodies {
24
+ return new WaterBodies({
25
+ field,
26
+ lakes: lakes.map((lake) => ({
27
+ at: lake.at,
28
+ level: lake.level,
29
+ margin: LAKE_REACH,
30
+ radius: lake.radius,
31
+ })),
32
+ ocean: sea,
33
+ ribbons: rivers.map((river) => ({
34
+ flow: RIVER_FLOW_MPS,
35
+ points: river.points,
36
+ width: river.width,
37
+ })),
38
+ });
39
+ }
40
+
41
+ /**
42
+ * The height of the water the player sees at (x, z), or `undefined` where none is drawn: the query
43
+ * `CharacterBody3D.water` swims in. `sea` is the sea the world draws, where it draws one.
44
+ *
45
+ * Ground above the surface is dry by itself, because the body measures its immersion against this
46
+ * height.
47
+ */
48
+ export function waterSurfaceAt(
49
+ rivers: readonly IBakedRiver[],
50
+ lakes: readonly IBakedLake[],
51
+ field: Heightfield,
52
+ sea?: IWaterOcean,
53
+ ): (x: number, z: number) => number | undefined {
54
+ const bodies = waterBodies(rivers, lakes, field, sea);
55
+ return (x, z) => bodies.surfaceAt(x, z);
56
+ }
57
+
58
+ /**
59
+ * The flow the river carries a body with at (x, z), in m/s, or `undefined` where there is no water:
60
+ * the query `CharacterBody3D.waterCurrent` drifts a swimmer with. A lake and the sea stand still and
61
+ * report zero. `sea` is the sea the world draws, where it draws one.
62
+ *
63
+ * The direction is the downstream tangent at the nearest spline station — the direction the surface
64
+ * is drawn flowing in — at `RIVER_FLOW_MPS`, so the ripples and the swimmer travel at one speed.
65
+ */
66
+ export function waterCurrentAt(
67
+ rivers: readonly IBakedRiver[],
68
+ lakes: readonly IBakedLake[],
69
+ field: Heightfield,
70
+ sea?: IWaterOcean,
71
+ ): (x: number, z: number) => { x: number; z: number } | undefined {
72
+ const bodies = waterBodies(rivers, lakes, field, sea);
73
+ return (x, z) => bodies.currentAt(x, z);
74
+ }
@@ -0,0 +1,13 @@
1
+ import type { IAssetLoader } from "@threenative/core";
2
+ import { fetchBakedFile } from "./render/bakedFile.js";
3
+ import type { IBakedWorld } from "./render/ground/terrain.js";
4
+ import { WORLD } from "./render/worldNames.js";
5
+
6
+ /**
7
+ * The baked terrain arrays (`world/<WORLD>.json`, written by `bake.mjs`), fetched rather than imported:
8
+ * as a JSON module the 6 MB file costs seconds to compile before the first frame.
9
+ */
10
+ export async function loadBakedWorld(assets: Pick<IAssetLoader, "resolve">): Promise<IBakedWorld> {
11
+ const response = await fetchBakedFile(assets, `world/${WORLD}.json`);
12
+ return (await response.json()) as IBakedWorld;
13
+ }
@@ -1,126 +1,69 @@
1
1
  # Forest starter kit
2
2
 
3
- A 512 m forest on real elevations (USGS 3DEP), with hydraulic and thermal erosion, clustered fir
4
- stands, young firs and boulder fields. It is game source: once copied, every file is yours to edit.
3
+ A 512 m broadleaf valley on real elevations (Sprague Lake, USGS 3DEP), eroded, with its lake and
4
+ creek, streamed ground, scanned trees, shrubs, ferns, flowers, fallen wood and rocks, a mountain
5
+ ring with a surveyed massif, a physical sky and a walking player. It is game source: once copied,
6
+ every file is yours to edit.
5
7
 
6
- | File | What it decides |
7
- | --- | --- |
8
- | `recipe.json` | The terrain and the scatter: seed, size, erosion, `count`, `minDistance`, slope limits, `scale`, masks. |
9
- | `assets.json` | Each prop's models, LOD distance, draw distance and bounds; `"tree": true` marks the art a landform cook plants the biome's own tree with. |
10
- | `surface.json` | The ground: texture layers, tiles, tints, far tiles and blend thresholds. |
11
- | `bake.mjs` | Writes the world package and `world/water.json` (the lake and river) from the three files above. |
12
- | `world.ts` | `addForest(ctx, follow)`: terrain, props, shadows, collision; `COLLIDERS` per prop. |
13
- | `water.ts` | `addForestWater(ctx, water, field)`: the lake's surface (`WaterSurface3D`) and the river's ribbon, from `water.json`. |
14
- | `sky.ts` | `forestDaylight(follow)`: sun, sky, fill, haze, exposure and tone curve. |
15
-
16
- Art is CC0 (Poly Haven); provenance is in `@threenative/terrain/starter-credits.json`.
8
+ All art is CC0 (Poly Haven, Quaternius). Provenance is in `@threenative/terrain/starter-credits.json`.
17
9
 
18
10
  ## Three steps
19
11
 
20
12
  1. Copy `node_modules/@threenative/terrain/starter/forest` to `src/terrain/forest`.
21
- 2. Run `node src/terrain/forest/bake.mjs --out assets/terrain/forest`. The bake imports both
22
- `@threenative/terrain` and `@threenative/assets`, so install them as devDependencies
23
- (`npm install --save-dev @threenative/terrain @threenative/assets`); `three` must be installed
24
- too, because `@threenative/terrain` declares it as a peer dependency. The same recipe always
25
- writes the same bytes.
26
- 3. Add it to a scene:
27
-
28
- ```ts
29
- import { forestDaylight } from "../terrain/forest/sky.js";
30
- import { addForest } from "../terrain/forest/world.js";
31
-
32
- // In Scene.load (it awaits the package) — `player` is what the world streams around.
33
- const forest = await addForest(ctx, player);
34
- // In Scene.enter.
35
- ctx.add(forestDaylight(ctx.camera));
36
- ```
37
-
38
- `addForest` resolves once the ground can be stood on: one heightfield collider covers the whole
39
- world before it returns. Set the camera's `far` to at least the sky size in `sky.ts` (5000 m).
13
+ 2. Install the bake's tools, then bake:
14
+
15
+ ```sh
16
+ npm install --save-dev @threenative/terrain tsx
17
+ node src/terrain/forest/bake.mjs
18
+ ```
19
+
20
+ The bake writes `assets/terrain/forest/` (`--out <dir>` moves it): the baked world under
21
+ `world/`, and the art it draws, copied from the terrain package's starter assets. It downloads
22
+ those once and checks their hash. The same kit always bakes the same bytes. Keep the starter
23
+ `mannequin.glb` in `assets/`: it is the player.
24
+ 3. Start the game on the forest scene:
25
+
26
+ ```ts
27
+ import { defineGame } from "@threenative/core";
28
+ import { type IPhysicsContext, rapier } from "@threenative/physics";
29
+ import { FOREST_GAME, ForestScene } from "./terrain/forest/scene.js";
30
+ import type { TerrainState } from "./terrain/forest/sceneState.js";
31
+
32
+ export default defineGame<TerrainState, IPhysicsContext>({
33
+ ...FOREST_GAME,
34
+ plugins: [rapier({ deterministicRestart: true })],
35
+ scenes: { forest: ForestScene },
36
+ start: "forest",
37
+ });
38
+ ```
39
+
40
+ `FOREST_GAME` holds the camera (60 degrees, 5000 m far plane, for the sky), the input map (WASD or
41
+ arrows, Space jump, Shift sprint, pointer look, V cycles the benchmark views, L toggles the sun) and
42
+ the renderer. Spread it first and override any field after it.
43
+
44
+ ## What each part decides
45
+
46
+ | Path | What it decides |
47
+ | --- | --- |
48
+ | `recipe.json` | The landform: survey, erosion, lake bed, creek, road and pad; its `world` row names the far ring and its massif, the ground layers and the art copied. |
49
+ | `bake.mjs` | One `bakeKit` call that passes this kit's look (palette, ground maps, canopy) and prop policy. |
50
+ | `biome.data.json` | Where the stands, understorey, rocks and ground cover grow (`bakeBiome`). |
51
+ | `scene.ts` | `ForestScene` and `FOREST_GAME`: load, spawn, the player, the views and the frame facts it reports. |
52
+ | `world/terrainAssets.ts` | Every art path the forest asks for. Replace the art by editing this table. |
53
+ | `render/biomes.ts` | The forest's look row: sun, sky, haze, exposure, tints and ground cover. |
54
+ | `render/ground/` | The ground material, ground cover and the far collar; the streamed tiles and their collar morph come from `@threenative/terrain/starter`. |
55
+ | `render/props/` | The prop pack (`pack.ts` names each species' scan and size), materials, wind and far trees. |
56
+ | `render/sky/`, `render/water/` | The sky, atmosphere and post chain; the lake and creek surfaces. |
57
+
58
+ `assets.json` and `surface.json` are the inputs the `terrain_generate` MCP tool cooks a world.glb
59
+ from, with `recipe.json` and `heightmap.r16`. The forest bake does not read those two.
40
60
 
41
61
  ## Changing it
42
62
 
43
- - **A prop's collider:** edit its row in `COLLIDERS` in `world.ts` (`capsule`, `sphere` or `null`).
44
- - **A prop's model:** point `assets.json` at another glTF with its bounds, then re-bake.
45
- - **The layout:** edit `recipe.json` (or open it in the terrain editor), then re-bake.
46
- - **The water:** the recipe's `lake-bed`, `river` and `lake` layers set where it lies and how deep;
47
- `water.ts` sets how it looks.
48
- - **The look:** `surface.json` for the ground, `sky.ts` for the light, `PROP_SKY_LIGHT` in
49
- `world.ts` for how strongly the sky lights the props and `GROUND_SPECULAR` for the sheen on the
50
- ground (0 is matte; three's default is 1).
51
-
52
- ## Edit at startup, without rebaking
53
-
54
- The copied `world.ts` loads its own `surface.json` as the ground table on every startup.
55
- Edit tints, tiling and blend thresholds there, or the material graph and prop dressing in
56
- `world.ts`, then reload. The package's `terrain-table.json` remains the baked default for
57
- package-only consumers; its splat masks and texture descriptors still supply the ground data.
58
- A source table cannot name a mask that the bake did not produce.
59
-
60
- Add `edits` to the existing `spec` in your copied `world.ts`. Read real stable IDs from the
61
- package's `placement-ids.json` (named by `world.json.placementIds`); these example IDs are placeholders:
62
-
63
- ```ts
64
- edits: {
65
- assets: {
66
- accent: { glb: "props/accent.glb", bounds: { min: [-1, -1, -1], max: [1, 1, 1] } },
67
- },
68
- remove: ["promote-id"],
69
- clear: [{ center: [40, 18], radius: 6 }], // Optional assets: ["fir"] filter.
70
- overrides: {
71
- "move-id": { position: [12, 0, -30], quaternion: [0, 0, 0, 1], scale: [1, 1, 1] },
72
- },
73
- add: [{ id: "camp-accent", asset: "accent", position: [44, 0, 20],
74
- quaternion: [0, 0, 0, 1], scale: [1, 1, 1], grounding: true }],
75
- },
76
- ```
77
-
78
- `assets` replaces or adds a kind; copy the GLB into the served package directory first.
79
- GLB and LOD paths are package-relative, with no URL scheme, leading slash or `..` segment;
80
- provide accurate model-local `bounds`. The existing `COLLIDERS` table and dress function still
81
- choose each kind's collision and appearance. Positions must lie inside the world's extent,
82
- quaternions must be nonzero, values finite and scale uniform. Grounding defaults on and sets
83
- the origin Y to `field.heightAt(x, z)`; `grounding: false` preserves the authored Y.
84
-
85
- Edits run in the order shown: assets, remove, clear, overrides, add. A clear skips IDs named
86
- by overrides. Removing and overriding the same ID throws; additions need new IDs. Unmatched
87
- removal/override IDs warn and appear in `editReport.unmatched`. Old packages work without a
88
- sidecar for assets, clear and add; ID edits need one re-bake to write the sidecar. Without
89
- `edits`, the decoded manifest and placement bytes pass through unchanged.
90
-
91
- Promote only a few props to ordinary Three objects: remove their IDs from the instances,
92
- then use the returned `editReport.removed` in the scene. This example replaces each with a
93
- game-owned glowing box; use your own geometry, material, light and collision shape:
94
-
95
- ```ts
96
- import { CollisionShape3D, RigidBody3D } from "@threenative/physics";
97
- import { BoxGeometry, Mesh, MeshStandardMaterial, PointLight } from "three";
98
-
99
- const loaded = await addForest(ctx, player);
100
- for (const p of loaded.editReport.removed) {
101
- const mesh = new Mesh(new BoxGeometry(1, 1, 1), new MeshStandardMaterial({ color: 0xffbb66 }));
102
- mesh.position.set(p.position[0], loaded.field.heightAt(p.position[0], p.position[2]), p.position[2]);
103
- mesh.quaternion.fromArray(p.quaternion);
104
- mesh.scale.setScalar(p.scale);
105
- mesh.castShadow = mesh.receiveShadow = true;
106
- mesh.add(new PointLight(0xffaa55, 12, 6));
107
- ctx.add(mesh);
108
- const body = new RigidBody3D({ object: mesh, physics: ctx.physics, type: "fixed",
109
- shape: CollisionShape3D.box(p.scale, p.scale, p.scale) });
110
- ctx.entities.add(`promoted.${p.id}`, { dispose() {
111
- body.dispose(); mesh.removeFromParent(); mesh.geometry.dispose(); mesh.material.dispose();
112
- } });
113
- }
114
- ```
115
-
116
- Rendering, nearby prop collision, dressing and returned `manifest`, `placements` and
117
- `placementIds` all use the edited records. `clear` removals are not in the promotion report.
118
- The separate `editWorldPlacements` helper and its types are exported from
119
- `@threenative/terrain/starter` for callers that already own decoded package data.
120
-
121
- Shape, topology, erosion, mask painting, distribution rules and water still require regeneration.
122
- Changing cooked ground images requires the bake/cook texture normalization step; editing the
123
- game table cannot replace baked texture descriptors or introduce new channels. To replace the
124
- props' environment image at runtime, copy an HDR into the served package, change
125
- `spec.lighting.sky` in `world.ts` to its package-relative path, then reload. The daylight and
126
- background remain game choices in `sky.ts`. Package-only exports do not run these source edits.
63
+ - **The landform:** edit `recipe.json`, then bake again.
64
+ - **What grows where:** edit `biome.data.json`, then bake again.
65
+ - **A model or map:** edit its path in `world/terrainAssets.ts` or `render/props/pack.ts`, add the
66
+ file under `assets/terrain/forest/`, and reload.
67
+ - **The look:** edit `render/biomes.ts` (the forest row), then reload.
68
+ - **A new environment:** copy this kit under a new name and follow
69
+ `node_modules/@threenative/terrain/docs/authoring/new-environment.md`.
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "fir": {
3
- "near": "fir_tree_01/fir-b-lod1.glb",
3
+ "near": "tree_small_02/broadleaf-near.glb",
4
+ "mid": "tree_small_02/broadleaf-mid.glb",
5
+ "midDistance": 45,
4
6
  "maxDistance": 600,
5
7
  "bounds": {
6
- "min": [-2.869, 0, -3.619],
7
- "max": [2.763, 14.078, 2.465]
8
+ "min": [-4.202, -0.072, -4.442],
9
+ "max": [5.324, 14.208, 9.114]
8
10
  },
9
- "mid": "fir_tree_01/fir-b-lod2.glb",
10
- "midDistance": 45,
11
11
  "tree": true
12
12
  },
13
13
  "boulder": {
@@ -21,14 +21,14 @@
21
21
  }
22
22
  },
23
23
  "fir-c": {
24
- "near": "fir_tree_01/fir-c-lod1.glb",
24
+ "near": "tree_small_02/broadleaf-b-near.glb",
25
+ "mid": "tree_small_02/broadleaf-b-mid.glb",
26
+ "midDistance": 45,
25
27
  "maxDistance": 600,
26
28
  "bounds": {
27
- "min": [-2.727, 0, -3.498],
28
- "max": [3.623, 14.552, 2.508]
29
- },
30
- "mid": "fir_tree_01/fir-c-lod2.glb",
31
- "midDistance": 45
29
+ "min": [-4.513, -0.063, -3.92],
30
+ "max": [3.617, 12.287, 7.833]
31
+ }
32
32
  },
33
33
  "fern-a": {
34
34
  "near": "fern_02/fern-a.glb",
@@ -39,11 +39,11 @@
39
39
  }
40
40
  },
41
41
  "fern-b": {
42
- "near": "fern_02/fern-b.glb",
42
+ "near": "shrub_03/shrub_03_a.glb",
43
43
  "maxDistance": 50,
44
44
  "bounds": {
45
- "min": [-0.758, 0, -0.879],
46
- "max": [0.655, 0.687, 0.643]
45
+ "min": [-0.074, 0, -0.073],
46
+ "max": [0.127, 0.401, 0.078]
47
47
  }
48
48
  },
49
49
  "boulder-small-a": {
@@ -1,8 +1,30 @@
1
- // Run with [--assets <dir>] [--out <dir>]; defaults to installed assets and ./world.
2
- import { cookTerrainWorld } from "@threenative/assets";
1
+ // The forest's bake: `node src/terrain/forest/bake.mjs [--out <dir>]` (default `assets/terrain/forest`).
2
+ // `bakeKit` reads `recipe.json` (the surveyed Sprague Lake valley, USGS 3DEP, public domain; its far
3
+ // ring from the starter assets' `survey/` grids; its art) and `biome.data.json`; this kit's own TypeScript gives the look and the prop policy,
4
+ // so it runs under `tsx` (`npm i -D tsx`).
3
5
  import { bakeKit } from "@threenative/terrain/kit";
6
+ import { register } from "tsx/esm/api";
7
+
8
+ register();
9
+ const { terrainPalette } = await import("./render/ground/palette.js");
10
+ const { GROUND_MAPS, GROUND_TILE } = await import("./world/terrainAssets.ts");
11
+ const { CANOPY_CROWN } = await import("./render/ground/terrain.ts");
12
+ const props = await import("./render/props/props.ts");
4
13
 
5
14
  await bakeKit(import.meta.url, {
6
- sky: "hdri/kloofendal_48d_partly_cloudy_1k.hdr",
7
- cookTerrainWorld,
15
+ look: {
16
+ palette: terrainPalette,
17
+ ground: {
18
+ maps: {
19
+ ...GROUND_MAPS,
20
+ dirt: {
21
+ diffuse: "river_small_rocks/river_small_rocks_diff_512.jpg",
22
+ normal: "river_small_rocks/river_small_rocks_nor_gl_512.jpg",
23
+ },
24
+ },
25
+ tile: GROUND_TILE,
26
+ },
27
+ canopy: CANOPY_CROWN,
28
+ props,
29
+ },
8
30
  });