【发布时间】:2019-05-16 01:10:40
【问题描述】:
我已经从这篇文章成功地在 SceneKit 中构建并显示了一个自定义几何体(一个立方体)
现在,我想将每张脸的颜色设置为不同的颜色。我发现这篇文章应该这样做
不幸的是,我似乎无法将立方体面的颜色设置为特定颜色。例如,如果我将所有顶点的颜色设置为SCNVector3(x:1,y:0,z:0),我希望所有面都是红色的,但相反,它们都是绿色的。将颜色设置为SCNVector3(x:0,y:1,z:0) 会将面变为黑色。这是相关代码
let colors = [SCNVector3](count:vertices.count, repeatedValue:SCNVector3(x:1, y:0, z:0))
let colorData = NSData(bytes: colors, length: sizeof(SCNVector3) * colors.count)
let colorSource = SCNGeometrySource(data: colorData, semantic: SCNGeometrySourceSemanticColor, vectorCount: colors.count, floatComponents: true, componentsPerVector: 3, bytesPerComponent: sizeof(Float), dataOffset: 0, dataStride: sizeof(SCNVector3))
let geometry = SCNGeometry(sources: [colorSource, vertexSource, normalSource], elements: [element])
// Create a node and assign our custom geometry
let node = SCNNode()
let material = SCNMaterial()
material.diffuse.contents = NSColor.whiteColor()
geometry.materials = [material]
node.geometry = geometry
有谁知道为什么它不起作用?
【问题讨论】: