@vgai/engine 0.5.21 → 0.5.23

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 (339) hide show
  1. package/README.md +6 -3
  2. package/dist/adapter/adapter-module.d.ts.map +1 -1
  3. package/dist/adapter/adapter-module.js +2 -4
  4. package/dist/adapter/adapter-surface.d.ts +1 -1
  5. package/dist/adapter/adapter-surface.js +1 -1
  6. package/dist/adapter/authoring.d.ts +19 -21
  7. package/dist/adapter/authoring.d.ts.map +1 -1
  8. package/dist/adapter/authoring.js +2 -2
  9. package/dist/adapter/binding.d.ts +341 -0
  10. package/dist/adapter/binding.d.ts.map +1 -0
  11. package/dist/adapter/binding.js +148 -0
  12. package/dist/adapter/colyseus-networking-adapter.d.ts.map +1 -1
  13. package/dist/adapter/colyseus-networking-adapter.js +23 -4
  14. package/dist/adapter/entrypoint-selection-readers.d.ts +24 -0
  15. package/dist/adapter/entrypoint-selection-readers.d.ts.map +1 -0
  16. package/dist/adapter/entrypoint-selection-readers.js +63 -0
  17. package/dist/adapter/entrypoint-selection-source.d.ts.map +1 -1
  18. package/dist/adapter/entrypoint-selection-source.js +1 -44
  19. package/dist/adapter/finders/scenes-from-entrypoint-selection.d.ts.map +1 -1
  20. package/dist/adapter/finders/scenes-from-entrypoint-selection.js +1 -52
  21. package/dist/adapter/host-context.d.ts +46 -15
  22. package/dist/adapter/host-context.d.ts.map +1 -1
  23. package/dist/adapter/host-context.js +2 -9
  24. package/dist/adapter/index.d.ts +11 -12
  25. package/dist/adapter/index.d.ts.map +1 -1
  26. package/dist/adapter/index.js +9 -10
  27. package/dist/adapter/ingest/game-contract.d.ts +0 -3
  28. package/dist/adapter/ingest/game-contract.d.ts.map +1 -1
  29. package/dist/adapter/ingest/game-contract.js +0 -3
  30. package/dist/adapter/ingest/scene-capture.d.ts +19 -23
  31. package/dist/adapter/ingest/scene-capture.d.ts.map +1 -1
  32. package/dist/adapter/ingest/scene-capture.js +143 -17
  33. package/dist/adapter/ingest/visible-capture-window.d.ts +34 -0
  34. package/dist/adapter/ingest/visible-capture-window.d.ts.map +1 -1
  35. package/dist/adapter/manifest-interpreter.d.ts +59 -0
  36. package/dist/adapter/manifest-interpreter.d.ts.map +1 -0
  37. package/dist/adapter/manifest-interpreter.js +50 -0
  38. package/dist/adapter/native-debug-module.d.ts +71 -3
  39. package/dist/adapter/native-debug-module.d.ts.map +1 -1
  40. package/dist/adapter/native-debug-module.js +146 -10
  41. package/dist/adapter/rapier-physics-adapter.d.ts +31 -1
  42. package/dist/adapter/rapier-physics-adapter.d.ts.map +1 -1
  43. package/dist/adapter/rapier-physics-adapter.js +50 -36
  44. package/dist/adapter/renderer-config.d.ts +3 -3
  45. package/dist/adapter/renderer-config.js +3 -3
  46. package/dist/adapter/root-adapter.d.ts +7 -7
  47. package/dist/adapter/root-adapter.js +4 -4
  48. package/dist/adapter/system-adapter.d.ts +45 -7
  49. package/dist/adapter/system-adapter.d.ts.map +1 -1
  50. package/dist/adapter/system-seam-contract.d.ts +3 -3
  51. package/dist/adapter/system-seam-contract.js +3 -3
  52. package/dist/adapter/system-slot.d.ts +168 -0
  53. package/dist/adapter/system-slot.d.ts.map +1 -0
  54. package/dist/adapter/system-slot.js +229 -0
  55. package/dist/adapter/transform.d.ts +11 -1
  56. package/dist/adapter/transform.d.ts.map +1 -1
  57. package/dist/ai/navigation.d.ts +17 -1
  58. package/dist/ai/navigation.d.ts.map +1 -1
  59. package/dist/ai/navigation.js +26 -5
  60. package/dist/animation/anim-graph-types.d.ts +11 -3
  61. package/dist/animation/anim-graph-types.d.ts.map +1 -1
  62. package/dist/animation/theatre-clock-binding.d.ts +4 -4
  63. package/dist/animation/theatre-clock-binding.js +4 -4
  64. package/dist/animation/xstate-animation-binding.d.ts.map +1 -1
  65. package/dist/animation/xstate-animation-binding.js +2 -2
  66. package/dist/animation/xstate-animation-meta.d.ts +13 -0
  67. package/dist/animation/xstate-animation-meta.d.ts.map +1 -1
  68. package/dist/animation/xstate-animation-meta.js +14 -0
  69. package/dist/asset-formats/index.d.ts +4 -7
  70. package/dist/asset-formats/index.d.ts.map +1 -1
  71. package/dist/asset-formats/index.js +4 -7
  72. package/dist/asset-formats/render-env.d.ts +5 -8
  73. package/dist/asset-formats/render-env.d.ts.map +1 -1
  74. package/dist/asset-formats/render-env.js +3 -6
  75. package/dist/asset-parse-error.d.ts +2 -5
  76. package/dist/asset-parse-error.d.ts.map +1 -1
  77. package/dist/asset-parse-error.js +2 -5
  78. package/dist/audio/bus-mixer.d.ts +101 -0
  79. package/dist/audio/bus-mixer.d.ts.map +1 -0
  80. package/dist/audio/bus-mixer.js +115 -0
  81. package/dist/canvas-react/index.d.ts +5 -12
  82. package/dist/canvas-react/index.d.ts.map +1 -1
  83. package/dist/canvas-react/index.js +5 -12
  84. package/dist/canvas-react/pixi-react-root-factory.d.ts +34 -21
  85. package/dist/canvas-react/pixi-react-root-factory.d.ts.map +1 -1
  86. package/dist/canvas-react/pixi-react-root-factory.js +274 -36
  87. package/dist/core/countdown-timer.d.ts +118 -0
  88. package/dist/core/countdown-timer.d.ts.map +1 -0
  89. package/dist/core/countdown-timer.js +137 -0
  90. package/dist/core/deferred-commands.d.ts +127 -0
  91. package/dist/core/deferred-commands.d.ts.map +1 -0
  92. package/dist/core/deferred-commands.js +132 -0
  93. package/dist/core/frame-pacing.d.ts +1 -1
  94. package/dist/core/frame-pacing.js +2 -2
  95. package/dist/core/game-loop.d.ts +1 -3
  96. package/dist/core/game-loop.d.ts.map +1 -1
  97. package/dist/core/game-loop.js +1 -3
  98. package/dist/core/seeded-random.d.ts +1 -1
  99. package/dist/core/sim-clock.d.ts +19 -8
  100. package/dist/core/sim-clock.d.ts.map +1 -1
  101. package/dist/core/sim-clock.js +18 -7
  102. package/dist/core/types.d.ts +1 -3
  103. package/dist/core/types.d.ts.map +1 -1
  104. package/dist/defaults.d.ts +6 -14
  105. package/dist/defaults.d.ts.map +1 -1
  106. package/dist/defaults.js +6 -14
  107. package/dist/dev/instruments.d.ts +38 -11
  108. package/dist/dev/instruments.d.ts.map +1 -1
  109. package/dist/dev/instruments.js +81 -11
  110. package/dist/dev/register-render-vitals.d.ts +1 -4
  111. package/dist/dev/register-render-vitals.d.ts.map +1 -1
  112. package/dist/dev/register-render-vitals.js +1 -4
  113. package/dist/dev/render-debug-adapter.d.ts +2 -3
  114. package/dist/dev/render-debug-adapter.d.ts.map +1 -1
  115. package/dist/dev/render-debug-adapter.js +2 -3
  116. package/dist/dev/render-vitals.d.ts +3 -3
  117. package/dist/dev/render-vitals.js +3 -3
  118. package/dist/dev/webgl-frame-capture.d.ts +1 -1
  119. package/dist/dev/webgl-frame-capture.js +1 -1
  120. package/dist/index.d.ts +2 -5
  121. package/dist/index.d.ts.map +1 -1
  122. package/dist/index.js +2 -4
  123. package/dist/input/host-pointer.d.ts +122 -0
  124. package/dist/input/host-pointer.d.ts.map +1 -0
  125. package/dist/input/host-pointer.js +160 -0
  126. package/dist/input/input-manager.d.ts +33 -5
  127. package/dist/input/input-manager.d.ts.map +1 -1
  128. package/dist/input/input-manager.js +48 -13
  129. package/dist/input/rebind-controller.d.ts.map +1 -1
  130. package/dist/input/rebind-controller.js +6 -8
  131. package/dist/input/schema.d.ts.map +1 -1
  132. package/dist/input/schema.js +56 -28
  133. package/dist/manifest/filename.d.ts.map +1 -1
  134. package/dist/manifest/filename.js +8 -12
  135. package/dist/manifest/load.d.ts +10 -10
  136. package/dist/manifest/load.d.ts.map +1 -1
  137. package/dist/manifest/load.js +9 -6
  138. package/dist/manifest/schema.d.ts +17 -21
  139. package/dist/manifest/schema.d.ts.map +1 -1
  140. package/dist/manifest/schema.js +45 -35
  141. package/dist/physics/collider-dimensions.d.ts +8 -12
  142. package/dist/physics/collider-dimensions.d.ts.map +1 -1
  143. package/dist/physics/collider-dimensions.js +8 -12
  144. package/dist/pixi/scene-capture.d.ts +11 -13
  145. package/dist/pixi/scene-capture.d.ts.map +1 -1
  146. package/dist/react/world-state.d.ts +1 -1
  147. package/dist/react/world-state.d.ts.map +1 -1
  148. package/dist/render/directional-shadow-fit.d.ts +88 -0
  149. package/dist/render/directional-shadow-fit.d.ts.map +1 -0
  150. package/dist/render/directional-shadow-fit.js +133 -0
  151. package/dist/render/environment-capture.d.ts +68 -0
  152. package/dist/render/environment-capture.d.ts.map +1 -0
  153. package/dist/render/environment-capture.js +90 -0
  154. package/dist/render/ibl-override-material.d.ts +97 -0
  155. package/dist/render/ibl-override-material.d.ts.map +1 -0
  156. package/dist/render/ibl-override-material.js +114 -0
  157. package/dist/render/light-camera-factory.d.ts +5 -7
  158. package/dist/render/light-camera-factory.d.ts.map +1 -1
  159. package/dist/render/light-camera-factory.js +8 -11
  160. package/dist/render/material-factory.js +1 -1
  161. package/dist/render/render-batch-system.d.ts.map +1 -1
  162. package/dist/render/render-features.d.ts +17 -6
  163. package/dist/render/render-features.d.ts.map +1 -1
  164. package/dist/render/render-features.js +0 -28
  165. package/dist/runtime/create-runtime.d.ts +34 -25
  166. package/dist/runtime/create-runtime.d.ts.map +1 -1
  167. package/dist/runtime/create-runtime.js +218 -93
  168. package/dist/runtime/debug-registry.d.ts +77 -8
  169. package/dist/runtime/debug-registry.d.ts.map +1 -1
  170. package/dist/runtime/debug-registry.js +3 -3
  171. package/dist/runtime/dev-build.d.ts +2 -2
  172. package/dist/runtime/dev-build.js +2 -2
  173. package/dist/runtime/game-input-seams.d.ts +51 -0
  174. package/dist/runtime/game-input-seams.d.ts.map +1 -0
  175. package/dist/runtime/game-input-seams.js +86 -0
  176. package/dist/runtime/game.d.ts +104 -40
  177. package/dist/runtime/game.d.ts.map +1 -1
  178. package/dist/runtime/game.js +119 -61
  179. package/dist/runtime/mount-game.d.ts +0 -16
  180. package/dist/runtime/mount-game.d.ts.map +1 -1
  181. package/dist/runtime/mount-game.js +26 -41
  182. package/dist/runtime/mount-manifest.d.ts +22 -14
  183. package/dist/runtime/mount-manifest.d.ts.map +1 -1
  184. package/dist/runtime/mount-manifest.js +22 -20
  185. package/dist/runtime/playtest.d.ts +22 -0
  186. package/dist/runtime/playtest.d.ts.map +1 -0
  187. package/dist/runtime/playtest.js +12 -0
  188. package/dist/runtime/state-bridge.d.ts +2 -3
  189. package/dist/runtime/state-bridge.d.ts.map +1 -1
  190. package/dist/runtime/state-bridge.js +1 -0
  191. package/dist/setup/setup-audio.d.ts +12 -0
  192. package/dist/setup/setup-audio.d.ts.map +1 -1
  193. package/dist/setup/setup-audio.js +9 -10
  194. package/dist/setup/setup-renderer.d.ts +2 -25
  195. package/dist/setup/setup-renderer.d.ts.map +1 -1
  196. package/dist/setup/setup-renderer.js +2 -31
  197. package/dist/world3d-react/index.d.ts +15 -25
  198. package/dist/world3d-react/index.d.ts.map +1 -1
  199. package/dist/world3d-react/index.js +15 -25
  200. package/dist/world3d-react/r3f-root-factory.d.ts +28 -34
  201. package/dist/world3d-react/r3f-root-factory.d.ts.map +1 -1
  202. package/dist/world3d-react/r3f-root-factory.js +403 -57
  203. package/dist/world3d-react/rapier-physics-bridge.d.ts +30 -17
  204. package/dist/world3d-react/rapier-physics-bridge.d.ts.map +1 -1
  205. package/dist/world3d-react/rapier-physics-bridge.js +143 -58
  206. package/package.json +1 -1
  207. package/schemas/engine-capabilities.json +16 -14
  208. package/schemas/vgai-project.schema.json +35 -26
  209. package/src/adapter/adapter-module.ts +2 -4
  210. package/src/adapter/adapter-surface.ts +1 -1
  211. package/src/adapter/authoring.ts +19 -21
  212. package/src/adapter/binding.ts +468 -0
  213. package/src/adapter/colyseus-networking-adapter.ts +20 -5
  214. package/src/adapter/entrypoint-selection-readers.ts +66 -0
  215. package/src/adapter/entrypoint-selection-source.ts +1 -40
  216. package/src/adapter/finders/scenes-from-entrypoint-selection.ts +1 -48
  217. package/src/adapter/host-context.ts +45 -15
  218. package/src/adapter/index.ts +23 -11
  219. package/src/adapter/ingest/game-contract.ts +0 -3
  220. package/src/adapter/ingest/scene-capture.ts +190 -39
  221. package/src/adapter/ingest/visible-capture-window.ts +35 -0
  222. package/src/adapter/manifest-interpreter.ts +64 -0
  223. package/src/adapter/native-debug-module.ts +248 -15
  224. package/src/adapter/rapier-physics-adapter.ts +76 -20
  225. package/src/adapter/renderer-config.ts +3 -3
  226. package/src/adapter/root-adapter.ts +7 -7
  227. package/src/adapter/system-adapter.ts +43 -8
  228. package/src/adapter/system-seam-contract.ts +3 -3
  229. package/src/adapter/system-slot.ts +291 -0
  230. package/src/adapter/transform.ts +18 -1
  231. package/src/ai/navigation.ts +30 -3
  232. package/src/animation/anim-graph-types.ts +11 -3
  233. package/src/animation/theatre-clock-binding.ts +4 -4
  234. package/src/animation/xstate-animation-binding.ts +2 -2
  235. package/src/animation/xstate-animation-meta.ts +16 -0
  236. package/src/asset-formats/index.ts +4 -7
  237. package/src/asset-formats/render-env.ts +3 -6
  238. package/src/asset-parse-error.ts +2 -5
  239. package/src/audio/bus-mixer.ts +161 -0
  240. package/src/canvas-react/index.ts +5 -21
  241. package/src/canvas-react/pixi-react-root-factory.tsx +301 -39
  242. package/src/core/countdown-timer.ts +188 -0
  243. package/src/core/deferred-commands.ts +174 -0
  244. package/src/core/frame-pacing.ts +2 -2
  245. package/src/core/game-loop.ts +1 -3
  246. package/src/core/seeded-random.ts +1 -1
  247. package/src/core/sim-clock.ts +19 -8
  248. package/src/core/types.ts +1 -3
  249. package/src/defaults.ts +6 -14
  250. package/src/dev/instruments.ts +108 -11
  251. package/src/dev/register-render-vitals.ts +1 -4
  252. package/src/dev/render-debug-adapter.ts +2 -3
  253. package/src/dev/render-vitals.ts +3 -3
  254. package/src/dev/webgl-frame-capture.ts +1 -1
  255. package/src/index.ts +2 -5
  256. package/src/input/host-pointer.ts +230 -0
  257. package/src/input/input-manager.ts +49 -13
  258. package/src/input/input-types.ts +1 -1
  259. package/src/input/rebind-controller.ts +6 -8
  260. package/src/input/schema.ts +216 -188
  261. package/src/manifest/filename.ts +8 -12
  262. package/src/manifest/load.ts +17 -13
  263. package/src/manifest/schema.ts +55 -47
  264. package/src/physics/collider-dimensions.ts +8 -12
  265. package/src/pixi/scene-capture.ts +12 -15
  266. package/src/react/world-state.tsx +1 -1
  267. package/src/render/directional-shadow-fit.ts +156 -0
  268. package/src/render/environment-capture.ts +102 -0
  269. package/src/render/ibl-override-material.ts +170 -0
  270. package/src/render/light-camera-factory.ts +8 -11
  271. package/src/render/material-factory.ts +1 -1
  272. package/src/render/render-batch-system.ts +14 -6
  273. package/src/render/render-features.ts +17 -35
  274. package/src/runtime/create-runtime.ts +270 -108
  275. package/src/runtime/debug-registry.ts +84 -8
  276. package/src/runtime/dev-build.ts +2 -2
  277. package/src/runtime/game-input-seams.ts +108 -0
  278. package/src/runtime/game.ts +231 -85
  279. package/src/runtime/mount-game.ts +31 -57
  280. package/src/runtime/mount-manifest.ts +47 -36
  281. package/src/runtime/playtest.ts +22 -0
  282. package/src/runtime/state-bridge.ts +3 -3
  283. package/src/setup/setup-audio.ts +21 -11
  284. package/src/setup/setup-renderer.ts +2 -61
  285. package/src/world3d-react/index.ts +15 -31
  286. package/src/world3d-react/r3f-root-factory.tsx +451 -60
  287. package/src/world3d-react/rapier-physics-bridge.tsx +154 -58
  288. package/dist/adapter/setup-three-root-adapter.d.ts +0 -86
  289. package/dist/adapter/setup-three-root-adapter.d.ts.map +0 -1
  290. package/dist/adapter/setup-three-root-adapter.js +0 -908
  291. package/dist/animation/clip-map.d.ts +0 -12
  292. package/dist/animation/clip-map.d.ts.map +0 -1
  293. package/dist/animation/clip-map.js +0 -31
  294. package/dist/asset-registry.d.ts +0 -38
  295. package/dist/asset-registry.d.ts.map +0 -1
  296. package/dist/asset-registry.js +0 -66
  297. package/dist/canvas-react/engine-bridge.d.ts +0 -45
  298. package/dist/canvas-react/engine-bridge.d.ts.map +0 -1
  299. package/dist/canvas-react/engine-bridge.js +0 -45
  300. package/dist/canvas-react/pixi-react-adapter.d.ts +0 -77
  301. package/dist/canvas-react/pixi-react-adapter.d.ts.map +0 -1
  302. package/dist/canvas-react/pixi-react-adapter.js +0 -294
  303. package/dist/canvas-react/world-context.d.ts +0 -98
  304. package/dist/canvas-react/world-context.d.ts.map +0 -1
  305. package/dist/canvas-react/world-context.js +0 -173
  306. package/dist/dev/debug-draw.d.ts +0 -24
  307. package/dist/dev/debug-draw.d.ts.map +0 -1
  308. package/dist/dev/debug-draw.js +0 -73
  309. package/dist/render/auto-batcher.d.ts +0 -34
  310. package/dist/render/auto-batcher.d.ts.map +0 -1
  311. package/dist/render/auto-batcher.js +0 -140
  312. package/dist/render/lod.d.ts +0 -13
  313. package/dist/render/lod.d.ts.map +0 -1
  314. package/dist/render/lod.js +0 -16
  315. package/dist/runtime/types.d.ts +0 -303
  316. package/dist/runtime/types.d.ts.map +0 -1
  317. package/dist/runtime/types.js +0 -1
  318. package/dist/world3d-react/engine-bridge.d.ts +0 -47
  319. package/dist/world3d-react/engine-bridge.d.ts.map +0 -1
  320. package/dist/world3d-react/engine-bridge.js +0 -73
  321. package/dist/world3d-react/r3f-adapter.d.ts +0 -58
  322. package/dist/world3d-react/r3f-adapter.d.ts.map +0 -1
  323. package/dist/world3d-react/r3f-adapter.js +0 -634
  324. package/dist/world3d-react/world-context.d.ts +0 -182
  325. package/dist/world3d-react/world-context.d.ts.map +0 -1
  326. package/dist/world3d-react/world-context.js +0 -235
  327. package/src/adapter/setup-three-root-adapter.ts +0 -1032
  328. package/src/animation/clip-map.ts +0 -34
  329. package/src/asset-registry.ts +0 -89
  330. package/src/canvas-react/engine-bridge.ts +0 -59
  331. package/src/canvas-react/pixi-react-adapter.tsx +0 -356
  332. package/src/canvas-react/world-context.ts +0 -253
  333. package/src/dev/debug-draw.ts +0 -80
  334. package/src/render/auto-batcher.ts +0 -168
  335. package/src/render/lod.ts +0 -17
  336. package/src/runtime/types.ts +0 -328
  337. package/src/world3d-react/engine-bridge.ts +0 -86
  338. package/src/world3d-react/r3f-adapter.tsx +0 -717
  339. package/src/world3d-react/world-context.ts +0 -358
@@ -1,253 +0,0 @@
1
- /**
2
- * `createCanvasRootContext` — the ENGINE runtime a canvas world owns, split out
3
- * of `./pixi-react-adapter.tsx` so it stays react-free and headlessly
4
- * unit-testable (`test/canvas-react-context-parity.test.tsx`).
5
- *
6
- * This is the canvas surface's answer to the same question
7
- * `world3d-react/world-context.ts` answers for three: what does a component
8
- * inside the world tree reach when it asks the engine for something?
9
- *
10
- * 1. **`ctx.debug` / `ctx.random` / `ctx.game` / `ctx.roots` are wired** from
11
- * the ONE game-scoped registry (`getDebugRegistry(host.game)`), so a
12
- * component's effect can `ctx.debug.registerStateProvider(...)` and be
13
- * visible to `vgai eval`/the editor's debug panels.
14
- * 2. **`ctx.input` is the game-owned `InputManager` when a Game hosts the
15
- * root** (`host.game.input` — the
16
- * same instance every sibling root shares), and this module registers the
17
- * per-world debug-registry seams (`setVirtualInputTarget`/
18
- * `setInputActionsSource`/`setInputTraceSource`) that make `game.input.*`
19
- * (the bot-input doctrine) resolve instead of throwing
20
- * `DEBUG_INPUT_UNAVAILABLE`. The project's input map loads through
21
- * `Game.loadInputMap` (the game-owned, load-once path every root shares).
22
- * A missing/unparseable map degrades LOUDLY without failing the mount — a
23
- * canvas world with no declared actions is legal. A bare/foreign mount
24
- * receives `null`, visibly in the type, rather than a throwing getter.
25
- * 3. **Absent subsystems are absent from the type.** A canvas world builds no
26
- * THREE scene/camera, Rapier world, composer, first-party audio/particles/
27
- * debug-draw, or Three-flavoured `AssetCache`. Its explicit
28
- * {@link CanvasGameContext} cannot name those fields, so misuse fails at
29
- * the call site during typechecking instead of from a throwing getter at
30
- * runtime.
31
- *
32
- * The Pixi handles themselves are deliberately NOT re-exposed here: a component
33
- * reaches the live `Application` (and therefore `app.stage`, `app.renderer`,
34
- * `app.ticker`) through `@pixi/react`'s own `useApplication()`, and its assets
35
- * through Pixi's own `Assets`. Re-publishing them on `ctx` would be a wrapper
36
- * standing between the author and the library.
37
- */
38
-
39
- import type { Application } from 'pixi.js';
40
- import type { CanvasHostContext } from '../adapter';
41
- import type { SystemAdapters } from '../adapter/system-adapter';
42
- import {
43
- createSeededRandom,
44
- DEFAULT_SEEDED_RANDOM_SEED,
45
- getSeededRandom,
46
- } from '../core/seeded-random';
47
- import type { SimClock } from '../core/sim-clock';
48
- import { createSimClock, getSimClock, type SimClockInternal } from '../core/sim-clock';
49
- import { createSystemRunner } from '../core/system-runner';
50
- import {
51
- createDebugRegistry,
52
- type DebugRegistry,
53
- getDebugRegistry,
54
- } from '../runtime/debug-registry';
55
- import type { ComponentContextBase } from '../runtime/types';
56
-
57
- /** The conventional input-map location every scaffolded project ships. Shared
58
- * verbatim with the three lane — a project has ONE input map, whatever surface
59
- * reads it. */
60
- export const DEFAULT_INPUT_MAP_PATH = '/inputmaps/default.inputmap.json';
61
-
62
- export interface CanvasRootContextOptions {
63
- /** World id — provenance for every debug-registry registration (matches the
64
- * manifest root id). */
65
- readonly id: string;
66
- /**
67
- * Input map to load through `Game.loadInputMap` (game-owned, load-once —
68
- * several roots asking for the SAME path share one load; competing paths
69
- * throw there). Defaults to {@link DEFAULT_INPUT_MAP_PATH}. Pass `null` to
70
- * skip loading (a world with no actions). Ignored when no `host.game` is
71
- * present.
72
- */
73
- readonly inputMapPath?: string | null | undefined;
74
- }
75
-
76
- /** The engine services a Canvas component genuinely receives. Pixi's own
77
- * `useApplication()` and `Assets` remain the doors to rendering and assets.
78
- * `disposeAfter` is excluded because it accepts a `THREE.Object3D`; Canvas
79
- * code schedules `displayObject.destroy()` with `clock.after()` instead. */
80
- export type CanvasGameContext = ComponentContextBase & {
81
- readonly clock: Omit<SimClock, 'disposeAfter'>;
82
- };
83
-
84
- /** What {@link createCanvasRootContext} returns — the engine runtime one canvas
85
- * world owns, plus the wiring hooks the adapter's `mount()` drives. */
86
- export interface CanvasRootRuntime {
87
- /** The explicit Canvas context this world's components read through
88
- * `useGameContext`. See {@link CanvasGameContext}. */
89
- readonly ctx: CanvasGameContext;
90
- /** The world-local phase runner `mount().update(dt)` ticks. */
91
- readonly systems: ReturnType<typeof createSystemRunner>;
92
- /** The mounted world's `SystemAdapters` bag (`mounted.systems`) —
93
- * `ctx.registerSystemAdapter` writes into it; `debug` is pre-seeded. */
94
- readonly systemAdapters: SystemAdapters;
95
- /** Resolves once the input map load settles (immediately when skipped).
96
- * Never rejects — a failed load reports loudly and resolves. */
97
- readonly inputMapReady: Promise<void>;
98
- /** Backfill the live `Application` once `@pixi/react` has initialized it —
99
- * before any tick can run. Read back via {@link CanvasRootRuntime.app}. */
100
- setApplication(app: Application): void;
101
- /** The live `Application`, or `null` before the first commit resolves it. */
102
- readonly app: Application | null;
103
- /** Strip this world's debug registrations (scoped, so sibling roots and
104
- * react-door registrations are untouched when a Game hosts this world) and
105
- * dispose a clock this mount created. */
106
- dispose(): void;
107
- }
108
-
109
- /**
110
- * Build the engine runtime for one canvas world from a `CanvasHostContext`.
111
- * React-free on purpose: everything here is plain engine wiring the adapter
112
- * threads into the `@pixi/react` tree through `EngineBridge`.
113
- */
114
- export function createCanvasRootContext(
115
- host: CanvasHostContext,
116
- options: CanvasRootContextOptions,
117
- ): CanvasRootRuntime {
118
- const { id, inputMapPath = DEFAULT_INPUT_MAP_PATH } = options;
119
-
120
- // Same observer threading as the three lane — this world's phases show up
121
- // under the shared game profiler when hosted.
122
- const systems = createSystemRunner(host.game?.profiler.systemObserver, 'canvas');
123
-
124
- // The mounted world's adapter surface (`mounted.systems`) — declared before
125
- // ctx so `ctx.registerSystemAdapter` can close over it (a game-owned
126
- // capability like networking registers here from component code).
127
- const systemAdapters: SystemAdapters = {};
128
-
129
- let app: Application | null = null;
130
-
131
- const ctxRaw: Record<string, unknown> = {
132
- systems,
133
- input: host.game?.input ?? null,
134
- registerSystemAdapter: (kind: keyof SystemAdapters, adapter: SystemAdapters[typeof kind]) => {
135
- // biome-ignore lint/suspicious/noExplicitAny: same per-key record write the three lane performs; correct by construction
136
- (systemAdapters as any)[kind] = adapter;
137
- host.game?.notifySystemAdaptersChanged();
138
- },
139
- };
140
- const ctx = ctxRaw as unknown as CanvasGameContext;
141
- if (host.game) {
142
- ctx.game = host.game;
143
- ctx.roots = host.game.roots;
144
- ctx.playtest = host.game.playtest ?? null;
145
- }
146
-
147
- // --- ctx.debug — the ONE registry per Game root, shared across every world
148
- // mounted onto it; a bare mount with no Game shell gets a private,
149
- // mount-local registry instead. ---
150
- const debugRegistry: DebugRegistry =
151
- (host.game ? getDebugRegistry(host.game) : null) ??
152
- createDebugRegistry({ getTick: () => 0, getSimT: () => 0 });
153
- systemAdapters.debug = debugRegistry.adapter;
154
- ctx.debug = debugRegistry.forRoot(id);
155
- ctx.random =
156
- (host.game ? getSeededRandom(host.game) : null) ??
157
- createSeededRandom(DEFAULT_SEEDED_RANDOM_SEED);
158
-
159
- // --- ctx.clock — a REAL value, never a throwing getter: every world has a
160
- // sim clock. A bare mount with no Game shell gets a private, mount-local one.
161
- // `SimClock.disposeAfter` takes a THREE.Object3D, so the mount-local
162
- // fallback's disposer is a loud refusal rather than a fabricated no-op: a
163
- // canvas world's debris is a `PIXI.Container`, destroyed with its own
164
- // `container.destroy()`.
165
- const gameClock: SimClockInternal | null = host.game ? getSimClock(host.game) : null;
166
- const clock: SimClockInternal =
167
- gameClock ??
168
- createSimClock({
169
- dispose: () => {
170
- throw new Error(
171
- `canvas world "${id}": clock.disposeAfter() disposes a THREE.Object3D and has no ` +
172
- 'meaning in a canvas world — destroy a display object with its own ' +
173
- '`container.destroy({ children: true })`, scheduled with `clock.after(seconds, ...)`.',
174
- );
175
- },
176
- });
177
- ctxRaw['clock'] = clock;
178
-
179
- // --- ctx.input + the debug-registry input seams — the game-owned
180
- // InputManager, polled by the game-scoped runner each frame; this world
181
- // registers the per-world seams so `game.input.*` (virtual input) and the
182
- // built-in `input.actions`/`input.trace` providers resolve to it. ---
183
- let inputMapReady: Promise<void> = Promise.resolve();
184
- if (host.game) {
185
- const game = host.game;
186
- const input = game.input;
187
- debugRegistry.setInputActionsSource(id, () =>
188
- input.actionNames().map((name) => ({ name, valueType: input.getActionValueType(name) })),
189
- );
190
- debugRegistry.setInputTraceSource(id, () => {
191
- const raw = input.getInputTrace();
192
- return {
193
- version: raw.version,
194
- seed: getSeededRandom(game)?.seed ?? null,
195
- fixedDt: game.loop.fixedDt,
196
- ticks: raw.ticks,
197
- };
198
- });
199
- debugRegistry.setVirtualInputTarget(id, {
200
- setVirtualAction: (action, value) => input.setVirtualAction(action, value),
201
- tapVirtualAction: (action) => input.tapVirtualAction(action),
202
- clearVirtualActions: () => input.clearVirtualActions(),
203
- scheduleActionAtTick: (tick, action, value) =>
204
- input.scheduleActionAtTick(tick, action, value),
205
- startInputRecording: () => input.startInputRecording(),
206
- stopInputRecording: () => input.stopInputRecording(),
207
- isInputRecording: () => input.isInputRecording(),
208
- injectAxis: (sourceId, value) => input.injectAxis(sourceId, value),
209
- injectVector2: (sourceId, value) => input.injectVector2(sourceId, value),
210
- injectPointerDelta: (sourceId, delta) => input.injectPointerDelta(sourceId, delta),
211
- injectPointerPosition: (sourceId, value) => input.injectPointerPosition(sourceId, value),
212
- });
213
- if (!host.headless && inputMapPath !== null) {
214
- // Load-once through the game-owned path (competing paths across roots
215
- // throw THERE, loudly). A FAILED load must not fail this mount: a canvas
216
- // world with no declared actions is legal. It degrades loudly instead.
217
- inputMapReady = game.loadInputMap(inputMapPath).catch((err: unknown) => {
218
- // biome-ignore lint/suspicious/noConsole: deliberate loud degrade — the documented alternative to failing the mount
219
- console.error(
220
- `canvas world "${id}": failed to load input map "${inputMapPath}" — declared input ` +
221
- 'actions and `game.input.*` (bot/virtual input) will not work until a valid map ' +
222
- 'loads. Ship one at the conventional path or pass `inputMapPath` to ' +
223
- `createPixiReactAdapter (null to opt out). Cause: ${err instanceof Error ? err.message : String(err)}`,
224
- );
225
- });
226
- }
227
- }
228
-
229
- return {
230
- ctx,
231
- systems,
232
- systemAdapters,
233
- inputMapReady,
234
- get app(): Application | null {
235
- return app;
236
- },
237
- setApplication(next): void {
238
- app = next;
239
- },
240
- dispose(): void {
241
- // Same ownership rule the three lane follows: dispose ONLY a clock this
242
- // mount created. The game-scoped one belongs to `GameInternal.dispose()`
243
- // — killing it here would freeze sim time and cancel every SIBLING
244
- // world's timers.
245
- if (!gameClock) clock.dispose();
246
- app = null;
247
- // Scoped strip when a Game hosts this world (sibling roots stay live);
248
- // a bare standalone mount owns its private registry and clears it all.
249
- if (host.game) debugRegistry.strip(id);
250
- else debugRegistry.strip();
251
- },
252
- };
253
- }
@@ -1,80 +0,0 @@
1
- import * as THREE from 'three';
2
-
3
- /**
4
- * Debug drawing utilities for development.
5
- *
6
- * Draw lines, spheres, boxes, and arrows for visualizing
7
- * physics colliders, raycasts, AI paths, etc.
8
- *
9
- * All debug objects are added to a dedicated group that can be toggled.
10
- */
11
- export function createDebugDraw(scene: THREE.Scene) {
12
- const group = new THREE.Group();
13
- group.name = 'debug-draw';
14
- scene.add(group);
15
-
16
- return {
17
- /** Draw a line between two points */
18
- line(from: THREE.Vector3, to: THREE.Vector3, color = 0x00ff00) {
19
- const geometry = new THREE.BufferGeometry().setFromPoints([from, to]);
20
- const material = new THREE.LineBasicMaterial({ color });
21
- const line = new THREE.Line(geometry, material);
22
- group.add(line);
23
- return line;
24
- },
25
-
26
- /** Draw a wireframe sphere at a position */
27
- sphere(center: THREE.Vector3, radius = 0.1, color = 0xff0000) {
28
- const geo = new THREE.SphereGeometry(radius, 8, 8);
29
- const mat = new THREE.MeshBasicMaterial({ color, wireframe: true });
30
- const mesh = new THREE.Mesh(geo, mat);
31
- mesh.position.copy(center);
32
- group.add(mesh);
33
- return mesh;
34
- },
35
-
36
- /** Draw a wireframe box */
37
- box(center: THREE.Vector3, size: THREE.Vector3, color = 0x00ffff) {
38
- const geo = new THREE.BoxGeometry(size.x, size.y, size.z);
39
- const mat = new THREE.MeshBasicMaterial({ color, wireframe: true });
40
- const mesh = new THREE.Mesh(geo, mat);
41
- mesh.position.copy(center);
42
- group.add(mesh);
43
- return mesh;
44
- },
45
-
46
- /** Draw an arrow (direction indicator) */
47
- arrow(origin: THREE.Vector3, direction: THREE.Vector3, length = 1, color = 0xffff00) {
48
- // Clone before normalize() — never mutate the caller's vector.
49
- const dir = direction.clone().normalize();
50
- const arrow = new THREE.ArrowHelper(dir, origin, length, color);
51
- group.add(arrow);
52
- return arrow;
53
- },
54
-
55
- /** Clear all debug drawings */
56
- clear() {
57
- while (group.children.length > 0) {
58
- const child = group.children[0]!;
59
- group.remove(child);
60
- if (child instanceof THREE.Mesh || child instanceof THREE.Line) {
61
- // Mesh, Line and LineSegments all own geometry + material.
62
- child.geometry.dispose();
63
- (child.material as THREE.Material).dispose();
64
- } else if (child instanceof THREE.ArrowHelper) {
65
- // ArrowHelper owns a line + cone; dispose() frees both.
66
- child.dispose();
67
- }
68
- }
69
- },
70
-
71
- /** Toggle debug draw visibility */
72
- set visible(v: boolean) {
73
- group.visible = v;
74
- },
75
-
76
- get visible() {
77
- return group.visible;
78
- },
79
- };
80
- }
@@ -1,168 +0,0 @@
1
- import * as THREE from 'three';
2
-
3
- /**
4
- * Transparent auto-batcher (Strategy 1).
5
- *
6
- * The framework keeps each entity's Object3D as the logical handle (transform,
7
- * gameplay, physics, picking) and renders eligible entities through a shared
8
- * InstancedMesh under the hood — N logical objects, 1 draw call — WITHOUT the
9
- * user changing any code. Identity is never merged, so selection/raycast survive
10
- * (we keep an instanceId → entity map). The whole thing flips on/off live.
11
- *
12
- * Eligibility: an entity is a THREE.Mesh sharing geometry+material with others.
13
- * Entities marked `userData.__noBatch` (the per-entity opt-out) always render
14
- * individually. Custom/unique materials simply form their own (size-1) groups and
15
- * cost a draw each — they degrade, they don't break.
16
- *
17
- * Cost model (measured in docs/research/bench/): per-frame cost is paid only for
18
- * entities that MOVED (dirty-tracked via markMoved). A static scene re-syncs
19
- * nothing — write-once at build, then 1 draw/frame.
20
- */
21
-
22
- interface Batch {
23
- key: string;
24
- instanced: THREE.InstancedMesh;
25
- members: THREE.Mesh[]; // localIndex → entity mesh (for picking + sync)
26
- }
27
-
28
- const SIG = (m: THREE.Mesh): string => {
29
- const mat = Array.isArray(m.material) ? m.material[0]! : m.material;
30
- return `${(m.geometry as THREE.BufferGeometry).uuid}|${mat.uuid}`;
31
- };
32
-
33
- export class AutoBatcher {
34
- /** Root the batcher owns under the scene (instanced meshes when on, entities when off). */
35
- readonly root = new THREE.Group();
36
-
37
- private entities: THREE.Mesh[] = [];
38
- private batches = new Map<string, Batch>();
39
- private enabled: boolean;
40
- /** Indices of entities whose transform changed since last sync. */
41
- private dirty = new Set<number>();
42
- private touchedBatches = new Set<Batch>();
43
- // Per-mesh bookkeeping is kept in WeakMaps, NOT on userData (the typed userData
44
- // registry is reserved for documented engine keys — see user-data.ts).
45
- private indexOf = new WeakMap<THREE.Mesh, number>();
46
- private optOut = new WeakSet<THREE.Mesh>();
47
- private batchOf = new WeakMap<THREE.Mesh, { key: string; localIndex: number }>();
48
- private membersOf = new WeakMap<THREE.InstancedMesh, THREE.Mesh[]>();
49
-
50
- constructor(parent: THREE.Object3D, enabled = true) {
51
- this.enabled = enabled;
52
- this.root.name = 'AutoBatcher';
53
- parent.add(this.root);
54
- }
55
-
56
- /** Register an entity (a Mesh) as the logical handle. Call build() after adding. */
57
- add(entity: THREE.Mesh, optOut = false): void {
58
- this.indexOf.set(entity, this.entities.length);
59
- if (optOut) this.optOut.add(entity);
60
- this.entities.push(entity);
61
- }
62
-
63
- /** Mark an entity moved this frame (dirty-tracking input). */
64
- markMoved(entity: THREE.Mesh): void {
65
- const i = this.indexOf.get(entity);
66
- if (i !== undefined) this.dirty.add(i);
67
- }
68
-
69
- /** (Re)build the render representation for the current enabled state. */
70
- build(): void {
71
- this.clearRoot();
72
- this.batches.clear();
73
- if (!this.enabled) {
74
- for (const e of this.entities) this.root.add(e);
75
- return;
76
- }
77
- const m = new THREE.Matrix4();
78
- // group eligible entities; opt-outs render individually
79
- const groups = new Map<string, THREE.Mesh[]>();
80
- for (const e of this.entities) {
81
- if (this.optOut.has(e)) {
82
- this.root.add(e);
83
- continue;
84
- }
85
- const key = SIG(e);
86
- const arr = groups.get(key) ?? [];
87
- arr.push(e);
88
- groups.set(key, arr);
89
- }
90
- for (const [key, members] of groups) {
91
- const proto = members[0]!;
92
- const mat = Array.isArray(proto.material) ? proto.material[0]! : proto.material;
93
- const inst = new THREE.InstancedMesh(proto.geometry, mat, members.length);
94
- inst.frustumCulled = false;
95
- for (let i = 0; i < members.length; i++) {
96
- const e = members[i]!;
97
- e.updateMatrix();
98
- m.copy(e.matrix);
99
- inst.setMatrixAt(i, m);
100
- this.batchOf.set(e, { key, localIndex: i });
101
- }
102
- inst.instanceMatrix.needsUpdate = true;
103
- this.membersOf.set(inst, members); // localIndex → entity (picking)
104
- this.root.add(inst);
105
- this.batches.set(key, { key, instanced: inst, members });
106
- }
107
- }
108
-
109
- /** Apply the dirty set to the instance buffers. Cheap when few moved. */
110
- sync(): void {
111
- if (!this.enabled) return;
112
- const m = new THREE.Matrix4();
113
- this.touchedBatches.clear();
114
- for (const i of this.dirty) {
115
- const e = this.entities[i]!;
116
- const info = this.batchOf.get(e);
117
- if (!info) continue; // opt-out or not batched
118
- const batch = this.batches.get(info.key);
119
- if (!batch) continue;
120
- e.updateMatrix();
121
- m.copy(e.matrix);
122
- batch.instanced.setMatrixAt(info.localIndex, m);
123
- this.touchedBatches.add(batch);
124
- }
125
- for (const b of this.touchedBatches) b.instanced.instanceMatrix.needsUpdate = true;
126
- this.dirty.clear();
127
- }
128
-
129
- /** Live toggle: rebuilds the representation (one-time cost, not per-frame). */
130
- setEnabled(on: boolean): void {
131
- if (on === this.enabled) return;
132
- this.enabled = on;
133
- this.build();
134
- }
135
-
136
- isEnabled(): boolean {
137
- return this.enabled;
138
- }
139
-
140
- /** Map a raycast hit on a batch back to the logical entity (editor/gameplay picking). */
141
- resolvePick(intersection: THREE.Intersection): THREE.Mesh | null {
142
- const obj = intersection.object;
143
- if ((obj as THREE.InstancedMesh).isInstancedMesh && intersection.instanceId != null) {
144
- const members = this.membersOf.get(obj as THREE.InstancedMesh);
145
- return members?.[intersection.instanceId] ?? null;
146
- }
147
- return obj instanceof THREE.Mesh ? obj : null;
148
- }
149
-
150
- /** Per-frame draw-call count this batcher contributes (for stats). */
151
- get drawCallCount(): number {
152
- return this.enabled ? this.batches.size + this.optOutCount : this.entities.length;
153
- }
154
-
155
- private get optOutCount(): number {
156
- let n = 0;
157
- for (const e of this.entities) if (this.optOut.has(e)) n++;
158
- return n;
159
- }
160
-
161
- private clearRoot(): void {
162
- for (let i = this.root.children.length - 1; i >= 0; i--) {
163
- const c = this.root.children[i]!;
164
- this.root.remove(c);
165
- if ((c as THREE.InstancedMesh).isInstancedMesh) (c as THREE.InstancedMesh).dispose();
166
- }
167
- }
168
- }
package/src/render/lod.ts DELETED
@@ -1,17 +0,0 @@
1
- import type * as THREE from 'three';
2
-
3
- /**
4
- * Per-frame LOD tick. `THREE.LOD` only swaps its active level when
5
- * `.update(camera)` runs, so every `THREE.LOD` in the scene graph needs this
6
- * called once a frame. Wired into the runtime's `preRender` system in
7
- * `adapter/setup-three-root-adapter.ts`.
8
- *
9
- * Format-neutral: it matches THREE's own `isLOD` marker and knows nothing about
10
- * how the LOD was built. Formerly `@engine/scene/scene-loader`'s
11
- * `updateSceneLODs`, relocated here when WO-8 deleted the `.vscn` scene loader.
12
- */
13
- export function updateSceneLODs(scene: THREE.Object3D, camera: THREE.Camera): void {
14
- scene.traverse((o) => {
15
- if ((o as THREE.LOD).isLOD) (o as THREE.LOD).update(camera);
16
- });
17
- }