summaryrefslogtreecommitdiff
path: root/scene/2d/polygon_2d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d/polygon_2d.cpp')
-rw-r--r--scene/2d/polygon_2d.cpp195
1 files changed, 4 insertions, 191 deletions
diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp
index 9fe67a4d7e..a6da027e0a 100644
--- a/scene/2d/polygon_2d.cpp
+++ b/scene/2d/polygon_2d.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -33,6 +33,7 @@
#include "core/math/geometry.h"
#include "skeleton_2d.h"
+#ifdef TOOLS_ENABLED
Dictionary Polygon2D::_edit_get_state() const {
Dictionary state = Node2D::_edit_get_state();
state["offset"] = offset;
@@ -87,6 +88,7 @@ bool Polygon2D::_edit_is_selected_on_click(const Point2 &p_point, double p_toler
}
return Geometry::is_point_in_polygon(p_point - get_offset(), polygon2d);
}
+#endif
void Polygon2D::_skeleton_bone_setup_changed() {
update();
@@ -344,195 +346,6 @@ void Polygon2D::_notification(int p_what) {
if (total_indices.size()) {
VS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), total_indices, points, colors, uvs, bones, weights, texture.is_valid() ? texture->get_rid() : RID(), -1, RID(), antialiased);
}
-
-#if 0
- //use splits
- Vector<int> loop;
- int sc = splits.size();
- PoolVector<int>::Read r = splits.read();
-
-
- print_line("has splits, amount " + itos(splits.size()));
- Vector<Vector<int> > loops;
-
- // find a point that can be used to begin, must not be in a split, and have to the left and right the same one
- // like this one -> x---o
- // \ / \ .
- // o---o
- int base_point = -1;
- {
- int current_point = -1;
- int base_point_prev_split = -1;
-
-
- for (int i = 0; i < points.size(); i++) {
-
- //find if this point is in a split
- int split_index = -1;
- bool has_prev_split = false;
- int min_dist_to_end = 0x7FFFFFFF;
-
- for (int j = 0; j < sc; j += 2) {
-
- int split_pos = -1;
- int split_end = -1;
-
- if (r[j + 0] == i) { //found split in first point
- split_pos = r[j + 0];
- split_end = r[j + 1];
- } else if (r[j + 1] == i) { //found split in second point
- split_pos = r[j + 1];
- split_end = r[j + 0];
- }
-
- if (split_pos == split_end) {
- continue; //either nothing found or begin == end, this not a split in either case
- }
-
- if (j == base_point_prev_split) {
- has_prev_split = true;
- }
-
- //compute distance from split pos to split end in current traversal direction
- int dist_to_end = split_end > split_pos ? split_end - split_pos : (last - split_pos + split_end);
-
- if (dist_to_end < min_dist_to_end) {
- //always keep the valid split with the least distance to the loop
- min_dist_to_end = dist_to_end;
- split_index = j;
- }
- }
-
- if (split_index == -1) {
- current_point = i; //no split here, we are testing this point
- } else if (has_prev_split) {
- base_point = current_point; // there is a split and it contains the previous visited split, success
- break;
- } else {
- //invalidate current point and keep split
- current_point = -1;
- base_point_prev_split = split_index;
- }
- }
- }
-
- print_line("found base point: " + itos(base_point));
-
- if (base_point != -1) {
-
- int point = base_point;
- int last = base_point;
- //go through all the points, find splits
- do {
-
- int split;
- int last_dist_to_end = -1; //maximum valid distance to end
-
- do {
-
- loop.push_back(point); //push current point
-
- split = -1;
- int end = -1;
-
- int max_dist_to_end = 0;
-
- //find if this point is in a split
- for (int j = 0; j < sc; j += 2) {
-
- int split_pos = -1;
- int split_end = -1;
-
- if (r[j + 0] == point) { //match first split index
- split_pos = r[j + 0];
- split_end = r[j + 1];
- } else if (r[j + 1] == point) { //match second split index
- split_pos = r[j + 1];
- split_end = r[j + 0];
- }
-
- if (split_pos == split_end) {
- continue; //either nothing found or begin == end, this not a split in either case
- }
-
- //compute distance from split pos to split end
- int dist_to_end = split_end > split_pos ? split_end - split_pos : (points.size() - split_pos + split_end);
-
- if (last_dist_to_end != -1 && dist_to_end >= last_dist_to_end) {
- //distance must be shorter than in last iteration, means we've tested this before so ignore
- continue;
- } else if (dist_to_end > max_dist_to_end) {
- //always keep the valid point with the most distance (as long as it's valid)
- max_dist_to_end = dist_to_end;
- split = split_pos;
- end = split_end;
- }
- }
-
- if (split != -1) {
- //found a split!
- int from = end;
-
- //add points until last is reached
- while (true) {
- //find if point is in a split
- loop.push_back(from);
-
- if (from == last) {
- break;
- }
-
- from++;
- if (from >= points.size()) { //wrap if reached end
- from = 0;
- }
-
- if (from == loop[0]) {
- break; //end because we reached split source
- }
- }
-
- loops.push_back(loop); //done with this loop
- loop.clear();
-
- last_dist_to_end = max_dist_to_end;
- last = end; //algorithm can safely finish in this split point
- }
-
- } while (split != -1);
-
- } while (point != last);
- }
-
- if (loop.size() >=2 ) { //points remained
- //points remain
- loop.push_back(last); //no splits found, use last
- loops.push_back(loop);
- }
-
- print_line("total loops: " + itos(loops.size()));
-
- if (loops.size()) { //loops found
- Vector<int> indices;
-
- for (int i = 0; i < loops.size(); i++) {
- Vector<int> loop = loops[i];
- Vector<Vector2> vertices;
- vertices.resize(loop.size());
- for (int j = 0; j < vertices.size(); j++) {
- vertices.write[j] = points[loop[j]];
- }
- Vector<int> sub_indices = Geometry::triangulate_polygon(vertices);
- int from = indices.size();
- indices.resize(from + sub_indices.size());
- for (int j = 0; j < sub_indices.size(); j++) {
- indices.write[from + j] = loop[sub_indices[j]];
- }
- }
-
- VS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), indices, points, colors, uvs, bones, weights, texture.is_valid() ? texture->get_rid() : RID());
- }
-#endif
}
} break;