Creating and deleting Voxels through JS code


Expanding on the concept presented by @Fearghus, I wrote a simple do-while JS script to help others expand upon the JS building idea:

To focus on a practical example, I use my existing plot.

function markPlot() {

var x = 6272;
var y = 0;
var z = 7000;

x = x + 1;
Voxels.setVoxel(x, y, z, 10.0, 255, 0, 0);
while (x < 6472);

y = y + 1;
Voxels.setVoxel(x, y, z, 10.0, 255, 0, 0);
while (y < 400);

z = z + 1;
Voxels.setVoxel(x, y, z, 10.0, 255, 0, 0);
while (z < 7200);



This simple JS is pretty self-explanatory and again expands up @Fearghus example. My question is how can we remove voxels is there a deleteVoxel function?


@KevinMThomas There’s an eraseVoxel function. Check out examples/gun.js lines 157-158.


Thanks @brian much appreciated!


Check also this one out @KevinMThomas :

It has quite a few functions listed there, not all for a script but it’s a nice start.

Did you manage with your script btw to position the voxels correctly on the edge of your plot? with mine not all came on the spot where i told them to.


@Fearghus everything seemed to work within the limits of the plot so far. The key for me was creating a good do, while loop that included the <= dimensions.


Will look into it again when home then and see with your script.
I do notice you increase the x,y or z with 1 though and place a voxel of size 10 each time?


Hi @Fearghus I created a little JS building tutorial see it if sets your plot boundaries and let me know if it doesn’t ill try to tweak the code.


Cool I’ll check it out this evening @KevinMThomas.


Hey guys,

I explained some stuff about voxel creation on Gitter, but I’ll put it here too.
Since we are using an octree, you cannot build a voxel of any size anywhere you want, it has to comply to a few rules I’ll write below.

The scale must be equal to the WORLD_SCALE divided by a power of two.
So : voxel_scale = WORLD_SCALE / (2 ^ p), p being a positive integers.
Since by default WORLD_SCALE = 16384 = 2 ^ 14, that means your voxel_scale should be able to be written as 2 ^ p, p < 14 (possibly even negative)

Concerning the position, each coordinate must be a multiple of the scale of the voxel, so if the voxel scale is s = 2 ^ p, that means you should have x = s i, y = s j, z = s * k.

To summaries, for a voxel {x, y, z, s}, you must have:
x = i * s, with 0 <= i < 2 ^ (14 - p)
y = j * s, with 0 <= j < 2 ^ (14 - p)
z = k * s, with 0 <= k < 2 ^ (14 - p)
s = 2 ^ p, with p < 14

Will try to make an helper script for the end of the week, but no promises.