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

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

最佳答案

将其添加到场景:

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)

关于ios - 如何将ScnNode用作ScnLight?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47055935/

10-10 20:57