SCNText未显示在SceneKit中

时间:2018-12-08 02:20:06

标签: c# scenekit augmented-reality arkit scnnode

我正在尝试在3D场景中添加一个简单的文本叠加层,但没有任何显示。供参考,ClassTest可以很好地显示。帮助吗?

SCNBox

1 个答案:

答案 0 :(得分:0)

您忘记为text's SCNGeometry分配一个node.geometry

这是一个用Swift(mac版本)编写的工作示例:

import SceneKit
import QuartzCore

class GameViewController: NSViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let scene = SCNScene()
        let scnView = self.view as! SCNView
        scnView.scene = scene
        scnView.allowsCameraControl = true
        scnView.backgroundColor = NSColor.darkGray

        func placeText() {
            let text = SCNText(string: "HELLO WORLD", extrusionDepth: 3.0)
            text.font = NSFont(name: "Avenir", size: 18.0)
            text.chamferRadius = 0.3
            text.flatness = 0.1
            text.firstMaterial?.diffuse.contents = NSColor.white
            text.firstMaterial?.specular.contents = NSColor.blue
            let position = SCNVector3(-80,-10,0)
            let textNode = SCNNode()
            textNode.geometry = text                    // YOU MISSED THAT
            textNode.position = position
            scnView.scene!.rootNode.addChildNode(textNode)
        }
        placeText()
    }
}

enter image description here