summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/editor_node.cpp13
-rw-r--r--editor/icons/icon_auto_triangle.svg64
-rw-r--r--editor/icons/icon_tool_triangle.svg82
-rw-r--r--editor/import/editor_scene_importer_gltf.cpp7
-rw-r--r--editor/plugins/animation_blend_space_editor.cpp1023
-rw-r--r--editor/plugins/animation_blend_space_editor.h130
-rw-r--r--editor/plugins/animation_blend_tree_editor_plugin.cpp66
-rw-r--r--editor/plugins/animation_blend_tree_editor_plugin.h4
8 files changed, 1358 insertions, 31 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index a34aebc63a..83f1cd40ba 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -66,6 +66,7 @@
#include "editor/import/resource_importer_scene.h"
#include "editor/import/resource_importer_texture.h"
#include "editor/import/resource_importer_wav.h"
+#include "editor/plugins/animation_blend_space_editor.h"
#include "editor/plugins/animation_blend_tree_editor_plugin.h"
#include "editor/plugins/animation_player_editor_plugin.h"
#include "editor/plugins/animation_tree_editor_plugin.h"
@@ -1308,7 +1309,11 @@ bool EditorNode::item_has_editor(Object *p_object) {
void EditorNode::edit_item(Object *p_object) {
- Vector<EditorPlugin *> sub_plugins = editor_data.get_subeditors(p_object);
+ Vector<EditorPlugin *> sub_plugins;
+
+ if (p_object) {
+ sub_plugins = editor_data.get_subeditors(p_object);
+ }
if (!sub_plugins.empty()) {
_display_top_editors(false);
@@ -1316,6 +1321,8 @@ void EditorNode::edit_item(Object *p_object) {
_set_top_editors(sub_plugins);
_set_editing_top_editors(p_object);
_display_top_editors(true);
+ } else {
+ _hide_top_editors();
}
}
@@ -5371,8 +5378,6 @@ EditorNode::EditorNode() {
add_editor_plugin(memnew(SpatialEditorPlugin(this)));
add_editor_plugin(memnew(ScriptEditorPlugin(this)));
- add_editor_plugin(memnew(AnimationNodeBlendTreeEditorPlugin(this)));
-
EditorAudioBuses *audio_bus_editor = EditorAudioBuses::register_editor();
ScriptTextEditor::register_editor(); //register one for text scripts
@@ -5394,6 +5399,8 @@ EditorNode::EditorNode() {
add_editor_plugin(memnew(ShaderEditorPlugin(this)));
// FIXME: Disabled for Godot 3.0 as made incompatible, it needs to be ported to the new API.
//add_editor_plugin(memnew(ShaderGraphEditorPlugin(this)));
+ add_editor_plugin(memnew(AnimationNodeBlendTreeEditorPlugin(this)));
+ add_editor_plugin(memnew(AnimationNodeBlendSpaceEditorPlugin(this)));
add_editor_plugin(memnew(CameraEditorPlugin(this)));
add_editor_plugin(memnew(ThemeEditorPlugin(this)));
diff --git a/editor/icons/icon_auto_triangle.svg b/editor/icons/icon_auto_triangle.svg
new file mode 100644
index 0000000000..631f259452
--- /dev/null
+++ b/editor/icons/icon_auto_triangle.svg
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="16"
+ height="16"
+ version="1.1"
+ viewBox="0 0 16 16"
+ id="svg8"
+ sodipodi:docname="icon_auto_triangle.svg"
+ inkscape:version="0.92.3 (2405546, 2018-03-11)">
+ <metadata
+ id="metadata14">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <defs
+ id="defs12" />
+ <sodipodi:namedview
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1"
+ objecttolerance="10"
+ gridtolerance="10"
+ guidetolerance="10"
+ inkscape:pageopacity="0"
+ inkscape:pageshadow="2"
+ inkscape:window-width="1853"
+ inkscape:window-height="1016"
+ id="namedview10"
+ showgrid="false"
+ inkscape:zoom="29.5"
+ inkscape:cx="17.168167"
+ inkscape:cy="5.5708575"
+ inkscape:window-x="67"
+ inkscape:window-y="27"
+ inkscape:window-maximized="1"
+ inkscape:current-layer="g4" />
+ <g
+ transform="translate(0 -1036.4)"
+ id="g6">
+ <g
+ transform="translate(-26.001 -9.8683)"
+ id="g4">
+ <path
+ style="fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:1.87616086;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="M 8.2324219 0.67773438 L 0.64453125 15.289062 L 15.355469 15.289062 L 8.2324219 0.67773438 z M 6.9414062 5.4433594 L 9.2109375 5.4433594 C 9.5561128 6.0670927 9.8954447 6.7088542 10.230469 7.3671875 C 10.565492 8.0167875 10.901304 8.703974 11.236328 9.4316406 C 11.581503 10.159241 11.931781 10.934946 12.287109 11.757812 C 12.642437 12.580746 13.018126 13.477066 13.414062 14.447266 L 10.871094 14.447266 C 10.75942 14.135399 10.632366 13.815528 10.490234 13.486328 C 10.358255 13.157195 10.225729 12.827247 10.09375 12.498047 L 5.9824219 12.498047 C 5.8504432 12.827247 5.7143976 13.157195 5.5722656 13.486328 C 5.440287 13.815528 5.3167521 14.135399 5.2050781 14.447266 L 2.7382812 14.447266 C 3.1342186 13.477066 3.5099064 12.580746 3.8652344 11.757812 C 4.2205624 10.934946 4.5673204 10.159241 4.9023438 9.4316406 C 5.2475197 8.703974 5.5813793 8.0167875 5.90625 7.3671875 C 6.2412733 6.7088542 6.5860782 6.0670927 6.9414062 5.4433594 z M 8.0234375 7.4824219 C 7.9726708 7.6123552 7.8964385 7.790425 7.7949219 8.015625 C 7.6933999 8.240825 7.5772912 8.5003885 7.4453125 8.7949219 C 7.3133332 9.0894552 7.1643891 9.4143979 7.0019531 9.7695312 C 6.8496698 10.124665 6.6936847 10.496919 6.53125 10.886719 L 9.53125 10.886719 C 9.368814 10.496919 9.2108764 10.124665 9.0585938 9.7695312 C 8.9063104 9.4143979 8.7593188 9.0894552 8.6171875 8.7949219 C 8.4852082 8.5003885 8.3691001 8.240825 8.2675781 8.015625 C 8.1660555 7.790425 8.0843508 7.6123552 8.0234375 7.4824219 z "
+ transform="translate(26.001,1046.2683)"
+ id="path821" />
+ </g>
+ </g>
+</svg>
diff --git a/editor/icons/icon_tool_triangle.svg b/editor/icons/icon_tool_triangle.svg
new file mode 100644
index 0000000000..5696008767
--- /dev/null
+++ b/editor/icons/icon_tool_triangle.svg
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="16"
+ height="16"
+ version="1.1"
+ viewBox="0 0 16 16"
+ id="svg8"
+ sodipodi:docname="icon_tool_triangle.svg"
+ inkscape:version="0.92.3 (2405546, 2018-03-11)">
+ <metadata
+ id="metadata14">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title />
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <defs
+ id="defs12" />
+ <sodipodi:namedview
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1"
+ objecttolerance="10"
+ gridtolerance="10"
+ guidetolerance="10"
+ inkscape:pageopacity="0"
+ inkscape:pageshadow="2"
+ inkscape:window-width="1204"
+ inkscape:window-height="703"
+ id="namedview10"
+ showgrid="false"
+ inkscape:zoom="29.5"
+ inkscape:cx="8.0650451"
+ inkscape:cy="7.0341257"
+ inkscape:window-x="542"
+ inkscape:window-y="205"
+ inkscape:window-maximized="0"
+ inkscape:current-layer="g4" />
+ <g
+ transform="translate(0 -1036.4)"
+ id="g6">
+ <g
+ transform="translate(-26.001 -9.8683)"
+ id="g4">
+ <path
+ style="fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ d="m 27.695915,1056.3022 c 0,0 7.457627,-8.0678 7.118644,-7.8644 -0.338983,0.2034 5.830509,11.7288 5.830509,11.7288 z"
+ id="path821"
+ inkscape:connector-curvature="0" />
+ <circle
+ style="fill:#4b4b4b;fill-opacity:1;stroke:#e0e0e0;stroke-width:0.51200002;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path825"
+ cx="34.662014"
+ cy="1048.5903"
+ r="1.607564" />
+ <circle
+ style="fill:#4b4b4b;fill-opacity:1;stroke:#e0e0e0;stroke-width:0.51200002;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path825-3"
+ cx="39.933205"
+ cy="1059.6581"
+ r="1.607564" />
+ <circle
+ style="fill:#4b4b4b;fill-opacity:1;stroke:#e0e0e0;stroke-width:0.51200002;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path825-3-6"
+ cx="28.17049"
+ cy="1056.2683"
+ r="1.607564" />
+ </g>
+ </g>
+</svg>
diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp
index 07a4cf5884..777f757bb4 100644
--- a/editor/import/editor_scene_importer_gltf.cpp
+++ b/editor/import/editor_scene_importer_gltf.cpp
@@ -1256,12 +1256,15 @@ Error EditorSceneImporterGLTF::_parse_materials(GLTFState &state) {
}
if (mr.has("metallicFactor")) {
-
material->set_metallic(mr["metallicFactor"]);
+ } else {
+ material->set_metallic(1.0);
}
- if (mr.has("roughnessFactor")) {
+ if (mr.has("roughnessFactor")) {
material->set_roughness(mr["roughnessFactor"]);
+ } else {
+ material->set_roughness(1.0);
}
if (mr.has("metallicRoughnessTexture")) {
diff --git a/editor/plugins/animation_blend_space_editor.cpp b/editor/plugins/animation_blend_space_editor.cpp
new file mode 100644
index 0000000000..9118211bf2
--- /dev/null
+++ b/editor/plugins/animation_blend_space_editor.cpp
@@ -0,0 +1,1023 @@
+#include "animation_blend_space_editor.h"
+
+#include "core/io/resource_loader.h"
+#include "core/project_settings.h"
+#include "math/delaunay.h"
+#include "os/input.h"
+#include "os/keyboard.h"
+#include "scene/animation/animation_blend_tree.h"
+#include "scene/animation/animation_player.h"
+#include "scene/gui/menu_button.h"
+#include "scene/gui/panel.h"
+#include "scene/main/viewport.h"
+
+void AnimationNodeBlendSpaceEditor::edit(AnimationNodeBlendSpace *p_blend_space) {
+
+ if (blend_space.is_valid()) {
+ blend_space->disconnect("removed_from_graph", this, "_removed_from_graph");
+ }
+
+ if (p_blend_space) {
+ blend_space = Ref<AnimationNodeBlendSpace>(p_blend_space);
+ } else {
+ blend_space.unref();
+ }
+
+ if (blend_space.is_null()) {
+ hide();
+ } else {
+ blend_space->connect("removed_from_graph", this, "_removed_from_graph");
+
+ _update_space();
+ }
+}
+
+void AnimationNodeBlendSpaceEditor::_blend_space_gui_input(const Ref<InputEvent> &p_event) {
+
+ Ref<InputEventKey> k = p_event;
+ if (tool_select->is_pressed() && k.is_valid() && k->is_pressed() && k->get_scancode() == KEY_DELETE && !k->is_echo()) {
+ if (selected_point != -1 || selected_triangle != -1) {
+ _erase_selected();
+ accept_event();
+ }
+ }
+
+ Ref<InputEventMouseButton> mb = p_event;
+
+ if (mb.is_valid() && mb->is_pressed() && ((tool_select->is_pressed() && mb->get_button_index() == BUTTON_RIGHT) || (mb->get_button_index() == BUTTON_LEFT && tool_create->is_pressed()))) {
+ menu->clear();
+ animations_menu->clear();
+ animations_to_add.clear();
+ List<StringName> classes;
+ classes.sort_custom<StringName::AlphCompare>();
+
+ ClassDB::get_inheriters_from_class("AnimationRootNode", &classes);
+ menu->add_submenu_item(TTR("Add Animation"), "animations");
+
+ AnimationGraphPlayer *gp = blend_space->get_graph_player();
+ ERR_FAIL_COND(!gp);
+ if (gp && gp->has_node(gp->get_animation_player())) {
+ AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(gp->get_node(gp->get_animation_player()));
+ if (ap) {
+ List<StringName> names;
+ ap->get_animation_list(&names);
+ for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
+ animations_menu->add_icon_item(get_icon("Animation", "EditorIcons"), E->get());
+ animations_to_add.push_back(E->get());
+ }
+ }
+ }
+
+ for (List<StringName>::Element *E = classes.front(); E; E = E->next()) {
+
+ String name = String(E->get()).replace_first("AnimationNode", "");
+ if (name == "Animation")
+ continue; // nope
+ int idx = menu->get_item_count();
+ menu->add_item(vformat("Add %s", name));
+ menu->set_item_metadata(idx, E->get());
+ }
+
+ menu->set_global_position(blend_space_draw->get_global_transform().xform(mb->get_position()));
+ menu->popup();
+ add_point_pos = (mb->get_position() / blend_space_draw->get_size());
+ add_point_pos.y = 1.0 - add_point_pos.y;
+ add_point_pos *= (blend_space->get_max_space() - blend_space->get_min_space());
+ add_point_pos += blend_space->get_min_space();
+
+ if (snap->is_pressed()) {
+ add_point_pos.x = Math::stepify(add_point_pos.x, blend_space->get_snap().x);
+ add_point_pos.y = Math::stepify(add_point_pos.y, blend_space->get_snap().y);
+ }
+ }
+
+ if (mb.is_valid() && mb->is_pressed() && tool_select->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
+
+ blend_space_draw->update(); //update anyway
+ //try to see if a point can be selected
+ selected_point = -1;
+ selected_triangle = -1;
+ _update_tool_erase();
+
+ for (int i = 0; i < points.size(); i++) {
+
+ if (points[i].distance_to(mb->get_position()) < 10 * EDSCALE) {
+ selected_point = i;
+ Ref<AnimationNode> node = blend_space->get_blend_point_node(i);
+ EditorNode::get_singleton()->push_item(node.ptr(), "", true);
+ dragging_selected_attempt = true;
+ drag_from = mb->get_position();
+ _update_tool_erase();
+ _update_edited_point_pos();
+ return;
+ }
+ }
+
+ //then try to see if a triangle can be selected
+ if (!blend_space->get_auto_triangles()) { //if autotriangles use, disable this
+ for (int i = 0; i < blend_space->get_triangle_count(); i++) {
+ Vector<Vector2> triangle;
+
+ for (int j = 0; j < 3; j++) {
+ int idx = blend_space->get_triangle_point(i, j);
+ ERR_FAIL_INDEX(idx, points.size());
+ triangle.push_back(points[idx]);
+ }
+
+ if (Geometry::is_point_in_triangle(mb->get_position(), triangle[0], triangle[1], triangle[2])) {
+ selected_triangle = i;
+ _update_tool_erase();
+ return;
+ }
+ }
+ }
+ }
+
+ if (mb.is_valid() && mb->is_pressed() && tool_triangle->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
+
+ blend_space_draw->update(); //update anyway
+ //try to see if a point can be selected
+ selected_point = -1;
+
+ for (int i = 0; i < points.size(); i++) {
+
+ if (making_triangle.find(i) != -1)
+ continue;
+
+ if (points[i].distance_to(mb->get_position()) < 10 * EDSCALE) {
+ making_triangle.push_back(i);
+ if (making_triangle.size() == 3) {
+ //add triangle!
+ if (blend_space->has_triangle(making_triangle[0], making_triangle[1], making_triangle[2])) {
+ making_triangle.clear();
+ EditorNode::get_singleton()->show_warning(TTR("Triangle already exists"));
+ return;
+ }
+
+ updating = true;
+ undo_redo->create_action("Add Triangle");
+ undo_redo->add_do_method(blend_space.ptr(), "add_triangle", making_triangle[0], making_triangle[1], making_triangle[2]);
+ undo_redo->add_undo_method(blend_space.ptr(), "remove_triangle", blend_space->get_triangle_count());
+ undo_redo->add_do_method(this, "_update_space");
+ undo_redo->add_undo_method(this, "_update_space");
+ undo_redo->commit_action();
+ updating = false;
+ making_triangle.clear();
+ }
+ return;
+ }
+ }
+ }
+
+ if (mb.is_valid() && !mb->is_pressed() && dragging_selected_attempt && mb->get_button_index() == BUTTON_LEFT) {
+ if (dragging_selected) {
+ //move
+ Vector2 point = blend_space->get_blend_point_position(selected_point);
+ point += drag_ofs;
+ if (snap->is_pressed()) {
+ point.x = Math::stepify(point.x, blend_space->get_snap().x);
+ point.y = Math::stepify(point.y, blend_space->get_snap().y);
+ }
+
+ updating = true;
+ undo_redo->create_action("Move Node Point");
+ undo_redo->add_do_method(blend_space.ptr(), "set_blend_point_position", selected_point, point);
+ undo_redo->add_undo_method(blend_space.ptr(), "set_blend_point_position", selected_point, blend_space->get_blend_point_position(selected_point));
+ undo_redo->add_do_method(this, "_update_space");
+ undo_redo->add_undo_method(this, "_update_space");
+ undo_redo->add_do_method(this, "_update_edited_point_pos");
+ undo_redo->add_undo_method(this, "_update_edited_point_pos");
+ undo_redo->commit_action();
+ updating = false;
+ _update_edited_point_pos();
+ }
+ dragging_selected_attempt = false;
+ dragging_selected = false;
+ blend_space_draw->update();
+ }
+
+ if (mb.is_valid() && mb->is_pressed() && tool_blend->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
+
+ Vector2 blend_pos = (mb->get_position() / blend_space_draw->get_size());
+ blend_pos.y = 1.0 - blend_pos.y;
+ blend_pos *= (blend_space->get_max_space() - blend_space->get_min_space());
+ blend_pos += blend_space->get_min_space();
+
+ blend_space->set_blend_pos(blend_pos);
+ blend_space_draw->update();
+ }
+
+ Ref<InputEventMouseMotion> mm = p_event;
+
+ if (mm.is_valid() && !blend_space_draw->has_focus()) {
+ blend_space_draw->grab_focus();
+ blend_space_draw->update();
+ }
+
+ if (mm.is_valid() && dragging_selected_attempt) {
+ dragging_selected = true;
+ drag_ofs = ((mm->get_position() - drag_from) / blend_space_draw->get_size()) * (blend_space->get_max_space() - blend_space->get_min_space()) * Vector2(1, -1);
+ blend_space_draw->update();
+ _update_edited_point_pos();
+ }
+
+ if (mm.is_valid() && tool_triangle->is_pressed() && making_triangle.size()) {
+ blend_space_draw->update();
+ }
+
+ if (mm.is_valid() && !tool_triangle->is_pressed() && making_triangle.size()) {
+ making_triangle.clear();
+ blend_space_draw->update();
+ }
+
+ if (mm.is_valid() && tool_blend->is_pressed() && mm->get_button_mask() & BUTTON_MASK_LEFT) {
+
+ Vector2 blend_pos = (mm->get_position() / blend_space_draw->get_size());
+ blend_pos.y = 1.0 - blend_pos.y;
+ blend_pos *= (blend_space->get_max_space() - blend_space->get_min_space());
+ blend_pos += blend_space->get_min_space();
+
+ blend_space->set_blend_pos(blend_pos);
+ blend_space_draw->update();
+ }
+}
+
+void AnimationNodeBlendSpaceEditor::_add_menu_type(int p_index) {
+
+ String type = menu->get_item_metadata(p_index);
+
+ Object *obj = ClassDB::instance(type);
+ ERR_FAIL_COND(!obj);
+ AnimationNode *an = Object::cast_to<AnimationNode>(obj);
+ ERR_FAIL_COND(!an);
+
+ Ref<AnimationNode> node(an);
+
+ updating = true;
+ undo_redo->create_action("Add Node Point");
+ undo_redo->add_do_method(blend_space.ptr(), "add_blend_point", node, add_point_pos);
+ undo_redo->add_undo_method(blend_space.ptr(), "remove_blend_point", blend_space->get_blend_point_count());
+ undo_redo->add_do_method(this, "_update_space");
+ undo_redo->add_undo_method(this, "_update_space");
+ undo_redo->commit_action();
+ updating = false;
+
+ blend_space_draw->update();
+}
+
+void AnimationNodeBlendSpaceEditor::_add_animation_type(int p_index) {
+
+ Ref<AnimationNodeAnimation> anim;
+ anim.instance();
+
+ anim->set_animation(animations_to_add[p_index]);
+
+ updating = true;
+ undo_redo->create_action("Add Animation Point");
+ undo_redo->add_do_method(blend_space.ptr(), "add_blend_point", anim, add_point_pos);
+ undo_redo->add_undo_method(blend_space.ptr(), "remove_blend_point", blend_space->get_blend_point_count());
+ undo_redo->add_do_method(this, "_update_space");
+ undo_redo->add_undo_method(this, "_update_space");
+ undo_redo->commit_action();
+ updating = false;
+
+ blend_space_draw->update();
+}
+
+void AnimationNodeBlendSpaceEditor::_update_tool_erase() {
+ tool_erase->set_disabled(!(selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) && !(selected_triangle >= 0 && selected_triangle < blend_space->get_triangle_count()));
+ if (selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) {
+ Ref<AnimationNode> an = blend_space->get_blend_point_node(selected_point);
+ if (EditorNode::get_singleton()->item_has_editor(an.ptr())) {
+ open_editor->show();
+ } else {
+ open_editor->hide();
+ }
+ edit_hb->show();
+ } else {
+ edit_hb->hide();
+ }
+}
+
+void AnimationNodeBlendSpaceEditor::_tool_switch(int p_tool) {
+ making_triangle.clear();
+
+ if (p_tool == 2) {
+ Vector<Vector2> points;
+ for (int i = 0; i < blend_space->get_blend_point_count(); i++) {
+ points.push_back(blend_space->get_blend_point_position(i));
+ }
+ Vector<Delaunay2D::Triangle> tr = Delaunay2D::triangulate(points);
+ print_line("triangleS: " + itos(tr.size()));
+ for (int i = 0; i < tr.size(); i++) {
+ blend_space->add_triangle(tr[i].points[0], tr[i].points[1], tr[i].points[2]);
+ }
+ }
+
+ if (p_tool == 0) {
+ tool_erase->show();
+ tool_erase_sep->show();
+ } else {
+ tool_erase->hide();
+ tool_erase_sep->hide();
+ }
+ _update_tool_erase();
+ blend_space_draw->update();
+}
+
+void AnimationNodeBlendSpaceEditor::_blend_space_draw() {
+
+ Color linecolor = get_color("font_color", "Label");
+ Color linecolor_soft = linecolor;
+ linecolor_soft.a *= 0.5;
+ Ref<Font> font = get_font("font", "Label");
+ Ref<Texture> icon = get_icon("KeyValue", "EditorIcons");
+ Ref<Texture> icon_selected = get_icon("KeySelected", "EditorIcons");
+
+ Size2 s = blend_space_draw->get_size();
+
+ if (blend_space_draw->has_focus()) {
+ Color color = get_color("accent_color", "Editor");
+ blend_space_draw->draw_rect(Rect2(Point2(), s), color, false);
+ }
+ blend_space_draw->draw_line(Point2(1, 0), Point2(1, s.height - 1), linecolor);
+ blend_space_draw->draw_line(Point2(1, s.height - 1), Point2(s.width - 1, s.height - 1), linecolor);
+
+ blend_space_draw->draw_line(Point2(0, 0), Point2(5 * EDSCALE, 0), linecolor);
+ if (blend_space->get_min_space().y < 0) {
+ int y = (blend_space->get_max_space().y / (blend_space->get_max_space().y - blend_space->get_min_space().y)) * s.height;
+ blend_space_draw->draw_line(Point2(0, y), Point2(5 * EDSCALE, y), linecolor);
+ blend_space_draw->draw_string(font, Point2(2 * EDSCALE, y - font->get_height() + font->get_ascent()), "0", linecolor);
+ blend_space_draw->draw_line(Point2(5 * EDSCALE, y), Point2(s.width, y), linecolor_soft);
+ }
+
+ if (blend_space->get_min_space().x < 0) {
+ int x = (blend_space->get_max_space().x / (blend_space->get_max_space().x - blend_space->get_min_space().x)) * s.width;
+ blend_space_draw->draw_line(Point2(x, s.height - 1), Point2(x, s.height - 5 * EDSCALE), linecolor);
+ blend_space_draw->draw_string(font, Point2(x + 2 * EDSCALE, s.height - 2 * EDSCALE - font->get_height() + font->get_ascent()), "0", linecolor);
+ blend_space_draw->draw_line(Point2(x, s.height - 5 * EDSCALE), Point2(x, 0), linecolor_soft);
+ }
+
+ if (snap->is_pressed()) {
+
+ linecolor_soft.a = linecolor.a * 0.1;
+
+ if (blend_space->get_snap().x > 0) {
+
+ int prev_idx;
+ for (int i = 0; i < s.x; i++) {
+
+ float v = blend_space->get_min_space().x + i * (blend_space->get_max_space().x - blend_space->get_min_space().x) / s.x;
+ int idx = int(v / blend_space->get_snap().x);
+
+ if (i > 0 && prev_idx != idx) {
+ blend_space_draw->draw_line(Point2(i, 0), Point2(i, s.height), linecolor_soft);
+ }
+
+ prev_idx = idx;
+ }
+ }
+
+ if (blend_space->get_snap().y > 0) {
+
+ int prev_idx;
+ for (int i = 0; i < s.y; i++) {
+
+ float v = blend_space->get_max_space().y - i * (blend_space->get_max_space().y - blend_space->get_min_space().y) / s.y;
+ int idx = int(v / blend_space->get_snap().y);
+
+ if (i > 0 && prev_idx != idx) {
+ blend_space_draw->draw_line(Point2(0, i), Point2(s.width, i), linecolor_soft);
+ }
+
+ prev_idx = idx;
+ }
+ }
+ }
+
+ //triangles first
+ for (int i = 0; i < blend_space->get_triangle_count(); i++) {
+
+ Vector<Vector2> points;
+ points.resize(3);
+
+ for (int j = 0; j < 3; j++) {
+ int point_idx = blend_space->get_triangle_point(i, j);
+ Vector2 point = blend_space->get_blend_point_position(point_idx);
+ if (dragging_selected && selected_point == point_idx) {
+ point += drag_ofs;
+ if (snap->is_pressed()) {
+ point.x = Math::stepify(point.x, blend_space->get_snap().x);
+ point.y = Math::stepify(point.y, blend_space->get_snap().y);
+ }
+ }
+ point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
+ point *= s;
+ point.y = s.height - point.y;
+ points[j] = point;
+ }
+
+ for (int j = 0; j < 3; j++) {
+ blend_space_draw->draw_line(points[j], points[(j + 1) % 3], linecolor, 1, true);
+ }
+
+ Color color;
+ if (i == selected_triangle) {
+ color = get_color("accent_color", "Editor");
+ color.a *= 0.5;
+ } else {
+ color = linecolor;
+ color.a *= 0.2;
+ }
+
+ Vector<Color> colors;
+ colors.push_back(color);
+ colors.push_back(color);
+ colors.push_back(color);
+ blend_space_draw->draw_primitive(points, colors, Vector<Vector2>());
+ }
+
+ points.clear();
+ for (int i = 0; i < blend_space->get_blend_point_count(); i++) {
+
+ Vector2 point = blend_space->get_blend_point_position(i);
+ if (dragging_selected && selected_point == i) {
+ point += drag_ofs;
+ if (snap->is_pressed()) {
+ point.x = Math::stepify(point.x, blend_space->get_snap().x);
+ point.y = Math::stepify(point.y, blend_space->get_snap().y);
+ }
+ }
+ point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
+ point *= s;
+ point.y = s.height - point.y;
+
+ points.push_back(point);
+ point -= (icon->get_size() / 2);
+ point = point.floor();
+
+ if (i == selected_point) {
+ blend_space_draw->draw_texture(icon_selected, point);
+ } else {
+ blend_space_draw->draw_texture(icon, point);
+ }
+ }
+
+ if (making_triangle.size()) {
+ Vector<Vector2> points;
+ for (int i = 0; i < making_triangle.size(); i++) {
+ Vector2 point = blend_space->get_blend_point_position(making_triangle[i]);
+ point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
+ point *= s;
+ point.y = s.height - point.y;
+ points.push_back(point);
+ }
+
+ for (int i = 0; i < points.size() - 1; i++) {
+ blend_space_draw->draw_line(points[i], points[i + 1], linecolor, 2, true);
+ }
+ blend_space_draw->draw_line(points[points.size() - 1], blend_space_draw->get_local_mouse_position(), linecolor, 2, true);
+ }
+
+ ///draw cursor position
+
+ {
+ Color color;
+ if (tool_blend->is_pressed()) {
+ color = get_color("accent_color", "Editor");
+ } else {
+ color = linecolor;
+ color.a *= 0.5;
+ }
+
+ Vector2 point = blend_space->get_blend_pos();
+ point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
+ point *= s;
+ point.y = s.height - point.y;
+
+ if (blend_space->get_triangle_count()) {
+ Vector2 closest = blend_space->get_closest_point(blend_space->get_blend_pos());
+ closest = (closest - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
+ closest *= s;
+ closest.y = s.height - closest.y;
+
+ Color lcol = color;
+ lcol.a *= 0.4;
+ blend_space_draw->draw_line(point, closest, lcol, 2);
+ }
+
+ float mind = 5 * EDSCALE;
+ float maxd = 15 * EDSCALE;
+ blend_space_draw->draw_line(point + Vector2(mind, 0), point + Vector2(maxd, 0), color, 2);
+ blend_space_draw->draw_line(point + Vector2(-mind, 0), point + Vector2(-maxd, 0), color, 2);
+ blend_space_draw->draw_line(point + Vector2(0, mind), point + Vector2(0, maxd), color, 2);
+ blend_space_draw->draw_line(point + Vector2(0, -mind), point + Vector2(0, -maxd), color, 2);
+ }
+}
+
+void AnimationNodeBlendSpaceEditor::_snap_toggled() {
+
+ blend_space_draw->update();
+}
+
+void AnimationNodeBlendSpaceEditor::_update_space() {
+
+ if (updating)
+ return;
+
+ updating = true;
+
+ if (blend_space->get_parent().is_valid()) {
+ goto_parent_hb->show();
+ } else {
+ goto_parent_hb->hide();
+ }
+
+ if (blend_space->get_auto_triangles()) {
+ tool_triangle->hide();
+ } else {
+ tool_triangle->show();
+ }
+
+ auto_triangles->set_pressed(blend_space->get_auto_triangles());
+
+ max_x_value->set_value(blend_space->get_max_space().x);
+ max_y_value->set_value(blend_space->get_max_space().y);
+
+ min_x_value->set_value(blend_space->get_min_space().x);
+ min_y_value->set_value(blend_space->get_min_space().y);
+
+ label_x->set_text(blend_space->get_x_label());
+ label_y->set_text(blend_space->get_y_label());
+
+ snap_x->set_value(blend_space->get_snap().x);
+ snap_y->set_value(blend_space->get_snap().y);
+
+ blend_space_draw->update();
+
+ updating = false;
+}
+
+void AnimationNodeBlendSpaceEditor::_config_changed(double) {
+ if (updating)
+ return;
+
+ updating = true;
+ undo_redo->create_action("Change BlendSpace Limits");
+ undo_redo->add_do_method(blend_space.ptr(), "set_max_space", Vector2(max_x_value->get_value(), max_y_value->get_value()));
+ undo_redo->add_undo_method(blend_space.ptr(), "set_max_space", blend_space->get_max_space());
+ undo_redo->add_do_method(blend_space.ptr(), "set_min_space", Vector2(min_x_value->get_value(), min_y_value->get_value()));
+ undo_redo->add_undo_method(blend_space.ptr(), "set_min_space", blend_space->get_min_space());
+ undo_redo->add_do_method(blend_space.ptr(), "set_snap", Vector2(snap_x->get_value(), snap_y->get_value()));
+ undo_redo->add_undo_method(blend_space.ptr(), "set_snap", blend_space->get_snap());
+ undo_redo->add_do_method(this, "_update_space");
+ undo_redo->add_undo_method(this, "_update_space");
+ undo_redo->commit_action();
+ updating = false;
+
+ blend_space_draw->update();
+}
+
+void AnimationNodeBlendSpaceEditor::_labels_changed(String) {
+ if (updating)
+ return;
+
+ updating = true;
+ undo_redo->create_action("Change BlendSpace Labels", UndoRedo::MERGE_ENDS);
+ undo_redo->add_do_method(blend_space.ptr(), "set_x_label", label_x->get_text());
+ undo_redo->add_undo_method(blend_space.ptr(), "set_x_label", blend_space->get_x_label());
+ undo_redo->add_do_method(blend_space.ptr(), "set_y_label", label_y->get_text());
+ undo_redo->add_undo_method(blend_space.ptr(), "set_y_label", blend_space->get_y_label());
+ undo_redo->add_do_method(this, "_update_space");
+ undo_redo->add_undo_method(this, "_update_space");
+ undo_redo->commit_action();
+ updating = false;
+}
+
+void AnimationNodeBlendSpaceEditor::_erase_selected() {
+
+ if (selected_point != -1) {
+
+ updating = true;
+ undo_redo->create_action("Remove BlendSpace Point");
+ undo_redo->add_do_method(blend_space.ptr(), "remove_blend_point", selected_point);
+ undo_redo->add_undo_method(blend_space.ptr(), "add_blend_point", blend_space->get_blend_point_node(selected_point), blend_space->get_blend_point_position(selected_point), selected_point);
+
+ //restore triangles using this point
+ for (int i = 0; i < blend_space->get_triangle_count(); i++) {
+ for (int j = 0; j < 3; j++) {
+ if (blend_space->get_triangle_point(i, j) == selected_point) {
+ undo_redo->add_undo_method(blend_space.ptr(), "add_triangle", blend_space->get_triangle_point(i, 0), blend_space->get_triangle_point(i, 1), blend_space->get_triangle_point(i, 2), i);
+ break;
+ }
+ }
+ }
+
+ undo_redo->add_do_method(this, "_update_space");
+ undo_redo->add_undo_method(this, "_update_space");
+ undo_redo->commit_action();
+ updating = false;
+
+ blend_space_draw->update();
+ } else if (selected_triangle != -1) {
+
+ updating = true;
+ undo_redo->create_action("Remove BlendSpace Triangle");
+ undo_redo->add_do_method(blend_space.ptr(), "remove_triangle", selected_triangle);
+ undo_redo->add_undo_method(blend_space.ptr(), "add_triangle", blend_space->get_triangle_point(selected_triangle, 0), blend_space->get_triangle_point(selected_triangle, 1), blend_space->get_triangle_point(selected_triangle, 2), selected_triangle);
+
+ undo_redo->add_do_method(this, "_update_space");
+ undo_redo->add_undo_method(this, "_update_space");
+ undo_redo->commit_action();
+ updating = false;
+
+ blend_space_draw->update();
+ }
+}
+
+void AnimationNodeBlendSpaceEditor::_update_edited_point_pos() {
+ if (updating)
+ return;
+
+ if (selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) {
+ Vector2 pos = blend_space->get_blend_point_position(selected_point);
+ if (dragging_selected) {
+ pos += drag_ofs;
+ if (snap->is_pressed()) {
+ pos.x = Math::stepify(pos.x, blend_space->get_snap().x);
+ pos.y = Math::stepify(pos.y, blend_space->get_snap().y);
+ }
+ }
+ updating = true;
+ edit_x->set_value(pos.x);
+ edit_y->set_value(pos.y);
+ updating = false;
+ }
+}
+
+void AnimationNodeBlendSpaceEditor::_edit_point_pos(double) {
+ if (updating)
+ return;
+ updating = true;
+ undo_redo->create_action("Move Node Point");
+ undo_redo->add_do_method(blend_space.ptr(), "set_blend_point_position", selected_point, Vector2(edit_x->get_value(), edit_y->get_value()));
+ undo_redo->add_undo_method(blend_space.ptr(), "set_blend_point_position", selected_point, blend_space->get_blend_point_position(selected_point));
+ undo_redo->add_do_method(this, "_update_space");
+ undo_redo->add_undo_method(this, "_update_space");
+ undo_redo->add_do_method(this, "_update_edited_point_pos");
+ undo_redo->add_undo_method(this, "_update_edited_point_pos");
+ undo_redo->commit_action();
+ updating = false;
+
+ blend_space_draw->update();
+}
+
+void AnimationNodeBlendSpaceEditor::_notification(int p_what) {
+
+ if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
+ error_panel->add_style_override("panel", get_stylebox("bg", "Tree"));
+ error_label->add_color_override("font_color", get_color("error_color", "Editor"));
+ panel->add_style_override("panel", get_stylebox("bg", "Tree"));
+ tool_blend->set_icon(get_icon("EditPivot", "EditorIcons"));
+ tool_select->set_icon(get_icon("ToolSelect", "EditorIcons"));
+ tool_create->set_icon(get_icon("EditKey", "EditorIcons"));
+ tool_triangle->set_icon(get_icon("ToolTriangle", "EditorIcons"));
+ tool_erase->set_icon(get_icon("Remove", "EditorIcons"));
+ snap->set_icon(get_icon("SnapGrid", "EditorIcons"));
+ open_editor->set_icon(get_icon("Edit", "EditorIcons"));
+ goto_parent->set_icon(get_icon("MoveUp", "EditorIcons"));
+ auto_triangles->set_icon(get_icon("AutoTriangle", "EditorIcons"));
+ }
+
+ if (p_what == NOTIFICATION_PROCESS) {
+
+ String error;
+
+ if (!blend_space->get_graph_player()) {
+ error = TTR("BlendSpace does not belong to an AnimationGraphPlayer node.");
+ } else if (!blend_space->get_graph_player()->is_active()) {
+ error = TTR("AnimationGraphPlayer is inactive.\nActivate to enable playback, check node warnings if activation fails.");
+ } else if (blend_space->get_graph_player()->is_state_invalid()) {
+ error = blend_space->get_graph_player()->get_invalid_state_reason();
+ } else if (blend_space->get_triangle_count() == 0) {
+ error = TTR("No triangles exist, so no blending can take place.");
+ }
+
+ if (error != error_label->get_text()) {
+ error_label->set_text(error);
+ if (error != String()) {
+ error_panel->show();
+ } else {
+ error_panel->hide();
+ }
+ }
+ }
+}
+
+void AnimationNodeBlendSpaceEditor::_open_editor() {
+
+ if (selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) {
+ Ref<AnimationNode> an = blend_space->get_blend_point_node(selected_point);
+ ERR_FAIL_COND(!an.is_valid());
+ EditorNode::get_singleton()->edit_item(an.ptr());
+ }
+}
+
+void AnimationNodeBlendSpaceEditor::_goto_parent() {
+
+ EditorNode::get_singleton()->edit_item(blend_space->get_parent().ptr());
+}
+
+void AnimationNodeBlendSpaceEditor::_removed_from_graph() {
+ EditorNode::get_singleton()->edit_item(NULL);
+}
+
+void AnimationNodeBlendSpaceEditor::_auto_triangles_toggled() {
+
+ undo_redo->create_action("Toggle Auto Triangles");
+ undo_redo->add_do_method(blend_space.ptr(), "set_auto_triangles", auto_triangles->is_pressed());
+ undo_redo->add_undo_method(blend_space.ptr(), "set_auto_triangles", blend_space->get_auto_triangles());
+ undo_redo->add_do_method(this, "_update_space");
+ undo_redo->add_undo_method(this, "_update_space");
+ undo_redo->commit_action();
+}
+
+void AnimationNodeBlendSpaceEditor::_bind_methods() {
+
+ ClassDB::bind_method("_blend_space_gui_input", &AnimationNodeBlendSpaceEditor::_blend_space_gui_input);
+ ClassDB::bind_method("_blend_space_draw", &AnimationNodeBlendSpaceEditor::_blend_space_draw);
+ ClassDB::bind_method("_config_changed", &AnimationNodeBlendSpaceEditor::_config_changed);
+ ClassDB::bind_method("_labels_changed", &AnimationNodeBlendSpaceEditor::_labels_changed);
+ ClassDB::bind_method("_update_space", &AnimationNodeBlendSpaceEditor::_update_space);
+ ClassDB::bind_method("_snap_toggled", &AnimationNodeBlendSpaceEditor::_snap_toggled);
+ ClassDB::bind_method("_tool_switch", &AnimationNodeBlendSpaceEditor::_tool_switch);
+ ClassDB::bind_method("_erase_selected", &AnimationNodeBlendSpaceEditor::_erase_selected);
+ ClassDB::bind_method("_update_tool_erase", &AnimationNodeBlendSpaceEditor::_update_tool_erase);
+ ClassDB::bind_method("_edit_point_pos", &AnimationNodeBlendSpaceEditor::_edit_point_pos);
+
+ ClassDB::bind_method("_add_menu_type", &AnimationNodeBlendSpaceEditor::_add_menu_type);
+ ClassDB::bind_method("_add_animation_type", &AnimationNodeBlendSpaceEditor::_add_animation_type);
+
+ ClassDB::bind_method("_update_edited_point_pos", &AnimationNodeBlendSpaceEditor::_update_edited_point_pos);
+
+ ClassDB::bind_method("_open_editor", &AnimationNodeBlendSpaceEditor::_open_editor);
+ ClassDB::bind_method("_goto_parent", &AnimationNodeBlendSpaceEditor::_goto_parent);
+
+ ClassDB::bind_method("_removed_from_graph", &AnimationNodeBlendSpaceEditor::_removed_from_graph);
+
+ ClassDB::bind_method("_auto_triangles_toggled", &AnimationNodeBlendSpaceEditor::_auto_triangles_toggled);
+}
+
+AnimationNodeBlendSpaceEditor *AnimationNodeBlendSpaceEditor::singleton = NULL;
+
+AnimationNodeBlendSpaceEditor::AnimationNodeBlendSpaceEditor() {
+
+ singleton = this;
+ updating = false;
+
+ HBoxContainer *top_hb = memnew(HBoxContainer);
+ add_child(top_hb);
+
+ Ref<ButtonGroup> bg;
+ bg.instance();
+
+ goto_parent_hb = memnew(HBoxContainer);
+ top_hb->add_child(goto_parent_hb);
+ goto_parent = memnew(ToolButton);
+ goto_parent->connect("pressed", this, "_goto_parent", varray(), CONNECT_DEFERRED);
+ goto_parent_hb->add_child(goto_parent);
+ goto_parent_hb->add_child(memnew(VSeparator));
+ goto_parent_hb->hide();
+
+ tool_blend = memnew(ToolButton);
+ tool_blend->set_toggle_mode(true);
+ tool_blend->set_button_group(bg);
+ top_hb->add_child(tool_blend);
+ tool_blend->set_pressed(true);
+ tool_blend->set_tooltip(TTR("Set the blending position within the space"));
+ tool_blend->connect("pressed", this, "_tool_switch", varray(3));
+
+ tool_select = memnew(ToolButton);
+ tool_select->set_toggle_mode(true);
+ tool_select->set_button_group(bg);
+ top_hb->add_child(tool_select);
+ tool_select->set_tooltip(TTR("Select and move points, create points with RMB."));
+ tool_select->connect("pressed", this, "_tool_switch", varray(0));
+
+ tool_create = memnew(ToolButton);
+ tool_create->set_toggle_mode(true);
+ tool_create->set_button_group(bg);
+ top_hb->add_child(tool_create);
+ tool_create->set_tooltip(TTR("Create points."));
+ tool_create->connect("pressed", this, "_tool_switch", varray(1));
+
+ tool_triangle = memnew(ToolButton);
+ tool_triangle->set_toggle_mode(true);
+ tool_triangle->set_button_group(bg);
+ top_hb->add_child(tool_triangle);
+ tool_triangle->set_tooltip(TTR("Create triangles by connecting points."));
+ tool_triangle->connect("pressed", this, "_tool_switch", varray(2));
+
+ tool_erase_sep = memnew(VSeparator);
+ top_hb->add_child(tool_erase_sep);
+ tool_erase = memnew(ToolButton);
+ top_hb->add_child(tool_erase);
+ tool_erase->set_tooltip(TTR("Erase points and triangles."));
+ tool_erase->connect("pressed", this, "_erase_selected");
+ tool_erase->set_disabled(true);
+
+ top_hb->add_child(memnew(VSeparator));
+
+ auto_triangles = memnew(ToolButton);
+ top_hb->add_child(auto_triangles);
+ auto_triangles->connect("pressed", this, "_auto_triangles_toggled");
+ auto_triangles->set_toggle_mode(true);
+ auto_triangles->set_tooltip(TTR("Generate blend triangles automatically (instead of manually)"));
+
+ top_hb->add_child(memnew(VSeparator));
+
+ snap = memnew(ToolButton);
+ snap->set_toggle_mode(true);
+ top_hb->add_child(snap);
+ //snap->set_text(TTR("Snap"));
+ snap->set_pressed(true);
+ snap->connect("pressed", this, "_snap_toggled");
+
+ snap_x = memnew(SpinBox);
+ top_hb->add_child(snap_x);
+ snap_x->set_prefix("x:");
+ snap_x->set_min(0.01);
+ snap_x->set_step(0.01);
+ snap_x->set_max(1000);
+
+ snap_y = memnew(SpinBox);
+ top_hb->add_child(snap_y);
+ snap_y->set_prefix("y:");
+ snap_y->set_min(0.01);
+ snap_y->set_step(0.01);
+ snap_y->set_max(1000);
+
+ edit_hb = memnew(HBoxContainer);
+ top_hb->add_child(edit_hb);
+ edit_hb->add_child(memnew(VSeparator));
+ edit_hb->add_child(memnew(Label(TTR("Point"))));
+ edit_x = memnew(SpinBox);
+ edit_hb->add_child(edit_x);
+ edit_x->set_min(-1000);
+ edit_x->set_step(0.01);
+ edit_x->set_max(1000);
+ edit_x->connect("value_changed", this, "_edit_point_pos");
+ edit_y = memnew(SpinBox);
+ edit_hb->add_child(edit_y);
+ edit_y->set_min(-1000);
+ edit_y->set_step(0.01);
+ edit_y->set_max(1000);
+ edit_y->connect("value_changed", this, "_edit_point_pos");
+ open_editor = memnew(Button);
+ edit_hb->add_child(open_editor);
+ open_editor->set_text(TTR("Open Editor"));
+ open_editor->connect("pressed", this, "_open_editor", varray(), CONNECT_DEFERRED);
+ edit_hb->hide();
+ open_editor->hide();
+
+ HBoxContainer *main_hb = memnew(HBoxContainer);
+ add_child(main_hb);
+ main_hb->set_v_size_flags(SIZE_EXPAND_FILL);
+
+ GridContainer *main_grid = memnew(GridContainer);
+ main_grid->set_columns(2);
+ main_hb->add_child(main_grid);
+ main_grid->set_h_size_flags(SIZE_EXPAND_FILL);
+ {
+ VBoxContainer *left_vbox = memnew(VBoxContainer);
+ main_grid->add_child(left_vbox);
+ left_vbox->set_v_size_flags(SIZE_EXPAND_FILL);
+ max_y_value = memnew(SpinBox);
+ left_vbox->add_child(max_y_value);
+ left_vbox->add_spacer();
+ label_y = memnew(LineEdit);
+ left_vbox->add_child(label_y);
+ label_y->set_expand_to_text_length(true);
+ left_vbox->add_spacer();
+ min_y_value = memnew(SpinBox);
+ left_vbox->add_child(min_y_value);
+
+ max_y_value->set_max(10000);
+ max_y_value->set_min(0.01);
+ max_y_value->set_step(0.01);
+
+ min_y_value->set_min(-10000);
+ min_y_value->set_max(0);
+ min_y_value->set_step(0.01);
+ }
+
+ panel = memnew(PanelContainer);
+ panel->set_clip_contents(true);
+ main_grid->add_child(panel);
+ panel->set_h_size_flags(SIZE_EXPAND_FILL);
+
+ blend_space_draw = memnew(Control);
+ blend_space_draw->connect("gui_input", this, "_blend_space_gui_input");
+ blend_space_draw->connect("draw", this, "_blend_space_draw");
+ blend_space_draw->set_focus_mode(FOCUS_ALL);
+
+ panel->add_child(blend_space_draw);
+ main_grid->add_child(memnew(Control)); //empty bottom left
+
+ {
+ HBoxContainer *bottom_vbox = memnew(HBoxContainer);
+ main_grid->add_child(bottom_vbox);
+ bottom_vbox->set_h_size_flags(SIZE_EXPAND_FILL);
+ min_x_value = memnew(SpinBox);
+ bottom_vbox->add_child(min_x_value);
+ bottom_vbox->add_spacer();
+ label_x = memnew(LineEdit);
+ bottom_vbox->add_child(label_x);
+ label_x->set_expand_to_text_length(true);
+ bottom_vbox->add_spacer();
+ max_x_value = memnew(SpinBox);
+ bottom_vbox->add_child(max_x_value);
+
+ max_x_value->set_max(10000);
+ max_x_value->set_min(0.01);
+ max_x_value->set_step(0.01);
+
+ min_x_value->set_min(-10000);
+ min_x_value->set_max(0);
+ min_x_value->set_step(0.01);
+ }
+
+ snap_x->connect("value_changed", this, "_config_changed");
+ snap_y->connect("value_changed", this, "_config_changed");
+ max_x_value->connect("value_changed", this, "_config_changed");
+ min_x_value->connect("value_changed", this, "_config_changed");
+ max_y_value->connect("value_changed", this, "_config_changed");
+ min_y_value->connect("value_changed", this, "_config_changed");
+ label_x->connect("text_changed", this, "_labels_changed");
+ label_y->connect("text_changed", this, "_labels_changed");
+
+ error_panel = memnew(PanelContainer);
+ add_child(error_panel);
+ error_label = memnew(Label);
+ error_panel->add_child(error_label);
+ error_label->set_text("eh");
+
+ undo_redo = EditorNode::get_singleton()->get_undo_redo();
+
+ set_custom_minimum_size(Size2(0, 300 * EDSCALE));
+
+ menu = memnew(PopupMenu);
+ add_child(menu);
+ menu->connect("index_pressed", this, "_add_menu_type");
+
+ animations_menu = memnew(PopupMenu);
+ menu->add_child(animations_menu);
+ animations_menu->set_name("animations");
+ animations_menu->connect("index_pressed", this, "_add_animation_type");
+
+ selected_point = -1;
+ selected_triangle = -1;
+
+ dragging_selected = false;
+ dragging_selected_attempt = false;
+}
+
+void AnimationNodeBlendSpaceEditorPlugin::edit(Object *p_object) {
+
+ anim_tree_editor->edit(Object::cast_to<AnimationNodeBlendSpace>(p_object));
+}
+
+bool AnimationNodeBlendSpaceEditorPlugin::handles(Object *p_object) const {
+
+ return p_object->is_class("AnimationNodeBlendSpace");
+}
+
+void AnimationNodeBlendSpaceEditorPlugin::make_visible(bool p_visible) {
+
+ if (p_visible) {
+ //editor->hide_animation_player_editors();
+ //editor->animation_panel_make_visible(true);
+ button->show();
+ editor->make_bottom_panel_item_visible(anim_tree_editor);
+ anim_tree_editor->set_process(true);
+ } else {
+
+ if (anim_tree_editor->is_visible_in_tree())
+ editor->hide_bottom_panel();
+ button->hide();
+ anim_tree_editor->set_process(false);
+ }
+}
+
+AnimationNodeBlendSpaceEditorPlugin::AnimationNodeBlendSpaceEditorPlugin(EditorNode *p_node) {
+
+ editor = p_node;
+ anim_tree_editor = memnew(AnimationNodeBlendSpaceEditor);
+ anim_tree_editor->set_custom_minimum_size(Size2(0, 300));
+
+ button = editor->add_bottom_panel_item(TTR("BlendSpace"), anim_tree_editor);
+ button->hide();
+}
+
+AnimationNodeBlendSpaceEditorPlugin::~AnimationNodeBlendSpaceEditorPlugin() {
+}
diff --git a/editor/plugins/animation_blend_space_editor.h b/editor/plugins/animation_blend_space_editor.h
new file mode 100644
index 0000000000..66d2ec6cae
--- /dev/null
+++ b/editor/plugins/animation_blend_space_editor.h
@@ -0,0 +1,130 @@
+#ifndef ANIMATION_BLEND_SPACE_EDITOR_H
+#define ANIMATION_BLEND_SPACE_EDITOR_H
+
+#include "editor/editor_node.h"
+#include "editor/editor_plugin.h"
+#include "editor/property_editor.h"
+#include "scene/animation/animation_blend_space.h"
+#include "scene/gui/button.h"
+#include "scene/gui/graph_edit.h"
+#include "scene/gui/popup.h"
+#include "scene/gui/tree.h"
+/**
+ @author Juan Linietsky <reduzio@gmail.com>
+*/
+
+class AnimationNodeBlendSpaceEditor : public VBoxContainer {
+
+ GDCLASS(AnimationNodeBlendSpaceEditor, VBoxContainer);
+
+ Ref<AnimationNodeBlendSpace> blend_space;
+
+ HBoxContainer *goto_parent_hb;
+ ToolButton *goto_parent;
+
+ PanelContainer *panel;
+ ToolButton *tool_blend;
+ ToolButton *tool_select;
+ ToolButton *tool_create;
+ ToolButton *tool_triangle;
+ VSeparator *tool_erase_sep;
+ ToolButton *tool_erase;
+ ToolButton *snap;
+ SpinBox *snap_x;
+ SpinBox *snap_y;
+
+ ToolButton *auto_triangles;
+
+ LineEdit *label_x;
+ LineEdit *label_y;
+ SpinBox *max_x_value;
+ SpinBox *min_x_value;
+ SpinBox *max_y_value;
+ SpinBox *min_y_value;
+
+ HBoxContainer *edit_hb;
+ SpinBox *edit_x;
+ SpinBox *edit_y;
+ Button *open_editor;
+
+ int selected_point;
+ int selected_triangle;
+
+ Control *blend_space_draw;
+
+ PanelContainer *error_panel;
+ Label *error_label;
+
+ bool updating;
+
+ UndoRedo *undo_redo;
+
+ static AnimationNodeBlendSpaceEditor *singleton;
+
+ void _blend_space_gui_input(const Ref<InputEvent> &p_event);
+ void _blend_space_draw();
+
+ void _update_space();
+
+ void _config_changed(double);
+ void _labels_changed(String);
+ void _snap_toggled();
+
+ PopupMenu *menu;
+ PopupMenu *animations_menu;
+ Vector<String> animations_to_add;
+ Vector2 add_point_pos;
+ Vector<Vector2> points;
+
+ bool dragging_selected_attempt;
+ bool dragging_selected;
+ Vector2 drag_from;
+ Vector2 drag_ofs;
+
+ Vector<int> making_triangle;
+
+ void _add_menu_type(int p_index);
+ void _add_animation_type(int p_index);
+
+ void _tool_switch(int p_tool);
+ void _update_edited_point_pos();
+ void _update_tool_erase();
+ void _erase_selected();
+ void _edit_point_pos(double);
+ void _open_editor();
+
+ void _goto_parent();
+
+ void _removed_from_graph();
+
+ void _auto_triangles_toggled();
+
+protected:
+ void _notification(int p_what);
+ static void _bind_methods();
+
+public:
+ static AnimationNodeBlendSpaceEditor *get_singleton() { return singleton; }
+ void edit(AnimationNodeBlendSpace *p_blend_space);
+ AnimationNodeBlendSpaceEditor();
+};
+
+class AnimationNodeBlendSpaceEditorPlugin : public EditorPlugin {
+
+ GDCLASS(AnimationNodeBlendSpaceEditorPlugin, EditorPlugin);
+
+ AnimationNodeBlendSpaceEditor *anim_tree_editor;
+ EditorNode *editor;
+ Button *button;
+
+public:
+ virtual String get_name() const { return "BlendSpace"; }
+ bool has_main_screen() const { return false; }
+ virtual void edit(Object *p_object);
+ virtual bool handles(Object *p_object) const;
+ virtual void make_visible(bool p_visible);
+
+ AnimationNodeBlendSpaceEditorPlugin(EditorNode *p_node);
+ ~AnimationNodeBlendSpaceEditorPlugin();
+};
+#endif // ANIMATION_BLEND_SPACE_EDITOR_H
diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp
index f466758917..0875c93a16 100644
--- a/editor/plugins/animation_blend_tree_editor_plugin.cpp
+++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp
@@ -11,11 +11,21 @@
void AnimationNodeBlendTreeEditor::edit(AnimationNodeBlendTree *p_blend_tree) {
- blend_tree = p_blend_tree;
+ if (blend_tree.is_valid()) {
+ blend_tree->disconnect("removed_from_graph", this, "_removed_from_graph");
+ }
- if (!blend_tree) {
+ if (p_blend_tree) {
+ blend_tree = Ref<AnimationNodeBlendTree>(p_blend_tree);
+ } else {
+ blend_tree.unref();
+ }
+
+ if (blend_tree.is_null()) {
hide();
} else {
+ blend_tree->connect("removed_from_graph", this, "_removed_from_graph");
+
_update_graph();
}
}
@@ -66,7 +76,7 @@ void AnimationNodeBlendTreeEditor::_update_graph() {
graph->set_scroll_ofs(blend_tree->get_graph_offset() * EDSCALE);
- if (blend_tree->get_tree().is_valid()) {
+ if (blend_tree->get_parent().is_valid()) {
goto_parent->show();
} else {
goto_parent->hide();
@@ -247,8 +257,8 @@ void AnimationNodeBlendTreeEditor::_add_node(int p_idx) {
}
undo_redo->create_action("Add Node to BlendTree");
- undo_redo->add_do_method(blend_tree, "add_node", name, anode);
- undo_redo->add_undo_method(blend_tree, "remove_node", name);
+ undo_redo->add_do_method(blend_tree.ptr(), "add_node", name, anode);
+ undo_redo->add_undo_method(blend_tree.ptr(), "remove_node", name);
undo_redo->add_do_method(this, "_update_graph");
undo_redo->add_undo_method(this, "_update_graph");
undo_redo->commit_action();
@@ -276,8 +286,8 @@ void AnimationNodeBlendTreeEditor::_connection_request(const String &p_from, int
}
undo_redo->create_action("Nodes Connected");
- undo_redo->add_do_method(blend_tree, "connect_node", p_to, p_to_index, p_from);
- undo_redo->add_undo_method(blend_tree, "disconnect_node", p_to, p_to_index, p_from);
+ undo_redo->add_do_method(blend_tree.ptr(), "connect_node", p_to, p_to_index, p_from);
+ undo_redo->add_undo_method(blend_tree.ptr(), "disconnect_node", p_to, p_to_index, p_from);
undo_redo->add_do_method(this, "_update_graph");
undo_redo->add_undo_method(this, "_update_graph");
undo_redo->commit_action();
@@ -289,8 +299,8 @@ void AnimationNodeBlendTreeEditor::_disconnection_request(const String &p_from,
updating = true;
undo_redo->create_action("Nodes Disconnected");
- undo_redo->add_do_method(blend_tree, "disconnect_node", p_to, p_to_index);
- undo_redo->add_undo_method(blend_tree, "connect_node", p_to, p_to_index, p_from);
+ undo_redo->add_do_method(blend_tree.ptr(), "disconnect_node", p_to, p_to_index);
+ undo_redo->add_undo_method(blend_tree.ptr(), "connect_node", p_to, p_to_index, p_from);
undo_redo->add_do_method(this, "_update_graph");
undo_redo->add_undo_method(this, "_update_graph");
undo_redo->commit_action();
@@ -315,15 +325,15 @@ void AnimationNodeBlendTreeEditor::_anim_selected(int p_index, Array p_options,
void AnimationNodeBlendTreeEditor::_delete_request(const String &p_which) {
undo_redo->create_action("Delete Node");
- undo_redo->add_do_method(blend_tree, "remove_node", p_which);
- undo_redo->add_undo_method(blend_tree, "add_node", p_which, blend_tree->get_node(p_which));
+ undo_redo->add_do_method(blend_tree.ptr(), "remove_node", p_which);
+ undo_redo->add_undo_method(blend_tree.ptr(), "add_node", p_which, blend_tree->get_node(p_which));
List<AnimationNodeBlendTree::NodeConnection> conns;
blend_tree->get_node_connections(&conns);
for (List<AnimationNodeBlendTree::NodeConnection>::Element *E = conns.front(); E; E = E->next()) {
if (E->get().output_node == p_which || E->get().input_node == p_which) {
- undo_redo->add_undo_method(blend_tree, "connect_node", E->get().input_node, E->get().input_index, E->get().output_node);
+ undo_redo->add_undo_method(blend_tree.ptr(), "connect_node", E->get().input_node, E->get().input_index, E->get().output_node);
}
}
@@ -367,8 +377,8 @@ void AnimationNodeBlendTreeEditor::_open_in_editor(const String &p_which) {
}
void AnimationNodeBlendTreeEditor::_open_parent() {
- if (blend_tree->get_tree().is_valid()) {
- EditorNode::get_singleton()->edit_item(blend_tree->get_tree().ptr());
+ if (blend_tree->get_parent().is_valid()) {
+ EditorNode::get_singleton()->edit_item(blend_tree->get_parent().ptr());
}
}
@@ -573,6 +583,12 @@ void AnimationNodeBlendTreeEditor::_edit_filters(const String &p_which) {
filter_dialog->popup_centered_minsize(Size2(500, 500) * EDSCALE);
}
+void AnimationNodeBlendTreeEditor::_removed_from_graph() {
+ if (is_visible()) {
+ EditorNode::get_singleton()->edit_item(NULL);
+ }
+}
+
void AnimationNodeBlendTreeEditor::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
@@ -648,7 +664,7 @@ void AnimationNodeBlendTreeEditor::_scroll_changed(const Vector2 &p_scroll) {
void AnimationNodeBlendTreeEditor::_node_changed(ObjectID p_node) {
AnimationNode *an = Object::cast_to<AnimationNode>(ObjectDB::get_instance(p_node));
- if (an && an->get_tree() == blend_tree) {
+ if (an && an->get_parent() == blend_tree) {
_update_graph();
}
}
@@ -674,6 +690,7 @@ void AnimationNodeBlendTreeEditor::_bind_methods() {
ClassDB::bind_method("_oneshot_start", &AnimationNodeBlendTreeEditor::_oneshot_start);
ClassDB::bind_method("_oneshot_stop", &AnimationNodeBlendTreeEditor::_oneshot_stop);
ClassDB::bind_method("_node_changed", &AnimationNodeBlendTreeEditor::_node_changed);
+ ClassDB::bind_method("_removed_from_graph", &AnimationNodeBlendTreeEditor::_removed_from_graph);
ClassDB::bind_method("_anim_selected", &AnimationNodeBlendTreeEditor::_anim_selected);
}
@@ -703,8 +720,8 @@ void AnimationNodeBlendTreeEditor::_node_renamed(const String &p_text, Ref<Anima
updating = true;
undo_redo->create_action("Node Renamed");
- undo_redo->add_do_method(blend_tree, "rename_node", prev_name, name);
- undo_redo->add_undo_method(blend_tree, "rename_node", name, prev_name);
+ undo_redo->add_do_method(blend_tree.ptr(), "rename_node", prev_name, name);
+ undo_redo->add_undo_method(blend_tree.ptr(), "rename_node", name, prev_name);
undo_redo->add_do_method(this, "_update_graph");
undo_redo->add_undo_method(this, "_update_graph");
undo_redo->commit_action();
@@ -722,7 +739,6 @@ AnimationNodeBlendTreeEditor::AnimationNodeBlendTreeEditor() {
singleton = this;
updating = false;
- blend_tree = NULL;
graph = memnew(GraphEdit);
add_child(graph);
graph->add_valid_right_disconnect_type(0);
@@ -737,19 +753,18 @@ AnimationNodeBlendTreeEditor::AnimationNodeBlendTreeEditor() {
graph->get_zoom_hbox()->add_child(vs);
graph->get_zoom_hbox()->move_child(vs, 0);
- goto_parent = memnew(Button);
- goto_parent->set_text(TTR("Goto Parent"));
- graph->get_zoom_hbox()->add_child(goto_parent);
- graph->get_zoom_hbox()->move_child(goto_parent, 0);
- goto_parent->hide();
- goto_parent->connect("pressed", this, "_open_parent");
-
add_node = memnew(MenuButton);
graph->get_zoom_hbox()->add_child(add_node);
add_node->set_text(TTR("Add Node.."));
graph->get_zoom_hbox()->move_child(add_node, 0);
add_node->get_popup()->connect("index_pressed", this, "_add_node");
+ goto_parent = memnew(Button);
+ graph->get_zoom_hbox()->add_child(goto_parent);
+ graph->get_zoom_hbox()->move_child(goto_parent, 0);
+ goto_parent->hide();
+ goto_parent->connect("pressed", this, "_open_parent");
+
add_options.push_back(AddOption("Animation", "AnimationNodeAnimation"));
add_options.push_back(AddOption("OneShot", "AnimationNodeOneShot"));
add_options.push_back(AddOption("Add", "AnimationNodeAdd"));
@@ -759,6 +774,7 @@ AnimationNodeBlendTreeEditor::AnimationNodeBlendTreeEditor() {
add_options.push_back(AddOption("TimeScale", "AnimationNodeTimeScale"));
add_options.push_back(AddOption("Transition", "AnimationNodeTransition"));
add_options.push_back(AddOption("BlendTree", "AnimationNodeBlendTree"));
+ add_options.push_back(AddOption("BlendSpace", "AnimationNodeBlendSpace"));
_update_options_menu();
error_panel = memnew(PanelContainer);
diff --git a/editor/plugins/animation_blend_tree_editor_plugin.h b/editor/plugins/animation_blend_tree_editor_plugin.h
index 71efed6da6..deba3b2b0e 100644
--- a/editor/plugins/animation_blend_tree_editor_plugin.h
+++ b/editor/plugins/animation_blend_tree_editor_plugin.h
@@ -17,7 +17,7 @@ class AnimationNodeBlendTreeEditor : public VBoxContainer {
GDCLASS(AnimationNodeBlendTreeEditor, VBoxContainer);
- AnimationNodeBlendTree *blend_tree;
+ Ref<AnimationNodeBlendTree> blend_tree;
GraphEdit *graph;
MenuButton *add_node;
Button *goto_parent;
@@ -78,6 +78,8 @@ class AnimationNodeBlendTreeEditor : public VBoxContainer {
void _node_changed(ObjectID p_node);
+ void _removed_from_graph();
+
protected:
void _notification(int p_what);
static void _bind_methods();