@threenative/core 0.3.10 → 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.
Files changed (158) hide show
  1. package/capabilities.json +1096 -26
  2. package/dist/camera-shake-CZKOfGn4.d.ts +46 -0
  3. package/dist/{canvas-layer-vCtanIeB.d.ts → canvas-layer-CWuFRT7G.d.ts} +1 -1
  4. package/dist/chunk-2Z44XSI2.js +35 -0
  5. package/dist/chunk-5O73CDMR.js +1849 -0
  6. package/dist/chunk-6KLNISRJ.js +153 -0
  7. package/dist/chunk-7UUT3TY5.js +133 -0
  8. package/dist/chunk-CFGTPFUH.js +231 -0
  9. package/dist/chunk-DBELTTTM.js +615 -0
  10. package/dist/chunk-GMHATRPW.js +7701 -0
  11. package/dist/chunk-GXY7B3JG.js +46 -0
  12. package/dist/chunk-KIRUKTBQ.js +187 -0
  13. package/dist/chunk-N5LRP4BR.js +220 -0
  14. package/dist/chunk-OKXUCASC.js +2238 -0
  15. package/dist/chunk-QWJEMUUT.js +94 -0
  16. package/dist/chunk-VAZM36TV.js +497 -0
  17. package/dist/{game-DzMcitDO.d.ts → game-D7pAzZUY.d.ts} +15 -3
  18. package/dist/hot.d.ts +3 -3
  19. package/dist/hot.js +2 -46
  20. package/dist/index.d.ts +329 -302
  21. package/dist/index.js +10565 -22533
  22. package/dist/{model-lod-CTpZ6imz.d.ts → model-lod-B6BMqS1r.d.ts} +33 -3
  23. package/dist/playtest.d.ts +3 -3
  24. package/dist/playtest.js +24 -75
  25. package/dist/react-css.js +1 -215
  26. package/dist/react.d.ts +2 -2
  27. package/dist/{renderer-rZm0hVqq.d.ts → renderer-DvFVoAgj.d.ts} +13 -4
  28. package/dist/spells/index.d.ts +643 -0
  29. package/dist/spells/index.js +1558 -0
  30. package/dist/spells/ultra/index.d.ts +1600 -0
  31. package/dist/spells/ultra/index.js +6804 -0
  32. package/dist/terrain-jobs-worker.js +1 -123
  33. package/dist/two-sided-foliage-W523J3UM.js +1 -0
  34. package/dist/ui-layer.js +5 -384
  35. package/dist/worker.js +4 -41
  36. package/dist/world.d.ts +725 -259
  37. package/dist/world.js +16714 -18284
  38. package/mcp/animation-server.mjs +1 -1
  39. package/mcp/animation.mjs +2 -3
  40. package/mcp/engine-server.mjs +142 -47
  41. package/mcp/servers.mjs +9 -2
  42. package/mcp/terrain.mjs +8 -0
  43. package/package.json +14 -6
  44. package/patches/three@0.187.0-prd269-upgrade.patch +2102 -0
  45. package/patches/three@0.187.0.patch +2004 -407
  46. package/src/assets.ts +9 -2
  47. package/src/card-lod.ts +152 -0
  48. package/src/compressed-texture-preparation.ts +1008 -0
  49. package/src/frame-budget.ts +31 -20
  50. package/src/game-dev-tools.ts +93 -0
  51. package/src/game-frame-loop.ts +995 -0
  52. package/src/game-renderer-metrics.ts +77 -0
  53. package/src/game-startup.ts +1001 -0
  54. package/src/game-validate.ts +70 -0
  55. package/src/game.ts +253 -1935
  56. package/src/index.ts +27 -2
  57. package/src/launch-diagnostics.ts +22 -12
  58. package/src/look/ao-admission.ts +24 -0
  59. package/src/look/filmic-tone-mapping.ts +15 -13
  60. package/src/look/look-diagnostics.ts +3 -3
  61. package/src/look/quality.ts +10 -5
  62. package/src/look/world-environment.ts +76 -9
  63. package/src/loop.ts +29 -0
  64. package/src/model-lod.ts +42 -3
  65. package/src/particle-kinds.ts +515 -0
  66. package/src/picking.ts +17 -3
  67. package/src/playtest.ts +27 -1
  68. package/src/projection-apply.ts +4 -1
  69. package/src/projection-plan.ts +9 -6
  70. package/src/render/mesh-pool.ts +1 -1
  71. package/src/render/resolution-subrect.ts +2 -0
  72. package/src/render/rough-diffuse.ts +46 -12
  73. package/src/render/soft-shadow.ts +27 -12
  74. package/src/render/virtual-shadow-adaptive.ts +55 -0
  75. package/src/render/virtual-shadow-casters.ts +175 -0
  76. package/src/render/virtual-shadow-layers.ts +76 -0
  77. package/src/render/virtual-shadow-level.ts +224 -0
  78. package/src/render/virtual-shadow-markers.ts +193 -0
  79. package/src/render/virtual-shadow-options.ts +370 -0
  80. package/src/render/virtual-shadow-pages.ts +5 -0
  81. package/src/render/virtual-shadow.ts +213 -992
  82. package/src/render/world-impostor-surface.ts +293 -34
  83. package/src/render-camera-cull.ts +32 -1
  84. package/src/render-pass-budget.ts +34 -7
  85. package/src/renderProjection.ts +22 -0
  86. package/src/renderer.ts +92 -37
  87. package/src/snow-field.ts +1 -1
  88. package/src/spells/cast-pool.ts +361 -0
  89. package/src/spells/index.ts +177 -0
  90. package/src/spells/mechanisms.ts +295 -0
  91. package/src/spells/reaction-field.ts +415 -0
  92. package/src/spells/spell-lights.ts +139 -0
  93. package/src/spells/spell-world.ts +187 -0
  94. package/src/spells/spell.ts +397 -0
  95. package/src/spells/spells.ts +283 -0
  96. package/src/spells/ultra/engine/camera.ts +184 -0
  97. package/src/spells/ultra/engine/quality.ts +96 -0
  98. package/src/spells/ultra/index.ts +52 -0
  99. package/src/spells/ultra/main.ts +305 -0
  100. package/src/spells/ultra/scene/arenaMaterial.ts +325 -0
  101. package/src/spells/ultra/spells/cast.ts +233 -0
  102. package/src/spells/ultra/spells/fire.ts +1267 -0
  103. package/src/spells/ultra/vfx/FluidVolume.ts +816 -0
  104. package/src/spells/ultra/vfx/FluidVolume.tsl.ts +855 -0
  105. package/src/spells/ultra/vfx/FxTarget.ts +61 -0
  106. package/src/spells/ultra/vfx/GroundField.ts +1399 -0
  107. package/src/spells/ultra/vfx/Particles.ts +1475 -0
  108. package/src/spells/ultra/vfx/Ribbons.ts +645 -0
  109. package/src/spells/ultra/vfx/Shockwaves.ts +286 -0
  110. package/src/spells/ultra/vfx/Volumes.ts +489 -0
  111. package/src/spells/ultra/vfx/common.ts +1195 -0
  112. package/src/spells/ultra/vfx/noise.ts +441 -0
  113. package/src/startup-readiness.ts +128 -34
  114. package/src/version.ts +1 -1
  115. package/src/warmup.ts +56 -8
  116. package/src/water-surface.ts +9 -3
  117. package/src/world-bundle-safety.ts +401 -0
  118. package/src/world-cell-batches.ts +1216 -0
  119. package/src/world-cell-chunks.ts +1132 -0
  120. package/src/world-cell-data.ts +995 -0
  121. package/src/world-cell-impostors.ts +1449 -0
  122. package/src/world-cell-lod-bias.ts +151 -0
  123. package/src/world-cell-models.ts +1074 -0
  124. package/src/world-cell-options.ts +189 -0
  125. package/src/world-cell-placements.ts +694 -0
  126. package/src/world-cell-prewarm.ts +557 -0
  127. package/src/world-cell-readiness.ts +357 -0
  128. package/src/world-cell-render-bundles.ts +459 -0
  129. package/src/world-cell-render-gpu-dress.ts +714 -0
  130. package/src/world-cell-render-main-cull.ts +484 -0
  131. package/src/world-cell-render-shadow-claims.ts +198 -0
  132. package/src/world-cell-render-util.ts +246 -0
  133. package/src/world-cell-render.ts +1493 -0
  134. package/src/world-cell-residency.ts +745 -0
  135. package/src/world-cells.ts +1318 -10418
  136. package/src/world-chunk-shadow.ts +308 -0
  137. package/src/world-collar.ts +315 -0
  138. package/src/world-gpu-flags.ts +163 -0
  139. package/src/world-gpu-readback.ts +881 -0
  140. package/src/world-gpu-reference.ts +510 -0
  141. package/src/world-gpu-scene.ts +214 -2264
  142. package/src/world-gpu-shadow.ts +190 -0
  143. package/src/world-gpu-types.ts +381 -0
  144. package/src/world-gpu-validation.ts +518 -0
  145. package/src/world-heightfield.ts +802 -0
  146. package/src/world-load-limiter.ts +106 -0
  147. package/src/world-noise.ts +241 -0
  148. package/src/world-package.ts +42 -0
  149. package/src/world-region.ts +1 -1
  150. package/src/world-terrain-splat.ts +365 -149
  151. package/src/world-tile-budget.ts +256 -0
  152. package/src/world-tile-geometry.ts +469 -0
  153. package/src/world-tile-lod.ts +408 -0
  154. package/src/world-tile-observation.ts +566 -0
  155. package/src/world-tile-stitch.ts +166 -0
  156. package/src/world-tiles.ts +170 -1745
  157. package/src/world-water-bodies.ts +359 -0
  158. package/src/world.ts +35 -741
@@ -1,5 +1,5 @@
1
- import { Camera, Object3D, Mesh, BufferGeometry } from 'three';
2
- import { I as IRendererLike, a as IFrameBudgetWindow, b as IFrameBudgetSimulation } from './renderer-rZm0hVqq.js';
1
+ import { Camera, Object3D, Mesh, BufferGeometry, Sphere } from 'three';
2
+ import { I as IRendererLike, a as IFrameBudgetWindow, b as IFrameBudgetSimulation } from './renderer-DvFVoAgj.js';
3
3
 
4
4
  /** One simulation that can yield its compute work. */
5
5
  interface IBudgetCandidate {
@@ -173,6 +173,23 @@ declare function lodPixelScale(camera: Camera, viewportHeight: number, depth: nu
173
173
  declare const DISCRETE_LOD_DEFAULT_ERROR_PIXELS = 1;
174
174
  /** Default coarsen hysteresis when no resolved policy reaches the loader. */
175
175
  declare const DISCRETE_LOD_DEFAULT_HYSTERESIS = 0.15;
176
+ /**
177
+ * One baked chain: LOD0 is the mesh's own geometry, then one derived geometry per level sharing the
178
+ * same vertex attributes and differing only in index.
179
+ *
180
+ * A chain belongs to the geometry, not to the mesh, because `Object3D.clone()` — which is how a game
181
+ * reuses an imported model, and what `SkeletonUtils.clone` does for a rig — copies the mesh but
182
+ * *shares* its geometry. Keying selection to mesh identity would silently drop every clone to LOD0
183
+ * forever; recovering the chain from the geometry the clone carries is what makes a clone behave
184
+ * like the source.
185
+ */
186
+ interface ILodChain {
187
+ readonly levels: BufferGeometry[];
188
+ readonly errors: readonly number[];
189
+ readonly base: BufferGeometry;
190
+ /** Local-space bounds of the base, shared by every mesh over the chain; the mesh matrix is not. */
191
+ readonly sphere: Sphere;
192
+ }
176
193
  /** Resolved runtime policy the loader stamps onto a controller, from the manifest. */
177
194
  interface IModelLodPolicy {
178
195
  readonly hysteresis: number;
@@ -180,6 +197,19 @@ interface IModelLodPolicy {
180
197
  }
181
198
  /** The LOD0 geometry of a mesh under a discrete chain, or the mesh's own geometry otherwise. */
182
199
  declare function baseGeometryOf(mesh: Mesh): BufferGeometry;
200
+ /**
201
+ * The chain registered against `geometry`, or `undefined` when the geometry carries none.
202
+ *
203
+ * For a caller that draws one geometry many times. A `ModelLod` swaps one mesh's geometry, so an
204
+ * instanced batch — which cannot swap a geometry per instance — derives levels of its own from these
205
+ * numbers and crosses between them by distance instead. Selection stays here: this reads the chain
206
+ * out and hands it over, and the caller does the arithmetic {@link projectedLodError} documents, with
207
+ * a screen-space error budget of its own — a batch's placements are all at different distances, so
208
+ * the budget the loader registered the chain with, which is calibrated for the one mesh it drives,
209
+ * is not the one that applies. Any level of a chain answers, since a clone may be carrying a derived
210
+ * geometry.
211
+ */
212
+ declare function lodChainOf(geometry: BufferGeometry): ILodChain | undefined;
183
213
  /**
184
214
  * Takes every discrete-LOD mesh under `root` through this frame's selection.
185
215
  *
@@ -194,4 +224,4 @@ declare function updateModelLods(root: {
194
224
  traverse(callback: (object: object) => void): void;
195
225
  }, camera: Camera, viewportHeight: number): number;
196
226
 
197
- export { ComputeDrivenRegistry as C, DISCRETE_LOD_DEFAULT_ERROR_PIXELS as D, GPUReadback as G, type IComputeDriven as I, type ILodView as a, type IModelLodPolicy as b, type IGPUReadbackSample as c, type IBudgetCandidate as d, DISCRETE_LOD_DEFAULT_HYSTERESIS as e, type IGPUReadbackOptions as f, baseGeometryOf as g, lodPixelScale as l, updateModelLods as u };
227
+ export { ComputeDrivenRegistry as C, DISCRETE_LOD_DEFAULT_ERROR_PIXELS as D, GPUReadback as G, type IComputeDriven as I, type IGPUReadbackSample as a, type ILodView as b, type IModelLodPolicy as c, type IBudgetCandidate as d, DISCRETE_LOD_DEFAULT_HYSTERESIS as e, type IGPUReadbackOptions as f, baseGeometryOf as g, lodPixelScale as h, lodChainOf as l, updateModelLods as u };
@@ -1,11 +1,11 @@
1
1
  import { JsonValue, JsonPrimitive } from '@threenative/playtest/protocol';
2
2
  export { PLAYTEST_CLOCK_GLOBAL } from '@threenative/playtest/protocol';
3
- import { a as IGamePluginHooks } from './game-DzMcitDO.js';
3
+ import { a as IGamePluginHooks } from './game-D7pAzZUY.js';
4
4
  import './assets-YUbXa3-Y.js';
5
5
  import 'three';
6
- import './renderer-rZm0hVqq.js';
6
+ import './renderer-DvFVoAgj.js';
7
7
  import 'three/webgpu';
8
- import './canvas-layer-vCtanIeB.js';
8
+ import './canvas-layer-CWuFRT7G.js';
9
9
  import 'zustand/vanilla';
10
10
 
11
11
  /**
package/dist/playtest.js CHANGED
@@ -1,79 +1,13 @@
1
+ import { PIPELINE_CENSUS_CAPABILITY, discardEngineCountsSinceLastFrame, readRenderChainObservation, CORE_VERSION } from './chunk-OKXUCASC.js';
2
+ import { GEOMETRY_CAPTURE_CAPABILITY } from './chunk-5O73CDMR.js';
3
+ import { audioRuntimeSnapshot } from './chunk-DBELTTTM.js';
4
+ import './chunk-6KLNISRJ.js';
5
+ import './chunk-N5LRP4BR.js';
1
6
  import { requestedPlaytestClockMode, assertJsonSafe, PLAYTEST_PROTOCOL_LIMITS } from '@threenative/playtest/protocol';
2
7
  export { PLAYTEST_CLOCK_GLOBAL } from '@threenative/playtest/protocol';
3
8
  import { installThreePlaytestBridge } from '@threenative/playtest/three';
4
- import { Sphere, Vector3, Object3D } from 'three';
9
+ import { Object3D } from 'three';
5
10
 
6
- // src/playtest.ts
7
- var AUDIO_STATE = /* @__PURE__ */ Symbol.for("threenative.audio.runtime");
8
- function audioState() {
9
- const host = globalThis;
10
- const existing = host[AUDIO_STATE];
11
- if (existing !== void 0) return existing;
12
- const created = { buses: /* @__PURE__ */ new Set(), cueCounts: /* @__PURE__ */ new Map(), cueLog: [] };
13
- host[AUDIO_STATE] = created;
14
- return created;
15
- }
16
- function audioRuntimeSnapshot() {
17
- let queued = 0;
18
- let voices = 0;
19
- let pooled = 0;
20
- let paused = 0;
21
- const unsupported = /* @__PURE__ */ new Set();
22
- const state = audioState();
23
- for (const bus of state.buses) {
24
- queued += bus.queued;
25
- voices += bus.voices;
26
- pooled += bus.pooled;
27
- paused += bus.pausedVoices;
28
- for (const option of bus.unsupported) unsupported.add(option);
29
- }
30
- return {
31
- cues: Object.fromEntries(state.cueCounts),
32
- paused,
33
- pooled,
34
- queued,
35
- recentCues: state.cueLog.map((entry) => ({ ...entry })),
36
- unsupported: [...unsupported].sort(),
37
- voices
38
- };
39
- }
40
- var GEOMETRY_CAPTURE_CAPABILITY = "runtime.geometry";
41
- new Sphere();
42
- new Vector3();
43
- new Vector3();
44
-
45
- // src/version.ts
46
- var CORE_VERSION = "0.3.10";
47
-
48
- // src/pipeline-census.ts
49
- var PIPELINE_CENSUS_CAPABILITY = "runtime.pipelineCensus";
50
-
51
- // src/profiling/FrameCounters.ts
52
- function discardEngineCountsSinceLastFrame(host = globalThis) {
53
- host.__tnEngineCounterRebase?.();
54
- }
55
-
56
- // src/render/chain.ts
57
- var REPORT_KEY = /* @__PURE__ */ Symbol.for("threenative.renderChain.report");
58
- function storedReport(target) {
59
- return target[REPORT_KEY];
60
- }
61
- function readRenderChainReport(renderer) {
62
- if (!isObject(renderer)) return void 0;
63
- const raw = readRawRenderer(renderer);
64
- return storedReport(renderer) ?? (isObject(raw) ? storedReport(raw) : void 0);
65
- }
66
- function readRenderChainObservation(renderer) {
67
- return readRenderChainReport(renderer)?.applied;
68
- }
69
- function readRawRenderer(renderer) {
70
- return "raw" in renderer ? renderer.raw : renderer;
71
- }
72
- function isObject(value) {
73
- return typeof value === "object" && value !== null;
74
- }
75
-
76
- // src/playtest.ts
77
11
  var currentAgent = typeof navigator === "undefined" ? "node" : navigator.userAgent;
78
12
  function playtest(options = {}) {
79
13
  let dispose;
@@ -211,14 +145,22 @@ function playtest(options = {}) {
211
145
  installRuntimeChannels(installation.bridge, runtime);
212
146
  if (runnerAnnounced()) {
213
147
  runtime?.enableRuntimeDiagnostics?.();
214
- if (!wallClock) runtime?.freezeClock?.();
148
+ if (!wallClock)
149
+ runtime?.freezeClock?.(
150
+ shouldHoldUntilAttached(options) && runtime.settleClock !== void 0 ? 0 : void 0
151
+ );
215
152
  }
216
153
  dispose = installation.dispose;
217
154
  attached = holdUntilAttached(
218
155
  installation.bridge,
219
156
  options,
220
157
  () => startSceneEntered,
221
- runtime?.startSceneLoaded
158
+ runtime?.startSceneLoaded,
159
+ // The live mode, not the one this setup started with: a run that switched to the wall
160
+ // clock mid-run measures frames, and a settle would re-freeze the loop it just released.
161
+ () => {
162
+ if (clockMode !== "wall-clock") runtime?.settleClock?.();
163
+ }
222
164
  );
223
165
  const cleanup = () => {
224
166
  if (!clockDisposed && clockRuntime?._setClockMode !== void 0)
@@ -273,7 +215,7 @@ function runnerAnnounced() {
273
215
  const host = globalThis;
274
216
  return host[PLAYTEST_RUNNER_EXPECTED_GLOBAL] === true || host.TN_PLAYTEST_ENDPOINT !== void 0;
275
217
  }
276
- function holdUntilAttached(bridge, options, startSceneEntered, startSceneLoaded) {
218
+ function holdUntilAttached(bridge, options, startSceneEntered, startSceneLoaded, settleClock) {
277
219
  if (!shouldHoldUntilAttached(options)) return void 0;
278
220
  const timeoutMs = options.attachTimeoutMs ?? PLAYTEST_ATTACH_TIMEOUT_MS;
279
221
  if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
@@ -281,6 +223,12 @@ function holdUntilAttached(bridge, options, startSceneEntered, startSceneLoaded)
281
223
  }
282
224
  const describe = bridge.describe;
283
225
  const applySetup = bridge.applySetup;
226
+ let worldSettled = false;
227
+ const settle = () => {
228
+ if (worldSettled) return;
229
+ worldSettled = true;
230
+ settleClock?.();
231
+ };
284
232
  return new Promise((resolve, reject) => {
285
233
  let settled = false;
286
234
  const timer = setTimeout(() => {
@@ -320,6 +268,7 @@ function holdUntilAttached(bridge, options, startSceneEntered, startSceneLoaded)
320
268
  bridge.describe = async () => {
321
269
  release();
322
270
  await startSceneEntered();
271
+ settle();
323
272
  return describe();
324
273
  };
325
274
  });
package/dist/react-css.js CHANGED
@@ -1,221 +1,7 @@
1
+ import { connectUiBridge } from './chunk-CFGTPFUH.js';
1
2
  import ReactReconciler from 'react-reconciler';
2
3
  import { DiscreteEventPriority, NoEventPriority } from 'react-reconciler/constants.js';
3
4
 
4
- // src/react-css.ts
5
-
6
- // src/ui-bridge.ts
7
- var UI_BRIDGE_GLOBALS = {
8
- /** UI end, inbound: the host calls this with one JSON string. */
9
- uiReceive: "__tnUiReceive",
10
- /** UI end, outbound: an injected object with `postMessage(string)`. */
11
- uiHost: "tnHost",
12
- /** Game end, inbound: the runtime calls this with one JSON string. */
13
- gameReceive: "__tnUiGameReceive",
14
- /** Game end, outbound: the runtime installs this and forwards to the web view. */
15
- gamePost: "__tnUiPost"
16
- };
17
- var stateFrames = /* @__PURE__ */ new WeakMap();
18
- function assertSendable(message) {
19
- if (typeof message !== "object" || message === null || Array.isArray(message)) {
20
- throw new Error("TN_UI_BRIDGE_MESSAGE_INVALID: a bridge message must be a JSON object.");
21
- }
22
- if (typeof message.type !== "string" || message.type.length === 0) {
23
- throw new Error("TN_UI_BRIDGE_MESSAGE_INVALID: a bridge message must carry a string 'type'.");
24
- }
25
- let frame;
26
- try {
27
- frame = stateFrames.get(message) ?? JSON.stringify(message);
28
- } catch (error) {
29
- throw new Error(
30
- `TN_UI_BRIDGE_MESSAGE_INVALID: '${message.type}' is not JSON-serialisable: ${error instanceof Error ? error.message : String(error)}`
31
- );
32
- }
33
- if (frame === void 0) {
34
- throw new Error(`TN_UI_BRIDGE_MESSAGE_INVALID: '${message.type}' serialised to nothing.`);
35
- }
36
- return frame;
37
- }
38
- function parseFrame(frame) {
39
- const text = typeof frame === "string" ? frame : frame?.data;
40
- if (typeof text !== "string") {
41
- throw new Error("TN_UI_BRIDGE_FRAME_INVALID: expected a JSON string from the host.");
42
- }
43
- let parsed;
44
- try {
45
- parsed = JSON.parse(text);
46
- } catch (error) {
47
- throw new Error(
48
- `TN_UI_BRIDGE_FRAME_INVALID: not JSON: ${error instanceof Error ? error.message : String(error)}`
49
- );
50
- }
51
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
52
- throw new Error("TN_UI_BRIDGE_FRAME_INVALID: a bridge frame must be a JSON object.");
53
- }
54
- if (typeof parsed.type !== "string") {
55
- throw new Error("TN_UI_BRIDGE_FRAME_INVALID: a bridge frame must carry a string 'type'.");
56
- }
57
- return parsed;
58
- }
59
- function findOutbound(scope, end) {
60
- if (end === "game") {
61
- const post = scope[UI_BRIDGE_GLOBALS.gamePost];
62
- return typeof post === "function" ? (frame) => post(frame) : void 0;
63
- }
64
- const injected = scope[UI_BRIDGE_GLOBALS.uiHost];
65
- if (typeof injected?.postMessage === "function") {
66
- return (frame) => injected.postMessage(frame);
67
- }
68
- const webkit = scope.webkit;
69
- const handler = webkit?.messageHandlers?.[UI_BRIDGE_GLOBALS.uiHost];
70
- if (typeof handler?.postMessage === "function") {
71
- return (frame) => handler.postMessage(frame);
72
- }
73
- const ipc = scope.ipc;
74
- if (typeof ipc?.postMessage === "function") {
75
- return (frame) => ipc.postMessage(frame);
76
- }
77
- return void 0;
78
- }
79
- var BROKER_KEY = "__tnUiBridgeBroker";
80
- function broker(scope) {
81
- const existing = scope[BROKER_KEY];
82
- if (existing !== void 0) return existing;
83
- const created = { game: /* @__PURE__ */ new Set(), ui: /* @__PURE__ */ new Set(), inbound: /* @__PURE__ */ new Map() };
84
- scope[BROKER_KEY] = created;
85
- return created;
86
- }
87
- function installInbound(scope, key, deliver) {
88
- const bus = broker(scope);
89
- let slot = bus.inbound.get(key);
90
- if (slot === void 0) {
91
- const receivers = /* @__PURE__ */ new Set();
92
- slot = {
93
- receivers,
94
- dispatch: (frame) => {
95
- let firstError;
96
- let failed = false;
97
- for (const receiver of [...receivers]) {
98
- try {
99
- receiver(frame);
100
- } catch (error) {
101
- if (!failed) {
102
- failed = true;
103
- firstError = error;
104
- }
105
- }
106
- }
107
- if (failed) throw firstError;
108
- }
109
- };
110
- bus.inbound.set(key, slot);
111
- }
112
- slot.receivers.add(deliver);
113
- scope[key] = slot.dispatch;
114
- const installed = slot;
115
- return () => {
116
- installed.receivers.delete(deliver);
117
- if (installed.receivers.size === 0 && scope[key] === installed.dispatch) scope[key] = void 0;
118
- };
119
- }
120
- var LOOPBACK_KEY = "__tnUiLoopback";
121
- function installLoopback(scope) {
122
- const search = scope.location?.search;
123
- if (typeof search !== "string" || new URLSearchParams(search).get("tnUiLoopback") !== "1") return;
124
- if (scope[LOOPBACK_KEY] !== void 0) return;
125
- const { port1: gamePort, port2: uiPort } = new MessageChannel();
126
- const receive = (key) => (event) => scope[key]?.(event.data);
127
- gamePort.onmessage = receive(UI_BRIDGE_GLOBALS.gameReceive);
128
- uiPort.onmessage = receive(UI_BRIDGE_GLOBALS.uiReceive);
129
- scope[UI_BRIDGE_GLOBALS.gamePost] = (frame) => gamePort.postMessage(frame);
130
- scope[UI_BRIDGE_GLOBALS.uiHost] = { postMessage: (frame) => uiPort.postMessage(frame) };
131
- scope.__tnUiOverlayAttached = () => true;
132
- scope[LOOPBACK_KEY] = {
133
- close() {
134
- gamePort.close();
135
- uiPort.close();
136
- for (const key of [UI_BRIDGE_GLOBALS.gamePost, UI_BRIDGE_GLOBALS.uiHost, LOOPBACK_KEY])
137
- scope[key] = void 0;
138
- scope.__tnUiOverlayAttached = void 0;
139
- }
140
- };
141
- }
142
- function connectUiBridge(options) {
143
- const { end } = options;
144
- if (end !== "game" && end !== "ui") {
145
- throw new Error(`TN_UI_BRIDGE_END_INVALID: expected 'game' or 'ui', got '${String(end)}'.`);
146
- }
147
- const scope = options.scope ?? globalThis;
148
- installLoopback(scope);
149
- const listeners = /* @__PURE__ */ new Set();
150
- const deliver = (frame) => {
151
- const message = parseFrame(frame);
152
- for (const listener of [...listeners]) listener(message);
153
- };
154
- const outbound = findOutbound(scope, end);
155
- const inboundKey = end === "ui" ? UI_BRIDGE_GLOBALS.uiReceive : UI_BRIDGE_GLOBALS.gameReceive;
156
- let closed = false;
157
- if (outbound === void 0) {
158
- const bus = broker(scope);
159
- const peer = end === "ui" ? "game" : "ui";
160
- const own = (message) => {
161
- for (const listener of [...listeners]) listener(message);
162
- };
163
- bus[end].add(own);
164
- return {
165
- end,
166
- transport: "in-process",
167
- hasPeer: () => bus[peer].size > 0,
168
- post(message) {
169
- const frame = assertSendable(message);
170
- if (closed) throw new Error("TN_UI_BRIDGE_CLOSED: post on a closed bridge.");
171
- const copy = JSON.parse(frame);
172
- for (const listener of [...bus[peer]]) listener(copy);
173
- },
174
- onMessage(listener) {
175
- listeners.add(listener);
176
- return () => listeners.delete(listener);
177
- },
178
- close() {
179
- closed = true;
180
- listeners.clear();
181
- bus[end].delete(own);
182
- }
183
- };
184
- }
185
- const uninstall = installInbound(scope, inboundKey, deliver);
186
- const injected = scope[UI_BRIDGE_GLOBALS.uiHost];
187
- if (end === "ui" && injected !== void 0 && typeof injected === "object") {
188
- injected.onmessage = (event) => deliver(event);
189
- }
190
- return {
191
- end,
192
- transport: "host",
193
- hasPeer() {
194
- const attached = scope.__tnUiOverlayAttached;
195
- if (end === "ui") return true;
196
- return typeof attached === "function" ? attached() === true : false;
197
- },
198
- post(message) {
199
- const frame = assertSendable(message);
200
- if (closed) throw new Error("TN_UI_BRIDGE_CLOSED: post on a closed bridge.");
201
- outbound(frame);
202
- },
203
- onMessage(listener) {
204
- listeners.add(listener);
205
- return () => listeners.delete(listener);
206
- },
207
- close() {
208
- closed = true;
209
- listeners.clear();
210
- uninstall();
211
- if (end === "ui" && injected !== void 0 && typeof injected === "object") {
212
- injected.onmessage = void 0;
213
- }
214
- }
215
- };
216
- }
217
-
218
- // src/react-css.ts
219
5
  var CSS_UI_MESSAGE = "tn:css";
220
6
  var CSS_UI_TAGS = [
221
7
  "div",
package/dist/react.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ReactNode } from 'react';
2
- import { C as CanvasLayer } from './canvas-layer-vCtanIeB.js';
2
+ import { C as CanvasLayer } from './canvas-layer-CWuFRT7G.js';
3
3
  import 'three';
4
- import './renderer-rZm0hVqq.js';
4
+ import './renderer-DvFVoAgj.js';
5
5
  import 'three/webgpu';
6
6
 
7
7
  /**
@@ -631,9 +631,11 @@ interface IFrameBudgetWindow {
631
631
  interface IFrameBudgetSimulation {
632
632
  readonly tick: () => number;
633
633
  readonly step: number;
634
+ /** False counts presented frames while the simulation has not advanced in the window. */
635
+ readonly clockFrozen?: boolean;
634
636
  }
635
637
  interface IFrameBudgetOptions {
636
- /** Simulation ticks per report window when a clock is supplied, otherwise presented frames. Default 300. */
638
+ /** Simulation ticks per window; presented frames without a clock or while a live one is held. Default 300. */
637
639
  readonly reportEvery?: number;
638
640
  /** Minimum measured rendered frames per report window. Default 1. */
639
641
  readonly minFrames?: number;
@@ -779,8 +781,9 @@ declare class FrameBudget {
779
781
  */
780
782
  addStages(stages: IFrameStageSample): void;
781
783
  /**
782
- * Closes the frame and returns its phase split, or `undefined` when the frame was a hitch and
783
- * therefore excluded — a 27-second startup stall is not a frame time and must not enter a
784
+ * Closes the frame and returns its phase split, or `undefined` when `wantSample` is false. A hitch
785
+ * still returns its split — `loop.ts` feeds it to the per-frame diagnostics — and the window meters
786
+ * below are what exclude it: a 27-second startup stall is not a frame time and must not enter a
784
787
  * percentile anybody is asked to act on.
785
788
  *
786
789
  * `wantSample` is false when the caller is going to discard the split, which is the default
@@ -1636,8 +1639,14 @@ interface IRendererLike {
1636
1639
  * Ordinary textures and the WebGL fallback retain their existing paths and report no work.
1637
1640
  * `onProgress` receives the completed unique compressed texture count after each preparation
1638
1641
  * promise resolves; queued textures and writes that have not settled receive no credit.
1642
+ *
1643
+ * Pass `replacements` to receive caller-owned `original -> prepared` pairs. The renderer owns
1644
+ * the prepared GPU textures and publishes the map only after the whole call succeeds; an abort
1645
+ * or failure leaves the caller's map unchanged. Without it the call keeps the numeric contract
1646
+ * and prepared compressed replacements stay unpublished, so a material that samples the
1647
+ * original keeps its borrowed identity.
1639
1648
  */
1640
- prepareTextures?(textures: Iterable<Texture>, signal?: AbortSignal, onProgress?: (completed: number) => void): Promise<number>;
1649
+ prepareTextures?(textures: Iterable<Texture>, signal?: AbortSignal, onProgress?: (completed: number) => void, replacements?: Map<Texture, Texture>): Promise<number>;
1641
1650
  /**
1642
1651
  * Copies one GPU storage attribute back to the CPU, asynchronously.
1643
1652
  *