Hm, interesting… does this work for you?
Example script
local size = 100;
local solidMin = 2;
local solidSlopeZ = 0.05;
local waterLevel = 4;
local resolution = Vector3int16.new(size, size, size)
local terrainSize = Vector3int16.new(4,4,4) * resolution
local terrain = Game.Workspace.Terrain;
local region = Region3.new(Vector3.new(4,0,4), Vector3.new(terrainSize.X+4,terrainSize.Y,terrainSize.Z+4))
region = region:ExpandToGrid(4)
local function create3dTable(size)
local ret = {}
for x = 1, size.X do
ret[x] = {}
for y = 1, size.Y do
ret[x][y] = {}
end
end
return ret
end
local material = create3dTable(Vector3.new(resolution.X,resolution.Y,resolution.Z))
local occupancy = create3dTable(Vector3.new(resolution.X,resolution.Y,resolution.Z))
for x = 1, resolution.X,1 do
for z = 1, resolution.Z,1 do
local ySolid = solidMin + (z-1) * solidSlopeZ;
local ySolidInt = math.floor(ySolid);
for y = 1, resolution.Y,1 do
-- Note that this is NOT the correct calculation for occupancy of a perfect slope, but the approximation should be ok for this example
local o = math.clamp(ySolid+1-y, 0, 1);
occupancy[x][y][z] = o
material[x][y][z] = if o>0 then Enum.Material.Sand else Enum.Material.Air;
end
end
end
terrain:WriteVoxels(region, 4, material, occupancy)
local waterRegion = Region3.new(Vector3.new(-4,0,-4), Vector3.new(terrainSize.X+8,waterLevel*4,terrainSize.Z+8))
game.Workspace.Terrain:ReplaceMaterial(waterRegion, 4, Enum.Material.Air, Enum.Material.Water)
It should generate a gentle beach slope with shallow water, like this: