如何在两个地理位置之间创建SCNPlane(就像我在下面粘贴的图像一样)?

时间:2018-11-27 03:32:05

标签: ios swift mapbox arkit scnnode

我正在使用“ Mapbox”框架进行AR导航,我需要在两个地理位置之间添加SCNPlane,如下图所示

enter image description here

//代码-添加SCNNode和SCNPlane

func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
    // 1

    guard let planeAnchor = anchor as? ARPlaneAnchor else { return }

    // 2
    let width = CGFloat(planeAnchor.extent.x )
    let height = CGFloat(planeAnchor.extent.z)
    let plane = SCNPlane(width: width, height: height)

    // 3
    plane.materials.first?.diffuse.contents = UIColor.lightText

    // 4
    let planeNode = SCNNode(geometry: plane)

    // 5
    let x = CGFloat(planeAnchor.center.x)
    let y = CGFloat(planeAnchor.center.y)
    let z = CGFloat(planeAnchor.center.z)
    planeNode.position = SCNVector3(x,y,z)
    planeNode.eulerAngles.x = -.pi / 2

    // 6
    node.addChildNode(planeNode)
}

//在此处更新节点

func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {

    // 1
    guard let planeAnchor = anchor as?  ARPlaneAnchor,
        let planeNode = node.childNodes.first,
        let plane = planeNode.geometry as? SCNPlane
        else { return }

    // 2
    let width = CGFloat(planeAnchor.extent.x + 100)
    let height = CGFloat(planeAnchor.extent.z )
    plane.width = width
    plane.height = height

    // 3
    let x = CGFloat(planeAnchor.center.x)
    let y = CGFloat(planeAnchor.center.y)
    let z = CGFloat(planeAnchor.center.z)
    planeNode.position = SCNVector3(x, y, z)

}

在这里,我使用ARPlaneAnchor来检测平面并使用didAdd / didUpdate委托添加/更新SCNNode,但是我需要在两个地理位置之间绘制SCNPlane,而无需使用ARPlaneAnchor。

预先感谢

0 个答案:

没有答案