gpt4 book ai didi

swift - 将 SCNLight 添加到 SCNNode 会使 SCNNode 变黑

转载 作者:行者123 更新时间:2023-11-28 07:29:35 26 4
gpt4 key购买 nike

我正在尝试将 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com