Skip to content

Instantly share code, notes, and snippets.

@blooalien
Forked from Uradamus/ground_obj.lua
Created May 19, 2014 08:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blooalien/24a61780ddd5d72d92c9 to your computer and use it in GitHub Desktop.
Save blooalien/24a61780ddd5d72d92c9 to your computer and use it in GitHub Desktop.
--[[
Call this file with the height input file and the desired output file as arguments.
example: lua ground_obj.lua hieght.txt ground.obj
]]--
-- Read the input height values.
input = io.open(arg[1], "r")
heights = {}
for line in input:lines() do
table.insert(heights, tonumber(line))
end
io.close(input)
-- Write the output obj file.
output = io.open(arg[2], "w")
for x = 0, 256, 1 do
for y = 0, 256, 1 do
output:write("v ", x, " ", y, " ", heights[x*256+y+1], "\n")
end
end
for i = 0, 256, 1 do
for j = 1, 256, 1 do
output:write("f ", (i*257)+j, " ", (i*257)+j+1, " ", (257*(i+1))+j+1, " ", (257*(i+1))+j, "\n")
end
end
io.close(output)
-- This generates a file full of random height values that can be used to test the above script.
output = io.open("height.txt", "w")
for i = 1, 66049, 1 do
output:write(math.random(3), "\n")
end
io.close(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment