oxyresbuild.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from __future__ import unicode_literals, print_function
  4. import time
  5. import resbuild.xml_processor as xml_processor
  6. def str2bool(v):
  7. return v.lower() in ("yes", "true", "t", "1")
  8. def get_parser():
  9. import argparse
  10. parser = argparse.ArgumentParser(
  11. description="oxyresbuild is a tool for optimizing xml resource files."
  12. "It generates a <xml-name>.ox folder with a"
  13. "meta.xml file inside. The meta file has optimized information "
  14. "about resources including atlasses."
  15. )
  16. parser.add_argument(
  17. "--src_data", help="The data folder containing all the resources",
  18. default="."
  19. )
  20. parser.add_argument(
  21. "--dest_data", help="Destination data folder",
  22. default="."
  23. )
  24. parser.add_argument(
  25. "-x", "--xml", help="The xml file to process", default=".", required=True)
  26. parser.add_argument("-mw", "--max_width",
  27. help="max atlas width", type=int, default=2048)
  28. parser.add_argument("-mh", "--max_height",
  29. help="max atlas height", type=int, default=2048)
  30. parser.add_argument(
  31. "-s", "--scale", help="Scale value applied when resizing images. "
  32. "Value > 1 - upscale, Value < 1 - downscale. Should be used "
  33. "with --resize", type=float, default=1.0
  34. )
  35. parser.add_argument(
  36. "--trim_threshold", help="Alpha trim threshold. Used to optimize image when trimming transparent borders of image", type=int, default=2)
  37. parser.add_argument("-r", "--resize", help="Resize images by a scale value",
  38. action="store_true", default=False)
  39. parser.add_argument("-us", "--upscale",
  40. help="allow upscale (Recommended for HD resources)"
  41. "displays with texture compression",
  42. action="store_true", default=False)
  43. parser.add_argument("-c", "--compression", help="type of image "
  44. "compression. Defaults to pure rgba8888 packed to png",
  45. choices=["pvrtc", "pvrtc2", "etc1", "etc2", "no"], default="")
  46. parser.add_argument("--npot", help="Atlasses dimensions are not power of twos",
  47. action="store_true", default=False)
  48. parser.add_argument("-q", "--quality", help="select quality to "
  49. "compressed textures (default is fast)",
  50. choices=["default", "fast", "best"], default="default")
  51. parser.add_argument("-d", "--dither", help="added dithering to "
  52. "compressed textures (pvr option)",
  53. action="store_true", default=False)
  54. parser.add_argument("-w", "--warnings", help="show warnings",
  55. action="store_true", default=False)
  56. parser.add_argument("--simple_downsample", help="don't use smart algorithm when resizing args",
  57. action="store_true", default=False)
  58. parser.add_argument(
  59. "-v", "--verbosity", help="verbosity level. 1 - only errors, "
  60. "2 - normal. Default value is 2", type=int, default=2)
  61. parser.add_argument("--hash", help="enables creating md5 hash lists for "
  62. "certain special files",
  63. action="store_true", default=False)
  64. parser.add_argument("--debug", help="debug mode",
  65. action="store_true", default=False)
  66. parser.add_argument("--no_hit_test", help="disables generation of"
  67. "hit_test data by default",
  68. action="store_true", default=False)
  69. parser.add_argument("--nopng", help="stores images without "
  70. "packing to png. TGA will be used if "
  71. "compressiong is disabled.",
  72. action="store_true", default=False)
  73. return parser
  74. def do(args):
  75. p = xml_processor.XmlProcessor(args)
  76. p.process()
  77. return p
  78. def process(values):
  79. import shlex
  80. ar = shlex.split(values)
  81. #ar = values.split(" ")
  82. args = []
  83. for a in ar:
  84. v = a.strip()
  85. if not v:
  86. continue
  87. args.append(v)
  88. args = get_parser().parse_args(args)
  89. return do(args)
  90. if __name__ == "__main__":
  91. parser = get_parser()
  92. dt = time.clock()
  93. do(parser.parse_args())
  94. dt = time.clock() - dt
  95. # print("total time: " + str(dt))