People Occlusion

Where do I need to add one of these lines of code in order to enable people occlusion in my scene?

config.frameSemantics.insert(.personSegmentationWithDepth)
static var personSegmentationWithDepth: ARConfiguration.FrameSemantics { get }

Here is the code:

import UIKit
import RealityKit
import ARKit

class ViewControllerBarock: UIViewController, ARSessionDelegate {

    @IBOutlet var arView: ARView!

    let qubeAnchor = try! Barock.loadQube()
    var imageAnchorToEntity: [ARImageAnchor: AnchorEntity] = [:]

    override func viewDidLoad() {
        super.viewDidLoad()
        arView.scene.addAnchor(qubeAnchor)
        arView.session.delegate = self
    }

    func session(_ session: ARSession, didAdd anchors: [ARAnchor]){
        anchors.compactMap { $0 as? ARImageAnchor }.forEach {
            let anchorEntity = AnchorEntity()
            let modelEntity = qubeAnchor.stehgreifWurfel!
            anchorEntity.addChild(modelEntity)
            arView.scene.addAnchor(anchorEntity)
            anchorEntity.transform.matrix = $0.transform
            imageAnchorToEntity[$0] = anchorEntity
        }
    }

    func session(_ session: ARSession, didUpdate anchors: [ARAnchor]) {
        anchors.compactMap { $0 as? ARImageAnchor }.forEach {
            let anchorEntity = imageAnchorToEntity[$0]
            anchorEntity?.transform.matrix = $0.transform
        }
    }
}
Answered by Vision Pro Engineer in 738632022

ARView creates and runs an ARSession with a default configuration for you, but you can manually configure it if you need to. To that end, you can disable automatic configuration, make the desired settings, and call run on the session with the updated configuration. You could add the following code for example in viewDidLoad:

arView.automaticallyConfigureSession = false
let config = ARWorldTrackingConfiguration()
guard ARWorldTrackingConfiguration.supportsFrameSemantics(.personSegmentationWithDepth) else {
   print("People occlusion is not supported on this device.")
   return    
}
config.frameSemantics.insert(.personSegmentationWithDepth)
arView.session.run(config)
Accepted Answer

ARView creates and runs an ARSession with a default configuration for you, but you can manually configure it if you need to. To that end, you can disable automatic configuration, make the desired settings, and call run on the session with the updated configuration. You could add the following code for example in viewDidLoad:

arView.automaticallyConfigureSession = false
let config = ARWorldTrackingConfiguration()
guard ARWorldTrackingConfiguration.supportsFrameSemantics(.personSegmentationWithDepth) else {
   print("People occlusion is not supported on this device.")
   return    
}
config.frameSemantics.insert(.personSegmentationWithDepth)
arView.session.run(config)
People Occlusion
 
 
Q