2017-11-01 2 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

関連する問題