4.8.3 Mesh generation

Hey guys,

Recently I worked with C ++ code generating planets from bubbles (truncated octahedrons).

Here is my result.

I generate only front faces so it’s quite well oprtimized. Inside view:

What do You think about this idea? I have also implemented point gravity and character moves fine around the planets.

Unfortunatally I have some problems with mesh update. For small planets it works really well. All bubbles can be changed to any ID (material) and color. With increasing planet size performance suffer.

For planet 80x80x160 = 1024000 update takes 2 seconds. It cannot be stand anymore because game freezes.
Firstly I thought that every section from CreateMeshSection function are independent so I tried to use many sections. Right now I know it doesn’t matter because every time mesh change it regenerates whole mesh.

My question is how can I get better respond to mesh changes. Should I use more mesh objects?
mesh = CreateDefaultSubobject<UProceduralMeshComponent>(TEXT(“ProceduralMesh”));


For my game, I’m running the updates in chunks to keep it somewhat performant. During runtime you really don’t end up with situations where you’d need to make changes to hundreds of meshes at once most likely so it’s also probably ok if it takes a second since you only really incur that cost at load. You could also probably do this work in another thread so it doesn’t block the game loop if you want to, but that’s a bit above my understanding. I think Rama has a good tutorial on it on the wiki.

Problem is not to generate data which takes 0.2 sec. Problem is to run function provided with 4.8.3 version.
CreateMeshSection took ~3s :frowning: and it’s getting worse for bigger planets.
Only way is to generate separate meshes and update them when needed.

I probably could use Threads and instances meshes like buffer not slowing down game but in most cases i just need to update mesh quick (add/remove only a few faces).

for 80 size (40x40x80)
GenerateBubble in 0.025000
CreateMeshSection in 0.581000

for 160 size (80x80x160)
GenerateBubble in 0.151000
CreateMeshSection in 3.090000

What does the CreateMeshSection do?
Does it only mean “mesh->CreateMeshSection(0, Vertices, Triangles, Normals, UVs, VertexColors, Tangents, false);” or do you do something additional to that? Like calculating the array (vertices)…

Anyway, as other said, partition your space into chunks. So that your planet would consist of many 32by32by32 chunks instead of a huge one. At worst case (checkerboard) it can’t exceed 32768 blocks.
It seems you are already removing faces that are obscured.
I wouldn’t generate physics for the visual mesh either, as there are better ways to fake it.

As of the idea, it’s great. Maybe you can smooth the terain with some slanted bubbles.
Similar to the way a cube system would:

Yeah CreateMeshSection update whole mesh so it’s like generating mesh from nothing.
I already divide my 3d space into parts so my calculations are ok and I update only dirty part after change.
Anyway I still need several meshes because I cannot work with only one. There is no support for face updating. Only way to do it is just update entire mesh. I just wanted to convince myself. Thx

These are cubes with only 6 directions. Making spherical planets can be problematic except if You make the game like planet^3.

OK So I decided to divide space into chunks (4x4x4) 64 total for planet.
GenerateBubble in 0.001000
CreateMeshSection in 0.007000
Times are great. Everything works. Even if I need to update many chunks at once.

I meant similarly, not the same way. Just that a picture was hard to find.
So I made one :slight_smile:

The yellow one shows just how many nice cutting lines there are.
By using such cut out sub shapes, you could smooth the bumps to a minimum.
At least that was the hunch I had.

Yeah that’s cool. then surfaces can be completely flat and I can make game like TTD :smiley: I’ll think about it :slight_smile:

Anwyay I think “bubble” shape is great too. I can build very nice worlds from it. I never see it was used before.
It’s easier to use, needs less memory and I can shrink it even more.

Have you tried creating Instanced Static Mesh from the Procedural Mesh once it has been created?

I’m going to try, thought it may work in this situation.

I checked it out, and it works on the basis as other mesh. Using the UBodySetup which acts as the collision mesh in-game, you may be able to export the Mesh then Instance that for better performance. – It seems theoretically possible. Could be problems attempting this. I’ll try it if I get time if you don’t.

Why would I ever want to create instances of procedurally generated mesh?

Before I started with mesh generation I tested mesh instances. Performance was good but right now when I show only front faces it is even better. Problem was exactly the same - removing / adding instances was taking some time. I needed to create more and more instanced static mesh components. Right now I make many of Procedural mesh components. Performance suffer a little bit but I really need to be able to quickly modify generated mesh.

OK. so here is my final work. I just uploaded video for You guys.

That looks freaking fantastic. I desperately want to play that game.