@threenative/terrain 0.1.7 → 0.1.9
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/AGENT_GUIDE.md +19 -4
- package/dist/editor/index.d.ts +218 -5
- package/dist/editor/index.js +4093 -1399
- package/dist/editor/server.d.ts +2 -2
- package/dist/editor/server.js +752 -124
- package/dist/editor/worker.d.ts +33 -1
- package/dist/editor/worker.js +642 -114
- package/dist/export.d.ts +11 -9
- package/dist/export.js +22 -34
- package/dist/index.d.ts +866 -73
- package/dist/index.js +3003 -523
- package/dist/kit.d.ts +57 -0
- package/dist/kit.js +2718 -0
- package/dist/mcp/cook-child.d.ts +2 -0
- package/dist/mcp/cook-child.js +5346 -0
- package/dist/mcp/server.d.ts +7 -0
- package/dist/mcp/server.js +3970 -0
- package/dist/{server-ByM2hmYJ.d.ts → server-B5RdvEAC.d.ts} +3 -2
- package/dist/starter.d.ts +143 -0
- package/dist/starter.js +1031 -0
- package/dist/{terrain-gPnkCU6S.d.ts → terrain-CAEaW0mQ.d.ts} +3 -2
- package/dist/three.d.ts +1 -1
- package/dist/{types-Ant8-Axc.d.ts → types-BpH00qsx.d.ts} +20 -4
- package/dist/world-package-B8QgHjAQ.d.ts +53 -0
- package/package.json +28 -6
- package/starter/alpine/README.md +77 -1
- package/starter/alpine/bake.mjs +4 -116
- package/starter/alpine/biome.data.json +134 -0
- package/starter/alpine/heightmap.r16 +0 -0
- package/starter/alpine/recipe.json +3 -66051
- package/starter/alpine/world.ts +45 -293
- package/starter/coastal/README.md +82 -3
- package/starter/coastal/assets.json +2 -1
- package/starter/coastal/bake.mjs +4 -116
- package/starter/coastal/biome.data.json +156 -0
- package/starter/coastal/heightmap.r16 +0 -0
- package/starter/coastal/recipe.json +3 -66051
- package/starter/coastal/sea.ts +51 -66
- package/starter/coastal/world.ts +53 -318
- package/starter/desert/README.md +77 -1
- package/starter/desert/bake.mjs +4 -116
- package/starter/desert/biome.data.json +124 -0
- package/starter/desert/heightmap.r16 +0 -0
- package/starter/desert/recipe.json +3 -66051
- package/starter/desert/world.ts +45 -293
- package/starter/forest/README.md +85 -5
- package/starter/forest/assets.json +34 -1
- package/starter/forest/bake.mjs +6 -116
- package/starter/forest/biome.data.json +173 -0
- package/starter/forest/heightmap.r16 +0 -0
- package/starter/forest/recipe.json +192 -4428
- package/starter/forest/sky.ts +11 -0
- package/starter/forest/water.ts +39 -48
- package/starter/forest/world.ts +92 -323
- package/starter/tundra/README.md +77 -1
- package/starter/tundra/bake.mjs +4 -116
- package/starter/tundra/biome.data.json +141 -0
- package/starter/tundra/heightmap.r16 +0 -0
- package/starter/tundra/recipe.json +18 -66066
- package/starter/tundra/water.ts +9 -28
- package/starter/tundra/world.ts +65 -319
- package/starter-assets.json +6 -0
- package/{starter-assets/credits.json → starter-credits.json} +12 -105
- package/starter-assets/bark_brown_02/bark_brown_02_diff_1k.jpg +0 -0
- package/starter-assets/bark_brown_02/bark_brown_02_nor_gl_1k.jpg +0 -0
- package/starter-assets/bark_brown_02/bark_brown_02_rough_1k.jpg +0 -0
- package/starter-assets/boulder_01/boulder-mid.glb +0 -0
- package/starter-assets/boulder_01/boulder-near.glb +0 -0
- package/starter-assets/cliff_side/cliff_side_ao_1k.jpg +0 -0
- package/starter-assets/cliff_side/cliff_side_diff_1k.jpg +0 -0
- package/starter-assets/cliff_side/cliff_side_nor_gl_1k.jpg +0 -0
- package/starter-assets/cliff_side/cliff_side_rough_1k.jpg +0 -0
- package/starter-assets/fern_02/fern_02_alpha_512.png +0 -0
- package/starter-assets/fern_02/fern_02_diff_512.jpg +0 -0
- package/starter-assets/fern_02/fern_02_nor_gl_512.jpg +0 -0
- package/starter-assets/fir_tree_01/fir-b-lod1.glb +0 -0
- package/starter-assets/fir_tree_01/fir-b-lod2.glb +0 -0
- package/starter-assets/fir_tree_01/fir-c-lod1.glb +0 -0
- package/starter-assets/fir_tree_01/fir-c-lod2.glb +0 -0
- package/starter-assets/fir_tree_01/fir_tree_01_twig_arm_1k.jpg +0 -0
- package/starter-assets/fir_tree_01/fir_tree_01_twig_diff_1k.jpg +0 -0
- package/starter-assets/fir_tree_01/fir_tree_01_twig_nor_gl_1k.jpg +0 -0
- package/starter-assets/forest_ground_04/forest_ground_04_ao_1k.jpg +0 -0
- package/starter-assets/forest_ground_04/forest_ground_04_diff_1k.jpg +0 -0
- package/starter-assets/forest_ground_04/forest_ground_04_nor_gl_1k.jpg +0 -0
- package/starter-assets/forest_ground_04/forest_ground_04_rough_1k.jpg +0 -0
- package/starter-assets/forest_leaves_02/forest_leaves_02_arm_512.jpg +0 -0
- package/starter-assets/forest_leaves_02/forest_leaves_02_diff_512.jpg +0 -0
- package/starter-assets/forest_leaves_02/forest_leaves_02_nor_gl_512.jpg +0 -0
- package/starter-assets/grass_medium_02/grass_medium_02_alpha_512.png +0 -0
- package/starter-assets/grass_medium_02/grass_medium_02_diff_512.jpg +0 -0
- package/starter-assets/grass_medium_02/grass_medium_02_nor_gl_512.jpg +0 -0
- package/starter-assets/hdri/kloofendal_48d_partly_cloudy_1k.hdr +0 -0
- package/starter-assets/leafy_grass/leafy_grass_ao_1k.jpg +0 -0
- package/starter-assets/leafy_grass/leafy_grass_diff_1k.jpg +0 -0
- package/starter-assets/leafy_grass/leafy_grass_nor_gl_1k.jpg +0 -0
- package/starter-assets/leafy_grass/leafy_grass_rough_1k.jpg +0 -0
- package/starter-assets/lichen_rock/lichen_rock_arm_512.jpg +0 -0
- package/starter-assets/lichen_rock/lichen_rock_diff_512.jpg +0 -0
- package/starter-assets/lichen_rock/lichen_rock_nor_gl_512.jpg +0 -0
- package/starter-assets/mossy_rock/mossy_rock_ao_1k.jpg +0 -0
- package/starter-assets/mossy_rock/mossy_rock_diff_1k.jpg +0 -0
- package/starter-assets/mossy_rock/mossy_rock_nor_gl_1k.jpg +0 -0
- package/starter-assets/mossy_rock/mossy_rock_rough_1k.jpg +0 -0
- package/starter-assets/needle-atlas.png +0 -0
- package/starter-assets/needle-surface.png +0 -0
- package/starter-assets/river_small_rocks/river_small_rocks_arm_512.jpg +0 -0
- package/starter-assets/river_small_rocks/river_small_rocks_diff_512.jpg +0 -0
- package/starter-assets/river_small_rocks/river_small_rocks_nor_gl_512.jpg +0 -0
- package/starter-assets/rock_boulder_dry/rock_boulder_dry_arm_512.jpg +0 -0
- package/starter-assets/rock_boulder_dry/rock_boulder_dry_diff_512.jpg +0 -0
- package/starter-assets/rock_boulder_dry/rock_boulder_dry_nor_gl_512.jpg +0 -0
- package/starter-assets/rocks/boulder-mid.glb +0 -0
- package/starter-assets/rocks/boulder-near.glb +0 -0
- package/starter-assets/rocks/boulder-prep.json +0 -37
- package/starter-assets/rocks/rock01-mid.glb +0 -0
- package/starter-assets/rocks/rock01-near.glb +0 -0
- package/starter-assets/rocks/rock01-prep.json +0 -37
- package/starter-assets/rocks/rock04-mid.glb +0 -0
- package/starter-assets/rocks/rock04-near.glb +0 -0
- package/starter-assets/rocks/rock04-prep.json +0 -37
- package/starter-assets/sand_01/sand_01_ao_1k.jpg +0 -0
- package/starter-assets/sand_01/sand_01_diff_1k.jpg +0 -0
- package/starter-assets/sand_01/sand_01_nor_gl_1k.jpg +0 -0
- package/starter-assets/sand_01/sand_01_rough_1k.jpg +0 -0
- package/starter-assets/snow_02/snow_02_ao_1k.jpg +0 -0
- package/starter-assets/snow_02/snow_02_diff_1k.jpg +0 -0
- package/starter-assets/snow_02/snow_02_nor_gl_1k.jpg +0 -0
- package/starter-assets/snow_02/snow_02_rough_1k.jpg +0 -0
package/starter/forest/sky.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// Edit any number here to change the look; nothing in a package decides it.
|
|
3
3
|
import { Daylight } from "@threenative/core";
|
|
4
4
|
import { ACESFilmicToneMapping, Color, type Object3D, Vector3 } from "three";
|
|
5
|
+
import { color, mix, normalize, positionLocal, smoothstep, vec3 } from "three/tsl";
|
|
6
|
+
import type { Node } from "three/webgpu";
|
|
5
7
|
import { SKY_REFLECTION_LAYER } from "./water.js";
|
|
6
8
|
|
|
7
9
|
export function forestDaylight(follow: Object3D): Daylight {
|
|
@@ -21,6 +23,15 @@ export function forestDaylight(follow: Object3D): Daylight {
|
|
|
21
23
|
// The box's corners must stay inside the camera's far plane (5000 m in the kit's example scene).
|
|
22
24
|
skySize: 5000,
|
|
23
25
|
});
|
|
26
|
+
// Compress the bright lower dome without dimming the blue sky the lake reflects.
|
|
27
|
+
const elevation = normalize(positionLocal).y;
|
|
28
|
+
daylight.sky.material.colorNode = mix(
|
|
29
|
+
color(daylight.haze.color).mul(mix(2.4, 3.2, smoothstep(-0.6, 0, elevation))),
|
|
30
|
+
vec3(daylight.sky.material.colorNode as Node<"vec4">).mul(
|
|
31
|
+
mix(0.3, 1, smoothstep(-0.05, 0.45, elevation)),
|
|
32
|
+
),
|
|
33
|
+
smoothstep(-0.08, 0.08, elevation),
|
|
34
|
+
);
|
|
24
35
|
// The lake mirrors the sky: its mirror draws only the layer the sky sits on (see water.ts).
|
|
25
36
|
daylight.sky.layers.enable(SKY_REFLECTION_LAYER);
|
|
26
37
|
return daylight;
|
package/starter/forest/water.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// the shore are this file's to change: the kit owns its look.
|
|
7
7
|
import type { ICtx } from "@threenative/core";
|
|
8
8
|
import { WaterSurface3D } from "@threenative/core";
|
|
9
|
-
import type
|
|
9
|
+
import { type Heightfield, riverRibbonGeometry } from "@threenative/core/world";
|
|
10
10
|
import type { IPhysicsContext } from "@threenative/physics";
|
|
11
11
|
import {
|
|
12
12
|
BufferAttribute,
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
MeshStandardMaterial,
|
|
19
19
|
} from "three";
|
|
20
20
|
import {
|
|
21
|
+
attribute,
|
|
21
22
|
cameraPosition,
|
|
22
23
|
clamp,
|
|
23
24
|
dot,
|
|
@@ -61,19 +62,17 @@ export const SKY_REFLECTION_LAYER = 3;
|
|
|
61
62
|
/** The ribbon sits this far above its profile, clear of the carved bed. */
|
|
62
63
|
const RIVER_LIFT = 0.05;
|
|
63
64
|
/** Metres of water over the bed at which the lake is fully opaque; thinner water fades into the shore. */
|
|
64
|
-
const SHORE_DEPTH =
|
|
65
|
+
const SHORE_DEPTH = 1.8;
|
|
65
66
|
/**
|
|
66
67
|
* The colour the mirrored sky takes at grazing angles, in linear light. The sky's horizon is near-neutral,
|
|
67
|
-
* so the tint carries the lake's
|
|
68
|
+
* so the tint carries the lake's teal; the mirror keeps the sky's gradient.
|
|
68
69
|
*/
|
|
69
|
-
const SHEEN = new Color(
|
|
70
|
+
const SHEEN = new Color(0x94b9bf);
|
|
70
71
|
/** Deep water's own colour; the bed shows through where the lake is shallow. */
|
|
71
|
-
const BODY = new Color(
|
|
72
|
+
const BODY = new Color(0x285b59);
|
|
72
73
|
const RIVER = new Color(0x2a4b4c);
|
|
73
|
-
/**
|
|
74
|
-
const
|
|
75
|
-
/** Water thinner than this many metres takes the SHORE colour, fading in as it thins. */
|
|
76
|
-
const SHORE_BAND = 2;
|
|
74
|
+
/** Shallow water stays teal, gently darkening with the measured depth of the bed. */
|
|
75
|
+
const SHALLOW = new Color(0x3c746e);
|
|
77
76
|
|
|
78
77
|
/** The heightfield's sample grid in world metres: one node per column and row, the first at (x0, z0). */
|
|
79
78
|
function gridOf(field: Heightfield): { stepX: number; stepZ: number; x0: number; z0: number } {
|
|
@@ -133,16 +132,16 @@ function lakeGeometry(field: Heightfield, lake: ILake, flooded: Uint8Array): Buf
|
|
|
133
132
|
const { stepX, stepZ, x0, z0 } = gridOf(field);
|
|
134
133
|
const positions: number[] = [];
|
|
135
134
|
const indices: number[] = [];
|
|
135
|
+
const depths: number[] = [];
|
|
136
136
|
const vertexOf = new Map<number, number>();
|
|
137
137
|
const vertex = (node: number): number => {
|
|
138
138
|
const known = vertexOf.get(node);
|
|
139
139
|
if (known !== undefined) return known;
|
|
140
140
|
const index = positions.length / 3;
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
);
|
|
141
|
+
const x = x0 + (node % columns) * stepX;
|
|
142
|
+
const z = z0 + Math.floor(node / columns) * stepZ;
|
|
143
|
+
positions.push(x, lake.level, z);
|
|
144
|
+
depths.push(lake.level - field.heightAt(x, z));
|
|
146
145
|
vertexOf.set(node, index);
|
|
147
146
|
return index;
|
|
148
147
|
};
|
|
@@ -161,14 +160,15 @@ function lakeGeometry(field: Heightfield, lake: ILake, flooded: Uint8Array): Buf
|
|
|
161
160
|
}
|
|
162
161
|
const geometry = new BufferGeometry();
|
|
163
162
|
geometry.setAttribute("position", new BufferAttribute(new Float32Array(positions), 3));
|
|
163
|
+
geometry.setAttribute("waterDepth", new BufferAttribute(new Float32Array(depths), 1));
|
|
164
164
|
geometry.setIndex(indices);
|
|
165
165
|
return geometry;
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
/**
|
|
169
169
|
* The lake's surface: the sky mirrored in it at grazing angles, the bed seen through it where it is
|
|
170
|
-
* shallow, and the body's own colour where it is deep. Schlick at water's 1.333 index
|
|
171
|
-
*
|
|
170
|
+
* shallow, and the body's own colour where it is deep. Capped Schlick at water's 1.333 index keeps
|
|
171
|
+
* the far bank's reflection subdued. Where the water is thinner than SHORE_DEPTH it fades
|
|
172
172
|
* to nothing, because the ground has risen through the level there.
|
|
173
173
|
*/
|
|
174
174
|
function lakeMaterial(surface: WaterSurface3D): MeshBasicNodeMaterial {
|
|
@@ -176,45 +176,29 @@ function lakeMaterial(surface: WaterSurface3D): MeshBasicNodeMaterial {
|
|
|
176
176
|
const facing = clamp(dot(vec3(0, 1, 0), view), float(0), float(1));
|
|
177
177
|
const fresnel = float(0.02).add(pow(float(1).sub(facing), 5).mul(0.98));
|
|
178
178
|
const thickness = surface.thicknessAt();
|
|
179
|
-
|
|
179
|
+
// Bed depth shades the shore consistently; screen depth still preserves the bed and its shadows.
|
|
180
|
+
const bedDepth = attribute<"float">("waterDepth", "float");
|
|
181
|
+
const body = mix(
|
|
182
|
+
vec3(SHALLOW.r, SHALLOW.g, SHALLOW.b),
|
|
183
|
+
vec3(BODY.r, BODY.g, BODY.b),
|
|
184
|
+
smoothstep(float(0), float(3), bedDepth),
|
|
185
|
+
);
|
|
180
186
|
const submerged = mix(surface.refractionAt(), body, smoothstep(float(0.4), float(3), thickness));
|
|
181
187
|
const material = new MeshBasicNodeMaterial({ transparent: true, side: DoubleSide });
|
|
182
188
|
// The HDR mirror is compressed, then tinted: its horizon is neutral, the water should not be.
|
|
183
189
|
const mirror = surface.reflectionAt();
|
|
184
190
|
const compressed = mirror.div(mirror.add(vec3(1, 1, 1)));
|
|
185
|
-
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
191
|
+
// A small sky floor reveals the mirror; the cap keeps grazing water from becoming an ice sheet.
|
|
192
|
+
const reflection = clamp(float(0.16).add(fresnel.mul(0.3)), float(0), float(0.46));
|
|
193
|
+
const open = mix(submerged, compressed.mul(vec3(SHEEN.r, SHEEN.g, SHEEN.b)), reflection);
|
|
194
|
+
// Cap linear radiance before the scene tone curve, including the glancing shoreline.
|
|
195
|
+
material.colorNode = clamp(open, vec3(0, 0, 0), vec3(0.22, 0.22, 0.22));
|
|
196
|
+
material.opacityNode = smoothstep(float(0), float(SHORE_DEPTH), bedDepth).mul(
|
|
197
|
+
smoothstep(float(0), float(0.3), thickness),
|
|
198
|
+
);
|
|
189
199
|
return material;
|
|
190
200
|
}
|
|
191
201
|
|
|
192
|
-
/** A ribbon along the river's profile: each point's left and right edge across the course. */
|
|
193
|
-
function riverGeometry(river: IRiver): BufferGeometry {
|
|
194
|
-
const half = river.width / 2;
|
|
195
|
-
const positions: number[] = [];
|
|
196
|
-
const indices: number[] = [];
|
|
197
|
-
river.points.forEach(([x, y, z], i) => {
|
|
198
|
-
const before = river.points[Math.max(0, i - 1)] ?? [x, y, z];
|
|
199
|
-
const after = river.points[Math.min(river.points.length - 1, i + 1)] ?? [x, y, z];
|
|
200
|
-
const tx = after[0] - before[0];
|
|
201
|
-
const tz = after[2] - before[2];
|
|
202
|
-
const length = Math.hypot(tx, tz) || 1;
|
|
203
|
-
const sx = (-tz / length) * half;
|
|
204
|
-
const sz = (tx / length) * half;
|
|
205
|
-
positions.push(x + sx, y + RIVER_LIFT, z + sz, x - sx, y + RIVER_LIFT, z - sz);
|
|
206
|
-
if (i > 0) {
|
|
207
|
-
const a = 2 * (i - 1);
|
|
208
|
-
const b = 2 * i;
|
|
209
|
-
indices.push(a, b, a + 1, b, b + 1, a + 1);
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
const geometry = new BufferGeometry();
|
|
213
|
-
geometry.setAttribute("position", new BufferAttribute(new Float32Array(positions), 3));
|
|
214
|
-
geometry.setIndex(indices);
|
|
215
|
-
return geometry;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
202
|
/**
|
|
219
203
|
* Adds the lake and river the bake wrote. `field` is the ground the props and the colliders stand on.
|
|
220
204
|
* The caller owns the returned handle: its `dispose` removes both meshes and releases each surface.
|
|
@@ -248,7 +232,14 @@ export function addForestWater(
|
|
|
248
232
|
opacity: 0.9,
|
|
249
233
|
side: DoubleSide,
|
|
250
234
|
});
|
|
251
|
-
|
|
235
|
+
// One channel width across, out a half width past each end where the bed is carved; dry
|
|
236
|
+
// quads drop, so the water ends at the bank (core `riverRibbonGeometry`).
|
|
237
|
+
const mesh = new Mesh(
|
|
238
|
+
riverRibbonGeometry([river], field, { reach: 0.5, columns: 3 }),
|
|
239
|
+
material,
|
|
240
|
+
);
|
|
241
|
+
mesh.position.y = RIVER_LIFT;
|
|
242
|
+
meshes.push(mesh);
|
|
252
243
|
}
|
|
253
244
|
for (const mesh of meshes) ctx.add(mesh);
|
|
254
245
|
return {
|
package/starter/forest/world.ts
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
//
|
|
3
|
-
// `bake.mjs` wrote a world package (heightmap, splat masks, placements, CC0 models) into `world/`;
|
|
4
|
-
// the engine's `WorldCells` streams it, `loadTerrainSplat` textures its ground, and everything
|
|
5
|
-
// that decides how the world looks or what stops the player is in this folder for the game to edit.
|
|
6
|
-
import type { IComputeDriven, ICtx } from "@threenative/core";
|
|
1
|
+
import type { ICtx } from "@threenative/core";
|
|
7
2
|
import {
|
|
8
|
-
|
|
3
|
+
type ILoadTerrainSplatOptions,
|
|
4
|
+
type ITerrainSplatMaterialContext,
|
|
9
5
|
type IWorldPackage,
|
|
10
|
-
WorldCells,
|
|
11
|
-
heightSamplerFromHeightmap,
|
|
12
6
|
loadTerrainSplat,
|
|
13
|
-
loadWorldHeightmap,
|
|
14
7
|
} from "@threenative/core/world";
|
|
15
|
-
import {
|
|
8
|
+
import type { IPhysicsContext } from "@threenative/physics";
|
|
9
|
+
import {
|
|
10
|
+
type IStarterWorld,
|
|
11
|
+
type IStarterWorldSpec,
|
|
12
|
+
PropColliders as StarterPropColliders,
|
|
13
|
+
addStarterWorld,
|
|
14
|
+
} from "@threenative/terrain/starter";
|
|
16
15
|
import {
|
|
17
16
|
type Box3,
|
|
18
17
|
type BufferGeometry,
|
|
19
18
|
Color,
|
|
20
19
|
EquirectangularReflectionMapping,
|
|
21
|
-
type Material,
|
|
22
20
|
type Mesh,
|
|
23
21
|
type MeshStandardMaterial,
|
|
24
|
-
Object3D,
|
|
22
|
+
type Object3D,
|
|
25
23
|
type Texture,
|
|
26
24
|
Vector3,
|
|
27
25
|
} from "three";
|
|
28
|
-
import {
|
|
26
|
+
import { cameraViewMatrix, normalWorld, vec3, vec4 } from "three/tsl";
|
|
27
|
+
import { MeshPhysicalNodeMaterial } from "three/webgpu";
|
|
28
|
+
import surface from "./surface.json" with { type: "json" };
|
|
29
29
|
import { type IForestWater, type IForestWaterFile, addForestWater } from "./water.js";
|
|
30
|
-
|
|
31
30
|
/** Where the game's asset source holds the baked `world/` folder. */
|
|
32
31
|
export const FOREST_URL = "terrain/forest/world.json";
|
|
33
32
|
|
|
@@ -51,175 +50,95 @@ export const PROP_SKY_LIGHT = 0.65;
|
|
|
51
50
|
/** Multiplies every boulder's albedo: the CC0 scan photographed pink-orange, the forest's stone is cool grey. */
|
|
52
51
|
export const BOULDER_TINT = new Color(0.6, 0.74, 0.86);
|
|
53
52
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
/**
|
|
54
|
+
* The ground's dielectric specular, 0 to 1 (three's `specularIntensity`). The default 1 lays a pale
|
|
55
|
+
* sheen over soil and grass wherever the sun is low or ahead of the camera, so sunlit ground reads
|
|
56
|
+
* lighter than its albedo and the shaded floor loses its contrast. 0 leaves the photographed albedo.
|
|
57
|
+
*/
|
|
58
|
+
export const GROUND_SPECULAR = 0;
|
|
59
|
+
|
|
60
|
+
/** The splat's own shading in a physical material, which is what carries `specularIntensity`. */
|
|
61
|
+
function groundMaterial({
|
|
62
|
+
color,
|
|
63
|
+
normal,
|
|
64
|
+
orm,
|
|
65
|
+
}: ITerrainSplatMaterialContext): MeshPhysicalNodeMaterial {
|
|
66
|
+
const material = new MeshPhysicalNodeMaterial();
|
|
67
|
+
material.name = "terrain-splat";
|
|
68
|
+
material.colorNode = color;
|
|
69
|
+
// A top-down tangent frame, as the engine's own splat material builds it.
|
|
70
|
+
const n = normalWorld;
|
|
71
|
+
const tangent = vec3(1, 0, 0).sub(n.mul(n.x)).normalize();
|
|
72
|
+
const bitangent = n.cross(tangent).normalize();
|
|
73
|
+
const t = normal.mul(2).sub(1);
|
|
74
|
+
const perturbed = tangent.mul(t.x).add(bitangent.mul(t.y)).add(n.mul(t.z)).normalize();
|
|
75
|
+
material.normalNode = cameraViewMatrix.mul(vec4(perturbed, 0)).xyz.normalize();
|
|
76
|
+
material.aoNode = orm.r;
|
|
77
|
+
material.roughnessNode = orm.g;
|
|
78
|
+
material.metalnessNode = orm.b;
|
|
79
|
+
material.specularIntensity = GROUND_SPECULAR;
|
|
80
|
+
return material;
|
|
62
81
|
}
|
|
63
82
|
|
|
64
83
|
/** Metres around `follow` within which props collide; beyond it they only draw. */
|
|
65
84
|
export const PROP_COLLIDER_REACH = 60;
|
|
66
85
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
86
|
+
export interface IForestWorld extends IStarterWorld {
|
|
87
|
+
readonly water: IForestWater;
|
|
88
|
+
}
|
|
89
|
+
const spec: IStarterWorldSpec<IForestWater> = {
|
|
90
|
+
name: "Forest",
|
|
91
|
+
url: FOREST_URL,
|
|
92
|
+
colliders: COLLIDERS,
|
|
93
|
+
colliderReach: PROP_COLLIDER_REACH,
|
|
94
|
+
loadSurface: (ctx, url) =>
|
|
95
|
+
loadTerrainSplat({
|
|
96
|
+
assets: ctx.assets,
|
|
97
|
+
url,
|
|
98
|
+
table: surface as unknown as ILoadTerrainSplatOptions["table"],
|
|
99
|
+
materialFactory: groundMaterial,
|
|
100
|
+
}),
|
|
101
|
+
lighting: { sky: "sky.hdr", lods: true, dress: dressProp },
|
|
102
|
+
streaming: {
|
|
103
|
+
ring: 5,
|
|
104
|
+
impostors: true,
|
|
105
|
+
gpuScene: false,
|
|
106
|
+
// Every LOD casts: with only LOD0 (the default), each tree past 45 m dropped its shadow on the first refilter.
|
|
107
|
+
shadows: { cast: true, castLevels: 4, receive: true },
|
|
108
|
+
budgets: { residentCells: 64, instances: 40_000, bytes: 64_000_000 },
|
|
109
|
+
terrain: { streamRadius: 6 },
|
|
110
|
+
},
|
|
111
|
+
water: (ctx, file, field) => addForestWater(ctx, file as IForestWaterFile, field),
|
|
112
|
+
};
|
|
113
|
+
export class PropColliders extends StarterPropColliders {
|
|
114
|
+
constructor(
|
|
115
|
+
ctx: ICtx<Record<string, unknown>, IPhysicsContext>,
|
|
116
|
+
follow: Object3D,
|
|
117
|
+
manifest: IWorldPackage,
|
|
118
|
+
records: Float32Array,
|
|
119
|
+
) {
|
|
120
|
+
super(ctx, follow, manifest, records, COLLIDERS, PROP_COLLIDER_REACH, "Forest");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
72
123
|
export async function addForest(
|
|
73
124
|
ctx: ICtx<Record<string, unknown>, IPhysicsContext>,
|
|
74
125
|
follow: Object3D,
|
|
75
126
|
url = FOREST_URL,
|
|
76
127
|
whileCurrent: () => boolean = () => true,
|
|
77
128
|
): Promise<IForestWorld> {
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
error.name = "AbortError";
|
|
82
|
-
throw error;
|
|
83
|
-
};
|
|
84
|
-
let surface: Material | undefined;
|
|
85
|
-
let releaseLighting: (() => void) | undefined;
|
|
86
|
-
let world: WorldCells | undefined;
|
|
87
|
-
let ground: RigidBody3D | undefined;
|
|
88
|
-
let colliders: PropColliders | undefined;
|
|
89
|
-
let water: IForestWater | undefined;
|
|
90
|
-
let released = false;
|
|
91
|
-
const dispose = () => {
|
|
92
|
-
if (released) return;
|
|
93
|
-
released = true;
|
|
94
|
-
colliders?.detach();
|
|
95
|
-
colliders?.removeFromParent();
|
|
96
|
-
water?.dispose();
|
|
97
|
-
ground?.dispose();
|
|
98
|
-
ground?.object?.removeFromParent();
|
|
99
|
-
world?.dispose();
|
|
100
|
-
surface?.dispose();
|
|
101
|
-
releaseLighting?.();
|
|
102
|
-
};
|
|
103
|
-
try {
|
|
104
|
-
assertCurrent();
|
|
105
|
-
const manifest = (await (await fetchAsset(ctx, url, assertCurrent)).json()) as IWorldPackage;
|
|
106
|
-
assertCurrent();
|
|
107
|
-
const base = url.slice(0, url.lastIndexOf("/") + 1);
|
|
108
|
-
const records = await (
|
|
109
|
-
await fetchAsset(ctx, base + manifest.placements, assertCurrent)
|
|
110
|
-
).arrayBuffer();
|
|
111
|
-
assertCurrent();
|
|
112
|
-
const [heightmapUrl] = await ctx.assets.resolve(base + manifest.terrain.heightmap);
|
|
113
|
-
assertCurrent();
|
|
114
|
-
if (heightmapUrl === undefined) throw new Error("Forest world: its heightmap is not served.");
|
|
115
|
-
const heightmap = await loadWorldHeightmap(heightmapUrl);
|
|
116
|
-
assertCurrent();
|
|
117
|
-
surface = await loadTerrainSplat({ assets: ctx.assets, url });
|
|
118
|
-
assertCurrent();
|
|
119
|
-
releaseLighting = await lightProps(ctx, url, manifest, assertCurrent);
|
|
120
|
-
assertCurrent();
|
|
121
|
-
world = await WorldCells.load({
|
|
122
|
-
url,
|
|
123
|
-
assets: ctx.assets,
|
|
124
|
-
data: { manifest, placements: records, heightmap },
|
|
125
|
-
surface,
|
|
126
|
-
follow,
|
|
127
|
-
ring: 5,
|
|
128
|
-
// Far firs draw as engine-baked impostors; the authored model stays the shadow caster.
|
|
129
|
-
impostors: true,
|
|
130
|
-
// The GPU-culled path drops the near firs from the main pass while their shadows still draw
|
|
131
|
-
// (measured in a fresh game, 2026-10-05); the CPU path draws them. Engine finding, PRD-466.
|
|
132
|
-
gpuScene: false,
|
|
133
|
-
// Trees and rocks shade the ground and each other; impostors keep the authored model as the caster.
|
|
134
|
-
shadows: { cast: true, receive: true },
|
|
135
|
-
budgets: { residentCells: 64, instances: 40_000, bytes: 64_000_000 },
|
|
136
|
-
terrain: { streamRadius: 6 },
|
|
137
|
-
});
|
|
138
|
-
assertCurrent();
|
|
139
|
-
const field = forestField(manifest, heightmap);
|
|
140
|
-
ground = groundCollider(ctx, manifest, field);
|
|
141
|
-
const waterFile = (await (
|
|
142
|
-
await fetchAsset(ctx, `${base}water.json`, assertCurrent)
|
|
143
|
-
).json()) as IForestWaterFile;
|
|
144
|
-
assertCurrent();
|
|
145
|
-
const forestWater = addForestWater(ctx, waterFile, field);
|
|
146
|
-
water = forestWater;
|
|
147
|
-
colliders = new PropColliders(ctx, follow, manifest, new Float32Array(records));
|
|
148
|
-
ctx.add(world);
|
|
149
|
-
if (ground.object !== undefined) ctx.add(ground.object);
|
|
150
|
-
ctx.add(colliders);
|
|
151
|
-
ctx.entities.add(`forest-world.${world.uuid}`, { dispose });
|
|
152
|
-
return { world, ground, colliders, water: forestWater };
|
|
153
|
-
} catch (error) {
|
|
154
|
-
dispose();
|
|
155
|
-
throw error;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Cutout foliage with no environment draws flat and dark (the engine says TN_UNLIT_FOLIAGE): give
|
|
160
|
-
// every prop the sky as its own envMap before WorldCells adopts the shared cached models. Foliage
|
|
161
|
-
// cards also get normals bent out from the crown's axis, so a crown shades as one soft volume
|
|
162
|
-
// instead of a stack of flat cards, and lose the glossy specular glTF exporters give them.
|
|
163
|
-
async function lightProps(
|
|
164
|
-
ctx: ICtx<Record<string, unknown>, IPhysicsContext>,
|
|
165
|
-
url: string,
|
|
166
|
-
manifest: IWorldPackage,
|
|
167
|
-
assertCurrent: () => void,
|
|
168
|
-
): Promise<() => void> {
|
|
169
|
-
const base = url.slice(0, url.lastIndexOf("/") + 1);
|
|
170
|
-
const [skyUrl] = await ctx.assets.resolve(`${base}sky.hdr`);
|
|
171
|
-
assertCurrent();
|
|
172
|
-
if (skyUrl === undefined) throw new Error("Forest world: 'sky.hdr' is not served.");
|
|
173
|
-
const sky = await new HDRLoader().loadAsync(skyUrl);
|
|
174
|
-
const originals = new Map<
|
|
175
|
-
MeshStandardMaterial,
|
|
176
|
-
{ color: Color; envMap: Texture | null; intensity: number }
|
|
177
|
-
>();
|
|
178
|
-
const dispose = () => {
|
|
179
|
-
for (const [material, original] of originals) {
|
|
180
|
-
if (material.envMap !== sky) continue;
|
|
181
|
-
material.envMap = original.envMap;
|
|
182
|
-
material.envMapIntensity = original.intensity;
|
|
183
|
-
material.color.copy(original.color);
|
|
184
|
-
}
|
|
185
|
-
sky.dispose();
|
|
186
|
-
};
|
|
187
|
-
try {
|
|
188
|
-
assertCurrent();
|
|
189
|
-
sky.mapping = EquirectangularReflectionMapping;
|
|
190
|
-
// Every LOD of an asset, not only its nearest: a far boulder left undressed shows its raw scan.
|
|
191
|
-
const models = Object.entries(manifest.assets).flatMap(([id, asset]) =>
|
|
192
|
-
[asset.glb, ...(asset.lods ?? []).map((lod) => lod.glb)].map((glb) => ({ id, glb })),
|
|
193
|
-
);
|
|
194
|
-
for (const { id, glb } of models) {
|
|
195
|
-
const model = await ctx.assets.model<{ scene: Object3D }>(base + glb);
|
|
196
|
-
assertCurrent();
|
|
197
|
-
model.scene.traverse((object) => {
|
|
198
|
-
const mesh = object as Mesh;
|
|
199
|
-
for (const material of [mesh.material ?? []].flat() as MeshStandardMaterial[])
|
|
200
|
-
if (!originals.has(material))
|
|
201
|
-
originals.set(material, {
|
|
202
|
-
color: material.color.clone(),
|
|
203
|
-
envMap: material.envMap,
|
|
204
|
-
intensity: material.envMapIntensity,
|
|
205
|
-
});
|
|
206
|
-
dressProp(mesh, sky, id.startsWith("boulder") ? BOULDER_TINT : undefined, originals);
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
return dispose;
|
|
210
|
-
} catch (error) {
|
|
211
|
-
dispose();
|
|
212
|
-
throw error;
|
|
213
|
-
}
|
|
129
|
+
const result = await addStarterWorld(ctx, follow, spec, url, whileCurrent);
|
|
130
|
+
if (!result.extra) throw new Error("Forest world: missing water.");
|
|
131
|
+
return { ...result, water: result.extra };
|
|
214
132
|
}
|
|
215
|
-
|
|
216
133
|
/** One prop mesh: the sky as its envMap, and matte, crown-shaded foliage. */
|
|
217
134
|
function dressProp(
|
|
218
135
|
mesh: Mesh,
|
|
219
136
|
sky: Texture,
|
|
220
|
-
|
|
137
|
+
id: string,
|
|
221
138
|
originals: ReadonlyMap<MeshStandardMaterial, { color: Color }>,
|
|
222
139
|
): void {
|
|
140
|
+
sky.mapping = EquirectangularReflectionMapping;
|
|
141
|
+
const tint = id.startsWith("boulder") ? BOULDER_TINT : undefined;
|
|
223
142
|
const surfaces = [mesh.material ?? []].flat() as MeshStandardMaterial[];
|
|
224
143
|
const foliage = surfaces.some((material) => material.alphaTest > 0);
|
|
225
144
|
for (const material of surfaces) {
|
|
@@ -236,14 +155,19 @@ function dressProp(
|
|
|
236
155
|
}
|
|
237
156
|
|
|
238
157
|
/** How strongly the sky lights foliage, which the sun alone leaves near-black from most sides. */
|
|
239
|
-
export const FOLIAGE_SKY_LIGHT =
|
|
158
|
+
export const FOLIAGE_SKY_LIGHT = 1;
|
|
240
159
|
/** 0 keeps each card's own normal, 1 points every normal straight out from the crown's axis. */
|
|
241
160
|
export const CROWN_NORMAL_BEND = 0.7;
|
|
242
161
|
|
|
243
|
-
function bendCrownNormals(geometry: BufferGeometry, bend: number): void {
|
|
162
|
+
export function bendCrownNormals(geometry: BufferGeometry, bend: number): void {
|
|
244
163
|
const position = geometry.getAttribute("position");
|
|
245
164
|
const normal = geometry.getAttribute("normal");
|
|
246
165
|
if (position === undefined || normal === undefined) return;
|
|
166
|
+
// One cached model hands the same geometry to every visit; a second bend would lerp the bent
|
|
167
|
+
// normals again and the shading would drift. The original normals are gone after the first pass,
|
|
168
|
+
// so the geometry records the bend it already took.
|
|
169
|
+
if (geometry.userData.crownBend !== undefined) return;
|
|
170
|
+
geometry.userData.crownBend = bend;
|
|
247
171
|
geometry.computeBoundingBox();
|
|
248
172
|
const box = geometry.boundingBox as Box3;
|
|
249
173
|
const midY = (box.min.y + box.max.y) / 2;
|
|
@@ -256,158 +180,3 @@ function bendCrownNormals(geometry: BufferGeometry, bend: number): void {
|
|
|
256
180
|
}
|
|
257
181
|
normal.needsUpdate = true;
|
|
258
182
|
}
|
|
259
|
-
|
|
260
|
-
// The streamed terrain tiles arrive over several frames; a player spawned before its tile would fall
|
|
261
|
-
// through. One heightfield for the whole package (a few hundred kilobytes of samples) avoids that.
|
|
262
|
-
/** The kit's one heightfield: the collider stands on it and the water's shore reads it. */
|
|
263
|
-
function forestField(manifest: IWorldPackage, heightmap: Uint16Array): Heightfield {
|
|
264
|
-
const { extent, terrain } = manifest;
|
|
265
|
-
return Heightfield.fromSampler({
|
|
266
|
-
columns: terrain.columns,
|
|
267
|
-
rows: terrain.rows,
|
|
268
|
-
width: extent.sizeX,
|
|
269
|
-
depth: extent.sizeZ,
|
|
270
|
-
origin: { x: extent.minX + extent.sizeX / 2, z: extent.minZ + extent.sizeZ / 2 },
|
|
271
|
-
sampleHeight: heightSamplerFromHeightmap(terrain, extent, heightmap),
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
function groundCollider(
|
|
276
|
-
ctx: ICtx<Record<string, unknown>, IPhysicsContext>,
|
|
277
|
-
manifest: IWorldPackage,
|
|
278
|
-
field: Heightfield,
|
|
279
|
-
): RigidBody3D {
|
|
280
|
-
const { extent } = manifest;
|
|
281
|
-
const anchor = new Object3D();
|
|
282
|
-
anchor.position.set(extent.minX + extent.sizeX / 2, 0, extent.minZ + extent.sizeZ / 2);
|
|
283
|
-
return new RigidBody3D({
|
|
284
|
-
object: anchor,
|
|
285
|
-
physics: ctx.physics,
|
|
286
|
-
type: "fixed",
|
|
287
|
-
entity: "terrain",
|
|
288
|
-
shape: CollisionShape3D.heightfield(field.rows, field.columns, field.toColliderHeights(), {
|
|
289
|
-
x: extent.sizeX,
|
|
290
|
-
y: 1,
|
|
291
|
-
z: extent.sizeZ,
|
|
292
|
-
}),
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Fixed bodies for the props within `PROP_COLLIDER_REACH` of `follow`, rebuilt when it has moved a
|
|
298
|
-
* few metres. Thousands of resident bodies cost Rapier ~0.5 s per 8 s (measured); a hundred do not.
|
|
299
|
-
*/
|
|
300
|
-
export class PropColliders extends Object3D implements IComputeDriven {
|
|
301
|
-
readonly warmupNodes: readonly unknown[] = [];
|
|
302
|
-
readonly processCadence = "render" as const;
|
|
303
|
-
readonly #live = new Map<number, RigidBody3D>();
|
|
304
|
-
readonly #runs: { asset: string; offset: number; count: number }[] = [];
|
|
305
|
-
readonly #at = { x: Number.NaN, z: Number.NaN };
|
|
306
|
-
readonly #followPosition = new Vector3();
|
|
307
|
-
#released = false;
|
|
308
|
-
|
|
309
|
-
constructor(
|
|
310
|
-
private readonly ctx: ICtx<Record<string, unknown>, IPhysicsContext>,
|
|
311
|
-
private readonly follow: Object3D,
|
|
312
|
-
manifest: IWorldPackage,
|
|
313
|
-
private readonly records: Float32Array,
|
|
314
|
-
) {
|
|
315
|
-
super();
|
|
316
|
-
this.name = "forest-prop-colliders";
|
|
317
|
-
for (const cell of manifest.cells)
|
|
318
|
-
for (const run of cell.runs) if (COLLIDERS[run.asset]) this.#runs.push(run);
|
|
319
|
-
try {
|
|
320
|
-
this.#rebuild();
|
|
321
|
-
} catch (error) {
|
|
322
|
-
this.detach();
|
|
323
|
-
throw error;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/** How many prop bodies exist right now. */
|
|
328
|
-
get active(): number {
|
|
329
|
-
return this.#live.size;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
get released(): boolean {
|
|
333
|
-
return this.#released;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
attachRenderer(): void {}
|
|
337
|
-
|
|
338
|
-
process(): void {
|
|
339
|
-
if (this.#released) return;
|
|
340
|
-
const p = this.follow.getWorldPosition(this.#followPosition);
|
|
341
|
-
if (Math.hypot(p.x - this.#at.x, p.z - this.#at.z) > 4 || Number.isNaN(this.#at.x))
|
|
342
|
-
this.#rebuild();
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
detach(): void {
|
|
346
|
-
for (const body of this.#live.values()) body.dispose();
|
|
347
|
-
this.#live.clear();
|
|
348
|
-
this.#released = true;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
#rebuild(): void {
|
|
352
|
-
const { x: fx, z: fz } = this.follow.getWorldPosition(this.#followPosition);
|
|
353
|
-
this.#at.x = fx;
|
|
354
|
-
this.#at.z = fz;
|
|
355
|
-
const keep = new Set<number>();
|
|
356
|
-
for (const run of this.#runs) {
|
|
357
|
-
const shape = COLLIDERS[run.asset];
|
|
358
|
-
if (!shape) continue;
|
|
359
|
-
for (let i = run.offset; i < run.offset + run.count; i++) {
|
|
360
|
-
const x = this.records[i * 8] as number;
|
|
361
|
-
const z = this.records[i * 8 + 2] as number;
|
|
362
|
-
if (Math.hypot(x - fx, z - fz) > PROP_COLLIDER_REACH) continue;
|
|
363
|
-
keep.add(i);
|
|
364
|
-
if (this.#live.has(i)) continue;
|
|
365
|
-
const { lift, collider } = colliderAt(shape, this.records[i * 8 + 7] as number);
|
|
366
|
-
this.#live.set(
|
|
367
|
-
i,
|
|
368
|
-
new RigidBody3D({
|
|
369
|
-
physics: this.ctx.physics,
|
|
370
|
-
type: "fixed",
|
|
371
|
-
entity: `${run.asset}.${String(i)}`,
|
|
372
|
-
position: { x, y: (this.records[i * 8 + 1] as number) + lift, z },
|
|
373
|
-
shape: collider,
|
|
374
|
-
}),
|
|
375
|
-
);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
for (const [i, body] of this.#live)
|
|
379
|
-
if (!keep.has(i)) {
|
|
380
|
-
body.dispose();
|
|
381
|
-
this.#live.delete(i);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
/** One table row at one placement's scale; a capsule stands on the origin, a sphere sits on it. */
|
|
387
|
-
function colliderAt(
|
|
388
|
-
shape: NonNullable<(typeof COLLIDERS)[string]>,
|
|
389
|
-
scale: number,
|
|
390
|
-
): { lift: number; collider: CollisionShape3D } {
|
|
391
|
-
if ("sphere" in shape)
|
|
392
|
-
return { lift: 0, collider: CollisionShape3D.sphere(shape.sphere * scale) };
|
|
393
|
-
const [halfHeight, radius] = shape.capsule;
|
|
394
|
-
return {
|
|
395
|
-
lift: (halfHeight + radius) * scale,
|
|
396
|
-
collider: CollisionShape3D.capsule(halfHeight * scale, radius * scale),
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
async function fetchAsset(
|
|
401
|
-
ctx: ICtx<Record<string, unknown>, IPhysicsContext>,
|
|
402
|
-
path: string,
|
|
403
|
-
assertCurrent: () => void,
|
|
404
|
-
): Promise<Response> {
|
|
405
|
-
const candidates = await ctx.assets.resolve(path);
|
|
406
|
-
assertCurrent();
|
|
407
|
-
for (const candidate of candidates) {
|
|
408
|
-
const response = await fetch(candidate);
|
|
409
|
-
assertCurrent();
|
|
410
|
-
if (response.ok) return response;
|
|
411
|
-
}
|
|
412
|
-
throw new Error(`Forest world: '${path}' is not served.`);
|
|
413
|
-
}
|