如何关闭 Scene Kit(使用 Swift)中的环境光? [英] How to I turn off the ambient light in Scene Kit (with Swift)?

查看:73
本文介绍了如何关闭 Scene Kit(使用 Swift)中的环境光?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 Swift 语言创建一个新的 Scene Kit 游戏时,已经有一些来给出这个结果:
我想关闭照亮立方体的环境光,但我不知道该怎么做,因为没有任何光明确附加到任何节点.

When I create a new Scene Kit Game using the Swift language, there is already some come which gives this result :
I want to turn off the ambient light which is lighting the cube but I don't get how to do that since there isn't any light explicitly attached to any node.

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

Her's the Game View Controller code :

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

}

推荐答案

看起来您看到的是默认"照明.

It looks like you are seeing the "default" lighting.

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

You can explicitly disable it by calling

gameView.autoenablesDefaultLighting = false

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

It will also be disables as soon as you add your own lights to the scene.

这篇关于如何关闭 Scene Kit(使用 Swift)中的环境光?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆