如何判断 ARObjectAnchor 从场景中移除?

How to determine that ARObjectAnchor was removed from the scene?

我正在尝试使用 ARKit 来验证玩具的位置。我有一个 ARObject 扫描资源,将玩具放在相机视图中效果很好。换句话说,SCNSceneARSessiondidAdddidUpdate 在玩具被放置在相机视图后的合理时间内按预期调用。但是当我将玩具从相机视图中移开时,didRemove 会调用 not,无论是 SCNScene 还是 ARSession.

我确实读过对这种行为的提倡,说 "well ARKit can't know if it was really removed and it still may be just around the corner" 但这是相当不切实际的假设。关于此功能的整个 Apple 文档是 "ARKit may automatically remove anchors",但没有说明何时以及为何使用。我知道 isTrackedARObjectAnchor 似乎是 唯一没有实现 ARTrackable.

的 ARAnchor 子类

我能想到的唯一绝望的 hack 是当 didUpdate 停止被调用时的某种模糊超时,因为这是删除对象 AFAIK 的唯一效果。我是否忽略了 ARWorldTrackingConfiguration 中的某些内容?请?

要按名称查找锚点,请使用 init(name:transform:) 初始化器给它一个描述性名称:

let anchor = ARAnchor.init(name: "ObjAnchor", transform: mtx) as! ARObjectAnchor

self.sceneView.session.currentFrame?.anchors.filter { 
     [=10=].name == "ObjAnchor"
}

或:

self.sceneView.session.currentFrame?.anchors.contains { 
    [=11=].isKind(of: ARObjectAnchor.self)
}

来自Apple TSI的信息解读(id 731233593,如果有人想在他自己的TSI中提到这个问题):

当对象离开屏幕时,ARObjectAnchors 不一定会被移除。这不是应该依赖的行为。 这适用于 AR(SCNView|Session)Delegate.didRemove 回调和 ARFrame.anchors 的内容。仅当客户端代码以编程方式删除相关锚点时,才会明确调用回调。尽管明确询问,但我无法对官方文档行 "ARKit may automatically remove anchors" 提出更好的解释。 "你不必担心为什么会这样。"

didAdddidUpdate 回调超时是一种官方方法。 证据是 Apple's official project 创建对象扫描,文件 Controllers/TestRun.swift方法startNoDetectionTimer。使用 5 秒超时。

ARObjectAnchor 的实施 ARTrackable 的需求鼓励在 Feedback Assistant 填写增强请求。我个人被鼓励研究替代方案,发现 CoreML 出乎意料地友好并且更适合我的用例。

感谢@Andy 让我走到这一步。