@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
package/AGENT_GUIDE.md CHANGED
@@ -79,6 +79,18 @@ t.materials({ id: 'surfaces', base: 'grass', rules: [
79
79
  t.paint({ id: 'camp-dirt', at: [-70,50], radius: 27, material: 'dirt', strength: .9 });
80
80
  ```
81
81
 
82
+ ## Realistic mountains and environments
83
+
84
+ Start from a kind, not from noise. `landform(kind, { size, resolution, seed, relief })` returns an ordinary `Terrain` with a calibrated recipe: `alpine`, `temperateMountains`, `rollingHills`, `desertMesa`, `coastalCliffs`, `tundra`, `volcanic`. `LANDFORMS[kind]` names the real reference landscape and the measured targets. It decides shape only, never material or colour. Calibrated at size 5000, resolution 513; other sizes keep slopes and scale relief with `size`. `relief` (metres, highest minus lowest) defaults to the kind's real ratio times `size`.
85
+
86
+ ```js
87
+ import { landform, terrainStats } from '@threenative/terrain';
88
+ const state = landform('alpine', { seed: 4 }).evaluate(); // build script, about 1.5 s at 513
89
+ terrainStats(state.height, state.resolution, state.size); // relief, slopes, hypsometry, curvature kurtosis
90
+ ```
91
+
92
+ `erode({ method: 'fluvial' })` is the engine behind it: stream-power incision with uplift (Braun & Willett 2013, Cordonnier et al. 2016). The earlier layers are the uplift envelope; it cuts dendritic valleys and sharp divides that droplet erosion at game resolution does not. Params: `iterations` (default 40), `uplift` m/yr, `erodibility` K, `timeStep` yr, `talus` landslide threshold, `relief` metres. Follow it with a short `thermal` pass and `smooth` to remove the 8-neighbour grain. Bake a backdrop: `node packages/terrain/scripts/bake-horizon.mjs alpine --seed 4 --out alpine-horizon.json`.
93
+
82
94
  ## Roads, rivers and water
83
95
 
84
96
  A road, river or ramp **grades itself to the ground it crosses** when a control point leaves its elevation out (`null`, or `NaN` in code) or when it sets `followTerrain: true`. The elevation is sampled along the centreline, low-passed along arc length, then held inside `maxGrade` (default 0.12) and `maxCut`/`maxFill` (default 2.5 m / 1.5 m); the shoulder widens into a batter with the cut or fill, so a corridor never stands on a retaining step. Leaving the ground is the hard limit: where the ground itself is steeper than `maxGrade`, the road is steep too. Absolute elevations are still honoured exactly, so existing documents keep their meaning. Horizontal spline interpolation is Catmull–Rom; vertical interpolation is linear between controls to avoid vertical overshoot. Use `smooth:false` for a polyline.
@@ -169,11 +181,11 @@ panel that calls the same code. A write names `baseRevision`; a stale one is a 4
169
181
 
170
182
  ## Resolved static-world GLB
171
183
 
172
- Import `exportWorldGLB` from `@threenative/terrain/export` in browser authoring source. Its import is DOM-free; encoding requires FileReader and canvas. Root and `/three` remain headless. This entry uses the installed Three.js GLTFExporter rather than a terrain-specific loader format.
184
+ Import `prepareWorldGLTF` from `@threenative/terrain/export` in browser authoring source. Its import is DOM-free; scene preparation requires FileReader and canvas. Root and `/three` remain headless. This entry uses the installed Three.js GLTFExporter to prepare glTF JSON; the Node assets cook owns GLB encoding.
173
185
 
174
186
  ```ts
175
- import { exportWorldGLB } from '@threenative/terrain/export';
176
- const output = await exportWorldGLB({
187
+ import { prepareWorldGLTF } from '@threenative/terrain/export';
188
+ const prepared = await prepareWorldGLTF({
177
189
  revision, // accepted document's 64-character content hash
178
190
  snapshotTime, // finite seconds, pinned across all baked deformations
179
191
  state, // evaluated committed recipe with applied override records
@@ -182,7 +194,10 @@ const output = await exportWorldGLB({
182
194
  transforms, // Map<placementId, Matrix4>: actual final grounded root matrices
183
195
  water, // [{ id, object, time: snapshotTime, staleFrames: 0 }]
184
196
  });
185
- // output.bytes is the self-contained world.glb; persist only after success.
197
+ // Send prepared.json to your Node authoring process, then:
198
+ // import { cookTerrainWorld } from '@threenative/assets';
199
+ // const { worldGlb } = await cookTerrainWorld({ preparedWorld: prepared.json });
200
+ // worldGlb is the self-contained world.glb; persist only after success.
186
201
  ```
187
202
 
188
203
  Game source owns all geometry, materials and images. The terrain needs albedo `map`, `normalMap`, `roughnessMap` and `aoMap`; vertex colours alone are insufficient. MeshStandardMaterial metallic/roughness surfaces are supported. Colour/emissive images are sRGB, data maps are NoColorSpace. Supply decoded byte images (at most 16 megapixels); DataTexture images need complete RGBA bytes. Bake alpha into the colour image. Bake displacement, bump/light maps, node shaders, skinning/morphing and wind into the supplied static geometry/material first. Use tangent-space normal maps with equal X/Y scale magnitudes; bake object-space/anisotropic maps first. MeshPhysicalMaterial extensions are outside this bounded encoder's contract.
@@ -1,7 +1,10 @@
1
- import { P as PatchCommand } from '../terrain-gPnkCU6S.js';
2
- import { I as ITerrainState } from '../types-Ant8-Axc.js';
3
- import { I as IAuthoringDocument, a as ISavedCamera, b as IFocusRequest, c as IFocusOutcome, d as IFocusBounds, e as IEnvironment, f as IEditorActivation, g as IEditorSnapshot, h as ISpatialQuery, i as ISpatialObservation, j as ICameraOperation, k as ICameraResult, l as IEnvironmentOperation, m as IEnvironmentResult, n as IAssetOperation, o as IAssetResult } from '../server-ByM2hmYJ.js';
4
- export { p as IAssetAdjust, q as IAssetBounds, r as IAssetKind, s as IAssetLimits, t as ICameraPose, u as ICameraSet, v as IFocusFraming, w as IFocusResolver, x as IFocusTarget, y as IHexColour, z as IPointObservation, A as IProfileObservation, B as IProfileSample, C as IProjectAsset, D as IReferenceObservation, E as ISavedSpatialReference, F as ISpatialControlPoint, G as ISpatialReference, H as ISurfaceMapping, J as ISurfaceMappings, K as ISurfaceReading, L as checkEnvironmentAssets, M as focusCamera, N as inspectSpatial, O as probeTerrain, P as runCameraOperation, Q as runEnvironmentOperation, R as sniff, S as surfaceSpace, T as validateAsset, U as validateAssets, V as validateCamera, W as validateCameras, X as validateEnvironment, Y as validateSpatialReference, Z as validateSurfaces } from '../server-ByM2hmYJ.js';
1
+ import { P as PatchCommand } from '../terrain-CAEaW0mQ.js';
2
+ import { L as Layer, i as IPlacementOverride, I as ITerrainState } from '../types-BpH00qsx.js';
3
+ import { I as IEditorSnapshot, a as IAuthoringDocument, b as ISavedCamera, c as IFocusRequest, d as IFocusOutcome, e as IFocusBounds, f as IEnvironment, g as IEditorActivation, h as ISpatialQuery, i as ISpatialObservation, j as ICameraOperation, k as ICameraResult, l as IEnvironmentOperation, m as IEnvironmentResult, n as IAssetOperation, o as IAssetResult } from '../server-B5RdvEAC.js';
4
+ export { p as IAssetAdjust, q as IAssetBounds, r as IAssetKind, s as IAssetLimits, t as ICameraPose, u as ICameraSet, v as IFocusFraming, w as IFocusResolver, x as IFocusTarget, y as IHexColour, z as IPointObservation, A as IProfileObservation, B as IProfileSample, C as IProjectAsset, D as IReferenceObservation, E as ISavedSpatialReference, F as ISpatialControlPoint, G as ISpatialReference, H as ISurfaceMapping, J as ISurfaceMappings, K as ISurfaceReading, L as checkEnvironmentAssets, M as focusCamera, N as inspectSpatial, O as probeTerrain, P as runCameraOperation, Q as runEnvironmentOperation, R as sniff, S as surfaceSpace, T as validateAsset, U as validateAssets, V as validateCamera, W as validateCameras, X as validateEnvironment, Y as validateSpatialReference, Z as validateSurfaces } from '../server-B5RdvEAC.js';
5
+ import * as three from 'three';
6
+ import { Quaternion, Vector3, Camera, Vector2, Object3D, Intersection, Mesh, Matrix4 } from 'three';
7
+ import { TransformControls } from 'three/addons/controls/TransformControls.js';
5
8
  import 'vite';
6
9
 
7
10
  /**
@@ -51,6 +54,214 @@ declare function inspectImage(bytes: Uint8Array, format: string, limits: {
51
54
  maxDimension: number;
52
55
  }): IImageReport;
53
56
 
57
+ /** A range bar over a number. */
58
+ interface ITweakRange {
59
+ readonly value: number;
60
+ readonly min: number;
61
+ readonly max: number;
62
+ /** The bar's step and the snapshot's rounding. Default: a hundredth of the range. */
63
+ readonly step?: number;
64
+ /** A heading drawn above the first knob that names it. */
65
+ readonly group?: string;
66
+ }
67
+ /** A picker over an sRGB hex colour. */
68
+ interface ITweakColor {
69
+ readonly color: number;
70
+ readonly group?: string;
71
+ }
72
+ /** One knob of a tweak box. */
73
+ type TweakKnob = ITweakRange | ITweakColor;
74
+ /** The page, the store and the clipboard a tweak box uses. A test passes its own. */
75
+ interface ITweakHost {
76
+ readonly document?: Document;
77
+ readonly storage?: Pick<Storage, "getItem" | "setItem" | "removeItem">;
78
+ readonly copy?: (text: string) => void;
79
+ }
80
+ interface ITweakBoxOptions<K extends string> {
81
+ /** The box's heading, and the `tweaks` name written into a snapshot. */
82
+ readonly title: string;
83
+ readonly knobs: Readonly<Record<K, TweakKnob>>;
84
+ /** Called once per knob when the box is made, with the stored or default value, and on each change. */
85
+ readonly onChange: (name: K, value: number, values: Readonly<Record<K, number>>) => void;
86
+ /** Where the values survive a reload (`localStorage`). Absent, nothing is stored. */
87
+ readonly storageKey?: string;
88
+ readonly host?: ITweakHost;
89
+ }
90
+ interface ITweakBox<K extends string> {
91
+ /** The live values: a number per knob, a colour as its sRGB hex number. */
92
+ readonly values: Readonly<Record<K, number>>;
93
+ /** Set one knob as its bar would. Throws on a value outside the knob's range. */
94
+ set(name: K, value: number): void;
95
+ /** The values as JSON text: numbers at their step, colours as `#rrggbb`. This is what Copy copies. */
96
+ snapshot(): string;
97
+ /** Put every knob back to the value its spec names, and forget the stored ones. */
98
+ reset(): void;
99
+ dispose(): void;
100
+ }
101
+ /**
102
+ * A box of range bars and colour pickers over the running game, for tuning numbers by eye.
103
+ *
104
+ * The game names its knobs and applies each change itself; the box owns the page elements, the
105
+ * stored values and the Copy button, whose JSON is what gets pasted back and written into the game's
106
+ * own source. With no `document` (a native launch, a test) it draws nothing and still holds the
107
+ * values, so the game code that reads them is the same on every target.
108
+ *
109
+ * @situation tune look numbers by eye with live range bars and colour pickers while the game runs
110
+ * @requires npm i -D @threenative/terrain
111
+ * @example const box = createTweakBox({ title: "Fog", knobs: { density: { min: 0, max: 0.1, value: 0.02 } }, onChange: (name, value) => console.info(name, value) });
112
+ */
113
+ declare function createTweakBox<K extends string>(options: ITweakBoxOptions<K>): ITweakBox<K>;
114
+
115
+ /**
116
+ * Recipe footprints are heights over X/Z, never independently transformed solids.
117
+ * @requires npm i -D @threenative/terrain
118
+ * @situation derive a terrain-editor gizmo pose from a landform layer
119
+ * @constraint the caller supplies world and default footprint sizes; unsupported layers return undefined
120
+ * @example const pose = landformPose(layer, terrain.size, footprintSize);
121
+ */
122
+ declare function landformPose(layer: Layer, worldSize: number, defaultSize: number): {
123
+ position: [number, number, number];
124
+ quaternion: Quaternion;
125
+ scale: [number, number, number];
126
+ rectangular: boolean;
127
+ } | undefined;
128
+ /**
129
+ * Convert a terrain-editor gizmo pose into a heightfield landform footprint.
130
+ * @requires npm i -D @threenative/terrain
131
+ * @situation apply a terrain-editor gizmo transform to a landform layer
132
+ * @constraint finite coordinates and positive scales are required; X/Z rotations that overhang throw
133
+ * @example const next = transformedLandform(layer, position, quaternion, scale, surfaceHeight);
134
+ */
135
+ declare function transformedLandform(layer: Layer, position: Vector3, quaternion: Quaternion, scale: Vector3, anchor: number): Layer;
136
+
137
+ type EditorRaycast = (options: {
138
+ screen?: Vector2;
139
+ origin?: Vector3;
140
+ direction?: Vector3;
141
+ targets: readonly Object3D[];
142
+ }) => Intersection | undefined;
143
+ /**
144
+ * Convert viewport client coordinates once; the installed picker owns ray intersection.
145
+ * @requires npm i -D @threenative/terrain
146
+ * @situation pick a terrain-editor surface from viewport client coordinates
147
+ * @constraint the caller supplies the raycast implementation and ordered targets
148
+ * @example const hit = pickEditorSurface(ctx, [terrainMesh], event.clientX, event.clientY);
149
+ */
150
+ declare function pickEditorSurface(ctx: {
151
+ renderer: {
152
+ domElement: {
153
+ getBoundingClientRect(): {
154
+ left: number;
155
+ top: number;
156
+ };
157
+ };
158
+ };
159
+ raycast: EditorRaycast;
160
+ }, targets: readonly Object3D[], clientX: number, clientY: number): Intersection<Object3D<three.Object3DEventMap>> | undefined;
161
+ /**
162
+ * Query the rendered heightfield, including its triangulation rather than an interpolated bake.
163
+ * @requires npm i -D @threenative/terrain
164
+ * @situation query terrain-editor surface elevation at world X/Z coordinates
165
+ * @constraint the supplied mesh and raycast determine the surface; missing intersections return undefined
166
+ * @example const height = editorSurfaceHeight(ctx, terrainMesh, x, z);
167
+ */
168
+ declare function editorSurfaceHeight(ctx: {
169
+ raycast: EditorRaycast;
170
+ }, mesh: Mesh, x: number, z: number, originHeight?: number): number | undefined;
171
+ /**
172
+ * A foreground terrain hit occludes placements; matching uses the evaluated world position.
173
+ * @requires npm i -D @threenative/terrain
174
+ * @situation pick a placed instance in the terrain editor from viewport client coordinates
175
+ * @constraint the caller supplies the raycast context, terrain mesh, instanced meshes and evaluated placements
176
+ * @example const id = pickEditorPlacement(ctx, terrainMesh, meshes, placements, event.clientX, event.clientY);
177
+ */
178
+ declare function pickEditorPlacement(ctx: Parameters<typeof pickEditorSurface>[0], terrain: Mesh, meshes: readonly Object3D[], placements: Iterable<{
179
+ pose: Matrix4;
180
+ placement: {
181
+ id: string;
182
+ };
183
+ }>, clientX: number, clientY: number): string | undefined;
184
+ /**
185
+ * Project an injected world point to client pixels in the caller's viewport.
186
+ * @requires npm i -D @threenative/terrain
187
+ * @situation convert a terrain-editor world point to viewport client pixels
188
+ * @constraint the point is projected in place; pass a clone to keep the original
189
+ * @example const [x, y] = editorPointToClient(point.clone(), camera, canvas.getBoundingClientRect());
190
+ */
191
+ declare function editorPointToClient(point: Vector3, camera: Camera, box: {
192
+ width: number;
193
+ height: number;
194
+ left: number;
195
+ top: number;
196
+ }): [number, number];
197
+ /**
198
+ * Transform the caller's measured geometry centre into the evaluated placement's world space.
199
+ * @requires npm i -D @threenative/terrain
200
+ * @situation find the world-space centre of a placed terrain-editor instance
201
+ * @constraint the point is multiplied in place; the pose needs finite position, quaternion and scale
202
+ * @example const centre = editorPlacementCenter(localCentre.clone(), placement);
203
+ */
204
+ declare function editorPlacementCenter(point: Vector3, pose: IPlacementOverride): Vector3;
205
+
206
+ /**
207
+ * Gesture and transaction mechanics; the caller owns the controls, proxy and all rendering.
208
+ * @requires npm i -D @threenative/terrain
209
+ * @situation drive terrain-editor selection, gizmo drags, undo and saved transactions
210
+ * @constraint the caller supplies the TransformControls, proxy, controller and every drawing callback
211
+ * @example const selection = createEditorSelection({ gizmo, proxy, controller, grounding, surface, defaultFootprintSize, refreshPose, drawFootprint, restorePlacement, previewPlacement, setSaving, selectedChanged, setNavigation, message });
212
+ */
213
+ declare function createEditorSelection({ gizmo, proxy, controller, grounding, surface, defaultFootprintSize, refreshPose, drawFootprint, restorePlacement, previewPlacement, setSaving, selectedChanged, setNavigation, message, }: {
214
+ gizmo: TransformControls;
215
+ proxy: Object3D;
216
+ controller: Pick<TerrainEditorController, "commit" | "snapshot">;
217
+ grounding(): boolean;
218
+ surface(x: number, z: number): number | undefined;
219
+ defaultFootprintSize: number;
220
+ refreshPose(): void;
221
+ drawFootprint(layer: Layer): void;
222
+ restorePlacement(id: string, value: IPlacementOverride | undefined): void;
223
+ previewPlacement(id: string, value: IPlacementOverride): void;
224
+ setSaving(value: boolean): void;
225
+ selectedChanged(id: string | undefined, isLayer: boolean): void;
226
+ setNavigation(value: boolean): void;
227
+ message(text: string): void;
228
+ }): {
229
+ readonly snapshot: IEditorSnapshot | undefined;
230
+ readonly selected: string | undefined;
231
+ readonly selectedLayer: string | undefined;
232
+ readonly anchor: number;
233
+ readonly layerDraft: Layer | undefined;
234
+ readonly active: boolean;
235
+ readonly drag: {
236
+ id: string;
237
+ base: IEditorSnapshot;
238
+ grounding: boolean;
239
+ layer?: Layer;
240
+ anchor: number;
241
+ } | undefined;
242
+ readonly saving: boolean;
243
+ readonly draft: {
244
+ id: string;
245
+ transform: IPlacementOverride;
246
+ } | undefined;
247
+ applyPose: (layer?: Layer, placement?: IPlacementOverride) => number[] | undefined;
248
+ save: (id: string, value: IPlacementOverride | undefined, base?: IEditorSnapshot | undefined, remember?: boolean) => Promise<void>;
249
+ select: (id: string | undefined, isLayer?: boolean) => void;
250
+ undo: () => Promise<void>;
251
+ applyFields: (values: number[], grounded: boolean) => void;
252
+ reassign(id: string): Promise<void>;
253
+ clearDrafts(): void;
254
+ cancel(): void;
255
+ canPick(event: {
256
+ button: number;
257
+ altKey: boolean;
258
+ }): boolean;
259
+ dispose(): void;
260
+ selectLayer(id: string): void;
261
+ setActive(enabled: boolean): void;
262
+ sync(next: IEditorSnapshot, matchesPreview: boolean): void;
263
+ };
264
+
54
265
  /** The live view's own camera surface, shared by the GUI list and a controller. */
55
266
  interface IViewCamera {
56
267
  /** The actual current viewer pose, not the last saved bookmark. */
@@ -205,6 +416,8 @@ declare class TerrainEditorController {
205
416
  baseRevision: string;
206
417
  commands: readonly PatchCommand[];
207
418
  }): Promise<IEditorSnapshot>;
419
+ reload(): Promise<IEditorSnapshot>;
420
+ restoreLastValid(): Promise<IEditorSnapshot>;
208
421
  subscribe(listener: (snapshot: IEditorSnapshot) => void, onError: () => void): () => void;
209
422
  }
210
423
  /**
@@ -228,4 +441,4 @@ declare function mountTerrainEditor(options: {
228
441
  dispose(): void;
229
442
  }>;
230
443
 
231
- export { IAssetOperation, IAssetResult, ICameraOperation, ICameraResult, type IEditorView, IEnvironment, IEnvironmentOperation, IEnvironmentResult, IFocusBounds, IFocusOutcome, IFocusRequest, type IImageReport, ISavedCamera, ISpatialObservation, ISpatialQuery, type ISurfaceChannel, type IViewCamera, type IViewEnvironment, type IViewerPose, SURFACE_CHANNELS, TerrainEditorController, inspectImage, mountTerrainEditor };
444
+ export { IAssetOperation, IAssetResult, ICameraOperation, ICameraResult, type IEditorView, IEnvironment, IEnvironmentOperation, IEnvironmentResult, IFocusBounds, IFocusOutcome, IFocusRequest, type IImageReport, ISavedCamera, ISpatialObservation, ISpatialQuery, type ISurfaceChannel, type ITweakBox, type ITweakBoxOptions, type ITweakColor, type ITweakHost, type ITweakRange, type IViewCamera, type IViewEnvironment, type IViewerPose, SURFACE_CHANNELS, TerrainEditorController, type TweakKnob, createEditorSelection, createTweakBox, editorPlacementCenter, editorPointToClient, editorSurfaceHeight, inspectImage, landformPose, mountTerrainEditor, pickEditorPlacement, pickEditorSurface, transformedLandform };