Map Creation
Scan a space into a new VPS map with the iOS SDK, with LiDAR or on any ARKit device: setup, scanning, drafts, background uploads and the API.
Overview
From version 2.1.0 the iOS SDK can scan a space, package the capture, keep it on the device as a draft, and upload it to your account, where it is built into a VPS map. The capture format and the upload live inside MultiSetSDK.xcframework. MultiSetAR/Mapping/ supplies the ARKit side, and the demo app's MultiSet-iOS-SDK/Views/Mapping/ the screens, which you can reuse.
There are two kinds of scan (MappingCaptureKind):
LiDAR (.lidar)
Camera images, depth and a reconstructed mesh
A LiDAR scanner
The reconstructed mesh
Non-LiDAR (.posedRGB)
Camera images and their poses
World tracking only
ARKit's feature points, and how well tracking is going
Both upload the same package layout; a Non-LiDAR package has no depth or mesh. Prefer LiDAR where the device has it. A Non-LiDAR map depends on good tracking, so scan textured, well-lit spaces and move slowly. The upload follows the mobile map upload format.
Setup
Add
MultiSetAR/to your target, includingMapping/andMapping/ScanMeshSurface.metal(in Compile Sources).Forward the background upload session's wake-up from your app delegate, so an upload that finishes while your app is not running is recorded:
func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) { MultiSet.shared.mapping.handleEventsForBackgroundURLSession( identifier: identifier, completionHandler: completionHandler) }Scans are recorded in landscape. Return the adapter's lock from your app delegate, or the scan screen rotates with the device. Outside the scan screen the lock answers with the orientations your
Info.plistdeclares, so the rest of your app is unaffected:func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { OrientationLock.shared.mask }Call
await MultiSet.shared.mapping.resumeUploads()when your app becomes active, for example fromsceneDidBecomeActive(_:).
The demo app's AppDelegate.swift and SceneDelegate.swift do all three. No background mode is needed. The camera and location usage descriptions in the Info.plist configuration cover scanning; without location access a scanned map carries no coordinates.
Scanning
Offer only the kinds in MappingSupport.captureKinds: both on a LiDAR device, .posedRGB alone without one. A .lidar source on a device without LiDAR previews, then fails at Start with MappingFailure.Reason.sessionError and a message saying why.
Scan rules the SDK enforces:
A scan shorter than
MappingLimits.minimumScanDuration(10 s) is discarded, andstopScan()returns.discardedTooShort. The SDK stops a scan atMappingLimits.maximumScanDuration(600 s) by itself.Starting needs about 1.5 GB of free space for a LiDAR scan and 600 MB for a Non-LiDAR scan.
A map name must be at least
MappingLimits.minimumMapNameLength(3) characters once trimmed.Frames too blurred to use are dropped;
scan.showsMotionWarningturns on when the device moves too fast for a sharp capture.An interruption (a call, the app leaving the foreground) ends the scan, because tracking afterwards is in a different world frame. A scan past the minimum is packaged as it stood; a shorter one fails.
ARMappingSourcereports interruptions for you, andscan.autoStopReasonsays why the SDK stopped a scan by itself.
A Non-LiDAR scan adds:
A frame is kept only when the camera has moved 5 cm or turned 5° since the last kept frame, and only once tracking has held for a second (two after a loss). Frames taken in the second before tracking is lost, or before ARKit corrects its pose in a jump, are deleted;
scan.discardedFramescounts them.scan.trackinggrades tracking (good, weak, lost) with the reason, andscan.trackingAdvicenames a problem that has lasted, at most once every few seconds, for a toast.scan.walkedAreais the floor area the kept frames cover, once they span a metre.A warm device captures less often (
scan.isCapturingSlowly). The scan stops by itself if free space falls below what packaging needs.Packaging can be stopped with
cancelPackaging();resumePackaging()starts it again anddiscardScan()deletes the scan.
Observing
Read state from MultiSet.shared.mapping when one of these is posted on the main thread:
.multiSetMappingScanDidChange
scan: phase, elapsed time, packaging progress, frame counts, motion warning, and for Non-LiDAR the tracking status and advice
.multiSetMappingDraftsDidChange
drafts()
.multiSetMappingUploadsDidChange
uploadState(for:)
A failed scan reports MappingPhase.failed(MappingFailure), whose message is written for the user. Call acknowledgeFailure() once it has been shown. MappingPhase and the other mapping enums can gain cases, so a switch over them needs @unknown default.
Drafts and Uploads
A draft stays until an upload succeeds. Every failure keeps the scan, so a retry never costs another scan.
The transfer runs on a background
URLSession. It continues when the app is backgrounded, locked or terminated.Uploads retry by themselves. An interrupted upload waits 5, 15, 30, 60 and 120 s between attempts. After that it waits for
resumeUploads()or for the network to return.deleteDraft(id:)removes the scan's files and cancels its upload.Files location. Scans are stored in Application Support, not in your app's Documents folder, so they do not appear in the Files app.
The map says how it was captured.
MappingDraft.captureKindtells the two kinds apart, and the map is created with the matching upload type.
Custom Runtimes
To scan with something other than ARKit, implement MultiSetMappingSource.
A
.lidarsource supplies raw camera frames (MappingFrame: a 1920 × 1440420fimage, a 256 × 192DepthFloat32depth map, the camera transform and intrinsics, all from one frame), tracking samples, and the reconstructed mesh at stop.A
.posedRGBsource returns.posedRGBfromcaptureKind, suppliesMappingRGBFrame(a420fimage at the size tracking started with, the transform, the intrinsics and the frame's timestamp) fromacquireRGBFrame(), and passes every camera update toMultiSet.shared.mapping.reportTrackingSample(_:)with its tracking state, feature-point count and light estimate.
Pass every value raw; the SDK does every conversion. A frame of any other size is dropped. Call reportSourceFailure(_:) when your session fails, and reportSourceInterrupted() when it is interrupted. MultiSetAR/Mapping/ARMappingSource.swift is the reference implementation.
API
Demo App Screens
Landing: Mapping card
Scans a space into a new map. On a LiDAR device it offers LiDAR or Non-LiDAR; on any other device it scans Non-LiDAR.
MappingInstructionsView
Capture tips before a scan.
MappingFlowView
The landscape scan screen: start and stop, the scan mesh or feature points, tracking guidance, then naming, saving and uploading.
DraftMapsView
Scans saved on the device and not yet uploaded, with their upload status.
Related
Last updated
Was this helpful?

