Path: blob/master/scene/animation/animation_blend_space_2d.cpp
21467 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"34#include "scene/resources/material.h"3536void AnimationNodeBlendSpace2D::get_parameter_list(List<PropertyInfo> *r_list) const {37AnimationNode::get_parameter_list(r_list);38r_list->push_back(PropertyInfo(Variant::VECTOR2, blend_position));39r_list->push_back(PropertyInfo(Variant::INT, closest, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE));40}4142Variant AnimationNodeBlendSpace2D::get_parameter_default_value(const StringName &p_parameter) const {43Variant ret = AnimationNode::get_parameter_default_value(p_parameter);44if (ret != Variant()) {45return ret;46}4748if (p_parameter == closest) {49return (int)-1;50} else {51return Vector2();52}53}5455void AnimationNodeBlendSpace2D::get_child_nodes(List<ChildNode> *r_child_nodes) {56for (int i = 0; i < blend_points_used; i++) {57ChildNode cn;58cn.name = itos(i);59cn.node = blend_points[i].node;60r_child_nodes->push_back(cn);61}62}6364void AnimationNodeBlendSpace2D::add_blend_point(const Ref<AnimationRootNode> &p_node, const Vector2 &p_position, int p_at_index) {65ERR_FAIL_COND(blend_points_used >= MAX_BLEND_POINTS);66ERR_FAIL_COND(p_node.is_null());67ERR_FAIL_COND(p_at_index < -1 || p_at_index > blend_points_used);6869if (p_at_index == -1 || p_at_index == blend_points_used) {70p_at_index = blend_points_used;71} else {72for (int i = blend_points_used - 1; i > p_at_index; i--) {73blend_points[i] = blend_points[i - 1];74}75for (int i = 0; i < triangles.size(); i++) {76for (int j = 0; j < 3; j++) {77if (triangles[i].points[j] >= p_at_index) {78triangles.write[i].points[j]++;79}80}81}82}83blend_points[p_at_index].node = p_node;84blend_points[p_at_index].position = p_position;8586blend_points[p_at_index].node->connect("tree_changed", callable_mp(this, &AnimationNodeBlendSpace2D::_tree_changed), CONNECT_REFERENCE_COUNTED);87blend_points[p_at_index].node->connect("animation_node_renamed", callable_mp(this, &AnimationNodeBlendSpace2D::_animation_node_renamed), CONNECT_REFERENCE_COUNTED);88blend_points[p_at_index].node->connect("animation_node_removed", callable_mp(this, &AnimationNodeBlendSpace2D::_animation_node_removed), CONNECT_REFERENCE_COUNTED);89blend_points_used++;9091_queue_auto_triangles();9293emit_signal(SNAME("tree_changed"));94}9596void AnimationNodeBlendSpace2D::set_blend_point_position(int p_point, const Vector2 &p_position) {97ERR_FAIL_INDEX(p_point, blend_points_used);98blend_points[p_point].position = p_position;99_queue_auto_triangles();100}101102void AnimationNodeBlendSpace2D::set_blend_point_node(int p_point, const Ref<AnimationRootNode> &p_node) {103ERR_FAIL_INDEX(p_point, blend_points_used);104ERR_FAIL_COND(p_node.is_null());105106if (blend_points[p_point].node.is_valid()) {107blend_points[p_point].node->disconnect("tree_changed", callable_mp(this, &AnimationNodeBlendSpace2D::_tree_changed));108blend_points[p_point].node->disconnect("animation_node_renamed", callable_mp(this, &AnimationNodeBlendSpace2D::_animation_node_renamed));109blend_points[p_point].node->disconnect("animation_node_removed", callable_mp(this, &AnimationNodeBlendSpace2D::_animation_node_removed));110}111blend_points[p_point].node = p_node;112blend_points[p_point].node->connect("tree_changed", callable_mp(this, &AnimationNodeBlendSpace2D::_tree_changed), CONNECT_REFERENCE_COUNTED);113blend_points[p_point].node->connect("animation_node_renamed", callable_mp(this, &AnimationNodeBlendSpace2D::_animation_node_renamed), CONNECT_REFERENCE_COUNTED);114blend_points[p_point].node->connect("animation_node_removed", callable_mp(this, &AnimationNodeBlendSpace2D::_animation_node_removed), CONNECT_REFERENCE_COUNTED);115116emit_signal(SNAME("tree_changed"));117}118119Vector2 AnimationNodeBlendSpace2D::get_blend_point_position(int p_point) const {120ERR_FAIL_INDEX_V(p_point, MAX_BLEND_POINTS, Vector2());121return blend_points[p_point].position;122}123124Ref<AnimationRootNode> AnimationNodeBlendSpace2D::get_blend_point_node(int p_point) const {125ERR_FAIL_INDEX_V(p_point, MAX_BLEND_POINTS, Ref<AnimationRootNode>());126return blend_points[p_point].node;127}128129void AnimationNodeBlendSpace2D::remove_blend_point(int p_point) {130ERR_FAIL_INDEX(p_point, blend_points_used);131132ERR_FAIL_COND(blend_points[p_point].node.is_null());133blend_points[p_point].node->disconnect("tree_changed", callable_mp(this, &AnimationNodeBlendSpace2D::_tree_changed));134blend_points[p_point].node->disconnect("animation_node_renamed", callable_mp(this, &AnimationNodeBlendSpace2D::_animation_node_renamed));135blend_points[p_point].node->disconnect("animation_node_removed", callable_mp(this, &AnimationNodeBlendSpace2D::_animation_node_removed));136137for (int i = 0; i < triangles.size(); i++) {138bool erase = false;139for (int j = 0; j < 3; j++) {140if (triangles[i].points[j] == p_point) {141erase = true;142break;143} else if (triangles[i].points[j] > p_point) {144triangles.write[i].points[j]--;145}146}147if (erase) {148triangles.remove_at(i);149150i--;151}152}153154for (int i = p_point; i < blend_points_used - 1; i++) {155blend_points[i] = blend_points[i + 1];156}157blend_points_used--;158159emit_signal(SNAME("animation_node_removed"), get_instance_id(), itos(p_point));160emit_signal(SNAME("tree_changed"));161}162163int AnimationNodeBlendSpace2D::get_blend_point_count() const {164return blend_points_used;165}166167bool AnimationNodeBlendSpace2D::has_triangle(int p_x, int p_y, int p_z) const {168ERR_FAIL_INDEX_V(p_x, blend_points_used, false);169ERR_FAIL_INDEX_V(p_y, blend_points_used, false);170ERR_FAIL_INDEX_V(p_z, blend_points_used, false);171172BlendTriangle t;173t.points[0] = p_x;174t.points[1] = p_y;175t.points[2] = p_z;176177SortArray<int> sort;178sort.sort(t.points, 3);179180for (int i = 0; i < triangles.size(); i++) {181bool all_equal = true;182for (int j = 0; j < 3; j++) {183if (triangles[i].points[j] != t.points[j]) {184all_equal = false;185break;186}187}188if (all_equal) {189return true;190}191}192193return false;194}195196void AnimationNodeBlendSpace2D::add_triangle(int p_x, int p_y, int p_z, int p_at_index) {197ERR_FAIL_INDEX(p_x, blend_points_used);198ERR_FAIL_INDEX(p_y, blend_points_used);199ERR_FAIL_INDEX(p_z, blend_points_used);200201_update_triangles();202203BlendTriangle t;204t.points[0] = p_x;205t.points[1] = p_y;206t.points[2] = p_z;207208SortArray<int> sort;209sort.sort(t.points, 3);210211for (int i = 0; i < triangles.size(); i++) {212bool all_equal = true;213for (int j = 0; j < 3; j++) {214if (triangles[i].points[j] != t.points[j]) {215all_equal = false;216break;217}218}219ERR_FAIL_COND(all_equal);220}221222if (p_at_index == -1 || p_at_index == triangles.size()) {223triangles.push_back(t);224} else {225triangles.insert(p_at_index, t);226}227}228229int AnimationNodeBlendSpace2D::get_triangle_point(int p_triangle, int p_point) {230_update_triangles();231232ERR_FAIL_INDEX_V(p_point, 3, -1);233ERR_FAIL_INDEX_V(p_triangle, triangles.size(), -1);234return triangles[p_triangle].points[p_point];235}236237void AnimationNodeBlendSpace2D::remove_triangle(int p_triangle) {238ERR_FAIL_INDEX(p_triangle, triangles.size());239240triangles.remove_at(p_triangle);241}242243int AnimationNodeBlendSpace2D::get_triangle_count() const {244return triangles.size();245}246247void AnimationNodeBlendSpace2D::set_min_space(const Vector2 &p_min) {248min_space = p_min;249if (min_space.x >= max_space.x) {250min_space.x = max_space.x - 1;251}252if (min_space.y >= max_space.y) {253min_space.y = max_space.y - 1;254}255}256257Vector2 AnimationNodeBlendSpace2D::get_min_space() const {258return min_space;259}260261void AnimationNodeBlendSpace2D::set_max_space(const Vector2 &p_max) {262max_space = p_max;263if (max_space.x <= min_space.x) {264max_space.x = min_space.x + 1;265}266if (max_space.y <= min_space.y) {267max_space.y = min_space.y + 1;268}269}270271Vector2 AnimationNodeBlendSpace2D::get_max_space() const {272return max_space;273}274275void AnimationNodeBlendSpace2D::set_snap(const Vector2 &p_snap) {276snap = p_snap;277}278279Vector2 AnimationNodeBlendSpace2D::get_snap() const {280return snap;281}282283void AnimationNodeBlendSpace2D::set_x_label(const String &p_label) {284x_label = p_label;285}286287String AnimationNodeBlendSpace2D::get_x_label() const {288return x_label;289}290291void AnimationNodeBlendSpace2D::set_y_label(const String &p_label) {292y_label = p_label;293}294295String AnimationNodeBlendSpace2D::get_y_label() const {296return y_label;297}298299void AnimationNodeBlendSpace2D::_add_blend_point(int p_index, const Ref<AnimationRootNode> &p_node) {300if (p_index == blend_points_used) {301add_blend_point(p_node, Vector2());302} else {303set_blend_point_node(p_index, p_node);304}305}306307void AnimationNodeBlendSpace2D::_set_triangles(const Vector<int> &p_triangles) {308if (auto_triangles) {309return;310}311ERR_FAIL_COND(p_triangles.size() % 3 != 0);312for (int i = 0; i < p_triangles.size(); i += 3) {313add_triangle(p_triangles[i + 0], p_triangles[i + 1], p_triangles[i + 2]);314}315}316317Vector<int> AnimationNodeBlendSpace2D::_get_triangles() const {318Vector<int> t;319if (auto_triangles && triangles_dirty) {320return t;321}322323t.resize(triangles.size() * 3);324for (int i = 0; i < triangles.size(); i++) {325t.write[i * 3 + 0] = triangles[i].points[0];326t.write[i * 3 + 1] = triangles[i].points[1];327t.write[i * 3 + 2] = triangles[i].points[2];328}329return t;330}331332void AnimationNodeBlendSpace2D::_queue_auto_triangles() {333if (!auto_triangles || triangles_dirty) {334return;335}336337triangles_dirty = true;338callable_mp(this, &AnimationNodeBlendSpace2D::_update_triangles).call_deferred();339}340341void AnimationNodeBlendSpace2D::_update_triangles() {342if (!auto_triangles || !triangles_dirty) {343return;344}345346triangles_dirty = false;347triangles.clear();348if (blend_points_used < 3) {349emit_signal(SNAME("triangles_updated"));350return;351}352353Vector<Vector2> points;354points.resize(blend_points_used);355for (int i = 0; i < blend_points_used; i++) {356points.write[i] = blend_points[i].position;357}358359Vector<Delaunay2D::Triangle> tr = Delaunay2D::triangulate(points);360361for (int i = 0; i < tr.size(); i++) {362add_triangle(tr[i].points[0], tr[i].points[1], tr[i].points[2]);363}364emit_signal(SNAME("triangles_updated"));365}366367Vector2 AnimationNodeBlendSpace2D::get_closest_point(const Vector2 &p_point) {368_update_triangles();369370if (triangles.is_empty()) {371return Vector2();372}373374Vector2 best_point;375bool first = true;376377for (int i = 0; i < triangles.size(); i++) {378Vector2 points[3];379for (int j = 0; j < 3; j++) {380points[j] = get_blend_point_position(get_triangle_point(i, j));381}382383if (Geometry2D::is_point_in_triangle(p_point, points[0], points[1], points[2])) {384return p_point;385}386387for (int j = 0; j < 3; j++) {388const Vector2 segment_a = points[j];389const Vector2 segment_b = points[(j + 1) % 3];390Vector2 closest_point = Geometry2D::get_closest_point_to_segment(p_point, segment_a, segment_b);391if (first || closest_point.distance_to(p_point) < best_point.distance_to(p_point)) {392best_point = closest_point;393first = false;394}395}396}397398return best_point;399}400401void AnimationNodeBlendSpace2D::_blend_triangle(const Vector2 &p_pos, const Vector2 *p_points, float *r_weights) {402if (p_pos.is_equal_approx(p_points[0])) {403r_weights[0] = 1;404r_weights[1] = 0;405r_weights[2] = 0;406return;407}408if (p_pos.is_equal_approx(p_points[1])) {409r_weights[0] = 0;410r_weights[1] = 1;411r_weights[2] = 0;412return;413}414if (p_pos.is_equal_approx(p_points[2])) {415r_weights[0] = 0;416r_weights[1] = 0;417r_weights[2] = 1;418return;419}420421Vector2 v0 = p_points[1] - p_points[0];422Vector2 v1 = p_points[2] - p_points[0];423Vector2 v2 = p_pos - p_points[0];424425float d00 = v0.dot(v0);426float d01 = v0.dot(v1);427float d11 = v1.dot(v1);428float d20 = v2.dot(v0);429float d21 = v2.dot(v1);430float denom = (d00 * d11 - d01 * d01);431if (denom == 0) {432r_weights[0] = 1;433r_weights[1] = 0;434r_weights[2] = 0;435return;436}437float v = (d11 * d20 - d01 * d21) / denom;438float w = (d00 * d21 - d01 * d20) / denom;439float u = 1.0f - v - w;440441r_weights[0] = u;442r_weights[1] = v;443r_weights[2] = w;444}445446AnimationNode::NodeTimeInfo AnimationNodeBlendSpace2D::_process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only) {447_update_triangles();448449if (!blend_points_used) {450return NodeTimeInfo();451}452453Vector2 blend_pos = get_parameter(blend_position);454int cur_closest = get_parameter(closest);455NodeTimeInfo mind; //time of min distance point456457AnimationMixer::PlaybackInfo pi = p_playback_info;458459if (blend_mode == BLEND_MODE_INTERPOLATED) {460if (triangles.is_empty()) {461return NodeTimeInfo();462}463464Vector2 best_point;465bool first = true;466int blend_triangle = -1;467float blend_weights[3] = { 0, 0, 0 };468469for (int i = 0; i < triangles.size(); i++) {470Vector2 points[3];471for (int j = 0; j < 3; j++) {472points[j] = get_blend_point_position(get_triangle_point(i, j));473}474475if (Geometry2D::is_point_in_triangle(blend_pos, points[0], points[1], points[2])) {476blend_triangle = i;477_blend_triangle(blend_pos, points, blend_weights);478break;479}480481for (int j = 0; j < 3; j++) {482const Vector2 segment_a = points[j];483const Vector2 segment_b = points[(j + 1) % 3];484Vector2 closest2 = Geometry2D::get_closest_point_to_segment(blend_pos, segment_a, segment_b);485if (first || closest2.distance_to(blend_pos) < best_point.distance_to(blend_pos)) {486best_point = closest2;487blend_triangle = i;488first = false;489const real_t d = segment_a.distance_to(segment_b);490if (d == 0.0) {491blend_weights[j] = 1.0;492blend_weights[(j + 1) % 3] = 0.0;493blend_weights[(j + 2) % 3] = 0.0;494} else {495const real_t c = segment_a.distance_to(closest2) / d;496497blend_weights[j] = 1.0 - c;498blend_weights[(j + 1) % 3] = c;499blend_weights[(j + 2) % 3] = 0.0;500}501}502}503}504505ERR_FAIL_COND_V(blend_triangle == -1, NodeTimeInfo()); //should never reach here506507int triangle_points[3];508for (int j = 0; j < 3; j++) {509triangle_points[j] = get_triangle_point(blend_triangle, j);510}511512first = true;513514double max_weight = 0.0;515for (int i = 0; i < blend_points_used; i++) {516bool found = false;517for (int j = 0; j < 3; j++) {518if (i == triangle_points[j]) {519//blend with the given weight520pi.weight = blend_weights[j];521NodeTimeInfo t = blend_node(blend_points[i].node, blend_points[i].name, pi, FILTER_IGNORE, true, p_test_only);522if (first || pi.weight > max_weight) {523mind = t;524max_weight = pi.weight;525first = false;526}527found = true;528break;529}530}531532if (sync && !found) {533pi.weight = 0;534blend_node(blend_points[i].node, blend_points[i].name, pi, FILTER_IGNORE, true, p_test_only);535}536}537} else {538int new_closest = -1;539float new_closest_dist = 1e20;540541for (int i = 0; i < blend_points_used; i++) {542float d = blend_points[i].position.distance_squared_to(blend_pos);543if (d < new_closest_dist) {544new_closest = i;545new_closest_dist = d;546}547}548549if (new_closest != cur_closest && new_closest != -1) {550if (blend_mode == BLEND_MODE_DISCRETE_CARRY && cur_closest != -1) {551NodeTimeInfo from;552// For ping-pong loop.553Ref<AnimationNodeAnimation> na_c = static_cast<Ref<AnimationNodeAnimation>>(blend_points[cur_closest].node);554Ref<AnimationNodeAnimation> na_n = static_cast<Ref<AnimationNodeAnimation>>(blend_points[new_closest].node);555if (na_c.is_valid() && na_n.is_valid()) {556na_n->process_state = process_state;557na_c->process_state = process_state;558559na_n->set_backward(na_c->is_backward());560561na_n = nullptr;562na_c = nullptr;563}564// See how much animation remains.565pi.seeked = false;566pi.weight = 0;567from = blend_node(blend_points[cur_closest].node, blend_points[cur_closest].name, pi, FILTER_IGNORE, true, true);568pi.time = from.position;569}570pi.seeked = true;571pi.weight = 1.0;572mind = blend_node(blend_points[new_closest].node, blend_points[new_closest].name, pi, FILTER_IGNORE, true, p_test_only);573cur_closest = new_closest;574} else {575pi.weight = 1.0;576mind = blend_node(blend_points[cur_closest].node, blend_points[cur_closest].name, pi, FILTER_IGNORE, true, p_test_only);577}578579if (sync) {580pi = p_playback_info;581pi.weight = 0;582for (int i = 0; i < blend_points_used; i++) {583if (i != cur_closest) {584blend_node(blend_points[i].node, blend_points[i].name, pi, FILTER_IGNORE, true, p_test_only);585}586}587}588}589590set_parameter(closest, cur_closest);591return mind;592}593594String AnimationNodeBlendSpace2D::get_caption() const {595return "BlendSpace2D";596}597598void AnimationNodeBlendSpace2D::_validate_property(PropertyInfo &p_property) const {599if (auto_triangles && p_property.name == "triangles") {600p_property.usage = PROPERTY_USAGE_NONE;601}602if (p_property.name.begins_with("blend_point_")) {603String left = p_property.name.get_slicec('/', 0);604int idx = left.get_slicec('_', 2).to_int();605if (idx >= blend_points_used) {606p_property.usage = PROPERTY_USAGE_NONE;607}608}609}610611void AnimationNodeBlendSpace2D::set_auto_triangles(bool p_enable) {612if (auto_triangles == p_enable) {613return;614}615616auto_triangles = p_enable;617_queue_auto_triangles();618}619620bool AnimationNodeBlendSpace2D::get_auto_triangles() const {621return auto_triangles;622}623624Ref<AnimationNode> AnimationNodeBlendSpace2D::get_child_by_name(const StringName &p_name) const {625return get_blend_point_node(p_name.operator String().to_int());626}627628void AnimationNodeBlendSpace2D::set_blend_mode(BlendMode p_blend_mode) {629blend_mode = p_blend_mode;630}631632AnimationNodeBlendSpace2D::BlendMode AnimationNodeBlendSpace2D::get_blend_mode() const {633return blend_mode;634}635636void AnimationNodeBlendSpace2D::set_use_sync(bool p_sync) {637sync = p_sync;638}639640bool AnimationNodeBlendSpace2D::is_using_sync() const {641return sync;642}643644void AnimationNodeBlendSpace2D::_tree_changed() {645AnimationRootNode::_tree_changed();646}647648void AnimationNodeBlendSpace2D::_animation_node_renamed(const ObjectID &p_oid, const String &p_old_name, const String &p_new_name) {649AnimationRootNode::_animation_node_renamed(p_oid, p_old_name, p_new_name);650}651652void AnimationNodeBlendSpace2D::_animation_node_removed(const ObjectID &p_oid, const StringName &p_node) {653AnimationRootNode::_animation_node_removed(p_oid, p_node);654}655656void AnimationNodeBlendSpace2D::_bind_methods() {657ClassDB::bind_method(D_METHOD("add_blend_point", "node", "pos", "at_index"), &AnimationNodeBlendSpace2D::add_blend_point, DEFVAL(-1));658ClassDB::bind_method(D_METHOD("set_blend_point_position", "point", "pos"), &AnimationNodeBlendSpace2D::set_blend_point_position);659ClassDB::bind_method(D_METHOD("get_blend_point_position", "point"), &AnimationNodeBlendSpace2D::get_blend_point_position);660ClassDB::bind_method(D_METHOD("set_blend_point_node", "point", "node"), &AnimationNodeBlendSpace2D::set_blend_point_node);661ClassDB::bind_method(D_METHOD("get_blend_point_node", "point"), &AnimationNodeBlendSpace2D::get_blend_point_node);662ClassDB::bind_method(D_METHOD("remove_blend_point", "point"), &AnimationNodeBlendSpace2D::remove_blend_point);663ClassDB::bind_method(D_METHOD("get_blend_point_count"), &AnimationNodeBlendSpace2D::get_blend_point_count);664665ClassDB::bind_method(D_METHOD("add_triangle", "x", "y", "z", "at_index"), &AnimationNodeBlendSpace2D::add_triangle, DEFVAL(-1));666ClassDB::bind_method(D_METHOD("get_triangle_point", "triangle", "point"), &AnimationNodeBlendSpace2D::get_triangle_point);667ClassDB::bind_method(D_METHOD("remove_triangle", "triangle"), &AnimationNodeBlendSpace2D::remove_triangle);668ClassDB::bind_method(D_METHOD("get_triangle_count"), &AnimationNodeBlendSpace2D::get_triangle_count);669670ClassDB::bind_method(D_METHOD("set_min_space", "min_space"), &AnimationNodeBlendSpace2D::set_min_space);671ClassDB::bind_method(D_METHOD("get_min_space"), &AnimationNodeBlendSpace2D::get_min_space);672673ClassDB::bind_method(D_METHOD("set_max_space", "max_space"), &AnimationNodeBlendSpace2D::set_max_space);674ClassDB::bind_method(D_METHOD("get_max_space"), &AnimationNodeBlendSpace2D::get_max_space);675676ClassDB::bind_method(D_METHOD("set_snap", "snap"), &AnimationNodeBlendSpace2D::set_snap);677ClassDB::bind_method(D_METHOD("get_snap"), &AnimationNodeBlendSpace2D::get_snap);678679ClassDB::bind_method(D_METHOD("set_x_label", "text"), &AnimationNodeBlendSpace2D::set_x_label);680ClassDB::bind_method(D_METHOD("get_x_label"), &AnimationNodeBlendSpace2D::get_x_label);681682ClassDB::bind_method(D_METHOD("set_y_label", "text"), &AnimationNodeBlendSpace2D::set_y_label);683ClassDB::bind_method(D_METHOD("get_y_label"), &AnimationNodeBlendSpace2D::get_y_label);684685ClassDB::bind_method(D_METHOD("_add_blend_point", "index", "node"), &AnimationNodeBlendSpace2D::_add_blend_point);686687ClassDB::bind_method(D_METHOD("_set_triangles", "triangles"), &AnimationNodeBlendSpace2D::_set_triangles);688ClassDB::bind_method(D_METHOD("_get_triangles"), &AnimationNodeBlendSpace2D::_get_triangles);689690ClassDB::bind_method(D_METHOD("set_auto_triangles", "enable"), &AnimationNodeBlendSpace2D::set_auto_triangles);691ClassDB::bind_method(D_METHOD("get_auto_triangles"), &AnimationNodeBlendSpace2D::get_auto_triangles);692693ClassDB::bind_method(D_METHOD("set_blend_mode", "mode"), &AnimationNodeBlendSpace2D::set_blend_mode);694ClassDB::bind_method(D_METHOD("get_blend_mode"), &AnimationNodeBlendSpace2D::get_blend_mode);695696ClassDB::bind_method(D_METHOD("set_use_sync", "enable"), &AnimationNodeBlendSpace2D::set_use_sync);697ClassDB::bind_method(D_METHOD("is_using_sync"), &AnimationNodeBlendSpace2D::is_using_sync);698699ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_triangles", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_auto_triangles", "get_auto_triangles");700701for (int i = 0; i < MAX_BLEND_POINTS; i++) {702ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "blend_point_" + itos(i) + "/node", PROPERTY_HINT_RESOURCE_TYPE, AnimationRootNode::get_class_static(), PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_add_blend_point", "get_blend_point_node", i);703ADD_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);704}705706ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "triangles", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_triangles", "_get_triangles");707708ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "min_space", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_min_space", "get_min_space");709ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "max_space", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_max_space", "get_max_space");710ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "snap", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_snap", "get_snap");711ADD_PROPERTY(PropertyInfo(Variant::STRING, "x_label", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_x_label", "get_x_label");712ADD_PROPERTY(PropertyInfo(Variant::STRING, "y_label", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_y_label", "get_y_label");713ADD_PROPERTY(PropertyInfo(Variant::INT, "blend_mode", PROPERTY_HINT_ENUM, "Interpolated,Discrete,Carry", PROPERTY_USAGE_NO_EDITOR), "set_blend_mode", "get_blend_mode");714ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sync", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_use_sync", "is_using_sync");715716ADD_SIGNAL(MethodInfo("triangles_updated"));717BIND_ENUM_CONSTANT(BLEND_MODE_INTERPOLATED);718BIND_ENUM_CONSTANT(BLEND_MODE_DISCRETE);719BIND_ENUM_CONSTANT(BLEND_MODE_DISCRETE_CARRY);720}721722AnimationNodeBlendSpace2D::AnimationNodeBlendSpace2D() {723for (int i = 0; i < MAX_BLEND_POINTS; i++) {724blend_points[i].name = itos(i);725}726}727728AnimationNodeBlendSpace2D::~AnimationNodeBlendSpace2D() {729}730731732