【发布时间】:2017-12-15 14:25:16
【问题描述】:
我刚刚创建了项目:Xcode:文件 > 新建 > 项目 > 增强现实应用程序。
我想将 ship.scn 的颜色更改为黄色,但没有任何反应。如何更改 ship.scn 的颜色??
override func viewDidLoad() {
super.viewDidLoad()
sceneView.delegate = self
sceneView.showsStatistics = true
let scene = SCNScene(named: "art.scnassets/ship.scn")!
// here, trying to change the color of the ship.scn
scene.rootNode.geometry?.materials.first?.diffuse.contents = UIColor.yellow
sceneView.scene = scene
}
我尝试了断点和 po 命令来检查 rootNode 包含的内容。
(lldb) po scene.rootNode.childNodes
▿ 1 element
- 0 : <SCNNode: 0x1c01f8d00 'ship' | 1 child>
(lldb) po scene.rootNode.childNodes.first?.name
▿ Optional<String>
- some : "ship"
(lldb) po scene.rootNode.childNodes.first?.geometry
nil
为什么几何是零?我可以看到彩色的船。
【问题讨论】:
-
scene.rootNode.childNodes.first?.childNodes.first?.geometry?.materials.first?.diffuse.contents = UIColor.yellow