我试图将SCNLight
添加到SCNSphere
中的SCNNode
(SceneKit
)中。它的工作原理令人惊讶,唯一的问题是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
变成黑色。
答案 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)