@vgai/engine 0.5.11 → 0.5.13

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 (152) hide show
  1. package/README.md +6 -5
  2. package/dist/adapter/authoring.d.ts +51 -28
  3. package/dist/adapter/authoring.d.ts.map +1 -1
  4. package/dist/adapter/body-marks.d.ts +59 -0
  5. package/dist/adapter/body-marks.d.ts.map +1 -0
  6. package/dist/adapter/body-marks.js +62 -0
  7. package/dist/adapter/constraint.d.ts +41 -0
  8. package/dist/adapter/constraint.d.ts.map +1 -0
  9. package/dist/adapter/constraint.js +27 -0
  10. package/dist/adapter/hierarchy-marks.d.ts +138 -0
  11. package/dist/adapter/hierarchy-marks.d.ts.map +1 -0
  12. package/dist/adapter/hierarchy-marks.js +148 -0
  13. package/dist/adapter/index.d.ts +1 -1
  14. package/dist/adapter/index.d.ts.map +1 -1
  15. package/dist/adapter/ingest/contract-system-adapters.d.ts +64 -0
  16. package/dist/adapter/ingest/contract-system-adapters.d.ts.map +1 -0
  17. package/dist/adapter/ingest/contract-system-adapters.js +134 -0
  18. package/dist/adapter/ingest/game-contract.d.ts +87 -9
  19. package/dist/adapter/ingest/game-contract.d.ts.map +1 -1
  20. package/dist/adapter/ingest/game-contract.js +7 -6
  21. package/dist/adapter/ingest/scene-capture.d.ts +31 -4
  22. package/dist/adapter/ingest/scene-capture.d.ts.map +1 -1
  23. package/dist/adapter/ingest/scene-capture.js +29 -7
  24. package/dist/adapter/ingest/structural-ids.d.ts +1 -1
  25. package/dist/adapter/ingest/structural-ids.js +2 -2
  26. package/dist/adapter/reflection-probe.d.ts +53 -0
  27. package/dist/adapter/reflection-probe.d.ts.map +1 -0
  28. package/dist/adapter/reflection-probe.js +18 -0
  29. package/dist/asset-formats/index.d.ts +4 -10
  30. package/dist/asset-formats/index.d.ts.map +1 -1
  31. package/dist/asset-formats/index.js +3 -8
  32. package/dist/asset-formats/material.d.ts +0 -66
  33. package/dist/asset-formats/material.d.ts.map +1 -1
  34. package/dist/asset-formats/material.js +0 -8
  35. package/dist/asset-formats/mesh.d.ts +1 -2
  36. package/dist/asset-formats/mesh.d.ts.map +1 -1
  37. package/dist/asset-formats/mesh.js +3 -13
  38. package/dist/asset-formats/render-env.d.ts +2 -2
  39. package/dist/asset-parse-error.d.ts +4 -5
  40. package/dist/asset-parse-error.d.ts.map +1 -1
  41. package/dist/asset-parse-error.js +4 -5
  42. package/dist/config.d.ts +7 -0
  43. package/dist/config.d.ts.map +1 -1
  44. package/dist/config.js +7 -0
  45. package/dist/data/curve.d.ts +116 -0
  46. package/dist/data/curve.d.ts.map +1 -0
  47. package/dist/data/curve.js +230 -0
  48. package/dist/data/vite-plugin-data.d.ts +2 -2
  49. package/dist/data/vite-plugin-data.d.ts.map +1 -1
  50. package/dist/data/vite-plugin-data.js +24 -15
  51. package/dist/dev/performance-profiler.d.ts +1 -0
  52. package/dist/dev/performance-profiler.d.ts.map +1 -1
  53. package/dist/dev/performance-profiler.js +25 -2
  54. package/dist/ecs/user-data.d.ts +49 -1
  55. package/dist/ecs/user-data.d.ts.map +1 -1
  56. package/dist/ecs/user-data.js +34 -0
  57. package/dist/index.d.ts +2 -3
  58. package/dist/index.d.ts.map +1 -1
  59. package/dist/index.js +2 -3
  60. package/dist/manifest/index.d.ts +3 -3
  61. package/dist/manifest/index.d.ts.map +1 -1
  62. package/dist/manifest/index.js +2 -2
  63. package/dist/manifest/load.d.ts +15 -67
  64. package/dist/manifest/load.d.ts.map +1 -1
  65. package/dist/manifest/load.js +11 -103
  66. package/dist/manifest/schema.d.ts +18 -103
  67. package/dist/manifest/schema.d.ts.map +1 -1
  68. package/dist/manifest/schema.js +59 -179
  69. package/dist/pixi/index.d.ts +2 -3
  70. package/dist/pixi/index.d.ts.map +1 -1
  71. package/dist/pixi/index.js +2 -3
  72. package/dist/pixi/ingest.d.ts +7 -75
  73. package/dist/pixi/ingest.d.ts.map +1 -1
  74. package/dist/pixi/ingest.js +6 -14
  75. package/dist/pixi/scene-capture.d.ts +2 -2
  76. package/dist/pixi/scene-capture.js +2 -2
  77. package/dist/react/use-data.d.ts +10 -5
  78. package/dist/react/use-data.d.ts.map +1 -1
  79. package/dist/react/use-data.js +15 -15
  80. package/dist/render/viewport-shading.d.ts +1 -1
  81. package/dist/render/viewport-shading.d.ts.map +1 -1
  82. package/dist/render/viewport-shading.js +14 -0
  83. package/dist/runtime/create-runtime.d.ts +12 -0
  84. package/dist/runtime/create-runtime.d.ts.map +1 -1
  85. package/dist/runtime/create-runtime.js +7 -2
  86. package/dist/runtime/mount-game.d.ts +1 -1
  87. package/dist/runtime/mount-game.d.ts.map +1 -1
  88. package/dist/runtime/mount-manifest.d.ts.map +1 -1
  89. package/dist/runtime/mount-manifest.js +5 -1
  90. package/dist/world3d-react/r3f-adapter.d.ts.map +1 -1
  91. package/dist/world3d-react/r3f-adapter.js +69 -39
  92. package/dist/world3d-react/renderer-config.d.ts +15 -0
  93. package/dist/world3d-react/renderer-config.d.ts.map +1 -1
  94. package/dist/world3d-react/renderer-config.js +15 -0
  95. package/dist/world3d-react/world-context.d.ts +2 -1
  96. package/dist/world3d-react/world-context.d.ts.map +1 -1
  97. package/dist-config/config.js +140 -20
  98. package/dist-config/config.js.map +4 -4
  99. package/package.json +1 -1
  100. package/schemas/engine-capabilities.json +10 -10
  101. package/schemas/vgai-project.schema.json +21 -76
  102. package/src/adapter/authoring.ts +54 -31
  103. package/src/adapter/body-marks.ts +69 -0
  104. package/src/adapter/constraint.ts +71 -0
  105. package/src/adapter/hierarchy-marks.ts +155 -0
  106. package/src/adapter/index.ts +2 -3
  107. package/src/adapter/ingest/contract-system-adapters.ts +174 -0
  108. package/src/adapter/ingest/game-contract.ts +98 -9
  109. package/src/adapter/ingest/scene-capture.ts +61 -11
  110. package/src/adapter/ingest/structural-ids.ts +2 -2
  111. package/src/adapter/reflection-probe.ts +75 -0
  112. package/src/asset-formats/index.ts +4 -10
  113. package/src/asset-formats/material.ts +0 -11
  114. package/src/asset-formats/mesh.ts +3 -16
  115. package/src/asset-parse-error.ts +4 -5
  116. package/src/config.ts +13 -0
  117. package/src/data/curve.ts +263 -0
  118. package/src/data/vite-plugin-data.ts +48 -14
  119. package/src/dev/performance-profiler.ts +21 -2
  120. package/src/ecs/user-data.ts +50 -0
  121. package/src/index.ts +2 -3
  122. package/src/manifest/index.ts +3 -15
  123. package/src/manifest/load.ts +27 -143
  124. package/src/manifest/schema.ts +65 -223
  125. package/src/pixi/index.ts +2 -15
  126. package/src/pixi/ingest.ts +13 -87
  127. package/src/pixi/scene-capture.ts +2 -2
  128. package/src/react/use-data.ts +15 -20
  129. package/src/render/viewport-shading.ts +16 -1
  130. package/src/runtime/create-runtime.ts +30 -5
  131. package/src/runtime/mount-game.ts +1 -1
  132. package/src/runtime/mount-manifest.ts +5 -1
  133. package/src/world3d-react/r3f-adapter.tsx +73 -39
  134. package/src/world3d-react/renderer-config.ts +31 -0
  135. package/src/world3d-react/world-context.ts +2 -1
  136. package/dist/asset-formats/instances.d.ts +0 -17
  137. package/dist/asset-formats/instances.d.ts.map +0 -1
  138. package/dist/asset-formats/instances.js +0 -31
  139. package/dist/asset-formats/parse.d.ts +0 -20
  140. package/dist/asset-formats/parse.d.ts.map +0 -1
  141. package/dist/asset-formats/parse.js +0 -34
  142. package/dist/pixi/ingest-iframe.d.ts +0 -82
  143. package/dist/pixi/ingest-iframe.d.ts.map +0 -1
  144. package/dist/pixi/ingest-iframe.js +0 -166
  145. package/dist/render/instance-mesh.d.ts +0 -5
  146. package/dist/render/instance-mesh.d.ts.map +0 -1
  147. package/dist/render/instance-mesh.js +0 -19
  148. package/schemas/mat.schema.json +0 -255
  149. package/src/asset-formats/instances.ts +0 -38
  150. package/src/asset-formats/parse.ts +0 -39
  151. package/src/pixi/ingest-iframe.ts +0 -255
  152. package/src/render/instance-mesh.ts +0 -25
@@ -238,7 +238,7 @@ export interface InspectorProvider {
238
238
  /** Schema-driven — NOT fixed to `SceneEntity`. */
239
239
  properties(id: string): PropertyDescriptor[];
240
240
  get(id: string, path: string): unknown;
241
- set(id: string, path: string, value: unknown): void;
241
+ set(id: string, path: string, value: unknown): void | Promise<void>;
242
242
  /**
243
243
  * Optional — REMOVE a property's authored override entirely (not "set to a
244
244
  * value"), letting whatever governs it in its absence take over. The one
@@ -281,6 +281,19 @@ export interface AssetSubjectProvider {
281
281
  entries?(): ReadonlyArray<{ id: string; subject: AuthoringAssetSubject }>;
282
282
  }
283
283
 
284
+ /** A semantic jump from one authored subject to another document/subject.
285
+ * The adapter owns resolution and opening; the inspector only presents the
286
+ * title and exposes the same verb to human and serialized projections. */
287
+ export interface RelatedSubjectLink {
288
+ readonly id: string;
289
+ readonly title: string;
290
+ open(): void;
291
+ }
292
+
293
+ export interface RelatedSubjectsProvider {
294
+ links(id: string): readonly RelatedSubjectLink[];
295
+ }
296
+
284
297
  export interface StructureProvider {
285
298
  create(kind: string, parentId?: string): string;
286
299
  /**
@@ -384,26 +397,6 @@ export interface PersistenceProvider {
384
397
  applyExternal?(content: unknown, rawContent?: string): void;
385
398
  }
386
399
 
387
- /** D8 — mutually-exclusive root groups (radio roots): e.g. a "Scenes" group whose
388
- * members are the game's scene roots, only one of which is loaded/active at a
389
- * time (unlike ordinary sibling roots, which all coexist). */
390
- export interface RootGroup {
391
- id: string; // stable, e.g. 'scenes'
392
- label: string; // 'Scenes'
393
- memberRootIds: string[]; // EditorNode ids; each is a hierarchy root
394
- activeRootId: string | null;
395
- }
396
- export interface RootGroupsProvider {
397
- groups(): RootGroup[];
398
- activate(groupId: string, rootId: string): Promise<void> | void;
399
- }
400
-
401
- /** D8 — data-file → root mapping ("opening a file" = activating its root). */
402
- export interface FileMapProvider {
403
- /** project-relative path → node id this adapter maps it to, else null. */
404
- rootForFile(path: string): string | null;
405
- }
406
-
407
400
  /** D12 — per-layer viewport picking. Coordinates are client (browser) px. */
408
401
  export interface PickProvider {
409
402
  pick(clientX: number, clientY: number): string | null;
@@ -510,9 +503,11 @@ export interface BoxEditProvider {
510
503
  referencePoint?(id: string): BoxEditReferencePoint | null;
511
504
  }
512
505
 
513
- /** Text-content editing currently OFF-contract (the react adapter has an `editText(id)`
514
- * method, react-world-authoring-adapter.ts:728, not reachable via the contract). Bring it
515
- * on so the overlay's double-click-to-edit-text (D3) is contract-driven. */
506
+ /** Text-content editing, ON the contract: the react-world adapter implements this
507
+ * provider (`react-world-authoring-adapter.ts`'s `readonly text: TextProvider`),
508
+ * bringing its own `editText(id)` write path onto the seam, so the overlay's
509
+ * double-click-to-edit-text (D3) is contract-driven rather than reaching for a
510
+ * concrete adapter's method. */
516
511
  export interface TextProvider {
517
512
  /** the element's editable pure-text, or null if the body is dynamic/has child elements */
518
513
  get(id: string): string | null;
@@ -539,15 +534,46 @@ export interface ColorSampleProvider {
539
534
  }
540
535
 
541
536
  /**
542
- * WO-IDX1 — where a node's live object was CREATED in the game's own source.
537
+ * WO-IDX1 — where a node's live object CAME FROM in the game's own truth.
543
538
  *
544
- * `display` is the `file:line` the editor shows verbatim. The unanchored shape
539
+ * `display` is the string the editor shows verbatim. The unanchored shape
545
540
  * carries a `reason` rather than a blank, because "we don't know" and "a
546
541
  * library built it" are different facts and neither may present as silence
547
542
  * (the honest-floor rule).
543
+ *
544
+ * TWO ANCHORED KINDS, because a game has two kinds of truth and only one of
545
+ * them is source.
546
+ *
547
+ * - `source` is the original: a `new` expression at a `file:line:col` in the
548
+ * game's own code, which is where an edit to a constructor literal has to be
549
+ * written.
550
+ * - `data` is the sibling a level-based game needs. Descent's placed cargo —
551
+ * the robots, the powerups, the hostages — reaches no source literal at all;
552
+ * it is binary records inside `descent.hog` that the game parses at load. An
553
+ * authored move of a robot is therefore an edit to THE GAME'S OWN DATA, and
554
+ * the honest anchor is the data file plus the index of the record that
555
+ * addresses the object inside it.
556
+ *
557
+ * `kind` is an explicit discriminant rather than an inferred one, so a consumer
558
+ * that only understands source anchors fails to compile against a data anchor
559
+ * instead of silently reading `line` off something that has none.
560
+ *
561
+ * A data record is EXACTLY ONE object by construction — an index addresses one
562
+ * record — so the "how many objects did this site construct?" question that
563
+ * governs a source write has no data-side analogue and must not be invented
564
+ * for one.
548
565
  */
549
566
  export type NodeCreationSite =
550
- | { anchored: true; file: string; line: number; col: number; display: string }
567
+ | { anchored: true; kind: 'source'; file: string; line: number; col: number; display: string }
568
+ | {
569
+ anchored: true;
570
+ kind: 'data';
571
+ /** Project-relative path of the game's own data file, POSIX separators. */
572
+ file: string;
573
+ /** Index of the record inside that file which addresses this object. */
574
+ record: number;
575
+ display: string;
576
+ }
551
577
  | { anchored: false; reason: string };
552
578
 
553
579
  /**
@@ -571,12 +597,9 @@ export interface AuthoringAdapter {
571
597
  readonly inspector?: InspectorProvider;
572
598
  /** The selected node is an atomic asset that can open in the Asset Editor. */
573
599
  readonly assetSubject?: AssetSubjectProvider;
600
+ readonly related?: RelatedSubjectsProvider;
574
601
  readonly structure?: StructureProvider;
575
602
  readonly persistence?: PersistenceProvider;
576
- /** D8 — mutually-exclusive root groups (radio roots). Absent ⇒ no grouped roots. */
577
- readonly rootGroups?: RootGroupsProvider;
578
- /** D8 — data-file → root mapping. Absent ⇒ this adapter maps no files to roots. */
579
- readonly files?: FileMapProvider;
580
603
  /** D12 — per-layer viewport picking. Absent ⇒ this adapter is not pickable. */
581
604
  readonly pickable?: PickProvider;
582
605
  /** T0 (spec 27 §2) — per-node screen geometry for a DOM visual editor's overlay/
@@ -0,0 +1,69 @@
1
+ /**
2
+ * The transform-AUTHORITY convention: how a game tells the host which of its
3
+ * nodes have their pose written by a rigid body rather than by the node itself.
4
+ *
5
+ * Sibling of `hierarchy-marks.ts`, and the same shape of idea. That module's
6
+ * marks answer "what IS this node" for the panel; this one answers "who WRITES
7
+ * this node's pose" for an edit. Both are written by GAME code at the seam that
8
+ * knows the answer, read generically by the host, and namespaced `vgai*` because
9
+ * they are the host's namespace on a node the game owns.
10
+ *
11
+ * ## Why it exists
12
+ *
13
+ * A world that simulates writes `node.position/quaternion` FROM its bodies every
14
+ * step. Setting the node is therefore not an edit — it is a value that survives
15
+ * until the next step and then vanishes, which is what "the gizmo does nothing"
16
+ * looks like from the outside. The edit has to reach the body.
17
+ *
18
+ * The host cannot find the body on its own. Three.js has no body concept, the
19
+ * body is usually not in the scene graph at all, and the mapping from node to
20
+ * body is private to whichever code built the pair. So the code that ATTACHES a
21
+ * body to a node draws the link in the same breath — one call, at the one place
22
+ * the answer is known — exactly as `markBuiltInternal` is called at the attach
23
+ * seam and never by a later sweep of the tree.
24
+ *
25
+ * ## Prefer the system adapter when you have one
26
+ *
27
+ * A game that already registers `SystemAdapters.physics` needs none of this: the
28
+ * adapter's `ownerOf`/`freeze`/`commit`/`unfreeze` is the richer answer, and the
29
+ * editor asks it first. This mark is for the case that seam cannot cover — a
30
+ * world whose bodies are built by ordinary per-scene code with no central
31
+ * registry to hand a `bodyFor(nodeId)` resolver (every translated import lane),
32
+ * where the only place node and body meet is the constructor that made both.
33
+ * Marked nodes reach the SAME four verbs through
34
+ * {@link createRapierBodyEditing}; this is a second SOURCE for one mechanism,
35
+ * not a second mechanism.
36
+ *
37
+ * ## What to mark
38
+ *
39
+ * The node whose pose the body writes — normally the body's own root node. Not
40
+ * subtree-scoped (unlike `vgaiBuiltInternal`): a child of a body-driven node
41
+ * inherits its parent's motion through the transform chain, and its own local
42
+ * pose is still the node's to keep. Mark exactly the node the sync writes.
43
+ */
44
+
45
+ import type * as THREE from 'three';
46
+ import { getUserData, setUserData } from '../ecs/user-data';
47
+ import type { RapierEditableBody } from './rapier-physics-adapter';
48
+
49
+ /**
50
+ * Declare that `body` owns `node`'s pose: a transform edit on `node` is applied
51
+ * to `body`, and the next step is what puts the result back on the node.
52
+ *
53
+ * Call it where the pair is created. `body` is the game's OWN Rapier body,
54
+ * passed through unchanged — the parameter type names five of Rapier's own
55
+ * methods structurally (see {@link RapierEditableBody}) because this repo
56
+ * legitimately resolves two copies of `@dimforge/rapier3d-compat` whose
57
+ * `RigidBody` classes are unrelated nominal types.
58
+ */
59
+ export function markBodyOwnedNode(node: THREE.Object3D, body: RapierEditableBody): void {
60
+ setUserData(node, 'vgaiBodyOwner', body);
61
+ }
62
+
63
+ /** The body that owns `node`'s pose, or `undefined` for a node that owns its own. */
64
+ export function bodyOwningNode(
65
+ node: THREE.Object3D | null | undefined,
66
+ ): RapierEditableBody | undefined {
67
+ const body = getUserData(node, 'vgaiBodyOwner');
68
+ return body ?? undefined;
69
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Format-neutral live mark for source-owned spatial constraints.
3
+ *
4
+ * The project capability that performs a solve attaches one or more marks to
5
+ * the Object3D that owns the constrained pose. The editor reads the marks to
6
+ * render an ordinary constraint stack and transient viewport handles. This is
7
+ * observation, not authored data: the owning TS/TSX and its ordinary target /
8
+ * pole Object3Ds remain the only source of truth.
9
+ */
10
+ import type * as THREE from 'three';
11
+ import { deleteUserData, getUserData, setUserData } from '../ecs/user-data';
12
+
13
+ export type ConstraintStatus = 'ready' | 'disabled' | 'unresolved' | 'error';
14
+
15
+ export interface ConstraintConfig {
16
+ /** Stable only within this mounted owner. */
17
+ readonly id: string;
18
+ readonly type: 'two-bone-ik' | 'ccd-ik' | (string & {});
19
+ readonly label: string;
20
+ readonly enabled: boolean;
21
+ readonly weight: number;
22
+ /** Evaluation order among constraints attached to this owner. */
23
+ readonly order: number;
24
+ }
25
+
26
+ export interface ConstraintSnapshot {
27
+ readonly status: ConstraintStatus;
28
+ readonly message?: string;
29
+ /** Root → effector, using the real bones from the live skeleton. */
30
+ readonly chain: readonly THREE.Object3D[];
31
+ readonly target: THREE.Object3D | null;
32
+ readonly pole: THREE.Object3D | null;
33
+ /** Effector-to-target distance after the latest solve, in world units. */
34
+ readonly error: number | null;
35
+ }
36
+
37
+ export interface ConstraintMark {
38
+ readonly config: ConstraintConfig;
39
+ getSnapshot(): ConstraintSnapshot;
40
+ }
41
+
42
+ export function constraintsOf(
43
+ object: THREE.Object3D | null | undefined,
44
+ ): readonly ConstraintMark[] {
45
+ const candidate = getUserData(object, 'constraints');
46
+ if (!Array.isArray(candidate)) return [];
47
+ return candidate.filter(
48
+ (entry): entry is ConstraintMark =>
49
+ Boolean(entry) &&
50
+ typeof entry === 'object' &&
51
+ typeof (entry as Partial<ConstraintMark>).getSnapshot === 'function' &&
52
+ Boolean((entry as Partial<ConstraintMark>).config),
53
+ );
54
+ }
55
+
56
+ /** Add or replace one constraint mark without disturbing sibling constraints. */
57
+ export function setConstraintMark(object: THREE.Object3D, mark: ConstraintMark): void {
58
+ const next = constraintsOf(object).filter((entry) => entry.config.id !== mark.config.id);
59
+ setUserData(object, 'constraints', [...next, mark]);
60
+ }
61
+
62
+ /** Remove one mark, or the whole live projection when no id is supplied. */
63
+ export function clearConstraintMark(object: THREE.Object3D, id?: string): void {
64
+ if (id === undefined) {
65
+ deleteUserData(object, 'constraints');
66
+ return;
67
+ }
68
+ const next = constraintsOf(object).filter((entry) => entry.config.id !== id);
69
+ if (next.length === 0) deleteUserData(object, 'constraints');
70
+ else setUserData(object, 'constraints', next);
71
+ }
@@ -0,0 +1,155 @@
1
+ /**
2
+ * The hierarchy-presentation convention: how a game tells the editor which
3
+ * parts of its LIVE scene graph are one component instance, and which parts are
4
+ * implementation rather than content.
5
+ *
6
+ * ## Why marks and not a second tree
7
+ *
8
+ * The live tree IS the display surface. A hierarchy derived from source would
9
+ * be a mirror layer — a second model of the world that drifts from the one on
10
+ * screen — so the boundaries a reader needs have to live ON the nodes. That is
11
+ * what these marks are, and it is the whole mechanism: a component WRAPS its
12
+ * functionality and MARKS its root; the editor supports the convention
13
+ * generically and never learns which library, importer or lane produced the
14
+ * node.
15
+ *
16
+ * ## STRUCTURE IS THE TREE'S JOB. MARKS ONLY CLASSIFY.
17
+ *
18
+ * There is deliberately no mark that says "show this row somewhere else". A
19
+ * group owns its children by CONTAINING them; a prefab owns its parts by
20
+ * CONTAINING them. If an object reads as belonging under something it is not
21
+ * parented to, the tree is wrong and the tree is what to fix — because the
22
+ * panel is not the only reader. `getWorldPosition`, raycasting, disposal,
23
+ * `traverse`, every physics or gameplay walk and every person reading the
24
+ * source all follow real parenthood, and a presentation-only "logical parent"
25
+ * would be true for exactly one of them.
26
+ *
27
+ * The usual reason a world gets this wrong is that three's parent chain is a
28
+ * TRANSFORM chain: `matrixWorld` is unconditionally `parent × local`, so an
29
+ * object that must not inherit its owner's pose — a physics-driven body writing
30
+ * a world transform every step, a world-space trail or decal, a follow camera
31
+ * that must escape its target's rotation — gets mounted at the scene root, and
32
+ * ownership is lost as a side effect. **That trade is not necessary.** Set
33
+ * `object.matrixWorldAutoUpdate = false` (three r144+) and the parent's
34
+ * propagation skips it: the object stays parented where it belongs and its
35
+ * `matrixWorld` becomes yours to write. Keep it parented, own the matrix, and
36
+ * the hierarchy needs no help.
37
+ *
38
+ * These two marks then have exactly one job left, which is CLASSIFICATION:
39
+ * which of the objects that really are here is the game, and which is the
40
+ * machinery underneath it.
41
+ *
42
+ * ## What the hierarchy is FOR
43
+ *
44
+ * It shows YOUR GAME: the structure you authored, plus the objects your game
45
+ * makes while it runs. Nothing else. Three consequences, and every rule below
46
+ * follows from them:
47
+ *
48
+ * - **A spawned object is content.** A bullet you fired, a wave of enemies, a
49
+ * prop pulled out of a pool and parented into the level — these are rows.
50
+ * They exist, you can select them, and they are usually the exact things you
51
+ * opened the panel to look at. An object your game frees stops being a row,
52
+ * because it stopped existing.
53
+ * - **An implementation artifact is not.** The bones behind a rig, the batched
54
+ * renderer behind a particle system, the instanced-mesh pools behind a tile
55
+ * field, the `target` object three needs in order to aim a directional
56
+ * light: machinery a library or a helper builds so one thing you DID author
57
+ * can work. It belongs UNDER that thing, folded, not beside it.
58
+ * - **"Not in the source file" is the wrong test for either.** Half of a
59
+ * running world is not in the source file — that is what running means.
60
+ * Folding spawned gameplay because a document does not name it is the same
61
+ * defect as listing bones, in the more damaging direction: the rows it loses
62
+ * are the ones you were looking for.
63
+ *
64
+ * ## The two marks
65
+ *
66
+ * - {@link markComponentRoot} — "this subtree is one instance of `<name>`."
67
+ * The editor renders it as ONE row, closed, expandable on demand. Put it on
68
+ * the EARLIEST point the node exists: the constructor that makes it, or the
69
+ * ref callback that receives it. A component whose root is a plain `<mesh>`
70
+ * marks that mesh.
71
+ * - {@link markBuiltInternal} — "this is IMPLEMENTATION, not content." It is
72
+ * **subtree-scoped**: marking the root of a built subtree marks everything
73
+ * under it, so a 60-bone rig costs one call and folding is transitive. The
74
+ * editor hides these rows and offers them behind the same "Reveal Internals"
75
+ * action a source-backed instance's internals already use — revealed rows
76
+ * are read-only, because there is no authored source for a rename or a
77
+ * reparent to write to.
78
+ *
79
+ * An instance therefore reads as the parent of everything meaningful beneath
80
+ * it: content nested inside an implementation node is listed under the instance
81
+ * rather than lost with it (the editor's `hierarchy-component-marks.ts` calls
82
+ * that promotion), so marking a rig does not hide the mesh skinned to it.
83
+ *
84
+ * ## Mark it where the subtree is ATTACHED, by whoever attaches it
85
+ *
86
+ * A mark belongs at the attach seam: the code that puts an implementation
87
+ * subtree into the world marks it in the same breath, because that code is the
88
+ * only thing that knows the subtree is implementation. Not a later sweep of the
89
+ * tree — "everything present at time T that the source did not name" is the
90
+ * wrong predicate twice over. It arrives too early for anything attached
91
+ * asynchronously (a model clone landing after its bytes resolve, a node gated
92
+ * on an audio decode) and too late in principle for anything attached
93
+ * afterwards (every spawn) — and were it re-run to catch those, it would
94
+ * classify each spawned object as implementation, which is the second bullet
95
+ * above inverted. Attach-seam marking has neither failure: it fires once, at
96
+ * the moment the answer is known, and an unmarked node is content by default.
97
+ *
98
+ * The subtree scope is what keeps this cheap — one call per attached root, not
99
+ * one per node, so a rig or a pool costs one line at the one place that builds
100
+ * it.
101
+ *
102
+ * ## What is NOT built-internal
103
+ *
104
+ * A node your game means as content — even one a class rather than JSX
105
+ * constructs — is content. `vgaiBuiltInternal` is not "the editor cannot write
106
+ * this"; that question is `TransformProvider.editability`'s, answered per
107
+ * channel with a sentence. This mark answers "is this implementation", and
108
+ * getting it wrong hides real content.
109
+ *
110
+ * Both keys live in the typed `userData` registry (`../ecs/user-data.ts`) so
111
+ * their literal strings are spelled exactly once; this module is the only
112
+ * reader/writer, which is why the helpers below exist at all rather than
113
+ * `setUserData` calls scattered through emitters and prefabs.
114
+ */
115
+
116
+ import type * as THREE from 'three';
117
+ import { getUserData, setUserData } from '../ecs/user-data';
118
+
119
+ /**
120
+ * Declare `node` the root of one component instance, displayed under `name`.
121
+ *
122
+ * `name` is the COMPONENT's name (`'Coin'`, `'HeroBox'`), not the instance's —
123
+ * the instance is already named by `node.name`, and the editor prints both.
124
+ */
125
+ export function markComponentRoot(node: THREE.Object3D, name: string): void {
126
+ setUserData(node, 'vgaiComponentRoot', name);
127
+ }
128
+
129
+ /** The component name `node` is the root of, or `undefined` for an ordinary node. */
130
+ export function componentRootName(node: THREE.Object3D | null | undefined): string | undefined {
131
+ const name = getUserData(node, 'vgaiComponentRoot');
132
+ return typeof name === 'string' && name ? name : undefined;
133
+ }
134
+
135
+ /** Whether `node` is a marked component-instance root. */
136
+ export function isComponentRoot(node: THREE.Object3D | null | undefined): boolean {
137
+ return componentRootName(node) !== undefined;
138
+ }
139
+
140
+ /**
141
+ * Declare `node` (and everything under it) IMPLEMENTATION of whatever node it
142
+ * sits under, rather than content of its own. Call it on the ROOT of the built
143
+ * subtree only, at the seam that attaches it — see this module's header for why
144
+ * the seam and not a sweep.
145
+ */
146
+ export function markBuiltInternal(node: THREE.Object3D): void {
147
+ setUserData(node, 'vgaiBuiltInternal', true);
148
+ }
149
+
150
+ /** Whether `node` itself carries the implementation mark. Ancestry is the
151
+ * CALLER's walk — see this module's header for why the mark is subtree-scoped
152
+ * but not restamped onto descendants. */
153
+ export function isBuiltInternal(node: THREE.Object3D | null | undefined): boolean {
154
+ return getUserData(node, 'vgaiBuiltInternal') === true;
155
+ }
@@ -39,7 +39,6 @@ export type {
39
39
  DOMRectLike,
40
40
  EditorNode,
41
41
  EditorNodeRole,
42
- FileMapProvider,
43
42
  HierarchyProvider,
44
43
  InspectorProvider,
45
44
  NodeCreationSite,
@@ -47,8 +46,8 @@ export type {
47
46
  PickProvider,
48
47
  PropertyDescriptor,
49
48
  RectProvider,
50
- RootGroup,
51
- RootGroupsProvider,
49
+ RelatedSubjectLink,
50
+ RelatedSubjectsProvider,
52
51
  SelectionProvider,
53
52
  SelectionResolution,
54
53
  StoriesProvider,
@@ -0,0 +1,174 @@
1
+ /**
2
+ * Projects a game's declared {@link VgaiGameSystemAdapters}
3
+ * (`window.vgaiGame.systems.systemAdapters`) onto the host's ordinary
4
+ * {@link SystemAdapters} bag — the ingest-realm counterpart of a first-party
5
+ * world's `ctx.registerSystemAdapter`, and the sibling of
6
+ * `contract-debug-adapter.ts` (which owns the `debug` slot).
7
+ *
8
+ * ## Why a projection with a verdict per slot
9
+ *
10
+ * The ingestion bar (docs/BRINGING-AN-EXISTING-GAME.md §The ingestion
11
+ * checklist) admits exactly two terminal states per slot: IMPLEMENTED or
12
+ * IMPLEMENTED-EMPTY. `SystemAdapters` alone cannot express the second — an
13
+ * omitted key means "unsupported", which is the same shape as "nobody looked".
14
+ * So this returns THREE lists, and the caller hands the non-`bound` ones to the
15
+ * coverage report, where a positively-answered absence prints as terminal and an
16
+ * unanswered slot prints as a work order.
17
+ *
18
+ * ## Why the shape check
19
+ *
20
+ * A slot that declares `{}` would otherwise register as "implemented" and light
21
+ * up an editor panel over an object with no methods. Each slot therefore names
22
+ * the members its interface makes REQUIRED, and a declaration missing any of
23
+ * them is `malformed` — reported by name, never silently bound and never
24
+ * silently dropped. This is the same honesty the anti-shim rule asks of the
25
+ * other direction: a wrong "present" claim is as much a defect as a wrong
26
+ * "empty" one.
27
+ *
28
+ * Nothing here calls a declared method. Presence and shape only.
29
+ */
30
+
31
+ import type { SystemAdapters } from '../system-adapter';
32
+ import type { VgaiGameSystemAdapters, VgaiGameSystemEmpty, VgaiGameSystems } from './game-contract';
33
+
34
+ /** The slots a game may declare through the contract (`debug` is projected from
35
+ * `commands`/`state` instead — see {@link VgaiGameSystemAdapters}). */
36
+ export type ContractSystemSlot = keyof VgaiGameSystemAdapters;
37
+
38
+ /**
39
+ * The members each slot's interface makes NON-optional. A declaration missing
40
+ * one of these cannot honour the interface, whatever else it carries.
41
+ *
42
+ * This table is the single place the required surface is spelled; it is checked
43
+ * against the interfaces by the compiler at the point of use below (each list
44
+ * is typed as keys of its own adapter), so it cannot drift into naming a member
45
+ * that does not exist.
46
+ */
47
+ const REQUIRED_MEMBERS: {
48
+ [K in ContractSystemSlot]: readonly (keyof NonNullable<SystemAdapters[K]>)[];
49
+ } = {
50
+ physics: ['ownerOf', 'freeze', 'commit', 'unfreeze'],
51
+ networking: [
52
+ 'peers',
53
+ 'networkId',
54
+ 'authority',
55
+ 'editable',
56
+ 'getConnectionState',
57
+ 'getRoomInfo',
58
+ 'getReplicationStats',
59
+ 'subscribe',
60
+ ],
61
+ navigation: ['hasNavMesh', 'findPath', 'debugMesh'],
62
+ audio: ['setMuted', 'isMuted'],
63
+ renderDebug: ['captureFrame'],
64
+ };
65
+
66
+ /** Fixed slot order, so two reports of the same mount are diffable line for
67
+ * line (the same rule the coverage report's row order follows). */
68
+ export const CONTRACT_SYSTEM_SLOTS: readonly ContractSystemSlot[] = [
69
+ 'physics',
70
+ 'networking',
71
+ 'navigation',
72
+ 'audio',
73
+ 'renderDebug',
74
+ ];
75
+
76
+ /** One slot the game positively answered as having nothing behind it. */
77
+ export interface ContractSystemEmptySlot {
78
+ readonly slot: ContractSystemSlot;
79
+ /** The game's own source-level evidence, verbatim. */
80
+ readonly evidence: string;
81
+ }
82
+
83
+ /** One slot whose declaration could not be honoured, and why. */
84
+ export interface ContractSystemMalformedSlot {
85
+ readonly slot: ContractSystemSlot;
86
+ readonly reason: string;
87
+ }
88
+
89
+ export interface ContractSystemAdapterProjection {
90
+ /** Real adapters, ready to spread onto a `MountedRoot`'s `systems`. */
91
+ readonly bound: Partial<Pick<SystemAdapters, ContractSystemSlot>>;
92
+ /** Slots answered IMPLEMENTED-EMPTY, with the evidence. */
93
+ readonly empty: readonly ContractSystemEmptySlot[];
94
+ /** Slots declared but unusable — bound to nothing, reported by name. */
95
+ readonly malformed: readonly ContractSystemMalformedSlot[];
96
+ }
97
+
98
+ const EMPTY_PROJECTION: ContractSystemAdapterProjection = {
99
+ bound: {},
100
+ empty: [],
101
+ malformed: [],
102
+ };
103
+
104
+ function isEmptyRecord(value: object): value is VgaiGameSystemEmpty {
105
+ return (value as { present?: unknown }).present === false;
106
+ }
107
+
108
+ function missingMembers(slot: ContractSystemSlot, value: object): string[] {
109
+ const missing: string[] = [];
110
+ for (const member of REQUIRED_MEMBERS[slot]) {
111
+ if (typeof (value as Record<string, unknown>)[member as string] !== 'function') {
112
+ missing.push(member as string);
113
+ }
114
+ }
115
+ return missing;
116
+ }
117
+
118
+ /**
119
+ * Read the declared slots and sort each into exactly one verdict. A game that
120
+ * declared no `systemAdapters` at all projects to three empty lists — which is
121
+ * the "nobody answered" case, and is deliberately NOT the same as declaring
122
+ * every slot empty.
123
+ */
124
+ export function projectContractSystemAdapters(
125
+ systems: VgaiGameSystems | undefined | null,
126
+ ): ContractSystemAdapterProjection {
127
+ const declared = systems?.systemAdapters;
128
+ if (!declared) return EMPTY_PROJECTION;
129
+
130
+ const bound: Record<string, unknown> = {};
131
+ const empty: ContractSystemEmptySlot[] = [];
132
+ const malformed: ContractSystemMalformedSlot[] = [];
133
+
134
+ for (const slot of CONTRACT_SYSTEM_SLOTS) {
135
+ const value: unknown = declared[slot];
136
+ if (value === undefined || value === null) continue;
137
+ if (typeof value !== 'object') {
138
+ malformed.push({
139
+ slot,
140
+ reason: `declared as ${typeof value}; expected an adapter object or { present: false, evidence }`,
141
+ });
142
+ continue;
143
+ }
144
+ if (isEmptyRecord(value)) {
145
+ const evidence = (value as VgaiGameSystemEmpty).evidence;
146
+ if (typeof evidence !== 'string' || evidence.trim() === '') {
147
+ // An empty claim with no evidence is exactly the "wrong empty claim"
148
+ // the bar calls a defect — it asserts an absence nobody can re-check.
149
+ malformed.push({
150
+ slot,
151
+ reason: 'declared `present: false` with no `evidence` string to back the absence',
152
+ });
153
+ continue;
154
+ }
155
+ empty.push({ slot, evidence });
156
+ continue;
157
+ }
158
+ const missing = missingMembers(slot, value);
159
+ if (missing.length > 0) {
160
+ malformed.push({
161
+ slot,
162
+ reason: `declared an adapter missing required member(s): ${missing.join(', ')}`,
163
+ });
164
+ continue;
165
+ }
166
+ bound[slot] = value;
167
+ }
168
+
169
+ return {
170
+ bound: bound as ContractSystemAdapterProjection['bound'],
171
+ empty,
172
+ malformed,
173
+ };
174
+ }