Hi guys,
I’m making a grand strategy game in which the map is an icosphere (ie a sphere composed of hexagons and 12 pentagons).
Papers about hexaginal grids I found on the net mention flat maps only and do not apply to my case (unless I misunderstand the core concept), so I’m calling for your help
I think you need details (I’m affraid this makes for a lengthy post) :
-
What am I intending to do exactely :
As the player clicks, or the mouse hovers over the sphere, data corresponding to the selected cell is retrieved and served for the player’s masochistic pleasure.
Obviously this system is the game’s backbone, and nothing can be done without it ! -
What am I doing precisely :
I divided planet Earth into 20 game objects, each of them representing the icosphere face (bcs meshes can’t store more than 2^16 vertices and we do need plenty).
Each face is subdivided 6 times (1 hexagon represents ~100km). Needless to say that there’ll be TONS of hexagons
Each vertex is the center of an hexagon (or pentagon). Actually it’s more complicated (I want to save your synapses =), you’ll see at the end of the post…
The world cells data will be stored into an array[ ], in its own script : the data managing script.
That script will access data by knowing the clicked/hovered face id and the closest vertex from the click.
I want to acces a given cell like that :
int index = faceId * faceLength + vertexId; // faceId, faceLength are passed by the face game object script. VertexId is retrieved by computing the shortest distance raycasthit.point ↔ raycasthit.triangleIndex (we’re making 3 checks)
array[index].DoStuff ();
In order this to work, array needs data be stored by face and vertex order (that’s tricky to explain, example incoming)
That’s precisely my issue, the algorithm responsible for creating the geometry works that way ( SarvanZ: Sphere tessellation/triangulation using Icosahedron ) :
Primary face vertices (* = vertex)
*A
C* *B
We get (beware pseudo code) mesh.vertices = { A,B,C }
1st subdivision
*A
1* *2
C* * *B
3
mesh.vertices = { A,B,C,1,2,3 }
The 2nd subdivision will break a,b,c into 4 triangles, leading to sth like mesh.vertices = { A,B,C,1,2,3,do,re,mi } // Hear the programing melody ?
Rince and repeat 4 more times. I let you imagine the mess inside mesh.vertices (and triangles)
What I want to achieve is ordering vertices the same way as we, westerners, read text (upper row, left, to right, then next row, left right…) :
mesh.vertices = { A,1,2,C,3,B }
I can’t find a way to achieve this, especially knowing that in addition to vertices reordering, we must reassign triangles.
Oh, remember that I told you it gets dirtier ? every vertices are generated 3 times (the same texture is applied on every triangles, UVs will differ depending on terrain type)
T_T
I will greatly appreciate some help, really and I thank you a lot by advance
p.s. : I’ll take any simpler/better way to handle this visuals-data system