忘记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
而不是相机。
这里的诀窍是将你的新灯光添加到相机节点或它的一个孩子。这样,当相机移动时,光线也会移动。尝试通过['scnView.pointOfView'属性]访问默认相机节点(https://developer.apple.com/library/mac/documentation/SceneKit/Reference/SCNSceneRenderer_Protocol/index.html#//apple_ref/occ/intfp/ SCNSceneRenderer/pointOfView)。 – lock
让你的灯光成为相机的孩子,让相机成为根的孩子。将几何节点放入容器中,使其成为根的子项。保持几何独立于相机。 (切勿移动根!)默认照明和相机在选项中是基本的。创建你自己的更好,并不那么困难。 – bpedit
谢谢!我会试试看! –