Question about "Chunks"

Hey I’m having a little trouble with “Chunks” I understand how they work logically but I can’t for the life of me figure out how to put it into practice programmatically. I’ve checked out a few examples but I’m still quite stuck so I thought I’d see if anyone on here could maybe write up some pseudo code and explain it a bit.

Thanks in advance everyone, Carl

Minecraft is really advanced stuff but the basics are quite simple. Notch generates few perlin noises and uses them as density map and height map and some other ones. Then he iterates trough the pixels of the noise and splits it into “chunks”. If you want good optimization and you are working on a minecraft like game than a 32x32x128 chunk has really good performance. So you iterate trough the noise and at every 32 pixel just split it into another chunk. Also one chunk is one mesh. So you have to add sides, yes sides not cubes, to it, and check if the side can be seen, so you don’t waste ram. Chunks are good for not having the whole world in ram at once.

Short: World is made of chunks. Chunks are made of faces that make cubes. Chunks are parts of noise. Don’t use instantiate it will kill your PC/MAC, instead use the Mesh class and generate meshes manually.

Also, take a look at MinePackage. It is a really nice terrain generation algorithm made in unity, and you can download the source code.

Edit: I read your coment about “indexing the chunks”. If you want to save it, just save the noise and the changed cubes instead of whole meshes and generate the world again and again on each run from the noise + changed cubes.

– David