【问题标题】:SCNText not showing in SceneKitSCNText 未在 SceneKit 中显示
【发布时间】:2019-05-09 18:38:29
【问题描述】:

我正在尝试在我的 3D 场景中添加一个简单的文本叠加层,但没有显示任何内容。作为参考,SCNBox 添加并显示得很好。帮忙?

SCNNode PlaceText(SCNVector3 pos)
{
    var text = SCNText.Create("hello world", 5);
    text.Font = UIFont.FromName("Avenir Heavy", 50);
    text.ChamferRadius = 0.3f;
    text.Flatness = 0.1f;
    text.FirstMaterial.Diffuse.Contents = UIColor.White;
    text.FirstMaterial.Specular.Contents = UIColor.Blue;

    var offset = new SCNVector3(0.2f, 0.2f, 0.2f);
    offset = SCNVector3.Add(pos, offset);

    var textNode = new SCNNode { Position = offset, Geometry = text };
    scnView.Scene.RootNode.AddChildNode(textNode);

    return textNode;
}

【问题讨论】:

    标签: c# scenekit augmented-reality arkit scnnode


    【解决方案1】:

    您忘记将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()
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-23
      • 2020-05-18
      • 2015-02-19
      • 1970-01-01
      • 2018-10-06
      • 1970-01-01
      • 2017-08-23
      • 2014-10-05
      相关资源
      最近更新 更多