@threenative/core 0.3.11 → 0.3.13
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/README.md +1 -1
- package/capabilities.json +1988 -204
- package/dist/{assets-YUbXa3-Y.d.ts → assets-CfMKnOsK.d.ts} +78 -1
- package/dist/camera-shake-CZKOfGn4.d.ts +46 -0
- package/dist/{canvas-layer-vCtanIeB.d.ts → canvas-layer-G7ttVy7y.d.ts} +1 -1
- package/dist/chunk-4SRAQFTU.js +133 -0
- package/dist/chunk-CFGTPFUH.js +231 -0
- package/dist/chunk-DIPIJICH.js +8916 -0
- package/dist/chunk-EEABDLUC.js +2237 -0
- package/dist/chunk-EFWZWLPY.js +1895 -0
- package/dist/chunk-GXY7B3JG.js +46 -0
- package/dist/chunk-GYUZJQ7U.js +280 -0
- package/dist/chunk-H4J6IAJE.js +504 -0
- package/dist/chunk-KIRUKTBQ.js +187 -0
- package/dist/chunk-QWJEMUUT.js +94 -0
- package/dist/chunk-SV4QVUTQ.js +31 -0
- package/dist/chunk-U4YHUKKL.js +615 -0
- package/dist/chunk-VP43GIWW.js +18 -0
- package/dist/chunk-XDTZ4QMO.js +160 -0
- package/dist/default-tone-mapping-GgKPTiBP.d.ts +4 -0
- package/dist/{game-DzMcitDO.d.ts → game-k8K3hZai.d.ts} +85 -9
- package/dist/hot.d.ts +5 -4
- package/dist/hot.js +5 -52
- package/dist/index.d.ts +633 -1351
- package/dist/index.js +12873 -23068
- package/dist/{model-lod-CTpZ6imz.d.ts → model-lod-DPTzeCcD.d.ts} +35 -3
- package/dist/playtest.d.ts +5 -4
- package/dist/playtest.js +25 -75
- package/dist/quality-BYqKGAwo.d.ts +868 -0
- package/dist/react-css.js +1 -215
- package/dist/react.d.ts +3 -2
- package/dist/render-environment.d.ts +170 -0
- package/dist/render-environment.js +352 -0
- package/dist/{renderer-rZm0hVqq.d.ts → renderer-BtOSseYf.d.ts} +42 -35
- package/dist/spells/index.d.ts +643 -0
- package/dist/spells/index.js +1558 -0
- package/dist/spells/ultra/index.d.ts +1600 -0
- package/dist/spells/ultra/index.js +6804 -0
- package/dist/terrain-jobs-worker.js +1 -123
- package/dist/two-sided-foliage-W523J3UM.js +1 -0
- package/dist/ui-layer.js +6 -384
- package/dist/worker.js +13 -43
- package/dist/world.d.ts +988 -268
- package/dist/world.js +17464 -18290
- package/mcp/animation-server.mjs +1 -1
- package/mcp/animation.mjs +2 -3
- package/mcp/engine-server.mjs +245 -52
- package/mcp/servers.mjs +10 -3
- package/mcp/terrain.mjs +8 -0
- package/package.json +19 -7
- package/patches/three@0.187.0-prd269-upgrade.patch +2102 -0
- package/patches/three@0.187.0.patch +2004 -407
- package/src/animation-batch.ts +193 -0
- package/src/animation-layers.ts +7 -3
- package/src/animation.ts +209 -29
- package/src/asset-cache.ts +3 -3
- package/src/asset-memo.ts +202 -0
- package/src/assets.ts +437 -125
- package/src/auto-batch.ts +190 -44
- package/src/card-lod.ts +152 -0
- package/src/compressed-texture-preparation.ts +1008 -0
- package/src/compute-driven.ts +1 -1
- package/src/config.ts +8 -0
- package/src/debug.ts +103 -22
- package/src/dev-global.ts +54 -0
- package/src/engine-hooks.ts +37 -0
- package/src/frame-budget.ts +50 -23
- package/src/game-boot-phase.ts +269 -0
- package/src/game-dev-tools.ts +86 -0
- package/src/game-frame-loop.ts +958 -0
- package/src/game-renderer-metrics.ts +77 -0
- package/src/game-startup.ts +1076 -0
- package/src/game-ui.ts +84 -0
- package/src/game-validate.ts +70 -0
- package/src/game.ts +198 -2264
- package/src/gamepad-mappings.ts +269 -0
- package/src/generated/console-markers.ts +13 -0
- package/src/geometry-capture.ts +28 -4
- package/src/gpu-readings.ts +98 -0
- package/src/gpu-scene-bvh.ts +149 -36
- package/src/hot.ts +4 -7
- package/src/index.ts +141 -9
- package/src/input.ts +237 -25
- package/src/instanced-batch-lod.ts +3 -8
- package/src/interpolation.ts +171 -40
- package/src/launch-diagnostics.ts +22 -12
- package/src/look/ao-admission.ts +25 -0
- package/src/look/auto-exposure.ts +5 -16
- package/src/look/default-tone-mapping.ts +41 -5
- package/src/look/filmic-tone-mapping.ts +15 -13
- package/src/look/local-exposure.ts +2 -7
- package/src/look/look-diagnostics.ts +3 -3
- package/src/look/quad-pass.ts +21 -0
- package/src/look/quality.ts +14 -5
- package/src/look/unreal-bloom.ts +4 -13
- package/src/look/world-environment.ts +113 -103
- package/src/loop.ts +29 -0
- package/src/merge-parts.ts +20 -24
- package/src/model-lod.ts +139 -17
- package/src/particle-kinds.ts +515 -0
- package/src/particle-significance.ts +12 -0
- package/src/particles.ts +19 -10
- package/src/picking.ts +17 -3
- package/src/platform.ts +23 -4
- package/src/playtest.ts +27 -1
- package/src/profiling/FrameStages.ts +5 -6
- package/src/profiling/Spans.ts +3 -17
- package/src/profiling/debug-telemetry.ts +2 -6
- package/src/profiling/render-list-validate.ts +6 -15
- package/src/projection-apply.ts +4 -1
- package/src/projection-marker.ts +2 -1
- package/src/projection-plan.ts +9 -6
- package/src/quiet-markers.ts +3 -10
- package/src/render/cpu-bvh.ts +100 -0
- package/src/render/depth-pyramid.ts +6 -14
- package/src/render/environment/environmentContribution.ts +202 -0
- package/src/render/environment/environmentRadiance.ts +44 -0
- package/src/render/environment/environmentSampleCache.ts +56 -0
- package/src/render/environment/environmentSampling.ts +201 -0
- package/src/render/environment/environmentSnapshot.ts +71 -0
- package/src/render/environment/gate.ts +57 -0
- package/src/render/mesh-pool.ts +4 -20
- package/src/render/probe-trace.ts +872 -0
- package/src/render/probe-volume.ts +780 -34
- package/src/render/radiance-cache.ts +17 -0
- package/src/render/resolution-subrect.ts +2 -0
- package/src/render/rough-diffuse.ts +46 -12
- package/src/render/soft-shadow.ts +27 -12
- package/src/render/virtual-shadow-adaptive.ts +55 -0
- package/src/render/virtual-shadow-casters.ts +175 -0
- package/src/render/virtual-shadow-layers.ts +76 -0
- package/src/render/virtual-shadow-level.ts +224 -0
- package/src/render/virtual-shadow-markers.ts +193 -0
- package/src/render/virtual-shadow-options.ts +370 -0
- package/src/render/virtual-shadow-pages.ts +5 -0
- package/src/render/virtual-shadow-partial.ts +13 -0
- package/src/render/virtual-shadow.ts +231 -1008
- package/src/render/world-impostor-surface.ts +402 -40
- package/src/render/world-impostor.ts +5 -2
- package/src/render-camera-cull.ts +98 -3
- package/src/render-environment.ts +41 -0
- package/src/render-pass-budget.ts +34 -7
- package/src/renderProjection.ts +22 -0
- package/src/renderer-config.ts +36 -0
- package/src/renderer-facts.ts +37 -0
- package/src/renderer.ts +144 -65
- package/src/resolution-scaler.ts +3 -2
- package/src/scene-entry-inspectors.ts +61 -0
- package/src/snow-field.ts +2 -1
- package/src/spells/cast-pool.ts +361 -0
- package/src/spells/index.ts +177 -0
- package/src/spells/mechanisms.ts +295 -0
- package/src/spells/reaction-field.ts +415 -0
- package/src/spells/spell-lights.ts +139 -0
- package/src/spells/spell-world.ts +187 -0
- package/src/spells/spell.ts +397 -0
- package/src/spells/spells.ts +283 -0
- package/src/spells/ultra/engine/camera.ts +184 -0
- package/src/spells/ultra/engine/quality.ts +96 -0
- package/src/spells/ultra/index.ts +52 -0
- package/src/spells/ultra/main.ts +305 -0
- package/src/spells/ultra/scene/arenaMaterial.ts +325 -0
- package/src/spells/ultra/spells/cast.ts +233 -0
- package/src/spells/ultra/spells/fire.ts +1267 -0
- package/src/spells/ultra/vfx/FluidVolume.ts +816 -0
- package/src/spells/ultra/vfx/FluidVolume.tsl.ts +855 -0
- package/src/spells/ultra/vfx/FxTarget.ts +61 -0
- package/src/spells/ultra/vfx/GroundField.ts +1399 -0
- package/src/spells/ultra/vfx/Particles.ts +1475 -0
- package/src/spells/ultra/vfx/Ribbons.ts +645 -0
- package/src/spells/ultra/vfx/Shockwaves.ts +286 -0
- package/src/spells/ultra/vfx/Volumes.ts +489 -0
- package/src/spells/ultra/vfx/common.ts +1195 -0
- package/src/spells/ultra/vfx/noise.ts +441 -0
- package/src/startup-offscreen-bytes.ts +78 -0
- package/src/startup-readiness.ts +128 -34
- package/src/static-transform.ts +25 -19
- package/src/streamed-textures.ts +112 -0
- package/src/streaming.ts +68 -4
- package/src/texture-streaming.ts +331 -0
- package/src/version.ts +1 -1
- package/src/warmup.ts +56 -8
- package/src/water-surface.ts +9 -3
- package/src/worker.ts +12 -2
- package/src/world-bundle-safety.ts +446 -0
- package/src/world-cell-batches.ts +1178 -0
- package/src/world-cell-chunks.ts +1128 -0
- package/src/world-cell-data.ts +995 -0
- package/src/world-cell-impostors.ts +1461 -0
- package/src/world-cell-lod-bias.ts +151 -0
- package/src/world-cell-models.ts +1074 -0
- package/src/world-cell-options.ts +177 -0
- package/src/world-cell-placements.ts +798 -0
- package/src/world-cell-prewarm.ts +592 -0
- package/src/world-cell-readiness.ts +357 -0
- package/src/world-cell-records.ts +401 -0
- package/src/world-cell-render-bundles.ts +459 -0
- package/src/world-cell-render-gpu-dress.ts +710 -0
- package/src/world-cell-render-main-cull.ts +540 -0
- package/src/world-cell-render-shadow-claims.ts +198 -0
- package/src/world-cell-render-util.ts +259 -0
- package/src/world-cell-render.ts +1501 -0
- package/src/world-cell-residency.ts +754 -0
- package/src/world-cell-stale.ts +238 -0
- package/src/world-cells.ts +1335 -10418
- package/src/world-chunk-shadow.ts +308 -0
- package/src/world-collar.ts +315 -0
- package/src/world-gpu-flags.ts +131 -0
- package/src/world-gpu-readback.ts +881 -0
- package/src/world-gpu-reference.ts +524 -0
- package/src/world-gpu-scene.ts +256 -2286
- package/src/world-gpu-shadow.ts +203 -0
- package/src/world-gpu-types.ts +409 -0
- package/src/world-gpu-validation.ts +518 -0
- package/src/world-heightfield.ts +802 -0
- package/src/world-load-limiter.ts +111 -0
- package/src/world-model-sections.ts +80 -0
- package/src/world-noise.ts +241 -0
- package/src/world-package.ts +42 -0
- package/src/world-region.ts +1 -1
- package/src/world-river-ribbon.ts +282 -0
- package/src/world-root-frame.ts +39 -0
- package/src/world-shore-field.ts +91 -0
- package/src/world-static-pose.ts +163 -0
- package/src/world-surface-sampler.ts +48 -0
- package/src/world-terrain-splat.ts +361 -153
- package/src/world-tile-budget.ts +249 -0
- package/src/world-tile-geometry.ts +469 -0
- package/src/world-tile-lod.ts +408 -0
- package/src/world-tile-observation.ts +566 -0
- package/src/world-tile-stitch.ts +166 -0
- package/src/world-tiles.ts +247 -1755
- package/src/world-validate.ts +6 -14
- package/src/world-warm.ts +51 -0
- package/src/world-water-bodies.ts +359 -0
- package/src/world.ts +48 -741
package/src/platform.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type PlatformRuntime = "web" | "native";
|
|
2
|
-
export type PlatformOS = "android" | "ios" | "linux" | "macos" | "windows" | "unknown";
|
|
3
|
-
export type PlatformFormFactor = "mobile" | "desktop" | "unknown";
|
|
2
|
+
export type PlatformOS = "android" | "ios" | "linux" | "macos" | "windows" | "ps4" | "unknown";
|
|
3
|
+
export type PlatformFormFactor = "mobile" | "desktop" | "console" | "unknown";
|
|
4
4
|
|
|
5
5
|
export interface IPlatformInfo {
|
|
6
6
|
readonly runtime: PlatformRuntime;
|
|
@@ -22,6 +22,7 @@ interface IUserAgentData {
|
|
|
22
22
|
|
|
23
23
|
const DESKTOP_OS = new Set<PlatformOS>(["linux", "macos", "windows"]);
|
|
24
24
|
const MOBILE_OS = new Set<PlatformOS>(["android", "ios"]);
|
|
25
|
+
const CONSOLE_OS = new Set<PlatformOS>(["ps4"]);
|
|
25
26
|
|
|
26
27
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
27
28
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -51,11 +52,17 @@ function nativePlatform(source: unknown): Readonly<IPlatformInfo> {
|
|
|
51
52
|
os !== "linux" &&
|
|
52
53
|
os !== "macos" &&
|
|
53
54
|
os !== "windows" &&
|
|
55
|
+
os !== "ps4" &&
|
|
54
56
|
os !== "unknown"
|
|
55
57
|
) {
|
|
56
58
|
invalidNativePlatform("os is unknown");
|
|
57
59
|
}
|
|
58
|
-
if (
|
|
60
|
+
if (
|
|
61
|
+
formFactor !== "mobile" &&
|
|
62
|
+
formFactor !== "desktop" &&
|
|
63
|
+
formFactor !== "console" &&
|
|
64
|
+
formFactor !== "unknown"
|
|
65
|
+
) {
|
|
59
66
|
invalidNativePlatform("formFactor is unknown");
|
|
60
67
|
}
|
|
61
68
|
if (!Number.isInteger(maxTouchPoints) || (maxTouchPoints as number) < 0) {
|
|
@@ -66,7 +73,9 @@ function nativePlatform(source: unknown): Readonly<IPlatformInfo> {
|
|
|
66
73
|
? "mobile"
|
|
67
74
|
: DESKTOP_OS.has(os as PlatformOS)
|
|
68
75
|
? "desktop"
|
|
69
|
-
:
|
|
76
|
+
: CONSOLE_OS.has(os as PlatformOS)
|
|
77
|
+
? "console"
|
|
78
|
+
: "unknown";
|
|
70
79
|
if (formFactor !== expectedFormFactor) {
|
|
71
80
|
invalidNativePlatform("os and formFactor disagree");
|
|
72
81
|
}
|
|
@@ -209,6 +218,16 @@ export function isMobile(): boolean {
|
|
|
209
218
|
return getPlatform().formFactor === "mobile";
|
|
210
219
|
}
|
|
211
220
|
|
|
221
|
+
/** A games console (PS4): a pad is the input, there is no keyboard, mouse or touchscreen. */
|
|
222
|
+
export function isConsole(): boolean {
|
|
223
|
+
return getPlatform().formFactor === "console";
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** A PlayStation 4: the pad is a DualShock 4, so its buttons are ✕ ○ □ △ and OPTIONS. */
|
|
227
|
+
export function isPs4(): boolean {
|
|
228
|
+
return getPlatform().os === "ps4";
|
|
229
|
+
}
|
|
230
|
+
|
|
212
231
|
export function isTouchscreenAvailable(): boolean {
|
|
213
232
|
return getPlatform().maxTouchPoints > 0;
|
|
214
233
|
}
|
package/src/playtest.ts
CHANGED
|
@@ -235,7 +235,19 @@ export function playtest<
|
|
|
235
235
|
// measures a frame rate for a game, and the frozen loop's presented frames repeat a
|
|
236
236
|
// standing state while the scenario's ticks arrive in bursts — a profile of a game that is
|
|
237
237
|
// not playing. It asked by name, so it is not frozen.
|
|
238
|
-
|
|
238
|
+
//
|
|
239
|
+
// The settling pass the freeze owes the world is named zero here, and spent by `describe()`
|
|
240
|
+
// once the start scene has entered: a loop that spends it on its first live frame settles
|
|
241
|
+
// whatever scene that frame draws, and the 60 steps it ran then reach no world clock at
|
|
242
|
+
// all. That made the same anchor 1.0 s apart between two engines on the sailing pose, by
|
|
243
|
+
// their boot order alone. Only a hold can spend it on demand: a game that asked for no
|
|
244
|
+
// hold (`holdUntilAttached: false`) has no `describe()` to settle from, so a zero freeze
|
|
245
|
+
// there would leave the world as the game built it for the whole run. A runtime with no
|
|
246
|
+
// `settleClock` keeps the frame's own settle, for the same reason.
|
|
247
|
+
if (!wallClock)
|
|
248
|
+
runtime?.freezeClock?.(
|
|
249
|
+
shouldHoldUntilAttached(options) && runtime.settleClock !== undefined ? 0 : undefined,
|
|
250
|
+
);
|
|
239
251
|
}
|
|
240
252
|
dispose = installation.dispose;
|
|
241
253
|
attached = holdUntilAttached(
|
|
@@ -243,6 +255,11 @@ export function playtest<
|
|
|
243
255
|
options,
|
|
244
256
|
() => startSceneEntered,
|
|
245
257
|
runtime?.startSceneLoaded,
|
|
258
|
+
// The live mode, not the one this setup started with: a run that switched to the wall
|
|
259
|
+
// clock mid-run measures frames, and a settle would re-freeze the loop it just released.
|
|
260
|
+
() => {
|
|
261
|
+
if (clockMode !== "wall-clock") runtime?.settleClock?.();
|
|
262
|
+
},
|
|
246
263
|
);
|
|
247
264
|
const cleanup = () => {
|
|
248
265
|
if (!clockDisposed && clockRuntime?._setClockMode !== undefined)
|
|
@@ -395,6 +412,7 @@ function holdUntilAttached(
|
|
|
395
412
|
options: IPlaytestOptions,
|
|
396
413
|
startSceneEntered: () => Promise<void> | undefined,
|
|
397
414
|
startSceneLoaded?: () => Promise<void>,
|
|
415
|
+
settleClock?: () => void,
|
|
398
416
|
): Promise<void> | undefined {
|
|
399
417
|
if (!shouldHoldUntilAttached(options)) return undefined;
|
|
400
418
|
const timeoutMs = options.attachTimeoutMs ?? PLAYTEST_ATTACH_TIMEOUT_MS;
|
|
@@ -403,6 +421,13 @@ function holdUntilAttached(
|
|
|
403
421
|
}
|
|
404
422
|
const describe = bridge.describe;
|
|
405
423
|
const applySetup = bridge.applySetup;
|
|
424
|
+
// Once per run: the settle is a settling pass, not a step every describe repeats.
|
|
425
|
+
let worldSettled = false;
|
|
426
|
+
const settle = () => {
|
|
427
|
+
if (worldSettled) return;
|
|
428
|
+
worldSettled = true;
|
|
429
|
+
settleClock?.();
|
|
430
|
+
};
|
|
406
431
|
return new Promise<void>((resolve, reject) => {
|
|
407
432
|
let settled = false;
|
|
408
433
|
const timer = setTimeout(() => {
|
|
@@ -445,6 +470,7 @@ function holdUntilAttached(
|
|
|
445
470
|
bridge.describe = async () => {
|
|
446
471
|
release();
|
|
447
472
|
await startSceneEntered();
|
|
473
|
+
settle();
|
|
448
474
|
return describe();
|
|
449
475
|
};
|
|
450
476
|
});
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* stages (`wasmRendererGap` is what `Renderer::render` spends outside its plan and encode halves) so the unlocated time is a number and never a quiet category. On an engine that publishes no
|
|
17
17
|
* stage totals (upstream three), the whole call is `engineJs`.
|
|
18
18
|
*/
|
|
19
|
+
import { readLaunchFlag } from "../debug.js";
|
|
19
20
|
|
|
20
21
|
import type { IFrameCounters } from "./FrameCounters.js";
|
|
21
22
|
|
|
@@ -217,12 +218,10 @@ export function createStageReader(
|
|
|
217
218
|
* `stages`: the paired A/B that prices the meters runs one build with this switch alone.
|
|
218
219
|
*/
|
|
219
220
|
export function stageMetersRequested(): boolean {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
if (typeof query === "string" && /[?&]tnStages=(?:0|false)(?:&|$)/u.test(query)) return false;
|
|
225
|
-
return host.__tnStages !== false;
|
|
221
|
+
return !readLaunchFlag(
|
|
222
|
+
{ environment: "TN_STAGES", global: "__tnStages", query: "tnStages" },
|
|
223
|
+
"off",
|
|
224
|
+
);
|
|
226
225
|
}
|
|
227
226
|
|
|
228
227
|
interface IEngineWorkHost {
|
package/src/profiling/Spans.ts
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
* The ids are integers on the hot path — a span call must not allocate a string to be cheap enough
|
|
24
24
|
* to put around a per-draw call — and the names exist only in the report.
|
|
25
25
|
*/
|
|
26
|
+
import { readLaunchFlag } from "../debug.js";
|
|
26
27
|
|
|
27
28
|
/** Marker printed once per report window when spans are installed. */
|
|
28
29
|
import { countDebug, debugRequested } from "./debug-telemetry.js";
|
|
@@ -535,24 +536,9 @@ export function addSpan(id: SpanId, ms: number): void {
|
|
|
535
536
|
* `globalThis.__tnFrameSpans` before the game boots.
|
|
536
537
|
*/
|
|
537
538
|
export function spansRequested(): boolean {
|
|
538
|
-
if (debugRequested()) return true;
|
|
539
|
-
const host = globalThis as {
|
|
540
|
-
process?: { env?: Record<string, unknown> };
|
|
541
|
-
__tnFrameSpans?: unknown;
|
|
542
|
-
};
|
|
543
|
-
const fromEnv = host.process?.env?.[SPANS_FLAG];
|
|
544
|
-
if (typeof fromEnv === "string" && fromEnv !== "" && fromEnv !== "0" && fromEnv !== "false")
|
|
545
|
-
return true;
|
|
546
|
-
const query = globalThis.location?.search;
|
|
547
|
-
if (typeof query === "string" && /[?&]tnFrameSpans=(?!0(?:&|$))(?!false(?:&|$))[^&]/u.test(query))
|
|
548
|
-
return true;
|
|
549
|
-
const fromGlobal = host.__tnFrameSpans;
|
|
550
539
|
return (
|
|
551
|
-
|
|
552
|
-
(
|
|
553
|
-
fromGlobal !== "" &&
|
|
554
|
-
fromGlobal !== "0" &&
|
|
555
|
-
fromGlobal !== "false")
|
|
540
|
+
debugRequested() ||
|
|
541
|
+
readLaunchFlag({ environment: SPANS_FLAG, global: "__tnFrameSpans", query: "tnFrameSpans" })
|
|
556
542
|
);
|
|
557
543
|
}
|
|
558
544
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readLaunchFlag } from "../debug.js";
|
|
1
2
|
import type { IFrameBudgetWindow } from "../frame-budget.js";
|
|
2
3
|
|
|
3
4
|
export interface IDebugSource {
|
|
@@ -34,12 +35,7 @@ export function isContentScaled(name: string): boolean {
|
|
|
34
35
|
const DEBUG_GLOBAL = "__THREENATIVE_DEBUG__";
|
|
35
36
|
|
|
36
37
|
export function debugRequested(): boolean {
|
|
37
|
-
|
|
38
|
-
return (
|
|
39
|
-
host.process?.env?.TN_DEBUG === "1" ||
|
|
40
|
-
(globalThis as Record<string, unknown>)[DEBUG_GLOBAL] === true ||
|
|
41
|
-
/[?&]tnDebug=1(?:&|$)/u.test(globalThis.location?.search ?? "")
|
|
42
|
-
);
|
|
38
|
+
return readLaunchFlag({ environment: "TN_DEBUG", global: DEBUG_GLOBAL, query: "tnDebug" });
|
|
43
39
|
}
|
|
44
40
|
|
|
45
41
|
/** Debug-only producers call this; the existing engine-cost reader owns the per-frame difference. */
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*
|
|
14
14
|
* Off by default and expensive by construction — it does the work it is checking, twice.
|
|
15
15
|
*/
|
|
16
|
+
import { readLaunchFlag } from "../debug.js";
|
|
16
17
|
|
|
17
18
|
import { Matrix4, type Object3D } from "three";
|
|
18
19
|
import { composeSilencedByFreeze, worldSilencedByFreeze } from "../static-transform.js";
|
|
@@ -34,21 +35,11 @@ const TOLERANCE = 1e-6;
|
|
|
34
35
|
|
|
35
36
|
/** Whether `TN_RENDERLIST_VALIDATE` asks for validation on this launch. */
|
|
36
37
|
export function renderListValidationRequested(): boolean {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
__tnRenderListValidate
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (typeof fromEnv === "string" && fromEnv !== "" && fromEnv !== "0" && fromEnv !== "false")
|
|
43
|
-
return true;
|
|
44
|
-
const query = globalThis.location?.search;
|
|
45
|
-
if (
|
|
46
|
-
typeof query === "string" &&
|
|
47
|
-
/[?&]tnRenderListValidate=(?!0(?:&|$))(?!false(?:&|$))[^&]/u.test(query)
|
|
48
|
-
)
|
|
49
|
-
return true;
|
|
50
|
-
const fromGlobal = host.__tnRenderListValidate;
|
|
51
|
-
return fromGlobal === true || fromGlobal === "1";
|
|
38
|
+
return readLaunchFlag({
|
|
39
|
+
environment: RENDERLIST_VALIDATE_FLAG,
|
|
40
|
+
global: "__tnRenderListValidate",
|
|
41
|
+
query: "tnRenderListValidate",
|
|
42
|
+
});
|
|
52
43
|
}
|
|
53
44
|
|
|
54
45
|
/** What one frame's check found. */
|
package/src/projection-apply.ts
CHANGED
|
@@ -859,6 +859,10 @@ export class ProjectionMirror {
|
|
|
859
859
|
#syncLights(lights: readonly (Light | undefined)[], lightCount: number): string | undefined {
|
|
860
860
|
for (let index = 0; index < lightCount; index += 1) {
|
|
861
861
|
const light = lights[index] as Light;
|
|
862
|
+
const shadow = (light as Light & { shadow?: { autoUpdate: boolean; shadowNode?: unknown } })
|
|
863
|
+
.shadow;
|
|
864
|
+
if (shadow?.shadowNode != null)
|
|
865
|
+
return `a ${light.type} uses a custom shadow node that cannot be mirrored`;
|
|
862
866
|
let proxy = this.#lightProxies.get(light);
|
|
863
867
|
if (proxy === undefined) {
|
|
864
868
|
const cloned = light.clone() as Light & { target?: Object3D };
|
|
@@ -903,7 +907,6 @@ export class ProjectionMirror {
|
|
|
903
907
|
}
|
|
904
908
|
// The clone above copied `autoUpdate` before it was switched off, so the drawn light keeps
|
|
905
909
|
// its shadow. Only the source — whose map nothing samples this frame — is taken offline.
|
|
906
|
-
const shadow = (light as Light & { shadow?: { autoUpdate: boolean } }).shadow;
|
|
907
910
|
if (
|
|
908
911
|
shadow !== undefined &&
|
|
909
912
|
shadow.autoUpdate === true &&
|
package/src/projection-marker.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CONSOLE_MARKER } from "./generated/console-markers.js";
|
|
1
2
|
import type { IMatrixWorldReport } from "./matrix-world.js";
|
|
2
3
|
import type { IRenderCameraCullReport } from "./render-camera-cull.js";
|
|
3
4
|
import type {
|
|
@@ -15,7 +16,7 @@ import type {
|
|
|
15
16
|
* produces a series rather than a single sentence, and it carries the one thing the projection
|
|
16
17
|
* cannot know on its own: how many draws the renderer was actually handed.
|
|
17
18
|
*/
|
|
18
|
-
export const PROJECTION_MARKER =
|
|
19
|
+
export const PROJECTION_MARKER = CONSOLE_MARKER.projection;
|
|
19
20
|
|
|
20
21
|
export interface IProjectionWindowJson {
|
|
21
22
|
/**
|
package/src/projection-plan.ts
CHANGED
|
@@ -1438,27 +1438,30 @@ export function scanProjection(
|
|
|
1438
1438
|
workspace.scanNumber += 1;
|
|
1439
1439
|
const state = walkProjection(source, workspace);
|
|
1440
1440
|
|
|
1441
|
-
|
|
1441
|
+
// The floor first: a scene too small to batch declines whatever it carries, and naming a hook or
|
|
1442
|
+
// an authored BatchedMesh there reports a decline that removing it would not lift. The walk
|
|
1443
|
+
// counts every eligible mesh past a block, so the floor reads the whole scene either way.
|
|
1444
|
+
if (workspace.eligibleCount + workspace.skinnedCount * SKINNED_FLOOR_WEIGHT < minMeshes) {
|
|
1442
1445
|
return {
|
|
1443
1446
|
exactLane: workspace.exactLane,
|
|
1444
1447
|
exactLaneCount: workspace.exactLaneCount,
|
|
1445
1448
|
plan: {
|
|
1446
1449
|
action: "decline",
|
|
1447
|
-
reasonCode:
|
|
1448
|
-
reason:
|
|
1450
|
+
reasonCode: "belowMeshFloor",
|
|
1451
|
+
reason: `fewer than ${minMeshes} batchable meshes; the mirror would cost more than it saves`,
|
|
1449
1452
|
},
|
|
1450
1453
|
renderables: state.renderables,
|
|
1451
1454
|
seen: workspace.seen,
|
|
1452
1455
|
};
|
|
1453
1456
|
}
|
|
1454
|
-
if (
|
|
1457
|
+
if (state.blocked !== undefined) {
|
|
1455
1458
|
return {
|
|
1456
1459
|
exactLane: workspace.exactLane,
|
|
1457
1460
|
exactLaneCount: workspace.exactLaneCount,
|
|
1458
1461
|
plan: {
|
|
1459
1462
|
action: "decline",
|
|
1460
|
-
reasonCode:
|
|
1461
|
-
reason:
|
|
1463
|
+
reasonCode: state.blocked.code,
|
|
1464
|
+
reason: state.blocked.reason,
|
|
1462
1465
|
},
|
|
1463
1466
|
renderables: state.renderables,
|
|
1464
1467
|
seen: workspace.seen,
|
package/src/quiet-markers.ts
CHANGED
|
@@ -9,24 +9,17 @@
|
|
|
9
9
|
* Only a real browser page installs it: the native host stubs `document.location` but sets no
|
|
10
10
|
* `globalThis.location`, so a native game keeps its console as the host prints it.
|
|
11
11
|
*/
|
|
12
|
+
import { readLaunchFlag } from "./debug.js";
|
|
13
|
+
|
|
12
14
|
const LOG_FLAG = "TN_LOG";
|
|
13
15
|
const BROWSER_PROTOCOLS = new Set(["http:", "https:", "file:"]);
|
|
14
16
|
|
|
15
17
|
type ConsoleMethod = (...args: unknown[]) => void;
|
|
16
18
|
let restore: { log: ConsoleMethod; info: ConsoleMethod } | undefined;
|
|
17
19
|
|
|
18
|
-
const isOn = (value: unknown): boolean =>
|
|
19
|
-
value === true ||
|
|
20
|
-
(typeof value === "string" && value !== "" && value !== "0" && value !== "false");
|
|
21
|
-
|
|
22
20
|
/** Whether `TN_LOG` asks for markers at their own console level on this launch. */
|
|
23
21
|
export function markerLogRequested(): boolean {
|
|
24
|
-
|
|
25
|
-
if (isOn(host.process?.env?.[LOG_FLAG])) return true;
|
|
26
|
-
const query = globalThis.location?.search;
|
|
27
|
-
if (typeof query === "string" && /[?&]tnLog=(?!0(?:&|$))(?!false(?:&|$))[^&]/u.test(query))
|
|
28
|
-
return true;
|
|
29
|
-
return isOn((globalThis as Record<string, unknown>).__THREENATIVE_LOG__);
|
|
22
|
+
return readLaunchFlag({ environment: LOG_FLAG, global: "__THREENATIVE_LOG__", query: "tnLog" });
|
|
30
23
|
}
|
|
31
24
|
|
|
32
25
|
/** Re-routes `TN_` log/info lines to `console.debug`; a second call is a no-op. */
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A CPU bounding-volume hierarchy for the probe trace, in the node layout the trace threads
|
|
3
|
+
* (`threadBvh`): 8 words a node, bounds as 6 floats, then a leaf offset and `0xffff0000 | count`, or the
|
|
4
|
+
* right child's distance in nodes and an axis. The left child of node `i` is node `i + 1`.
|
|
5
|
+
*
|
|
6
|
+
* It exists because the owned engine's `MeshBVH` builds no tree (`TN_NATIVE_MESH_BVH_OPTIONS_UNSUPPORTED`),
|
|
7
|
+
* so `GPUSceneBVH` cannot take its nodes there. A median split along the longest centroid axis is
|
|
8
|
+
* slower to trace than a surface-area split. It builds in O(n log^2 n) and is correct on any engine.
|
|
9
|
+
*/
|
|
10
|
+
const LEAF_FLAG = 0xffff0000;
|
|
11
|
+
export const CPU_BVH_LEAF_SIZE = 8;
|
|
12
|
+
|
|
13
|
+
export interface ICpuBvh {
|
|
14
|
+
/** 8 words a node, depth-first, left child first. */
|
|
15
|
+
readonly nodes: Uint32Array;
|
|
16
|
+
/** `order[slot]` is the source triangle held at leaf slot `slot`. */
|
|
17
|
+
readonly order: Uint32Array;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** `positions` are tight xyz triples and `indices` three vertex indices a triangle. */
|
|
21
|
+
export function buildCpuBvh(positions: Float32Array, indices: Uint32Array): ICpuBvh {
|
|
22
|
+
const count = Math.floor(indices.length / 3);
|
|
23
|
+
const order = Uint32Array.from({ length: count }, (_, i) => i);
|
|
24
|
+
if (count === 0) return { nodes: new Uint32Array(8), order };
|
|
25
|
+
const low = new Float32Array(count * 3);
|
|
26
|
+
const high = new Float32Array(count * 3);
|
|
27
|
+
const centre = new Float32Array(count * 3);
|
|
28
|
+
for (let t = 0; t < count; t += 1) {
|
|
29
|
+
for (let axis = 0; axis < 3; axis += 1) {
|
|
30
|
+
let lo = Number.POSITIVE_INFINITY;
|
|
31
|
+
let hi = Number.NEGATIVE_INFINITY;
|
|
32
|
+
for (let corner = 0; corner < 3; corner += 1) {
|
|
33
|
+
const value = positions[(indices[t * 3 + corner] as number) * 3 + axis] as number;
|
|
34
|
+
lo = Math.min(lo, value);
|
|
35
|
+
hi = Math.max(hi, value);
|
|
36
|
+
}
|
|
37
|
+
low[t * 3 + axis] = lo;
|
|
38
|
+
high[t * 3 + axis] = hi;
|
|
39
|
+
centre[t * 3 + axis] = (lo + hi) / 2;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const words: number[] = [];
|
|
43
|
+
const floats = new Float32Array(1);
|
|
44
|
+
const bits = new Uint32Array(floats.buffer);
|
|
45
|
+
const bitsOf = (value: number): number => {
|
|
46
|
+
floats[0] = value;
|
|
47
|
+
return bits[0] as number;
|
|
48
|
+
};
|
|
49
|
+
const build = (start: number, end: number): number => {
|
|
50
|
+
const node = words.length / 8;
|
|
51
|
+
words.push(0, 0, 0, 0, 0, 0, 0, 0);
|
|
52
|
+
const box = [
|
|
53
|
+
Number.POSITIVE_INFINITY,
|
|
54
|
+
Number.POSITIVE_INFINITY,
|
|
55
|
+
Number.POSITIVE_INFINITY,
|
|
56
|
+
Number.NEGATIVE_INFINITY,
|
|
57
|
+
Number.NEGATIVE_INFINITY,
|
|
58
|
+
Number.NEGATIVE_INFINITY,
|
|
59
|
+
];
|
|
60
|
+
const middle = [
|
|
61
|
+
Number.POSITIVE_INFINITY,
|
|
62
|
+
Number.POSITIVE_INFINITY,
|
|
63
|
+
Number.POSITIVE_INFINITY,
|
|
64
|
+
Number.NEGATIVE_INFINITY,
|
|
65
|
+
Number.NEGATIVE_INFINITY,
|
|
66
|
+
Number.NEGATIVE_INFINITY,
|
|
67
|
+
];
|
|
68
|
+
for (let slot = start; slot < end; slot += 1) {
|
|
69
|
+
const t = order[slot] as number;
|
|
70
|
+
for (let axis = 0; axis < 3; axis += 1) {
|
|
71
|
+
box[axis] = Math.min(box[axis] as number, low[t * 3 + axis] as number);
|
|
72
|
+
box[axis + 3] = Math.max(box[axis + 3] as number, high[t * 3 + axis] as number);
|
|
73
|
+
middle[axis] = Math.min(middle[axis] as number, centre[t * 3 + axis] as number);
|
|
74
|
+
middle[axis + 3] = Math.max(middle[axis + 3] as number, centre[t * 3 + axis] as number);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
for (let i = 0; i < 6; i += 1) words[node * 8 + i] = bitsOf(box[i] as number);
|
|
78
|
+
const spread = (a: number) => (middle[a + 3] as number) - (middle[a] as number);
|
|
79
|
+
let axis = 0;
|
|
80
|
+
if (spread(1) > spread(axis)) axis = 1;
|
|
81
|
+
if (spread(2) > spread(axis)) axis = 2;
|
|
82
|
+
if (end - start <= CPU_BVH_LEAF_SIZE || spread(axis) <= 0) {
|
|
83
|
+
words[node * 8 + 6] = start;
|
|
84
|
+
words[node * 8 + 7] = (LEAF_FLAG | (end - start)) >>> 0;
|
|
85
|
+
return node;
|
|
86
|
+
}
|
|
87
|
+
const slice = Array.from(order.subarray(start, end)).sort(
|
|
88
|
+
(a, b) => (centre[a * 3 + axis] as number) - (centre[b * 3 + axis] as number),
|
|
89
|
+
);
|
|
90
|
+
order.set(slice, start);
|
|
91
|
+
const half = start + ((end - start) >> 1);
|
|
92
|
+
build(start, half);
|
|
93
|
+
const right = build(half, end);
|
|
94
|
+
words[node * 8 + 6] = right - node;
|
|
95
|
+
words[node * 8 + 7] = axis;
|
|
96
|
+
return node;
|
|
97
|
+
};
|
|
98
|
+
build(0, count);
|
|
99
|
+
return { nodes: Uint32Array.from(words), order };
|
|
100
|
+
}
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
vec4,
|
|
23
23
|
} from "three/tsl";
|
|
24
24
|
import { StorageBufferAttribute } from "three/webgpu";
|
|
25
|
+
import { readLaunchValue } from "../debug.js";
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* The hierarchical-depth (pyramid) occlusion test, and the max-distance pyramid it reads.
|
|
@@ -64,21 +65,12 @@ export type OcclusionMode = "off" | "measure";
|
|
|
64
65
|
* browser asks with `?tnOcclusion=measure`, and a test sets the global.
|
|
65
66
|
*/
|
|
66
67
|
export function occlusionMode(): OcclusionMode {
|
|
67
|
-
const host = globalThis as {
|
|
68
|
-
process?: { env?: Record<string, unknown> };
|
|
69
|
-
__tnOcclusion?: unknown;
|
|
70
|
-
location?: { search?: string };
|
|
71
|
-
};
|
|
72
|
-
const fromEnv = host.process?.env?.[OCCLUSION_FLAG];
|
|
73
|
-
const query = host.location?.search;
|
|
74
68
|
const asked =
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
:
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
? host.__tnOcclusion
|
|
81
|
-
: "";
|
|
69
|
+
readLaunchValue({
|
|
70
|
+
environment: OCCLUSION_FLAG,
|
|
71
|
+
global: "__tnOcclusion",
|
|
72
|
+
query: "tnOcclusion",
|
|
73
|
+
}) ?? "";
|
|
82
74
|
const value = asked.trim().toLowerCase();
|
|
83
75
|
if (value === "" || value === "0" || value === "off" || value === "false") return "off";
|
|
84
76
|
if (value === "measure" || value === "1" || value === "true") return "measure";
|