2017-11-01 11 views
1
var sun = SCNNode(geometry: SCNSphere(radius:0.35)) 

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

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

그리고 태양 광 SCNSphere를 옴니 광원으로 사용하고 싶습니다.ScnLight로 ScnNode를 사용하는 방법?

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

하지만이 코드를 실행하면 해가 짙어집니다.

+0

당신이 당신의 코드에서 다른 곳 장면에 태양 빛을 추가하고 있습니까? –

답변

0

장면에 추가 :

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 = true 

// 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) 
+0

내 코드는 있지만 태양은 여전히 ​​검은 색입니다. – DAWID