当我在 ARKit 中切换到 People Occlusion (.personSegmentationWithDepth) 时,ARSCNView 有时会冻结。 下面的代码在 iOS 14.1 之前对我来说很好用。或者。现在,当切换到 .personSegmentationWithDepth 时,相机不会冻结,这只是幸运
func setupScene() {
sceneView.delegate = self
sceneView.session.delegate = self
sceneView.autoenablesDefaultLighting = true
sceneView.scene = scene
}
func initSceneSession() {
let configuration = ARWorldTrackingConfiguration()
configuration.planeDetection = .horizontal
sceneView.session.run(configuration, options: [.resetTracking, .removeExistingAnchors])
}
func switchPeopleOcc(on: Bool){
guard let config = sceneView.session.configuration as? ARWorldTrackingConfiguration,
ARWorldTrackingConfiguration.supportsFrameSemantics(.personSegmentationWithDepth) else { return
}
switch on {
case true:
config.frameSemantics.insert(.personSegmentationWithDepth)
case false:
config.frameSemantics.remove(.personSegmentationWithDepth)
}
sceneView.session.run(config)
}