
254
|
第
8
章
8.9
纹理对象
问题
我们要在物体上使用纹理。
解决方案
要在一个对象上使用纹理,首先需要从某个地方获得纹理。通常,我们会从文件中
加载纹理:
let loadedTexture = SKTexture(imageNamed: "Ball")
一旦获得纹理对象,就可以将它赋给材质的反射(
diffuse
)组件:
let textureMaterial = SCNMaterial()
textureMaterial.diffuse.contents = loadedTexture
text.materials = [textureMaterial]
讨论
除了从文件中加载图片,我们还可以用
Sprite Kite
来产生一个杂点图片:
let noiseTexture = SKTexture(noiseWithSmoothness: 0.25,
size: CGSize(width: 512, height: 512), grayscale: true)
let noiseMaterial = SCNMaterial()
noiseMaterial.diffuse.contents = noiseTexture
//
现在可以将
noiseMaterial
赋给一个对象
8.10
法向贴图
问题
我们想在物体上使用凹凸贴图。
解决方案
要使物体表面显得粗糙不平,可以在材质上使用法向贴图。我们既可以从位图中加
载法向贴图,也可以用
Sprite Kit
生成法向贴图: