2016-07-31 97 views
0

我需要灯在我的场景中保持“固定”。目前为止我发现的最好的照明方法实际上是使用scnView.autoenablesDefaultLighting = true,但我无法弄清楚是否有任何方法可以控制某些属性。光线的强度太亮,光线的位置不同于我想要的位置,这些属性。你可以改变scnView.autoenablesDefaultLighting的属性吗?

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

+2

这里的诀窍是将你的新灯光添加到相机节点或它的一个孩子。这样,当相机移动时,光线也会移动。尝试通过['scnView.pointOfView'属性]访问默认相机节点(https://developer.apple.com/library/mac/documentation/SceneKit/Reference/SCNSceneRenderer_Protocol/index.html#//apple_ref/occ/intfp/ SCNSceneRenderer/pointOfView)。 – lock

+0

让你的灯光成为相机的孩子,让相机成为根的孩子。将几何节点放入容器中,使其成为根的子项。保持几何独立于相机。 (切勿移动根!)默认照明和相机在选项中是基本的。创建你自己的更好,并不那么困难。 – bpedit

+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而不是相机。

相关问题