我需要灯光在我的场景中保持“静止”。到目前为止我发现的最好的照明方法是实际使用 scnView.autoenablesDefaultLighting = true
但是,我不知道是否有任何方法可以控制某些属性。光的强度有点太亮,光的位置与我想要的位置有点不同,这些属性。
我尝试过使用各种其他灯光,对它们单独编码,但是因为它们作为节点添加到场景中,当我设置 scnView.allowsCameraControl = true
时,灯光(在那些情况下)本身会移动.一旦用户开始四处移动相机,默认照明是唯一会保持“静止”的照明。您可以访问/控制默认照明的属性吗?
最佳答案
如果您想控制场景,请忘记 allowsCameraControl
和默认相机和灯光。
let sceneView = SCNView()
let cameraNode = SCNNode() // the camera
var baseNode = SCNNode() // the basic model-root
let keyLight = SCNLight() ; let keyLightNode = SCNNode()
let ambientLight = SCNLight() ; let ambientLightNode = SCNNode()
func sceneSetup() {
let scene = SCNScene()
// add to an SCNView
sceneView.scene = scene
// add the container node containing all model elements
sceneView.scene!.rootNode.addChildNode(baseNode)
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3Make(0, 0, 50)
scene.rootNode.addChildNode(cameraNode)
keyLight.type = SCNLightTypeOmni
keyLightNode.light = keyLight
keyLightNode.position = SCNVector3(x: 10, y: 10, z: 5)
cameraNode.addChildNode(keyLightNode)
ambientLight.type = SCNLightTypeAmbient
let shade: CGFloat = 0.40
ambientLight.color = UIColor(red: shade, green: shade, blue: shade, alpha: 1.0)
ambientLightNode.light = ambientLight
cameraNode.addChildNode(ambientLightNode)
// view the scene through your camera
sceneView.pointOfView = cameraNode
// add gesture recognizers here
}
移动或旋转 cameraNode
以影响 View 中的运动。或者,移动或旋转 baseNode
。无论哪种方式,您的灯光相对于相机保持固定。
如果您希望灯光相对于模型固定,请将它们设为 baseNode
的子节点,而不是相机。
关于ios - 您可以更改 scnView.autoenablesDefaultLighting 的属性吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38688306/