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)
}
}
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With