@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,291 @@
1
+ // Run with <out dir> (the starter art's `desert_rocks/`); needs @threenative/procedural-environment.
2
+ // Bakes the desert's stones once into GLBs the species pack (`render/props/pack.ts`) and the
3
+ // formations (`render/props/formations.ts`) draw. Every Outcrop form has a row, in three tones of
4
+ // sandstone, so a hillside is not one rock repeated: chipped boulders and worn ones, bedded slabs,
5
+ // crags, fins, hoodoos, an arch, and cliff walls baked as runs of modules that join.
6
+ // Outcrop's own desert palette is cream sandstone, which drew as white loaves under the sun, so
7
+ // this file names its own colours and shapes. The same row always writes the same bytes.
8
+ // Normals are stored as int8 and colours as uint8 (KHR_mesh_quantization), positions stay float.
9
+ import { mkdir, mkdtemp, rm } from "node:fs/promises";
10
+ import { tmpdir } from "node:os";
11
+ import { join } from "node:path";
12
+ import { NodeIO } from "@gltf-transform/core";
13
+ import { ALL_EXTENSIONS } from "@gltf-transform/extensions";
14
+ import { normals, quantize, simplify, weld } from "@gltf-transform/functions";
15
+ import { bakeRock } from "@threenative/procedural-environment";
16
+ import { MeshoptSimplifier } from "meshoptimizer";
17
+
18
+ const out = process.argv[2];
19
+ if (!out) throw new Error("bake-rocks: pass the output folder, e.g. starter-assets/desert_rocks");
20
+
21
+ /** Rock darker than the sand it lies on; `sandColor` is the kit's sand, so a drift joins the dune. */
22
+ const RED = {
23
+ rockA: "#7a4630",
24
+ rockB: "#a3623f",
25
+ accent: "#bd8258",
26
+ banding: 0.35,
27
+ sand: 0.25,
28
+ sandColor: "#b96a40",
29
+ edgeWear: 0.3,
30
+ cavity: 0.85,
31
+ };
32
+ /** Desert varnish: the near-black crust iron and manganese leave on stone that has lain for long. */
33
+ const VARNISH = { ...RED, rockA: "#4a2c26", rockB: "#6e4031", accent: "#8f5b41", banding: 0.2 };
34
+ /** The paler cap bed the slabs break from. */
35
+ const TAN = { ...RED, rockA: "#7d5237", rockB: "#96684a", accent: "#aa7d59", banding: 0.5 };
36
+ /** Broken, angular stone: planar chips and joints, little rounding. */
37
+ const CRAG = { chipping: 0.9, fracture: 0.45, roughness: 0.35, weathering: 0.15, strata: 0.4 };
38
+ /** Stone the wind has worn: rounded shoulders, few fresh chips. */
39
+ const WORN = { chipping: 0.35, fracture: 0.25, roughness: 0.45, weathering: 0.6, strata: 0.3 };
40
+ /** A bedded wall: Outcrop's cliff module has a flat back and underside, so it sits in a slope. */
41
+ const BEDS = {
42
+ chipping: 0.8,
43
+ fracture: 0.6,
44
+ roughness: 0.5,
45
+ weathering: 0.1,
46
+ strata: 0.9,
47
+ layers: 7,
48
+ };
49
+ /** A flagstone: thin beds that split along their layers. */
50
+ const PLATE = { ...CRAG, chipping: 0.6, fracture: 0.5, strata: 0.9, layers: 5 };
51
+
52
+ /**
53
+ * One wall of `count` cliff modules. A module ends in a cut face, and joins its neighbour only when
54
+ * both share the seed and stand one width apart, so module n is baked at `offset: [n * width, 0, 0]`
55
+ * and `formations.ts` stands them in that order.
56
+ */
57
+ const wall = (file, seed, size, traits, surface, count = 3) =>
58
+ Array.from({ length: count }, (_, n) => ({
59
+ file: `${file}-${n}`,
60
+ form: "cliff",
61
+ seed,
62
+ detail: 0.42,
63
+ size,
64
+ traits,
65
+ surface,
66
+ offset: [n * size[0], 0, 0],
67
+ far: 3200,
68
+ }));
69
+
70
+ /**
71
+ * One rock per row; the file names are the ones `pack.ts` and `formations.ts` quote.
72
+ * `near` and `far` are triangle counts: `near` simplifies the bake itself (Outcrop's floor is
73
+ * 1 500 triangles), `far` also writes `<file>-far.glb` for the rocks past the near band.
74
+ */
75
+ const ROWS = [
76
+ // Boulders: chipped and worn, red and varnished.
77
+ // An angular block is a thick slab: Outcrop's boulder is a ball however much it is chipped.
78
+ {
79
+ file: "boulder-a",
80
+ form: "slab",
81
+ seed: 3,
82
+ size: [2.3, 1.6, 1.9],
83
+ traits: { ...CRAG, fracture: 0.6 },
84
+ near: 5000,
85
+ far: 900,
86
+ },
87
+ { file: "boulder-b", form: "boulder", seed: 8, traits: WORN, near: 5000, far: 900 },
88
+ {
89
+ file: "boulder-c",
90
+ form: "boulder",
91
+ seed: 21,
92
+ traits: { ...CRAG, chipping: 0.7, fracture: 0.6, roughness: 0.5 },
93
+ surface: VARNISH,
94
+ near: 5000,
95
+ far: 900,
96
+ },
97
+ {
98
+ file: "boulder-d",
99
+ form: "slab",
100
+ seed: 34,
101
+ size: [3.2, 1.4, 2.3],
102
+ traits: { ...WORN, strata: 0.7 },
103
+ surface: VARNISH,
104
+ near: 5000,
105
+ far: 900,
106
+ },
107
+ // Slabs: fallen blocks and the flagstones a cap bed breaks into.
108
+ {
109
+ file: "block-a",
110
+ form: "slab",
111
+ seed: 5,
112
+ traits: { ...CRAG, fracture: 0.5, strata: 0.8 },
113
+ near: 5000,
114
+ far: 900,
115
+ },
116
+ {
117
+ file: "slab-b",
118
+ form: "slab",
119
+ seed: 12,
120
+ size: [4.2, 0.6, 2.8],
121
+ traits: PLATE,
122
+ surface: TAN,
123
+ near: 2600,
124
+ far: 600,
125
+ },
126
+ {
127
+ file: "slab-c",
128
+ form: "slab",
129
+ seed: 27,
130
+ size: [2.8, 1.2, 2.2],
131
+ traits: { ...PLATE, fracture: 0.7 },
132
+ near: 2600,
133
+ far: 600,
134
+ },
135
+ // Cobbles and pebbles strewn by the hundred: a few hundred triangles each.
136
+ { file: "cobble", form: "boulder", seed: 11, detail: 0.05, traits: CRAG, near: 700 },
137
+ {
138
+ file: "pebble",
139
+ form: "boulder",
140
+ seed: 17,
141
+ detail: 0,
142
+ traits: { ...CRAG, fracture: 0.2 },
143
+ near: 160,
144
+ },
145
+ {
146
+ file: "pebble-b",
147
+ form: "slab",
148
+ seed: 9,
149
+ detail: 0,
150
+ traits: { ...WORN, fracture: 0.2 },
151
+ surface: VARNISH,
152
+ near: 160,
153
+ },
154
+ // Crags: the jointed cores of an outcrop.
155
+ {
156
+ file: "crag-a",
157
+ form: "stack",
158
+ seed: 5,
159
+ detail: 0.4,
160
+ traits: { ...CRAG, chipping: 0.8, fracture: 0.5, roughness: 0.5, strata: 0.7 },
161
+ near: 9000,
162
+ far: 2200,
163
+ },
164
+ {
165
+ file: "crag-b",
166
+ form: "stack",
167
+ seed: 14,
168
+ detail: 0.4,
169
+ size: [5.2, 4.2, 4.2],
170
+ traits: { ...CRAG, chipping: 1, fracture: 0.7, roughness: 0.6, strata: 0.5 },
171
+ surface: VARNISH,
172
+ near: 9000,
173
+ far: 2200,
174
+ },
175
+ // Fins and hoodoos: what a wall leaves standing when the rock round it has gone.
176
+ {
177
+ file: "fin-a",
178
+ form: "spire",
179
+ seed: 4,
180
+ detail: 0.4,
181
+ size: [3.4, 7, 2],
182
+ traits: { ...BEDS, strata: 0.8 },
183
+ near: 8000,
184
+ far: 2000,
185
+ },
186
+ {
187
+ file: "fin-b",
188
+ form: "spire",
189
+ seed: 9,
190
+ detail: 0.4,
191
+ size: [2.2, 5, 2.2],
192
+ traits: { ...CRAG, strata: 0.8, layers: 9 },
193
+ surface: VARNISH,
194
+ near: 8000,
195
+ far: 2000,
196
+ },
197
+ {
198
+ file: "hoodoo-a",
199
+ form: "hoodoo",
200
+ seed: 2,
201
+ detail: 0.4,
202
+ traits: { ...BEDS, chipping: 0.5, layers: 9 },
203
+ near: 8000,
204
+ far: 2000,
205
+ },
206
+ {
207
+ file: "hoodoo-b",
208
+ form: "hoodoo",
209
+ seed: 6,
210
+ detail: 0.4,
211
+ size: [2.8, 4.4, 2.6],
212
+ traits: { ...BEDS, chipping: 0.6, weathering: 0.3 },
213
+ surface: TAN,
214
+ near: 8000,
215
+ far: 2000,
216
+ },
217
+ {
218
+ file: "arch",
219
+ form: "arch",
220
+ seed: 3,
221
+ detail: 0.5,
222
+ traits: { ...BEDS, chipping: 0.6, layers: 9 },
223
+ far: 5000,
224
+ },
225
+ // Cliff walls: a tall red wall of four modules and a low varnished rim of three.
226
+ ...wall("wall-a", 2, [12, 6, 5], BEDS, RED, 4),
227
+ ...wall(
228
+ "wall-b",
229
+ 5,
230
+ [10, 4, 4.5],
231
+ { ...BEDS, chipping: 0.9, fracture: 0.5, roughness: 0.6, strata: 0.7, layers: 5 },
232
+ VARNISH,
233
+ ),
234
+ // The landmarks on the skyline: a mesa, a butte and a spire.
235
+ { file: "mesa", form: "mesa", seed: 7, detail: 0.6, traits: { ...BEDS, layers: 12 } },
236
+ { file: "butte", form: "mesa", seed: 12, detail: 0.55, traits: { ...BEDS, layers: 9 } },
237
+ { file: "spire", form: "spire", seed: 4, detail: 0.5, traits: { ...BEDS, strata: 0.8 } },
238
+ ];
239
+
240
+ await mkdir(out, { recursive: true });
241
+ await MeshoptSimplifier.ready;
242
+ const scratch = await mkdtemp(join(tmpdir(), "desert-rocks-"));
243
+ try {
244
+ const io = new NodeIO().registerExtensions(ALL_EXTENSIONS);
245
+ /**
246
+ * Joins the faces, collapses them to `count` when given, and shades them smooth. Flat facets
247
+ * drew every sliver the simplifier left as a black shard, and a flipped one as a hole; the
248
+ * scanned relief in `formations.ts` and the pack draws the fine breaks instead.
249
+ */
250
+ const reduce = async (doc, from, count) => {
251
+ for (const mesh of doc.getRoot().listMeshes())
252
+ for (const prim of mesh.listPrimitives()) prim.setAttribute("NORMAL", null);
253
+ await doc.transform(
254
+ weld(),
255
+ ...(count && count < from
256
+ ? [simplify({ simplifier: MeshoptSimplifier, ratio: count / from, error: 0.2 })]
257
+ : []),
258
+ normals({ overwrite: true }),
259
+ );
260
+ const prim = doc.getRoot().listMeshes()[0].listPrimitives()[0];
261
+ return (prim.getIndices()?.getCount() ?? prim.getAttribute("POSITION").getCount()) / 3;
262
+ };
263
+ for (const row of ROWS) {
264
+ const { file, form, seed, detail = 0.3, traits, surface = RED, size, offset, near, far } = row;
265
+ const [level] = await bakeRock({
266
+ form,
267
+ biome: "desert",
268
+ seed,
269
+ detail,
270
+ traits,
271
+ surface,
272
+ ...(size ? { size } : {}),
273
+ ...(offset ? { offset } : {}),
274
+ out: scratch,
275
+ });
276
+ for (const [name, count] of [
277
+ [`${file}.glb`, near],
278
+ ...(far ? [[`${file}-far.glb`, far]] : []),
279
+ ]) {
280
+ const doc = await io.read(level.path);
281
+ const triangles = await reduce(doc, level.triangles, count);
282
+ await doc.transform(
283
+ quantize({ pattern: /^(NORMAL|COLOR_0)$/, quantizeNormal: 8, quantizeColor: 8 }),
284
+ );
285
+ await io.write(join(out, name), doc);
286
+ console.log(`${name} ${form}@${seed} ${triangles} triangles`);
287
+ }
288
+ }
289
+ } finally {
290
+ await rm(scratch, { recursive: true, force: true });
291
+ }
@@ -1,6 +1,19 @@
1
1
  // Run with [--assets <dir>] [--out <dir>]; defaults to installed assets and ./world.
2
+ // The desert kit's look: its palette, its ground maps, its canopy rows and its prop policy.
2
3
  import { bakeKit } from "@threenative/terrain/kit";
4
+ import { register } from "tsx/esm/api";
5
+
6
+ register();
7
+ const { terrainPalette } = await import("./render/ground/palette.js");
8
+ const { GROUND_MAPS, GROUND_TILE } = await import("./world/terrainAssets.ts");
9
+ const { CANOPY_CROWN } = await import("./render/ground/terrain.ts");
10
+ const props = await import("./render/props/props.ts");
3
11
 
4
12
  await bakeKit(import.meta.url, {
5
- sky: "hdri/kloofendal_48d_partly_cloudy_1k.hdr",
13
+ look: {
14
+ palette: terrainPalette,
15
+ ground: { maps: GROUND_MAPS, tile: GROUND_TILE },
16
+ canopy: CANOPY_CROWN,
17
+ props,
18
+ },
6
19
  });
@@ -28,24 +28,24 @@
28
28
  "foliage": [
29
29
  {
30
30
  "species": "sapling",
31
- "density": 0,
32
- "slope": [0, 32],
31
+ "density": 160,
32
+ "slope": [0, 26],
33
33
  "height": null,
34
- "spacing": [3.4, 3.4],
34
+ "spacing": [9, 9],
35
35
  "collision": "trunk",
36
36
  "stands": false,
37
- "grassThreshold": 0.18,
38
- "standThreshold": 0.42,
37
+ "grassThreshold": 0.2,
38
+ "standThreshold": 0.3,
39
39
  "far": null
40
40
  }
41
41
  ],
42
42
  "grass": [
43
43
  {
44
44
  "species": "grass",
45
- "density": 0.32,
45
+ "density": 0.55,
46
46
  "slope": [0, 24],
47
47
  "height": null,
48
- "spacing": 7,
48
+ "spacing": 4,
49
49
  "slopeFalloff": 20,
50
50
  "heightFalloff": 28,
51
51
  "mats": null,
@@ -61,10 +61,10 @@
61
61
  },
62
62
  "bladeScale": 0.95,
63
63
  "bladeJitter": 0.5,
64
- "scrubChance": 0.65,
64
+ "scrubChance": 0.8,
65
65
  "scrubScale": 0.8,
66
66
  "scrubJitter": 0.6,
67
- "scrubBush": false,
67
+ "scrubBush": true,
68
68
  "shoreGround": false,
69
69
  "cobbledBed": false
70
70
  }
@@ -115,10 +115,22 @@
115
115
  ],
116
116
  "water": [],
117
117
  "spawn": {
118
- "at": [180, 160],
118
+ "at": [140, 120],
119
119
  "cameraOffset": [28, 24, 42],
120
- "focus": [170, 180]
120
+ "focus": [120, 110]
121
121
  },
122
- "species": ["boulder", "grass", "reveal", "riverrock", "scree", "scrub", "volcanic"],
122
+ "species": [
123
+ "boulder",
124
+ "bush",
125
+ "deadfall",
126
+ "grass",
127
+ "pebble",
128
+ "reveal",
129
+ "riverrock",
130
+ "sapling",
131
+ "scree",
132
+ "scrub",
133
+ "volcanic"
134
+ ],
123
135
  "aliases": ["desert", "dune", "dunes", "sand", "canyon", "canyons", "arid", "badlands", "mesa"]
124
136
  }
@@ -0,0 +1,89 @@
1
+ import type { Heightfield } from "@threenative/core/world";
2
+ import {
3
+ type IMannequin,
4
+ type IPlayerRig,
5
+ type PlayerWallProbe,
6
+ createPlayerRig as createRig,
7
+ } from "@threenative/terrain/starter";
8
+ import { type AnimationClip, Vector3 } from "three";
9
+ import { CAMERA_RIG, type WallProbe, createOrbitCamera } from "./render/orbitCamera.js";
10
+ import { SIGHT_RADIUS, sightLine } from "./render/props/pack.js";
11
+ import type { TerrainCtx } from "./sceneState.js";
12
+
13
+ export type { IMannequin, IPlayerRig };
14
+ export type { WallProbe };
15
+
16
+ /** The starter kit's mannequin (Quaternius Universal Animation Library, CC0) and its clips. */
17
+ const CLIPS = {
18
+ idle: "Idle_Loop",
19
+ walk: "Walk_Loop",
20
+ run: "Jog_Fwd_Loop",
21
+ fall: "Jump_Loop",
22
+ swim: "Swim_Fwd_Loop",
23
+ tread: "Swim_Idle_Loop",
24
+ } as const;
25
+ /** Ground speeds in m/s: the walk clip's pace, the jog, and the Shift sprint. */
26
+ const STRIDE = 1.8;
27
+ const JOG = 6;
28
+ const SPRINT = 9;
29
+
30
+ export interface IPlayerRigOptions {
31
+ readonly world: string;
32
+ /** The player's launch point, in world metres. */
33
+ readonly at: readonly [number, number];
34
+ /** Where the launch camera stands relative to the player: above the ground under the spawn. */
35
+ readonly cameraOffset: readonly [number, number, number];
36
+ /** The ground the spawn stands on: the launch pose is measured from it, not guessed. */
37
+ readonly field: Heightfield;
38
+ readonly mannequin: IMannequin;
39
+ /** The rig's two swim clips, which the mannequin's own clips do not carry. */
40
+ readonly swimClips: readonly AnimationClip[];
41
+ /** A staged world streams its own ground, so the player walks only while the player view draws. */
42
+ readonly staged: boolean;
43
+ /** A vista look frames the player from a fixed aim instead of the orbit camera. */
44
+ readonly vista: boolean;
45
+ /** Centres the sun's shadow pages, or clears them when no player framing draws. */
46
+ readonly focusShadows: (at: Vector3 | undefined) => void;
47
+ /** The horizon seam the scene draws under the player, for the scene picker's report. */
48
+ readonly horizon: () => unknown;
49
+ }
50
+
51
+ /**
52
+ * The player: the package's capsule and clip state machine, this kit's mannequin, gait data and
53
+ * orbit camera. The follow camera and the wall probe stay here because the arm's framing and the
54
+ * sight line are look decisions of this game.
55
+ */
56
+ export function createPlayerRig(ctx: TerrainCtx, options: IPlayerRigOptions): IPlayerRig {
57
+ const { at, cameraOffset, field, focusShadows, horizon, mannequin, staged, swimClips, vista } =
58
+ options;
59
+ // The terrain and the prop colliders are the camera's walls; both answer on the kit's ground lens.
60
+ const along = new Vector3();
61
+ const probe: WallProbe = (from, to) =>
62
+ along.subVectors(to, from).lengthSq() < 1e-8
63
+ ? undefined
64
+ : ctx.physics.directSpaceState.intersectRay({
65
+ ...(staged ? {} : { collisionMask: 4 }),
66
+ from,
67
+ to,
68
+ })?.distance;
69
+ const camera = createOrbitCamera(ctx.camera);
70
+ return createRig({
71
+ ctx,
72
+ at,
73
+ field,
74
+ mannequin,
75
+ clips: CLIPS,
76
+ swimClips,
77
+ cameraOffset,
78
+ collisionMask: staged ? undefined : 4,
79
+ gait: { stride: STRIDE, run: JOG, sprint: SPRINT },
80
+ camera,
81
+ probe: probe as PlayerWallProbe,
82
+ following: () => !vista && ctx.state.getState().view === "player",
83
+ aimHeight: CAMERA_RIG.aimHeight,
84
+ // The vision line the camera aims: the player's own eye line at the prop pack's sight radius.
85
+ sight: { aim: sightLine.aim, radius: sightLine.radius, radiusValue: SIGHT_RADIUS },
86
+ focusShadows,
87
+ horizon,
88
+ });
89
+ }
@@ -46,7 +46,7 @@
46
46
  "type": "erode",
47
47
  "params": {
48
48
  "method": "thermal",
49
- "talus": 60,
49
+ "talus": 48,
50
50
  "iterations": 1,
51
51
  "rate": 0.004
52
52
  }
@@ -58,12 +58,6 @@
58
58
  "type": "materials",
59
59
  "params": {
60
60
  "rules": [
61
- {
62
- "material": "sand",
63
- "mask": {
64
- "type": "all"
65
- }
66
- },
67
61
  {
68
62
  "material": "dirt",
69
63
  "mask": {
@@ -79,7 +73,7 @@
79
73
  "material": "rock",
80
74
  "mask": {
81
75
  "type": "slope",
82
- "min": 28,
76
+ "min": 30,
83
77
  "max": 90,
84
78
  "fade": 8
85
79
  }
@@ -90,19 +84,72 @@
90
84
  {
91
85
  "enabled": true,
92
86
  "opacity": 1,
93
- "id": "scrub",
87
+ "id": "scree",
94
88
  "type": "scatter",
95
89
  "params": {
96
90
  "asset": "boulder",
97
- "count": 140,
98
- "minDistance": 5,
99
- "maxSlope": 25,
100
- "scale": [
101
- 0.7,
102
- 1.3
103
- ]
91
+ "count": 90,
92
+ "minDistance": 6,
93
+ "minSlope": 15,
94
+ "maxSlope": 45,
95
+ "scale": [0.6, 1.6]
104
96
  }
105
97
  }
106
98
  ]
99
+ },
100
+ "world": {
101
+ "name": "desert",
102
+ "ground": {
103
+ "base": "grass",
104
+ "layers": ["dirt", "moss", "sand", "rock", "snow"],
105
+ "roughness": 0.95
106
+ },
107
+ "art": [
108
+ "boulder_01",
109
+ "rock_face",
110
+ "rock_boulder_dry",
111
+ "rocks",
112
+ "cliff_side",
113
+ "snow_02",
114
+ "grass_medium",
115
+ "leafy_grass",
116
+ "lichen_rock",
117
+ "mossy_rock",
118
+ "shrub_02",
119
+ "tree_small_02",
120
+ "fir_tree_01",
121
+ "hdri/kloofendal_48d_partly_cloudy_1k.hdr",
122
+ "mannequin-swim.glb",
123
+ "bark_brown_02",
124
+ "celandine_01",
125
+ "dandelion_01",
126
+ "dead_tree_trunk",
127
+ "dry_branches_medium_01",
128
+ "fern_02",
129
+ "forest_ground_04",
130
+ "moss_01",
131
+ "nettle_plant",
132
+ "periwinkle_plant",
133
+ "sand_01",
134
+ "shrub_04",
135
+ "tree_stump_01",
136
+ "weed_plant_02",
137
+ "needle-atlas.png",
138
+ "needle-surface.png",
139
+ "fir_tree_01/fir_tree_01_twig_arm_1k.jpg",
140
+ "fir_tree_01/fir_tree_01_twig_diff_1k.jpg",
141
+ "fir_tree_01/fir_tree_01_twig_nor_gl_1k.jpg",
142
+ "hdri/kloofendal_48d_partly_cloudy_2k.hdr",
143
+ "desert_flora",
144
+ "desert_rocks",
145
+ "aerial_beach_01",
146
+ "rocky_trail_02"
147
+ ],
148
+ "farRing": {
149
+ "survey": "desert-horizon",
150
+ "datum": 1420,
151
+ "seed": 1,
152
+ "layers": []
153
+ }
107
154
  }
108
155
  }
@@ -0,0 +1,17 @@
1
+ import { type IAssetLoader, fetchAsset } from "@threenative/core";
2
+
3
+ /**
4
+ * One baked file under `world/`, from the first root the asset loader resolves that serves it
5
+ * (core `fetchAsset`). A miss on every root fails closed, naming the file the world is missing.
6
+ */
7
+ export async function fetchBakedFile(
8
+ assets: Pick<IAssetLoader, "resolve">,
9
+ path: string,
10
+ what = "world file",
11
+ ): Promise<Response> {
12
+ try {
13
+ return await fetchAsset(assets, path);
14
+ } catch (error) {
15
+ throw new Error(`Missing baked ${what}: ${path}`, { cause: error });
16
+ }
17
+ }
@@ -0,0 +1,79 @@
1
+ import type { WorldName } from "./biomes.js";
2
+
3
+ /**
4
+ * The fixed benchmark framings, in world metres, per world.
5
+ *
6
+ * Fixed rather than relative to the player so a capture at seed 73 is the same picture on every
7
+ * machine, and so the rubric's "close ground/vegetation view" and "landscape overview" are two
8
+ * numbers rather than two moods. `eye` is the height above the terrain under the camera, which is
9
+ * what makes "eye height ~1.7 m" true on a slope instead of true only on a flat.
10
+ *
11
+ * The meadow focus is where the ground is grass with spruces on it and a slope to look along, and
12
+ * it is also where the dense grass goes: ground cover is placed around this point, not around the
13
+ * origin, because a meadow is a place rather than a texture.
14
+ */
15
+
16
+ /** Every framing the `V` key can hold, whether or not the current world has one for it. */
17
+ export type ViewName = "meadow-close" | "overview" | "player" | "river" | "vista";
18
+
19
+ interface IBenchmarkPose {
20
+ /** World x and z of the eye, and the height above the terrain under it. */
21
+ readonly at: readonly [number, number];
22
+ readonly eye: number;
23
+ /** Absolute elevation for an overview over surveyed scenery beyond the playable collider. */
24
+ readonly eyeY?: number;
25
+ /** World x and z to look at, and the height above the terrain under *that*. */
26
+ readonly look: readonly [number, number];
27
+ readonly lookUp: number;
28
+ /**
29
+ * An absolute world height to look at instead, for a target with no ground under it: a sea
30
+ * horizon is a direction, and thirty metres below the surface three hundred metres out is how a
31
+ * hillside tips its view down far enough for the water to be a band rather than a line.
32
+ */
33
+ readonly lookY?: number;
34
+ }
35
+
36
+ interface IBenchmark {
37
+ /**
38
+ * The playable square the poses frame, in metres. A cooked world of another size
39
+ * (`STRATA_WORLD`, "a huge spruce forest") scales them, so the vista still stands past its edge.
40
+ */
41
+ readonly size?: number;
42
+ /** Where this world's ground cover is placed. */
43
+ readonly focus: { readonly x: number; readonly z: number };
44
+ readonly poses: Readonly<Record<string, IBenchmarkPose>>;
45
+ /** The order the `V` key walks, and the framings the playtest screenshots. */
46
+ readonly views: readonly ViewName[];
47
+ }
48
+
49
+ export const BENCHMARK: Record<WorldName, IBenchmark> = {
50
+ desert: {
51
+ size: 512,
52
+ focus: { x: 120, z: 110 },
53
+ poses: {
54
+ // On the sand flat south-east of Setting Hen Butte, looking at its east face across the scrub.
55
+ "meadow-close": { at: [110, 95], eye: 1.7, look: [20, -10], lookUp: 6 },
56
+ overview: { at: [215, 205], eye: 70, look: [-20, -30], lookUp: 5 },
57
+ // Down in the dry wash south-east of the square, looking back up it to the butte.
58
+ river: { at: [215, 215], eye: 1.7, look: [30, -30], lookUp: 8 },
59
+ // From the butte's shoulder east over the valley floor to the surveyed buttes and Cedar Mesa's
60
+ // rim 2-2.5 km off: the frame that shows the far ring and its join with the square.
61
+ vista: { at: [30, -20], eye: 0, eyeY: 110, look: [2200, 300], lookUp: 0, lookY: 70 },
62
+ },
63
+ views: ["player", "meadow-close", "overview", "river", "vista"],
64
+ },
65
+ };
66
+
67
+ /** A world's poses for a square of `size` metres: x and z scale with it, heights do not. */
68
+ export function posesFor(world: WorldName, size: number): Readonly<Record<string, IBenchmarkPose>> {
69
+ const { poses, size: framed } = BENCHMARK[world];
70
+ const k = framed === undefined ? 1 : size / framed;
71
+ if (k === 1) return poses;
72
+ const scaled = ([x, z]: readonly [number, number]) => [x * k, z * k] as const;
73
+ return Object.fromEntries(
74
+ Object.entries(poses).map(([name, pose]) => [
75
+ name,
76
+ { ...pose, at: scaled(pose.at), look: scaled(pose.look) },
77
+ ]),
78
+ );
79
+ }