【发布时间】:2019-06-10 03:26:30
【问题描述】:
我的灯没有跟随我的相机。
在将相机添加到场景之前,我已将灯光添加为相机的 childNode,但这仍然不能解决问题。
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
}
无论相机的位置如何,灯光仍然只照亮模型的最前面。
【问题讨论】:
-
您确定所选答案解决了这个问题吗?我遇到了同样的问题,但在我的情况下,设置
pointOfView不是解决方案。我设法让这个工作的唯一方法是使用SCNSceneRendererDelegate在每一帧中对齐灯光和相机。但是,该策略会导致光/影闪烁,因此不好。见stackoverflow.com/questions/71537020/…