在我的SCNScene中,我有一个球,一个具有自定义几何形状(用于复制地形)的地板平面和一个全向灯光。我要尝试做的是使全向灯光仅在球上发光,而不在地板上发光。我已经读到我需要调整每个节点的categoryBitMask并使灯光categoryBitMask与我要对其作用的对象相同。但是我无法完成这项工作,并且对原因感到非常困惑。非常感谢您的帮助,非常感谢!
注意:当我运行下面的代码时,灯光什么都不发光,但是当我删除灯光类别BitMask时,它在球和飞机上都发光。
代码:
func addBall(ballPosition: SCNVector3) {
let ball = SCNSphere(radius: 1)
let ballNode = SCNNode(geometry: ball)
ballNode.position = ballPosition
let ballPhysicsBody = SCNPhysicsBody(type: .dynamic, shape: SCNPhysicsShape(geometry: SCNSphere(radius: 1)))
ballPhysicsBody.categoryBitMask = 00000010
ballNode.physicsBody = ballPhysicsBody
self.rootNode.addChildNode(ballNode)
addLight(referencePosition: ballPosition)
}
func addLight(referencePosition: SCNVector3) {
let omniLight = SCNLight()
omniLight.type = SCNLight.LightType.omni
omniLight.color = UIColor.white
omniLight.intensity = 1000
omniLight.categoryBitMask = 00000010
let lightNode = SCNNode()
lightNode.light = omniLight
lightNode.position = SCNVector3(x: referencePosition.x, y: 15, z: referencePosition.z)
self.rootNode.addChildNode(lightNode)
}