Paste
Of Code


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
for x = 1, numChunks do
    for y = 1, numChunks do
		local chunk = TerrainChunk.new(x, y)
		chunk:Generate()
	end
end

function TerrainChunk.new(chunkX, chunkY)
.... -- not necessary for you to see the code here
end


function TerrainChunk:Generate()
	local topLeftX = self.chunkX + (chunkSize / -2)
	local topLeftZ = self.chunkY + (chunkSize / 2)

	local meshSimplificationIncrement = math.max(1, self.levelOfDetail * 2)
	local verticesPerLine = math.ceil(chunkSize / meshSimplificationIncrement) + 1

	-- Tables to store vertex data
	local vertexPositions = {}

	-- Create vertices with correct LOD using verticesPerLine
	for x = 0, verticesPerLine - 1 do
		local actualX = x * meshSimplificationIncrement
		if actualX > chunkSize then actualX = chunkSize end
		vertexPositions[actualX] = {}
		for y = 0, verticesPerLine - 1 do
			local actualY = y * meshSimplificationIncrement
			if actualY > chunkSize then actualY = chunkSize end

			local worldX = topLeftX + actualX
			local worldZ = topLeftZ - actualY
			
			--[[ This calls the ComputeNoise function ]]
			local finalValue = Noise(worldX,worldZ)
			--

			local noiseHeight = finalValue * 150 -- Final height for this vertex


			-- Store vertex position and material
			vertexPositions[actualX][actualY] = Vector3.new(worldX, noiseHeight, worldZ)
		end
	end

	-- Later on we draw the triangles to create the mesh etc
end

Toggle: theme, font