@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
package/starter/forest/bake.mjs
CHANGED
|
@@ -1,422 +1,30 @@
|
|
|
1
1
|
// The forest's bake: `node src/terrain/forest/bake.mjs [--out <dir>]` (default `assets/terrain/forest`).
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// and river, places the biome file's stands, and writes what the game fetches under `<out>/world/`:
|
|
5
|
-
// the field, its splat, the far ring and its massif, the canopy and sky the ground shader reads, and
|
|
6
|
-
// the streamed prop containers. It then copies the CC0 art the forest draws from the terrain
|
|
7
|
-
// package's starter assets into `<out>/`. The game loads all of it through `forestAssets`.
|
|
8
|
-
//
|
|
9
|
-
// It imports this kit's own TypeScript (`render/`, `world/`) for the placement policy and the canopy,
|
|
2
|
+
// `bakeKit` reads `recipe.json` (the surveyed Sprague Lake valley, USGS 3DEP, public domain; its far
|
|
3
|
+
// ring from the starter assets' `survey/` grids; its art) and `biome.data.json`; this kit's own TypeScript gives the look and the prop policy,
|
|
10
4
|
// so it runs under `tsx` (`npm i -D tsx`).
|
|
11
|
-
import
|
|
12
|
-
import { createHash } from "node:crypto";
|
|
13
|
-
import { readFileSync } from "node:fs";
|
|
14
|
-
import { cp, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
15
|
-
import { dirname, join, resolve } from "node:path";
|
|
16
|
-
import { fileURLToPath } from "node:url";
|
|
17
|
-
import {
|
|
18
|
-
MATERIAL_IDS,
|
|
19
|
-
Mask,
|
|
20
|
-
Terrain,
|
|
21
|
-
bakeBiome,
|
|
22
|
-
bakeMesh,
|
|
23
|
-
compilePropBuckets,
|
|
24
|
-
landformBackdrop,
|
|
25
|
-
placeMassif,
|
|
26
|
-
propPackageFiles,
|
|
27
|
-
validateBiome,
|
|
28
|
-
} from "@threenative/terrain";
|
|
29
|
-
import { starterAssetsDir } from "@threenative/terrain/kit";
|
|
30
|
-
import { BufferGeometry, Float32BufferAttribute, Mesh } from "three";
|
|
5
|
+
import { bakeKit } from "@threenative/terrain/kit";
|
|
31
6
|
import { register } from "tsx/esm/api";
|
|
32
7
|
|
|
33
8
|
register();
|
|
34
|
-
const here = dirname(fileURLToPath(import.meta.url));
|
|
35
9
|
const { terrainPalette } = await import("./render/ground/palette.js");
|
|
36
10
|
const { GROUND_MAPS, GROUND_TILE } = await import("./world/terrainAssets.ts");
|
|
37
|
-
const {
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
/** The CC0 art the forest draws, copied from the starter assets as it is named there. */
|
|
52
|
-
const ART = [
|
|
53
|
-
"bark_brown_02",
|
|
54
|
-
"boulder_01",
|
|
55
|
-
"celandine_01",
|
|
56
|
-
"dandelion_01",
|
|
57
|
-
"dead_tree_trunk",
|
|
58
|
-
"dry_branches_medium_01",
|
|
59
|
-
"fern_02",
|
|
60
|
-
"forest_ground_04",
|
|
61
|
-
"grass_medium",
|
|
62
|
-
"leafy_grass",
|
|
63
|
-
"lichen_rock",
|
|
64
|
-
"moss_01",
|
|
65
|
-
"mossy_rock",
|
|
66
|
-
"nettle_plant",
|
|
67
|
-
"periwinkle_plant",
|
|
68
|
-
"river_small_rocks",
|
|
69
|
-
"rock_boulder_dry",
|
|
70
|
-
"rock_face",
|
|
71
|
-
"rocks",
|
|
72
|
-
"sand_01",
|
|
73
|
-
"shrub_02",
|
|
74
|
-
"shrub_04",
|
|
75
|
-
"snow_02",
|
|
76
|
-
"tree_small_02",
|
|
77
|
-
"tree_stump_01",
|
|
78
|
-
"weed_plant_02",
|
|
79
|
-
"needle-atlas.png",
|
|
80
|
-
"needle-surface.png",
|
|
81
|
-
"fir_tree_01/fir_tree_01_twig_arm_1k.jpg",
|
|
82
|
-
"fir_tree_01/fir_tree_01_twig_diff_1k.jpg",
|
|
83
|
-
"fir_tree_01/fir_tree_01_twig_nor_gl_1k.jpg",
|
|
84
|
-
"hdri/kloofendal_48d_partly_cloudy_2k.hdr",
|
|
85
|
-
"mannequin-swim.glb",
|
|
86
|
-
];
|
|
87
|
-
|
|
88
|
-
/** One surveyed grid from `starter-assets/survey/`, checked against its own hash. */
|
|
89
|
-
async function survey(name) {
|
|
90
|
-
const meta = JSON.parse(await readFile(join(starter, "survey", `${name}.json`), "utf8"));
|
|
91
|
-
const bytes = await readFile(join(starter, "survey", `${name}.bin`));
|
|
92
|
-
assert.equal(bytes.length, meta.resolution ** 2 * 2, `${name}: truncated survey`);
|
|
93
|
-
assert.equal(createHash("sha256").update(bytes).digest("hex"), meta.sha256, `${name}: hash`);
|
|
94
|
-
return { meta, bytes };
|
|
95
|
-
}
|
|
96
|
-
const decimetres = ({ meta, bytes }) => ({
|
|
97
|
-
width: meta.resolution,
|
|
98
|
-
height: meta.resolution,
|
|
99
|
-
values: Array.from({ length: meta.resolution ** 2 }, (_, i) => bytes.readInt16LE(i * 2) / 10),
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
// Sprague Lake's hydro-flattened survey measures the water surface, not its bed: the valley and
|
|
103
|
-
// shore stay surveyed, and a shallow lake bed and a creek are authored into that surface.
|
|
104
|
-
const dem = decimetres(await survey("forest"));
|
|
105
|
-
const recipe = new Terrain({ size: 512, resolution: 257, seed: 73 })
|
|
106
|
-
.heightmap({ id: "usgs-3dep", data: dem })
|
|
107
|
-
.erode({
|
|
108
|
-
id: "surface-runoff",
|
|
109
|
-
method: "hydraulic",
|
|
110
|
-
droplets: 20000,
|
|
111
|
-
maxSteps: 45,
|
|
112
|
-
capacity: 2,
|
|
113
|
-
erosion: 0.015,
|
|
114
|
-
strength: 0.002,
|
|
115
|
-
deposition: 0.2,
|
|
116
|
-
evaporation: 0.035,
|
|
117
|
-
})
|
|
118
|
-
.erode({ id: "loose-talus", method: "thermal", talus: 38, iterations: 1, rate: 0.004 })
|
|
119
|
-
.materials({
|
|
120
|
-
id: "surfaces",
|
|
121
|
-
rules: [
|
|
122
|
-
{ material: "dirt", mask: Mask.noise(78, 0.52, 73, 0.32), strength: 0.5 },
|
|
123
|
-
{ material: "rock", mask: Mask.slope(34, 90, 9) },
|
|
124
|
-
],
|
|
125
|
-
})
|
|
126
|
-
.road({
|
|
127
|
-
id: "access-road",
|
|
128
|
-
followTerrain: true,
|
|
129
|
-
points: [
|
|
130
|
-
[-240, null, -185],
|
|
131
|
-
[-150, null, -185],
|
|
132
|
-
[-125, null, -185],
|
|
133
|
-
],
|
|
134
|
-
width: 6,
|
|
135
|
-
shoulder: 4,
|
|
136
|
-
})
|
|
137
|
-
.flatten({ id: "building-pad", at: [-160, -180], radius: 12, falloff: 0.75 })
|
|
138
|
-
.paint({ id: "pad-surface", at: [-160, -180], radius: 12, material: "dirt" })
|
|
139
|
-
.flatten({
|
|
140
|
-
id: "lake-bed",
|
|
141
|
-
at: [-70, 25],
|
|
142
|
-
radius: 105,
|
|
143
|
-
height: 11.4,
|
|
144
|
-
falloff: 0.1,
|
|
145
|
-
mask: Mask.height(12.8, 13.3, 0.1),
|
|
146
|
-
})
|
|
147
|
-
.river({
|
|
148
|
-
id: "river",
|
|
149
|
-
followTerrain: true,
|
|
150
|
-
points: [
|
|
151
|
-
[-120, null, -220],
|
|
152
|
-
[-110, null, -175],
|
|
153
|
-
[-120, null, -130],
|
|
154
|
-
[-100, null, -95],
|
|
155
|
-
[-70, null, -60],
|
|
156
|
-
],
|
|
157
|
-
width: 7,
|
|
158
|
-
depth: 1.8,
|
|
159
|
-
shoulder: 10,
|
|
160
|
-
enforceDownhill: true,
|
|
161
|
-
})
|
|
162
|
-
.water({ id: "lake", kind: "lake", at: [-70, 25], radius: 105, level: 13.3 })
|
|
163
|
-
// What a full-world export places; the game draws its own runtime scatter, not these.
|
|
164
|
-
.scatter({
|
|
165
|
-
id: "stand",
|
|
166
|
-
asset: "spruce",
|
|
167
|
-
count: 120,
|
|
168
|
-
minDistance: 8,
|
|
169
|
-
maxSlope: 35,
|
|
170
|
-
avoidWater: true,
|
|
171
|
-
scale: [0.9, 1.5],
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* The far ring: Glacier Creek's relief (865 m over 5 km) as a generated temperate backdrop, ridged
|
|
176
|
-
* crests and spurs above the treeline, and one whole surveyed mountain standing 2.4 km from the
|
|
177
|
-
* vista eye, its steepest wall turned south into the low sun.
|
|
178
|
-
*/
|
|
179
|
-
async function continuation() {
|
|
180
|
-
const { meta } = await survey("forest-horizon");
|
|
181
|
-
const ring = decimetres(await survey("forest-horizon"));
|
|
182
|
-
const backdrop = landformBackdrop("temperateMountains", {
|
|
183
|
-
size: meta.size,
|
|
184
|
-
resolution: meta.resolution,
|
|
185
|
-
seed: 23,
|
|
186
|
-
relief: 865,
|
|
187
|
-
centerHeight: ring.values[((meta.resolution - 1) / 2) * (meta.resolution + 1)],
|
|
188
|
-
});
|
|
189
|
-
const crested = new Terrain({ size: meta.size, resolution: meta.resolution, seed: 1 })
|
|
190
|
-
.heightmap({
|
|
191
|
-
id: "usgs-surroundings",
|
|
192
|
-
data: { width: meta.resolution, height: meta.resolution, values: backdrop.heights },
|
|
193
|
-
})
|
|
194
|
-
.noise({
|
|
195
|
-
id: "crests",
|
|
196
|
-
mode: "ridged",
|
|
197
|
-
amplitude: 170,
|
|
198
|
-
scale: 1100,
|
|
199
|
-
octaves: 3,
|
|
200
|
-
warp: 300,
|
|
201
|
-
mask: Mask.height(320, 1e9, 200),
|
|
202
|
-
})
|
|
203
|
-
.noise({
|
|
204
|
-
id: "spurs",
|
|
205
|
-
mode: "fbm",
|
|
206
|
-
amplitude: 45,
|
|
207
|
-
scale: 320,
|
|
208
|
-
octaves: 3,
|
|
209
|
-
warp: 150,
|
|
210
|
-
mask: Mask.height(200, 1e9, 80),
|
|
211
|
-
})
|
|
212
|
-
.erode({
|
|
213
|
-
id: "gullies",
|
|
214
|
-
method: "hydraulic",
|
|
215
|
-
droplets: 40000,
|
|
216
|
-
mask: Mask.height(380, 1e9, 160),
|
|
217
|
-
});
|
|
218
|
-
const tiles = [];
|
|
219
|
-
for (const id of ["longs", "teton", "maroon"]) {
|
|
220
|
-
const tile = await survey(`massif-${id}`);
|
|
221
|
-
tiles.push({
|
|
222
|
-
id,
|
|
223
|
-
size: tile.meta.size,
|
|
224
|
-
resolution: tile.meta.resolution,
|
|
225
|
-
heights: Float32Array.from(
|
|
226
|
-
{ length: tile.meta.resolution ** 2 },
|
|
227
|
-
(_, i) => tile.meta.elevationOffset + tile.bytes.readInt16LE(i * 2) / 10,
|
|
228
|
-
),
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
const placed = placeMassif(crested, {
|
|
232
|
-
seed: 6,
|
|
233
|
-
tile: tiles,
|
|
234
|
-
at: [-2050, -150],
|
|
235
|
-
face: 90,
|
|
236
|
-
keepOut: 650,
|
|
237
|
-
top: [1100, 1160],
|
|
238
|
-
});
|
|
239
|
-
return { state: placed.terrain.evaluate(), massif: placed.placement };
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/** A placed massif's 4 m heights for the collar's relief map: int16 decimetres above `offset`. */
|
|
243
|
-
function packMassif({ origin, spacing, columns, rows, heights }) {
|
|
244
|
-
let offset = Number.POSITIVE_INFINITY;
|
|
245
|
-
for (const height of heights) offset = Math.min(offset, Math.floor(height));
|
|
246
|
-
const bytes = Buffer.alloc(heights.length * 2);
|
|
247
|
-
for (let i = 0; i < heights.length; i++) {
|
|
248
|
-
const quantized = Math.round((heights[i] - offset) * 10);
|
|
249
|
-
assert(quantized >= 0 && quantized <= 32767, "massif heights exceed int16 decimetres");
|
|
250
|
-
bytes.writeInt16LE(quantized, i * 2);
|
|
251
|
-
}
|
|
252
|
-
return { origin, spacing, columns, rows, offset, heights: bytes.toString("base64") };
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/** The splat the ground loader reads (`loadTerrainSplat`): eight raw planes, two RGBA images. */
|
|
256
|
-
function surfacePackage(state) {
|
|
257
|
-
const count = state.resolution ** 2;
|
|
258
|
-
assert.equal(state.splat.length, count * MATERIAL_IDS.length, "invalid splat grid");
|
|
259
|
-
const splat = new Uint8Array(count * 8);
|
|
260
|
-
for (let row = 0; row < state.resolution; row += 1)
|
|
261
|
-
for (let column = 0; column < state.resolution; column += 1)
|
|
262
|
-
for (let channel = 0; channel < MATERIAL_IDS.length; channel += 1) {
|
|
263
|
-
const value = state.splat[(row * state.resolution + column) * 8 + channel];
|
|
264
|
-
assert(Number.isFinite(value), "nonfinite splat channel");
|
|
265
|
-
// Package ground is (x, -z): reverse the evaluator's increasing-Z rows.
|
|
266
|
-
const pixel = (state.resolution - 1 - row) * state.resolution + column;
|
|
267
|
-
splat[Math.floor(channel / 4) * count * 4 + pixel * 4 + (channel % 4)] = Math.round(
|
|
268
|
-
Math.max(0, Math.min(1, value)) * 255,
|
|
269
|
-
);
|
|
270
|
-
}
|
|
271
|
-
const maps = {
|
|
272
|
-
...GROUND_MAPS,
|
|
273
|
-
dirt: {
|
|
274
|
-
diffuse: "river_small_rocks/river_small_rocks_diff_512.jpg",
|
|
275
|
-
normal: "river_small_rocks/river_small_rocks_nor_gl_512.jpg",
|
|
276
|
-
},
|
|
277
|
-
};
|
|
278
|
-
const layer = (id) => ({
|
|
279
|
-
id,
|
|
280
|
-
tile: GROUND_TILE[id],
|
|
281
|
-
tint: [1, 1, 1],
|
|
282
|
-
roughness: 0.95,
|
|
283
|
-
metalness: 0,
|
|
284
|
-
normal: maps[id].normal !== undefined,
|
|
285
|
-
maps: {
|
|
286
|
-
diffuse: `../${maps[id].diffuse}`,
|
|
287
|
-
...(maps[id].normal === undefined ? {} : { normal: `../${maps[id].normal}` }),
|
|
288
|
-
},
|
|
289
|
-
});
|
|
290
|
-
return {
|
|
291
|
-
world: {
|
|
292
|
-
version: 1,
|
|
293
|
-
extent: {
|
|
294
|
-
minX: -state.size / 2,
|
|
295
|
-
minZ: -state.size / 2,
|
|
296
|
-
sizeX: state.size,
|
|
297
|
-
sizeZ: state.size,
|
|
11
|
+
const { CANOPY_CROWN } = await import("./render/ground/terrain.ts");
|
|
12
|
+
const props = await import("./render/props/props.ts");
|
|
13
|
+
|
|
14
|
+
await bakeKit(import.meta.url, {
|
|
15
|
+
look: {
|
|
16
|
+
palette: terrainPalette,
|
|
17
|
+
ground: {
|
|
18
|
+
maps: {
|
|
19
|
+
...GROUND_MAPS,
|
|
20
|
+
dirt: {
|
|
21
|
+
diffuse: "river_small_rocks/river_small_rocks_diff_512.jpg",
|
|
22
|
+
normal: "river_small_rocks/river_small_rocks_nor_gl_512.jpg",
|
|
23
|
+
},
|
|
298
24
|
},
|
|
299
|
-
|
|
25
|
+
tile: GROUND_TILE,
|
|
300
26
|
},
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
mask: id,
|
|
306
|
-
channel: "r",
|
|
307
|
-
lo: 0,
|
|
308
|
-
hi: 1,
|
|
309
|
-
})),
|
|
310
|
-
breakup: { scale: 1, push: 0 },
|
|
311
|
-
macro: { scale: 1, min: 1, max: 1 },
|
|
312
|
-
textures: "",
|
|
313
|
-
splat: {
|
|
314
|
-
size: state.resolution,
|
|
315
|
-
planes: 2,
|
|
316
|
-
masks: Object.fromEntries(
|
|
317
|
-
MATERIAL_IDS.map((id, index) => [
|
|
318
|
-
id,
|
|
319
|
-
[Math.floor(index / 4), ["r", "g", "b", "a"][index % 4]],
|
|
320
|
-
]),
|
|
321
|
-
),
|
|
322
|
-
},
|
|
323
|
-
},
|
|
324
|
-
splat,
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
/** The streamed prop package: one manifest and one container per streamed world. */
|
|
329
|
-
async function writeProps(placements, size) {
|
|
330
|
-
const indices = new Map();
|
|
331
|
-
const entries = placements.map((placement) => {
|
|
332
|
-
const variant = `${placement.asset}:${variantFor(placement, placement.asset)}`;
|
|
333
|
-
const index = indices.get(variant) ?? 0;
|
|
334
|
-
indices.set(variant, index + 1);
|
|
335
|
-
const reach = streamedReach(placement, index);
|
|
336
|
-
return {
|
|
337
|
-
bucket: streamedBucket(placement, reach),
|
|
338
|
-
key: propKey(placement),
|
|
339
|
-
placement: withAuthoredPose(placement),
|
|
340
|
-
reach,
|
|
341
|
-
};
|
|
342
|
-
});
|
|
343
|
-
const pkg = compilePropBuckets(entries, {
|
|
344
|
-
bounds: { minX: -size / 2, minZ: -size / 2, sizeX: size, sizeZ: size },
|
|
345
|
-
});
|
|
346
|
-
const { files, manifest } = propPackageFiles(pkg, "forest");
|
|
347
|
-
await writeFile(join(worldDir, "forest.props.json"), manifest);
|
|
348
|
-
for (const [file, bytes] of Object.entries(files)) await writeFile(join(worldDir, file), bytes);
|
|
349
|
-
return pkg.buckets.map((bucket) => `${bucket.bucket} ${bucket.ids.length}`).join(", ");
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
const started = performance.now();
|
|
353
|
-
await mkdir(worldDir, { recursive: true });
|
|
354
|
-
const state = recipe.evaluate();
|
|
355
|
-
for (const channel of ["flow", "sediment", "deposition", "talus"])
|
|
356
|
-
assert(state.erosion?.[channel]?.every(Number.isFinite), `missing or nonfinite ${channel}`);
|
|
357
|
-
const surface = surfacePackage(state);
|
|
358
|
-
await writeFile(join(worldDir, "forest.world.json"), JSON.stringify(surface.world));
|
|
359
|
-
await writeFile(join(worldDir, "forest.layers.json"), JSON.stringify(surface.table));
|
|
360
|
-
await writeFile(join(worldDir, "forest.splat.rgba8"), surface.splat);
|
|
361
|
-
|
|
362
|
-
const spec = validateBiome(
|
|
363
|
-
JSON.parse(readFileSync(join(here, "biome.data.json"), "utf8")),
|
|
364
|
-
"forest",
|
|
365
|
-
);
|
|
366
|
-
const { scatter } = bakeBiome({ state, spec });
|
|
367
|
-
assert(scatter !== null, "the biome file places nothing");
|
|
368
|
-
const world = {
|
|
369
|
-
size: state.size,
|
|
370
|
-
resolution: state.resolution,
|
|
371
|
-
heights: Array.from(state.height),
|
|
372
|
-
colors: Array.from(bakeMesh(state, { palette: terrainPalette }).colors),
|
|
373
|
-
erosion: Object.fromEntries(
|
|
374
|
-
Object.entries(state.erosion ?? {}).map(([key, values]) => [
|
|
375
|
-
key,
|
|
376
|
-
Array.from(values, (value) => Math.round(value * 1000) / 1000),
|
|
377
|
-
]),
|
|
378
|
-
),
|
|
379
|
-
rivers: state.rivers,
|
|
380
|
-
waterLevel: state.waters.find((water) => water.kind === "ocean")?.level ?? null,
|
|
381
|
-
lakes: state.waters
|
|
382
|
-
.filter((water) => water.kind === "lake")
|
|
383
|
-
.map(({ id, at, radius, level }) => ({ id, at, radius, level })),
|
|
384
|
-
};
|
|
385
|
-
await writeFile(join(worldDir, "forest.json"), JSON.stringify(world));
|
|
386
|
-
|
|
387
|
-
const ring = await continuation();
|
|
388
|
-
await writeFile(
|
|
389
|
-
join(worldDir, "horizon.json"),
|
|
390
|
-
JSON.stringify({
|
|
391
|
-
forest: {
|
|
392
|
-
size: ring.state.size,
|
|
393
|
-
resolution: ring.state.resolution,
|
|
394
|
-
heights: Array.from(ring.state.height, (height) => Math.round(height * 10) / 10),
|
|
395
|
-
massif: packMassif(ring.massif.detail),
|
|
396
|
-
},
|
|
397
|
-
}),
|
|
398
|
-
);
|
|
399
|
-
|
|
400
|
-
const mesh = new Mesh(new BufferGeometry());
|
|
401
|
-
mesh.geometry.setAttribute(
|
|
402
|
-
"canopy",
|
|
403
|
-
new Float32BufferAttribute(new Float32Array(world.resolution ** 2), 1),
|
|
404
|
-
);
|
|
405
|
-
paintCanopy(mesh, world, scatter.placements);
|
|
406
|
-
const canopy = mesh.geometry.getAttribute("canopy").array;
|
|
407
|
-
await writeFile(
|
|
408
|
-
join(worldDir, "forest.canopy.bin"),
|
|
409
|
-
new Uint8Array(canopy.buffer, canopy.byteOffset, canopy.byteLength),
|
|
410
|
-
);
|
|
411
|
-
// The share of the sky each vertex sees past the relief, one byte a vertex, for the ground's AO.
|
|
412
|
-
const sky = skyVisibility(world.heights, world.resolution, world.size);
|
|
413
|
-
await writeFile(
|
|
414
|
-
join(worldDir, "forest.sky.bin"),
|
|
415
|
-
Uint8Array.from(sky, (v) => Math.round(v * 255)),
|
|
416
|
-
);
|
|
417
|
-
const buckets = await writeProps(scatter.placements, world.size);
|
|
418
|
-
|
|
419
|
-
for (const path of ART) await cp(join(starter, path), join(out, path), { recursive: true });
|
|
420
|
-
console.log(
|
|
421
|
-
`forest: ${scatter.placements.length} placements (${buckets}); ${ART.length} art entries; ${((performance.now() - started) / 1000).toFixed(1)} s -> ${out}`,
|
|
422
|
-
);
|
|
27
|
+
canopy: CANOPY_CROWN,
|
|
28
|
+
props,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
@@ -1,30 +1,19 @@
|
|
|
1
|
-
import { BlendSpace1D, SkeletalMesh3D } from "@threenative/core";
|
|
2
1
|
import type { Heightfield } from "@threenative/core/world";
|
|
3
|
-
import { CharacterBody3D, CollisionShape3D } from "@threenative/physics";
|
|
4
2
|
import {
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} from "three";
|
|
13
|
-
import {
|
|
14
|
-
CAMERA_RIG,
|
|
15
|
-
type IOrbitCamera,
|
|
16
|
-
type WallProbe,
|
|
17
|
-
createOrbitCamera,
|
|
18
|
-
} from "./render/orbitCamera.js";
|
|
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";
|
|
19
10
|
import { SIGHT_RADIUS, sightLine } from "./render/props/pack.js";
|
|
20
11
|
import type { TerrainCtx } from "./sceneState.js";
|
|
21
12
|
|
|
22
|
-
|
|
23
|
-
export
|
|
24
|
-
readonly scene: Object3D;
|
|
25
|
-
readonly animations: readonly AnimationClip[];
|
|
26
|
-
}
|
|
13
|
+
export type { IMannequin, IPlayerRig };
|
|
14
|
+
export type { WallProbe };
|
|
27
15
|
|
|
16
|
+
/** The starter kit's mannequin (Quaternius Universal Animation Library, CC0) and its clips. */
|
|
28
17
|
const CLIPS = {
|
|
29
18
|
idle: "Idle_Loop",
|
|
30
19
|
walk: "Walk_Loop",
|
|
@@ -32,10 +21,9 @@ const CLIPS = {
|
|
|
32
21
|
fall: "Jump_Loop",
|
|
33
22
|
swim: "Swim_Fwd_Loop",
|
|
34
23
|
tread: "Swim_Idle_Loop",
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
const
|
|
38
|
-
/** Ground speeds in m/s: the jog the clip was authored for, and the Shift sprint. */
|
|
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;
|
|
39
27
|
const JOG = 6;
|
|
40
28
|
const SPRINT = 9;
|
|
41
29
|
|
|
@@ -48,7 +36,7 @@ export interface IPlayerRigOptions {
|
|
|
48
36
|
/** The ground the spawn stands on: the launch pose is measured from it, not guessed. */
|
|
49
37
|
readonly field: Heightfield;
|
|
50
38
|
readonly mannequin: IMannequin;
|
|
51
|
-
/** The rig's two swim clips, which the
|
|
39
|
+
/** The rig's two swim clips, which the mannequin's own clips do not carry. */
|
|
52
40
|
readonly swimClips: readonly AnimationClip[];
|
|
53
41
|
/** A staged world streams its own ground, so the player walks only while the player view draws. */
|
|
54
42
|
readonly staged: boolean;
|
|
@@ -60,72 +48,15 @@ export interface IPlayerRigOptions {
|
|
|
60
48
|
readonly horizon: () => unknown;
|
|
61
49
|
}
|
|
62
50
|
|
|
63
|
-
export interface IPlayerRig {
|
|
64
|
-
readonly actor: Mesh;
|
|
65
|
-
readonly body: CharacterBody3D;
|
|
66
|
-
readonly figure: SkeletalMesh3D;
|
|
67
|
-
/** The launch point, frozen at entry: the streamed worlds measure their spawn cells around it. */
|
|
68
|
-
readonly spawn: Vector3;
|
|
69
|
-
/** The camera's yaw, so movement follows the ground the eye looks along. */
|
|
70
|
-
readonly yaw: () => number;
|
|
71
|
-
/** Top ground speed the scene spends on the player's own movement, in m/s. */
|
|
72
|
-
readonly pace: (sprinting: boolean) => number;
|
|
73
|
-
/** Face the travel direction and blend the gait: one call per fixed step. */
|
|
74
|
-
readonly animate: (dt: number) => void;
|
|
75
|
-
/** True while the figure plays a swim clip: the playtest reads swimming that way. */
|
|
76
|
-
readonly playsSwimClip: () => boolean;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
51
|
/**
|
|
80
|
-
* The player: the capsule
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* The stepped world is the authority for both the ground the player stands on and the wall the orbit
|
|
84
|
-
* camera cannot pass, which is why both queries mask to layer 4: what the player can walk on.
|
|
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.
|
|
85
55
|
*/
|
|
86
56
|
export function createPlayerRig(ctx: TerrainCtx, options: IPlayerRigOptions): IPlayerRig {
|
|
87
57
|
const { at, cameraOffset, field, focusShadows, horizon, mannequin, staged, swimClips, vista } =
|
|
88
58
|
options;
|
|
89
|
-
|
|
90
|
-
const actor = new Mesh(
|
|
91
|
-
new CapsuleGeometry(0.35, 1.0, 6, 12),
|
|
92
|
-
new MeshStandardMaterial({ color: 0xffc76d }),
|
|
93
|
-
);
|
|
94
|
-
actor.position.set(startX, field.heightAt(startX, startZ) + 2, startZ);
|
|
95
|
-
actor.name = "player";
|
|
96
|
-
// Freeze the launch region before gameplay or a review view can move its follow camera.
|
|
97
|
-
const spawn = actor.position.clone().add(new Vector3(...cameraOffset));
|
|
98
|
-
ctx.camera.position.copy(spawn);
|
|
99
|
-
ctx.add(actor);
|
|
100
|
-
const body = new CharacterBody3D({
|
|
101
|
-
object: actor,
|
|
102
|
-
physics: ctx.physics,
|
|
103
|
-
entity: "player",
|
|
104
|
-
shape: CollisionShape3D.capsule(0.5, 0.35),
|
|
105
|
-
snapToGround: 0.4,
|
|
106
|
-
// The kit's ground and prop colliders keep the default layer.
|
|
107
|
-
...(staged ? {} : { collisionMask: 4 }),
|
|
108
|
-
});
|
|
109
|
-
// The starter kit's humanoid rides the capsule: the capsule is the collider, the mannequin is what
|
|
110
|
-
// the player sees. Its feet sit at the capsule's bottom (0.5 m half-height plus 0.35 m radius),
|
|
111
|
-
// sunk 1 cm like the starter's; the model faces +Z.
|
|
112
|
-
const figure = new SkeletalMesh3D({
|
|
113
|
-
source: mannequin.scene,
|
|
114
|
-
clips: [...mannequin.animations, ...swimClips],
|
|
115
|
-
requiredClips: Object.values(CLIPS),
|
|
116
|
-
strideRoot: actor,
|
|
117
|
-
});
|
|
118
|
-
figure.root.traverse((object) => {
|
|
119
|
-
object.castShadow = true;
|
|
120
|
-
});
|
|
121
|
-
figure.root.position.y = FEET;
|
|
122
|
-
figure.root.rotation.y = Math.PI;
|
|
123
|
-
// engine-override: the capsule is the physics body only; the rigged figure added below is what draws.
|
|
124
|
-
actor.material.visible = false;
|
|
125
|
-
actor.add(figure.root);
|
|
126
|
-
figure.play(CLIPS.idle);
|
|
127
|
-
// Third person: the collectathon kit's orbit camera, with the terrain as its walls. The vista
|
|
128
|
-
// worlds keep their fixed player framing below.
|
|
59
|
+
// The terrain and the prop colliders are the camera's walls; both answer on the kit's ground lens.
|
|
129
60
|
const along = new Vector3();
|
|
130
61
|
const probe: WallProbe = (from, to) =>
|
|
131
62
|
along.subVectors(to, from).lengthSq() < 1e-8
|
|
@@ -135,89 +66,24 @@ export function createPlayerRig(ctx: TerrainCtx, options: IPlayerRigOptions): IP
|
|
|
135
66
|
from,
|
|
136
67
|
to,
|
|
137
68
|
})?.distance;
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
sightLine.radius.value = SIGHT_RADIUS;
|
|
158
|
-
// Shadows centre on the hero, not the orbiting eye: a camera turn re-renders no shadow page.
|
|
159
|
-
focusShadows(actor.position);
|
|
160
|
-
});
|
|
161
|
-
ctx.entities.add("player", {
|
|
162
|
-
mesh: actor,
|
|
163
|
-
debug: () => ({
|
|
164
|
-
grounded: body.grounded,
|
|
165
|
-
position: actor.position.toArray(),
|
|
166
|
-
visible: actor.visible && figure.root.visible,
|
|
167
|
-
horizon: horizon(),
|
|
168
|
-
}),
|
|
169
|
-
dispose: () => {
|
|
170
|
-
body.dispose();
|
|
171
|
-
actor.geometry.dispose();
|
|
172
|
-
actor.material.dispose();
|
|
173
|
-
},
|
|
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,
|
|
174
88
|
});
|
|
175
|
-
const gaits = new BlendSpace1D([1.8, JOG]);
|
|
176
|
-
const heading = new Quaternion();
|
|
177
|
-
let airborne = 0;
|
|
178
|
-
|
|
179
|
-
/** Swim, or ease back to land. The swim clips put the root on the waterline; True while swimming. */
|
|
180
|
-
const swim = (dt: number, speed: number): boolean => {
|
|
181
|
-
const surface = body.swimming ? body.waterSurface : undefined;
|
|
182
|
-
const target = surface === undefined ? FEET : surface - body.object.position.y;
|
|
183
|
-
figure.root.position.y += (target - figure.root.position.y) * Math.min(1, dt * 8);
|
|
184
|
-
if (surface === undefined) return false;
|
|
185
|
-
figure.play(speed > 0.3 ? CLIPS.swim : CLIPS.tread, { fade: 0.3 });
|
|
186
|
-
return true;
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
/** The starter's gait logic: face the travel direction, blend walk and jog by ground speed. */
|
|
190
|
-
const animate = (dt: number): void => {
|
|
191
|
-
const { x, z } = body.velocity;
|
|
192
|
-
const speed = Math.hypot(x, z);
|
|
193
|
-
if (speed > 0.05) {
|
|
194
|
-
heading.setFromAxisAngle(figure.root.up, Math.atan2(x, z));
|
|
195
|
-
figure.root.quaternion.slerp(heading, Math.min(1, dt * 12));
|
|
196
|
-
}
|
|
197
|
-
airborne = body.grounded ? 0 : airborne + dt;
|
|
198
|
-
if (swim(dt, speed)) airborne = 0;
|
|
199
|
-
else if (airborne > 0.2) figure.play(CLIPS.fall, { fade: 0.15 });
|
|
200
|
-
else if (speed > 0.05) {
|
|
201
|
-
const weights = gaits.sample(speed);
|
|
202
|
-
figure.playWeighted([
|
|
203
|
-
{ clip: CLIPS.walk, weight: weights[0] ?? 0 },
|
|
204
|
-
{ clip: CLIPS.run, weight: weights[1] ?? 0 },
|
|
205
|
-
]);
|
|
206
|
-
} else figure.play(CLIPS.idle, { fade: 0.2 });
|
|
207
|
-
figure.update(dt);
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
return {
|
|
211
|
-
actor,
|
|
212
|
-
animate,
|
|
213
|
-
body,
|
|
214
|
-
figure,
|
|
215
|
-
pace: (sprinting: boolean): number => (sprinting ? SPRINT : JOG),
|
|
216
|
-
playsSwimClip: (): boolean => {
|
|
217
|
-
const clip = figure.current;
|
|
218
|
-
return clip === CLIPS.swim || clip === CLIPS.tread;
|
|
219
|
-
},
|
|
220
|
-
spawn,
|
|
221
|
-
yaw: () => orbit.yaw,
|
|
222
|
-
};
|
|
223
89
|
}
|