Search code examples
xcodescenekitboxlight

Xcode SceneKit Making a glowing light box


I have been trying to figure out if there a way to make a "glowing" SCNBox in SceneKit. Unfortunately, I didn't figure it out by myself.

Don't know if the solution is so simple it didn't come into my mind.

Ideas are welcome Thanks


Solution

  • Make an omni light in the same position as your SCNNode. And set the value of the emission of the SCNNode the same colour as your light.

    let box = SCNBox.init(width: 1, height: 1, length: 1, chamferRadius: 0.3)
    box.materials.first?.diffuse.contents = UIColor.blue
    box.materials.first?.emission.contents = UIColor.white
    box.materials.first?.emission.intensity = 1.0
    let boxNode = SCNNode.init(geometry: box)
    boxNode.position = SCNVector3(x: 0, y: 0, z: -10)
    self.sceneView.scene?.rootNode.addChildNode(boxNode)
    
    
    let omniLight = SCNLight()
    omniLight.type = .omni
    omniLight.color = UIColor.yellow
    boxNode.light = omniLight