我正在构建一个scenekit
应用程序,但是我遇到了一些更精细的问题。我创建了一个scene
,我正在向它添加自定义几何图形,它工作正常,直到节点数量达到大约 100。将大量节点添加到场景中是理想的,有没有更清洁的方法来做到这一点?
for i in 0..<modelArr!.count {
let model = modelArr![i]
let pos: [SCNVector3] = Parser.loadPosition(model)
let norm:[SCNVector3] = Parser.loadNormals(model)
let ind:[CInt] = Parser.loadIndices(model)
let src = SCNGeometrySource(vertices: pos, count: pos.count)
let norSrc = SCNGeometrySource(normals: norm, count: norm.count)
//let indexData = NSData(bytes: ind, length: sizeof(CInt) * ind.count)
let indexData = NSData(bytes: Array<CInt>(0..<CInt(ind.count)),
length: ind.count * sizeof(Float))
let element = SCNGeometryElement(data: indexData,
primitiveType: .Triangles,
primitiveCount: pos.count / 3,
bytesPerIndex: sizeof(Float))
let geo = SCNGeometry(sources: [src, norSrc], elements: [element])
let material = SCNMaterial()
material.diffuse.contents = UIColor.redColor()
material.specular.contents = UIColor.whiteColor()
let cubeNode = SCNNode(geometry: geo)
cubeNode.geometry?.firstMaterial = material
emptyNode.addChildNode(cubeNode)
}
scn.rootNode.addChildNode(emptyNode)
}
我有大量的索引、法线和位置。