Hey. I've combed through the seriously weak documentation, looked for examples (none of which are in Swift) I found an Obj-C example and converted it. It doesn't work. It creates an empty hierarchy of SCNNodes. What is going on here? this is the third time, I've written SCNGeometry code from scratch, using examples from different sources, trying to follow the insanely arcane, undocumented, and openGL-ish design pattern. This time, I've taken Obj-C code, and simply converted it, leaving everything as close to the original as possible.
what is going on?
// BKPivotNode is a subclass of SCNNode.
func genTubeTest(aPivot: BKPivotNode)->SCNNode{
var retNode = SCNNode()
if aPivot.children.isEmpty != true{
for aChild in aPivot.childNodes{
if let bChild = aChild as? BKPivotNode {
let sources = [SCNGeometrySource(vertices: [ SCNVector3(x: -1.0, y: -1.0, z: 0),
SCNVector3(x: -1.0, y: 1.0, z: 0),
SCNVector3(x: 1.0, y: 1.0, z: 0),
SCNVector3(x: 1.0, y: -1.0, z: 0)], count: 4 ),
SCNGeometrySource(normals: [ SCNVector3(x: 0.0, y: 0.0, z: -1.0),
SCNVector3(x: 0.0, y: 0.0, z: -1.0),
SCNVector3(x: 0.0, y: 0.0, z: -1.0),
SCNVector3(x: 0.0, y: 0.0, z: -1.0)], count: 4 ),
SCNGeometrySource(textureCoordinates: [ CGPoint(x: 0.0, y: 0.0),
CGPoint(x: 0.0, y: 1.0),
CGPoint(x: 1.0, y: 1.0),
CGPoint(x: 1.0, y: 0.0)], count: 4 )]
let newElement = SCNGeometryElement(data: NSData(bytes: [0, 2, 3,0,1,2], length: sizeof(Int)), primitiveType: .Triangles, primitiveCount: 2, bytesPerIndex: sizeof(Int))
let newGeo = SCNGeometry(sources:sources, elements:[newElement])
let newMat = SCNMaterial()
newMat.diffuse.contents = NSColor.redColor()
newMat.transparency = 0.5
newMat.doubleSided = true
newGeo.firstMaterial = newMat;
let newNode = SCNNode()
newNode.geometry = newGeo
retNode.addChildNode(newNode)
}
}
}
return retNode
}