将SCNLight添加到SCNNode会使SCNNode变黑

时间:2019-03-21 00:00:40

标签: swift scenekit

我试图将SCNLight添加到SCNSphere中的SCNNodeSceneKit)中。它的工作原理令人惊讶,唯一的问题是SCNLight所在的源球是完全黑色的,因为作为源,它根本不会发出任何光。如何确定光源(即Sphere)完全点亮?

这是光源代码:

public func addLightSource(position: SCNVector3) -> SCNLight {
        let light = SCNLight()
        light.type = .omni
        light.intensity = 5000
        light.temperature = CGFloat(3500)
        return light
}

及以后的


ParentNode.light = addLightSource(position: absolutePosition)

可以,但是将ParentNode变成黑色。

1 个答案:

答案 0 :(得分:0)

为球体设置categoryBitMask实例属性,并为光排除/包含实例属性。

func addLightSource(position: SCNVector3) -> SCNLight {
    let light = SCNLight()
    light.type = .omni
    light.intensity = 5000
    light.categoryBitMask = 1
    light.temperature = CGFloat(2000)
    return light
}

let sphereNode1 = SCNNode()
sphereNode1.geometry = SCNSphere(radius: 2)
sphereNode1.position = SCNVector3(x: 10, y: 0, z: 0)
sphereNode1.light = addLightSource(position: sphereNode1.position)
sphereNode1.categoryBitMask = 1
scene.rootNode.addChildNode(sphereNode1)