-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconvert.lua
32 lines (30 loc) · 1.17 KB
/
convert.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
local
function convert(prefix)
local color_filename = prefix.."_color.png"
local heightmap_filename = prefix.."_heightmap.png"
local color_image = am.load_image(color_filename)
local heightmap_image = am.load_image(heightmap_filename)
if color_image.width ~= heightmap_image.width then
error(string.format("%s and %s have different widths (%d vs %d)",
color_filename, heightmap_filename, color_image.width, heightmap_image.width))
end
if color_image.height ~= heightmap_image.height then
error(string.format("%s and %s have different heights (%d vs %d)",
color_filename, heightmap_filename, color_image.height, heightmap_image.height))
end
local alpha_view = color_image.buffer:view("ubyte", 3, 4)
local depth_view = heightmap_image.buffer:view("ubyte", 0, 4)
alpha_view:set(depth_view)
local texture = am.texture2d(color_image)
texture.wrap = "mirrored_repeat"
texture.filter = "linear"
am.save_image(color_image, prefix..".png")
end
local n = arg[1]
if not n then
error("missing arg")
end
convert("floor"..n)
convert("floor"..n.."_detail")
convert("ceiling"..n)
convert("ceiling"..n.."_detail")