【发布时间】:2019-09-02 15:20:24
【问题描述】:
我正在使用 ARKit 生成飞机,如果我手动移除飞机,我无法检测到相同位置的飞机。
为了检测飞机,我设置了场景配置
let config = ARWorldTrackingConfiguration()
config.worldAlignment = .gravity
config.providesAudioData = false
config.isLightEstimationEnabled = true
...
else if ARMode == .floor {
self.ARMode = .floor
scannerBox.isHidden=true
focusNode?.isHidden=false
plusButton.isHidden=true
config.planeDetection = .horizontal self.planeTexture="test.scnassets/Textures/Surface_Texture.png"
}
...
sceneView.session.run(config)
在渲染器函数中将平面添加到场景中
let planeNode = self.createARPlaneNode(planeAnchor: planeAnchor,
color: UIColor.yellow.withAlphaComponent(0.5))
node.addChildNode(planeNode)
如果按下某个按钮,飞机和其他物体应该被移除
scene.rootNode.enumerateChildNodes { (node, _) in
print(node.name)
if (node.name == "sphere" ) {
node.removeFromParentNode()
}
if ( node.name == "surfacePlane") {
node.removeFromParentNode()
}
if(node.name != nil){
if (node.name?.contains("ProductModel_"))! {
node.removeFromParentNode()
}
}
}
当上述代码触发时,平面、球体和产品会按预期消失。 如果我尝试扫描房间其他地方的表面,它会按预期工作,但如果我尝试扫描飞机所在的位置并生成一个新的,它将无法正常工作。它不会生成一个新的平面,如果附近的平面扩展到覆盖相同的区域,它们就会消失。
我认为问题很可能是已移除平面的场景几何形状仍然存在,并阻止了同一空间中的新平面。 作为我的临时工作,停止和启动 AR 会话并移除飞机。
let config = sceneView.session.configuration as!
ARWorldTrackingConfiguration
config.planeDetection = .horizontal
sceneView.session.run(config,
options: [.resetTracking, .removeExistingAnchors])
我正在尝试确定为什么会出现这种情况,并且飞机与我明确放置在场景中的对象不同。
【问题讨论】:
-
为什么不直接删除飞机的孩子而不是飞机本身?一旦
didAddAnchor被调用为ARPlaneAnchor,它就不会再次被调用,除非你说过重置会话。 -
我希望移除现有的平面,这样当我移动到应用程序的新状态时,以前的环境对象和窗格就不会干扰。