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