Member-only story
Custom Geometry in SceneKit Under SwiftUI
Continuing an investigation into SceneKit

The other week, I published this article, a piece looking at quaternions in SceneKit. Within it, I published a very short snippet of code that — well, could almost have come out of Kernighan & Ritchie’s classic C guide, a rough edge in the framework, I feel.
Sorry to say that when you start to work with custom geometry in SceneKit, you might find yourself in the same place — indeed deeper, since not only do some of the code templates look like they came out of a computer science class, but the math can be equally baffling too.
So let me begin this CS class code with what Apple should have put into the framework, this excellent extension that I found here.
Together with this class; we will build a custom geometric shape for you [with the exception of polygons, later].
Now, onto the details.
SCNGeometrySource
Bon — as I have been using these past few weeks, SceneKit provides half a dozen pre-baked shapes, standard ones like cubes or spheres, the docs you can find here.
They’re all good, but of course, if you want more than you got two main choices; the first is to use a model built with a CAD app like Blender or Fusion 360 or to use custom geometry shape.
Now building shapes is/can be a bit twiddling work since you find yourself working with coordinates or vertices, as SceneKit calls them. Vertices in custom shapes are the corners of shape, the points which mark where two edges meet. You also find yourself working with indices too, which, to be honest, are a little bit of black art, it seems sometimes. For the most part, indices dictate the order in…