ios - 在 ARKit 中检测平面

标签 ios swift arkit

当应用在 ARKit 中检测到至少一架飞机时,我如何收到通知?

我目前正在做这样的事情,但它没有触发/它不相关:

extension MyViewController: ARSCNViewDelegate, ARSessionDelegate {
    internal func setupAR() {
        let scene = SCNScene()
        sceneView.scene = scene
        let configuration = ARWorldTrackingConfiguration()
        configuration.planeDetection = [.horizontal]
        sceneView.session.delegate = self
        sceneView.session.run(configuration)
    }

    public func session(_ session: ARSession, didUpdate anchors: [ARAnchor]) {
        if !anchors.isEmpty {
            print("ANCHORS NOT EMPTY")
            planesDetectedState()
        } else {
            print("Anchors is empty")
        }
    }
}

最佳答案

请先添加 anchor 以更新。您需要使用以下功能:

func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {
        guard let frame = session.currentFrame else { return }
        print("Just added an anchor and felt so good")
}

此外,您将无法看到任何平面,除非您向 anchor 添加一个节点,您可以通过以下方式做到这一点:

func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
        // Add a planeNode and make it a child to the node automatically added.
}

我还建议,下载入门代码,它很容易理解您正在考虑的事情。

https://developer.apple.com/documentation/arkit/building_your_first_ar_experience

关于ios - 在 ARKit 中检测平面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50354915/

相关文章:

ios - 蓝牙连接至 iPhone 的设备

ios - 嵌套的 AVPlayer 全屏?

swift - CVPixelBuffer – 如何以每秒 60 帧的速度捕获每第三帧?

ios - 请求失败 : unacceptable content-type: application/osm3s+xml

iPhone Native系统例程(datagram-socket-type)

ios - 在 Xcode 中保存 NSMutableArray 的其他方法

ios - 在 Storyboard中将项目从一个 View 复制并粘贴到另一个 View 而不引用网点?

ios - SwiftyJSON 添加 JSON 对象数组

swift - ARKit ARSCNView.snapshot() 内存泄漏

swift - 如何删除最后放置的子节点?