通过ARKIT向识别的图像添加文本

时间:2018-12-27 11:59:04

标签: swift arkit

现在我有一个简单的图像检测,上面覆盖了SCNPlane。

func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {

    let node = SCNNode()

    if let imageAnchor = anchor as? ARImageAnchor {

        let plane = SCNPlane(width: imageAnchor.referenceImage.physicalSize.width, height: imageAnchor.referenceImage.physicalSize.height)

        plane.firstMaterial?.diffuse.contents = UIColor(white: 1, alpha: 0.5)
        let planeNode = SCNNode(geometry: plane)

        planeNode.eulerAngles.x = -.pi / 2

        node.addChildNode(planeNode)
    }

    return node

}

我想在识别的图像的右侧显示一个简单的文本,而不是图像覆盖。

我已经尝试过:

func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {

    let node = SCNNode()

        let text = SCNText(string: "testtext", extrusionDepth: 1)
        let material = SCNMaterial()

        material.diffuse.contents = UIColor.green
        text.materials = [material]

        let textNode = SCNNode(geometry: text)


        node.addChildNode(textNode)

    return node

}

我在这里做错了什么?

0 个答案:

没有答案