editor_atlas_packer.h 886 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef EDITOR_ATLAS_PACKER_H
  2. #define EDITOR_ATLAS_PACKER_H
  3. #include "core/math/vector2.h"
  4. #include "core/vector.h"
  5. #include "scene/resources/bit_map.h"
  6. class EditorAtlasPacker {
  7. public:
  8. struct Chart {
  9. Vector<Vector2> vertices;
  10. struct Face {
  11. int vertex[3];
  12. };
  13. Vector<Face> faces;
  14. bool can_transpose;
  15. Vector2 final_offset;
  16. bool transposed;
  17. };
  18. private:
  19. struct PlottedBitmap {
  20. int chart_index;
  21. Vector2i offset;
  22. int area;
  23. Vector<int> top_heights;
  24. Vector<int> bottom_heights;
  25. bool transposed;
  26. Vector2 final_pos;
  27. bool operator<(const PlottedBitmap &p_bm) const {
  28. return area > p_bm.area;
  29. }
  30. };
  31. static void _plot_triangle(Ref<BitMap> p_bitmap, Vector2i *vertices);
  32. public:
  33. static void chart_pack(Vector<Chart> &charts, int &r_width, int &r_height, int p_atlas_max_size = 2048, int p_cell_resolution = 4);
  34. };
  35. #endif // EDITOR_ATLAS_PACKER_H