@threenative/core 0.3.11 → 0.3.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.
- package/capabilities.json +1096 -26
- package/dist/camera-shake-CZKOfGn4.d.ts +46 -0
- package/dist/{canvas-layer-vCtanIeB.d.ts → canvas-layer-CWuFRT7G.d.ts} +1 -1
- package/dist/chunk-2Z44XSI2.js +35 -0
- package/dist/chunk-5O73CDMR.js +1849 -0
- package/dist/chunk-6KLNISRJ.js +153 -0
- package/dist/chunk-7UUT3TY5.js +133 -0
- package/dist/chunk-CFGTPFUH.js +231 -0
- package/dist/chunk-DBELTTTM.js +615 -0
- package/dist/chunk-GMHATRPW.js +7701 -0
- package/dist/chunk-GXY7B3JG.js +46 -0
- package/dist/chunk-KIRUKTBQ.js +187 -0
- package/dist/chunk-N5LRP4BR.js +220 -0
- package/dist/chunk-OKXUCASC.js +2238 -0
- package/dist/chunk-QWJEMUUT.js +94 -0
- package/dist/chunk-VAZM36TV.js +497 -0
- package/dist/{game-DzMcitDO.d.ts → game-D7pAzZUY.d.ts} +15 -3
- package/dist/hot.d.ts +3 -3
- package/dist/hot.js +2 -46
- package/dist/index.d.ts +329 -302
- package/dist/index.js +10566 -22552
- package/dist/{model-lod-CTpZ6imz.d.ts → model-lod-B6BMqS1r.d.ts} +33 -3
- package/dist/playtest.d.ts +3 -3
- package/dist/playtest.js +24 -75
- package/dist/react-css.js +1 -215
- package/dist/react.d.ts +2 -2
- package/dist/{renderer-rZm0hVqq.d.ts → renderer-DvFVoAgj.d.ts} +13 -4
- 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 +5 -384
- package/dist/worker.js +4 -41
- package/dist/world.d.ts +725 -259
- package/dist/world.js +16714 -18284
- package/mcp/animation-server.mjs +1 -1
- package/mcp/animation.mjs +2 -3
- package/mcp/engine-server.mjs +142 -47
- package/mcp/servers.mjs +9 -2
- package/mcp/terrain.mjs +8 -0
- package/package.json +14 -6
- package/patches/three@0.187.0-prd269-upgrade.patch +2102 -0
- package/patches/three@0.187.0.patch +2004 -407
- package/src/assets.ts +9 -2
- package/src/card-lod.ts +152 -0
- package/src/compressed-texture-preparation.ts +1008 -0
- package/src/frame-budget.ts +31 -20
- package/src/game-dev-tools.ts +93 -0
- package/src/game-frame-loop.ts +995 -0
- package/src/game-renderer-metrics.ts +77 -0
- package/src/game-startup.ts +1001 -0
- package/src/game-validate.ts +70 -0
- package/src/game.ts +253 -1935
- package/src/index.ts +27 -2
- package/src/launch-diagnostics.ts +22 -12
- package/src/look/ao-admission.ts +24 -0
- package/src/look/filmic-tone-mapping.ts +15 -13
- package/src/look/look-diagnostics.ts +3 -3
- package/src/look/quality.ts +10 -5
- package/src/look/world-environment.ts +76 -9
- package/src/loop.ts +29 -0
- package/src/model-lod.ts +42 -3
- package/src/particle-kinds.ts +515 -0
- package/src/picking.ts +17 -3
- package/src/playtest.ts +27 -1
- package/src/projection-apply.ts +4 -1
- package/src/projection-plan.ts +9 -6
- package/src/render/mesh-pool.ts +1 -1
- 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.ts +213 -992
- package/src/render/world-impostor-surface.ts +293 -34
- package/src/render-pass-budget.ts +34 -7
- package/src/renderProjection.ts +22 -0
- package/src/renderer.ts +92 -37
- package/src/snow-field.ts +1 -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-readiness.ts +128 -34
- package/src/version.ts +1 -1
- package/src/warmup.ts +56 -8
- package/src/water-surface.ts +9 -3
- package/src/world-bundle-safety.ts +401 -0
- package/src/world-cell-batches.ts +1216 -0
- package/src/world-cell-chunks.ts +1132 -0
- package/src/world-cell-data.ts +995 -0
- package/src/world-cell-impostors.ts +1449 -0
- package/src/world-cell-lod-bias.ts +151 -0
- package/src/world-cell-models.ts +1074 -0
- package/src/world-cell-options.ts +189 -0
- package/src/world-cell-placements.ts +694 -0
- package/src/world-cell-prewarm.ts +557 -0
- package/src/world-cell-readiness.ts +357 -0
- package/src/world-cell-render-bundles.ts +459 -0
- package/src/world-cell-render-gpu-dress.ts +714 -0
- package/src/world-cell-render-main-cull.ts +484 -0
- package/src/world-cell-render-shadow-claims.ts +198 -0
- package/src/world-cell-render-util.ts +246 -0
- package/src/world-cell-render.ts +1493 -0
- package/src/world-cell-residency.ts +745 -0
- package/src/world-cells.ts +1318 -10418
- package/src/world-chunk-shadow.ts +308 -0
- package/src/world-collar.ts +315 -0
- package/src/world-gpu-flags.ts +163 -0
- package/src/world-gpu-readback.ts +881 -0
- package/src/world-gpu-reference.ts +510 -0
- package/src/world-gpu-scene.ts +214 -2264
- package/src/world-gpu-shadow.ts +190 -0
- package/src/world-gpu-types.ts +381 -0
- package/src/world-gpu-validation.ts +518 -0
- package/src/world-heightfield.ts +802 -0
- package/src/world-load-limiter.ts +106 -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-terrain-splat.ts +365 -149
- package/src/world-tile-budget.ts +256 -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 +170 -1745
- package/src/world-water-bodies.ts +359 -0
- package/src/world.ts +35 -741
|
@@ -1,126 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
function mergeBlockAttributes(job) {
|
|
3
|
-
let vertexCount = 0;
|
|
4
|
-
let indexCount = 0;
|
|
5
|
-
for (const part of job.parts) {
|
|
6
|
-
vertexCount += part.positions.length / 3;
|
|
7
|
-
indexCount += part.indices.length;
|
|
8
|
-
}
|
|
9
|
-
const positions = new Float32Array(vertexCount * 3);
|
|
10
|
-
const normals = new Float32Array(vertexCount * 3);
|
|
11
|
-
const indices = new Uint32Array(indexCount);
|
|
12
|
-
let vertexOffset = 0;
|
|
13
|
-
let indexOffset = 0;
|
|
14
|
-
for (const part of job.parts) {
|
|
15
|
-
const dx = part.origin.x - job.blockOrigin.x;
|
|
16
|
-
const dz = part.origin.z - job.blockOrigin.z;
|
|
17
|
-
const count = part.positions.length / 3;
|
|
18
|
-
for (let vertex = 0; vertex < count; vertex += 1) {
|
|
19
|
-
const at = (vertexOffset + vertex) * 3;
|
|
20
|
-
const from = vertex * 3;
|
|
21
|
-
positions[at] = part.positions[from] + dx;
|
|
22
|
-
positions[at + 1] = part.positions[from + 1];
|
|
23
|
-
positions[at + 2] = part.positions[from + 2] + dz;
|
|
24
|
-
normals[at] = part.normals[from];
|
|
25
|
-
normals[at + 1] = part.normals[from + 1];
|
|
26
|
-
normals[at + 2] = part.normals[from + 2];
|
|
27
|
-
}
|
|
28
|
-
for (let element = 0; element < part.indices.length; element += 1)
|
|
29
|
-
indices[indexOffset + element] = part.indices[element] + vertexOffset;
|
|
30
|
-
vertexOffset += count;
|
|
31
|
-
indexOffset += part.indices.length;
|
|
32
|
-
}
|
|
33
|
-
return { indices, kind: "merge", normals, positions };
|
|
34
|
-
}
|
|
35
|
-
function interpolatedEdgeSample(samples, normalized, name) {
|
|
36
|
-
const position = Math.max(0, Math.min(1, normalized)) * (samples.length - 1);
|
|
37
|
-
const lower = Math.floor(position);
|
|
38
|
-
const upper = Math.min(samples.length - 1, lower + 1);
|
|
39
|
-
const mix = position - lower;
|
|
40
|
-
const lowerValue = samples[lower];
|
|
41
|
-
const upperValue = samples[upper];
|
|
42
|
-
if (!Number.isFinite(lowerValue) || !Number.isFinite(upperValue))
|
|
43
|
-
throw new Error(`TerrainTiles retained ${name} edge sample must be finite.`);
|
|
44
|
-
return lowerValue * (1 - mix) + upperValue * mix;
|
|
45
|
-
}
|
|
46
|
-
function edgeWorldPoint(edge, normalized, height) {
|
|
47
|
-
const minimumX = edge.origin.x - edge.width / 2;
|
|
48
|
-
const minimumZ = edge.origin.z - edge.depth / 2;
|
|
49
|
-
const x = edge.side === "west" ? minimumX : edge.side === "east" ? minimumX + edge.width : minimumX + normalized * edge.width;
|
|
50
|
-
const z = edge.side === "north" ? minimumZ : edge.side === "south" ? minimumZ + edge.depth : minimumZ + normalized * edge.depth;
|
|
51
|
-
return [x, height, z];
|
|
52
|
-
}
|
|
53
|
-
function stitchBridgeAttributes(fine, coarse) {
|
|
54
|
-
const positions = new Float32Array(fine.resolution * 6);
|
|
55
|
-
const normals = new Float32Array(fine.resolution * 6);
|
|
56
|
-
const indices = new Uint32Array((fine.resolution - 1) * 12);
|
|
57
|
-
let coverageDepth = 0;
|
|
58
|
-
for (let index = 0; index < fine.resolution; index += 1) {
|
|
59
|
-
const normalized = index / (fine.resolution - 1);
|
|
60
|
-
const fineHeight = interpolatedEdgeSample(
|
|
61
|
-
fine.samples,
|
|
62
|
-
normalized,
|
|
63
|
-
`${fine.side} of finer LOD`
|
|
64
|
-
);
|
|
65
|
-
const coarseHeight = interpolatedEdgeSample(
|
|
66
|
-
coarse.samples,
|
|
67
|
-
normalized,
|
|
68
|
-
`${coarse.side} of coarser LOD`
|
|
69
|
-
);
|
|
70
|
-
coverageDepth = Math.max(coverageDepth, Math.abs(fineHeight - coarseHeight));
|
|
71
|
-
const at = index * 6;
|
|
72
|
-
const finePoint = edgeWorldPoint(fine, normalized, fineHeight);
|
|
73
|
-
const coarsePoint = edgeWorldPoint(coarse, normalized, coarseHeight);
|
|
74
|
-
positions[at] = finePoint[0];
|
|
75
|
-
positions[at + 1] = finePoint[1];
|
|
76
|
-
positions[at + 2] = finePoint[2];
|
|
77
|
-
positions[at + 3] = coarsePoint[0];
|
|
78
|
-
positions[at + 4] = coarsePoint[1];
|
|
79
|
-
positions[at + 5] = coarsePoint[2];
|
|
80
|
-
normals[at] = 0;
|
|
81
|
-
normals[at + 1] = 1;
|
|
82
|
-
normals[at + 2] = 0;
|
|
83
|
-
normals[at + 3] = 0;
|
|
84
|
-
normals[at + 4] = 1;
|
|
85
|
-
normals[at + 5] = 0;
|
|
86
|
-
}
|
|
87
|
-
for (let index = 0; index < fine.resolution - 1; index += 1) {
|
|
88
|
-
const fine2 = index * 2;
|
|
89
|
-
const coarse2 = fine2 + 1;
|
|
90
|
-
const nextFine = fine2 + 2;
|
|
91
|
-
const nextCoarse = coarse2 + 2;
|
|
92
|
-
const at = index * 12;
|
|
93
|
-
indices[at] = fine2;
|
|
94
|
-
indices[at + 1] = coarse2;
|
|
95
|
-
indices[at + 2] = nextFine;
|
|
96
|
-
indices[at + 3] = nextFine;
|
|
97
|
-
indices[at + 4] = coarse2;
|
|
98
|
-
indices[at + 5] = nextCoarse;
|
|
99
|
-
indices[at + 6] = nextFine;
|
|
100
|
-
indices[at + 7] = coarse2;
|
|
101
|
-
indices[at + 8] = fine2;
|
|
102
|
-
indices[at + 9] = nextCoarse;
|
|
103
|
-
indices[at + 10] = coarse2;
|
|
104
|
-
indices[at + 11] = nextFine;
|
|
105
|
-
}
|
|
106
|
-
return { coverageDepth, indices, normals, positions };
|
|
107
|
-
}
|
|
108
|
-
function runTerrainJob(job) {
|
|
109
|
-
if (job.kind === "merge") return mergeBlockAttributes(job);
|
|
110
|
-
return {
|
|
111
|
-
bridges: job.pairs.map(({ coarse, fine }) => stitchBridgeAttributes(fine, coarse)),
|
|
112
|
-
kind: "seam"
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
function terrainJobTransfers(result) {
|
|
116
|
-
if (result.kind === "merge")
|
|
117
|
-
return [result.positions.buffer, result.normals.buffer, result.indices.buffer];
|
|
118
|
-
return result.bridges.flatMap((bridge) => [
|
|
119
|
-
bridge.positions.buffer,
|
|
120
|
-
bridge.normals.buffer,
|
|
121
|
-
bridge.indices.buffer
|
|
122
|
-
]);
|
|
123
|
-
}
|
|
1
|
+
import { runTerrainJob, terrainJobTransfers } from './chunk-KIRUKTBQ.js';
|
|
124
2
|
|
|
125
3
|
// src/terrain-jobs-worker.ts
|
|
126
4
|
self.onmessage = (event) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { addFoliageBackLight, foliageTransmission, installFoliageTransmission } from './chunk-GXY7B3JG.js';
|
package/dist/ui-layer.js
CHANGED
|
@@ -1,386 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var UI_DEV_METRICS_MESSAGE = "tn:dev-metrics";
|
|
6
|
-
var UI_STARTUP_MESSAGE = "tn:startup";
|
|
7
|
-
var UI_READY_INTENT = "tn:ready";
|
|
8
|
-
var UI_BRIDGE_GLOBALS = {
|
|
9
|
-
/** UI end, inbound: the host calls this with one JSON string. */
|
|
10
|
-
uiReceive: "__tnUiReceive",
|
|
11
|
-
/** UI end, outbound: an injected object with `postMessage(string)`. */
|
|
12
|
-
uiHost: "tnHost",
|
|
13
|
-
/** Game end, inbound: the runtime calls this with one JSON string. */
|
|
14
|
-
gameReceive: "__tnUiGameReceive",
|
|
15
|
-
/** Game end, outbound: the runtime installs this and forwards to the web view. */
|
|
16
|
-
gamePost: "__tnUiPost"
|
|
17
|
-
};
|
|
18
|
-
var stateFrames = /* @__PURE__ */ new WeakMap();
|
|
19
|
-
function serializeUiState(state) {
|
|
20
|
-
return assertSendable({ type: GAME_STATE_MESSAGE, state });
|
|
21
|
-
}
|
|
22
|
-
function postUiState(bridge, state, frame) {
|
|
23
|
-
const message = { type: GAME_STATE_MESSAGE, state };
|
|
24
|
-
stateFrames.set(message, frame);
|
|
25
|
-
try {
|
|
26
|
-
bridge.post(message);
|
|
27
|
-
} finally {
|
|
28
|
-
stateFrames.delete(message);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function assertSendable(message) {
|
|
32
|
-
if (typeof message !== "object" || message === null || Array.isArray(message)) {
|
|
33
|
-
throw new Error("TN_UI_BRIDGE_MESSAGE_INVALID: a bridge message must be a JSON object.");
|
|
34
|
-
}
|
|
35
|
-
if (typeof message.type !== "string" || message.type.length === 0) {
|
|
36
|
-
throw new Error("TN_UI_BRIDGE_MESSAGE_INVALID: a bridge message must carry a string 'type'.");
|
|
37
|
-
}
|
|
38
|
-
let frame;
|
|
39
|
-
try {
|
|
40
|
-
frame = stateFrames.get(message) ?? JSON.stringify(message);
|
|
41
|
-
} catch (error) {
|
|
42
|
-
throw new Error(
|
|
43
|
-
`TN_UI_BRIDGE_MESSAGE_INVALID: '${message.type}' is not JSON-serialisable: ${error instanceof Error ? error.message : String(error)}`
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
if (frame === void 0) {
|
|
47
|
-
throw new Error(`TN_UI_BRIDGE_MESSAGE_INVALID: '${message.type}' serialised to nothing.`);
|
|
48
|
-
}
|
|
49
|
-
return frame;
|
|
50
|
-
}
|
|
51
|
-
function parseFrame(frame) {
|
|
52
|
-
const text = typeof frame === "string" ? frame : frame?.data;
|
|
53
|
-
if (typeof text !== "string") {
|
|
54
|
-
throw new Error("TN_UI_BRIDGE_FRAME_INVALID: expected a JSON string from the host.");
|
|
55
|
-
}
|
|
56
|
-
let parsed;
|
|
57
|
-
try {
|
|
58
|
-
parsed = JSON.parse(text);
|
|
59
|
-
} catch (error) {
|
|
60
|
-
throw new Error(
|
|
61
|
-
`TN_UI_BRIDGE_FRAME_INVALID: not JSON: ${error instanceof Error ? error.message : String(error)}`
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
65
|
-
throw new Error("TN_UI_BRIDGE_FRAME_INVALID: a bridge frame must be a JSON object.");
|
|
66
|
-
}
|
|
67
|
-
if (typeof parsed.type !== "string") {
|
|
68
|
-
throw new Error("TN_UI_BRIDGE_FRAME_INVALID: a bridge frame must carry a string 'type'.");
|
|
69
|
-
}
|
|
70
|
-
return parsed;
|
|
71
|
-
}
|
|
72
|
-
function findOutbound(scope, end) {
|
|
73
|
-
if (end === "game") {
|
|
74
|
-
const post = scope[UI_BRIDGE_GLOBALS.gamePost];
|
|
75
|
-
return typeof post === "function" ? (frame) => post(frame) : void 0;
|
|
76
|
-
}
|
|
77
|
-
const injected = scope[UI_BRIDGE_GLOBALS.uiHost];
|
|
78
|
-
if (typeof injected?.postMessage === "function") {
|
|
79
|
-
return (frame) => injected.postMessage(frame);
|
|
80
|
-
}
|
|
81
|
-
const webkit = scope.webkit;
|
|
82
|
-
const handler = webkit?.messageHandlers?.[UI_BRIDGE_GLOBALS.uiHost];
|
|
83
|
-
if (typeof handler?.postMessage === "function") {
|
|
84
|
-
return (frame) => handler.postMessage(frame);
|
|
85
|
-
}
|
|
86
|
-
const ipc = scope.ipc;
|
|
87
|
-
if (typeof ipc?.postMessage === "function") {
|
|
88
|
-
return (frame) => ipc.postMessage(frame);
|
|
89
|
-
}
|
|
90
|
-
return void 0;
|
|
91
|
-
}
|
|
92
|
-
var BROKER_KEY = "__tnUiBridgeBroker";
|
|
93
|
-
function broker(scope) {
|
|
94
|
-
const existing = scope[BROKER_KEY];
|
|
95
|
-
if (existing !== void 0) return existing;
|
|
96
|
-
const created = { game: /* @__PURE__ */ new Set(), ui: /* @__PURE__ */ new Set(), inbound: /* @__PURE__ */ new Map() };
|
|
97
|
-
scope[BROKER_KEY] = created;
|
|
98
|
-
return created;
|
|
99
|
-
}
|
|
100
|
-
function installInbound(scope, key, deliver) {
|
|
101
|
-
const bus = broker(scope);
|
|
102
|
-
let slot = bus.inbound.get(key);
|
|
103
|
-
if (slot === void 0) {
|
|
104
|
-
const receivers = /* @__PURE__ */ new Set();
|
|
105
|
-
slot = {
|
|
106
|
-
receivers,
|
|
107
|
-
dispatch: (frame) => {
|
|
108
|
-
let firstError;
|
|
109
|
-
let failed = false;
|
|
110
|
-
for (const receiver of [...receivers]) {
|
|
111
|
-
try {
|
|
112
|
-
receiver(frame);
|
|
113
|
-
} catch (error) {
|
|
114
|
-
if (!failed) {
|
|
115
|
-
failed = true;
|
|
116
|
-
firstError = error;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
if (failed) throw firstError;
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
bus.inbound.set(key, slot);
|
|
124
|
-
}
|
|
125
|
-
slot.receivers.add(deliver);
|
|
126
|
-
scope[key] = slot.dispatch;
|
|
127
|
-
const installed = slot;
|
|
128
|
-
return () => {
|
|
129
|
-
installed.receivers.delete(deliver);
|
|
130
|
-
if (installed.receivers.size === 0 && scope[key] === installed.dispatch) scope[key] = void 0;
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
var LOOPBACK_KEY = "__tnUiLoopback";
|
|
134
|
-
function installLoopback(scope) {
|
|
135
|
-
const search = scope.location?.search;
|
|
136
|
-
if (typeof search !== "string" || new URLSearchParams(search).get("tnUiLoopback") !== "1") return;
|
|
137
|
-
if (scope[LOOPBACK_KEY] !== void 0) return;
|
|
138
|
-
const { port1: gamePort, port2: uiPort } = new MessageChannel();
|
|
139
|
-
const receive = (key) => (event) => scope[key]?.(event.data);
|
|
140
|
-
gamePort.onmessage = receive(UI_BRIDGE_GLOBALS.gameReceive);
|
|
141
|
-
uiPort.onmessage = receive(UI_BRIDGE_GLOBALS.uiReceive);
|
|
142
|
-
scope[UI_BRIDGE_GLOBALS.gamePost] = (frame) => gamePort.postMessage(frame);
|
|
143
|
-
scope[UI_BRIDGE_GLOBALS.uiHost] = { postMessage: (frame) => uiPort.postMessage(frame) };
|
|
144
|
-
scope.__tnUiOverlayAttached = () => true;
|
|
145
|
-
scope[LOOPBACK_KEY] = {
|
|
146
|
-
close() {
|
|
147
|
-
gamePort.close();
|
|
148
|
-
uiPort.close();
|
|
149
|
-
for (const key of [UI_BRIDGE_GLOBALS.gamePost, UI_BRIDGE_GLOBALS.uiHost, LOOPBACK_KEY])
|
|
150
|
-
scope[key] = void 0;
|
|
151
|
-
scope.__tnUiOverlayAttached = void 0;
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
function connectUiBridge(options) {
|
|
156
|
-
const { end } = options;
|
|
157
|
-
if (end !== "game" && end !== "ui") {
|
|
158
|
-
throw new Error(`TN_UI_BRIDGE_END_INVALID: expected 'game' or 'ui', got '${String(end)}'.`);
|
|
159
|
-
}
|
|
160
|
-
const scope = options.scope ?? globalThis;
|
|
161
|
-
installLoopback(scope);
|
|
162
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
163
|
-
const deliver = (frame) => {
|
|
164
|
-
const message = parseFrame(frame);
|
|
165
|
-
for (const listener of [...listeners]) listener(message);
|
|
166
|
-
};
|
|
167
|
-
const outbound = findOutbound(scope, end);
|
|
168
|
-
const inboundKey = end === "ui" ? UI_BRIDGE_GLOBALS.uiReceive : UI_BRIDGE_GLOBALS.gameReceive;
|
|
169
|
-
let closed = false;
|
|
170
|
-
if (outbound === void 0) {
|
|
171
|
-
const bus = broker(scope);
|
|
172
|
-
const peer = end === "ui" ? "game" : "ui";
|
|
173
|
-
const own = (message) => {
|
|
174
|
-
for (const listener of [...listeners]) listener(message);
|
|
175
|
-
};
|
|
176
|
-
bus[end].add(own);
|
|
177
|
-
return {
|
|
178
|
-
end,
|
|
179
|
-
transport: "in-process",
|
|
180
|
-
hasPeer: () => bus[peer].size > 0,
|
|
181
|
-
post(message) {
|
|
182
|
-
const frame = assertSendable(message);
|
|
183
|
-
if (closed) throw new Error("TN_UI_BRIDGE_CLOSED: post on a closed bridge.");
|
|
184
|
-
const copy = JSON.parse(frame);
|
|
185
|
-
for (const listener of [...bus[peer]]) listener(copy);
|
|
186
|
-
},
|
|
187
|
-
onMessage(listener) {
|
|
188
|
-
listeners.add(listener);
|
|
189
|
-
return () => listeners.delete(listener);
|
|
190
|
-
},
|
|
191
|
-
close() {
|
|
192
|
-
closed = true;
|
|
193
|
-
listeners.clear();
|
|
194
|
-
bus[end].delete(own);
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
const uninstall = installInbound(scope, inboundKey, deliver);
|
|
199
|
-
const injected = scope[UI_BRIDGE_GLOBALS.uiHost];
|
|
200
|
-
if (end === "ui" && injected !== void 0 && typeof injected === "object") {
|
|
201
|
-
injected.onmessage = (event) => deliver(event);
|
|
202
|
-
}
|
|
203
|
-
return {
|
|
204
|
-
end,
|
|
205
|
-
transport: "host",
|
|
206
|
-
hasPeer() {
|
|
207
|
-
const attached = scope.__tnUiOverlayAttached;
|
|
208
|
-
if (end === "ui") return true;
|
|
209
|
-
return typeof attached === "function" ? attached() === true : false;
|
|
210
|
-
},
|
|
211
|
-
post(message) {
|
|
212
|
-
const frame = assertSendable(message);
|
|
213
|
-
if (closed) throw new Error("TN_UI_BRIDGE_CLOSED: post on a closed bridge.");
|
|
214
|
-
outbound(frame);
|
|
215
|
-
},
|
|
216
|
-
onMessage(listener) {
|
|
217
|
-
listeners.add(listener);
|
|
218
|
-
return () => listeners.delete(listener);
|
|
219
|
-
},
|
|
220
|
-
close() {
|
|
221
|
-
closed = true;
|
|
222
|
-
listeners.clear();
|
|
223
|
-
uninstall();
|
|
224
|
-
if (end === "ui" && injected !== void 0 && typeof injected === "object") {
|
|
225
|
-
injected.onmessage = void 0;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// src/profiling/debug-telemetry.ts
|
|
232
|
-
var DEBUG_GLOBAL = "__THREENATIVE_DEBUG__";
|
|
233
|
-
function debugRequested() {
|
|
234
|
-
const host = globalThis;
|
|
235
|
-
return host.process?.env?.TN_DEBUG === "1" || globalThis[DEBUG_GLOBAL] === true || /[?&]tnDebug=1(?:&|$)/u.test(globalThis.location?.search ?? "");
|
|
236
|
-
}
|
|
237
|
-
function countDebug(name, value, area, caller, unit = "count") {
|
|
238
|
-
if (!Number.isFinite(value) || value < 0)
|
|
239
|
-
throw new Error(`TN_DEBUG: invalid ${name} observation.`);
|
|
240
|
-
const host = globalThis;
|
|
241
|
-
host.__tnEngineCost ??= {};
|
|
242
|
-
host.__tnDebugSources ??= {};
|
|
243
|
-
host.__tnEngineCost[name] = (host.__tnEngineCost[name] ?? 0) + value;
|
|
244
|
-
host.__tnDebugSources[name] ??= { area, caller, unit };
|
|
245
|
-
}
|
|
246
|
-
function measureDebug(name, area, caller, run) {
|
|
247
|
-
const start = performance.now();
|
|
248
|
-
try {
|
|
249
|
-
return run();
|
|
250
|
-
} finally {
|
|
251
|
-
countDebug(`${name}Ms`, performance.now() - start, area, caller, "ms");
|
|
252
|
-
countDebug(`${name}Calls`, 1, area, caller);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// src/ui-state.ts
|
|
257
|
-
var microtask = (flush) => {
|
|
258
|
-
void Promise.resolve().then(flush);
|
|
259
|
-
};
|
|
260
|
-
function publishUiState(bridge, store, options = {}) {
|
|
261
|
-
if (bridge.end !== "game") {
|
|
262
|
-
throw new Error(
|
|
263
|
-
`TN_UI_STATE_WRONG_END: state is published by the 'game' end, not '${bridge.end}'.`
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
const schedule = options.schedule ?? microtask;
|
|
267
|
-
const debug = debugRequested();
|
|
268
|
-
const serialize = debug ? (state) => {
|
|
269
|
-
countDebug("uiSerializations", 1, "ui", "publishUiState");
|
|
270
|
-
return measureDebug("uiSerialize", "ui", "publishUiState", () => serializeUiState(state));
|
|
271
|
-
} : serializeUiState;
|
|
272
|
-
const read = () => store.getPublishedState === void 0 ? store.getState() : store.getPublishedState();
|
|
273
|
-
let stopped = false;
|
|
274
|
-
let queued = false;
|
|
275
|
-
let lastFrame = "";
|
|
276
|
-
const send = (state, frame) => {
|
|
277
|
-
lastFrame = frame;
|
|
278
|
-
postUiState(bridge, state, frame);
|
|
279
|
-
if (debug) {
|
|
280
|
-
countDebug("uiMessages", 1, "ui", "publishUiState");
|
|
281
|
-
countDebug(
|
|
282
|
-
"uiMessageBytes",
|
|
283
|
-
new TextEncoder().encode(frame).byteLength,
|
|
284
|
-
"ui",
|
|
285
|
-
"publishUiState"
|
|
286
|
-
);
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
const publish = () => {
|
|
290
|
-
if (stopped) return;
|
|
291
|
-
const state = read();
|
|
292
|
-
send(state, serialize(state));
|
|
293
|
-
};
|
|
294
|
-
const flush = () => {
|
|
295
|
-
queued = false;
|
|
296
|
-
if (stopped) return;
|
|
297
|
-
if (!bridge.hasPeer()) return;
|
|
298
|
-
const state = read();
|
|
299
|
-
const frame = serialize(state);
|
|
300
|
-
if (frame === lastFrame) return;
|
|
301
|
-
send(state, frame);
|
|
302
|
-
};
|
|
303
|
-
const unsubscribe = store.subscribe(() => {
|
|
304
|
-
if (stopped || queued) return;
|
|
305
|
-
queued = true;
|
|
306
|
-
schedule(flush);
|
|
307
|
-
});
|
|
308
|
-
if (bridge.hasPeer()) publish();
|
|
309
|
-
return {
|
|
310
|
-
publish,
|
|
311
|
-
stop() {
|
|
312
|
-
stopped = true;
|
|
313
|
-
unsubscribe();
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
function subscribeUiState(bridge) {
|
|
318
|
-
if (bridge.end !== "ui") {
|
|
319
|
-
throw new Error(
|
|
320
|
-
`TN_UI_STATE_WRONG_END: state is mirrored by the 'ui' end, not '${bridge.end}'.`
|
|
321
|
-
);
|
|
322
|
-
}
|
|
323
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
324
|
-
let current;
|
|
325
|
-
let covered = false;
|
|
326
|
-
const off = bridge.onMessage((message) => {
|
|
327
|
-
if (message.type === UI_STARTUP_MESSAGE) {
|
|
328
|
-
const next = message.phase !== "ready";
|
|
329
|
-
if (next === covered) return;
|
|
330
|
-
covered = next;
|
|
331
|
-
for (const listener of [...listeners]) listener();
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
if (message.type !== GAME_STATE_MESSAGE) return;
|
|
335
|
-
const state = message.state;
|
|
336
|
-
if (typeof state !== "object" || state === null || Array.isArray(state)) {
|
|
337
|
-
throw new Error("TN_UI_STATE_FRAME_INVALID: a published state frame must carry an object.");
|
|
338
|
-
}
|
|
339
|
-
current = state;
|
|
340
|
-
for (const listener of [...listeners]) listener();
|
|
341
|
-
});
|
|
342
|
-
return {
|
|
343
|
-
get: () => current,
|
|
344
|
-
covered: () => covered,
|
|
345
|
-
subscribe(listener) {
|
|
346
|
-
listeners.add(listener);
|
|
347
|
-
return () => listeners.delete(listener);
|
|
348
|
-
},
|
|
349
|
-
stop() {
|
|
350
|
-
off();
|
|
351
|
-
listeners.clear();
|
|
352
|
-
}
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
function sendUiIntent(bridge, intent, payload) {
|
|
356
|
-
if (bridge.end !== "ui") {
|
|
357
|
-
throw new Error(
|
|
358
|
-
`TN_UI_INTENT_WRONG_END: intents are sent by the 'ui' end, not '${bridge.end}'.`
|
|
359
|
-
);
|
|
360
|
-
}
|
|
361
|
-
if (typeof intent !== "string" || intent.length === 0) {
|
|
362
|
-
throw new Error("TN_UI_INTENT_INVALID: an intent needs a non-empty name.");
|
|
363
|
-
}
|
|
364
|
-
bridge.post({
|
|
365
|
-
type: UI_INTENT_MESSAGE,
|
|
366
|
-
intent,
|
|
367
|
-
...payload === void 0 ? {} : { payload }
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
function onUiIntent(bridge, listener) {
|
|
371
|
-
if (bridge.end !== "game") {
|
|
372
|
-
throw new Error(
|
|
373
|
-
`TN_UI_INTENT_WRONG_END: intents are received by the 'game' end, not '${bridge.end}'.`
|
|
374
|
-
);
|
|
375
|
-
}
|
|
376
|
-
return bridge.onMessage((message) => {
|
|
377
|
-
if (message.type !== UI_INTENT_MESSAGE) return;
|
|
378
|
-
if (typeof message.intent !== "string" || message.intent.length === 0) {
|
|
379
|
-
throw new Error("TN_UI_INTENT_INVALID: an intent frame must carry a non-empty name.");
|
|
380
|
-
}
|
|
381
|
-
listener(message.intent, message.payload);
|
|
382
|
-
});
|
|
383
|
-
}
|
|
1
|
+
export { onUiIntent, publishUiState, sendUiIntent, subscribeUiState } from './chunk-7UUT3TY5.js';
|
|
2
|
+
import './chunk-N5LRP4BR.js';
|
|
3
|
+
import { HIT_REGIONS_MESSAGE } from './chunk-CFGTPFUH.js';
|
|
4
|
+
export { GAME_STATE_MESSAGE, HIT_REGIONS_MESSAGE, UI_BRIDGE_GLOBALS, UI_DEV_METRICS_MESSAGE, UI_INTENT_MESSAGE, UI_READY_INTENT, UI_STARTUP_MESSAGE, connectUiBridge } from './chunk-CFGTPFUH.js';
|
|
384
5
|
|
|
385
6
|
// src/ui-hit-regions.ts
|
|
386
7
|
var INTERACTIVE_ATTRIBUTE = "data-tn-interactive";
|
|
@@ -546,4 +167,4 @@ function isDevelopment() {
|
|
|
546
167
|
return import.meta.env?.DEV === true;
|
|
547
168
|
}
|
|
548
169
|
|
|
549
|
-
export {
|
|
170
|
+
export { INTERACTIVE_ATTRIBUTE, publishHitRegions };
|
package/dist/worker.js
CHANGED
|
@@ -1,44 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
function hostDocument() {
|
|
6
|
-
return typeof document === "undefined" ? void 0 : document;
|
|
7
|
-
}
|
|
8
|
-
function hostResizeObserver() {
|
|
9
|
-
return typeof ResizeObserver === "undefined" ? void 0 : ResizeObserver;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// src/profiling/debug-telemetry.ts
|
|
13
|
-
var DEBUG_GLOBAL = "__THREENATIVE_DEBUG__";
|
|
14
|
-
function debugRequested() {
|
|
15
|
-
const host = globalThis;
|
|
16
|
-
return host.process?.env?.TN_DEBUG === "1" || globalThis[DEBUG_GLOBAL] === true || /[?&]tnDebug=1(?:&|$)/u.test(globalThis.location?.search ?? "");
|
|
17
|
-
}
|
|
18
|
-
function countDebug(name, value, area, caller, unit = "count") {
|
|
19
|
-
if (!Number.isFinite(value) || value < 0)
|
|
20
|
-
throw new Error(`TN_DEBUG: invalid ${name} observation.`);
|
|
21
|
-
const host = globalThis;
|
|
22
|
-
host.__tnEngineCost ??= {};
|
|
23
|
-
host.__tnDebugSources ??= {};
|
|
24
|
-
host.__tnEngineCost[name] = (host.__tnEngineCost[name] ?? 0) + value;
|
|
25
|
-
host.__tnDebugSources[name] ??= { area, caller, unit };
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// src/quiet-markers.ts
|
|
29
|
-
var LOG_FLAG = "TN_LOG";
|
|
30
|
-
var isOn = (value) => value === true || typeof value === "string" && value !== "" && value !== "0" && value !== "false";
|
|
31
|
-
function markerLogRequested() {
|
|
32
|
-
const host = globalThis;
|
|
33
|
-
if (isOn(host.process?.env?.[LOG_FLAG])) return true;
|
|
34
|
-
const query = globalThis.location?.search;
|
|
35
|
-
if (typeof query === "string" && /[?&]tnLog=(?!0(?:&|$))(?!false(?:&|$))[^&]/u.test(query))
|
|
36
|
-
return true;
|
|
37
|
-
return isOn(globalThis.__THREENATIVE_LOG__);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// src/ui-bridge.ts
|
|
41
|
-
var GAME_STATE_MESSAGE = "tn:state";
|
|
1
|
+
import { markerLogRequested } from './chunk-2Z44XSI2.js';
|
|
2
|
+
import { hostWindow, hostDocument, hostResizeObserver } from './chunk-6KLNISRJ.js';
|
|
3
|
+
import { debugRequested, countDebug } from './chunk-N5LRP4BR.js';
|
|
4
|
+
import { GAME_STATE_MESSAGE } from './chunk-CFGTPFUH.js';
|
|
42
5
|
|
|
43
6
|
// src/worker-audio.ts
|
|
44
7
|
var PARAM_DEFAULTS = {
|