Color in SCNNodes

I am trying to set the SCNNode color to a custom RGBA color, however when I try to check this box it will be white:

let box = SCNBox(width: 4, height: 1, length: 4, chamferRadius: 0)
    let boxNode = SCNNode(geometry: box)
    myScene.rootNode.addChildNode(boxNode)

    boxNode.castsShadow = true


    box.firstMaterial?.diffuse.contents  = UIColor(red: 30, green: 150, blue: 30, alpha: 1)

This makes the field white, however, does something like this:

box.firstMaterial?.diffuse.contents  = UIColor.greenColor()

How can I make a box with custom RGBA color?

-Thank

+4
source share
1 answer

The values ​​passed to the initializer UIColormust be between 0 and 1. You must divide your rgb values ​​by 255.

box.firstMaterial?.diffuse.contents  = UIColor(red: 30.0 / 255.0, green: 150.0 / 255.0, blue: 30.0 / 255.0, alpha: 1)
+7
source

All Articles