@threenative/terrain 0.1.11 → 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 (218) hide show
  1. package/README.md +1 -0
  2. package/dist/bake-DJ5cxg0C.d.ts +82 -0
  3. package/dist/editor/index.d.ts +4 -4
  4. package/dist/editor/index.js +1 -1
  5. package/dist/editor/server.d.ts +2 -2
  6. package/dist/editor/worker.d.ts +1 -1
  7. package/dist/editor/worker.js +1 -1
  8. package/dist/export.d.ts +1 -1
  9. package/dist/index.d.ts +51 -222
  10. package/dist/index.js +111 -2
  11. package/dist/kit-world.d.ts +107 -0
  12. package/dist/kit-world.js +5134 -0
  13. package/dist/kit.d.ts +21 -4
  14. package/dist/kit.js +19 -4
  15. package/dist/mcp/cook-child.js +9 -6
  16. package/dist/mcp/server.js +14 -4
  17. package/dist/prop-package-Dwz0EWoB.d.ts +141 -0
  18. package/dist/{server-B5RdvEAC.d.ts → server-LnFwY8sr.d.ts} +1 -1
  19. package/dist/starter.d.ts +1141 -6
  20. package/dist/starter.js +1999 -17
  21. package/dist/{terrain-CAEaW0mQ.d.ts → terrain-DYCyAOCJ.d.ts} +1 -1
  22. package/dist/three.d.ts +1 -1
  23. package/dist/{types-BpH00qsx.d.ts → types-kpI0C4hW.d.ts} +1 -1
  24. package/dist/{world-package-B8QgHjAQ.d.ts → world-package-DqJC3-Nn.d.ts} +2 -2
  25. package/docs/authoring/new-environment.md +97 -0
  26. package/package.json +8 -8
  27. package/starter/alpine/README.md +22 -14
  28. package/starter/alpine/bake.mjs +14 -1
  29. package/starter/alpine/biome.data.json +187 -25
  30. package/starter/alpine/heightmap.r16 +0 -0
  31. package/starter/alpine/playerRig.ts +89 -0
  32. package/starter/alpine/recipe.json +169 -15
  33. package/starter/alpine/render/bakedFile.ts +17 -0
  34. package/starter/alpine/render/benchmark.ts +77 -0
  35. package/starter/alpine/render/biomeData.ts +14 -0
  36. package/starter/alpine/render/biomes.ts +687 -0
  37. package/starter/alpine/render/ground/cover.ts +565 -0
  38. package/starter/alpine/render/ground/horizon.ts +219 -0
  39. package/starter/alpine/render/ground/palette.d.ts +1 -0
  40. package/starter/alpine/render/ground/palette.js +11 -0
  41. package/starter/alpine/render/ground/scatter.ts +104 -0
  42. package/starter/alpine/render/ground/terrain.ts +1860 -0
  43. package/starter/alpine/render/kitAssets.ts +28 -0
  44. package/starter/alpine/render/loading.ts +354 -0
  45. package/starter/alpine/render/lookKnobs.ts +37 -0
  46. package/starter/alpine/render/orbitCamera.ts +155 -0
  47. package/starter/alpine/render/props/farForest.ts +94 -0
  48. package/starter/alpine/render/props/pack.ts +1114 -0
  49. package/starter/alpine/render/props/prepared.ts +225 -0
  50. package/starter/alpine/render/props/propMaterials.ts +1239 -0
  51. package/starter/alpine/render/props/propProgress.ts +2 -0
  52. package/starter/alpine/render/props/propWorld.ts +105 -0
  53. package/starter/alpine/render/props/props.ts +633 -0
  54. package/starter/alpine/render/props/spruce.ts +440 -0
  55. package/starter/alpine/render/sky/atmosphere.ts +329 -0
  56. package/starter/alpine/render/sky/sky.ts +382 -0
  57. package/starter/alpine/render/texturePreparation.ts +135 -0
  58. package/starter/alpine/render/water/river.ts +1132 -0
  59. package/starter/alpine/render/worldNames.ts +6 -0
  60. package/starter/alpine/scene.ts +715 -0
  61. package/starter/alpine/sceneProps.ts +561 -0
  62. package/starter/alpine/sceneState.ts +33 -0
  63. package/starter/alpine/world/terrainAssets.ts +145 -0
  64. package/starter/alpine/world/walkBand.ts +47 -0
  65. package/starter/alpine/world/water.ts +74 -0
  66. package/starter/alpine/worlds.ts +13 -0
  67. package/starter/coastal/README.md +26 -27
  68. package/starter/coastal/assets.json +10 -0
  69. package/starter/coastal/bake.mjs +14 -1
  70. package/starter/coastal/biome.data.json +18 -3
  71. package/starter/coastal/playerRig.ts +89 -0
  72. package/starter/coastal/recipe.json +220 -18
  73. package/starter/coastal/render/bakedFile.ts +17 -0
  74. package/starter/coastal/render/benchmark.ts +81 -0
  75. package/starter/coastal/render/biomeData.ts +14 -0
  76. package/starter/coastal/render/biomes.ts +678 -0
  77. package/starter/coastal/render/ground/cover.ts +565 -0
  78. package/starter/coastal/render/ground/horizon.ts +219 -0
  79. package/starter/coastal/render/ground/palette.d.ts +1 -0
  80. package/starter/coastal/render/ground/palette.js +11 -0
  81. package/starter/coastal/render/ground/scatter.ts +104 -0
  82. package/starter/coastal/render/ground/terrain.ts +1829 -0
  83. package/starter/coastal/render/kitAssets.ts +28 -0
  84. package/starter/coastal/render/loading.ts +354 -0
  85. package/starter/coastal/render/lookKnobs.ts +37 -0
  86. package/starter/coastal/render/orbitCamera.ts +155 -0
  87. package/starter/coastal/render/props/farForest.ts +94 -0
  88. package/starter/coastal/render/props/pack.ts +1109 -0
  89. package/starter/coastal/render/props/prepared.ts +225 -0
  90. package/starter/coastal/render/props/propMaterials.ts +1239 -0
  91. package/starter/coastal/render/props/propProgress.ts +2 -0
  92. package/starter/coastal/render/props/propWorld.ts +105 -0
  93. package/starter/coastal/render/props/props.ts +633 -0
  94. package/starter/coastal/render/props/spruce.ts +440 -0
  95. package/starter/coastal/render/sky/atmosphere.ts +329 -0
  96. package/starter/coastal/render/sky/sky.ts +382 -0
  97. package/starter/coastal/render/texturePreparation.ts +135 -0
  98. package/starter/coastal/render/water/ocean.ts +284 -0
  99. package/starter/coastal/render/water/river.ts +1132 -0
  100. package/starter/coastal/render/worldNames.ts +6 -0
  101. package/starter/coastal/scene.ts +740 -0
  102. package/starter/coastal/sceneProps.ts +559 -0
  103. package/starter/coastal/sceneState.ts +33 -0
  104. package/starter/coastal/world/terrainAssets.ts +151 -0
  105. package/starter/coastal/world/walkBand.ts +47 -0
  106. package/starter/coastal/world/water.ts +74 -0
  107. package/starter/coastal/worlds.ts +13 -0
  108. package/starter/desert/README.md +51 -25
  109. package/starter/desert/bake-flora.mjs +142 -0
  110. package/starter/desert/bake-rocks.mjs +291 -0
  111. package/starter/desert/bake.mjs +14 -1
  112. package/starter/desert/biome.data.json +24 -12
  113. package/starter/desert/playerRig.ts +89 -0
  114. package/starter/desert/recipe.json +63 -16
  115. package/starter/desert/render/bakedFile.ts +17 -0
  116. package/starter/desert/render/benchmark.ts +79 -0
  117. package/starter/desert/render/biomeData.ts +14 -0
  118. package/starter/desert/render/biomes.ts +660 -0
  119. package/starter/desert/render/ground/cover.ts +565 -0
  120. package/starter/desert/render/ground/debris.ts +136 -0
  121. package/starter/desert/render/ground/horizon.ts +219 -0
  122. package/starter/desert/render/ground/palette.d.ts +1 -0
  123. package/starter/desert/render/ground/palette.js +11 -0
  124. package/starter/desert/render/ground/scatter.ts +104 -0
  125. package/starter/desert/render/ground/terrain.ts +1854 -0
  126. package/starter/desert/render/kitAssets.ts +28 -0
  127. package/starter/desert/render/loading.ts +354 -0
  128. package/starter/desert/render/lookKnobs.ts +37 -0
  129. package/starter/desert/render/orbitCamera.ts +155 -0
  130. package/starter/desert/render/props/farForest.ts +96 -0
  131. package/starter/desert/render/props/formations.ts +630 -0
  132. package/starter/desert/render/props/pack.ts +1195 -0
  133. package/starter/desert/render/props/prepared.ts +225 -0
  134. package/starter/desert/render/props/propMaterials.ts +1255 -0
  135. package/starter/desert/render/props/propProgress.ts +2 -0
  136. package/starter/desert/render/props/propWorld.ts +105 -0
  137. package/starter/desert/render/props/props.ts +624 -0
  138. package/starter/desert/render/props/spruce.ts +440 -0
  139. package/starter/desert/render/sand.ts +581 -0
  140. package/starter/desert/render/sky/atmosphere.ts +329 -0
  141. package/starter/desert/render/sky/sky.ts +382 -0
  142. package/starter/desert/render/texturePreparation.ts +135 -0
  143. package/starter/desert/render/water/river.ts +1132 -0
  144. package/starter/desert/render/worldNames.ts +6 -0
  145. package/starter/desert/scene.ts +748 -0
  146. package/starter/desert/sceneProps.ts +562 -0
  147. package/starter/desert/sceneState.ts +33 -0
  148. package/starter/desert/world/terrainAssets.ts +162 -0
  149. package/starter/desert/world/walkBand.ts +47 -0
  150. package/starter/desert/world/water.ts +74 -0
  151. package/starter/desert/worlds.ts +13 -0
  152. package/starter/forest/README.md +8 -5
  153. package/starter/forest/bake.mjs +21 -413
  154. package/starter/forest/playerRig.ts +37 -171
  155. package/starter/forest/recipe.json +237 -47
  156. package/starter/forest/render/biomes.ts +2 -1
  157. package/starter/forest/render/ground/horizon.ts +4 -302
  158. package/starter/forest/render/ground/terrain.ts +14 -32
  159. package/starter/forest/render/kitAssets.ts +3 -2
  160. package/starter/forest/render/props/farForest.ts +2 -1
  161. package/starter/forest/render/props/pack.ts +4 -2
  162. package/starter/forest/render/props/prepared.ts +2 -1
  163. package/starter/forest/render/props/propProgress.ts +1 -11
  164. package/starter/forest/render/props/propWorld.ts +48 -662
  165. package/starter/forest/render/props/props.ts +64 -248
  166. package/starter/forest/render/sky/sky.ts +2 -1
  167. package/starter/forest/render/worldNames.ts +6 -2
  168. package/starter/forest/scene.ts +34 -25
  169. package/starter/forest/sceneProps.ts +2 -2
  170. package/starter/forest/sceneState.ts +5 -4
  171. package/starter/forest/surface.json +2 -2
  172. package/starter/forest/worlds.ts +3 -2
  173. package/starter/tundra/README.md +35 -16
  174. package/starter/tundra/bake.mjs +14 -1
  175. package/starter/tundra/biome.data.json +6 -6
  176. package/starter/tundra/playerRig.ts +89 -0
  177. package/starter/tundra/recipe.json +111 -110
  178. package/starter/tundra/render/bakedFile.ts +17 -0
  179. package/starter/tundra/render/benchmark.ts +79 -0
  180. package/starter/tundra/render/biomeData.ts +14 -0
  181. package/starter/tundra/render/biomes.ts +714 -0
  182. package/starter/tundra/render/ground/cover.ts +565 -0
  183. package/starter/tundra/render/ground/horizon.ts +219 -0
  184. package/starter/tundra/render/ground/palette.d.ts +1 -0
  185. package/starter/tundra/render/ground/palette.js +11 -0
  186. package/starter/tundra/render/ground/scatter.ts +104 -0
  187. package/starter/tundra/render/ground/terrain.ts +1874 -0
  188. package/starter/tundra/render/kitAssets.ts +28 -0
  189. package/starter/tundra/render/loading.ts +354 -0
  190. package/starter/tundra/render/lookKnobs.ts +37 -0
  191. package/starter/tundra/render/orbitCamera.ts +155 -0
  192. package/starter/tundra/render/props/farForest.ts +96 -0
  193. package/starter/tundra/render/props/pack.ts +1088 -0
  194. package/starter/tundra/render/props/prepared.ts +225 -0
  195. package/starter/tundra/render/props/propMaterials.ts +1247 -0
  196. package/starter/tundra/render/props/propProgress.ts +2 -0
  197. package/starter/tundra/render/props/propWorld.ts +105 -0
  198. package/starter/tundra/render/props/props.ts +624 -0
  199. package/starter/tundra/render/props/spruce.ts +440 -0
  200. package/starter/tundra/render/sky/atmosphere.ts +329 -0
  201. package/starter/tundra/render/sky/sky.ts +382 -0
  202. package/starter/tundra/render/texturePreparation.ts +135 -0
  203. package/starter/tundra/render/water/river.ts +1132 -0
  204. package/starter/tundra/render/worldNames.ts +6 -0
  205. package/starter/tundra/scene.ts +715 -0
  206. package/starter/tundra/sceneProps.ts +559 -0
  207. package/starter/tundra/sceneState.ts +33 -0
  208. package/starter/tundra/world/terrainAssets.ts +159 -0
  209. package/starter/tundra/world/walkBand.ts +47 -0
  210. package/starter/tundra/world/water.ts +74 -0
  211. package/starter/tundra/worlds.ts +13 -0
  212. package/starter-assets.json +4 -4
  213. package/starter-credits.json +613 -10
  214. package/starter/forest/diagnostics.ts +0 -1020
  215. package/starter/forest/render/sky/skyVisibility.ts +0 -121
  216. package/starter/forest/spawnGate.ts +0 -183
  217. package/starter/forest/viewStatistics.ts +0 -47
  218. package/starter/forest/world/streamedGround.ts +0 -139
@@ -0,0 +1,151 @@
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
+ dirt: {
33
+ diffuse: "forest_ground_04/forest_ground_04_diff_1k.jpg",
34
+ normal: "forest_ground_04/forest_ground_04_nor_gl_1k.jpg",
35
+ },
36
+ grass: {
37
+ diffuse: "leafy_grass/leafy_grass_diff_1k.jpg",
38
+ normal: "leafy_grass/leafy_grass_nor_gl_1k.jpg",
39
+ occlusion: "leafy_grass/leafy_grass_ao_1k.jpg",
40
+ roughness: "leafy_grass/leafy_grass_rough_1k.jpg",
41
+ },
42
+ moss: {
43
+ diffuse: "mossy_rock/mossy_rock_diff_1k.jpg",
44
+ normal: "mossy_rock/mossy_rock_nor_gl_1k.jpg",
45
+ },
46
+ rock: {
47
+ diffuse: "rock_boulder_dry/rock_boulder_dry_diff_512.jpg",
48
+ normal: "rock_boulder_dry/rock_boulder_dry_nor_gl_512.jpg",
49
+ },
50
+ sand: { diffuse: "sand_01/sand_01_diff_1k.jpg" },
51
+ snow: { diffuse: "snow_02/snow_02_diff_1k.jpg" },
52
+ };
53
+
54
+ /** Metres one ground tile spans, per layer. The size of a pattern, not of the file. */
55
+ export const GROUND_TILE: Record<LayerKey, number> = {
56
+ dirt: 3.4,
57
+ grass: 2.6,
58
+ moss: 3.6,
59
+ rock: 3.8,
60
+ sand: 3.2,
61
+ snow: 12,
62
+ };
63
+
64
+ /** The cliffs' rock face: Poly Haven's `rock_face` (CC0), dark cracked plates. */
65
+ export const ROCKFACE_MAPS: IGroundMaps = {
66
+ diffuse: "rock_face/rock_face_diff_1k.jpg",
67
+ normal: "rock_face/rock_face_nor_gl_1k.jpg",
68
+ };
69
+
70
+ /** One mapped prop surface's albedo, tangent-space normal and roughness. */
71
+ export interface ISurfaceMaps {
72
+ readonly diffuse: string;
73
+ readonly normal: string;
74
+ readonly roughness: string;
75
+ }
76
+
77
+ /** CC0 dry stone for beach and desert props; ARM uses AO in R and roughness in G. */
78
+ export const DRY_STONE_MAPS = {
79
+ diffuse: "rock_boulder_dry/rock_boulder_dry_diff_512.jpg",
80
+ normal: "rock_boulder_dry/rock_boulder_dry_nor_gl_512.jpg",
81
+ arm: "rock_boulder_dry/rock_boulder_dry_arm_512.jpg",
82
+ } as const;
83
+
84
+ /** The bark and stone the props bind, and the soil the bases of both fade into. */
85
+ export const PROP_MAPS: Record<"bark" | "stone", ISurfaceMaps> = {
86
+ bark: {
87
+ diffuse: "bark_brown_02/bark_brown_02_diff_1k.jpg",
88
+ normal: "bark_brown_02/bark_brown_02_nor_gl_1k.jpg",
89
+ roughness: "bark_brown_02/bark_brown_02_rough_1k.jpg",
90
+ },
91
+ stone: {
92
+ diffuse: "mossy_rock/mossy_rock_diff_1k.jpg",
93
+ normal: "mossy_rock/mossy_rock_nor_gl_1k.jpg",
94
+ roughness: "mossy_rock/mossy_rock_rough_1k.jpg",
95
+ },
96
+ };
97
+
98
+ /** The forest floor the props' bases blend into. */
99
+ export const SOIL_MAP = "forest_ground_04/forest_ground_04_diff_1k.jpg";
100
+
101
+ /** The generated needle atlas, and the relief it carries in RG with occlusion in B. */
102
+ export const NEEDLE_ATLAS = "needle-atlas.png";
103
+ export const NEEDLE_SURFACE = "needle-surface.png";
104
+
105
+ /**
106
+ * Poly Haven's `tree_small_02` (CC0), grown to forest height as leaf cards: two silhouettes, each a
107
+ * `-near.glb` and a `-mid.glb` (`scripts/prep/prep-polyhaven-broadleaf.py`).
108
+ */
109
+ export const BROADLEAF_TREES = ["tree_small_02/broadleaf", "tree_small_02/broadleaf-b"] as const;
110
+
111
+ /** The fern's own atlas: a photographed frond and its separate cut-out alpha. */
112
+ export const FERN_MAPS = {
113
+ alpha: "fern_02/fern_02_alpha_512.png",
114
+ diffuse: "fern_02/fern_02_diff_512.jpg",
115
+ } as const;
116
+
117
+ /** One prepared placement file: what it is, which variant it fills, and which detail level it is. */
118
+ export interface IPreparedFile {
119
+ readonly asset: string;
120
+ readonly level: number;
121
+ readonly path: string;
122
+ readonly variant: number;
123
+ }
124
+
125
+ /**
126
+ * The prepared files, in the order they are asked for.
127
+ *
128
+ * **Nothing on this list any more.** The three CC0 rocks and the two prepared firs were replaced by
129
+ * the licensed Landscape Pro species in `src/render/props/pack.ts` — real photoscanned stone at 7,178
130
+ * triangles where the CC0 set's were 1–2k, and real pines where the fir's crown measured 0.3% of
131
+ * its own silhouette at the tree budget (`credits.json` has that number, and it is why the starter
132
+ * kept its procedural spruce). The list and its loader stay because they are how the next source is
133
+ * measured, and because a prepared file that is not there is not an error: this map is empty on CI,
134
+ * on a fresh clone and in a review, and the procedural variants are what draw there.
135
+ *
136
+ * A species that IS added back comes in as one entry per detail level, because a variant with a near
137
+ * level and no mid level is a variant whose middle distance pops. Three rocks at both of their levels
138
+ * was six draws for stone the eye cannot tell apart at meadow distance, against the starter's
139
+ * twenty-four-draw ceiling for the whole meadow — which is the trade this list now records.
140
+ */
141
+ export const PREPARED: readonly IPreparedFile[] = [
142
+ // The committed fallback's stone: two photoscanned CC0 rocks at both levels. Where the licensed
143
+ // pack loaded, its boulders take these same indices 1 and 2 (the pack's parts are merged after these), so
144
+ // this only draws on CI, on a fresh clone and in a review — which is the starter that ships, and
145
+ // a procedural lump there is the wrong first impression. Two, not three: three at two levels put
146
+ // the pack-less meadow one draw over its ceiling.
147
+ { asset: "boulder", level: 0, path: "rocks/rock01-near.glb", variant: 1 },
148
+ { asset: "boulder", level: 1, path: "rocks/rock01-mid.glb", variant: 1 },
149
+ { asset: "boulder", level: 0, path: "rocks/boulder-near.glb", variant: 2 },
150
+ { asset: "boulder", level: 1, path: "rocks/boulder-mid.glb", variant: 2 },
151
+ ];
@@ -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,43 +1,69 @@
1
- # Desert starter kit (placeholder scatter)
1
+ # Desert starter kit
2
2
 
3
- A 512 m desert on a real survey (USGS 1 m DEM, Colorado), with hydraulic and thermal erosion, sand
4
- on the low ground, dirt patches, rock on the steep ground and a scatter of 140 props. It is game
5
- source: once copied, every file is yours to edit.
3
+ A 512 m Colorado Plateau desert at Setting Hen Butte, Valley of the Gods, Utah (USGS 3DEP 1 m DEM),
4
+ with hydraulic and thermal erosion: red sand flats, gravel pavement in the hollows, bedded orange
5
+ sandstone with desert varnish on the steep faces, and the butte itself standing about 100 m over the
6
+ flat. The far ring is the same survey out to 5 km: the valley's other buttes and the Cedar Mesa rim,
7
+ real heights on the square's own datum. It is game source: once copied, every file is yours to edit.
6
8
 
7
9
  | File | What it decides |
8
10
  | --- | --- |
9
- | `recipe.json` | The terrain: the survey heightmap, erosion, the sand, dirt and rock surfaces, and the scatter. |
10
- | `heightmap.r16` | The real elevations the recipe's heightmap layer reads: 16-bit samples, decoded at the bake to 0.1 m steps. |
11
- | `biome.data.json` | The biome record the `terrain_generate` MCP tool cooks from. The bake does not read it. |
12
- | `assets.json` | The boulder model, its LOD distance and draw distance, and its bounds. |
13
- | `surface.json` | The ground: the sand base, the dirt and rock layers, tiles, tints and blend thresholds. |
14
- | `bake.mjs` | Writes the world package and `water.json` from `recipe.json`, `heightmap.r16`, `assets.json` and `surface.json`. |
15
- | `world.ts` | The runtime: streams the baked world, one heightfield for the ground, sphere colliders for the boulders near the player, and the sky as the props' light. |
16
- | `sky.ts` | The daylight: the sun, sky, fill, haze, exposure and tone curve. |
17
-
18
- Art is CC0 (Poly Haven); provenance is in `@threenative/terrain/starter-credits.json`.
19
-
20
- ## Placeholder
21
-
22
- The preview's desert scrub is drawn from generated cards, and the starter assets do not ship a CC0
23
- shrub model. Until one is added, this kit scatters the CC0 boulder in the scrub's place, with the
24
- same count, spacing and slope limits. The result does not look like the preview's desert. Replace the
25
- `scrub` entry in `recipe.json` and the boulder row in `assets.json` with a CC0 shrub model to fix it.
11
+ | `recipe.json` | The terrain: the survey heightmap, erosion, the gravel and rock surfaces, the far ring and the art the bake copies. |
12
+ | `heightmap.r16` | The real elevations the recipe's heightmap layer reads: 16-bit samples, decoded at the bake to 0.1 m steps. `scripts/cook-kit-survey.ts` in `@threenative/terrain` cuts it and the far ring from any lat/lon. |
13
+ | `biome.data.json` | The biome record: the juniper scatter, the scrub and grass cover and their bands. The streamed bake places from it. |
14
+ | `assets.json` | The legacy cell package's boulder model, LOD distance, draw distance and bounds. |
15
+ | `surface.json` | The legacy cell package's ground table: sand base, dirt and rock layers, tiles, tints and thresholds. |
16
+ | `bake.mjs` | Runs `bakeKit` with this kit's look and writes the streamed world: the baked grid, its splat, the canopy and sky bytes, `horizon.json`, the prop package and the art. |
17
+ | `scene.ts` | The scene, `DesertScene`, and `DESERT_GAME`: the streamed ground, the far ring, the props, the sky and the player rig. |
18
+ | `render/` | The look: the biome row, the ground material, the palette, the species pack and the sky. |
19
+ | `world.ts`, `sky.ts` | The legacy cell-package loader and its daylight, kept until the streamed bake retires them here. |
20
+
21
+ ## The plants
22
+
23
+ Valley of the Gods is cold desert on the Colorado Plateau, not the Sonoran or Mojave desert: no
24
+ saguaro, joshua tree or acacia grows there. The kit draws what does, from
25
+ `@threenative/procedural-environment` bakes in `starter-assets/desert_flora/`:
26
+
27
+ | Plant | Drawn with (preset) | Placed as |
28
+ | --- | --- | --- |
29
+ | Utah juniper | `olive`, two seeds, a far level each | the sparse tree (`sapling`) |
30
+ | Big sagebrush | `creosote` | scrub, and the occasional large bush |
31
+ | Blackbrush | `thornbush` | scrub |
32
+ | Utah yucca | `agave` | scrub |
33
+ | Indian ricegrass, galleta, cheatgrass | `bunchgrass`, `drygrass` | grass |
34
+ | Desert marigold | `marigold` | grass |
35
+ | Dead juniper wood | `branch` | bush |
36
+
37
+ The saguaro is a column, and a column is all surface: Arbor's drawn cactus bark is a flat
38
+ pinstripe, so `bake-flora.mjs` paints `desert_flora/saguaro-skin.png` (photographed succulent
39
+ flesh from Poly Haven's CC0 `crystalline_iceplant`) with `saguaro-skin-nor.png` as its rib relief,
40
+ through `bakeVegetation`'s `barkImage`/`barkNormalImage`. Both PNGs are generated, not downloaded:
41
+ `node packages/terrain/scripts/make-cactus-skin.mjs --source <crystalline_iceplant_diff_1k.jpg>`
42
+ rewrites them byte for byte.
43
+
44
+ The stones are the kit's CC0 Poly Haven boulder scans, drawn with the desert's bedded rock colour.
45
+ Ground art is CC0 Poly Haven (`aerial_beach_01`, `cliff_side`, `rocky_trail_02`); provenance is in
46
+ `@threenative/terrain/starter-credits.json`.
26
47
 
27
48
  ## Status
28
49
 
29
- The kit bakes and streams. The kit ships no scene: the game writes one. The placeholder boulders are
30
- colliders like any other prop, and the scene picks its spawn from the loaded heightfield.
50
+ The kit is a source kit on the forest's stack: `scene.ts` streams the baked world, its far ring and
51
+ its props, and composes the player rig and diagnostics from `@threenative/terrain/starter`. The
52
+ player spawns on the sand flat south-east of the butte.
31
53
 
32
54
  ## Steps
33
55
 
34
56
  1. Copy `node_modules/@threenative/terrain/starter/desert` to `src/terrain/desert`.
35
57
  2. Run `node src/terrain/desert/bake.mjs --out assets/terrain/desert` (needs `@threenative/terrain`
36
- as a devDependency). The same recipe always writes the same bytes.
37
- 3. In the scene, call `addDesert(ctx, follow)` for the world and `desertDaylight(follow)` for the light.
58
+ and `tsx` as devDependencies, because the bake reads this kit's TypeScript look). The same recipe
59
+ always writes the same bytes.
60
+ 3. Spread `DESERT_GAME` into `defineGame` and register `DesertScene`, as the forest kit's README shows.
38
61
 
39
62
  ## Edit at startup, without rebaking
40
63
 
64
+ > The streamed bake retires this path for the desert kit: the ground table and the props now come
65
+ > from `render/`, and the section below still describes the legacy cell package.
66
+
41
67
  The copied `world.ts` loads its own `surface.json` as the ground table on every startup.
42
68
  Edit tints, tiling and blend thresholds there, or the material graph and prop dressing in
43
69
  `world.ts`, then reload. The package's `terrain-table.json` remains the baked default for
@@ -0,0 +1,142 @@
1
+ // Run with <out dir> (the starter art's `desert_flora/`); needs @threenative/procedural-environment.
2
+ // Bakes the desert's plants and dead wood once into GLBs the species pack (`render/props/pack.ts`)
3
+ // draws. Valley of the Gods has no Poly Haven scan for these species, so they are Arbor and
4
+ // forest-kit presets: the same preset, seed and level always write the same bytes.
5
+ import { cp, mkdir, mkdtemp, rm } from "node:fs/promises";
6
+ import { tmpdir } from "node:os";
7
+ import { join } from "node:path";
8
+ import { bakeVegetation } from "@threenative/procedural-environment";
9
+
10
+ const out = process.argv[2];
11
+ if (!out) throw new Error("bake-flora: pass the output folder, e.g. starter-assets/desert_flora");
12
+
13
+ /**
14
+ * The saguaro's own surface: Arbor's drawn cactus bark is a flat pinstripe on a column that is all
15
+ * silhouette, so the two saguaros carry the photographed skin `make-cactus-skin.mjs` builds.
16
+ * `--assets` names the folder those PNGs live in when it is not the output one.
17
+ */
18
+ const assets = process.argv.includes("--assets")
19
+ ? process.argv[process.argv.indexOf("--assets") + 1]
20
+ : out;
21
+ /**
22
+ * A rosette is judged on its leaves, and Arbor's `agave` row draws sixteen wide cards that widen to
23
+ * a squared end: at screen size that is a paper star. The desert's two rosettes patch the row —
24
+ * more leaves, a lance width, and `taper: 1`, which takes the tip row to zero width.
25
+ *
26
+ * `fold` stays 0, and that is a measurement, not taste: a fold puts a third, lifted vertex across
27
+ * the blade (`across === 3` in Arbor), and that ridge holds the tip open into a blunt wedge. With
28
+ * the fold the leaves end square and read as paper strips; without it they close to a point.
29
+ */
30
+ const ROSETTE = (count, length, width, fold, droop, angle, extra = {}) => ({
31
+ leaves: [
32
+ {
33
+ count,
34
+ size: [length, width],
35
+ fold,
36
+ droop,
37
+ angle,
38
+ taper: 1,
39
+ segs: 4,
40
+ sizeVar: 0.28,
41
+ ...extra,
42
+ },
43
+ ],
44
+ });
45
+
46
+ /**
47
+ * A grass tuft is judged on its blades, and Arbor's rows draw 11-18 flat straps that stop short of
48
+ * a point (`taper: 0.93`) and barely arch (`droop: 0.5`): at 0.4 m that is a wire star. The desert's
49
+ * three tufts patch the leaf row instead — twice the blades, thinner, `taper: 1` so each closes to a
50
+ * point, and enough droop and segments that the tips arch over instead of standing out straight.
51
+ */
52
+ const GRASS = (blades, length, width, droop, splay) => ({
53
+ leaves: [
54
+ {
55
+ count: blades,
56
+ size: [length, width],
57
+ taper: 1,
58
+ segs: 6,
59
+ droop,
60
+ angle: [4, splay],
61
+ angleVar: 12,
62
+ sizeVar: 0.5,
63
+ },
64
+ ],
65
+ });
66
+
67
+ const CACTUS = {
68
+ barkImage: join(assets, "saguaro-skin.png"),
69
+ barkNormalImage: join(assets, "saguaro-skin-nor.png"),
70
+ };
71
+
72
+ /** [file, preset, seed, { level: file suffix }, skin?]: the file names `pack.ts` quotes. */
73
+ const ROWS = [
74
+ // Utah juniper: the gnarled grey-green `olive` crown is the nearest Arbor form. Its far levels are
75
+ // their own call so their leaf card is drawn at 256 px: past 190 m a juniper is a few pixels and a
76
+ // 1024 px card was a megabyte of texels the frame never shows.
77
+ ["juniper-a", "olive", 1, { 1: "" }],
78
+ ["juniper-a", "olive", 1, { 2: "-far" }, { leafSize: 256 }],
79
+ ["juniper-b", "olive", 2, { 1: "" }],
80
+ ["juniper-b", "olive", 2, { 2: "-far" }, { leafSize: 256 }],
81
+ // Saguaro: the cactus the request names first; Arbor's columnar form with its arms, under the
82
+ // ribbed skin and its relief.
83
+ ["saguaro-a", "saguaro", 1, { 0: "", 2: "-far" }, CACTUS],
84
+ ["saguaro-b", "saguaro", 4, { 0: "", 2: "-far" }, CACTUS],
85
+ // A shrub a metre tall, or a grass tuft a hand wide, is drawn at a few hundred pixels on screen:
86
+ // Arbor's 1024 px card is a megabyte of texels none of them can show, so these take 512.
87
+ ["sage", "creosote", 1, { 0: "" }, { leafSize: 512 }],
88
+ ["creosote-b", "creosote", 3, { 0: "" }, { leafSize: 512 }],
89
+ ["thornbush-b", "thornbush", 4, { 0: "" }, { leafSize: 512 }],
90
+ // Pale, broad-leaved agave: 26 leaves instead of 16, half the width, a 0.42 midrib fold.
91
+ [
92
+ "agave-b",
93
+ "agave",
94
+ 5,
95
+ { 0: "" },
96
+ { leafSize: 512, form: ROSETTE(34, 0.42, 0.045, 0, 0.3, [26, 72]) },
97
+ ],
98
+ ["blackbrush", "thornbush", 1, { 0: "" }, { leafSize: 512 }],
99
+ // Utah yucca: stiffer and narrower still, held upright, its tips barely drooping.
100
+ [
101
+ "yucca",
102
+ "agave",
103
+ 1,
104
+ { 0: "" },
105
+ { leafSize: 512, form: ROSETTE(36, 0.58, 0.03, 0, 0.12, [10, 56]) },
106
+ ],
107
+ [
108
+ "bunchgrass-a",
109
+ "bunchgrass",
110
+ 1,
111
+ { 0: "" },
112
+ { leafSize: 512, form: GRASS(34, 0.46, 0.012, 0.95, 62) },
113
+ ],
114
+ [
115
+ "bunchgrass-b",
116
+ "bunchgrass",
117
+ 2,
118
+ { 0: "" },
119
+ { leafSize: 512, form: GRASS(30, 0.4, 0.011, 1.05, 58) },
120
+ ],
121
+ ["drygrass", "drygrass", 1, { 0: "" }, { leafSize: 512, form: GRASS(28, 0.42, 0.01, 1.15, 54) }],
122
+ ["marigold", "marigold", 1, { 0: "" }, { leafSize: 512 }],
123
+ ["branch", "branch", 1, { 0: "" }],
124
+ ["branch-b", "branch", 2, { 0: "" }],
125
+ ["twig", "twig", 1, { 0: "" }],
126
+ ];
127
+
128
+ await mkdir(out, { recursive: true });
129
+ const scratch = await mkdtemp(join(tmpdir(), "desert-flora-"));
130
+ try {
131
+ for (const [file, preset, seed, levels, skin] of ROWS) {
132
+ const lods = Object.keys(levels).map(Number);
133
+ for (const level of await bakeVegetation({ preset, seed, lods, out: scratch, ...skin })) {
134
+ await cp(level.path, join(out, `${file}${levels[level.lod]}.glb`));
135
+ console.log(
136
+ `${file}${levels[level.lod]}.glb ${preset}@${seed} lod${level.lod} ${level.triangles} triangles`,
137
+ );
138
+ }
139
+ }
140
+ } finally {
141
+ await rm(scratch, { recursive: true, force: true });
142
+ }