2

Is there any way to render different contents for both radius and height sections

I am trying to use a cylinder shaped object and rendering image on it using diffuse.contents of SCMaterial instance

myCustomMaterial.diffuse.contents = UIImage(named: "image")

It renders this image on cylinder, however same image gets rendered on both height and render section.

I would like to render a different image on height section than radius section. Is it possible?

Hal Mueller
  • 7,019
  • 2
  • 24
  • 42
iHS
  • 5,372
  • 4
  • 31
  • 49

1 Answers1

5

Use an array of materials.

let cylinder = SCNCylinder(radius: 1.0, height: 1.0)
let cylinderNode = SCNNode(geometry: cylinder)
let fillMurray = SCNMaterial()
fillMurray.diffuse.contents = UIImage(named: "fillmurray460x300")
let kitten = SCNMaterial()
kitten.diffuse.contents = UIImage(named: "kitten140")
cylinder.materials = [fillMurray, kitten]

enter image description here

Hal Mueller
  • 7,019
  • 2
  • 24
  • 42
  • Thanks. However, it flipped (mirrored) the second image. – iHS Nov 10 '15 at 21:11
  • 1
    Nevermind. I was able to transform it using contentsTransform. Thanks alot – iHS Nov 10 '15 at 21:19
  • Interesting. I wonder what it did to the other end of the cylinder! For another approach to flipping, you can see http://stackoverflow.com/questions/33638532/setting-contents-images-on-scncylinder-is-reversed-flipped. – Hal Mueller Nov 10 '15 at 21:20
  • 1
    I had to use contentsTransform on both ends i.e for both images material.diffuse.contentsTransform = SCNMatrix4MakeScale(1,-1,1). But I will try to use the solution you mentioned in different answer. – iHS Nov 10 '15 at 21:25