Chapter 6: Textures (without ModelI/O)

Per my post in Face normal vs vertex normal - #17 by ericmock I really don’t think Metal provides a direct way to enter face normals. If it did, then the people that wrote ModelIO were not aware of it. I suspect this is because in the vast majority of cases you don’t want faceted surfaces like you and I do.

The way I’ve overcome this appears to be similar to how ModelIO overcomes it, by repeating vertices. You will need three times the number of vertices as is necessary to define you’re hexagon mesh. (Well, not exactly if the centroid of each hexagon is a vertex.) This way you can assign three different normals to a vertex that describes the position of a corner of your hexagon.

I’m not sure how you want to organize the data structures but I went with defining a MyPolygon class (Polygon conflicts with something) that contains all the information for each face. In hindsight it probably should be a struct, but… Once I had all the polygons I just iterated over them to build by vertices (position, normal, etc.) and indices. It’s inefficient from a memory standpoint because the data send to the GPU is very repetitive, put there are few vertices compared to what you’d have in a complex scene.

The other option I considered was making a buffer of UInts that would map vertex IDs to normals in a buffer of normals. This would be more memory efficient but I didn’t feel like figuring out how to do it. The issue is figuring out which face you’re rendering in the vertex shader. Using sub-meshes for each face like Caroline did is probably the best way.