ARKit/RealityKit – 人物遮挡配置不起作用 [英] ARKit/RealityKit – People Occlusion config not working

查看:23
本文介绍了ARKit/RealityKit – 人物遮挡配置不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

For some reason I can't get people occlusion to work, even though I looked at someone's question on Stackoverflow. Here is my code:

//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

我错过了什么?

推荐答案

你的代码应该是这样的:

Your code should look like this:

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

这篇关于ARKit/RealityKit – 人物遮挡配置不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆