我正在使用 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 session ,从而删除了飞机。
let config = sceneView.session.configuration as!
ARWorldTrackingConfiguration
config.planeDetection = .horizontal
sceneView.session.run(config,
options: [.resetTracking, .removeExistingAnchors])
我试图确定为什么会出现这种情况,并且飞机的处理方式与我明确放置在场景中的对象不同。
最佳答案
我相信您还需要删除您的平面节点所附加的 ARPlaneAnchor,以便 ARKit 将创建一个新的 ARPlaneAnchor 并启动正在创建您的平面节点的渲染器功能。
类似的东西
if ( node.name == "surfacePlane") {
if let planeAnchor = sceneView.anchor(for: node) as? ARPlaneAnchor {
sceneView.session.remove(anchor: planeAnchor)
}
node.removeFromParentNode()
}
关于ios - 删除planeDetection平面可以防止放置额外的平面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55641807/