@margoengine/xr 0.0.0-stage → 0.1.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 (52) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +592 -3
  4. package/dist/ar-extra.d.ts +167 -0
  5. package/dist/ar-extra.js +247 -0
  6. package/dist/ar.d.ts +177 -0
  7. package/dist/ar.js +195 -0
  8. package/dist/body.d.ts +58 -0
  9. package/dist/body.js +134 -0
  10. package/dist/controller.d.ts +32 -0
  11. package/dist/device-check.d.ts +39 -0
  12. package/dist/device-check.js +155 -0
  13. package/dist/errors-XvcwUnU4.js +7 -0
  14. package/dist/eye-target.d.ts +25 -0
  15. package/dist/eyes.d.ts +24 -0
  16. package/dist/gizmo.d.ts +165 -0
  17. package/dist/gizmo.js +198 -0
  18. package/dist/hands.d.ts +48 -0
  19. package/dist/hands.js +198 -0
  20. package/dist/hit-test.d.ts +69 -0
  21. package/dist/index.d.ts +148 -0
  22. package/dist/index.js +957 -0
  23. package/dist/interaction.d.ts +136 -0
  24. package/dist/interaction.js +205 -0
  25. package/dist/launch.d.ts +65 -0
  26. package/dist/launch.js +54 -0
  27. package/dist/layers-BTUTAawG.js +391 -0
  28. package/dist/layers.d.ts +247 -0
  29. package/dist/layers.js +1 -0
  30. package/dist/locomotion.d.ts +63 -0
  31. package/dist/locomotion.js +184 -0
  32. package/dist/models.d.ts +136 -0
  33. package/dist/models.js +335 -0
  34. package/dist/near.d.ts +465 -0
  35. package/dist/near.js +643 -0
  36. package/dist/occlusion.d.ts +49 -0
  37. package/dist/occlusion.js +218 -0
  38. package/dist/performance.d.ts +67 -0
  39. package/dist/performance.js +78 -0
  40. package/dist/pointer.d.ts +93 -0
  41. package/dist/pointer.js +205 -0
  42. package/dist/reflection.d.ts +70 -0
  43. package/dist/reflection.js +147 -0
  44. package/dist/renderer.d.ts +21 -0
  45. package/dist/scene-owner-BRObO-WJ.js +15 -0
  46. package/dist/scene-owner.d.ts +3 -0
  47. package/dist/scene-scope-DufD_3B6.js +42 -0
  48. package/dist/session.d.ts +60 -0
  49. package/dist/session.js +68 -0
  50. package/dist/shared/xr-run.d.ts +64 -0
  51. package/dist/types.d.ts +221 -0
  52. package/package.json +153 -6
@@ -0,0 +1,148 @@
1
+ /// <reference lib="esnext.disposable" preserve="true" />
2
+ import { type Engine, type EnginePlugin, type FrameGraph } from '@margoengine/core/extension';
3
+ import { type EngineKernel, type EngineOptions } from '@margoengine/core';
4
+ import type { XREyeTarget } from './eye-target.js';
5
+ export type { XREyeTarget } from './eye-target.js';
6
+ import { XRController } from './controller.js';
7
+ export { XRController } from './controller.js';
8
+ export { HitTest, type Hit, type HitTestHost, type HitTestOptions } from './hit-test.js';
9
+ import type { XRBinding, XRFrameState, XRMode, XRNativeSession, XRProjectionLayer, XRSpace } from './types.js';
10
+ export type { XRBinding, XRFrameState, XRMode, XRNativeFrame, XRNativeSession, XRInputSource, XRInputPose, XRPose, XRSpace, XRView, XRViewerPose, XRProjectionLayer, XRSubImage, XRSystem, XRAnchor, XRHitTestResult, XRHitTestSource, XRHitTestTrackableType, XRRayLike, XRTransientInputHitTestResult, XRTransientInputHitTestSource, } from './types.js';
11
+ /** Options for {@link XR.create} and {@link XR.attach}. */
12
+ export interface XRCreateOptions {
13
+ /** Abandons the wait for the device and releases it. */
14
+ signal?: AbortSignal;
15
+ /** Render layer mask both eyes draw; default every layer. See {@link XR.layers}. */
16
+ layers?: number;
17
+ }
18
+ /** Options for {@link XR.requestSession}. */
19
+ export interface XRSessionOptions {
20
+ /** Space of frame poses. Default 'local' (immersive) or 'viewer' (inline). */
21
+ referenceSpace?: 'viewer' | 'local' | 'local-floor' | 'bounded-floor' | 'unbounded';
22
+ /** Features the session must have, such as 'hand-tracking'; the request fails without them. */
23
+ requiredFeatures?: string[];
24
+ /** Features used when granted, such as 'hit-test'. */
25
+ optionalFeatures?: string[];
26
+ /**
27
+ * More session init members from WebXR modules, passed to `navigator.xr.requestSession` as given: for example
28
+ * `{ depthSensing: DEPTH_SENSING }` from `@margoengine/xr/ar`. The feature lists above win over any given here.
29
+ */
30
+ init?: Record<string, unknown>;
31
+ /** Projection resolution relative to the runtime recommendation. Default native 1, or installXR's setting on compatibility. */
32
+ framebufferScale?: number;
33
+ /** Abort while the browser negotiates the session or the layer is set up: the session is ended and the request rejects with the reason. */
34
+ signal?: AbortSignal;
35
+ /** Called once per XR frame with reused state; copy anything you keep. Return false to own rendering with renderFrame(). */
36
+ onFrame?: (state: XRFrameState) => unknown;
37
+ }
38
+ /**
39
+ * Creates a WebGPU engine on an XR-compatible adapter (WebXR/WebGPU binding: `requestAdapter({xrCompatible: true})`),
40
+ * so `XR.create` shares its GPU device and draws each eye through the engine's own frame graph: lines, points,
41
+ * terrain, shadows and post effects appear in both eyes as on the desktop. Takes the options of `Engine.create`;
42
+ * `backend` is always 'webgpu'. After a device loss and restore the engine's new device is not XR-compatible, and a new
43
+ * `XR.create` draws through a device of its own, as with a plain engine.
44
+ * @throws MargoError 'unsupported' without WebGPU.
45
+ */
46
+ export declare function createXREngine(canvas: HTMLCanvasElement, options?: Omit<EngineOptions, 'backend'>): Promise<EngineKernel>;
47
+ /** WebGPU WebXR plugin: negotiates a session, tracks inputs and draws the scene in stereo. `using` or `dispose()` detaches it. */
48
+ export declare class XR implements EnginePlugin {
49
+ private readonly device;
50
+ /** Plugin name, 'xr'. */
51
+ readonly name = "xr";
52
+ /** The active native session, or null. */
53
+ session: XRNativeSession | null;
54
+ /**
55
+ * How the eyes are drawn. 'engine': through the engine's frame graph on its own device (an engine from
56
+ * `createXREngine`), so every package pass and post effect draws. 'separate': on a device of XR's own, which draws
57
+ * core meshes and loader PBR models only.
58
+ */
59
+ readonly route: 'engine' | 'separate';
60
+ private mask?;
61
+ /**
62
+ * Render layer mask both eyes draw (@margoengine/cameras/layers), on either route; undefined (default) draws every
63
+ * layer. A first-person avatar sets the mask of its head-free view here: `xr.layers = firstPerson.firstPersonLayers`.
64
+ * @throws RangeError for a mask that is not an integer from 0 to 0xffffffff.
65
+ */
66
+ get layers(): number | undefined;
67
+ set layers(mask: number | undefined);
68
+ private engine;
69
+ private readonly renderer?;
70
+ private eyes?;
71
+ private context?;
72
+ private binding?;
73
+ private layer?;
74
+ private space?;
75
+ private handle;
76
+ private pending;
77
+ private disposed;
78
+ private lost;
79
+ private last;
80
+ private mode;
81
+ private callback?;
82
+ private readonly listeners;
83
+ /** One controller per current input source; updated each XR frame and kept in step with the session's inputs. */
84
+ readonly controllers: XRController[];
85
+ private readonly state;
86
+ private readonly renderOptions;
87
+ private insideFrame;
88
+ private resume;
89
+ /** True while composition layers sit below the scene, so the scene keeps alpha where it draws nothing. */
90
+ private seeThrough;
91
+ /** True when the browser can start `mode`: WebXR (and for immersive modes WebGPU bindings) is present and supports it. */
92
+ static isSupported(mode?: XRMode): Promise<boolean>;
93
+ /** Prepare before the click handler so requestSession preserves the browser's user activation. */
94
+ static attach(engine: EngineKernel, options?: XRCreateOptions): Promise<XR>;
95
+ /** Creates the XR-compatible GPU device and adds the plugin to `engine`. `signal` abandons the wait and releases the device. */
96
+ static create(engine: EngineKernel, options?: XRCreateOptions): Promise<XR>;
97
+ private constructor();
98
+ /** Its device was lost (one reaction per device, called by `watchLost`). */
99
+ private lostDevice;
100
+ setup(engine: Engine): void;
101
+ /**
102
+ * Calls `callback` every XR frame of every session, after the poses and controllers update and before the session's
103
+ * own `onFrame`; packages such as `XRModels` follow the inputs through it. Returns the function that stops it.
104
+ */
105
+ onFrame(callback: (state: XRFrameState) => void): () => void;
106
+ private readonly eyeListeners;
107
+ /** Runs for each immersive eye after its scene renders and before GPU submission. Returns an unsubscribe function. */
108
+ onEye(callback: (target: XREyeTarget) => void): () => void;
109
+ private readonly drawEye;
110
+ /** The session's reference space (the space of frame poses and hit results); undefined without a session. */
111
+ get referenceSpace(): XRSpace | undefined;
112
+ /**
113
+ * Replaces the space of frame poses, controllers and hits for the rest of the session: `Locomotion` from
114
+ * `@margoengine/xr/layers` passes an offset of the current one (WebXR `getOffsetReferenceSpace`) to teleport and turn.
115
+ */
116
+ useReferenceSpace(space: XRSpace): void;
117
+ /** The active immersive projection layer, including its baseLayer on compatibility; undefined otherwise. */
118
+ get projectionLayer(): XRProjectionLayer | undefined;
119
+ /** The immersive session's WebGPU binding and the device its layers use; undefined otherwise. For `XRLayers`. */
120
+ get layerBinding(): {
121
+ binding: XRBinding;
122
+ device: GPUDevice;
123
+ } | undefined;
124
+ /**
125
+ * Shows `below`, then the scene, then `above` (WebXR Layers: composited in order with source-over). While any layer is
126
+ * below, the scene keeps alpha where it draws nothing, as in AR, so the layers show through. For `XRLayers`.
127
+ */
128
+ setLayers(below: readonly object[], above: readonly object[]): void;
129
+ private readonly uncaptured;
130
+ registerPasses(graph: FrameGraph): void;
131
+ /** Starts a session (call from a user gesture). Rejects if one is active or pending; `options.signal` cancels it. */
132
+ requestSession(mode?: XRMode, options?: XRSessionOptions): Promise<XRNativeSession>;
133
+ private readonly frame;
134
+ /** Render the current tracked eyes (or mirror) from onFrame. Return false there to suppress the automatic draw. */
135
+ renderFrame(): void;
136
+ private readonly sourcesChanged;
137
+ private fail;
138
+ private readonly ended;
139
+ /** Ends the active session (no-op without one) and restarts the window render loop. */
140
+ end(): Promise<void>;
141
+ /** Ends any session, destroys the XR GPU device and removes the plugin. Safe to call twice. */
142
+ dispose(): void;
143
+ /** Same as {@link XR.dispose}, for `using`. */
144
+ [Symbol.dispose]: () => void;
145
+ }
146
+ export { XR as XRManager };
147
+ /** Request using a manager prepared before the user gesture. The caller owns manager disposal. */
148
+ export declare function useXRSession(manager: XR, mode?: XRMode, options?: XRSessionOptions): Promise<XRNativeSession>;