你能改变scnView.autoenablesDefaultLighting的属性吗?

时间:2016-07-31 20:51:30

标签: ios swift scenekit

我需要灯光才能保持静止"在我的场景中。到目前为止我发现的最好的照明方法是实际使用scnView.autoenablesDefaultLighting = true但是,我无法弄清楚是否有任何方法可以控制某些属性。光的强度是BIT太亮,光的位置是BIT不同于我喜欢它的那些属性。

我尝试过使用各种其他灯光,单独编码但是因为它们作为节点添加到场景中,当我设置scnView.allowsCameraControl = true时灯光(在这些情况下)本身会移动。默认照明是唯一一个将保持静止"一旦用户开始移动相机。您可以访问/控制默认照明的属性吗?

1 个答案:

答案 0 :(得分:4)

如果想要控制场景,请忘记allowsCameraControl并默认相机和灯光。

let sceneView = SCNView()
let cameraNode = SCNNode()          // the camera
var baseNode = SCNNode()            // the basic model-root
let keyLight = SCNLight()       ;   let keyLightNode = SCNNode()
let ambientLight = SCNLight()   ;   let ambientLightNode = SCNNode()

func sceneSetup() {
    let scene = SCNScene()
    // add to an SCNView
    sceneView.scene = scene

    // add the container node containing all model elements
    sceneView.scene!.rootNode.addChildNode(baseNode)

    cameraNode.camera = SCNCamera()
    cameraNode.position = SCNVector3Make(0, 0, 50)
    scene.rootNode.addChildNode(cameraNode)

    keyLight.type = SCNLightTypeOmni
    keyLightNode.light = keyLight
    keyLightNode.position = SCNVector3(x: 10, y: 10, z: 5)
    cameraNode.addChildNode(keyLightNode)

    ambientLight.type = SCNLightTypeAmbient
    let shade: CGFloat = 0.40
    ambientLight.color = UIColor(red: shade, green: shade, blue: shade, alpha: 1.0)
    ambientLightNode.light = ambientLight
    cameraNode.addChildNode(ambientLightNode)

    // view the scene through your camera  
    sceneView.pointOfView = cameraNode

    // add gesture recognizers here
}

移动或旋转cameraNode以在视图中实现动作。或者,移动或旋转baseNode。无论哪种方式,您的灯都相对于相机保持固定。

如果您希望灯光相对于模型固定,请将它们设为baseNode而不是相机。

相关问题