@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.
- package/README.md +1 -0
- package/dist/bake-DJ5cxg0C.d.ts +82 -0
- package/dist/editor/index.d.ts +4 -4
- package/dist/editor/index.js +1 -1
- package/dist/editor/server.d.ts +2 -2
- package/dist/editor/worker.d.ts +1 -1
- package/dist/editor/worker.js +1 -1
- package/dist/export.d.ts +1 -1
- package/dist/index.d.ts +51 -222
- package/dist/index.js +111 -2
- 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 +19 -4
- package/dist/mcp/cook-child.js +9 -6
- package/dist/mcp/server.js +14 -4
- 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 +1141 -6
- package/dist/starter.js +1999 -17
- package/dist/{terrain-CAEaW0mQ.d.ts → terrain-DYCyAOCJ.d.ts} +1 -1
- package/dist/three.d.ts +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/new-environment.md +97 -0
- package/package.json +8 -8
- package/starter/alpine/README.md +22 -14
- 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/coastal/README.md +26 -27
- 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 -25
- 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 +8 -5
- package/starter/forest/bake.mjs +21 -413
- package/starter/forest/playerRig.ts +37 -171
- package/starter/forest/recipe.json +237 -47
- package/starter/forest/render/biomes.ts +2 -1
- package/starter/forest/render/ground/horizon.ts +4 -302
- package/starter/forest/render/ground/terrain.ts +14 -32
- package/starter/forest/render/kitAssets.ts +3 -2
- package/starter/forest/render/props/farForest.ts +2 -1
- package/starter/forest/render/props/pack.ts +4 -2
- package/starter/forest/render/props/prepared.ts +2 -1
- package/starter/forest/render/props/propProgress.ts +1 -11
- package/starter/forest/render/props/propWorld.ts +48 -662
- package/starter/forest/render/props/props.ts +64 -248
- package/starter/forest/render/sky/sky.ts +2 -1
- package/starter/forest/render/worldNames.ts +6 -2
- package/starter/forest/scene.ts +34 -25
- package/starter/forest/sceneProps.ts +2 -2
- package/starter/forest/sceneState.ts +5 -4
- package/starter/forest/surface.json +2 -2
- package/starter/forest/worlds.ts +3 -2
- package/starter/tundra/README.md +35 -16
- 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 +613 -10
- package/starter/forest/diagnostics.ts +0 -1020
- package/starter/forest/render/sky/skyVisibility.ts +0 -121
- package/starter/forest/spawnGate.ts +0 -183
- package/starter/forest/viewStatistics.ts +0 -47
- package/starter/forest/world/streamedGround.ts +0 -139
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { createRandom } from "@threenative/core";
|
|
2
|
+
// The desert floor's loose stone and dead wood: talus aprons under every butte face, and pebbles,
|
|
3
|
+
// stones and fallen juniper wood scattered thinly across the flats.
|
|
4
|
+
//
|
|
5
|
+
// A sandstone face sheds blocks that roll to its foot, so the debris is densest on the gentle ground
|
|
6
|
+
// just below a cliff and thins with distance from it. The bake's ordered stream places the boulders a
|
|
7
|
+
// biome row asks for; this is the game's own runtime layer over the playable square, from the baked
|
|
8
|
+
// heights and the game's own seed, the way `scatter.ts` plants the meadow past the square.
|
|
9
|
+
import type { IPlacement } from "@threenative/terrain";
|
|
10
|
+
|
|
11
|
+
/** The seed the debris draws from, a step past the bake's ordered stream and the meadow's. */
|
|
12
|
+
const DEBRIS_SEED = 466_468 + 57;
|
|
13
|
+
|
|
14
|
+
/** The talus apron, in metres and degrees: what counts as a face, and how far below it stone lies. */
|
|
15
|
+
export const TALUS = {
|
|
16
|
+
/** Ground at least this steep is a shedding face. */
|
|
17
|
+
faceSlope: 38,
|
|
18
|
+
/** Ground steeper than this holds no loose stone: it slides on down. */
|
|
19
|
+
restSlope: 34,
|
|
20
|
+
/** How far below a face the apron reaches. */
|
|
21
|
+
reach: 22,
|
|
22
|
+
/** How much higher the face must stand than the apron cell, so a rim is not its own talus. */
|
|
23
|
+
drop: 3,
|
|
24
|
+
} as const;
|
|
25
|
+
|
|
26
|
+
/** Mean placements per 2 m cell at full apron weight, and on the open flats. */
|
|
27
|
+
const APRON = { pebble: 2.2, scree: 0.9, volcanic: 0.28, reveal: 0.05, deadfall: 0.03 } as const;
|
|
28
|
+
const FLAT = { pebble: 0.16, scree: 0.02, volcanic: 0.006, deadfall: 0.022 } as const;
|
|
29
|
+
|
|
30
|
+
/** The heights this layer reads: the bake's square, row-major Z then X, centred at zero. */
|
|
31
|
+
export interface IDebrisGround {
|
|
32
|
+
readonly size: number;
|
|
33
|
+
readonly resolution: number;
|
|
34
|
+
readonly heights: ArrayLike<number>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Slope in degrees at every cell, from central differences. */
|
|
38
|
+
function slopes({ size, resolution: n, heights }: IDebrisGround): Float32Array {
|
|
39
|
+
const step = size / (n - 1);
|
|
40
|
+
const out = new Float32Array(n * n);
|
|
41
|
+
const at = (r: number, c: number) =>
|
|
42
|
+
heights[Math.min(n - 1, Math.max(0, r)) * n + Math.min(n - 1, Math.max(0, c))] ?? 0;
|
|
43
|
+
for (let r = 0; r < n; r++)
|
|
44
|
+
for (let c = 0; c < n; c++) {
|
|
45
|
+
const dx = (at(r, c + 1) - at(r, c - 1)) / (2 * step);
|
|
46
|
+
const dz = (at(r + 1, c) - at(r - 1, c)) / (2 * step);
|
|
47
|
+
out[r * n + c] = (Math.atan(Math.hypot(dx, dz)) * 180) / Math.PI;
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The apron weight at every cell, 0..1: 1 at the foot of a face, falling to 0 at `TALUS.reach`
|
|
54
|
+
* metres, and 0 on ground too steep to hold stone or above every nearby face.
|
|
55
|
+
*/
|
|
56
|
+
export function talusWeight(ground: IDebrisGround): Float32Array {
|
|
57
|
+
const { size, resolution: n, heights } = ground;
|
|
58
|
+
const step = size / (n - 1);
|
|
59
|
+
const slope = slopes(ground);
|
|
60
|
+
const radius = Math.ceil(TALUS.reach / step);
|
|
61
|
+
const weight = new Float32Array(n * n);
|
|
62
|
+
for (let r = 0; r < n; r++)
|
|
63
|
+
for (let c = 0; c < n; c++) {
|
|
64
|
+
const here = r * n + c;
|
|
65
|
+
if ((slope[here] ?? 90) > TALUS.restSlope) continue;
|
|
66
|
+
const height = heights[here] ?? 0;
|
|
67
|
+
let nearest = Number.POSITIVE_INFINITY;
|
|
68
|
+
for (let dr = -radius; dr <= radius; dr++)
|
|
69
|
+
for (let dc = -radius; dc <= radius; dc++) {
|
|
70
|
+
const rr = r + dr;
|
|
71
|
+
const cc = c + dc;
|
|
72
|
+
if (rr < 0 || cc < 0 || rr >= n || cc >= n) continue;
|
|
73
|
+
const there = rr * n + cc;
|
|
74
|
+
if ((slope[there] ?? 0) < TALUS.faceSlope) continue;
|
|
75
|
+
if ((heights[there] ?? 0) < height + TALUS.drop) continue;
|
|
76
|
+
nearest = Math.min(nearest, Math.hypot(dr, dc) * step);
|
|
77
|
+
}
|
|
78
|
+
if (nearest < TALUS.reach) weight[here] = (1 - nearest / TALUS.reach) ** 1.5;
|
|
79
|
+
}
|
|
80
|
+
return weight;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Every debris placement on the square: talus at the cliff feet, a thin scatter on the flats. `y` is
|
|
85
|
+
* 0: the game's ground query sets the height, as it does for the meadow.
|
|
86
|
+
*/
|
|
87
|
+
export function desertDebris(ground: IDebrisGround): IPlacement[] {
|
|
88
|
+
const { size, resolution: n } = ground;
|
|
89
|
+
const step = size / (n - 1);
|
|
90
|
+
const half = size / 2;
|
|
91
|
+
const slope = slopes(ground);
|
|
92
|
+
const apron = talusWeight(ground);
|
|
93
|
+
const random = createRandom(DEBRIS_SEED);
|
|
94
|
+
const placements: IPlacement[] = [];
|
|
95
|
+
const counts: Record<string, number> = {};
|
|
96
|
+
const put = (asset: string, x: number, z: number, scale: number) => {
|
|
97
|
+
if (Math.abs(x) > half - 2 || Math.abs(z) > half - 2) return;
|
|
98
|
+
const index = counts[asset] ?? 0;
|
|
99
|
+
counts[asset] = index + 1;
|
|
100
|
+
placements.push({
|
|
101
|
+
asset,
|
|
102
|
+
id: `desert-${asset}:debris-${index}`,
|
|
103
|
+
layer: `desert-${asset}`,
|
|
104
|
+
alignToNormal: asset !== "deadfall",
|
|
105
|
+
normal: [0, 1, 0],
|
|
106
|
+
position: [x, 0, z],
|
|
107
|
+
rotation: random() * Math.PI * 2,
|
|
108
|
+
scale,
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
/** Rounds `mean` to a whole count with the remainder as a chance. */
|
|
112
|
+
const many = (mean: number) => Math.floor(mean) + (random() < mean % 1 ? 1 : 0);
|
|
113
|
+
for (let r = 0; r < n; r++)
|
|
114
|
+
for (let c = 0; c < n; c++) {
|
|
115
|
+
const here = r * n + c;
|
|
116
|
+
const w = apron[here] ?? 0;
|
|
117
|
+
const open = (slope[here] ?? 90) < 22 ? 1 : 0;
|
|
118
|
+
const x0 = -half + c * step;
|
|
119
|
+
const z0 = -half + r * step;
|
|
120
|
+
const at = (): [number, number] => [
|
|
121
|
+
x0 + (random() - 0.5) * step,
|
|
122
|
+
z0 + (random() - 0.5) * step,
|
|
123
|
+
];
|
|
124
|
+
for (let k = many(APRON.pebble * w + FLAT.pebble * open); k > 0; k--)
|
|
125
|
+
put("pebble", ...at(), 0.08 + random() * 0.22);
|
|
126
|
+
for (let k = many(APRON.scree * w + FLAT.scree * open); k > 0; k--)
|
|
127
|
+
put("scree", ...at(), 0.4 + random() * 0.9 * (0.5 + w));
|
|
128
|
+
for (let k = many(APRON.volcanic * w + FLAT.volcanic * open); k > 0; k--)
|
|
129
|
+
put("volcanic", ...at(), 0.12 + random() * 0.35 * (0.4 + w));
|
|
130
|
+
for (let k = many(APRON.reveal * w); k > 0; k--)
|
|
131
|
+
put("reveal", ...at(), 0.36 + random() * 0.5);
|
|
132
|
+
for (let k = many(APRON.deadfall * w + FLAT.deadfall * open); k > 0; k--)
|
|
133
|
+
put("deadfall", ...at(), 0.6 + random() * 0.7);
|
|
134
|
+
}
|
|
135
|
+
return placements;
|
|
136
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import type { IAssetLoader } from "@threenative/core";
|
|
2
|
+
import {
|
|
3
|
+
Heightfield,
|
|
4
|
+
HeightfieldCollar,
|
|
5
|
+
type IHeightfieldCollarSite,
|
|
6
|
+
} from "@threenative/core/world";
|
|
7
|
+
import { MathUtils } from "three";
|
|
8
|
+
import { fetchBakedFile } from "../bakedFile.js";
|
|
9
|
+
import type { WorldName } from "../biomes.js";
|
|
10
|
+
import type { IBakedWorld } from "./terrain.js";
|
|
11
|
+
|
|
12
|
+
/** `world/horizon.json`: each world's same-site USGS surroundings, as `scripts/bake/bake.mjs` writes them. */
|
|
13
|
+
export type HorizonSurroundings = Record<
|
|
14
|
+
string,
|
|
15
|
+
{ resolution: number; size: number; heights: number[]; massif?: IPackedMassif }
|
|
16
|
+
>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A placed survey massif at its tile's own spacing (`placeMassif`), for the collar's relief map:
|
|
20
|
+
* int16 decimetres above `offset`, base64, row-major from `origin`, +X east and +Z south.
|
|
21
|
+
*/
|
|
22
|
+
export interface IPackedMassif {
|
|
23
|
+
readonly origin: readonly [number, number];
|
|
24
|
+
readonly spacing: number;
|
|
25
|
+
readonly columns: number;
|
|
26
|
+
readonly rows: number;
|
|
27
|
+
readonly offset: number;
|
|
28
|
+
readonly heights: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Each world keeps its own surroundings in the installed Heightfield query. They are fetched, not
|
|
32
|
+
// imported: as a module the 7 MB file took about 3 s to compile before the first frame.
|
|
33
|
+
let continuationFields: Record<string, Heightfield> = {};
|
|
34
|
+
let sources: HorizonSurroundings = {};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* `world/horizon.json`, fetched once per page and installed here. A failed fetch clears the memo
|
|
38
|
+
* before it rethrows, so the next world load retries instead of rethrowing the first failure for
|
|
39
|
+
* the page's whole life.
|
|
40
|
+
*/
|
|
41
|
+
let horizonLoad: Promise<void> | undefined;
|
|
42
|
+
|
|
43
|
+
export function loadHorizonSurroundings(assets: Pick<IAssetLoader, "resolve">): Promise<void> {
|
|
44
|
+
horizonLoad ??= fetchBakedFile(assets, "world/horizon.json")
|
|
45
|
+
.then((response) => response.json())
|
|
46
|
+
.then((distant) => setHorizonSurroundings(distant as HorizonSurroundings))
|
|
47
|
+
.catch((error: unknown) => {
|
|
48
|
+
horizonLoad = undefined;
|
|
49
|
+
throw error;
|
|
50
|
+
});
|
|
51
|
+
return horizonLoad;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Installs the surroundings `createHorizonCollar` reads; call once before building terrain. */
|
|
55
|
+
export function setHorizonSurroundings(baked: HorizonSurroundings): void {
|
|
56
|
+
sources = baked;
|
|
57
|
+
continuationFields = Object.fromEntries(
|
|
58
|
+
Object.entries(baked).map(([name, source]) => [
|
|
59
|
+
name,
|
|
60
|
+
field(source, new Float32Array(source.heights)),
|
|
61
|
+
]),
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** One world's installed surroundings, unfiltered, as the bake wrote them. */
|
|
66
|
+
export function horizonSurroundings(name: string): HorizonSurroundings[string] | undefined {
|
|
67
|
+
return sources[name];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function field(source: HorizonSurroundings[string], heights: Float32Array): Heightfield {
|
|
71
|
+
return new Heightfield({
|
|
72
|
+
rows: source.resolution,
|
|
73
|
+
columns: source.resolution,
|
|
74
|
+
width: source.size,
|
|
75
|
+
depth: source.size,
|
|
76
|
+
origin: { x: 0, z: 0 },
|
|
77
|
+
heights,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const catmullRom = (a: number, b: number, c: number, d: number, t: number): number =>
|
|
82
|
+
b + 0.5 * t * (c - a + t * (2 * a - 5 * b + 4 * c - d + t * (3 * (b - c) + d - a)));
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The survey at `(x, z)` through a Catmull-Rom patch of its 4×4 nearest samples: C1 across cell
|
|
86
|
+
* edges, so a diagonal wall draws a straight skyline, and it passes through every sample, so no
|
|
87
|
+
* ridge or gully is lost to a blur. Throws outside the survey, as `Heightfield.heightAt` does.
|
|
88
|
+
*/
|
|
89
|
+
export function cubicAt(world: string, x: number, z: number): number {
|
|
90
|
+
const source = sources[world];
|
|
91
|
+
if (!source) throw new RangeError(`Missing surveyed surroundings for '${world}'`);
|
|
92
|
+
const { heights, resolution: n, size } = source;
|
|
93
|
+
const column = (x / size + 0.5) * (n - 1);
|
|
94
|
+
const row = (z / size + 0.5) * (n - 1);
|
|
95
|
+
if (!(column >= 0 && row >= 0 && column <= n - 1 && row <= n - 1))
|
|
96
|
+
throw new RangeError(`Survey query (${x}, ${z}) is outside '${world}'`);
|
|
97
|
+
const c0 = Math.min(n - 2, Math.floor(column));
|
|
98
|
+
const r0 = Math.min(n - 2, Math.floor(row));
|
|
99
|
+
const at = (r: number, c: number): number =>
|
|
100
|
+
heights[Math.min(n - 1, Math.max(0, r)) * n + Math.min(n - 1, Math.max(0, c))] as number;
|
|
101
|
+
const line = (r: number): number =>
|
|
102
|
+
catmullRom(at(r, c0 - 1), at(r, c0), at(r, c0 + 1), at(r, c0 + 2), column - c0);
|
|
103
|
+
return catmullRom(line(r0 - 1), line(r0), line(r0 + 1), line(r0 + 2), row - r0);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* How far past the playable square the surveyed surroundings are ground: a hill at the edge is
|
|
108
|
+
* climbable up to here, and the level's walls stand at this band's outer edge.
|
|
109
|
+
*/
|
|
110
|
+
export const HORIZON_WALK_BAND = 200;
|
|
111
|
+
|
|
112
|
+
/** Rings of the far collar, and the radius they reach: the survey's own rim, at 2.1 km. */
|
|
113
|
+
const HORIZON_RINGS = 384;
|
|
114
|
+
export const HORIZON_REACH = 2100;
|
|
115
|
+
/** How the rings spread: ring `k` stands `(k / rings) ** 1.65` of the reach past the edge. */
|
|
116
|
+
const HORIZON_POWER = 1.65;
|
|
117
|
+
/** The ring curve `createHorizonCollar` builds and the package's collar morph inverts. */
|
|
118
|
+
export const COLLAR_CURVE = { power: HORIZON_POWER, reach: HORIZON_REACH } as const;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The far collar for one world: the square's edge continued onto that site's surveyed surroundings,
|
|
122
|
+
* 384 rings out to 2.1 km. Every height it answers is this game's look — the survey itself, its
|
|
123
|
+
* Catmull-Rom sample blended in past 300 m, and the seam step that closes the detail boundary.
|
|
124
|
+
*/
|
|
125
|
+
export function createHorizonCollar(data: IBakedWorld, world: WorldName): HeightfieldCollar {
|
|
126
|
+
return new HeightfieldCollar({
|
|
127
|
+
height: collarHeight(data, world),
|
|
128
|
+
resolution: data.resolution,
|
|
129
|
+
ringDistance: (ring) => (ring / HORIZON_RINGS) ** HORIZON_POWER * HORIZON_REACH,
|
|
130
|
+
rings: HORIZON_RINGS,
|
|
131
|
+
size: data.size,
|
|
132
|
+
walkBand: HORIZON_WALK_BAND,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** The square's own heights as a bilinear query, centred on the origin. */
|
|
137
|
+
function squareField(data: IBakedWorld): Heightfield {
|
|
138
|
+
return new Heightfield({
|
|
139
|
+
rows: data.resolution,
|
|
140
|
+
columns: data.resolution,
|
|
141
|
+
width: data.size,
|
|
142
|
+
depth: data.size,
|
|
143
|
+
origin: { x: 0, z: 0 },
|
|
144
|
+
heights: Float32Array.from(data.heights),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The ground at any `(x, z)` of one world: the playable square inside it, the collar's own height
|
|
150
|
+
* past its edge (`distance` is how far past the edge the point stands). Streamed tiles sample this,
|
|
151
|
+
* so a tile that crosses the edge draws the same surface the square and the collar draw.
|
|
152
|
+
*/
|
|
153
|
+
export function createWorldHeight(
|
|
154
|
+
data: IBakedWorld,
|
|
155
|
+
world: WorldName,
|
|
156
|
+
): (x: number, z: number) => number {
|
|
157
|
+
const square = squareField(data);
|
|
158
|
+
const collar = collarHeight(data, world);
|
|
159
|
+
const half = data.size / 2;
|
|
160
|
+
return (x, z) => {
|
|
161
|
+
const distance = Math.max(Math.abs(x), Math.abs(z)) - half;
|
|
162
|
+
return distance <= 0
|
|
163
|
+
? square.heightAt(x, z)
|
|
164
|
+
: collar({ distance, x, z } as IHeightfieldCollarSite);
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function collarHeight(
|
|
169
|
+
data: IBakedWorld,
|
|
170
|
+
world: WorldName,
|
|
171
|
+
): (site: IHeightfieldCollarSite) => number {
|
|
172
|
+
const surveyed = continuationFields[world];
|
|
173
|
+
if (!surveyed || !sources[world])
|
|
174
|
+
throw new RangeError(`Missing surveyed surroundings for '${world}'`);
|
|
175
|
+
const square = squareField(data);
|
|
176
|
+
const half = data.size / 2;
|
|
177
|
+
return ({ distance, x, z }: IHeightfieldCollarSite): number => {
|
|
178
|
+
// The square's edge point this vertex grew from: the seam is stated there, not out at the ring.
|
|
179
|
+
const scale = (half + distance) / half;
|
|
180
|
+
const edgeX = Math.min(half, Math.max(-half, x / scale));
|
|
181
|
+
const edgeZ = Math.min(half, Math.max(-half, z / scale));
|
|
182
|
+
const near = surveyed.heightAt(x, z);
|
|
183
|
+
// Past 300 m the collar takes a Catmull-Rom sample of the survey, blended in over 600 m:
|
|
184
|
+
// bilinear heights turn a diagonal wall into grid-aligned skyline stairs, and the curve has no
|
|
185
|
+
// stairs while it keeps every ridge and gully the survey holds. The box-filtered copy it
|
|
186
|
+
// replaces erased them, and a 1 km peak read as smooth clay.
|
|
187
|
+
const fold = Math.min(1, Math.max(0, (distance - 300) / 600));
|
|
188
|
+
const smoothed =
|
|
189
|
+
fold > 0 ? (cubicAt(world, x, z) - near) * MathUtils.smoothstep(fold, 0, 1) : 0;
|
|
190
|
+
// Match the exact detail boundary; fade only the resolution/erosion difference over 40 m.
|
|
191
|
+
// Unlike the procedural collar, all surveyed relief immediately beyond that seam is real. The
|
|
192
|
+
// square's edge is read between its vertices too, so a streamed tile meets it with no step.
|
|
193
|
+
const seam = square.heightAt(edgeX, edgeZ) - surveyed.heightAt(edgeX, edgeZ);
|
|
194
|
+
return near + smoothed + seam * Math.exp(-distance / 40);
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* The collar's colours: every ring carries the square's own boundary colour at that perimeter
|
|
200
|
+
* vertex, so the ring grid grows out of the detail mesh without a visible seam.
|
|
201
|
+
*/
|
|
202
|
+
export function collarColors(collar: HeightfieldCollar, data: IBakedWorld): Float32Array {
|
|
203
|
+
const boundary = new Float32Array(collar.perimeter * 3);
|
|
204
|
+
for (let vertex = 0; vertex < collar.perimeter; vertex++) {
|
|
205
|
+
const { column, row } = collar.boundary(vertex);
|
|
206
|
+
const edge = (row * data.resolution + column) * 3;
|
|
207
|
+
for (let lane = 0; lane < 3; lane++)
|
|
208
|
+
boundary[vertex * 3 + lane] = data.colors[edge + lane] as number;
|
|
209
|
+
}
|
|
210
|
+
const count = collar.geometry.getAttribute("position").count;
|
|
211
|
+
const colors = new Float32Array(count * 3);
|
|
212
|
+
for (let vertex = 0; vertex < count; vertex++) {
|
|
213
|
+
const source = (vertex % collar.perimeter) * 3;
|
|
214
|
+
colors[vertex * 3] = boundary[source] as number;
|
|
215
|
+
colors[vertex * 3 + 1] = boundary[source + 1] as number;
|
|
216
|
+
colors[vertex * 3 + 2] = boundary[source + 2] as number;
|
|
217
|
+
}
|
|
218
|
+
return colors;
|
|
219
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const terrainPalette: readonly (readonly [number, number, number])[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Explicit sRGB surface colours owned by this game, in Strata material-ID order.
|
|
2
|
+
export const terrainPalette = [
|
|
3
|
+
[0.38, 0.46, 0.26],
|
|
4
|
+
[0.46, 0.36, 0.25],
|
|
5
|
+
[0.47, 0.47, 0.44],
|
|
6
|
+
[0.91, 0.94, 0.95],
|
|
7
|
+
[0.73, 0.63, 0.46],
|
|
8
|
+
[0.37, 0.32, 0.24],
|
|
9
|
+
[0.48, 0.44, 0.36],
|
|
10
|
+
[0.32, 0.4, 0.28],
|
|
11
|
+
];
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { createRandom } from "@threenative/core";
|
|
2
|
+
// The meadow past the square: the one placement rule the GAME still runs.
|
|
3
|
+
//
|
|
4
|
+
// The bake's rules moved to `@threenative/terrain` (`core/scatter-ordered.ts`, one ordered stream):
|
|
5
|
+
// the package places a biome's props and `scripts/bake/bake.mjs` writes them. What is left here is the
|
|
6
|
+
// cover a camera view plants at runtime, off the baked square, from the game's own seed.
|
|
7
|
+
import type { IPlacement } from "@threenative/terrain";
|
|
8
|
+
|
|
9
|
+
/** The seed the meadow's own carpet draws from, a step past the bake's ordered stream. */
|
|
10
|
+
const MEADOW_SEED = 466_468 + 31;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Ground cover for a fixed view whose eye stands on the surveyed surroundings, where the bake places
|
|
14
|
+
* nothing (`put` keeps to the playable square): a carpet of short grass mats, fine within 25 m and
|
|
15
|
+
* thinning to `reach` (each far mat grown to keep the slope covered), taller clumps, low
|
|
16
|
+
* ground-foliage mats and wildflowers near the eye, flower patches, and a few low stones. The
|
|
17
|
+
* carpet is full density across the view of `look` and a quarter elsewhere; patches and stones go
|
|
18
|
+
* where the view looks (within 40 degrees). Only ground past the square's edge
|
|
19
|
+
* and inside `band` (the walk band whose collider grounds each placement) is planted. `y` is 0: the
|
|
20
|
+
* game's ground query sets the height. UE 5.8.3 plants grass the same way, on whatever landscape lies
|
|
21
|
+
* within the cull distance of a rendered view, on a jittered grid
|
|
22
|
+
* (`Engine/Source/Runtime/Landscape/Private/LandscapeGrass.cpp:2925` and `:1482-1489`: grid on,
|
|
23
|
+
* jitter 1, cull distance 100 m). Past 80 m the mats draw a thinned far level (`pack.ts`).
|
|
24
|
+
*/
|
|
25
|
+
export function meadowCover(
|
|
26
|
+
eye: { readonly x: number; readonly z: number },
|
|
27
|
+
look: { readonly x: number; readonly z: number },
|
|
28
|
+
half: number,
|
|
29
|
+
band: number,
|
|
30
|
+
reach = 220,
|
|
31
|
+
): IPlacement[] {
|
|
32
|
+
const random = createRandom(MEADOW_SEED);
|
|
33
|
+
const placements: IPlacement[] = [];
|
|
34
|
+
const counts: Record<string, number> = {};
|
|
35
|
+
// White and violet blooms, with the odd red poppy.
|
|
36
|
+
const flower = () => (random() < 0.8 ? "bloom" : "poppy");
|
|
37
|
+
const put = (asset: string, x: number, z: number, scale: number) => {
|
|
38
|
+
const out = Math.max(Math.abs(x), Math.abs(z));
|
|
39
|
+
if (out <= half + 1 || out >= half + band) return;
|
|
40
|
+
const index = counts[asset] ?? 0;
|
|
41
|
+
counts[asset] = index + 1;
|
|
42
|
+
placements.push({
|
|
43
|
+
asset,
|
|
44
|
+
id: `temperate-${asset}:meadow-${index}`,
|
|
45
|
+
layer: `temperate-${asset}`,
|
|
46
|
+
alignToNormal: false,
|
|
47
|
+
normal: [0, 1, 0],
|
|
48
|
+
position: [x, 0, z],
|
|
49
|
+
rotation: random() * Math.PI * 2,
|
|
50
|
+
scale,
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
const heading = Math.atan2(look.z - eye.z, look.x - eye.x);
|
|
54
|
+
for (const [from, to, step] of [
|
|
55
|
+
[0, 25, 0.5],
|
|
56
|
+
[25, 80, 1.2],
|
|
57
|
+
[80, reach, 2.4],
|
|
58
|
+
] as const)
|
|
59
|
+
for (let dz = -to; dz <= to; dz += step)
|
|
60
|
+
for (let dx = -to; dx <= to; dx += step) {
|
|
61
|
+
const distance = Math.hypot(dx, dz);
|
|
62
|
+
if (distance < from || distance >= to) continue;
|
|
63
|
+
// Full density across the frame (55 degrees either side of the look), a quarter elsewhere:
|
|
64
|
+
// the meadow stays a meadow off-frame without drawing three times the grass.
|
|
65
|
+
const off = Math.abs(
|
|
66
|
+
((Math.atan2(dz, dx) - heading + 3 * Math.PI) % (2 * Math.PI)) - Math.PI,
|
|
67
|
+
);
|
|
68
|
+
if (off > 0.96 && random() > 0.25) continue;
|
|
69
|
+
const x = eye.x + dx + (random() - 0.5) * step;
|
|
70
|
+
const z = eye.z + dz + (random() - 0.5) * step;
|
|
71
|
+
// A short mat everywhere; a far one grows with distance (twice its size at 220 m) so the
|
|
72
|
+
// thinner far grid still covers a slope instead of dotting it.
|
|
73
|
+
put("meadow", x, z, (0.9 + random() * 0.5) * (1 + Math.max(0, distance - 80) / 140));
|
|
74
|
+
if (distance >= 80) continue;
|
|
75
|
+
// An unmown meadow: taller clumps than the forest's 0.8-1.45 over the mats.
|
|
76
|
+
if (random() < 0.35) put("grass", x, z, 0.95 + random() * 0.6);
|
|
77
|
+
if (random() < 0.08)
|
|
78
|
+
put("scrub", x + random() - 0.5, z + random() - 0.5, 0.9 + random() * 0.6);
|
|
79
|
+
if (random() < 0.08)
|
|
80
|
+
put(flower(), x + random() - 0.5, z + random() - 0.5, 0.9 + random() * 0.5);
|
|
81
|
+
}
|
|
82
|
+
const ahead = (near: number, far: number): [number, number] => {
|
|
83
|
+
const angle = heading + (random() - 0.5) * 1.4;
|
|
84
|
+
const distance = near + Math.sqrt(random()) * (far - near);
|
|
85
|
+
return [eye.x + Math.cos(angle) * distance, eye.z + Math.sin(angle) * distance];
|
|
86
|
+
};
|
|
87
|
+
// Flowers also grow in drifts, inside the flower draw reach.
|
|
88
|
+
for (let patch = 0; patch < 60; patch++) {
|
|
89
|
+
const [px, pz] = ahead(8, 60);
|
|
90
|
+
const radius = 1.5 + random() * 3;
|
|
91
|
+
const kind = flower();
|
|
92
|
+
for (let k = 0; k < 30 + random() * 30; k++) {
|
|
93
|
+
const a = random() * Math.PI * 2;
|
|
94
|
+
const r = radius * Math.sqrt(random());
|
|
95
|
+
put(kind, px + Math.cos(a) * r, pz + Math.sin(a) * r, 0.9 + random() * 0.5);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// A few low stones lying in the turf, not boulders: a third of the bake's boulder scale.
|
|
99
|
+
for (let stone = 0; stone < 12; stone++) {
|
|
100
|
+
const [x, z] = ahead(10, 35);
|
|
101
|
+
put("boulder", x, z, 0.2 + random() * 0.2);
|
|
102
|
+
}
|
|
103
|
+
return placements;
|
|
104
|
+
}
|