多个ARSCNViews,并且在ARKit Face Tracking中仅显示面网格

时间:2019-08-18 17:37:23

标签: xcode arkit face

按照Apple的ARKit代码示例,我能够在真实的面孔上显示Face Mesh。现在我只想在单独的ARSCN视图中显示面部网格,即一个视图显示真实面部,第二个视图仅显示面部网格(因此稍后我可以对其进行修改,例如制作头像)。怎么做?

据说可以同时运行ARSCN视图,例如看到, Is it possible to run two ARSCNView at the same time?

但是我无法运行第二个场景,其中仅显示面部网格。这是我的代码:

override func viewDidLoad() {
    super.viewDidLoad()

    guard ARFaceTrackingConfiguration.isSupported else { fatalError() }
    sceneView.delegate = self


    sceneView.isPlaying = true // this is my first scene view
    transformView.isPlaying = true // second scene view


}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    let configuration = ARFaceTrackingConfiguration()

    sceneView.session.run(configuration)
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)

    sceneView.session.pause()
}

extension FaceTrackViewController: ARSCNViewDelegate {

func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
    guard let faceAnchor = anchor as? ARFaceAnchor,
        //          let device = sceneView.MTLDevice else { return nil }
        let device = MTLCreateSystemDefaultDevice() else { return nil }
    let faceGeometry = ARSCNFaceGeometry(device: device)
    let node = SCNNode(geometry: faceGeometry)
    node.geometry?.firstMaterial?.fillMode = .lines

    node.geometry?.firstMaterial?.transparency = 0.5

    return node



}



func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
    guard let faceAnchor = anchor as? ARFaceAnchor, let faceGeometry = node.geometry as? ARSCNFaceGeometry else { return }

    faceGeometry.update(from: faceAnchor.geometry)

}

仅显示在我的真实面部上重叠有面部网格的第一个场景视图

0 个答案:

没有答案