当应用在 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/