如何删除 arView.session.currentFrame 的锚点?

How to remove anchor of arView.session.currentFrame?

最近研究了ARWorldTrackingConfiguration。但这是非常困难的。首先我想使用这个功能:

func session(_ session: ARSession, didRemove anchors: [ARAnchor]) { }

我已经尝试过这些,但它不起作用:

arView.session.remove(anchor: frame.anchors[0])
arView.session.currentFrame?.anchors.removeAll() // 'anchors' is a get-only property

有人知道 'didRemove' 会话功能吗?

请帮助我掌握 ARkit。

要从 ARSession 中删除 ARAnchor,您需要使用 remove(anchor:) 实例方法:

let specialAnchor = ARAnchor(name: "special", transform: simd_float4x4())

arView.session.remove(anchor: specialAnchor)

当从会话中删除锚点时调用您提到的方法:

func session(_ session: ARSession, didRemove anchors: [ARAnchor]) {
    self.anchorsData(anchors: anchors)
}

func anchorsData(anchors: [ARAnchor]) -> [Any] {
    var data = [Any]()
    // some code...
    return data
}