SCNBox different colour or texture on each face

前端 未结 3 1016
天涯浪人
天涯浪人 2020-12-08 01:10

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

3条回答
  •  遥遥无期
    2020-12-08 01:27

    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
    

提交回复
热议问题