Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Color in SCNNodes

I am trying to set the color of a SCNNode to a custom RGBA Color however when I try to the box will end up 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 box white however doing something like this works:

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

How can I make the box have a custom RGBA color?

-Thanks

like image 803
Tob Avatar asked Apr 12 '16 21:04

Tob


1 Answers

The values passed to the UIColor initializer need to be between 0 and 1. You should 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)
like image 168
dan Avatar answered Nov 05 '22 03:11

dan