I have a binary file that contains many triples of Float
values; it is actually a long array of SCNVector3
representing the vertices for a SCNGeometrySource
. I read the file (excuse the omission of do-try-catch, etc) into memory:
let sceneVectors = Data(contentsOf: sceneURL)
and want to pass that in memory data as a [SCNVector3]
along to SceneKit:
let sceneGeometry = SCNGeometrySource(vertices: sceneVectors)
I've been wrestling today with using the UnsafePointer
mechanism to re-type the contents of Data
buffer as an array of SCNVector3
to satisfy the SCNGeometrySource
contract; something like this.
dataBuffer.withUnsafeBytes {
(vertexBuffer: UnsafePointer<SCNVector3>) -> SCNGeometry in
« magic happens here »
return sceneGeometry
}
My reading about this tells me that, within the closure, the buffer can be accessed as an array of SCNVector3
, but when passed to SCNGeometrySource
it causes Swift to report:
cannot convert value of type 'UnsafePointer<SCNVector3>' to expected argument type '[SCNVector3]'
As usual, I suspect there is a simple solution that I've not figured out yet, so I would appreciate any suggestion for resolving this.