首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >可以用鲜红的SCNSpotlight画出清晰的SCNSphere吗?

可以用鲜红的SCNSpotlight画出清晰的SCNSphere吗?
EN

Stack Overflow用户
提问于 2016-09-14 21:50:20
回答 1查看 1.6K关注 0票数 2

在过去的几天里,我对SceneKit有点纠结。我正在尝试绘制一个带有红色聚光灯的清晰/透明的SCNSphere。如果我将SCNSphere设置为透明/透明颜色,我的红色聚光灯似乎也变得透明。是否可以取消SCNLight节点与SCNSphereNode的链接,以便如果SCNSphere是透明的,则聚光灯的鲜红色保持不变?两个球体的图像都在代码下面。

我的代码:

代码语言:javascript
复制
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)


    }

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

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

EN

回答 1

Stack Overflow用户

发布于 2016-09-14 23:13:04

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

如果要取消它们的链接,同时仍使它们一起移动,则可以创建一个空SCNNode,然后将另外两个SCNNode实例作为子实例添加到其中(一个用于灯光,另一个用于球体):

代码语言:javascript
复制
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)

}

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39492219

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档