【问题标题】:Light not moving with Camera - SceneKit光不随相机移动 - SceneKit
【发布时间】: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/…

标签: swift scenekit


【解决方案1】:

完美。唯一缺少的行如下。

sceneView.pointOfView = cameraNode

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-21
    • 1970-01-01
    • 2017-03-28
    • 2012-09-17
    • 2017-08-28
    • 2016-02-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多