ios – How to create a SCNNode with a geometry created using an array of x, y, and z values?



I am trying to create a SCNNode whose geometry is created using an array of x, y, and z positions. I am using the following code; however, this is not showing up. Does anyone know what’s wrong?

class CustomShapeNode: SCNNode {
    init(positions: [(Double, Double, Double)]) {
        // Create an array of SCNVector3 from the positions array
        var scnPositions = [SCNVector3]()
        for position in positions {
            scnPositions.append(SCNVector3(Float(position.0), Float(position.1), Float(position.2)))
        // Create a geometry from the positions array
        let geometry = SCNGeometry(sources: [SCNGeometrySource(vertices: scnPositions)], elements: [SCNGeometryElement(indices: Array(0..<scnPositions.count), primitiveType: .triangles)])
        // Set the geometry to the node
        self.geometry = geometry
        // Set the color of the node geometry
        self.geometry?.firstMaterial?.diffuse.contents =

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")