【问题标题】:Adding SCNLight to SCNNode turns SCNNode black将 SCNLight 添加到 SCNNode 会使 SCNNode 变黑
【发布时间】:2019-08-11 19:17:01
【问题描述】:

我正在尝试将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变黑。

【问题讨论】:

  • 调整光位掩码。

标签: swift scenekit


【解决方案1】:

为球体和光设置一个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)

【讨论】:

    猜你喜欢
    • 2018-04-13
    • 1970-01-01
    • 2018-08-10
    • 2018-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-06
    • 1970-01-01
    相关资源
    最近更新 更多