Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RealityKit - Face Anchor

I'm trying to set up a face anchor using Apple's ARKit 3.0 (Reality Kit) but fail. 1. In the past it was only available for front camera. Is it still the case? 2. How can I make Reality Kit's ARView use the front camera? 3. Any other reason face anchor might not work on the back camera?

Attached a simple snippet

Thanks !

import UIKit
import RealityKit

class ViewController: UIViewController {

    @IBOutlet var arView: ARView!

    override func viewDidLoad() {
        super.viewDidLoad()
        let anchor = AnchorEntity(.face)
        arView.scene.addAnchor(anchor)

        let e = Entity()
        e.components[ModelComponent] = ModelComponent(
            mesh: .generateBox(size: [0.1, 0.1, 0.1]),
            materials: [SimpleMaterial(color: UIColor.gray, isMetallic: false)]
        )
        e.setPosition([0,0,0], relativeTo: anchor)
        anchor.addChild(e)
    }
}
like image 932
ori.rdt Avatar asked Apr 18 '26 13:04

ori.rdt


1 Answers

You can use the front camera for face tracking in RealityKit by setting ARFaceTrackingConfiguration on your ARView's session like so:

class ViewController: UIViewController {

   @IBOutlet var arView: ARView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Indicate to use the FaceTrackingConfiguration (front camera)
        guard ARFaceTrackingConfiguration.isSupported else { return }
        let configuration = ARFaceTrackingConfiguration()
        configuration.isLightEstimationEnabled = true

        arView.session.run(configuration, options: [.resetTracking, .removeExistingAnchors])

        // Now, append your anchors to the scene
    }

like image 97
lreichold Avatar answered Apr 23 '26 23:04

lreichold