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

- Find a starting point, that isn’t empty, and hasn’t already been merged.
- For each axis, one at a time (X, Y, Z)
- Look one coordinate ahead. Is there a block?
- If so, merge it with the previous block and step forward.
- If not, then move on to the next axis.

- Repeat the above steps until you have merged every block.

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
```