I can’t find any examples online showing the proper creation of triangles for SCNGeometry
that don't use the NSData
/Data
API. I’m trying to do this but nothing renders:
func
testTriangles()
-> SCNNode
{
// Vertices…
var vertices = [SCNVector3]()
vertices.append(SCNVector3(x: 0.0, y: 0.0, z: 0.0))
vertices.append(SCNVector3(x: 0.0, y: 0.0, z: 50.0))
vertices.append(SCNVector3(x: 50.0, y: 0.0, z: 50.0))
let vertexSource = SCNGeometrySource(vertices: vertices)
var normals = [SCNVector3]()
normals.append(SCNVector3(x: 0.0, y: 1.0, z: 0.0))
normals.append(SCNVector3(x: 0.0, y: 1.0, z: 0.0))
normals.append(SCNVector3(x: 0.0, y: 1.0, z: 0.0))
let normalSource = SCNGeometrySource(normals: normals)
// Indices…
var indices = [0, 1, 2]
let triangles = SCNGeometryElement(indices: indices, primitiveType: .triangles)
let geom = SCNGeometry(sources: [vertexSource, normalSource], elements: [triangles])
let node = SCNNode()
node.geometry = geom
let mat = SCNMaterial()
mat.diffuse.contents = NSColor.green
geom.materials = [mat]
return node
}