0

My materials are only applying to half of the faces. Here is my code:

        let boxGeometry = SCNBox(width: 10, height: 10, length: 10, chamferRadius: 0)
    let boxNode = SCNNode(geometry: boxGeometry)
    boxNode.position = SCNVector3Make(0, 0, -20)
    boxNode.runAction(SCNAction.repeatActionForever(SCNAction.rotateByX(1, y: 2, z: 0, duration: 1)))
    boxNode.geometry?.firstMaterial?.diffuse.magnificationFilter = SCNFilterMode.Nearest
    boxNode.geometry?.firstMaterial?.diffuse.minificationFilter = SCNFilterMode.Nearest
    var texture = SKTexture(imageNamed:"fixed!_textures_blocks_blockRedstone.png")
    texture.filteringMode = SKTextureFilteringMode.Nearest

    boxNode.geometry?.firstMaterial?.diffuse.contents = texture

    var material = SCNMaterial()
    material.diffuse.contents = UIColor.blueColor()
    boxNode.geometry?.insertMaterial(material, atIndex: 1)

    view.scene?.rootNode.addChildNode(boxNode)

I created a new material and added a blue color. Anyone know why it is only applying to three out of 6 faces? Thanks

https://i.stack.imgur.com/6IXh5.png

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Sam Kirkiles
  • 304
  • 5
  • 13

1 Answers1

3

You used insertMaterial:atIndex: to add a material to your box, so your box now has two materials.

SCNBox automatically divides the materials you assign among its six faces. With two materials, you'll get one material on three of the faces, and the other on the other three. With three materials, you'll get two faces each (and, IIRC, they'll be the three pairs of opposing faces). Four or five are sort of oddball cases, but if you want six different faces, assign six different materials.

If you want all the faces to be the same material, don't insert a new material, replace the contents of the firstMaterial.

rickster
  • 124,678
  • 26
  • 272
  • 326