3

我正在尝试使用 Apple 的 ARKit 3.0(Reality Kit)设置面部锚,但失败了。1. 以前只支持前置摄像头。还是这样吗?2、如何让Reality Kit的ARView使用前置摄像头?3. 后置摄像头可能无法使用其他任何原因?

附上一个简单的片段

谢谢 !

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

1 回答 1

2

ARFaceTrackingConfiguration您可以在 RealityKit 中使用前置摄像头进行面部跟踪,方法是ARView这样设置session

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
    }

于 2019-10-11T04:40:56.020 回答