I\'m new to iOS development and I\'ve got myself stumped. I am trying to render a cube using SceneKit that has a different colour for each face.
This is what I\'ve g
Here's a Swift 4 answer.
let colors = [UIColor.green, // front
UIColor.red, // right
UIColor.blue, // back
UIColor.yellow, // left
UIColor.purple, // top
UIColor.gray] // bottom
let sideMaterials = colors.map { color -> SCNMaterial in
let material = SCNMaterial()
material.diffuse.contents = color
material.locksAmbientWithDiffuse = true
return material
}
materials = sideMaterials
To change the front material just grab the material and change it's content
let frontMaterial = materials[0]
frontMaterial.diffuse.contents = UIColor.white