Skip to content

How to make a Voxel Mesh Chunk

Geometry of one Voxel

first we need the Basic coordinates of one Voxel:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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

    1
    2
    3
    4
    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