c# - SCNText 未在 SceneKit 中显示
问题描述
我正在尝试在我的 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;
}
解决方案
您忘记将 a 分配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()
}
}
推荐阅读
- node.js - oracle/node多条sql查询并合并为一个对象作为结果集
- powershell - 从 get-adprincipal powershell 中提取 Samaccount 名称
- css - 在 chrome 中看起来模糊的边框
- javascript - ES6 使用原型在类继承中访问 this
- php - PHP Codeigniter MySQL 查询 - 将 4 个表连接在一起,其中 3 个表使用每个表中的一列分组
- redirect - IIS URL重写模块 - 更改查询字符串参数值形成多个查询字符串
- sql - 具有多个键的 SQL 连接
- javascript - Javascript: append to an array not working
- android - Android 的约束布局
- jquery - 使用 jQuery 根据锚点的焦点向父 div 添加类