Path: blob/master/scene/animation/animation_blend_space_2d.cpp
9896 views
/**************************************************************************/1/* animation_blend_space_2d.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "animation_blend_space_2d.h"3132#include "animation_blend_tree.h"33#include "core/math/geometry_2d.h"3435void AnimationNodeBlendSpace2D::get_parameter_list(List<PropertyInfo> *r_list) const {36AnimationNode::get_parameter_list(r_list);37r_list->push_back(PropertyInfo(Variant::VECTOR2, blend_position));38r_list->push_back(PropertyInfo(Variant::INT, closest, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE));39}4041Variant AnimationNodeBlendSpace2D::get_parameter_default_value(const StringName &p_parameter) const {42Variant ret = AnimationNode::get_parameter_default_value(p_parameter);43if (ret != Variant()) {44return ret;45}4647if (p_parameter == closest) {48return (int)-1;49} else {50return Vector2();51}52}5354void AnimationNodeBlendSpace2D::get_child_nodes(List<ChildNode> *r_child_nodes) {55for (int i = 0; i < blend_points_used; i++) {56ChildNode cn;57cn.name = itos(i);58cn.node = blend_points[i].node;59r_child_nodes->push_back(cn);60}61}6263void AnimationNodeBlendSpace2D::add_blend_point(const Ref<AnimationRootNode> &p_node, const Vector2 &p_position, int p_at_index) {64ERR_FAIL_COND(blend_points_used >= MAX_BLEND_POINTS);65ERR_FAIL_COND(p_node.is_null());66ERR_FAIL_COND(p_at_index < -1 || p_at_index > blend_points_used);6768if (p_at_index == -1 || p_at_index == blend_points_used) {69p_at_index = blend_points_used;70} else {71for (int i = blend_points_used - 1; i > p_at_index; i--) {72blend_points[i] = blend_points[i - 1];73}74for (int i = 0; i < triangles.size(); i++) {75for (int j = 0; j < 3; j++) {76if (triangles[i].points[j] >= p_at_index) {77triangles.write[i].points[j]++;78}79}80}81}82blend_points[p_at_index].node = p_node;83blend_points[p_at_index].position = p_position;8485blend_points[p_at_index].node->connect("tree_changed", callable_mp(this, &AnimationNodeBlendSpace2D::_tree_changed), CONNECT_REFERENCE_COUNTED);86blend_points[p_at_index].node->connect("animation_node_renamed", callable_mp(this, &AnimationNodeBlendSpace2D::_animation_node_renamed), CONNECT_REFERENCE_COUNTED);87blend_points[p_at_index].node->connect("animation_node_removed", callable_mp(this, &AnimationNodeBlendSpace2D::_animation_node_removed), CONNECT_REFERENCE_COUNTED);88blend_points_used++;8990_queue_auto_triangles();9192emit_signal(SNAME("tree_changed"));93}9495void AnimationNodeBlendSpace2D::set_blend_point_position(int p_point, const Vector2 &p_position) {96ERR_FAIL_INDEX(p_point, blend_points_used);97blend_points[p_point].position = p_position;98_queue_auto_triangles();99}100101void AnimationNodeBlendSpace2D::set_blend_point_node(int p_point, const Ref<AnimationRootNode> &p_node) {102ERR_FAIL_INDEX(p_point, blend_points_used);103ERR_FAIL_COND(p_node.is_null());104105if (blend_points[p_point].node.is_valid()) {106blend_points[p_point].node->disconnect("tree_changed", callable_mp(this, &AnimationNodeBlendSpace2D::_tree_changed));107blend_points[p_point].node->disconnect("animation_node_renamed", callable_mp(this, &AnimationNodeBlendSpace2D::_animation_node_renamed));108blend_points[p_point].node->disconnect("animation_node_removed", callable_mp(this, &AnimationNodeBlendSpace2D::_animation_node_removed));109}110blend_points[p_point].node = p_node;111blend_points[p_point].node->connect("tree_changed", callable_mp(this, &AnimationNodeBlendSpace2D::_tree_changed), CONNECT_REFERENCE_COUNTED);112blend_points[p_point].node->connect("animation_node_renamed", callable_mp(this, &AnimationNodeBlendSpace2D::_animation_node_renamed), CONNECT_REFERENCE_COUNTED);113blend_points[p_point].node->connect("animation_node_removed", callable_mp(this, &AnimationNodeBlendSpace2D::_animation_node_removed), CONNECT_REFERENCE_COUNTED);114115emit_signal(SNAME("tree_changed"));116}117118Vector2 AnimationNodeBlendSpace2D::get_blend_point_position(int p_point) const {119ERR_FAIL_INDEX_V(p_point, MAX_BLEND_POINTS, Vector2());120return blend_points[p_point].position;121}122123Ref<AnimationRootNode> AnimationNodeBlendSpace2D::get_blend_point_node(int p_point) const {124ERR_FAIL_INDEX_V(p_point, MAX_BLEND_POINTS, Ref<AnimationRootNode>());125return blend_points[p_point].node;126}127128void AnimationNodeBlendSpace2D::remove_blend_point(int p_point) {129ERR_FAIL_INDEX(p_point, blend_points_used);130131ERR_FAIL_COND(blend_points[p_point].node.is_null());132blend_points[p_point].node->disconnect("tree_changed", callable_mp(this, &AnimationNodeBlendSpace2D::_tree_changed));133blend_points[p_point].node->disconnect("animation_node_renamed", callable_mp(this, &AnimationNodeBlendSpace2D::_animation_node_renamed));134blend_points[p_point].node->disconnect("animation_node_removed", callable_mp(this, &AnimationNodeBlendSpace2D::_animation_node_removed));135136for (int i = 0; i < triangles.size(); i++) {137bool erase = false;138for (int j = 0; j < 3; j++) {139if (triangles[i].points[j] == p_point) {140erase = true;141break;142} else if (triangles[i].points[j] > p_point) {143triangles.write[i].points[j]--;144}145}146if (erase) {147triangles.remove_at(i);148149i--;150}151}152153for (int i = p_point; i < blend_points_used - 1; i++) {154blend_points[i] = blend_points[i + 1];155}156blend_points_used--;157158emit_signal(SNAME("animation_node_removed"), get_instance_id(), itos(p_point));159emit_signal(SNAME("tree_changed"));160}161162int AnimationNodeBlendSpace2D::get_blend_point_count() const {163return blend_points_used;164}165166bool AnimationNodeBlendSpace2D::has_triangle(int p_x, int p_y, int p_z) const {167ERR_FAIL_INDEX_V(p_x, blend_points_used, false);168ERR_FAIL_INDEX_V(p_y, blend_points_used, false);169ERR_FAIL_INDEX_V(p_z, blend_points_used, false);170171BlendTriangle t;172t.points[0] = p_x;173t.points[1] = p_y;174t.points[2] = p_z;175176SortArray<int> sort;177sort.sort(t.points, 3);178179for (int i = 0; i < triangles.size(); i++) {180bool all_equal = true;181for (int j = 0; j < 3; j++) {182if (triangles[i].points[j] != t.points[j]) {183all_equal = false;184break;185}186}187if (all_equal) {188return true;189}190}191192return false;193}194195void AnimationNodeBlendSpace2D::add_triangle(int p_x, int p_y, int p_z, int p_at_index) {196ERR_FAIL_INDEX(p_x, blend_points_used);197ERR_FAIL_INDEX(p_y, blend_points_used);198ERR_FAIL_INDEX(p_z, blend_points_used);199200_update_triangles();201202BlendTriangle t;203t.points[0] = p_x;204t.points[1] = p_y;205t.points[2] = p_z;206207SortArray<int> sort;208sort.sort(t.points, 3);209210for (int i = 0; i < triangles.size(); i++) {211bool all_equal = true;212for (int j = 0; j < 3; j++) {213if (triangles[i].points[j] != t.points[j]) {214all_equal = false;215break;216}217}218ERR_FAIL_COND(all_equal);219}220221if (p_at_index == -1 || p_at_index == triangles.size()) {222triangles.push_back(t);223} else {224triangles.insert(p_at_index, t);225}226}227228int AnimationNodeBlendSpace2D::get_triangle_point(int p_triangle, int p_point) {229_update_triangles();230231ERR_FAIL_INDEX_V(p_point, 3, -1);232ERR_FAIL_INDEX_V(p_triangle, triangles.size(), -1);233return triangles[p_triangle].points[p_point];234}235236void AnimationNodeBlendSpace2D::remove_triangle(int p_triangle) {237ERR_FAIL_INDEX(p_triangle, triangles.size());238239triangles.remove_at(p_triangle);240}241242int AnimationNodeBlendSpace2D::get_triangle_count() const {243return triangles.size();244}245246void AnimationNodeBlendSpace2D::set_min_space(const Vector2 &p_min) {247min_space = p_min;248if (min_space.x >= max_space.x) {249min_space.x = max_space.x - 1;250}251if (min_space.y >= max_space.y) {252min_space.y = max_space.y - 1;253}254}255256Vector2 AnimationNodeBlendSpace2D::get_min_space() const {257return min_space;258}259260void AnimationNodeBlendSpace2D::set_max_space(const Vector2 &p_max) {261max_space = p_max;262if (max_space.x <= min_space.x) {263max_space.x = min_space.x + 1;264}265if (max_space.y <= min_space.y) {266max_space.y = min_space.y + 1;267}268}269270Vector2 AnimationNodeBlendSpace2D::get_max_space() const {271return max_space;272}273274void AnimationNodeBlendSpace2D::set_snap(const Vector2 &p_snap) {275snap = p_snap;276}277278Vector2 AnimationNodeBlendSpace2D::get_snap() const {279return snap;280}281282void AnimationNodeBlendSpace2D::set_x_label(const String &p_label) {283x_label = p_label;284}285286String AnimationNodeBlendSpace2D::get_x_label() const {287return x_label;288}289290void AnimationNodeBlendSpace2D::set_y_label(const String &p_label) {291y_label = p_label;292}293294String AnimationNodeBlendSpace2D::get_y_label() const {295return y_label;296}297298void AnimationNodeBlendSpace2D::_add_blend_point(int p_index, const Ref<AnimationRootNode> &p_node) {299if (p_index == blend_points_used) {300add_blend_point(p_node, Vector2());301} else {302set_blend_point_node(p_index, p_node);303}304}305306void AnimationNodeBlendSpace2D::_set_triangles(const Vector<int> &p_triangles) {307if (auto_triangles) {308return;309}310ERR_FAIL_COND(p_triangles.size() % 3 != 0);311for (int i = 0; i < p_triangles.size(); i += 3) {312add_triangle(p_triangles[i + 0], p_triangles[i + 1], p_triangles[i + 2]);313}314}315316Vector<int> AnimationNodeBlendSpace2D::_get_triangles() const {317Vector<int> t;318if (auto_triangles && triangles_dirty) {319return t;320}321322t.resize(triangles.size() * 3);323for (int i = 0; i < triangles.size(); i++) {324t.write[i * 3 + 0] = triangles[i].points[0];325t.write[i * 3 + 1] = triangles[i].points[1];326t.write[i * 3 + 2] = triangles[i].points[2];327}328return t;329}330331void AnimationNodeBlendSpace2D::_queue_auto_triangles() {332if (!auto_triangles || triangles_dirty) {333return;334}335336triangles_dirty = true;337callable_mp(this, &AnimationNodeBlendSpace2D::_update_triangles).call_deferred();338}339340void AnimationNodeBlendSpace2D::_update_triangles() {341if (!auto_triangles || !triangles_dirty) {342return;343}344345triangles_dirty = false;346triangles.clear();347if (blend_points_used < 3) {348emit_signal(SNAME("triangles_updated"));349return;350}351352Vector<Vector2> points;353points.resize(blend_points_used);354for (int i = 0; i < blend_points_used; i++) {355points.write[i] = blend_points[i].position;356}357358Vector<Delaunay2D::Triangle> tr = Delaunay2D::triangulate(points);359360for (int i = 0; i < tr.size(); i++) {361add_triangle(tr[i].points[0], tr[i].points[1], tr[i].points[2]);362}363emit_signal(SNAME("triangles_updated"));364}365366Vector2 AnimationNodeBlendSpace2D::get_closest_point(const Vector2 &p_point) {367_update_triangles();368369if (triangles.is_empty()) {370return Vector2();371}372373Vector2 best_point;374bool first = true;375376for (int i = 0; i < triangles.size(); i++) {377Vector2 points[3];378for (int j = 0; j < 3; j++) {379points[j] = get_blend_point_position(get_triangle_point(i, j));380}381382if (Geometry2D::is_point_in_triangle(p_point, points[0], points[1], points[2])) {383return p_point;384}385386for (int j = 0; j < 3; j++) {387const Vector2 segment_a = points[j];388const Vector2 segment_b = points[(j + 1) % 3];389Vector2 closest_point = Geometry2D::get_closest_point_to_segment(p_point, segment_a, segment_b);390if (first || closest_point.distance_to(p_point) < best_point.distance_to(p_point)) {391best_point = closest_point;392first = false;393}394}395}396397return best_point;398}399400void AnimationNodeBlendSpace2D::_blend_triangle(const Vector2 &p_pos, const Vector2 *p_points, float *r_weights) {401if (p_pos.is_equal_approx(p_points[0])) {402r_weights[0] = 1;403r_weights[1] = 0;404r_weights[2] = 0;405return;406}407if (p_pos.is_equal_approx(p_points[1])) {408r_weights[0] = 0;409r_weights[1] = 1;410r_weights[2] = 0;411return;412}413if (p_pos.is_equal_approx(p_points[2])) {414r_weights[0] = 0;415r_weights[1] = 0;416r_weights[2] = 1;417return;418}419420Vector2 v0 = p_points[1] - p_points[0];421Vector2 v1 = p_points[2] - p_points[0];422Vector2 v2 = p_pos - p_points[0];423424float d00 = v0.dot(v0);425float d01 = v0.dot(v1);426float d11 = v1.dot(v1);427float d20 = v2.dot(v0);428float d21 = v2.dot(v1);429float denom = (d00 * d11 - d01 * d01);430if (denom == 0) {431r_weights[0] = 1;432r_weights[1] = 0;433r_weights[2] = 0;434return;435}436float v = (d11 * d20 - d01 * d21) / denom;437float w = (d00 * d21 - d01 * d20) / denom;438float u = 1.0f - v - w;439440r_weights[0] = u;441r_weights[1] = v;442r_weights[2] = w;443}444445AnimationNode::NodeTimeInfo AnimationNodeBlendSpace2D::_process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only) {446_update_triangles();447448if (!blend_points_used) {449return NodeTimeInfo();450}451452Vector2 blend_pos = get_parameter(blend_position);453int cur_closest = get_parameter(closest);454NodeTimeInfo mind; //time of min distance point455456AnimationMixer::PlaybackInfo pi = p_playback_info;457458if (blend_mode == BLEND_MODE_INTERPOLATED) {459if (triangles.is_empty()) {460return NodeTimeInfo();461}462463Vector2 best_point;464bool first = true;465int blend_triangle = -1;466float blend_weights[3] = { 0, 0, 0 };467468for (int i = 0; i < triangles.size(); i++) {469Vector2 points[3];470for (int j = 0; j < 3; j++) {471points[j] = get_blend_point_position(get_triangle_point(i, j));472}473474if (Geometry2D::is_point_in_triangle(blend_pos, points[0], points[1], points[2])) {475blend_triangle = i;476_blend_triangle(blend_pos, points, blend_weights);477break;478}479480for (int j = 0; j < 3; j++) {481const Vector2 segment_a = points[j];482const Vector2 segment_b = points[(j + 1) % 3];483Vector2 closest2 = Geometry2D::get_closest_point_to_segment(blend_pos, segment_a, segment_b);484if (first || closest2.distance_to(blend_pos) < best_point.distance_to(blend_pos)) {485best_point = closest2;486blend_triangle = i;487first = false;488const real_t d = segment_a.distance_to(segment_b);489if (d == 0.0) {490blend_weights[j] = 1.0;491blend_weights[(j + 1) % 3] = 0.0;492blend_weights[(j + 2) % 3] = 0.0;493} else {494const real_t c = segment_a.distance_to(closest2) / d;495496blend_weights[j] = 1.0 - c;497blend_weights[(j + 1) % 3] = c;498blend_weights[(j + 2) % 3] = 0.0;499}500}501}502}503504ERR_FAIL_COND_V(blend_triangle == -1, NodeTimeInfo()); //should never reach here505506int triangle_points[3];507for (int j = 0; j < 3; j++) {508triangle_points[j] = get_triangle_point(blend_triangle, j);509}510511first = true;512513double max_weight = 0.0;514for (int i = 0; i < blend_points_used; i++) {515bool found = false;516for (int j = 0; j < 3; j++) {517if (i == triangle_points[j]) {518//blend with the given weight519pi.weight = blend_weights[j];520NodeTimeInfo t = blend_node(blend_points[i].node, blend_points[i].name, pi, FILTER_IGNORE, true, p_test_only);521if (first || pi.weight > max_weight) {522mind = t;523max_weight = pi.weight;524first = false;525}526found = true;527break;528}529}530531if (sync && !found) {532pi.weight = 0;533blend_node(blend_points[i].node, blend_points[i].name, pi, FILTER_IGNORE, true, p_test_only);534}535}536} else {537int new_closest = -1;538float new_closest_dist = 1e20;539540for (int i = 0; i < blend_points_used; i++) {541float d = blend_points[i].position.distance_squared_to(blend_pos);542if (d < new_closest_dist) {543new_closest = i;544new_closest_dist = d;545}546}547548if (new_closest != cur_closest && new_closest != -1) {549if (blend_mode == BLEND_MODE_DISCRETE_CARRY && cur_closest != -1) {550NodeTimeInfo from;551// For ping-pong loop.552Ref<AnimationNodeAnimation> na_c = static_cast<Ref<AnimationNodeAnimation>>(blend_points[cur_closest].node);553Ref<AnimationNodeAnimation> na_n = static_cast<Ref<AnimationNodeAnimation>>(blend_points[new_closest].node);554if (na_c.is_valid() && na_n.is_valid()) {555na_n->process_state = process_state;556na_c->process_state = process_state;557558na_n->set_backward(na_c->is_backward());559560na_n = nullptr;561na_c = nullptr;562}563// See how much animation remains.564pi.seeked = false;565pi.weight = 0;566from = blend_node(blend_points[cur_closest].node, blend_points[cur_closest].name, pi, FILTER_IGNORE, true, true);567pi.time = from.position;568}569pi.seeked = true;570pi.weight = 1.0;571mind = blend_node(blend_points[new_closest].node, blend_points[new_closest].name, pi, FILTER_IGNORE, true, p_test_only);572cur_closest = new_closest;573} else {574pi.weight = 1.0;575mind = blend_node(blend_points[cur_closest].node, blend_points[cur_closest].name, pi, FILTER_IGNORE, true, p_test_only);576}577578if (sync) {579pi = p_playback_info;580pi.weight = 0;581for (int i = 0; i < blend_points_used; i++) {582if (i != cur_closest) {583blend_node(blend_points[i].node, blend_points[i].name, pi, FILTER_IGNORE, true, p_test_only);584}585}586}587}588589set_parameter(closest, cur_closest);590return mind;591}592593String AnimationNodeBlendSpace2D::get_caption() const {594return "BlendSpace2D";595}596597void AnimationNodeBlendSpace2D::_validate_property(PropertyInfo &p_property) const {598if (auto_triangles && p_property.name == "triangles") {599p_property.usage = PROPERTY_USAGE_NONE;600}601if (p_property.name.begins_with("blend_point_")) {602String left = p_property.name.get_slicec('/', 0);603int idx = left.get_slicec('_', 2).to_int();604if (idx >= blend_points_used) {605p_property.usage = PROPERTY_USAGE_NONE;606}607}608}609610void AnimationNodeBlendSpace2D::set_auto_triangles(bool p_enable) {611if (auto_triangles == p_enable) {612return;613}614615auto_triangles = p_enable;616_queue_auto_triangles();617}618619bool AnimationNodeBlendSpace2D::get_auto_triangles() const {620return auto_triangles;621}622623Ref<AnimationNode> AnimationNodeBlendSpace2D::get_child_by_name(const StringName &p_name) const {624return get_blend_point_node(p_name.operator String().to_int());625}626627void AnimationNodeBlendSpace2D::set_blend_mode(BlendMode p_blend_mode) {628blend_mode = p_blend_mode;629}630631AnimationNodeBlendSpace2D::BlendMode AnimationNodeBlendSpace2D::get_blend_mode() const {632return blend_mode;633}634635void AnimationNodeBlendSpace2D::set_use_sync(bool p_sync) {636sync = p_sync;637}638639bool AnimationNodeBlendSpace2D::is_using_sync() const {640return sync;641}642643void AnimationNodeBlendSpace2D::_tree_changed() {644AnimationRootNode::_tree_changed();645}646647void AnimationNodeBlendSpace2D::_animation_node_renamed(const ObjectID &p_oid, const String &p_old_name, const String &p_new_name) {648AnimationRootNode::_animation_node_renamed(p_oid, p_old_name, p_new_name);649}650651void AnimationNodeBlendSpace2D::_animation_node_removed(const ObjectID &p_oid, const StringName &p_node) {652AnimationRootNode::_animation_node_removed(p_oid, p_node);653}654655void AnimationNodeBlendSpace2D::_bind_methods() {656ClassDB::bind_method(D_METHOD("add_blend_point", "node", "pos", "at_index"), &AnimationNodeBlendSpace2D::add_blend_point, DEFVAL(-1));657ClassDB::bind_method(D_METHOD("set_blend_point_position", "point", "pos"), &AnimationNodeBlendSpace2D::set_blend_point_position);658ClassDB::bind_method(D_METHOD("get_blend_point_position", "point"), &AnimationNodeBlendSpace2D::get_blend_point_position);659ClassDB::bind_method(D_METHOD("set_blend_point_node", "point", "node"), &AnimationNodeBlendSpace2D::set_blend_point_node);660ClassDB::bind_method(D_METHOD("get_blend_point_node", "point"), &AnimationNodeBlendSpace2D::get_blend_point_node);661ClassDB::bind_method(D_METHOD("remove_blend_point", "point"), &AnimationNodeBlendSpace2D::remove_blend_point);662ClassDB::bind_method(D_METHOD("get_blend_point_count"), &AnimationNodeBlendSpace2D::get_blend_point_count);663664ClassDB::bind_method(D_METHOD("add_triangle", "x", "y", "z", "at_index"), &AnimationNodeBlendSpace2D::add_triangle, DEFVAL(-1));665ClassDB::bind_method(D_METHOD("get_triangle_point", "triangle", "point"), &AnimationNodeBlendSpace2D::get_triangle_point);666ClassDB::bind_method(D_METHOD("remove_triangle", "triangle"), &AnimationNodeBlendSpace2D::remove_triangle);667ClassDB::bind_method(D_METHOD("get_triangle_count"), &AnimationNodeBlendSpace2D::get_triangle_count);668669ClassDB::bind_method(D_METHOD("set_min_space", "min_space"), &AnimationNodeBlendSpace2D::set_min_space);670ClassDB::bind_method(D_METHOD("get_min_space"), &AnimationNodeBlendSpace2D::get_min_space);671672ClassDB::bind_method(D_METHOD("set_max_space", "max_space"), &AnimationNodeBlendSpace2D::set_max_space);673ClassDB::bind_method(D_METHOD("get_max_space"), &AnimationNodeBlendSpace2D::get_max_space);674675ClassDB::bind_method(D_METHOD("set_snap", "snap"), &AnimationNodeBlendSpace2D::set_snap);676ClassDB::bind_method(D_METHOD("get_snap"), &AnimationNodeBlendSpace2D::get_snap);677678ClassDB::bind_method(D_METHOD("set_x_label", "text"), &AnimationNodeBlendSpace2D::set_x_label);679ClassDB::bind_method(D_METHOD("get_x_label"), &AnimationNodeBlendSpace2D::get_x_label);680681ClassDB::bind_method(D_METHOD("set_y_label", "text"), &AnimationNodeBlendSpace2D::set_y_label);682ClassDB::bind_method(D_METHOD("get_y_label"), &AnimationNodeBlendSpace2D::get_y_label);683684ClassDB::bind_method(D_METHOD("_add_blend_point", "index", "node"), &AnimationNodeBlendSpace2D::_add_blend_point);685686ClassDB::bind_method(D_METHOD("_set_triangles", "triangles"), &AnimationNodeBlendSpace2D::_set_triangles);687ClassDB::bind_method(D_METHOD("_get_triangles"), &AnimationNodeBlendSpace2D::_get_triangles);688689ClassDB::bind_method(D_METHOD("set_auto_triangles", "enable"), &AnimationNodeBlendSpace2D::set_auto_triangles);690ClassDB::bind_method(D_METHOD("get_auto_triangles"), &AnimationNodeBlendSpace2D::get_auto_triangles);691692ClassDB::bind_method(D_METHOD("set_blend_mode", "mode"), &AnimationNodeBlendSpace2D::set_blend_mode);693ClassDB::bind_method(D_METHOD("get_blend_mode"), &AnimationNodeBlendSpace2D::get_blend_mode);694695ClassDB::bind_method(D_METHOD("set_use_sync", "enable"), &AnimationNodeBlendSpace2D::set_use_sync);696ClassDB::bind_method(D_METHOD("is_using_sync"), &AnimationNodeBlendSpace2D::is_using_sync);697698ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_triangles", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_auto_triangles", "get_auto_triangles");699700for (int i = 0; i < MAX_BLEND_POINTS; i++) {701ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "blend_point_" + itos(i) + "/node", PROPERTY_HINT_RESOURCE_TYPE, "AnimationRootNode", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_add_blend_point", "get_blend_point_node", i);702ADD_PROPERTYI(PropertyInfo(Variant::VECTOR2, "blend_point_" + itos(i) + "/pos", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "set_blend_point_position", "get_blend_point_position", i);703}704705ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "triangles", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_triangles", "_get_triangles");706707ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "min_space", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_min_space", "get_min_space");708ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "max_space", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_max_space", "get_max_space");709ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "snap", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_snap", "get_snap");710ADD_PROPERTY(PropertyInfo(Variant::STRING, "x_label", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_x_label", "get_x_label");711ADD_PROPERTY(PropertyInfo(Variant::STRING, "y_label", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_y_label", "get_y_label");712ADD_PROPERTY(PropertyInfo(Variant::INT, "blend_mode", PROPERTY_HINT_ENUM, "Interpolated,Discrete,Carry", PROPERTY_USAGE_NO_EDITOR), "set_blend_mode", "get_blend_mode");713ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sync", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_use_sync", "is_using_sync");714715ADD_SIGNAL(MethodInfo("triangles_updated"));716BIND_ENUM_CONSTANT(BLEND_MODE_INTERPOLATED);717BIND_ENUM_CONSTANT(BLEND_MODE_DISCRETE);718BIND_ENUM_CONSTANT(BLEND_MODE_DISCRETE_CARRY);719}720721AnimationNodeBlendSpace2D::AnimationNodeBlendSpace2D() {722for (int i = 0; i < MAX_BLEND_POINTS; i++) {723blend_points[i].name = itos(i);724}725}726727AnimationNodeBlendSpace2D::~AnimationNodeBlendSpace2D() {728}729730731