2
 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

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

4

1 回答 1

-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)
于 2017-11-01T23:02:20.427 回答