2

最近几天我在 SceneKit 上有点挣扎。我正在尝试绘制一个清晰/透明的 SCNSphere,带有红色聚光灯。如果我将 SCNSphere 设置为透明/清晰的颜色,我的红色聚光灯似乎也变得透明。是否可以取消 SCNLight 节点与 SCNSphereNode 的链接,以便在 SCNSphere 透明的情况下保留光斑的鲜红色?两个球体的图像都在代码下方。

我的代码:

func setupView() {
    scene = SCNScene()
    caliView.scene = scene
    caliView.allowsCameraControl = true
    caliView.backgroundColor = UIColor.clearColor()
    let clearMaterial = SCNMaterial()
    clearMaterial.diffuse.contents = UIColor(white: 0.9, alpha: 0.5)
    clearMaterial.locksAmbientWithDiffuse = true


    let shape = SCNSphere(radius: 5)
    shape.materials = [clearMaterial]
    let shapeNode = SCNNode(geometry: shape)

    let spotLight = SCNLight()
    spotLight.type = SCNLightTypeSpot
    spotLight.color = UIColor.init(colorLiteralRed: 180, green: 0, blue: 0, alpha: 0.0)
    let lightNode = SCNNode()
    lightNode.light = spotLight

    lightNode.position = SCNVector3(x: 0.0, y:0.0, z:15.0)
    lightNode.orientation = SCNQuaternion(x: 0.0, y:0, z:30, w:0.0)


    let ambientLight = SCNLight()
    ambientLight.type = SCNLightTypeAmbient
    ambientLight.color = UIColor(white: 0.8, alpha: 0.2)
    let ambientNode = SCNNode()
    ambientNode.light = ambientLight

    shapeNode.position = SCNVector3(x: 0.0, y: 0.0, z: 0.0)

    scene.rootNode.addChildNode(ambientNode)
    scene.rootNode.addChildNode(shapeNode)
    shapeNode.addChildNode(lightNode)


    }

带有亮红色聚光灯的较暗球体:

带有亮红色聚光灯的较暗球体

更透明的球体,带有柔和的红色聚光灯:

更透明的球体,带有柔和的红色聚光灯

4

1 回答 1

3

在这一行中... shapeNode.addChildNode(lightNode) ...您将灯光节点添加到球体节点。

如果你想在它们一起移动的同时取消链接,你可以创建一个空的 SCNNode 并将另外两个 SCNNode 实例添加到它作为子节点(一个用于灯光,一个用于球体):

func setupView() {
scene = SCNScene()
caliView.scene = scene
caliView.allowsCameraControl = true
caliView.backgroundColor = UIColor.clearColor()
let clearMaterial = SCNMaterial()
clearMaterial.diffuse.contents = UIColor(white: 0.9, alpha: 0.5)
clearMaterial.locksAmbientWithDiffuse = true

let emptyNode = SCNNode()

let shape = SCNSphere(radius: 5)
shape.materials = [clearMaterial]
let shapeNode = SCNNode(geometry: shape)

let spotLight = SCNLight()
spotLight.type = SCNLightTypeSpot
spotLight.color = UIColor.init(colorLiteralRed: 180, green: 0, blue: 0, alpha: 0.0)
let lightNode = SCNNode()
lightNode.light = spotLight

lightNode.position = SCNVector3(x: 0.0, y:0.0, z:15.0)
lightNode.orientation = SCNQuaternion(x: 0.0, y:0, z:30, w:0.0)

let ambientLight = SCNLight()
ambientLight.type = SCNLightTypeAmbient
ambientLight.color = UIColor(white: 0.8, alpha: 0.2)
let ambientNode = SCNNode()
ambientNode.light = ambientLight

shapeNode.position = SCNVector3(x: 0.0, y: 0.0, z: 0.0)

emptyNode.addChild(shapeNode)
emptyNode.addChild(lightNode)
scene.rootNode.addChildNode(emptyNode)
scene.rootNode.addChildNode(ambientNode)

}

于 2016-09-14T15:13:04.087 回答