【发布时间】:2018-04-04 19:34:12
【问题描述】:
我正在尝试弄清楚如何以编程方式将材质分配给我的 ARKit(XCode 9 / Swift 4)场景中的某个对象(SCNNode)。我正在尝试以编程方式执行此操作,因为我希望使用太多变体(或用户生成的图像)来渲染相同形状的对象,以便能够通过场景中的菜单分配来实现。该对象只是一个立方体 - 目前,我只是试图让一侧显示从 Assets 文件夹中提取的此材质。
这是我尝试引用以前的 Stack 帖子的当前代码,但对象只是保持白色。
let material = SCNMaterial()
material.diffuse.contents = UIImage(named: "texture.jpg")
let nodeObject = self.lastUsedObject?.childNode(withName: "box", recursively: true)
// I believed this lets me grab the last thing I rendered in an ARKit scene - please
// correct me if I'm wrong. My object is also labeled "box".
nodeObject?.geometry?.materials
nodeObject?.geometry?.materials[0] = material // I wanted to grab the first face of the box
提前非常感谢您!我一直在摆弄这个,但我似乎无法掌握 Swift 中 3D 对象/场景的编程方法。
【问题讨论】:
-
首先,改变那些?到 !看看你的程序是否崩溃。如果它崩溃了,你就知道你没有抓住你的盒子
-
是的,当我将其更改为“!”时它崩溃了- 感谢您的提醒。
标签: swift scenekit arkit scnnode