为 ARQuickLook 提取 Reality Composer 场景

Extract Reality Composer scene for ARQuickLook

我有一个 Reality Composer 场景,我想将其提取为 usdz 文件或任何可在 ARQuickLook 中使用的文件? 可能吗?

来自 Apple 的 Creating 3D Content with Reality Composer 文档:

You can also save your composition to a .reality file for use as a lightweight AR Quick Look experience in your app or on the web. This allows users to place and preview content in the real world to get a quick sense of what it’s like.

To create a Reality file, choose File > Export > Export Project in the Reality Composer menu, and provide a name for the file. You use the Reality file that gets stored to disk just like you would use a USDZ file, as described in Previewing a Model with AR Quick Look.

在构建时,Xcode 将您的 .rcproject 编译成 .reality 文件,AR Quick Look 接受 .reality 类型的预览项目。这是一个使用 AR Quick Look 预览取自 Apple 的 SwiftStrike TableTop 示例代码的 Experience.rcproject 的示例:

import UIKit
import QuickLook
import ARKit


class ViewController: UIViewController, QLPreviewControllerDataSource {

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

    func numberOfPreviewItems(in controller: QLPreviewController) -> Int { return 1 }

    func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
        guard let path = Bundle.main.path(forResource: "Experience", ofType: "reality") else { fatalError("couldn't find the rcproject file.") }
        let url = URL(fileURLWithPath: path)
        let item = ARQuickLookPreviewItem(fileAt: url)
        return item
    }    
}