在 QLPreviewController 中禁用 AR 对象遮挡

Disable AR Object occlusion in QLPreviewController

我正在使用 QLPreviewController 来显示 AR 内容。对于带有 LIDAR 的较新 iPhone,对象遮挡似乎默认启用。

有没有什么方法可以在 QLVideoController 中禁用对象遮挡而无需构建自定义 ARKit 视图控制器?由于我的模型很大(真人大小的建筑物),它们似乎在最后消失或被切断。

ARQuickLook 是一个为快速和高质量的 AR 可视化而构建的库。它采用 RealityKit 引擎,因此这里支持的所有功能,如遮挡、锚点、光线跟踪阴影、物理、DoF、运动模糊、HDR 等,看起来与它们在 RealityKit 中的外观相同。

但是,您无法在 QuickLook 的 API 中打开 on/off 这些功能。如果您的 iPhone 支持,它们默认为 on。如果你想转 on/off People Occlusion 你必须使用 ARKit/RealityKit 框架,而不是 QuickLook。

class ViewController: UIViewController {
    
    @IBOutlet var arView: ARView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let box = try! Experience.loadBox()
        arView.scene.anchors.append(box)
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        self.switchOcclusion()
    }
    
    fileprivate func switchOcclusion() {
        
        guard let config = arView.session.configuration as?
                                                   ARWorldTrackingConfiguration
        else { return }
        
        guard ARWorldTrackingConfiguration.supportsFrameSemantics(
                                                  .personSegmentationWithDepth)
        else { return }
        
        switch config.frameSemantics {           
            case [.personSegmentationWithDepth]: 
                     config.frameSemantics.remove(.personSegmentationWithDepth)
            default: 
                     config.frameSemantics.insert(.personSegmentationWithDepth)
        }           
        arView.session.run(config)
    }
}

请特别注意 People Occlusion 支持 A12 及更高版本的芯片组。如果您 运行 iOS 12 岁或更高,它就有效。


P.S.

QuickLook 唯一可自定义的对象是来自 class ARQuickLookPreviewItem.

的对象

Use ARQuickLookPreviewItem class when you want to control the background, designate which content the share sheet shares, or disable scaling in case it's not appropriate to allow the user to scale a particular model.