ARKit 是否公开了一种显示地平面的自动方式,还是应该将其作为对象添加到某些坐标

does ARKit exposes an automatic way of displaying ground planes, or should it be added as an object to some coordinates

我正在尝试使用 ARKit 显示地平面,我看到 ARSCNView 公开了两个选项:showWorldOriginshowFeaturePoints 这样当它们是 "on" ,世界坐标和特征点显示,无需额外代码。

地平面也有这样的钩子吗?我知道如果我这样做:

        let config = ARWorldTrackingConfiguration()
        config.planeDetection = WorldTrackingSessionConfiguration.PlaneDetection.horizontal 

然后大概正在检测地平面,我想要两件事:

  1. 地平面坐标的控制台打印输出

  2. 地平面的相机内显示

这些任务是否有预先公开的选项,或者是否必须执行?如果是这样,有哪些教程可以完成此类任务?

ARSCNViewDelegate 提供为每个平面调用的回调 detected/updated/removed:

public func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) 
public func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) 
public func renderer(_ renderer: SCNSceneRenderer, didRemove node: SCNNode, for anchor: ARAnchor)

虽然它不会绘制或打印出东西,但您可以在其中添加节点并打印它。例如:

public func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
    guard let anchor = anchor as? ARPlaneAnchor else { return }

    print(anchor.extent)

    // Create a SceneKit plane to visualize the node using its position and extent.
    // Create the geometry and its materials
    let plane = SCNPlane(width: CGFloat(anchor.extent.x), height: CGFloat(anchor.extent.z))

    let lavaImage = UIImage(named: "Lava")
    let lavaMaterial = SCNMaterial()
    lavaMaterial.diffuse.contents = lavaImage
    lavaMaterial.isDoubleSided = true

    plane.materials = [lavaMaterial]

    // Create a node with the plane geometry we created
    let planeNode = SCNNode(geometry: plane)
    planeNode.position = SCNVector3Make(anchor.center.x, 0, anchor.center.z)

    // SCNPlanes are vertically oriented in their local coordinate space.
    // Rotate it to match the horizontal orientation of the ARPlaneAnchor.
    planeNode.transform = SCNMatrix4MakeRotation(-Float.pi / 2, 1, 0, 0)

    // ARKit owns the node corresponding to the anchor, so make the plane a child node.
    node.addChildNode(planeNode)
}

当然你需要处理updateNode和removeNode