following the guide on three.js fundamentals on how to make a voxell terrain i made this
but you can only build and remove voxels by the orbit controls;
i’ve tryed to add a collision detection by adding the coordinates in an array, but with terrible results
for (var y = 0; y < cellSize; ++y) {
for (var z = 0; z < cellSize; ++z) {
for (var x = 0; x < cellSize; ++x) {
var height = Math.round(noise.perlin2(x / freq, z / freq) * amp) < 0? 0 : Math.round(noise.perlin2(x / freq, z / freq) * amp);
if(height <= 3) {
world.setVoxel(x, height + 15, z, 3);
}else {
world.setVoxel(x, height + 15, z, 14);
}
world.setVoxel(x, height + 14, z, 7);
world.setVoxel(x, height + 13, z, 7);
world.setVoxel(x, height + 12, z, 7);
world.setVoxel(x, height + 11, z, 7);
world.setVoxel(x, height + 10, z, 5);
world.setVoxel(x, height + 9, z, 5);
world.setVoxel(x, height + 8, z, 5);
world.setVoxel(x, height + 7, z, 5);
world.setVoxel(x, height + 6, z, 5);
world.setVoxel(x, height + 5, z, 5);
world.setVoxel(x, height + 4, z, 5);
world.setVoxel(x, height + 3, z, 5);
world.setVoxel(x, height + 2, z, 15);
world.setVoxel(x, height + 1, z, 15);
world.setVoxel(x, height, z, 15);
world.setVoxel(x, 16, z, 13);
coordinates.push({x:x,y:height + 15,z:z})
}
}
}
this is the world generation code