【问题标题】:Write text on sphere surface SceneKit?在球面SceneKit上写文字?
【发布时间】:2015-04-07 20:31:39
【问题描述】:

我想知道是否有一种方法可以在 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)

【问题讨论】:

    标签: ios scenekit


    【解决方案1】:

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

    【讨论】:

    • 我试图在其中添加一个带有 TextLayer 的 CALayer,但该框消失了......所以,我做错了。不知道是什么。
    • 好的,添加背景颜色(橙色)现在图层用作盒子上的纹理,但我还没有看到任何文字。
    • 您也可以使用 SpriteKit SKScene 作为材质属性内容。无论哪种方式,您都可能需要弄乱contentsTransform 以使其以您想要的方向/位置出现。
    猜你喜欢
    • 2017-11-20
    • 1970-01-01
    • 1970-01-01
    • 2015-09-05
    • 1970-01-01
    • 2016-12-23
    • 2017-12-30
    • 2018-09-22
    • 2021-08-27
    相关资源
    最近更新 更多