加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何关闭Scene Kit中的环境光(使用Swift)?

发布时间:2020-12-14 05:31:29 所属栏目:百科 来源:网络整理
导读:当我使用 Swift语言创建一个新的Scene Kit游戏时,已经出现了一些结果: 我想要关闭照亮立方体的环境光,但我不知道如何做到这一点,因为没有明确附加到任何节点的任何光. 她的游戏视图控制器代码: import SceneKitimport QuartzCoreclass GameViewController:
当我使用 Swift语言创建一个新的Scene Kit游戏时,已经出现了一些结果:

我想要关闭照亮立方体的环境光,但我不知道如何做到这一点,因为没有明确附加到任何节点的任何光.

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

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()
    }

}
看起来你正在看到“默认”照明.

您可以通过调用显式禁用它

gameView.autoenablesDefaultLighting = false

只要您将自己的灯光添加到场景中,它也会被禁用.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读