@margoengine/xr 0.1.0 → 1.0.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.
@@ -37,7 +37,7 @@ export interface TrackedImageInit {
37
37
  }
38
38
  /** Chooses the current marker-tracking feature or legacy image-tracking feature explicitly. */
39
39
  export interface ImageTrackingSessionOptions {
40
- /** Use image-tracking/getImageTrackingScores on older runtimes. Default false. */
40
+ /** Use the image-tracking feature and getTrackedImageScores of Chrome's shipped module. Default false. */
41
41
  legacy?: boolean;
42
42
  }
43
43
  /** Configures image targets before session negotiation. Default current marker-tracking feature. */
@@ -75,6 +75,71 @@ export declare class ImageTracking {
75
75
  dispose(): void;
76
76
  [Symbol.dispose]: () => void;
77
77
  }
78
+ /** Session options for the WebXR marker tracking module: markers (QR codes) the runtime finds itself, no targets. */
79
+ export declare function markerTrackingSessionOptions(base?: XRSessionOptions): XRSessionOptions;
80
+ /**
81
+ * Which tracking module a session runs: `'markers'` for the marker tracking module (discovered markers,
82
+ * `getMarkerTrackingResults`), `'images'` for the image tracking module (targets given at session start), or null.
83
+ * Both may be granted under the `'marker-tracking'` name, so this reads the session's members.
84
+ */
85
+ export declare function trackingModule(session: XRNativeSession | null): 'markers' | 'images' | null;
86
+ /** The physical size of a found marker. */
87
+ export interface MarkerExtent {
88
+ readonly widthInMeters: number;
89
+ readonly heightInMeters: number;
90
+ }
91
+ /** A copied marker observation, retained independently of the browser frame. */
92
+ export interface TrackedMarker {
93
+ /**
94
+ * A number the tracker gives each marker the runtime reports as one object; it holds while the runtime keeps that
95
+ * object, so use it as a map key. A marker lost, or paused, may come back under a new number.
96
+ */
97
+ readonly id: number;
98
+ /** `'emulated'` while the runtime holds a marker it can no longer see. */
99
+ readonly trackingState: 'tracked' | 'emulated';
100
+ /** The decoded payload (a QR code's text), or null while the runtime has none. */
101
+ readonly payload: string | null;
102
+ /** The marker's measured size, or null while unknown. */
103
+ readonly extent: MarkerExtent | null;
104
+ /** Pose of the marker centre in the host reference space (x-y is the marker face), or null while unavailable. */
105
+ readonly matrix: Float32Array | null;
106
+ }
107
+ /** Marker tracking subscriptions. */
108
+ export interface MarkerTrackingOptions {
109
+ /** Called once per frame with copied observations. Default no callback; markers remains available. */
110
+ onUpdate?: (markers: readonly TrackedMarker[]) => void;
111
+ /** Remove frame and session listeners on abort. */
112
+ signal?: AbortSignal;
113
+ }
114
+ /** Tracks the markers a marker tracking session finds, with pause and resume. */
115
+ export declare class MarkerTracking {
116
+ private readonly host;
117
+ private readonly options;
118
+ /** Current copied observations in the runtime's order; replaced every frame. */
119
+ markers: readonly TrackedMarker[];
120
+ private readonly lifetime;
121
+ private disposed;
122
+ private readonly ids;
123
+ private nextId;
124
+ private wanted;
125
+ /** Attaches after negotiating markerTrackingSessionOptions. */
126
+ static attach(host: ARExtraHost, options?: MarkerTrackingOptions): MarkerTracking;
127
+ private constructor();
128
+ /**
129
+ * True while the runtime looks for markers, or is asked to from the next frame; false after pause() or when the
130
+ * session does not say.
131
+ */
132
+ get active(): boolean;
133
+ /** Stops the runtime looking for markers, to save power, as the next frame begins; observations empty from it. */
134
+ pause(): void;
135
+ /** Starts the runtime looking for markers again as the next frame begins. */
136
+ resume(): void;
137
+ private request;
138
+ private update;
139
+ /** Unsubscribes and clears observations; tracking itself is left as it is. Idempotent. */
140
+ dispose(): void;
141
+ [Symbol.dispose]: () => void;
142
+ }
78
143
  /** Browser mesh detection object. */
79
144
  export interface XRDetectedMesh {
80
145
  readonly meshSpace: XRSpace;
package/dist/ar-extra.js CHANGED
@@ -1,4 +1,4 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
3
 
4
4
  import { n as e } from "./errors-XvcwUnU4.js";
@@ -18,7 +18,7 @@ function a(e, t = {}) {
18
18
  };
19
19
  }
20
20
  var o = class e {
21
- static attach(t, n, r = {}) {__margoAssertCore(t,__margoCoreRequirement("0.1.0",import.meta.url));
21
+ static attach(t, n, r = {}) {__margoAssertCore(t,__margoCoreRequirement("1.0.0",import.meta.url));
22
22
  return new e(t, n, r);
23
23
  }
24
24
  constructor(e, t, n) {
@@ -87,23 +87,24 @@ var c = (t, n) => {
87
87
  }
88
88
  }
89
89
  }, u = class t {
90
- static attach(e, n = {}) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
90
+ static attach(e, n = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
91
91
  return new t(e, n);
92
92
  }
93
- constructor(e, t) {
94
- this.host = e, this.options = t, this.images = /* @__PURE__ */ new Map(), this.disposed = !1;
95
- let n = e.session?.enabledFeatures?.includes("marker-tracking") ? "marker-tracking" : "image-tracking";
96
- this.lifetime = new l(c(e, n), t.signal, () => this.dispose()), this.lifetime.stops.push(e.onFrame((e) => this.update(e)));
93
+ constructor(t, n) {
94
+ this.host = t, this.options = n, this.images = /* @__PURE__ */ new Map(), this.disposed = !1;
95
+ let r = t.session, i = r?.enabledFeatures?.includes("marker-tracking") ? "marker-tracking" : "image-tracking";
96
+ if (f(r) === "markers") throw e("unsupported", "The session runs the marker tracking module, which finds markers itself; use MarkerTracking");
97
+ this.lifetime = new l(c(t, i), n.signal, () => this.dispose()), this.lifetime.stops.push(t.onFrame((e) => this.update(e)));
97
98
  }
98
99
  async trackability(t) {
99
- let n = this.lifetime.session, r = n.getImageTrackability ?? n.getImageTrackingScores;
100
+ let n = this.lifetime.session, r = n.getImageTrackability ?? n.getTrackedImageScores;
100
101
  if (!r) throw e("unsupported", "The session cannot report image trackability; use a runtime with the image tracking module");
101
102
  return this.lifetime.abort.signal.throwIfAborted(), t?.throwIfAborted(), Object.freeze([...await this.lifetime.wait(r.call(n), t)]);
102
103
  }
103
104
  update(t) {
104
105
  if (this.disposed || t.frame.session !== this.lifetime.session) return;
105
106
  let n = t.frame.getImageTrackingResults;
106
- if (!n) throw e("unsupported", "The frame has no image tracking results; request marker-tracking or legacy image-tracking");
107
+ if (!n) throw e("unsupported", "getMarkerTrackingResults" in t.frame ? "The session runs the marker tracking module, which finds markers itself; use MarkerTracking" : "The frame has no image tracking results; request marker-tracking or legacy image-tracking");
107
108
  let r = /* @__PURE__ */ new Map(), i = this.host.referenceSpace;
108
109
  for (let e of n.call(t.frame)) {
109
110
  let n = i ? t.frame.getPose(e.imageSpace, i) : null;
@@ -124,7 +125,74 @@ var c = (t, n) => {
124
125
  [Symbol.dispose ?? Symbol()]() {
125
126
  this.dispose();
126
127
  }
127
- }, d = class a {
128
+ };
129
+ function d(e = {}) {
130
+ return {
131
+ ...e,
132
+ requiredFeatures: [.../* @__PURE__ */ new Set([...e.requiredFeatures ?? [], "marker-tracking"])]
133
+ };
134
+ }
135
+ function f(e) {
136
+ if (!e) return null;
137
+ let t = e;
138
+ return "markerTrackingActive" in t || typeof t.pauseMarkerTracking == "function" ? "markers" : typeof t.getImageTrackability == "function" || typeof t.getTrackedImageScores == "function" || t.enabledFeatures?.includes("image-tracking") ? "images" : null;
139
+ }
140
+ var p = class t {
141
+ static attach(e, n = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
142
+ return new t(e, n);
143
+ }
144
+ constructor(t, n) {
145
+ this.host = t, this.options = n, this.markers = Object.freeze([]), this.disposed = !1, this.ids = /* @__PURE__ */ new WeakMap(), this.nextId = 1, this.wanted = null;
146
+ let r = c(t, "marker-tracking");
147
+ if (f(r) === "images") throw e("unsupported", "The session runs the image tracking module; use ImageTracking with imageTrackingSessionOptions");
148
+ this.lifetime = new l(r, n.signal, () => this.dispose()), this.lifetime.stops.push(t.onFrame((e) => this.update(e)));
149
+ }
150
+ get active() {
151
+ return !this.disposed && (this.wanted ?? this.lifetime.session.markerTrackingActive === !0);
152
+ }
153
+ pause() {
154
+ this.request(!1);
155
+ }
156
+ resume() {
157
+ this.request(!0);
158
+ }
159
+ request(t) {
160
+ if (this.disposed) throw e("disposed", "Marker tracking is disposed; attach a tracker to an active session");
161
+ let n = t ? "resumeMarkerTracking" : "pauseMarkerTracking";
162
+ if (typeof this.lifetime.session[n] != "function") throw e("unsupported", `The session has no ${n}; use a runtime with the marker tracking module`);
163
+ this.wanted = t;
164
+ }
165
+ update(t) {
166
+ if (this.disposed || t.frame.session !== this.lifetime.session) return;
167
+ if (this.wanted !== null) {
168
+ let e = this.lifetime.session, t = this.wanted;
169
+ this.wanted = null, e[t ? "resumeMarkerTracking" : "pauseMarkerTracking"]();
170
+ }
171
+ let n = t.frame.getMarkerTrackingResults;
172
+ if (!n) throw e("unsupported", "The frame has no marker tracking results; request marker-tracking from a runtime with the marker module");
173
+ let r = this.host.referenceSpace, i = [];
174
+ for (let e of n.call(t.frame)) {
175
+ let n = e.marker, a = r ? t.frame.getPose(n.markerSpace, r) : null, o = n.extent, s = this.ids.get(n);
176
+ s === void 0 && this.ids.set(n, s = this.nextId++), i.push(Object.freeze({
177
+ id: s,
178
+ trackingState: e.trackingState,
179
+ payload: n.payloadString ?? null,
180
+ extent: o ? Object.freeze({
181
+ widthInMeters: o.widthInMeters,
182
+ heightInMeters: o.heightInMeters
183
+ }) : null,
184
+ matrix: a ? new Float32Array(a.transform.matrix) : null
185
+ }));
186
+ }
187
+ this.markers = Object.freeze(i), this.options.onUpdate?.(this.markers);
188
+ }
189
+ dispose() {
190
+ this.disposed || (this.disposed = !0, this.lifetime.stop(), this.markers = Object.freeze([]));
191
+ }
192
+ [Symbol.dispose ?? Symbol()]() {
193
+ this.dispose();
194
+ }
195
+ }, m = class a {
128
196
  static async create(t, n = {}) {
129
197
  let r = c(t, "mesh-detection");
130
198
  n.signal?.throwIfAborted();
@@ -178,8 +246,8 @@ var c = (t, n) => {
178
246
  [Symbol.dispose ?? Symbol()]() {
179
247
  this.dispose();
180
248
  }
181
- }, f = class t {
182
- static attach(e, n = {}) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
249
+ }, h = class t {
250
+ static attach(e, n = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
183
251
  return new t(e, n.signal);
184
252
  }
185
253
  constructor(t, n) {
@@ -244,4 +312,4 @@ var c = (t, n) => {
244
312
  }
245
313
  };
246
314
  //#endregion
247
- export { o as DOMOverlay, u as ImageTracking, d as MeshDetection, f as PersistentAnchors, a as domOverlaySessionOptions, s as imageTrackingSessionOptions };
315
+ export { o as DOMOverlay, u as ImageTracking, p as MarkerTracking, m as MeshDetection, h as PersistentAnchors, a as domOverlaySessionOptions, s as imageTrackingSessionOptions, d as markerTrackingSessionOptions, f as trackingModule };
package/dist/eyes.d.ts CHANGED
@@ -10,15 +10,36 @@ export declare class EyeViews {
10
10
  private readonly offset;
11
11
  private pipelines?;
12
12
  private readonly options;
13
+ /** While true, the AR alpha pass (see `clearAlphaShader`) runs in this object's eye views. */
14
+ private ar;
15
+ /**
16
+ * The engine's premultiplied mark before AR eyes set it, while they hold it: with empty pixels at alpha 0 the eye is
17
+ * premultiplied colour over the real world, so TAA keeps coverage in its history and display transforms take
18
+ * straight colour, as on a TransparentCanvas (shared/straight-display.js).
19
+ */
20
+ private premultipliedBefore?;
21
+ private readonly alphaPipelines;
22
+ private alphaModule?;
23
+ /** The frame graphs holding the AR alpha pass (one per scene drawn), with their removers. */
24
+ private readonly alphaGraphs;
25
+ private readonly alphaDescriptor;
13
26
  constructor(engine: Engine, device: GPUDevice);
27
+ private readonly clearAlpha;
28
+ /** Adds the AR alpha pass to the frame graph of the scene about to be drawn, once per graph. */
29
+ private watchAlpha;
14
30
  /** Moves eye `i`'s camera to `view`: its pose and its projection, with depth reversed. */
15
31
  private place;
16
32
  private eye;
17
33
  /** Makes the eye's textures for a sub-image of `width` by `height`, keeping them while the size holds. */
18
34
  private size;
35
+ private dropCover;
36
+ /** Records the eye's share of drawn samples (see `coverageShader`) and returns the texture holding it. */
37
+ private cover;
19
38
  private build;
20
39
  /** Draws this frame's eyes and puts them in `layer`. `delta` in seconds; `ar` keeps the real world behind the scene. */
21
40
  render(binding: XRBinding, layer: XRProjectionLayer, viewer: XRViewerPose, delta: number, ar: boolean, onEye?: (target: XREyeTarget) => boolean | void, layers?: number): void;
41
+ /** Gives the engine back the premultiplied mark it had before AR eyes. */
42
+ private unmark;
22
43
  /** Frees the eyes' textures and buffers; the engine and its device stay. */
23
44
  dispose(): void;
24
45
  }
package/dist/gizmo.js CHANGED
@@ -1,4 +1,4 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
3
 
4
4
  import { r as e } from "./errors-XvcwUnU4.js";
@@ -102,7 +102,7 @@ var s = [
102
102
  "right",
103
103
  "none"
104
104
  ], p = class t {
105
- static attach(e, n, r = {}) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
105
+ static attach(e, n, r = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
106
106
  return r.signal?.throwIfAborted(), new t(e, n, r);
107
107
  }
108
108
  constructor(t, n, r) {