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

查看:16
本文介绍了获取 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天全站免登陆