How to put text over node in scenekit?

2019-05-03 17:34发布

Really simple question which for some reason I cannot find anywhere. How can I write 2D text on a 3D face of a SCNNode? For example, on something like this:

let geo = SCNBox(width: 20, height: 20, length: 20, chamferRadius: 0.0);
//geo.writeFace(postion, text)
let box = SCNNode(geometry: geo);

Of course the comment is made up. Anything like it?

1条回答
beautiful°
2楼-- · 2019-05-03 17:54

You'll need to create a texture of the desired font and text, then apply that as a part of the material on the object. Though I've not seen anything like UVW mapping in Scene Kit to let you control the placement. It must be there. If you're only working with SCN geometry you might be OK, because SCNBox at least permits per side specification for material/texture.

You can dynamically create 2D type textures with either UIKit text drawing to a context, or rasterisation of Sprite Kit text with use of textureToNode: https://developer.apple.com/reference/spritekit/skview/1520114-texturefromnode?language=objc

查看更多
登录 后发表回答