-1

I need to create WebAR using iPhone 12's LiDAR sensor.

Is that possible to get permission or API to access it?

Kindly suggest me the good reference for my requirement.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220

1 Answers1

1

AR QuickLook content implementation

In 2019 Apple released AR Quick Look framework allowing you to create a web-based Augmented Reality experience browsing Safari. QuickLook is based on RealityKit engine, it's easy to implement and conveniently to use. It automatically uses LiDAR Scanner if your iPhone has it. If there's no LiDAR Scanner on-board, it runs regular plane detection feature.

Here's a Swift sample code for native Xcode project:

import ARKit
import QuickLook

extension ViewController: QLPreviewControllerDelegate,
                          QLPreviewControllerDataSource {
    
    func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
        return 1
    }
    
    func previewController(_ controller: QLPreviewController, 
                    previewItemAt index: Int) -> QLPreviewItem {
        
        guard let path = Bundle.main.path(forResource: "file", ofType: "usdz")
        else { fatalError("Couldn't find a model") }
        
        let url = URL(fileURLWithPath: path)           
        return url as QLPreviewItem
    }
}

class ViewController: UIViewController {
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        let previewController = QLPreviewController()
        previewController.delegate = self
        previewController.dataSource = self            
        self.present(previewController, animated: true, completion: nil)
    }
}

enter image description here


Web AR content implementation

To activate your USDZ model through web resource, use the following HTML tags:

<div>
    <a rel="ar" href="/assets/models/bicycle.usdz">
        <img src="/assets/models/bicycle-image.jpg">
    </a>
</div>

You cannot access the LiDAR scanner's parameters when you enable AR Quick Look via iOS Safari. If your iPhone has a LiDAR on-board, it will be used automatically.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220