|
@@ -52,6 +52,14 @@ Vector2 Polygon2DEditor::_get_offset(int p_idx) const {
|
|
return node->get_offset();
|
|
return node->get_offset();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+int Polygon2DEditor::_get_polygon_count() const {
|
|
|
|
+ if (node->get_internal_vertex_count() > 0) {
|
|
|
|
+ return 0; //do not edit if internal vertices exist
|
|
|
|
+ } else {
|
|
|
|
+ return 1;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
void Polygon2DEditor::_notification(int p_what) {
|
|
void Polygon2DEditor::_notification(int p_what) {
|
|
|
|
|
|
switch (p_what) {
|
|
switch (p_what) {
|
|
@@ -66,13 +74,15 @@ void Polygon2DEditor::_notification(int p_what) {
|
|
|
|
|
|
button_uv->set_icon(get_icon("Uv", "EditorIcons"));
|
|
button_uv->set_icon(get_icon("Uv", "EditorIcons"));
|
|
|
|
|
|
- uv_button[UV_MODE_CREATE]->set_icon(get_icon("Add", "EditorIcons"));
|
|
|
|
|
|
+ uv_button[UV_MODE_CREATE]->set_icon(get_icon("Edit", "EditorIcons"));
|
|
|
|
+ uv_button[UV_MODE_CREATE_INTERNAL]->set_icon(get_icon("EditInternal", "EditorIcons"));
|
|
|
|
+ uv_button[UV_MODE_REMOVE_INTERNAL]->set_icon(get_icon("RemoveInternal", "EditorIcons"));
|
|
uv_button[UV_MODE_EDIT_POINT]->set_icon(get_icon("ToolSelect", "EditorIcons"));
|
|
uv_button[UV_MODE_EDIT_POINT]->set_icon(get_icon("ToolSelect", "EditorIcons"));
|
|
uv_button[UV_MODE_MOVE]->set_icon(get_icon("ToolMove", "EditorIcons"));
|
|
uv_button[UV_MODE_MOVE]->set_icon(get_icon("ToolMove", "EditorIcons"));
|
|
uv_button[UV_MODE_ROTATE]->set_icon(get_icon("ToolRotate", "EditorIcons"));
|
|
uv_button[UV_MODE_ROTATE]->set_icon(get_icon("ToolRotate", "EditorIcons"));
|
|
uv_button[UV_MODE_SCALE]->set_icon(get_icon("ToolScale", "EditorIcons"));
|
|
uv_button[UV_MODE_SCALE]->set_icon(get_icon("ToolScale", "EditorIcons"));
|
|
- uv_button[UV_MODE_ADD_SPLIT]->set_icon(get_icon("AddSplit", "EditorIcons"));
|
|
|
|
- uv_button[UV_MODE_REMOVE_SPLIT]->set_icon(get_icon("DeleteSplit", "EditorIcons"));
|
|
|
|
|
|
+ uv_button[UV_MODE_ADD_POLYGON]->set_icon(get_icon("Edit", "EditorIcons"));
|
|
|
|
+ uv_button[UV_MODE_REMOVE_POLYGON]->set_icon(get_icon("Close", "EditorIcons"));
|
|
uv_button[UV_MODE_PAINT_WEIGHT]->set_icon(get_icon("PaintVertex", "EditorIcons"));
|
|
uv_button[UV_MODE_PAINT_WEIGHT]->set_icon(get_icon("PaintVertex", "EditorIcons"));
|
|
uv_button[UV_MODE_CLEAR_WEIGHT]->set_icon(get_icon("UnpaintVertex", "EditorIcons"));
|
|
uv_button[UV_MODE_CLEAR_WEIGHT]->set_icon(get_icon("UnpaintVertex", "EditorIcons"));
|
|
|
|
|
|
@@ -191,11 +201,13 @@ void Polygon2DEditor::_uv_edit_mode_select(int p_mode) {
|
|
if (p_mode == 0) { //uv
|
|
if (p_mode == 0) { //uv
|
|
|
|
|
|
uv_button[UV_MODE_CREATE]->hide();
|
|
uv_button[UV_MODE_CREATE]->hide();
|
|
|
|
+ uv_button[UV_MODE_CREATE_INTERNAL]->hide();
|
|
|
|
+ uv_button[UV_MODE_REMOVE_INTERNAL]->hide();
|
|
for (int i = UV_MODE_MOVE; i <= UV_MODE_SCALE; i++) {
|
|
for (int i = UV_MODE_MOVE; i <= UV_MODE_SCALE; i++) {
|
|
uv_button[i]->show();
|
|
uv_button[i]->show();
|
|
}
|
|
}
|
|
- uv_button[UV_MODE_ADD_SPLIT]->hide();
|
|
|
|
- uv_button[UV_MODE_REMOVE_SPLIT]->hide();
|
|
|
|
|
|
+ uv_button[UV_MODE_ADD_POLYGON]->hide();
|
|
|
|
+ uv_button[UV_MODE_REMOVE_POLYGON]->hide();
|
|
uv_button[UV_MODE_PAINT_WEIGHT]->hide();
|
|
uv_button[UV_MODE_PAINT_WEIGHT]->hide();
|
|
uv_button[UV_MODE_CLEAR_WEIGHT]->hide();
|
|
uv_button[UV_MODE_CLEAR_WEIGHT]->hide();
|
|
_uv_mode(UV_MODE_EDIT_POINT);
|
|
_uv_mode(UV_MODE_EDIT_POINT);
|
|
@@ -209,8 +221,8 @@ void Polygon2DEditor::_uv_edit_mode_select(int p_mode) {
|
|
for (int i = 0; i <= UV_MODE_SCALE; i++) {
|
|
for (int i = 0; i <= UV_MODE_SCALE; i++) {
|
|
uv_button[i]->show();
|
|
uv_button[i]->show();
|
|
}
|
|
}
|
|
- uv_button[UV_MODE_ADD_SPLIT]->hide();
|
|
|
|
- uv_button[UV_MODE_REMOVE_SPLIT]->hide();
|
|
|
|
|
|
+ uv_button[UV_MODE_ADD_POLYGON]->hide();
|
|
|
|
+ uv_button[UV_MODE_REMOVE_POLYGON]->hide();
|
|
uv_button[UV_MODE_PAINT_WEIGHT]->hide();
|
|
uv_button[UV_MODE_PAINT_WEIGHT]->hide();
|
|
uv_button[UV_MODE_CLEAR_WEIGHT]->hide();
|
|
uv_button[UV_MODE_CLEAR_WEIGHT]->hide();
|
|
_uv_mode(UV_MODE_EDIT_POINT);
|
|
_uv_mode(UV_MODE_EDIT_POINT);
|
|
@@ -224,11 +236,11 @@ void Polygon2DEditor::_uv_edit_mode_select(int p_mode) {
|
|
for (int i = 0; i <= UV_MODE_SCALE; i++) {
|
|
for (int i = 0; i <= UV_MODE_SCALE; i++) {
|
|
uv_button[i]->hide();
|
|
uv_button[i]->hide();
|
|
}
|
|
}
|
|
- uv_button[UV_MODE_ADD_SPLIT]->show();
|
|
|
|
- uv_button[UV_MODE_REMOVE_SPLIT]->show();
|
|
|
|
|
|
+ uv_button[UV_MODE_ADD_POLYGON]->show();
|
|
|
|
+ uv_button[UV_MODE_REMOVE_POLYGON]->show();
|
|
uv_button[UV_MODE_PAINT_WEIGHT]->hide();
|
|
uv_button[UV_MODE_PAINT_WEIGHT]->hide();
|
|
uv_button[UV_MODE_CLEAR_WEIGHT]->hide();
|
|
uv_button[UV_MODE_CLEAR_WEIGHT]->hide();
|
|
- _uv_mode(UV_MODE_ADD_SPLIT);
|
|
|
|
|
|
+ _uv_mode(UV_MODE_ADD_POLYGON);
|
|
|
|
|
|
bone_scroll_main_vb->hide();
|
|
bone_scroll_main_vb->hide();
|
|
bone_paint_strength->hide();
|
|
bone_paint_strength->hide();
|
|
@@ -236,7 +248,7 @@ void Polygon2DEditor::_uv_edit_mode_select(int p_mode) {
|
|
bone_paint_radius_label->hide();
|
|
bone_paint_radius_label->hide();
|
|
} else if (p_mode == 3) { //bones´
|
|
} else if (p_mode == 3) { //bones´
|
|
|
|
|
|
- for (int i = 0; i <= UV_MODE_REMOVE_SPLIT; i++) {
|
|
|
|
|
|
+ for (int i = 0; i <= UV_MODE_REMOVE_POLYGON; i++) {
|
|
uv_button[i]->hide();
|
|
uv_button[i]->hide();
|
|
}
|
|
}
|
|
uv_button[UV_MODE_PAINT_WEIGHT]->show();
|
|
uv_button[UV_MODE_PAINT_WEIGHT]->show();
|
|
@@ -290,6 +302,7 @@ void Polygon2DEditor::_menu_option(int p_option) {
|
|
uv_edit->popup(EditorSettings::get_singleton()->get("interface/dialogs/uv_editor_bounds"));
|
|
uv_edit->popup(EditorSettings::get_singleton()->get("interface/dialogs/uv_editor_bounds"));
|
|
else
|
|
else
|
|
uv_edit->popup_centered_ratio(0.85);
|
|
uv_edit->popup_centered_ratio(0.85);
|
|
|
|
+ _update_bone_list();
|
|
} break;
|
|
} break;
|
|
case UVEDIT_POLYGON_TO_UV: {
|
|
case UVEDIT_POLYGON_TO_UV: {
|
|
|
|
|
|
@@ -348,8 +361,10 @@ void Polygon2DEditor::_cancel_editing() {
|
|
uv_create = false;
|
|
uv_create = false;
|
|
node->set_uv(uv_create_uv_prev);
|
|
node->set_uv(uv_create_uv_prev);
|
|
node->set_polygon(uv_create_poly_prev);
|
|
node->set_polygon(uv_create_poly_prev);
|
|
|
|
+ node->set_internal_vertex_count(uv_create_prev_internal_vertices);
|
|
|
|
+ node->set_vertex_colors(uv_create_colors_prev);
|
|
node->call("_set_bones", uv_create_bones_prev);
|
|
node->call("_set_bones", uv_create_bones_prev);
|
|
- node->set_splits(splits_prev);
|
|
|
|
|
|
+ node->set_polygons(polygons_prev);
|
|
} else if (uv_drag) {
|
|
} else if (uv_drag) {
|
|
uv_drag = false;
|
|
uv_drag = false;
|
|
if (uv_edit_mode[0]->is_pressed()) { // Edit UV.
|
|
if (uv_edit_mode[0]->is_pressed()) { // Edit UV.
|
|
@@ -357,9 +372,9 @@ void Polygon2DEditor::_cancel_editing() {
|
|
} else if (uv_edit_mode[1]->is_pressed()) { // Edit polygon.
|
|
} else if (uv_edit_mode[1]->is_pressed()) { // Edit polygon.
|
|
node->set_polygon(points_prev);
|
|
node->set_polygon(points_prev);
|
|
}
|
|
}
|
|
- } else if (split_create) {
|
|
|
|
- split_create = false;
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ polygon_create.clear();
|
|
}
|
|
}
|
|
|
|
|
|
void Polygon2DEditor::_commit_action() {
|
|
void Polygon2DEditor::_commit_action() {
|
|
@@ -409,7 +424,7 @@ void Polygon2DEditor::_set_snap_step_y(float p_val) {
|
|
|
|
|
|
void Polygon2DEditor::_uv_mode(int p_mode) {
|
|
void Polygon2DEditor::_uv_mode(int p_mode) {
|
|
|
|
|
|
- split_create = false;
|
|
|
|
|
|
+ polygon_create.clear();
|
|
uv_drag = false;
|
|
uv_drag = false;
|
|
uv_create = false;
|
|
uv_create = false;
|
|
|
|
|
|
@@ -461,8 +476,10 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
|
uv_create = true;
|
|
uv_create = true;
|
|
uv_create_uv_prev = node->get_uv();
|
|
uv_create_uv_prev = node->get_uv();
|
|
uv_create_poly_prev = node->get_polygon();
|
|
uv_create_poly_prev = node->get_polygon();
|
|
|
|
+ uv_create_prev_internal_vertices = node->get_internal_vertex_count();
|
|
|
|
+ uv_create_colors_prev = node->get_vertex_colors();
|
|
uv_create_bones_prev = node->call("_get_bones");
|
|
uv_create_bones_prev = node->call("_get_bones");
|
|
- splits_prev = node->get_splits();
|
|
|
|
|
|
+ polygons_prev = node->get_polygons();
|
|
node->set_polygon(points_prev);
|
|
node->set_polygon(points_prev);
|
|
node->set_uv(points_prev);
|
|
node->set_uv(points_prev);
|
|
|
|
|
|
@@ -477,6 +494,10 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
|
undo_redo->add_undo_method(node, "set_uv", uv_create_uv_prev);
|
|
undo_redo->add_undo_method(node, "set_uv", uv_create_uv_prev);
|
|
undo_redo->add_do_method(node, "set_polygon", node->get_polygon());
|
|
undo_redo->add_do_method(node, "set_polygon", node->get_polygon());
|
|
undo_redo->add_undo_method(node, "set_polygon", uv_create_poly_prev);
|
|
undo_redo->add_undo_method(node, "set_polygon", uv_create_poly_prev);
|
|
|
|
+ undo_redo->add_do_method(node, "set_internal_vertex_count", 0);
|
|
|
|
+ undo_redo->add_undo_method(node, "set_internal_vertex_count", uv_create_prev_internal_vertices);
|
|
|
|
+ undo_redo->add_do_method(node, "set_vertex_colors", Vector<Color>());
|
|
|
|
+ undo_redo->add_undo_method(node, "set_vertex_colors", uv_create_colors_prev);
|
|
undo_redo->add_do_method(node, "clear_bones");
|
|
undo_redo->add_do_method(node, "clear_bones");
|
|
undo_redo->add_undo_method(node, "_set_bones", uv_create_bones_prev);
|
|
undo_redo->add_undo_method(node, "_set_bones", uv_create_bones_prev);
|
|
undo_redo->add_do_method(uv_edit_draw, "update");
|
|
undo_redo->add_do_method(uv_edit_draw, "update");
|
|
@@ -499,6 +520,97 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
|
CanvasItemEditor::get_singleton()->update_viewport();
|
|
CanvasItemEditor::get_singleton()->update_viewport();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (uv_move_current == UV_MODE_CREATE_INTERNAL) {
|
|
|
|
+
|
|
|
|
+ uv_create_uv_prev = node->get_uv();
|
|
|
|
+ uv_create_poly_prev = node->get_polygon();
|
|
|
|
+ uv_create_colors_prev = node->get_vertex_colors();
|
|
|
|
+ uv_create_bones_prev = node->call("_get_bones");
|
|
|
|
+ int internal_vertices = node->get_internal_vertex_count();
|
|
|
|
+
|
|
|
|
+ Vector2 pos = mtx.affine_inverse().xform(snap_point(Vector2(mb->get_position().x, mb->get_position().y)));
|
|
|
|
+
|
|
|
|
+ uv_create_poly_prev.push_back(pos);
|
|
|
|
+ uv_create_uv_prev.push_back(pos);
|
|
|
|
+ if (uv_create_colors_prev.size()) {
|
|
|
|
+ uv_create_colors_prev.push_back(Color(1, 1, 1));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ undo_redo->create_action(TTR("Create Internal Vertex"));
|
|
|
|
+ undo_redo->add_do_method(node, "set_uv", uv_create_uv_prev);
|
|
|
|
+ undo_redo->add_undo_method(node, "set_uv", node->get_uv());
|
|
|
|
+ undo_redo->add_do_method(node, "set_polygon", uv_create_poly_prev);
|
|
|
|
+ undo_redo->add_undo_method(node, "set_polygon", node->get_polygon());
|
|
|
|
+ undo_redo->add_do_method(node, "set_vertex_colors", uv_create_colors_prev);
|
|
|
|
+ undo_redo->add_undo_method(node, "set_vertex_colors", node->get_vertex_colors());
|
|
|
|
+ for (int i = 0; i < node->get_bone_count(); i++) {
|
|
|
|
+ PoolVector<float> bonew = node->get_bone_weights(i);
|
|
|
|
+ bonew.push_back(0);
|
|
|
|
+ undo_redo->add_do_method(node, "set_bone_weights", i, bonew);
|
|
|
|
+ undo_redo->add_undo_method(node, "set_bone_weights", i, node->get_bone_weights(i));
|
|
|
|
+ }
|
|
|
|
+ undo_redo->add_do_method(node, "set_internal_vertex_count", internal_vertices + 1);
|
|
|
|
+ undo_redo->add_undo_method(node, "set_internal_vertex_count", internal_vertices);
|
|
|
|
+
|
|
|
|
+ undo_redo->add_do_method(uv_edit_draw, "update");
|
|
|
|
+ undo_redo->add_undo_method(uv_edit_draw, "update");
|
|
|
|
+ undo_redo->commit_action();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (uv_move_current == UV_MODE_REMOVE_INTERNAL) {
|
|
|
|
+
|
|
|
|
+ uv_create_uv_prev = node->get_uv();
|
|
|
|
+ uv_create_poly_prev = node->get_polygon();
|
|
|
|
+ uv_create_colors_prev = node->get_vertex_colors();
|
|
|
|
+ uv_create_bones_prev = node->call("_get_bones");
|
|
|
|
+ int internal_vertices = node->get_internal_vertex_count();
|
|
|
|
+
|
|
|
|
+ if (internal_vertices <= 0)
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ int closest = -1;
|
|
|
|
+ float closest_dist = 1e20;
|
|
|
|
+
|
|
|
|
+ for (int i = points_prev.size() - internal_vertices; i < points_prev.size(); i++) {
|
|
|
|
+
|
|
|
|
+ Vector2 tuv = mtx.xform(uv_create_poly_prev[i]);
|
|
|
|
+ float dist = tuv.distance_to(Vector2(mb->get_position().x, mb->get_position().y));
|
|
|
|
+ if (dist < 8 && dist < closest_dist) {
|
|
|
|
+ closest = i;
|
|
|
|
+ closest_dist = dist;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (closest == -1)
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ uv_create_poly_prev.remove(closest);
|
|
|
|
+ uv_create_uv_prev.remove(closest);
|
|
|
|
+ if (uv_create_colors_prev.size()) {
|
|
|
|
+ uv_create_colors_prev.remove(closest);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ undo_redo->create_action(TTR("Remove Internal Vertex"));
|
|
|
|
+ undo_redo->add_do_method(node, "set_uv", uv_create_uv_prev);
|
|
|
|
+ undo_redo->add_undo_method(node, "set_uv", node->get_uv());
|
|
|
|
+ undo_redo->add_do_method(node, "set_polygon", uv_create_poly_prev);
|
|
|
|
+ undo_redo->add_undo_method(node, "set_polygon", node->get_polygon());
|
|
|
|
+ undo_redo->add_do_method(node, "set_vertex_colors", uv_create_colors_prev);
|
|
|
|
+ undo_redo->add_undo_method(node, "set_vertex_colors", node->get_vertex_colors());
|
|
|
|
+ for (int i = 0; i < node->get_bone_count(); i++) {
|
|
|
|
+ PoolVector<float> bonew = node->get_bone_weights(i);
|
|
|
|
+ bonew.remove(closest);
|
|
|
|
+ undo_redo->add_do_method(node, "set_bone_weights", i, bonew);
|
|
|
|
+ undo_redo->add_undo_method(node, "set_bone_weights", i, node->get_bone_weights(i));
|
|
|
|
+ }
|
|
|
|
+ undo_redo->add_do_method(node, "set_internal_vertex_count", internal_vertices - 1);
|
|
|
|
+ undo_redo->add_undo_method(node, "set_internal_vertex_count", internal_vertices);
|
|
|
|
+
|
|
|
|
+ undo_redo->add_do_method(uv_edit_draw, "update");
|
|
|
|
+ undo_redo->add_undo_method(uv_edit_draw, "update");
|
|
|
|
+ undo_redo->commit_action();
|
|
|
|
+ }
|
|
|
|
+
|
|
if (uv_move_current == UV_MODE_EDIT_POINT) {
|
|
if (uv_move_current == UV_MODE_EDIT_POINT) {
|
|
|
|
|
|
if (mb->get_shift() && mb->get_command())
|
|
if (mb->get_shift() && mb->get_command())
|
|
@@ -526,129 +638,80 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (uv_move_current == UV_MODE_ADD_SPLIT) {
|
|
|
|
|
|
+ if (uv_move_current == UV_MODE_ADD_POLYGON) {
|
|
|
|
+
|
|
|
|
+ int closest = -1;
|
|
|
|
+ float closest_dist = 1e20;
|
|
|
|
|
|
- int split_to_index = -1;
|
|
|
|
- split_to_index = -1;
|
|
|
|
for (int i = 0; i < points_prev.size(); i++) {
|
|
for (int i = 0; i < points_prev.size(); i++) {
|
|
|
|
|
|
Vector2 tuv = mtx.xform(points_prev[i]);
|
|
Vector2 tuv = mtx.xform(points_prev[i]);
|
|
- if (tuv.distance_to(Vector2(mb->get_position().x, mb->get_position().y)) < 8) {
|
|
|
|
- split_to_index = i;
|
|
|
|
|
|
+ float dist = tuv.distance_to(Vector2(mb->get_position().x, mb->get_position().y));
|
|
|
|
+ if (dist < 8 && dist < closest_dist) {
|
|
|
|
+ closest = i;
|
|
|
|
+ closest_dist = dist;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (split_to_index == -1) {
|
|
|
|
- split_create = false;
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (split_create) {
|
|
|
|
-
|
|
|
|
- split_create = false;
|
|
|
|
- if (split_to_index < point_drag_index) {
|
|
|
|
- SWAP(split_to_index, point_drag_index);
|
|
|
|
- }
|
|
|
|
- bool valid = true;
|
|
|
|
- String split_error;
|
|
|
|
- if (split_to_index == point_drag_index) {
|
|
|
|
- split_error = TTR("Split point with itself.");
|
|
|
|
- valid = false;
|
|
|
|
- }
|
|
|
|
- if (split_to_index + 1 == point_drag_index) {
|
|
|
|
- //not a split,goes along the edge
|
|
|
|
- split_error = TTR("Split can't form an existing edge.");
|
|
|
|
- valid = false;
|
|
|
|
- }
|
|
|
|
- if (split_to_index == points_prev.size() - 1 && point_drag_index == 0) {
|
|
|
|
- //not a split,goes along the edge
|
|
|
|
- split_error = TTR("Split can't form an existing edge.");
|
|
|
|
- valid = false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for (int i = 0; i < splits_prev.size(); i += 2) {
|
|
|
|
-
|
|
|
|
- if (splits_prev[i] == point_drag_index && splits_prev[i + 1] == split_to_index) {
|
|
|
|
- //already exists
|
|
|
|
- split_error = TTR("Split already exists.");
|
|
|
|
- valid = false;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- int a_state; //-1, outside split, 0 split point, +1, inside split
|
|
|
|
- if (point_drag_index == splits_prev[i] || point_drag_index == splits_prev[i + 1]) {
|
|
|
|
- a_state = 0;
|
|
|
|
- } else if (point_drag_index < splits_prev[i] || point_drag_index > splits_prev[i + 1]) {
|
|
|
|
- a_state = -1;
|
|
|
|
- } else {
|
|
|
|
- a_state = 1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- int b_state; //-1, outside split, 0 split point, +1, inside split
|
|
|
|
- if (split_to_index == splits_prev[i] || split_to_index == splits_prev[i + 1]) {
|
|
|
|
- b_state = 0;
|
|
|
|
- } else if (split_to_index < splits_prev[i] || split_to_index > splits_prev[i + 1]) {
|
|
|
|
- b_state = -1;
|
|
|
|
|
|
+ if (closest != -1) {
|
|
|
|
+ if (polygon_create.size() && closest == polygon_create[0]) {
|
|
|
|
+ //close
|
|
|
|
+ if (polygon_create.size() < 3) {
|
|
|
|
+ error->set_text(TTR("Invalid Polygon (need 3 different vertices)"));
|
|
|
|
+ error->popup_centered_minsize();
|
|
} else {
|
|
} else {
|
|
- b_state = 1;
|
|
|
|
|
|
+ Array polygons = node->get_polygons();
|
|
|
|
+ polygons = polygons.duplicate(); //copy because its a reference
|
|
|
|
+
|
|
|
|
+ //todo, could check whether it already exists?
|
|
|
|
+ polygons.push_back(polygon_create);
|
|
|
|
+ undo_redo->create_action(TTR("Add Polygon"));
|
|
|
|
+ undo_redo->add_do_method(node, "set_polygons", polygons);
|
|
|
|
+ undo_redo->add_undo_method(node, "set_polygons", polygons_prev);
|
|
|
|
+ undo_redo->add_do_method(uv_edit_draw, "update");
|
|
|
|
+ undo_redo->add_undo_method(uv_edit_draw, "update");
|
|
|
|
+ undo_redo->commit_action();
|
|
}
|
|
}
|
|
|
|
|
|
- if (b_state * a_state < 0) {
|
|
|
|
- //crossing
|
|
|
|
- split_error = "Split crosses another split.";
|
|
|
|
- valid = false;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
|
|
+ polygon_create.clear();
|
|
|
|
+ } else if (polygon_create.find(closest) == -1) {
|
|
|
|
+ //add temporarily if not exists
|
|
|
|
+ polygon_create.push_back(closest);
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (valid) {
|
|
|
|
-
|
|
|
|
- splits_prev.push_back(point_drag_index);
|
|
|
|
- splits_prev.push_back(split_to_index);
|
|
|
|
-
|
|
|
|
- undo_redo->create_action(TTR("Add Split"));
|
|
|
|
- undo_redo->add_do_method(node, "set_splits", splits_prev);
|
|
|
|
- undo_redo->add_undo_method(node, "set_splits", node->get_splits());
|
|
|
|
- undo_redo->add_do_method(uv_edit_draw, "update");
|
|
|
|
- undo_redo->add_undo_method(uv_edit_draw, "update");
|
|
|
|
- undo_redo->commit_action();
|
|
|
|
- } else {
|
|
|
|
- error->set_text(TTR("Invalid Split: ") + split_error);
|
|
|
|
- error->popup_centered_minsize();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
- point_drag_index = split_to_index;
|
|
|
|
- split_create = true;
|
|
|
|
- splits_prev = node->get_splits();
|
|
|
|
- uv_create_to = mtx.affine_inverse().xform(Vector2(mb->get_position().x, mb->get_position().y));
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (uv_move_current == UV_MODE_REMOVE_SPLIT) {
|
|
|
|
|
|
+ if (uv_move_current == UV_MODE_REMOVE_POLYGON) {
|
|
|
|
+ Array polygons = node->get_polygons();
|
|
|
|
+ polygons = polygons.duplicate(); //copy because its a reference
|
|
|
|
+
|
|
|
|
+ int erase_index = -1;
|
|
|
|
+ for (int i = polygons.size() - 1; i >= 0; i--) {
|
|
|
|
+ PoolVector<int> points = polygons[i];
|
|
|
|
+ Vector<Vector2> polys;
|
|
|
|
+ polys.resize(points.size());
|
|
|
|
+ for (int j = 0; j < polys.size(); j++) {
|
|
|
|
+ int idx = points[j];
|
|
|
|
+ if (idx < 0 || idx >= points_prev.size())
|
|
|
|
+ continue;
|
|
|
|
+ polys.write[j] = mtx.xform(points_prev[idx]);
|
|
|
|
+ }
|
|
|
|
|
|
- splits_prev = node->get_splits();
|
|
|
|
- for (int i = 0; i < splits_prev.size(); i += 2) {
|
|
|
|
- if (splits_prev[i] < 0 || splits_prev[i] >= points_prev.size())
|
|
|
|
- continue;
|
|
|
|
- if (splits_prev[i + 1] < 0 || splits_prev[i] >= points_prev.size())
|
|
|
|
- continue;
|
|
|
|
- Vector2 e[2] = { mtx.xform(points_prev[splits_prev[i]]), mtx.xform(points_prev[splits_prev[i + 1]]) };
|
|
|
|
- Vector2 mp = Vector2(mb->get_position().x, mb->get_position().y);
|
|
|
|
- Vector2 cp = Geometry::get_closest_point_to_segment_2d(mp, e);
|
|
|
|
- if (cp.distance_to(mp) < 8) {
|
|
|
|
- splits_prev.remove(i);
|
|
|
|
- splits_prev.remove(i);
|
|
|
|
-
|
|
|
|
- undo_redo->create_action(TTR("Remove Split"));
|
|
|
|
- undo_redo->add_do_method(node, "set_splits", splits_prev);
|
|
|
|
- undo_redo->add_undo_method(node, "set_splits", node->get_splits());
|
|
|
|
- undo_redo->add_do_method(uv_edit_draw, "update");
|
|
|
|
- undo_redo->add_undo_method(uv_edit_draw, "update");
|
|
|
|
- undo_redo->commit_action();
|
|
|
|
|
|
+ if (Geometry::is_point_in_polygon(Vector2(mb->get_position().x, mb->get_position().y), polys)) {
|
|
|
|
+ erase_index = i;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (erase_index != -1) {
|
|
|
|
+ polygons.remove(erase_index);
|
|
|
|
+ undo_redo->create_action(TTR("Remove Polygon"));
|
|
|
|
+ undo_redo->add_do_method(node, "set_polygons", polygons);
|
|
|
|
+ undo_redo->add_undo_method(node, "set_polygons", polygons_prev);
|
|
|
|
+ undo_redo->add_do_method(uv_edit_draw, "update");
|
|
|
|
+ undo_redo->add_undo_method(uv_edit_draw, "update");
|
|
|
|
+ undo_redo->commit_action();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
if (uv_move_current == UV_MODE_PAINT_WEIGHT || uv_move_current == UV_MODE_CLEAR_WEIGHT) {
|
|
if (uv_move_current == UV_MODE_PAINT_WEIGHT || uv_move_current == UV_MODE_CLEAR_WEIGHT) {
|
|
@@ -849,7 +912,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
|
|
|
|
|
uv_edit_draw->update();
|
|
uv_edit_draw->update();
|
|
CanvasItemEditor::get_singleton()->update_viewport();
|
|
CanvasItemEditor::get_singleton()->update_viewport();
|
|
- } else if (split_create) {
|
|
|
|
|
|
+ } else if (polygon_create.size()) {
|
|
uv_create_to = mtx.affine_inverse().xform(Vector2(mm->get_position().x, mm->get_position().y));
|
|
uv_create_to = mtx.affine_inverse().xform(Vector2(mm->get_position().x, mm->get_position().y));
|
|
uv_edit_draw->update();
|
|
uv_edit_draw->update();
|
|
} else if (uv_mode == UV_MODE_PAINT_WEIGHT || uv_mode == UV_MODE_CLEAR_WEIGHT) {
|
|
} else if (uv_mode == UV_MODE_PAINT_WEIGHT || uv_mode == UV_MODE_CLEAR_WEIGHT) {
|
|
@@ -930,6 +993,8 @@ void Polygon2DEditor::_uv_draw() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ Array polygons = node->get_polygons();
|
|
|
|
+
|
|
PoolVector<Vector2> uvs;
|
|
PoolVector<Vector2> uvs;
|
|
if (uv_edit_mode[0]->is_pressed()) { //edit uv
|
|
if (uv_edit_mode[0]->is_pressed()) { //edit uv
|
|
uvs = node->get_uv();
|
|
uvs = node->get_uv();
|
|
@@ -956,17 +1021,54 @@ void Polygon2DEditor::_uv_draw() {
|
|
}
|
|
}
|
|
|
|
|
|
Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons");
|
|
Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons");
|
|
|
|
+ Ref<Texture> internal_handle = get_icon("EditorInternalHandle", "EditorIcons");
|
|
|
|
|
|
Color poly_line_color = Color(0.9, 0.5, 0.5);
|
|
Color poly_line_color = Color(0.9, 0.5, 0.5);
|
|
|
|
+ Color polygon_line_color = Color(0.5, 0.5, 0.9);
|
|
|
|
+ Vector<Color> polygon_fill_color;
|
|
|
|
+ {
|
|
|
|
+ Color pf = polygon_line_color;
|
|
|
|
+ pf.a *= 0.5;
|
|
|
|
+ polygon_fill_color.push_back(pf);
|
|
|
|
+ }
|
|
Color prev_color = Color(0.5, 0.5, 0.5);
|
|
Color prev_color = Color(0.5, 0.5, 0.5);
|
|
Rect2 rect(Point2(), mtx.basis_xform(base_tex->get_size()));
|
|
Rect2 rect(Point2(), mtx.basis_xform(base_tex->get_size()));
|
|
rect.expand_to(mtx.basis_xform(uv_edit_draw->get_size()));
|
|
rect.expand_to(mtx.basis_xform(uv_edit_draw->get_size()));
|
|
|
|
|
|
|
|
+ int uv_draw_max = uvs.size();
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < polygons.size(); i++) {
|
|
|
|
+
|
|
|
|
+ PoolVector<int> points = polygons[i];
|
|
|
|
+ Vector<Vector2> polypoints;
|
|
|
|
+ for (int i = 0; i < points.size(); i++) {
|
|
|
|
+ int next = (i + 1) % points.size();
|
|
|
|
+
|
|
|
|
+ int idx = points[i];
|
|
|
|
+ int idx_next = points[next];
|
|
|
|
+ if (idx < 0 || idx >= uvs.size())
|
|
|
|
+ continue;
|
|
|
|
+ polypoints.push_back(mtx.xform(uvs[idx]));
|
|
|
|
+
|
|
|
|
+ if (idx_next < 0 || idx_next >= uvs.size())
|
|
|
|
+ continue;
|
|
|
|
+ uv_edit_draw->draw_line(mtx.xform(uvs[idx]), mtx.xform(uvs[idx_next]), polygon_line_color, 2 * EDSCALE);
|
|
|
|
+ }
|
|
|
|
+ if (points.size() >= 3) {
|
|
|
|
+ uv_edit_draw->draw_polygon(polypoints, polygon_fill_color);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ uv_draw_max -= node->get_internal_vertex_count();
|
|
|
|
+ if (uv_draw_max < 0) {
|
|
|
|
+ uv_draw_max = 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
for (int i = 0; i < uvs.size(); i++) {
|
|
for (int i = 0; i < uvs.size(); i++) {
|
|
|
|
|
|
- int next = (i + 1) % uvs.size();
|
|
|
|
|
|
+ int next = uv_draw_max > 0 ? (i + 1) % uv_draw_max : 0;
|
|
|
|
|
|
- if (uv_drag && uv_move_current == UV_MODE_EDIT_POINT && EDITOR_DEF("editors/poly_editor/show_previous_outline", true)) {
|
|
|
|
|
|
+ if (i < uv_draw_max && uv_drag && uv_move_current == UV_MODE_EDIT_POINT && EDITOR_DEF("editors/poly_editor/show_previous_outline", true)) {
|
|
uv_edit_draw->draw_line(mtx.xform(points_prev[i]), mtx.xform(points_prev[next]), prev_color, 2 * EDSCALE);
|
|
uv_edit_draw->draw_line(mtx.xform(points_prev[i]), mtx.xform(points_prev[next]), prev_color, 2 * EDSCALE);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -974,24 +1076,33 @@ void Polygon2DEditor::_uv_draw() {
|
|
if (uv_create && i == uvs.size() - 1) {
|
|
if (uv_create && i == uvs.size() - 1) {
|
|
next_point = uv_create_to;
|
|
next_point = uv_create_to;
|
|
}
|
|
}
|
|
- uv_edit_draw->draw_line(mtx.xform(uvs[i]), mtx.xform(next_point), poly_line_color, 2 * EDSCALE);
|
|
|
|
|
|
+ if (i < uv_draw_max && polygons.size() == 0 && polygon_create.size() == 0) { //if using or creating polygons, do not show outline (will show polygons instead)
|
|
|
|
+ uv_edit_draw->draw_line(mtx.xform(uvs[i]), mtx.xform(next_point), poly_line_color, 2 * EDSCALE);
|
|
|
|
+ }
|
|
|
|
|
|
if (weight_r.ptr()) {
|
|
if (weight_r.ptr()) {
|
|
Vector2 draw_pos = mtx.xform(uvs[i]);
|
|
Vector2 draw_pos = mtx.xform(uvs[i]);
|
|
float weight = weight_r[i];
|
|
float weight = weight_r[i];
|
|
uv_edit_draw->draw_rect(Rect2(draw_pos - Vector2(2, 2) * EDSCALE, Vector2(5, 5) * EDSCALE), Color(weight, weight, weight, 1.0));
|
|
uv_edit_draw->draw_rect(Rect2(draw_pos - Vector2(2, 2) * EDSCALE, Vector2(5, 5) * EDSCALE), Color(weight, weight, weight, 1.0));
|
|
} else {
|
|
} else {
|
|
- uv_edit_draw->draw_texture(handle, mtx.xform(uvs[i]) - handle->get_size() * 0.5);
|
|
|
|
|
|
+ if (i < uv_draw_max) {
|
|
|
|
+ uv_edit_draw->draw_texture(handle, mtx.xform(uvs[i]) - handle->get_size() * 0.5);
|
|
|
|
+ } else {
|
|
|
|
+ uv_edit_draw->draw_texture(internal_handle, mtx.xform(uvs[i]) - internal_handle->get_size() * 0.5);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
rect.expand_to(mtx.basis_xform(uvs[i]));
|
|
rect.expand_to(mtx.basis_xform(uvs[i]));
|
|
}
|
|
}
|
|
|
|
|
|
- if (split_create) {
|
|
|
|
- Vector2 from = uvs[point_drag_index];
|
|
|
|
- Vector2 to = uv_create_to;
|
|
|
|
- uv_edit_draw->draw_line(mtx.xform(from), mtx.xform(to), poly_line_color, 2);
|
|
|
|
|
|
+ if (polygon_create.size()) {
|
|
|
|
+ for (int i = 0; i < polygon_create.size(); i++) {
|
|
|
|
+ Vector2 from = uvs[polygon_create[i]];
|
|
|
|
+ Vector2 to = (i + 1) < polygon_create.size() ? uvs[polygon_create[i + 1]] : uv_create_to;
|
|
|
|
+ uv_edit_draw->draw_line(mtx.xform(from), mtx.xform(to), poly_line_color, 2);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#if 0
|
|
PoolVector<int> splits = node->get_splits();
|
|
PoolVector<int> splits = node->get_splits();
|
|
|
|
|
|
for (int i = 0; i < splits.size(); i += 2) {
|
|
for (int i = 0; i < splits.size(); i += 2) {
|
|
@@ -1001,7 +1112,7 @@ void Polygon2DEditor::_uv_draw() {
|
|
continue;
|
|
continue;
|
|
uv_edit_draw->draw_line(mtx.xform(uvs[idx_from]), mtx.xform(uvs[idx_to]), poly_line_color, 2);
|
|
uv_edit_draw->draw_line(mtx.xform(uvs[idx_from]), mtx.xform(uvs[idx_to]), poly_line_color, 2);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+#endif
|
|
if (uv_mode == UV_MODE_PAINT_WEIGHT || uv_mode == UV_MODE_CLEAR_WEIGHT) {
|
|
if (uv_mode == UV_MODE_PAINT_WEIGHT || uv_mode == UV_MODE_CLEAR_WEIGHT) {
|
|
|
|
|
|
NodePath bone_path;
|
|
NodePath bone_path;
|
|
@@ -1155,8 +1266,8 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) :
|
|
|
|
|
|
uv_edit_mode[0]->set_text(TTR("UV"));
|
|
uv_edit_mode[0]->set_text(TTR("UV"));
|
|
uv_edit_mode[0]->set_pressed(true);
|
|
uv_edit_mode[0]->set_pressed(true);
|
|
- uv_edit_mode[1]->set_text(TTR("Poly"));
|
|
|
|
- uv_edit_mode[2]->set_text(TTR("Splits"));
|
|
|
|
|
|
+ uv_edit_mode[1]->set_text(TTR("Points"));
|
|
|
|
+ uv_edit_mode[2]->set_text(TTR("Polygons"));
|
|
uv_edit_mode[3]->set_text(TTR("Bones"));
|
|
uv_edit_mode[3]->set_text(TTR("Bones"));
|
|
|
|
|
|
uv_edit_mode[0]->set_button_group(uv_edit_group);
|
|
uv_edit_mode[0]->set_button_group(uv_edit_group);
|
|
@@ -1181,22 +1292,26 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) :
|
|
uv_button[i]->set_focus_mode(FOCUS_NONE);
|
|
uv_button[i]->set_focus_mode(FOCUS_NONE);
|
|
}
|
|
}
|
|
|
|
|
|
- uv_button[0]->set_tooltip(TTR("Create Polygon"));
|
|
|
|
- uv_button[1]->set_tooltip(TTR("Move Points") + "\n" + TTR("Ctrl: Rotate") + "\n" + TTR("Shift: Move All") + "\n" + TTR("Shift+Ctrl: Scale"));
|
|
|
|
- uv_button[2]->set_tooltip(TTR("Move Polygon"));
|
|
|
|
- uv_button[3]->set_tooltip(TTR("Rotate Polygon"));
|
|
|
|
- uv_button[4]->set_tooltip(TTR("Scale Polygon"));
|
|
|
|
- uv_button[5]->set_tooltip(TTR("Connect two points to make a split."));
|
|
|
|
- uv_button[6]->set_tooltip(TTR("Select a split to erase it."));
|
|
|
|
- uv_button[7]->set_tooltip(TTR("Paint weights with specified intensity."));
|
|
|
|
- uv_button[8]->set_tooltip(TTR("Unpaint weights with specified intensity."));
|
|
|
|
-
|
|
|
|
- uv_button[0]->hide();
|
|
|
|
- uv_button[5]->hide();
|
|
|
|
- uv_button[6]->hide();
|
|
|
|
- uv_button[7]->hide();
|
|
|
|
- uv_button[8]->hide();
|
|
|
|
- uv_button[1]->set_pressed(true);
|
|
|
|
|
|
+ uv_button[UV_MODE_CREATE]->set_tooltip(TTR("Create Polygon"));
|
|
|
|
+ uv_button[UV_MODE_CREATE_INTERNAL]->set_tooltip(TTR("Create Internal Vertex"));
|
|
|
|
+ uv_button[UV_MODE_REMOVE_INTERNAL]->set_tooltip(TTR("Erase Internal Vertex"));
|
|
|
|
+ uv_button[UV_MODE_EDIT_POINT]->set_tooltip(TTR("Move Points") + "\n" + TTR("Ctrl: Rotate") + "\n" + TTR("Shift: Move All") + "\n" + TTR("Shift+Ctrl: Scale"));
|
|
|
|
+ uv_button[UV_MODE_MOVE]->set_tooltip(TTR("Move Polygon"));
|
|
|
|
+ uv_button[UV_MODE_ROTATE]->set_tooltip(TTR("Rotate Polygon"));
|
|
|
|
+ uv_button[UV_MODE_SCALE]->set_tooltip(TTR("Scale Polygon"));
|
|
|
|
+ uv_button[UV_MODE_ADD_POLYGON]->set_tooltip(TTR("Create a custom polygon. Enables custom polygon rendering."));
|
|
|
|
+ uv_button[UV_MODE_REMOVE_POLYGON]->set_tooltip(TTR("Remove a custom polygon. If none remain, custom polygon rendering is disabled."));
|
|
|
|
+ uv_button[UV_MODE_PAINT_WEIGHT]->set_tooltip(TTR("Paint weights with specified intensity."));
|
|
|
|
+ uv_button[UV_MODE_CLEAR_WEIGHT]->set_tooltip(TTR("Unpaint weights with specified intensity."));
|
|
|
|
+
|
|
|
|
+ uv_button[UV_MODE_CREATE]->hide();
|
|
|
|
+ uv_button[UV_MODE_CREATE_INTERNAL]->hide();
|
|
|
|
+ uv_button[UV_MODE_REMOVE_INTERNAL]->hide();
|
|
|
|
+ uv_button[UV_MODE_ADD_POLYGON]->hide();
|
|
|
|
+ uv_button[UV_MODE_REMOVE_POLYGON]->hide();
|
|
|
|
+ uv_button[UV_MODE_PAINT_WEIGHT]->hide();
|
|
|
|
+ uv_button[UV_MODE_CLEAR_WEIGHT]->hide();
|
|
|
|
+ uv_button[UV_MODE_EDIT_POINT]->set_pressed(true);
|
|
|
|
|
|
bone_paint_strength = memnew(HSlider);
|
|
bone_paint_strength = memnew(HSlider);
|
|
uv_mode_hb->add_child(bone_paint_strength);
|
|
uv_mode_hb->add_child(bone_paint_strength);
|
|
@@ -1354,7 +1469,6 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) :
|
|
uv_drag = false;
|
|
uv_drag = false;
|
|
uv_create = false;
|
|
uv_create = false;
|
|
updating_uv_scroll = false;
|
|
updating_uv_scroll = false;
|
|
- split_create = false;
|
|
|
|
bone_painting = false;
|
|
bone_painting = false;
|
|
|
|
|
|
error = memnew(AcceptDialog);
|
|
error = memnew(AcceptDialog);
|