获取ARKIT中聚焦相机的所有ARAnchors [英] Get All ARAnchors of focused Camera in ARKIT

查看:124
本文介绍了获取ARKIT中聚焦相机的所有ARAnchors的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先启动应用程序时,在一个墙上检测到一个垂直表面,而不是相机聚焦到第二个墙上,在第二个墙上检测到另一个表面.现在第一面墙不再对ARCamera可见,但是此代码为我提供了第一面墙的锚点.但是我需要第二个墙的锚点,现在第二个墙是可见的/集中在相机中.

When application launched first a vertical surface is detected on one wall than camera focus to the second wall, in the second wall another surface is detected. The first wall is now no more visible to the ARCamera but this code is providing me the anchors of the first wall. but I need anchors of the second wall which is right now Visible/focused in camera.

if let anchor = sceneView.session.currentFrame?.anchors.first {
    let node = sceneView.node(for: anchor)
    addNode(position: SCNVector3Zero, anchorNode: node)
} else {
    debugPrint("anchor node is nil")
}

推荐答案

为了获得当前处于角度的节点,您可以执行以下操作:

In order to get the node that is currently is in point of view you can do something like this:

       var targettedAnchorNode: SCNNode?
       if let anchors = sceneView.session.currentFrame?.anchors {
           for anchor in anchors {

               if let anchorNode = sceneView.node(for: anchor), let pointOfView = sceneView.pointOfView, sceneView.isNode(anchorNode, insideFrustumOf: pointOfView) {
                   targettedAnchorNode = anchorNode
                   break
               }
           }

           if let targettedAnchorNode = targettedAnchorNode {
               addNode(position: SCNVector3Zero, anchorNode: targettedAnchorNode)
           } else {
               debugPrint("Targetted node not found")
           }

       } else {
           debugPrint("Anchors not found")
       }

如果要获取所有焦点节点,请将它们收集在满足指定条件的数组中

If you would like to get all focused nodes, collect them in an array satisfying specified condition

祝你好运!

这篇关于获取ARKIT中聚焦相机的所有ARAnchors的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆