@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,28 @@
|
|
|
1
|
+
import type { IAssetLoader } from "@threenative/core";
|
|
2
|
+
import { WORLD } from "./worldNames.js";
|
|
3
|
+
|
|
4
|
+
/** Where `bake.mjs` (default `--out assets/terrain/<WORLD>`) writes the world in the game's asset tree. */
|
|
5
|
+
export const TUNDRA_ROOT = `terrain/${WORLD}/`;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The game's asset loader, with every relative path read under {@link TUNDRA_ROOT}: the forest's
|
|
9
|
+
* art and baked files keep the names the render code asks for, and the game's own assets stay at
|
|
10
|
+
* its asset root. Every other member is the game loader's own.
|
|
11
|
+
*/
|
|
12
|
+
export function tundraAssets(assets: IAssetLoader): IAssetLoader {
|
|
13
|
+
const at = (path: string): string => (/^(?:[a-z]+:|\/)/u.test(path) ? path : TUNDRA_ROOT + path);
|
|
14
|
+
const scoped: Partial<IAssetLoader> = {
|
|
15
|
+
model: (path, options) => assets.model(at(path), options),
|
|
16
|
+
texture: (path, options) => assets.texture(at(path), options),
|
|
17
|
+
audio: (path) => assets.audio(at(path)),
|
|
18
|
+
release: (kind, path) => assets.release(kind, at(path)),
|
|
19
|
+
resolve: (path) => assets.resolve(at(path)),
|
|
20
|
+
};
|
|
21
|
+
return new Proxy(assets, {
|
|
22
|
+
get(target, key) {
|
|
23
|
+
if (Object.hasOwn(scoped, key)) return scoped[key as keyof IAssetLoader];
|
|
24
|
+
const value = Reflect.get(target, key, target) as unknown;
|
|
25
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Camera,
|
|
3
|
+
CanvasTexture,
|
|
4
|
+
ClampToEdgeWrapping,
|
|
5
|
+
Mesh,
|
|
6
|
+
MeshBasicMaterial,
|
|
7
|
+
type OrthographicCamera,
|
|
8
|
+
PlaneGeometry,
|
|
9
|
+
type Scene,
|
|
10
|
+
type Texture,
|
|
11
|
+
} from "three";
|
|
12
|
+
const palette = { skyLow: 0x142321, skyHigh: 0x304636, accent: 0xb6c586 };
|
|
13
|
+
|
|
14
|
+
/* BEGIN THREENATIVE LOADING APPEARANCE */
|
|
15
|
+
/** Edit these source constants for the starter's loading look. */
|
|
16
|
+
export const loading = {
|
|
17
|
+
backgroundColor: palette.skyLow,
|
|
18
|
+
backgroundImage: undefined as string | undefined,
|
|
19
|
+
enabled: true,
|
|
20
|
+
fillImage: undefined as string | undefined,
|
|
21
|
+
logoImage: undefined as string | undefined,
|
|
22
|
+
progressColor: palette.accent,
|
|
23
|
+
showStatus: true,
|
|
24
|
+
trackColor: palette.skyHigh,
|
|
25
|
+
bar: { anchorX: 0.5, anchorY: 0.72, height: 12, maxWidth: 520, minWidth: 1, width: 0.62 },
|
|
26
|
+
} as const;
|
|
27
|
+
/* END THREENATIVE LOADING APPEARANCE */
|
|
28
|
+
|
|
29
|
+
interface ILoadingHost {
|
|
30
|
+
onReveal?(): void;
|
|
31
|
+
readonly assets?: { texture(path: string): Promise<Texture> };
|
|
32
|
+
readonly camera: Camera;
|
|
33
|
+
readonly canvasLayer: {
|
|
34
|
+
readonly camera: OrthographicCamera;
|
|
35
|
+
readonly scene: Scene;
|
|
36
|
+
opaque: boolean;
|
|
37
|
+
keepWorldRendering?: boolean;
|
|
38
|
+
renderWorldDuringStartup?: boolean;
|
|
39
|
+
};
|
|
40
|
+
/** Opt out while cold textures prepare; enable the layer again before draw-backed cell prewarm. */
|
|
41
|
+
readonly keepWorldRendering?: boolean;
|
|
42
|
+
readonly scene: Scene;
|
|
43
|
+
readonly startup: {
|
|
44
|
+
readonly progress: number;
|
|
45
|
+
readonly warmup?: { readonly status: "complete" | "incomplete" | "unavailable" };
|
|
46
|
+
whenReady(): Promise<void>;
|
|
47
|
+
};
|
|
48
|
+
readonly viewport?: {
|
|
49
|
+
readonly safeArea: { height: number; width: number; x: number; y: number };
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface ILoadingController {
|
|
54
|
+
update(): void;
|
|
55
|
+
finish(): void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function noOp(layer: ILoadingHost["canvasLayer"]): ILoadingController {
|
|
59
|
+
layer.opaque = false;
|
|
60
|
+
return { finish: () => undefined, update: () => undefined };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function meshFor(
|
|
64
|
+
layer: ILoadingHost["canvasLayer"],
|
|
65
|
+
material: MeshBasicMaterial,
|
|
66
|
+
renderOrder: number,
|
|
67
|
+
): Mesh<PlaneGeometry, MeshBasicMaterial> {
|
|
68
|
+
const mesh = new Mesh(new PlaneGeometry(1, 1), material);
|
|
69
|
+
mesh.frustumCulled = false;
|
|
70
|
+
mesh.renderOrder = renderOrder;
|
|
71
|
+
layer.scene.add(mesh);
|
|
72
|
+
return mesh;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function imageAspect(texture: Texture | null | undefined): number {
|
|
76
|
+
const image = texture?.image as { height?: number; width?: number } | undefined;
|
|
77
|
+
const width = image?.width ?? 1;
|
|
78
|
+
const height = image?.height ?? 1;
|
|
79
|
+
return width > 0 && height > 0 ? width / height : 1;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function configureTexture(texture: Texture): void {
|
|
83
|
+
texture.wrapS = ClampToEdgeWrapping;
|
|
84
|
+
texture.wrapT = ClampToEdgeWrapping;
|
|
85
|
+
texture.needsUpdate = true;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function setFillUv(geometry: PlaneGeometry, progress: number, base: readonly number[]): void {
|
|
89
|
+
const uv = geometry.getAttribute("uv");
|
|
90
|
+
for (let index = 0; index < uv.count; index += 1) uv.setX(index, (base[index] ?? 0) * progress);
|
|
91
|
+
uv.needsUpdate = true;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function coverUv(
|
|
95
|
+
geometry: PlaneGeometry,
|
|
96
|
+
texture: Texture,
|
|
97
|
+
width: number,
|
|
98
|
+
height: number,
|
|
99
|
+
baseU: readonly number[],
|
|
100
|
+
baseV: readonly number[],
|
|
101
|
+
): void {
|
|
102
|
+
const imageRatio = imageAspect(texture);
|
|
103
|
+
const boxRatio = width / Math.max(1, height);
|
|
104
|
+
const visibleU = imageRatio > boxRatio ? boxRatio / imageRatio : 1;
|
|
105
|
+
const visibleV = imageRatio < boxRatio ? imageRatio / boxRatio : 1;
|
|
106
|
+
const offsetU = (1 - visibleU) / 2;
|
|
107
|
+
const offsetV = (1 - visibleV) / 2;
|
|
108
|
+
const uv = geometry.getAttribute("uv");
|
|
109
|
+
for (let index = 0; index < uv.count; index += 1) {
|
|
110
|
+
uv.setX(index, offsetU + (baseU[index] ?? 0) * visibleU);
|
|
111
|
+
uv.setY(index, offsetV + (baseV[index] ?? 0) * visibleV);
|
|
112
|
+
}
|
|
113
|
+
uv.needsUpdate = true;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function statusMesh(layer: ILoadingHost["canvasLayer"]):
|
|
117
|
+
| {
|
|
118
|
+
mesh: Mesh<PlaneGeometry, MeshBasicMaterial>;
|
|
119
|
+
texture: Texture;
|
|
120
|
+
update(value: number | string): void;
|
|
121
|
+
}
|
|
122
|
+
| undefined {
|
|
123
|
+
if (!loading.showStatus || typeof document === "undefined") return undefined;
|
|
124
|
+
const canvas = document.createElement("canvas");
|
|
125
|
+
canvas.width = 1000;
|
|
126
|
+
canvas.height = 48;
|
|
127
|
+
const context = canvas.getContext("2d");
|
|
128
|
+
if (context === null) return undefined;
|
|
129
|
+
const texture = new CanvasTexture(canvas);
|
|
130
|
+
const mesh = meshFor(
|
|
131
|
+
layer,
|
|
132
|
+
new MeshBasicMaterial({ depthTest: false, depthWrite: false, map: texture, transparent: true }),
|
|
133
|
+
4,
|
|
134
|
+
);
|
|
135
|
+
let displayedText: string | undefined;
|
|
136
|
+
const update = (value: number | string): void => {
|
|
137
|
+
const text = typeof value === "string" ? value : `${Math.round(value * 100)}%`;
|
|
138
|
+
if (text === displayedText) return;
|
|
139
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
140
|
+
context.fillStyle = "#ffffff";
|
|
141
|
+
context.font = "700 20px monospace";
|
|
142
|
+
context.textAlign = "center";
|
|
143
|
+
context.textBaseline = "middle";
|
|
144
|
+
context.fillText(text, canvas.width / 2, canvas.height / 2, 980);
|
|
145
|
+
displayedText = text;
|
|
146
|
+
texture.needsUpdate = true;
|
|
147
|
+
};
|
|
148
|
+
update(0);
|
|
149
|
+
return { mesh, texture, update };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function createLoadingScreen(host: ILoadingHost): ILoadingController {
|
|
153
|
+
const layer = host.canvasLayer;
|
|
154
|
+
const previousWorldRendering = layer.keepWorldRendering ?? false;
|
|
155
|
+
const previousStartupRendering = layer.renderWorldDuringStartup ?? true;
|
|
156
|
+
if (!loading.enabled) return noOp(layer);
|
|
157
|
+
const camera = layer.camera;
|
|
158
|
+
const backdrop = meshFor(
|
|
159
|
+
layer,
|
|
160
|
+
new MeshBasicMaterial({ color: loading.backgroundColor, depthTest: false, depthWrite: false }),
|
|
161
|
+
0,
|
|
162
|
+
);
|
|
163
|
+
const track = meshFor(
|
|
164
|
+
layer,
|
|
165
|
+
new MeshBasicMaterial({ color: loading.trackColor, depthTest: false, depthWrite: false }),
|
|
166
|
+
1,
|
|
167
|
+
);
|
|
168
|
+
const fill = meshFor(
|
|
169
|
+
layer,
|
|
170
|
+
new MeshBasicMaterial({ color: loading.progressColor, depthTest: false, depthWrite: false }),
|
|
171
|
+
2,
|
|
172
|
+
);
|
|
173
|
+
const fillBaseU = Array.from({ length: fill.geometry.getAttribute("uv").count }, (_, index) =>
|
|
174
|
+
fill.geometry.getAttribute("uv").getX(index),
|
|
175
|
+
);
|
|
176
|
+
const fillBaseV = Array.from({ length: fill.geometry.getAttribute("uv").count }, (_, index) =>
|
|
177
|
+
fill.geometry.getAttribute("uv").getY(index),
|
|
178
|
+
);
|
|
179
|
+
const logo =
|
|
180
|
+
loading.logoImage === undefined
|
|
181
|
+
? undefined
|
|
182
|
+
: meshFor(
|
|
183
|
+
layer,
|
|
184
|
+
new MeshBasicMaterial({
|
|
185
|
+
color: 0xffffff,
|
|
186
|
+
depthTest: false,
|
|
187
|
+
depthWrite: false,
|
|
188
|
+
transparent: true,
|
|
189
|
+
}),
|
|
190
|
+
3,
|
|
191
|
+
);
|
|
192
|
+
const status = statusMesh(layer);
|
|
193
|
+
const parts = [
|
|
194
|
+
backdrop,
|
|
195
|
+
track,
|
|
196
|
+
fill,
|
|
197
|
+
...(logo === undefined ? [] : [logo]),
|
|
198
|
+
...(status === undefined ? [] : [status.mesh]),
|
|
199
|
+
];
|
|
200
|
+
const ownedTextures = new Set<Texture>(status === undefined ? [] : [status.texture]);
|
|
201
|
+
let width = 1;
|
|
202
|
+
let height = 1;
|
|
203
|
+
let barWidth = 1;
|
|
204
|
+
let barHeight: number = loading.bar.height;
|
|
205
|
+
let barX = 0;
|
|
206
|
+
let barY = 0;
|
|
207
|
+
let progress = 0;
|
|
208
|
+
let done = false;
|
|
209
|
+
let failed = false;
|
|
210
|
+
let backdropTexture: Texture | undefined;
|
|
211
|
+
|
|
212
|
+
const layout = (): void => {
|
|
213
|
+
width = Math.max(1, camera.right - camera.left);
|
|
214
|
+
height = Math.max(1, camera.top - camera.bottom);
|
|
215
|
+
const safe = host.viewport?.safeArea ?? { height, width, x: 0, y: 0 };
|
|
216
|
+
const safeWidth = Math.max(1, Math.min(width, safe.width));
|
|
217
|
+
const safeHeight = Math.max(1, Math.min(height, safe.height));
|
|
218
|
+
const safeX = Math.max(0, Math.min(width - safeWidth, safe.x));
|
|
219
|
+
const safeY = Math.max(0, Math.min(height - safeHeight, safe.y));
|
|
220
|
+
barWidth = Math.max(2, Math.min(loading.bar.maxWidth, safeWidth * loading.bar.width));
|
|
221
|
+
barHeight = Math.max(2, Math.min(loading.bar.height, safeHeight * 0.05));
|
|
222
|
+
barX = safeX + safeWidth * loading.bar.anchorX;
|
|
223
|
+
barY = safeY + safeHeight * loading.bar.anchorY;
|
|
224
|
+
const worldX = (screenX: number): number => camera.left + screenX;
|
|
225
|
+
const worldY = (screenY: number): number => camera.top - screenY;
|
|
226
|
+
const visibleWidth = Math.max(loading.bar.minWidth, barWidth * progress);
|
|
227
|
+
backdrop.scale.set(width, height, 1);
|
|
228
|
+
backdrop.position.set(worldX(width / 2), worldY(height / 2), 0);
|
|
229
|
+
track.scale.set(barWidth, barHeight, 1);
|
|
230
|
+
track.position.set(worldX(barX), worldY(barY), 0);
|
|
231
|
+
fill.scale.set(visibleWidth, barHeight, 1);
|
|
232
|
+
fill.position.set(worldX(barX - barWidth / 2 + visibleWidth / 2), worldY(barY), 0);
|
|
233
|
+
if (logo?.visible) {
|
|
234
|
+
const logoWidth = Math.min(safeWidth * 0.42, 280);
|
|
235
|
+
logo.scale.set(
|
|
236
|
+
logoWidth,
|
|
237
|
+
Math.min(logoWidth / imageAspect(logo.material.map), safeHeight * 0.22),
|
|
238
|
+
1,
|
|
239
|
+
);
|
|
240
|
+
logo.position.set(worldX(barX), worldY(Math.max(safeY, barY - safeHeight * 0.2)), 0);
|
|
241
|
+
}
|
|
242
|
+
if (status !== undefined) {
|
|
243
|
+
// Keep the 1000×48 canvas's aspect, or a long error message is squeezed into a smear.
|
|
244
|
+
const statusWidth = Math.min(1000, safeWidth * 0.9);
|
|
245
|
+
status.mesh.scale.set(statusWidth, (statusWidth * 48) / 1000, 1);
|
|
246
|
+
status.mesh.position.set(worldX(barX), worldY(Math.min(height, barY + barHeight * 2.5)), 0);
|
|
247
|
+
}
|
|
248
|
+
if (backdropTexture !== undefined)
|
|
249
|
+
coverUv(backdrop.geometry, backdropTexture, width, height, fillBaseU, fillBaseV);
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
const updateProgress = (value: number): void => {
|
|
253
|
+
const bounded = Number.isFinite(value) ? Math.max(0, Math.min(1, value)) : 0;
|
|
254
|
+
// A missing or incomplete backend observation cannot prove that all first-use work is done.
|
|
255
|
+
// Keep the bar visibly indeterminate until readiness removes the cover; never turn unknown
|
|
256
|
+
// coverage into a false 100% claim.
|
|
257
|
+
const observationUnknown =
|
|
258
|
+
host.startup.warmup !== undefined && host.startup.warmup.status !== "complete";
|
|
259
|
+
progress = observationUnknown ? Math.min(0.9, bounded) : bounded;
|
|
260
|
+
setFillUv(fill.geometry, progress, fillBaseU);
|
|
261
|
+
status?.update(observationUnknown ? "Preparing" : progress);
|
|
262
|
+
layout();
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
const attachTexture = (mesh: Mesh<PlaneGeometry, MeshBasicMaterial>, texture: Texture): void => {
|
|
266
|
+
if (done) return;
|
|
267
|
+
configureTexture(texture);
|
|
268
|
+
mesh.material.map = texture;
|
|
269
|
+
mesh.material.color.set(0xffffff);
|
|
270
|
+
mesh.material.needsUpdate = true;
|
|
271
|
+
ownedTextures.add(texture);
|
|
272
|
+
if (mesh === backdrop) backdropTexture = texture;
|
|
273
|
+
layout();
|
|
274
|
+
updateProgress(progress);
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
const load = (source: string | undefined, mesh: Mesh<PlaneGeometry, MeshBasicMaterial>): void => {
|
|
278
|
+
if (source === undefined || host.assets === undefined) return;
|
|
279
|
+
void host.assets
|
|
280
|
+
.texture(source)
|
|
281
|
+
.then((texture) => attachTexture(mesh, texture))
|
|
282
|
+
.catch(() => undefined);
|
|
283
|
+
};
|
|
284
|
+
load(loading.backgroundImage, backdrop);
|
|
285
|
+
load(loading.fillImage, fill);
|
|
286
|
+
if (logo !== undefined && loading.logoImage !== undefined && host.assets !== undefined) {
|
|
287
|
+
void host.assets
|
|
288
|
+
.texture(loading.logoImage)
|
|
289
|
+
.then((texture) => {
|
|
290
|
+
if (done) return;
|
|
291
|
+
configureTexture(texture);
|
|
292
|
+
logo.material.map = texture;
|
|
293
|
+
logo.material.needsUpdate = true;
|
|
294
|
+
logo.visible = true;
|
|
295
|
+
ownedTextures.add(texture);
|
|
296
|
+
layout();
|
|
297
|
+
})
|
|
298
|
+
.catch(() => undefined);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
layer.opaque = true;
|
|
302
|
+
layer.keepWorldRendering = host.keepWorldRendering ?? true;
|
|
303
|
+
layer.renderWorldDuringStartup = host.keepWorldRendering ?? true;
|
|
304
|
+
layout();
|
|
305
|
+
updateProgress(0);
|
|
306
|
+
|
|
307
|
+
const finish = (): void => {
|
|
308
|
+
if (done) return;
|
|
309
|
+
done = true;
|
|
310
|
+
for (const mesh of parts) {
|
|
311
|
+
mesh.removeFromParent();
|
|
312
|
+
mesh.geometry.dispose();
|
|
313
|
+
mesh.material.dispose();
|
|
314
|
+
}
|
|
315
|
+
for (const texture of ownedTextures) texture.dispose();
|
|
316
|
+
layer.opaque = false;
|
|
317
|
+
layer.keepWorldRendering = previousWorldRendering;
|
|
318
|
+
layer.renderWorldDuringStartup = previousStartupRendering;
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
void (async () => {
|
|
322
|
+
try {
|
|
323
|
+
await host.startup.whenReady();
|
|
324
|
+
} catch (error) {
|
|
325
|
+
if (done) return;
|
|
326
|
+
failed = true;
|
|
327
|
+
layer.keepWorldRendering = previousWorldRendering;
|
|
328
|
+
layer.renderWorldDuringStartup = previousStartupRendering;
|
|
329
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
330
|
+
backdrop.userData.loadingError = message;
|
|
331
|
+
fill.material.color.set(0xe36b5c);
|
|
332
|
+
status?.update(message);
|
|
333
|
+
console.error(`Strata loading failed: ${message}`);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
if (done) return;
|
|
337
|
+
finish();
|
|
338
|
+
// Named and logged, never an unhandled rejection: a failed reveal probe leaves the world up.
|
|
339
|
+
try {
|
|
340
|
+
host.onReveal?.();
|
|
341
|
+
} catch (error) {
|
|
342
|
+
console.error(
|
|
343
|
+
`Strata reveal failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
})();
|
|
347
|
+
|
|
348
|
+
return {
|
|
349
|
+
finish,
|
|
350
|
+
update(): void {
|
|
351
|
+
if (!done && !failed) updateProgress(host.startup.progress);
|
|
352
|
+
},
|
|
353
|
+
};
|
|
354
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Color, Vector3 } from "three";
|
|
2
|
+
import { uniform } from "three/tsl";
|
|
3
|
+
import type { Node } from "three/webgpu";
|
|
4
|
+
import { BIOMES } from "./biomes.js";
|
|
5
|
+
|
|
6
|
+
const row = BIOMES.tundra;
|
|
7
|
+
const mist = row.atmosphere.groundMist;
|
|
8
|
+
const tint = (r: number, g: number, b: number) =>
|
|
9
|
+
uniform(new Vector3(r, g, b)) as unknown as Node<"vec3"> & { value: Vector3 };
|
|
10
|
+
const amount = (value: number) => uniform(value) as unknown as Node<"float"> & { value: number };
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The wood's look numbers a tweak box can move while the game runs (`?tweak`): each is a uniform
|
|
14
|
+
* that starts at the forest row's own value, so a game that never opens the box draws the row.
|
|
15
|
+
* A value that looks right is copied from the box and written back into `biomes.ts`.
|
|
16
|
+
*/
|
|
17
|
+
export const LOOK = {
|
|
18
|
+
/** Multiplies every blade, frond and mat (`swardTint`). */
|
|
19
|
+
sward: tint(...(row.swardTint ?? [1, 1, 1])),
|
|
20
|
+
/** Multiplies the open turf under them (`turfTint`). */
|
|
21
|
+
turf: tint(...(row.turfTint ?? [1, 1, 1])),
|
|
22
|
+
/** Multiplies the spruce crowns. */
|
|
23
|
+
crown: tint(1, 1, 1),
|
|
24
|
+
/** Multiplies the trunk bark, and the limbs. */
|
|
25
|
+
bark: amount(1),
|
|
26
|
+
limb: amount(1),
|
|
27
|
+
/** Multiplies the massif's rock. */
|
|
28
|
+
rock: tint(1, 1, 1),
|
|
29
|
+
/** The share of ambient and sky light a plant keeps under a closed crown (`understoreySkyLight`). */
|
|
30
|
+
plantShade: amount(row.understoreySkyLight ?? 1),
|
|
31
|
+
mistColor: uniform(new Color(mist?.color ?? 0x808080)) as unknown as Node<"vec3"> & {
|
|
32
|
+
value: Color;
|
|
33
|
+
},
|
|
34
|
+
mistDensity: amount(mist?.term.density ?? 0),
|
|
35
|
+
mistOpacity: amount(mist?.maxOpacity ?? 0),
|
|
36
|
+
mistScale: amount(mist?.term.scale ?? 1),
|
|
37
|
+
};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// The collectathon kit's orbit follow camera, copied unchanged except that the game config keeps
|
|
2
|
+
// the lens (this world needs a 5 km far plane). It sits behind the hero on a fixed arm, swings
|
|
3
|
+
// slowly toward the direction of travel and pulls in in front of any ground between the hero and
|
|
4
|
+
// the arm's end. `game.ts` calls `update` from `afterPhysics`, because `moveAndSlide` only
|
|
5
|
+
// queues motion, and passes the terrain ray test as the wall probe.
|
|
6
|
+
import { type Camera, MathUtils, Vector3 } from "three";
|
|
7
|
+
|
|
8
|
+
/** Camera framing, in metres and radians. */
|
|
9
|
+
export const CAMERA_RIG = {
|
|
10
|
+
/** Arm length from the aim point. */
|
|
11
|
+
distance: 9,
|
|
12
|
+
/** Arm angle above the horizon. */
|
|
13
|
+
elevation: 0.32,
|
|
14
|
+
/** The aim point sits this high above the hero's waist, so the ground ahead fills the frame. */
|
|
15
|
+
aimHeight: 1.1,
|
|
16
|
+
/**
|
|
17
|
+
* The lens looks this far above the aim point at full arm length (less as the arm shortens), so
|
|
18
|
+
* the view pitches about 8° down instead of the arm's 18°: the hero sits in the lower third and
|
|
19
|
+
* the horizon, the hills and the castle fill the top, as in a 3D platformer's establishing view.
|
|
20
|
+
*/
|
|
21
|
+
lookAbove: 1.6,
|
|
22
|
+
/** How fast the arm swings toward the travel direction at full run, in 1/s. */
|
|
23
|
+
swingRate: 1.6,
|
|
24
|
+
/** Closest the camera comes to the aim point, even when the hero has its back to a wall. */
|
|
25
|
+
minDistance: 0.3,
|
|
26
|
+
/** Gap kept between the camera and the wall it is pulled in front of. */
|
|
27
|
+
wallGap: 0.35,
|
|
28
|
+
/** Ease toward the arm's end, in 1/s; a pull-in snaps instead. */
|
|
29
|
+
followRate: 9,
|
|
30
|
+
/**
|
|
31
|
+
* When a wall would pull the camera closer than this, it looks for a clearer arm instead: in a
|
|
32
|
+
* shaft the open side is beside the hero, and a camera at 0.3 m shows the back of the cap.
|
|
33
|
+
*/
|
|
34
|
+
craneBelow: 4,
|
|
35
|
+
/** The steepest arm angle it tries: 35° above the horizon, so the view never turns top-down. */
|
|
36
|
+
craneElevation: 0.61,
|
|
37
|
+
/** The headings it tries, as offsets from the current yaw, nearest first. */
|
|
38
|
+
craneHeadings: [0, Math.PI / 2, -Math.PI / 2, Math.PI / 4, -Math.PI / 4, 2.36, -2.36],
|
|
39
|
+
/** Mouse orbit, in radians per pixel of pointer motion. */
|
|
40
|
+
lookSensitivity: 0.0035,
|
|
41
|
+
/** The arm angles the mouse can tilt between: just above the ground to 50° above the horizon. */
|
|
42
|
+
lookElevation: [0.05, 0.87],
|
|
43
|
+
/** After the mouse turns the arm, the travel swing waits this long, in seconds. */
|
|
44
|
+
lookHold: 1.5,
|
|
45
|
+
} as const;
|
|
46
|
+
|
|
47
|
+
/** Distance along the ray from `from` to `to` to the first wall, or undefined when clear. */
|
|
48
|
+
export type WallProbe = (from: Vector3, to: Vector3) => number | undefined;
|
|
49
|
+
|
|
50
|
+
export interface IOrbitCamera {
|
|
51
|
+
/** The yaw the camera looks along (Three.js convention: forward is -Z at 0). */
|
|
52
|
+
readonly yaw: number;
|
|
53
|
+
/** Puts the camera behind a hero facing `yaw`, with no easing. */
|
|
54
|
+
snap(target: Vector3, yaw: number, probe: WallProbe): void;
|
|
55
|
+
/** Turns the arm by a pointer delta in pixels: right turns the view right, down raises the arm. */
|
|
56
|
+
look(dx: number, dy: number): void;
|
|
57
|
+
update(target: Vector3, velocity: Vector3, dt: number, probe: WallProbe): void;
|
|
58
|
+
debug(): Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function createOrbitCamera(camera: Camera): IOrbitCamera {
|
|
62
|
+
const aim = new Vector3();
|
|
63
|
+
const desired = new Vector3();
|
|
64
|
+
const arm = new Vector3();
|
|
65
|
+
let yaw = 0;
|
|
66
|
+
let distance: number = CAMERA_RIG.distance;
|
|
67
|
+
let elevation: number = CAMERA_RIG.elevation;
|
|
68
|
+
// The arm angle at rest, which the mouse tilts, and how long the travel swing still waits.
|
|
69
|
+
let tilt: number = CAMERA_RIG.elevation;
|
|
70
|
+
let held = 0;
|
|
71
|
+
let pulledIn = false;
|
|
72
|
+
let cuts = 0;
|
|
73
|
+
let peakElevation = elevation;
|
|
74
|
+
let closest = distance;
|
|
75
|
+
|
|
76
|
+
/** How far the arm reaches along `heading` at `angle`; also leaves `arm` pointing along it. */
|
|
77
|
+
const reachAt = (heading: number, angle: number, probe: WallProbe): number => {
|
|
78
|
+
const flat = Math.cos(angle);
|
|
79
|
+
arm.set(Math.sin(heading) * flat, Math.sin(angle), Math.cos(heading) * flat);
|
|
80
|
+
desired.copy(aim).addScaledVector(arm, CAMERA_RIG.distance);
|
|
81
|
+
const hit = probe(aim, desired);
|
|
82
|
+
return hit === undefined ? CAMERA_RIG.distance : hit - CAMERA_RIG.wallGap;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const place = (target: Vector3, probe: WallProbe, ease: number): void => {
|
|
86
|
+
aim.set(target.x, target.y + CAMERA_RIG.aimHeight, target.z);
|
|
87
|
+
// Crane: when the arm is boxed in, take the heading and angle that reach farthest. A new
|
|
88
|
+
// heading is a cut, not a swing: an arm swept round a shaft passes through its wall.
|
|
89
|
+
let goal = tilt;
|
|
90
|
+
let heading = yaw;
|
|
91
|
+
let best = reachAt(yaw, goal, probe);
|
|
92
|
+
if (best < CAMERA_RIG.craneBelow) {
|
|
93
|
+
for (const offset of CAMERA_RIG.craneHeadings) {
|
|
94
|
+
// The 35° arm first: on a tie it looks down into a shaft instead of along its walls.
|
|
95
|
+
for (const angle of [CAMERA_RIG.craneElevation, CAMERA_RIG.elevation]) {
|
|
96
|
+
const reach = reachAt(yaw + offset, angle, probe);
|
|
97
|
+
if (reach > best + 0.5) [heading, goal, best] = [yaw + offset, angle, reach];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (heading !== yaw) {
|
|
102
|
+
[yaw, elevation, distance] = [heading, goal, best];
|
|
103
|
+
cuts += 1;
|
|
104
|
+
}
|
|
105
|
+
// Up is immediate, like a pull-in; back down is eased.
|
|
106
|
+
elevation = goal > elevation ? goal : elevation + (goal - elevation) * ease;
|
|
107
|
+
const hit = reachAt(yaw, elevation, probe);
|
|
108
|
+
pulledIn = hit < CAMERA_RIG.distance;
|
|
109
|
+
const reach = Math.max(CAMERA_RIG.minDistance, hit);
|
|
110
|
+
// Out is eased, in is immediate: a camera that eases into a wall shows the inside of it.
|
|
111
|
+
distance = reach < distance ? reach : distance + (reach - distance) * ease;
|
|
112
|
+
camera.position.copy(aim).addScaledVector(arm, distance);
|
|
113
|
+
camera.lookAt(aim.x, aim.y + (CAMERA_RIG.lookAbove * distance) / CAMERA_RIG.distance, aim.z);
|
|
114
|
+
peakElevation = Math.max(peakElevation, elevation);
|
|
115
|
+
closest = Math.min(closest, distance);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
get yaw() {
|
|
120
|
+
return yaw;
|
|
121
|
+
},
|
|
122
|
+
snap(target, heroYaw, probe) {
|
|
123
|
+
yaw = heroYaw;
|
|
124
|
+
distance = CAMERA_RIG.distance;
|
|
125
|
+
elevation = tilt = CAMERA_RIG.elevation;
|
|
126
|
+
held = 0;
|
|
127
|
+
[cuts, peakElevation, closest] = [0, elevation, distance];
|
|
128
|
+
place(target, probe, 1);
|
|
129
|
+
},
|
|
130
|
+
look(dx, dy) {
|
|
131
|
+
if (dx === 0 && dy === 0) return;
|
|
132
|
+
yaw -= dx * CAMERA_RIG.lookSensitivity;
|
|
133
|
+
const [low, high] = CAMERA_RIG.lookElevation;
|
|
134
|
+
tilt = MathUtils.clamp(tilt + dy * CAMERA_RIG.lookSensitivity, low, high);
|
|
135
|
+
held = CAMERA_RIG.lookHold;
|
|
136
|
+
},
|
|
137
|
+
update(target, velocity, dt, probe) {
|
|
138
|
+
const speed = Math.hypot(velocity.x, velocity.z);
|
|
139
|
+
held = Math.max(0, held - dt);
|
|
140
|
+
if (speed > 1 && held === 0) {
|
|
141
|
+
const travel = Math.atan2(-velocity.x, -velocity.z);
|
|
142
|
+
const turn = MathUtils.euclideanModulo(travel - yaw + Math.PI, Math.PI * 2) - Math.PI;
|
|
143
|
+
// Running at the camera does not spin it round: only travel within 120° of the view swings it.
|
|
144
|
+
if (Math.abs(turn) < (Math.PI * 2) / 3) {
|
|
145
|
+
const rate = CAMERA_RIG.swingRate * Math.min(1, speed / 9.6);
|
|
146
|
+
yaw = MathUtils.damp(yaw, yaw + turn, rate, dt);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
place(target, probe, MathUtils.damp(0, 1, CAMERA_RIG.followRate, dt));
|
|
150
|
+
},
|
|
151
|
+
debug() {
|
|
152
|
+
return { closest, cuts, distance, elevation, peakElevation, pulledIn, tilt, yaw };
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// The forest past the playable square: spruce across the surveyed valley and up its lower slopes.
|
|
2
|
+
//
|
|
3
|
+
// The bake plants only the 512 m square, so from the vista the surroundings read as a bare lawn
|
|
4
|
+
// around one square block of trees. `@threenative/terrain` owns the rule now (`farForestPlacements`):
|
|
5
|
+
// altitude, slope, water, stands and spacing, each a density in 0..1 multiplied together, cited on
|
|
6
|
+
// the package's own tests. What stays here is the GAME's part: which worlds plant a collar, the
|
|
7
|
+
// layer its streaming buckets a far tree under, the impostor gate, and the biome row the numbers
|
|
8
|
+
// come from.
|
|
9
|
+
//
|
|
10
|
+
// Every tree is an ordinary spruce placement on the `far-forest` layer, so `propWorld.ts` draws
|
|
11
|
+
// it through WorldCells with the cooked LOD chain and the engine's whole-asset impostor; the far
|
|
12
|
+
// bucket switches to the impostor sooner and casts no shadow, which is what keeps it cheap.
|
|
13
|
+
// `?farForest=on` is the named override: trees past the square. Without it the frame is the one
|
|
14
|
+
// before this file.
|
|
15
|
+
import type { HeightfieldCollar } from "@threenative/core/world";
|
|
16
|
+
import {
|
|
17
|
+
type IPlacement,
|
|
18
|
+
collarSampler,
|
|
19
|
+
farForestPlacements as farFieldPlacements,
|
|
20
|
+
} from "@threenative/terrain";
|
|
21
|
+
import { biomeSpec } from "../biomeData.js";
|
|
22
|
+
import type { WorldName } from "../biomes.js";
|
|
23
|
+
import type { IBakedLake, IBakedRiver } from "../water/river.js";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The far trees plant the band of hills just past the square, where a bare lawn read as a bug
|
|
27
|
+
* (owner, 2026-11-09: "why some hills have barely any vegetation?"), this many metres past its edge.
|
|
28
|
+
*/
|
|
29
|
+
const NEAR_REACH = 700;
|
|
30
|
+
export const FAR_FOREST = true;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The worlds that plant the collar past the square. None here: the tundra's ring is above the tree
|
|
34
|
+
* line on the ridges, and its forested valleys draw as the backdrop's spruce cover below `treeline`.
|
|
35
|
+
*/
|
|
36
|
+
export const FAR_FOREST_WORLDS: readonly WorldName[] = [];
|
|
37
|
+
|
|
38
|
+
/** The layer `streamedBucket` reads to put a placement in the far, shadowless bucket. */
|
|
39
|
+
export const FAR_FOREST_LAYER = "far-forest";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Unit-scale metres at which a far-forest spruce becomes the engine's whole-asset impostor; WorldCells
|
|
43
|
+
* scales it by each placement's own scale. The square's spruce switch at 150 m over their smallest
|
|
44
|
+
* scale (`impostorDistanceForScale`), about 360 m, and a cooked far spruce is 4-20 k triangles, so
|
|
45
|
+
* the same gate on the collar's ninety thousand trees would draw millions of them from the vista.
|
|
46
|
+
* The world package rejects a gate inside the last authored step, so with the licensed spruce's
|
|
47
|
+
* 80/150 m chain `propWorld.ts` lifts it to just past 150 m. The world's biome row carries it
|
|
48
|
+
* (`foliage[].far.impostor`), and this is the constant the streaming reads.
|
|
49
|
+
*/
|
|
50
|
+
export const FAR_FOREST_IMPOSTOR = 110;
|
|
51
|
+
|
|
52
|
+
export { collarSampler };
|
|
53
|
+
|
|
54
|
+
/** What the game hands the rule: its drawn collar, its treeline band, its water and its cameras. */
|
|
55
|
+
interface IFarForestOptions {
|
|
56
|
+
readonly size: number;
|
|
57
|
+
readonly resolution: number;
|
|
58
|
+
/** The world's far collar, as drawn. */
|
|
59
|
+
readonly collar: HeightfieldCollar;
|
|
60
|
+
/** The measured treeline band, metres (`IWorldBiome.heightBands.treeline`). */
|
|
61
|
+
readonly treeline: readonly [number, number];
|
|
62
|
+
readonly world: WorldName;
|
|
63
|
+
readonly rivers?: readonly IBakedRiver[];
|
|
64
|
+
readonly lakes?: readonly IBakedLake[];
|
|
65
|
+
/** Circles kept open, [x, z, radius]: the vista's meadow. */
|
|
66
|
+
readonly clear?: readonly (readonly [
|
|
67
|
+
number,
|
|
68
|
+
number,
|
|
69
|
+
number,
|
|
70
|
+
])[] /** The sea's surface height when the world has one (`data.waterLevel`): no tree under it. */;
|
|
71
|
+
readonly seaLevel?: number | null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Spruce placements on the collar; also paints the collar's `canopy` attribute under each crown. */
|
|
75
|
+
export function farForestPlacements(options: IFarForestOptions): IPlacement[] {
|
|
76
|
+
const far = biomeSpec(options.world).foliage[0]?.far;
|
|
77
|
+
if (far === undefined || far === null)
|
|
78
|
+
throw new RangeError(`${options.world}: the biome file carries no far field rule`);
|
|
79
|
+
const placed = farFieldPlacements({
|
|
80
|
+
size: options.size,
|
|
81
|
+
resolution: options.resolution,
|
|
82
|
+
collar: options.collar,
|
|
83
|
+
treeline: options.treeline,
|
|
84
|
+
rivers: options.rivers,
|
|
85
|
+
lakes: options.lakes,
|
|
86
|
+
clear: options.clear,
|
|
87
|
+
seaLevel: options.seaLevel,
|
|
88
|
+
rules: far,
|
|
89
|
+
asset: "spruce",
|
|
90
|
+
layer: FAR_FOREST_LAYER,
|
|
91
|
+
});
|
|
92
|
+
const reach = options.size / 2 + NEAR_REACH;
|
|
93
|
+
return placed.filter(
|
|
94
|
+
(tree) => Math.max(Math.abs(tree.position[0]), Math.abs(tree.position[2])) <= reach,
|
|
95
|
+
);
|
|
96
|
+
}
|