@threenative/terrain 0.1.11 → 0.1.12

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 (218) hide show
  1. package/README.md +1 -0
  2. package/dist/bake-DJ5cxg0C.d.ts +82 -0
  3. package/dist/editor/index.d.ts +4 -4
  4. package/dist/editor/index.js +1 -1
  5. package/dist/editor/server.d.ts +2 -2
  6. package/dist/editor/worker.d.ts +1 -1
  7. package/dist/editor/worker.js +1 -1
  8. package/dist/export.d.ts +1 -1
  9. package/dist/index.d.ts +51 -222
  10. package/dist/index.js +111 -2
  11. package/dist/kit-world.d.ts +107 -0
  12. package/dist/kit-world.js +5134 -0
  13. package/dist/kit.d.ts +21 -4
  14. package/dist/kit.js +19 -4
  15. package/dist/mcp/cook-child.js +9 -6
  16. package/dist/mcp/server.js +14 -4
  17. package/dist/prop-package-Dwz0EWoB.d.ts +141 -0
  18. package/dist/{server-B5RdvEAC.d.ts → server-LnFwY8sr.d.ts} +1 -1
  19. package/dist/starter.d.ts +1141 -6
  20. package/dist/starter.js +1999 -17
  21. package/dist/{terrain-CAEaW0mQ.d.ts → terrain-DYCyAOCJ.d.ts} +1 -1
  22. package/dist/three.d.ts +1 -1
  23. package/dist/{types-BpH00qsx.d.ts → types-kpI0C4hW.d.ts} +1 -1
  24. package/dist/{world-package-B8QgHjAQ.d.ts → world-package-DqJC3-Nn.d.ts} +2 -2
  25. package/docs/authoring/new-environment.md +97 -0
  26. package/package.json +8 -8
  27. package/starter/alpine/README.md +22 -14
  28. package/starter/alpine/bake.mjs +14 -1
  29. package/starter/alpine/biome.data.json +187 -25
  30. package/starter/alpine/heightmap.r16 +0 -0
  31. package/starter/alpine/playerRig.ts +89 -0
  32. package/starter/alpine/recipe.json +169 -15
  33. package/starter/alpine/render/bakedFile.ts +17 -0
  34. package/starter/alpine/render/benchmark.ts +77 -0
  35. package/starter/alpine/render/biomeData.ts +14 -0
  36. package/starter/alpine/render/biomes.ts +687 -0
  37. package/starter/alpine/render/ground/cover.ts +565 -0
  38. package/starter/alpine/render/ground/horizon.ts +219 -0
  39. package/starter/alpine/render/ground/palette.d.ts +1 -0
  40. package/starter/alpine/render/ground/palette.js +11 -0
  41. package/starter/alpine/render/ground/scatter.ts +104 -0
  42. package/starter/alpine/render/ground/terrain.ts +1860 -0
  43. package/starter/alpine/render/kitAssets.ts +28 -0
  44. package/starter/alpine/render/loading.ts +354 -0
  45. package/starter/alpine/render/lookKnobs.ts +37 -0
  46. package/starter/alpine/render/orbitCamera.ts +155 -0
  47. package/starter/alpine/render/props/farForest.ts +94 -0
  48. package/starter/alpine/render/props/pack.ts +1114 -0
  49. package/starter/alpine/render/props/prepared.ts +225 -0
  50. package/starter/alpine/render/props/propMaterials.ts +1239 -0
  51. package/starter/alpine/render/props/propProgress.ts +2 -0
  52. package/starter/alpine/render/props/propWorld.ts +105 -0
  53. package/starter/alpine/render/props/props.ts +633 -0
  54. package/starter/alpine/render/props/spruce.ts +440 -0
  55. package/starter/alpine/render/sky/atmosphere.ts +329 -0
  56. package/starter/alpine/render/sky/sky.ts +382 -0
  57. package/starter/alpine/render/texturePreparation.ts +135 -0
  58. package/starter/alpine/render/water/river.ts +1132 -0
  59. package/starter/alpine/render/worldNames.ts +6 -0
  60. package/starter/alpine/scene.ts +715 -0
  61. package/starter/alpine/sceneProps.ts +561 -0
  62. package/starter/alpine/sceneState.ts +33 -0
  63. package/starter/alpine/world/terrainAssets.ts +145 -0
  64. package/starter/alpine/world/walkBand.ts +47 -0
  65. package/starter/alpine/world/water.ts +74 -0
  66. package/starter/alpine/worlds.ts +13 -0
  67. package/starter/coastal/README.md +26 -27
  68. package/starter/coastal/assets.json +10 -0
  69. package/starter/coastal/bake.mjs +14 -1
  70. package/starter/coastal/biome.data.json +18 -3
  71. package/starter/coastal/playerRig.ts +89 -0
  72. package/starter/coastal/recipe.json +220 -18
  73. package/starter/coastal/render/bakedFile.ts +17 -0
  74. package/starter/coastal/render/benchmark.ts +81 -0
  75. package/starter/coastal/render/biomeData.ts +14 -0
  76. package/starter/coastal/render/biomes.ts +678 -0
  77. package/starter/coastal/render/ground/cover.ts +565 -0
  78. package/starter/coastal/render/ground/horizon.ts +219 -0
  79. package/starter/coastal/render/ground/palette.d.ts +1 -0
  80. package/starter/coastal/render/ground/palette.js +11 -0
  81. package/starter/coastal/render/ground/scatter.ts +104 -0
  82. package/starter/coastal/render/ground/terrain.ts +1829 -0
  83. package/starter/coastal/render/kitAssets.ts +28 -0
  84. package/starter/coastal/render/loading.ts +354 -0
  85. package/starter/coastal/render/lookKnobs.ts +37 -0
  86. package/starter/coastal/render/orbitCamera.ts +155 -0
  87. package/starter/coastal/render/props/farForest.ts +94 -0
  88. package/starter/coastal/render/props/pack.ts +1109 -0
  89. package/starter/coastal/render/props/prepared.ts +225 -0
  90. package/starter/coastal/render/props/propMaterials.ts +1239 -0
  91. package/starter/coastal/render/props/propProgress.ts +2 -0
  92. package/starter/coastal/render/props/propWorld.ts +105 -0
  93. package/starter/coastal/render/props/props.ts +633 -0
  94. package/starter/coastal/render/props/spruce.ts +440 -0
  95. package/starter/coastal/render/sky/atmosphere.ts +329 -0
  96. package/starter/coastal/render/sky/sky.ts +382 -0
  97. package/starter/coastal/render/texturePreparation.ts +135 -0
  98. package/starter/coastal/render/water/ocean.ts +284 -0
  99. package/starter/coastal/render/water/river.ts +1132 -0
  100. package/starter/coastal/render/worldNames.ts +6 -0
  101. package/starter/coastal/scene.ts +740 -0
  102. package/starter/coastal/sceneProps.ts +559 -0
  103. package/starter/coastal/sceneState.ts +33 -0
  104. package/starter/coastal/world/terrainAssets.ts +151 -0
  105. package/starter/coastal/world/walkBand.ts +47 -0
  106. package/starter/coastal/world/water.ts +74 -0
  107. package/starter/coastal/worlds.ts +13 -0
  108. package/starter/desert/README.md +51 -25
  109. package/starter/desert/bake-flora.mjs +142 -0
  110. package/starter/desert/bake-rocks.mjs +291 -0
  111. package/starter/desert/bake.mjs +14 -1
  112. package/starter/desert/biome.data.json +24 -12
  113. package/starter/desert/playerRig.ts +89 -0
  114. package/starter/desert/recipe.json +63 -16
  115. package/starter/desert/render/bakedFile.ts +17 -0
  116. package/starter/desert/render/benchmark.ts +79 -0
  117. package/starter/desert/render/biomeData.ts +14 -0
  118. package/starter/desert/render/biomes.ts +660 -0
  119. package/starter/desert/render/ground/cover.ts +565 -0
  120. package/starter/desert/render/ground/debris.ts +136 -0
  121. package/starter/desert/render/ground/horizon.ts +219 -0
  122. package/starter/desert/render/ground/palette.d.ts +1 -0
  123. package/starter/desert/render/ground/palette.js +11 -0
  124. package/starter/desert/render/ground/scatter.ts +104 -0
  125. package/starter/desert/render/ground/terrain.ts +1854 -0
  126. package/starter/desert/render/kitAssets.ts +28 -0
  127. package/starter/desert/render/loading.ts +354 -0
  128. package/starter/desert/render/lookKnobs.ts +37 -0
  129. package/starter/desert/render/orbitCamera.ts +155 -0
  130. package/starter/desert/render/props/farForest.ts +96 -0
  131. package/starter/desert/render/props/formations.ts +630 -0
  132. package/starter/desert/render/props/pack.ts +1195 -0
  133. package/starter/desert/render/props/prepared.ts +225 -0
  134. package/starter/desert/render/props/propMaterials.ts +1255 -0
  135. package/starter/desert/render/props/propProgress.ts +2 -0
  136. package/starter/desert/render/props/propWorld.ts +105 -0
  137. package/starter/desert/render/props/props.ts +624 -0
  138. package/starter/desert/render/props/spruce.ts +440 -0
  139. package/starter/desert/render/sand.ts +581 -0
  140. package/starter/desert/render/sky/atmosphere.ts +329 -0
  141. package/starter/desert/render/sky/sky.ts +382 -0
  142. package/starter/desert/render/texturePreparation.ts +135 -0
  143. package/starter/desert/render/water/river.ts +1132 -0
  144. package/starter/desert/render/worldNames.ts +6 -0
  145. package/starter/desert/scene.ts +748 -0
  146. package/starter/desert/sceneProps.ts +562 -0
  147. package/starter/desert/sceneState.ts +33 -0
  148. package/starter/desert/world/terrainAssets.ts +162 -0
  149. package/starter/desert/world/walkBand.ts +47 -0
  150. package/starter/desert/world/water.ts +74 -0
  151. package/starter/desert/worlds.ts +13 -0
  152. package/starter/forest/README.md +8 -5
  153. package/starter/forest/bake.mjs +21 -413
  154. package/starter/forest/playerRig.ts +37 -171
  155. package/starter/forest/recipe.json +237 -47
  156. package/starter/forest/render/biomes.ts +2 -1
  157. package/starter/forest/render/ground/horizon.ts +4 -302
  158. package/starter/forest/render/ground/terrain.ts +14 -32
  159. package/starter/forest/render/kitAssets.ts +3 -2
  160. package/starter/forest/render/props/farForest.ts +2 -1
  161. package/starter/forest/render/props/pack.ts +4 -2
  162. package/starter/forest/render/props/prepared.ts +2 -1
  163. package/starter/forest/render/props/propProgress.ts +1 -11
  164. package/starter/forest/render/props/propWorld.ts +48 -662
  165. package/starter/forest/render/props/props.ts +64 -248
  166. package/starter/forest/render/sky/sky.ts +2 -1
  167. package/starter/forest/render/worldNames.ts +6 -2
  168. package/starter/forest/scene.ts +34 -25
  169. package/starter/forest/sceneProps.ts +2 -2
  170. package/starter/forest/sceneState.ts +5 -4
  171. package/starter/forest/surface.json +2 -2
  172. package/starter/forest/worlds.ts +3 -2
  173. package/starter/tundra/README.md +35 -16
  174. package/starter/tundra/bake.mjs +14 -1
  175. package/starter/tundra/biome.data.json +6 -6
  176. package/starter/tundra/playerRig.ts +89 -0
  177. package/starter/tundra/recipe.json +111 -110
  178. package/starter/tundra/render/bakedFile.ts +17 -0
  179. package/starter/tundra/render/benchmark.ts +79 -0
  180. package/starter/tundra/render/biomeData.ts +14 -0
  181. package/starter/tundra/render/biomes.ts +714 -0
  182. package/starter/tundra/render/ground/cover.ts +565 -0
  183. package/starter/tundra/render/ground/horizon.ts +219 -0
  184. package/starter/tundra/render/ground/palette.d.ts +1 -0
  185. package/starter/tundra/render/ground/palette.js +11 -0
  186. package/starter/tundra/render/ground/scatter.ts +104 -0
  187. package/starter/tundra/render/ground/terrain.ts +1874 -0
  188. package/starter/tundra/render/kitAssets.ts +28 -0
  189. package/starter/tundra/render/loading.ts +354 -0
  190. package/starter/tundra/render/lookKnobs.ts +37 -0
  191. package/starter/tundra/render/orbitCamera.ts +155 -0
  192. package/starter/tundra/render/props/farForest.ts +96 -0
  193. package/starter/tundra/render/props/pack.ts +1088 -0
  194. package/starter/tundra/render/props/prepared.ts +225 -0
  195. package/starter/tundra/render/props/propMaterials.ts +1247 -0
  196. package/starter/tundra/render/props/propProgress.ts +2 -0
  197. package/starter/tundra/render/props/propWorld.ts +105 -0
  198. package/starter/tundra/render/props/props.ts +624 -0
  199. package/starter/tundra/render/props/spruce.ts +440 -0
  200. package/starter/tundra/render/sky/atmosphere.ts +329 -0
  201. package/starter/tundra/render/sky/sky.ts +382 -0
  202. package/starter/tundra/render/texturePreparation.ts +135 -0
  203. package/starter/tundra/render/water/river.ts +1132 -0
  204. package/starter/tundra/render/worldNames.ts +6 -0
  205. package/starter/tundra/scene.ts +715 -0
  206. package/starter/tundra/sceneProps.ts +559 -0
  207. package/starter/tundra/sceneState.ts +33 -0
  208. package/starter/tundra/world/terrainAssets.ts +159 -0
  209. package/starter/tundra/world/walkBand.ts +47 -0
  210. package/starter/tundra/world/water.ts +74 -0
  211. package/starter/tundra/worlds.ts +13 -0
  212. package/starter-assets.json +4 -4
  213. package/starter-credits.json +613 -10
  214. package/starter/forest/diagnostics.ts +0 -1020
  215. package/starter/forest/render/sky/skyVisibility.ts +0 -121
  216. package/starter/forest/spawnGate.ts +0 -183
  217. package/starter/forest/viewStatistics.ts +0 -47
  218. package/starter/forest/world/streamedGround.ts +0 -139
package/dist/starter.d.ts CHANGED
@@ -1,8 +1,12 @@
1
- import { IComputeDriven, ICtx } from '@threenative/core';
2
- import { IWorldPackage, WorldCells, Heightfield, IWorldCellsLoadOptions } from '@threenative/core/world';
3
- import { RigidBody3D, IPhysicsContext } from '@threenative/physics';
4
- import { Object3D, Material, Mesh, Texture, MeshStandardMaterial, Color } from 'three';
5
- import { i as IPlacementOverride } from './types-BpH00qsx.js';
1
+ import { ICtx, IRaycastOptions, IFrameBudgetWindow, IAssetLoader, SkeletalMesh3D, IComputeDriven } from '@threenative/core';
2
+ import { IWorldPackage, HeightfieldCollar, TerrainTiles, WorldCells, IWorldCellsFollow, IShadowRegion, Heightfield, IWorldCellsLoadOptions } from '@threenative/core/world';
3
+ import { IPhysicsContext, CharacterBody3D, RigidBody3D } from '@threenative/physics';
4
+ import * as three from 'three';
5
+ import { Vector2, Object3D, Intersection, InstancedMesh, Mesh, Vector3, PerspectiveCamera, Box3, Material, Matrix4, BufferGeometry, Camera, AnimationClip, Texture, MeshStandardMaterial, Color } from 'three';
6
+ import { m as IPlacementOverride, h as IPlacement } from './types-kpI0C4hW.js';
7
+ import { UniformNode, Node, MeshStandardNodeMaterial } from 'three/webgpu';
8
+ import { I as IPropBucketKind, a as IPropPackage, b as IPropBucketPackage } from './prop-package-Dwz0EWoB.js';
9
+ import './world-package-DqJC3-Nn.js';
6
10
 
7
11
  type PlacementEdit = Omit<IPlacementOverride, "position" | "quaternion" | "scale" | "grounding"> & {
8
12
  readonly position: readonly [number, number, number];
@@ -56,6 +60,1137 @@ declare function editWorldPlacements(data: {
56
60
  removed: readonly IRemovedPlacement[];
57
61
  };
58
62
 
63
+ /** What the gate writes into the scene's own state store, so any kit's store fits it. */
64
+ interface ISpawnGateState {
65
+ readonly worldReady: boolean;
66
+ readonly loadingError: string;
67
+ }
68
+ /** The scene whose spawn this gates: a starter context, whose own state is the kit's. */
69
+ type SpawnGateHost = ICtx<Record<string, unknown> & ISpawnGateState, IPhysicsContext>;
70
+ /** How much of the spawn's own region landed: the two counts the run report publishes. */
71
+ interface ISpawnRegion {
72
+ readonly required: number;
73
+ readonly loaded: number;
74
+ }
75
+ /** Where the scene's own preparation stands, for the failure report. */
76
+ interface ISpawnWitness {
77
+ /** The preparation phase the scene is in, when it has one. */
78
+ readonly phase: string | undefined;
79
+ /** The streamed or staged build's own stage name. */
80
+ readonly stage: string;
81
+ readonly bucket: string | null;
82
+ readonly added: number | null;
83
+ readonly total: number | null;
84
+ readonly buildStartedAt: number | undefined;
85
+ readonly phaseStartedAt: number | undefined;
86
+ readonly lastProgressAt: number | undefined;
87
+ }
88
+ interface ISpawnGateOptions {
89
+ readonly world: string;
90
+ /** Completed work units, so the loading screen's percentage cannot claim progress a stall did not make. */
91
+ readonly progress: () => number;
92
+ /**
93
+ * Where preparation stands when the spawn fails, so the failure names the phase it died in.
94
+ * Absent until the scene's own build exists: a failure before that reports nulls, not a guess.
95
+ */
96
+ readonly witness: () => ISpawnWitness | undefined;
97
+ /** True once the scene tore its world down: a join that lands afterwards must not revive it. */
98
+ readonly released: () => boolean;
99
+ }
100
+ interface ISpawnGate {
101
+ readonly deadlineAt: number;
102
+ /** Settles when the spawn's data and draws both landed; rejects when it failed or was cancelled. */
103
+ readonly promise: Promise<void>;
104
+ readonly ready: boolean;
105
+ readonly error: string;
106
+ readonly cells: ISpawnRegion;
107
+ /** Keeps the loading screen up until the spawn promise settles. */
108
+ readonly hold: () => void;
109
+ /** Await one readiness join under the gate's deadline. */
110
+ readonly watch: (join: (remainingMs: number) => Promise<{
111
+ requiredCells: number;
112
+ loadedCells: number;
113
+ }>) => void;
114
+ /** The join landed: publish the cells it covers and release the gate. */
115
+ readonly land: (region: {
116
+ requiredCells: number;
117
+ loadedCells: number;
118
+ }) => void;
119
+ /** Release the gate without a failure receipt: the spawn landed, or the scene left. */
120
+ readonly settle: (error?: Error) => void;
121
+ /** Kill the gate with a receipt: the spawn failed. */
122
+ readonly fail: (reason?: unknown) => void;
123
+ }
124
+ /**
125
+ * The spawn gate: one deadline, one settlement, one failure report.
126
+ *
127
+ * `WorldCells.whenSpawnReady` is the data authority and each streamed world's `prewarmed` is the
128
+ * draw gate; this gate turns their landing into the loading screen's release, and writes the one
129
+ * console line a failed spawn leaves behind.
130
+ *
131
+ * @situation hold a streamed starter world's loading screen until its spawn has landed
132
+ * @constraint Every value it reports is supplied by the game; a failure writes one `TN_` line
133
+ * @requires npm i -D @threenative/terrain
134
+ * @example const gate = createSpawnGate(ctx, { world, progress, witness, released });
135
+ */
136
+ declare function createSpawnGate(ctx: SpawnGateHost, options: ISpawnGateOptions): ISpawnGate;
137
+
138
+ /**
139
+ * The collar ring grid's own spacing curve: ring `k` stands `(k / rings) ** power * reach` metres
140
+ * past the playable square's edge. The kit builds the collar, so it passes the curve its rings
141
+ * follow; the morph and the arithmetic locate a point's ring by inverting it.
142
+ */
143
+ interface ICollarRingCurve {
144
+ /** How the rings spread; 1 is even spacing. */
145
+ readonly power: number;
146
+ /** Metres past the square's edge the outermost ring reaches. */
147
+ readonly reach: number;
148
+ }
149
+ /** What the tile shader reads about the block the streamed tiles draw. */
150
+ interface ICollarStream {
151
+ /** The drawn block's centre, on the tile lattice. */
152
+ readonly centre: UniformNode<"vec2", Vector2>;
153
+ /** Half the drawn block's side, metres; 0 before the first tile settles. */
154
+ readonly half: UniformNode<"float", number>;
155
+ }
156
+ /** Streamed tile width in metres; the outermost tile of the drawn square is the morph band. */
157
+ declare const STREAM_TILE = 64;
158
+ /**
159
+ * Metres the collar also draws under the streamed block's edge. The tile and the collar cut their
160
+ * triangles differently, so at the split their surfaces part by up to the fold `collarSeamGap`
161
+ * measures; cut at one line, a view across that step saw the sky through it as a dotted white seam.
162
+ */
163
+ declare const COLLAR_UNDER_TILE: number;
164
+ /**
165
+ * Metres inside the square's edge where the streamed tiles still draw. Each tile hangs a skirt on
166
+ * that edge; a mask cut on the edge itself dropped it, and the rounding cracks where the square
167
+ * and the tiles meet showed the sky as a dotted white line along low-view crests.
168
+ */
169
+ declare const TILE_INSIDE_SQUARE = 0.5;
170
+ /**
171
+ * The collar's drawn height under `(x, z)`; null where there is no collar.
172
+ *
173
+ * @requires npm i -D @threenative/terrain
174
+ * @situation measure or collide against the triangles a collar actually draws
175
+ * @constraint reads the collar it is given; never resamples the square or builds a surface
176
+ * @example const y = collarDrawnHeight(collar, x, z);
177
+ */
178
+ declare function collarDrawnHeight(collar: HeightfieldCollar, x: number, z: number): number | null;
179
+ /**
180
+ * PRD-790: where streamed tiles meet the collar. The tiles draw inside the square
181
+ * `(centreX, centreZ, half)` and the collar outside it, so the seam is that square's edge, past the
182
+ * playable square. `gap` is the largest step at the tiles' edge vertices (`spacing` apart), as core
183
+ * measures a tile-to-tile seam; `fold` is the largest step between them, where a fold of the
184
+ * collar's coarser triangles crosses a tile's straight edge.
185
+ *
186
+ * @requires npm i -D @threenative/terrain
187
+ * @situation prove a streamed ground and its collar meet without a step
188
+ * @constraint the caller supplies the height the tiles draw; a coarser `step` samples faster
189
+ * @example const { gap, fold } = collarSeamGap(collar, tilesHeight, x, z, 288, 2);
190
+ */
191
+ declare function collarSeamGap(collar: HeightfieldCollar, height: (x: number, z: number) => number, centreX: number, centreZ: number, half: number, spacing: number, step?: number): {
192
+ fold: number;
193
+ gap: number;
194
+ };
195
+ /**
196
+ * The collar triangle under `(x, z)` found by arithmetic alone, as the tile shader finds it: the
197
+ * ring from the ring spacing, the perimeter step from the face the point projects onto, and the
198
+ * triangle from the point's place in the quad. On one face the world point is an affine map of
199
+ * `(scale, share * scale)`, so weights read there are the drawn triangle's own.
200
+ *
201
+ * @requires npm i -D @threenative/terrain
202
+ * @situation answer a collar height on the CPU exactly as its tile shader computes it
203
+ * @constraint the curve must be the one the collar was built with
204
+ * @example const y = collarArithmeticHeight(collar, { power: 1.65, reach: 2100 }, x, z);
205
+ */
206
+ declare function collarArithmeticHeight(collar: HeightfieldCollar, curve: ICollarRingCurve, x: number, z: number): number;
207
+ /**
208
+ * PRD-790 box 2: the streamed tiles' vertex shift. Only the outermost tile of the square the tiles
209
+ * draw slides onto the collar's drawn height, smoothly over that tile, so at the square's edge every
210
+ * tile vertex stands on the collar; the ground inside keeps the survey's smooth surface. The
211
+ * collar's heights go to the GPU once, as a float texture of rings by perimeter steps.
212
+ *
213
+ * @requires npm i -D @threenative/terrain
214
+ * @situation slide the streamed ground's outer tile onto a drawn collar without a seam
215
+ * @constraint the curve must be the one the collar was built with; the band is one tile wide
216
+ * @example tile.positionNode = collarMorph(collar, { power: 1.65, reach: 2100 }, stream, 64);
217
+ */
218
+ declare function collarMorph(collar: HeightfieldCollar, curve: ICollarRingCurve, stream: ICollarStream, band: number): Node<"vec3">;
219
+ /**
220
+ * The height a tile vertex stands at once `collarMorph` moved it: the survey inside the band, the
221
+ * collar's arithmetic height at the drawn square's edge. The seam measure reads this.
222
+ *
223
+ * @requires npm i -D @threenative/terrain
224
+ * @situation check on the CPU the surface the tile shader draws after its morph
225
+ * @constraint mirrors `collarMorph`'s weight exactly; both read the same curve and band
226
+ * @example const height = createMorphedHeight(collar, curve, surveyHeight, x, z, 288, 64);
227
+ */
228
+ declare function createMorphedHeight(collar: HeightfieldCollar, curve: ICollarRingCurve, height: (x: number, z: number) => number, centreX: number, centreZ: number, half: number, band: number): (x: number, z: number) => number;
229
+
230
+ /** What one frame of streaming reports into the scene's own state. */
231
+ interface IStreamedGroundFacts {
232
+ readonly streamTiles: number;
233
+ readonly streamCoveredHalf: number;
234
+ readonly streamSeamGap: number;
235
+ readonly streamCollarGap: number;
236
+ readonly streamCollarFold: number;
237
+ }
238
+ /** Everything the mechanism reads: the game's ground and collar, and the block it follows. */
239
+ interface IStreamedGroundOptions {
240
+ /** The scene's context: it owns the tiles' lifetime and the physics bodies. */
241
+ readonly ctx: ICtx<Record<string, unknown>, IPhysicsContext>;
242
+ /** The world's own name, for the one line a malformed kit leaves behind. */
243
+ readonly name: string;
244
+ /** The playable square's side, metres. */
245
+ readonly size: number;
246
+ /** The square heightfield's samples per side; the tile grid shares its spacing. */
247
+ readonly resolution: number;
248
+ /**
249
+ * The ground at any `(x, z)` of the world, the square and the collar both: the kit's own survey
250
+ * function, so a tile meets the square and its neighbours with no step.
251
+ */
252
+ readonly height: (x: number, z: number) => number;
253
+ /** The collar the square grows out to; the tiles stop at its rim. */
254
+ readonly collar: HeightfieldCollar;
255
+ /** The curve the collar's rings were built with, so the morph inverts it. */
256
+ readonly curve: ICollarRingCurve;
257
+ /** Metres past the square's edge the collar reaches: the stream ends there. */
258
+ readonly reach: number;
259
+ /** The block the tiles draw, read by the tile material's collar morph. */
260
+ readonly stream: ICollarStream;
261
+ /** The ground material the tiles draw with, owned by the game and disposed with the tiles. */
262
+ readonly surface: MeshStandardNodeMaterial;
263
+ /** What the block follows: the player's actor. */
264
+ readonly follow: Object3D;
265
+ /** Where each frame's resident tiles and seam measures go. */
266
+ readonly report: (facts: IStreamedGroundFacts) => void;
267
+ }
268
+ /**
269
+ * PRD-790: the ground past the playable square, streamed around the player by `TerrainTiles` out to
270
+ * the collar's reach. Tiles sample the kit's own height function, the surface the square and the
271
+ * collar's vertices stand on, so a tile meets the square and its neighbours with no step. The tile
272
+ * material slides the outermost tile onto the collar's drawn height (`collarMorph`), so at the
273
+ * collar every tile vertex stands on it; `?tnTerrainValidate=1` reports `streamCollarGap`. The
274
+ * largest block of resident tiles around the player is written to the stream each frame: the tiles
275
+ * draw inside it, the collar everywhere else, so a tile that is still building leaves the collar
276
+ * showing, never a hole.
277
+ *
278
+ * @requires npm i -D @threenative/terrain @threenative/physics
279
+ * @situation stream an authored square's ground past its edge, out to a drawn collar
280
+ * @constraint the game supplies the height, the collar, its curve and the tile material
281
+ * @example const ground = addStreamedGround({ ctx, name, size, resolution, height, collar, curve, reach, stream, surface, follow, report });
282
+ */
283
+ declare function addStreamedGround(options: IStreamedGroundOptions): {
284
+ dispose(): void;
285
+ readonly ready: Promise<void>;
286
+ readonly tiles: TerrainTiles;
287
+ };
288
+
289
+ /**
290
+ * What one scene measures about the player, the ground and the props, step by step.
291
+ *
292
+ * The scene builds the world and calls `step()` from its physics hook; the counters and the probes
293
+ * live here. Each probe fails closed by the same rule the scene had: a contact the run cannot
294
+ * observe throws rather than publishing a healthy-looking zero.
295
+ */
296
+ interface IMeasureOptions {
297
+ readonly world: string;
298
+ readonly physics: IPhysicsContext;
299
+ readonly raycast: (options: IRaycastOptions) => Intersection | undefined;
300
+ readonly actor: Mesh;
301
+ readonly player: CharacterBody3D;
302
+ /** The baked world's own size, in metres: the square the player can walk off. */
303
+ readonly size: number;
304
+ readonly mesh: Mesh | undefined;
305
+ /** The drawn triangles of the staged world's ground, when the run draws a staged world. */
306
+ readonly stage: IStagedWorld | undefined;
307
+ /** The invisible asymmetric fixture the bilinear-difference probe walks. */
308
+ readonly fixture: {
309
+ heightAt: (x: number, z: number) => number;
310
+ };
311
+ readonly probeMesh: Mesh;
312
+ /** True while the figure plays a swim clip: the playtest reads swimming that way. */
313
+ readonly swimmingClip: () => boolean;
314
+ /** True once the scene holds prop colliders to probe. */
315
+ readonly hasPropColliders: () => boolean;
316
+ readonly eye: () => Vector3;
317
+ readonly camera: () => PerspectiveCamera;
318
+ readonly ocean: IOceanSample | undefined;
319
+ readonly spawnReady: () => boolean;
320
+ readonly terrainTargets: () => Object3D | readonly Object3D[] | undefined;
321
+ readonly view: () => string;
322
+ }
323
+ interface IStagedWorld {
324
+ readonly world: {
325
+ stats: () => unknown;
326
+ traverseVisible: (callback: (object: Object3D) => void) => void;
327
+ };
328
+ readonly ground: {
329
+ readonly body: {
330
+ readonly id: number | string;
331
+ };
332
+ };
333
+ }
334
+ interface IOceanSample {
335
+ readonly steps: number;
336
+ readonly sampleHeight: (x: number, z: number) => {
337
+ readonly height: number;
338
+ } | undefined;
339
+ }
340
+ /** The measurements a scene publishes each time `publish` runs. */
341
+ interface IMeasureFacts {
342
+ readonly travel: number;
343
+ readonly straightTravel: number;
344
+ readonly edgeOvershoot: number;
345
+ readonly grounded: boolean;
346
+ readonly propOverlapFrames: number;
347
+ readonly swimming: boolean;
348
+ readonly immersionDepth: number;
349
+ readonly swimSamples: number;
350
+ readonly swimFloatSamples: number;
351
+ readonly swimExits: number;
352
+ readonly swimDrift: number;
353
+ readonly contactSamples: number;
354
+ readonly maxContactError: number;
355
+ readonly bilinearDifference: number;
356
+ readonly oceanSteps: number;
357
+ readonly waveSamples: number;
358
+ readonly waveRange: number;
359
+ readonly sampleSlopeRange: number;
360
+ readonly propCounts: {
361
+ readonly draws: number;
362
+ readonly instances: number;
363
+ readonly triangles: number;
364
+ };
365
+ readonly coverNearEye: number;
366
+ readonly coverFar: number;
367
+ readonly farForestInView: number;
368
+ }
369
+ interface IMeasure {
370
+ /** One fixed physics step: travel, contact, the edge, the swim and the water's own samples. */
371
+ readonly step: () => void;
372
+ /** The drawn prop counts and the cover in front of the eye, every thirtieth step. */
373
+ readonly countProps: (meshes: InstancedMesh[], farWorld: Object3D | undefined) => void;
374
+ readonly facts: () => IMeasureFacts;
375
+ }
376
+ /**
377
+ * The asymmetric fixture: eight seeded points where a bilinear height and the drawn triangle disagree,
378
+ * walked by both paths — the picker's triangles and the solver's own ray. It throws when either path
379
+ * answers nothing, because a run that cannot see the ground must not publish a healthy zero.
380
+ */
381
+ interface IContactProbeOptions {
382
+ readonly mesh: {
383
+ updateMatrixWorld: (force?: boolean) => unknown;
384
+ } | undefined;
385
+ readonly probeMesh: {
386
+ updateMatrixWorld: (force?: boolean) => unknown;
387
+ };
388
+ readonly raycast: (options: IRaycastOptions) => Intersection | undefined;
389
+ readonly physics: IPhysicsContext;
390
+ readonly fixture: {
391
+ heightAt: (x: number, z: number) => number;
392
+ };
393
+ }
394
+ interface IContactWitness {
395
+ readonly bilinearDifference: number;
396
+ readonly contactSamples: number;
397
+ readonly maxContactError: number;
398
+ }
399
+ /**
400
+ * The per-world measurement: contacts, travel, edge overshoot, water and the frame facts a run
401
+ * reports.
402
+ *
403
+ * @requires npm i -D @threenative/terrain @threenative/physics
404
+ * @situation measure one played starter world every fixed step
405
+ * @constraint the game supplies the actor, the player body and the probe fixture; it owns no look
406
+ * @example const measure = createMeasure({ world, physics: ctx.physics, raycast, actor, player, ...options });
407
+ */
408
+ declare function createMeasure(options: IMeasureOptions): IMeasure;
409
+ /**
410
+ * What the reveal cost, measured from the frame it completes: batches published in view, shadows
411
+ * invalidated, impostors still pending, and every pipeline the device created since.
412
+ *
413
+ * One source counts the pipelines, picked at the reveal: three's census on its backend, else the
414
+ * owned engine's own compile count. The owned engine builds pipelines inside Wasm, where the census
415
+ * sees none and stays incomplete.
416
+ */
417
+ interface IRevealProbeOptions {
418
+ readonly camera: () => PerspectiveCamera;
419
+ readonly pipelineCensus: () => {
420
+ readonly complete: boolean;
421
+ readonly counts: {
422
+ readonly deviceCreations?: number;
423
+ };
424
+ } | undefined;
425
+ readonly engineCompiles: () => number | undefined;
426
+ /** True while a loading overlay covers the world: the reveal has not happened yet. */
427
+ readonly covered: () => boolean;
428
+ readonly phase: () => string;
429
+ readonly shadowNode: () => unknown;
430
+ /** Impostors still pending across every streamed world. */
431
+ readonly pendingImpostors: () => number;
432
+ readonly released: () => boolean;
433
+ readonly afterPhysics: (callback: () => void) => unknown;
434
+ readonly revealed: () => void;
435
+ }
436
+ interface IRevealProbe {
437
+ /** The loading screen reported its reveal: take the baseline this probe measures against. */
438
+ readonly initialize: () => void;
439
+ /** A props batch was published; count it when the reveal frustum holds it. */
440
+ readonly publishedBatch: (bounds: Box3) => void;
441
+ /** The measured numbers as plain data: the run report's `props.reveal` readout. */
442
+ readonly readout: () => Readonly<Record<string, number | string | boolean>>;
443
+ }
444
+ /**
445
+ * What the loading reveal showed once the curtain lifts: drawn batches, pipelines and impostor
446
+ * readiness, measured against the reveal's own baseline.
447
+ *
448
+ * @requires npm i -D @threenative/terrain
449
+ * @situation measure whether the spawn drew before the curtain released it
450
+ * @example const reveal = createRevealProbe({ camera, covered, phase, released, ...options });
451
+ */
452
+ declare function createRevealProbe(options: IRevealProbeOptions): IRevealProbe;
453
+
454
+ /**
455
+ * The state one world's measurements are reported through, with its own name in it. The game spreads
456
+ * this into its own state and adds the look values it also reports; the counters live here.
457
+ *
458
+ * The window groups and the drawn-frame counts are module-level on purpose: `ctx.goto` builds a new
459
+ * scene for the next world, and the numbers a run reports are the run's, not one scene's.
460
+ *
461
+ * @requires npm i -D @threenative/terrain @threenative/physics
462
+ * @situation start a kit's game state with the measurements every streamed starter world reports
463
+ * @constraint the world name is the one this state measures; a blank name fails rather than reporting ""
464
+ * @example const state = { ...createDiagnosticsState("forest"), showcase: false };
465
+ */
466
+ declare function createDiagnosticsState(world: string): {
467
+ elevationMin: number;
468
+ elevationMax: number;
469
+ snowFrom: number;
470
+ snowTo: number;
471
+ worldReady: boolean;
472
+ spawnReadiness: Array<Record<string, string | number | boolean>>;
473
+ loadingError: string;
474
+ spawnCellsRequired: number;
475
+ spawnCellsLoaded: number;
476
+ streamingResidentCells: number;
477
+ streamingLoadedCells: number;
478
+ streamingEvictions: number;
479
+ streamingInstances: number;
480
+ streamingFailures: number;
481
+ streamingPendingPrewarm: number;
482
+ streamingLoadsInFlight: number;
483
+ streamingAdmissionMs: number;
484
+ streamingAdmissionBacklog: number;
485
+ timeToReadyMs: number;
486
+ enterMs: number;
487
+ tasksAvailable: boolean;
488
+ longestLoadTaskMs: number;
489
+ afterFirstFrameTaskMs: number;
490
+ maxViewGpuMs: number;
491
+ measuredGpuViewCount: number;
492
+ viewGpu: {
493
+ view: string;
494
+ gpuMs: number;
495
+ gpuMain: number;
496
+ gpuShadow: number;
497
+ gpuOther: number;
498
+ windows: number;
499
+ passes: Record<string, {
500
+ triangles: number;
501
+ draws: number;
502
+ }>;
503
+ scale: number;
504
+ samples: number;
505
+ }[];
506
+ world: string;
507
+ groundBiome: string;
508
+ terrainTransportBound: boolean;
509
+ erosionFlowSamples: number;
510
+ erosionDepositSamples: number;
511
+ frames: number;
512
+ travel: number;
513
+ /** The farthest the player stood from where it spawned, in a straight line on the ground plane. */
514
+ straightTravel: number;
515
+ edgeOvershoot: number;
516
+ grounded: boolean;
517
+ /** Rock and trunk bodies resident around the player (`ScatterColliders`). */
518
+ propColliders: number;
519
+ /** Frames the player's capsule crossed into a rock or trunk; 0 while props are solid. */
520
+ propOverlapFrames: number;
521
+ swimming: boolean;
522
+ immersionDepth: number;
523
+ swimSamples: number;
524
+ swimFloatSamples: number;
525
+ swimExits: number;
526
+ /** Metres the river current carried the player along itself, while swimming. */
527
+ swimDrift: number;
528
+ contactSamples: number;
529
+ maxContactError: number;
530
+ bilinearDifference: number;
531
+ oceanSteps: number;
532
+ waveSamples: number;
533
+ waveRange: number;
534
+ sampleSlopeRange: number;
535
+ lakePlacementError: number;
536
+ lakeSurfaceCount: number;
537
+ riverSurfaceCount: number;
538
+ lakeTriangles: number;
539
+ lakeFootprintError: number;
540
+ sunX: number;
541
+ propDraws: number;
542
+ propInstances: number;
543
+ propTriangles: number;
544
+ /** Drawn prop instances within 40 m of the eye in a fixed view (0 in the player view). */
545
+ coverNearEye: number;
546
+ /** Drawn grass instances 100-200 m from the eye in a fixed view: the far slopes' cover. */
547
+ coverFar: number;
548
+ /** Spruce planted past the square (`farForest.ts`), and those drawn inside the view's frustum. */
549
+ farForest: number;
550
+ farForestInView: number;
551
+ preparedLodBaseSpread: number;
552
+ compressedTexturesPrepared: number;
553
+ preparedLevelsWithoutSolid: number;
554
+ view: string;
555
+ revealComplete: boolean;
556
+ windowDrawCalls: number;
557
+ windowFrameMs: number;
558
+ currentViewWindows: number;
559
+ viewFrameP50s: {
560
+ view: string;
561
+ p50: number;
562
+ presentedP95: number;
563
+ windows: number;
564
+ }[];
565
+ maxViewFrameP50: number;
566
+ maxViewPresentedP95: number;
567
+ measuredViewCount: number;
568
+ riverFrameP50: number;
569
+ playerFrameP50: number;
570
+ meadowFrameP50: number;
571
+ meadowFrameP99: number;
572
+ meadowTriangles: number;
573
+ overviewFrameP50: number;
574
+ overviewFrameP99: number;
575
+ overviewTriangles: number;
576
+ alpineRenderedFrames: number;
577
+ desertRenderedFrames: number;
578
+ tundraRenderedFrames: number;
579
+ alpineFrameP50: number;
580
+ desertFrameP50: number;
581
+ tundraFrameP50: number;
582
+ alpineOverviewFrameP50: number;
583
+ desertOverviewFrameP50: number;
584
+ tundraOverviewFrameP50: number;
585
+ };
586
+ type DiagnosticsState = ReturnType<typeof createDiagnosticsState>;
587
+ declare const launchedAt: number;
588
+ /**
589
+ * Per-view frame cost, latched across the windows that closed while that camera was up.
590
+ *
591
+ * `budget` alone cannot answer "did the trees cost more at the meadow or at the overview": a playtest
592
+ * cycles the cameras faster than a window closes, so the one number it holds belongs to whichever
593
+ * view happened to be current. This keeps every window grouped by the view that was on screen, and
594
+ * reports the median of each group's p50s and the worst p99 — the worst, because a LOD band that pops
595
+ * once is a one-frame cost the median hides.
596
+ */
597
+ interface IViewWindow {
598
+ readonly view: string;
599
+ readonly p50s: number[];
600
+ readonly p99s: number[];
601
+ /** Presented-frame interval p95 per window: the whole frame the player sees, GPU included. */
602
+ readonly presentedP95s: number[];
603
+ readonly triangles: number[];
604
+ readonly gpuMs: number[];
605
+ readonly gpuMain: number[];
606
+ readonly gpuShadow: number[];
607
+ readonly gpuOther: number[];
608
+ readonly passes: Record<string, {
609
+ triangles: number;
610
+ draws: number;
611
+ }>[];
612
+ readonly surfaces: {
613
+ scale: number;
614
+ samples: number;
615
+ }[];
616
+ }
617
+ /**
618
+ * Start a scene's view accounting: the player view it opens in, and nothing measured yet.
619
+ *
620
+ * @requires npm i -D @threenative/terrain
621
+ * @situation start the run's view accounting when a scene enters
622
+ * @example beginScene("forest");
623
+ */
624
+ declare function beginScene(world: string): void;
625
+ /**
626
+ * The camera cycle moved to another view: a keyed group for it, and a fresh measurement.
627
+ *
628
+ * @requires npm i -D @threenative/terrain
629
+ * @situation switch the measured view when the benchmark camera cycle moves
630
+ * @example const { windows } = enterView("forest", "overview");
631
+ */
632
+ declare function enterView(world: string, view: string): {
633
+ current: string;
634
+ windows: number;
635
+ };
636
+ /** What a scene says about itself for one report: everything the counters cannot know. */
637
+ interface ISceneFacts {
638
+ readonly world: string;
639
+ readonly groundBiome: string;
640
+ readonly elevation: readonly [number, number];
641
+ readonly snowBand: readonly [number, number];
642
+ readonly worldReady: boolean;
643
+ readonly spawnReadiness: DiagnosticsState["spawnReadiness"];
644
+ readonly spawnCells: {
645
+ readonly required: number;
646
+ readonly loaded: number;
647
+ };
648
+ readonly streaming: {
649
+ readonly residentCells: number;
650
+ readonly loadedCells: number;
651
+ readonly evictions: number;
652
+ readonly instances: number;
653
+ readonly failures: number;
654
+ readonly pendingPrewarm: number;
655
+ readonly loadsInFlight: number;
656
+ readonly admissionMs: number;
657
+ readonly admissionBacklog: number;
658
+ } | undefined;
659
+ readonly terrainTransportBound: boolean;
660
+ readonly erosion: {
661
+ readonly flow: number;
662
+ readonly deposition: number;
663
+ };
664
+ readonly sunX: number;
665
+ readonly frames: number;
666
+ readonly travel: number;
667
+ readonly straightTravel: number;
668
+ readonly edgeOvershoot: number;
669
+ readonly grounded: boolean;
670
+ readonly propColliders: number;
671
+ readonly propOverlapFrames: number;
672
+ readonly swimming: boolean;
673
+ readonly immersionDepth: number;
674
+ readonly swimSamples: number;
675
+ readonly swimFloatSamples: number;
676
+ readonly swimExits: number;
677
+ readonly swimDrift: number;
678
+ readonly contactSamples: number;
679
+ readonly maxContactError: number;
680
+ readonly bilinearDifference: number;
681
+ readonly oceanSteps: number;
682
+ readonly waveSamples: number;
683
+ readonly waveRange: number;
684
+ readonly sampleSlopeRange: number;
685
+ readonly propCounts: {
686
+ readonly draws: number;
687
+ readonly instances: number;
688
+ readonly triangles: number;
689
+ };
690
+ readonly coverNearEye: number;
691
+ readonly coverFar: number;
692
+ readonly farForest: number;
693
+ readonly farForestInView: number;
694
+ readonly preparedLodBaseSpread: number;
695
+ readonly compressedTexturesPrepared: number;
696
+ readonly preparedLevelsWithoutSolid: number;
697
+ }
698
+ /**
699
+ * The frame-budget window closed: latch it, and update the numbers the run reports.
700
+ *
701
+ * @requires npm i -D @threenative/terrain
702
+ * @situation read the engine's own closed frame window into the run's report
703
+ * @example frameBudget: { onWindow: observeWindow }
704
+ */
705
+ declare function observeWindow(window: IFrameBudgetWindow): void;
706
+ /** The scene it is counting and the phase the run is in: what a frame counter asks the game. */
707
+ interface ICounterCtx {
708
+ readonly startup: {
709
+ readonly phase: string;
710
+ };
711
+ readonly renderer: {
712
+ readonly gpuFrameSample?: () => {
713
+ readonly frame: number;
714
+ } | undefined;
715
+ readonly gpuFrameAge?: () => number | undefined;
716
+ };
717
+ readonly state: {
718
+ getState: () => DiagnosticsState;
719
+ };
720
+ }
721
+ /**
722
+ * One world frame was drawn: count it, and open a fresh GPU sample window if the view or the
723
+ * readiness changed. Called from the render hook, before the camera is placed.
724
+ *
725
+ * @requires npm i -D @threenative/terrain
726
+ * @situation count a drawn frame and open the next GPU sample window
727
+ * @example ctx.beforeRender(() => observeFrame(ctx));
728
+ */
729
+ declare function observeFrame(ctx: ICounterCtx): void;
730
+ /**
731
+ * Publish the measurements and the scene's own facts into state, twice per second.
732
+ *
733
+ * @requires npm i -D @threenative/terrain
734
+ * @situation write the measured view and frame numbers into the game's state
735
+ * @example publish(ctx, { world, worldReady, frames, ...facts });
736
+ */
737
+ declare function publish(ctx: {
738
+ readonly state: {
739
+ set: (patch: Partial<DiagnosticsState>) => void;
740
+ getState: () => DiagnosticsState;
741
+ };
742
+ }, facts: ISceneFacts): void;
743
+ /**
744
+ * The scene is gone: nothing is on screen, so no window can belong to a view.
745
+ *
746
+ * @requires npm i -D @threenative/terrain
747
+ * @situation stop attributing windows to a view when its scene is left
748
+ * @example leaveScene();
749
+ */
750
+ declare function leaveScene(): void;
751
+
752
+ /** The ground under a placement: the height at the query, and the authored offset to add. */
753
+ type PropGroundQuery = (placement: IPlacement, position: [number, number, number]) => {
754
+ height: number | null;
755
+ offset: number;
756
+ };
757
+ /** One placed prop: the pose the game draws and the clearance it reports to the editor. */
758
+ interface IPropInstance {
759
+ material: Material;
760
+ onTransform?: (transform: IPlacementOverride | undefined) => void;
761
+ placement: IPlacement;
762
+ pose: Matrix4;
763
+ geometry: BufferGeometry;
764
+ grounding: boolean;
765
+ clearance: number | null;
766
+ cragBaseClearance?: number;
767
+ cragRingSamples?: number;
768
+ }
769
+ /** The pose a baked package record carries: the quaternion the bake authored for the placement. */
770
+ interface IPropPoseOverride {
771
+ readonly quaternion: readonly [number, number, number, number];
772
+ }
773
+ /** The result of grounding one prop: its matrix, and what the ground left underneath it. */
774
+ interface IPropPose {
775
+ readonly matrix: Matrix4;
776
+ readonly grounding: boolean;
777
+ readonly clearance: number | null;
778
+ readonly cragBaseClearance?: number;
779
+ readonly cragRingSamples?: number;
780
+ }
781
+ /**
782
+ * How far a placement's own geometry sinks below the snapped surface, per asset family.
783
+ *
784
+ * The pose steps are mechanism (a lowest point meets the ground, a slope's downhill lip closes), but
785
+ * which assets bury — and how deep — is the game's: a boulder is a rock that is part buried, a crag
786
+ * collar is measured at its rim, and a flat footprint sinks on its downhill side. The package asks
787
+ * these rules for each placement and applies them in one order.
788
+ */
789
+ interface IPropGroundRules {
790
+ /** The share of its own height a placement sinks after the ground snap, or undefined to skip. */
791
+ readonly burial?: (placement: IPlacement) => {
792
+ readonly share: number;
793
+ readonly crag: boolean;
794
+ } | undefined;
795
+ /** True for a flat-footed placement whose downhill footprint is buried too. */
796
+ readonly footprint?: (placement: IPlacement) => boolean;
797
+ /** The gap, in metres, the footprint search may close. */
798
+ readonly footprintThreshold?: number;
799
+ /** True for a crag whose base ring is measured, so a buried stem cannot hold a hanging collar. */
800
+ readonly baseRing?: (placement: IPlacement) => boolean;
801
+ /** Clearance, in metres, a crag's measured rim keeps above the ground under it. */
802
+ readonly baseRingClearance?: number;
803
+ }
804
+ /**
805
+ * The quaternion a placement's own scatter numbers describe: the normal tilt, then the yaw.
806
+ *
807
+ * @requires npm i -D @threenative/terrain
808
+ * @situation compose a placement's authored rotation before grounding it
809
+ * @example const quaternion = authoredQuaternion(placement);
810
+ */
811
+ declare function authoredQuaternion(placement: IPlacement): readonly [number, number, number, number];
812
+ /**
813
+ * A placement as a package record stores it: the authored pose becomes its transform, at one scale.
814
+ *
815
+ * A record holds position, quaternion and one uniform scale, so an edited placement's own transform
816
+ * is folded down to the scale its record carries. The shape that scale removed is `propKey`'s ratio,
817
+ * and the drawable model that ratio names carries it instead.
818
+ *
819
+ * @requires npm i -D @threenative/terrain
820
+ * @situation fold an authored placement into the record transform the bake stores
821
+ * @example const record = withAuthoredPose(placement);
822
+ */
823
+ declare function withAuthoredPose(placement: IPlacement): IPlacement;
824
+ /**
825
+ * The model a record draws: its asset, its variant, and the shape a non-uniform edit gave it.
826
+ *
827
+ * `WorldCells` names the model through the run the record sits in, so this key is what the container
828
+ * stores. A placement with one uniform scale draws its variant as authored (`spruce:2`); a placement
829
+ * the editor scaled unevenly draws a model of that shape (`spruce:2@1,0.5,0.5`), so the record stays
830
+ * one uniform scale and the picture keeps the edit.
831
+ *
832
+ * @requires npm i -D @threenative/terrain
833
+ * @situation name the model a baked or live placement record draws
834
+ * @example const key = propKey(placement, 2);
835
+ */
836
+ declare function propKey(placement: IPlacement, variant: number): string;
837
+ /**
838
+ * The shape `propKey` wrote, so the loader scales the model the record's one scale cannot carry.
839
+ *
840
+ * @requires npm i -D @threenative/terrain
841
+ * @situation scale a streamed model by the shape its record's single scale cannot carry
842
+ * @example const ratio = propRatio("spruce:2@1,0.5,0.5");
843
+ */
844
+ declare function propRatio(key: string): [number, number, number];
845
+ /**
846
+ * The pose a prop draws at, grounded on the game's own height field.
847
+ *
848
+ * The record's quaternion, when present, replaces the rotation a live placement composes; every step
849
+ * below it — the ground snap, the boulder burial, the flat-footprint sink and the crag base ring —
850
+ * still runs, because the record is a pose and not an override of the pose. A placement with no
851
+ * ground under it fails closed by its own id, so a streamed world cannot silently float.
852
+ *
853
+ * @requires npm i -D @threenative/terrain
854
+ * @situation ground one baked prop record on the game's height field before streaming it
855
+ * @constraint the burial, footprint and base-ring assets are the game's; the package applies them
856
+ * @example const pose = preparePose(foot.geometry, material, record.placement, undefined, groundAt, rules);
857
+ */
858
+ declare function preparePose(geometry: BufferGeometry, _material: Material, placement: IPlacement, transform: IPlacementOverride | undefined, groundAt: PropGroundQuery, rules: IPropGroundRules, pose?: IPropPoseOverride): IPropPose;
859
+ /**
860
+ * The pose and the transform an editor edited, prepared together so one write reports both.
861
+ *
862
+ * @requires npm i -D @threenative/terrain
863
+ * @situation re-pose one prop the editor edited and keep the transform it reported
864
+ * @example const prepared = preparePropTransform(instance, transform, groundAt, rules);
865
+ */
866
+ declare function preparePropTransform(instance: IPropInstance, transform: IPlacementOverride | undefined, groundAt: PropGroundQuery, rules: IPropGroundRules): {
867
+ transform: IPlacementOverride | undefined;
868
+ matrix: Matrix4;
869
+ grounding: boolean;
870
+ clearance: number | null;
871
+ cragBaseClearance?: number;
872
+ cragRingSamples?: number;
873
+ };
874
+ /**
875
+ * Writes a prepared pose onto the instance, reporting the transform only when the pose changed.
876
+ *
877
+ * @requires npm i -D @threenative/terrain
878
+ * @situation write an edited prop's prepared pose back onto its instance
879
+ * @example writePropTransform(instance, prepared);
880
+ */
881
+ declare function writePropTransform(instance: IPropInstance, prepared: ReturnType<typeof preparePropTransform>): void;
882
+ /**
883
+ * The transform an instance's current pose describes.
884
+ *
885
+ * @requires npm i -D @threenative/terrain
886
+ * @situation read an edited prop's current pose for the scene format
887
+ * @example const transform = readPropTransform(instance);
888
+ */
889
+ declare function readPropTransform(instance: IPropInstance): IPlacementOverride;
890
+
891
+ /** One part of a prop's prepared model: a geometry, its surface, and the level it draws at. */
892
+ interface IPropPart {
893
+ readonly geometry: BufferGeometry;
894
+ /** The surface this part draws with, when it is not the role's. */
895
+ readonly material?: Material;
896
+ /** Which detail level this part is. `0` is the full one; a variant with only it never steps. */
897
+ readonly level?: number;
898
+ readonly role: string;
899
+ readonly variant: number;
900
+ }
901
+ /** Consumer preparation only; the worlds still own admission, residency and prewarm. */
902
+ interface IPropPreparationProgress {
903
+ readonly phase: "grounding" | "models" | "world-load" | "complete";
904
+ readonly bucket: string;
905
+ readonly added: number;
906
+ readonly total: number;
907
+ readonly worlds: readonly WorldCells[];
908
+ /** Live promise settlements, distinct from load completion and the last rendered counters. */
909
+ readonly prewarmedWorlds: number;
910
+ }
911
+ /** The streamed world a placement joins: its name, its kind, and whether it casts shadows. */
912
+ interface IPropBucketRow {
913
+ readonly name: string;
914
+ readonly kind: IPropBucketKind;
915
+ readonly shadows: boolean;
916
+ }
917
+ interface IPropWorldOptions {
918
+ /** The baked package, one streamed world per bucket. May be empty when every placement is live. */
919
+ readonly package?: IPropPackage;
920
+ /**
921
+ * Placements the caller holds live, compiled here through this package.
922
+ *
923
+ * A bake plants none: its records come from the package. The editor compiles the placements it is
924
+ * editing, and a script that proves one pose compiles the one it built.
925
+ */
926
+ readonly placements?: readonly IPlacement[];
927
+ /** Which baked buckets this run keeps; the query flags answer it. Every bucket by default. */
928
+ readonly buckets?: (bucket: IPropBucketPackage) => boolean;
929
+ readonly groundAt: PropGroundQuery;
930
+ readonly groundRules: IPropGroundRules;
931
+ readonly parts: ReadonlyMap<string, readonly IPropPart[]>;
932
+ readonly materials: Readonly<Record<string, Material>>;
933
+ /** The surface `WorldCells` samples where the container has no material of its own. */
934
+ readonly surface: Material;
935
+ readonly follow: IWorldCellsFollow;
936
+ /** The world square the bake packaged; live placements use its bounds too. */
937
+ readonly size: number;
938
+ readonly horizonDistance?: number;
939
+ readonly castShadows?: boolean;
940
+ /** The biome row's `standShade`: the tint a gate asset takes where no sun shadow is drawn on it. */
941
+ readonly standShade?: readonly [number, number, number];
942
+ /** The sun's outer shadow window, metres; a local tree takes `standShade` past it. */
943
+ readonly shadowReach?: number;
944
+ readonly bundles?: boolean;
945
+ readonly assets?: IAssetLoader;
946
+ readonly whileCurrent: () => boolean;
947
+ readonly invalidateShadows?: (region?: IShadowRegion) => void;
948
+ readonly onProgress?: (progress: IPropPreparationProgress) => void;
949
+ readonly onPublication?: (bounds: Box3) => void;
950
+ /** The variant a placement picks; the kit's seeded picker. */
951
+ readonly variantOf: (placement: IPlacement) => number;
952
+ /** The draw reach a live placement's variant gives it. */
953
+ readonly reachOf: (placement: IPlacement, variantIndex: number) => number;
954
+ /** The streamed world a placement joins. */
955
+ readonly bucketOf: (placement: IPlacement, reach: number) => IPropBucketRow;
956
+ /** The metres at which an asset steps to its mid and far prepared detail. */
957
+ readonly lodOf: (asset: string) => readonly [number, number];
958
+ /** The dither band's slack, as a share of the step. */
959
+ readonly lodHysteresis: number;
960
+ /** The far band's distance, the floor of a gate asset's terminal impostor. */
961
+ readonly lodFar: number;
962
+ /** Every asset a container may name, so the run report still counts a zero. */
963
+ readonly assetNames: readonly string[];
964
+ /** The asset family that takes a whole-asset terminal impostor. */
965
+ readonly gateAsset: string;
966
+ /** The terminal distance a gate asset in a far bucket keeps. */
967
+ readonly gateFarDistance: number;
968
+ /** The stand shade a gate asset wears where no shadow reaches it. */
969
+ readonly shadeStand?: (source: Material, shade: readonly [number, number, number], shadowReach?: number) => Material;
970
+ /** Whether a baked bucket's world casts shadows. */
971
+ readonly shadowsOf: (bucket: IPropBucketPackage) => boolean;
972
+ }
973
+ /**
974
+ * Keep WorldCells' changed caster bounds when forwarding to the existing shadow renderer.
975
+ *
976
+ * @requires npm i -D @threenative/terrain
977
+ * @situation forward a streamed world's changed caster bounds to the game's shadow renderer
978
+ * @example invalidatePropShadows(ctx.shadows, region);
979
+ */
980
+ declare function invalidatePropShadows(shadow: {
981
+ invalidateRegion(region: IShadowRegion): void;
982
+ invalidateAll(): void;
983
+ }, region?: IShadowRegion): void;
984
+ /** One streamed prop world: the containers it streams, the canopy it shades and the counts it reports. */
985
+ interface IScatter {
986
+ readonly package: IPropPackage;
987
+ readonly canopy: Float32Array;
988
+ readonly counts: Readonly<Record<string, number>>;
989
+ }
990
+ /** One world's baked props: the containers it streams, the canopy it shades and the counts it reports. */
991
+ interface IScatter {
992
+ readonly package: IPropPackage;
993
+ readonly canopy: Float32Array;
994
+ readonly counts: Readonly<Record<string, number>>;
995
+ }
996
+ /**
997
+ * Records per asset across the package's buckets: what the run report calls the scatter's counts.
998
+ *
999
+ * @requires npm i -D @threenative/terrain
1000
+ * @situation report how many records each asset drew, zero included
1001
+ * @example const counts = propCounts(pkg, ["spruce", "boulder"]);
1002
+ */
1003
+ declare function propCounts(pkg: IPropPackage, assetNames: readonly string[]): Record<string, number>;
1004
+ /**
1005
+ * The baked prop package of one world, fetched as the bake wrote it.
1006
+ *
1007
+ * The files are the bake's output, not the game's: the manifest names one container, one reach array
1008
+ * and one placement-ID list per streamed world, and nothing here derives a placement.
1009
+ *
1010
+ * @requires npm i -D @threenative/terrain
1011
+ * @situation load the prop containers a bake wrote for one world
1012
+ * @example const props = await loadPropPackage(assets, "forest");
1013
+ */
1014
+ declare function loadPropPackage(assets: Pick<IAssetLoader, "resolve">, world: string): Promise<IPropPackage>;
1015
+ /**
1016
+ * The canopy weight the ground shader reads, painted from the placements the bake drew.
1017
+ *
1018
+ * @requires npm i -D @threenative/terrain
1019
+ * @situation load the canopy map a streamed world's ground shades with
1020
+ * @example const canopy = await loadCanopy(assets, "forest");
1021
+ */
1022
+ declare function loadCanopy(assets: Pick<IAssetLoader, "resolve">, world: string): Promise<Float32Array>;
1023
+ /**
1024
+ * The share of the sky each terrain vertex sees past the relief, as `skyVisibility` baked it.
1025
+ *
1026
+ * @requires npm i -D @threenative/terrain
1027
+ * @situation load the sky-visibility map a streamed world's ground shades with
1028
+ * @example const sky = await loadSky(assets, "forest");
1029
+ */
1030
+ declare function loadSky(assets: Pick<IAssetLoader, "resolve">, world: string): Promise<Float32Array>;
1031
+ /**
1032
+ * Load the prop worlds, pose every record on the ground, and hand each bucket to `WorldCells`.
1033
+ *
1034
+ * The passes are short and yield between slices, because the whole point of streaming is that the
1035
+ * first frame does not wait for 200 000 records: the records are decoded and grounded in slices, and
1036
+ * each bucket loads as its own world.
1037
+ *
1038
+ * @requires npm i -D @threenative/terrain
1039
+ * @situation stream a world's baked prop containers and its live placements through WorldCells
1040
+ * @constraint the variant, reach, bucket, LOD and gate rows are the game's; the package only applies
1041
+ * @example const props = await streamProps({ package: propPackage, groundAt, parts, materials, surface,
1042
+ * follow, size, whileCurrent, variantOf, reachOf, bucketOf, lodOf, ...options });
1043
+ */
1044
+ declare function streamProps(options: IPropWorldOptions): Promise<{
1045
+ worlds: WorldCells[];
1046
+ byId: Map<string, IPropInstance>;
1047
+ stats: () => {
1048
+ residentCells: number;
1049
+ loadedCells: number;
1050
+ instances: number;
1051
+ evictions: number;
1052
+ failures: number;
1053
+ loadsInFlight: number;
1054
+ loadsQueued: number;
1055
+ pendingPrewarm: number;
1056
+ impostor: {
1057
+ pending: number;
1058
+ drawn: number;
1059
+ };
1060
+ admissionMs: number;
1061
+ admissionBacklog: number;
1062
+ admissionDeferred: number;
1063
+ };
1064
+ compileSlices: number;
1065
+ readinessAt(camera: Camera): {
1066
+ required: number;
1067
+ loaded: number;
1068
+ failures: number;
1069
+ ready: boolean;
1070
+ };
1071
+ readonly ready: boolean;
1072
+ readonly meshes: InstancedMesh<BufferGeometry<three.NormalBufferAttributes, three.BufferGeometryEventMap>, Material<three.MaterialEventMap> | Material<three.MaterialEventMap>[], three.Object3DEventMap>[];
1073
+ dispose(): void;
1074
+ } | undefined>;
1075
+
1076
+ /** The humanoid a kit's player rig puts on the capsule. */
1077
+ interface IMannequin {
1078
+ readonly scene: Object3D;
1079
+ readonly animations: readonly AnimationClip[];
1080
+ }
1081
+ /** The clip names a kit's mannequin carries; the package plays them, the kit names them. */
1082
+ interface IPlayerRigClips {
1083
+ readonly idle: string;
1084
+ readonly walk: string;
1085
+ readonly run: string;
1086
+ readonly fall: string;
1087
+ readonly swim: string;
1088
+ readonly tread: string;
1089
+ }
1090
+ /** Ground speeds in m/s: the walk clip's pace, the jog, and the sprint. */
1091
+ interface IPlayerRigGait {
1092
+ /** The walk/jog blend's lower speed. */
1093
+ readonly stride: number;
1094
+ /** The jog the run clip was authored for. */
1095
+ readonly run: number;
1096
+ /** The Shift sprint. */
1097
+ readonly sprint: number;
1098
+ }
1099
+ /** Distance along the ray from `from` to `to` to the first wall, or undefined when clear. */
1100
+ type PlayerWallProbe = (from: Vector3, to: Vector3) => number | undefined;
1101
+ /**
1102
+ * The game's follow camera. The package drives it (pointer look, the per-step update) but never
1103
+ * builds it: framing is the game's, so a kit owns the arm length, the angles and the lens.
1104
+ */
1105
+ interface IPlayerRigCamera {
1106
+ /** The yaw the camera looks along (Three.js convention: forward is -Z at 0). */
1107
+ readonly yaw: number;
1108
+ /** Puts the camera behind a hero facing `yaw`, with no easing. */
1109
+ snap(target: Vector3, yaw: number, probe: PlayerWallProbe): void;
1110
+ /** Turns the arm by a pointer delta in pixels: right turns the view right, down raises the arm. */
1111
+ look(dx: number, dy: number): void;
1112
+ update(target: Vector3, velocity: Vector3, dt: number, probe: PlayerWallProbe): void;
1113
+ }
1114
+ /** The eye-line the kit draws from the hero to what it can see (`sightLine`). */
1115
+ interface IPlayerRigSight {
1116
+ readonly aim: {
1117
+ value: Vector3;
1118
+ };
1119
+ readonly radius: {
1120
+ value: number;
1121
+ };
1122
+ /** The radius a clear line carries, in metres. */
1123
+ readonly radiusValue: number;
1124
+ }
1125
+ /** Everything the rig reads from the game: its scene, its data and the values that shape it. */
1126
+ interface IPlayerRigOptions {
1127
+ readonly ctx: ICtx<Record<string, unknown> & {
1128
+ view: string;
1129
+ }, IPhysicsContext>;
1130
+ /** The player's launch point, in world metres. */
1131
+ readonly at: readonly [number, number];
1132
+ /** The ground the spawn stands on: the launch pose is measured from it, not guessed. */
1133
+ readonly field: Heightfield;
1134
+ readonly mannequin: IMannequin;
1135
+ readonly clips: IPlayerRigClips;
1136
+ /** The rig's two swim clips, which the mannequin's own clips do not carry. */
1137
+ readonly swimClips: readonly AnimationClip[];
1138
+ /** Where the launch camera stands relative to the player: above the ground under the spawn. */
1139
+ readonly cameraOffset: readonly [number, number, number];
1140
+ /** The capsule: radius and cylinder height, metres. The figure's feet are derived from them. */
1141
+ readonly capsule?: {
1142
+ readonly radius: number;
1143
+ readonly height: number;
1144
+ };
1145
+ /** The collision mask the ground and the props answer on; absent keeps the physics default. */
1146
+ readonly collisionMask?: number;
1147
+ readonly gait: IPlayerRigGait;
1148
+ /** The game's follow camera, already built. */
1149
+ readonly camera: IPlayerRigCamera;
1150
+ /** The game's wall probe against its own ground and prop colliders. */
1151
+ readonly probe: PlayerWallProbe;
1152
+ /** Should the follow camera run this step? False in a fixed view or a vista framing. */
1153
+ readonly following: () => boolean;
1154
+ /** The aim height above the player the sight line follows, metres. */
1155
+ readonly aimHeight: number;
1156
+ readonly sight?: IPlayerRigSight;
1157
+ /** Centres the sun's shadow pages, or clears them when no player framing draws. */
1158
+ readonly focusShadows: (at: Vector3 | undefined) => void;
1159
+ /** The horizon seam the scene draws under the player, for the scene picker's report. */
1160
+ readonly horizon: () => unknown;
1161
+ }
1162
+ /** The player: the capsule the solver moves, the mannequin that rides it and the camera that follows. */
1163
+ interface IPlayerRig {
1164
+ readonly actor: Mesh;
1165
+ readonly body: CharacterBody3D;
1166
+ readonly figure: SkeletalMesh3D;
1167
+ /** The launch point, frozen at entry: the streamed worlds measure their spawn cells around it. */
1168
+ readonly spawn: Vector3;
1169
+ /** The camera's yaw, so movement follows the ground the eye looks along. */
1170
+ readonly yaw: () => number;
1171
+ /** Top ground speed the scene spends on the player's own movement, in m/s. */
1172
+ readonly pace: (sprinting: boolean) => number;
1173
+ /** Face the travel direction and blend the gait: one call per fixed step. */
1174
+ readonly animate: (dt: number) => void;
1175
+ /** True while the figure plays a swim clip: the playtest reads swimming that way. */
1176
+ readonly playsSwimClip: () => boolean;
1177
+ }
1178
+ /**
1179
+ * The player: the capsule the solver moves, the mannequin that rides it, and the third-person camera
1180
+ * that follows with the terrain as its walls.
1181
+ *
1182
+ * The stepped world is the authority for both the ground the player stands on and the wall the orbit
1183
+ * camera cannot pass, which is why both queries mask to the game's ground layer: what the player can
1184
+ * walk on. Every appearance value — the mannequin, its clips, the gait speeds, the capsule and the
1185
+ * camera framing — comes from the game.
1186
+ *
1187
+ * @requires npm i -D @threenative/terrain @threenative/physics
1188
+ * @situation give a copied starter kit its player capsule, mannequin and follow camera
1189
+ * @constraint the game builds the camera and the wall probe; the package owns only their wiring
1190
+ * @example const rig = createPlayerRig({ at, field, mannequin, clips, gait, camera, probe, ...options });
1191
+ */
1192
+ declare function createPlayerRig(options: IPlayerRigOptions): IPlayerRig;
1193
+
59
1194
  type StarterContext = ICtx<Record<string, unknown>, IPhysicsContext>;
60
1195
  type StarterColliders = Readonly<Record<string, {
61
1196
  sphere: number;
@@ -140,4 +1275,4 @@ declare class PropColliders extends Object3D implements IComputeDriven {
140
1275
  detach(): void;
141
1276
  }
142
1277
 
143
- export { type IRemovedPlacement, type IStarterWorld, type IStarterWorldSpec, type IWorldPlacementEdits, PropColliders, type StarterColliders, type StarterContext, addStarterWorld, editWorldPlacements };
1278
+ export { COLLAR_UNDER_TILE, type DiagnosticsState, type ICollarRingCurve, type ICollarStream, type IContactProbeOptions, type IContactWitness, type ICounterCtx, type IMannequin, type IMeasure, type IMeasureFacts, type IMeasureOptions, type IPlayerRig, type IPlayerRigCamera, type IPlayerRigClips, type IPlayerRigGait, type IPlayerRigOptions, type IPlayerRigSight, type IPropBucketRow, type IPropGroundRules, type IPropInstance, type IPropPart, type IPropPose, type IPropPoseOverride, type IPropPreparationProgress, type IPropWorldOptions, type IRemovedPlacement, type IRevealProbe, type IRevealProbeOptions, type IScatter, type ISceneFacts, type ISpawnGate, type ISpawnGateOptions, type ISpawnGateState, type ISpawnRegion, type ISpawnWitness, type IStarterWorld, type IStarterWorldSpec, type IStreamedGroundFacts, type IStreamedGroundOptions, type IViewWindow, type IWorldPlacementEdits, type PlayerWallProbe, PropColliders, type PropGroundQuery, STREAM_TILE, type StarterColliders, type StarterContext, TILE_INSIDE_SQUARE, addStarterWorld, addStreamedGround, authoredQuaternion, beginScene, collarArithmeticHeight, collarDrawnHeight, collarMorph, collarSeamGap, createDiagnosticsState, createMeasure, createMorphedHeight, createPlayerRig, createRevealProbe, createSpawnGate, editWorldPlacements, enterView, invalidatePropShadows, launchedAt, leaveScene, loadCanopy, loadPropPackage, loadSky, observeFrame, observeWindow, preparePose, preparePropTransform, propCounts, propKey, propRatio, publish, readPropTransform, streamProps, withAuthoredPose, writePropTransform };