在过去的几天里,我对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)
}
带有鲜红色聚光灯的较暗球体:
更透明的球体,带有柔和的红色聚光灯:
发布于 2016-09-14 15:13:04
在这一行..。shapeNode.addChildNode(lightNode) ...you将灯光节点添加到球体节点。
如果要取消它们的链接,同时仍使它们一起移动,则可以创建一个空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)
}
https://stackoverflow.com/questions/39492219
复制相似问题