@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.
- package/README.md +40 -59
- package/THIRD_PARTY_NOTICES.md +2 -1
- package/dist/bake-DJ5cxg0C.d.ts +82 -0
- package/dist/editor/index.d.ts +4 -4
- package/dist/editor/index.js +130 -128
- package/dist/editor/server.d.ts +2 -2
- package/dist/editor/server.js +38 -35
- package/dist/editor/worker.d.ts +1 -1
- package/dist/editor/worker.js +101 -101
- package/dist/export.d.ts +1 -1
- package/dist/index.d.ts +156 -273
- package/dist/index.js +562 -378
- package/dist/kit-world.d.ts +107 -0
- package/dist/kit-world.js +5134 -0
- package/dist/kit.d.ts +21 -4
- package/dist/kit.js +337 -223
- package/dist/mcp/cook-child.js +1963 -1543
- package/dist/mcp/server.js +716 -429
- package/dist/prop-package-Dwz0EWoB.d.ts +141 -0
- package/dist/{server-B5RdvEAC.d.ts → server-LnFwY8sr.d.ts} +1 -1
- package/dist/starter.d.ts +1142 -7
- package/dist/starter.js +2102 -120
- package/dist/{terrain-CAEaW0mQ.d.ts → terrain-DYCyAOCJ.d.ts} +1 -1
- package/dist/three.d.ts +1 -1
- package/dist/three.js +1 -1
- package/dist/{types-BpH00qsx.d.ts → types-kpI0C4hW.d.ts} +1 -1
- package/dist/{world-package-B8QgHjAQ.d.ts → world-package-DqJC3-Nn.d.ts} +2 -2
- package/docs/authoring/editor.md +73 -0
- package/docs/authoring/new-environment.md +97 -0
- package/docs/authoring/recipes.md +97 -0
- package/docs/authoring/world-export.md +66 -0
- package/package.json +24 -8
- package/starter/alpine/README.md +22 -12
- package/starter/alpine/bake.mjs +14 -1
- package/starter/alpine/biome.data.json +187 -25
- package/starter/alpine/heightmap.r16 +0 -0
- package/starter/alpine/playerRig.ts +89 -0
- package/starter/alpine/recipe.json +169 -15
- package/starter/alpine/render/bakedFile.ts +17 -0
- package/starter/alpine/render/benchmark.ts +77 -0
- package/starter/alpine/render/biomeData.ts +14 -0
- package/starter/alpine/render/biomes.ts +687 -0
- package/starter/alpine/render/ground/cover.ts +565 -0
- package/starter/alpine/render/ground/horizon.ts +219 -0
- package/starter/alpine/render/ground/palette.d.ts +1 -0
- package/starter/alpine/render/ground/palette.js +11 -0
- package/starter/alpine/render/ground/scatter.ts +104 -0
- package/starter/alpine/render/ground/terrain.ts +1860 -0
- package/starter/alpine/render/kitAssets.ts +28 -0
- package/starter/alpine/render/loading.ts +354 -0
- package/starter/alpine/render/lookKnobs.ts +37 -0
- package/starter/alpine/render/orbitCamera.ts +155 -0
- package/starter/alpine/render/props/farForest.ts +94 -0
- package/starter/alpine/render/props/pack.ts +1114 -0
- package/starter/alpine/render/props/prepared.ts +225 -0
- package/starter/alpine/render/props/propMaterials.ts +1239 -0
- package/starter/alpine/render/props/propProgress.ts +2 -0
- package/starter/alpine/render/props/propWorld.ts +105 -0
- package/starter/alpine/render/props/props.ts +633 -0
- package/starter/alpine/render/props/spruce.ts +440 -0
- package/starter/alpine/render/sky/atmosphere.ts +329 -0
- package/starter/alpine/render/sky/sky.ts +382 -0
- package/starter/alpine/render/texturePreparation.ts +135 -0
- package/starter/alpine/render/water/river.ts +1132 -0
- package/starter/alpine/render/worldNames.ts +6 -0
- package/starter/alpine/scene.ts +715 -0
- package/starter/alpine/sceneProps.ts +561 -0
- package/starter/alpine/sceneState.ts +33 -0
- package/starter/alpine/world/terrainAssets.ts +145 -0
- package/starter/alpine/world/walkBand.ts +47 -0
- package/starter/alpine/world/water.ts +74 -0
- package/starter/alpine/worlds.ts +13 -0
- package/starter/arbor/wind.ts +84 -0
- package/starter/coastal/README.md +26 -25
- package/starter/coastal/assets.json +10 -0
- package/starter/coastal/bake.mjs +14 -1
- package/starter/coastal/biome.data.json +18 -3
- package/starter/coastal/playerRig.ts +89 -0
- package/starter/coastal/recipe.json +220 -18
- package/starter/coastal/render/bakedFile.ts +17 -0
- package/starter/coastal/render/benchmark.ts +81 -0
- package/starter/coastal/render/biomeData.ts +14 -0
- package/starter/coastal/render/biomes.ts +678 -0
- package/starter/coastal/render/ground/cover.ts +565 -0
- package/starter/coastal/render/ground/horizon.ts +219 -0
- package/starter/coastal/render/ground/palette.d.ts +1 -0
- package/starter/coastal/render/ground/palette.js +11 -0
- package/starter/coastal/render/ground/scatter.ts +104 -0
- package/starter/coastal/render/ground/terrain.ts +1829 -0
- package/starter/coastal/render/kitAssets.ts +28 -0
- package/starter/coastal/render/loading.ts +354 -0
- package/starter/coastal/render/lookKnobs.ts +37 -0
- package/starter/coastal/render/orbitCamera.ts +155 -0
- package/starter/coastal/render/props/farForest.ts +94 -0
- package/starter/coastal/render/props/pack.ts +1109 -0
- package/starter/coastal/render/props/prepared.ts +225 -0
- package/starter/coastal/render/props/propMaterials.ts +1239 -0
- package/starter/coastal/render/props/propProgress.ts +2 -0
- package/starter/coastal/render/props/propWorld.ts +105 -0
- package/starter/coastal/render/props/props.ts +633 -0
- package/starter/coastal/render/props/spruce.ts +440 -0
- package/starter/coastal/render/sky/atmosphere.ts +329 -0
- package/starter/coastal/render/sky/sky.ts +382 -0
- package/starter/coastal/render/texturePreparation.ts +135 -0
- package/starter/coastal/render/water/ocean.ts +284 -0
- package/starter/coastal/render/water/river.ts +1132 -0
- package/starter/coastal/render/worldNames.ts +6 -0
- package/starter/coastal/scene.ts +740 -0
- package/starter/coastal/sceneProps.ts +559 -0
- package/starter/coastal/sceneState.ts +33 -0
- package/starter/coastal/world/terrainAssets.ts +151 -0
- package/starter/coastal/world/walkBand.ts +47 -0
- package/starter/coastal/world/water.ts +74 -0
- package/starter/coastal/worlds.ts +13 -0
- package/starter/desert/README.md +51 -23
- package/starter/desert/bake-flora.mjs +142 -0
- package/starter/desert/bake-rocks.mjs +291 -0
- package/starter/desert/bake.mjs +14 -1
- package/starter/desert/biome.data.json +24 -12
- package/starter/desert/playerRig.ts +89 -0
- package/starter/desert/recipe.json +63 -16
- package/starter/desert/render/bakedFile.ts +17 -0
- package/starter/desert/render/benchmark.ts +79 -0
- package/starter/desert/render/biomeData.ts +14 -0
- package/starter/desert/render/biomes.ts +660 -0
- package/starter/desert/render/ground/cover.ts +565 -0
- package/starter/desert/render/ground/debris.ts +136 -0
- package/starter/desert/render/ground/horizon.ts +219 -0
- package/starter/desert/render/ground/palette.d.ts +1 -0
- package/starter/desert/render/ground/palette.js +11 -0
- package/starter/desert/render/ground/scatter.ts +104 -0
- package/starter/desert/render/ground/terrain.ts +1854 -0
- package/starter/desert/render/kitAssets.ts +28 -0
- package/starter/desert/render/loading.ts +354 -0
- package/starter/desert/render/lookKnobs.ts +37 -0
- package/starter/desert/render/orbitCamera.ts +155 -0
- package/starter/desert/render/props/farForest.ts +96 -0
- package/starter/desert/render/props/formations.ts +630 -0
- package/starter/desert/render/props/pack.ts +1195 -0
- package/starter/desert/render/props/prepared.ts +225 -0
- package/starter/desert/render/props/propMaterials.ts +1255 -0
- package/starter/desert/render/props/propProgress.ts +2 -0
- package/starter/desert/render/props/propWorld.ts +105 -0
- package/starter/desert/render/props/props.ts +624 -0
- package/starter/desert/render/props/spruce.ts +440 -0
- package/starter/desert/render/sand.ts +581 -0
- package/starter/desert/render/sky/atmosphere.ts +329 -0
- package/starter/desert/render/sky/sky.ts +382 -0
- package/starter/desert/render/texturePreparation.ts +135 -0
- package/starter/desert/render/water/river.ts +1132 -0
- package/starter/desert/render/worldNames.ts +6 -0
- package/starter/desert/scene.ts +748 -0
- package/starter/desert/sceneProps.ts +562 -0
- package/starter/desert/sceneState.ts +33 -0
- package/starter/desert/world/terrainAssets.ts +162 -0
- package/starter/desert/world/walkBand.ts +47 -0
- package/starter/desert/world/water.ts +74 -0
- package/starter/desert/worlds.ts +13 -0
- package/starter/forest/README.md +59 -116
- package/starter/forest/assets.json +14 -14
- package/starter/forest/bake.mjs +26 -4
- package/starter/forest/playerRig.ts +89 -0
- package/starter/forest/recipe.json +233 -43
- package/starter/forest/render/bakedFile.ts +17 -0
- package/starter/forest/render/benchmark.ts +77 -0
- package/starter/forest/render/biomeData.ts +14 -0
- package/starter/forest/render/biomes.ts +637 -0
- package/starter/forest/render/ground/cover.ts +565 -0
- package/starter/forest/render/ground/horizon.ts +219 -0
- package/starter/forest/render/ground/palette.d.ts +1 -0
- package/starter/forest/render/ground/palette.js +11 -0
- package/starter/forest/render/ground/scatter.ts +104 -0
- package/starter/forest/render/ground/terrain.ts +1796 -0
- package/starter/forest/render/kitAssets.ts +28 -0
- package/starter/forest/render/loading.ts +354 -0
- package/starter/forest/render/lookKnobs.ts +37 -0
- package/starter/forest/render/orbitCamera.ts +155 -0
- package/starter/forest/render/props/farForest.ts +94 -0
- package/starter/forest/render/props/pack.ts +1078 -0
- package/starter/forest/render/props/prepared.ts +226 -0
- package/starter/forest/render/props/propMaterials.ts +1247 -0
- package/starter/forest/render/props/propProgress.ts +2 -0
- package/starter/forest/render/props/propWorld.ts +105 -0
- package/starter/forest/render/props/props.ts +624 -0
- package/starter/forest/render/props/spruce.ts +440 -0
- package/starter/forest/render/sky/atmosphere.ts +329 -0
- package/starter/forest/render/sky/sky.ts +382 -0
- package/starter/forest/render/texturePreparation.ts +135 -0
- package/starter/forest/render/water/river.ts +1132 -0
- package/starter/forest/render/worldNames.ts +6 -0
- package/starter/forest/scene.ts +715 -0
- package/starter/forest/sceneProps.ts +559 -0
- package/starter/forest/sceneState.ts +33 -0
- package/starter/forest/surface.json +2 -2
- package/starter/forest/world/terrainAssets.ts +158 -0
- package/starter/forest/world/walkBand.ts +47 -0
- package/starter/forest/world/water.ts +74 -0
- package/starter/forest/worlds.ts +13 -0
- package/starter/tundra/README.md +35 -14
- package/starter/tundra/bake.mjs +14 -1
- package/starter/tundra/biome.data.json +6 -6
- package/starter/tundra/playerRig.ts +89 -0
- package/starter/tundra/recipe.json +111 -110
- package/starter/tundra/render/bakedFile.ts +17 -0
- package/starter/tundra/render/benchmark.ts +79 -0
- package/starter/tundra/render/biomeData.ts +14 -0
- package/starter/tundra/render/biomes.ts +714 -0
- package/starter/tundra/render/ground/cover.ts +565 -0
- package/starter/tundra/render/ground/horizon.ts +219 -0
- package/starter/tundra/render/ground/palette.d.ts +1 -0
- package/starter/tundra/render/ground/palette.js +11 -0
- package/starter/tundra/render/ground/scatter.ts +104 -0
- package/starter/tundra/render/ground/terrain.ts +1874 -0
- package/starter/tundra/render/kitAssets.ts +28 -0
- package/starter/tundra/render/loading.ts +354 -0
- package/starter/tundra/render/lookKnobs.ts +37 -0
- package/starter/tundra/render/orbitCamera.ts +155 -0
- package/starter/tundra/render/props/farForest.ts +96 -0
- package/starter/tundra/render/props/pack.ts +1088 -0
- package/starter/tundra/render/props/prepared.ts +225 -0
- package/starter/tundra/render/props/propMaterials.ts +1247 -0
- package/starter/tundra/render/props/propProgress.ts +2 -0
- package/starter/tundra/render/props/propWorld.ts +105 -0
- package/starter/tundra/render/props/props.ts +624 -0
- package/starter/tundra/render/props/spruce.ts +440 -0
- package/starter/tundra/render/sky/atmosphere.ts +329 -0
- package/starter/tundra/render/sky/sky.ts +382 -0
- package/starter/tundra/render/texturePreparation.ts +135 -0
- package/starter/tundra/render/water/river.ts +1132 -0
- package/starter/tundra/render/worldNames.ts +6 -0
- package/starter/tundra/scene.ts +715 -0
- package/starter/tundra/sceneProps.ts +559 -0
- package/starter/tundra/sceneState.ts +33 -0
- package/starter/tundra/world/terrainAssets.ts +159 -0
- package/starter/tundra/world/walkBand.ts +47 -0
- package/starter/tundra/world/water.ts +74 -0
- package/starter/tundra/worlds.ts +13 -0
- package/starter-assets.json +4 -4
- package/starter-credits.json +901 -15
- package/AGENT_GUIDE.md +0 -209
- package/starter/forest/sky.ts +0 -38
- package/starter/forest/water.ts +0 -257
- package/starter/forest/world.ts +0 -182
|
@@ -0,0 +1,158 @@
|
|
|
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
|
+
/** The prepared fir's twig atlas: colour, tangent-space normal, and the packed arms map. */
|
|
106
|
+
export const FIR_MAPS = {
|
|
107
|
+
arms: "fir_tree_01/fir_tree_01_twig_arm_1k.jpg",
|
|
108
|
+
normal: "fir_tree_01/fir_tree_01_twig_nor_gl_1k.jpg",
|
|
109
|
+
surface: "fir_tree_01/fir_tree_01_twig_diff_1k.jpg",
|
|
110
|
+
} as const;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Poly Haven's `tree_small_02` (CC0), grown to forest height as leaf cards: two silhouettes, each a
|
|
114
|
+
* `-near.glb` and a `-mid.glb` (`scripts/prep/prep-polyhaven-broadleaf.py`).
|
|
115
|
+
*/
|
|
116
|
+
export const BROADLEAF_TREES = ["tree_small_02/broadleaf", "tree_small_02/broadleaf-b"] as const;
|
|
117
|
+
|
|
118
|
+
/** The fern's own atlas: a photographed frond and its separate cut-out alpha. */
|
|
119
|
+
export const FERN_MAPS = {
|
|
120
|
+
alpha: "fern_02/fern_02_alpha_512.png",
|
|
121
|
+
diffuse: "fern_02/fern_02_diff_512.jpg",
|
|
122
|
+
} as const;
|
|
123
|
+
|
|
124
|
+
/** One prepared placement file: what it is, which variant it fills, and which detail level it is. */
|
|
125
|
+
export interface IPreparedFile {
|
|
126
|
+
readonly asset: string;
|
|
127
|
+
readonly level: number;
|
|
128
|
+
readonly path: string;
|
|
129
|
+
readonly variant: number;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The prepared files, in the order they are asked for.
|
|
134
|
+
*
|
|
135
|
+
* **Nothing on this list any more.** The three CC0 rocks and the two prepared firs were replaced by
|
|
136
|
+
* the licensed Landscape Pro species in `src/render/props/pack.ts` — real photoscanned stone at 7,178
|
|
137
|
+
* triangles where the CC0 set's were 1–2k, and real pines where the fir's crown measured 0.3% of
|
|
138
|
+
* its own silhouette at the tree budget (`credits.json` has that number, and it is why the starter
|
|
139
|
+
* kept its procedural spruce). The list and its loader stay because they are how the next source is
|
|
140
|
+
* measured, and because a prepared file that is not there is not an error: this map is empty on CI,
|
|
141
|
+
* on a fresh clone and in a review, and the procedural variants are what draw there.
|
|
142
|
+
*
|
|
143
|
+
* A species that IS added back comes in as one entry per detail level, because a variant with a near
|
|
144
|
+
* level and no mid level is a variant whose middle distance pops. Three rocks at both of their levels
|
|
145
|
+
* was six draws for stone the eye cannot tell apart at meadow distance, against the starter's
|
|
146
|
+
* twenty-four-draw ceiling for the whole meadow — which is the trade this list now records.
|
|
147
|
+
*/
|
|
148
|
+
export const PREPARED: readonly IPreparedFile[] = [
|
|
149
|
+
// The committed fallback's stone: two photoscanned CC0 rocks at both levels. Where the licensed
|
|
150
|
+
// pack loaded, its boulders take these same indices 1 and 2 (the pack's parts are merged after these), so
|
|
151
|
+
// this only draws on CI, on a fresh clone and in a review — which is the starter that ships, and
|
|
152
|
+
// a procedural lump there is the wrong first impression. Two, not three: three at two levels put
|
|
153
|
+
// the pack-less meadow one draw over its ceiling.
|
|
154
|
+
{ asset: "boulder", level: 0, path: "rocks/rock01-near.glb", variant: 1 },
|
|
155
|
+
{ asset: "boulder", level: 1, path: "rocks/rock01-mid.glb", variant: 1 },
|
|
156
|
+
{ asset: "boulder", level: 0, path: "rocks/boulder-near.glb", variant: 2 },
|
|
157
|
+
{ asset: "boulder", level: 1, path: "rocks/boulder-mid.glb", variant: 2 },
|
|
158
|
+
];
|
|
@@ -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
|
+
}
|
package/starter/tundra/README.md
CHANGED
|
@@ -1,35 +1,56 @@
|
|
|
1
1
|
# Tundra starter kit
|
|
2
2
|
|
|
3
|
-
A 512 m
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
A 512 m alpine tundra on Trail Ridge, Rocky Mountain National Park, 3430-3480 m (USGS 1 m DEM),
|
|
4
|
+
above the tree line: short sedge and grass turf, fellfield gravel and grey lichen, late snow patches,
|
|
5
|
+
two meltwater streams and two kettle ponds, krummholz at the low edge, dwarf willow in the swales and
|
|
6
|
+
lichen-crusted erratics. The far ring is the same survey out to 5 km on the square's own datum: Trail
|
|
7
|
+
Ridge's 3.7-3.8 km peaks and the forested valleys under them. It is game source: once copied, every
|
|
8
|
+
file is yours to edit.
|
|
6
9
|
|
|
7
10
|
| File | What it decides |
|
|
8
11
|
| --- | --- |
|
|
9
|
-
| `recipe.json` | The terrain: the survey heightmap, erosion, the kettle beds, the two
|
|
10
|
-
| `
|
|
11
|
-
| `
|
|
12
|
-
| `
|
|
13
|
-
| `
|
|
14
|
-
| `
|
|
15
|
-
| `
|
|
12
|
+
| `recipe.json` | The terrain: the survey heightmap, erosion, the kettle beds, the two streams, the two ponds, the surfaces and the erratics; its `world` row names the ground layers, the art and the far ring. |
|
|
13
|
+
| `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. |
|
|
14
|
+
| `biome.data.json` | The biome record: the krummholz, the turf, the cushion plants, the willow, the stones and their bands. The streamed bake places from it. |
|
|
15
|
+
| `assets.json` | The legacy cell package's boulder model, LOD distance, draw distance and bounds. |
|
|
16
|
+
| `surface.json` | The legacy cell package's ground table: moss base, snow and rock layers, tiles, tints and thresholds. |
|
|
17
|
+
| `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. |
|
|
18
|
+
| `scene.ts` | The scene, `TundraScene`, and `TUNDRA_GAME`: the streamed ground, the far ring, the props, the sky, the ponds and streams, and the player rig. |
|
|
19
|
+
| `render/` | The look: the biome row (`render/biomes.ts`), the ground material, the palette, the species pack (`render/props/pack.ts`), the sky and the water. |
|
|
20
|
+
| `world.ts`, `sky.ts`, `water.ts` | The legacy cell-package loader, its daylight and its water, kept until the streamed bake retires them here. |
|
|
16
21
|
|
|
17
22
|
Art is CC0 (Poly Haven); provenance is in `@threenative/terrain/starter-credits.json`.
|
|
18
23
|
|
|
24
|
+
## What draws each species
|
|
25
|
+
|
|
26
|
+
The bake's ordered tundra stream places six kinds; `render/props/pack.ts` decides the art for each:
|
|
27
|
+
|
|
28
|
+
| Placed kind | Drawn as |
|
|
29
|
+
| --- | --- |
|
|
30
|
+
| `sapling` | Krummholz spruce and fir: the fir scan, squashed to a wind-pruned mat |
|
|
31
|
+
| `bush` | Dwarf willow and blueberry shrubs |
|
|
32
|
+
| `grass` | Short alpine sedge and grass tufts |
|
|
33
|
+
| `scrub` | Cushion plants and moss mats |
|
|
34
|
+
| `boulder`, `riverrock` | Lichen-crusted erratics and stream stones |
|
|
35
|
+
|
|
19
36
|
## Status
|
|
20
37
|
|
|
21
|
-
The kit
|
|
22
|
-
|
|
38
|
+
The kit is a source kit on the forest's stack: `scene.ts` streams the baked world, its far ring and
|
|
39
|
+
its props, and composes the player rig and diagnostics from `@threenative/terrain/starter`.
|
|
23
40
|
|
|
24
41
|
## Steps
|
|
25
42
|
|
|
26
43
|
1. Copy `node_modules/@threenative/terrain/starter/tundra` to `src/terrain/tundra`.
|
|
27
44
|
2. Run `node src/terrain/tundra/bake.mjs --out assets/terrain/tundra` (needs `@threenative/terrain`
|
|
28
|
-
as
|
|
29
|
-
|
|
45
|
+
and `tsx` as devDependencies, because the bake reads this kit's TypeScript look). The same recipe
|
|
46
|
+
always writes the same bytes.
|
|
47
|
+
3. Spread `TUNDRA_GAME` into `defineGame` and register `TundraScene`, as the forest kit's README shows.
|
|
30
48
|
|
|
31
49
|
## Edit at startup, without rebaking
|
|
32
50
|
|
|
51
|
+
> The streamed bake retires this path for the tundra kit: the ground table and the props now come
|
|
52
|
+
> from `render/`, and the section below still describes the legacy cell package.
|
|
53
|
+
|
|
33
54
|
The copied `world.ts` loads its own `surface.json` as the ground table on every startup.
|
|
34
55
|
Edit tints, tiling and blend thresholds there, or the material graph and prop dressing in
|
|
35
56
|
`world.ts`, then reload. The package's `terrain-table.json` remains the baked default for
|
package/starter/tundra/bake.mjs
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
// Run with [--assets <dir>] [--out <dir>]; defaults to installed assets and ./world.
|
|
2
|
+
// The tundra 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
|
-
|
|
13
|
+
look: {
|
|
14
|
+
palette: terrainPalette,
|
|
15
|
+
ground: { maps: GROUND_MAPS, tile: GROUND_TILE },
|
|
16
|
+
canopy: CANOPY_CROWN,
|
|
17
|
+
props,
|
|
18
|
+
},
|
|
6
19
|
});
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"seed": 466468,
|
|
14
14
|
"attempts": 80000,
|
|
15
15
|
"stoneRadius": 1.9,
|
|
16
|
-
"clearings": [[
|
|
16
|
+
"clearings": [[150, 205, 10]],
|
|
17
17
|
"understorey": {
|
|
18
18
|
"attempts": 14000,
|
|
19
19
|
"litter": 1,
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"foliage": [
|
|
29
29
|
{
|
|
30
30
|
"species": "sapling",
|
|
31
|
-
"density":
|
|
31
|
+
"density": 140,
|
|
32
32
|
"slope": [0, 32],
|
|
33
33
|
"height": null,
|
|
34
34
|
"spacing": [3.4, 3.4],
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"density": 1,
|
|
46
46
|
"slope": [0, 30],
|
|
47
47
|
"height": null,
|
|
48
|
-
"spacing": 1.
|
|
48
|
+
"spacing": 1.1,
|
|
49
49
|
"slopeFalloff": 22,
|
|
50
50
|
"heightFalloff": 28,
|
|
51
51
|
"mats": [0.47, 0.3],
|
|
@@ -132,10 +132,10 @@
|
|
|
132
132
|
}
|
|
133
133
|
],
|
|
134
134
|
"spawn": {
|
|
135
|
-
"at": [
|
|
135
|
+
"at": [150, 205],
|
|
136
136
|
"cameraOffset": [28, 24, 42],
|
|
137
|
-
"focus": [150,
|
|
137
|
+
"focus": [150, 205]
|
|
138
138
|
},
|
|
139
|
-
"species": ["boulder", "bush", "riverrock", "sapling", "scree", "scrub"],
|
|
139
|
+
"species": ["boulder", "bush", "grass", "riverrock", "sapling", "scree", "scrub"],
|
|
140
140
|
"aliases": ["tundra", "arctic", "ice", "frozen", "permafrost", "glacial"]
|
|
141
141
|
}
|
|
@@ -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
|
+
}
|