@vgai/engine 0.5.16 → 0.5.17

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 (99) hide show
  1. package/dist/adapter/adapter-module.d.ts +1 -16
  2. package/dist/adapter/adapter-module.d.ts.map +1 -1
  3. package/dist/adapter/adapter-module.js +1 -11
  4. package/dist/adapter/finders/scenes-from-entrypoint-selection.d.ts +0 -2
  5. package/dist/adapter/finders/scenes-from-entrypoint-selection.d.ts.map +1 -1
  6. package/dist/adapter/finders/scenes-from-entrypoint-selection.js +3 -6
  7. package/dist/adapter/root-adapter.d.ts +4 -0
  8. package/dist/adapter/root-adapter.d.ts.map +1 -1
  9. package/dist/adapter/root-seam-contract.d.ts +5 -0
  10. package/dist/adapter/root-seam-contract.d.ts.map +1 -1
  11. package/dist/adapter/root-seam-contract.js +1 -0
  12. package/dist/adapter/setup-three-root-adapter.js +9 -9
  13. package/dist/canvas-react/pixi-react-adapter.d.ts.map +1 -1
  14. package/dist/canvas-react/pixi-react-adapter.js +92 -41
  15. package/dist/data/curve.d.ts +1 -1
  16. package/dist/data/curve.js +2 -2
  17. package/dist/dev/instruments.d.ts +4 -4
  18. package/dist/dev/instruments.js +4 -4
  19. package/dist/dev/register-render-vitals.d.ts +2 -2
  20. package/dist/dev/register-render-vitals.js +2 -2
  21. package/dist/dev/static-batch-advisor.d.ts +1 -1
  22. package/dist/dev/static-batch-advisor.js +2 -2
  23. package/dist/input/input-manager.d.ts +15 -0
  24. package/dist/input/input-manager.d.ts.map +1 -1
  25. package/dist/input/input-manager.js +22 -0
  26. package/dist/manifest/load.d.ts +0 -3
  27. package/dist/manifest/load.d.ts.map +1 -1
  28. package/dist/manifest/load.js +0 -4
  29. package/dist/manifest/schema.d.ts +0 -2
  30. package/dist/manifest/schema.d.ts.map +1 -1
  31. package/dist/manifest/schema.js +2 -23
  32. package/dist/pixi/authoring.d.ts +33 -0
  33. package/dist/pixi/authoring.d.ts.map +1 -1
  34. package/dist/pixi/authoring.js +86 -6
  35. package/dist/react/world-state.d.ts +12 -0
  36. package/dist/react/world-state.d.ts.map +1 -1
  37. package/dist/react/world-state.js +14 -0
  38. package/dist/render/soft-particle-depth.d.ts +3 -3
  39. package/dist/render/soft-particle-depth.d.ts.map +1 -1
  40. package/dist/render/soft-particle-depth.js +8 -13
  41. package/dist/runtime/create-runtime.d.ts +2 -16
  42. package/dist/runtime/create-runtime.d.ts.map +1 -1
  43. package/dist/runtime/create-runtime.js +36 -38
  44. package/dist/runtime/dev-build.d.ts +37 -0
  45. package/dist/runtime/dev-build.d.ts.map +1 -0
  46. package/dist/runtime/dev-build.js +49 -0
  47. package/dist/runtime/game.d.ts +9 -1
  48. package/dist/runtime/game.d.ts.map +1 -1
  49. package/dist/runtime/game.js +25 -1
  50. package/dist/runtime/mount-manifest.d.ts +0 -13
  51. package/dist/runtime/mount-manifest.d.ts.map +1 -1
  52. package/dist/runtime/mount-manifest.js +1 -20
  53. package/dist/world3d-react/engine-bridge.d.ts.map +1 -1
  54. package/dist/world3d-react/engine-bridge.js +28 -3
  55. package/dist/world3d-react/index.d.ts +1 -1
  56. package/dist/world3d-react/index.js +1 -1
  57. package/dist/world3d-react/r3f-adapter.d.ts.map +1 -1
  58. package/dist/world3d-react/r3f-adapter.js +89 -14
  59. package/dist/world3d-react/r3f-root-factory.d.ts.map +1 -1
  60. package/dist/world3d-react/r3f-root-factory.js +12 -2
  61. package/dist/world3d-react/rapier-physics-bridge.d.ts +4 -4
  62. package/dist/world3d-react/rapier-physics-bridge.js +3 -3
  63. package/dist/world3d-react/world-context.d.ts +43 -0
  64. package/dist/world3d-react/world-context.d.ts.map +1 -1
  65. package/dist/world3d-react/world-context.js +89 -46
  66. package/dist-config/config.js.map +1 -1
  67. package/package.json +1 -1
  68. package/schemas/engine-capabilities.json +3 -3
  69. package/schemas/vgai-project.schema.json +1 -6
  70. package/src/adapter/adapter-module.ts +1 -25
  71. package/src/adapter/finders/scenes-from-entrypoint-selection.ts +3 -8
  72. package/src/adapter/root-adapter.ts +4 -0
  73. package/src/adapter/root-seam-contract.ts +1 -0
  74. package/src/adapter/setup-three-root-adapter.ts +9 -9
  75. package/src/canvas-react/pixi-react-adapter.tsx +98 -53
  76. package/src/data/curve.ts +2 -2
  77. package/src/dev/instruments.ts +4 -4
  78. package/src/dev/register-render-vitals.ts +2 -2
  79. package/src/dev/static-batch-advisor.ts +2 -2
  80. package/src/input/input-manager.ts +23 -0
  81. package/src/manifest/load.ts +0 -7
  82. package/src/manifest/schema.ts +2 -25
  83. package/src/pixi/authoring.ts +98 -6
  84. package/src/react/world-state.tsx +15 -0
  85. package/src/render/soft-particle-depth.ts +8 -13
  86. package/src/runtime/create-runtime.ts +38 -52
  87. package/src/runtime/dev-build.ts +49 -0
  88. package/src/runtime/game.ts +31 -2
  89. package/src/runtime/mount-manifest.ts +1 -32
  90. package/src/world3d-react/engine-bridge.ts +28 -3
  91. package/src/world3d-react/index.ts +1 -1
  92. package/src/world3d-react/r3f-adapter.tsx +87 -18
  93. package/src/world3d-react/r3f-root-factory.tsx +12 -2
  94. package/src/world3d-react/rapier-physics-bridge.tsx +4 -4
  95. package/src/world3d-react/world-context.ts +100 -51
  96. package/dist/runtime/dev-layers.d.ts +0 -34
  97. package/dist/runtime/dev-layers.d.ts.map +0 -1
  98. package/dist/runtime/dev-layers.js +0 -46
  99. package/src/runtime/dev-layers.ts +0 -46
@@ -28,10 +28,10 @@ import { createWebGLFrameCapture } from '../dev/webgl-frame-capture';
28
28
  import { WorldProvider } from '../react/world-state';
29
29
  import { createSoftParticleDepthPass } from '../render/soft-particle-depth';
30
30
  import { getDebugRegistry } from '../runtime/debug-registry';
31
- import { devLayersEnabled } from '../runtime/dev-layers';
31
+ import { devBuildEnabled } from '../runtime/dev-build';
32
32
  import { EngineBridge } from './engine-bridge';
33
33
  import { applyWorldRendererConfig } from './renderer-config';
34
- import { createR3FRootContext } from './world-context';
34
+ import { createR3FRootContext, DEFAULT_INPUT_MAP_PATH, wireGameInputSeams } from './world-context';
35
35
  /**
36
36
  * Scene depth for any soft-particle system this world mounted, drawn between
37
37
  * gameplay and the draw.
@@ -52,6 +52,11 @@ import { createR3FRootContext } from './world-context';
52
52
  * sort is stable) — the tie-break among priority-0 callbacks is insertion
53
53
  * order.
54
54
  *
55
+ * It is mounted only when THIS host carries a real WebGL context. The editor's
56
+ * design-time host deliberately reconciles the scene without one because the
57
+ * editor viewport owns the real renderer and camera; that viewport runs the
58
+ * same generic depth pass immediately before it presents the adopted scene.
59
+ *
55
60
  * Costs nothing while no soft-particle system is armed — see
56
61
  * `../render/soft-particle-depth.ts` for what "armed" means and what the pass
57
62
  * spends when it is.
@@ -127,10 +132,32 @@ export function createR3FAdapter(options) {
127
132
  // `ctx` rides the bridge so ordinary components can reach engine
128
133
  // services through `useGameContext()`.
129
134
  const bridge = runtime ? { ctx: runtime.ctx } : null;
135
+ const gameDebugRegistry = host.game ? getDebugRegistry(host.game) : null;
136
+ // THE HOST STILL WIRES THIS GAME'S INPUT WHEN THE WORLD TAKES NO CONTEXT.
137
+ //
138
+ // A default-exported world mounts with `engineRuntime: false` — no vgai
139
+ // runtime context enters its React tree, by design. That says nothing
140
+ // about the GAME-scoped input the host owns from the outside: the
141
+ // project's declared map, and this root's `game.input.*` seams on the
142
+ // debug registry. Skipping those made a fresh scaffold's bot/autoplay/
143
+ // `vgai eval` input doors throw `DEBUG_INPUT_UNAVAILABLE` and left the
144
+ // declared actions unloaded — in the ONE world shape `vgai create`
145
+ // produces. Same host-vs-context split as `WorldProvider` below.
146
+ //
147
+ // `inputMapPath` unset (what the default-export factory passes) means
148
+ // "the conventional path, if this project ships one" — quiet when it
149
+ // does not, since a brand-new project declares no actions yet.
150
+ const hostInputReady = runtime || !gameDebugRegistry
151
+ ? null
152
+ : wireGameInputSeams(host, gameDebugRegistry, {
153
+ id,
154
+ inputMapPath: inputMapPath ?? DEFAULT_INPUT_MAP_PATH,
155
+ optionalInputMap: inputMapPath === undefined,
156
+ });
130
157
  // Actions must exist before any component's init()/first frame reads
131
158
  // them — wait for the (never-rejecting) input-map load before the first
132
159
  // commit.
133
- await runtime?.inputMapReady;
160
+ await (runtime?.inputMapReady ?? hostInputReady);
134
161
  // The world's own colour pipeline. Applied AFTER `root.configure()` below — see the comment
135
162
  // at its call site for why "before" is the version that silently does nothing.
136
163
  let restoreRendererConfig = () => { };
@@ -257,13 +284,37 @@ export function createR3FAdapter(options) {
257
284
  // until this landed. `host.game` is genuinely absent in bare/headless
258
285
  // hosts, so the provider is conditional and those hooks stay the inert
259
286
  // no-ops they already document themselves to be.
260
- const game = runtime?.ctx.game;
287
+ //
288
+ // READ FROM `host.game`, NEVER FROM `runtime` — the two are not the same
289
+ // question, and conflating them silently dark-ended the seam for every
290
+ // scaffolded game. The IDIOMATIC three world (`export default function
291
+ // World()`) mounts through `resolveR3FEntryAdapter` with
292
+ // `engineRuntime: false` (`r3f-root-factory.tsx`), so it has no
293
+ // `runtime` and no `bridge` — by design, because the vgai runtime
294
+ // CONTEXT (`useGameContext`) must not enter an ecosystem-native tree.
295
+ // `WorldProvider` is not that context: it carries the Game handle the
296
+ // host already holds, and it is the only way a game's own
297
+ // `useDebugProvider('stat', …)` can reach the ONE game-scoped registry
298
+ // the editor/`vgai eval` read. Keyed off `runtime`, every
299
+ // default-exported world's registrations no-opped in silence and
300
+ // `vgai eval 'await game.providers()'` listed only the built-ins.
301
+ // The canvas lane never had the gap (`canvas-react/
302
+ // pixi-react-root-factory.tsx` keeps its entry runtime on).
303
+ const game = host.game;
261
304
  // `SoftParticleDepth` trails the world's own tree deliberately — see its
262
- // docblock for why the subscription must land last.
263
- const world = createElement(Fragment, null, content, runtime ? createElement(SoftParticleDepth, { key: 'vgai-soft-particle-depth' }) : null, createElement(MountEffectsReady, { key: 'vgai-mount-effects-ready' }));
264
- root.render(bridge
265
- ? createElement(EngineBridge.Provider, { value: bridge }, game ? createElement(WorldProvider, { game }, world) : world)
266
- : world);
305
+ // docblock for why the subscription must land last. A no-context design
306
+ // mount omits this fiber callback because the adopting editor viewport
307
+ // runs the pass with its own renderer and camera instead.
308
+ const world = createElement(Fragment, null, content, runtime && typeof host.renderer.getContext === 'function'
309
+ ? createElement(SoftParticleDepth, { key: 'vgai-soft-particle-depth' })
310
+ : null, createElement(MountEffectsReady, { key: 'vgai-mount-effects-ready' }));
311
+ // The two providers are INDEPENDENT: `EngineBridge` rides `bridge` (the
312
+ // vgai runtime context, absent for a native default-exported world),
313
+ // `WorldProvider` rides `host.game` (the React seam, present whenever a
314
+ // Game hosts this world). Nesting the second inside the first is what
315
+ // made the seam a hostage of the first.
316
+ const provided = game ? createElement(WorldProvider, { game }, world) : world;
317
+ root.render(bridge ? createElement(EngineBridge.Provider, { value: bridge }, provided) : provided);
267
318
  // A reconcile-time crash (e.g. a missing `extend` catalogue entry)
268
319
  // surfaces as an uncaught window error and `onCreated` never fires —
269
320
  // without this guard, `mount()` would await `statePromise` FOREVER and
@@ -274,6 +325,8 @@ export function createR3FAdapter(options) {
274
325
  cleanup();
275
326
  root.unmount();
276
327
  runtime?.dispose();
328
+ if (!runtime)
329
+ gameDebugRegistry?.strip(id);
277
330
  restoreRendererConfig();
278
331
  reject(new Error(`r3f-adapter: fiber crashed before its first commit — ${event.message} ` +
279
332
  '(mount() fails loudly instead of hanging on onCreated)'));
@@ -282,6 +335,8 @@ export function createR3FAdapter(options) {
282
335
  cleanup();
283
336
  root.unmount();
284
337
  runtime?.dispose();
338
+ if (!runtime)
339
+ gameDebugRegistry?.strip(id);
285
340
  restoreRendererConfig();
286
341
  reject(new Error('r3f-adapter: onCreated did not fire within 10s — the R3F tree never reached ' +
287
342
  'its first commit (mount() fails loudly instead of hanging)'));
@@ -334,7 +389,6 @@ export function createR3FAdapter(options) {
334
389
  // `RootState` for precisely this reason, so reading it per frame is the
335
390
  // supported way to see the live root. It is a plain map read.
336
391
  const live = () => state.get();
337
- const gameDebugRegistry = host.game ? getDebugRegistry(host.game) : null;
338
392
  // --- Live render vitals (issue #1504), for an R3F world -----------------
339
393
  // The SAME door the classic adapter seeds
340
394
  // (`../adapter/setup-three-root-adapter.ts`), seeded here for the same
@@ -345,11 +399,11 @@ export function createR3FAdapter(options) {
345
399
  // world is the only shape a scaffolded project's three root has, so a
346
400
  // door wired only into the classic path is a door no scaffolded project
347
401
  // ever gets (issue #1518: `game.state('render.vitals')` answered "no
348
- // state provider registered" in the field while every other dev layer of
349
- // the same world worked).
402
+ // state provider registered" in the field while every other debug
403
+ // reading of the same world worked).
350
404
  //
351
405
  // The gate is the same three conditions, minus the one that cannot
352
- // arise: `devLayersEnabled()` (`../runtime/dev-layers.ts`, the ONE owner
406
+ // arise: `devBuildEnabled()` (`../runtime/dev-build.ts`, the ONE owner
353
407
  // of "is this a dev context" — a ship build registers nothing and pays
354
408
  // nothing), and a `Game` shell (the readings are folded out of that
355
409
  // game's profiler frames). "Not headless" needs no term here: a headless
@@ -367,7 +421,7 @@ export function createR3FAdapter(options) {
367
421
  // (the fold) and `runtime.dispose()`'s scoped `strip(id)` (the
368
422
  // registrations) — the same split the classic adapter documents.
369
423
  let renderVitals = null;
370
- if (host.game && devLayersEnabled()) {
424
+ if (host.game && devBuildEnabled()) {
371
425
  // Same auto-enable as the classic adapter: the readings are folded out
372
426
  // of profiler frames, and the profiler is a flag the editor already
373
427
  // sets on play — under the dev gate this is the same cost arriving a
@@ -551,6 +605,27 @@ export function createR3FAdapter(options) {
551
605
  renderVitals?.dispose();
552
606
  renderVitals = null;
553
607
  runtime?.dispose();
608
+ // The no-context path has no `runtime.dispose()` to carry its scoped
609
+ // strip, so it ends its own registrations here — the same
610
+ // `strip(id)`, at the same moment. That is what ends this world's
611
+ // PROVIDERS AND COMMANDS (the render-vitals door above is the one
612
+ // this path actually registers under `id`); sibling roots are
613
+ // untouched.
614
+ //
615
+ // It does NOT end the input seams `wireGameInputSeams` set, and
616
+ // nothing else does either: `strip` walks providers/commands only
617
+ // (`runtime/debug-registry.ts`), so `virtualInputTargets`/
618
+ // `inputActionsSources`/`inputTraceSources` keep this world's id
619
+ // until a remount of the same id overwrites it. The runtime path has
620
+ // always been identical, and the residue is inert rather than
621
+ // hidden: every one of those closures reads GAME-scoped state
622
+ // (`game.input`, `game.loop.fixedDt`, the game's seed), so a stale
623
+ // entry actuates exactly what a live one would. What it can still do
624
+ // is name a dead world in `DEBUG_INPUT_WORLD_NOT_FOUND`'s registered
625
+ // list. Do not write "the strip clears the input seams" here again
626
+ // without changing `strip` to actually do it.
627
+ if (!runtime)
628
+ gameDebugRegistry?.strip(id);
554
629
  restoreRendererConfig();
555
630
  },
556
631
  };
@@ -1 +1 @@
1
- {"version":3,"file":"r3f-root-factory.d.ts","sourceRoot":"","sources":["../../src/world3d-react/r3f-root-factory.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAUnE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAc/F;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,qBAQ5B,CAAC"}
1
+ {"version":3,"file":"r3f-root-factory.d.ts","sourceRoot":"","sources":["../../src/world3d-react/r3f-root-factory.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAUnE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAwB/F;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,qBAQ5B,CAAC"}
@@ -60,8 +60,18 @@ export function resolveR3FEntryAdapter(entryModule, rootId) {
60
60
  id: rootId,
61
61
  content: createElement(mod.default),
62
62
  // A default-exported R3F component is an ordinary R3F app. The host
63
- // controls Fiber's native `frameloop: 'never'` scheduler; vgai runtime
64
- // context, systems and state providers never enter its React tree.
63
+ // controls Fiber's native `frameloop: 'never'` scheduler; the vgai
64
+ // runtime CONTEXT (`useGameContext`, `ctx.systems`) never enters its
65
+ // React tree.
66
+ //
67
+ // This flag governs that context and nothing else. It does NOT govern
68
+ // `WorldProvider`: `useDebugProvider`/`useDebugCommand`/`useWorldState`
69
+ // are the documented door a game declares its own state/commands
70
+ // through, and they must work in the idiomatic shape — which is the
71
+ // ONLY shape `vgai create` scaffolds. `r3f-adapter.tsx` therefore keys
72
+ // that provider off `host.game`, not off this flag; see the comment
73
+ // beside `const game = host.game` there for the measured symptom
74
+ // (`vgai eval 'await game.providers()'` listing only built-ins).
65
75
  engineRuntime: false,
66
76
  });
67
77
  }
@@ -3,7 +3,7 @@
3
3
  * `@react-three/rapier` physics VISIBLE to the engine's editor/dev seams.
4
4
  *
5
5
  * WHY IT EXISTS. `SystemAdapters.physics` is what the editor's transform
6
- * coordination (`freeze → apply → unfreeze`) and the dev menu's universal
6
+ * coordination (`freeze → apply → unfreeze`) and the universal
7
7
  * "Colliders drawn" instrument (`@engine/dev/instruments`) read. The
8
8
  * first-party imperative three root registers one from
9
9
  * `../adapter/setup-three-root-adapter.ts`; an R3F world builds no first-party
@@ -44,7 +44,7 @@
44
44
  * on the R3F root it is mounted in. It allocates nothing else — no timers, no
45
45
  * subscriptions, no per-frame work (see the phase note below), and no Rapier
46
46
  * objects: the bodies it edits belong to `<Physics>`.
47
- * SHARERS: every reader of `game.systemAdapters.physics` — the dev menu's
47
+ * SHARERS: every reader of `game.systemAdapters.physics` — the
48
48
  * colliders instrument, the editor's transform coordination. They read; they
49
49
  * never dispose.
50
50
  * TEARDOWN: the effect's cleanup, and nothing else — it clears the SAME key it
@@ -55,13 +55,13 @@
55
55
  *
56
56
  * PHASE ORDERING: none to respect — this component registers pull-only
57
57
  * callbacks and runs no per-frame work. Every method it exposes is invoked
58
- * BETWEEN frames, by an editor gesture or a dev-menu command, never from a
58
+ * BETWEEN frames, by an editor gesture or an instrument command, never from a
59
59
  * phase.
60
60
  */
61
61
  export interface RapierPhysicsBridgeProps {
62
62
  /**
63
63
  * Set the `debug` prop of the SAME `<Physics>` this bridge is mounted in.
64
- * The dev menu's "Colliders drawn" toggle calls it; the world's own state is
64
+ * The "Colliders drawn" instrument calls it; the world's own state is
65
65
  * what `<Physics debug={…}>` reads, so the library's debug rendering is the
66
66
  * only thing that ever draws a collider.
67
67
  */
@@ -3,7 +3,7 @@
3
3
  * `@react-three/rapier` physics VISIBLE to the engine's editor/dev seams.
4
4
  *
5
5
  * WHY IT EXISTS. `SystemAdapters.physics` is what the editor's transform
6
- * coordination (`freeze → apply → unfreeze`) and the dev menu's universal
6
+ * coordination (`freeze → apply → unfreeze`) and the universal
7
7
  * "Colliders drawn" instrument (`@engine/dev/instruments`) read. The
8
8
  * first-party imperative three root registers one from
9
9
  * `../adapter/setup-three-root-adapter.ts`; an R3F world builds no first-party
@@ -44,7 +44,7 @@
44
44
  * on the R3F root it is mounted in. It allocates nothing else — no timers, no
45
45
  * subscriptions, no per-frame work (see the phase note below), and no Rapier
46
46
  * objects: the bodies it edits belong to `<Physics>`.
47
- * SHARERS: every reader of `game.systemAdapters.physics` — the dev menu's
47
+ * SHARERS: every reader of `game.systemAdapters.physics` — the
48
48
  * colliders instrument, the editor's transform coordination. They read; they
49
49
  * never dispose.
50
50
  * TEARDOWN: the effect's cleanup, and nothing else — it clears the SAME key it
@@ -55,7 +55,7 @@
55
55
  *
56
56
  * PHASE ORDERING: none to respect — this component registers pull-only
57
57
  * callbacks and runs no per-frame work. Every method it exposes is invoked
58
- * BETWEEN frames, by an editor gesture or a dev-menu command, never from a
58
+ * BETWEEN frames, by an editor gesture or an instrument command, never from a
59
59
  * phase.
60
60
  */
61
61
  import { useRapier } from '@react-three/rapier';
@@ -128,6 +128,49 @@ export interface R3FRootRuntime {
128
128
  * react-door registrations are untouched when a Game hosts this world). */
129
129
  dispose(): void;
130
130
  }
131
+ /**
132
+ * The GAME-SCOPED input wiring one three root owns — and the half that has
133
+ * nothing to do with the vgai runtime context.
134
+ *
135
+ * Two things happen here, both of them HOST work performed from outside the
136
+ * world's own tree:
137
+ *
138
+ * 1. the project's input map is loaded through `Game.loadInputMap` (game-owned,
139
+ * load-once), so the actions the project declared exist;
140
+ * 2. this root's seams are registered on the game-scoped debug registry
141
+ * (`setVirtualInputTarget`/`setInputActionsSource`/`setInputTraceSource`),
142
+ * which is what makes `game.input.hold/tap/...` (the bot/`vgai eval` input
143
+ * doctrine) and the built-in `input.actions`/`input.trace` providers
144
+ * resolve to this world instead of throwing `DEBUG_INPUT_UNAVAILABLE`.
145
+ *
146
+ * It is called on BOTH three-root paths, and that is the point: a world that
147
+ * mounts as a default-exported component receives no vgai runtime context
148
+ * (`engineRuntime: false` — see `r3f-root-factory.tsx`), but "no context in the
149
+ * tree" was never meant to say "the host does not wire this game's input". It
150
+ * was read that way, and the cost was measured on a fresh scaffold: the
151
+ * declared map never loaded and every `game.input.*` door threw, so the QA
152
+ * bot, autoplay routes and `vgai eval` could not drive the ONE world shape
153
+ * `vgai create` produces. Same split, same reasoning, as `WorldProvider`
154
+ * riding `host.game` rather than the runtime (see `r3f-adapter.tsx`).
155
+ *
156
+ * `optionalInputMap` is the CONVENTIONAL-PATH probe used when the project
157
+ * never named a map: an absent file is the ordinary state of a brand-new
158
+ * project, so it resolves quietly instead of printing an error on every boot.
159
+ * A map that exists and fails to parse is as loud as ever.
160
+ *
161
+ * LIFETIME, honestly: `registry.strip(id)` runs on the mount's dispose (both
162
+ * paths), but it walks providers/commands only — the three seams set here
163
+ * survive it, keyed by this world's id, until a remount of the same id
164
+ * overwrites them. That residue is inert rather than hidden: every closure
165
+ * below reads GAME-scoped state (`game.input`, `game.loop.fixedDt`, the game's
166
+ * seed), so a stale entry actuates exactly what a live one would. See the
167
+ * dispose comment in `r3f-adapter.tsx` for the full accounting.
168
+ */
169
+ export declare function wireGameInputSeams(host: ThreeHostContext, registry: DebugRegistry, options: {
170
+ readonly id: string;
171
+ readonly inputMapPath?: string | null | undefined;
172
+ readonly optionalInputMap?: boolean | undefined;
173
+ }): Promise<void>;
131
174
  /**
132
175
  * Build the engine runtime for one R3F world from a `ThreeHostContext` — the same
133
176
  * wiring, at the same layer, as the classic `SetupThreeRootAdapter.mount()`
@@ -1 +1 @@
1
- {"version":3,"file":"world-context.d.ts","sourceRoot":"","sources":["../../src/world3d-react/world-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAmCK;AAEL,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AACpC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAOhE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,EAEL,KAAK,aAAa,EAEnB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE1E;iFACiF;AACjF,eAAO,MAAM,sBAAsB,qCAAqC,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,MAAM,cAAc,GAAG,oBAAoB,GAC/C,IAAI,CAAC,WAAW,EAAE,OAAO,GAAG,YAAY,GAAG,QAAQ,GAAG,OAAO,CAAC,GAAG;IAC/D,qEAAqE;IACrE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC;CACtB,CAAC;AAEJ,MAAM,WAAW,qBAAqB;IACpC;gF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,EACvB,OAAO,EAAE;IACP,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAClD,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACjD,GACA,OAAO,CAAC,IAAI,CAAC,CAiDf;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,gBAAgB,EACtB,OAAO,EAAE,qBAAqB,GAC7B,cAAc,CAqGhB"}
@@ -43,6 +43,92 @@ import { disposeDebrisSubtree } from '../runtime/game';
43
43
  /** The classic adapter's default input-map path — the conventional location
44
44
  * every scaffolded project ships (`public/inputmaps/default.inputmap.json`). */
45
45
  export const DEFAULT_INPUT_MAP_PATH = '/inputmaps/default.inputmap.json';
46
+ /**
47
+ * The GAME-SCOPED input wiring one three root owns — and the half that has
48
+ * nothing to do with the vgai runtime context.
49
+ *
50
+ * Two things happen here, both of them HOST work performed from outside the
51
+ * world's own tree:
52
+ *
53
+ * 1. the project's input map is loaded through `Game.loadInputMap` (game-owned,
54
+ * load-once), so the actions the project declared exist;
55
+ * 2. this root's seams are registered on the game-scoped debug registry
56
+ * (`setVirtualInputTarget`/`setInputActionsSource`/`setInputTraceSource`),
57
+ * which is what makes `game.input.hold/tap/...` (the bot/`vgai eval` input
58
+ * doctrine) and the built-in `input.actions`/`input.trace` providers
59
+ * resolve to this world instead of throwing `DEBUG_INPUT_UNAVAILABLE`.
60
+ *
61
+ * It is called on BOTH three-root paths, and that is the point: a world that
62
+ * mounts as a default-exported component receives no vgai runtime context
63
+ * (`engineRuntime: false` — see `r3f-root-factory.tsx`), but "no context in the
64
+ * tree" was never meant to say "the host does not wire this game's input". It
65
+ * was read that way, and the cost was measured on a fresh scaffold: the
66
+ * declared map never loaded and every `game.input.*` door threw, so the QA
67
+ * bot, autoplay routes and `vgai eval` could not drive the ONE world shape
68
+ * `vgai create` produces. Same split, same reasoning, as `WorldProvider`
69
+ * riding `host.game` rather than the runtime (see `r3f-adapter.tsx`).
70
+ *
71
+ * `optionalInputMap` is the CONVENTIONAL-PATH probe used when the project
72
+ * never named a map: an absent file is the ordinary state of a brand-new
73
+ * project, so it resolves quietly instead of printing an error on every boot.
74
+ * A map that exists and fails to parse is as loud as ever.
75
+ *
76
+ * LIFETIME, honestly: `registry.strip(id)` runs on the mount's dispose (both
77
+ * paths), but it walks providers/commands only — the three seams set here
78
+ * survive it, keyed by this world's id, until a remount of the same id
79
+ * overwrites them. That residue is inert rather than hidden: every closure
80
+ * below reads GAME-scoped state (`game.input`, `game.loop.fixedDt`, the game's
81
+ * seed), so a stale entry actuates exactly what a live one would. See the
82
+ * dispose comment in `r3f-adapter.tsx` for the full accounting.
83
+ */
84
+ export function wireGameInputSeams(host, registry, options) {
85
+ const { id, inputMapPath = DEFAULT_INPUT_MAP_PATH, optionalInputMap = false } = options;
86
+ if (!host.game)
87
+ return Promise.resolve();
88
+ const game = host.game;
89
+ const input = game.input;
90
+ registry.setInputActionsSource(id, () => input.actionNames().map((name) => ({ name, valueType: input.getActionValueType(name) })));
91
+ registry.setInputTraceSource(id, () => {
92
+ const raw = input.getInputTrace();
93
+ return {
94
+ version: raw.version,
95
+ seed: getSeededRandom(game)?.seed ?? null,
96
+ fixedDt: game.loop.fixedDt,
97
+ ticks: raw.ticks,
98
+ };
99
+ });
100
+ registry.setVirtualInputTarget(id, {
101
+ setVirtualAction: (action, value) => input.setVirtualAction(action, value),
102
+ tapVirtualAction: (action) => input.tapVirtualAction(action),
103
+ clearVirtualActions: () => input.clearVirtualActions(),
104
+ scheduleActionAtTick: (tick, action, value) => input.scheduleActionAtTick(tick, action, value),
105
+ startInputRecording: () => input.startInputRecording(),
106
+ stopInputRecording: () => input.stopInputRecording(),
107
+ isInputRecording: () => input.isInputRecording(),
108
+ injectAxis: (sourceId, value) => input.injectAxis(sourceId, value),
109
+ injectVector2: (sourceId, value) => input.injectVector2(sourceId, value),
110
+ injectPointerDelta: (sourceId, delta) => input.injectPointerDelta(sourceId, delta),
111
+ injectPointerPosition: (sourceId, value) => input.injectPointerPosition(sourceId, value),
112
+ });
113
+ if (host.headless || inputMapPath === null)
114
+ return Promise.resolve();
115
+ // Load-once through the game-owned path (competing paths across roots throw
116
+ // THERE, loudly). A FAILED load (missing/bad file) must not fail the mount:
117
+ // a three world with no declared actions is legal. It degrades loudly
118
+ // instead — naming exactly what breaks.
119
+ // The non-optional call passes ONE argument, exactly as it always has — a
120
+ // trailing `undefined` is a different call to any observer of it.
121
+ const load = optionalInputMap
122
+ ? game.loadInputMap(inputMapPath, { optional: true })
123
+ : game.loadInputMap(inputMapPath);
124
+ return load.catch((err) => {
125
+ // biome-ignore lint/suspicious/noConsole: deliberate loud degrade — the documented alternative to failing the mount (see comment above)
126
+ console.error(`three world "${id}": failed to load input map "${inputMapPath}" — declared input ` +
127
+ 'actions and `game.input.*` (bot/virtual input) will not work until a valid map ' +
128
+ 'loads. Ship one at the conventional path or pass `inputMapPath` to ' +
129
+ `createR3FAdapter (null to opt out). Cause: ${err instanceof Error ? err.message : String(err)}`);
130
+ });
131
+ }
46
132
  /**
47
133
  * Build the engine runtime for one R3F world from a `ThreeHostContext` — the same
48
134
  * wiring, at the same layer, as the classic `SetupThreeRootAdapter.mount()`
@@ -101,52 +187,9 @@ export function createR3FRootContext(host, options) {
101
187
  const gameClock = host.game ? getSimClock(host.game) : null;
102
188
  const clock = gameClock ?? createSimClock({ dispose: (obj) => disposeDebrisSubtree(obj, []) });
103
189
  ctx.clock = clock;
104
- // --- ctx.input + the debug-registry input seams (gap 3) — the game-owned
105
- // InputManager, polled by the game-scoped runner each frame; this world
106
- // registers the SAME per-world seams the classic adapter registers so
107
- // `game.input.*` (virtual input) and the built-in `input.actions`/
108
- // `input.trace` providers resolve to it. ---
109
- let inputMapReady = Promise.resolve();
110
- if (host.game) {
111
- const game = host.game;
112
- const input = game.input;
113
- debugRegistry.setInputActionsSource(id, () => input.actionNames().map((name) => ({ name, valueType: input.getActionValueType(name) })));
114
- debugRegistry.setInputTraceSource(id, () => {
115
- const raw = input.getInputTrace();
116
- return {
117
- version: raw.version,
118
- seed: getSeededRandom(game)?.seed ?? null,
119
- fixedDt: game.loop.fixedDt,
120
- ticks: raw.ticks,
121
- };
122
- });
123
- debugRegistry.setVirtualInputTarget(id, {
124
- setVirtualAction: (action, value) => input.setVirtualAction(action, value),
125
- tapVirtualAction: (action) => input.tapVirtualAction(action),
126
- clearVirtualActions: () => input.clearVirtualActions(),
127
- scheduleActionAtTick: (tick, action, value) => input.scheduleActionAtTick(tick, action, value),
128
- startInputRecording: () => input.startInputRecording(),
129
- stopInputRecording: () => input.stopInputRecording(),
130
- isInputRecording: () => input.isInputRecording(),
131
- injectAxis: (sourceId, value) => input.injectAxis(sourceId, value),
132
- injectVector2: (sourceId, value) => input.injectVector2(sourceId, value),
133
- injectPointerDelta: (sourceId, delta) => input.injectPointerDelta(sourceId, delta),
134
- injectPointerPosition: (sourceId, value) => input.injectPointerPosition(sourceId, value),
135
- });
136
- if (!host.headless && inputMapPath !== null) {
137
- // Load-once through the game-owned path (classic parity — competing
138
- // paths across roots throw THERE, loudly). A FAILED load (missing/bad
139
- // file) must not fail this mount: an R3F tree with no declared actions
140
- // is legal. It degrades loudly instead — naming exactly what breaks.
141
- inputMapReady = game.loadInputMap(inputMapPath).catch((err) => {
142
- // biome-ignore lint/suspicious/noConsole: deliberate loud degrade — the documented alternative to failing the mount (see comment above)
143
- console.error(`R3F world "${id}": failed to load input map "${inputMapPath}" — declared input ` +
144
- 'actions and `game.input.*` (bot/virtual input) will not work until a valid map ' +
145
- 'loads. Ship one at the conventional path or pass `inputMapPath` to ' +
146
- `createR3FAdapter (null to opt out). Cause: ${err instanceof Error ? err.message : String(err)}`);
147
- });
148
- }
149
- }
190
+ // --- ctx.input + the debug-registry input seams (gap 3) — see
191
+ // `wireGameInputSeams` below; `ctx.input` is that same game-owned manager. ---
192
+ const inputMapReady = wireGameInputSeams(host, debugRegistry, { id, inputMapPath });
150
193
  return {
151
194
  ctx,
152
195
  systems,