@threenative/core 0.3.13 → 0.3.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/capabilities.json +299 -10
- package/dist/{chunk-4SRAQFTU.js → chunk-2GPHICV6.js} +1 -1
- package/dist/{chunk-DIPIJICH.js → chunk-GEMQJBY4.js} +70 -18
- package/dist/{chunk-EFWZWLPY.js → chunk-QAMSM3Z5.js} +354 -12
- package/dist/{chunk-SV4QVUTQ.js → chunk-QAQHYOWY.js} +1 -1
- package/dist/{chunk-EEABDLUC.js → chunk-VBBYWGAT.js} +2 -2
- package/dist/{chunk-GYUZJQ7U.js → chunk-VQRPEOKY.js} +4 -1
- package/dist/index.d.ts +605 -7
- package/dist/index.js +1973 -609
- package/dist/playtest.js +3 -3
- package/dist/{quality-BYqKGAwo.d.ts → quality-BADStsTn.d.ts} +2 -2
- package/dist/render-environment.d.ts +1 -1
- package/dist/ui-layer.js +2 -2
- package/dist/worker.js +2 -2
- package/dist/world.d.ts +13 -3
- package/dist/world.js +179 -36
- package/mcp/animation-server.mjs +1 -1
- package/mcp/engine-server.mjs +32 -6
- package/mcp/servers.mjs +3 -3
- package/package.json +5 -5
- package/scripts/ensure-mcp.mjs +6 -1
- package/src/clustered-batch.ts +146 -3
- package/src/clustered-mesh.ts +548 -20
- package/src/debug.ts +16 -0
- package/src/displaced-surface.ts +428 -0
- package/src/frame-budget.ts +16 -0
- package/src/generated/console-markers.ts +1 -0
- package/src/grass-field.ts +628 -0
- package/src/index.ts +112 -0
- package/src/render/material-key.ts +21 -1
- package/src/render/screen-probe-gather.ts +303 -0
- package/src/render/short-range-ao.ts +274 -0
- package/src/render/world-impostor-surface.ts +98 -3
- package/src/render-camera-cull.ts +9 -3
- package/src/renderer.ts +26 -4
- package/src/scatter-field.ts +496 -0
- package/src/startup-offscreen-bytes.ts +11 -5
- package/src/state.ts +16 -3
- package/src/static-transform.ts +75 -6
- package/src/tile-ring.ts +294 -0
- package/src/version.ts +1 -1
- package/src/warmup.ts +15 -2
- package/src/world-cell-batches.ts +4 -0
- package/src/world-cell-data.ts +7 -0
- package/src/world-cell-models.ts +36 -8
- package/src/world-cell-render-gpu-dress.ts +4 -2
- package/src/world-cell-render-util.ts +2 -2
- package/src/world-cells.ts +1 -1
- package/src/world-river-ribbon.ts +13 -22
- package/src/world-water-bodies.ts +113 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BufferAttribute, BufferGeometry } from "three";
|
|
2
2
|
import type { Heightfield } from "./world-heightfield.js";
|
|
3
|
-
import { type IWaterLake, WATER_RIBBON_REACH,
|
|
3
|
+
import { type IWaterLake, WATER_RIBBON_REACH, lakeDisc } from "./world-water-bodies.js";
|
|
4
4
|
|
|
5
5
|
/** How a ribbon is cut; every value has the default `WaterBodies` and the Strata preview use. */
|
|
6
6
|
export interface IRiverRibbonOptions {
|
|
@@ -206,13 +206,16 @@ export interface ILakeSurfaceOptions {
|
|
|
206
206
|
|
|
207
207
|
/**
|
|
208
208
|
* A lake's water surface: a level disc out to `lakeReach`, the footprint `WaterBodies` floods, with a
|
|
209
|
-
* `metres` attribute (water depth over the ground). Only cells with
|
|
210
|
-
* so the surface does not hover over dry hillside
|
|
209
|
+
* `metres` attribute (water depth over the ground). Only cells with a corner the seed's water reaches
|
|
210
|
+
* get triangles, so the surface does not hover over dry hillside, a hollow past the basin's rim (a
|
|
211
|
+
* river valley beyond the dam) stays dry instead of standing under a sheet that stops where the reach
|
|
212
|
+
* does, and the shore follows the ground's contour. The
|
|
211
213
|
* rings pack towards the middle, so an irregular basin costs vertices where the camera sees them.
|
|
212
214
|
* Returns `undefined` when the basin holds no water at its level.
|
|
213
215
|
*
|
|
214
216
|
* @situation draw a lake's water surface from the baked level and seed
|
|
215
217
|
* @situation a lake's drawn water and the swimmer's water disagree
|
|
218
|
+
* @situation lake water ends in a straight edge over a valley past the basin's rim
|
|
216
219
|
* @constraint the lake row and field come from the game's bake; the game's material shades the geometry
|
|
217
220
|
* @example const geometry = lakeSurfaceGeometry({ ...lake, margin: 1.12 }, field, { maxDepth: 1.6 });
|
|
218
221
|
*/
|
|
@@ -231,28 +234,16 @@ export function lakeSurfaceGeometry(
|
|
|
231
234
|
);
|
|
232
235
|
if (!(packing > 0) || !(maxDepth > 0))
|
|
233
236
|
throw new Error("TN_LAKE_SURFACE_INVALID: packing and maxDepth must be positive.");
|
|
234
|
-
const
|
|
235
|
-
if (
|
|
236
|
-
const
|
|
237
|
-
const minX = field.origin.x - field.width / 2;
|
|
238
|
-
const minZ = field.origin.z - field.depth / 2;
|
|
239
|
-
const count = (rings - 1) * spokes + 1;
|
|
237
|
+
const disc = lakeDisc(field, lake, rings, spokes, packing);
|
|
238
|
+
if (disc === undefined) return undefined;
|
|
239
|
+
const count = disc.depths.length;
|
|
240
240
|
const positions = new Float32Array(count * 3);
|
|
241
241
|
const depths = new Float32Array(count);
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const x = Math.max(minX, Math.min(minX + field.width, cx + Math.cos(angle) * radius));
|
|
245
|
-
const z = Math.max(minZ, Math.min(minZ + field.depth, cz + Math.sin(angle) * radius));
|
|
246
|
-
positions[index * 3] = x;
|
|
242
|
+
for (let index = 0; index < count; index += 1) {
|
|
243
|
+
positions[index * 3] = disc.positions[index * 2] as number;
|
|
247
244
|
positions[index * 3 + 1] = lake.level;
|
|
248
|
-
positions[index * 3 + 2] =
|
|
249
|
-
depths[index] = Math.min(maxDepth,
|
|
250
|
-
};
|
|
251
|
-
place(0, 0, 0);
|
|
252
|
-
for (let ring = 1; ring < rings; ring += 1) {
|
|
253
|
-
const radius = reach * (ring / (rings - 1)) ** packing;
|
|
254
|
-
for (let spoke = 0; spoke < spokes; spoke += 1)
|
|
255
|
-
place(1 + (ring - 1) * spokes + spoke, radius, spoke);
|
|
245
|
+
positions[index * 3 + 2] = disc.positions[index * 2 + 1] as number;
|
|
246
|
+
depths[index] = Math.min(maxDepth, disc.depths[index] as number);
|
|
256
247
|
}
|
|
257
248
|
const depth = (index: number): number => depths[index] ?? 0;
|
|
258
249
|
const indices: number[] = [];
|
|
@@ -83,6 +83,8 @@ interface IPool {
|
|
|
83
83
|
readonly z: number;
|
|
84
84
|
readonly radius2: number;
|
|
85
85
|
readonly level: number;
|
|
86
|
+
readonly disc: ILakeDisc | undefined;
|
|
87
|
+
readonly field: Heightfield;
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
/** What stands at one (x, z): the water body covering it, its surface, and the river piece carrying it. */
|
|
@@ -155,6 +157,95 @@ export function waterlineRadius(
|
|
|
155
157
|
return furthest;
|
|
156
158
|
}
|
|
157
159
|
|
|
160
|
+
/**
|
|
161
|
+
* A lake's disc: `rings` rings of `spokes` vertices around its seed, out to `lakeReach`, packed towards
|
|
162
|
+
* the middle. Vertex 0 is the seed; ring `r` (1 to `rings - 1`) spoke `s` is `1 + (r - 1) * spokes + s`.
|
|
163
|
+
*
|
|
164
|
+
* `depths` is the water over the ground at each vertex, and it is zero where dry ground cuts the vertex
|
|
165
|
+
* off from the seed: a hollow beyond the basin's rim sits under the level too, but the lake does not
|
|
166
|
+
* reach it (a river valley past the dam would otherwise stand under a sheet of lake water that stops
|
|
167
|
+
* where the reach does, in a straight edge). Neighbours are the next spoke on a ring and the next ring
|
|
168
|
+
* on a spoke, so water crosses a ridge only where the ridge falls below the level.
|
|
169
|
+
*/
|
|
170
|
+
export interface ILakeDisc {
|
|
171
|
+
readonly x: number;
|
|
172
|
+
readonly z: number;
|
|
173
|
+
readonly reach: number;
|
|
174
|
+
readonly rings: number;
|
|
175
|
+
readonly spokes: number;
|
|
176
|
+
readonly packing: number;
|
|
177
|
+
/** `[x, z]` per vertex, clamped to the field. */
|
|
178
|
+
readonly positions: Float32Array;
|
|
179
|
+
readonly depths: Float32Array;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function lakeDisc(
|
|
183
|
+
field: Heightfield,
|
|
184
|
+
lake: IWaterLake,
|
|
185
|
+
rings = 44,
|
|
186
|
+
spokes = 88,
|
|
187
|
+
packing = 1.7,
|
|
188
|
+
): ILakeDisc | undefined {
|
|
189
|
+
const reach = lakeReach(field, lake);
|
|
190
|
+
if (!(reach > 0)) return undefined;
|
|
191
|
+
const [cx = 0, cz = 0] = lake.at;
|
|
192
|
+
const minX = field.origin.x - field.width / 2;
|
|
193
|
+
const minZ = field.origin.z - field.depth / 2;
|
|
194
|
+
const count = (rings - 1) * spokes + 1;
|
|
195
|
+
const positions = new Float32Array(count * 2);
|
|
196
|
+
const raw = new Float32Array(count);
|
|
197
|
+
for (let index = 0; index < count; index += 1) {
|
|
198
|
+
const ring = index === 0 ? 0 : Math.floor((index - 1) / spokes) + 1;
|
|
199
|
+
const angle = (((index - 1) % spokes) / spokes) * Math.PI * 2;
|
|
200
|
+
const radius = index === 0 ? 0 : reach * (ring / (rings - 1)) ** packing;
|
|
201
|
+
const x = Math.max(minX, Math.min(minX + field.width, cx + Math.cos(angle) * radius));
|
|
202
|
+
const z = Math.max(minZ, Math.min(minZ + field.depth, cz + Math.sin(angle) * radius));
|
|
203
|
+
positions[index * 2] = x;
|
|
204
|
+
positions[index * 2 + 1] = z;
|
|
205
|
+
raw[index] = Math.max(0, lake.level - field.heightAt(x, z));
|
|
206
|
+
}
|
|
207
|
+
// Flood from the seed through wet vertices only.
|
|
208
|
+
const depths = new Float32Array(count);
|
|
209
|
+
const stack = [0];
|
|
210
|
+
depths[0] = raw[0] as number;
|
|
211
|
+
const visit = (index: number): void => {
|
|
212
|
+
if ((raw[index] as number) > 0 && depths[index] === 0) {
|
|
213
|
+
depths[index] = raw[index] as number;
|
|
214
|
+
stack.push(index);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
while (stack.length > 0) {
|
|
218
|
+
const index = stack.pop() as number;
|
|
219
|
+
if (index === 0) {
|
|
220
|
+
for (let spoke = 0; spoke < spokes; spoke += 1) visit(1 + spoke);
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
const ring = Math.floor((index - 1) / spokes) + 1;
|
|
224
|
+
const spoke = (index - 1) % spokes;
|
|
225
|
+
const at = (r: number, s: number): number => (r === 0 ? 0 : 1 + (r - 1) * spokes + s);
|
|
226
|
+
visit(at(ring, (spoke + 1) % spokes));
|
|
227
|
+
visit(at(ring, (spoke + spokes - 1) % spokes));
|
|
228
|
+
visit(at(ring - 1, spoke));
|
|
229
|
+
if (ring + 1 < rings) visit(at(ring + 1, spoke));
|
|
230
|
+
}
|
|
231
|
+
return { x: cx, z: cz, reach, rings, spokes, packing, positions, depths };
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** Whether the disc cell holding (x, z) has a corner the seed's water reaches. */
|
|
235
|
+
function discReaches(disc: ILakeDisc, x: number, z: number): boolean {
|
|
236
|
+
const dx = x - disc.x;
|
|
237
|
+
const dz = z - disc.z;
|
|
238
|
+
const t = (Math.hypot(dx, dz) / disc.reach) ** (1 / disc.packing) * (disc.rings - 1);
|
|
239
|
+
const ring = Math.min(disc.rings - 2, Math.floor(t));
|
|
240
|
+
const turn = (Math.atan2(dz, dx) / (Math.PI * 2) + 1) % 1;
|
|
241
|
+
const spoke = Math.floor(turn * disc.spokes) % disc.spokes;
|
|
242
|
+
const at = (r: number, s: number): number => (r === 0 ? 0 : 1 + (r - 1) * disc.spokes + s);
|
|
243
|
+
const next = (spoke + 1) % disc.spokes;
|
|
244
|
+
return [at(ring, spoke), at(ring, next), at(ring + 1, spoke), at(ring + 1, next)].some(
|
|
245
|
+
(index) => (disc.depths[index] as number) > 0,
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
158
249
|
/**
|
|
159
250
|
* How far a lake's water reaches: the waterline its basin measures, `margin` times out, capped.
|
|
160
251
|
*
|
|
@@ -272,7 +363,11 @@ export class WaterBodies {
|
|
|
272
363
|
river === undefined ? Number.NEGATIVE_INFINITY : river.ha + (river.hb - river.ha) * along;
|
|
273
364
|
let kind: WaterBodyKind | undefined = river === undefined ? undefined : "river";
|
|
274
365
|
for (const pool of this.#pools)
|
|
275
|
-
if (
|
|
366
|
+
if (
|
|
367
|
+
(x - pool.x) ** 2 + (z - pool.z) ** 2 <= pool.radius2 &&
|
|
368
|
+
pool.level > level &&
|
|
369
|
+
!isolated(pool, x, z)
|
|
370
|
+
) {
|
|
276
371
|
level = pool.level;
|
|
277
372
|
river = undefined;
|
|
278
373
|
kind = "lake";
|
|
@@ -292,6 +387,20 @@ export class WaterBodies {
|
|
|
292
387
|
}
|
|
293
388
|
}
|
|
294
389
|
|
|
390
|
+
/** Ground under a lake's level that its water does not reach: a hollow past the basin's rim. */
|
|
391
|
+
function isolated(pool: IPool, x: number, z: number): boolean {
|
|
392
|
+
const disc = pool.disc;
|
|
393
|
+
if (disc === undefined || discReaches(disc, x, z)) return false;
|
|
394
|
+
const field = pool.field;
|
|
395
|
+
const minX = field.origin.x - field.width / 2;
|
|
396
|
+
const minZ = field.origin.z - field.depth / 2;
|
|
397
|
+
const ground = field.heightAt(
|
|
398
|
+
Math.max(minX, Math.min(minX + field.width, x)),
|
|
399
|
+
Math.max(minZ, Math.min(minZ + field.depth, z)),
|
|
400
|
+
);
|
|
401
|
+
return ground < pool.level;
|
|
402
|
+
}
|
|
403
|
+
|
|
295
404
|
/** One row of river stations as straight pieces, each as wide as the channel stands over. */
|
|
296
405
|
function buildReaches(ribbon: IWaterRibbon, into: IReach[]): void {
|
|
297
406
|
const width = positive(ribbon.width, "ribbon width");
|
|
@@ -329,8 +438,9 @@ function poolOf(field: Heightfield | undefined, lake: IWaterLake): IPool {
|
|
|
329
438
|
const [x = 0, z = 0] = lake.at;
|
|
330
439
|
finite(x, "lake x");
|
|
331
440
|
finite(z, "lake z");
|
|
332
|
-
const
|
|
333
|
-
|
|
441
|
+
const disc = lakeDisc(field, lake);
|
|
442
|
+
const radius = disc?.reach ?? 0;
|
|
443
|
+
return { level: lake.level, radius2: radius * radius, x, z, disc, field };
|
|
334
444
|
}
|
|
335
445
|
|
|
336
446
|
/**
|