swift - 如何在 ARKit 中停止实时跟踪图像并将 SCNNode 保留在场景中?
问题描述
我可以跟踪一个对象并在其上方放置一个文本,它工作得非常好。我使用这个函数来创建我的 SCNNode:
func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
let node = SCNNode()
if let _ = anchor as? ARImageAnchor {
let virtualNode = VirtualObjectNode(text: "ho ho ho")
node.addChildNode(virtualNode)
textNode = node
let scene = SCNScene()
scene.rootNode.addChildNode(node)
sceneView.scene = scene
}
return node
}
现在我想将我的文本保持在它出现的第一个位置并停止跟踪对象......但我无法做到这一点。我创建了这个全局变量:
var textNode: SCNNode?
如您所见,我在创建文本后填充它,并在“didAdd node”函数中使用此代码将其添加到新场景中:
guard let planeAnchor = anchor as? ARPlaneAnchor else { return }
guard let planeGeoemtry = ARSCNPlaneGeometry(device: sceneView.device!) else { fatalError() }
planeAnchor.addPlaneNode(on: node, geometry: planeGeoemtry, contents: UIColor.yellow.withAlphaComponent(0.1))
DispatchQueue.main.async(execute: {
node.addChildNode(self.textNode!)
})
但它只是行不通!
解决方案
推荐阅读
- flutter - 使用 BLoC 模式,如何最好地处理不会导致状态更改的事件(例如日志)?
- google-cloud-firestore - firestore 可以用于公司内部应用程序吗?
- python - 切片 jax.numpy 数组时性能下降
- algorithm - 给定边的最短路径
- django - 将过滤后的数据传递给模板时出错。未找到反向。已尝试 1 种模式。应该使用什么查询来避免此错误?
- expo - 安装后运行 expo --version 时找不到 expo 命令
- syslog - syslog 和 kern.log 文件很大
- python - 构建一个梦幻足球应用程序。如果玩家名称不在 JSON 数据文件中,则将分数设置为零。听起来很简单,但我如何让它工作呢?
- python - 创建数组列但出现错误:TypeError: 'list' object is not callable in PySpark
- python - 我想使用 PyPDF 模块获取 pdf 文件中的所有字段,得到错误:- TypeError: 'NoneType' object is not iterable