gpt4 book ai didi

swift - ARKit/RealityKit – People Occlusion 配置不工作

转载 作者:行者123 更新时间:2023-12-04 04:14:36 25 4
gpt4 key购买 nike

出于某种原因,即使我在 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

我错过了什么?

最佳答案

您的代码应如下所示:

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


或者还有一个很酷的解决方案,使用 type(of:) 方法:

let config = ARWorldTrackingConfiguration()
config.planeDetection = [.horizontal]
arView.session.run(config)

if type(of: config).supportsFrameSemantics(.sceneDepth) {
config.frameSemantics = .personSegmentationWithDepth
} else {
print("This device doesn't support segmentation with depth")
}

关于swift - ARKit/RealityKit – People Occlusion 配置不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60983313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com