Merging Box Mesh Data into a single Mesh Section?

So I am using the Procedural Mesh Component, and my goal is to use functions that will give me a structure in the form of a custom 3D array that indicates the locations of the cubes to create. I want to develop a voxel generator, however, I am having difficulty merging the vertices and triangles generated by the Generate Box Mesh function into one larger mesh.

This is a stitched-together screenshot of my current code. The base structure is there, and I have verified that my function is returning the locations of cubes (as positions in a custom array structure) as expected.

However, when I attempt to combine all vertices into one temporary array, and then all triangles, I always wind up with one generated cube mesh being rendered, as seen below, instead of the larger, combined mesh I am expecting.

I am not sure where I am going wrong with how I am combining vertices. I was under the impression that if I add all points into one array, it would work, but that is obviously not the case!

I also know that to actually improve upon this basic idea that I will need to remove redundant vertices and merge triangles, but I just want to complete this basic idea of “one large mesh” before I continue onto optimization.

Now, I’m not bending on the Blueprints. My idea for procedural generation is based solely on building complete, small dungeons, from blocks-built parts (for example, a table would be generated and placed around the dungeon), however, because the idea of merging cubes is more of a logical problem than a code-one, I figure even those who’ve built these parts in C++ should be able to point me in the right direction!

Thanks everyone!

Nope, thats not how its working! You’re connecting the vertices of the first generated box all over again.

Create Mesh Section - Triangles: Index buffer indicating which vertices make up each triangle. Length must be a multiple of 3.

So its always
1-2-3-1-2-3-1-2-3 | Because you’re adding the same indexes all over again in Temp Room Triangles, without thinking about the old ones
it should be
1-2-3-4-5-6-7-8-9 | You have to connect it with the correct vertices index.

Not sure though, but my thought on it.

Should be fixed if you add the correct vertice index
X * Y * Array Element (Triangle) instead of Array Element (Triangle) to the Temp Room Triangles.

@KrautPotato Oh my God that’s likely exactly what the issue is.

I’ll adjust my code and see if that solves it! Thank you!

Took me some time to figure it out though. Hope it works :smiley:

@KrautPotato Still having issues. I tried your solution, that didn’t quite work, but it’s on the right track

I get that with a 3x3 floor section using Array Element + ((X + Y + Z) * Length(TrianglesArray)).

So the first cube should always be 1, 2, 3 … + ((0) * 36).

Second cube should be 1, 2, 3 … + ((1) * 36).

But again, I am getting completely lost. I’ve literally spent 8 hours on this and I can’t wrap my head around the math.

Got it. Took me some time to find the error. We had to use the amount of vertices of course. The Array Element points to the vertice index, not the triangle index. (Stupid mistake :smiley: )

Got 2 solutions:
First one as you had planned with 1 section. (Sorry for the mess, didn’t clean up. Branch is useless though.)

Second one with more sections. (temp count default value is -1! | and the branch is useless though, didn’t delete it.)

Have fun. :slight_smile:

edit: Please note that the “unseen” triangles between the blocks are still there.

Your code worked beautifully!

This is the result, in a little GIF form.

And here is the stitch of the new code! I was able to trim some and clean up, but your idea of using the number of vertices is exactly the solution.

Thank you so much for working with me! I really appreciate the assistance. I’m gonna make sure I understand your solution before moving on, too.