Greedy meshing, visually


Greedy meshing blocks in a voxel game doesn’t have to be hard. Here’s a simple explanation for people who prefer seeing how the algorithm progresses.

This post is the newer version of my popular tutorial from the Roblox DevForum: Consume everything - how greedy meshing works

The algorithm

By the way, finding a starting point isn’t too hard. It’s pretty sufficient to just loop over them in the normal way - you’ll always have merged every block by the end, and it’s relatively efficient at merging things into large groups.

for x = 1, size.x do
    for y = 1, size.y do
        for z = 1, size.z do
			-- if this is a starting point, start merging stuff...
		end
	end
end

A simple visual example along one axis

A row of 5 blocks in a straight line is greedy meshed with the algorithm above, producing one group containing the whole row.

The same example, with two axes (2D)

A 5 by 5 area of blocks is greedy meshed with the algorithm above, producing one group containing the whole area.

A more complex demonstration

Two 3 by 3 areas of blocks, which share only one of their corner blocks. When greedy meshed, a 3 by 3 group is created for one of the areas, and to fill the remaining L shape, a 3 by 2 group and a 2 by 1 group are created.


Posted on