我尝试通过 .autoenablesDefaultLighting
实例属性在 SCNView 中打开和关闭默认照明,但不起作用(无论是在 UI 中还是以编程方式)。
当没有光时,我需要所有物体都是黑色的。
如何关闭默认灯光?
这是一个代码:
import SceneKit
import QuartzCore
class GameViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
let scnView = SCNView(frame: NSRect(x: 0,
y: 0,
width: 450,
height: 300))
view.addSubview(scnView)
scnView.autoenablesDefaultLighting = false // DOESN'T WORK
scnView.allowsCameraControl = true
scnView.backgroundColor = NSColor.blue
let scene = SCNScene()
scnView.scene = scene
let sphereGeo = SCNSphere(radius: 2)
sphereGeo.segmentCount = 4
sphereGeo.materials.first?.diffuse.contents = NSColor.lightGray
let sphereNode = SCNNode(geometry: sphereGeo)
sphereNode.name = "Sphere Node"
scene.rootNode.addChildNode(sphereNode)
}
}
最佳答案
似乎只有当我使用基于物理的渲染
着色模型时它才起作用。
let material = SCNMaterial()
material.lightingModel = SCNMaterial.LightingModel.physicallyBased
sceneView.autoenablesDefaultLighting = false
如果我使用 .physicallyBased
类型属性为模型着色,则照明将按预期工作。
关于swift - SceneKit的实例属性 "autoenablesDefaultLighting"不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55903682/