Programmable Shape - Mesh? Brush? Procedural Generation?

I am new to UE4 and 3D game development in general, and I am trying to create a geodesic sphere that I can interact with in code/blueprints/whatever. For anyone who doesn’t know what a geodesic sphere is, see below the below mesh created in Blender.

What I would like to do, at the highest level, is create a geodesic sphere that will act as a game board. I want to be able to color the pentagons, differentiate them from the hexagons, and allow a user to interact with both the hexagon and pentagon nodes via click/tap/whatever. However, I don’t know the best way to go about creating this ‘programmable’ geometric shape. I created something similar to what I’m looking for using the sphere brush, pictured below, but the hexagons are very skewed, and I still don’t know how I would go about programming it.

I am a software dev by trade and have used some 2D game dev frameworks, so I have some experience. I am just looking for someone to point me in the right direction. I have found a c++ implementation of a geodesic sphere, but it’s not for UE. I am guessing I can adapt it, but instead of spending hours trying to figure out the best way I figured this is a better place to start.

Thanks,

u

This thread has quite a discussion on generating procedural meshes

This wiki page has an implementation for procedural mesh generation in UDK

It can certainly be done - it’s something I looked into a while back for roughly the same purpose. It’s quite a lot of work however, whichever approach you take. We were using instanced mesh components from assets with an algorithm.

There’s a lot more to it than just placing hexagons and pentagons. It’s important to realise that each ‘tile’ is not necessarily a regular hex / pent, and things like having correct normals will take some additional work to get right. Since you apparently have time and interest, and I’d like to achieve the same thing, perhaps we should chat?

Definitely, that would help me get on my way. I wasn’t trying to downplay the difficulty… just give a high-level idea of what I’m trying to do.

I would like to know how this got on if possible. I need to create a geodesic sphere, too, but I have no idea which direction I should be taking.

Necro’ed! In case in the future anyone else wants to know how to place hexagons around a sphere, this is how to do it.

First you start off deciding where the pentagons are going to be. From the center, you’ll want one straight up (to be the north pole), one straight down (the south pole), five in a ring 26.56 degrees up from the center and separated from each other 72 degrees around a circle (the northern ring, kind of like our planet’s Tropic of Cancer), then five more in a ring 26.56 degrees down from the center (the southern ring, kind of our own Tropic of Capricorn), also 72 degrees apart from each other around a circle, but offset 36 degrees from the northern ring.

Then in general, this is what you do to fill in the sphere. You push the pentagons out a certain radius from the center (exact distance will be determined by the size of your hexagons and how many you want between each pentagon). Then you’ll need 4 quaternions:



FQuat StartQuat1 = FQuat::FindBetweenVectors((TargetLocation1 - this->GetActorLocation()), (StartLocation - this->GetActorLocation()));
FQuat StartQuat2 = FQuat::FindBetweenVectors((TargetLocation2 - this->GetActorLocation()), (StartLocation - this->GetActorLocation()));

FQuat Edge1Quat = (TargetLocation1 - this->GetActorLocation()).ToOrientationQuat();
FQuat Edge2Quat = (TargetLocation2 - this->GetActorLocation()).ToOrientationQuat();

StartQuat1 *= Edge1Quat;
StartQuat2 *= Edge2Quat;


In that code, “this” is the actor that I move around to set the center of the sphere and which has a function for building the sphere. StartLocation, Target1Location, and Target2Location are the locations of 3 adjacent pentagons. Their locations are the equivalent of the points of a triangle on a D20-shaped dodecahedron. When we have our three vectors, and we get our quaternions from them, then we use FQuat::Slerp. Slerping is basically taking two rotations (represented by quaternions), and you give it a number between 0 and 1, and it returns the quaternion at that point in an interpolation from Quat1 to Quat2. We make a for-loop to slerp along the surface of the sphere from Start1 to Edge1 and Start2 to Edge2*, placing hexagons at regular intervals, and then a nested for-loop to slerp from one side of the triangle to the other, placing hexagons inside the triangle.

Do that 20 times to fill in each of the 20 triangles between pentagons.

There’s a little more to it than that to figure out the rotation for each hexagon/pentagon, and also pentagons take up slightly less space than hexagons, so you have to account for that too, but that’s basically how it works.

  • (Note: Start1 and Start2 are quaternions that both point in the same forward direction, for example from the center of the earth toward the north pole. But they are rotated so that as you slerp them, Start1 will head toward Target1 and Start2 will head toward Target2.)