swiftmetalmetalkitmodelio

How do I pull the data out of a MDLMeshBufferData to fill a MTKMeshBuffer?


I need to create a MTKMeshBuffer instance from a MDLMeshBufferData instance. Here is a code snippet:

let mdlm = MDLMesh(scnGeometry:sceneGeometry, bufferAllocator:nil)

let mdlSubmesh:MDLSubmesh = mdlm.submeshes?[ 0 ] as! MDLSubmesh

let mdlIndexBufferData:MDLMeshBufferData = mdlSubmesh.indexBuffer as! MDLMeshBufferData

let d:Data = mdlIndexBufferData.data

let mtlIndexBuffer:MTKMeshBuffer = device.makeBuffer(bytes: ???, length: ???, options:MTLResourceOptions.storageModeShared) as! MTKMeshBuffer

The ??? are the bits I need to fill. Can someone please show me the proper API to use to extract the bits from the MDL buffer to fill the MTK buffer?


Solution

  • The solution is to build the MTLBuffers for each of vertexBuffer and indexBuffer and use them in the draw loop. Works fine.

    See: https://github.com/turner/HelloMetal and run the HelloSceneKit target.