Use the AR SpaceCapture API
1. Add AR SpaceCapture to an LWC
In your component’s JavaScript file, import ARSpaceCapture using the standard JavaScript import statement. Specifically, import the getARSpaceCapture() factory function from the lightning/mobileCapabilities module.
1import {getARSpaceCapture} from 'lightning/mobileCapabilities';After it’s imported into your component, use the factory function to get an instance of ARSpaceCapture. With your ARSpaceCapture instance, use the utility functions and constants to verify availability. Then use the feature functions to perform the associated functionality.
2. Test AR SpaceCapture Availability
AR SpaceCapture depends on physical device hardware and platform features. A component that uses SpaceCapture renders without errors on a desktop computer or in a mobile browser, but SpaceCapture functions fail. To avoid these errors, test if SpaceCapture functionality is available before you use it.
1handleCheckARSpaceCaptureClick(event) {
2 const myARSpaceCapture = getARSpaceCapture();
3 if(myARSpaceCapture.isAvailable()) {
4 // Perform next operations
5 } else {
6 // AR SpaceCapture isn't available, or consuming app hasn’t implemented it
7 // Not running on hardware with AR functionality, etc.
8 // Handle with message, error, beep, and so on
9 }
10}3. Start an AR SpaceCapture Scan
Start a room scan with the scanRoom() function. You can then handle the JSON file that represents the USDZ file as required.
For example:
1handleScanRoomClicked(event) {
2 if (this.myARSpaceCapture != null && this.myARSpaceCapture.isAvailable()) {
3 this.myARSpaceCapture.scanRoom()
4 .then((arSpaceCaptureResult) => {
5 console.log(JSON.stringify(arSpaceCaptureResult, undefined, 2))
6 })
7 .catch((error) => {
8 console.log(error);
9 });
10 }
11}- The floor must be leveled when starting the scan.
- A scanned space includes only items that are on the same level.