From 869a1d1bcdeea9908664d3901b5b6b34634d833b Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 4 Oct 2013 14:11:35 +0300 Subject: [PATCH] Have the maketex script take texture parameters as options --- scripts/maketex.py | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/scripts/maketex.py b/scripts/maketex.py index 8c7d5a19..04de1d38 100755 --- a/scripts/maketex.py +++ b/scripts/maketex.py @@ -13,7 +13,7 @@ def escape(str): result += c return result; -def make_tex(fn): +def make_tex(fn, filter="LINEAR", anisotropy=0, wrap=None): import Image img = Image.open(fn) @@ -25,7 +25,13 @@ def make_tex(fn): fmt = "LUMINANCE" result = "storage %s %d %d;\n"%(fmt, img.size[0], img.size[1]) - result += "min_filter LINEAR;\n" + result += "filter %s;\n"%filter + if "MIPMAP" in filter: + result += "generate_mipmap true;\n" + if anisotropy: + result += "max_anisotropy %d;\n"%anisotropy + if wrap: + result += "wrap %s;\n"%wrap result += "raw_data \"" data = list(img.getdata()) for y in range(img.size[1]): @@ -36,11 +42,24 @@ def make_tex(fn): return result if __name__=="__main__": - import sys import os + import argparse - if len(sys.argv)<2: - print "Usage: %s "%sys.argv[0] - else: - out = file(os.path.splitext(sys.argv[1])[0]+".tex", "w") - out.write(make_tex(sys.argv[1])) + parser = argparse.ArgumentParser() + parser.add_argument("-o", "--output", metavar="FILE", help="Output filename") + parser.add_argument("-f", "--filter", choices=["NEAREST", "LINEAR", "MIPMAP"], default="LINEAR", help="Filtering mode") + parser.add_argument("-a", "--anisotropy", metavar="NUMBER", help="Maximum anisotropy, 0 = disable") + parser.add_argument("-w", "--wrap", choices=["REPEAT", "CLAMP_TO_EDGE", "MIRRORED_REPEAT"], help="Wrapping mode") + parser.add_argument("image") + + args = parser.parse_args() + + filter = args.filter + if filter=="MIPMAP": + filter = "LINEAR_MIPMAP_LINEAR" + + out_fn = args.output + if not out_fn: + out_fn = os.path.splitext(args.image)[0]+".tex2d" + out = file(out_fn, "w") + out.write(make_tex(args.image, filter, args.anisotropy, args.wrap)) -- 2.45.2