So I was looking at Studio-Tools/TerrainTools.rbxmx at master · Roblox/Studio-Tools · GitHub and turns out the sphere brush is nothing else than WriteVoxels with specific occupancies. I don’y get it, how can you create Sphere just with WriteVoxels ? I might need that for some thing Im working on.
There’s the FillBall function which can be used to create Spheres. I’m not certain about WriteVoxels
I know about FillBall. That’s not my point of interest here.
A sphere is defined by all of the points which are within a given distance of the sphere’s centre. That’s what the code in the brush is expressing. It looks roughly at each voxel in the grid near the sphere’s centre (a big cube of voxels) and uses that condition to test whether it should be filled.
brushOccupancy = max(0, min(1, (radius + .5 * resolution - distance) / resolution))
If you try plugging radii into the above expression you’ll see that it’s 1 inside of the radius and 0 otherwise.
magnitudePercent = cos(min(1, distance / (radius + resolution * .5)) * pi * .5)
This is an approximation for how much of the voxel is within the radius for voxels which are only partially within it.