如何在SceneKit中以编程方式将png纹理包裹在立方体周围 [英] How to programmatically wrap png texture around cube in SceneKit
问题描述
我是SceneKit的新手,正在尝试使一些基本的东西工作至今没有取得太大的成功.由于某些原因,当我尝试将png纹理应用于CNBox时,我最终只能得到黑色.这是我在viewDidLoad中拥有的简单代码段:
I'm new to SceneKit... trying to get some basic stuff working without much success so far. For some reason when I try to apply a png texture to a CNBox I end up with nothing but blackness. Here is the simple code snippet I have in viewDidLoad:
let sceneView = (view as SCNView)
let scene = SCNScene()
let boxGeometry = SCNBox(width: 10.0, height: 10.0, length: 10.0, chamferRadius: 1.0)
let mat = SCNMaterial()
mat.locksAmbientWithDiffuse = true
mat.diffuse.contents = ["sofb.png","sofb.png","sofb.png","sofb.png","sofb.png", "sofb.png"]
mat.specular.contents = UIColor.whiteColor()
boxGeometry.firstMaterial = mat
let boxNode = SCNNode(geometry: boxGeometry)
scene.rootNode.addChildNode(boxNode)
sceneView.scene = scene
sceneView.autoenablesDefaultLighting = true
sceneView.allowsCameraControl = true
最终看起来像是一个白色光源,在黑色背景下从黑色立方体反射回来.我想念什么?我感谢所有答复
What it ends up looking like is a white light source reflecting off of a black cube against a black background. What am I missing? I appreciate all responses
推荐答案
仅reflective
材质属性和场景的background
支持传递图像数组(以创建立方体贴图).
Passing an array of images (to create a cube map) is only supported by the reflective
material property and the scene's background
.
在您的情况下,所有图像都是相同的,因此您只需将图像(而不是数组)分配给内容,使其出现在框的所有侧面
In your case, all the images are the same, so you would only have to assign the image (not an array) to the contents to have it appear on all sides of the box
这篇关于如何在SceneKit中以编程方式将png纹理包裹在立方体周围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!