2014-07-07 22:44:21 +02:00
|
|
|
|
/*************************************************************************/
|
2016-06-18 14:46:12 +02:00
|
|
|
|
/* polygon_2d_editor_plugin.cpp */
|
2014-07-07 22:44:21 +02:00
|
|
|
|
/*************************************************************************/
|
|
|
|
|
/* This file is part of: */
|
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
|
/* https://godotengine.org */
|
2014-07-07 22:44:21 +02:00
|
|
|
|
/*************************************************************************/
|
2018-01-01 14:40:08 +01:00
|
|
|
|
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
|
|
|
|
|
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-07-07 22:44:21 +02:00
|
|
|
|
/* */
|
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
|
/* the following conditions: */
|
|
|
|
|
/* */
|
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
|
/* */
|
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
|
2014-07-07 22:44:21 +02:00
|
|
|
|
#include "polygon_2d_editor_plugin.h"
|
2017-01-16 08:04:19 +01:00
|
|
|
|
|
2014-07-07 22:44:21 +02:00
|
|
|
|
#include "canvas_item_editor_plugin.h"
|
2017-03-05 14:21:25 +01:00
|
|
|
|
#include "editor/editor_settings.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
|
#include "os/file_access.h"
|
2014-07-07 22:44:21 +02:00
|
|
|
|
#include "os/input.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
|
#include "os/keyboard.h"
|
2018-05-02 16:00:35 +02:00
|
|
|
|
#include "scene/2d/skeleton_2d.h"
|
2017-09-06 18:41:14 +02:00
|
|
|
|
Node2D *Polygon2DEditor::_get_node() const {
|
|
|
|
|
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Polygon2DEditor::_set_node(Node *p_polygon) {
|
|
|
|
|
|
|
|
|
|
node = Object::cast_to<Polygon2D>(p_polygon);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector2 Polygon2DEditor::_get_offset(int p_idx) const {
|
|
|
|
|
|
|
|
|
|
return node->get_offset();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-07 22:44:21 +02:00
|
|
|
|
void Polygon2DEditor::_notification(int p_what) {
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
switch (p_what) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
|
|
|
|
case NOTIFICATION_READY: {
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
button_uv->set_icon(get_icon("Uv", "EditorIcons"));
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2018-02-22 21:38:33 +01:00
|
|
|
|
uv_button[UV_MODE_CREATE]->set_icon(get_icon("Add", "EditorIcons"));
|
2017-03-05 16:44:50 +01:00
|
|
|
|
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_ROTATE]->set_icon(get_icon("ToolRotate", "EditorIcons"));
|
|
|
|
|
uv_button[UV_MODE_SCALE]->set_icon(get_icon("ToolScale", "EditorIcons"));
|
2018-02-25 16:06:30 +01:00
|
|
|
|
uv_button[UV_MODE_ADD_SPLIT]->set_icon(get_icon("AddSplit", "EditorIcons"));
|
|
|
|
|
uv_button[UV_MODE_REMOVE_SPLIT]->set_icon(get_icon("DeleteSplit", "EditorIcons"));
|
2018-05-02 16:00:35 +02:00
|
|
|
|
uv_button[UV_MODE_PAINT_WEIGHT]->set_icon(get_icon("PaintVertex", "EditorIcons"));
|
|
|
|
|
uv_button[UV_MODE_CLEAR_WEIGHT]->set_icon(get_icon("UnpaintVertex", "EditorIcons"));
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
b_snap_grid->set_icon(get_icon("Grid", "EditorIcons"));
|
2017-09-17 22:52:41 +02:00
|
|
|
|
b_snap_enable->set_icon(get_icon("SnapGrid", "EditorIcons"));
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_icon_zoom->set_texture(get_icon("Zoom", "EditorIcons"));
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
|
|
|
|
} break;
|
2017-09-30 16:19:07 +02:00
|
|
|
|
case NOTIFICATION_PHYSICS_PROCESS: {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-02 16:00:35 +02:00
|
|
|
|
void Polygon2DEditor::_sync_bones() {
|
|
|
|
|
|
|
|
|
|
print_line("syncinc");
|
|
|
|
|
if (!node->has_node(node->get_skeleton())) {
|
|
|
|
|
error->set_text(TTR("The skeleton property of the Polygon2D does not point to a Skeleton2D node"));
|
|
|
|
|
error->popup_centered_minsize();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Node *sn = node->get_node(node->get_skeleton());
|
|
|
|
|
Skeleton2D *skeleton = Object::cast_to<Skeleton2D>(sn);
|
|
|
|
|
|
|
|
|
|
if (!skeleton) {
|
|
|
|
|
error->set_text(TTR("The skeleton property of the Polygon2D does not point to a Skeleton2D node"));
|
|
|
|
|
error->popup_centered_minsize();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Array prev_bones = node->call("_get_bones");
|
|
|
|
|
node->clear_bones();
|
|
|
|
|
|
|
|
|
|
print_line("bones in skeleton: " + itos(skeleton->get_bone_count()));
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < skeleton->get_bone_count(); i++) {
|
|
|
|
|
NodePath path = skeleton->get_path_to(skeleton->get_bone(i));
|
|
|
|
|
PoolVector<float> weights;
|
|
|
|
|
int wc = node->get_polygon().size();
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < prev_bones.size(); j += 2) {
|
|
|
|
|
NodePath pvp = prev_bones[j];
|
|
|
|
|
PoolVector<float> pv = prev_bones[j + 1];
|
|
|
|
|
if (pvp == path && pv.size() == wc) {
|
|
|
|
|
weights = pv;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (weights.size() == 0) { //create them
|
|
|
|
|
weights.resize(node->get_polygon().size());
|
|
|
|
|
PoolVector<float>::Write w = weights.write();
|
|
|
|
|
for (int j = 0; j < wc; j++) {
|
|
|
|
|
w[j] = 0.0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
node->add_bone(path, weights);
|
|
|
|
|
}
|
|
|
|
|
Array new_bones = node->call("_get_bones");
|
|
|
|
|
|
|
|
|
|
undo_redo->create_action(TTR("Sync bones"));
|
|
|
|
|
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(uv_edit_draw, "update");
|
|
|
|
|
undo_redo->add_undo_method(uv_edit_draw, "update");
|
|
|
|
|
undo_redo->add_do_method(this, "_update_bone_list");
|
|
|
|
|
undo_redo->add_undo_method(this, "_update_bone_list");
|
|
|
|
|
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;
|
|
|
|
|
bg.instance();
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
if (name == String()) {
|
|
|
|
|
name = "Bone " + itos(i);
|
|
|
|
|
}
|
|
|
|
|
cb->set_text(name);
|
|
|
|
|
cb->set_button_group(bg);
|
|
|
|
|
cb->set_meta("bone_path", np);
|
|
|
|
|
bone_scroll_vb->add_child(cb);
|
|
|
|
|
|
|
|
|
|
if (np == selected)
|
|
|
|
|
cb->set_pressed(true);
|
|
|
|
|
|
|
|
|
|
cb->connect("pressed", this, "_bone_paint_selected", varray(i));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uv_edit_draw->update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Polygon2DEditor::_bone_paint_selected(int p_index) {
|
|
|
|
|
uv_edit_draw->update();
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-22 21:38:33 +01:00
|
|
|
|
void Polygon2DEditor::_uv_edit_mode_select(int p_mode) {
|
|
|
|
|
|
2018-05-02 16:00:35 +02:00
|
|
|
|
if (p_mode == 0) { //uv
|
2018-02-22 21:38:33 +01:00
|
|
|
|
uv_button[UV_MODE_CREATE]->hide();
|
2018-02-25 16:06:30 +01:00
|
|
|
|
for (int i = UV_MODE_MOVE; i <= UV_MODE_SCALE; i++) {
|
|
|
|
|
uv_button[i]->show();
|
|
|
|
|
}
|
|
|
|
|
uv_button[UV_MODE_ADD_SPLIT]->hide();
|
|
|
|
|
uv_button[UV_MODE_REMOVE_SPLIT]->hide();
|
2018-05-02 16:00:35 +02:00
|
|
|
|
uv_button[UV_MODE_PAINT_WEIGHT]->hide();
|
|
|
|
|
uv_button[UV_MODE_CLEAR_WEIGHT]->hide();
|
2018-02-25 16:06:30 +01:00
|
|
|
|
_uv_mode(UV_MODE_EDIT_POINT);
|
|
|
|
|
|
2018-05-02 16:00:35 +02: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-02-25 16:06:30 +01:00
|
|
|
|
for (int i = 0; i <= UV_MODE_SCALE; i++) {
|
|
|
|
|
uv_button[i]->show();
|
|
|
|
|
}
|
|
|
|
|
uv_button[UV_MODE_ADD_SPLIT]->hide();
|
|
|
|
|
uv_button[UV_MODE_REMOVE_SPLIT]->hide();
|
2018-05-02 16:00:35 +02:00
|
|
|
|
uv_button[UV_MODE_PAINT_WEIGHT]->hide();
|
|
|
|
|
uv_button[UV_MODE_CLEAR_WEIGHT]->hide();
|
2018-02-25 16:06:30 +01:00
|
|
|
|
_uv_mode(UV_MODE_EDIT_POINT);
|
2018-05-02 16:00:35 +02: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-02-25 16:06:30 +01:00
|
|
|
|
for (int i = 0; i <= UV_MODE_SCALE; i++) {
|
|
|
|
|
uv_button[i]->hide();
|
|
|
|
|
}
|
|
|
|
|
uv_button[UV_MODE_ADD_SPLIT]->show();
|
|
|
|
|
uv_button[UV_MODE_REMOVE_SPLIT]->show();
|
2018-05-02 16:00:35 +02:00
|
|
|
|
uv_button[UV_MODE_PAINT_WEIGHT]->hide();
|
|
|
|
|
uv_button[UV_MODE_CLEAR_WEIGHT]->hide();
|
2018-02-25 16:06:30 +01:00
|
|
|
|
_uv_mode(UV_MODE_ADD_SPLIT);
|
2018-05-02 16:00:35 +02: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´
|
|
|
|
|
for (int i = 0; i <= UV_MODE_REMOVE_SPLIT; i++) {
|
|
|
|
|
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 21:38:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uv_edit_draw->update();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-07 22:44:21 +02:00
|
|
|
|
void Polygon2DEditor::_menu_option(int p_option) {
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
switch (p_option) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
|
|
|
|
case MODE_EDIT_UV: {
|
|
|
|
|
|
|
|
|
|
if (node->get_texture().is_null()) {
|
|
|
|
|
|
|
|
|
|
error->set_text("No texture in this polygon.\nSet a texture to be able to edit UV.");
|
2015-04-08 19:02:13 +02:00
|
|
|
|
error->popup_centered_minsize();
|
2014-07-07 22:44:21 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
|
PoolVector<Vector2> points = node->get_polygon();
|
|
|
|
|
PoolVector<Vector2> uvs = node->get_uv();
|
2017-03-05 16:44:50 +01:00
|
|
|
|
if (uvs.size() != points.size()) {
|
2016-05-04 03:25:37 +02:00
|
|
|
|
undo_redo->create_action(TTR("Create UV Map"));
|
2017-03-05 16:44:50 +01:00
|
|
|
|
undo_redo->add_do_method(node, "set_uv", points);
|
|
|
|
|
undo_redo->add_undo_method(node, "set_uv", uvs);
|
|
|
|
|
undo_redo->add_do_method(uv_edit_draw, "update");
|
|
|
|
|
undo_redo->add_undo_method(uv_edit_draw, "update");
|
2014-07-07 22:44:21 +02:00
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uv_edit->popup_centered_ratio(0.85);
|
|
|
|
|
} break;
|
|
|
|
|
case UVEDIT_POLYGON_TO_UV: {
|
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
|
PoolVector<Vector2> points = node->get_polygon();
|
2017-03-05 16:44:50 +01:00
|
|
|
|
if (points.size() == 0)
|
2014-07-07 22:44:21 +02:00
|
|
|
|
break;
|
2017-01-07 22:25:37 +01:00
|
|
|
|
PoolVector<Vector2> uvs = node->get_uv();
|
2016-05-04 03:25:37 +02:00
|
|
|
|
undo_redo->create_action(TTR("Create UV Map"));
|
2017-03-05 16:44:50 +01:00
|
|
|
|
undo_redo->add_do_method(node, "set_uv", points);
|
|
|
|
|
undo_redo->add_undo_method(node, "set_uv", uvs);
|
|
|
|
|
undo_redo->add_do_method(uv_edit_draw, "update");
|
|
|
|
|
undo_redo->add_undo_method(uv_edit_draw, "update");
|
2014-07-07 22:44:21 +02:00
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
case UVEDIT_UV_TO_POLYGON: {
|
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
|
PoolVector<Vector2> points = node->get_polygon();
|
|
|
|
|
PoolVector<Vector2> uvs = node->get_uv();
|
2017-03-05 16:44:50 +01:00
|
|
|
|
if (uvs.size() == 0)
|
2014-07-07 22:44:21 +02:00
|
|
|
|
break;
|
|
|
|
|
|
2016-05-04 03:25:37 +02:00
|
|
|
|
undo_redo->create_action(TTR("Create UV Map"));
|
2017-03-05 16:44:50 +01:00
|
|
|
|
undo_redo->add_do_method(node, "set_polygon", uvs);
|
|
|
|
|
undo_redo->add_undo_method(node, "set_polygon", points);
|
|
|
|
|
undo_redo->add_do_method(uv_edit_draw, "update");
|
|
|
|
|
undo_redo->add_undo_method(uv_edit_draw, "update");
|
2014-07-07 22:44:21 +02:00
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
case UVEDIT_UV_CLEAR: {
|
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
|
PoolVector<Vector2> uvs = node->get_uv();
|
2017-03-05 16:44:50 +01:00
|
|
|
|
if (uvs.size() == 0)
|
2014-07-07 22:44:21 +02:00
|
|
|
|
break;
|
2016-05-04 03:25:37 +02:00
|
|
|
|
undo_redo->create_action(TTR("Create UV Map"));
|
2017-03-05 16:44:50 +01:00
|
|
|
|
undo_redo->add_do_method(node, "set_uv", PoolVector<Vector2>());
|
|
|
|
|
undo_redo->add_undo_method(node, "set_uv", uvs);
|
|
|
|
|
undo_redo->add_do_method(uv_edit_draw, "update");
|
|
|
|
|
undo_redo->add_undo_method(uv_edit_draw, "update");
|
2014-07-07 22:44:21 +02:00
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
|
|
|
|
|
} break;
|
2018-05-03 22:29:15 +02:00
|
|
|
|
case UVEDIT_GRID_SETTINGS: {
|
|
|
|
|
grid_settings->popup_centered_minsize();
|
|
|
|
|
} break;
|
2017-09-06 18:41:14 +02:00
|
|
|
|
default: {
|
|
|
|
|
AbstractPolygon2DEditor::_menu_option(p_option);
|
|
|
|
|
} break;
|
2014-07-07 22:44:21 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
void Polygon2DEditor::_set_use_snap(bool p_use) {
|
|
|
|
|
use_snap = p_use;
|
2015-09-28 05:06:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
void Polygon2DEditor::_set_show_grid(bool p_show) {
|
|
|
|
|
snap_show_grid = p_show;
|
2015-09-28 05:06:06 +02:00
|
|
|
|
uv_edit_draw->update();
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
void Polygon2DEditor::_set_snap_off_x(float p_val) {
|
|
|
|
|
snap_offset.x = p_val;
|
2015-09-28 05:06:06 +02:00
|
|
|
|
uv_edit_draw->update();
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
void Polygon2DEditor::_set_snap_off_y(float p_val) {
|
|
|
|
|
snap_offset.y = p_val;
|
2015-09-28 05:06:06 +02:00
|
|
|
|
uv_edit_draw->update();
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
void Polygon2DEditor::_set_snap_step_x(float p_val) {
|
|
|
|
|
snap_step.x = p_val;
|
2015-09-28 05:06:06 +02:00
|
|
|
|
uv_edit_draw->update();
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
void Polygon2DEditor::_set_snap_step_y(float p_val) {
|
|
|
|
|
snap_step.y = p_val;
|
2015-09-28 05:06:06 +02:00
|
|
|
|
uv_edit_draw->update();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-07 22:44:21 +02:00
|
|
|
|
void Polygon2DEditor::_uv_mode(int p_mode) {
|
|
|
|
|
|
2018-02-25 16:06:30 +01:00
|
|
|
|
split_create = false;
|
|
|
|
|
uv_drag = false;
|
|
|
|
|
uv_create = false;
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_mode = UVMode(p_mode);
|
|
|
|
|
for (int i = 0; i < UV_MODE_MAX; i++) {
|
|
|
|
|
uv_button[i]->set_pressed(p_mode == i);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
|
void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
|
Transform2D mtx;
|
2017-03-05 16:44:50 +01:00
|
|
|
|
mtx.elements[2] = -uv_draw_ofs;
|
|
|
|
|
mtx.scale_basis(Vector2(uv_draw_zoom, uv_draw_zoom));
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
|
Ref<InputEventMouseButton> mb = p_input;
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
|
if (mb.is_valid()) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
|
if (mb->get_button_index() == BUTTON_LEFT) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
|
if (mb->is_pressed()) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-06-03 10:54:24 +02:00
|
|
|
|
uv_drag_from = Vector2(mb->get_position().x, mb->get_position().y);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_drag = true;
|
|
|
|
|
uv_prev = node->get_uv();
|
2018-02-22 21:38:33 +01:00
|
|
|
|
|
2018-02-25 16:06:30 +01:00
|
|
|
|
if (uv_edit_mode[0]->is_pressed()) { //edit uv
|
2018-02-22 21:38:33 +01:00
|
|
|
|
uv_prev = node->get_uv();
|
2018-02-25 16:06:30 +01:00
|
|
|
|
} else { //edit polygon
|
2018-02-22 21:38:33 +01:00
|
|
|
|
uv_prev = node->get_polygon();
|
2018-02-25 16:06:30 +01:00
|
|
|
|
}
|
2018-02-22 21:38:33 +01:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_move_current = uv_mode;
|
2018-02-22 21:38:33 +01:00
|
|
|
|
if (uv_move_current == UV_MODE_CREATE) {
|
|
|
|
|
|
|
|
|
|
if (!uv_create) {
|
|
|
|
|
uv_prev.resize(0);
|
|
|
|
|
Vector2 tuv = mtx.affine_inverse().xform(Vector2(mb->get_position().x, mb->get_position().y));
|
|
|
|
|
uv_prev.push_back(tuv);
|
|
|
|
|
uv_create_to = tuv;
|
|
|
|
|
uv_drag_index = 0;
|
|
|
|
|
uv_drag_from = tuv;
|
|
|
|
|
uv_drag = true;
|
|
|
|
|
uv_create = true;
|
|
|
|
|
uv_create_uv_prev = node->get_uv();
|
|
|
|
|
uv_create_poly_prev = node->get_polygon();
|
2018-05-02 16:00:35 +02:00
|
|
|
|
uv_create_bones_prev = node->call("_get_bones");
|
2018-02-25 16:06:30 +01:00
|
|
|
|
splits_prev = node->get_splits();
|
2018-02-22 21:38:33 +01:00
|
|
|
|
node->set_polygon(uv_prev);
|
|
|
|
|
node->set_uv(uv_prev);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
Vector2 tuv = mtx.affine_inverse().xform(Vector2(mb->get_position().x, mb->get_position().y));
|
|
|
|
|
|
|
|
|
|
if (uv_prev.size() > 3 && tuv.distance_to(uv_prev[0]) < 8) {
|
|
|
|
|
undo_redo->create_action(TTR("Create Polygon & UV"));
|
|
|
|
|
undo_redo->add_do_method(node, "set_uv", node->get_uv());
|
|
|
|
|
undo_redo->add_undo_method(node, "set_uv", uv_prev);
|
|
|
|
|
undo_redo->add_do_method(node, "set_polygon", node->get_polygon());
|
|
|
|
|
undo_redo->add_undo_method(node, "set_polygon", uv_prev);
|
2018-05-02 16:00:35 +02:00
|
|
|
|
undo_redo->add_do_method(node, "clear_bones");
|
|
|
|
|
undo_redo->add_undo_method(node, "_set_bones", node->call("_get_bones"));
|
2018-02-22 21:38:33 +01:00
|
|
|
|
undo_redo->add_do_method(uv_edit_draw, "update");
|
|
|
|
|
undo_redo->add_undo_method(uv_edit_draw, "update");
|
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
uv_drag = false;
|
|
|
|
|
uv_create = false;
|
|
|
|
|
_uv_mode(UV_MODE_EDIT_POINT);
|
|
|
|
|
} else {
|
|
|
|
|
uv_prev.push_back(tuv);
|
|
|
|
|
uv_drag_index = uv_prev.size() - 1;
|
|
|
|
|
uv_drag_from = tuv;
|
|
|
|
|
}
|
|
|
|
|
node->set_polygon(uv_prev);
|
|
|
|
|
node->set_uv(uv_prev);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
if (uv_move_current == UV_MODE_EDIT_POINT) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
|
if (mb->get_shift() && mb->get_command())
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_move_current = UV_MODE_SCALE;
|
2017-05-20 17:38:03 +02:00
|
|
|
|
else if (mb->get_shift())
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_move_current = UV_MODE_MOVE;
|
2017-05-20 17:38:03 +02:00
|
|
|
|
else if (mb->get_command())
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_move_current = UV_MODE_ROTATE;
|
2014-07-07 22:44:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
if (uv_move_current == UV_MODE_EDIT_POINT) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_drag_index = -1;
|
|
|
|
|
for (int i = 0; i < uv_prev.size(); i++) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
Vector2 tuv = mtx.xform(uv_prev[i]);
|
2017-06-03 10:54:24 +02:00
|
|
|
|
if (tuv.distance_to(Vector2(mb->get_position().x, mb->get_position().y)) < 8) {
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_drag_from = tuv;
|
|
|
|
|
uv_drag_index = i;
|
2014-07-07 22:44:21 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
if (uv_drag_index == -1) {
|
|
|
|
|
uv_drag = false;
|
2014-07-07 22:44:21 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-25 16:06:30 +01:00
|
|
|
|
|
|
|
|
|
if (uv_move_current == UV_MODE_ADD_SPLIT) {
|
|
|
|
|
|
|
|
|
|
int drag_index = -1;
|
|
|
|
|
drag_index = -1;
|
|
|
|
|
for (int i = 0; i < uv_prev.size(); i++) {
|
|
|
|
|
|
|
|
|
|
Vector2 tuv = mtx.xform(uv_prev[i]);
|
|
|
|
|
if (tuv.distance_to(Vector2(mb->get_position().x, mb->get_position().y)) < 8) {
|
|
|
|
|
drag_index = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (drag_index == -1) {
|
|
|
|
|
split_create = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (split_create) {
|
|
|
|
|
|
|
|
|
|
split_create = false;
|
|
|
|
|
if (drag_index < uv_drag_index) {
|
|
|
|
|
SWAP(drag_index, uv_drag_index);
|
|
|
|
|
}
|
|
|
|
|
bool valid = true;
|
|
|
|
|
if (drag_index == uv_drag_index) {
|
|
|
|
|
valid = false;
|
|
|
|
|
}
|
|
|
|
|
if (drag_index + 1 == uv_drag_index) {
|
|
|
|
|
//not a split,goes along the edge
|
|
|
|
|
valid = false;
|
|
|
|
|
}
|
|
|
|
|
if (drag_index == uv_prev.size() - 1 && uv_drag_index == 0) {
|
|
|
|
|
//not a split,goes along the edge
|
|
|
|
|
valid = false;
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < splits_prev.size(); i += 2) {
|
|
|
|
|
if (splits_prev[i] == uv_drag_index && splits_prev[i + 1] == drag_index) {
|
|
|
|
|
//already exists
|
|
|
|
|
valid = false;
|
|
|
|
|
}
|
|
|
|
|
if (splits_prev[i] > uv_drag_index && splits_prev[i + 1] > drag_index) {
|
|
|
|
|
//crossing
|
|
|
|
|
valid = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (splits_prev[i] < uv_drag_index && splits_prev[i + 1] < drag_index) {
|
|
|
|
|
//crossing opposite direction
|
|
|
|
|
valid = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (valid) {
|
|
|
|
|
|
|
|
|
|
splits_prev.push_back(uv_drag_index);
|
|
|
|
|
splits_prev.push_back(drag_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"));
|
|
|
|
|
error->popup_centered_minsize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
uv_drag_index = drag_index;
|
|
|
|
|
split_create = true;
|
|
|
|
|
uv_create_to = mtx.affine_inverse().xform(Vector2(mb->get_position().x, mb->get_position().y));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (uv_move_current == UV_MODE_REMOVE_SPLIT) {
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < splits_prev.size(); i += 2) {
|
|
|
|
|
if (splits_prev[i] < 0 || splits_prev[i] >= uv_prev.size())
|
|
|
|
|
continue;
|
|
|
|
|
if (splits_prev[i + 1] < 0 || splits_prev[i] >= uv_prev.size())
|
|
|
|
|
continue;
|
|
|
|
|
Vector2 e[2] = { mtx.xform(uv_prev[splits_prev[i]]), mtx.xform(uv_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();
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-02 16:00:35 +02: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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bone_selected != -1 && node->get_bone_weights(bone_selected).size() == uv_prev.size()) {
|
|
|
|
|
|
|
|
|
|
prev_weights = node->get_bone_weights(bone_selected);
|
|
|
|
|
bone_painting = true;
|
|
|
|
|
bone_painting_bone = bone_selected;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-22 21:38:33 +01:00
|
|
|
|
} else if (uv_drag && !uv_create) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2016-05-04 03:25:37 +02:00
|
|
|
|
undo_redo->create_action(TTR("Transform UV Map"));
|
2018-02-22 21:38:33 +01:00
|
|
|
|
|
|
|
|
|
if (uv_edit_mode[0]->is_pressed()) { //edit uv
|
|
|
|
|
undo_redo->add_do_method(node, "set_uv", node->get_uv());
|
|
|
|
|
undo_redo->add_undo_method(node, "set_uv", uv_prev);
|
2018-02-25 16:06:30 +01:00
|
|
|
|
} else if (uv_edit_mode[1]->is_pressed()) { //edit polygon
|
2018-02-22 21:38:33 +01:00
|
|
|
|
undo_redo->add_do_method(node, "set_polygon", node->get_polygon());
|
|
|
|
|
undo_redo->add_undo_method(node, "set_polygon", uv_prev);
|
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
|
undo_redo->add_do_method(uv_edit_draw, "update");
|
|
|
|
|
undo_redo->add_undo_method(uv_edit_draw, "update");
|
2014-07-07 22:44:21 +02:00
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_drag = false;
|
2018-05-02 16:00:35 +02:00
|
|
|
|
} else 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);
|
|
|
|
|
undo_redo->add_do_method(uv_edit_draw, "update");
|
|
|
|
|
undo_redo->add_undo_method(uv_edit_draw, "update");
|
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
bone_painting = false;
|
2014-07-07 22:44:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
|
} else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2018-02-22 21:38:33 +01:00
|
|
|
|
if (uv_create) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_drag = false;
|
2018-02-22 21:38:33 +01:00
|
|
|
|
uv_create = false;
|
|
|
|
|
node->set_uv(uv_create_uv_prev);
|
|
|
|
|
node->set_polygon(uv_create_poly_prev);
|
2018-05-02 16:00:35 +02:00
|
|
|
|
node->call("_set_bones", uv_create_bones_prev);
|
2018-02-25 16:06:30 +01:00
|
|
|
|
node->set_splits(splits_prev);
|
2018-02-22 21:38:33 +01:00
|
|
|
|
uv_edit_draw->update();
|
|
|
|
|
} else if (uv_drag) {
|
|
|
|
|
|
|
|
|
|
uv_drag = false;
|
|
|
|
|
if (uv_edit_mode[0]->is_pressed()) { //edit uv
|
|
|
|
|
node->set_uv(uv_prev);
|
2018-02-25 16:06:30 +01:00
|
|
|
|
} else if (uv_edit_mode[1]->is_pressed()) { //edit polygon
|
2018-02-22 21:38:33 +01:00
|
|
|
|
node->set_polygon(uv_prev);
|
|
|
|
|
}
|
2014-07-07 22:44:21 +02:00
|
|
|
|
uv_edit_draw->update();
|
2018-02-25 16:06:30 +01:00
|
|
|
|
} else if (split_create) {
|
|
|
|
|
split_create = false;
|
|
|
|
|
uv_edit_draw->update();
|
2018-05-02 16:00:35 +02:00
|
|
|
|
} else if (bone_painting) {
|
|
|
|
|
node->set_bone_weights(bone_painting_bone, prev_weights);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
|
} else if (mb->get_button_index() == BUTTON_WHEEL_UP && mb->is_pressed()) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
|
uv_zoom->set_value(uv_zoom->get_value() / (1 - (0.1 * mb->get_factor())));
|
|
|
|
|
} else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && mb->is_pressed()) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
|
uv_zoom->set_value(uv_zoom->get_value() * (1 - (0.1 * mb->get_factor())));
|
2014-07-07 22:44:21 +02:00
|
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
|
}
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
|
Ref<InputEventMouseMotion> mm = p_input;
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
|
if (mm.is_valid()) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-09-07 21:48:50 +02:00
|
|
|
|
if ((mm->get_button_mask() & BUTTON_MASK_MIDDLE) || Input::get_singleton()->is_key_pressed(KEY_SPACE)) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
|
Vector2 drag(mm->get_relative().x, mm->get_relative().y);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_hscroll->set_value(uv_hscroll->get_value() - drag.x);
|
|
|
|
|
uv_vscroll->set_value(uv_vscroll->get_value() - drag.y);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
|
|
|
|
} else if (uv_drag) {
|
|
|
|
|
|
2017-06-03 10:54:24 +02:00
|
|
|
|
Vector2 uv_drag_to = mm->get_position();
|
2014-07-07 22:44:21 +02:00
|
|
|
|
Vector2 drag = mtx.affine_inverse().xform(uv_drag_to) - mtx.affine_inverse().xform(uv_drag_from);
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
switch (uv_move_current) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2018-02-22 21:38:33 +01:00
|
|
|
|
case UV_MODE_CREATE: {
|
|
|
|
|
if (uv_create) {
|
|
|
|
|
uv_create_to = mtx.affine_inverse().xform(Vector2(mm->get_position().x, mm->get_position().y));
|
|
|
|
|
}
|
|
|
|
|
} break;
|
2014-07-07 22:44:21 +02:00
|
|
|
|
case UV_MODE_EDIT_POINT: {
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
PoolVector<Vector2> uv_new = uv_prev;
|
|
|
|
|
uv_new.set(uv_drag_index, uv_new[uv_drag_index] + drag);
|
2018-02-22 21:38:33 +01:00
|
|
|
|
|
|
|
|
|
if (uv_edit_mode[0]->is_pressed()) { //edit uv
|
|
|
|
|
node->set_uv(uv_new);
|
2018-02-25 16:06:30 +01:00
|
|
|
|
} else if (uv_edit_mode[1]->is_pressed()) { //edit polygon
|
2018-02-22 21:38:33 +01:00
|
|
|
|
node->set_polygon(uv_new);
|
|
|
|
|
}
|
2014-07-07 22:44:21 +02:00
|
|
|
|
} break;
|
|
|
|
|
case UV_MODE_MOVE: {
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
PoolVector<Vector2> uv_new = uv_prev;
|
|
|
|
|
for (int i = 0; i < uv_new.size(); i++)
|
|
|
|
|
uv_new.set(i, uv_new[i] + drag);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2018-02-22 21:38:33 +01:00
|
|
|
|
if (uv_edit_mode[0]->is_pressed()) { //edit uv
|
|
|
|
|
node->set_uv(uv_new);
|
2018-02-25 16:06:30 +01:00
|
|
|
|
} else if (uv_edit_mode[1]->is_pressed()) { //edit polygon
|
2018-02-22 21:38:33 +01:00
|
|
|
|
node->set_polygon(uv_new);
|
|
|
|
|
}
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
case UV_MODE_ROTATE: {
|
|
|
|
|
|
|
|
|
|
Vector2 center;
|
2017-03-05 16:44:50 +01:00
|
|
|
|
PoolVector<Vector2> uv_new = uv_prev;
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
for (int i = 0; i < uv_new.size(); i++)
|
|
|
|
|
center += uv_prev[i];
|
|
|
|
|
center /= uv_new.size();
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
float angle = (uv_drag_from - mtx.xform(center)).normalized().angle_to((uv_drag_to - mtx.xform(center)).normalized());
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
for (int i = 0; i < uv_new.size(); i++) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
Vector2 rel = uv_prev[i] - center;
|
2017-03-05 16:44:50 +01:00
|
|
|
|
rel = rel.rotated(angle);
|
|
|
|
|
uv_new.set(i, center + rel);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-22 21:38:33 +01:00
|
|
|
|
if (uv_edit_mode[0]->is_pressed()) { //edit uv
|
|
|
|
|
node->set_uv(uv_new);
|
2018-02-25 16:06:30 +01:00
|
|
|
|
} else if (uv_edit_mode[1]->is_pressed()) { //edit polygon
|
2018-02-22 21:38:33 +01:00
|
|
|
|
node->set_polygon(uv_new);
|
|
|
|
|
}
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
case UV_MODE_SCALE: {
|
|
|
|
|
|
|
|
|
|
Vector2 center;
|
2017-03-05 16:44:50 +01:00
|
|
|
|
PoolVector<Vector2> uv_new = uv_prev;
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
for (int i = 0; i < uv_new.size(); i++)
|
|
|
|
|
center += uv_prev[i];
|
|
|
|
|
center /= uv_new.size();
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
|
|
|
|
float from_dist = uv_drag_from.distance_to(mtx.xform(center));
|
|
|
|
|
float to_dist = uv_drag_to.distance_to(mtx.xform(center));
|
2017-03-05 16:44:50 +01:00
|
|
|
|
if (from_dist < 2)
|
2014-07-07 22:44:21 +02:00
|
|
|
|
break;
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
float scale = to_dist / from_dist;
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
for (int i = 0; i < uv_new.size(); i++) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
Vector2 rel = uv_prev[i] - center;
|
2017-03-05 16:44:50 +01:00
|
|
|
|
rel = rel * scale;
|
|
|
|
|
uv_new.set(i, center + rel);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-22 21:38:33 +01:00
|
|
|
|
if (uv_edit_mode[0]->is_pressed()) { //edit uv
|
|
|
|
|
node->set_uv(uv_new);
|
2018-02-25 16:06:30 +01:00
|
|
|
|
} else if (uv_edit_mode[1]->is_pressed()) { //edit polygon
|
2018-02-22 21:38:33 +01:00
|
|
|
|
node->set_polygon(uv_new);
|
|
|
|
|
}
|
2014-07-07 22:44:21 +02:00
|
|
|
|
} break;
|
|
|
|
|
}
|
2018-05-02 16:00:35 +02:00
|
|
|
|
|
|
|
|
|
if (bone_painting) {
|
|
|
|
|
bone_paint_pos = Vector2(mm->get_position().x, mm->get_position().y);
|
|
|
|
|
PoolVector<float> painted_weights = node->get_bone_weights(bone_painting_bone);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
int pc = painted_weights.size();
|
|
|
|
|
float amount = bone_paint_strength->get_value();
|
|
|
|
|
float radius = bone_paint_radius->get_value() * EDSCALE;
|
|
|
|
|
|
|
|
|
|
if (uv_mode == UV_MODE_CLEAR_WEIGHT) {
|
|
|
|
|
amount = -amount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PoolVector<float>::Write w = painted_weights.write();
|
|
|
|
|
PoolVector<float>::Read r = prev_weights.read();
|
|
|
|
|
PoolVector<Vector2>::Read rv = uv_prev.read();
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2014-07-07 22:44:21 +02:00
|
|
|
|
uv_edit_draw->update();
|
2018-02-25 16:06:30 +01:00
|
|
|
|
} else if (split_create) {
|
|
|
|
|
uv_create_to = mtx.affine_inverse().xform(Vector2(mm->get_position().x, mm->get_position().y));
|
|
|
|
|
uv_edit_draw->update();
|
2018-05-02 16:00:35 +02:00
|
|
|
|
} else if (uv_mode == UV_MODE_PAINT_WEIGHT || uv_mode == UV_MODE_CLEAR_WEIGHT) {
|
|
|
|
|
bone_paint_pos = Vector2(mm->get_position().x, mm->get_position().y);
|
|
|
|
|
uv_edit_draw->update();
|
2014-07-07 22:44:21 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-01 21:49:39 +01: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 22:44:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Polygon2DEditor::_uv_scroll_changed(float) {
|
|
|
|
|
|
|
|
|
|
if (updating_uv_scroll)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_draw_ofs.x = uv_hscroll->get_value();
|
|
|
|
|
uv_draw_ofs.y = uv_vscroll->get_value();
|
|
|
|
|
uv_draw_zoom = uv_zoom->get_value();
|
2014-07-07 22:44:21 +02:00
|
|
|
|
uv_edit_draw->update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Polygon2DEditor::_uv_draw() {
|
|
|
|
|
|
|
|
|
|
Ref<Texture> base_tex = node->get_texture();
|
|
|
|
|
if (base_tex.is_null())
|
|
|
|
|
return;
|
|
|
|
|
|
2018-05-03 22:29:15 +02:00
|
|
|
|
String warning;
|
|
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
|
Transform2D mtx;
|
2017-03-05 16:44:50 +01:00
|
|
|
|
mtx.elements[2] = -uv_draw_ofs;
|
|
|
|
|
mtx.scale_basis(Vector2(uv_draw_zoom, uv_draw_zoom));
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
VS::get_singleton()->canvas_item_add_set_transform(uv_edit_draw->get_canvas_item(), mtx);
|
|
|
|
|
uv_edit_draw->draw_texture(base_tex, Point2());
|
|
|
|
|
VS::get_singleton()->canvas_item_add_set_transform(uv_edit_draw->get_canvas_item(), Transform2D());
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2015-09-28 05:06:06 +02:00
|
|
|
|
if (snap_show_grid) {
|
|
|
|
|
Size2 s = uv_edit_draw->get_size();
|
2017-09-01 22:33:39 +02:00
|
|
|
|
int last_cell = 0;
|
2015-09-28 05:06:06 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01: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));
|
|
|
|
|
if (i == 0)
|
|
|
|
|
last_cell = cell;
|
|
|
|
|
if (last_cell != cell)
|
|
|
|
|
uv_edit_draw->draw_line(Point2(i, 0), Point2(i, s.height), Color(0.3, 0.7, 1, 0.3));
|
|
|
|
|
last_cell = cell;
|
2015-09-28 05:06:06 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
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));
|
|
|
|
|
if (i == 0)
|
|
|
|
|
last_cell = cell;
|
|
|
|
|
if (last_cell != cell)
|
|
|
|
|
uv_edit_draw->draw_line(Point2(0, i), Point2(s.width, i), Color(0.3, 0.7, 1, 0.3));
|
|
|
|
|
last_cell = cell;
|
2015-09-28 05:06:06 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-22 21:38:33 +01:00
|
|
|
|
PoolVector<Vector2> uvs;
|
2018-02-25 16:06:30 +01:00
|
|
|
|
if (uv_edit_mode[0]->is_pressed()) { //edit uv
|
2018-02-22 21:38:33 +01:00
|
|
|
|
uvs = node->get_uv();
|
2018-02-25 16:06:30 +01:00
|
|
|
|
} else { //edit polygon
|
2018-02-22 21:38:33 +01:00
|
|
|
|
uvs = node->get_polygon();
|
2018-02-25 16:06:30 +01:00
|
|
|
|
}
|
2018-02-22 21:38:33 +01:00
|
|
|
|
|
2018-05-02 16:00:35 +02:00
|
|
|
|
PoolVector<float>::Read weight_r;
|
|
|
|
|
|
|
|
|
|
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()) {
|
|
|
|
|
|
|
|
|
|
weight_r = node->get_bone_weights(bone_selected).read();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons");
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
Rect2 rect(Point2(), mtx.basis_xform(base_tex->get_size()));
|
2014-07-07 22:44:21 +02:00
|
|
|
|
rect.expand_to(mtx.basis_xform(uv_edit_draw->get_size()));
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
for (int i = 0; i < uvs.size(); i++) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
int next = (i + 1) % uvs.size();
|
2018-02-22 21:38:33 +01:00
|
|
|
|
Vector2 next_point = uvs[next];
|
|
|
|
|
if (uv_create && i == uvs.size() - 1) {
|
|
|
|
|
next_point = uv_create_to;
|
|
|
|
|
}
|
|
|
|
|
uv_edit_draw->draw_line(mtx.xform(uvs[i]), mtx.xform(next_point), Color(0.9, 0.5, 0.5), 2);
|
2018-05-02 16:00:35 +02:00
|
|
|
|
if (weight_r.ptr()) {
|
|
|
|
|
|
|
|
|
|
Vector2 draw_pos = mtx.xform(uvs[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));
|
|
|
|
|
} else {
|
|
|
|
|
uv_edit_draw->draw_texture(handle, mtx.xform(uvs[i]) - handle->get_size() * 0.5);
|
|
|
|
|
}
|
2014-07-07 22:44:21 +02:00
|
|
|
|
rect.expand_to(mtx.basis_xform(uvs[i]));
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-25 16:06:30 +01:00
|
|
|
|
if (split_create) {
|
|
|
|
|
Vector2 from = uvs[uv_drag_index];
|
|
|
|
|
Vector2 to = uv_create_to;
|
|
|
|
|
uv_edit_draw->draw_line(mtx.xform(from), mtx.xform(to), Color(0.9, 0.5, 0.5), 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PoolVector<int> splits = node->get_splits();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < splits.size(); i += 2) {
|
|
|
|
|
int idx_from = splits[i];
|
|
|
|
|
int idx_to = splits[i + 1];
|
|
|
|
|
if (idx_from < 0 || idx_to >= uvs.size())
|
|
|
|
|
continue;
|
|
|
|
|
uv_edit_draw->draw_line(mtx.xform(uvs[idx_from]), mtx.xform(uvs[idx_to]), Color(0.9, 0.5, 0.5), 2);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-02 16:00:35 +02:00
|
|
|
|
if (uv_mode == UV_MODE_PAINT_WEIGHT || uv_mode == UV_MODE_CLEAR_WEIGHT) {
|
|
|
|
|
|
2018-05-03 22:29:15 +02: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);
|
|
|
|
|
if (bone->get_rest() == Transform2D(0, 0, 0, 0, 0, 0))
|
|
|
|
|
continue; //not set
|
|
|
|
|
|
|
|
|
|
bool current = bone_path == skeleton->get_path_to(bone);
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < bone->get_child_count(); j++) {
|
|
|
|
|
|
|
|
|
|
Node2D *n = Object::cast_to<Node2D>(bone->get_child(j));
|
|
|
|
|
if (!n)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
bool edit_bone = n->has_meta("_edit_bone_") && n->get_meta("_edit_bone_");
|
|
|
|
|
if (edit_bone) {
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
Color color = current ? Color(1, 1, 1) : Color(0.5, 0.5, 0.5);
|
|
|
|
|
uv_edit_draw->draw_line(mtx.xform(bone_xform.get_origin()), mtx.xform(endpoint_xform.get_origin()), Color(0, 0, 0), current ? 5 : 4);
|
|
|
|
|
uv_edit_draw->draw_line(mtx.xform(bone_xform.get_origin()), mtx.xform(endpoint_xform.get_origin()), color, current ? 3 : 2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//draw paint circle
|
2018-05-02 16:00:35 +02:00
|
|
|
|
uv_edit_draw->draw_circle(bone_paint_pos, bone_paint_radius->get_value() * EDSCALE, Color(1, 1, 1, 0.1));
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
rect = rect.grow(200);
|
|
|
|
|
updating_uv_scroll = true;
|
2017-06-04 00:25:13 +02:00
|
|
|
|
uv_hscroll->set_min(rect.position.x);
|
|
|
|
|
uv_hscroll->set_max(rect.position.x + rect.size.x);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
uv_hscroll->set_page(uv_edit_draw->get_size().x);
|
2017-01-04 05:16:14 +01:00
|
|
|
|
uv_hscroll->set_value(uv_draw_ofs.x);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
uv_hscroll->set_step(0.001);
|
|
|
|
|
|
2017-06-04 00:25:13 +02:00
|
|
|
|
uv_vscroll->set_min(rect.position.y);
|
|
|
|
|
uv_vscroll->set_max(rect.position.y + rect.size.y);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
uv_vscroll->set_page(uv_edit_draw->get_size().y);
|
2017-01-04 05:16:14 +01:00
|
|
|
|
uv_vscroll->set_value(uv_draw_ofs.y);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
uv_vscroll->set_step(0.001);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
updating_uv_scroll = false;
|
2014-07-07 22:44:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Polygon2DEditor::_bind_methods() {
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
ClassDB::bind_method(D_METHOD("_uv_mode"), &Polygon2DEditor::_uv_mode);
|
|
|
|
|
ClassDB::bind_method(D_METHOD("_uv_draw"), &Polygon2DEditor::_uv_draw);
|
|
|
|
|
ClassDB::bind_method(D_METHOD("_uv_input"), &Polygon2DEditor::_uv_input);
|
|
|
|
|
ClassDB::bind_method(D_METHOD("_uv_scroll_changed"), &Polygon2DEditor::_uv_scroll_changed);
|
|
|
|
|
ClassDB::bind_method(D_METHOD("_set_use_snap"), &Polygon2DEditor::_set_use_snap);
|
|
|
|
|
ClassDB::bind_method(D_METHOD("_set_show_grid"), &Polygon2DEditor::_set_show_grid);
|
|
|
|
|
ClassDB::bind_method(D_METHOD("_set_snap_off_x"), &Polygon2DEditor::_set_snap_off_x);
|
|
|
|
|
ClassDB::bind_method(D_METHOD("_set_snap_off_y"), &Polygon2DEditor::_set_snap_off_y);
|
|
|
|
|
ClassDB::bind_method(D_METHOD("_set_snap_step_x"), &Polygon2DEditor::_set_snap_step_x);
|
|
|
|
|
ClassDB::bind_method(D_METHOD("_set_snap_step_y"), &Polygon2DEditor::_set_snap_step_y);
|
2018-02-22 21:38:33 +01:00
|
|
|
|
ClassDB::bind_method(D_METHOD("_uv_edit_mode_select"), &Polygon2DEditor::_uv_edit_mode_select);
|
2018-05-02 16:00:35 +02:00
|
|
|
|
ClassDB::bind_method(D_METHOD("_sync_bones"), &Polygon2DEditor::_sync_bones);
|
|
|
|
|
ClassDB::bind_method(D_METHOD("_update_bone_list"), &Polygon2DEditor::_update_bone_list);
|
|
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("_bone_paint_selected"), &Polygon2DEditor::_bone_paint_selected);
|
2015-09-28 05:06:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector2 Polygon2DEditor::snap_point(Vector2 p_target) const {
|
|
|
|
|
if (use_snap) {
|
2017-09-18 23:44:04 +02: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 05:06:06 +02:00
|
|
|
|
}
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2015-09-28 05:06:06 +02:00
|
|
|
|
return p_target;
|
2014-07-07 22:44:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-06 21:36:34 +01:00
|
|
|
|
Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) :
|
|
|
|
|
AbstractPolygon2DEditor(p_editor) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
snap_step = Vector2(10, 10);
|
|
|
|
|
use_snap = false;
|
|
|
|
|
snap_show_grid = false;
|
2015-09-28 05:06:06 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
button_uv = memnew(ToolButton);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
add_child(button_uv);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
button_uv->connect("pressed", this, "_menu_option", varray(MODE_EDIT_UV));
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_mode = UV_MODE_EDIT_POINT;
|
|
|
|
|
uv_edit = memnew(AcceptDialog);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
add_child(uv_edit);
|
2016-05-04 03:25:37 +02:00
|
|
|
|
uv_edit->set_title(TTR("Polygon 2D UV Editor"));
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_edit->set_self_modulate(Color(1, 1, 1, 0.9));
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
VBoxContainer *uv_main_vb = memnew(VBoxContainer);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
uv_edit->add_child(uv_main_vb);
|
2017-01-10 05:49:55 +01:00
|
|
|
|
//uv_edit->set_child_rect(uv_main_vb);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
HBoxContainer *uv_mode_hb = memnew(HBoxContainer);
|
2018-02-22 21:38:33 +01:00
|
|
|
|
|
|
|
|
|
uv_edit_group.instance();
|
|
|
|
|
|
|
|
|
|
uv_edit_mode[0] = memnew(ToolButton);
|
|
|
|
|
uv_mode_hb->add_child(uv_edit_mode[0]);
|
|
|
|
|
uv_edit_mode[0]->set_toggle_mode(true);
|
|
|
|
|
uv_edit_mode[1] = memnew(ToolButton);
|
|
|
|
|
uv_mode_hb->add_child(uv_edit_mode[1]);
|
|
|
|
|
uv_edit_mode[1]->set_toggle_mode(true);
|
2018-02-25 16:06:30 +01:00
|
|
|
|
uv_edit_mode[2] = memnew(ToolButton);
|
|
|
|
|
uv_mode_hb->add_child(uv_edit_mode[2]);
|
|
|
|
|
uv_edit_mode[2]->set_toggle_mode(true);
|
2018-05-02 16:00:35 +02:00
|
|
|
|
uv_edit_mode[3] = memnew(ToolButton);
|
|
|
|
|
uv_mode_hb->add_child(uv_edit_mode[3]);
|
|
|
|
|
uv_edit_mode[3]->set_toggle_mode(true);
|
2018-02-22 21:38:33 +01:00
|
|
|
|
|
|
|
|
|
uv_edit_mode[0]->set_text(TTR("UV"));
|
|
|
|
|
uv_edit_mode[0]->set_pressed(true);
|
|
|
|
|
uv_edit_mode[1]->set_text(TTR("Poly"));
|
2018-02-25 16:06:30 +01:00
|
|
|
|
uv_edit_mode[2]->set_text(TTR("Splits"));
|
2018-05-02 16:00:35 +02:00
|
|
|
|
uv_edit_mode[3]->set_text(TTR("Bones"));
|
2018-02-22 21:38:33 +01:00
|
|
|
|
|
|
|
|
|
uv_edit_mode[0]->set_button_group(uv_edit_group);
|
|
|
|
|
uv_edit_mode[1]->set_button_group(uv_edit_group);
|
2018-02-25 16:06:30 +01:00
|
|
|
|
uv_edit_mode[2]->set_button_group(uv_edit_group);
|
2018-05-02 16:00:35 +02:00
|
|
|
|
uv_edit_mode[3]->set_button_group(uv_edit_group);
|
2018-02-22 21:38:33 +01:00
|
|
|
|
|
|
|
|
|
uv_edit_mode[0]->connect("pressed", this, "_uv_edit_mode_select", varray(0));
|
|
|
|
|
uv_edit_mode[1]->connect("pressed", this, "_uv_edit_mode_select", varray(1));
|
2018-02-25 16:06:30 +01:00
|
|
|
|
uv_edit_mode[2]->connect("pressed", this, "_uv_edit_mode_select", varray(2));
|
2018-05-02 16:00:35 +02:00
|
|
|
|
uv_edit_mode[3]->connect("pressed", this, "_uv_edit_mode_select", varray(3));
|
2018-02-22 21:38:33 +01:00
|
|
|
|
|
|
|
|
|
uv_mode_hb->add_child(memnew(VSeparator));
|
|
|
|
|
|
2014-07-07 22:44:21 +02:00
|
|
|
|
uv_main_vb->add_child(uv_mode_hb);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
for (int i = 0; i < UV_MODE_MAX; i++) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_button[i] = memnew(ToolButton);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
uv_button[i]->set_toggle_mode(true);
|
|
|
|
|
uv_mode_hb->add_child(uv_button[i]);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_button[i]->connect("pressed", this, "_uv_mode", varray(i));
|
2014-07-07 22:44:21 +02:00
|
|
|
|
uv_button[i]->set_focus_mode(FOCUS_NONE);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-22 21:38:33 +01:00
|
|
|
|
uv_button[0]->set_tooltip(TTR("Create Polygon"));
|
|
|
|
|
uv_button[1]->set_tooltip(TTR("Move Point") + "\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"));
|
2018-02-25 16:06:30 +01:00
|
|
|
|
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"));
|
2018-05-02 16:00:35 +02:00
|
|
|
|
uv_button[7]->set_tooltip(TTR("Paint weights with specified intensity"));
|
|
|
|
|
uv_button[8]->set_tooltip(TTR("UnPaint weights with specified intensity"));
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2018-02-22 21:38:33 +01:00
|
|
|
|
uv_button[0]->hide();
|
2018-02-25 16:06:30 +01:00
|
|
|
|
uv_button[5]->hide();
|
|
|
|
|
uv_button[6]->hide();
|
2018-05-02 16:00:35 +02:00
|
|
|
|
uv_button[7]->hide();
|
|
|
|
|
uv_button[8]->hide();
|
2018-02-22 21:38:33 +01:00
|
|
|
|
uv_button[1]->set_pressed(true);
|
2018-05-02 16:00:35 +02: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);
|
|
|
|
|
|
|
|
|
|
bone_paint_radius_label = memnew(Label(" " + TTR("Radius:") + " "));
|
|
|
|
|
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);
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
HBoxContainer *uv_main_hb = memnew(HBoxContainer);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
uv_main_vb->add_child(uv_main_hb);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_edit_draw = memnew(Control);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
uv_main_hb->add_child(uv_edit_draw);
|
|
|
|
|
uv_main_hb->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
uv_edit_draw->set_h_size_flags(SIZE_EXPAND_FILL);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_menu = memnew(MenuButton);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
uv_mode_hb->add_child(uv_menu);
|
2016-05-04 03:25:37 +02:00
|
|
|
|
uv_menu->set_text(TTR("Edit"));
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_menu->get_popup()->add_item(TTR("Polygon->UV"), UVEDIT_POLYGON_TO_UV);
|
|
|
|
|
uv_menu->get_popup()->add_item(TTR("UV->Polygon"), UVEDIT_UV_TO_POLYGON);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
uv_menu->get_popup()->add_separator();
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_menu->get_popup()->add_item(TTR("Clear UV"), UVEDIT_UV_CLEAR);
|
2018-05-03 22:29:15 +02:00
|
|
|
|
uv_menu->get_popup()->add_separator();
|
|
|
|
|
uv_menu->get_popup()->add_item(TTR("Grid Settings"), UVEDIT_GRID_SETTINGS);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_menu->get_popup()->connect("id_pressed", this, "_menu_option");
|
2015-09-28 05:06:06 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_mode_hb->add_child(memnew(VSeparator));
|
2015-09-28 05:06:06 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
b_snap_enable = memnew(ToolButton);
|
2015-09-28 05:06:06 +02:00
|
|
|
|
uv_mode_hb->add_child(b_snap_enable);
|
2016-05-04 03:25:37 +02:00
|
|
|
|
b_snap_enable->set_text(TTR("Snap"));
|
2015-09-28 05:06:06 +02:00
|
|
|
|
b_snap_enable->set_focus_mode(FOCUS_NONE);
|
|
|
|
|
b_snap_enable->set_toggle_mode(true);
|
|
|
|
|
b_snap_enable->set_pressed(use_snap);
|
2016-05-04 03:25:37 +02:00
|
|
|
|
b_snap_enable->set_tooltip(TTR("Enable Snap"));
|
2017-03-05 16:44:50 +01:00
|
|
|
|
b_snap_enable->connect("toggled", this, "_set_use_snap");
|
2015-09-28 05:06:06 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
b_snap_grid = memnew(ToolButton);
|
2015-09-28 05:06:06 +02:00
|
|
|
|
uv_mode_hb->add_child(b_snap_grid);
|
2016-05-04 03:25:37 +02:00
|
|
|
|
b_snap_grid->set_text(TTR("Grid"));
|
2015-09-28 05:06:06 +02:00
|
|
|
|
b_snap_grid->set_focus_mode(FOCUS_NONE);
|
|
|
|
|
b_snap_grid->set_toggle_mode(true);
|
|
|
|
|
b_snap_grid->set_pressed(snap_show_grid);
|
2016-05-04 03:25:37 +02:00
|
|
|
|
b_snap_grid->set_tooltip(TTR("Show Grid"));
|
2017-03-05 16:44:50 +01:00
|
|
|
|
b_snap_grid->connect("toggled", this, "_set_show_grid");
|
2015-09-28 05:06:06 +02:00
|
|
|
|
|
2018-05-03 22:29:15 +02: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 05:06:06 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
SpinBox *sb_off_x = memnew(SpinBox);
|
2015-09-28 05:06:06 +02:00
|
|
|
|
sb_off_x->set_min(-256);
|
|
|
|
|
sb_off_x->set_max(256);
|
|
|
|
|
sb_off_x->set_step(1);
|
2017-01-04 05:16:14 +01:00
|
|
|
|
sb_off_x->set_value(snap_offset.x);
|
2015-09-28 05:06:06 +02:00
|
|
|
|
sb_off_x->set_suffix("px");
|
|
|
|
|
sb_off_x->connect("value_changed", this, "_set_snap_off_x");
|
2018-05-03 22:29:15 +02:00
|
|
|
|
grid_settings_vb->add_margin_child(TTR("Grid Offset X:"), sb_off_x);
|
2015-09-28 05:06:06 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
SpinBox *sb_off_y = memnew(SpinBox);
|
2015-09-28 05:06:06 +02:00
|
|
|
|
sb_off_y->set_min(-256);
|
|
|
|
|
sb_off_y->set_max(256);
|
|
|
|
|
sb_off_y->set_step(1);
|
2017-01-04 05:16:14 +01:00
|
|
|
|
sb_off_y->set_value(snap_offset.y);
|
2015-09-28 05:06:06 +02:00
|
|
|
|
sb_off_y->set_suffix("px");
|
|
|
|
|
sb_off_y->connect("value_changed", this, "_set_snap_off_y");
|
2018-05-03 22:29:15 +02:00
|
|
|
|
grid_settings_vb->add_margin_child(TTR("Grid Offset Y:"), sb_off_y);
|
2015-09-28 05:06:06 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
SpinBox *sb_step_x = memnew(SpinBox);
|
2015-09-28 05:06:06 +02:00
|
|
|
|
sb_step_x->set_min(-256);
|
|
|
|
|
sb_step_x->set_max(256);
|
|
|
|
|
sb_step_x->set_step(1);
|
2017-01-04 05:16:14 +01:00
|
|
|
|
sb_step_x->set_value(snap_step.x);
|
2015-09-28 05:06:06 +02:00
|
|
|
|
sb_step_x->set_suffix("px");
|
|
|
|
|
sb_step_x->connect("value_changed", this, "_set_snap_step_x");
|
2018-05-03 22:29:15 +02:00
|
|
|
|
grid_settings_vb->add_margin_child(TTR("Grid Step X:"), sb_step_x);
|
2015-09-28 05:06:06 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
SpinBox *sb_step_y = memnew(SpinBox);
|
2015-09-28 05:06:06 +02:00
|
|
|
|
sb_step_y->set_min(-256);
|
|
|
|
|
sb_step_y->set_max(256);
|
|
|
|
|
sb_step_y->set_step(1);
|
2017-01-04 05:16:14 +01:00
|
|
|
|
sb_step_y->set_value(snap_step.y);
|
2015-09-28 05:06:06 +02:00
|
|
|
|
sb_step_y->set_suffix("px");
|
|
|
|
|
sb_step_y->connect("value_changed", this, "_set_snap_step_y");
|
2018-05-03 22:29:15 +02:00
|
|
|
|
grid_settings_vb->add_margin_child(TTR("Grid Step Y:"), sb_step_y);
|
2015-09-28 05:06:06 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_mode_hb->add_child(memnew(VSeparator));
|
|
|
|
|
uv_icon_zoom = memnew(TextureRect);
|
|
|
|
|
uv_mode_hb->add_child(uv_icon_zoom);
|
|
|
|
|
uv_zoom = memnew(HSlider);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
uv_zoom->set_min(0.01);
|
|
|
|
|
uv_zoom->set_max(4);
|
2017-01-04 05:16:14 +01:00
|
|
|
|
uv_zoom->set_value(1);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
uv_zoom->set_step(0.01);
|
2018-05-02 16:00:35 +02:00
|
|
|
|
uv_zoom->set_v_size_flags(SIZE_SHRINK_CENTER);
|
|
|
|
|
|
2014-07-07 22:44:21 +02:00
|
|
|
|
uv_mode_hb->add_child(uv_zoom);
|
2018-05-03 22:29:15 +02:00
|
|
|
|
uv_zoom->set_custom_minimum_size(Size2(80 * EDSCALE, 0));
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_zoom_value = memnew(SpinBox);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
uv_zoom->share(uv_zoom_value);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_zoom_value->set_custom_minimum_size(Size2(50, 0));
|
2014-07-07 22:44:21 +02:00
|
|
|
|
uv_mode_hb->add_child(uv_zoom_value);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_zoom->connect("value_changed", this, "_uv_scroll_changed");
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_vscroll = memnew(VScrollBar);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
uv_main_hb->add_child(uv_vscroll);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_vscroll->connect("value_changed", this, "_uv_scroll_changed");
|
|
|
|
|
uv_hscroll = memnew(HScrollBar);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
uv_main_vb->add_child(uv_hscroll);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_hscroll->connect("value_changed", this, "_uv_scroll_changed");
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2018-05-02 16:00:35 +02:00
|
|
|
|
bone_scroll_main_vb = memnew(VBoxContainer);
|
|
|
|
|
bone_scroll_main_vb->hide();
|
2018-05-03 22:29:15 +02:00
|
|
|
|
sync_bones = memnew(Button(TTR("Sync Bones to Polygon")));
|
2018-05-02 16:00:35 +02:00
|
|
|
|
bone_scroll_main_vb->add_child(sync_bones);
|
|
|
|
|
uv_main_hb->add_child(bone_scroll_main_vb);
|
|
|
|
|
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);
|
|
|
|
|
sync_bones->connect("pressed", this, "_sync_bones");
|
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
uv_edit_draw->connect("draw", this, "_uv_draw");
|
|
|
|
|
uv_edit_draw->connect("gui_input", this, "_uv_input");
|
|
|
|
|
uv_draw_zoom = 1.0;
|
|
|
|
|
uv_drag_index = -1;
|
|
|
|
|
uv_drag = false;
|
2018-02-25 16:06:30 +01:00
|
|
|
|
uv_create = false;
|
2017-03-05 16:44:50 +01:00
|
|
|
|
updating_uv_scroll = false;
|
2018-02-25 16:06:30 +01:00
|
|
|
|
split_create = false;
|
2018-05-02 16:00:35 +02:00
|
|
|
|
bone_painting = false;
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
|
error = memnew(AcceptDialog);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
add_child(error);
|
|
|
|
|
|
2017-01-09 19:50:08 +01:00
|
|
|
|
uv_edit_draw->set_clip_contents(true);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-06 21:36:34 +01:00
|
|
|
|
Polygon2DEditorPlugin::Polygon2DEditorPlugin(EditorNode *p_node) :
|
|
|
|
|
AbstractPolygon2DEditorPlugin(p_node, memnew(Polygon2DEditor(p_node)), "Polygon2D") {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
}
|