【问题标题】:Get the direction arrow toward the SCNNode once that node is not visible in ARCamera一旦该节点在 ARCamera 中不可见,获取指向 SCNNode 的方向箭头
【发布时间】:2019-04-04 15:16:22
【问题描述】:

如果 ARCamera 向左、向右、向上或向下移动,并且该节点在 ARCamera 中变得不可见。我想指出你需要向上/向下/向右/向左移动相机的箭头。

【问题讨论】:

  • 您好,您有没有找到一种方法来检测节点的方向,即向左或向右。如果您能提供一些示例代码将会很有帮助。

标签: ios swift xcode arkit scnnode


【解决方案1】:
    if let pointOfView = sceneView.pointOfView{
        let isMaybeVisible = sceneView.isNode((displayNode.presentation), insideFrustumOf: pointOfView)
        if isMaybeVisible{
            if arrowVisible{
                 arrow.removeFromParentNode()
            }
        }else{
            if !arrowVisible{
                 sceneView.pointOfView?.addChildNode(arrow)
            }
        }
    }

isNode(_:insideFrustumOf:) 在这里检查节点是否在 ARCamera 中可见。
renderer(_:updateAtTime:)里面使用它

编辑: 这里的箭头是一个节点(3d 箭头)。记住箭头的点需要面对-z轴

    let scene = SCNScene(named: "art.scnassets/arrow.dae")
    let arrow = scene?.rootNode.childNode(withName: "arrow", recursively: false)
    arrow.constraints = [SCNLookAtConstraint.init(target: node)]

【讨论】:

  • 感谢您的回答,它适用于第一步。在 ARCamera 中看不到的那个节点的方向呢?
  • 以上代码中的箭头需要arrow.constraints = [SCNLookAtConstraint.init(target: displayNode)]SCNLookAtConstraint
  • 感谢@Alok Subedi
  • 对不起,迟到了;)我尝试了上述建议的方法,但没有奏效。也许是因为我做错了? :) 您能否发布指向节点的箭头/方向的示例代码?
  • 你好@AlokSubedi,你能否提供一个hot的示例代码来检测节点的方向,即左或右。这会很有帮助。
猜你喜欢
  • 2022-06-10
  • 1970-01-01
  • 2013-05-15
  • 1970-01-01
  • 2013-01-17
  • 2010-09-25
  • 1970-01-01
  • 2015-01-05
  • 2018-11-22
相关资源
最近更新 更多