//ARSCNViewDelegate
extension FaceTrackingBasicViewController: ARSCNViewDelegate {
func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
guard let device = sceneView.device else {
return nil
}
let faceGeometry = ARSCNFaceGeometry(device: device) //시각화
let node = SCNNode(geometry: faceGeometry) //node에 faceGeometry를 넣어준다.
node.geometry?.firstMaterial?.fillMode = .lines //face에 line을 그려줄것인가
return node
}
//눈을 깜박거리거나, 입을 벌리거나, 얼굴을 움직일때마다 계속 업데이트 시켜준다.
func renderer(_ renderer: SCNSceneRenderer, willUpdate node: SCNNode, for anchor: ARAnchor) {
guard let faceAnchor = anchor as? ARFaceAnchor, let faceGeometry = node.geometry as? ARSCNFaceGeometry else {
return
}
faceGeometry.update(from: faceAnchor.geometry)
}
}