【问题标题】:ARKit/RealityKit – People Occlusion config not workingARKit/RealityKit – 人物遮挡配置不起作用
【发布时间】:2020-04-02 02:25:23
【问题描述】:

由于某种原因,即使我在 Stackoverflow 上查看了某人的问题,我也无法让人们使用遮挡。这是我的代码:

//Load ARView
let arView = ARView(frame: .zero)

//Load people occlusion
let session = ARSession()

if let configuration = session.configuration as? ARWorldTrackingConfiguration {
    configuration.frameSemantics.insert(.personSegmentationWithDepth)
    session.run(configuration)
}

//Load custom model(not in use)
let model = try! Entity.loadModel(named: "Mug")

//Load Anchor + Entity
let anchor = AnchorEntity(plane: .horizontal)
let box = MeshResource.generateBox(size: 0.1)
let material = SimpleMaterial(color: .red, isMetallic: true)
let entity = ModelEntity(mesh: box, materials: [material])
arView.scene.anchors.append(anchor)
anchor.addChild(entity)
return arView

我错过了什么?

【问题讨论】:

    标签: swift xcode augmented-reality arkit realitykit


    【解决方案1】:

    您的代码应如下所示:

    let arView = ARView(frame: .zero)
    
    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)
    }
    

    【讨论】:

    • 出于某种原因,我试图完全按照您的回答进行操作,但即使我更改为通用 iOS 设备,我也会得到“'ARViewContainer' 类型的值没有成员 'arView'”
    • 我有这个确切的代码(除了print 必须是fatalError 在guard 块中),它不起作用。似乎有一段时间,arView.session.configuration 是 nil。
    • @Boris,你的 iPhone 型号是什么?
    • @AndyFedoroff 11 英寸 iPad Pro,第 3 代。上个月买的。
    • 试试这样的 - let frame = arView.session.currentFrame 然后guard frame?.estimatedDepthData != nil else { print("depth is being captured") return } 在委托方法renderer(...) 或session(...) 中。
    猜你喜欢
    • 2019-12-07
    • 2020-02-04
    • 2022-01-24
    • 2020-09-23
    • 2021-11-04
    • 2015-05-06
    • 2014-10-06
    • 2022-01-08
    • 1970-01-01
    相关资源
    最近更新 更多