Skip to content

Instantly share code, notes, and snippets.

@mattrobmattrob
Created August 31, 2017 19:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattrobmattrob/e934d664ef0fc8d45b7837d9eb797255 to your computer and use it in GitHub Desktop.
Save mattrobmattrob/e934d664ef0fc8d45b7837d9eb797255 to your computer and use it in GitHub Desktop.
Swift transposed version of a different color approach on all sides of a `SCNBox` (https://stackoverflow.com/a/27509866/856336)
/// Generate `SCNMaterial` that is the specified color
func material(withColor color : UIColor) -> SCNMaterial {
let material = SCNMaterial();
material.diffuse.contents = color
material.locksAmbientWithDiffuse = true
return material
}
let greenMaterial = material(withColor: UIColor.green)
let redMaterial = material(withColor: UIColor.red)
let blueMaterial = material(withColor: UIColor.blue)
let yellowMaterial = material(withColor: UIColor.yellow)
let purpleMaterial = material(withColor: UIColor.purple)
let magentaMaterial = material(withColor: UIColor.magenta)
cube.materials = [greenMaterial, redMaterial, blueMaterial, yellowMaterial, purpleMaterial, magentaMaterial];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment