我刚开始学习ARKitexample和Scenekit.我读了一些Scenekit,发现为了添加文本,我需要使用SCNText.
我试着像这样写,但它没有表现出来.
guard let pointOfView = sceneView.pointOfView else { return }
let text = SCNText(string: "Hello", extrusionDepth: 4)
let textNode = SCNNode(geometry: text)
textNode.geometry = text
textNode.position = SCNVector3Make(pointOfView.position.x, pointOfView.position.y, pointOfView.position.z)
sceneView.scene.rootNode.addChildNode(textNode)
Run Code Online (Sandbox Code Playgroud)
我只想在用户按下按钮时在SCNScene上添加一些文本(如"hello world").
编辑
我看到那个文字,但由于我没有设置平面(或锚),我不能把它看作好像我在那个文本前面.我能怎么做?
我正在尝试在 ARKit 的语音气泡中创建一个带有简单文本的报价生成器。
我可以用文本显示语音气泡,但文本始终从中间开始并溢出到语音气泡之外。
任何帮助让它在语音气泡的左上角对齐并包裹在语音气泡内的帮助将不胜感激。
结果
课程
class SpeechBubbleNode: SCNNode {
private let textNode = TextNode()
var string: String? {
didSet {
textNode.string = string
}
}
override init() {
super.init()
// Speech Bubble
let plane = SCNPlane(width: 200.0, height: 100.0)
plane.cornerRadius = 4.0
plane.firstMaterial?.isDoubleSided = true
geometry = plane
// Text Node
textNode.position = SCNVector3(position.x, position.y, position.z + 1.0)
// textNode.position = convertPosition(SCNVector3(0.0, 0.0, 1.0), to: textNode)
// textNode.position = SCNVector3(0.0, 0.0, position.z + 1.0)
addChildNode(textNode)
}
required init?(coder …Run Code Online (Sandbox Code Playgroud) 我希望添加类似于此应用程序的广告牌效果:https://twitter.com/marpi_/status/897130955105644544
我希望使用SCNText几何体的SCNodes始终面向相机.
我试图取得成功:
开箱即用,SKLabelNode将始终面对ARKit中的相机,这正是我想要的,除了使用SCNText.