ArrayMesh grid

DschoonmakerDschoonmaker Posts: 260Member
in 3D

I'm trying to make a grid mesh using ArrayMesh, kind of like a subdivided PlaneMesh. I found I can use indices to merge triangle vertices, to make a quad with only 4 vertices instead of 6. But it requires a particular order. My question is, how can I procedurally create a grid mesh, while merging unnecessary vertices? This is my grid, all the vertices should be connected, but right now each quad is separate:

Best Answer

  • DschoonmakerDschoonmaker Posts: 260
    Accepted Answer

    I got it, if anyone has the same problem I can explain it.

Answers

  • DschoonmakerDschoonmaker Posts: 260Member
    Accepted Answer

    I got it, if anyone has the same problem I can explain it.

  • SIsilicon28SIsilicon28 Posts: 749Moderator

    I don't have a problem, but I'd like to here how you solved it. :)

  • DschoonmakerDschoonmaker Posts: 260Member

    I'm not entirely sure why it works myself, but I'll explain as best I can.

    First, I create a grid of vertices, constructed row by row, left to right.

    For indices, I have this code for a loop:

    var i = 0
    var y = 0
    var x = 0
    while y < gridSize-1:
        while x < gridSize-1:
            indices.append(i+gridSize)
            indices.append(i+1)
            indices.append(i)
            indices.append(i+gridSize)
            indices.append(i+gridSize+1)
            indices.append(i+1)
            x+=1
            i+=1
        x = 0
        y+=1
        i+=1
    

    I have a specific order that worked for indices(for a single plane), it goes:

    • bottomleft
    • topright
    • topleft
    • bottomleft
    • bottomright
    • topright

    And this creates two triangles out of four vertices(top and bottom may be reversed). For the index code, I adapted this to work in a loop(with the variable i). The loop just loops over X and Y directions, adding vertices based on the variable i, which is increased every quad. Because the index code to make a quad assumes that there's vertices to the right and bottom, I subtract 1 from gridSize in the loop. Last, I have to increase i by 2 at the end of a row. I'm not entirely sure why, but it works when I do.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file