【问题标题】:ARKit 4.0 – Ignoring the ".ceiling" from horizontal plane detectionARKit 4.0 – 忽略水平面检测中的“.ceiling”
【发布时间】:2020-10-28 14:32:35
【问题描述】:

我试图让我的代码检测水平面以找到地板。我的地板是起点设备下方最大的水平面。我目前的算法正在寻找最大的水平面并将其识别为地板,但它也将天花板视为水平面——它不应该这样做。我一直在寻找解决这个问题的方法,但没有骰子。

感谢任何帮助。

这是我的代码:

var areas = [Float]()

for grid1 in grids {
    let a = grid1.planeGeometry.width * grid1.planeGeometry.height
    areas.append(Float(a))
}

for grid2 in grids {
    let area = grid2.planeGeometry.width * grid2.planeGeometry.height

     if (Float(area)==areas.max()) {
         grid2.floored(state: true)
     } else {
         grid2.floored(state: false)
     }
}

编辑

为了澄清地板的定义,它是从设备的初始起点检测到的最大、最低的平面。因此,例如,如果分别检测到两个平面(例如地毯和地板本身)并且尺寸相同,则较低的平面将是地板。但是,如果地毯覆盖的空间更大,那就是地板。

【问题讨论】:

    标签: swift augmented-reality arkit realitykit


    【解决方案1】:

    ARKit 4.0 中,它仍然是 gettable-only property - 它说明了 ARKit 如何对表面进行分类:

    public var classification: ARPlaneAnchor.Classification { get }
    


    使用 RealityKit可设置 且符合 OptionSet 协议的属性:

    let surfaceClassification: AnchoringComponent.Target.Classification = [.floor, 
                                                                           .seat]
    

    在实际代码中,它可能如下所示:

    import RealityKit
    
    let arView = ARView(frame: cgRect)
    
    let box = MeshResource.generateBox(size: 0.25)
    let entity = ModelEntity(mesh: box)
    
    let anchor = AnchorEntity(plane: .horizontal,
                     classification: .floor,
                      minimumBounds: [2.0, 2.0])
    
    anchor.addChild(entity)
    arView.scene.anchors.append(anchor)
    

    【讨论】:

    • 我已经尝试添加一个警卫来检查飞机的锚点是否在地板上,但它不是等平的。我试过类似guard planeAnchor.classification == .floor else {return}
    • 我喜欢 Realitykit 解决方案,但在整个项目中,我一直使用 ARPlaneAnchor 作为我的锚点类型,并且到目前为止它运行良好。除了切换我所有的锚点之外,没有其他方法可以继续使用 ARkit 吗?
    • 除了let anchor = AnchorEntity(anchor: ARAnchor())没有解决办法
    • 尝试修改我的代码,但发现从 ARAnchor 转换为 AnchorEntity 不起作用,并且您的初始化解决方案也不起作用,因为它没有 init()。所以,这种方法的底线是我需要重新制作整个东西以使用 RealityKit 而不是 ARKit 和 SceneKit
    • 是的。您应该使用 ARKit+RealityKit 而不是 ARKit+SceneKit(如果您需要管理 classification)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-06
    • 2020-04-09
    • 1970-01-01
    • 1970-01-01
    • 2019-09-11
    • 2017-11-09
    相关资源
    最近更新 更多