@threenative/terrain 0.1.7 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/AGENT_GUIDE.md +19 -4
  2. package/dist/editor/index.d.ts +218 -5
  3. package/dist/editor/index.js +4093 -1399
  4. package/dist/editor/server.d.ts +2 -2
  5. package/dist/editor/server.js +752 -124
  6. package/dist/editor/worker.d.ts +33 -1
  7. package/dist/editor/worker.js +642 -114
  8. package/dist/export.d.ts +11 -9
  9. package/dist/export.js +22 -34
  10. package/dist/index.d.ts +866 -73
  11. package/dist/index.js +3003 -523
  12. package/dist/kit.d.ts +57 -0
  13. package/dist/kit.js +2718 -0
  14. package/dist/mcp/cook-child.d.ts +2 -0
  15. package/dist/mcp/cook-child.js +5346 -0
  16. package/dist/mcp/server.d.ts +7 -0
  17. package/dist/mcp/server.js +3970 -0
  18. package/dist/{server-ByM2hmYJ.d.ts → server-B5RdvEAC.d.ts} +3 -2
  19. package/dist/starter.d.ts +143 -0
  20. package/dist/starter.js +1031 -0
  21. package/dist/{terrain-gPnkCU6S.d.ts → terrain-CAEaW0mQ.d.ts} +3 -2
  22. package/dist/three.d.ts +1 -1
  23. package/dist/{types-Ant8-Axc.d.ts → types-BpH00qsx.d.ts} +20 -4
  24. package/dist/world-package-B8QgHjAQ.d.ts +53 -0
  25. package/package.json +28 -6
  26. package/starter/alpine/README.md +77 -1
  27. package/starter/alpine/bake.mjs +4 -116
  28. package/starter/alpine/biome.data.json +134 -0
  29. package/starter/alpine/heightmap.r16 +0 -0
  30. package/starter/alpine/recipe.json +3 -66051
  31. package/starter/alpine/world.ts +45 -293
  32. package/starter/coastal/README.md +82 -3
  33. package/starter/coastal/assets.json +2 -1
  34. package/starter/coastal/bake.mjs +4 -116
  35. package/starter/coastal/biome.data.json +156 -0
  36. package/starter/coastal/heightmap.r16 +0 -0
  37. package/starter/coastal/recipe.json +3 -66051
  38. package/starter/coastal/sea.ts +51 -66
  39. package/starter/coastal/world.ts +53 -318
  40. package/starter/desert/README.md +77 -1
  41. package/starter/desert/bake.mjs +4 -116
  42. package/starter/desert/biome.data.json +124 -0
  43. package/starter/desert/heightmap.r16 +0 -0
  44. package/starter/desert/recipe.json +3 -66051
  45. package/starter/desert/world.ts +45 -293
  46. package/starter/forest/README.md +85 -5
  47. package/starter/forest/assets.json +34 -1
  48. package/starter/forest/bake.mjs +6 -116
  49. package/starter/forest/biome.data.json +173 -0
  50. package/starter/forest/heightmap.r16 +0 -0
  51. package/starter/forest/recipe.json +192 -4428
  52. package/starter/forest/sky.ts +11 -0
  53. package/starter/forest/water.ts +39 -48
  54. package/starter/forest/world.ts +92 -323
  55. package/starter/tundra/README.md +77 -1
  56. package/starter/tundra/bake.mjs +4 -116
  57. package/starter/tundra/biome.data.json +141 -0
  58. package/starter/tundra/heightmap.r16 +0 -0
  59. package/starter/tundra/recipe.json +18 -66066
  60. package/starter/tundra/water.ts +9 -28
  61. package/starter/tundra/world.ts +65 -319
  62. package/starter-assets.json +6 -0
  63. package/{starter-assets/credits.json → starter-credits.json} +12 -105
  64. package/starter-assets/bark_brown_02/bark_brown_02_diff_1k.jpg +0 -0
  65. package/starter-assets/bark_brown_02/bark_brown_02_nor_gl_1k.jpg +0 -0
  66. package/starter-assets/bark_brown_02/bark_brown_02_rough_1k.jpg +0 -0
  67. package/starter-assets/boulder_01/boulder-mid.glb +0 -0
  68. package/starter-assets/boulder_01/boulder-near.glb +0 -0
  69. package/starter-assets/cliff_side/cliff_side_ao_1k.jpg +0 -0
  70. package/starter-assets/cliff_side/cliff_side_diff_1k.jpg +0 -0
  71. package/starter-assets/cliff_side/cliff_side_nor_gl_1k.jpg +0 -0
  72. package/starter-assets/cliff_side/cliff_side_rough_1k.jpg +0 -0
  73. package/starter-assets/fern_02/fern_02_alpha_512.png +0 -0
  74. package/starter-assets/fern_02/fern_02_diff_512.jpg +0 -0
  75. package/starter-assets/fern_02/fern_02_nor_gl_512.jpg +0 -0
  76. package/starter-assets/fir_tree_01/fir-b-lod1.glb +0 -0
  77. package/starter-assets/fir_tree_01/fir-b-lod2.glb +0 -0
  78. package/starter-assets/fir_tree_01/fir-c-lod1.glb +0 -0
  79. package/starter-assets/fir_tree_01/fir-c-lod2.glb +0 -0
  80. package/starter-assets/fir_tree_01/fir_tree_01_twig_arm_1k.jpg +0 -0
  81. package/starter-assets/fir_tree_01/fir_tree_01_twig_diff_1k.jpg +0 -0
  82. package/starter-assets/fir_tree_01/fir_tree_01_twig_nor_gl_1k.jpg +0 -0
  83. package/starter-assets/forest_ground_04/forest_ground_04_ao_1k.jpg +0 -0
  84. package/starter-assets/forest_ground_04/forest_ground_04_diff_1k.jpg +0 -0
  85. package/starter-assets/forest_ground_04/forest_ground_04_nor_gl_1k.jpg +0 -0
  86. package/starter-assets/forest_ground_04/forest_ground_04_rough_1k.jpg +0 -0
  87. package/starter-assets/forest_leaves_02/forest_leaves_02_arm_512.jpg +0 -0
  88. package/starter-assets/forest_leaves_02/forest_leaves_02_diff_512.jpg +0 -0
  89. package/starter-assets/forest_leaves_02/forest_leaves_02_nor_gl_512.jpg +0 -0
  90. package/starter-assets/grass_medium_02/grass_medium_02_alpha_512.png +0 -0
  91. package/starter-assets/grass_medium_02/grass_medium_02_diff_512.jpg +0 -0
  92. package/starter-assets/grass_medium_02/grass_medium_02_nor_gl_512.jpg +0 -0
  93. package/starter-assets/hdri/kloofendal_48d_partly_cloudy_1k.hdr +0 -0
  94. package/starter-assets/leafy_grass/leafy_grass_ao_1k.jpg +0 -0
  95. package/starter-assets/leafy_grass/leafy_grass_diff_1k.jpg +0 -0
  96. package/starter-assets/leafy_grass/leafy_grass_nor_gl_1k.jpg +0 -0
  97. package/starter-assets/leafy_grass/leafy_grass_rough_1k.jpg +0 -0
  98. package/starter-assets/lichen_rock/lichen_rock_arm_512.jpg +0 -0
  99. package/starter-assets/lichen_rock/lichen_rock_diff_512.jpg +0 -0
  100. package/starter-assets/lichen_rock/lichen_rock_nor_gl_512.jpg +0 -0
  101. package/starter-assets/mossy_rock/mossy_rock_ao_1k.jpg +0 -0
  102. package/starter-assets/mossy_rock/mossy_rock_diff_1k.jpg +0 -0
  103. package/starter-assets/mossy_rock/mossy_rock_nor_gl_1k.jpg +0 -0
  104. package/starter-assets/mossy_rock/mossy_rock_rough_1k.jpg +0 -0
  105. package/starter-assets/needle-atlas.png +0 -0
  106. package/starter-assets/needle-surface.png +0 -0
  107. package/starter-assets/river_small_rocks/river_small_rocks_arm_512.jpg +0 -0
  108. package/starter-assets/river_small_rocks/river_small_rocks_diff_512.jpg +0 -0
  109. package/starter-assets/river_small_rocks/river_small_rocks_nor_gl_512.jpg +0 -0
  110. package/starter-assets/rock_boulder_dry/rock_boulder_dry_arm_512.jpg +0 -0
  111. package/starter-assets/rock_boulder_dry/rock_boulder_dry_diff_512.jpg +0 -0
  112. package/starter-assets/rock_boulder_dry/rock_boulder_dry_nor_gl_512.jpg +0 -0
  113. package/starter-assets/rocks/boulder-mid.glb +0 -0
  114. package/starter-assets/rocks/boulder-near.glb +0 -0
  115. package/starter-assets/rocks/boulder-prep.json +0 -37
  116. package/starter-assets/rocks/rock01-mid.glb +0 -0
  117. package/starter-assets/rocks/rock01-near.glb +0 -0
  118. package/starter-assets/rocks/rock01-prep.json +0 -37
  119. package/starter-assets/rocks/rock04-mid.glb +0 -0
  120. package/starter-assets/rocks/rock04-near.glb +0 -0
  121. package/starter-assets/rocks/rock04-prep.json +0 -37
  122. package/starter-assets/sand_01/sand_01_ao_1k.jpg +0 -0
  123. package/starter-assets/sand_01/sand_01_diff_1k.jpg +0 -0
  124. package/starter-assets/sand_01/sand_01_nor_gl_1k.jpg +0 -0
  125. package/starter-assets/sand_01/sand_01_rough_1k.jpg +0 -0
  126. package/starter-assets/snow_02/snow_02_ao_1k.jpg +0 -0
  127. package/starter-assets/snow_02/snow_02_diff_1k.jpg +0 -0
  128. package/starter-assets/snow_02/snow_02_nor_gl_1k.jpg +0 -0
  129. package/starter-assets/snow_02/snow_02_rough_1k.jpg +0 -0
@@ -1,4 +1,4 @@
1
- import { L as Layer, O as OperationType, a as IMask, b as LayerParams, c as ITerrainConfig, d as ITerrainDocument, e as IEvaluateOptions, I as ITerrainState, f as ICopyRegionOptions } from './types-Ant8-Axc.js';
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-BpH00qsx.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?: OperationOptions<"scatter">): this;
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
@@ -1,5 +1,5 @@
1
1
  import { BufferGeometry } from 'three';
2
- import { g as IBakedMesh } from './types-Ant8-Axc.js';
2
+ import { h as IBakedMesh } from './types-BpH00qsx.js';
3
3
 
4
4
  /**
5
5
  * Converts baked arrays to ordinary geometry using the consumer's installed Three.js.
@@ -129,18 +129,34 @@ 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" | "gully" | "scree";
133
+ /** Erosion passes: thermal, scree, hydraulic, gully (default 200), or fluvial time steps (default 40). */
133
134
  readonly iterations?: number;
134
- /** Maximum stable slope in degrees. */
135
+ /**
136
+ * Maximum stable slope in degrees. `fluvial` enforces it as its landslide threshold, `scree`
137
+ * slides anything steeper (default 35; upstream's scree angle defaults to 90, which is "off").
138
+ */
135
139
  readonly talus?: number;
140
+ /** `fluvial`: rock uplift at the highest input point, m/yr (default 1e-3). Relief scales with uplift / erodibility. */
141
+ readonly uplift?: number;
142
+ /** `fluvial`: stream-power erodibility K, m^(1-2m)/yr (default 5e-6). */
143
+ readonly erodibility?: number;
144
+ /** `fluvial`: years per step (default 2e4); the implicit solver is stable at any value. */
145
+ readonly timeStep?: number;
146
+ /** `fluvial`: metres; rescales the eroded surface to this highest-minus-lowest. Omit to keep the natural relief. */
147
+ readonly relief?: number;
148
+ /** `thermal`: share of the excess a pass moves (default 0.22). `scree`: the same, default 0.05. */
136
149
  readonly rate?: number;
137
150
  readonly droplets?: number;
138
151
  readonly maxSteps?: number;
139
152
  readonly inertia?: number;
153
+ /** `hydraulic`: sediment capacity (default 4). `gully`: transport capacity Kc (default 0.05). */
140
154
  readonly capacity?: number;
141
155
  readonly erosion?: number;
142
156
  readonly deposition?: number;
143
157
  readonly evaporation?: number;
158
+ /** `gully`: metres of rain per step (default 0.0005, upstream `rain`). */
159
+ readonly rain?: number;
144
160
  }
145
161
  interface ITerraceParams extends IOperationBase {
146
162
  readonly step?: number;
@@ -165,7 +181,7 @@ interface IBiomeParams extends IBrushParams {
165
181
  readonly value?: number;
166
182
  }
167
183
  interface IScatterParams extends IOperationBase {
168
- readonly asset?: string;
184
+ readonly asset: string;
169
185
  readonly count?: number;
170
186
  /** Guaranteed within one rule, never across rules. */
171
187
  readonly minDistance?: number;
@@ -483,4 +499,4 @@ interface ISplatPng {
483
499
  interface IHeightPngMetadata extends IHeightRange {
484
500
  }
485
501
 
486
- export type { ITerraceParams as $, IGrid as A, IHeightData as B, IHeightPngMetadata as C, IHeightmapParams as D, ExportKind as E, ILayer as F, IMaterialRule as G, IMaterialsParams as H, ITerrainState as I, INoiseParams as J, IPaintParams as K, Layer as L, MaterialId as M, IPasteParams as N, OperationType as O, IPlacement 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 _, IMask as a, ITerrainInspection as a0, IWaterBody as a1, IWaterParams as a2, IWaterRule as a3, MaskSampler as a4, MaskType as a5, SplinePoint as a6, LayerParams as b, ITerrainConfig as c, ITerrainDocument as d, IEvaluateOptions as e, ICopyRegionOptions as f, IBakedMesh as g, IPlacementOverride as h, ISampledGrid as i, IBakeMeshOptions as j, IBakeTerrainOptions as k, IBakedTerrain as l, IDecodeHeightPngOptions as m, IDecodeRaw16Options as n, IHeightRange as o, IRaw16Options as p, IExportFile as q, IExportArchive as r, IBiomeParams as s, IBrushParams as t, IClearParams as u, IDecodedHeightPng as v, IErodeParams as w, IErosionMaps as x, IFlattenParams as y, IGradeParams as z };
502
+ 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,53 @@
1
+ import * as _threenative_core_world from '@threenative/core/world';
2
+ import { I as ITerrainState } from './types-BpH00qsx.js';
3
+
4
+ /** One streamed asset: its LOD0 model, its authored bounds and the levels it swaps to. */
5
+ type IWorldPackageAsset = _threenative_core_world.IWorldAsset;
6
+ /** One cell's contiguous run of placement records, eight float32 values each. */
7
+ type IWorldPackageRun = _threenative_core_world.IWorldRun;
8
+ /**
9
+ * The `world.json` contract. Its one declaration is core's (`IWorldPackage`), imported as a type so
10
+ * this addon still pulls nothing from core at runtime — a type import is erased before the bundle.
11
+ */
12
+ type IWorldPackageManifest = _threenative_core_world.IWorldPackage;
13
+ /** The splat layout to copy into a terrain table: eight material masks in two RGBA8 planes. */
14
+ interface IWorldPackageSplat {
15
+ readonly size: number;
16
+ readonly planes: number;
17
+ readonly masks: Readonly<Record<string, readonly [number, "r" | "g" | "b" | "a"]>>;
18
+ }
19
+ interface IBakeWorldPackageOptions {
20
+ /** Every asset any instance may reference. An instance outside this set fails the bake. */
21
+ readonly assets: Readonly<Record<string, IWorldPackageAsset>>;
22
+ /** Metres per streamed cell. Defaults to 64. */
23
+ readonly cellSize?: number;
24
+ /** Extra `terrain.layers` entries, e.g. `{ table: "terrain-table.json" }`. */
25
+ readonly layers?: Readonly<Record<string, string>>;
26
+ readonly names?: {
27
+ readonly heightmap?: string;
28
+ readonly placements?: string;
29
+ readonly placementIds?: string;
30
+ readonly splat?: string;
31
+ };
32
+ }
33
+ interface IBakedWorldPackage {
34
+ readonly manifest: IWorldPackageManifest;
35
+ readonly splat: IWorldPackageSplat;
36
+ /** The baked package files, keyed by the manifest names that point at them. */
37
+ readonly files: Readonly<Record<string, Uint8Array>>;
38
+ }
39
+ /**
40
+ * Bake an evaluated terrain into the engine's world package: a `world.json` manifest, a uint16
41
+ * heightmap, a splat mask array, a placement buffer of eight float32 per instance, a placement ID
42
+ * sidecar and the square cells that stream them. The encodings and row orders are the ones the Blender recipe
43
+ * `export_world.py` writes, so one runtime streams both without a second reader.
44
+ *
45
+ * @requires npm i -D @threenative/terrain
46
+ * @situation hand an evaluated Strata terrain to a game without a Blender round trip
47
+ * @constraint headless authoring; no three, no DOM, and nothing here decides how the world looks
48
+ * @example const { manifest, files } = bakeWorldPackage(state, { assets });
49
+ * @override every asset path, bound, LOD distance and cell size comes from the caller's options
50
+ */
51
+ declare function bakeWorldPackage(state: ITerrainState, options: IBakeWorldPackageOptions): IBakedWorldPackage;
52
+
53
+ 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.7",
3
+ "version": "0.1.9",
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-assets",
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.11",
73
- "@threenative/physics": "0.3.11"
86
+ "@threenative/core": "0.3.13",
87
+ "@threenative/physics": "0.3.13"
74
88
  },
75
89
  "peerDependencies": {
90
+ "@threenative/core": ">=0.3.13 <0.4.0",
91
+ "@threenative/physics": ">=0.3.13 <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
  }
@@ -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-assets/credits.json`.
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.
@@ -1,118 +1,6 @@
1
- // Bakes this folder's recipe into a self-contained world package. Run it once from your game
2
- // project, then serve the folder it writes:
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
- const here = dirname(fileURLToPath(import.meta.url));
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,134 @@
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
+ "understorey": {
18
+ "attempts": 14000,
19
+ "litter": 1,
20
+ "fern": 1,
21
+ "bush": 1,
22
+ "flower": 1,
23
+ "deadfall": 0,
24
+ "shade": 0,
25
+ "shadeRadius": 3
26
+ }
27
+ },
28
+ "foliage": [
29
+ {
30
+ "species": "spruce",
31
+ "density": 0,
32
+ "slope": [0, 32],
33
+ "height": [0, 52],
34
+ "spacing": [3.4, 3.4],
35
+ "collision": "trunk",
36
+ "stands": false,
37
+ "grassThreshold": 0.18,
38
+ "standThreshold": 0.42,
39
+ "far": null
40
+ }
41
+ ],
42
+ "grass": [
43
+ {
44
+ "species": "grass",
45
+ "density": 0,
46
+ "slope": [0, 0],
47
+ "height": null,
48
+ "spacing": 3.5,
49
+ "slopeFalloff": 0,
50
+ "heightFalloff": 28,
51
+ "mats": null,
52
+ "waterMargin": 7.5,
53
+ "beach": null,
54
+ "detailSpacing": 0.6,
55
+ "drift": {
56
+ "field": "stand",
57
+ "frequency": [2.1, 2.4],
58
+ "offset": 0,
59
+ "amplitude": 1,
60
+ "band": [0.3, 0.45]
61
+ },
62
+ "bladeScale": 0.55,
63
+ "bladeJitter": 0.5,
64
+ "scrubChance": 0.3,
65
+ "scrubScale": 0.9,
66
+ "scrubJitter": 0.6,
67
+ "scrubBush": false,
68
+ "shoreGround": false,
69
+ "cobbledBed": false
70
+ }
71
+ ],
72
+ "layers": [
73
+ {
74
+ "layer": "alpine",
75
+ "from": 0.06,
76
+ "to": 0.1
77
+ },
78
+ {
79
+ "layer": "rock",
80
+ "from": 0.02,
81
+ "to": 0.11
82
+ },
83
+ {
84
+ "layer": "treeline",
85
+ "from": 0.3,
86
+ "to": 0.55
87
+ },
88
+ {
89
+ "layer": "cap",
90
+ "from": 0.82,
91
+ "to": 1
92
+ },
93
+ {
94
+ "layer": "desertRock",
95
+ "from": 0.18,
96
+ "to": 0.48
97
+ },
98
+ {
99
+ "layer": "alpineRock",
100
+ "from": 0.06,
101
+ "to": 0.14
102
+ },
103
+ {
104
+ "layer": "alpineHollow",
105
+ "from": 0.05,
106
+ "to": 0.12
107
+ },
108
+ {
109
+ "layer": "snow",
110
+ "from": 0.6,
111
+ "to": 0.85,
112
+ "shedFrom": 0.16,
113
+ "shedTo": 0.39
114
+ }
115
+ ],
116
+ "water": [],
117
+ "spawn": {
118
+ "at": [180, -190],
119
+ "cameraOffset": [28, 24, 42],
120
+ "focus": [180, -190]
121
+ },
122
+ "species": ["boulder", "grass", "mountain", "riverrock", "sapling", "scree", "scrub", "spruce"],
123
+ "aliases": [
124
+ "alpine",
125
+ "mountain",
126
+ "mountains",
127
+ "snowy",
128
+ "peaks",
129
+ "alps",
130
+ "glacier",
131
+ "glaciers",
132
+ "snow"
133
+ ]
134
+ }
Binary file