There are lots of games out there that use a planet built from hexagons and pentagons. Before We Leave, for example:
I want to work with a similar thing in Unreal, but I also want to be able to manipulate the shape of the planet at a finer resolution than simply those large cells. So here’s a geodesic icosahedron in Blender, then the same thing with 2 levels of subdivision, and then again with 4 levels of subdivision and some manipulation made possible by the higher vertex count. I’ve added the colours just for visualisation.
Now taking that shape, returning it to its spherical-ish form and ditching the materials, this is what Unreal sees when it is imported:
I want to be able to do things like:
- each cell has its own state/data
- know which cell any point on the surface is in
- per-cell material changes
- operations based on things like counting cells with some state across the whole surface, etc.
The main caveats are:
- a high vertex count is required
- 500-1000 cells are desired, so separating cells by assigning materials in Blender isn’t an option
- the mesh can be divided into regions with clean edges, ie., regions borders are visually smooth, unlike the red region in the image below. I’ve been going with the icosahedron for this reason, but hexagons aren’t strictly required, only smooth regions are.
So the question is:
How would you go about getting every triangle to know which hexagonal/pentagonal cell it is in?
There might be another path entirely to suggest that ticks the above boxes. I’m interested if so.
*Quick addition to mention the approach I’m currently taking:
- Create a 2nd “shell” mesh the same as the first but without the subdivisions
- Make it slightly larger, make its faces face inwards, and position it in the same place as the main mesh
- Line trace outwards from every tri on the main mesh, to hit the cells on the shell mesh
- Get the normal from the line trace hit. If it’s a normal that hasn’t been discovered yet, register that tri to a new cell. If it’s a normal that has already been discovered, register that tri to the cell that previously-discovered normal goes with.
It’s more maths than it is Unreal, so I’m hoping there’s a smarter/more elegant way that better uses Unreal’s features to achieve a similar result.*