The adapter architecture
vgai’s editor and host don’t depend on any one game’s internals. They depend on interfaces, and games — first-party TSX/R3F worlds or unmodified third-party three.js games — are peer implementers of those interfaces.
The core interfaces
Section titled “The core interfaces”RootAdapter<K>(packages/engine/src/adapter/root-adapter.ts) — the host⇄runtime lifecycle, generic over the adapter surface (default'three'). A “game” is anything that mounts viamount(host), returning its kind-tagged surface —MountedThreeWorld(whichMountedRootpermanently names),MountedPixiWorld, orMountedReactWorld. The threejs surface exposes the live scene + camera and lifecycle hooks (update/fixedUpdate/ setPaused/step) plus optional authoring/systems providers.- Host contexts (
host-context.ts) — what the host provides, split PER SURFACE:HostContextBasecarries only what every surface genuinely gets (the root handle,headless), andThreeHostContext/CanvasHostContext/DomHostContextadd that surface’s own primitives — three, renderer, surface and asset cache for three; the canvas plus compositing hints for canvas; a plain container for dom.HostContextFor<K>selects one, somount’s parameter is kind-typed and a Pixi root is never handed a WebGL renderer it can’t use.HostContextis a permanent alias of the three context. Rapier/Colyseus are kept behind system adapters, not baked into the host. AuthoringAdapter(authoring.ts) — the editor’s authoring contract: hierarchy / selection / transform / inspector / structure / persistence, keyed by opaque string node ids. The editor UI never branches on which implementer it’s editing.
First-party implementers
Section titled “First-party implementers”vgai’s own content plugs into the same seams:
SetupThreeRootAdapterwraps an imperativesetup()export as aRootAdapter;fromSetup()adapts every existing example with zero edits.VgaiSceneAuthoringAdapterimplementsAuthoringAdapterby delegating to the editor’s existing store/scene logic — so the hierarchy/inspector/gizmo/save all route through it.
System adapters
Section titled “System adapters”Optional subsystem capability providers hang off MountedRoot.systems
(system-adapter.ts) — the editor coordinates with a game’s systems without owning them:
Physics, Networking, Input, Asset, Navigation. First-party implementers wrap Rapier,
Colyseus, the input manager, the asset cache, and the navmesh manager.
See also
Section titled “See also”- Ingesting unmodified games — the render-accessor trap + overlays.
- Editor Guide — the authoring surface that rides on
AuthoringAdapter.