2014-07-11 19 views
8

当我创建使用雨燕语言的新场景套件游戏,已经有一些来赋予这个结果: enter image description here
我想关闭该照明立方体环境光,但我不明白如何要做到这一点,因为没有任何光明确附加到任何节点。如何关闭Scene Kit中的环境光(使用Swift)?

她是游戏视图控制器代码:

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

我已经移植你的代码到ObjC并在iOS SceneKit模板中替换,我只是将NSImage和NSColor更改为UIImage和UIColor,并且渲染了该多维数据集,但没有纹理或灯光,你有什么想法问题可能是?我猜测代码正在加载模板中的默认纹理。我是否需要为代码添加灯光? – rraallvv

回答

10

它看起来像你所看到的“默认”照明。

可以明确调用

gameView.autoenablesDefaultLighting = false 

这也将是禁用只要你添加自己的灯光场景禁用它。

+0

这也可以从StoryBoard中的SCNView检查器中关闭 – Toyos

+0

非常感谢!我忘了谢谢你! –