As written in the docs for MDLMesh: "Typically, you obtain meshes by traversing the object hierarchy of a
MDLAsset
object, but
you can also create meshes from your own vertex data or create parametric meshes"
The bold part is what I aim to do, create meshes from my own vertex data. Specifically I have a half-edge datastructure that is updated frequently (though not every frame). I currently use geometryWithSources to generate a SCNGeometry object and assign that to an SCNNode. I want to utilize the normal generation and subdivision and file export options etc from ModelIO. I can load the SCNGeometry into an MDLMesh, create another one based on that using initMeshBySubdividingMesh and then generate normals and then turn it into SCNGeometry again. Aside from the memory leaks in subdivision (another topic...) that works, but it's obviously not efficient and affects performance negavtively.
During rebuilding of the geometry (based on the half edge data structure's data) I end up with basic arrays for vertex positions and indices and colors. I then use geometrySourceWithVertices to create the geometry source, and then use geometrySourceWithData to create the SCNGeometryElement from the incides and another SCNGeometrySource for the color data (on a side note it appears there could or should be a geometrySourceWithColors too).
The few code samples I could find cover at best how to create an MDLMesh from an asset, I would very much appreciate an (obj c) sample of how to use MDLMesh with programmatically generated vertex data instead. Specifcally it seems nobody (as a matter of speaking, based on google search) uses initWithVertexBuffer of MDLMesh.
Long story short, how can I go from SCNVector vertexpos[] and int indices[] (currently stored as described here: https://developer.apple.com/documentation/scenekit/scngeometryprimitivetype/scngeometryprimitivetypepolygon z) to an MDLMesh directly.
To put it in yet a different way, I'd like to see some more examples/sample code from Apple (or anyone else of course) on creating and rendering (in scenekit or metal) an MDLMesh not loaded from an asset like the fighter jet but from vertex data for a simple cube or 4-vertex plane even.