Swift: Displaying the vertices label properly using SCNText

随声附和 提交于 2021-02-20 03:48:37

问题


I am trying to generate the face mesh from the AR face tutorial with proper vertices label using SCNText. I follow the online tutorial and have the following:

enterextension EmojiBlingViewController: ARSCNViewDelegate {
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)
}
  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)
    for x in [1076, 1070, 1163] {
          let text = SCNText(string: "\(x)", extrusionDepth: 1)
          let txtnode = SCNNode(geometry: text)
          txtnode.scale = SCNVector3(x: 0.001, y: 0.001, z: 0.001)
          txtnode.name = "\(x)"
          node.addChildNode(txtnode)
          txtnode.geometry?.firstMaterial?.fillMode = .fill
      }
    node.geometry?.firstMaterial?.fillMode = .lines
    return node
  }
} 

However, those vertices (1076, 1070, 1163) not show properly- they are overlapped in the centre.

So my question is, does anyone would know how to show (x in [1076, 1070, 1163]) properly in the correct location on the mesh?

Thanks!

Updates: I saw the numbers overlapped and they moved along with the front camera..

来源:https://stackoverflow.com/questions/61965336/swift-displaying-the-vertices-label-properly-using-scntext

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!