@threenative/terrain 0.1.7 → 0.1.8
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 +160 -5
- package/dist/editor/index.js +3783 -1406
- package/dist/editor/server.d.ts +2 -2
- package/dist/editor/server.js +555 -121
- package/dist/editor/worker.d.ts +33 -1
- package/dist/editor/worker.js +444 -110
- package/dist/export.d.ts +11 -9
- package/dist/export.js +22 -34
- package/dist/index.d.ts +727 -73
- package/dist/index.js +2434 -553
- package/dist/kit.d.ts +56 -0
- package/dist/kit.js +2524 -0
- package/dist/mcp/cook-child.d.ts +2 -0
- package/dist/mcp/cook-child.js +3705 -0
- package/dist/mcp/server.d.ts +7 -0
- package/dist/mcp/server.js +3279 -0
- package/dist/{server-ByM2hmYJ.d.ts → server-C8Ydr_IM.d.ts} +3 -2
- package/dist/starter.d.ts +143 -0
- package/dist/starter.js +1030 -0
- package/dist/{terrain-gPnkCU6S.d.ts → terrain-B3DkduPw.d.ts} +3 -2
- package/dist/three.d.ts +1 -1
- package/dist/{types-Ant8-Axc.d.ts → types-CPYAc9vo.d.ts} +13 -4
- package/dist/world-package-B7KGYIou.d.ts +94 -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 +114 -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 +77 -1
- package/starter/coastal/bake.mjs +4 -116
- package/starter/coastal/biome.data.json +135 -0
- package/starter/coastal/heightmap.r16 +0 -0
- package/starter/coastal/recipe.json +3 -66051
- package/starter/coastal/sea.ts +49 -16
- 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 +114 -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 +84 -4
- package/starter/forest/assets.json +32 -0
- package/starter/forest/bake.mjs +6 -116
- package/starter/forest/biome.data.json +150 -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 +30 -20
- package/starter/forest/world.ts +86 -322
- package/starter/tundra/README.md +77 -1
- package/starter/tundra/bake.mjs +4 -116
- package/starter/tundra/biome.data.json +131 -0
- package/starter/tundra/heightmap.r16 +0 -0
- package/starter/tundra/recipe.json +18 -66066
- 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/tundra/world.ts
CHANGED
|
@@ -1,31 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
//
|
|
3
|
-
// `bake.mjs` wrote a world package into `world/`: heightmap, splat masks, placements and the CC0 boulder.
|
|
4
|
-
// The engine's `WorldCells` streams it. `loadTerrainSplat` textures its ground.
|
|
5
|
-
// Everything 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
|
-
|
|
9
|
-
type IWorldCellsLoadOptions,
|
|
3
|
+
type ILoadTerrainSplatOptions,
|
|
10
4
|
type IWorldPackage,
|
|
11
|
-
WorldCells,
|
|
12
|
-
heightSamplerFromHeightmap,
|
|
13
5
|
loadTerrainSplat,
|
|
14
|
-
loadWorldHeightmap,
|
|
15
6
|
} from "@threenative/core/world";
|
|
16
|
-
import {
|
|
7
|
+
import type { IPhysicsContext } from "@threenative/physics";
|
|
8
|
+
import {
|
|
9
|
+
type IStarterWorld,
|
|
10
|
+
type IStarterWorldSpec,
|
|
11
|
+
PropColliders as StarterPropColliders,
|
|
12
|
+
addStarterWorld,
|
|
13
|
+
} from "@threenative/terrain/starter";
|
|
17
14
|
import {
|
|
18
15
|
EquirectangularReflectionMapping,
|
|
19
|
-
type Material,
|
|
20
16
|
type Mesh,
|
|
21
17
|
type MeshStandardMaterial,
|
|
22
|
-
Object3D,
|
|
18
|
+
type Object3D,
|
|
23
19
|
type Texture,
|
|
24
|
-
Vector3,
|
|
25
20
|
} from "three";
|
|
26
|
-
import
|
|
21
|
+
import surface from "./surface.json" with { type: "json" };
|
|
27
22
|
import { type ITundraWater, type ITundraWaterFile, addTundraWater } from "./water.js";
|
|
28
|
-
|
|
29
23
|
/** Where the game's asset source holds the baked `world/` folder. */
|
|
30
24
|
export const TUNDRA_URL = "terrain/tundra/world.json";
|
|
31
25
|
|
|
@@ -43,324 +37,76 @@ export const PROP_SKY_LIGHT = 0.5;
|
|
|
43
37
|
/** Metres around `follow` within which props collide. Beyond that, props only draw. */
|
|
44
38
|
export const PROP_COLLIDER_REACH = 60;
|
|
45
39
|
|
|
46
|
-
export interface
|
|
47
|
-
readonly
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
readonly colliders: PropColliders;
|
|
52
|
-
/** The heightfield the ground stands on: `heightAt(x, z)` reads the terrain under any point. */
|
|
53
|
-
readonly field: Heightfield;
|
|
54
|
-
/** Every placed prop's record, eight floats each, as the bake wrote it. */
|
|
55
|
-
readonly placements: Float32Array;
|
|
56
|
-
/** The world's extent in metres, as the bake wrote it. */
|
|
57
|
-
readonly extent: IWorldPackage["extent"];
|
|
58
|
-
/** The kettle lakes the bake wrote, as circles on the ground: the scene keeps its spawn off their shores. */
|
|
40
|
+
export interface ITundraLake {
|
|
41
|
+
readonly at: readonly [number, number];
|
|
42
|
+
readonly radius: number;
|
|
43
|
+
}
|
|
44
|
+
export interface ITundraWorld extends IStarterWorld {
|
|
59
45
|
readonly lakes: readonly ITundraLake[];
|
|
60
|
-
/** How many meltwater rivers the bake wrote. They are drawn, and counted into the playtest. */
|
|
61
46
|
readonly rivers: number;
|
|
62
|
-
/** The lakes and rivers as they were drawn. `dispose` removes their meshes. */
|
|
63
47
|
readonly water: ITundraWater;
|
|
64
48
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
49
|
+
const spec: IStarterWorldSpec<{
|
|
50
|
+
dispose(): void;
|
|
51
|
+
water: ITundraWater;
|
|
52
|
+
lakes: readonly ITundraLake[];
|
|
53
|
+
rivers: number;
|
|
54
|
+
}> = {
|
|
55
|
+
name: "Tundra",
|
|
56
|
+
url: TUNDRA_URL,
|
|
57
|
+
colliders: COLLIDERS,
|
|
58
|
+
colliderReach: PROP_COLLIDER_REACH,
|
|
59
|
+
loadSurface: (ctx, url) =>
|
|
60
|
+
loadTerrainSplat({
|
|
61
|
+
assets: ctx.assets,
|
|
62
|
+
url,
|
|
63
|
+
table: surface as unknown as ILoadTerrainSplatOptions["table"],
|
|
64
|
+
}),
|
|
65
|
+
lighting: { sky: "sky.hdr", lods: false, dress: dressProp },
|
|
66
|
+
streaming: {
|
|
67
|
+
ring: 5,
|
|
68
|
+
impostors: false,
|
|
69
|
+
gpuScene: false,
|
|
70
|
+
shadows: { cast: true, receive: true },
|
|
71
|
+
budgets: { residentCells: 64, instances: 40_000, bytes: 64_000_000 },
|
|
72
|
+
terrain: { streamRadius: 6 },
|
|
73
|
+
},
|
|
74
|
+
water: (ctx, file, field) => {
|
|
75
|
+
const data = file as ITundraWaterFile;
|
|
76
|
+
const water = addTundraWater(ctx, data, field);
|
|
77
|
+
return {
|
|
78
|
+
water,
|
|
79
|
+
lakes: data.lakes.map((lake) => ({ at: lake.at, radius: lake.radius })),
|
|
80
|
+
rivers: data.rivers.length,
|
|
81
|
+
dispose: () => water.dispose(),
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
export class PropColliders extends StarterPropColliders {
|
|
86
|
+
constructor(
|
|
87
|
+
ctx: ICtx<Record<string, unknown>, IPhysicsContext>,
|
|
88
|
+
follow: Object3D,
|
|
89
|
+
manifest: IWorldPackage,
|
|
90
|
+
records: Float32Array,
|
|
91
|
+
) {
|
|
92
|
+
super(ctx, follow, manifest, records, COLLIDERS, PROP_COLLIDER_REACH, "Tundra");
|
|
93
|
+
}
|
|
70
94
|
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Stream the tundra world around `follow` (usually the player or the camera) and give it collision.
|
|
74
|
-
* `whileCurrent` stops a departed scene's async load from attaching anything. Its resources are
|
|
75
|
-
* released on cancellation, failure and when the game's entity registry ends this scene.
|
|
76
|
-
*/
|
|
77
95
|
export async function addTundra(
|
|
78
96
|
ctx: ICtx<Record<string, unknown>, IPhysicsContext>,
|
|
79
97
|
follow: Object3D,
|
|
80
98
|
url = TUNDRA_URL,
|
|
81
99
|
whileCurrent: () => boolean = () => true,
|
|
82
100
|
): Promise<ITundraWorld> {
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
error.name = "AbortError";
|
|
87
|
-
throw error;
|
|
88
|
-
};
|
|
89
|
-
let surface: Material | undefined;
|
|
90
|
-
let releaseLighting: (() => void) | undefined;
|
|
91
|
-
let world: WorldCells | undefined;
|
|
92
|
-
let ground: RigidBody3D | undefined;
|
|
93
|
-
let colliders: PropColliders | undefined;
|
|
94
|
-
let water: ITundraWater | undefined;
|
|
95
|
-
let released = false;
|
|
96
|
-
const dispose = () => {
|
|
97
|
-
if (released) return;
|
|
98
|
-
released = true;
|
|
99
|
-
colliders?.detach();
|
|
100
|
-
colliders?.removeFromParent();
|
|
101
|
-
ground?.dispose();
|
|
102
|
-
ground?.object?.removeFromParent();
|
|
103
|
-
water?.dispose();
|
|
104
|
-
world?.dispose();
|
|
105
|
-
surface?.dispose();
|
|
106
|
-
releaseLighting?.();
|
|
107
|
-
};
|
|
108
|
-
try {
|
|
109
|
-
assertCurrent();
|
|
110
|
-
const manifest = (await (await fetchAsset(ctx, url, assertCurrent)).json()) as IWorldPackage;
|
|
111
|
-
assertCurrent();
|
|
112
|
-
const base = url.slice(0, url.lastIndexOf("/") + 1);
|
|
113
|
-
const records = await (
|
|
114
|
-
await fetchAsset(ctx, base + manifest.placements, assertCurrent)
|
|
115
|
-
).arrayBuffer();
|
|
116
|
-
assertCurrent();
|
|
117
|
-
const [heightmapUrl] = await ctx.assets.resolve(base + manifest.terrain.heightmap);
|
|
118
|
-
assertCurrent();
|
|
119
|
-
if (heightmapUrl === undefined) throw new Error("Tundra world: its heightmap is not served.");
|
|
120
|
-
const heightmap = await loadWorldHeightmap(heightmapUrl);
|
|
121
|
-
assertCurrent();
|
|
122
|
-
surface = await loadTerrainSplat({ assets: ctx.assets, url });
|
|
123
|
-
assertCurrent();
|
|
124
|
-
releaseLighting = await lightProps(ctx, url, manifest, assertCurrent);
|
|
125
|
-
assertCurrent();
|
|
126
|
-
const options: IWorldCellsLoadOptions = {
|
|
127
|
-
url,
|
|
128
|
-
assets: ctx.assets,
|
|
129
|
-
data: { manifest, placements: records, heightmap },
|
|
130
|
-
surface,
|
|
131
|
-
follow,
|
|
132
|
-
ring: 5,
|
|
133
|
-
impostors: false,
|
|
134
|
-
gpuScene: false,
|
|
135
|
-
shadows: { cast: true, receive: true },
|
|
136
|
-
budgets: { residentCells: 64, instances: 40_000, bytes: 64_000_000 },
|
|
137
|
-
terrain: { streamRadius: 6 },
|
|
138
|
-
};
|
|
139
|
-
world = await WorldCells.load(options);
|
|
140
|
-
assertCurrent();
|
|
141
|
-
const field = tundraField(manifest, heightmap);
|
|
142
|
-
ground = groundCollider(ctx, manifest, field);
|
|
143
|
-
const waterFile = (await (
|
|
144
|
-
await fetchAsset(ctx, `${base}water.json`, assertCurrent)
|
|
145
|
-
).json()) as ITundraWaterFile;
|
|
146
|
-
assertCurrent();
|
|
147
|
-
const lakeWater = addTundraWater(ctx, waterFile, field);
|
|
148
|
-
water = lakeWater;
|
|
149
|
-
const props = new Float32Array(records);
|
|
150
|
-
colliders = new PropColliders(ctx, follow, manifest, props);
|
|
151
|
-
ctx.add(world);
|
|
152
|
-
if (ground.object !== undefined) ctx.add(ground.object);
|
|
153
|
-
ctx.add(colliders);
|
|
154
|
-
ctx.entities.add(`tundra-world.${world.uuid}`, { dispose });
|
|
155
|
-
return {
|
|
156
|
-
world,
|
|
157
|
-
ground,
|
|
158
|
-
colliders,
|
|
159
|
-
field,
|
|
160
|
-
placements: props,
|
|
161
|
-
extent: manifest.extent,
|
|
162
|
-
lakes: waterFile.lakes.map((lake) => ({ at: lake.at, radius: lake.radius })),
|
|
163
|
-
rivers: waterFile.rivers.length,
|
|
164
|
-
water: lakeWater,
|
|
165
|
-
};
|
|
166
|
-
} catch (error) {
|
|
167
|
-
dispose();
|
|
168
|
-
throw error;
|
|
169
|
-
}
|
|
101
|
+
const result = await addStarterWorld(ctx, follow, spec, url, whileCurrent);
|
|
102
|
+
if (!result.extra) throw new Error("Tundra world: missing water.");
|
|
103
|
+
return { ...result, ...result.extra };
|
|
170
104
|
}
|
|
171
|
-
|
|
172
|
-
// Every prop gets the sky as its own envMap before WorldCells adopts the shared cached models.
|
|
173
|
-
// Without it, a boulder lit by the sun alone draws flat.
|
|
174
|
-
async function lightProps(
|
|
175
|
-
ctx: ICtx<Record<string, unknown>, IPhysicsContext>,
|
|
176
|
-
url: string,
|
|
177
|
-
manifest: IWorldPackage,
|
|
178
|
-
assertCurrent: () => void,
|
|
179
|
-
): Promise<() => void> {
|
|
180
|
-
const base = url.slice(0, url.lastIndexOf("/") + 1);
|
|
181
|
-
const [skyUrl] = await ctx.assets.resolve(`${base}sky.hdr`);
|
|
182
|
-
assertCurrent();
|
|
183
|
-
if (skyUrl === undefined) throw new Error("Tundra world: 'sky.hdr' is not served.");
|
|
184
|
-
const sky = await new HDRLoader().loadAsync(skyUrl);
|
|
185
|
-
const originals = new Map<MeshStandardMaterial, { envMap: Texture | null; intensity: number }>();
|
|
186
|
-
const dispose = () => {
|
|
187
|
-
for (const [material, original] of originals) {
|
|
188
|
-
if (material.envMap !== sky) continue;
|
|
189
|
-
material.envMap = original.envMap;
|
|
190
|
-
material.envMapIntensity = original.intensity;
|
|
191
|
-
}
|
|
192
|
-
sky.dispose();
|
|
193
|
-
};
|
|
194
|
-
try {
|
|
195
|
-
assertCurrent();
|
|
196
|
-
sky.mapping = EquirectangularReflectionMapping;
|
|
197
|
-
for (const asset of Object.values(manifest.assets)) {
|
|
198
|
-
const model = await ctx.assets.model<{ scene: Object3D }>(base + asset.glb);
|
|
199
|
-
assertCurrent();
|
|
200
|
-
model.scene.traverse((object) => {
|
|
201
|
-
const mesh = object as Mesh;
|
|
202
|
-
for (const material of [mesh.material ?? []].flat() as MeshStandardMaterial[])
|
|
203
|
-
if (!originals.has(material))
|
|
204
|
-
originals.set(material, {
|
|
205
|
-
envMap: material.envMap,
|
|
206
|
-
intensity: material.envMapIntensity,
|
|
207
|
-
});
|
|
208
|
-
dressProp(mesh, sky);
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
return dispose;
|
|
212
|
-
} catch (error) {
|
|
213
|
-
dispose();
|
|
214
|
-
throw error;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
105
|
/** One prop mesh: the sky as its envMap. */
|
|
219
106
|
function dressProp(mesh: Mesh, sky: Texture): void {
|
|
220
107
|
for (const material of [mesh.material ?? []].flat() as MeshStandardMaterial[]) {
|
|
108
|
+
sky.mapping = EquirectangularReflectionMapping;
|
|
221
109
|
material.envMap = sky;
|
|
222
110
|
material.envMapIntensity = PROP_SKY_LIGHT;
|
|
223
111
|
}
|
|
224
112
|
}
|
|
225
|
-
|
|
226
|
-
// The streamed terrain tiles arrive over several frames. A player spawned before its tile would
|
|
227
|
-
// fall through. One heightfield for the whole package avoids that, at a few hundred kilobytes.
|
|
228
|
-
/** The kit's one heightfield: the collider stands on it. */
|
|
229
|
-
function tundraField(manifest: IWorldPackage, heightmap: Uint16Array): Heightfield {
|
|
230
|
-
const { extent, terrain } = manifest;
|
|
231
|
-
return Heightfield.fromSampler({
|
|
232
|
-
columns: terrain.columns,
|
|
233
|
-
rows: terrain.rows,
|
|
234
|
-
width: extent.sizeX,
|
|
235
|
-
depth: extent.sizeZ,
|
|
236
|
-
origin: { x: extent.minX + extent.sizeX / 2, z: extent.minZ + extent.sizeZ / 2 },
|
|
237
|
-
sampleHeight: heightSamplerFromHeightmap(terrain, extent, heightmap),
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function groundCollider(
|
|
242
|
-
ctx: ICtx<Record<string, unknown>, IPhysicsContext>,
|
|
243
|
-
manifest: IWorldPackage,
|
|
244
|
-
field: Heightfield,
|
|
245
|
-
): RigidBody3D {
|
|
246
|
-
const { extent } = manifest;
|
|
247
|
-
const anchor = new Object3D();
|
|
248
|
-
anchor.position.set(extent.minX + extent.sizeX / 2, 0, extent.minZ + extent.sizeZ / 2);
|
|
249
|
-
return new RigidBody3D({
|
|
250
|
-
object: anchor,
|
|
251
|
-
physics: ctx.physics,
|
|
252
|
-
type: "fixed",
|
|
253
|
-
entity: "terrain",
|
|
254
|
-
shape: CollisionShape3D.heightfield(field.rows, field.columns, field.toColliderHeights(), {
|
|
255
|
-
x: extent.sizeX,
|
|
256
|
-
y: 1,
|
|
257
|
-
z: extent.sizeZ,
|
|
258
|
-
}),
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Fixed bodies for the props within `PROP_COLLIDER_REACH` of `follow`, rebuilt when it has moved a few
|
|
264
|
-
* metres. Thousands of resident bodies cost Rapier about 0.5 s per 8 s (measured). A hundred do not.
|
|
265
|
-
*/
|
|
266
|
-
export class PropColliders extends Object3D implements IComputeDriven {
|
|
267
|
-
readonly warmupNodes: readonly unknown[] = [];
|
|
268
|
-
readonly processCadence = "render" as const;
|
|
269
|
-
readonly #live = new Map<number, RigidBody3D>();
|
|
270
|
-
readonly #runs: { asset: string; offset: number; count: number }[] = [];
|
|
271
|
-
readonly #at = { x: Number.NaN, z: Number.NaN };
|
|
272
|
-
readonly #followPosition = new Vector3();
|
|
273
|
-
#released = false;
|
|
274
|
-
|
|
275
|
-
constructor(
|
|
276
|
-
private readonly ctx: ICtx<Record<string, unknown>, IPhysicsContext>,
|
|
277
|
-
private readonly follow: Object3D,
|
|
278
|
-
manifest: IWorldPackage,
|
|
279
|
-
private readonly records: Float32Array,
|
|
280
|
-
) {
|
|
281
|
-
super();
|
|
282
|
-
this.name = "tundra-prop-colliders";
|
|
283
|
-
for (const cell of manifest.cells)
|
|
284
|
-
for (const run of cell.runs) if (COLLIDERS[run.asset]) this.#runs.push(run);
|
|
285
|
-
try {
|
|
286
|
-
this.#rebuild();
|
|
287
|
-
} catch (error) {
|
|
288
|
-
this.detach();
|
|
289
|
-
throw error;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/** How many prop bodies exist right now. */
|
|
294
|
-
get active(): number {
|
|
295
|
-
return this.#live.size;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
get released(): boolean {
|
|
299
|
-
return this.#released;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
attachRenderer(): void {}
|
|
303
|
-
|
|
304
|
-
process(): void {
|
|
305
|
-
if (this.#released) return;
|
|
306
|
-
const p = this.follow.getWorldPosition(this.#followPosition);
|
|
307
|
-
if (Math.hypot(p.x - this.#at.x, p.z - this.#at.z) > 4 || Number.isNaN(this.#at.x))
|
|
308
|
-
this.#rebuild();
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
detach(): void {
|
|
312
|
-
for (const body of this.#live.values()) body.dispose();
|
|
313
|
-
this.#live.clear();
|
|
314
|
-
this.#released = true;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
#rebuild(): void {
|
|
318
|
-
const { x: fx, z: fz } = this.follow.getWorldPosition(this.#followPosition);
|
|
319
|
-
this.#at.x = fx;
|
|
320
|
-
this.#at.z = fz;
|
|
321
|
-
const keep = new Set<number>();
|
|
322
|
-
for (const run of this.#runs) {
|
|
323
|
-
const shape = COLLIDERS[run.asset];
|
|
324
|
-
if (!shape) continue;
|
|
325
|
-
for (let i = run.offset; i < run.offset + run.count; i++) {
|
|
326
|
-
const x = this.records[i * 8] as number;
|
|
327
|
-
const z = this.records[i * 8 + 2] as number;
|
|
328
|
-
if (Math.hypot(x - fx, z - fz) > PROP_COLLIDER_REACH) continue;
|
|
329
|
-
keep.add(i);
|
|
330
|
-
if (this.#live.has(i)) continue;
|
|
331
|
-
const collider = CollisionShape3D.sphere(
|
|
332
|
-
shape.sphere * (this.records[i * 8 + 7] as number),
|
|
333
|
-
);
|
|
334
|
-
this.#live.set(
|
|
335
|
-
i,
|
|
336
|
-
new RigidBody3D({
|
|
337
|
-
physics: this.ctx.physics,
|
|
338
|
-
type: "fixed",
|
|
339
|
-
entity: `${run.asset}.${String(i)}`,
|
|
340
|
-
position: { x, y: this.records[i * 8 + 1] as number, z },
|
|
341
|
-
shape: collider,
|
|
342
|
-
}),
|
|
343
|
-
);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
for (const [i, body] of this.#live)
|
|
347
|
-
if (!keep.has(i)) {
|
|
348
|
-
body.dispose();
|
|
349
|
-
this.#live.delete(i);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
async function fetchAsset(
|
|
355
|
-
ctx: ICtx<Record<string, unknown>, IPhysicsContext>,
|
|
356
|
-
url: string,
|
|
357
|
-
assertCurrent: () => void,
|
|
358
|
-
): Promise<Response> {
|
|
359
|
-
const [resolved] = await ctx.assets.resolve(url);
|
|
360
|
-
assertCurrent();
|
|
361
|
-
if (resolved === undefined) throw new Error(`Tundra world: '${url}' is not served.`);
|
|
362
|
-
const response = await fetch(resolved);
|
|
363
|
-
assertCurrent();
|
|
364
|
-
if (!response.ok) throw new Error(`Tundra world: '${url}' answered ${String(response.status)}.`);
|
|
365
|
-
return response;
|
|
366
|
-
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.1.1",
|
|
3
|
+
"url": "https://github.com/ThreeNativeHQ/threenative-engine/releases/download/terrain-starter-assets-sha256-1bca8689b8e872ba5db3c70697e10fa99917932f84cb682327dabaa7a2fd7fe4/terrain-starter-assets-0.1.1.tar.gz",
|
|
4
|
+
"sha256": "1bca8689b8e872ba5db3c70697e10fa99917932f84cb682327dabaa7a2fd7fe4",
|
|
5
|
+
"bytes": 32212004
|
|
6
|
+
}
|
|
@@ -88,14 +88,6 @@
|
|
|
88
88
|
"metresPerTile": null,
|
|
89
89
|
"note": "The lichen-crusted weathered boulder set. Seam 11.5 against an interior 12.1: tileable. Distinct from the existing mossy_rock set, which is moss rather than lichen, so a boulder bed does not read as one surface twice."
|
|
90
90
|
},
|
|
91
|
-
"forest_leaves_02": {
|
|
92
|
-
"asset": "Forest Leaves 02",
|
|
93
|
-
"author": "Rob Tuytel (All)",
|
|
94
|
-
"license": "CC0",
|
|
95
|
-
"groundLayer": null,
|
|
96
|
-
"metresPerTile": null,
|
|
97
|
-
"note": "Leaf litter and forest floor for the ground under trees. Seam 19.7 against an interior 17.2: tileable. metresPerTile is deliberately null: the tiling is the terrain render layer's choice, not this folder's."
|
|
98
|
-
},
|
|
99
91
|
"river_small_rocks": {
|
|
100
92
|
"asset": "River Small Rocks",
|
|
101
93
|
"author": "Rob Tuytel (Photography, Processing), Rico Cilliers (Minor adjustment)",
|
|
@@ -111,14 +103,6 @@
|
|
|
111
103
|
"groundLayer": null,
|
|
112
104
|
"metresPerTile": null,
|
|
113
105
|
"note": "Alpha-cut card atlas only (diffuse, alpha, OpenGL normal at 512 px). The upstream plant meshes are not shipped: cut to the starter budget they kept one blade or frond of each plant, so the game builds its own cards on this atlas."
|
|
114
|
-
},
|
|
115
|
-
"grass_medium_02": {
|
|
116
|
-
"asset": "Grass Medium 02",
|
|
117
|
-
"author": "Rob Tuytel (photography), Rico Cilliers (modeling)",
|
|
118
|
-
"license": "CC0",
|
|
119
|
-
"groundLayer": null,
|
|
120
|
-
"metresPerTile": null,
|
|
121
|
-
"note": "Alpha-cut card atlas only (diffuse, alpha, OpenGL normal at 512 px). The upstream plant meshes are not shipped: cut to the starter budget they kept one blade or frond of each plant, so the game builds its own cards on this atlas."
|
|
122
106
|
}
|
|
123
107
|
},
|
|
124
108
|
"files": [
|
|
@@ -650,54 +634,6 @@
|
|
|
650
634
|
"sampledByTemperateGround": false,
|
|
651
635
|
"sha256": "cccadfc7b806a15bd396cc433175c80fdb386009674726a8a17e48ba50ce50cb"
|
|
652
636
|
},
|
|
653
|
-
{
|
|
654
|
-
"set": "forest_leaves_02",
|
|
655
|
-
"asset": "Forest Leaves 02",
|
|
656
|
-
"author": "Rob Tuytel (All)",
|
|
657
|
-
"license": "CC0",
|
|
658
|
-
"map": "diff",
|
|
659
|
-
"file": "forest_leaves_02/forest_leaves_02_diff_512.jpg",
|
|
660
|
-
"url": "https://dl.polyhaven.org/file/ph-assets/Textures/jpg/1k/forest_leaves_02/forest_leaves_02_diffuse_1k.jpg",
|
|
661
|
-
"bytes": 131897,
|
|
662
|
-
"dimensions": "512x512",
|
|
663
|
-
"colourSpace": "srgb",
|
|
664
|
-
"metresPerTile": null,
|
|
665
|
-
"groundLayer": null,
|
|
666
|
-
"sampledByTemperateGround": false,
|
|
667
|
-
"sha256": "3041025c2bb5c57530d2e611618d8f8bcf75f54cd1a092f323fdc87520f6e2d0"
|
|
668
|
-
},
|
|
669
|
-
{
|
|
670
|
-
"set": "forest_leaves_02",
|
|
671
|
-
"asset": "Forest Leaves 02",
|
|
672
|
-
"author": "Rob Tuytel (All)",
|
|
673
|
-
"license": "CC0",
|
|
674
|
-
"map": "nor_gl",
|
|
675
|
-
"file": "forest_leaves_02/forest_leaves_02_nor_gl_512.jpg",
|
|
676
|
-
"url": "https://dl.polyhaven.org/file/ph-assets/Textures/jpg/1k/forest_leaves_02/forest_leaves_02_nor_gl_1k.jpg",
|
|
677
|
-
"bytes": 155946,
|
|
678
|
-
"dimensions": "512x512",
|
|
679
|
-
"colourSpace": "linear",
|
|
680
|
-
"metresPerTile": null,
|
|
681
|
-
"groundLayer": null,
|
|
682
|
-
"sampledByTemperateGround": false,
|
|
683
|
-
"sha256": "248afab4b44e078501a2363856e679909560a70587c1314a1c17f3f8063218ba"
|
|
684
|
-
},
|
|
685
|
-
{
|
|
686
|
-
"set": "forest_leaves_02",
|
|
687
|
-
"asset": "Forest Leaves 02",
|
|
688
|
-
"author": "Rob Tuytel (All)",
|
|
689
|
-
"license": "CC0",
|
|
690
|
-
"map": "arm",
|
|
691
|
-
"file": "forest_leaves_02/forest_leaves_02_arm_512.jpg",
|
|
692
|
-
"url": "https://dl.polyhaven.org/file/ph-assets/Textures/jpg/1k/forest_leaves_02/forest_leaves_02_arm_1k.jpg",
|
|
693
|
-
"bytes": 105808,
|
|
694
|
-
"dimensions": "512x512",
|
|
695
|
-
"colourSpace": "linear",
|
|
696
|
-
"metresPerTile": null,
|
|
697
|
-
"groundLayer": null,
|
|
698
|
-
"sampledByTemperateGround": false,
|
|
699
|
-
"sha256": "415b28f50e5bca6ef188dee4c9a66a4e2e6668bb909c310e0cb596f746f297cd"
|
|
700
|
-
},
|
|
701
637
|
{
|
|
702
638
|
"set": "river_small_rocks",
|
|
703
639
|
"asset": "River Small Rocks",
|
|
@@ -782,42 +718,6 @@
|
|
|
782
718
|
"dimensions": [512, 512],
|
|
783
719
|
"sha256": "72d64f5a9632cf5cc26969b8e60b1a5da5432bbde562b87a6fccef29949e28a8"
|
|
784
720
|
},
|
|
785
|
-
{
|
|
786
|
-
"set": "grass_medium_02",
|
|
787
|
-
"asset": "Grass Medium 02",
|
|
788
|
-
"author": "Rob Tuytel (photography), Rico Cilliers (modeling)",
|
|
789
|
-
"license": "CC0",
|
|
790
|
-
"map": "alpha",
|
|
791
|
-
"file": "grass_medium_02/grass_medium_02_alpha_512.png",
|
|
792
|
-
"url": "https://polyhaven.com/a/grass_medium_02",
|
|
793
|
-
"bytes": 24268,
|
|
794
|
-
"dimensions": [512, 512],
|
|
795
|
-
"sha256": "4f94afff57290dae13e02ea16742ec2fa446f7c596f71eb44da6e92f5b2e17ad"
|
|
796
|
-
},
|
|
797
|
-
{
|
|
798
|
-
"set": "grass_medium_02",
|
|
799
|
-
"asset": "Grass Medium 02",
|
|
800
|
-
"author": "Rob Tuytel (photography), Rico Cilliers (modeling)",
|
|
801
|
-
"license": "CC0",
|
|
802
|
-
"map": "diff",
|
|
803
|
-
"file": "grass_medium_02/grass_medium_02_diff_512.jpg",
|
|
804
|
-
"url": "https://polyhaven.com/a/grass_medium_02",
|
|
805
|
-
"bytes": 26341,
|
|
806
|
-
"dimensions": [512, 512],
|
|
807
|
-
"sha256": "0df2de1764006ceebe633be49dcfaadab6b27b78c7c21f869b1c93f029b92a74"
|
|
808
|
-
},
|
|
809
|
-
{
|
|
810
|
-
"set": "grass_medium_02",
|
|
811
|
-
"asset": "Grass Medium 02",
|
|
812
|
-
"author": "Rob Tuytel (photography), Rico Cilliers (modeling)",
|
|
813
|
-
"license": "CC0",
|
|
814
|
-
"map": "nor_gl",
|
|
815
|
-
"file": "grass_medium_02/grass_medium_02_nor_gl_512.jpg",
|
|
816
|
-
"url": "https://polyhaven.com/a/grass_medium_02",
|
|
817
|
-
"bytes": 16575,
|
|
818
|
-
"dimensions": [512, 512],
|
|
819
|
-
"sha256": "bc6c9eaf576fd396347c5ea5b3931907cb9ace0943f0159c20d4824c4b2fe0d0"
|
|
820
|
-
},
|
|
821
721
|
{
|
|
822
722
|
"set": "kloofendal_48d_partly_cloudy",
|
|
823
723
|
"asset": "Kloofendal 48d Partly Cloudy",
|
|
@@ -838,10 +738,10 @@
|
|
|
838
738
|
"generator": "examples/strata-terrain-preview/scripts/make-needle-atlas.mjs",
|
|
839
739
|
"seed": 466468,
|
|
840
740
|
"command": "node scripts/make-needle-atlas.mjs",
|
|
841
|
-
"bytes":
|
|
741
|
+
"bytes": 320942,
|
|
842
742
|
"dimensions": "1024x1024 (4 cells of 512x512)",
|
|
843
743
|
"preprocessing": "none. Drawn from a seeded PRNG and deflated as PNG by the script itself: no image library, no upload, byte-identical on every run.",
|
|
844
|
-
"sha256": "
|
|
744
|
+
"sha256": "f320c76ff8f07c053f7ff392f5fc792a00f4c2e176f022b2233685b3c6b7d363",
|
|
845
745
|
"why": "A photograph of foliage does not give a card with the twig down the middle and needles fanning off both sides, which is what makes an alpha-cutout branch read as a branch from every angle."
|
|
846
746
|
},
|
|
847
747
|
"needle-surface.png": {
|
|
@@ -849,10 +749,10 @@
|
|
|
849
749
|
"generator": "examples/strata-terrain-preview/scripts/make-needle-atlas.mjs",
|
|
850
750
|
"seed": 466468,
|
|
851
751
|
"command": "node scripts/make-needle-atlas.mjs",
|
|
852
|
-
"bytes":
|
|
752
|
+
"bytes": 1024122,
|
|
853
753
|
"dimensions": "1024x1024 (4 cells of 512x512)",
|
|
854
754
|
"preprocessing": "none. Cooked from the coverage and ridge the same run recorded while drawing the albedo, and deflated as PNG by the script itself: no image library, byte-identical on every run.",
|
|
855
|
-
"sha256": "
|
|
755
|
+
"sha256": "30bbf3302df729aaa8e13872bc04cea3e7c3c4139bcebcab171c17486ae31bd3",
|
|
856
756
|
"why": "An alpha-tested quad has no thickness, so a crown built from cards had exactly one flat normal per card and read as stacked flat quads. A normal per needle plus the spray's own occlusion is what makes a card a mass of needles rather than a silhouette."
|
|
857
757
|
}
|
|
858
758
|
},
|
|
@@ -883,7 +783,7 @@
|
|
|
883
783
|
"authors": "Rob Tuytel, Rico Cilliers",
|
|
884
784
|
"license": "CC0",
|
|
885
785
|
"url": "https://polyhaven.com/a/rock_moss_set_01",
|
|
886
|
-
"note": "rock01 and rock04, both levels. Shaded by the starter's own mossy_rock set, triplanar."
|
|
786
|
+
"note": "rock01 and rock04, both levels. Shaded by the starter's own mossy_rock set, triplanar. pebble-a and pebble-b: the rock01 and rock04 mid levels with a flat grey material, by packages/terrain/scripts/bake-ground-cover.py."
|
|
887
787
|
},
|
|
888
788
|
{
|
|
889
789
|
"asset": "Boulder 01",
|
|
@@ -898,6 +798,13 @@
|
|
|
898
798
|
"license": "CC0",
|
|
899
799
|
"url": "https://polyhaven.com/a/boulder_01",
|
|
900
800
|
"note": "Authored LOD1 (33,060 tris) and LOD2 (16,530 tris) with base, normal and roughness maps, exported by examples/strata-terrain-preview/scripts/prep-polyhaven-rock.py; the forest starter kit's boulder."
|
|
801
|
+
},
|
|
802
|
+
{
|
|
803
|
+
"asset": "Fern 02",
|
|
804
|
+
"authors": "Rob Tuytel, Rico Cilliers",
|
|
805
|
+
"license": "CC0",
|
|
806
|
+
"url": "https://polyhaven.com/a/fern_02",
|
|
807
|
+
"note": "fern-a and fern-b: crossed-arch alpha cards cut from the fern_02 alpha and diffuse maps, built by packages/terrain/scripts/bake-ground-cover.py."
|
|
901
808
|
}
|
|
902
809
|
],
|
|
903
810
|
"firedCoverage": {
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|