在球体表面 SceneKit 上写文字?
Write text on sphere surface SceneKit?
我想知道是否有一种方法可以在 SceneKit 中沿着球体对象的表面书写文本。
我知道我在表面上放置了纹理并在有图像的情况下实现了这种效果,但我想知道我是否可以以某种方式在球体表面上动态添加文本。
有什么想法吗?
编辑:
这个有效:
let layer = CALayer()
layer.frame = CGRectMake(0, 0, 100, 100)
layer.backgroundColor = UIColor.orangeColor().CGColor
var textLayer = CATextLayer()
textLayer.frame = layer.bounds
textLayer.fontSize = layer.bounds.size.height
textLayer.string = "Test"
textLayer.alignmentMode = kCAAlignmentLeft
textLayer.foregroundColor = UIColor.greenColor().CGColor
textLayer.display()
layer.addSublayer(textLayer)
let box = SCNBox(width: 10, height: 10, length: 10, chamferRadius: 0.5)
let boxNode = SCNNode(geometry: box)
box.firstMaterial?.locksAmbientWithDiffuse = true
boxNode.position = position
box.firstMaterial?.diffuse.contents = layer
scene.rootNode.addChildNode(boxNode)
您可以使用任何 CALayer
作为 SCNMaterialProperty
的内容:)
我想知道是否有一种方法可以在 SceneKit 中沿着球体对象的表面书写文本。
我知道我在表面上放置了纹理并在有图像的情况下实现了这种效果,但我想知道我是否可以以某种方式在球体表面上动态添加文本。
有什么想法吗?
编辑:
这个有效:
let layer = CALayer()
layer.frame = CGRectMake(0, 0, 100, 100)
layer.backgroundColor = UIColor.orangeColor().CGColor
var textLayer = CATextLayer()
textLayer.frame = layer.bounds
textLayer.fontSize = layer.bounds.size.height
textLayer.string = "Test"
textLayer.alignmentMode = kCAAlignmentLeft
textLayer.foregroundColor = UIColor.greenColor().CGColor
textLayer.display()
layer.addSublayer(textLayer)
let box = SCNBox(width: 10, height: 10, length: 10, chamferRadius: 0.5)
let boxNode = SCNNode(geometry: box)
box.firstMaterial?.locksAmbientWithDiffuse = true
boxNode.position = position
box.firstMaterial?.diffuse.contents = layer
scene.rootNode.addChildNode(boxNode)
您可以使用任何 CALayer
作为 SCNMaterialProperty
的内容:)