@vgai/engine 0.2.0

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 (147) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +35 -0
  3. package/package.json +55 -0
  4. package/src/adapter/authoring.ts +402 -0
  5. package/src/adapter/colyseus-networking-adapter.ts +72 -0
  6. package/src/adapter/first-party-systems.ts +103 -0
  7. package/src/adapter/game-adapter.ts +151 -0
  8. package/src/adapter/host-context.ts +77 -0
  9. package/src/adapter/index.ts +85 -0
  10. package/src/adapter/ingest/game-contract.ts +59 -0
  11. package/src/adapter/ingest/overlay-applier.ts +207 -0
  12. package/src/adapter/ingest/overlay-apply.ts +124 -0
  13. package/src/adapter/ingest/overlay-file.ts +126 -0
  14. package/src/adapter/ingest/overlay-report.ts +176 -0
  15. package/src/adapter/ingest/scene-capture.ts +307 -0
  16. package/src/adapter/ingest/upstream-pin.ts +52 -0
  17. package/src/adapter/loop-gate-report.ts +54 -0
  18. package/src/adapter/rapier-physics-adapter.ts +56 -0
  19. package/src/adapter/system-adapter.ts +154 -0
  20. package/src/adapter/transform.ts +18 -0
  21. package/src/adapter/vgai-scene-game-adapter.ts +886 -0
  22. package/src/adapter/world-kind.ts +34 -0
  23. package/src/ai/navigation.ts +164 -0
  24. package/src/animation/anim-graph-types.ts +56 -0
  25. package/src/animation/anim-graph.ts +406 -0
  26. package/src/animation/anim-system.ts +28 -0
  27. package/src/animation/blend-node.ts +119 -0
  28. package/src/animation/property-track.ts +178 -0
  29. package/src/animation/schema.ts +204 -0
  30. package/src/assets.ts +80 -0
  31. package/src/audio/ambient.ts +300 -0
  32. package/src/audio/impacts.ts +212 -0
  33. package/src/audio/index.ts +7 -0
  34. package/src/audio/movement.ts +140 -0
  35. package/src/audio/musical.ts +200 -0
  36. package/src/audio/ui-sounds.ts +171 -0
  37. package/src/audio/vehicle.ts +235 -0
  38. package/src/audio/weapons.ts +152 -0
  39. package/src/core/game-loop.ts +127 -0
  40. package/src/core/system-runner.ts +298 -0
  41. package/src/core/types.ts +58 -0
  42. package/src/dev/console-bridge.ts +83 -0
  43. package/src/dev/debug-draw.ts +80 -0
  44. package/src/dev/logger.ts +119 -0
  45. package/src/ecs/component-manager.ts +748 -0
  46. package/src/ecs/game-component.ts +147 -0
  47. package/src/ecs/hmr-swap-report.ts +65 -0
  48. package/src/input/input-manager.ts +439 -0
  49. package/src/input/input-types.ts +19 -0
  50. package/src/input/schema.ts +129 -0
  51. package/src/loader.ts +70 -0
  52. package/src/manifest/index.ts +24 -0
  53. package/src/manifest/load-file.ts +16 -0
  54. package/src/manifest/load.ts +378 -0
  55. package/src/manifest/schema.ts +375 -0
  56. package/src/physics/collision-system.ts +76 -0
  57. package/src/physics/physics-registry.ts +83 -0
  58. package/src/physics/transform-writer.ts +41 -0
  59. package/src/physics/trigger-dispatch.ts +97 -0
  60. package/src/react/game-state.tsx +172 -0
  61. package/src/render/auto-batcher.ts +169 -0
  62. package/src/render/render-batch-system.ts +268 -0
  63. package/src/render/render-features.ts +146 -0
  64. package/src/render/render-settings.ts +72 -0
  65. package/src/runtime/create-runtime.ts +1152 -0
  66. package/src/runtime/frame-selector-cache.ts +81 -0
  67. package/src/runtime/game.ts +1003 -0
  68. package/src/runtime/input-router.ts +213 -0
  69. package/src/runtime/mount-game.ts +269 -0
  70. package/src/runtime/mount-manifest.ts +361 -0
  71. package/src/runtime/scene-ui-bridge.ts +86 -0
  72. package/src/runtime/scene-ui-data.ts +119 -0
  73. package/src/runtime/state-bridge.ts +79 -0
  74. package/src/runtime/types.ts +196 -0
  75. package/src/scene/asset-loaders.ts +195 -0
  76. package/src/scene/asset-paths.ts +123 -0
  77. package/src/scene/asset-registry.ts +67 -0
  78. package/src/scene/collider-dimensions.ts +125 -0
  79. package/src/scene/component-registry.ts +40 -0
  80. package/src/scene/defaults.ts +164 -0
  81. package/src/scene/geometries/index.ts +7 -0
  82. package/src/scene/geometries/terrain.ts +42 -0
  83. package/src/scene/geometry-registry.ts +42 -0
  84. package/src/scene/instance-registry.ts +84 -0
  85. package/src/scene/instancers/grid.ts +38 -0
  86. package/src/scene/instancers/index.ts +7 -0
  87. package/src/scene/light-camera-factory.ts +97 -0
  88. package/src/scene/material-factory.ts +211 -0
  89. package/src/scene/material-registry.ts +73 -0
  90. package/src/scene/materials/index.ts +7 -0
  91. package/src/scene/materials/water.ts +56 -0
  92. package/src/scene/parse.ts +71 -0
  93. package/src/scene/particles-factory.ts +383 -0
  94. package/src/scene/scene-apply.ts +356 -0
  95. package/src/scene/scene-diff-schema.ts +115 -0
  96. package/src/scene/scene-diff-types.ts +29 -0
  97. package/src/scene/scene-loader.ts +1533 -0
  98. package/src/scene/scene-query.ts +63 -0
  99. package/src/scene/scene-types.ts +34 -0
  100. package/src/scene/scene-version.ts +40 -0
  101. package/src/scene/schema/animation.ts +95 -0
  102. package/src/scene/schema/audio.ts +25 -0
  103. package/src/scene/schema/camera.ts +21 -0
  104. package/src/scene/schema/collider.ts +69 -0
  105. package/src/scene/schema/entity-ref.ts +78 -0
  106. package/src/scene/schema/entity.ts +169 -0
  107. package/src/scene/schema/environment.ts +384 -0
  108. package/src/scene/schema/index.ts +95 -0
  109. package/src/scene/schema/instances.ts +35 -0
  110. package/src/scene/schema/joint.ts +26 -0
  111. package/src/scene/schema/light.ts +38 -0
  112. package/src/scene/schema/material.ts +113 -0
  113. package/src/scene/schema/mesh.ts +108 -0
  114. package/src/scene/schema/particles.ts +398 -0
  115. package/src/scene/schema/physics.ts +49 -0
  116. package/src/scene/schema/scene-file.ts +299 -0
  117. package/src/scene/schema/shadow.ts +24 -0
  118. package/src/scene/schema/spline.ts +21 -0
  119. package/src/scene/schema/tuples.ts +21 -0
  120. package/src/scene/schema/ui.ts +602 -0
  121. package/src/scene/user-data.ts +203 -0
  122. package/src/setup/setup-audio.ts +60 -0
  123. package/src/setup/setup-particles.ts +23 -0
  124. package/src/setup/setup-physics.ts +67 -0
  125. package/src/setup/setup-renderer.ts +529 -0
  126. package/src/types-n8ao.d.ts +37 -0
  127. package/src/types-realism-effects.d.ts +61 -0
  128. package/src/world2d/authoring-2d.ts +208 -0
  129. package/src/world2d/capture-to-scene2d.ts +52 -0
  130. package/src/world2d/collision-2d.ts +106 -0
  131. package/src/world2d/components-2d.ts +86 -0
  132. package/src/world2d/index.ts +66 -0
  133. package/src/world2d/ingest-iframe-2d.ts +255 -0
  134. package/src/world2d/ingest2d.ts +131 -0
  135. package/src/world2d/physics2d-registry.ts +49 -0
  136. package/src/world2d/pixi-game-adapter.ts +325 -0
  137. package/src/world2d/pixi-surface.ts +78 -0
  138. package/src/world2d/scene-capture-2d.ts +117 -0
  139. package/src/world2d/scene2d-loader.ts +308 -0
  140. package/src/world2d/schema/entity2d.ts +145 -0
  141. package/src/world2d/schema/physics2d.ts +53 -0
  142. package/src/world2d/schema/sprite.ts +71 -0
  143. package/src/world2d/schema/tilemap.ts +22 -0
  144. package/src/world2d/schema/tuples2d.ts +25 -0
  145. package/src/world2d/system-adapters-2d.ts +49 -0
  146. package/src/world2d/transform-writer-2d.ts +24 -0
  147. package/src/world2d/types.ts +55 -0
@@ -0,0 +1,24 @@
1
+ import type { Physics2DRegistry } from './physics2d-registry';
2
+
3
+ /**
4
+ * Build the single postPhysics transform writer for world2d — the ~5-line 2D
5
+ * analog of `createTransformWriter`.
6
+ *
7
+ * Rapier 2D reports `translation()` as `{x, y}` and `rotation()` as a SCALAR angle
8
+ * (radians), so the writeback is simply `display.position.set(x, y)` +
9
+ * `display.rotation = angle`. Scale is left untouched (Rapier carries no scale).
10
+ *
11
+ * Bodies are simulated in world2d pixel space directly (the surface uses a
12
+ * y-down, pixel-unit world), so no unit conversion is needed; parented entities
13
+ * are kept flat under the world container by the loader, mirroring the 3D writer's
14
+ * scene-root fast path.
15
+ */
16
+ export function createTransformWriter2D(physics: Physics2DRegistry) {
17
+ return function writeTransforms2D(): void {
18
+ for (const [display, { body }] of physics.entries()) {
19
+ const t = body.translation();
20
+ display.position.set(t.x, t.y);
21
+ display.rotation = body.rotation();
22
+ }
23
+ };
24
+ }
@@ -0,0 +1,55 @@
1
+ import type RAPIER from '@dimforge/rapier2d-compat';
2
+ import type { Application, Container } from 'pixi.js';
3
+ import type { z } from 'zod';
4
+ import type { createSystemRunner } from '../core/system-runner';
5
+ import type { SystemPhaseName } from '../core/types';
6
+ import type { ComponentManager } from '../ecs/component-manager';
7
+ import type { GameComponent } from '../ecs/game-component';
8
+ import type { Collision2DSystem } from './collision-2d';
9
+ import type { Physics2DRegistry } from './physics2d-registry';
10
+
11
+ /**
12
+ * All world2d subsystems, passed to every world2d `setup(ctx)` and to each
13
+ * `GameComponent<'pixijs'>` lifecycle method — the 2D analog of `GameContext`.
14
+ *
15
+ * Raw libraries (call directly, no wrappers): `app` / `stage` (PixiJS),
16
+ * `rapier2dWorld` / `rapier2d` (Rapier 2D). Engine handles bridge them into the
17
+ * SAME phase-ordered loop the 3D path uses (`systems` is the very same
18
+ * `createSystemRunner`, and `PHASE_ORDER` is shared).
19
+ */
20
+ export interface World2DContext {
21
+ /** The PixiJS application. Its renderer draws `stage`; auto-ticker is disabled. */
22
+ app: Application;
23
+ /** The world2d scene-graph root (the camera/world container under app.stage). */
24
+ stage: Container;
25
+ /** The Rapier 2D physics `World`. One shared world per world2d scene. */
26
+ rapier2dWorld: RAPIER.World;
27
+ /** The Rapier 2D module namespace (RigidBodyDesc, ColliderDesc, Vector2, …). */
28
+ rapier2d: typeof RAPIER;
29
+ /** `Container ↔ Rapier2D body/collider` registry (+ collider→entity reverse index). */
30
+ physics2d: Physics2DRegistry;
31
+ /** Rapier 2D collision/trigger event dispatcher; drained each postPhysics. */
32
+ collisions2d: Collision2DSystem;
33
+ /** Manager for all live GameComponent instances in this pixi world — the
34
+ * unified `ComponentManager` (`ecs/component-manager.ts`, constructed with
35
+ * `{ kind: 'pixijs' }`). The world2d-silo-only manager this replaced
36
+ * (T7.3) is deleted; every 2D component attaches here, exactly like a
37
+ * threejs component attaches onto its world's manager. */
38
+ components: ComponentManager;
39
+ /** The phase-ordered system runner (shared with the 3D path). */
40
+ systems: ReturnType<typeof createSystemRunner>;
41
+ /** DOM overlay for screen-space React/HUD UI (pointer-events:none by default). */
42
+ uiContainer: HTMLDivElement;
43
+ }
44
+
45
+ /** Constructor type for `GameComponent<'pixijs'>` subclasses used in a world2d
46
+ * registry (carries static phase/schema) — the 2D-registry analog of
47
+ * `GameComponentClass` (`ecs/game-component.ts`), narrowed to the pixijs kind
48
+ * so `new Cls()` returns a properly-typed `GameComponent<'pixijs'>` without a cast. */
49
+ export type Pixi2DComponentClass = (new () => GameComponent<'pixijs'>) & {
50
+ phase?: SystemPhaseName;
51
+ schema?: z.ZodObject<z.ZodRawShape>;
52
+ };
53
+
54
+ /** Component registry for world2d — a plain name→class map (the 2D analog). */
55
+ export type Component2DRegistry = Record<string, Pixi2DComponentClass>;