@threenative/core 0.3.12 → 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/README.md +1 -1
- package/capabilities.json +1047 -44
- package/dist/{assets-YUbXa3-Y.d.ts → assets-CfMKnOsK.d.ts} +78 -1
- package/dist/{canvas-layer-CWuFRT7G.d.ts → canvas-layer-G7ttVy7y.d.ts} +1 -1
- package/dist/{chunk-7UUT3TY5.js → chunk-2GPHICV6.js} +1 -1
- package/dist/{chunk-GMHATRPW.js → chunk-GEMQJBY4.js} +1650 -383
- package/dist/{chunk-VAZM36TV.js → chunk-H4J6IAJE.js} +17 -10
- package/dist/{chunk-5O73CDMR.js → chunk-QAMSM3Z5.js} +415 -27
- package/dist/{chunk-2Z44XSI2.js → chunk-QAQHYOWY.js} +3 -7
- package/dist/{chunk-DBELTTTM.js → chunk-U4YHUKKL.js} +1 -1
- package/dist/{chunk-OKXUCASC.js → chunk-VBBYWGAT.js} +3 -4
- package/dist/chunk-VP43GIWW.js +18 -0
- package/dist/{chunk-N5LRP4BR.js → chunk-VQRPEOKY.js} +66 -3
- package/dist/{chunk-6KLNISRJ.js → chunk-XDTZ4QMO.js} +11 -4
- package/dist/default-tone-mapping-GgKPTiBP.d.ts +4 -0
- package/dist/{game-D7pAzZUY.d.ts → game-k8K3hZai.d.ts} +72 -8
- package/dist/hot.d.ts +5 -4
- package/dist/hot.js +5 -8
- package/dist/index.d.ts +871 -1018
- package/dist/index.js +4786 -1631
- package/dist/{model-lod-B6BMqS1r.d.ts → model-lod-DPTzeCcD.d.ts} +4 -2
- package/dist/playtest.d.ts +5 -4
- package/dist/playtest.js +6 -5
- package/dist/quality-BADStsTn.d.ts +868 -0
- 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-DvFVoAgj.d.ts → renderer-BtOSseYf.d.ts} +29 -31
- package/dist/spells/index.js +1 -1
- package/dist/ui-layer.js +3 -2
- package/dist/worker.js +12 -5
- package/dist/world.d.ts +280 -16
- package/dist/world.js +1529 -642
- package/mcp/animation-server.mjs +1 -1
- package/mcp/engine-server.mjs +135 -11
- package/mcp/servers.mjs +4 -4
- package/package.json +10 -6
- package/scripts/ensure-mcp.mjs +6 -1
- 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 +436 -131
- package/src/auto-batch.ts +190 -44
- package/src/clustered-batch.ts +146 -3
- package/src/clustered-mesh.ts +548 -20
- package/src/compute-driven.ts +1 -1
- package/src/config.ts +8 -0
- package/src/debug.ts +119 -22
- package/src/dev-global.ts +54 -0
- package/src/displaced-surface.ts +428 -0
- package/src/engine-hooks.ts +37 -0
- package/src/frame-budget.ts +35 -3
- package/src/game-boot-phase.ts +269 -0
- package/src/game-dev-tools.ts +7 -14
- package/src/game-frame-loop.ts +45 -82
- package/src/game-startup.ts +145 -70
- package/src/game-ui.ts +84 -0
- package/src/game.ts +168 -552
- package/src/gamepad-mappings.ts +269 -0
- package/src/generated/console-markers.ts +14 -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/grass-field.ts +628 -0
- package/src/hot.ts +4 -7
- package/src/index.ts +227 -8
- package/src/input.ts +237 -25
- package/src/instanced-batch-lod.ts +3 -8
- package/src/interpolation.ts +171 -40
- package/src/look/ao-admission.ts +4 -3
- package/src/look/auto-exposure.ts +5 -16
- package/src/look/default-tone-mapping.ts +41 -5
- package/src/look/local-exposure.ts +2 -7
- package/src/look/quad-pass.ts +21 -0
- package/src/look/quality.ts +4 -0
- package/src/look/unreal-bloom.ts +4 -13
- package/src/look/world-environment.ts +58 -115
- package/src/merge-parts.ts +20 -24
- package/src/model-lod.ts +97 -14
- package/src/particle-significance.ts +12 -0
- package/src/particles.ts +19 -10
- package/src/platform.ts +23 -4
- 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-marker.ts +2 -1
- 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/material-key.ts +21 -1
- package/src/render/mesh-pool.ts +3 -19
- 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/screen-probe-gather.ts +303 -0
- package/src/render/short-range-ao.ts +274 -0
- package/src/render/virtual-shadow-partial.ts +13 -0
- package/src/render/virtual-shadow.ts +18 -16
- package/src/render/world-impostor-surface.ts +207 -9
- package/src/render/world-impostor.ts +5 -2
- package/src/render-camera-cull.ts +105 -4
- package/src/render-environment.ts +41 -0
- package/src/renderer-config.ts +36 -0
- package/src/renderer-facts.ts +37 -0
- package/src/renderer.ts +78 -32
- package/src/resolution-scaler.ts +3 -2
- package/src/scatter-field.ts +496 -0
- package/src/scene-entry-inspectors.ts +61 -0
- package/src/snow-field.ts +1 -0
- package/src/startup-offscreen-bytes.ts +84 -0
- package/src/state.ts +16 -3
- package/src/static-transform.ts +100 -25
- package/src/streamed-textures.ts +112 -0
- package/src/streaming.ts +68 -4
- package/src/texture-streaming.ts +331 -0
- package/src/tile-ring.ts +294 -0
- package/src/version.ts +1 -1
- package/src/warmup.ts +15 -2
- package/src/worker.ts +12 -2
- package/src/world-bundle-safety.ts +55 -10
- package/src/world-cell-batches.ts +166 -200
- package/src/world-cell-chunks.ts +3 -7
- package/src/world-cell-data.ts +7 -0
- package/src/world-cell-impostors.ts +20 -8
- package/src/world-cell-models.ts +36 -8
- package/src/world-cell-options.ts +2 -14
- package/src/world-cell-placements.ts +194 -90
- package/src/world-cell-prewarm.ts +39 -4
- package/src/world-cell-records.ts +401 -0
- package/src/world-cell-render-bundles.ts +2 -2
- package/src/world-cell-render-gpu-dress.ts +17 -19
- package/src/world-cell-render-main-cull.ts +73 -17
- package/src/world-cell-render-util.ts +18 -5
- package/src/world-cell-render.ts +13 -5
- package/src/world-cell-residency.ts +15 -6
- package/src/world-cell-stale.ts +238 -0
- package/src/world-cells.ts +23 -6
- package/src/world-gpu-flags.ts +18 -50
- package/src/world-gpu-reference.ts +22 -8
- package/src/world-gpu-scene.ts +44 -24
- package/src/world-gpu-shadow.ts +21 -8
- package/src/world-gpu-types.ts +41 -13
- package/src/world-load-limiter.ts +5 -0
- package/src/world-model-sections.ts +80 -0
- package/src/world-river-ribbon.ts +273 -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 +10 -18
- package/src/world-tile-budget.ts +4 -11
- package/src/world-tiles.ts +79 -12
- package/src/world-validate.ts +6 -14
- package/src/world-warm.ts +51 -0
- package/src/world-water-bodies.ts +113 -3
- package/src/world.ts +13 -0
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
|
}
|
|
@@ -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-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/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";
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// Generated for you. Measure actual source radiance; unreadable environments stay unknown.
|
|
2
|
+
import {
|
|
3
|
+
type Color,
|
|
4
|
+
EquirectangularReflectionMapping,
|
|
5
|
+
FloatType,
|
|
6
|
+
LinearSRGBColorSpace,
|
|
7
|
+
NoColorSpace,
|
|
8
|
+
RGBAFormat,
|
|
9
|
+
SRGBColorSpace,
|
|
10
|
+
type Scene,
|
|
11
|
+
type Texture,
|
|
12
|
+
UnsignedByteType,
|
|
13
|
+
} from "three";
|
|
14
|
+
|
|
15
|
+
export interface IEnvironmentMeasurement {
|
|
16
|
+
readonly status: "measured" | "unknown";
|
|
17
|
+
readonly meanRadiance: number | null;
|
|
18
|
+
readonly meanRGB: readonly [number, number, number] | null;
|
|
19
|
+
readonly reason: string;
|
|
20
|
+
}
|
|
21
|
+
const unknown = (reason: string): IEnvironmentMeasurement => ({
|
|
22
|
+
status: "unknown",
|
|
23
|
+
meanRadiance: null,
|
|
24
|
+
meanRGB: null,
|
|
25
|
+
reason,
|
|
26
|
+
});
|
|
27
|
+
const linear = (value: number) =>
|
|
28
|
+
value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
29
|
+
|
|
30
|
+
function validSize(value: unknown): value is number {
|
|
31
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
32
|
+
}
|
|
33
|
+
interface IReadableSource {
|
|
34
|
+
readonly status: "source";
|
|
35
|
+
readonly data: Uint8Array | Float32Array;
|
|
36
|
+
readonly width: number;
|
|
37
|
+
readonly height: number;
|
|
38
|
+
readonly bytes: boolean;
|
|
39
|
+
}
|
|
40
|
+
function readSource(
|
|
41
|
+
texture: Texture,
|
|
42
|
+
maxSourceTexels: number,
|
|
43
|
+
): IReadableSource | IEnvironmentMeasurement {
|
|
44
|
+
if (texture.mapping !== EquirectangularReflectionMapping)
|
|
45
|
+
return unknown("Only CPU-readable equirectangular source radiance is qualified.");
|
|
46
|
+
const image: unknown = texture.image;
|
|
47
|
+
if (
|
|
48
|
+
image === null ||
|
|
49
|
+
typeof image !== "object" ||
|
|
50
|
+
!("data" in image) ||
|
|
51
|
+
!("width" in image) ||
|
|
52
|
+
!("height" in image)
|
|
53
|
+
)
|
|
54
|
+
return unknown("Environment source pixels are not CPU-readable; no radiance was inferred.");
|
|
55
|
+
const { data, width, height } = image;
|
|
56
|
+
if (!validSize(width) || !validSize(height))
|
|
57
|
+
return unknown("Environment source dimensions are invalid.");
|
|
58
|
+
if (width * height > maxSourceTexels)
|
|
59
|
+
return unknown("Environment CPU sample budget exceeded; no radiance was inferred.");
|
|
60
|
+
if (texture.format !== RGBAFormat)
|
|
61
|
+
return unknown("Only explicit RGBA source samples are qualified.");
|
|
62
|
+
const bytes = texture.type === UnsignedByteType && data instanceof Uint8Array;
|
|
63
|
+
const floats = texture.type === FloatType && data instanceof Float32Array;
|
|
64
|
+
if (!bytes && !floats) return unknown("Environment source sample type is not qualified.");
|
|
65
|
+
if (data.length !== width * height * 4)
|
|
66
|
+
return unknown("Environment source samples do not match their dimensions.");
|
|
67
|
+
if (
|
|
68
|
+
!new Set<string>([NoColorSpace, LinearSRGBColorSpace, SRGBColorSpace]).has(texture.colorSpace)
|
|
69
|
+
)
|
|
70
|
+
return unknown("Environment source color-space conversion is not qualified.");
|
|
71
|
+
return { status: "source", data, width, height, bytes };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function accumulate(source: IReadableSource, srgb: boolean) {
|
|
75
|
+
const { data, width, height, bytes } = source;
|
|
76
|
+
const sums = [0, 0, 0];
|
|
77
|
+
const weights = Array.from(
|
|
78
|
+
{ length: height },
|
|
79
|
+
(_, y) => Math.cos((Math.PI * y) / height) - Math.cos((Math.PI * (y + 1)) / height),
|
|
80
|
+
);
|
|
81
|
+
for (let offset = 0; offset < data.length; offset += 4) {
|
|
82
|
+
const weight = weights[Math.floor(offset / (width * 4))] ?? 0;
|
|
83
|
+
for (let channel = 0; channel < 3; channel += 1) {
|
|
84
|
+
const sample = data[offset + channel];
|
|
85
|
+
if (sample === undefined || !Number.isFinite(sample) || sample < 0)
|
|
86
|
+
return unknown("Environment radiance samples must be finite and nonnegative.");
|
|
87
|
+
const value = bytes ? sample / 255 : sample;
|
|
88
|
+
sums[channel] = (sums[channel] ?? 0) + (srgb ? linear(value) : value) * weight;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return { sums, weightSum: weights.reduce((a, b) => a + b, 0) * width };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* CPU-readable equirectangular source radiance only; no DOM/canvas or invented JPEG mean.
|
|
96
|
+
* Rows are weighted by their exact spherical solid angle, rather than overweighting the poles.
|
|
97
|
+
* Arbitrary GPU/compressed/HTML/cube sources remain explicitly unknown until separately proven.
|
|
98
|
+
* @example const m = measureEnvironment(scene, 2048);
|
|
99
|
+
*/
|
|
100
|
+
export function measureEnvironment(scene: Scene, maxSourceTexels: number): IEnvironmentMeasurement {
|
|
101
|
+
if (!Number.isSafeInteger(maxSourceTexels) || maxSourceTexels < 1)
|
|
102
|
+
throw new Error("Environment CPU sample budget must be a positive safe integer.");
|
|
103
|
+
const texture = scene.environment;
|
|
104
|
+
if (texture === null)
|
|
105
|
+
return {
|
|
106
|
+
status: "measured",
|
|
107
|
+
meanRadiance: 0,
|
|
108
|
+
meanRGB: [0, 0, 0],
|
|
109
|
+
reason: "No environment is bound.",
|
|
110
|
+
};
|
|
111
|
+
if (!Number.isFinite(scene.environmentIntensity) || scene.environmentIntensity < 0)
|
|
112
|
+
return unknown("Environment intensity must be finite and nonnegative.");
|
|
113
|
+
const source = readSource(texture, maxSourceTexels);
|
|
114
|
+
if (source.status !== "source") return source;
|
|
115
|
+
const accumulated = accumulate(source, texture.colorSpace === SRGBColorSpace);
|
|
116
|
+
if ("status" in accumulated) return accumulated;
|
|
117
|
+
const { sums, weightSum } = accumulated;
|
|
118
|
+
const meanRGB = sums.map((sum) => (sum / weightSum) * scene.environmentIntensity) as [
|
|
119
|
+
number,
|
|
120
|
+
number,
|
|
121
|
+
number,
|
|
122
|
+
];
|
|
123
|
+
const meanRadiance = meanRGB[0] * 0.2126 + meanRGB[1] * 0.7152 + meanRGB[2] * 0.0722;
|
|
124
|
+
if (!meanRGB.every(Number.isFinite) || !Number.isFinite(meanRadiance))
|
|
125
|
+
return unknown("Environment radiance accumulation overflowed.");
|
|
126
|
+
return {
|
|
127
|
+
status: "measured",
|
|
128
|
+
meanRadiance,
|
|
129
|
+
meanRGB,
|
|
130
|
+
reason: "Solid-angle-weighted linear source radiance, with active environment intensity.",
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* What a contribution report reads: the backlight's gains and the source-texel limit.
|
|
136
|
+
*
|
|
137
|
+
* Exported because `reportEnvironmentContribution` takes it — a public function with a private
|
|
138
|
+
* parameter type cannot be called from a game, which is how its example failed to compile.
|
|
139
|
+
*/
|
|
140
|
+
export interface IContributionControls {
|
|
141
|
+
readonly darkThreshold: number;
|
|
142
|
+
readonly rimGain: number;
|
|
143
|
+
readonly fillGain: number;
|
|
144
|
+
readonly fillAdmitted: boolean;
|
|
145
|
+
readonly fillColor: Color;
|
|
146
|
+
readonly maxSourceTexels: number;
|
|
147
|
+
}
|
|
148
|
+
function fillReport(options: IContributionControls) {
|
|
149
|
+
const blackColorOverride = options.fillColor.toArray().every((value) => value === 0);
|
|
150
|
+
let reason = "analytic fill enabled by caller; contribution still needs pixel qualification";
|
|
151
|
+
if (!options.fillAdmitted) reason = "not admitted by this qualification";
|
|
152
|
+
else if (options.fillGain === 0) reason = "disabled by fillGain override";
|
|
153
|
+
else if (blackColorOverride) reason = "disabled by black fillColor override";
|
|
154
|
+
return {
|
|
155
|
+
requestedGain: options.fillGain,
|
|
156
|
+
admitted: options.fillAdmitted,
|
|
157
|
+
effectiveGain: options.fillAdmitted ? options.fillGain : 0,
|
|
158
|
+
color: options.fillColor.toArray(),
|
|
159
|
+
blackColorOverride,
|
|
160
|
+
reason,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Overrides change the look, never whether its source contribution is measured/reported.
|
|
165
|
+
* @example
|
|
166
|
+
* reportEnvironmentContribution(scene, {
|
|
167
|
+
* darkThreshold: 0.02, fillAdmitted: true, fillColor: new Color(1, 1, 1), fillGain: 0.4,
|
|
168
|
+
* maxSourceTexels: 2048, rimGain: 0.6,
|
|
169
|
+
* });
|
|
170
|
+
*/
|
|
171
|
+
export function reportEnvironmentContribution(
|
|
172
|
+
scene: Scene,
|
|
173
|
+
options: IContributionControls,
|
|
174
|
+
measurement?: IEnvironmentMeasurement,
|
|
175
|
+
) {
|
|
176
|
+
if (
|
|
177
|
+
![
|
|
178
|
+
options.darkThreshold,
|
|
179
|
+
options.rimGain,
|
|
180
|
+
options.fillGain,
|
|
181
|
+
...options.fillColor.toArray(),
|
|
182
|
+
].every((value) => Number.isFinite(value) && value >= 0)
|
|
183
|
+
)
|
|
184
|
+
throw new Error("Backlight measurement controls must be finite and nonnegative.");
|
|
185
|
+
const measured = measurement ?? measureEnvironment(scene, options.maxSourceTexels);
|
|
186
|
+
const dark =
|
|
187
|
+
measured.meanRadiance === null ? null : measured.meanRadiance <= options.darkThreshold;
|
|
188
|
+
const environmentState =
|
|
189
|
+
scene.environment === null ? "missing" : dark === null ? "unknown" : dark ? "dark" : "bright";
|
|
190
|
+
const report = {
|
|
191
|
+
...measured,
|
|
192
|
+
scope: "scene environment source availability; not material-specific reflected contribution",
|
|
193
|
+
environmentState,
|
|
194
|
+
ibl: dark === null ? "unknown" : dark ? "non-contributing" : "contributing",
|
|
195
|
+
analyticFill: fillReport(options),
|
|
196
|
+
rimGain: options.rimGain,
|
|
197
|
+
fillGain: options.fillGain,
|
|
198
|
+
darkThreshold: options.darkThreshold,
|
|
199
|
+
};
|
|
200
|
+
console.info(`TN_ENVIRONMENT_CONTRIBUTION:${JSON.stringify(report)}`);
|
|
201
|
+
return report;
|
|
202
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Generated for you. Spherical accumulation of bounded linear source samples.
|
|
2
|
+
import type { IEnvironmentMeasurement } from "./environmentContribution.js";
|
|
3
|
+
const WIDTH = 64;
|
|
4
|
+
const HEIGHT = 32;
|
|
5
|
+
function unmeasured(reason: string): IEnvironmentMeasurement {
|
|
6
|
+
return { status: "unknown", meanRadiance: null, meanRGB: null, reason };
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The mean radiance and colour of a bounded linear sample, or `unknown` with the reason.
|
|
10
|
+
*
|
|
11
|
+
* @situation turn an environment readback into the radiance a material's fill light needs
|
|
12
|
+
* @situation know why an environment sample could not be measured
|
|
13
|
+
* @constraint the sample must be the qualified 64x32 float RGBA readback; anything else is refused by name
|
|
14
|
+
* @example const m = sampledRadiance(readback, 1);
|
|
15
|
+
*/
|
|
16
|
+
export function sampledRadiance(samples: unknown, intensity: number): IEnvironmentMeasurement {
|
|
17
|
+
if (!(samples instanceof Float32Array) || samples.length !== WIDTH * HEIGHT * 4)
|
|
18
|
+
return unmeasured("GPU readback did not provide the qualified float RGBA sample layout.");
|
|
19
|
+
const sums = [0, 0, 0];
|
|
20
|
+
const weights = Array.from(
|
|
21
|
+
{ length: HEIGHT },
|
|
22
|
+
(_, y) => Math.cos((Math.PI * y) / HEIGHT) - Math.cos((Math.PI * (y + 1)) / HEIGHT),
|
|
23
|
+
);
|
|
24
|
+
const totalWeight = weights.reduce((sum, weight) => sum + weight, 0) * WIDTH;
|
|
25
|
+
for (const [offset, value] of samples.entries()) {
|
|
26
|
+
const channel = offset % 4;
|
|
27
|
+
if (channel === 3) continue;
|
|
28
|
+
if (!Number.isFinite(value) || value < 0)
|
|
29
|
+
return unmeasured("GPU radiance samples must be finite and nonnegative.");
|
|
30
|
+
const weight = weights[Math.floor(offset / (WIDTH * 4))] ?? 0;
|
|
31
|
+
sums[channel] = (sums[channel] ?? 0) + value * weight;
|
|
32
|
+
}
|
|
33
|
+
const meanRGB = sums.map((sum) => (sum / totalWeight) * intensity) as [number, number, number];
|
|
34
|
+
const meanRadiance = meanRGB[0] * 0.2126 + meanRGB[1] * 0.7152 + meanRGB[2] * 0.0722;
|
|
35
|
+
if (!meanRGB.every(Number.isFinite) || !Number.isFinite(meanRadiance))
|
|
36
|
+
return unmeasured("GPU radiance accumulation overflowed.");
|
|
37
|
+
return {
|
|
38
|
+
status: "measured",
|
|
39
|
+
meanRGB,
|
|
40
|
+
meanRadiance,
|
|
41
|
+
reason:
|
|
42
|
+
"Estimated linear scene-environment source radiance from 64x32 GPU samples, spherical row weighting and active intensity; not material-specific BRDF contribution.",
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Generated for you. Weak ownership and full provenance guard successful source estimates.
|
|
2
|
+
import type { Scene, Texture } from "three";
|
|
3
|
+
import type { IEnvironmentSample } from "./environmentSampling.js";
|
|
4
|
+
import { environmentSnapshotCurrent } from "./environmentSnapshot.js";
|
|
5
|
+
const samples = new WeakMap<object, WeakMap<Texture, IEnvironmentSample>>();
|
|
6
|
+
/**
|
|
7
|
+
* The sample this renderer took of `scene`'s environment, if it is still current.
|
|
8
|
+
*
|
|
9
|
+
* @situation skip a second environment readback in the same frame
|
|
10
|
+
* @constraint a sample whose source texture or intensity moved is dropped, so a stale one never reaches a material
|
|
11
|
+
* @example const hit = cachedEnvironmentSample(renderer, scene);
|
|
12
|
+
*/
|
|
13
|
+
export function cachedEnvironmentSample(
|
|
14
|
+
renderer: object,
|
|
15
|
+
scene: Scene,
|
|
16
|
+
): IEnvironmentSample | undefined {
|
|
17
|
+
if (scene.environment === null) return undefined;
|
|
18
|
+
const sample = samples.get(renderer)?.get(scene.environment);
|
|
19
|
+
return sample !== undefined && environmentSnapshotCurrent(scene, sample)
|
|
20
|
+
? copySample(sample)
|
|
21
|
+
: undefined;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Remembers `sample` as this renderer's reading of `scene`'s environment.
|
|
25
|
+
*
|
|
26
|
+
* @situation reuse one environment readback across the materials of a scene
|
|
27
|
+
* @example cacheEnvironmentSample(renderer, scene, sample);
|
|
28
|
+
*/
|
|
29
|
+
export function cacheEnvironmentSample(
|
|
30
|
+
renderer: object,
|
|
31
|
+
scene: Scene,
|
|
32
|
+
sample: IEnvironmentSample,
|
|
33
|
+
): void {
|
|
34
|
+
if (
|
|
35
|
+
sample.source === null ||
|
|
36
|
+
sample.measurement.status !== "measured" ||
|
|
37
|
+
!environmentSnapshotCurrent(scene, sample)
|
|
38
|
+
)
|
|
39
|
+
return;
|
|
40
|
+
let byTexture = samples.get(renderer);
|
|
41
|
+
if (byTexture === undefined) {
|
|
42
|
+
byTexture = new WeakMap();
|
|
43
|
+
samples.set(renderer, byTexture);
|
|
44
|
+
}
|
|
45
|
+
byTexture.set(sample.source, copySample(sample));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function copySample(sample: IEnvironmentSample): IEnvironmentSample {
|
|
49
|
+
return {
|
|
50
|
+
...sample,
|
|
51
|
+
measurement: {
|
|
52
|
+
...sample.measurement,
|
|
53
|
+
meanRGB: sample.measurement.meanRGB === null ? null : [...sample.measurement.meanRGB],
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|