在 SceneKit 中如何在球体表面写字?

8
我想知道在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)
1个回答

3
你可以使用任何CALayer作为你的SCNMaterialProperty的内容 :)

我尝试添加一个包含TextLayer的CALayer,但是框消失了...所以,我做错了什么。不确定是什么。 - zumzum
好的,现在添加背景颜色(橙色),图层作为盒子的纹理使用,但我还没有看到文本。 - zumzum
您还可以使用SpriteKit的SKScene作为材料属性内容。无论哪种方式,您都可能需要调整contentsTransform以使其以您想要的方向/位置出现。 - rickster

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接