file = GetString("file", "testground.png", "script png")
grassMap = GetString("grass", "", "script png")
heightScale = GetInt("scale", 64)
tileSize = GetInt("tilesize", 128)
hollow = GetInt("hollow", 0)

function init()
	CreateMaterial("rock", 0.41569, 0.40784, 0.37647) -- matRock
	CreateMaterial("dirt", 0.34118, 0.30588, 0.25098, 1, 0, 0.1) -- matDirt
	CreateMaterial("unphysical", 0.27451, 0.34510, 0.23137, 1, 0, 0.2) -- matGrass1
	CreateMaterial("unphysical", 0.28235, 0.38824, 0.22745, 1, 0, 0.2) -- matGrass2
	CreateMaterial("masonry", 0.39608, 0.39216, 0.38824, 1, 0, 0.4) -- matTarmac
	CreateMaterial("masonry", 0.3, 0.3, 0.3, 1, 0, 0.3) -- matTarmacTrack
	CreateMaterial("masonry", 0.7, 0.7, 0.7, 1, 0, 0.6) -- matTarmacLine

	if grassMap == "" then
		LoadImage(file)
	else
		local black = {0.27, 0.34, 0.23}
		local white = {0.45, 0.41, 0.26}
		for i=1, 8 do
			local t = (i-1)/7.0
			local r = black[1]*(1-t)+white[1]*t
			local g = black[2]*(1-t)+white[2]*t
			local b = black[3]*(1-t)+white[3]*t
			CreateMaterial("unphysical", r, g, b, 1, 0, 0.2)
		end
		LoadImage(file, grassMap)
	end
	
	
	local w,h = GetImageSize()

	local maxSize = tileSize
	
	local y0 = 0
	while y0 < h-1 do
		local y1 = y0 + maxSize
		if y1 > h-1 then y1 = h-1 end

		local x0 = 0
		while x0 < w-1 do
			local x1 = x0 + maxSize
			if x1 > w-1 then x1 = w-1 end
			Vox(x0, 0, y0)
			Heightmap(x0, y0, x1, y1, heightScale)
			x0 = x1
		end
		y0 = y1
	end
end

