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) {
console.log(gltf);
gltf.scene.scale.multiplyScalar(0.5);
default_block = gltf.scene;
chunk = new Chunk(0, 0, 0, default_block, scene);
chunk.fill();
chunk.addEntitiesToScene();
}, undefined, function (error) {
console.error(error);
});
Thanks for your help.