我正在尝试将 SCNLight
添加到 SceneKit
中的 SCNSphere
(SCNNode
)。它的效果令人惊叹,唯一的问题是 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
变黑。
最佳答案
设置 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)
关于swift - 将 SCNLight 添加到 SCNNode 会使 SCNNode 变黑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55271885/