如何通过Web应用程序使用iPhone LiDAR传感器?

问题描述 投票:0回答:1

我需要使用 iPhone 12 的 LiDAR 传感器创建 WebAR。

是否可以获得许可或API来访问它?

请为我的要求推荐好的参考。

augmented-reality arkit realitykit lidar arquicklook
1个回答
1
投票

AR QuickLook 内容实现

2019 年,Apple 发布了 AR Quick Look 框架,允许您创建基于 Web 的增强现实体验浏览 Safari。 QuickLook基于RealityKit引擎,实现简单,使用方便。如果您的 iPhone 有 LiDAR 扫描仪,它会自动使用它。如果机上没有 LiDAR 扫描仪,它会运行常规

plane detection
功能。当您通过 iOS Safari 启用 AR Quick Look 时,您无法访问 LiDAR 扫描仪的参数。如果您的 iPhone 内置 LiDAR,则会自动使用它。

这是本机 Xcode 项目的 Swift 示例代码:

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)
    }
}


Web AR 内容实现

要通过网络资源激活您的 USDZ 模型,请使用以下 HTML 标签:

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

新的 HTML 元素

2023 年,实施了一个名为 <model> 的新 HTML 元素

<body>
    <h1>An example <code>model</code> Element</h1>
    <model interactive width="1419" height="713">
        <source src="assets/FlightHelmet.usdz" type="model/vnd.usdz+zip" />
        <picture>
            <img src="assets/FlightHelmet.png" width="285" height="600" />
        </picture>
    </model>
</body>

© www.soinside.com 2019 - 2024. All rights reserved.