Blockchain Terrain Generation #3 - Programmatic Mesh Generation and Major Optimization

In the previous version of my project, every block was individually created as a new Unity GameObject and then combined the mesh with the corresponding height level colour of that block. Although after the blocks were combined the frame rate was greatly improved, it still left huge problems in the time that process took, and presented me with devastating limitations on what the user could do. For example, using the old method, to edit one block would mean all the blocks in the map/chunk would have to be regenerated which would cause a lag spike every time.

To solve this problem, I decided to start researching how the game Minecraft goes about solving this problem.

I came across this video that gave an explanation of how it is done in Minecraft. If a face of a cube is not able to be seen, it is not rendered at all.

To do this, I decided that I should no longer use the Unity primitive cube, but instead programmatically create the mesh myself. This way, I would have full control over what sides of a block is rendered.

I watched a YouTube video by Brackeys to learn about how programmatically create a mesh in Unity.

Now, using this information and my previous terrain generation code, I started on a new version that checks if the block face being created is facing the air, and if it is, it creates the face. Doing this made the generation of a single chunk next to instantaneous Which means that when I add the ability to place and remove blocks, this can be done seamlessly.

7 views0 comments