SceneKit:向摄像机节点添加定向光无效

Cra*_*lot 5 scenekit scnnode scnlight scnscene

根据本答案中的建议,目标是向场景添加环境光以及相机的定向光.

这适用于Xcode场景编辑器,定向灯设置为70%白色,环境光设置为50%白色.方向灯的欧拉角使用默认值.

编码这种安排失败了.就好像没有添加定向灯一样.对场景没有影响; 好像只有环境光存在.

x欧拉角分量的不同值没有区别 - 尝试了PI/2,PI和其他值,但仍然没有变化.

但是,将方向光添加到场景的根节点(scene.rootNode.addChildNode(directionalLightNode))确实会将光添加到场景中.

fileprivate func addLightNode() {
    // Create ambient light
    let ambientLightNode = SCNNode()
    ambientLightNode.light = SCNLight()
    ambientLightNode.light!.type = .ambient
    ambientLightNode.light!.color = UIColor(white: 0.70, alpha: 1.0)

    // Add ambient light to scene
    scene.rootNode.addChildNode(ambientLightNode)

    // Create directional light
    let directionalLight = SCNNode()
    directionalLight.light = SCNLight()
    directionalLight.light!.type = .directional
    directionalLight.light!.color = UIColor(white: 1.0, alpha: 1.0)
    directionalLight.eulerAngles = SCNVector3(x: 0, y: 0, z: 0)

    // Add directional light to camera
    let cameraNode = sceneView.pointOfView!
    cameraNode.addChildNode(directionalLight)
}
Run Code Online (Sandbox Code Playgroud)

Xar*_*tec 4

创建一个 SCNNode,例如名称为“cameraNode”的节点。\n创建一个 SCNCamera 并将其分配给“ cameraNode”的相机属性。\n将“cameraNode”添加到场景中(作为 rootNode 的子节点)。

\n\n

之后,您可以将灯光节点添加为cameraNode的子节点,或者,给定它\xe2\x80\x99s唯一的相机,作为pointOfView节点(现在代表您创建并添加到场景中的cameraNode)的子节点。默认相机及其 pointOfView 节点不是 scene\xe2\x80\x99s 对象层次结构的一部分。

\n