Get All ARAnchors of focused Camera in ARKIT

后端 未结 2 1024
情深已故
情深已故 2021-02-11 05:22

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. T

2条回答
  •  南旧
    南旧 (楼主)
    2021-02-11 05:49

    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

    Good luck!

提交回复
热议问题