ARKit:在 didUpdate 方法中渲染多个锚点和节点

问题描述 投票:0回答:1

尝试在 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
        }
    }
swift arkit renderer aranchor
1个回答
0
投票

您可以在一个函数中处理这两种情况

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
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.