尝试在 renderer(_ renderer:didUpdate:for:) 方法中为不同的锚点更新两个不同的节点 看起来它让我只更新一个节点,但我需要两个: ARFaceAnchor 和 ARMeshAnchor 我该如何解决这个问题?
// 1
func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor ) {
if let faceAnchor = anchor as? ARFaceAnchor {
targetFaceGeometry = faceAnchor.geometry
}
}
&
// 2
func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor ) {
if let meshAnchor = anchor as? ARMeshAnchor {
let geometry = createGeometryFromAnchor(meshAnchor: meshAnchor)
geometry.firstMaterial?.colorBufferWriteMask = [.alpha]
node.geometry = geometry
}
}
您可以在一个函数中处理这两种情况
func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
if let faceAnchor = anchor as? ARFaceAnchor {
targetFaceGeometry = faceAnchor.geometry
} else if let meshAnchor = anchor as? ARMeshAnchor {
let geometry = createGeometryFromAnchor(meshAnchor: meshAnchor)
geometry.firstMaterial?.colorBufferWriteMask = [.alpha]
node.geometry = geometry
}
}