Implement custom AR button
This document describes how to integrate a custom button into your application to display Roomle product configurations in Augmented Reality (AR) on mobile devices.
Last updated
This document describes how to integrate a custom button into your application to display Roomle product configurations in Augmented Reality (AR) on mobile devices.
Last updated
Overview:
Roomle's AR functionality leverages the native AR frameworks of iOS (AR Quick Look) and Android (Google Scene Viewer). Therefore, the implementation of an AR button must be device-dependent.
Device Detection: First, determine if the user is accessing the page with an iOS, Android, or Desktop device.
Fetching Data: Depending on the device, the appropriate 3D model (USDZ for iOS, glTF/GLB for Android) is fetched via the Roomle API.
Launching AR View:
iOS: The USDZ model is opened directly in the AR Quick Look viewer.
Android: A specific Intent link is constructed and invoked to launch the GLB model in the Google Scene Viewer.
Desktop: A QR code is displayed, linking to a mobile landing page. This page then performs steps 1-3 for mobile devices.
Prerequisites:
You need a valid configurationId
for the Roomle product you want to display in AR.
You have to save the configuration to get the :
Implementation Details:
1. Device Detection:
Implement logic (e.g., using JavaScript navigator.userAgent
or a suitable library) to identify the user's operating system. You need to differentiate between iOS, Android, and others (Desktop).
2. Fetching 3D Assets:
Use the following Roomle API V2 endpoints to get the URLs for the required 3D files. Replace :configurationId
with the ID of your configuration.
For iOS (USDZ):
JavaScript
For Android (GLB):
JavaScript
3. Launching AR View:
iOS Implementation:
Call getUsdzUrl(configurationId)
to get the URL for the USDZ file.
Redirect the browser directly to this URL. iOS recognizes the .usdz
extension and automatically opens the AR Quick Look viewer.JavaScript
Android Implementation:
Call getGlbUrl(configurationId)
to get the URL for the GLB file.
Construct the following Intent link. Important: The glbUrl
must be URL-encoded before being inserted into the intent string.JavaScript
When this Intent link is invoked, Android opens the Google Scene Viewer with the 3D model.
Desktop Implementation:
If a desktop device is detected, display a QR code instead of a direct link.
The QR code should encode a URL pointing to a specially created mobile landing page (e.g., https://your-domain.com/ar-mobile?configId=YOUR_CONFIG_ID
).
On this mobile landing page, perform the device detection again (Step 1) and then trigger the appropriate iOS or Android implementation (Step 3).
You can use JavaScript libraries (like qrcode.js
) to dynamically generate the QR code in the browser, or create it server-side.