我正在创建一个自定义 SCNGeometry。首先,我将其开发为平面。它会显示,我可以将颜色应用到它的漫反射内容,但如果我尝试应用任何东西,例如 UIImage 或 CALayer,它会显示为白色。
代码:
let positions = [
SCNVector3(-1, 0, 0),
SCNVector3(1, 0, 0),
SCNVector3(-1, 0, -1),
SCNVector3(1, 0, -1)
]
let indices: [UInt8] = [
0, 1, 2,
1, 3, 2
]
let vertexSource = SCNGeometrySource(vertices: positions)
let indexData = Data(bytes: indices, count: indices.count)
let element = SCNGeometryElement(
data: indexData,
primitiveType: SCNGeometryPrimitiveType.triangles,
primitiveCount: indices.count / 3,
bytesPerIndex: 1)
let geometry = SCNGeometry(
sources: [vertexSource],
elements: [element])
geometry.firstMaterial?.diffuse.contents = UIImage(named: "homer")