-
-
Save blooalien/24a61780ddd5d72d92c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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