调用 AnchorEntity 的初始化程序时没有完全匹配

No exact matches in call to initializer for AnchorEntity

嗨,我正在尝试制作一个 AR 面部跟踪项目,但是在将面部锚点分配给 AnchorEntity 时出现错误。错误消息是“在对初始化程序的调用中没有完全匹配”。我尝试了不同的方法,但它根本不起作用。我是 swift 的新手,有人可以帮我解决这个问题吗?谢谢

func makeCoordinator() -> Coordinator {
     Coordinator(self)
}
    
class Coordinator: NSObject, ARSessionDelegate {
      var parent: ARViewContainer
      var faceAnchorEntity: AnchorEntity
      var arView: ARView
    
      init(_ parent: ARViewContainer) {
          self.parent = parent
          self.faceAnchorEntity = AnchorEntity()
          self.arView = ARView()
      }
        
      func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {
           guard let faceAnhcor = anchors[0] as? ARFaceAnchor else { return }
           parent.viewModel.vertices = faceAnhcor.geometry.vertices
           faceAnchorEntity = AnchorEntity(anchor: faceAnhcor)
           arView.scene.addAnchor(faceAnhcor) 
      }  
}

你可以使用 RealityKit 的原生 .face 目标,这更容易实现。

import SwiftUI
import RealityKit
import ARKit 

func makeUIView(context: Context) -> ARView {

    let arView = ARView(frame: .zero)
    let ball = ModelEntity(mesh: .generateSphere(radius: 0.07))
    arView.session.run(ARFaceTrackingConfiguration())
    
    let anchor = AnchorEntity(.face)
    anchor.position.y += 0.04
    anchor.addChild(ball)
    arView.scene.addAnchor(anchor)
    return arView
}