Core Usage
Use XRSessionManager with any WebGL2 renderer without Three.js
If you are using a custom renderer, Babylon.js, or any other WebGL2 library, import from @multisetai/vps/core. This entry point has zero peer dependencies.
Setup
import { MultisetClient, XRSessionManager } from '@multisetai/vps/core';
const client = new MultisetClient({
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
mapType: 'map',
code: 'MAP_XXXXXXXXXX',
});
await client.authorize();Create the Session Manager
Pass a WebGL2RenderingContext from your canvas and a session options object.
const canvas = document.getElementById('canvas') as HTMLCanvasElement;
const gl = canvas.getContext('webgl2')!;
const session = new XRSessionManager(gl, {
client,
autoLocalize: true,
onSessionStart: () => {
console.log('AR session started');
},
onSessionEnd: () => {
console.log('AR session ended');
},
onLocalizationResult: (result) => {
const { position, rotation, confidence } = result.localizeData;
console.log('Pose found:', position, rotation, 'confidence:', confidence);
},
onLocalizationFailure: (reason) => {
console.warn('Localization failed:', reason);
},
onError: (error) => {
console.error('Session error:', error);
},
});Handle XR Frames
Register a frame handler to drive your own render loop. The SDK owns the WebXR session; your handler receives everything you need per frame.
Mount the AR Button
createButton() returns a pre-styled <button> that handles start and stop. It must be activated by a user gesture (click/tap) to satisfy browser security requirements.
Or trigger the session manually from your own button:
Handle Localization Results
If you want to react to localization from outside the frame handler, use the session callbacks. To also access the result handler used by adapters, register an adapter result handler:
Manual Localization
With autoLocalize: false, trigger localization on demand:
Cleanup
Checking Support
Last updated
Was this helpful?

