I've recently ported the hexasphere implementation by Rob Scanlon at https://github.com/arscan/hexasphere.js to objective-c for use in a project I'm exploring.
As a port, it works very well, and I can render the hexasphere using SceneKit on iOS however it's terribly inefficient. Because I want to dynamically animate individual facets of the hexasphere, I originally implemented each facet as a single SCNNode with it's own SCNGeometry object.
This produces a very slow rendering, with frame rates well below 30fps because of the high draw count.
Here is an image of the output after the original port:
With some advice from another developer, I've improved the rendering by creating a single SCNGeometry object that represents a single hexagon, and then using that single geometry multiple times, once for every hexagon in the hexasphere.
Whilst this brought down the draw count to an amazing 8 draws, it introduced a new problem.
By taking the multiple geometries generated by the original hexasphere code, each hexasphere was oriented in 3D so that they fit into the hexasphere appropriately.
Moving to the new design where I am positioning each SCNNode on the centrepoint of each hexagon, left me with a single geometry, correctly position in 3D, but incorrectly oriented, as this image shows:
After some experimentation I worked out that if I use the latitude and longitude of each hexagon, these would appear to give the correct orientation in the X and Y axes.
Applying this, I got a much better result:
But there is still a problem. The hexagons, whilst correctly positioned, are not oriented correctly on the face of the hexasphere.
So, finally, my question.
I'm trying to work out how to rotate those hexagons on the surface of the hexasphere, but I can't see how to. I had thought it was about rotating it on the Z axis, but that doesn't appear to work. I think I somehow need to calculate a set of 3 angles, 2 of which much be close to the latitude and longitude.
My current thought is that given that I have the boundary points of the original hexagon generated by the original code, I should be able to calculate (somehow) a 3D vector that represents the slope/orientation of the plane formed by those points, and use that to get the hexagons looking the way they are supposed to look.
Can someone help me get this right. Now I know I'm working with SceneKit and Objective-C, but I'm open to solutions in other languages. What I'm hoping is that I don't just get told to read a site with arcane maths because believe me, I've tried, and I just don't get it.
[UPDATE] I've completed my project now, and have made my Objective-C implementation of the hexasphere public on git at: https://github.com/pkclsoft/HexasphereDemo