2023-01-05 12:25:55 +00:00
|
|
|
|
/**************************************************************************/
|
|
|
|
|
/* polygon_2d_editor_plugin.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-04 23:50:27 +00:00
|
|
|
|
|
2014-07-07 20:44:21 +00:00
|
|
|
|
#include "polygon_2d_editor_plugin.h"
|
2017-01-16 07:04:19 +00:00
|
|
|
|
|
2022-02-14 13:00:03 +00:00
|
|
|
|
#include "core/input/input_event.h"
|
2020-05-25 17:20:45 +00:00
|
|
|
|
#include "core/math/geometry_2d.h"
|
2022-08-29 10:10:32 +00:00
|
|
|
|
#include "editor/editor_node.h"
|
2019-12-24 07:17:23 +00:00
|
|
|
|
#include "editor/editor_scale.h"
|
2017-03-05 13:21:25 +00:00
|
|
|
|
#include "editor/editor_settings.h"
|
2022-08-29 10:10:32 +00:00
|
|
|
|
#include "editor/editor_undo_redo_manager.h"
|
2022-02-14 13:00:03 +00:00
|
|
|
|
#include "editor/plugins/canvas_item_editor_plugin.h"
|
2018-05-02 14:00:35 +00:00
|
|
|
|
#include "scene/2d/skeleton_2d.h"
|
2022-11-19 11:45:49 +00:00
|
|
|
|
#include "scene/gui/check_box.h"
|
2022-02-12 01:46:22 +00:00
|
|
|
|
#include "scene/gui/menu_button.h"
|
2022-01-13 16:19:15 +00:00
|
|
|
|
#include "scene/gui/scroll_container.h"
|
2022-02-12 01:46:22 +00:00
|
|
|
|
#include "scene/gui/separator.h"
|
|
|
|
|
#include "scene/gui/slider.h"
|
2022-11-19 11:45:49 +00:00
|
|
|
|
#include "scene/gui/spin_box.h"
|
|
|
|
|
#include "scene/gui/split_container.h"
|
|
|
|
|
#include "scene/gui/texture_rect.h"
|
2022-01-13 16:19:15 +00:00
|
|
|
|
#include "scene/gui/view_panner.h"
|
2018-08-24 07:35:07 +00:00
|
|
|
|
|
2017-09-06 16:41:14 +00:00
|
|
|
|
Node2D *Polygon2DEditor::_get_node() const {
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Polygon2DEditor::_set_node(Node *p_polygon) {
|
|
|
|
|
node = Object::cast_to<Polygon2D>(p_polygon);
|
2019-02-16 18:46:09 +00:00
|
|
|
|
_update_polygon_editing_state();
|
2017-09-06 16:41:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector2 Polygon2DEditor::_get_offset(int p_idx) const {
|
|
|
|
|
return node->get_offset();
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-08 22:10:24 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-07 20:44:21 +00:00
|
|
|
|
void Polygon2DEditor::_notification(int p_what) {
|
|
|
|
|
switch (p_what) {
|
2018-11-24 04:38:26 +00:00
|
|
|
|
case NOTIFICATION_ENTER_TREE:
|
2022-01-13 16:19:15 +00:00
|
|
|
|
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
|
2022-10-18 14:43:37 +00:00
|
|
|
|
uv_panner->setup((ViewPanner::ControlScheme)EDITOR_GET("editors/panning/sub_editors_panning_scheme").operator int(), ED_GET_SHORTCUT("canvas_item_editor/pan_view"), bool(EDITOR_GET("editors/panning/simple_panning")));
|
2018-11-24 04:38:26 +00:00
|
|
|
|
} break;
|
2022-02-16 02:44:22 +00:00
|
|
|
|
|
2014-07-07 20:44:21 +00:00
|
|
|
|
case NOTIFICATION_READY: {
|
2021-07-17 21:22:52 +00:00
|
|
|
|
button_uv->set_icon(get_theme_icon(SNAME("Uv"), SNAME("EditorIcons")));
|
|
|
|
|
|
|
|
|
|
uv_button[UV_MODE_CREATE]->set_icon(get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")));
|
|
|
|
|
uv_button[UV_MODE_CREATE_INTERNAL]->set_icon(get_theme_icon(SNAME("EditInternal"), SNAME("EditorIcons")));
|
|
|
|
|
uv_button[UV_MODE_REMOVE_INTERNAL]->set_icon(get_theme_icon(SNAME("RemoveInternal"), SNAME("EditorIcons")));
|
|
|
|
|
uv_button[UV_MODE_EDIT_POINT]->set_icon(get_theme_icon(SNAME("ToolSelect"), SNAME("EditorIcons")));
|
|
|
|
|
uv_button[UV_MODE_MOVE]->set_icon(get_theme_icon(SNAME("ToolMove"), SNAME("EditorIcons")));
|
|
|
|
|
uv_button[UV_MODE_ROTATE]->set_icon(get_theme_icon(SNAME("ToolRotate"), SNAME("EditorIcons")));
|
|
|
|
|
uv_button[UV_MODE_SCALE]->set_icon(get_theme_icon(SNAME("ToolScale"), SNAME("EditorIcons")));
|
|
|
|
|
uv_button[UV_MODE_ADD_POLYGON]->set_icon(get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")));
|
|
|
|
|
uv_button[UV_MODE_REMOVE_POLYGON]->set_icon(get_theme_icon(SNAME("Close"), SNAME("EditorIcons")));
|
|
|
|
|
uv_button[UV_MODE_PAINT_WEIGHT]->set_icon(get_theme_icon(SNAME("Bucket"), SNAME("EditorIcons")));
|
|
|
|
|
uv_button[UV_MODE_CLEAR_WEIGHT]->set_icon(get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")));
|
|
|
|
|
|
|
|
|
|
b_snap_grid->set_icon(get_theme_icon(SNAME("Grid"), SNAME("EditorIcons")));
|
|
|
|
|
b_snap_enable->set_icon(get_theme_icon(SNAME("SnapGrid"), SNAME("EditorIcons")));
|
|
|
|
|
uv_icon_zoom->set_texture(get_theme_icon(SNAME("Zoom"), SNAME("EditorIcons")));
|
2020-01-23 00:55:52 +00:00
|
|
|
|
|
2020-12-22 16:24:29 +00:00
|
|
|
|
uv_vscroll->set_anchors_and_offsets_preset(PRESET_RIGHT_WIDE);
|
|
|
|
|
uv_hscroll->set_anchors_and_offsets_preset(PRESET_BOTTOM_WIDE);
|
2022-08-29 09:04:31 +00:00
|
|
|
|
[[fallthrough]];
|
|
|
|
|
}
|
2022-01-13 16:19:15 +00:00
|
|
|
|
case NOTIFICATION_THEME_CHANGED: {
|
2022-09-06 17:09:32 +00:00
|
|
|
|
uv_edit_draw->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), SNAME("Tree")));
|
|
|
|
|
bone_scroll->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), SNAME("Tree")));
|
2014-07-07 20:44:21 +00:00
|
|
|
|
} break;
|
2022-02-16 02:44:22 +00:00
|
|
|
|
|
2018-11-24 04:38:26 +00:00
|
|
|
|
case NOTIFICATION_VISIBILITY_CHANGED: {
|
|
|
|
|
if (!is_visible()) {
|
|
|
|
|
uv_edit->hide();
|
|
|
|
|
}
|
2014-07-07 20:44:21 +00:00
|
|
|
|
} break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-02 14:00:35 +00:00
|
|
|
|
void Polygon2DEditor::_sync_bones() {
|
2020-04-01 23:20:12 +00:00
|
|
|
|
Skeleton2D *skeleton = nullptr;
|
2018-05-02 14:00:35 +00:00
|
|
|
|
if (!node->has_node(node->get_skeleton())) {
|
|
|
|
|
error->set_text(TTR("The skeleton property of the Polygon2D does not point to a Skeleton2D node"));
|
2020-03-06 17:00:16 +00:00
|
|
|
|
error->popup_centered();
|
2018-11-24 04:38:26 +00:00
|
|
|
|
} else {
|
|
|
|
|
Node *sn = node->get_node(node->get_skeleton());
|
|
|
|
|
skeleton = Object::cast_to<Skeleton2D>(sn);
|
2018-05-02 14:00:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-24 04:38:26 +00:00
|
|
|
|
Array prev_bones = node->call("_get_bones");
|
|
|
|
|
node->clear_bones();
|
2018-05-02 14:00:35 +00:00
|
|
|
|
|
|
|
|
|
if (!skeleton) {
|
|
|
|
|
error->set_text(TTR("The skeleton property of the Polygon2D does not point to a Skeleton2D node"));
|
2020-03-06 17:00:16 +00:00
|
|
|
|
error->popup_centered();
|
2018-11-24 04:38:26 +00:00
|
|
|
|
} else {
|
|
|
|
|
for (int i = 0; i < skeleton->get_bone_count(); i++) {
|
|
|
|
|
NodePath path = skeleton->get_path_to(skeleton->get_bone(i));
|
2020-02-17 21:06:54 +00:00
|
|
|
|
Vector<float> weights;
|
2018-11-24 04:38:26 +00:00
|
|
|
|
int wc = node->get_polygon().size();
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < prev_bones.size(); j += 2) {
|
|
|
|
|
NodePath pvp = prev_bones[j];
|
2020-02-17 21:06:54 +00:00
|
|
|
|
Vector<float> pv = prev_bones[j + 1];
|
2018-11-24 04:38:26 +00:00
|
|
|
|
if (pvp == path && pv.size() == wc) {
|
|
|
|
|
weights = pv;
|
|
|
|
|
}
|
2018-05-02 14:00:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-24 04:38:26 +00:00
|
|
|
|
if (weights.size() == 0) { //create them
|
|
|
|
|
weights.resize(node->get_polygon().size());
|
2020-02-17 21:06:54 +00:00
|
|
|
|
float *w = weights.ptrw();
|
2018-11-24 04:38:26 +00:00
|
|
|
|
for (int j = 0; j < wc; j++) {
|
|
|
|
|
w[j] = 0.0;
|
|
|
|
|
}
|
2018-05-02 14:00:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-24 04:38:26 +00:00
|
|
|
|
node->add_bone(path, weights);
|
|
|
|
|
}
|
2018-05-02 14:00:35 +00:00
|
|
|
|
}
|
2018-11-24 04:38:26 +00:00
|
|
|
|
|
2018-05-02 14:00:35 +00:00
|
|
|
|
Array new_bones = node->call("_get_bones");
|
|
|
|
|
|
2022-12-23 22:53:16 +00:00
|
|
|
|
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
2018-11-24 04:38:26 +00:00
|
|
|
|
undo_redo->create_action(TTR("Sync Bones"));
|
2018-05-02 14:00:35 +00:00
|
|
|
|
undo_redo->add_do_method(node, "_set_bones", new_bones);
|
|
|
|
|
undo_redo->add_undo_method(node, "_set_bones", prev_bones);
|
|
|
|
|
undo_redo->add_do_method(this, "_update_bone_list");
|
|
|
|
|
undo_redo->add_undo_method(this, "_update_bone_list");
|
2022-08-13 21:21:24 +00:00
|
|
|
|
undo_redo->add_do_method(uv_edit_draw, "queue_redraw");
|
|
|
|
|
undo_redo->add_undo_method(uv_edit_draw, "queue_redraw");
|
2018-05-02 14:00:35 +00:00
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Polygon2DEditor::_update_bone_list() {
|
|
|
|
|
NodePath selected;
|
|
|
|
|
while (bone_scroll_vb->get_child_count()) {
|
|
|
|
|
CheckBox *cb = Object::cast_to<CheckBox>(bone_scroll_vb->get_child(0));
|
|
|
|
|
if (cb && cb->is_pressed()) {
|
|
|
|
|
selected = cb->get_meta("bone_path");
|
|
|
|
|
}
|
|
|
|
|
memdelete(bone_scroll_vb->get_child(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ref<ButtonGroup> bg;
|
2021-06-17 22:03:09 +00:00
|
|
|
|
bg.instantiate();
|
2018-05-02 14:00:35 +00:00
|
|
|
|
for (int i = 0; i < node->get_bone_count(); i++) {
|
|
|
|
|
CheckBox *cb = memnew(CheckBox);
|
|
|
|
|
NodePath np = node->get_bone_path(i);
|
|
|
|
|
String name;
|
|
|
|
|
if (np.get_name_count()) {
|
|
|
|
|
name = np.get_name(np.get_name_count() - 1);
|
|
|
|
|
}
|
2021-12-09 09:42:46 +00:00
|
|
|
|
if (name.is_empty()) {
|
2018-05-02 14:00:35 +00:00
|
|
|
|
name = "Bone " + itos(i);
|
|
|
|
|
}
|
|
|
|
|
cb->set_text(name);
|
|
|
|
|
cb->set_button_group(bg);
|
|
|
|
|
cb->set_meta("bone_path", np);
|
2018-11-24 04:38:26 +00:00
|
|
|
|
cb->set_focus_mode(FOCUS_NONE);
|
2018-05-02 14:00:35 +00:00
|
|
|
|
bone_scroll_vb->add_child(cb);
|
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
|
if (np == selected || bone_scroll_vb->get_child_count() < 2) {
|
2018-05-02 14:00:35 +00:00
|
|
|
|
cb->set_pressed(true);
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2018-05-02 14:00:35 +00:00
|
|
|
|
|
2022-07-28 20:56:41 +00:00
|
|
|
|
cb->connect("pressed", callable_mp(this, &Polygon2DEditor::_bone_paint_selected).bind(i));
|
2018-05-02 14:00:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-13 21:21:24 +00:00
|
|
|
|
uv_edit_draw->queue_redraw();
|
2018-05-02 14:00:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Polygon2DEditor::_bone_paint_selected(int p_index) {
|
2022-08-13 21:21:24 +00:00
|
|
|
|
uv_edit_draw->queue_redraw();
|
2018-05-02 14:00:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-22 20:38:33 +00:00
|
|
|
|
void Polygon2DEditor::_uv_edit_mode_select(int p_mode) {
|
2018-05-02 14:00:35 +00:00
|
|
|
|
if (p_mode == 0) { //uv
|
2018-11-24 04:38:26 +00:00
|
|
|
|
|
2018-02-22 20:38:33 +00:00
|
|
|
|
uv_button[UV_MODE_CREATE]->hide();
|
2019-01-08 22:10:24 +00:00
|
|
|
|
uv_button[UV_MODE_CREATE_INTERNAL]->hide();
|
|
|
|
|
uv_button[UV_MODE_REMOVE_INTERNAL]->hide();
|
2020-10-29 19:45:17 +00:00
|
|
|
|
for (int i = UV_MODE_EDIT_POINT; i <= UV_MODE_SCALE; i++) {
|
2018-02-25 15:06:30 +00:00
|
|
|
|
uv_button[i]->show();
|
|
|
|
|
}
|
2019-01-08 22:10:24 +00:00
|
|
|
|
uv_button[UV_MODE_ADD_POLYGON]->hide();
|
|
|
|
|
uv_button[UV_MODE_REMOVE_POLYGON]->hide();
|
2018-05-02 14:00:35 +00:00
|
|
|
|
uv_button[UV_MODE_PAINT_WEIGHT]->hide();
|
|
|
|
|
uv_button[UV_MODE_CLEAR_WEIGHT]->hide();
|
2018-02-25 15:06:30 +00:00
|
|
|
|
_uv_mode(UV_MODE_EDIT_POINT);
|
|
|
|
|
|
2018-05-02 14:00:35 +00:00
|
|
|
|
bone_scroll_main_vb->hide();
|
|
|
|
|
bone_paint_strength->hide();
|
|
|
|
|
bone_paint_radius->hide();
|
|
|
|
|
bone_paint_radius_label->hide();
|
|
|
|
|
} else if (p_mode == 1) { //poly
|
2018-11-24 04:38:26 +00:00
|
|
|
|
|
2018-02-25 15:06:30 +00:00
|
|
|
|
for (int i = 0; i <= UV_MODE_SCALE; i++) {
|
|
|
|
|
uv_button[i]->show();
|
|
|
|
|
}
|
2019-01-08 22:10:24 +00:00
|
|
|
|
uv_button[UV_MODE_ADD_POLYGON]->hide();
|
|
|
|
|
uv_button[UV_MODE_REMOVE_POLYGON]->hide();
|
2018-05-02 14:00:35 +00:00
|
|
|
|
uv_button[UV_MODE_PAINT_WEIGHT]->hide();
|
|
|
|
|
uv_button[UV_MODE_CLEAR_WEIGHT]->hide();
|
2018-02-25 15:06:30 +00:00
|
|
|
|
_uv_mode(UV_MODE_EDIT_POINT);
|
2018-05-02 14:00:35 +00:00
|
|
|
|
|
|
|
|
|
bone_scroll_main_vb->hide();
|
|
|
|
|
bone_paint_strength->hide();
|
|
|
|
|
bone_paint_radius->hide();
|
|
|
|
|
bone_paint_radius_label->hide();
|
|
|
|
|
} else if (p_mode == 2) { //splits
|
2018-11-24 04:38:26 +00:00
|
|
|
|
|
2018-02-25 15:06:30 +00:00
|
|
|
|
for (int i = 0; i <= UV_MODE_SCALE; i++) {
|
|
|
|
|
uv_button[i]->hide();
|
|
|
|
|
}
|
2019-01-08 22:10:24 +00:00
|
|
|
|
uv_button[UV_MODE_ADD_POLYGON]->show();
|
|
|
|
|
uv_button[UV_MODE_REMOVE_POLYGON]->show();
|
2018-05-02 14:00:35 +00:00
|
|
|
|
uv_button[UV_MODE_PAINT_WEIGHT]->hide();
|
|
|
|
|
uv_button[UV_MODE_CLEAR_WEIGHT]->hide();
|
2019-01-08 22:10:24 +00:00
|
|
|
|
_uv_mode(UV_MODE_ADD_POLYGON);
|
2018-05-02 14:00:35 +00:00
|
|
|
|
|
|
|
|
|
bone_scroll_main_vb->hide();
|
|
|
|
|
bone_paint_strength->hide();
|
|
|
|
|
bone_paint_radius->hide();
|
|
|
|
|
bone_paint_radius_label->hide();
|
|
|
|
|
} else if (p_mode == 3) { //bones´
|
2018-11-24 04:38:26 +00:00
|
|
|
|
|
2019-01-08 22:10:24 +00:00
|
|
|
|
for (int i = 0; i <= UV_MODE_REMOVE_POLYGON; i++) {
|
2018-05-02 14:00:35 +00:00
|
|
|
|
uv_button[i]->hide();
|
|
|
|
|
}
|
|
|
|
|
uv_button[UV_MODE_PAINT_WEIGHT]->show();
|
|
|
|
|
uv_button[UV_MODE_CLEAR_WEIGHT]->show();
|
|
|
|
|
_uv_mode(UV_MODE_PAINT_WEIGHT);
|
|
|
|
|
|
|
|
|
|
bone_scroll_main_vb->show();
|
|
|
|
|
bone_paint_strength->show();
|
|
|
|
|
bone_paint_radius->show();
|
|
|
|
|
bone_paint_radius_label->show();
|
|
|
|
|
_update_bone_list();
|
|
|
|
|
bone_paint_pos = Vector2(-100000, -100000); //send brush away when switching
|
2018-02-22 20:38:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-24 04:38:26 +00:00
|
|
|
|
uv_edit->set_size(uv_edit->get_size()); // Necessary readjustment of the popup window.
|
2022-08-13 21:21:24 +00:00
|
|
|
|
uv_edit_draw->queue_redraw();
|
2018-02-22 20:38:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-24 04:38:26 +00:00
|
|
|
|
void Polygon2DEditor::_uv_edit_popup_hide() {
|
2020-03-06 17:00:16 +00:00
|
|
|
|
EditorSettings::get_singleton()->set("interface/dialogs/uv_editor_bounds", Rect2(uv_edit->get_position(), uv_edit->get_size()));
|
2018-11-24 04:38:26 +00:00
|
|
|
|
|
|
|
|
|
_cancel_editing();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-07 20:44:21 +00:00
|
|
|
|
void Polygon2DEditor::_menu_option(int p_option) {
|
2022-12-23 22:53:16 +00:00
|
|
|
|
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
2014-07-07 20:44:21 +00:00
|
|
|
|
switch (p_option) {
|
|
|
|
|
case MODE_EDIT_UV: {
|
|
|
|
|
if (node->get_texture().is_null()) {
|
2018-11-24 04:38:26 +00:00
|
|
|
|
error->set_text(TTR("No texture in this polygon.\nSet a texture to be able to edit UV."));
|
2020-03-06 17:00:16 +00:00
|
|
|
|
error->popup_centered();
|
2014-07-07 20:44:21 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-17 21:06:54 +00:00
|
|
|
|
Vector<Vector2> points = node->get_polygon();
|
|
|
|
|
Vector<Vector2> uvs = node->get_uv();
|
2014-07-07 20:44:21 +00:00
|
|
|
|
if (uvs.size() != points.size()) {
|
2016-05-04 01:25:37 +00:00
|
|
|
|
undo_redo->create_action(TTR("Create UV Map"));
|
2014-07-07 20:44:21 +00:00
|
|
|
|
undo_redo->add_do_method(node, "set_uv", points);
|
|
|
|
|
undo_redo->add_undo_method(node, "set_uv", uvs);
|
2022-08-13 21:21:24 +00:00
|
|
|
|
undo_redo->add_do_method(uv_edit_draw, "queue_redraw");
|
|
|
|
|
undo_redo->add_undo_method(uv_edit_draw, "queue_redraw");
|
2014-07-07 20:44:21 +00:00
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
|
if (EditorSettings::get_singleton()->has_setting("interface/dialogs/uv_editor_bounds")) {
|
2022-10-18 14:43:37 +00:00
|
|
|
|
uv_edit->popup(EDITOR_GET("interface/dialogs/uv_editor_bounds"));
|
2020-05-14 14:41:43 +00:00
|
|
|
|
} else {
|
2018-11-24 04:38:26 +00:00
|
|
|
|
uv_edit->popup_centered_ratio(0.85);
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2019-01-08 22:10:24 +00:00
|
|
|
|
_update_bone_list();
|
2014-07-07 20:44:21 +00:00
|
|
|
|
} break;
|
|
|
|
|
case UVEDIT_POLYGON_TO_UV: {
|
2020-02-17 21:06:54 +00:00
|
|
|
|
Vector<Vector2> points = node->get_polygon();
|
2020-05-14 14:41:43 +00:00
|
|
|
|
if (points.size() == 0) {
|
2014-07-07 20:44:21 +00:00
|
|
|
|
break;
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2020-02-17 21:06:54 +00:00
|
|
|
|
Vector<Vector2> uvs = node->get_uv();
|
2016-05-04 01:25:37 +00:00
|
|
|
|
undo_redo->create_action(TTR("Create UV Map"));
|
2014-07-07 20:44:21 +00:00
|
|
|
|
undo_redo->add_do_method(node, "set_uv", points);
|
|
|
|
|
undo_redo->add_undo_method(node, "set_uv", uvs);
|
2022-08-13 21:21:24 +00:00
|
|
|
|
undo_redo->add_do_method(uv_edit_draw, "queue_redraw");
|
|
|
|
|
undo_redo->add_undo_method(uv_edit_draw, "queue_redraw");
|
2014-07-07 20:44:21 +00:00
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
} break;
|
|
|
|
|
case UVEDIT_UV_TO_POLYGON: {
|
2020-02-17 21:06:54 +00:00
|
|
|
|
Vector<Vector2> points = node->get_polygon();
|
|
|
|
|
Vector<Vector2> uvs = node->get_uv();
|
2020-05-14 14:41:43 +00:00
|
|
|
|
if (uvs.size() == 0) {
|
2014-07-07 20:44:21 +00:00
|
|
|
|
break;
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2014-07-07 20:44:21 +00:00
|
|
|
|
|
2018-11-24 04:38:26 +00:00
|
|
|
|
undo_redo->create_action(TTR("Create Polygon"));
|
2014-07-07 20:44:21 +00:00
|
|
|
|
undo_redo->add_do_method(node, "set_polygon", uvs);
|
|
|
|
|
undo_redo->add_undo_method(node, "set_polygon", points);
|
2022-08-13 21:21:24 +00:00
|
|
|
|
undo_redo->add_do_method(uv_edit_draw, "queue_redraw");
|
|
|
|
|
undo_redo->add_undo_method(uv_edit_draw, "queue_redraw");
|
2014-07-07 20:44:21 +00:00
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
} break;
|
|
|
|
|
case UVEDIT_UV_CLEAR: {
|
2020-02-17 21:06:54 +00:00
|
|
|
|
Vector<Vector2> uvs = node->get_uv();
|
2020-05-14 14:41:43 +00:00
|
|
|
|
if (uvs.size() == 0) {
|
2014-07-07 20:44:21 +00:00
|
|
|
|
break;
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2016-05-04 01:25:37 +00:00
|
|
|
|
undo_redo->create_action(TTR("Create UV Map"));
|
2020-02-17 21:06:54 +00:00
|
|
|
|
undo_redo->add_do_method(node, "set_uv", Vector<Vector2>());
|
2014-07-07 20:44:21 +00:00
|
|
|
|
undo_redo->add_undo_method(node, "set_uv", uvs);
|
2022-08-13 21:21:24 +00:00
|
|
|
|
undo_redo->add_do_method(uv_edit_draw, "queue_redraw");
|
|
|
|
|
undo_redo->add_undo_method(uv_edit_draw, "queue_redraw");
|
2014-07-07 20:44:21 +00:00
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
} break;
|
2018-05-03 20:29:15 +00:00
|
|
|
|
case UVEDIT_GRID_SETTINGS: {
|
2020-03-06 17:00:16 +00:00
|
|
|
|
grid_settings->popup_centered();
|
2018-05-03 20:29:15 +00:00
|
|
|
|
} break;
|
2017-09-06 16:41:14 +00:00
|
|
|
|
default: {
|
|
|
|
|
AbstractPolygon2DEditor::_menu_option(p_option);
|
|
|
|
|
} break;
|
2014-07-07 20:44:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-24 04:38:26 +00:00
|
|
|
|
void Polygon2DEditor::_cancel_editing() {
|
|
|
|
|
if (uv_create) {
|
|
|
|
|
uv_drag = false;
|
|
|
|
|
uv_create = false;
|
|
|
|
|
node->set_uv(uv_create_uv_prev);
|
|
|
|
|
node->set_polygon(uv_create_poly_prev);
|
2019-01-08 22:10:24 +00:00
|
|
|
|
node->set_internal_vertex_count(uv_create_prev_internal_vertices);
|
|
|
|
|
node->set_vertex_colors(uv_create_colors_prev);
|
2018-11-24 04:38:26 +00:00
|
|
|
|
node->call("_set_bones", uv_create_bones_prev);
|
2019-01-08 22:10:24 +00:00
|
|
|
|
node->set_polygons(polygons_prev);
|
2019-02-16 18:46:09 +00:00
|
|
|
|
|
|
|
|
|
_update_polygon_editing_state();
|
2018-11-24 04:38:26 +00:00
|
|
|
|
} else if (uv_drag) {
|
|
|
|
|
uv_drag = false;
|
|
|
|
|
if (uv_edit_mode[0]->is_pressed()) { // Edit UV.
|
|
|
|
|
node->set_uv(points_prev);
|
|
|
|
|
} else if (uv_edit_mode[1]->is_pressed()) { // Edit polygon.
|
|
|
|
|
node->set_polygon(points_prev);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-08 22:10:24 +00:00
|
|
|
|
|
|
|
|
|
polygon_create.clear();
|
2018-11-24 04:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-16 18:46:09 +00:00
|
|
|
|
void Polygon2DEditor::_update_polygon_editing_state() {
|
2020-05-14 14:41:43 +00:00
|
|
|
|
if (!_get_node()) {
|
2019-02-16 18:46:09 +00:00
|
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2019-02-16 18:46:09 +00:00
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
|
if (node->get_internal_vertex_count() > 0) {
|
2019-02-16 18:46:09 +00:00
|
|
|
|
disable_polygon_editing(true, TTR("Polygon 2D has internal vertices, so it can no longer be edited in the viewport."));
|
2020-05-14 14:41:43 +00:00
|
|
|
|
} else {
|
2019-02-16 18:46:09 +00:00
|
|
|
|
disable_polygon_editing(false, String());
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2019-02-16 18:46:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-24 04:38:26 +00:00
|
|
|
|
void Polygon2DEditor::_commit_action() {
|
2019-02-16 18:46:09 +00:00
|
|
|
|
// Makes that undo/redoing actions made outside of the UV editor still affect its polygon.
|
2022-12-23 22:53:16 +00:00
|
|
|
|
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
2022-08-13 21:21:24 +00:00
|
|
|
|
undo_redo->add_do_method(uv_edit_draw, "queue_redraw");
|
|
|
|
|
undo_redo->add_undo_method(uv_edit_draw, "queue_redraw");
|
2018-11-24 04:38:26 +00:00
|
|
|
|
undo_redo->add_do_method(CanvasItemEditor::get_singleton(), "update_viewport");
|
|
|
|
|
undo_redo->add_undo_method(CanvasItemEditor::get_singleton(), "update_viewport");
|
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-28 03:06:06 +00:00
|
|
|
|
void Polygon2DEditor::_set_use_snap(bool p_use) {
|
|
|
|
|
use_snap = p_use;
|
2018-11-24 04:38:26 +00:00
|
|
|
|
EditorSettings::get_singleton()->set_project_metadata("polygon_2d_uv_editor", "snap_enabled", p_use);
|
2015-09-28 03:06:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Polygon2DEditor::_set_show_grid(bool p_show) {
|
|
|
|
|
snap_show_grid = p_show;
|
2018-11-24 04:38:26 +00:00
|
|
|
|
EditorSettings::get_singleton()->set_project_metadata("polygon_2d_uv_editor", "show_grid", p_show);
|
2022-08-13 21:21:24 +00:00
|
|
|
|
uv_edit_draw->queue_redraw();
|
2015-09-28 03:06:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-21 03:30:19 +00:00
|
|
|
|
void Polygon2DEditor::_set_snap_off_x(real_t p_val) {
|
2015-09-28 03:06:06 +00:00
|
|
|
|
snap_offset.x = p_val;
|
2018-11-24 04:38:26 +00:00
|
|
|
|
EditorSettings::get_singleton()->set_project_metadata("polygon_2d_uv_editor", "snap_offset", snap_offset);
|
2022-08-13 21:21:24 +00:00
|
|
|
|
uv_edit_draw->queue_redraw();
|
2015-09-28 03:06:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-21 03:30:19 +00:00
|
|
|
|
void Polygon2DEditor::_set_snap_off_y(real_t p_val) {
|
2015-09-28 03:06:06 +00:00
|
|
|
|
snap_offset.y = p_val;
|
2018-11-24 04:38:26 +00:00
|
|
|
|
EditorSettings::get_singleton()->set_project_metadata("polygon_2d_uv_editor", "snap_offset", snap_offset);
|
2022-08-13 21:21:24 +00:00
|
|
|
|
uv_edit_draw->queue_redraw();
|
2015-09-28 03:06:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-21 03:30:19 +00:00
|
|
|
|
void Polygon2DEditor::_set_snap_step_x(real_t p_val) {
|
2015-09-28 03:06:06 +00:00
|
|
|
|
snap_step.x = p_val;
|
2018-11-24 04:38:26 +00:00
|
|
|
|
EditorSettings::get_singleton()->set_project_metadata("polygon_2d_uv_editor", "snap_step", snap_step);
|
2022-08-13 21:21:24 +00:00
|
|
|
|
uv_edit_draw->queue_redraw();
|
2015-09-28 03:06:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-21 03:30:19 +00:00
|
|
|
|
void Polygon2DEditor::_set_snap_step_y(real_t p_val) {
|
2015-09-28 03:06:06 +00:00
|
|
|
|
snap_step.y = p_val;
|
2018-11-24 04:38:26 +00:00
|
|
|
|
EditorSettings::get_singleton()->set_project_metadata("polygon_2d_uv_editor", "snap_step", snap_step);
|
2022-08-13 21:21:24 +00:00
|
|
|
|
uv_edit_draw->queue_redraw();
|
2015-09-28 03:06:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-07 20:44:21 +00:00
|
|
|
|
void Polygon2DEditor::_uv_mode(int p_mode) {
|
2019-01-08 22:10:24 +00:00
|
|
|
|
polygon_create.clear();
|
2018-02-25 15:06:30 +00:00
|
|
|
|
uv_drag = false;
|
|
|
|
|
uv_create = false;
|
|
|
|
|
|
2014-07-07 20:44:21 +00:00
|
|
|
|
uv_mode = UVMode(p_mode);
|
|
|
|
|
for (int i = 0; i < UV_MODE_MAX; i++) {
|
|
|
|
|
uv_button[i]->set_pressed(p_mode == i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
|
void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
2020-05-14 14:41:43 +00:00
|
|
|
|
if (!_get_node()) {
|
2018-11-24 04:38:26 +00:00
|
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2018-11-24 04:38:26 +00:00
|
|
|
|
|
2022-01-13 16:19:15 +00:00
|
|
|
|
if (uv_panner->gui_input(p_input)) {
|
|
|
|
|
accept_event();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-11 03:52:51 +00:00
|
|
|
|
Transform2D mtx;
|
2022-04-24 21:59:24 +00:00
|
|
|
|
mtx.columns[2] = -uv_draw_ofs;
|
2014-07-07 20:44:21 +00:00
|
|
|
|
mtx.scale_basis(Vector2(uv_draw_zoom, uv_draw_zoom));
|
|
|
|
|
|
2022-12-23 22:53:16 +00:00
|
|
|
|
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
2014-07-07 20:44:21 +00:00
|
|
|
|
|
2022-08-29 10:10:32 +00:00
|
|
|
|
Ref<InputEventMouseButton> mb = p_input;
|
2017-05-20 15:38:03 +00:00
|
|
|
|
if (mb.is_valid()) {
|
2021-08-13 21:31:57 +00:00
|
|
|
|
if (mb->get_button_index() == MouseButton::LEFT) {
|
2017-05-20 15:38:03 +00:00
|
|
|
|
if (mb->is_pressed()) {
|
2021-09-23 14:58:43 +00:00
|
|
|
|
uv_drag_from = snap_point(mb->get_position());
|
2014-07-07 20:44:21 +00:00
|
|
|
|
uv_drag = true;
|
2018-05-04 12:32:40 +00:00
|
|
|
|
points_prev = node->get_uv();
|
2018-02-22 20:38:33 +00:00
|
|
|
|
|
2018-02-25 15:06:30 +00:00
|
|
|
|
if (uv_edit_mode[0]->is_pressed()) { //edit uv
|
2018-05-04 12:32:40 +00:00
|
|
|
|
points_prev = node->get_uv();
|
2018-02-25 15:06:30 +00:00
|
|
|
|
} else { //edit polygon
|
2018-05-04 12:32:40 +00:00
|
|
|
|
points_prev = node->get_polygon();
|
2018-02-25 15:06:30 +00:00
|
|
|
|
}
|
2018-02-22 20:38:33 +00:00
|
|
|
|
|
2014-07-07 20:44:21 +00:00
|
|
|
|
uv_move_current = uv_mode;
|
2018-02-22 20:38:33 +00:00
|
|
|
|
if (uv_move_current == UV_MODE_CREATE) {
|
|
|
|
|
if (!uv_create) {
|
2022-02-01 18:19:13 +00:00
|
|
|
|
points_prev.clear();
|
2021-09-23 14:58:43 +00:00
|
|
|
|
Vector2 tuv = mtx.affine_inverse().xform(snap_point(mb->get_position()));
|
2018-05-04 12:32:40 +00:00
|
|
|
|
points_prev.push_back(tuv);
|
2018-02-22 20:38:33 +00:00
|
|
|
|
uv_create_to = tuv;
|
2018-05-04 12:32:40 +00:00
|
|
|
|
point_drag_index = 0;
|
2018-02-22 20:38:33 +00:00
|
|
|
|
uv_drag_from = tuv;
|
|
|
|
|
uv_drag = true;
|
|
|
|
|
uv_create = true;
|
|
|
|
|
uv_create_uv_prev = node->get_uv();
|
|
|
|
|
uv_create_poly_prev = node->get_polygon();
|
2019-01-08 22:10:24 +00:00
|
|
|
|
uv_create_prev_internal_vertices = node->get_internal_vertex_count();
|
|
|
|
|
uv_create_colors_prev = node->get_vertex_colors();
|
2018-05-02 14:00:35 +00:00
|
|
|
|
uv_create_bones_prev = node->call("_get_bones");
|
2019-01-08 22:10:24 +00:00
|
|
|
|
polygons_prev = node->get_polygons();
|
2019-02-16 18:46:09 +00:00
|
|
|
|
disable_polygon_editing(false, String());
|
2018-05-04 12:32:40 +00:00
|
|
|
|
node->set_polygon(points_prev);
|
|
|
|
|
node->set_uv(points_prev);
|
2019-01-15 18:43:55 +00:00
|
|
|
|
node->set_internal_vertex_count(0);
|
2018-02-22 20:38:33 +00:00
|
|
|
|
|
2022-08-13 21:21:24 +00:00
|
|
|
|
uv_edit_draw->queue_redraw();
|
2018-02-22 20:38:33 +00:00
|
|
|
|
} else {
|
2021-09-23 14:58:43 +00:00
|
|
|
|
Vector2 tuv = mtx.affine_inverse().xform(snap_point(mb->get_position()));
|
2018-11-24 04:38:26 +00:00
|
|
|
|
|
2020-06-23 07:22:08 +00:00
|
|
|
|
// Close the polygon if selected point is near start. Threshold for closing scaled by zoom level
|
|
|
|
|
if (points_prev.size() > 2 && tuv.distance_to(points_prev[0]) < (8 / uv_draw_zoom)) {
|
2018-02-22 20:38:33 +00:00
|
|
|
|
undo_redo->create_action(TTR("Create Polygon & UV"));
|
|
|
|
|
undo_redo->add_do_method(node, "set_uv", node->get_uv());
|
2018-11-24 04:38:26 +00:00
|
|
|
|
undo_redo->add_undo_method(node, "set_uv", uv_create_uv_prev);
|
2018-02-22 20:38:33 +00:00
|
|
|
|
undo_redo->add_do_method(node, "set_polygon", node->get_polygon());
|
2018-11-24 04:38:26 +00:00
|
|
|
|
undo_redo->add_undo_method(node, "set_polygon", uv_create_poly_prev);
|
2019-01-08 22:10:24 +00:00
|
|
|
|
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);
|
2018-05-02 14:00:35 +00:00
|
|
|
|
undo_redo->add_do_method(node, "clear_bones");
|
2018-11-24 04:38:26 +00:00
|
|
|
|
undo_redo->add_undo_method(node, "_set_bones", uv_create_bones_prev);
|
2019-02-16 18:46:09 +00:00
|
|
|
|
undo_redo->add_do_method(this, "_update_polygon_editing_state");
|
|
|
|
|
undo_redo->add_undo_method(this, "_update_polygon_editing_state");
|
2022-08-13 21:21:24 +00:00
|
|
|
|
undo_redo->add_do_method(uv_edit_draw, "queue_redraw");
|
|
|
|
|
undo_redo->add_undo_method(uv_edit_draw, "queue_redraw");
|
2018-02-22 20:38:33 +00:00
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
uv_drag = false;
|
|
|
|
|
uv_create = false;
|
2018-11-24 04:38:26 +00:00
|
|
|
|
|
2018-02-22 20:38:33 +00:00
|
|
|
|
_uv_mode(UV_MODE_EDIT_POINT);
|
2018-11-24 04:38:26 +00:00
|
|
|
|
_menu_option(MODE_EDIT);
|
2018-02-22 20:38:33 +00:00
|
|
|
|
} else {
|
2018-05-04 12:32:40 +00:00
|
|
|
|
points_prev.push_back(tuv);
|
|
|
|
|
point_drag_index = points_prev.size() - 1;
|
2018-02-22 20:38:33 +00:00
|
|
|
|
uv_drag_from = tuv;
|
|
|
|
|
}
|
2018-05-04 12:32:40 +00:00
|
|
|
|
node->set_polygon(points_prev);
|
|
|
|
|
node->set_uv(points_prev);
|
2018-02-22 20:38:33 +00:00
|
|
|
|
}
|
2018-11-24 04:38:26 +00:00
|
|
|
|
|
|
|
|
|
CanvasItemEditor::get_singleton()->update_viewport();
|
2018-02-22 20:38:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-08 22:10:24 +00:00
|
|
|
|
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();
|
|
|
|
|
|
2021-09-23 14:58:43 +00:00
|
|
|
|
Vector2 pos = mtx.affine_inverse().xform(snap_point(mb->get_position()));
|
2019-01-08 22:10:24 +00:00
|
|
|
|
|
|
|
|
|
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++) {
|
2020-02-17 21:06:54 +00:00
|
|
|
|
Vector<float> bonew = node->get_bone_weights(i);
|
2019-01-08 22:10:24 +00:00
|
|
|
|
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);
|
2019-02-16 18:46:09 +00:00
|
|
|
|
undo_redo->add_do_method(this, "_update_polygon_editing_state");
|
|
|
|
|
undo_redo->add_undo_method(this, "_update_polygon_editing_state");
|
2022-08-13 21:21:24 +00:00
|
|
|
|
undo_redo->add_do_method(uv_edit_draw, "queue_redraw");
|
|
|
|
|
undo_redo->add_undo_method(uv_edit_draw, "queue_redraw");
|
2019-01-08 22:10:24 +00:00
|
|
|
|
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();
|
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
|
if (internal_vertices <= 0) {
|
2019-01-08 22:10:24 +00:00
|
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2019-01-08 22:10:24 +00:00
|
|
|
|
|
|
|
|
|
int closest = -1;
|
2021-06-21 03:30:19 +00:00
|
|
|
|
real_t closest_dist = 1e20;
|
2019-01-08 22:10:24 +00:00
|
|
|
|
|
|
|
|
|
for (int i = points_prev.size() - internal_vertices; i < points_prev.size(); i++) {
|
|
|
|
|
Vector2 tuv = mtx.xform(uv_create_poly_prev[i]);
|
2021-09-23 14:58:43 +00:00
|
|
|
|
real_t dist = tuv.distance_to(mb->get_position());
|
2019-01-08 22:10:24 +00:00
|
|
|
|
if (dist < 8 && dist < closest_dist) {
|
|
|
|
|
closest = i;
|
|
|
|
|
closest_dist = dist;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
|
if (closest == -1) {
|
2019-01-08 22:10:24 +00:00
|
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2019-01-08 22:10:24 +00:00
|
|
|
|
|
2021-07-03 22:17:03 +00:00
|
|
|
|
uv_create_poly_prev.remove_at(closest);
|
|
|
|
|
uv_create_uv_prev.remove_at(closest);
|
2019-01-08 22:10:24 +00:00
|
|
|
|
if (uv_create_colors_prev.size()) {
|
2021-07-03 22:17:03 +00:00
|
|
|
|
uv_create_colors_prev.remove_at(closest);
|
2019-01-08 22:10:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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++) {
|
2020-02-17 21:06:54 +00:00
|
|
|
|
Vector<float> bonew = node->get_bone_weights(i);
|
2021-07-03 22:17:03 +00:00
|
|
|
|
bonew.remove_at(closest);
|
2019-01-08 22:10:24 +00:00
|
|
|
|
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);
|
2019-02-16 18:46:09 +00:00
|
|
|
|
undo_redo->add_do_method(this, "_update_polygon_editing_state");
|
|
|
|
|
undo_redo->add_undo_method(this, "_update_polygon_editing_state");
|
2022-08-13 21:21:24 +00:00
|
|
|
|
undo_redo->add_do_method(uv_edit_draw, "queue_redraw");
|
|
|
|
|
undo_redo->add_undo_method(uv_edit_draw, "queue_redraw");
|
2019-01-08 22:10:24 +00:00
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-07 20:44:21 +00:00
|
|
|
|
if (uv_move_current == UV_MODE_EDIT_POINT) {
|
2022-09-02 09:37:48 +00:00
|
|
|
|
if (mb->is_shift_pressed() && mb->is_command_or_control_pressed()) {
|
2014-07-07 20:44:21 +00:00
|
|
|
|
uv_move_current = UV_MODE_SCALE;
|
2021-04-24 20:33:50 +00:00
|
|
|
|
} else if (mb->is_shift_pressed()) {
|
2014-07-07 20:44:21 +00:00
|
|
|
|
uv_move_current = UV_MODE_MOVE;
|
2022-09-02 09:37:48 +00:00
|
|
|
|
} else if (mb->is_command_or_control_pressed()) {
|
2014-07-07 20:44:21 +00:00
|
|
|
|
uv_move_current = UV_MODE_ROTATE;
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2014-07-07 20:44:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (uv_move_current == UV_MODE_EDIT_POINT) {
|
2018-05-04 12:32:40 +00:00
|
|
|
|
point_drag_index = -1;
|
|
|
|
|
for (int i = 0; i < points_prev.size(); i++) {
|
|
|
|
|
Vector2 tuv = mtx.xform(points_prev[i]);
|
2021-09-23 14:58:43 +00:00
|
|
|
|
if (tuv.distance_to(mb->get_position()) < 8) {
|
2015-09-28 03:06:06 +00:00
|
|
|
|
uv_drag_from = tuv;
|
2018-05-04 12:32:40 +00:00
|
|
|
|
point_drag_index = i;
|
2014-07-07 20:44:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-04 12:32:40 +00:00
|
|
|
|
if (point_drag_index == -1) {
|
2014-07-07 20:44:21 +00:00
|
|
|
|
uv_drag = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-25 15:06:30 +00:00
|
|
|
|
|
2019-01-08 22:10:24 +00:00
|
|
|
|
if (uv_move_current == UV_MODE_ADD_POLYGON) {
|
|
|
|
|
int closest = -1;
|
2021-06-21 03:30:19 +00:00
|
|
|
|
real_t closest_dist = 1e20;
|
2018-02-25 15:06:30 +00:00
|
|
|
|
|
2018-05-04 12:32:40 +00:00
|
|
|
|
for (int i = 0; i < points_prev.size(); i++) {
|
|
|
|
|
Vector2 tuv = mtx.xform(points_prev[i]);
|
2021-09-23 14:58:43 +00:00
|
|
|
|
real_t dist = tuv.distance_to(mb->get_position());
|
2019-01-08 22:10:24 +00:00
|
|
|
|
if (dist < 8 && dist < closest_dist) {
|
|
|
|
|
closest = i;
|
|
|
|
|
closest_dist = dist;
|
2018-02-25 15:06:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-08 22:10:24 +00:00
|
|
|
|
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)"));
|
2020-03-06 17:00:16 +00:00
|
|
|
|
error->popup_centered();
|
2018-05-04 12:32:40 +00:00
|
|
|
|
} else {
|
2019-01-08 22:10:24 +00:00
|
|
|
|
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);
|
2019-01-11 00:19:01 +00:00
|
|
|
|
undo_redo->create_action(TTR("Add Custom Polygon"));
|
2019-01-08 22:10:24 +00:00
|
|
|
|
undo_redo->add_do_method(node, "set_polygons", polygons);
|
2019-01-11 00:19:01 +00:00
|
|
|
|
undo_redo->add_undo_method(node, "set_polygons", node->get_polygons());
|
2022-08-13 21:21:24 +00:00
|
|
|
|
undo_redo->add_do_method(uv_edit_draw, "queue_redraw");
|
|
|
|
|
undo_redo->add_undo_method(uv_edit_draw, "queue_redraw");
|
2019-01-08 22:10:24 +00:00
|
|
|
|
undo_redo->commit_action();
|
2018-05-04 12:32:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-08 22:10:24 +00:00
|
|
|
|
polygon_create.clear();
|
2022-02-01 18:19:13 +00:00
|
|
|
|
} else if (!polygon_create.has(closest)) {
|
2019-01-08 22:10:24 +00:00
|
|
|
|
//add temporarily if not exists
|
|
|
|
|
polygon_create.push_back(closest);
|
2018-02-25 15:06:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-08 22:10:24 +00:00
|
|
|
|
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--) {
|
2020-02-17 21:06:54 +00:00
|
|
|
|
Vector<int> points = polygons[i];
|
2019-01-08 22:10:24 +00:00
|
|
|
|
Vector<Vector2> polys;
|
|
|
|
|
polys.resize(points.size());
|
|
|
|
|
for (int j = 0; j < polys.size(); j++) {
|
|
|
|
|
int idx = points[j];
|
2020-05-14 14:41:43 +00:00
|
|
|
|
if (idx < 0 || idx >= points_prev.size()) {
|
2019-01-08 22:10:24 +00:00
|
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2019-01-08 22:10:24 +00:00
|
|
|
|
polys.write[j] = mtx.xform(points_prev[idx]);
|
|
|
|
|
}
|
2018-02-25 15:06:30 +00:00
|
|
|
|
|
2021-09-23 14:58:43 +00:00
|
|
|
|
if (Geometry2D::is_point_in_polygon(mb->get_position(), polys)) {
|
2019-01-08 22:10:24 +00:00
|
|
|
|
erase_index = i;
|
2018-02-25 15:06:30 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-08 22:10:24 +00:00
|
|
|
|
|
|
|
|
|
if (erase_index != -1) {
|
2021-07-03 22:17:03 +00:00
|
|
|
|
polygons.remove_at(erase_index);
|
2019-01-11 00:19:01 +00:00
|
|
|
|
undo_redo->create_action(TTR("Remove Custom Polygon"));
|
2019-01-08 22:10:24 +00:00
|
|
|
|
undo_redo->add_do_method(node, "set_polygons", polygons);
|
2019-01-11 00:19:01 +00:00
|
|
|
|
undo_redo->add_undo_method(node, "set_polygons", node->get_polygons());
|
2022-08-13 21:21:24 +00:00
|
|
|
|
undo_redo->add_do_method(uv_edit_draw, "queue_redraw");
|
|
|
|
|
undo_redo->add_undo_method(uv_edit_draw, "queue_redraw");
|
2019-01-08 22:10:24 +00:00
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
}
|
2018-02-25 15:06:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-02 14:00:35 +00:00
|
|
|
|
if (uv_move_current == UV_MODE_PAINT_WEIGHT || uv_move_current == UV_MODE_CLEAR_WEIGHT) {
|
|
|
|
|
int bone_selected = -1;
|
|
|
|
|
for (int i = 0; i < bone_scroll_vb->get_child_count(); i++) {
|
|
|
|
|
CheckBox *c = Object::cast_to<CheckBox>(bone_scroll_vb->get_child(i));
|
|
|
|
|
if (c && c->is_pressed()) {
|
|
|
|
|
bone_selected = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-04 12:32:40 +00:00
|
|
|
|
if (bone_selected != -1 && node->get_bone_weights(bone_selected).size() == points_prev.size()) {
|
2018-05-02 14:00:35 +00:00
|
|
|
|
prev_weights = node->get_bone_weights(bone_selected);
|
|
|
|
|
bone_painting = true;
|
|
|
|
|
bone_painting_bone = bone_selected;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-25 06:16:41 +00:00
|
|
|
|
} else {
|
|
|
|
|
if (uv_drag && !uv_create) {
|
|
|
|
|
if (uv_edit_mode[0]->is_pressed()) { // Edit UV.
|
|
|
|
|
undo_redo->create_action(TTR("Transform UV Map"));
|
|
|
|
|
undo_redo->add_do_method(node, "set_uv", node->get_uv());
|
|
|
|
|
undo_redo->add_undo_method(node, "set_uv", points_prev);
|
2022-08-13 21:21:24 +00:00
|
|
|
|
undo_redo->add_do_method(uv_edit_draw, "queue_redraw");
|
|
|
|
|
undo_redo->add_undo_method(uv_edit_draw, "queue_redraw");
|
2020-06-25 06:16:41 +00:00
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
} else if (uv_edit_mode[1]->is_pressed() && uv_move_current == UV_MODE_EDIT_POINT) { // Edit polygon.
|
|
|
|
|
undo_redo->create_action(TTR("Transform Polygon"));
|
|
|
|
|
undo_redo->add_do_method(node, "set_polygon", node->get_polygon());
|
|
|
|
|
undo_redo->add_undo_method(node, "set_polygon", points_prev);
|
2022-08-13 21:21:24 +00:00
|
|
|
|
undo_redo->add_do_method(uv_edit_draw, "queue_redraw");
|
|
|
|
|
undo_redo->add_undo_method(uv_edit_draw, "queue_redraw");
|
2020-06-25 06:16:41 +00:00
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
}
|
2018-05-02 14:00:35 +00:00
|
|
|
|
|
2020-06-25 06:16:41 +00:00
|
|
|
|
uv_drag = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bone_painting) {
|
|
|
|
|
undo_redo->create_action(TTR("Paint Bone Weights"));
|
|
|
|
|
undo_redo->add_do_method(node, "set_bone_weights", bone_painting_bone, node->get_bone_weights(bone_painting_bone));
|
|
|
|
|
undo_redo->add_undo_method(node, "set_bone_weights", bone_painting_bone, prev_weights);
|
2022-08-13 21:21:24 +00:00
|
|
|
|
undo_redo->add_do_method(uv_edit_draw, "queue_redraw");
|
|
|
|
|
undo_redo->add_undo_method(uv_edit_draw, "queue_redraw");
|
2019-01-11 00:19:01 +00:00
|
|
|
|
undo_redo->commit_action();
|
2020-06-25 06:16:41 +00:00
|
|
|
|
bone_painting = false;
|
2018-02-22 20:38:33 +00:00
|
|
|
|
}
|
2014-07-07 20:44:21 +00:00
|
|
|
|
}
|
2021-08-13 21:31:57 +00:00
|
|
|
|
} else if (mb->get_button_index() == MouseButton::RIGHT && mb->is_pressed()) {
|
2018-11-24 04:38:26 +00:00
|
|
|
|
_cancel_editing();
|
2018-02-22 20:38:33 +00:00
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
|
if (bone_painting) {
|
2018-05-02 14:00:35 +00:00
|
|
|
|
node->set_bone_weights(bone_painting_bone, prev_weights);
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2018-11-24 04:38:26 +00:00
|
|
|
|
|
2022-08-13 21:21:24 +00:00
|
|
|
|
uv_edit_draw->queue_redraw();
|
2014-07-07 20:44:21 +00:00
|
|
|
|
}
|
2017-05-20 15:38:03 +00:00
|
|
|
|
}
|
2014-07-07 20:44:21 +00:00
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
|
Ref<InputEventMouseMotion> mm = p_input;
|
2014-07-07 20:44:21 +00:00
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
|
if (mm.is_valid()) {
|
2022-01-13 16:19:15 +00:00
|
|
|
|
if (uv_drag) {
|
2017-06-03 08:54:24 +00:00
|
|
|
|
Vector2 uv_drag_to = mm->get_position();
|
2018-11-24 04:38:26 +00:00
|
|
|
|
uv_drag_to = snap_point(uv_drag_to); // FIXME: Only works correctly with 'UV_MODE_EDIT_POINT', it's imprecise with the rest.
|
2014-07-07 20:44:21 +00:00
|
|
|
|
Vector2 drag = mtx.affine_inverse().xform(uv_drag_to) - mtx.affine_inverse().xform(uv_drag_from);
|
|
|
|
|
|
|
|
|
|
switch (uv_move_current) {
|
2018-02-22 20:38:33 +00:00
|
|
|
|
case UV_MODE_CREATE: {
|
|
|
|
|
if (uv_create) {
|
2021-09-23 14:58:43 +00:00
|
|
|
|
uv_create_to = mtx.affine_inverse().xform(snap_point(mm->get_position()));
|
2018-02-22 20:38:33 +00:00
|
|
|
|
}
|
|
|
|
|
} break;
|
2014-07-07 20:44:21 +00:00
|
|
|
|
case UV_MODE_EDIT_POINT: {
|
2020-02-17 21:06:54 +00:00
|
|
|
|
Vector<Vector2> uv_new = points_prev;
|
2018-05-04 12:32:40 +00:00
|
|
|
|
uv_new.set(point_drag_index, uv_new[point_drag_index] + drag);
|
2018-02-22 20:38:33 +00:00
|
|
|
|
|
|
|
|
|
if (uv_edit_mode[0]->is_pressed()) { //edit uv
|
|
|
|
|
node->set_uv(uv_new);
|
2018-02-25 15:06:30 +00:00
|
|
|
|
} else if (uv_edit_mode[1]->is_pressed()) { //edit polygon
|
2018-02-22 20:38:33 +00:00
|
|
|
|
node->set_polygon(uv_new);
|
|
|
|
|
}
|
2014-07-07 20:44:21 +00:00
|
|
|
|
} break;
|
|
|
|
|
case UV_MODE_MOVE: {
|
2020-02-17 21:06:54 +00:00
|
|
|
|
Vector<Vector2> uv_new = points_prev;
|
2020-05-14 14:41:43 +00:00
|
|
|
|
for (int i = 0; i < uv_new.size(); i++) {
|
2014-07-07 20:44:21 +00:00
|
|
|
|
uv_new.set(i, uv_new[i] + drag);
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2014-07-07 20:44:21 +00:00
|
|
|
|
|
2018-02-22 20:38:33 +00:00
|
|
|
|
if (uv_edit_mode[0]->is_pressed()) { //edit uv
|
|
|
|
|
node->set_uv(uv_new);
|
2018-02-25 15:06:30 +00:00
|
|
|
|
} else if (uv_edit_mode[1]->is_pressed()) { //edit polygon
|
2018-02-22 20:38:33 +00:00
|
|
|
|
node->set_polygon(uv_new);
|
|
|
|
|
}
|
2014-07-07 20:44:21 +00:00
|
|
|
|
} break;
|
|
|
|
|
case UV_MODE_ROTATE: {
|
|
|
|
|
Vector2 center;
|
2020-02-17 21:06:54 +00:00
|
|
|
|
Vector<Vector2> uv_new = points_prev;
|
2014-07-07 20:44:21 +00:00
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
|
for (int i = 0; i < uv_new.size(); i++) {
|
2018-05-04 12:32:40 +00:00
|
|
|
|
center += points_prev[i];
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2014-07-07 20:44:21 +00:00
|
|
|
|
center /= uv_new.size();
|
|
|
|
|
|
2021-06-21 03:30:19 +00:00
|
|
|
|
real_t angle = (uv_drag_from - mtx.xform(center)).normalized().angle_to((uv_drag_to - mtx.xform(center)).normalized());
|
2014-07-07 20:44:21 +00:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < uv_new.size(); i++) {
|
2018-05-04 12:32:40 +00:00
|
|
|
|
Vector2 rel = points_prev[i] - center;
|
2014-07-07 20:44:21 +00:00
|
|
|
|
rel = rel.rotated(angle);
|
|
|
|
|
uv_new.set(i, center + rel);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-22 20:38:33 +00:00
|
|
|
|
if (uv_edit_mode[0]->is_pressed()) { //edit uv
|
|
|
|
|
node->set_uv(uv_new);
|
2018-02-25 15:06:30 +00:00
|
|
|
|
} else if (uv_edit_mode[1]->is_pressed()) { //edit polygon
|
2018-02-22 20:38:33 +00:00
|
|
|
|
node->set_polygon(uv_new);
|
|
|
|
|
}
|
2014-07-07 20:44:21 +00:00
|
|
|
|
} break;
|
|
|
|
|
case UV_MODE_SCALE: {
|
|
|
|
|
Vector2 center;
|
2020-02-17 21:06:54 +00:00
|
|
|
|
Vector<Vector2> uv_new = points_prev;
|
2014-07-07 20:44:21 +00:00
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
|
for (int i = 0; i < uv_new.size(); i++) {
|
2018-05-04 12:32:40 +00:00
|
|
|
|
center += points_prev[i];
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2014-07-07 20:44:21 +00:00
|
|
|
|
center /= uv_new.size();
|
|
|
|
|
|
2021-06-21 03:30:19 +00:00
|
|
|
|
real_t from_dist = uv_drag_from.distance_to(mtx.xform(center));
|
|
|
|
|
real_t to_dist = uv_drag_to.distance_to(mtx.xform(center));
|
2020-05-14 14:41:43 +00:00
|
|
|
|
if (from_dist < 2) {
|
2014-07-07 20:44:21 +00:00
|
|
|
|
break;
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2014-07-07 20:44:21 +00:00
|
|
|
|
|
2021-06-21 03:30:19 +00:00
|
|
|
|
real_t scale = to_dist / from_dist;
|
2014-07-07 20:44:21 +00:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < uv_new.size(); i++) {
|
2018-05-04 12:32:40 +00:00
|
|
|
|
Vector2 rel = points_prev[i] - center;
|
2014-07-07 20:44:21 +00:00
|
|
|
|
rel = rel * scale;
|
|
|
|
|
uv_new.set(i, center + rel);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-22 20:38:33 +00:00
|
|
|
|
if (uv_edit_mode[0]->is_pressed()) { //edit uv
|
|
|
|
|
node->set_uv(uv_new);
|
2018-02-25 15:06:30 +00:00
|
|
|
|
} else if (uv_edit_mode[1]->is_pressed()) { //edit polygon
|
2018-02-22 20:38:33 +00:00
|
|
|
|
node->set_polygon(uv_new);
|
|
|
|
|
}
|
2014-07-07 20:44:21 +00:00
|
|
|
|
} break;
|
2018-11-24 04:38:26 +00:00
|
|
|
|
case UV_MODE_PAINT_WEIGHT:
|
|
|
|
|
case UV_MODE_CLEAR_WEIGHT: {
|
2021-09-23 14:58:43 +00:00
|
|
|
|
bone_paint_pos = mm->get_position();
|
2018-11-24 04:38:26 +00:00
|
|
|
|
} break;
|
2019-04-09 15:08:36 +00:00
|
|
|
|
default: {
|
|
|
|
|
}
|
2014-07-07 20:44:21 +00:00
|
|
|
|
}
|
2018-05-02 14:00:35 +00:00
|
|
|
|
|
|
|
|
|
if (bone_painting) {
|
2020-02-17 21:06:54 +00:00
|
|
|
|
Vector<float> painted_weights = node->get_bone_weights(bone_painting_bone);
|
2018-05-02 14:00:35 +00:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
int pc = painted_weights.size();
|
2021-06-21 03:30:19 +00:00
|
|
|
|
real_t amount = bone_paint_strength->get_value();
|
|
|
|
|
real_t radius = bone_paint_radius->get_value() * EDSCALE;
|
2018-05-02 14:00:35 +00:00
|
|
|
|
|
|
|
|
|
if (uv_mode == UV_MODE_CLEAR_WEIGHT) {
|
|
|
|
|
amount = -amount;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-17 21:06:54 +00:00
|
|
|
|
float *w = painted_weights.ptrw();
|
|
|
|
|
const float *r = prev_weights.ptr();
|
|
|
|
|
const Vector2 *rv = points_prev.ptr();
|
2018-05-02 14:00:35 +00:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < pc; i++) {
|
|
|
|
|
if (mtx.xform(rv[i]).distance_to(bone_paint_pos) < radius) {
|
|
|
|
|
w[i] = CLAMP(r[i] + amount, 0, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
node->set_bone_weights(bone_painting_bone, painted_weights);
|
|
|
|
|
}
|
2018-11-24 04:38:26 +00:00
|
|
|
|
|
2022-08-13 21:21:24 +00:00
|
|
|
|
uv_edit_draw->queue_redraw();
|
2018-11-24 04:38:26 +00:00
|
|
|
|
CanvasItemEditor::get_singleton()->update_viewport();
|
2019-01-08 22:10:24 +00:00
|
|
|
|
} else if (polygon_create.size()) {
|
2021-09-23 14:58:43 +00:00
|
|
|
|
uv_create_to = mtx.affine_inverse().xform(mm->get_position());
|
2022-08-13 21:21:24 +00:00
|
|
|
|
uv_edit_draw->queue_redraw();
|
2018-05-02 14:00:35 +00:00
|
|
|
|
} else if (uv_mode == UV_MODE_PAINT_WEIGHT || uv_mode == UV_MODE_CLEAR_WEIGHT) {
|
2021-09-23 14:58:43 +00:00
|
|
|
|
bone_paint_pos = mm->get_position();
|
2022-08-13 21:21:24 +00:00
|
|
|
|
uv_edit_draw->queue_redraw();
|
2014-07-07 20:44:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-01 20:49:39 +00:00
|
|
|
|
|
|
|
|
|
Ref<InputEventMagnifyGesture> magnify_gesture = p_input;
|
|
|
|
|
if (magnify_gesture.is_valid()) {
|
|
|
|
|
uv_zoom->set_value(uv_zoom->get_value() * magnify_gesture->get_factor());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ref<InputEventPanGesture> pan_gesture = p_input;
|
|
|
|
|
if (pan_gesture.is_valid()) {
|
|
|
|
|
uv_hscroll->set_value(uv_hscroll->get_value() + uv_hscroll->get_page() * pan_gesture->get_delta().x / 8);
|
|
|
|
|
uv_vscroll->set_value(uv_vscroll->get_value() + uv_vscroll->get_page() * pan_gesture->get_delta().y / 8);
|
|
|
|
|
}
|
2014-07-07 20:44:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-19 16:50:51 +00:00
|
|
|
|
void Polygon2DEditor::_uv_pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event) {
|
2022-01-13 16:19:15 +00:00
|
|
|
|
uv_hscroll->set_value(uv_hscroll->get_value() - p_scroll_vec.x);
|
|
|
|
|
uv_vscroll->set_value(uv_vscroll->get_value() - p_scroll_vec.y);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-19 16:50:51 +00:00
|
|
|
|
void Polygon2DEditor::_uv_zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputEvent> p_event) {
|
|
|
|
|
uv_zoom->set_value(uv_zoom->get_value() * p_zoom_factor);
|
2022-01-13 16:19:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-21 03:30:19 +00:00
|
|
|
|
void Polygon2DEditor::_uv_scroll_changed(real_t) {
|
2020-05-14 14:41:43 +00:00
|
|
|
|
if (updating_uv_scroll) {
|
2014-07-07 20:44:21 +00:00
|
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2014-07-07 20:44:21 +00:00
|
|
|
|
|
2017-01-04 04:16:14 +00:00
|
|
|
|
uv_draw_ofs.x = uv_hscroll->get_value();
|
|
|
|
|
uv_draw_ofs.y = uv_vscroll->get_value();
|
|
|
|
|
uv_draw_zoom = uv_zoom->get_value();
|
2022-08-13 21:21:24 +00:00
|
|
|
|
uv_edit_draw->queue_redraw();
|
2014-07-07 20:44:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Polygon2DEditor::_uv_draw() {
|
2020-05-14 14:41:43 +00:00
|
|
|
|
if (!uv_edit->is_visible() || !_get_node()) {
|
2018-11-24 04:38:26 +00:00
|
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2018-11-24 04:38:26 +00:00
|
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
|
Ref<Texture2D> base_tex = node->get_texture();
|
2020-05-14 14:41:43 +00:00
|
|
|
|
if (base_tex.is_null()) {
|
2014-07-07 20:44:21 +00:00
|
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2014-07-07 20:44:21 +00:00
|
|
|
|
|
2018-05-03 20:29:15 +00:00
|
|
|
|
String warning;
|
|
|
|
|
|
2017-01-11 03:52:51 +00:00
|
|
|
|
Transform2D mtx;
|
2022-04-24 21:59:24 +00:00
|
|
|
|
mtx.columns[2] = -uv_draw_ofs;
|
2014-07-07 20:44:21 +00:00
|
|
|
|
mtx.scale_basis(Vector2(uv_draw_zoom, uv_draw_zoom));
|
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
|
RS::get_singleton()->canvas_item_add_set_transform(uv_edit_draw->get_canvas_item(), mtx);
|
2014-07-07 20:44:21 +00:00
|
|
|
|
uv_edit_draw->draw_texture(base_tex, Point2());
|
2020-03-27 18:21:27 +00:00
|
|
|
|
RS::get_singleton()->canvas_item_add_set_transform(uv_edit_draw->get_canvas_item(), Transform2D());
|
2014-07-07 20:44:21 +00:00
|
|
|
|
|
2015-09-28 03:06:06 +00:00
|
|
|
|
if (snap_show_grid) {
|
2018-11-24 04:38:26 +00:00
|
|
|
|
Color grid_color = Color(1.0, 1.0, 1.0, 0.15);
|
2015-09-28 03:06:06 +00:00
|
|
|
|
Size2 s = uv_edit_draw->get_size();
|
2017-09-01 20:33:39 +00:00
|
|
|
|
int last_cell = 0;
|
2015-09-28 03:06:06 +00:00
|
|
|
|
|
|
|
|
|
if (snap_step.x != 0) {
|
|
|
|
|
for (int i = 0; i < s.width; i++) {
|
|
|
|
|
int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(i, 0)).x - snap_offset.x) / snap_step.x));
|
2020-05-14 14:41:43 +00:00
|
|
|
|
if (i == 0) {
|
2015-09-28 03:06:06 +00:00
|
|
|
|
last_cell = cell;
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
|
|
|
|
if (last_cell != cell) {
|
2019-07-08 23:49:43 +00:00
|
|
|
|
uv_edit_draw->draw_line(Point2(i, 0), Point2(i, s.height), grid_color, Math::round(EDSCALE));
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2015-09-28 03:06:06 +00:00
|
|
|
|
last_cell = cell;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (snap_step.y != 0) {
|
|
|
|
|
for (int i = 0; i < s.height; i++) {
|
|
|
|
|
int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(0, i)).y - snap_offset.y) / snap_step.y));
|
2020-05-14 14:41:43 +00:00
|
|
|
|
if (i == 0) {
|
2015-09-28 03:06:06 +00:00
|
|
|
|
last_cell = cell;
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
|
|
|
|
if (last_cell != cell) {
|
2019-07-08 23:49:43 +00:00
|
|
|
|
uv_edit_draw->draw_line(Point2(0, i), Point2(s.width, i), grid_color, Math::round(EDSCALE));
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2015-09-28 03:06:06 +00:00
|
|
|
|
last_cell = cell;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-08 22:10:24 +00:00
|
|
|
|
Array polygons = node->get_polygons();
|
|
|
|
|
|
2020-02-17 21:06:54 +00:00
|
|
|
|
Vector<Vector2> uvs;
|
2018-02-25 15:06:30 +00:00
|
|
|
|
if (uv_edit_mode[0]->is_pressed()) { //edit uv
|
2018-02-22 20:38:33 +00:00
|
|
|
|
uvs = node->get_uv();
|
2018-02-25 15:06:30 +00:00
|
|
|
|
} else { //edit polygon
|
2018-02-22 20:38:33 +00:00
|
|
|
|
uvs = node->get_polygon();
|
2018-02-25 15:06:30 +00:00
|
|
|
|
}
|
2018-02-22 20:38:33 +00:00
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
|
const float *weight_r = nullptr;
|
2018-05-02 14:00:35 +00:00
|
|
|
|
|
|
|
|
|
if (uv_edit_mode[3]->is_pressed()) {
|
|
|
|
|
int bone_selected = -1;
|
|
|
|
|
for (int i = 0; i < bone_scroll_vb->get_child_count(); i++) {
|
|
|
|
|
CheckBox *c = Object::cast_to<CheckBox>(bone_scroll_vb->get_child(i));
|
|
|
|
|
if (c && c->is_pressed()) {
|
|
|
|
|
bone_selected = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bone_selected != -1 && node->get_bone_weights(bone_selected).size() == uvs.size()) {
|
2020-02-17 21:06:54 +00:00
|
|
|
|
weight_r = node->get_bone_weights(bone_selected).ptr();
|
2018-05-02 14:00:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-18 20:18:57 +00:00
|
|
|
|
// All UV points are sharp, so use the sharp handle icon
|
2021-07-17 21:22:52 +00:00
|
|
|
|
Ref<Texture2D> handle = get_theme_icon(SNAME("EditorPathSharpHandle"), SNAME("EditorIcons"));
|
2014-07-07 20:44:21 +00:00
|
|
|
|
|
2018-11-24 04:38:26 +00:00
|
|
|
|
Color poly_line_color = Color(0.9, 0.5, 0.5);
|
2019-02-13 14:37:35 +00:00
|
|
|
|
if (polygons.size() || polygon_create.size()) {
|
|
|
|
|
poly_line_color.a *= 0.25;
|
|
|
|
|
}
|
2019-01-08 22:10:24 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
2018-11-24 04:38:26 +00:00
|
|
|
|
Color prev_color = Color(0.5, 0.5, 0.5);
|
2019-04-25 13:51:27 +00:00
|
|
|
|
Rect2 rect;
|
2014-07-07 20:44:21 +00:00
|
|
|
|
|
2019-01-08 22:10:24 +00:00
|
|
|
|
int uv_draw_max = uvs.size();
|
|
|
|
|
|
2019-02-13 14:37:35 +00:00
|
|
|
|
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++) {
|
|
|
|
|
int next = uv_draw_max > 0 ? (i + 1) % uv_draw_max : 0;
|
|
|
|
|
|
2022-03-06 20:39:19 +00:00
|
|
|
|
if (i < uv_draw_max && uv_drag && uv_move_current == UV_MODE_EDIT_POINT && EDITOR_GET("editors/polygon_editor/show_previous_outline")) {
|
2019-06-25 01:24:07 +00:00
|
|
|
|
uv_edit_draw->draw_line(mtx.xform(points_prev[i]), mtx.xform(points_prev[next]), prev_color, Math::round(EDSCALE));
|
2019-02-13 14:37:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector2 next_point = uvs[next];
|
|
|
|
|
if (uv_create && i == uvs.size() - 1) {
|
|
|
|
|
next_point = uv_create_to;
|
|
|
|
|
}
|
2022-02-16 12:56:32 +00:00
|
|
|
|
if (i < uv_draw_max) { // If using or creating polygons, do not show outline (will show polygons instead).
|
2019-06-25 01:24:07 +00:00
|
|
|
|
uv_edit_draw->draw_line(mtx.xform(uvs[i]), mtx.xform(next_point), poly_line_color, Math::round(EDSCALE));
|
2019-02-13 14:37:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-08 22:10:24 +00:00
|
|
|
|
for (int i = 0; i < polygons.size(); i++) {
|
2020-02-17 21:06:54 +00:00
|
|
|
|
Vector<int> points = polygons[i];
|
2019-01-08 22:10:24 +00:00
|
|
|
|
Vector<Vector2> polypoints;
|
2019-02-12 20:10:08 +00:00
|
|
|
|
for (int j = 0; j < points.size(); j++) {
|
|
|
|
|
int next = (j + 1) % points.size();
|
2019-01-08 22:10:24 +00:00
|
|
|
|
|
2019-02-12 20:10:08 +00:00
|
|
|
|
int idx = points[j];
|
2019-01-08 22:10:24 +00:00
|
|
|
|
int idx_next = points[next];
|
2020-05-14 14:41:43 +00:00
|
|
|
|
if (idx < 0 || idx >= uvs.size()) {
|
2019-01-08 22:10:24 +00:00
|
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2019-01-08 22:10:24 +00:00
|
|
|
|
polypoints.push_back(mtx.xform(uvs[idx]));
|
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
|
if (idx_next < 0 || idx_next >= uvs.size()) {
|
2019-01-08 22:10:24 +00:00
|
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2019-06-25 01:24:07 +00:00
|
|
|
|
uv_edit_draw->draw_line(mtx.xform(uvs[idx]), mtx.xform(uvs[idx_next]), polygon_line_color, Math::round(EDSCALE));
|
2019-01-08 22:10:24 +00:00
|
|
|
|
}
|
|
|
|
|
if (points.size() >= 3) {
|
|
|
|
|
uv_edit_draw->draw_polygon(polypoints, polygon_fill_color);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-07 20:44:21 +00:00
|
|
|
|
for (int i = 0; i < uvs.size(); i++) {
|
2020-02-17 21:06:54 +00:00
|
|
|
|
if (weight_r) {
|
2018-05-02 14:00:35 +00:00
|
|
|
|
Vector2 draw_pos = mtx.xform(uvs[i]);
|
|
|
|
|
float weight = weight_r[i];
|
2019-07-08 23:49:43 +00:00
|
|
|
|
uv_edit_draw->draw_rect(Rect2(draw_pos - Vector2(2, 2) * EDSCALE, Vector2(5, 5) * EDSCALE), Color(weight, weight, weight, 1.0), Math::round(EDSCALE));
|
2018-05-02 14:00:35 +00:00
|
|
|
|
} else {
|
2019-01-08 22:10:24 +00:00
|
|
|
|
if (i < uv_draw_max) {
|
|
|
|
|
uv_edit_draw->draw_texture(handle, mtx.xform(uvs[i]) - handle->get_size() * 0.5);
|
|
|
|
|
} else {
|
2019-08-18 20:18:57 +00:00
|
|
|
|
// Internal vertex
|
|
|
|
|
uv_edit_draw->draw_texture(handle, mtx.xform(uvs[i]) - handle->get_size() * 0.5, Color(0.6, 0.8, 1));
|
2019-01-08 22:10:24 +00:00
|
|
|
|
}
|
2018-05-02 14:00:35 +00:00
|
|
|
|
}
|
2014-07-07 20:44:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-08 22:10:24 +00:00
|
|
|
|
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;
|
2019-06-25 01:24:07 +00:00
|
|
|
|
uv_edit_draw->draw_line(mtx.xform(from), mtx.xform(to), polygon_line_color, Math::round(EDSCALE));
|
2019-01-08 22:10:24 +00:00
|
|
|
|
}
|
2018-02-25 15:06:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-02 14:00:35 +00:00
|
|
|
|
if (uv_mode == UV_MODE_PAINT_WEIGHT || uv_mode == UV_MODE_CLEAR_WEIGHT) {
|
2018-05-03 20:29:15 +00:00
|
|
|
|
NodePath bone_path;
|
|
|
|
|
for (int i = 0; i < bone_scroll_vb->get_child_count(); i++) {
|
|
|
|
|
CheckBox *c = Object::cast_to<CheckBox>(bone_scroll_vb->get_child(i));
|
|
|
|
|
if (c && c->is_pressed()) {
|
|
|
|
|
bone_path = node->get_bone_path(i);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//draw skeleton
|
|
|
|
|
NodePath skeleton_path = node->get_skeleton();
|
|
|
|
|
if (node->has_node(skeleton_path)) {
|
|
|
|
|
Skeleton2D *skeleton = Object::cast_to<Skeleton2D>(node->get_node(skeleton_path));
|
|
|
|
|
if (skeleton) {
|
|
|
|
|
for (int i = 0; i < skeleton->get_bone_count(); i++) {
|
|
|
|
|
Bone2D *bone = skeleton->get_bone(i);
|
2020-05-14 14:41:43 +00:00
|
|
|
|
if (bone->get_rest() == Transform2D(0, 0, 0, 0, 0, 0)) {
|
2018-05-03 20:29:15 +00:00
|
|
|
|
continue; //not set
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2018-05-03 20:29:15 +00:00
|
|
|
|
|
|
|
|
|
bool current = bone_path == skeleton->get_path_to(bone);
|
|
|
|
|
|
2018-11-23 01:22:16 +00:00
|
|
|
|
bool found_child = false;
|
|
|
|
|
|
2018-05-03 20:29:15 +00:00
|
|
|
|
for (int j = 0; j < bone->get_child_count(); j++) {
|
2018-11-23 01:22:16 +00:00
|
|
|
|
Bone2D *n = Object::cast_to<Bone2D>(bone->get_child(j));
|
2020-05-14 14:41:43 +00:00
|
|
|
|
if (!n) {
|
2018-05-03 20:29:15 +00:00
|
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
|
}
|
2018-05-03 20:29:15 +00:00
|
|
|
|
|
2018-11-23 01:22:16 +00:00
|
|
|
|
found_child = true;
|
2018-05-03 20:29:15 +00:00
|
|
|
|
|
2018-11-23 01:22:16 +00:00
|
|
|
|
Transform2D bone_xform = node->get_global_transform().affine_inverse() * (skeleton->get_global_transform() * bone->get_skeleton_rest());
|
|
|
|
|
Transform2D endpoint_xform = bone_xform * n->get_transform();
|
2018-05-03 20:29:15 +00:00
|
|
|
|
|
2018-11-23 01:22:16 +00:00
|
|
|
|
Color color = current ? Color(1, 1, 1) : Color(0.5, 0.5, 0.5);
|
2019-07-08 23:49:43 +00:00
|
|
|
|
uv_edit_draw->draw_line(mtx.xform(bone_xform.get_origin()), mtx.xform(endpoint_xform.get_origin()), Color(0, 0, 0), Math::round((current ? 5 : 4) * EDSCALE));
|
|
|
|
|
uv_edit_draw->draw_line(mtx.xform(bone_xform.get_origin()), mtx.xform(endpoint_xform.get_origin()), color, Math::round((current ? 3 : 2) * EDSCALE));
|
2018-11-23 01:22:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!found_child) {
|
|
|
|
|
//draw normally
|
|
|
|
|
Transform2D bone_xform = node->get_global_transform().affine_inverse() * (skeleton->get_global_transform() * bone->get_skeleton_rest());
|
New and improved IK system for Skeleton2D
This PR and commit adds a new IK system for 2D with the Skeleton2D node
that adds several new IK solvers, a way to control bones in a Skeleton2D
node similar to that in Skeleton3D. It also adds additional changes
and functionality.
This work was sponsored by GSoC 2020 and TwistedTwigleg.
Full list of changes:
* Adds a SkeletonModifier2D resource
* This resource is the base where all IK code is written and executed
* Has a function for clamping angles, since it is so commonly used
* Modifiers are unique when duplicated so it works with instancing
* Adds a SkeletonModifierStack2D resource
* This resource manages a series of SkeletonModification2Ds
* This is what the Skeleton2D directly interfaces with to make IK possible
* Adds SkeletonModifier2D resources for LookAt, CCDIK, FABRIK, Jiggle, and TwoBoneIK
* Each modification is in its own file
* There is also a SkeletonModifier2D resource that acts as a stack for using multiple stacks together
* Adds a PhysicalBone2D node
* Works similar to the PhysicalBone3D node, but uses a RigidBody2D node
* Changes to Skeleton2D listed below:
* Skeleton2D now holds a single SkeletonModificationStack2D for IK
* Skeleton2D now has a local_pose_override, which overrides the Bone2D position similar to how the overrides work in Skeleton3D
* Changes to Bone2D listed below:
* The default_length property has been changed to length. Length is the length of the bone to its child bone node
* New bone_angle property, which is the angle the bone has to its first child bone node
* Bone2D caches its transform when not modified by IK for IK interpolation purposes
* Bone2D draws its own editor gizmo, though this is stated to change in the future
* Changes to CanvasItemEditor listed below:
* Bone2D gizmo drawing code removed
* The 2D IK code is removed. Now Bone2D is the only bone system for 2D
* Transform2D now has a looking_at function for rotating to face a position
* Two new node notifications: NOTIFICATION_EDITOR_PRE_SAVE and NOTIFICATION_EDITOR_POST_SAVE
* These notifications only are called in the editor right before and after saving a scene
* Needed for not saving the IK position when executing IK in the editor
* Documentation for all the changes listed above.
2020-08-03 18:02:24 +00:00
|
|
|
|
Transform2D endpoint_xform = bone_xform * Transform2D(0, Vector2(bone->get_length(), 0));
|
2018-11-23 01:22:16 +00:00
|
|
|
|
|
|
|
|
|
Color color = current ? Color(1, 1, 1) : Color(0.5, 0.5, 0.5);
|
2019-07-08 23:49:43 +00:00
|
|
|
|
uv_edit_draw->draw_line(mtx.xform(bone_xform.get_origin()), mtx.xform(endpoint_xform.get_origin()), Color(0, 0, 0), Math::round((current ? 5 : 4) * EDSCALE));
|
|
|
|
|
uv_edit_draw->draw_line(mtx.xform(bone_xform.get_origin()), mtx.xform(endpoint_xform.get_origin()), color, Math::round((current ? 3 : 2) * EDSCALE));
|
2018-05-03 20:29:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//draw paint circle
|
2018-05-02 14:00:35 +00:00
|
|
|
|
uv_edit_draw->draw_circle(bone_paint_pos, bone_paint_radius->get_value() * EDSCALE, Color(1, 1, 1, 0.1));
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 14:49:18 +00:00
|
|
|
|
rect.position = -uv_edit_draw->get_size();
|
|
|
|
|
rect.size = uv_edit_draw->get_size() * 2.0 + base_tex->get_size() * uv_draw_zoom;
|
2020-01-14 11:25:55 +00:00
|
|
|
|
|
2014-07-07 20:44:21 +00:00
|
|
|
|
updating_uv_scroll = true;
|
2020-01-14 11:25:55 +00:00
|
|
|
|
|
2017-06-03 22:25:13 +00:00
|
|
|
|
uv_hscroll->set_min(rect.position.x);
|
|
|
|
|
uv_hscroll->set_max(rect.position.x + rect.size.x);
|
2018-11-24 04:38:26 +00:00
|
|
|
|
if (ABS(rect.position.x - (rect.position.x + rect.size.x)) <= uv_edit_draw->get_size().x) {
|
|
|
|
|
uv_hscroll->hide();
|
|
|
|
|
} else {
|
|
|
|
|
uv_hscroll->show();
|
|
|
|
|
uv_hscroll->set_page(uv_edit_draw->get_size().x);
|
|
|
|
|
uv_hscroll->set_value(uv_draw_ofs.x);
|
|
|
|
|
}
|
2014-07-07 20:44:21 +00:00
|
|
|
|
|
2017-06-03 22:25:13 +00:00
|
|
|
|
uv_vscroll->set_min(rect.position.y);
|
|
|
|
|
uv_vscroll->set_max(rect.position.y + rect.size.y);
|
2018-11-24 04:38:26 +00:00
|
|
|
|
if (ABS(rect.position.y - (rect.position.y + rect.size.y)) <= uv_edit_draw->get_size().y) {
|
|
|
|
|
uv_vscroll->hide();
|
|
|
|
|
} else {
|
|
|
|
|
uv_vscroll->show();
|
|
|
|
|
uv_vscroll->set_page(uv_edit_draw->get_size().y);
|
|
|
|
|
uv_vscroll->set_value(uv_draw_ofs.y);
|
|
|
|
|
}
|
2020-01-14 11:25:55 +00:00
|
|
|
|
|
|
|
|
|
Size2 hmin = uv_hscroll->get_combined_minimum_size();
|
|
|
|
|
Size2 vmin = uv_vscroll->get_combined_minimum_size();
|
|
|
|
|
|
|
|
|
|
// Avoid scrollbar overlapping.
|
2020-12-22 16:24:29 +00:00
|
|
|
|
uv_hscroll->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, uv_vscroll->is_visible() ? -vmin.width : 0);
|
|
|
|
|
uv_vscroll->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, uv_hscroll->is_visible() ? -hmin.height : 0);
|
2020-01-14 11:25:55 +00:00
|
|
|
|
|
2014-07-07 20:44:21 +00:00
|
|
|
|
updating_uv_scroll = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Polygon2DEditor::_bind_methods() {
|
2018-05-02 14:00:35 +00:00
|
|
|
|
ClassDB::bind_method(D_METHOD("_update_bone_list"), &Polygon2DEditor::_update_bone_list);
|
2019-02-16 18:46:09 +00:00
|
|
|
|
ClassDB::bind_method(D_METHOD("_update_polygon_editing_state"), &Polygon2DEditor::_update_polygon_editing_state);
|
2015-09-28 03:06:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector2 Polygon2DEditor::snap_point(Vector2 p_target) const {
|
|
|
|
|
if (use_snap) {
|
2017-09-18 21:44:04 +00:00
|
|
|
|
p_target.x = Math::snap_scalar(snap_offset.x * uv_draw_zoom - uv_draw_ofs.x, snap_step.x * uv_draw_zoom, p_target.x);
|
|
|
|
|
p_target.y = Math::snap_scalar(snap_offset.y * uv_draw_zoom - uv_draw_ofs.y, snap_step.y * uv_draw_zoom, p_target.y);
|
2015-09-28 03:06:06 +00:00
|
|
|
|
}
|
2014-07-07 20:44:21 +00:00
|
|
|
|
|
2015-09-28 03:06:06 +00:00
|
|
|
|
return p_target;
|
2014-07-07 20:44:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 16:49:05 +00:00
|
|
|
|
Polygon2DEditor::Polygon2DEditor() {
|
2018-11-24 04:38:26 +00:00
|
|
|
|
snap_offset = EditorSettings::get_singleton()->get_project_metadata("polygon_2d_uv_editor", "snap_offset", Vector2());
|
2023-02-21 16:02:24 +00:00
|
|
|
|
// A power-of-two value works better as a default grid size.
|
|
|
|
|
snap_step = EditorSettings::get_singleton()->get_project_metadata("polygon_2d_uv_editor", "snap_step", Vector2(8, 8));
|
2018-11-24 04:38:26 +00:00
|
|
|
|
use_snap = EditorSettings::get_singleton()->get_project_metadata("polygon_2d_uv_editor", "snap_enabled", false);
|
|
|
|
|
snap_show_grid = EditorSettings::get_singleton()->get_project_metadata("polygon_2d_uv_editor", "show_grid", false);
|
2015-09-28 03:06:06 +00:00
|
|
|
|
|
2020-06-19 18:49:04 +00:00
|
|
|
|
button_uv = memnew(Button);
|
|
|
|
|
button_uv->set_flat(true);
|
2014-07-07 20:44:21 +00:00
|
|
|
|
add_child(button_uv);
|
2022-08-25 10:42:17 +00:00
|
|
|
|
button_uv->set_tooltip_text(TTR("Open Polygon 2D UV editor."));
|
2022-07-28 20:56:41 +00:00
|
|
|
|
button_uv->connect("pressed", callable_mp(this, &Polygon2DEditor::_menu_option).bind(MODE_EDIT_UV));
|
2014-07-07 20:44:21 +00:00
|
|
|
|
|
|
|
|
|
uv_mode = UV_MODE_EDIT_POINT;
|
|
|
|
|
uv_edit = memnew(AcceptDialog);
|
|
|
|
|
add_child(uv_edit);
|
2016-05-04 01:25:37 +00:00
|
|
|
|
uv_edit->set_title(TTR("Polygon 2D UV Editor"));
|
2023-01-21 11:25:29 +00:00
|
|
|
|
uv_edit->connect("canceled", callable_mp(this, &Polygon2DEditor::_uv_edit_popup_hide));
|
2014-07-07 20:44:21 +00:00
|
|
|
|
|
|
|
|
|
VBoxContainer *uv_main_vb = memnew(VBoxContainer);
|
|
|
|
|
uv_edit->add_child(uv_main_vb);
|
|
|
|
|
HBoxContainer *uv_mode_hb = memnew(HBoxContainer);
|
2018-02-22 20:38:33 +00:00
|
|
|
|
|
2021-06-17 22:03:09 +00:00
|
|
|
|
uv_edit_group.instantiate();
|
2018-02-22 20:38:33 +00:00
|
|
|
|
|
2020-06-19 18:49:04 +00:00
|
|
|
|
uv_edit_mode[0] = memnew(Button);
|
2018-02-22 20:38:33 +00:00
|
|
|
|
uv_mode_hb->add_child(uv_edit_mode[0]);
|
|
|
|
|
uv_edit_mode[0]->set_toggle_mode(true);
|
2020-06-19 18:49:04 +00:00
|
|
|
|
uv_edit_mode[1] = memnew(Button);
|
2018-02-22 20:38:33 +00:00
|
|
|
|
uv_mode_hb->add_child(uv_edit_mode[1]);
|
|
|
|
|
uv_edit_mode[1]->set_toggle_mode(true);
|
2020-06-19 18:49:04 +00:00
|
|
|
|
uv_edit_mode[2] = memnew(Button);
|
2018-02-25 15:06:30 +00:00
|
|
|
|
uv_mode_hb->add_child(uv_edit_mode[2]);
|
|
|
|
|
uv_edit_mode[2]->set_toggle_mode(true);
|
2020-06-19 18:49:04 +00:00
|
|
|
|
uv_edit_mode[3] = memnew(Button);
|
2018-05-02 14:00:35 +00:00
|
|
|
|
uv_mode_hb->add_child(uv_edit_mode[3]);
|
|
|
|
|
uv_edit_mode[3]->set_toggle_mode(true);
|
2018-02-22 20:38:33 +00:00
|
|
|
|
|
|
|
|
|
uv_edit_mode[0]->set_text(TTR("UV"));
|
|
|
|
|
uv_edit_mode[0]->set_pressed(true);
|
2019-01-08 22:10:24 +00:00
|
|
|
|
uv_edit_mode[1]->set_text(TTR("Points"));
|
|
|
|
|
uv_edit_mode[2]->set_text(TTR("Polygons"));
|
2018-05-02 14:00:35 +00:00
|
|
|
|
uv_edit_mode[3]->set_text(TTR("Bones"));
|
2018-02-22 20:38:33 +00:00
|
|
|
|
|
|
|
|
|
uv_edit_mode[0]->set_button_group(uv_edit_group);
|
|
|
|
|
uv_edit_mode[1]->set_button_group(uv_edit_group);
|
2018-02-25 15:06:30 +00:00
|
|
|
|
uv_edit_mode[2]->set_button_group(uv_edit_group);
|
2018-05-02 14:00:35 +00:00
|
|
|
|
uv_edit_mode[3]->set_button_group(uv_edit_group);
|
2018-02-22 20:38:33 +00:00
|
|
|
|
|
2022-07-28 20:56:41 +00:00
|
|
|
|
uv_edit_mode[0]->connect("pressed", callable_mp(this, &Polygon2DEditor::_uv_edit_mode_select).bind(0));
|
|
|
|
|
uv_edit_mode[1]->connect("pressed", callable_mp(this, &Polygon2DEditor::_uv_edit_mode_select).bind(1));
|
|
|
|
|
uv_edit_mode[2]->connect("pressed", callable_mp(this, &Polygon2DEditor::_uv_edit_mode_select).bind(2));
|
|
|
|
|
uv_edit_mode[3]->connect("pressed", callable_mp(this, &Polygon2DEditor::_uv_edit_mode_select).bind(3));
|
2018-02-22 20:38:33 +00:00
|
|
|
|
|
|
|
|
|
uv_mode_hb->add_child(memnew(VSeparator));
|
|
|
|
|
|
2014-07-07 20:44:21 +00:00
|
|
|
|
uv_main_vb->add_child(uv_mode_hb);
|
|
|
|
|
for (int i = 0; i < UV_MODE_MAX; i++) {
|
2020-06-19 18:49:04 +00:00
|
|
|
|
uv_button[i] = memnew(Button);
|
2020-10-29 19:53:41 +00:00
|
|
|
|
uv_button[i]->set_flat(true);
|
2014-07-07 20:44:21 +00:00
|
|
|
|
uv_button[i]->set_toggle_mode(true);
|
|
|
|
|
uv_mode_hb->add_child(uv_button[i]);
|
2022-07-28 20:56:41 +00:00
|
|
|
|
uv_button[i]->connect("pressed", callable_mp(this, &Polygon2DEditor::_uv_mode).bind(i));
|
2014-07-07 20:44:21 +00:00
|
|
|
|
uv_button[i]->set_focus_mode(FOCUS_NONE);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 10:42:17 +00:00
|
|
|
|
uv_button[UV_MODE_CREATE]->set_tooltip_text(TTR("Create Polygon"));
|
|
|
|
|
uv_button[UV_MODE_CREATE_INTERNAL]->set_tooltip_text(TTR("Create Internal Vertex"));
|
|
|
|
|
uv_button[UV_MODE_REMOVE_INTERNAL]->set_tooltip_text(TTR("Remove Internal Vertex"));
|
|
|
|
|
uv_button[UV_MODE_EDIT_POINT]->set_tooltip_text(TTR("Move Points") + "\n" + TTR("Ctrl: Rotate") + "\n" + TTR("Shift: Move All") + "\n" + TTR("Shift+Ctrl: Scale"));
|
|
|
|
|
uv_button[UV_MODE_MOVE]->set_tooltip_text(TTR("Move Polygon"));
|
|
|
|
|
uv_button[UV_MODE_ROTATE]->set_tooltip_text(TTR("Rotate Polygon"));
|
|
|
|
|
uv_button[UV_MODE_SCALE]->set_tooltip_text(TTR("Scale Polygon"));
|
|
|
|
|
uv_button[UV_MODE_ADD_POLYGON]->set_tooltip_text(TTR("Create a custom polygon. Enables custom polygon rendering."));
|
|
|
|
|
uv_button[UV_MODE_REMOVE_POLYGON]->set_tooltip_text(TTR("Remove a custom polygon. If none remain, custom polygon rendering is disabled."));
|
|
|
|
|
uv_button[UV_MODE_PAINT_WEIGHT]->set_tooltip_text(TTR("Paint weights with specified intensity."));
|
|
|
|
|
uv_button[UV_MODE_CLEAR_WEIGHT]->set_tooltip_text(TTR("Unpaint weights with specified intensity."));
|
2019-01-08 22:10:24 +00:00
|
|
|
|
|
|
|
|
|
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);
|
2018-05-02 14:00:35 +00:00
|
|
|
|
|
|
|
|
|
bone_paint_strength = memnew(HSlider);
|
|
|
|
|
uv_mode_hb->add_child(bone_paint_strength);
|
|
|
|
|
bone_paint_strength->set_custom_minimum_size(Size2(75 * EDSCALE, 0));
|
|
|
|
|
bone_paint_strength->set_v_size_flags(SIZE_SHRINK_CENTER);
|
|
|
|
|
bone_paint_strength->set_min(0);
|
|
|
|
|
bone_paint_strength->set_max(1);
|
|
|
|
|
bone_paint_strength->set_step(0.01);
|
|
|
|
|
bone_paint_strength->set_value(0.5);
|
|
|
|
|
|
2018-11-24 04:38:26 +00:00
|
|
|
|
bone_paint_radius_label = memnew(Label(TTR("Radius:")));
|
2018-05-02 14:00:35 +00:00
|
|
|
|
uv_mode_hb->add_child(bone_paint_radius_label);
|
|
|
|
|
bone_paint_radius = memnew(SpinBox);
|
|
|
|
|
uv_mode_hb->add_child(bone_paint_radius);
|
|
|
|
|
|
|
|
|
|
bone_paint_strength->hide();
|
|
|
|
|
bone_paint_radius->hide();
|
|
|
|
|
bone_paint_radius_label->hide();
|
|
|
|
|
bone_paint_radius->set_min(1);
|
|
|
|
|
bone_paint_radius->set_max(100);
|
|
|
|
|
bone_paint_radius->set_step(1);
|
|
|
|
|
bone_paint_radius->set_value(32);
|
|
|
|
|
|
2018-11-24 04:38:26 +00:00
|
|
|
|
HSplitContainer *uv_main_hsc = memnew(HSplitContainer);
|
|
|
|
|
uv_main_vb->add_child(uv_main_hsc);
|
|
|
|
|
uv_main_hsc->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
uv_edit_draw = memnew(Panel);
|
|
|
|
|
uv_main_hsc->add_child(uv_edit_draw);
|
2014-07-07 20:44:21 +00:00
|
|
|
|
uv_edit_draw->set_h_size_flags(SIZE_EXPAND_FILL);
|
2018-11-24 04:38:26 +00:00
|
|
|
|
uv_edit_draw->set_custom_minimum_size(Size2(200, 200) * EDSCALE);
|
2020-01-31 03:15:52 +00:00
|
|
|
|
|
|
|
|
|
Control *space = memnew(Control);
|
|
|
|
|
uv_mode_hb->add_child(space);
|
|
|
|
|
space->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
|
2014-07-07 20:44:21 +00:00
|
|
|
|
uv_menu = memnew(MenuButton);
|
|
|
|
|
uv_mode_hb->add_child(uv_menu);
|
2016-05-04 01:25:37 +00:00
|
|
|
|
uv_menu->set_text(TTR("Edit"));
|
2020-01-31 03:15:52 +00:00
|
|
|
|
uv_menu->get_popup()->add_item(TTR("Copy Polygon to UV"), UVEDIT_POLYGON_TO_UV);
|
|
|
|
|
uv_menu->get_popup()->add_item(TTR("Copy UV to Polygon"), UVEDIT_UV_TO_POLYGON);
|
2014-07-07 20:44:21 +00:00
|
|
|
|
uv_menu->get_popup()->add_separator();
|
2016-05-04 01:25:37 +00:00
|
|
|
|
uv_menu->get_popup()->add_item(TTR("Clear UV"), UVEDIT_UV_CLEAR);
|
2018-05-03 20:29:15 +00:00
|
|
|
|
uv_menu->get_popup()->add_separator();
|
|
|
|
|
uv_menu->get_popup()->add_item(TTR("Grid Settings"), UVEDIT_GRID_SETTINGS);
|
2020-02-21 22:26:13 +00:00
|
|
|
|
uv_menu->get_popup()->connect("id_pressed", callable_mp(this, &Polygon2DEditor::_menu_option));
|
2015-09-28 03:06:06 +00:00
|
|
|
|
|
|
|
|
|
uv_mode_hb->add_child(memnew(VSeparator));
|
|
|
|
|
|
2020-06-19 18:49:04 +00:00
|
|
|
|
b_snap_enable = memnew(Button);
|
|
|
|
|
b_snap_enable->set_flat(true);
|
2015-09-28 03:06:06 +00:00
|
|
|
|
uv_mode_hb->add_child(b_snap_enable);
|
2016-05-04 01:25:37 +00:00
|
|
|
|
b_snap_enable->set_text(TTR("Snap"));
|
2015-09-28 03:06:06 +00:00
|
|
|
|
b_snap_enable->set_focus_mode(FOCUS_NONE);
|
|
|
|
|
b_snap_enable->set_toggle_mode(true);
|
|
|
|
|
b_snap_enable->set_pressed(use_snap);
|
2022-08-25 10:42:17 +00:00
|
|
|
|
b_snap_enable->set_tooltip_text(TTR("Enable Snap"));
|
2020-02-21 17:28:45 +00:00
|
|
|
|
b_snap_enable->connect("toggled", callable_mp(this, &Polygon2DEditor::_set_use_snap));
|
2015-09-28 03:06:06 +00:00
|
|
|
|
|
2020-06-19 18:49:04 +00:00
|
|
|
|
b_snap_grid = memnew(Button);
|
|
|
|
|
b_snap_grid->set_flat(true);
|
2015-09-28 03:06:06 +00:00
|
|
|
|
uv_mode_hb->add_child(b_snap_grid);
|
2016-05-04 01:25:37 +00:00
|
|
|
|
b_snap_grid->set_text(TTR("Grid"));
|
2015-09-28 03:06:06 +00:00
|
|
|
|
b_snap_grid->set_focus_mode(FOCUS_NONE);
|
|
|
|
|
b_snap_grid->set_toggle_mode(true);
|
|
|
|
|
b_snap_grid->set_pressed(snap_show_grid);
|
2022-08-25 10:42:17 +00:00
|
|
|
|
b_snap_grid->set_tooltip_text(TTR("Show Grid"));
|
2020-02-21 17:28:45 +00:00
|
|
|
|
b_snap_grid->connect("toggled", callable_mp(this, &Polygon2DEditor::_set_show_grid));
|
2015-09-28 03:06:06 +00:00
|
|
|
|
|
2018-05-03 20:29:15 +00:00
|
|
|
|
grid_settings = memnew(AcceptDialog);
|
|
|
|
|
grid_settings->set_title(TTR("Configure Grid:"));
|
|
|
|
|
add_child(grid_settings);
|
|
|
|
|
VBoxContainer *grid_settings_vb = memnew(VBoxContainer);
|
|
|
|
|
grid_settings->add_child(grid_settings_vb);
|
2015-09-28 03:06:06 +00:00
|
|
|
|
|
|
|
|
|
SpinBox *sb_off_x = memnew(SpinBox);
|
|
|
|
|
sb_off_x->set_min(-256);
|
|
|
|
|
sb_off_x->set_max(256);
|
|
|
|
|
sb_off_x->set_step(1);
|
2017-01-04 04:16:14 +00:00
|
|
|
|
sb_off_x->set_value(snap_offset.x);
|
2015-09-28 03:06:06 +00:00
|
|
|
|
sb_off_x->set_suffix("px");
|
2020-02-21 17:28:45 +00:00
|
|
|
|
sb_off_x->connect("value_changed", callable_mp(this, &Polygon2DEditor::_set_snap_off_x));
|
2018-05-03 20:29:15 +00:00
|
|
|
|
grid_settings_vb->add_margin_child(TTR("Grid Offset X:"), sb_off_x);
|
2015-09-28 03:06:06 +00:00
|
|
|
|
|
|
|
|
|
SpinBox *sb_off_y = memnew(SpinBox);
|
|
|
|
|
sb_off_y->set_min(-256);
|
|
|
|
|
sb_off_y->set_max(256);
|
|
|
|
|
sb_off_y->set_step(1);
|
2017-01-04 04:16:14 +00:00
|
|
|
|
sb_off_y->set_value(snap_offset.y);
|
2015-09-28 03:06:06 +00:00
|
|
|
|
sb_off_y->set_suffix("px");
|
2020-02-21 17:28:45 +00:00
|
|
|
|
sb_off_y->connect("value_changed", callable_mp(this, &Polygon2DEditor::_set_snap_off_y));
|
2018-05-03 20:29:15 +00:00
|
|
|
|
grid_settings_vb->add_margin_child(TTR("Grid Offset Y:"), sb_off_y);
|
2015-09-28 03:06:06 +00:00
|
|
|
|
|
|
|
|
|
SpinBox *sb_step_x = memnew(SpinBox);
|
|
|
|
|
sb_step_x->set_min(-256);
|
|
|
|
|
sb_step_x->set_max(256);
|
|
|
|
|
sb_step_x->set_step(1);
|
2017-01-04 04:16:14 +00:00
|
|
|
|
sb_step_x->set_value(snap_step.x);
|
2015-09-28 03:06:06 +00:00
|
|
|
|
sb_step_x->set_suffix("px");
|
2020-02-21 17:28:45 +00:00
|
|
|
|
sb_step_x->connect("value_changed", callable_mp(this, &Polygon2DEditor::_set_snap_step_x));
|
2018-05-03 20:29:15 +00:00
|
|
|
|
grid_settings_vb->add_margin_child(TTR("Grid Step X:"), sb_step_x);
|
2015-09-28 03:06:06 +00:00
|
|
|
|
|
|
|
|
|
SpinBox *sb_step_y = memnew(SpinBox);
|
|
|
|
|
sb_step_y->set_min(-256);
|
|
|
|
|
sb_step_y->set_max(256);
|
|
|
|
|
sb_step_y->set_step(1);
|
2017-01-04 04:16:14 +00:00
|
|
|
|
sb_step_y->set_value(snap_step.y);
|
2015-09-28 03:06:06 +00:00
|
|
|
|
sb_step_y->set_suffix("px");
|
2020-02-21 17:28:45 +00:00
|
|
|
|
sb_step_y->connect("value_changed", callable_mp(this, &Polygon2DEditor::_set_snap_step_y));
|
2018-05-03 20:29:15 +00:00
|
|
|
|
grid_settings_vb->add_margin_child(TTR("Grid Step Y:"), sb_step_y);
|
2015-09-28 03:06:06 +00:00
|
|
|
|
|
2014-07-07 20:44:21 +00:00
|
|
|
|
uv_mode_hb->add_child(memnew(VSeparator));
|
2017-01-12 21:27:27 +00:00
|
|
|
|
uv_icon_zoom = memnew(TextureRect);
|
2018-11-24 04:38:26 +00:00
|
|
|
|
uv_icon_zoom->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);
|
2015-09-28 03:06:06 +00:00
|
|
|
|
uv_mode_hb->add_child(uv_icon_zoom);
|
2014-07-07 20:44:21 +00:00
|
|
|
|
uv_zoom = memnew(HSlider);
|
|
|
|
|
uv_zoom->set_min(0.01);
|
2019-12-14 19:48:47 +00:00
|
|
|
|
uv_zoom->set_max(16);
|
2017-01-04 04:16:14 +00:00
|
|
|
|
uv_zoom->set_value(1);
|
2014-07-07 20:44:21 +00:00
|
|
|
|
uv_zoom->set_step(0.01);
|
2018-05-02 14:00:35 +00:00
|
|
|
|
uv_zoom->set_v_size_flags(SIZE_SHRINK_CENTER);
|
|
|
|
|
|
2014-07-07 20:44:21 +00:00
|
|
|
|
uv_mode_hb->add_child(uv_zoom);
|
2018-05-03 20:29:15 +00:00
|
|
|
|
uv_zoom->set_custom_minimum_size(Size2(80 * EDSCALE, 0));
|
2014-07-07 20:44:21 +00:00
|
|
|
|
uv_zoom_value = memnew(SpinBox);
|
|
|
|
|
uv_zoom->share(uv_zoom_value);
|
|
|
|
|
uv_zoom_value->set_custom_minimum_size(Size2(50, 0));
|
|
|
|
|
uv_mode_hb->add_child(uv_zoom_value);
|
2020-02-21 17:28:45 +00:00
|
|
|
|
uv_zoom->connect("value_changed", callable_mp(this, &Polygon2DEditor::_uv_scroll_changed));
|
2014-07-07 20:44:21 +00:00
|
|
|
|
|
|
|
|
|
uv_vscroll = memnew(VScrollBar);
|
2018-11-24 04:38:26 +00:00
|
|
|
|
uv_vscroll->set_step(0.001);
|
|
|
|
|
uv_edit_draw->add_child(uv_vscroll);
|
2020-02-21 17:28:45 +00:00
|
|
|
|
uv_vscroll->connect("value_changed", callable_mp(this, &Polygon2DEditor::_uv_scroll_changed));
|
2014-07-07 20:44:21 +00:00
|
|
|
|
uv_hscroll = memnew(HScrollBar);
|
2018-11-24 04:38:26 +00:00
|
|
|
|
uv_hscroll->set_step(0.001);
|
|
|
|
|
uv_edit_draw->add_child(uv_hscroll);
|
2020-02-21 17:28:45 +00:00
|
|
|
|
uv_hscroll->connect("value_changed", callable_mp(this, &Polygon2DEditor::_uv_scroll_changed));
|
2014-07-07 20:44:21 +00:00
|
|
|
|
|
2018-05-02 14:00:35 +00:00
|
|
|
|
bone_scroll_main_vb = memnew(VBoxContainer);
|
|
|
|
|
bone_scroll_main_vb->hide();
|
2018-11-24 04:38:26 +00:00
|
|
|
|
bone_scroll_main_vb->set_custom_minimum_size(Size2(150 * EDSCALE, 0));
|
2018-05-03 20:29:15 +00:00
|
|
|
|
sync_bones = memnew(Button(TTR("Sync Bones to Polygon")));
|
2018-05-02 14:00:35 +00:00
|
|
|
|
bone_scroll_main_vb->add_child(sync_bones);
|
2018-11-24 04:38:26 +00:00
|
|
|
|
sync_bones->set_h_size_flags(0);
|
2020-02-21 17:28:45 +00:00
|
|
|
|
sync_bones->connect("pressed", callable_mp(this, &Polygon2DEditor::_sync_bones));
|
2018-11-24 04:38:26 +00:00
|
|
|
|
uv_main_hsc->add_child(bone_scroll_main_vb);
|
2018-05-02 14:00:35 +00:00
|
|
|
|
bone_scroll = memnew(ScrollContainer);
|
|
|
|
|
bone_scroll->set_v_scroll(true);
|
|
|
|
|
bone_scroll->set_h_scroll(false);
|
|
|
|
|
bone_scroll_main_vb->add_child(bone_scroll);
|
|
|
|
|
bone_scroll->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
bone_scroll_vb = memnew(VBoxContainer);
|
|
|
|
|
bone_scroll->add_child(bone_scroll_vb);
|
|
|
|
|
|
2022-01-19 18:59:12 +00:00
|
|
|
|
uv_panner.instantiate();
|
2023-01-19 16:50:51 +00:00
|
|
|
|
uv_panner->set_callbacks(callable_mp(this, &Polygon2DEditor::_uv_pan_callback), callable_mp(this, &Polygon2DEditor::_uv_zoom_callback));
|
2022-01-19 18:59:12 +00:00
|
|
|
|
|
2020-02-21 17:28:45 +00:00
|
|
|
|
uv_edit_draw->connect("draw", callable_mp(this, &Polygon2DEditor::_uv_draw));
|
|
|
|
|
uv_edit_draw->connect("gui_input", callable_mp(this, &Polygon2DEditor::_uv_input));
|
2022-01-19 18:59:12 +00:00
|
|
|
|
uv_edit_draw->connect("focus_exited", callable_mp(uv_panner.ptr(), &ViewPanner::release_pan_key));
|
|
|
|
|
uv_edit_draw->set_focus_mode(FOCUS_CLICK);
|
2014-07-07 20:44:21 +00:00
|
|
|
|
uv_draw_zoom = 1.0;
|
2018-05-04 12:32:40 +00:00
|
|
|
|
point_drag_index = -1;
|
2014-07-07 20:44:21 +00:00
|
|
|
|
uv_drag = false;
|
2018-02-25 15:06:30 +00:00
|
|
|
|
uv_create = false;
|
2014-07-07 20:44:21 +00:00
|
|
|
|
updating_uv_scroll = false;
|
2018-05-02 14:00:35 +00:00
|
|
|
|
bone_painting = false;
|
2014-07-07 20:44:21 +00:00
|
|
|
|
|
|
|
|
|
error = memnew(AcceptDialog);
|
|
|
|
|
add_child(error);
|
|
|
|
|
|
2017-01-09 18:50:08 +00:00
|
|
|
|
uv_edit_draw->set_clip_contents(true);
|
2014-07-07 20:44:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-27 09:36:51 +00:00
|
|
|
|
Polygon2DEditorPlugin::Polygon2DEditorPlugin() :
|
|
|
|
|
AbstractPolygon2DEditorPlugin(memnew(Polygon2DEditor), "Polygon2D") {
|
2014-07-07 20:44:21 +00:00
|
|
|
|
}
|