polygon_2d.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /**************************************************************************/
  2. /* polygon_2d.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef POLYGON_2D_H
  31. #define POLYGON_2D_H
  32. #include "scene/2d/node_2d.h"
  33. class Polygon2D : public Node2D {
  34. GDCLASS(Polygon2D, Node2D);
  35. Vector<Vector2> polygon;
  36. Vector<Vector2> uv;
  37. Vector<Color> vertex_colors;
  38. Array polygons;
  39. int internal_vertices = 0;
  40. struct Bone {
  41. NodePath path;
  42. Vector<float> weights;
  43. };
  44. Vector<Bone> bone_weights;
  45. Color color = Color(1, 1, 1);
  46. Ref<Texture2D> texture;
  47. Size2 tex_scale = Vector2(1, 1);
  48. Vector2 tex_ofs;
  49. bool tex_tile = true;
  50. real_t tex_rot = 0.0;
  51. bool invert = false;
  52. real_t invert_border = 100.0;
  53. bool antialiased = false;
  54. Vector2 offset;
  55. mutable bool rect_cache_dirty = true;
  56. mutable Rect2 item_rect;
  57. NodePath skeleton;
  58. ObjectID current_skeleton_id;
  59. Array _get_bones() const;
  60. void _set_bones(const Array &p_bones);
  61. void _skeleton_bone_setup_changed();
  62. RID mesh;
  63. protected:
  64. void _notification(int p_what);
  65. static void _bind_methods();
  66. void _validate_property(PropertyInfo &p_property) const;
  67. public:
  68. #ifdef TOOLS_ENABLED
  69. virtual Dictionary _edit_get_state() const override;
  70. virtual void _edit_set_state(const Dictionary &p_state) override;
  71. virtual void _edit_set_pivot(const Point2 &p_pivot) override;
  72. virtual Point2 _edit_get_pivot() const override;
  73. virtual bool _edit_use_pivot() const override;
  74. #endif // TOOLS_ENABLED
  75. #ifdef DEBUG_ENABLED
  76. virtual Rect2 _edit_get_rect() const override;
  77. virtual bool _edit_use_rect() const override;
  78. virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const override;
  79. #endif // DEBUG_ENABLED
  80. void set_polygon(const Vector<Vector2> &p_polygon);
  81. Vector<Vector2> get_polygon() const;
  82. void set_internal_vertex_count(int p_count);
  83. int get_internal_vertex_count() const;
  84. void set_uv(const Vector<Vector2> &p_uv);
  85. Vector<Vector2> get_uv() const;
  86. void set_polygons(const Array &p_polygons);
  87. Array get_polygons() const;
  88. void set_color(const Color &p_color);
  89. Color get_color() const;
  90. void set_vertex_colors(const Vector<Color> &p_colors);
  91. Vector<Color> get_vertex_colors() const;
  92. void set_texture(const Ref<Texture2D> &p_texture);
  93. Ref<Texture2D> get_texture() const;
  94. void set_texture_offset(const Vector2 &p_offset);
  95. Vector2 get_texture_offset() const;
  96. void set_texture_rotation(real_t p_rot);
  97. real_t get_texture_rotation() const;
  98. void set_texture_scale(const Size2 &p_scale);
  99. Size2 get_texture_scale() const;
  100. void set_invert(bool p_invert);
  101. bool get_invert() const;
  102. void set_antialiased(bool p_antialiased);
  103. bool get_antialiased() const;
  104. void set_invert_border(real_t p_invert_border);
  105. real_t get_invert_border() const;
  106. void set_offset(const Vector2 &p_offset);
  107. Vector2 get_offset() const;
  108. void add_bone(const NodePath &p_path = NodePath(), const Vector<float> &p_weights = Vector<float>());
  109. int get_bone_count() const;
  110. NodePath get_bone_path(int p_index) const;
  111. Vector<float> get_bone_weights(int p_index) const;
  112. void erase_bone(int p_idx);
  113. void clear_bones();
  114. void set_bone_weights(int p_index, const Vector<float> &p_weights);
  115. void set_bone_path(int p_index, const NodePath &p_path);
  116. void set_skeleton(const NodePath &p_skeleton);
  117. NodePath get_skeleton() const;
  118. Polygon2D();
  119. ~Polygon2D();
  120. };
  121. #endif // POLYGON_2D_H