0

I have an SCNNode (made up of an SCNPlane) with an image on it, and I want to put text over the image. I understand that an SCNNode can have different materials. My problem is that I can load an image on the SCNNode, but the text does not appear when I load it. My code looks something like this:

let mat = SCNMaterial()
let mat2 = SCNMaterial()
let node = SCNNode(geometry: SCNPlane(width: 6, length: 9))

mat.diffuse.contents = imgName
mat2.diffuse.contents = strName

node.geometry?.firstMaterial?.locksAmbientWithDiffuse = true
node.geometry?.materials = [mat, mat2]

(imgName is a UIImage and strName is a String)

And if I try to load the text before the image ([mat2, mat]), I'm just going to get a blank plane. Am I missing a step in preparing the SCNMaterial?

1 Answers1

3

By specifying

node.geometry?.materials = [mat, mat2]

you're saying that the first face of your node should have material mat, and the second face should have material mat2(and so on for the 3rd, 4th, 5th, 6th, etc faces).Since you're working with an SCNPlane, that should be its front and back.

Do your compositing of the text over the image outside of SceneKit, so that you have just one image. Or, use the material's transparent property for the text (you'll probably want to use SCNTransparencyMode.RGBZero) to overlay the image. David Ronnqvist's SceneKit book has nice examples of transparency in the planet examples.

Hal Mueller
  • 7,019
  • 2
  • 24
  • 42
  • Your suggestion to modify the image outside of SceneKit made me reconsider my approach. I found [this](http://stackoverflow.com/questions/28906914/how-do-i-add-text-to-an-image-in-ios-swift) while searching, and incorporated another function into my code that would make a copy of the image for the purpose of adding to that plane only. Now I can see text on my image. Thanks for the point in the right direction. – William Putnam Feb 15 '16 at 15:33