I'm using this code to create a rectangle (that will eventually be a more complex shape):
let vertices = [simd_float3(x: 1, y: 1, z: 0), simd_float3(x: 1, y: -1, z: 0), simd_float3(x: -1, y: -1, z: 0), simd_float3(x: -1, y: 1, z: 0)]
let vertexSource = SCNGeometrySource(data: Data(bytes: vertices, count: MemoryLayout<simd_float3>.size * vertices.count), semantic: .vertex, vectorCount: vertices.count, usesFloatComponents: true, componentsPerVector: 3, bytesPerComponent: MemoryLayout<Float>.size, dataOffset: 0, dataStride: MemoryLayout<simd_float3>.stride)
let indices: [Int32] = Array(0..<Int32(vertices.count))
let element = SCNGeometryElement(data: Data(bytes: indices, count: MemoryLayout<Int32>.size * indices.count), primitiveType: .polygon, primitiveCount: 1, bytesPerIndex: MemoryLayout<Int32>.size)
let geometry = SCNGeometry(sources: [vertexSource], elements: [element])
which logs this error in the Xcode console:
[SceneKit] Error: SCNGeometryElement initialization - Invalid polygon edge count (0)
There also doesn't seem to be any documentation about how to use this .polygon
mode. When using .triangleStrip
with a primitiveCount of 2, no error is logged.