I'm trying to create a custom SCNPlane class that could have the form of any polygon, as the regular SCNPlane can only be a rectangle.
I have attempted to accomplish this by extending SCNGeometry. Below is the code I use:
extension SCNGeometry {
static func polygonPlane(vertices: [SCNVector3]) -> SCNGeometry {
let src = SCNGeometrySource(vertices: vertices)
var indices: [UInt32] = []
var index: UInt32 = 0
for _ in vertices {
indices.append(index)
index += 1
}
let inds = SCNGeometryElement(indices: indices, primitiveType: .polygon)
return SCNGeometry(sources: [src], elements: [inds])
}
}
As you can see the method takes an array of vertices as input, and my wish is to connect these in order to make a plane with a specified geometry using the vertices provided.
When using SCNGeometryPrimitiveType.polygon as in the code above I get a weird error: "Thread 1: EXC_BREAKPOINT (code=1, subcode=0x106362e20)". It seems as the functionality for this case is not implemented in swift, but that it is for Objective-C? Is there any way for me to make use of this?
I also tried using the other options for the primitiveType-value, and there is no crash using those values, further strengthening my belief that there is something wrong with the .polygon case.