2014-07-11 12 views
8

Quando creo un nuovo gioco Kit scena utilizzando il linguaggio Swift, c'è già alcune sono che dà questo risultato: enter image description here
voglio spegnere la luce ambientale, che è l'illuminazione il cubo, ma non ho ricevuto come per farlo poiché non c'è luce esplicitamente collegata a nessun nodo.Come si spegne la luce ambientale in Scene Kit (con Swift)?

Il suo è il codice di gioco View Controller:

import SceneKit 
import QuartzCore 

class GameViewController: NSViewController { 

    @IBOutlet var gameView: GameView 

    override func awakeFromNib(){ 
     // create a new scene 
     let scene = SCNScene() 

     // create and add a camera to the scene 
     let cameraNode = SCNNode() 
     cameraNode.camera = SCNCamera() 
     scene.rootNode.addChildNode(cameraNode) 

     // place the camera 
     cameraNode.position = SCNVector3(x: 0, y: 0, z: 2) 

     // create and add a 3d box to the scene 
     let boxNode = SCNNode() 
     boxNode.geometry = SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0.02) 
     scene.rootNode.addChildNode(boxNode) 

     // create and configure a material 
     let material = SCNMaterial() 
     material.diffuse.contents = NSImage(named: "texture") 
     material.specular.contents = NSColor.whiteColor() 
     material.specular.intensity = 0.2 
     material.locksAmbientWithDiffuse = true 

     // set the material to the 3d object geometry 
     boxNode.geometry.firstMaterial = material 

     // animate the 3d object 
     let animation: CABasicAnimation = CABasicAnimation(keyPath: "rotation") 
     animation.toValue = NSValue(SCNVector4: SCNVector4(x: 1, y: 1, z: 0, w: M_PI*2)) 
     animation.duration = 5 
     animation.repeatCount = MAXFLOAT //repeat forever 
     boxNode.addAnimation(animation, forKey: "") 

     // set the scene to the view 
     self.gameView!.scene = scene 

     // allows the user to manipulate the camera 
     self.gameView!.allowsCameraControl = true 

     // show statistics such as fps and timing information 
     self.gameView!.showsStatistics = true 

     // configure the view 
     self.gameView!.backgroundColor = NSColor.blackColor() 
    } 

} 
+0

Ho portato il codice a ObjC e sostituito nel modello di SceneKit di iOS, ho appena cambiato NSImage e NSColor in UIImage e UIColor, e il cubo è renderizzato, ma non c'è trama né luci, hai un'idea il problema potrebbe essere? Immagino che il codice sta caricando la trama predefinita nel modello. Devo aggiungere una luce al tuo codice? – rraallvv

risposta

10

Sembra che si sta vedendo la luce "default".

È possibile disattivare in modo esplicito chiamando

gameView.autoenablesDefaultLighting = false 

Sarà anche disabili, non appena si aggiungono le proprie luci per la scena.

+0

Questo può anche essere disattivato dall'ispettore SCNView in StoryBoard – Toyos

+0

Grazie mille! Mi ero dimenticato di ringraziarti! –

Problemi correlati