Announcement

Collapse
No announcement yet.

Merging Box Mesh Data into a single Mesh Section?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    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!

    #2
    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.
    Last edited by KrautPotato; 08-11-2016, 01:36 AM.
    @CarstenZarbock - Follow me on Twitter, thank you

    Comment


      #3
      [MENTION=29149]KrautPotato[/MENTION] Oh my God that's likely exactly what the issue is.

      I'll adjust my code and see if that solves it! Thank you!
      Last edited by DatapawWolf; 08-11-2016, 01:49 AM.

      Comment


        #4
        Took me some time to figure it out though. Hope it works
        @CarstenZarbock - Follow me on Twitter, thank you

        Comment


          #5
          [MENTION=29149]KrautPotato[/MENTION] 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.

          Comment


            #6
            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 )

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

            Click image for larger version

Name:	solution 2.png
Views:	1
Size:	606.8 KB
ID:	1113629

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

            Click image for larger version

Name:	solution 1.png
Views:	1
Size:	524.3 KB
ID:	1113630

            Have fun.

            Click image for larger version

Name:	blablalsdasd.png
Views:	1
Size:	704.6 KB
ID:	1113631

            edit: Please note that the "unseen" triangles between the blocks are still there.
            Last edited by KrautPotato; 08-12-2016, 02:20 AM.
            @CarstenZarbock - Follow me on Twitter, thank you

            Comment


              #7
              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.

              Comment

              Working...
              X