__init__.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import numpy
  2. from PF2.VectorMask import Path
  3. class VectorMask:
  4. def __init__(self):
  5. self.paths = []
  6. self.width = 0
  7. self.height = 0
  8. self.__map = None
  9. def set_dimentions(self, width, height):
  10. self.width = width
  11. self.height = height
  12. def get_new_path(self, brush_size, brush_feather, scale, additive):
  13. path = Path.Path(brush_size, brush_feather, scale, additive)
  14. self.paths.append(path)
  15. return path
  16. def get_mask_map(self):
  17. if(self.has_updated()):
  18. map = numpy.zeros((self.height, self.width, 1), dtype=numpy.uint8)
  19. for path in self.paths:
  20. map = path.get_mask_map(map)
  21. map32 = map.astype(numpy.float32)
  22. map32 = map32 / 255.0
  23. self.__map = map32
  24. return self.__map
  25. def has_updated(self):
  26. res = True
  27. for path in self.paths:
  28. res &= path.has_rendered
  29. return not res
  30. def get_vector_mask_dict(self):
  31. paths = []
  32. for path in self.paths:
  33. paths.append(path.get_path_dict())
  34. return {
  35. "width": self.width,
  36. "height": self.height,
  37. "paths": paths
  38. }
  39. def set_from_vector_mask_dict(self, dict):
  40. self.width = dict["width"]
  41. self.height = dict["height"]
  42. paths = []
  43. for path in dict["paths"]:
  44. paths.append(Path.Path.new_from_dict(path))
  45. self.paths = paths