Skip to content

How to make a Voxel Mesh Chunk

Geometry of one Voxel

first we need the Basic coordinates of one Voxel:

Voxel Structure

   5-------6
  /|      /|
 / |     / |
4-------7  |      y
|  1----|--2      ^  z
| /     | /       | /
|/      |/        |/ 
0-------3         o----> x

assuming we have a unit cube we can define the geometry as follows:

vertices =  [
    [0,0,0],
    [0,0,1],
    [1,0,1],
    [1,0,0],

    [0,1,0],
    [0,1,1],
    [1,1,1],
    [1,1,0]
]

tris = [
    # bottom
    0,1,2,
    2,3,0,

    # top
    6,5,4,
    4,7,6,

    # front
    7,4,0,
    0,3,7,

    # back
    1,5,6,
    6,2,1,

    # right
    6,7,3,
    3,2,6,

    # left
    0,4,5,
    5,1,0
]

General Idea:

  • represent terrain by simple data stream, where 0 decodes an empty Block.
  • at first generation

    foreach value x in datastream:
        if x == 0:
            for each neihbor n:
                # build mesh for adjacent plane and add it to chunk mesh
    

    • result: a mesh containing all planes that are possible visible
      • possible optimization: combine adjacent planes with same face normal to reduce amount of vertices
    • we assume that in future only single blocks are changing, so we can just update a chunk’s mesh with low cost