当尝试从大量SCNVector3位置渲染某些多边形时,出现以下错误消息。我确实需要渲染多边形,但我不知道为什么会这样。如果有人知道另一种渲染多边形的方法,我将很乐意对其进行测试!
[MTLDebugDevice validateNewBufferArgs:options:]
:467: failed assertion Cannot create buffer of zero length.
以下代码用于创建自定义SCNGeometry。
extension SCNGeometry {
static func multiPolygon (vertices: [SCNVector3]) -> SCNGeometry {
var indices: [Int32] = [Int32(vertices.count)]
indices.append(contentsOf: generateIndices(max: vertices.count))
let vertexSource = SCNGeometrySource(vertices: vertices )
let indexData = Data(bytes: indices,
count: indices.count * MemoryLayout<Int32>.size)
let element = SCNGeometryElement(data: indexData,
primitiveType: .polygon,
primitiveCount: 1,
bytesPerIndex: MemoryLayout<Int32>.size)
return SCNGeometry(sources: [vertexSource], elements: [element])
}
static private func generateIndices(max maxIndexValue: Int) -> [Int32]{
var counter: Int = 0
var output: [Int32] = []
while counter < maxIndexValue {
output.append(Int32(counter))
counter += 1
}
return output
}
}