我的灯光不跟随我的相机。
在将相机添加到场景之前,我已经将灯光作为相机的子节点添加了进去,但这仍然无法解决问题。
override func viewDidLoad()
{
super.viewDidLoad()
let scene = SCNScene()
let shipScene = SCNScene(named: "merchant.scn")
guard let shipNode = shipScene?.rootNode.childNode(withName: "merchant", recursively: true)
else
{
fatalError("ShipModel is not found!")
}
shipNode.position = SCNVector3(x:0, y:0, z:0)
scene.rootNode.addChildNode(shipNode)
let lightNode = SCNNode()
lightNode.light = SCNLight()
lightNode.light?.type = .omni
lightNode.position = SCNVector3(x:0, y:2, z:10)
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3(x:0, y:1, z:8)
cameraNode.addChildNode(lightNode)
scene.rootNode.addChildNode(cameraNode)
let sceneView = self.view as! SCNView
sceneView.scene = scene
sceneView.showsStatistics = true
sceneView.backgroundColor = UIColor.gray
sceneView.allowsCameraControl = true
}
无论相机的位置如何,灯光仍然只照亮模型的正面。