我需要灯光在我的场景中保持“静止”。到目前为止,我发现的最好的照明方法是实际使用scnView.autoenablesDefaultLighting = true,但是,我不知道是否有任何方法可以控制一些属性。光的强度有点太亮了,光的位置和我想要的位置有点不同,这些属性。
我尝试使用所有其他类型的灯光,分别对它们进行编码,但由于它们作为节点添加到场景中,当我设置scnView.allowsCameraControl = true时,灯光(在这些情况下)本身将移动。默认照明是唯一一种在用户开始移动相机时保持“静止”的照明。您可以访问/控制默认照明的属性吗?
发布于 2016-08-03 07:37:11
如果希望控制场景,请忽略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以实现视图中的运动。或者,移动或旋转baseNode。无论哪种方式,您的灯光相对于摄影机都是固定的。
如果要相对于模型固定灯光,请将其设置为baseNode的子项,而不是摄影机的子项。
发布于 2021-08-27 08:05:05
如果有人想知道如何通过与swift ui集成的新Scenekit来设置整个场景,可以试试这个。这个工作得很好。
struct TestControllerNew: View {
let sceneView = SCNView()
let cameraNode = SCNNode()
var baseNode = SCNNode()
let id = "D69A09F8-EA80-4231-AD35-4A9908B4343C"
var scene = SCNScene()
var body: some View {
SceneView(
scene: sceneSetup(),
pointOfView: cameraNode,
options: [
.autoenablesDefaultLighting
]
)
}
func getTermsOfUseURL() -> URL {
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
return paths[0].appendingPathComponent("\(id).usdz")
}
func sceneSetup() -> SCNScene {
let scene = try! SCNScene(url: getTermsOfUseURL())
// 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, 1, 10)
scene.rootNode.addChildNode(cameraNode)
// view the scene through your camera
sceneView.pointOfView = cameraNode
// add gesture recognizers here
return scene
}
}在这里,从文档目录获取的USDZ文件作为URL,您可以使用name代替它。
https://stackoverflow.com/questions/38688306
复制相似问题