Ideal code structure for Minecraft clone

I’m working on building a Minecraft clone and as a first step, I’m building my world out of 16x16x16 block ‘chunks’ where each block is a clone of a model I’ve loaded.

I have implemented a JavaScript ‘chunk’ class and I want to be able to load and unload all the blocks in a chunk on-demand.

Right now, to accomplish this, I’m passing the chunk instances a reference to the model and the scene in their constructor. This strikes me as possibly being a bad practice. Is there any way around this, or a more idiomatic way to approach this?

My current code that loads the model and initializes a chunk:

loader.load('/minecraft_grass_block/default_block.gltf', function (gltf) {
    default_block = gltf.scene;

    chunk = new Chunk(0, 0, 0, default_block, scene);

}, undefined, function (error) {

Thanks for your help. :slightly_smiling_face:

I think you ideally want to separate world information from actually rendering the world. Your GLTF model is presumably a cube that contains 6 faces. However, if that block would be surrounded on the X and Z plane, then you would waste a lot of resources, because 4 of the 6 faces would be occluded by neighboring blocks.

Instead, write a 3D grid system that you can traverse over to then generate the geometry that would be visible by testing against neighboring blocks.

1 Like

Thanks for the help!

This is what I think I was missing. I’m planning on eventually implementing the culling that you propose and this change will also make that (and any other rendering refactors) easier.