@multisetai/vps 1.0.4

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 MultiSet
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,377 @@
1
+ # Multiset VPS WebXR
2
+
3
+ Multiset VPS WebXR is a TypeScript SDK that enables developers to integrate Multiset's Visual Positioning System (VPS) capabilities into WebXR applications. It provides precise 6-DOF (6 degrees of freedom) localization by matching camera frames against cloud-hosted maps, allowing AR applications to understand their position and orientation in physical space.
4
+
5
+ ## Features
6
+
7
+ - **Core Client** (`@multisetai/vps/core`) - Authentication and API client for Multiset VPS services
8
+ - **WebXR Controller** (`@multisetai/vps/webxr`) - Three.js WebXR session management and frame capture
9
+ - **Framework-agnostic** - Works with React, Vue, Angular, or vanilla JavaScript
10
+ - **TypeScript support** - Full type definitions included
11
+ - **Event-driven architecture** - Comprehensive callbacks for all operations
12
+ - **Precise localization** - 6-DOF pose estimation with position and rotation
13
+ - **Cloud-based mapping** - Leverages Multiset's cloud infrastructure for map storage and matching
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @multisetai/vps three
19
+ ```
20
+
21
+ > **Note**: `three` is a peer dependency and must be installed separately.
22
+
23
+ ## Requirements
24
+
25
+ ### Runtime Requirements
26
+
27
+ - **HTTPS**: WebXR requires a secure context. Use HTTPS in production or `https://localhost` for local development.
28
+ - **WebXR-capable device**: Android device with ARCore or iOS device with ARKit (via WebXR Viewer or Safari)
29
+ - **Modern browser**: Chrome/Edge (Android) or Safari (iOS 15+)
30
+ - **Three.js**: Version 0.176.0 or higher (peer dependency)
31
+
32
+ ### Development Requirements
33
+
34
+ - Node.js 16+ and npm
35
+ - TypeScript 5.8+ (for TypeScript projects)
36
+
37
+ ## Quick Start
38
+
39
+ ### 1. Import the SDK
40
+
41
+ ```typescript
42
+ import { MultisetClient, DEFAULT_ENDPOINTS } from '@multisetai/vps/core';
43
+ import { WebxrController } from '@multisetai/vps/webxr';
44
+ ```
45
+
46
+ ### 2. Create and authorize the client
47
+
48
+ ```typescript
49
+ const client = new MultisetClient({
50
+ clientId: 'your-client-id',
51
+ clientSecret: 'your-client-secret',
52
+ code: 'MAP_YOUR_MAP_CODE',
53
+ mapType: 'map', // or 'map-set'
54
+ endpoints: DEFAULT_ENDPOINTS,
55
+ onAuthorize: (token) => console.log('Authorized:', token),
56
+ onError: (error) => console.error('Error:', error),
57
+ });
58
+
59
+ await client.authorize();
60
+ ```
61
+
62
+ ### 3. Initialize WebXR controller
63
+
64
+ ```typescript
65
+ const controller = new WebxrController({
66
+ client,
67
+ canvas: document.querySelector('canvas'),
68
+ overlayRoot: document.body,
69
+ onSessionStart: () => console.log('AR session started'),
70
+ onSessionEnd: () => console.log('AR session ended'),
71
+ });
72
+
73
+ await controller.initialize();
74
+ ```
75
+
76
+ ### 4. Capture and localize
77
+
78
+ ```typescript
79
+ const result = await controller.captureFrame();
80
+ if (result?.localizeData?.poseFound) {
81
+ console.log('Position:', result.localizeData.position);
82
+ console.log('Rotation:', result.localizeData.rotation);
83
+ }
84
+ ```
85
+
86
+ ## Core Client API
87
+
88
+ ### `MultisetClient`
89
+
90
+ The core client handles authentication and API interactions with Multiset services.
91
+
92
+ #### Constructor
93
+
94
+ ```typescript
95
+ new MultisetClient(config: IMultisetSdkConfig)
96
+ ```
97
+
98
+ **Configuration Options:**
99
+
100
+ ```typescript
101
+ interface IMultisetSdkConfig {
102
+ clientId: string; // Your Multiset client ID
103
+ clientSecret: string; // Your Multiset client secret
104
+ code: string; // Map code (e.g., 'MAP_XXXXX')
105
+ mapType: 'map' | 'map-set'; // Type of map to use
106
+ endpoints?: Partial<IMultisetSdkEndpoints>; // Optional custom endpoints
107
+ onAuthorize?: (token: string) => void;
108
+ onFrameCaptured?: (payload: IFrameCaptureEvent) => void;
109
+ onCameraIntrinsics?: (intrinsics: ICameraIntrinsicsEvent) => void;
110
+ onPoseResult?: (payload: IPoseResultEvent) => void;
111
+ onError?: (error: unknown) => void;
112
+ }
113
+ ```
114
+
115
+ #### Methods
116
+
117
+ ##### `authorize(): Promise<string>`
118
+
119
+ Authenticates with Multiset services and obtains an access token. Must be called before making any API requests.
120
+
121
+ ```typescript
122
+ const token = await client.authorize();
123
+ ```
124
+
125
+ **Returns**: The access token as a string.
126
+
127
+ #### Events
128
+
129
+ The client emits events through callback functions:
130
+
131
+ - **`onAuthorize`**: Called when authorization succeeds with the access token
132
+ - **`onFrameCaptured`**: Called when a camera frame is captured for localization
133
+ - **`onCameraIntrinsics`**: Called with camera intrinsic parameters
134
+ - **`onPoseResult`**: Called with localization results (pose found/not found)
135
+ - **`onError`**: Called when any error occurs
136
+
137
+ ## WebXR Controller API
138
+
139
+ ### `WebxrController`
140
+
141
+ Manages WebXR sessions, Three.js scene, camera, and renderer. Handles AR button creation and frame capture for localization.
142
+
143
+ #### Constructor
144
+
145
+ ```typescript
146
+ new WebxrController(options: IWebxrControllerOptions)
147
+ ```
148
+
149
+ **Configuration Options:**
150
+
151
+ ```typescript
152
+ interface IWebxrControllerOptions {
153
+ client: MultisetClient; // Required: MultisetClient instance
154
+ canvas?: HTMLCanvasElement; // Optional: Canvas element (created if not provided)
155
+ overlayRoot?: HTMLElement; // Optional: Root for DOM overlay (default: document.body)
156
+ buttonContainer?: HTMLElement; // Optional: Container for AR button
157
+ onARButtonCreated?: (button: HTMLButtonElement) => void;
158
+ onSessionStart?: () => void;
159
+ onSessionEnd?: () => void;
160
+ }
161
+ ```
162
+
163
+ #### Methods
164
+
165
+ ##### `initialize(buttonContainer?: HTMLElement): Promise<HTMLButtonElement>`
166
+
167
+ Initializes the WebXR controller, sets up Three.js scene/renderer/camera, and creates the AR button.
168
+
169
+ ```typescript
170
+ const arButton = await controller.initialize(buttonContainer);
171
+ ```
172
+
173
+ **Returns**: The created AR button element.
174
+
175
+ ##### `captureFrame(): Promise<ILocalizeAndMapDetails | null>`
176
+
177
+ Captures the current camera frame and performs localization.
178
+
179
+ ```typescript
180
+ const result = await controller.captureFrame();
181
+ if (result?.localizeData?.poseFound) {
182
+ const { position, rotation, confidence } = result.localizeData;
183
+ console.log('Localized at:', position);
184
+ }
185
+ ```
186
+
187
+ **Returns**: Object with `localizeData` and optional `mapDetails`, or `null` if capture fails.
188
+
189
+ ##### `getScene(): THREE.Scene`
190
+
191
+ Gets the Three.js scene object for adding 3D models and objects.
192
+
193
+ ```typescript
194
+ const scene = controller.getScene();
195
+ const cube = new THREE.Mesh(geometry, material);
196
+ scene.add(cube);
197
+ ```
198
+
199
+ ##### `getCamera(): THREE.PerspectiveCamera`
200
+
201
+ Gets the Three.js camera object for custom camera configuration.
202
+
203
+ ```typescript
204
+ const camera = controller.getCamera();
205
+ camera.near = 0.1;
206
+ camera.far = 1000;
207
+ ```
208
+
209
+ ##### `getRenderer(): THREE.WebGLRenderer`
210
+
211
+ Gets the Three.js WebGL renderer for advanced rendering configuration.
212
+
213
+ ```typescript
214
+ const renderer = controller.getRenderer();
215
+ renderer.shadowMap.enabled = true;
216
+ ```
217
+
218
+ ##### `hasActiveSession(): boolean`
219
+
220
+ Checks if an active WebXR session is currently running.
221
+
222
+ ```typescript
223
+ if (controller.hasActiveSession()) {
224
+ // AR session is active
225
+ }
226
+ ```
227
+
228
+ ##### `dispose(): void`
229
+
230
+ Cleans up resources and removes event listeners. Call this when destroying the controller.
231
+
232
+ ```typescript
233
+ controller.dispose();
234
+ ```
235
+
236
+ ## Type Definitions
237
+
238
+ All TypeScript types are exported from the main entry points:
239
+
240
+ ```typescript
241
+ // Core types
242
+ import type {
243
+ IMultisetSdkConfig,
244
+ IMultisetSdkEndpoints,
245
+ IFrameCaptureEvent,
246
+ ICameraIntrinsicsEvent,
247
+ IPoseResultEvent,
248
+ ILocalizeAndMapDetails,
249
+ MapType,
250
+ } from '@multisetai/vps/core';
251
+
252
+ // WebXR types
253
+ import type {
254
+ IWebxrControllerOptions,
255
+ } from '@multisetai/vps/webxr';
256
+ ```
257
+
258
+ ## Examples
259
+
260
+ ### Vanilla JavaScript
261
+
262
+ ```javascript
263
+ import * as THREE from 'three';
264
+ import { MultisetClient, DEFAULT_ENDPOINTS } from '@multisetai/vps/core';
265
+ import { WebxrController } from '@multisetai/vps/webxr';
266
+
267
+ const client = new MultisetClient({
268
+ clientId: 'your-client-id',
269
+ clientSecret: 'your-client-secret',
270
+ code: 'MAP_YOUR_MAP_CODE',
271
+ mapType: 'map',
272
+ endpoints: DEFAULT_ENDPOINTS,
273
+ onAuthorize: (token) => console.log('Authorized:', token),
274
+ onError: (error) => console.error('Error:', error),
275
+ });
276
+
277
+ const controller = new WebxrController({
278
+ client,
279
+ canvas: document.querySelector('canvas'),
280
+ overlayRoot: document.body,
281
+ onSessionStart: () => console.log('AR session started'),
282
+ onSessionEnd: () => console.log('AR session ended'),
283
+ });
284
+
285
+ // Authorize and initialize
286
+ await client.authorize();
287
+ await controller.initialize();
288
+
289
+ // Add 3D objects to scene
290
+ const scene = controller.getScene();
291
+ const cube = new THREE.Mesh(
292
+ new THREE.BoxGeometry(0.1, 0.1, 0.1),
293
+ new THREE.MeshBasicMaterial({ color: 0xff0077 })
294
+ );
295
+ cube.position.set(0, 0, -0.4);
296
+ scene.add(cube);
297
+
298
+ // Capture and localize
299
+ const result = await controller.captureFrame();
300
+ if (result?.localizeData?.poseFound) {
301
+ console.log('Position:', result.localizeData.position);
302
+ }
303
+ ```
304
+
305
+ ### React
306
+
307
+ ```tsx
308
+ import { useEffect, useRef, useState } from 'react';
309
+ import * as THREE from 'three';
310
+ import { MultisetClient, DEFAULT_ENDPOINTS } from '@multisetai/vps/core';
311
+ import { WebxrController } from '@multisetai/vps/webxr';
312
+
313
+ export default function App() {
314
+ const [authorized, setAuthorized] = useState(false);
315
+ const canvasRef = useRef<HTMLCanvasElement>(null);
316
+ const clientRef = useRef<MultisetClient | null>(null);
317
+ const controllerRef = useRef<WebxrController | null>(null);
318
+
319
+ useEffect(() => {
320
+ clientRef.current = new MultisetClient({
321
+ clientId: 'your-client-id',
322
+ clientSecret: 'your-client-secret',
323
+ code: 'MAP_YOUR_MAP_CODE',
324
+ mapType: 'map',
325
+ endpoints: DEFAULT_ENDPOINTS,
326
+ });
327
+
328
+ controllerRef.current = new WebxrController({
329
+ client: clientRef.current,
330
+ canvas: canvasRef.current!,
331
+ });
332
+
333
+ return () => {
334
+ controllerRef.current?.dispose();
335
+ };
336
+ }, []);
337
+
338
+ const handleAuthorize = async () => {
339
+ await clientRef.current!.authorize();
340
+ await controllerRef.current!.initialize();
341
+
342
+ // Add 3D objects
343
+ const scene = controllerRef.current!.getScene();
344
+ const cube = new THREE.Mesh(
345
+ new THREE.BoxGeometry(0.1, 0.1, 0.1),
346
+ new THREE.MeshBasicMaterial({ color: 0xff0077 })
347
+ );
348
+ scene.add(cube);
349
+
350
+ setAuthorized(true);
351
+ };
352
+
353
+ const handleCapture = async () => {
354
+ const result = await controllerRef.current!.captureFrame();
355
+ if (result?.localizeData?.poseFound) {
356
+ console.log('Localized!', result.localizeData.position);
357
+ }
358
+ };
359
+
360
+ return (
361
+ <div>
362
+ <button onClick={handleAuthorize} disabled={authorized}>
363
+ Authorize
364
+ </button>
365
+ <button onClick={handleCapture} disabled={!authorized}>
366
+ Capture
367
+ </button>
368
+ <canvas ref={canvasRef} />
369
+ </div>
370
+ );
371
+ }
372
+ ```
373
+
374
+ ## License
375
+
376
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
377
+
@@ -0,0 +1,201 @@
1
+ type MapType = 'map' | 'map-set';
2
+ interface IPosition {
3
+ x: number;
4
+ y: number;
5
+ z: number;
6
+ }
7
+ interface IRotation {
8
+ x: number;
9
+ y: number;
10
+ z: number;
11
+ w: number;
12
+ }
13
+ interface ILocalizeResponse {
14
+ poseFound: boolean;
15
+ position: IPosition;
16
+ rotation: IRotation;
17
+ retrieval_scores: number[];
18
+ num_matches: number[];
19
+ confidence: number;
20
+ retreived_imgs: string[];
21
+ mapIds: string[];
22
+ }
23
+ interface IMapLocation {
24
+ type: string;
25
+ coordinates: [number, number, number];
26
+ _id: string;
27
+ }
28
+ interface ICameraIntrinsicsResponse {
29
+ fx: number;
30
+ fy: number;
31
+ px: number;
32
+ py: number;
33
+ }
34
+ interface IMeshInfo {
35
+ type: string;
36
+ meshLink: string;
37
+ }
38
+ interface IMapMesh {
39
+ rawMesh: IMeshInfo;
40
+ texturedMesh: IMeshInfo;
41
+ }
42
+ interface IResolution {
43
+ width: number;
44
+ height: number;
45
+ }
46
+ interface IMapSource {
47
+ provider: string;
48
+ fileType: string;
49
+ coordinateSystem: string;
50
+ }
51
+ interface IGetMapsDetailsResponse {
52
+ _id: string;
53
+ accountId: string;
54
+ mapName: string;
55
+ location: IMapLocation;
56
+ status: string;
57
+ storage: number;
58
+ createdAt: string;
59
+ updatedAt: string;
60
+ cameraIntrinsics: ICameraIntrinsicsResponse;
61
+ mapMesh: IMapMesh;
62
+ resolution: IResolution;
63
+ globalFeature: string;
64
+ mapCode: string;
65
+ source: IMapSource;
66
+ }
67
+ interface IMapSetMapData {
68
+ _id: string;
69
+ order: number;
70
+ relativePose: {
71
+ position: {
72
+ x: number;
73
+ y: number;
74
+ z: number;
75
+ };
76
+ rotation: {
77
+ qx: number;
78
+ qy: number;
79
+ qz: number;
80
+ qw: number;
81
+ };
82
+ };
83
+ createdAt: string;
84
+ updatedAt: string;
85
+ map: {
86
+ _id: string;
87
+ accountId: string;
88
+ mapName: string;
89
+ status: string;
90
+ mapCode: string;
91
+ thumbnail: string;
92
+ storage: number;
93
+ createdAt: string;
94
+ updatedAt: string;
95
+ mapMesh: {
96
+ rawMesh: {
97
+ type: string;
98
+ meshLink: string;
99
+ };
100
+ texturedMesh: {
101
+ type: string;
102
+ meshLink: string;
103
+ };
104
+ };
105
+ coordinates: {
106
+ latitude: number;
107
+ longitude: number;
108
+ altitude: number;
109
+ };
110
+ offlineBundleStatus?: string;
111
+ offlineBundle?: string;
112
+ };
113
+ }
114
+ interface IMapSetMapsResponse {
115
+ mapSet: {
116
+ _id: string;
117
+ name: string;
118
+ accountId: string;
119
+ createdAt: string;
120
+ updatedAt: string;
121
+ status: string;
122
+ mapSetData: IMapSetMapData[];
123
+ };
124
+ }
125
+ interface ILocalizeAndMapDetails {
126
+ localizeData: ILocalizeResponse;
127
+ mapDetails?: IGetMapsDetailsResponse;
128
+ }
129
+
130
+ interface IMultisetSdkConfig {
131
+ clientId: string;
132
+ clientSecret: string;
133
+ code: string;
134
+ mapType: MapType;
135
+ endpoints?: Partial<IMultisetSdkEndpoints>;
136
+ onAuthorize?: (token: string) => void;
137
+ onFrameCaptured?: (payload: IFrameCaptureEvent) => void;
138
+ onCameraIntrinsics?: (intrinsics: ICameraIntrinsicsEvent) => void;
139
+ onPoseResult?: (payload: IPoseResultEvent) => void;
140
+ onError?: (error: unknown) => void;
141
+ }
142
+ interface IMultisetSdkEndpoints {
143
+ authUrl: string;
144
+ queryUrl: string;
145
+ mapDetailsUrl: string;
146
+ fileDownloadUrl: string;
147
+ mapSetDetailsUrl: string;
148
+ }
149
+ interface IFrameCaptureEvent {
150
+ blob: Blob;
151
+ width: number;
152
+ height: number;
153
+ }
154
+ interface ICameraIntrinsicsEvent {
155
+ fx: number;
156
+ fy: number;
157
+ px: number;
158
+ py: number;
159
+ width: number;
160
+ height: number;
161
+ }
162
+ interface IPoseResultEvent {
163
+ poseFound: boolean;
164
+ position: {
165
+ x: number;
166
+ y: number;
167
+ z: number;
168
+ };
169
+ rotation: {
170
+ x: number;
171
+ y: number;
172
+ z: number;
173
+ w: number;
174
+ };
175
+ mapIds: string[];
176
+ confidence?: number;
177
+ }
178
+ interface ILocalizeResultEvent {
179
+ frame: IFrameCaptureEvent;
180
+ intrinsics: ICameraIntrinsicsEvent;
181
+ response: ILocalizeAndMapDetails | null;
182
+ }
183
+ declare const DEFAULT_ENDPOINTS: IMultisetSdkEndpoints;
184
+ /**
185
+ * Placeholder class to be implemented by porting logic from multiset-webxr-sdk.
186
+ */
187
+ declare class MultisetClient {
188
+ private readonly config;
189
+ private readonly endpoints;
190
+ private accessToken;
191
+ constructor(config: IMultisetSdkConfig);
192
+ get token(): string | null;
193
+ authorize(): Promise<string>;
194
+ private handleError;
195
+ localizeWithFrame(frame: IFrameCaptureEvent, intrinsics: ICameraIntrinsicsEvent): Promise<ILocalizeAndMapDetails | null>;
196
+ private queryLocalization;
197
+ private fetchMapDetails;
198
+ private fetchMapSetDetails;
199
+ }
200
+
201
+ export { DEFAULT_ENDPOINTS, type ICameraIntrinsicsEvent, type IFrameCaptureEvent, type IGetMapsDetailsResponse, type ILocalizeAndMapDetails, type ILocalizeResponse, type ILocalizeResultEvent, type IMapSetMapsResponse, type IMultisetSdkConfig as IMultisetClientOptions, type IMultisetSdkConfig, type IMultisetSdkEndpoints, type IPoseResultEvent, type MapType, MultisetClient };