@wonderlandengine/ar-provider-zappar 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.
@@ -0,0 +1,17 @@
1
+ /// <reference path="../../src/types/global.d.ts" />
2
+ import { Component } from '@wonderlandengine/api';
3
+ import { TrackingMode } from '@wonderlandengine/ar-tracking';
4
+ import { ZapparProvider } from './zappar-provider.js';
5
+ /**
6
+ * SLAM tracking implementation backed by Zappar.
7
+ */
8
+ export declare class WorldTracking_Zappar extends TrackingMode {
9
+ private readonly _cameraTransform;
10
+ constructor(provider: ZapparProvider, component: Component);
11
+ init(): void;
12
+ startSession(): void;
13
+ endSession(): void;
14
+ getCameraTransformWorld(): ArrayLike<number> | null;
15
+ getCameraProjectionMatrix(out: Float32Array): boolean;
16
+ update(): void;
17
+ }
@@ -0,0 +1,46 @@
1
+ /// <reference path="./types/global.d.ts" />
2
+ import { quat2 } from 'gl-matrix';
3
+ import { TrackingMode } from '@wonderlandengine/ar-tracking';
4
+ /**
5
+ * SLAM tracking implementation backed by Zappar.
6
+ */
7
+ export class WorldTracking_Zappar extends TrackingMode {
8
+ _cameraTransform = quat2.create();
9
+ constructor(provider, component) {
10
+ super(provider, component);
11
+ }
12
+ init() {
13
+ const input = this.component.object.getComponent('input');
14
+ if (input) {
15
+ // Camera pose will be driven by the AR tracking implementation.
16
+ input.active = false;
17
+ }
18
+ }
19
+ startSession() {
20
+ void this.provider.startSession();
21
+ }
22
+ endSession() {
23
+ void this.provider.endSession();
24
+ }
25
+ getCameraTransformWorld() {
26
+ const provider = this.provider;
27
+ return provider.hasSlamTrackingState ? this._cameraTransform : null;
28
+ }
29
+ getCameraProjectionMatrix(out) {
30
+ const provider = this.provider;
31
+ const projection = provider.slamProjectionMatrix;
32
+ if (!projection)
33
+ return false;
34
+ out.set(projection);
35
+ return true;
36
+ }
37
+ update() {
38
+ const provider = this.provider;
39
+ const pose = provider.slamCameraPoseMatrix;
40
+ if (!pose)
41
+ return;
42
+ // Zappar's THREE.js wrapper treats pipeline.cameraPose*(...) matrices as a camera world transform.
43
+ // Wonderland stores transforms as dual quaternions (8 floats): [rotation quat, translation dual part].
44
+ quat2.fromMat4(this._cameraTransform, pose);
45
+ }
46
+ }
@@ -0,0 +1,5 @@
1
+ export type ZapparNamespace = typeof import('@zappar/zappar');
2
+ type ZapparCore = typeof import('@zappar/zappar/lib/zappar.js');
3
+ export declare function loadZappar(): Promise<ZapparNamespace>;
4
+ export declare function setOptions(opts: Parameters<ZapparCore['setOptions']>[0]): Promise<void>;
5
+ export {};
@@ -0,0 +1,43 @@
1
+ function ensureEditorWindow() {
2
+ if (typeof window !== 'undefined')
3
+ return;
4
+ if (typeof WL_EDITOR === 'undefined' || !WL_EDITOR)
5
+ return;
6
+ const globalObject = globalThis;
7
+ if (!globalObject.window) {
8
+ globalObject.window = globalObject;
9
+ }
10
+ const ensuredWindow = globalObject.window;
11
+ if (!ensuredWindow.location) {
12
+ ensuredWindow.location = { href: '' };
13
+ }
14
+ }
15
+ let zapparPromise = null;
16
+ let zapparCorePromise = null;
17
+ export function loadZappar() {
18
+ if (!zapparPromise) {
19
+ zapparPromise = (async () => {
20
+ ensureEditorWindow();
21
+ return import('@zappar/zappar');
22
+ })();
23
+ }
24
+ return zapparPromise;
25
+ }
26
+ async function loadZapparCore() {
27
+ if (!zapparCorePromise) {
28
+ zapparCorePromise = (async () => {
29
+ ensureEditorWindow();
30
+ return import('@zappar/zappar/lib/zappar.js');
31
+ })();
32
+ }
33
+ return zapparCorePromise;
34
+ }
35
+ export async function setOptions(opts) {
36
+ const [core, main] = await Promise.all([loadZapparCore(), loadZappar()]);
37
+ core.setOptions(opts);
38
+ /* If the main module also has setOptions (it might be re-exported), call it too.
39
+ * This helps if the bundler has duplicated the zappar module instance. */
40
+ if (main.setOptions && main.setOptions !== core.setOptions) {
41
+ main.setOptions(opts);
42
+ }
43
+ }
@@ -0,0 +1,115 @@
1
+ /// <reference path="../../src/types/global.d.ts" />
2
+ /// <reference types="webxr" />
3
+ import { Component, Emitter } from '@wonderlandengine/api';
4
+ import { mat4 } from 'gl-matrix';
5
+ import { ARProvider, ARSession, ITrackingMode, ImageScanningEvent, TrackingType } from '@wonderlandengine/ar-tracking';
6
+ import { loadZappar } from './zappar-module.js';
7
+ import type { FaceMesh, FaceTracker, ImageTracker, Pipeline } from '@zappar/zappar';
8
+ type ZapparImageTargetType = 'flat' | 'cylindrical' | 'conical';
9
+ export interface ZapparImageTargetOptions {
10
+ name: string;
11
+ type?: ZapparImageTargetType;
12
+ physicalWidthInMeters?: number;
13
+ metadata?: unknown;
14
+ }
15
+ interface ZapparImageTargetDescriptor {
16
+ name: string;
17
+ type: ZapparImageTargetType;
18
+ geometry: ImageScanningEvent['imageTargets'][0]['geometry'];
19
+ properties: ImageScanningEvent['imageTargets'][0]['properties'];
20
+ metadata: unknown;
21
+ }
22
+ /**
23
+ * ARProvider implementation backed by the Zappar Universal AR JavaScript SDK.
24
+ */
25
+ export declare class ZapparProvider extends ARProvider {
26
+ private static _cvWorkerConfigured;
27
+ private static _cvWorker;
28
+ /** Mirror Zappar THREE.js `CameraPoseMode` for SLAM pose output. */
29
+ slamPoseMode: 'default' | 'attitude' | 'anchor-origin';
30
+ private _xrSession;
31
+ private _gl;
32
+ private _zappar;
33
+ private pipeline;
34
+ private cameraSource;
35
+ private instantTracker;
36
+ private _faceTracker;
37
+ private _faceMesh;
38
+ private _faceResourcesPromise;
39
+ private _imageTracker;
40
+ private _imageTargetDescriptors;
41
+ private readonly _imageTargetsChanged;
42
+ private cameraStarted;
43
+ private hasInitializedAnchor;
44
+ private _anchorWarmupFramesRemaining;
45
+ private preRenderRegistered;
46
+ private _slamStateValid;
47
+ private readonly _slamProjectionMatrix;
48
+ private readonly _slamAnchorMatrix;
49
+ private _slamFrameNumber;
50
+ private _videoTextureUnit;
51
+ private _videoTextureProgram;
52
+ private _videoTextureUniform;
53
+ private _videoTextureTransformUniform;
54
+ private _videoTextureBindErrorLogged;
55
+ private _missingCameraTextureFrames;
56
+ private _missingCameraTextureWarningLogged;
57
+ private readonly _slamCameraMatrix;
58
+ private readonly _slamCameraPosition;
59
+ private readonly _slamCameraRotation;
60
+ private readonly _debugCameraPosition;
61
+ private readonly _debugAnchorPosition;
62
+ private readonly _debugCameraPositionDelta;
63
+ private readonly _debugAnchorPositionDelta;
64
+ private _debugLastSampleFrameNumber;
65
+ private readonly _debugLastSampleCameraPosition;
66
+ private readonly _debugLastSampleAnchorPosition;
67
+ private _zapparDebugLogIntervalId;
68
+ private _preRenderErrorLogged;
69
+ static Name: string;
70
+ get name(): string;
71
+ get supportsInstantTracking(): boolean;
72
+ get onImageTargetsChanged(): Emitter<void[]>;
73
+ get xrSession(): XRSession | null;
74
+ static registerTrackingProviderWithARSession(arSession: ARSession): ZapparProvider;
75
+ private constructor();
76
+ startSession(): Promise<void>;
77
+ private startZapparDebugLogging;
78
+ private stopZapparDebugLogging;
79
+ private ensureZapparLoaded;
80
+ /** Used by tracking modes that need the Zappar namespace. */
81
+ ensureZapparNamespace(): Promise<Awaited<ReturnType<typeof loadZappar>>>;
82
+ private configureCvWorkerIfNeeded;
83
+ private ensurePipeline;
84
+ getPipeline(): Pipeline;
85
+ ensureFaceResources(): Promise<void>;
86
+ getFaceTracker(): FaceTracker;
87
+ getFaceMesh(): FaceMesh;
88
+ ensureImageTracker(): ImageTracker;
89
+ registerImageTarget(source: string | ArrayBuffer, options: ZapparImageTargetOptions): Promise<void>;
90
+ private _inferImageTargetType;
91
+ private _buildImageTargetGeometry;
92
+ getImageScanningEvent(): ImageScanningEvent;
93
+ getImageTargetDescriptors(): ReadonlyArray<ZapparImageTargetDescriptor>;
94
+ getImageTargetDescriptor(index: number): ZapparImageTargetDescriptor | undefined;
95
+ private ensureCameraRunning;
96
+ private onVisibilityChange;
97
+ private onPreRender;
98
+ /** Latest projection matrix for the SLAM camera (valid only if {@link hasSlamTrackingState} is true). */
99
+ get slamProjectionMatrix(): Readonly<Float32Array> | null;
100
+ /** Latest camera pose matrix for the SLAM camera (valid only if {@link hasSlamTrackingState} is true). */
101
+ get slamCameraPoseMatrix(): Readonly<mat4> | null;
102
+ /** Latest anchor pose matrix (valid only if {@link hasSlamTrackingState} is true). */
103
+ get slamAnchorPoseMatrix(): Readonly<mat4> | null;
104
+ get hasSlamTrackingState(): boolean;
105
+ get slamFrameNumber(): number;
106
+ private bindVideoTextureForSkyMaterial;
107
+ updateTracking(): void;
108
+ endSession(): Promise<void>;
109
+ load(): Promise<void>;
110
+ /** Whether this provider supports given tracking type */
111
+ supports(type: TrackingType): boolean;
112
+ /** Create a tracking implementation */
113
+ createTracking(type: TrackingType, component: Component): ITrackingMode;
114
+ }
115
+ export {};