ae_movie_image_polygonize.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from tools import tools
  2. from tools import image_polygonize
  3. class MyTools(tools.Tools):
  4. def _initialize(self):
  5. self.add_argument_file('--in_path', 'in_path')
  6. self.add_argument_file('--source_path', 'source_path')
  7. self.add_argument_float('--offset_x', 'offset_x')
  8. self.add_argument_float('--offset_y', 'offset_y')
  9. self.add_argument_float('--width', 'width')
  10. self.add_argument_float('--height', 'height')
  11. self.add_argument_integer('--tolerance', 'tolerance')
  12. self.add_argument_bool('--use_sha1', 'use_sha1')
  13. pass
  14. def _run(self, args):
  15. if args.use_sha1 is True:
  16. sha1hex = self.get_file_sha1(args.source_path)
  17. sha1tag = "image_polygonize {0}:{1} {2}:{3} {4}".format(args.offset_x, args.offset_y, args.width, args.height, args.tolerance)
  18. temp_path = self.get_sha1_cach_path(sha1tag, sha1hex + ".image_polygonize")
  19. pass
  20. else:
  21. temp_path = self.get_temp_path("image_polygonize.info")
  22. pass
  23. if args.use_sha1 is False or self.exist_file(temp_path) is False:
  24. temp_dir = self.get_temp_dir()
  25. log_path = self.get_temp_path("ae_export_atlas.log")
  26. rv, info = image_polygonize.process(args.in_path, temp_dir=temp_dir, log_path=log_path, offset_x=args.offset_x, offset_y=args.offset_y, width=args.width, height=args.height, tolerance=args.tolerance)
  27. with open(temp_path,'w') as f:
  28. f.write(str(info[0])+'\n')
  29. f.write(str(info[1])+'\n')
  30. f.write(', '.join(map(str, info[2]))+'\n')
  31. f.write(', '.join(map(str, info[3]))+'\n')
  32. f.write(', '.join(map(str, info[4]))+'\n')
  33. pass
  34. pass
  35. with open(temp_path, "r") as f:
  36. vertex_count = f.readline().rstrip('\n')
  37. index_count = f.readline().rstrip('\n')
  38. positions = f.readline().rstrip('\n')
  39. uvs = f.readline().rstrip('\n')
  40. indices = f.readline().rstrip('\n')
  41. pass
  42. print("vertex_count = {0}\n".format(vertex_count))
  43. print("index_count = {0}\n".format(index_count))
  44. print("positions = {0}\n".format(positions))
  45. print("uvs = {0}\n".format(uvs))
  46. print("indices = {0}\n".format(indices))
  47. return True
  48. pass
  49. pass
  50. tools.run(MyTools)