@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { L as Layer, O as OperationType,
|
|
1
|
+
import { L as Layer, O as OperationType, c as IMask, d as LayerParams, e as ITerrainConfig, b as ITerrainDocument, f as IEvaluateOptions, I as ITerrainState, g as ICopyRegionOptions } from './types-CPYAc9vo.js';
|
|
2
2
|
|
|
3
3
|
type OperationOptions<T extends OperationType> = LayerParams[T] & {
|
|
4
4
|
id?: string;
|
|
@@ -57,6 +57,7 @@ declare class TerrainEvaluator {
|
|
|
57
57
|
* @requires npm i @threenative/terrain
|
|
58
58
|
* @situation author seeded terrain with noise, sculpting, erosion, roads, rivers and scatter
|
|
59
59
|
* @situation generate a procedural heightmap landscape or island for a game
|
|
60
|
+
* @situation make realistic mountains, hills, desert, coast, tundra or volcano terrain: start from `landform(kind)`, or add `erode({ method: "fluvial" })` for dendritic valleys
|
|
60
61
|
* @constraint authoring stays outside the game's steady-play graph; no renderer or physics is created
|
|
61
62
|
* @constraint units are metres with Y up; `size` is the world edge in metres (1 to 100000), centred on the origin
|
|
62
63
|
* @constraint `resolution` counts vertices per edge and must be one of 17, 33, 65, 129, 257, 513 or 1025
|
|
@@ -129,7 +130,7 @@ declare class Terrain {
|
|
|
129
130
|
materials(options: OperationOptions<"materials">): this;
|
|
130
131
|
paint(options?: OperationOptions<"paint">): this;
|
|
131
132
|
biome(options?: OperationOptions<"biome">): this;
|
|
132
|
-
scatter(options
|
|
133
|
+
scatter(options: OperationOptions<"scatter">): this;
|
|
133
134
|
clear(options: OperationOptions<"clear">): this;
|
|
134
135
|
road(options: OperationOptions<"road">): this;
|
|
135
136
|
river(options: OperationOptions<"river">): this;
|
package/dist/three.d.ts
CHANGED
|
@@ -129,10 +129,19 @@ interface IStampParams extends IOperationBase {
|
|
|
129
129
|
interface IPasteParams extends Omit<IStampParams, "shape" | "roughness" | "amplitude"> {
|
|
130
130
|
}
|
|
131
131
|
interface IErodeParams extends IBrushParams {
|
|
132
|
-
readonly method?: "thermal" | "hydraulic";
|
|
132
|
+
readonly method?: "thermal" | "hydraulic" | "fluvial";
|
|
133
|
+
/** Thermal passes, or fluvial time steps (default 40). */
|
|
133
134
|
readonly iterations?: number;
|
|
134
|
-
/** Maximum stable slope in degrees. */
|
|
135
|
+
/** Maximum stable slope in degrees; `fluvial` also enforces it as its landslide threshold. */
|
|
135
136
|
readonly talus?: number;
|
|
137
|
+
/** `fluvial`: rock uplift at the highest input point, m/yr (default 1e-3). Relief scales with uplift / erodibility. */
|
|
138
|
+
readonly uplift?: number;
|
|
139
|
+
/** `fluvial`: stream-power erodibility K, m^(1-2m)/yr (default 5e-6). */
|
|
140
|
+
readonly erodibility?: number;
|
|
141
|
+
/** `fluvial`: years per step (default 2e4); the implicit solver is stable at any value. */
|
|
142
|
+
readonly timeStep?: number;
|
|
143
|
+
/** `fluvial`: metres; rescales the eroded surface to this highest-minus-lowest. Omit to keep the natural relief. */
|
|
144
|
+
readonly relief?: number;
|
|
136
145
|
readonly rate?: number;
|
|
137
146
|
readonly droplets?: number;
|
|
138
147
|
readonly maxSteps?: number;
|
|
@@ -165,7 +174,7 @@ interface IBiomeParams extends IBrushParams {
|
|
|
165
174
|
readonly value?: number;
|
|
166
175
|
}
|
|
167
176
|
interface IScatterParams extends IOperationBase {
|
|
168
|
-
readonly asset
|
|
177
|
+
readonly asset: string;
|
|
169
178
|
readonly count?: number;
|
|
170
179
|
/** Guaranteed within one rule, never across rules. */
|
|
171
180
|
readonly minDistance?: number;
|
|
@@ -483,4 +492,4 @@ interface ISplatPng {
|
|
|
483
492
|
interface IHeightPngMetadata extends IHeightRange {
|
|
484
493
|
}
|
|
485
494
|
|
|
486
|
-
export type { ITerraceParams as $,
|
|
495
|
+
export type { ITerraceParams as $, IGradeParams as A, IGrid as B, IHeightData as C, IHeightPngMetadata as D, ExportKind as E, IHeightmapParams as F, ILayer as G, IMaterialRule as H, ITerrainState as I, IMaterialsParams as J, INoiseParams as K, Layer as L, MaterialId as M, IPaintParams as N, OperationType as O, IPasteParams as P, IRampParams as Q, IRiver as R, IRiverParams as S, IRoadParams as T, IScatterClear as U, IScatterParams as V, IScatterRule as W, ISculptParams as X, ISmoothParams as Y, ISplatPng as Z, IStampParams as _, IExportArchive as a, ITerrainInspection as a0, IWaterBody as a1, IWaterParams as a2, IWaterRule as a3, MaskSampler as a4, MaskType as a5, SplinePoint as a6, ITerrainDocument as b, IMask as c, LayerParams as d, ITerrainConfig as e, IEvaluateOptions as f, ICopyRegionOptions as g, IBakedMesh as h, IPlacementOverride as i, IPlacement as j, IErosionMaps as k, ISampledGrid as l, IBakeMeshOptions as m, IBakeTerrainOptions as n, IBakedTerrain as o, IDecodeHeightPngOptions as p, IDecodeRaw16Options as q, IHeightRange as r, IRaw16Options as s, IExportFile as t, IBiomeParams as u, IBrushParams as v, IClearParams as w, IDecodedHeightPng as x, IErodeParams as y, IFlattenParams as z };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { I as ITerrainState } from './types-CPYAc9vo.js';
|
|
2
|
+
|
|
3
|
+
/** One streamed asset: its LOD0 model, its authored bounds and the levels it swaps to. */
|
|
4
|
+
interface IWorldPackageAsset {
|
|
5
|
+
readonly glb: string;
|
|
6
|
+
readonly bounds: {
|
|
7
|
+
readonly min: readonly [number, number, number];
|
|
8
|
+
readonly max: readonly [number, number, number];
|
|
9
|
+
};
|
|
10
|
+
readonly lods?: readonly {
|
|
11
|
+
readonly glb: string;
|
|
12
|
+
readonly distance: number;
|
|
13
|
+
/** Scene inside `glb`; a cooked species keeps every level in one file and selects by scene. */
|
|
14
|
+
readonly scene?: string;
|
|
15
|
+
}[];
|
|
16
|
+
readonly maxDistance?: number;
|
|
17
|
+
}
|
|
18
|
+
/** One cell's contiguous run of placement records, eight float32 values each. */
|
|
19
|
+
interface IWorldPackageRun {
|
|
20
|
+
readonly asset: string;
|
|
21
|
+
/** Record offset into the placement buffer, not a byte offset. */
|
|
22
|
+
readonly offset: number;
|
|
23
|
+
readonly count: number;
|
|
24
|
+
}
|
|
25
|
+
/** The `world.json` contract, declared here so this addon needs no `@threenative/core` import. */
|
|
26
|
+
interface IWorldPackageManifest {
|
|
27
|
+
readonly version: 1;
|
|
28
|
+
readonly extent: {
|
|
29
|
+
readonly minX: number;
|
|
30
|
+
readonly minZ: number;
|
|
31
|
+
readonly sizeX: number;
|
|
32
|
+
readonly sizeZ: number;
|
|
33
|
+
};
|
|
34
|
+
readonly cellSize: number;
|
|
35
|
+
readonly terrain: {
|
|
36
|
+
readonly heightmap: string;
|
|
37
|
+
readonly columns: number;
|
|
38
|
+
readonly rows: number;
|
|
39
|
+
readonly spacing: number;
|
|
40
|
+
readonly heightMin: number;
|
|
41
|
+
readonly heightMax: number;
|
|
42
|
+
readonly layers?: Readonly<Record<string, string>>;
|
|
43
|
+
};
|
|
44
|
+
readonly assets: Readonly<Record<string, IWorldPackageAsset>>;
|
|
45
|
+
readonly placements: string;
|
|
46
|
+
/** Optional package-relative JSON array of placement IDs in binary record order. */
|
|
47
|
+
readonly placementIds?: string;
|
|
48
|
+
readonly cells: readonly {
|
|
49
|
+
readonly x: number;
|
|
50
|
+
readonly z: number;
|
|
51
|
+
readonly runs: readonly IWorldPackageRun[];
|
|
52
|
+
}[];
|
|
53
|
+
}
|
|
54
|
+
/** The splat layout to copy into a terrain table: eight material masks in two RGBA8 planes. */
|
|
55
|
+
interface IWorldPackageSplat {
|
|
56
|
+
readonly size: number;
|
|
57
|
+
readonly planes: number;
|
|
58
|
+
readonly masks: Readonly<Record<string, readonly [number, "r" | "g" | "b" | "a"]>>;
|
|
59
|
+
}
|
|
60
|
+
interface IBakeWorldPackageOptions {
|
|
61
|
+
/** Every asset any instance may reference. An instance outside this set fails the bake. */
|
|
62
|
+
readonly assets: Readonly<Record<string, IWorldPackageAsset>>;
|
|
63
|
+
/** Metres per streamed cell. Defaults to 64. */
|
|
64
|
+
readonly cellSize?: number;
|
|
65
|
+
/** Extra `terrain.layers` entries, e.g. `{ table: "terrain-table.json" }`. */
|
|
66
|
+
readonly layers?: Readonly<Record<string, string>>;
|
|
67
|
+
readonly names?: {
|
|
68
|
+
readonly heightmap?: string;
|
|
69
|
+
readonly placements?: string;
|
|
70
|
+
readonly placementIds?: string;
|
|
71
|
+
readonly splat?: string;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
interface IBakedWorldPackage {
|
|
75
|
+
readonly manifest: IWorldPackageManifest;
|
|
76
|
+
readonly splat: IWorldPackageSplat;
|
|
77
|
+
/** The baked package files, keyed by the manifest names that point at them. */
|
|
78
|
+
readonly files: Readonly<Record<string, Uint8Array>>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Bake an evaluated terrain into the engine's world package: a `world.json` manifest, a uint16
|
|
82
|
+
* heightmap, a splat mask array, a placement buffer of eight float32 per instance, a placement ID
|
|
83
|
+
* sidecar and the square cells that stream them. The encodings and row orders are the ones the Blender recipe
|
|
84
|
+
* `export_world.py` writes, so one runtime streams both without a second reader.
|
|
85
|
+
*
|
|
86
|
+
* @requires npm i -D @threenative/terrain
|
|
87
|
+
* @situation hand an evaluated Strata terrain to a game without a Blender round trip
|
|
88
|
+
* @constraint headless authoring; no three, no DOM, and nothing here decides how the world looks
|
|
89
|
+
* @example const { manifest, files } = bakeWorldPackage(state, { assets });
|
|
90
|
+
* @override every asset path, bound, LOD distance and cell size comes from the caller's options
|
|
91
|
+
*/
|
|
92
|
+
declare function bakeWorldPackage(state: ITerrainState, options: IBakeWorldPackageOptions): IBakedWorldPackage;
|
|
93
|
+
|
|
94
|
+
export { type IWorldPackageAsset as I, type IWorldPackageManifest as a, bakeWorldPackage as b, type IBakeWorldPackageOptions as c, type IBakedWorldPackage as d, type IWorldPackageRun as e };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threenative/terrain",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Headless terrain authoring — noise, erosion, sculpting, roads, rivers, material splats and scatter — evaluated into ordinary typed arrays and indexed Three.js geometry.",
|
|
6
6
|
"keywords": [
|
|
@@ -18,18 +18,24 @@
|
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
|
-
"url": "git+https://github.com/ThreeNativeHQ/threenative.git",
|
|
21
|
+
"url": "git+https://github.com/ThreeNativeHQ/threenative-engine.git",
|
|
22
22
|
"directory": "packages/terrain"
|
|
23
23
|
},
|
|
24
24
|
"type": "module",
|
|
25
25
|
"files": [
|
|
26
26
|
"dist",
|
|
27
|
-
"starter",
|
|
28
|
-
"starter
|
|
27
|
+
"starter/*/*.json",
|
|
28
|
+
"starter/*/*.r16",
|
|
29
|
+
"starter/*/*.mjs",
|
|
30
|
+
"starter/*/*.ts",
|
|
31
|
+
"starter/*/*.md",
|
|
32
|
+
"starter-assets.json",
|
|
33
|
+
"starter-credits.json",
|
|
29
34
|
"README.md",
|
|
30
35
|
"AGENT_GUIDE.md",
|
|
31
36
|
"THIRD_PARTY_NOTICES.md"
|
|
32
37
|
],
|
|
38
|
+
"bin": "./dist/mcp/server.js",
|
|
33
39
|
"main": "./dist/index.js",
|
|
34
40
|
"module": "./dist/index.js",
|
|
35
41
|
"types": "./dist/index.d.ts",
|
|
@@ -46,6 +52,10 @@
|
|
|
46
52
|
"types": "./dist/export.d.ts",
|
|
47
53
|
"import": "./dist/export.js"
|
|
48
54
|
},
|
|
55
|
+
"./kit": {
|
|
56
|
+
"types": "./dist/kit.d.ts",
|
|
57
|
+
"import": "./dist/kit.js"
|
|
58
|
+
},
|
|
49
59
|
"./package.json": "./package.json",
|
|
50
60
|
"./editor/server": {
|
|
51
61
|
"types": "./dist/editor/server.d.ts",
|
|
@@ -54,6 +64,10 @@
|
|
|
54
64
|
"./editor": {
|
|
55
65
|
"types": "./dist/editor/index.d.ts",
|
|
56
66
|
"import": "./dist/editor/index.js"
|
|
67
|
+
},
|
|
68
|
+
"./starter": {
|
|
69
|
+
"types": "./dist/starter.d.ts",
|
|
70
|
+
"import": "./dist/starter.js"
|
|
57
71
|
}
|
|
58
72
|
},
|
|
59
73
|
"publishConfig": {
|
|
@@ -69,14 +83,22 @@
|
|
|
69
83
|
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
70
84
|
"@typescript/native": "npm:typescript@7.0.2",
|
|
71
85
|
"vite": "8.2.0",
|
|
72
|
-
"@threenative/core": "0.3.
|
|
73
|
-
"@threenative/physics": "0.3.
|
|
86
|
+
"@threenative/core": "0.3.12",
|
|
87
|
+
"@threenative/physics": "0.3.12"
|
|
74
88
|
},
|
|
75
89
|
"peerDependencies": {
|
|
90
|
+
"@threenative/core": ">=0.3.12 <0.4.0",
|
|
91
|
+
"@threenative/physics": ">=0.3.12 <0.4.0",
|
|
76
92
|
"three": ">=0.187.0 <0.188.0",
|
|
77
93
|
"vite": ">=7.0.0 <9.0.0"
|
|
78
94
|
},
|
|
79
95
|
"peerDependenciesMeta": {
|
|
96
|
+
"@threenative/core": {
|
|
97
|
+
"optional": true
|
|
98
|
+
},
|
|
99
|
+
"@threenative/physics": {
|
|
100
|
+
"optional": true
|
|
101
|
+
},
|
|
80
102
|
"vite": {
|
|
81
103
|
"optional": true
|
|
82
104
|
}
|
package/starter/alpine/README.md
CHANGED
|
@@ -13,7 +13,7 @@ game source: once copied, every file is yours to edit.
|
|
|
13
13
|
| `world.ts` | The runtime: streams the baked world, one heightfield for the ground, sphere colliders for the boulders near the player, and the sky as the props' light. |
|
|
14
14
|
| `sky.ts` | The daylight: the sun, sky, fill, haze, exposure and tone curve. |
|
|
15
15
|
|
|
16
|
-
Art is CC0 (Poly Haven); provenance is in `@threenative/terrain/starter-
|
|
16
|
+
Art is CC0 (Poly Haven); provenance is in `@threenative/terrain/starter-credits.json`.
|
|
17
17
|
|
|
18
18
|
## Status
|
|
19
19
|
|
|
@@ -27,3 +27,79 @@ rings the nearest boulder with gentle ground and a clear walk.
|
|
|
27
27
|
2. Run `node src/terrain/alpine/bake.mjs --out assets/terrain/alpine` (needs `@threenative/terrain`
|
|
28
28
|
as a devDependency). The same recipe always writes the same bytes.
|
|
29
29
|
3. In the scene, call `addAlpine(ctx, follow)` for the world and `alpineDaylight(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 addAlpine(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.
|
package/starter/alpine/bake.mjs
CHANGED
|
@@ -1,118 +1,6 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
// node src/terrain/alpine/bake.mjs [--assets <dir>] [--out <dir>]
|
|
4
|
-
// The engine's `WorldCells` streams `world/world.json` and `loadTerrainSplat` textures its ground;
|
|
5
|
-
// the game never evaluates terrain at runtime.
|
|
6
|
-
import { copyFile, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
7
|
-
import { dirname, join, resolve } from "node:path";
|
|
8
|
-
import { fileURLToPath } from "node:url";
|
|
9
|
-
import { Terrain, applyPlacementOverrides, bakeWorldPackage } from "@threenative/terrain";
|
|
1
|
+
// Run with [--assets <dir>] [--out <dir>]; defaults to installed assets and ./world.
|
|
2
|
+
import { bakeKit } from "@threenative/terrain/kit";
|
|
10
3
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/** `--key value` after the script; `--assets` and `--out` default as noted below. */
|
|
14
|
-
function flag(name, fallback) {
|
|
15
|
-
const at = process.argv.indexOf(`--${name}`);
|
|
16
|
-
return at === -1 ? fallback : resolve(process.argv[at + 1] ?? "");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// The installed kit ships its models and textures beside the package manifest, so a copied kit
|
|
20
|
-
// finds them without asking the game for a path. `--assets` overrides that for a local checkout.
|
|
21
|
-
const installed = dirname(fileURLToPath(import.meta.resolve("@threenative/terrain/package.json")));
|
|
22
|
-
const assetsDir = flag("assets", join(installed, "starter-assets"));
|
|
23
|
-
const outDir = flag("out", join(here, "world"));
|
|
24
|
-
|
|
25
|
-
const recipe = JSON.parse(await readFile(join(here, "recipe.json"), "utf8"));
|
|
26
|
-
const assetTable = JSON.parse(await readFile(join(here, "assets.json"), "utf8"));
|
|
27
|
-
const surface = JSON.parse(await readFile(join(here, "surface.json"), "utf8"));
|
|
28
|
-
|
|
29
|
-
const state = applyPlacementOverrides(
|
|
30
|
-
Terrain.fromJSON(recipe.recipe).evaluate(),
|
|
31
|
-
recipe.placementOverrides ?? {},
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
const assets = Object.fromEntries(
|
|
35
|
-
Object.entries(assetTable).map(([id, spec]) => [
|
|
36
|
-
id,
|
|
37
|
-
{
|
|
38
|
-
bounds: spec.bounds,
|
|
39
|
-
glb: `models/${spec.near.split("/").at(-1)}`,
|
|
40
|
-
...(spec.mid
|
|
41
|
-
? { lods: [{ distance: spec.midDistance, glb: `models/${spec.mid.split("/").at(-1)}` }] }
|
|
42
|
-
: {}),
|
|
43
|
-
maxDistance: spec.maxDistance,
|
|
44
|
-
},
|
|
45
|
-
]),
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
const started = performance.now();
|
|
49
|
-
const { manifest, splat, files } = bakeWorldPackage(state, {
|
|
50
|
-
assets,
|
|
51
|
-
layers: { table: "terrain-table.json" },
|
|
4
|
+
await bakeKit(import.meta.url, {
|
|
5
|
+
sky: "hdri/kloofendal_48d_partly_cloudy_1k.hdr",
|
|
52
6
|
});
|
|
53
|
-
const written = new Map();
|
|
54
|
-
|
|
55
|
-
async function write(relative, bytes) {
|
|
56
|
-
await mkdir(join(outDir, dirname(relative)), { recursive: true });
|
|
57
|
-
await writeFile(join(outDir, relative), bytes);
|
|
58
|
-
written.set(relative, bytes.length ?? bytes.byteLength);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async function copy(from, to) {
|
|
62
|
-
await mkdir(join(outDir, dirname(to)), { recursive: true });
|
|
63
|
-
await copyFile(join(assetsDir, from), join(outDir, to));
|
|
64
|
-
written.set(to, (await readFile(join(outDir, to))).byteLength);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
await write("world.json", `${JSON.stringify(manifest, null, 2)}\n`);
|
|
68
|
-
// The lake and river the generator evaluated, so the game draws the water the bake shaped.
|
|
69
|
-
const round = (value) => Math.round(value * 1_000) / 1_000;
|
|
70
|
-
await write(
|
|
71
|
-
"water.json",
|
|
72
|
-
`${JSON.stringify(
|
|
73
|
-
{
|
|
74
|
-
lakes: state.waters.map((lake) => ({
|
|
75
|
-
id: lake.id,
|
|
76
|
-
at: lake.at,
|
|
77
|
-
radius: lake.radius,
|
|
78
|
-
level: lake.level,
|
|
79
|
-
})),
|
|
80
|
-
rivers: state.rivers.map((river) => ({
|
|
81
|
-
id: river.id,
|
|
82
|
-
width: round(river.width),
|
|
83
|
-
points: river.points.map((point) => point.map(round)),
|
|
84
|
-
})),
|
|
85
|
-
},
|
|
86
|
-
null,
|
|
87
|
-
2,
|
|
88
|
-
)}\n`,
|
|
89
|
-
);
|
|
90
|
-
for (const [name, bytes] of Object.entries(files)) await write(name, bytes);
|
|
91
|
-
for (const spec of Object.values(assetTable)) {
|
|
92
|
-
await copy(spec.near, `models/${spec.near.split("/").at(-1)}`);
|
|
93
|
-
if (spec.mid) await copy(spec.mid, `models/${spec.mid.split("/").at(-1)}`);
|
|
94
|
-
}
|
|
95
|
-
// The sky the props are lit by (CC0 Poly Haven Kloofendal); world.ts gives it to their materials.
|
|
96
|
-
await copy("hdri/kloofendal_48d_partly_cloudy_1k.hdr", "sky.hdr");
|
|
97
|
-
for (const layer of [surface.base, ...surface.layers]) {
|
|
98
|
-
const source = surface.sources[layer.id];
|
|
99
|
-
await copy(source.diff, `${surface.textures}/${layer.id}_diff.jpg`);
|
|
100
|
-
await copy(source.nrm, `${surface.textures}/${layer.id}_nrm.jpg`);
|
|
101
|
-
}
|
|
102
|
-
// `sources` is the bake's own lookup: the runtime reads only base/layers/splat/textures.
|
|
103
|
-
await write(
|
|
104
|
-
"terrain-table.json",
|
|
105
|
-
`${JSON.stringify({ ...surface, splat, textures: "textures" }, null, 2)}\n`,
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
const perAsset = {};
|
|
109
|
-
for (const cell of manifest.cells)
|
|
110
|
-
for (const run of cell.runs) perAsset[run.asset] = (perAsset[run.asset] ?? 0) + run.count;
|
|
111
|
-
const total = [...written.values()].reduce((sum, bytes) => sum + bytes, 0);
|
|
112
|
-
console.log(
|
|
113
|
-
`${Object.entries(perAsset)
|
|
114
|
-
.map(([asset, count]) => `${asset} ${String(count)}`)
|
|
115
|
-
.join(", ")} placements; ${[...written]
|
|
116
|
-
.map(([name, bytes]) => `${name} ${String(bytes)} B`)
|
|
117
|
-
.join(", ")}; ${String(total)} B total; ${Math.round(performance.now() - started)} ms`,
|
|
118
|
-
);
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
{
|
|
2
|
+
"look": "alpine",
|
|
3
|
+
"bake": {
|
|
4
|
+
"file": "alpine",
|
|
5
|
+
"key": null
|
|
6
|
+
},
|
|
7
|
+
"landform": "alpine",
|
|
8
|
+
"sizeMeters": 512,
|
|
9
|
+
"seed": 41,
|
|
10
|
+
"stream": "ordered",
|
|
11
|
+
"cover": {
|
|
12
|
+
"ground": "crag",
|
|
13
|
+
"seed": 466468,
|
|
14
|
+
"attempts": 80000,
|
|
15
|
+
"stoneRadius": 1.9,
|
|
16
|
+
"clearings": [[850, -1000, 10]]
|
|
17
|
+
},
|
|
18
|
+
"foliage": [
|
|
19
|
+
{
|
|
20
|
+
"species": "spruce",
|
|
21
|
+
"density": 0,
|
|
22
|
+
"slope": [0, 32],
|
|
23
|
+
"height": [0, 52],
|
|
24
|
+
"spacing": [3.4, 3.4],
|
|
25
|
+
"collision": "trunk",
|
|
26
|
+
"stands": false,
|
|
27
|
+
"grassThreshold": 0.18,
|
|
28
|
+
"standThreshold": 0.42,
|
|
29
|
+
"far": null
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
"grass": [
|
|
33
|
+
{
|
|
34
|
+
"species": "grass",
|
|
35
|
+
"density": 0,
|
|
36
|
+
"slope": [0, 0],
|
|
37
|
+
"height": null,
|
|
38
|
+
"spacing": 3.5,
|
|
39
|
+
"slopeFalloff": 0,
|
|
40
|
+
"heightFalloff": 28,
|
|
41
|
+
"mats": null,
|
|
42
|
+
"waterMargin": 7.5,
|
|
43
|
+
"beach": null,
|
|
44
|
+
"detailSpacing": 0.6,
|
|
45
|
+
"drift": {
|
|
46
|
+
"field": "stand",
|
|
47
|
+
"frequency": [2.1, 2.4],
|
|
48
|
+
"offset": 0,
|
|
49
|
+
"amplitude": 1,
|
|
50
|
+
"band": [0.3, 0.45]
|
|
51
|
+
},
|
|
52
|
+
"bladeScale": 0.55,
|
|
53
|
+
"bladeJitter": 0.5,
|
|
54
|
+
"scrubChance": 0.3,
|
|
55
|
+
"scrubScale": 0.9,
|
|
56
|
+
"scrubJitter": 0.6,
|
|
57
|
+
"scrubBush": false,
|
|
58
|
+
"shoreGround": false,
|
|
59
|
+
"cobbledBed": false
|
|
60
|
+
}
|
|
61
|
+
],
|
|
62
|
+
"layers": [
|
|
63
|
+
{
|
|
64
|
+
"layer": "alpine",
|
|
65
|
+
"from": 0.06,
|
|
66
|
+
"to": 0.1
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"layer": "rock",
|
|
70
|
+
"from": 0.02,
|
|
71
|
+
"to": 0.11
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"layer": "treeline",
|
|
75
|
+
"from": 0.3,
|
|
76
|
+
"to": 0.55
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"layer": "cap",
|
|
80
|
+
"from": 0.82,
|
|
81
|
+
"to": 1
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"layer": "desertRock",
|
|
85
|
+
"from": 0.18,
|
|
86
|
+
"to": 0.48
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"layer": "alpineRock",
|
|
90
|
+
"from": 0.06,
|
|
91
|
+
"to": 0.14
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"layer": "alpineHollow",
|
|
95
|
+
"from": 0.05,
|
|
96
|
+
"to": 0.12
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"layer": "snow",
|
|
100
|
+
"from": 0.6,
|
|
101
|
+
"to": 0.85,
|
|
102
|
+
"shedFrom": 0.16,
|
|
103
|
+
"shedTo": 0.39
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
"water": [],
|
|
107
|
+
"spawn": {
|
|
108
|
+
"at": [180, -190],
|
|
109
|
+
"cameraOffset": [28, 24, 42],
|
|
110
|
+
"focus": [180, -190]
|
|
111
|
+
},
|
|
112
|
+
"species": ["boulder", "grass", "mountain", "riverrock", "sapling", "scree", "scrub", "spruce"],
|
|
113
|
+
"aliases": ["alpine", "mountain", "mountains", "snowy", "peaks"]
|
|
114
|
+
}
|
|
Binary file
|