| 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 | |
| 31 | #ifndef POLYGON_2D_H |
| 32 | #define POLYGON_2D_H |
| 33 | |
| 34 | #include "scene/2d/node_2d.h" |
| 35 | |
| 36 | class Polygon2D : public Node2D { |
| 37 | GDCLASS(Polygon2D, Node2D); |
| 38 | |
| 39 | Vector<Vector2> polygon; |
| 40 | Vector<Vector2> uv; |
| 41 | Vector<Color> vertex_colors; |
| 42 | Array polygons; |
| 43 | int internal_vertices = 0; |
| 44 | |
| 45 | struct Bone { |
| 46 | NodePath path; |
| 47 | Vector<float> weights; |
| 48 | }; |
| 49 | |
| 50 | Vector<Bone> bone_weights; |
| 51 | |
| 52 | Color color = Color(1, 1, 1); |
| 53 | Ref<Texture2D> texture; |
| 54 | |
| 55 | Size2 tex_scale = Vector2(1, 1); |
| 56 | Vector2 tex_ofs; |
| 57 | bool tex_tile = true; |
| 58 | real_t tex_rot = 0.0; |
| 59 | bool invert = false; |
| 60 | real_t invert_border = 100.0; |
| 61 | bool antialiased = false; |
| 62 | |
| 63 | Vector2 offset; |
| 64 | mutable bool rect_cache_dirty = true; |
| 65 | mutable Rect2 item_rect; |
| 66 | |
| 67 | NodePath skeleton; |
| 68 | ObjectID current_skeleton_id; |
| 69 | |
| 70 | Array _get_bones() const; |
| 71 | void _set_bones(const Array &p_bones); |
| 72 | |
| 73 | void _skeleton_bone_setup_changed(); |
| 74 | |
| 75 | RID mesh; |
| 76 | |
| 77 | protected: |
| 78 | void _notification(int p_what); |
| 79 | static void _bind_methods(); |
| 80 | void _validate_property(PropertyInfo &p_property) const; |
| 81 | |
| 82 | public: |
| 83 | #ifdef TOOLS_ENABLED |
| 84 | virtual Dictionary _edit_get_state() const override; |
| 85 | virtual void _edit_set_state(const Dictionary &p_state) override; |
| 86 | |
| 87 | virtual void _edit_set_pivot(const Point2 &p_pivot) override; |
| 88 | virtual Point2 _edit_get_pivot() const override; |
| 89 | virtual bool _edit_use_pivot() const override; |
| 90 | virtual Rect2 _edit_get_rect() const override; |
| 91 | virtual bool _edit_use_rect() const override; |
| 92 | |
| 93 | virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const override; |
| 94 | #endif |
| 95 | |
| 96 | void set_polygon(const Vector<Vector2> &p_polygon); |
| 97 | Vector<Vector2> get_polygon() const; |
| 98 | |
| 99 | void set_internal_vertex_count(int p_count); |
| 100 | int get_internal_vertex_count() const; |
| 101 | |
| 102 | void set_uv(const Vector<Vector2> &p_uv); |
| 103 | Vector<Vector2> get_uv() const; |
| 104 | |
| 105 | void set_polygons(const Array &p_polygons); |
| 106 | Array get_polygons() const; |
| 107 | |
| 108 | void set_color(const Color &p_color); |
| 109 | Color get_color() const; |
| 110 | |
| 111 | void set_vertex_colors(const Vector<Color> &p_colors); |
| 112 | Vector<Color> get_vertex_colors() const; |
| 113 | |
| 114 | void set_texture(const Ref<Texture2D> &p_texture); |
| 115 | Ref<Texture2D> get_texture() const; |
| 116 | |
| 117 | void set_texture_offset(const Vector2 &p_offset); |
| 118 | Vector2 get_texture_offset() const; |
| 119 | |
| 120 | void set_texture_rotation(real_t p_rot); |
| 121 | real_t get_texture_rotation() const; |
| 122 | |
| 123 | void set_texture_scale(const Size2 &p_scale); |
| 124 | Size2 get_texture_scale() const; |
| 125 | |
| 126 | void set_invert(bool p_invert); |
| 127 | bool get_invert() const; |
| 128 | |
| 129 | void set_antialiased(bool p_antialiased); |
| 130 | bool get_antialiased() const; |
| 131 | |
| 132 | void set_invert_border(real_t p_invert_border); |
| 133 | real_t get_invert_border() const; |
| 134 | |
| 135 | void set_offset(const Vector2 &p_offset); |
| 136 | Vector2 get_offset() const; |
| 137 | |
| 138 | void add_bone(const NodePath &p_path = NodePath(), const Vector<float> &p_weights = Vector<float>()); |
| 139 | int get_bone_count() const; |
| 140 | NodePath get_bone_path(int p_index) const; |
| 141 | Vector<float> get_bone_weights(int p_index) const; |
| 142 | void erase_bone(int p_idx); |
| 143 | void clear_bones(); |
| 144 | void set_bone_weights(int p_index, const Vector<float> &p_weights); |
| 145 | void set_bone_path(int p_index, const NodePath &p_path); |
| 146 | |
| 147 | void set_skeleton(const NodePath &p_skeleton); |
| 148 | NodePath get_skeleton() const; |
| 149 | |
| 150 | Polygon2D(); |
| 151 | ~Polygon2D(); |
| 152 | }; |
| 153 | |
| 154 | #endif // POLYGON_2D_H |
| 155 | |