You can create your own DataSource as in this example sphere:
importPackage(Packages.abfab3d.util);
var radius;
var Sphere = {
getDataValue : function(pnt, data) {
var x = pnt.v[0];
var y = pnt.v[1];
var z = pnt.v[2];
var vs = pnt.getScaledVoxelSize();
var r = r = Math.sqrt(x*x + y*y + z*z);
data.v[0] = MathUtil.step10(r, radius, vs);
return DataSource.RESULT_OK;
}
};
function main(args){
radius = 5*MM;
var a = radius*1.1;
var voxelSize = 0.1*MM;
var dest = createGrid(-a,a,-a,a,-a,a,voxelSize);
var maker = new GridMaker();
maker.setSource(Sphere);
maker.makeGrid(dest);
return dest;
}
A data source calculates: The way to fill the voxel grid is to create an object with a DataSource interface, which can calculates a signed distance function for each point in space. This object is fed to an instance of GridMaker which controls the calculations. The distance function calculations may be very complex task for complex object. But this calculation can be simplified by composing complex object from many simpler one using several simple operations. I feel like I developed some more complex volume patterns but this is the best example I can find at home. I'll check at work tomorrow and see if I have better ones.