我正在为 IOS 开发一款基于 3D SceneKit 的基本游戏,我发现我在编辑器中选择的颜色与模拟中显示的颜色不匹配(屏幕截图 https://pasteboard.co/HVWdnnK.png )
代码与默认的 SceneKit 游戏代码几乎相同,只是我注释了配置灯光和所有内容的部分,因为它们已经在编辑器中手动配置了(我有一种感觉,我可能会遗漏一些东西在这里)
如果您能看一下,我将不胜感激。
override func viewDidLoad() {
super.viewDidLoad()
// create a new scene
let scene = SCNScene(named: "art.scnassets/ship.scn")!
// create and add a camera to the scene
let cameraNode = scene.rootNode.childNode(withName: "corner-camera", recursively: true)!
// cameraNode.camera = SCNCamera()
// scene.rootNode.addChildNode(cameraNode)
// place the camera
// let camera = scene.rootNode.childNode(withName: "corner-camera", recursively: true)!
// cameraNode.position = SCNVector3(x: 0, y: 0, z: 15)
// create and add a light to the scene
// let lightNode = SCNNode()
// lightNode.light = SCNLight()
// lightNode.light!.type = .omni
// lightNode.position = SCNVector3(x: 0, y: 10, z: 10)
// scene.rootNode.addChildNode(lightNode)
// create and add an ambient light to the scene
// let ambientLightNode = SCNNode()
// ambientLightNode.light = SCNLight()
// ambientLightNode.light!.type = .ambient
// ambientLightNode.light!.color = UIColor.darkGray
// scene.rootNode.addChildNode(ambientLightNode)
// retrieve the ship node
// let ship = scene.rootNode.childNode(withName: "ship", recursively: true)!
// animate the 3d object
// ship.runAction(SCNAction.repeatForever(SCNAction.rotateBy(x: 0, y: 2, z: 0, duration: 1)))
// retrieve the SCNView
let scnView = self.view as! SCNView
// set the scene to the view
scnView.scene = scene
// set camera to corner-camera
scnView.pointOfView = cameraNode
// allows the user to manipulate the camera
// scnView.allowsCameraControl = true
// show statistics such as fps and timing information
// scnView.showsStatistics = true
// configure the view
scnView.backgroundColor = UIColor.white
// add a tap gesture recognizer
// let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:)))
// scnView.addGestureRecognizer(tapGesture)
}
最佳答案
有一件事是模拟器使用 OpenGL 渲染器,而 Xcode 和 iOS 设备默认使用 Metal 渲染器。
Xcode 编辑器还具有多个选项来自定义渲染场景的方式,并且“default lighting ”选项可能与应用程序使用的选项不匹配。
关于ios - Swift SceneKit - 编辑器和模拟之间的色差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54145079/