2023-01-05 13:25:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* polygon_2d.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-07-07 22:44:21 +02:00
|
|
|
#include "polygon_2d.h"
|
2018-08-16 14:36:36 +02:00
|
|
|
|
2020-05-25 19:20:45 +02:00
|
|
|
#include "core/math/geometry_2d.h"
|
2018-05-03 22:29:15 +02:00
|
|
|
#include "skeleton_2d.h"
|
2018-08-16 14:36:36 +02:00
|
|
|
|
2019-10-21 23:37:07 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
2017-11-07 08:58:35 +01:00
|
|
|
Dictionary Polygon2D::_edit_get_state() const {
|
|
|
|
Dictionary state = Node2D::_edit_get_state();
|
|
|
|
state["offset"] = offset;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Polygon2D::_edit_set_state(const Dictionary &p_state) {
|
|
|
|
Node2D::_edit_set_state(p_state);
|
|
|
|
set_offset(p_state["offset"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Polygon2D::_edit_set_pivot(const Point2 &p_pivot) {
|
|
|
|
set_position(get_transform().xform(p_pivot));
|
|
|
|
set_offset(get_offset() - p_pivot);
|
|
|
|
}
|
|
|
|
|
|
|
|
Point2 Polygon2D::_edit_get_pivot() const {
|
|
|
|
return Vector2();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Polygon2D::_edit_use_pivot() const {
|
|
|
|
return true;
|
|
|
|
}
|
2014-07-07 22:44:21 +02:00
|
|
|
|
2017-11-07 08:58:35 +01:00
|
|
|
Rect2 Polygon2D::_edit_get_rect() const {
|
2014-07-07 22:44:21 +02:00
|
|
|
if (rect_cache_dirty) {
|
|
|
|
int l = polygon.size();
|
2020-02-17 22:06:54 +01:00
|
|
|
const Vector2 *r = polygon.ptr();
|
2014-07-07 22:44:21 +02:00
|
|
|
item_rect = Rect2();
|
|
|
|
for (int i = 0; i < l; i++) {
|
|
|
|
Vector2 pos = r[i] + offset;
|
2020-05-14 16:41:43 +02:00
|
|
|
if (i == 0) {
|
2017-06-04 00:25:13 +02:00
|
|
|
item_rect.position = pos;
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2014-07-07 22:44:21 +02:00
|
|
|
item_rect.expand_to(pos);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-07-07 22:44:21 +02:00
|
|
|
}
|
|
|
|
rect_cache_dirty = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item_rect;
|
|
|
|
}
|
|
|
|
|
2018-03-08 21:35:41 +01:00
|
|
|
bool Polygon2D::_edit_use_rect() const {
|
2019-07-08 11:35:52 +02:00
|
|
|
return polygon.size() > 0;
|
2018-03-08 21:35:41 +01:00
|
|
|
}
|
|
|
|
|
2017-12-27 09:28:02 +01:00
|
|
|
bool Polygon2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const {
|
2019-01-08 23:10:24 +01:00
|
|
|
Vector<Vector2> polygon2d = Variant(polygon);
|
|
|
|
if (internal_vertices > 0) {
|
|
|
|
polygon2d.resize(polygon2d.size() - internal_vertices);
|
|
|
|
}
|
2020-05-25 19:20:45 +02:00
|
|
|
return Geometry2D::is_point_in_polygon(p_point - get_offset(), polygon2d);
|
2014-07-07 22:44:21 +02:00
|
|
|
}
|
2021-03-04 00:51:35 +01:00
|
|
|
#endif
|
2020-02-14 03:34:59 +01:00
|
|
|
|
2022-08-12 22:57:11 +02:00
|
|
|
void Polygon2D::_validate_property(PropertyInfo &p_property) const {
|
|
|
|
if (!invert && p_property.name == "invert_border") {
|
|
|
|
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
|
2020-02-14 03:34:59 +01:00
|
|
|
}
|
|
|
|
}
|
2014-07-07 22:44:21 +02:00
|
|
|
|
2019-02-17 00:08:17 +01:00
|
|
|
void Polygon2D::_skeleton_bone_setup_changed() {
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2019-02-17 00:08:17 +01:00
|
|
|
}
|
|
|
|
|
2014-07-07 22:44:21 +02:00
|
|
|
void Polygon2D::_notification(int p_what) {
|
|
|
|
switch (p_what) {
|
|
|
|
case NOTIFICATION_DRAW: {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (polygon.size() < 3) {
|
2014-07-07 22:44:21 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-07-07 22:44:21 +02:00
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
Skeleton2D *skeleton_node = nullptr;
|
2018-05-03 22:29:15 +02:00
|
|
|
if (has_node(skeleton)) {
|
|
|
|
skeleton_node = Object::cast_to<Skeleton2D>(get_node(skeleton));
|
|
|
|
}
|
|
|
|
|
2020-02-12 18:24:06 +01:00
|
|
|
ObjectID new_skeleton_id;
|
2019-02-17 00:08:17 +01:00
|
|
|
|
2022-11-19 01:12:48 +01:00
|
|
|
if (skeleton_node && !invert && bone_weights.size()) {
|
2020-03-27 19:21:27 +01:00
|
|
|
RS::get_singleton()->canvas_item_attach_skeleton(get_canvas_item(), skeleton_node->get_skeleton());
|
2019-02-17 00:08:17 +01:00
|
|
|
new_skeleton_id = skeleton_node->get_instance_id();
|
|
|
|
} else {
|
2020-03-27 19:21:27 +01:00
|
|
|
RS::get_singleton()->canvas_item_attach_skeleton(get_canvas_item(), RID());
|
2019-02-17 00:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (new_skeleton_id != current_skeleton_id) {
|
|
|
|
Object *old_skeleton = ObjectDB::get_instance(current_skeleton_id);
|
|
|
|
if (old_skeleton) {
|
2020-02-21 18:28:45 +01:00
|
|
|
old_skeleton->disconnect("bone_setup_changed", callable_mp(this, &Polygon2D::_skeleton_bone_setup_changed));
|
2019-02-17 00:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (skeleton_node) {
|
2020-02-21 18:28:45 +01:00
|
|
|
skeleton_node->connect("bone_setup_changed", callable_mp(this, &Polygon2D::_skeleton_bone_setup_changed));
|
2019-02-17 00:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
current_skeleton_id = new_skeleton_id;
|
|
|
|
}
|
2018-05-03 22:29:15 +02:00
|
|
|
|
2014-07-07 22:44:21 +02:00
|
|
|
Vector<Vector2> points;
|
|
|
|
Vector<Vector2> uvs;
|
2018-05-03 22:29:15 +02:00
|
|
|
Vector<int> bones;
|
|
|
|
Vector<float> weights;
|
2014-07-07 22:44:21 +02:00
|
|
|
|
2019-01-08 23:10:24 +01:00
|
|
|
int len = polygon.size();
|
|
|
|
if ((invert || polygons.size() == 0) && internal_vertices > 0) {
|
|
|
|
//if no polygons are around, internal vertices must not be drawn, else let them be
|
|
|
|
len -= internal_vertices;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
points.resize(len);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
|
|
{
|
2020-02-17 22:06:54 +01:00
|
|
|
const Vector2 *polyr = polygon.ptr();
|
2014-07-07 22:44:21 +02:00
|
|
|
for (int i = 0; i < len; i++) {
|
2018-07-25 03:11:03 +02:00
|
|
|
points.write[i] = polyr[i] + offset;
|
2014-07-07 22:44:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (invert) {
|
|
|
|
Rect2 bounds;
|
|
|
|
int highest_idx = -1;
|
2021-01-30 05:10:32 +01:00
|
|
|
real_t highest_y = -1e20;
|
|
|
|
real_t sum = 0.0;
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < len; i++) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (i == 0) {
|
2017-06-04 00:25:13 +02:00
|
|
|
bounds.position = points[i];
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2014-07-07 22:44:21 +02:00
|
|
|
bounds.expand_to(points[i]);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-07-07 22:44:21 +02:00
|
|
|
if (points[i].y > highest_y) {
|
|
|
|
highest_idx = i;
|
|
|
|
highest_y = points[i].y;
|
|
|
|
}
|
|
|
|
int ni = (i + 1) % len;
|
|
|
|
sum += (points[ni].x - points[i].x) * (points[ni].y + points[i].y);
|
|
|
|
}
|
|
|
|
|
|
|
|
bounds = bounds.grow(invert_border);
|
|
|
|
|
|
|
|
Vector2 ep[7] = {
|
|
|
|
Vector2(points[highest_idx].x, points[highest_idx].y + invert_border),
|
2017-06-04 00:25:13 +02:00
|
|
|
Vector2(bounds.position + bounds.size),
|
|
|
|
Vector2(bounds.position + Vector2(bounds.size.x, 0)),
|
|
|
|
Vector2(bounds.position),
|
|
|
|
Vector2(bounds.position + Vector2(0, bounds.size.y)),
|
2014-07-07 22:44:21 +02:00
|
|
|
Vector2(points[highest_idx].x - CMP_EPSILON, points[highest_idx].y + invert_border),
|
|
|
|
Vector2(points[highest_idx].x - CMP_EPSILON, points[highest_idx].y),
|
|
|
|
};
|
|
|
|
|
|
|
|
if (sum > 0) {
|
|
|
|
SWAP(ep[1], ep[4]);
|
|
|
|
SWAP(ep[2], ep[3]);
|
|
|
|
SWAP(ep[5], ep[0]);
|
2018-07-25 03:11:03 +02:00
|
|
|
SWAP(ep[6], points.write[highest_idx]);
|
2014-07-07 22:44:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
points.resize(points.size() + 7);
|
|
|
|
for (int i = points.size() - 1; i >= highest_idx + 7; i--) {
|
2018-07-25 03:11:03 +02:00
|
|
|
points.write[i] = points[i - 7];
|
2014-07-07 22:44:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 7; i++) {
|
2018-07-25 03:11:03 +02:00
|
|
|
points.write[highest_idx + i + 1] = ep[i];
|
2014-07-07 22:44:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
len = points.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (texture.is_valid()) {
|
2017-01-11 04:52:51 +01:00
|
|
|
Transform2D texmat(tex_rot, tex_ofs);
|
2014-07-07 22:44:21 +02:00
|
|
|
texmat.scale(tex_scale);
|
2017-08-21 21:15:36 +02:00
|
|
|
Size2 tex_size = texture->get_size();
|
2019-01-08 23:10:24 +01:00
|
|
|
|
|
|
|
uvs.resize(len);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
|
|
if (points.size() == uv.size()) {
|
2020-02-17 22:06:54 +01:00
|
|
|
const Vector2 *uvr = uv.ptr();
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < len; i++) {
|
2018-07-25 03:11:03 +02:00
|
|
|
uvs.write[i] = texmat.xform(uvr[i]) / tex_size;
|
2014-07-07 22:44:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < len; i++) {
|
2018-07-25 03:11:03 +02:00
|
|
|
uvs.write[i] = texmat.xform(points[i]) / tex_size;
|
2014-07-07 22:44:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-23 13:35:43 +01:00
|
|
|
if (skeleton_node && !invert && bone_weights.size()) {
|
2018-05-03 22:29:15 +02:00
|
|
|
//a skeleton is set! fill indices and weights
|
2019-01-08 23:10:24 +01:00
|
|
|
int vc = len;
|
2018-05-03 22:29:15 +02:00
|
|
|
bones.resize(vc * 4);
|
|
|
|
weights.resize(vc * 4);
|
|
|
|
|
|
|
|
int *bonesw = bones.ptrw();
|
|
|
|
float *weightsw = weights.ptrw();
|
|
|
|
|
|
|
|
for (int i = 0; i < vc * 4; i++) {
|
|
|
|
bonesw[i] = 0;
|
|
|
|
weightsw[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < bone_weights.size(); i++) {
|
|
|
|
if (bone_weights[i].weights.size() != points.size()) {
|
|
|
|
continue; //different number of vertices, sorry not using.
|
|
|
|
}
|
|
|
|
if (!skeleton_node->has_node(bone_weights[i].path)) {
|
|
|
|
continue; //node does not exist
|
|
|
|
}
|
|
|
|
Bone2D *bone = Object::cast_to<Bone2D>(skeleton_node->get_node(bone_weights[i].path));
|
|
|
|
if (!bone) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int bone_index = bone->get_index_in_skeleton();
|
2020-02-17 22:06:54 +01:00
|
|
|
const float *r = bone_weights[i].weights.ptr();
|
2018-05-03 22:29:15 +02:00
|
|
|
for (int j = 0; j < vc; j++) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (r[j] == 0.0) {
|
2018-05-03 22:29:15 +02:00
|
|
|
continue; //weight is unpainted, skip
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-05-03 22:29:15 +02:00
|
|
|
//find an index with a weight
|
|
|
|
for (int k = 0; k < 4; k++) {
|
|
|
|
if (weightsw[j * 4 + k] < r[j]) {
|
|
|
|
//this is less than this weight, insert weight!
|
|
|
|
for (int l = 3; l > k; l--) {
|
|
|
|
weightsw[j * 4 + l] = weightsw[j * 4 + l - 1];
|
|
|
|
bonesw[j * 4 + l] = bonesw[j * 4 + l - 1];
|
|
|
|
}
|
|
|
|
weightsw[j * 4 + k] = r[j];
|
|
|
|
bonesw[j * 4 + k] = bone_index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//normalize the weights
|
|
|
|
for (int i = 0; i < vc; i++) {
|
2021-01-30 05:10:32 +01:00
|
|
|
real_t tw = 0.0;
|
2018-05-03 22:29:15 +02:00
|
|
|
for (int j = 0; j < 4; j++) {
|
|
|
|
tw += weightsw[i * 4 + j];
|
|
|
|
}
|
2020-05-14 16:41:43 +02:00
|
|
|
if (tw == 0) {
|
2018-05-03 22:29:15 +02:00
|
|
|
continue; //unpainted, do nothing
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-05-03 22:29:15 +02:00
|
|
|
|
|
|
|
//normalize
|
|
|
|
for (int j = 0; j < 4; j++) {
|
|
|
|
weightsw[i * 4 + j] /= tw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-07 22:44:21 +02:00
|
|
|
Vector<Color> colors;
|
2022-02-10 10:36:17 +01:00
|
|
|
colors.resize(len);
|
|
|
|
|
2019-01-08 23:10:24 +01:00
|
|
|
if (vertex_colors.size() == points.size()) {
|
2020-02-17 22:06:54 +01:00
|
|
|
const Color *color_r = vertex_colors.ptr();
|
2019-01-08 23:10:24 +01:00
|
|
|
for (int i = 0; i < len; i++) {
|
2018-07-25 03:11:03 +02:00
|
|
|
colors.write[i] = color_r[i];
|
2016-05-23 03:40:45 +02:00
|
|
|
}
|
2019-01-08 23:10:24 +01:00
|
|
|
} else {
|
2021-05-10 18:12:44 +02:00
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
colors.write[i] = color;
|
|
|
|
}
|
2016-05-23 03:40:45 +02:00
|
|
|
}
|
|
|
|
|
2021-05-10 18:12:44 +02:00
|
|
|
Vector<int> index_array;
|
|
|
|
|
2019-01-08 23:10:24 +01:00
|
|
|
if (invert || polygons.size() == 0) {
|
2021-05-10 18:12:44 +02:00
|
|
|
index_array = Geometry2D::triangulate_polygon(points);
|
2018-02-25 16:06:30 +01:00
|
|
|
} else {
|
2019-01-08 23:10:24 +01:00
|
|
|
//draw individual polygons
|
|
|
|
for (int i = 0; i < polygons.size(); i++) {
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<int> src_indices = polygons[i];
|
2019-01-08 23:10:24 +01:00
|
|
|
int ic = src_indices.size();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (ic < 3) {
|
2019-01-08 23:10:24 +01:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-17 22:06:54 +01:00
|
|
|
const int *r = src_indices.ptr();
|
2019-01-08 23:10:24 +01:00
|
|
|
|
|
|
|
Vector<Vector2> tmp_points;
|
|
|
|
tmp_points.resize(ic);
|
|
|
|
|
|
|
|
for (int j = 0; j < ic; j++) {
|
|
|
|
int idx = r[j];
|
|
|
|
ERR_CONTINUE(idx < 0 || idx >= points.size());
|
|
|
|
tmp_points.write[j] = points[r[j]];
|
|
|
|
}
|
2020-05-25 19:20:45 +02:00
|
|
|
Vector<int> indices = Geometry2D::triangulate_polygon(tmp_points);
|
2019-01-08 23:10:24 +01:00
|
|
|
int ic2 = indices.size();
|
|
|
|
const int *r2 = indices.ptr();
|
|
|
|
|
2021-05-10 18:12:44 +02:00
|
|
|
int bic = index_array.size();
|
|
|
|
index_array.resize(bic + ic2);
|
|
|
|
int *w2 = index_array.ptrw();
|
2019-01-08 23:10:24 +01:00
|
|
|
|
|
|
|
for (int j = 0; j < ic2; j++) {
|
|
|
|
w2[j + bic] = r[r2[j]];
|
|
|
|
}
|
|
|
|
}
|
2021-05-10 18:12:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
RS::get_singleton()->mesh_clear(mesh);
|
|
|
|
|
|
|
|
if (index_array.size()) {
|
|
|
|
Array arr;
|
|
|
|
arr.resize(RS::ARRAY_MAX);
|
|
|
|
arr[RS::ARRAY_VERTEX] = points;
|
|
|
|
if (uvs.size() == points.size()) {
|
|
|
|
arr[RS::ARRAY_TEX_UV] = uvs;
|
|
|
|
}
|
|
|
|
if (colors.size() == points.size()) {
|
|
|
|
arr[RS::ARRAY_COLOR] = colors;
|
|
|
|
}
|
2019-01-08 23:10:24 +01:00
|
|
|
|
2021-05-10 18:12:44 +02:00
|
|
|
if (bones.size() == points.size() * 4) {
|
|
|
|
arr[RS::ARRAY_BONES] = bones;
|
|
|
|
arr[RS::ARRAY_WEIGHTS] = weights;
|
2019-01-08 23:10:24 +01:00
|
|
|
}
|
2021-05-10 18:12:44 +02:00
|
|
|
|
|
|
|
arr[RS::ARRAY_INDEX] = index_array;
|
|
|
|
|
|
|
|
RS::get_singleton()->mesh_add_surface_from_arrays(mesh, RS::PRIMITIVE_TRIANGLES, arr, Array(), Dictionary(), RS::ARRAY_FLAG_USE_2D_VERTICES);
|
2021-06-24 09:26:51 +02:00
|
|
|
RS::get_singleton()->canvas_item_add_mesh(get_canvas_item(), mesh, Transform2D(), Color(1, 1, 1), texture.is_valid() ? texture->get_rid() : RID());
|
2018-02-25 16:06:30 +01:00
|
|
|
}
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
void Polygon2D::set_polygon(const Vector<Vector2> &p_polygon) {
|
2014-07-07 22:44:21 +02:00
|
|
|
polygon = p_polygon;
|
|
|
|
rect_cache_dirty = true;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2014-07-07 22:44:21 +02:00
|
|
|
}
|
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<Vector2> Polygon2D::get_polygon() const {
|
2014-07-07 22:44:21 +02:00
|
|
|
return polygon;
|
|
|
|
}
|
|
|
|
|
2019-01-08 23:10:24 +01:00
|
|
|
void Polygon2D::set_internal_vertex_count(int p_count) {
|
|
|
|
internal_vertices = p_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Polygon2D::get_internal_vertex_count() const {
|
|
|
|
return internal_vertices;
|
|
|
|
}
|
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
void Polygon2D::set_uv(const Vector<Vector2> &p_uv) {
|
2014-07-07 22:44:21 +02:00
|
|
|
uv = p_uv;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2014-07-07 22:44:21 +02:00
|
|
|
}
|
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<Vector2> Polygon2D::get_uv() const {
|
2014-07-07 22:44:21 +02:00
|
|
|
return uv;
|
|
|
|
}
|
|
|
|
|
2019-01-08 23:10:24 +01:00
|
|
|
void Polygon2D::set_polygons(const Array &p_polygons) {
|
|
|
|
polygons = p_polygons;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2018-02-25 16:06:30 +01:00
|
|
|
}
|
|
|
|
|
2019-01-08 23:10:24 +01:00
|
|
|
Array Polygon2D::get_polygons() const {
|
|
|
|
return polygons;
|
2018-02-25 16:06:30 +01:00
|
|
|
}
|
|
|
|
|
2014-07-07 22:44:21 +02:00
|
|
|
void Polygon2D::set_color(const Color &p_color) {
|
|
|
|
color = p_color;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2014-07-07 22:44:21 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2014-07-07 22:44:21 +02:00
|
|
|
Color Polygon2D::get_color() const {
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
void Polygon2D::set_vertex_colors(const Vector<Color> &p_colors) {
|
2016-05-23 03:40:45 +02:00
|
|
|
vertex_colors = p_colors;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2016-05-23 03:40:45 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<Color> Polygon2D::get_vertex_colors() const {
|
2016-05-23 03:40:45 +02:00
|
|
|
return vertex_colors;
|
|
|
|
}
|
|
|
|
|
2019-06-11 20:43:37 +02:00
|
|
|
void Polygon2D::set_texture(const Ref<Texture2D> &p_texture) {
|
2014-07-07 22:44:21 +02:00
|
|
|
texture = p_texture;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2014-07-07 22:44:21 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-06-11 20:43:37 +02:00
|
|
|
Ref<Texture2D> Polygon2D::get_texture() const {
|
2014-07-07 22:44:21 +02:00
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Polygon2D::set_texture_offset(const Vector2 &p_offset) {
|
|
|
|
tex_ofs = p_offset;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2014-07-07 22:44:21 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2014-07-07 22:44:21 +02:00
|
|
|
Vector2 Polygon2D::get_texture_offset() const {
|
|
|
|
return tex_ofs;
|
|
|
|
}
|
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
void Polygon2D::set_texture_rotation(real_t p_rot) {
|
2014-07-07 22:44:21 +02:00
|
|
|
tex_rot = p_rot;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2014-07-07 22:44:21 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
real_t Polygon2D::get_texture_rotation() const {
|
2014-07-07 22:44:21 +02:00
|
|
|
return tex_rot;
|
|
|
|
}
|
|
|
|
|
2016-09-20 06:36:24 +02:00
|
|
|
void Polygon2D::set_texture_scale(const Size2 &p_scale) {
|
2014-07-07 22:44:21 +02:00
|
|
|
tex_scale = p_scale;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2014-07-07 22:44:21 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2016-09-20 06:36:24 +02:00
|
|
|
Size2 Polygon2D::get_texture_scale() const {
|
2014-07-07 22:44:21 +02:00
|
|
|
return tex_scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Polygon2D::set_invert(bool p_invert) {
|
|
|
|
invert = p_invert;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2020-02-14 03:34:59 +01:00
|
|
|
notify_property_list_changed();
|
2014-07-07 22:44:21 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2014-07-07 22:44:21 +02:00
|
|
|
bool Polygon2D::get_invert() const {
|
|
|
|
return invert;
|
|
|
|
}
|
|
|
|
|
2017-08-19 18:14:04 +02:00
|
|
|
void Polygon2D::set_antialiased(bool p_antialiased) {
|
|
|
|
antialiased = p_antialiased;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2017-08-19 18:14:04 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-08-19 18:14:04 +02:00
|
|
|
bool Polygon2D::get_antialiased() const {
|
|
|
|
return antialiased;
|
|
|
|
}
|
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
void Polygon2D::set_invert_border(real_t p_invert_border) {
|
2014-07-07 22:44:21 +02:00
|
|
|
invert_border = p_invert_border;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2014-07-07 22:44:21 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
real_t Polygon2D::get_invert_border() const {
|
2014-07-07 22:44:21 +02:00
|
|
|
return invert_border;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Polygon2D::set_offset(const Vector2 &p_offset) {
|
|
|
|
offset = p_offset;
|
|
|
|
rect_cache_dirty = true;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2014-07-07 22:44:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector2 Polygon2D::get_offset() const {
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
void Polygon2D::add_bone(const NodePath &p_path, const Vector<float> &p_weights) {
|
2018-05-02 16:00:35 +02:00
|
|
|
Bone bone;
|
|
|
|
bone.path = p_path;
|
|
|
|
bone.weights = p_weights;
|
|
|
|
bone_weights.push_back(bone);
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2018-05-02 16:00:35 +02:00
|
|
|
int Polygon2D::get_bone_count() const {
|
|
|
|
return bone_weights.size();
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2018-05-02 16:00:35 +02:00
|
|
|
NodePath Polygon2D::get_bone_path(int p_index) const {
|
|
|
|
ERR_FAIL_INDEX_V(p_index, bone_weights.size(), NodePath());
|
|
|
|
return bone_weights[p_index].path;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<float> Polygon2D::get_bone_weights(int p_index) const {
|
|
|
|
ERR_FAIL_INDEX_V(p_index, bone_weights.size(), Vector<float>());
|
2018-05-02 16:00:35 +02:00
|
|
|
return bone_weights[p_index].weights;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2018-05-02 16:00:35 +02:00
|
|
|
void Polygon2D::erase_bone(int p_idx) {
|
|
|
|
ERR_FAIL_INDEX(p_idx, bone_weights.size());
|
2021-07-04 00:17:03 +02:00
|
|
|
bone_weights.remove_at(p_idx);
|
2018-05-02 16:00:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Polygon2D::clear_bones() {
|
|
|
|
bone_weights.clear();
|
|
|
|
}
|
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
void Polygon2D::set_bone_weights(int p_index, const Vector<float> &p_weights) {
|
2018-05-02 16:00:35 +02:00
|
|
|
ERR_FAIL_INDEX(p_index, bone_weights.size());
|
2018-07-25 03:11:03 +02:00
|
|
|
bone_weights.write[p_index].weights = p_weights;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2018-05-02 16:00:35 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2018-05-02 16:00:35 +02:00
|
|
|
void Polygon2D::set_bone_path(int p_index, const NodePath &p_path) {
|
|
|
|
ERR_FAIL_INDEX(p_index, bone_weights.size());
|
2018-07-25 03:11:03 +02:00
|
|
|
bone_weights.write[p_index].path = p_path;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2018-05-02 16:00:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Array Polygon2D::_get_bones() const {
|
|
|
|
Array bones;
|
|
|
|
for (int i = 0; i < get_bone_count(); i++) {
|
2021-11-02 23:52:40 +01:00
|
|
|
// Convert path property to String to avoid errors due to invalid node path in editor,
|
|
|
|
// because it's relative to the Skeleton2D node and not Polygon2D.
|
|
|
|
bones.push_back(String(get_bone_path(i)));
|
2018-05-02 16:00:35 +02:00
|
|
|
bones.push_back(get_bone_weights(i));
|
|
|
|
}
|
|
|
|
return bones;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2018-05-02 16:00:35 +02:00
|
|
|
void Polygon2D::_set_bones(const Array &p_bones) {
|
|
|
|
ERR_FAIL_COND(p_bones.size() & 1);
|
|
|
|
clear_bones();
|
|
|
|
for (int i = 0; i < p_bones.size(); i += 2) {
|
2021-11-02 23:52:40 +01:00
|
|
|
// Convert back from String to NodePath.
|
|
|
|
add_bone(NodePath(p_bones[i]), p_bones[i + 1]);
|
2018-05-02 16:00:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Polygon2D::set_skeleton(const NodePath &p_skeleton) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (skeleton == p_skeleton) {
|
2018-05-03 22:29:15 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-05-02 16:00:35 +02:00
|
|
|
skeleton = p_skeleton;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2018-05-02 16:00:35 +02:00
|
|
|
}
|
2018-05-03 22:29:15 +02:00
|
|
|
|
2018-05-02 16:00:35 +02:00
|
|
|
NodePath Polygon2D::get_skeleton() const {
|
|
|
|
return skeleton;
|
|
|
|
}
|
|
|
|
|
2014-07-07 22:44:21 +02:00
|
|
|
void Polygon2D::_bind_methods() {
|
2017-02-13 12:47:24 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_polygon", "polygon"), &Polygon2D::set_polygon);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_polygon"), &Polygon2D::get_polygon);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
2017-02-13 12:47:24 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_uv", "uv"), &Polygon2D::set_uv);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_uv"), &Polygon2D::get_uv);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
2017-02-13 12:47:24 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_color", "color"), &Polygon2D::set_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_color"), &Polygon2D::get_color);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
2019-01-08 23:10:24 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_polygons", "polygons"), &Polygon2D::set_polygons);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_polygons"), &Polygon2D::get_polygons);
|
2018-02-25 16:06:30 +01:00
|
|
|
|
2017-02-13 12:47:24 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_vertex_colors", "vertex_colors"), &Polygon2D::set_vertex_colors);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_vertex_colors"), &Polygon2D::get_vertex_colors);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
2017-08-09 13:19:41 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_texture", "texture"), &Polygon2D::set_texture);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_texture"), &Polygon2D::get_texture);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
2017-02-13 12:47:24 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_texture_offset", "texture_offset"), &Polygon2D::set_texture_offset);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_texture_offset"), &Polygon2D::get_texture_offset);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
2017-02-13 12:47:24 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_texture_rotation", "texture_rotation"), &Polygon2D::set_texture_rotation);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_texture_rotation"), &Polygon2D::get_texture_rotation);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
2017-02-13 12:47:24 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_texture_scale", "texture_scale"), &Polygon2D::set_texture_scale);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_texture_scale"), &Polygon2D::get_texture_scale);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
2022-08-24 12:50:44 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_invert_enabled", "invert"), &Polygon2D::set_invert);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_invert_enabled"), &Polygon2D::get_invert);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
2017-08-19 18:14:04 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_antialiased", "antialiased"), &Polygon2D::set_antialiased);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_antialiased"), &Polygon2D::get_antialiased);
|
|
|
|
|
2017-02-13 12:47:24 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_invert_border", "invert_border"), &Polygon2D::set_invert_border);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_invert_border"), &Polygon2D::get_invert_border);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
2017-02-12 01:11:37 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_offset", "offset"), &Polygon2D::set_offset);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_offset"), &Polygon2D::get_offset);
|
2017-01-04 05:16:14 +01:00
|
|
|
|
2018-05-02 16:00:35 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("add_bone", "path", "weights"), &Polygon2D::add_bone);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bone_count"), &Polygon2D::get_bone_count);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bone_path", "index"), &Polygon2D::get_bone_path);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bone_weights", "index"), &Polygon2D::get_bone_weights);
|
|
|
|
ClassDB::bind_method(D_METHOD("erase_bone", "index"), &Polygon2D::erase_bone);
|
|
|
|
ClassDB::bind_method(D_METHOD("clear_bones"), &Polygon2D::clear_bones);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_bone_path", "index", "path"), &Polygon2D::set_bone_path);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_bone_weights", "index", "weights"), &Polygon2D::set_bone_weights);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_skeleton", "skeleton"), &Polygon2D::set_skeleton);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_skeleton"), &Polygon2D::get_skeleton);
|
|
|
|
|
2019-01-08 23:10:24 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_internal_vertex_count", "internal_vertex_count"), &Polygon2D::set_internal_vertex_count);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_internal_vertex_count"), &Polygon2D::get_internal_vertex_count);
|
|
|
|
|
2018-05-02 16:00:35 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("_set_bones", "bones"), &Polygon2D::_set_bones);
|
|
|
|
ClassDB::bind_method(D_METHOD("_get_bones"), &Polygon2D::_get_bones);
|
|
|
|
|
2017-02-12 01:11:37 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset");
|
2017-08-19 18:14:04 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "antialiased"), "set_antialiased", "get_antialiased");
|
2022-06-14 16:33:44 +02:00
|
|
|
|
|
|
|
ADD_GROUP("Texture", "texture_");
|
2019-06-11 20:43:37 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture");
|
2021-12-03 01:09:19 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "texture_offset", PROPERTY_HINT_NONE, "suffix:px"), "set_texture_offset", "get_texture_offset");
|
2022-06-14 16:33:44 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "texture_scale", PROPERTY_HINT_LINK), "set_texture_scale", "get_texture_scale");
|
2022-03-27 19:16:03 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "texture_rotation", PROPERTY_HINT_RANGE, "-360,360,0.1,or_less,or_greater,radians"), "set_texture_rotation", "get_texture_rotation");
|
2022-06-14 16:33:44 +02:00
|
|
|
|
2018-05-02 16:00:35 +02:00
|
|
|
ADD_GROUP("Skeleton", "");
|
2018-06-28 01:50:25 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "skeleton", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Skeleton2D"), "set_skeleton", "get_skeleton");
|
2014-07-07 22:44:21 +02:00
|
|
|
|
2017-02-12 01:11:37 +01:00
|
|
|
ADD_GROUP("Invert", "invert_");
|
2022-08-24 12:50:44 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "invert_enabled"), "set_invert_enabled", "get_invert_enabled");
|
2022-05-20 07:24:41 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "invert_border", PROPERTY_HINT_RANGE, "0.1,16384,0.1,suffix:px"), "set_invert_border", "get_invert_border");
|
2018-05-02 16:00:35 +02:00
|
|
|
|
2019-01-08 23:10:24 +01:00
|
|
|
ADD_GROUP("Data", "");
|
2020-02-17 22:06:54 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR2_ARRAY, "polygon"), "set_polygon", "get_polygon");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR2_ARRAY, "uv"), "set_uv", "get_uv");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::PACKED_COLOR_ARRAY, "vertex_colors"), "set_vertex_colors", "get_vertex_colors");
|
2019-01-08 23:10:24 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "polygons"), "set_polygons", "get_polygons");
|
2022-01-11 05:17:42 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "bones", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "_set_bones", "_get_bones");
|
2019-01-08 23:10:24 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "internal_vertex_count", PROPERTY_HINT_RANGE, "0,1000"), "set_internal_vertex_count", "get_internal_vertex_count");
|
2014-07-07 22:44:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Polygon2D::Polygon2D() {
|
2021-05-10 18:12:44 +02:00
|
|
|
mesh = RS::get_singleton()->mesh_create();
|
|
|
|
}
|
|
|
|
|
|
|
|
Polygon2D::~Polygon2D() {
|
2022-11-25 02:34:25 +01:00
|
|
|
// This will free the internally-allocated mesh instance, if allocated.
|
2022-12-12 18:42:37 +01:00
|
|
|
ERR_FAIL_NULL(RenderingServer::get_singleton());
|
2022-11-25 02:34:25 +01:00
|
|
|
RS::get_singleton()->canvas_item_attach_skeleton(get_canvas_item(), RID());
|
2021-05-10 18:12:44 +02:00
|
|
|
RS::get_singleton()->free(mesh);
|
2014-07-07 22:44:21 +02:00
|
|
|
}
|