【问题标题】:How to use ScnNode as a ScnLight?如何将 ScnNode 用作 ScnLight?
【发布时间】:2018-04-13 20:01:16
【问题描述】:
 var sun = SCNNode(geometry: SCNSphere(radius:0.35))

 sun.geometry?.firstMaterial?.diffuse.contents=#imageLiteral(resourceName: "Sun")

 sun.position=SCNVector3(0,0,-1)

我想使用太阳 SCNSphere 作为全向光源。

 let OmniLight = SCNLight()      
  OmniLight.type = SCNLight.LightType.omni
       OmniLight.color = UIColor.white

但是如果我运行这段代码,太阳是全黑的。

【问题讨论】:

  • 您是否在代码中的其他位置将太阳和光线添加到场景中?

标签: ios swift scenekit scnnode scnlight


【解决方案1】:

将其添加到场景中:

scene.rootNode.addChildNode(sun)

这里是游乐场代码示例:

import UIKit
import SceneKit
import PlaygroundSupport


// create a scene view with an empty scene
var sceneView = SCNView(frame: CGRect(x: 0, y: 0, width: 640, height: 480))
var scene = SCNScene()
sceneView.scene = scene
PlaygroundPage.current.liveView = sceneView

// default lighting
sceneView.autoenablesDefaultLighting = false

// a camera
var cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3(x: 0, y: 0, z: 3)
scene.rootNode.addChildNode(cameraNode)

// your code (minus the image)
var sun = SCNNode(geometry: SCNSphere(radius:0.35))
sun.geometry?.firstMaterial?.diffuse.contents = UIColor.orange
sun.position=SCNVector3(0,0,-1)
let OmniLight = SCNLight()
OmniLight.type = SCNLight.LightType.omni
OmniLight.color = UIColor.white

// add to scene
scene.rootNode.addChildNode(sun)

【讨论】:

  • 这根本不是在使用 OmniLight。它依赖于“sceneView.autoenablesDefaultLighting = true”提供的调试光源
  • 好收获。编辑为禁用默认照明。
猜你喜欢
  • 2019-08-11
  • 2016-01-18
  • 2016-06-05
  • 2017-01-11
  • 2017-01-23
  • 2020-04-06
  • 2019-09-06
  • 2018-01-30
  • 2020-06-26
相关资源
最近更新 更多