polygon_2d.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. /*************************************************************************/
  2. /* polygon_2d.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  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. #include "polygon_2d.h"
  31. #include "core/math/geometry.h"
  32. #include "skeleton_2d.h"
  33. Dictionary Polygon2D::_edit_get_state() const {
  34. Dictionary state = Node2D::_edit_get_state();
  35. state["offset"] = offset;
  36. return state;
  37. }
  38. void Polygon2D::_edit_set_state(const Dictionary &p_state) {
  39. Node2D::_edit_set_state(p_state);
  40. set_offset(p_state["offset"]);
  41. }
  42. void Polygon2D::_edit_set_pivot(const Point2 &p_pivot) {
  43. set_position(get_transform().xform(p_pivot));
  44. set_offset(get_offset() - p_pivot);
  45. }
  46. Point2 Polygon2D::_edit_get_pivot() const {
  47. return Vector2();
  48. }
  49. bool Polygon2D::_edit_use_pivot() const {
  50. return true;
  51. }
  52. Rect2 Polygon2D::_edit_get_rect() const {
  53. if (rect_cache_dirty) {
  54. int l = polygon.size();
  55. PoolVector<Vector2>::Read r = polygon.read();
  56. item_rect = Rect2();
  57. for (int i = 0; i < l; i++) {
  58. Vector2 pos = r[i] + offset;
  59. if (i == 0)
  60. item_rect.position = pos;
  61. else
  62. item_rect.expand_to(pos);
  63. }
  64. rect_cache_dirty = false;
  65. }
  66. return item_rect;
  67. }
  68. bool Polygon2D::_edit_use_rect() const {
  69. return true;
  70. }
  71. bool Polygon2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const {
  72. return Geometry::is_point_in_polygon(p_point - get_offset(), Variant(polygon));
  73. }
  74. void Polygon2D::_notification(int p_what) {
  75. switch (p_what) {
  76. case NOTIFICATION_DRAW: {
  77. if (polygon.size() < 3)
  78. return;
  79. Skeleton2D *skeleton_node = NULL;
  80. if (has_node(skeleton)) {
  81. skeleton_node = Object::cast_to<Skeleton2D>(get_node(skeleton));
  82. }
  83. if (skeleton_node)
  84. VS::get_singleton()->canvas_item_attach_skeleton(get_canvas_item(), skeleton_node->get_skeleton());
  85. else
  86. VS::get_singleton()->canvas_item_attach_skeleton(get_canvas_item(), RID());
  87. Vector<Vector2> points;
  88. Vector<Vector2> uvs;
  89. Vector<int> bones;
  90. Vector<float> weights;
  91. points.resize(polygon.size());
  92. int len = points.size();
  93. {
  94. PoolVector<Vector2>::Read polyr = polygon.read();
  95. for (int i = 0; i < len; i++) {
  96. points.write[i] = polyr[i] + offset;
  97. }
  98. }
  99. if (invert) {
  100. Rect2 bounds;
  101. int highest_idx = -1;
  102. float highest_y = -1e20;
  103. float sum = 0;
  104. for (int i = 0; i < len; i++) {
  105. if (i == 0)
  106. bounds.position = points[i];
  107. else
  108. bounds.expand_to(points[i]);
  109. if (points[i].y > highest_y) {
  110. highest_idx = i;
  111. highest_y = points[i].y;
  112. }
  113. int ni = (i + 1) % len;
  114. sum += (points[ni].x - points[i].x) * (points[ni].y + points[i].y);
  115. }
  116. bounds = bounds.grow(invert_border);
  117. Vector2 ep[7] = {
  118. Vector2(points[highest_idx].x, points[highest_idx].y + invert_border),
  119. Vector2(bounds.position + bounds.size),
  120. Vector2(bounds.position + Vector2(bounds.size.x, 0)),
  121. Vector2(bounds.position),
  122. Vector2(bounds.position + Vector2(0, bounds.size.y)),
  123. Vector2(points[highest_idx].x - CMP_EPSILON, points[highest_idx].y + invert_border),
  124. Vector2(points[highest_idx].x - CMP_EPSILON, points[highest_idx].y),
  125. };
  126. if (sum > 0) {
  127. SWAP(ep[1], ep[4]);
  128. SWAP(ep[2], ep[3]);
  129. SWAP(ep[5], ep[0]);
  130. SWAP(ep[6], points.write[highest_idx]);
  131. }
  132. points.resize(points.size() + 7);
  133. for (int i = points.size() - 1; i >= highest_idx + 7; i--) {
  134. points.write[i] = points[i - 7];
  135. }
  136. for (int i = 0; i < 7; i++) {
  137. points.write[highest_idx + i + 1] = ep[i];
  138. }
  139. len = points.size();
  140. }
  141. if (texture.is_valid()) {
  142. Transform2D texmat(tex_rot, tex_ofs);
  143. texmat.scale(tex_scale);
  144. Size2 tex_size = texture->get_size();
  145. uvs.resize(points.size());
  146. if (points.size() == uv.size()) {
  147. PoolVector<Vector2>::Read uvr = uv.read();
  148. for (int i = 0; i < len; i++) {
  149. uvs.write[i] = texmat.xform(uvr[i]) / tex_size;
  150. }
  151. } else {
  152. for (int i = 0; i < len; i++) {
  153. uvs.write[i] = texmat.xform(points[i]) / tex_size;
  154. }
  155. }
  156. }
  157. if (skeleton_node && !invert && bone_weights.size()) {
  158. //a skeleton is set! fill indices and weights
  159. int vc = points.size();
  160. bones.resize(vc * 4);
  161. weights.resize(vc * 4);
  162. int *bonesw = bones.ptrw();
  163. float *weightsw = weights.ptrw();
  164. for (int i = 0; i < vc * 4; i++) {
  165. bonesw[i] = 0;
  166. weightsw[i] = 0;
  167. }
  168. for (int i = 0; i < bone_weights.size(); i++) {
  169. if (bone_weights[i].weights.size() != points.size()) {
  170. continue; //different number of vertices, sorry not using.
  171. }
  172. if (!skeleton_node->has_node(bone_weights[i].path)) {
  173. continue; //node does not exist
  174. }
  175. Bone2D *bone = Object::cast_to<Bone2D>(skeleton_node->get_node(bone_weights[i].path));
  176. if (!bone) {
  177. continue;
  178. }
  179. int bone_index = bone->get_index_in_skeleton();
  180. PoolVector<float>::Read r = bone_weights[i].weights.read();
  181. for (int j = 0; j < vc; j++) {
  182. if (r[j] == 0.0)
  183. continue; //weight is unpainted, skip
  184. //find an index with a weight
  185. for (int k = 0; k < 4; k++) {
  186. if (weightsw[j * 4 + k] < r[j]) {
  187. //this is less than this weight, insert weight!
  188. for (int l = 3; l > k; l--) {
  189. weightsw[j * 4 + l] = weightsw[j * 4 + l - 1];
  190. bonesw[j * 4 + l] = bonesw[j * 4 + l - 1];
  191. }
  192. weightsw[j * 4 + k] = r[j];
  193. bonesw[j * 4 + k] = bone_index;
  194. break;
  195. }
  196. }
  197. }
  198. }
  199. //normalize the weights
  200. for (int i = 0; i < vc; i++) {
  201. float tw = 0;
  202. for (int j = 0; j < 4; j++) {
  203. tw += weightsw[i * 4 + j];
  204. }
  205. if (tw == 0)
  206. continue; //unpainted, do nothing
  207. //normalize
  208. for (int j = 0; j < 4; j++) {
  209. weightsw[i * 4 + j] /= tw;
  210. }
  211. }
  212. }
  213. Vector<Color> colors;
  214. int color_len = vertex_colors.size();
  215. colors.resize(len);
  216. {
  217. PoolVector<Color>::Read color_r = vertex_colors.read();
  218. for (int i = 0; i < color_len && i < len; i++) {
  219. colors.write[i] = color_r[i];
  220. }
  221. for (int i = color_len; i < len; i++) {
  222. colors.write[i] = color;
  223. }
  224. }
  225. // Vector<int> indices = Geometry::triangulate_polygon(points);
  226. // VS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), indices, points, colors, uvs, texture.is_valid() ? texture->get_rid() : RID());
  227. if (invert || splits.size() == 0) {
  228. Vector<int> indices = Geometry::triangulate_polygon(points);
  229. VS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), indices, points, colors, uvs, bones, weights, texture.is_valid() ? texture->get_rid() : RID());
  230. } else {
  231. //use splits
  232. Vector<int> loop;
  233. int sc = splits.size();
  234. PoolVector<int>::Read r = splits.read();
  235. int last = points.size();
  236. Vector<Vector<int> > loops;
  237. for (int i = 0; i < last; i++) {
  238. int split;
  239. int min_end = -1;
  240. do {
  241. loop.push_back(i);
  242. split = -1;
  243. int end = -1;
  244. for (int j = 0; j < sc; j += 2) {
  245. if (r[j + 1] >= last)
  246. continue; //no longer valid
  247. if (min_end != -1 && r[j + 1] >= min_end)
  248. continue;
  249. if (r[j] == i) {
  250. if (split == -1 || r[j + 1] > end) {
  251. split = r[j];
  252. end = r[j + 1];
  253. }
  254. }
  255. }
  256. if (split != -1) {
  257. for (int j = end; j < last; j++) {
  258. loop.push_back(j);
  259. }
  260. loops.push_back(loop);
  261. last = end + 1;
  262. loop.clear();
  263. min_end = end; //avoid this split from repeating
  264. }
  265. } while (split != -1);
  266. }
  267. if (loop.size()) {
  268. loops.push_back(loop);
  269. }
  270. Vector<int> indices;
  271. for (int i = 0; i < loops.size(); i++) {
  272. Vector<int> loop = loops[i];
  273. Vector<Vector2> vertices;
  274. vertices.resize(loop.size());
  275. for (int j = 0; j < vertices.size(); j++) {
  276. vertices.write[j] = points[loop[j]];
  277. }
  278. Vector<int> sub_indices = Geometry::triangulate_polygon(vertices);
  279. int from = indices.size();
  280. indices.resize(from + sub_indices.size());
  281. for (int j = 0; j < sub_indices.size(); j++) {
  282. indices.write[from + j] = loop[sub_indices[j]];
  283. }
  284. }
  285. VS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), indices, points, colors, uvs, bones, weights, texture.is_valid() ? texture->get_rid() : RID());
  286. }
  287. } break;
  288. }
  289. }
  290. void Polygon2D::set_polygon(const PoolVector<Vector2> &p_polygon) {
  291. polygon = p_polygon;
  292. rect_cache_dirty = true;
  293. update();
  294. }
  295. PoolVector<Vector2> Polygon2D::get_polygon() const {
  296. return polygon;
  297. }
  298. void Polygon2D::set_uv(const PoolVector<Vector2> &p_uv) {
  299. uv = p_uv;
  300. update();
  301. }
  302. PoolVector<Vector2> Polygon2D::get_uv() const {
  303. return uv;
  304. }
  305. void Polygon2D::set_splits(const PoolVector<int> &p_splits) {
  306. ERR_FAIL_COND(p_splits.size() & 1); //splits should be multiple of 2
  307. splits = p_splits;
  308. update();
  309. }
  310. PoolVector<int> Polygon2D::get_splits() const {
  311. return splits;
  312. }
  313. void Polygon2D::set_color(const Color &p_color) {
  314. color = p_color;
  315. update();
  316. }
  317. Color Polygon2D::get_color() const {
  318. return color;
  319. }
  320. void Polygon2D::set_vertex_colors(const PoolVector<Color> &p_colors) {
  321. vertex_colors = p_colors;
  322. update();
  323. }
  324. PoolVector<Color> Polygon2D::get_vertex_colors() const {
  325. return vertex_colors;
  326. }
  327. void Polygon2D::set_texture(const Ref<Texture> &p_texture) {
  328. texture = p_texture;
  329. /*if (texture.is_valid()) {
  330. uint32_t flags=texture->get_flags();
  331. flags&=~Texture::FLAG_REPEAT;
  332. if (tex_tile)
  333. flags|=Texture::FLAG_REPEAT;
  334. texture->set_flags(flags);
  335. }*/
  336. update();
  337. }
  338. Ref<Texture> Polygon2D::get_texture() const {
  339. return texture;
  340. }
  341. void Polygon2D::set_texture_offset(const Vector2 &p_offset) {
  342. tex_ofs = p_offset;
  343. update();
  344. }
  345. Vector2 Polygon2D::get_texture_offset() const {
  346. return tex_ofs;
  347. }
  348. void Polygon2D::set_texture_rotation(float p_rot) {
  349. tex_rot = p_rot;
  350. update();
  351. }
  352. float Polygon2D::get_texture_rotation() const {
  353. return tex_rot;
  354. }
  355. void Polygon2D::set_texture_rotation_degrees(float p_rot) {
  356. set_texture_rotation(Math::deg2rad(p_rot));
  357. }
  358. float Polygon2D::get_texture_rotation_degrees() const {
  359. return Math::rad2deg(get_texture_rotation());
  360. }
  361. void Polygon2D::set_texture_scale(const Size2 &p_scale) {
  362. tex_scale = p_scale;
  363. update();
  364. }
  365. Size2 Polygon2D::get_texture_scale() const {
  366. return tex_scale;
  367. }
  368. void Polygon2D::set_invert(bool p_invert) {
  369. invert = p_invert;
  370. update();
  371. }
  372. bool Polygon2D::get_invert() const {
  373. return invert;
  374. }
  375. void Polygon2D::set_antialiased(bool p_antialiased) {
  376. antialiased = p_antialiased;
  377. update();
  378. }
  379. bool Polygon2D::get_antialiased() const {
  380. return antialiased;
  381. }
  382. void Polygon2D::set_invert_border(float p_invert_border) {
  383. invert_border = p_invert_border;
  384. update();
  385. }
  386. float Polygon2D::get_invert_border() const {
  387. return invert_border;
  388. }
  389. void Polygon2D::set_offset(const Vector2 &p_offset) {
  390. offset = p_offset;
  391. rect_cache_dirty = true;
  392. update();
  393. _change_notify("offset");
  394. }
  395. Vector2 Polygon2D::get_offset() const {
  396. return offset;
  397. }
  398. void Polygon2D::add_bone(const NodePath &p_path, const PoolVector<float> &p_weights) {
  399. Bone bone;
  400. bone.path = p_path;
  401. bone.weights = p_weights;
  402. bone_weights.push_back(bone);
  403. }
  404. int Polygon2D::get_bone_count() const {
  405. return bone_weights.size();
  406. }
  407. NodePath Polygon2D::get_bone_path(int p_index) const {
  408. ERR_FAIL_INDEX_V(p_index, bone_weights.size(), NodePath());
  409. return bone_weights[p_index].path;
  410. }
  411. PoolVector<float> Polygon2D::get_bone_weights(int p_index) const {
  412. ERR_FAIL_INDEX_V(p_index, bone_weights.size(), PoolVector<float>());
  413. return bone_weights[p_index].weights;
  414. }
  415. void Polygon2D::erase_bone(int p_idx) {
  416. ERR_FAIL_INDEX(p_idx, bone_weights.size());
  417. bone_weights.remove(p_idx);
  418. }
  419. void Polygon2D::clear_bones() {
  420. bone_weights.clear();
  421. }
  422. void Polygon2D::set_bone_weights(int p_index, const PoolVector<float> &p_weights) {
  423. ERR_FAIL_INDEX(p_index, bone_weights.size());
  424. bone_weights.write[p_index].weights = p_weights;
  425. update();
  426. }
  427. void Polygon2D::set_bone_path(int p_index, const NodePath &p_path) {
  428. ERR_FAIL_INDEX(p_index, bone_weights.size());
  429. bone_weights.write[p_index].path = p_path;
  430. update();
  431. }
  432. Array Polygon2D::_get_bones() const {
  433. Array bones;
  434. for (int i = 0; i < get_bone_count(); i++) {
  435. bones.push_back(get_bone_path(i));
  436. bones.push_back(get_bone_weights(i));
  437. }
  438. return bones;
  439. }
  440. void Polygon2D::_set_bones(const Array &p_bones) {
  441. ERR_FAIL_COND(p_bones.size() & 1);
  442. clear_bones();
  443. for (int i = 0; i < p_bones.size(); i += 2) {
  444. add_bone(p_bones[i], p_bones[i + 1]);
  445. }
  446. }
  447. void Polygon2D::set_skeleton(const NodePath &p_skeleton) {
  448. if (skeleton == p_skeleton)
  449. return;
  450. skeleton = p_skeleton;
  451. update();
  452. }
  453. NodePath Polygon2D::get_skeleton() const {
  454. return skeleton;
  455. }
  456. void Polygon2D::_bind_methods() {
  457. ClassDB::bind_method(D_METHOD("set_polygon", "polygon"), &Polygon2D::set_polygon);
  458. ClassDB::bind_method(D_METHOD("get_polygon"), &Polygon2D::get_polygon);
  459. ClassDB::bind_method(D_METHOD("set_uv", "uv"), &Polygon2D::set_uv);
  460. ClassDB::bind_method(D_METHOD("get_uv"), &Polygon2D::get_uv);
  461. ClassDB::bind_method(D_METHOD("set_color", "color"), &Polygon2D::set_color);
  462. ClassDB::bind_method(D_METHOD("get_color"), &Polygon2D::get_color);
  463. ClassDB::bind_method(D_METHOD("set_splits", "splits"), &Polygon2D::set_splits);
  464. ClassDB::bind_method(D_METHOD("get_splits"), &Polygon2D::get_splits);
  465. ClassDB::bind_method(D_METHOD("set_vertex_colors", "vertex_colors"), &Polygon2D::set_vertex_colors);
  466. ClassDB::bind_method(D_METHOD("get_vertex_colors"), &Polygon2D::get_vertex_colors);
  467. ClassDB::bind_method(D_METHOD("set_texture", "texture"), &Polygon2D::set_texture);
  468. ClassDB::bind_method(D_METHOD("get_texture"), &Polygon2D::get_texture);
  469. ClassDB::bind_method(D_METHOD("set_texture_offset", "texture_offset"), &Polygon2D::set_texture_offset);
  470. ClassDB::bind_method(D_METHOD("get_texture_offset"), &Polygon2D::get_texture_offset);
  471. ClassDB::bind_method(D_METHOD("set_texture_rotation", "texture_rotation"), &Polygon2D::set_texture_rotation);
  472. ClassDB::bind_method(D_METHOD("get_texture_rotation"), &Polygon2D::get_texture_rotation);
  473. ClassDB::bind_method(D_METHOD("set_texture_rotation_degrees", "texture_rotation"), &Polygon2D::set_texture_rotation_degrees);
  474. ClassDB::bind_method(D_METHOD("get_texture_rotation_degrees"), &Polygon2D::get_texture_rotation_degrees);
  475. ClassDB::bind_method(D_METHOD("set_texture_scale", "texture_scale"), &Polygon2D::set_texture_scale);
  476. ClassDB::bind_method(D_METHOD("get_texture_scale"), &Polygon2D::get_texture_scale);
  477. ClassDB::bind_method(D_METHOD("set_invert", "invert"), &Polygon2D::set_invert);
  478. ClassDB::bind_method(D_METHOD("get_invert"), &Polygon2D::get_invert);
  479. ClassDB::bind_method(D_METHOD("set_antialiased", "antialiased"), &Polygon2D::set_antialiased);
  480. ClassDB::bind_method(D_METHOD("get_antialiased"), &Polygon2D::get_antialiased);
  481. ClassDB::bind_method(D_METHOD("set_invert_border", "invert_border"), &Polygon2D::set_invert_border);
  482. ClassDB::bind_method(D_METHOD("get_invert_border"), &Polygon2D::get_invert_border);
  483. ClassDB::bind_method(D_METHOD("set_offset", "offset"), &Polygon2D::set_offset);
  484. ClassDB::bind_method(D_METHOD("get_offset"), &Polygon2D::get_offset);
  485. ClassDB::bind_method(D_METHOD("add_bone", "path", "weights"), &Polygon2D::add_bone);
  486. ClassDB::bind_method(D_METHOD("get_bone_count"), &Polygon2D::get_bone_count);
  487. ClassDB::bind_method(D_METHOD("get_bone_path", "index"), &Polygon2D::get_bone_path);
  488. ClassDB::bind_method(D_METHOD("get_bone_weights", "index"), &Polygon2D::get_bone_weights);
  489. ClassDB::bind_method(D_METHOD("erase_bone", "index"), &Polygon2D::erase_bone);
  490. ClassDB::bind_method(D_METHOD("clear_bones"), &Polygon2D::clear_bones);
  491. ClassDB::bind_method(D_METHOD("set_bone_path", "index", "path"), &Polygon2D::set_bone_path);
  492. ClassDB::bind_method(D_METHOD("set_bone_weights", "index", "weights"), &Polygon2D::set_bone_weights);
  493. ClassDB::bind_method(D_METHOD("set_skeleton", "skeleton"), &Polygon2D::set_skeleton);
  494. ClassDB::bind_method(D_METHOD("get_skeleton"), &Polygon2D::get_skeleton);
  495. ClassDB::bind_method(D_METHOD("_set_bones", "bones"), &Polygon2D::_set_bones);
  496. ClassDB::bind_method(D_METHOD("_get_bones"), &Polygon2D::_get_bones);
  497. ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "polygon"), "set_polygon", "get_polygon");
  498. ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "uv"), "set_uv", "get_uv");
  499. ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "splits"), "set_splits", "get_splits");
  500. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
  501. ADD_PROPERTY(PropertyInfo(Variant::POOL_COLOR_ARRAY, "vertex_colors"), "set_vertex_colors", "get_vertex_colors");
  502. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset");
  503. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "antialiased"), "set_antialiased", "get_antialiased");
  504. ADD_GROUP("Texture", "");
  505. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture");
  506. ADD_GROUP("Texture", "texture_");
  507. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "texture_offset"), "set_texture_offset", "get_texture_offset");
  508. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "texture_scale"), "set_texture_scale", "get_texture_scale");
  509. ADD_PROPERTY(PropertyInfo(Variant::REAL, "texture_rotation_degrees", PROPERTY_HINT_RANGE, "-1080,1080,0.1,or_lesser,or_greater"), "set_texture_rotation_degrees", "get_texture_rotation_degrees");
  510. ADD_PROPERTY(PropertyInfo(Variant::REAL, "texture_rotation", PROPERTY_HINT_NONE, "", 0), "set_texture_rotation", "get_texture_rotation");
  511. ADD_GROUP("Skeleton", "");
  512. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "skeleton", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Skeleton2D"), "set_skeleton", "get_skeleton");
  513. ADD_GROUP("Invert", "invert_");
  514. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "invert_enable"), "set_invert", "get_invert");
  515. ADD_PROPERTY(PropertyInfo(Variant::REAL, "invert_border", PROPERTY_HINT_RANGE, "0.1,16384,0.1"), "set_invert_border", "get_invert_border");
  516. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bones", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_bones", "_get_bones");
  517. }
  518. Polygon2D::Polygon2D() {
  519. invert = 0;
  520. invert_border = 100;
  521. antialiased = false;
  522. tex_rot = 0;
  523. tex_tile = true;
  524. tex_scale = Vector2(1, 1);
  525. color = Color(1, 1, 1);
  526. rect_cache_dirty = true;
  527. }