WebXR Integration
Integrate MultiSet VPS localization with your Web apps
Last updated
Integrate MultiSet VPS localization with your Web apps
Last updated
To try WebAR sample localization, open the developer portal in Chrome browser for Android navigate to the Maps sections and click on the AR button
Objective: Obtain the camera's intrinsic parameters—focal lengths (fx
, fy
) and principal points (px
, py
).
Method:
Use the projectionMatrix
from the XR view to calculate intrinsics.
Compute principal points using elements p[8]
and p[9]
of the projection matrix, adjusted by the viewport dimensions.
Calculate focal lengths using p[0]
and p[5]
, scaled by half the viewport width and height.
Objective: Capture the current camera frame as an image for processing.
Method:
Within the XR session, use XRWebGLBinding
to access the camera image texture.
Convert the WebGL texture to an image by:
Creating a framebuffer and attaching the texture.
Reading pixel data from the framebuffer.
Flipping the image vertically to correct orientation.
Drawing the pixel data onto a canvas.
Converting the canvas content to a JPEG data URL.
Objective: Send the captured image and camera intrinsics to a server to obtain localization data.
Method:
Create a FormData
object containing:
Camera intrinsics (fx
, fy
, px
, py
).
Image dimensions (width
, height
).
The image as a JPEG blob (queryImage
).
The map identifier (mapId
) and coordinate system flag (isRightHanded = true
).
Use a function like queryAPI(formData)
to send a POST request to the server with the form data.
Handle the server's response, which should include localization data such as position and rotation.
Objective: Update the AR scene based on the localization data received from the server.
Method:
Parse the API response to extract position and rotation data.
Create Three.js vectors and quaternions from the response data.
Construct transformation matrices to apply the position and rotation to the scene objects.
Adjust for any coordinate system differences (e.g., We flip it around the z axis).
Apply the calculated transformations to the parent and child objects in the scene hierarchy:
Child Object: Set its position and apply rotation adjustments.
Parent Object: Apply rotations to align the child correctly within the scene.
Grandparent Object: Adjust based on the camera's current position and orientation to correct any errors.
Update the scene to make the virtual content visible and correctly aligned with the real world.