@threenative/terrain 0.1.6 → 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/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
|
@@ -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,16 +176,26 @@ 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
|
|
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,7 +155,7 @@ 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
|
|
|
@@ -256,158 +175,3 @@ function bendCrownNormals(geometry: BufferGeometry, bend: number): void {
|
|
|
256
175
|
}
|
|
257
176
|
normal.needsUpdate = true;
|
|
258
177
|
}
|
|
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
|
-
}
|
package/starter/tundra/README.md
CHANGED
|
@@ -14,7 +14,7 @@ erratics. It is game source: once copied, every file is yours to edit.
|
|
|
14
14
|
| `sky.ts` | The daylight: the sun, sky, fill, haze, exposure and tone curve. It also lights the lakes' mirror. |
|
|
15
15
|
| `water.ts` | The kettle lakes and meltwater rivers, drawn with a pale ice tint on the lakes. |
|
|
16
16
|
|
|
17
|
-
Art is CC0 (Poly Haven); provenance is in `@threenative/terrain/starter-
|
|
17
|
+
Art is CC0 (Poly Haven); provenance is in `@threenative/terrain/starter-credits.json`.
|
|
18
18
|
|
|
19
19
|
## Status
|
|
20
20
|
|
|
@@ -27,3 +27,79 @@ gentle, so the scene picks its spawn from the loaded heightfield and keeps it of
|
|
|
27
27
|
2. Run `node src/terrain/tundra/bake.mjs --out assets/terrain/tundra` (needs `@threenative/terrain`
|
|
28
28
|
as a devDependency). The same recipe always writes the same bytes.
|
|
29
29
|
3. In the scene, call `addTundra(ctx, follow)` for the world and `tundraDaylight(follow)` for the light.
|
|
30
|
+
|
|
31
|
+
## Edit at startup, without rebaking
|
|
32
|
+
|
|
33
|
+
The copied `world.ts` loads its own `surface.json` as the ground table on every startup.
|
|
34
|
+
Edit tints, tiling and blend thresholds there, or the material graph and prop dressing in
|
|
35
|
+
`world.ts`, then reload. The package's `terrain-table.json` remains the baked default for
|
|
36
|
+
package-only consumers; its splat masks and texture descriptors still supply the ground data.
|
|
37
|
+
A source table cannot name a mask that the bake did not produce.
|
|
38
|
+
|
|
39
|
+
Add `edits` to the existing `spec` in your copied `world.ts`. Read real stable IDs from the
|
|
40
|
+
package's `placement-ids.json` (named by `world.json.placementIds`); these example IDs are placeholders:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
edits: {
|
|
44
|
+
assets: {
|
|
45
|
+
accent: { glb: "props/accent.glb", bounds: { min: [-1, -1, -1], max: [1, 1, 1] } },
|
|
46
|
+
},
|
|
47
|
+
remove: ["promote-id"],
|
|
48
|
+
clear: [{ center: [40, 18], radius: 6 }], // Optional assets: ["boulder"] filter.
|
|
49
|
+
overrides: {
|
|
50
|
+
"move-id": { position: [12, 0, -30], quaternion: [0, 0, 0, 1], scale: [1, 1, 1] },
|
|
51
|
+
},
|
|
52
|
+
add: [{ id: "camp-accent", asset: "accent", position: [44, 0, 20],
|
|
53
|
+
quaternion: [0, 0, 0, 1], scale: [1, 1, 1], grounding: true }],
|
|
54
|
+
},
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`assets` replaces or adds a kind; copy the GLB into the served package directory first.
|
|
58
|
+
GLB and LOD paths are package-relative, with no URL scheme, leading slash or `..` segment;
|
|
59
|
+
provide accurate model-local `bounds`. The existing `COLLIDERS` table and dress function still
|
|
60
|
+
choose each kind's collision and appearance. Positions must lie inside the world's extent,
|
|
61
|
+
quaternions must be nonzero, values finite and scale uniform. Grounding defaults on and sets
|
|
62
|
+
the origin Y to `field.heightAt(x, z)`; `grounding: false` preserves the authored Y.
|
|
63
|
+
|
|
64
|
+
Edits run in the order shown: assets, remove, clear, overrides, add. A clear skips IDs named
|
|
65
|
+
by overrides. Removing and overriding the same ID throws; additions need new IDs. Unmatched
|
|
66
|
+
removal/override IDs warn and appear in `editReport.unmatched`. Old packages work without a
|
|
67
|
+
sidecar for assets, clear and add; ID edits need one re-bake to write the sidecar. Without
|
|
68
|
+
`edits`, the decoded manifest and placement bytes pass through unchanged.
|
|
69
|
+
|
|
70
|
+
Promote only a few props to ordinary Three objects: remove their IDs from the instances,
|
|
71
|
+
then use the returned `editReport.removed` in the scene. This example replaces each with a
|
|
72
|
+
game-owned glowing box; use your own geometry, material, light and collision shape:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { CollisionShape3D, RigidBody3D } from "@threenative/physics";
|
|
76
|
+
import { BoxGeometry, Mesh, MeshStandardMaterial, PointLight } from "three";
|
|
77
|
+
|
|
78
|
+
const loaded = await addTundra(ctx, player);
|
|
79
|
+
for (const p of loaded.editReport.removed) {
|
|
80
|
+
const mesh = new Mesh(new BoxGeometry(1, 1, 1), new MeshStandardMaterial({ color: 0xffbb66 }));
|
|
81
|
+
mesh.position.set(p.position[0], loaded.field.heightAt(p.position[0], p.position[2]), p.position[2]);
|
|
82
|
+
mesh.quaternion.fromArray(p.quaternion);
|
|
83
|
+
mesh.scale.setScalar(p.scale);
|
|
84
|
+
mesh.castShadow = mesh.receiveShadow = true;
|
|
85
|
+
mesh.add(new PointLight(0xffaa55, 12, 6));
|
|
86
|
+
ctx.add(mesh);
|
|
87
|
+
const body = new RigidBody3D({ object: mesh, physics: ctx.physics, type: "fixed",
|
|
88
|
+
shape: CollisionShape3D.box(p.scale, p.scale, p.scale) });
|
|
89
|
+
ctx.entities.add(`promoted.${p.id}`, { dispose() {
|
|
90
|
+
body.dispose(); mesh.removeFromParent(); mesh.geometry.dispose(); mesh.material.dispose();
|
|
91
|
+
} });
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Rendering, nearby prop collision, dressing and returned `manifest`, `placements` and
|
|
96
|
+
`placementIds` all use the edited records. `clear` removals are not in the promotion report.
|
|
97
|
+
The separate `editWorldPlacements` helper and its types are exported from
|
|
98
|
+
`@threenative/terrain/starter` for callers that already own decoded package data.
|
|
99
|
+
|
|
100
|
+
Shape, topology, erosion, mask painting, distribution rules and water still require regeneration.
|
|
101
|
+
Changing cooked ground images requires the bake/cook texture normalization step; editing the
|
|
102
|
+
game table cannot replace baked texture descriptors or introduce new channels. To replace the
|
|
103
|
+
props' environment image at runtime, copy an HDR into the served package, change
|
|
104
|
+
`spec.lighting.sky` in `world.ts` to its package-relative path, then reload. The daylight and
|
|
105
|
+
background remain game choices in `sky.ts`. Package-only exports do not run these source edits.
|