2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* animation_tree_player.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2021-01-01 19:13:46 +00:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "animation_tree_player.h"
|
|
|
|
#include "animation_player.h"
|
|
|
|
|
2015-09-02 12:11:34 +00:00
|
|
|
#include "scene/scene_string_names.h"
|
|
|
|
|
|
|
|
void AnimationTreePlayer::set_animation_process_mode(AnimationProcessMode p_mode) {
|
|
|
|
|
|
|
|
if (animation_process_mode == p_mode)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool pr = processing;
|
|
|
|
if (pr)
|
|
|
|
_set_process(false);
|
|
|
|
animation_process_mode = p_mode;
|
|
|
|
if (pr)
|
|
|
|
_set_process(true);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AnimationTreePlayer::AnimationProcessMode AnimationTreePlayer::get_animation_process_mode() const {
|
2015-09-02 12:11:34 +00:00
|
|
|
|
|
|
|
return animation_process_mode;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::_set_process(bool p_process, bool p_force) {
|
2015-09-02 12:11:34 +00:00
|
|
|
if (processing == p_process && !p_force)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (animation_process_mode) {
|
|
|
|
|
2017-09-30 14:19:07 +00:00
|
|
|
case ANIMATION_PROCESS_PHYSICS: set_physics_process_internal(p_process && active); break;
|
2017-03-05 15:44:50 +00:00
|
|
|
case ANIMATION_PROCESS_IDLE: set_process_internal(p_process && active); break;
|
2015-09-02 12:11:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
processing = p_process;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool AnimationTreePlayer::_set(const StringName &p_name, const Variant &p_value) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (String(p_name) == "base_path") {
|
2014-02-10 01:10:30 +00:00
|
|
|
set_base_path(p_value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (String(p_name) == "master_player") {
|
2014-02-10 01:10:30 +00:00
|
|
|
set_master_player(p_value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (String(p_name) == SceneStringNames::get_singleton()->playback_active) {
|
2015-09-02 12:11:34 +00:00
|
|
|
set_active(p_value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (String(p_name) != "data")
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Dictionary data = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Array nodes = data.get_valid("nodes");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < nodes.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Dictionary node = nodes[i];
|
|
|
|
|
|
|
|
StringName id = node.get_valid("id");
|
2017-09-10 13:37:49 +00:00
|
|
|
Point2 pos = node.get_valid("position");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
NodeType nt = NODE_MAX;
|
2014-02-10 01:10:30 +00:00
|
|
|
String type = node.get_valid("type");
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (type == "output")
|
|
|
|
nt = NODE_OUTPUT;
|
|
|
|
else if (type == "animation")
|
|
|
|
nt = NODE_ANIMATION;
|
|
|
|
else if (type == "oneshot")
|
|
|
|
nt = NODE_ONESHOT;
|
|
|
|
else if (type == "mix")
|
|
|
|
nt = NODE_MIX;
|
|
|
|
else if (type == "blend2")
|
|
|
|
nt = NODE_BLEND2;
|
|
|
|
else if (type == "blend3")
|
|
|
|
nt = NODE_BLEND3;
|
|
|
|
else if (type == "blend4")
|
|
|
|
nt = NODE_BLEND4;
|
|
|
|
else if (type == "timescale")
|
|
|
|
nt = NODE_TIMESCALE;
|
|
|
|
else if (type == "timeseek")
|
|
|
|
nt = NODE_TIMESEEK;
|
|
|
|
else if (type == "transition")
|
|
|
|
nt = NODE_TRANSITION;
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(nt == NODE_MAX, false);
|
|
|
|
|
|
|
|
if (nt != NODE_OUTPUT)
|
|
|
|
add_node(nt, id);
|
2017-09-10 13:37:49 +00:00
|
|
|
node_set_position(id, pos);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
|
|
|
switch (nt) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case NODE_OUTPUT: {
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case NODE_ANIMATION: {
|
|
|
|
|
|
|
|
if (node.has("from"))
|
2017-03-05 15:44:50 +00:00
|
|
|
animation_node_set_master_animation(id, node.get_valid("from"));
|
2014-02-10 01:10:30 +00:00
|
|
|
else
|
2017-03-05 15:44:50 +00:00
|
|
|
animation_node_set_animation(id, node.get_valid("animation"));
|
|
|
|
Array filters = node.get_valid("filter");
|
2019-02-12 20:10:08 +00:00
|
|
|
for (int j = 0; j < filters.size(); j++) {
|
2016-04-25 09:41:23 +00:00
|
|
|
|
2019-02-12 20:10:08 +00:00
|
|
|
animation_node_set_filter_path(id, filters[j], true);
|
2016-04-25 09:41:23 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case NODE_ONESHOT: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
oneshot_node_set_fadein_time(id, node.get_valid("fade_in"));
|
|
|
|
oneshot_node_set_fadeout_time(id, node.get_valid("fade_out"));
|
|
|
|
oneshot_node_set_mix_mode(id, node.get_valid("mix"));
|
|
|
|
oneshot_node_set_autorestart(id, node.get_valid("autorestart"));
|
|
|
|
oneshot_node_set_autorestart_delay(id, node.get_valid("autorestart_delay"));
|
|
|
|
oneshot_node_set_autorestart_random_delay(id, node.get_valid("autorestart_random_delay"));
|
|
|
|
Array filters = node.get_valid("filter");
|
2019-02-12 20:10:08 +00:00
|
|
|
for (int j = 0; j < filters.size(); j++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-02-12 20:10:08 +00:00
|
|
|
oneshot_node_set_filter_path(id, filters[j], true);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case NODE_MIX: {
|
2017-03-05 15:44:50 +00:00
|
|
|
mix_node_set_amount(id, node.get_valid("mix"));
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case NODE_BLEND2: {
|
2017-03-05 15:44:50 +00:00
|
|
|
blend2_node_set_amount(id, node.get_valid("blend"));
|
|
|
|
Array filters = node.get_valid("filter");
|
2019-02-12 20:10:08 +00:00
|
|
|
for (int j = 0; j < filters.size(); j++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-02-12 20:10:08 +00:00
|
|
|
blend2_node_set_filter_path(id, filters[j], true);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case NODE_BLEND3: {
|
2017-03-05 15:44:50 +00:00
|
|
|
blend3_node_set_amount(id, node.get_valid("blend"));
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case NODE_BLEND4: {
|
2017-03-05 15:44:50 +00:00
|
|
|
blend4_node_set_amount(id, node.get_valid("blend"));
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case NODE_TIMESCALE: {
|
2017-03-05 15:44:50 +00:00
|
|
|
timescale_node_set_scale(id, node.get_valid("scale"));
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case NODE_TIMESEEK: {
|
|
|
|
} break;
|
|
|
|
case NODE_TRANSITION: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
transition_node_set_xfade_time(id, node.get_valid("xfade"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Array transitions = node.get_valid("transitions");
|
2017-03-05 15:44:50 +00:00
|
|
|
transition_node_set_input_count(id, transitions.size());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int x = 0; x < transitions.size(); x++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Dictionary d = transitions[x];
|
2014-02-10 01:10:30 +00:00
|
|
|
bool aa = d.get_valid("auto_advance");
|
2017-03-05 15:44:50 +00:00
|
|
|
transition_node_set_input_auto_advance(id, x, aa);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2019-04-09 15:08:36 +00:00
|
|
|
default: {
|
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Array connections = data.get_valid("connections");
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(connections.size() % 3, false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int cc = connections.size() / 3;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < cc; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
StringName src = connections[i * 3 + 0];
|
|
|
|
StringName dst = connections[i * 3 + 1];
|
|
|
|
int dst_in = connections[i * 3 + 2];
|
|
|
|
connect_nodes(src, dst, dst_in);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set_active(data.get_valid("active"));
|
|
|
|
set_master_player(data.get_valid("master"));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool AnimationTreePlayer::_get(const StringName &p_name, Variant &r_ret) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (String(p_name) == "base_path") {
|
|
|
|
r_ret = base_path;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (String(p_name) == "master_player") {
|
|
|
|
r_ret = master;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-02 12:11:34 +00:00
|
|
|
if (String(p_name) == "playback/active") {
|
2017-03-05 15:44:50 +00:00
|
|
|
r_ret = is_active();
|
2015-09-02 12:11:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (String(p_name) != "data")
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
Dictionary data;
|
|
|
|
|
|
|
|
Array nodes;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<StringName, NodeBase *>::Element *E = node_map.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
NodeBase *n = node_map[E->key()];
|
|
|
|
|
|
|
|
Dictionary node;
|
2017-03-05 15:44:50 +00:00
|
|
|
node["id"] = E->key();
|
2017-09-10 13:37:49 +00:00
|
|
|
node["position"] = n->pos;
|
2017-03-05 15:44:50 +00:00
|
|
|
|
|
|
|
switch (n->type) {
|
|
|
|
case NODE_OUTPUT: node["type"] = "output"; break;
|
|
|
|
case NODE_ANIMATION: node["type"] = "animation"; break;
|
|
|
|
case NODE_ONESHOT: node["type"] = "oneshot"; break;
|
|
|
|
case NODE_MIX: node["type"] = "mix"; break;
|
|
|
|
case NODE_BLEND2: node["type"] = "blend2"; break;
|
|
|
|
case NODE_BLEND3: node["type"] = "blend3"; break;
|
|
|
|
case NODE_BLEND4: node["type"] = "blend4"; break;
|
|
|
|
case NODE_TIMESCALE: node["type"] = "timescale"; break;
|
|
|
|
case NODE_TIMESEEK: node["type"] = "timeseek"; break;
|
|
|
|
case NODE_TRANSITION: node["type"] = "transition"; break;
|
|
|
|
default: node["type"] = ""; break;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (n->type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case NODE_OUTPUT: {
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case NODE_ANIMATION: {
|
2017-03-05 15:44:50 +00:00
|
|
|
AnimationNode *an = static_cast<AnimationNode *>(n);
|
|
|
|
if (master != NodePath() && an->from != "") {
|
|
|
|
node["from"] = an->from;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
node["animation"] = an->animation;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2016-04-25 09:41:23 +00:00
|
|
|
Array k;
|
|
|
|
List<NodePath> keys;
|
|
|
|
an->filter.get_key_list(&keys);
|
|
|
|
k.resize(keys.size());
|
2017-03-05 15:44:50 +00:00
|
|
|
int i = 0;
|
2019-02-12 20:10:08 +00:00
|
|
|
for (List<NodePath>::Element *F = keys.front(); F; F = F->next()) {
|
|
|
|
k[i++] = F->get();
|
2016-04-25 09:41:23 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
node["filter"] = k;
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case NODE_ONESHOT: {
|
2017-03-05 15:44:50 +00:00
|
|
|
OneShotNode *osn = static_cast<OneShotNode *>(n);
|
|
|
|
node["fade_in"] = osn->fade_in;
|
|
|
|
node["fade_out"] = osn->fade_out;
|
|
|
|
node["mix"] = osn->mix;
|
|
|
|
node["autorestart"] = osn->autorestart;
|
|
|
|
node["autorestart_delay"] = osn->autorestart_delay;
|
|
|
|
node["autorestart_random_delay"] = osn->autorestart_random_delay;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Array k;
|
|
|
|
List<NodePath> keys;
|
|
|
|
osn->filter.get_key_list(&keys);
|
|
|
|
k.resize(keys.size());
|
2017-03-05 15:44:50 +00:00
|
|
|
int i = 0;
|
2019-02-12 20:10:08 +00:00
|
|
|
for (List<NodePath>::Element *F = keys.front(); F; F = F->next()) {
|
|
|
|
k[i++] = F->get();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
node["filter"] = k;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case NODE_MIX: {
|
2017-03-05 15:44:50 +00:00
|
|
|
MixNode *mn = static_cast<MixNode *>(n);
|
|
|
|
node["mix"] = mn->amount;
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case NODE_BLEND2: {
|
2017-03-05 15:44:50 +00:00
|
|
|
Blend2Node *bn = static_cast<Blend2Node *>(n);
|
|
|
|
node["blend"] = bn->value;
|
2014-02-10 01:10:30 +00:00
|
|
|
Array k;
|
|
|
|
List<NodePath> keys;
|
|
|
|
bn->filter.get_key_list(&keys);
|
|
|
|
k.resize(keys.size());
|
2017-03-05 15:44:50 +00:00
|
|
|
int i = 0;
|
2019-02-12 20:10:08 +00:00
|
|
|
for (List<NodePath>::Element *F = keys.front(); F; F = F->next()) {
|
|
|
|
k[i++] = F->get();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
node["filter"] = k;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case NODE_BLEND3: {
|
2017-03-05 15:44:50 +00:00
|
|
|
Blend3Node *bn = static_cast<Blend3Node *>(n);
|
|
|
|
node["blend"] = bn->value;
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case NODE_BLEND4: {
|
2017-03-05 15:44:50 +00:00
|
|
|
Blend4Node *bn = static_cast<Blend4Node *>(n);
|
|
|
|
node["blend"] = bn->value;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case NODE_TIMESCALE: {
|
2017-03-05 15:44:50 +00:00
|
|
|
TimeScaleNode *tsn = static_cast<TimeScaleNode *>(n);
|
|
|
|
node["scale"] = tsn->scale;
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case NODE_TIMESEEK: {
|
|
|
|
} break;
|
|
|
|
case NODE_TRANSITION: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
TransitionNode *tn = static_cast<TransitionNode *>(n);
|
|
|
|
node["xfade"] = tn->xfade;
|
2014-02-10 01:10:30 +00:00
|
|
|
Array transitions;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < tn->input_data.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Dictionary d;
|
2017-03-05 15:44:50 +00:00
|
|
|
d["auto_advance"] = tn->input_data[i].auto_advance;
|
2014-02-10 01:10:30 +00:00
|
|
|
transitions.push_back(d);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
node["transitions"] = transitions;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
2019-04-09 15:08:36 +00:00
|
|
|
default: {
|
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nodes.push_back(node);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
data["nodes"] = nodes;
|
2014-02-10 01:10:30 +00:00
|
|
|
//connectiosn
|
|
|
|
|
|
|
|
List<Connection> connections;
|
|
|
|
get_connection_list(&connections);
|
|
|
|
Array connections_arr;
|
2017-03-05 15:44:50 +00:00
|
|
|
connections_arr.resize(connections.size() * 3);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = 0;
|
|
|
|
for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
connections_arr.set(idx + 0, E->get().src_node);
|
|
|
|
connections_arr.set(idx + 1, E->get().dst_node);
|
|
|
|
connections_arr.set(idx + 2, E->get().dst_input);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
idx += 3;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
data["connections"] = connections_arr;
|
|
|
|
data["active"] = active;
|
|
|
|
data["master"] = master;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
r_ret = data;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::_get_property_list(List<PropertyInfo> *p_list) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_NETWORK));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2015-09-02 12:11:34 +00:00
|
|
|
void AnimationTreePlayer::advance(float p_time) {
|
|
|
|
|
|
|
|
_process_animation(p_time);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
void AnimationTreePlayer::_notification(int p_what) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (p_what) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-09-02 12:11:34 +00:00
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
|
|
|
|
2019-08-08 20:11:48 +00:00
|
|
|
WARN_DEPRECATED_MSG("AnimationTreePlayer has been deprecated. Use AnimationTree instead.");
|
2018-12-07 23:53:07 +00:00
|
|
|
|
2015-09-02 12:11:34 +00:00
|
|
|
if (!processing) {
|
|
|
|
//make sure that a previous process state was not saved
|
|
|
|
//only process if "processing" is set
|
2017-09-30 14:19:07 +00:00
|
|
|
set_physics_process_internal(false);
|
2017-01-10 21:02:19 +00:00
|
|
|
set_process_internal(false);
|
2015-09-02 12:11:34 +00:00
|
|
|
}
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case NOTIFICATION_READY: {
|
2018-12-07 23:53:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
dirty_caches = true;
|
|
|
|
if (master != NodePath()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
_update_sources();
|
|
|
|
}
|
|
|
|
} break;
|
2017-01-10 21:02:19 +00:00
|
|
|
case NOTIFICATION_INTERNAL_PROCESS: {
|
2018-12-07 23:53:07 +00:00
|
|
|
|
2017-09-30 14:19:07 +00:00
|
|
|
if (animation_process_mode == ANIMATION_PROCESS_PHYSICS)
|
2015-09-02 12:11:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (processing)
|
2017-03-05 15:44:50 +00:00
|
|
|
_process_animation(get_process_delta_time());
|
2015-09-02 12:11:34 +00:00
|
|
|
} break;
|
2017-09-30 14:19:07 +00:00
|
|
|
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (animation_process_mode == ANIMATION_PROCESS_IDLE)
|
2015-09-02 12:11:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (processing)
|
2017-09-30 14:19:07 +00:00
|
|
|
_process_animation(get_physics_process_delta_time());
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::_compute_weights(float *p_fallback_weight, HashMap<NodePath, float> *p_weights, float p_coeff, const HashMap<NodePath, bool> *p_filter, float p_filtered_coeff) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-06-18 23:28:10 +00:00
|
|
|
if (p_filter != NULL) {
|
|
|
|
|
|
|
|
List<NodePath> key_list;
|
|
|
|
p_filter->get_key_list(&key_list);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<NodePath>::Element *E = key_list.front(); E; E = E->next()) {
|
2016-06-18 23:28:10 +00:00
|
|
|
|
|
|
|
if ((*p_filter)[E->get()]) {
|
|
|
|
|
|
|
|
if (p_weights->has(E->get())) {
|
|
|
|
(*p_weights)[E->get()] *= p_filtered_coeff;
|
|
|
|
} else {
|
|
|
|
p_weights->set(E->get(), *p_fallback_weight * p_filtered_coeff);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (p_weights->has(E->get())) {
|
2017-03-05 15:44:50 +00:00
|
|
|
(*p_weights)[E->get()] *= p_coeff;
|
2016-06-18 23:28:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
List<NodePath> key_list;
|
|
|
|
p_weights->get_key_list(&key_list);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
|
|
|
for (List<NodePath>::Element *E = key_list.front(); E; E = E->next()) {
|
2016-06-18 23:28:10 +00:00
|
|
|
if (p_filter == NULL || !p_filter->has(E->get())) {
|
|
|
|
(*p_weights)[E->get()] *= p_coeff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*p_fallback_weight *= p_coeff;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float AnimationTreePlayer::_process_node(const StringName &p_node, AnimationNode **r_prev_anim, float p_time, bool p_seek, float p_fallback_weight, HashMap<NodePath, float> *p_weights) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!node_map.has(p_node), 0);
|
2017-03-05 15:44:50 +00:00
|
|
|
NodeBase *nb = node_map[p_node];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//transform to seconds...
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (nb->type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case NODE_OUTPUT: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
NodeOut *on = static_cast<NodeOut *>(nb);
|
2016-06-18 23:28:10 +00:00
|
|
|
HashMap<NodePath, float> weights;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return _process_node(on->inputs[0].node, r_prev_anim, p_time, p_seek, p_fallback_weight, &weights);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case NODE_ANIMATION: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AnimationNode *an = static_cast<AnimationNode *>(nb);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
float rem = 0;
|
|
|
|
if (!an->animation.is_null()) {
|
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
//float pos = an->time;
|
|
|
|
//float delta = p_time;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
//const Animation *a = an->animation.operator->();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (p_seek) {
|
2017-03-05 15:44:50 +00:00
|
|
|
an->time = p_time;
|
|
|
|
an->step = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
an->time = MAX(0, an->time + p_time);
|
|
|
|
an->step = p_time;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float anim_size = an->animation->get_length();
|
|
|
|
|
|
|
|
if (an->animation->has_loop()) {
|
|
|
|
|
|
|
|
if (anim_size)
|
2017-03-05 15:44:50 +00:00
|
|
|
an->time = Math::fposmod(an->time, anim_size);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} else if (an->time > anim_size) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
an->time = anim_size;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
an->skip = true;
|
2016-06-18 23:28:10 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<AnimationNode::TrackRef>::Element *E = an->tref.front(); E; E = E->next()) {
|
2016-04-25 09:41:23 +00:00
|
|
|
NodePath track_path = an->animation->track_get_path(E->get().local_track);
|
2016-06-18 23:28:10 +00:00
|
|
|
if (an->filter.has(track_path) && an->filter[track_path]) {
|
2016-04-25 09:41:23 +00:00
|
|
|
E->get().weight = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2016-06-18 23:28:10 +00:00
|
|
|
if (p_weights->has(track_path)) {
|
|
|
|
float weight = (*p_weights)[track_path];
|
|
|
|
E->get().weight = weight;
|
|
|
|
} else {
|
|
|
|
E->get().weight = p_fallback_weight;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
if (E->get().weight > CMP_EPSILON)
|
|
|
|
an->skip = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rem = anim_size - an->time;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(*r_prev_anim))
|
2017-03-05 15:44:50 +00:00
|
|
|
active_list = an;
|
2016-03-08 23:00:52 +00:00
|
|
|
else
|
2017-03-05 15:44:50 +00:00
|
|
|
(*r_prev_anim)->next = an;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
an->next = NULL;
|
|
|
|
*r_prev_anim = an;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return rem;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case NODE_ONESHOT: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
OneShotNode *osn = static_cast<OneShotNode *>(nb);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!osn->active) {
|
|
|
|
//make it as if this node doesn't exist, pass input 0 by.
|
2017-03-05 15:44:50 +00:00
|
|
|
return _process_node(osn->inputs[0].node, r_prev_anim, p_time, p_seek, p_fallback_weight, p_weights);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-12-31 05:14:27 +00:00
|
|
|
bool os_seek = p_seek;
|
2016-03-27 11:19:05 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (p_seek)
|
2017-03-05 15:44:50 +00:00
|
|
|
osn->time = p_time;
|
2016-03-27 11:19:05 +00:00
|
|
|
if (osn->start) {
|
2017-03-05 15:44:50 +00:00
|
|
|
osn->time = 0;
|
2016-03-27 11:19:05 +00:00
|
|
|
os_seek = true;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
float blend;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (osn->time < osn->fade_in) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (osn->fade_in > 0)
|
|
|
|
blend = osn->time / osn->fade_in;
|
2014-02-10 01:10:30 +00:00
|
|
|
else
|
2017-03-05 15:44:50 +00:00
|
|
|
blend = 0; //wtf
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (!osn->start && osn->remaining < osn->fade_out) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (osn->fade_out)
|
2017-03-05 15:44:50 +00:00
|
|
|
blend = (osn->remaining / osn->fade_out);
|
2014-02-10 01:10:30 +00:00
|
|
|
else
|
2017-03-05 15:44:50 +00:00
|
|
|
blend = 1.0;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else
|
2017-03-05 15:44:50 +00:00
|
|
|
blend = 1.0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
float main_rem;
|
|
|
|
float os_rem;
|
|
|
|
|
2016-06-18 23:28:10 +00:00
|
|
|
HashMap<NodePath, float> os_weights(*p_weights);
|
|
|
|
float os_fallback_weight = p_fallback_weight;
|
2017-03-05 15:44:50 +00:00
|
|
|
_compute_weights(&p_fallback_weight, p_weights, osn->mix ? 1.0 : 1.0 - blend, &osn->filter, 1.0);
|
2016-06-18 23:28:10 +00:00
|
|
|
_compute_weights(&os_fallback_weight, &os_weights, blend, &osn->filter, 0.0);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
main_rem = _process_node(osn->inputs[0].node, r_prev_anim, p_time, p_seek, p_fallback_weight, p_weights);
|
|
|
|
os_rem = _process_node(osn->inputs[1].node, r_prev_anim, p_time, os_seek, os_fallback_weight, &os_weights);
|
2016-04-25 09:41:23 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (osn->start) {
|
2017-03-05 15:44:50 +00:00
|
|
|
osn->remaining = os_rem;
|
|
|
|
osn->start = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!p_seek) {
|
2017-03-05 15:44:50 +00:00
|
|
|
osn->time += p_time;
|
|
|
|
osn->remaining = os_rem;
|
|
|
|
if (osn->remaining <= 0)
|
|
|
|
osn->active = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return MAX(main_rem, osn->remaining);
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case NODE_MIX: {
|
2017-03-05 15:44:50 +00:00
|
|
|
MixNode *mn = static_cast<MixNode *>(nb);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-06-18 23:28:10 +00:00
|
|
|
HashMap<NodePath, float> mn_weights(*p_weights);
|
|
|
|
float mn_fallback_weight = p_fallback_weight;
|
|
|
|
_compute_weights(&mn_fallback_weight, &mn_weights, mn->amount);
|
2017-03-05 15:44:50 +00:00
|
|
|
float rem = _process_node(mn->inputs[0].node, r_prev_anim, p_time, p_seek, p_fallback_weight, p_weights);
|
|
|
|
_process_node(mn->inputs[1].node, r_prev_anim, p_time, p_seek, mn_fallback_weight, &mn_weights);
|
2014-02-10 01:10:30 +00:00
|
|
|
return rem;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case NODE_BLEND2: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Blend2Node *bn = static_cast<Blend2Node *>(nb);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-06-18 23:28:10 +00:00
|
|
|
HashMap<NodePath, float> bn_weights(*p_weights);
|
|
|
|
float bn_fallback_weight = p_fallback_weight;
|
2017-03-05 15:44:50 +00:00
|
|
|
_compute_weights(&p_fallback_weight, p_weights, 1.0 - bn->value, &bn->filter, 1.0);
|
|
|
|
_compute_weights(&bn_fallback_weight, &bn_weights, bn->value, &bn->filter, 0.0);
|
|
|
|
float rem = _process_node(bn->inputs[0].node, r_prev_anim, p_time, p_seek, p_fallback_weight, p_weights);
|
|
|
|
_process_node(bn->inputs[1].node, r_prev_anim, p_time, p_seek, bn_fallback_weight, &bn_weights);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return rem;
|
|
|
|
} break;
|
|
|
|
case NODE_BLEND3: {
|
2017-03-05 15:44:50 +00:00
|
|
|
Blend3Node *bn = static_cast<Blend3Node *>(nb);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
float rem;
|
2016-02-28 11:55:53 +00:00
|
|
|
float blend, lower_blend, upper_blend;
|
|
|
|
if (bn->value < 0) {
|
|
|
|
lower_blend = -bn->value;
|
|
|
|
blend = 1.0 - lower_blend;
|
|
|
|
upper_blend = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2016-02-28 11:55:53 +00:00
|
|
|
lower_blend = 0;
|
|
|
|
blend = 1.0 - bn->value;
|
|
|
|
upper_blend = bn->value;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-06-18 23:28:10 +00:00
|
|
|
HashMap<NodePath, float> upper_weights(*p_weights);
|
|
|
|
float upper_fallback_weight = p_fallback_weight;
|
|
|
|
HashMap<NodePath, float> lower_weights(*p_weights);
|
|
|
|
float lower_fallback_weight = p_fallback_weight;
|
2017-03-05 15:44:50 +00:00
|
|
|
_compute_weights(&upper_fallback_weight, &upper_weights, upper_blend);
|
|
|
|
_compute_weights(&p_fallback_weight, p_weights, blend);
|
|
|
|
_compute_weights(&lower_fallback_weight, &lower_weights, lower_blend);
|
2016-06-18 23:28:10 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
rem = _process_node(bn->inputs[1].node, r_prev_anim, p_time, p_seek, p_fallback_weight, p_weights);
|
|
|
|
_process_node(bn->inputs[0].node, r_prev_anim, p_time, p_seek, lower_fallback_weight, &lower_weights);
|
|
|
|
_process_node(bn->inputs[2].node, r_prev_anim, p_time, p_seek, upper_fallback_weight, &upper_weights);
|
2016-02-28 11:55:53 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return rem;
|
|
|
|
} break;
|
|
|
|
case NODE_BLEND4: {
|
2017-03-05 15:44:50 +00:00
|
|
|
Blend4Node *bn = static_cast<Blend4Node *>(nb);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-06-18 23:28:10 +00:00
|
|
|
HashMap<NodePath, float> weights1(*p_weights);
|
|
|
|
float fallback_weight1 = p_fallback_weight;
|
|
|
|
HashMap<NodePath, float> weights2(*p_weights);
|
|
|
|
float fallback_weight2 = p_fallback_weight;
|
|
|
|
HashMap<NodePath, float> weights3(*p_weights);
|
|
|
|
float fallback_weight3 = p_fallback_weight;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
_compute_weights(&p_fallback_weight, p_weights, 1.0 - bn->value.x);
|
|
|
|
_compute_weights(&fallback_weight1, &weights1, bn->value.x);
|
|
|
|
_compute_weights(&fallback_weight2, &weights2, 1.0 - bn->value.y);
|
|
|
|
_compute_weights(&fallback_weight3, &weights3, bn->value.y);
|
2016-06-18 23:28:10 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float rem = _process_node(bn->inputs[0].node, r_prev_anim, p_time, p_seek, p_fallback_weight, p_weights);
|
|
|
|
_process_node(bn->inputs[1].node, r_prev_anim, p_time, p_seek, fallback_weight1, &weights1);
|
|
|
|
float rem2 = _process_node(bn->inputs[2].node, r_prev_anim, p_time, p_seek, fallback_weight2, &weights2);
|
|
|
|
_process_node(bn->inputs[3].node, r_prev_anim, p_time, p_seek, fallback_weight3, &weights3);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return MAX(rem, rem2);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case NODE_TIMESCALE: {
|
2017-03-05 15:44:50 +00:00
|
|
|
TimeScaleNode *tsn = static_cast<TimeScaleNode *>(nb);
|
2016-03-07 22:21:07 +00:00
|
|
|
float rem;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (p_seek)
|
2017-03-05 15:44:50 +00:00
|
|
|
rem = _process_node(tsn->inputs[0].node, r_prev_anim, p_time, true, p_fallback_weight, p_weights);
|
2014-02-10 01:10:30 +00:00
|
|
|
else
|
2017-03-05 15:44:50 +00:00
|
|
|
rem = _process_node(tsn->inputs[0].node, r_prev_anim, p_time * tsn->scale, false, p_fallback_weight, p_weights);
|
2016-03-08 12:16:25 +00:00
|
|
|
if (tsn->scale == 0)
|
2017-02-06 22:44:22 +00:00
|
|
|
return Math_INF;
|
2014-02-10 01:10:30 +00:00
|
|
|
else
|
2016-03-08 12:16:25 +00:00
|
|
|
return rem / tsn->scale;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case NODE_TIMESEEK: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
TimeSeekNode *tsn = static_cast<TimeSeekNode *>(nb);
|
|
|
|
if (tsn->seek_pos >= 0 && !p_seek) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-03-31 14:06:38 +00:00
|
|
|
p_time = tsn->seek_pos;
|
|
|
|
p_seek = true;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
tsn->seek_pos = -1;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return _process_node(tsn->inputs[0].node, r_prev_anim, p_time, p_seek, p_fallback_weight, p_weights);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case NODE_TRANSITION: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
TransitionNode *tn = static_cast<TransitionNode *>(nb);
|
2016-06-18 23:28:10 +00:00
|
|
|
HashMap<NodePath, float> prev_weights(*p_weights);
|
|
|
|
float prev_fallback_weight = p_fallback_weight;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (tn->prev < 0) { // process current animation, check for transition
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float rem = _process_node(tn->inputs[tn->current].node, r_prev_anim, p_time, p_seek, p_fallback_weight, p_weights);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (p_seek)
|
2017-03-05 15:44:50 +00:00
|
|
|
tn->time = p_time;
|
2014-02-10 01:10:30 +00:00
|
|
|
else
|
2017-03-05 15:44:50 +00:00
|
|
|
tn->time += p_time;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-03-31 16:12:05 +00:00
|
|
|
if (tn->input_data[tn->current].auto_advance && rem <= tn->xfade) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
tn->set_current((tn->current + 1) % tn->inputs.size());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rem;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else { // cross-fading from tn->prev to tn->current
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float blend = tn->xfade ? (tn->prev_xfading / tn->xfade) : 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
float rem;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
_compute_weights(&p_fallback_weight, p_weights, 1.0 - blend);
|
|
|
|
_compute_weights(&prev_fallback_weight, &prev_weights, blend);
|
2016-06-18 23:28:10 +00:00
|
|
|
|
2016-03-27 11:19:05 +00:00
|
|
|
if (!p_seek && tn->switched) { //just switched, seek to start of current
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
rem = _process_node(tn->inputs[tn->current].node, r_prev_anim, 0, true, p_fallback_weight, p_weights);
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
rem = _process_node(tn->inputs[tn->current].node, r_prev_anim, p_time, p_seek, p_fallback_weight, p_weights);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
tn->switched = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_seek) { // don't seek prev animation
|
|
|
|
_process_node(tn->inputs[tn->prev].node, r_prev_anim, 0, false, prev_fallback_weight, &prev_weights);
|
|
|
|
tn->time = p_time;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
_process_node(tn->inputs[tn->prev].node, r_prev_anim, p_time, false, prev_fallback_weight, &prev_weights);
|
|
|
|
tn->time += p_time;
|
|
|
|
tn->prev_xfading -= p_time;
|
|
|
|
if (tn->prev_xfading < 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
tn->prev = -1;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2019-04-09 15:08:36 +00:00
|
|
|
default: {
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-09-02 12:11:34 +00:00
|
|
|
void AnimationTreePlayer::_process_animation(float p_delta) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (last_error != CONNECT_OK)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (dirty_caches)
|
|
|
|
_recompute_caches();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
active_list = NULL;
|
|
|
|
AnimationNode *prev = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (reset_request) {
|
2016-06-18 23:28:10 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
_process_node(out_name, &prev, 0, true);
|
|
|
|
reset_request = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else
|
2017-03-05 15:44:50 +00:00
|
|
|
_process_node(out_name, &prev, p_delta);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (dirty_caches) {
|
|
|
|
//some animation changed.. ignore this pass
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//update the tracks..
|
|
|
|
|
|
|
|
/* STEP 1 CLEAR TRACKS */
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (TrackMap::Element *E = track_map.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Track &t = E->get();
|
|
|
|
|
|
|
|
t.loc.zero();
|
2017-03-05 15:44:50 +00:00
|
|
|
t.rot = Quat();
|
|
|
|
t.scale.x = 0;
|
|
|
|
t.scale.y = 0;
|
|
|
|
t.scale.z = 0;
|
2016-02-18 03:34:49 +00:00
|
|
|
|
2017-05-30 20:20:15 +00:00
|
|
|
t.value = t.object->get_indexed(t.subpath);
|
2016-04-12 15:54:17 +00:00
|
|
|
t.value.zero();
|
2017-10-03 16:49:32 +00:00
|
|
|
|
2019-09-18 22:46:32 +00:00
|
|
|
t.skip = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* STEP 2 PROCESS ANIMATIONS */
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AnimationNode *anim_list = active_list;
|
2014-02-10 01:10:30 +00:00
|
|
|
Quat empty_rot;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (anim_list) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!anim_list->animation.is_null() && !anim_list->skip) {
|
|
|
|
//check if animation is meaningful
|
|
|
|
Animation *a = anim_list->animation.operator->();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<AnimationNode::TrackRef>::Element *E = anim_list->tref.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
AnimationNode::TrackRef &tr = E->get();
|
2017-11-28 15:46:37 +00:00
|
|
|
if (tr.track == NULL || tr.local_track < 0 || tr.weight < CMP_EPSILON || !a->track_is_enabled(tr.local_track))
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (a->track_get_type(tr.local_track)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case Animation::TYPE_TRANSFORM: { ///< Transform a node or a bone.
|
|
|
|
|
|
|
|
Vector3 loc;
|
|
|
|
Quat rot;
|
|
|
|
Vector3 scale;
|
2017-03-05 15:44:50 +00:00
|
|
|
a->transform_track_interpolate(tr.local_track, anim_list->time, &loc, &rot, &scale);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
tr.track->loc += loc * tr.weight;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
scale.x -= 1.0;
|
|
|
|
scale.y -= 1.0;
|
|
|
|
scale.z -= 1.0;
|
|
|
|
tr.track->scale += scale * tr.weight;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
tr.track->rot = tr.track->rot * empty_rot.slerp(rot, tr.weight);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Animation::TYPE_VALUE: { ///< Set a value in a property, can be interpolated.
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (a->value_track_get_update_mode(tr.local_track) == Animation::UPDATE_CONTINUOUS) {
|
|
|
|
Variant value = a->value_track_interpolate(tr.local_track, anim_list->time);
|
|
|
|
Variant::blend(tr.track->value, value, tr.weight, tr.track->value);
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
int index = a->track_find_key(tr.local_track, anim_list->time);
|
2016-04-24 08:39:32 +00:00
|
|
|
tr.track->value = a->track_get_key_value(tr.local_track, index);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case Animation::TYPE_METHOD: { ///< Call any method on a specific node.
|
|
|
|
|
|
|
|
List<int> indices;
|
2017-03-05 15:44:50 +00:00
|
|
|
a->method_track_get_key_indices(tr.local_track, anim_list->time, anim_list->step, &indices);
|
2019-02-12 20:10:08 +00:00
|
|
|
for (List<int>::Element *F = indices.front(); F; F = F->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-02-12 20:10:08 +00:00
|
|
|
StringName method = a->method_track_get_name(tr.local_track, F->get());
|
|
|
|
Vector<Variant> args = a->method_track_get_params(tr.local_track, F->get());
|
2015-12-16 11:34:57 +00:00
|
|
|
args.resize(VARIANT_ARG_MAX);
|
2017-03-05 15:44:50 +00:00
|
|
|
tr.track->object->call(method, args[0], args[1], args[2], args[3], args[4]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
} break;
|
2019-04-09 15:08:36 +00:00
|
|
|
default: {
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
anim_list = anim_list->next;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* STEP 3 APPLY TRACKS */
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (TrackMap::Element *E = track_map.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Track &t = E->get();
|
|
|
|
|
2017-10-03 16:49:32 +00:00
|
|
|
if (t.skip || !t.object)
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
2016-03-08 22:23:32 +00:00
|
|
|
|
2017-05-30 20:20:15 +00:00
|
|
|
if (t.subpath.size()) { // value track
|
|
|
|
t.object->set_indexed(t.subpath, t.value);
|
2016-03-08 22:23:32 +00:00
|
|
|
continue;
|
2016-04-24 08:39:32 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Transform xform;
|
2017-03-05 15:44:50 +00:00
|
|
|
xform.origin = t.loc;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
t.scale.x += 1.0;
|
|
|
|
t.scale.y += 1.0;
|
|
|
|
t.scale.z += 1.0;
|
2018-04-14 19:53:25 +00:00
|
|
|
xform.basis.set_quat_scale(t.rot, t.scale);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (t.bone_idx >= 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
if (t.skeleton)
|
2017-03-05 15:44:50 +00:00
|
|
|
t.skeleton->set_bone_pose(t.bone_idx, xform);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} else if (t.spatial) {
|
|
|
|
|
|
|
|
t.spatial->set_transform(xform);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::add_node(NodeType p_type, const StringName &p_node) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(p_type == NODE_OUTPUT);
|
|
|
|
ERR_FAIL_COND(node_map.has(p_node));
|
2021-02-17 08:52:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_type, NODE_MAX);
|
2017-03-05 15:44:50 +00:00
|
|
|
NodeBase *n = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (p_type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case NODE_ANIMATION: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
n = memnew(AnimationNode);
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case NODE_ONESHOT: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
n = memnew(OneShotNode);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case NODE_MIX: {
|
2017-03-05 15:44:50 +00:00
|
|
|
n = memnew(MixNode);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case NODE_BLEND2: {
|
2017-03-05 15:44:50 +00:00
|
|
|
n = memnew(Blend2Node);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case NODE_BLEND3: {
|
2017-03-05 15:44:50 +00:00
|
|
|
n = memnew(Blend3Node);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case NODE_BLEND4: {
|
2017-03-05 15:44:50 +00:00
|
|
|
n = memnew(Blend4Node);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case NODE_TIMESCALE: {
|
2017-03-05 15:44:50 +00:00
|
|
|
n = memnew(TimeScaleNode);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case NODE_TIMESEEK: {
|
2017-03-05 15:44:50 +00:00
|
|
|
n = memnew(TimeSeekNode);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case NODE_TRANSITION: {
|
2017-03-05 15:44:50 +00:00
|
|
|
n = memnew(TransitionNode);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
2019-04-09 15:08:36 +00:00
|
|
|
default: {
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//n->name+=" "+itos(p_node);
|
2017-03-05 15:44:50 +00:00
|
|
|
node_map[p_node] = n;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
StringName AnimationTreePlayer::node_get_input_source(const StringName &p_node, int p_input) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!node_map.has(p_node), StringName());
|
|
|
|
ERR_FAIL_INDEX_V(p_input, node_map[p_node]->inputs.size(), StringName());
|
2014-02-10 01:10:30 +00:00
|
|
|
return node_map[p_node]->inputs[p_input].node;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int AnimationTreePlayer::node_get_input_count(const StringName &p_node) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!node_map.has(p_node), -1);
|
2014-02-10 01:10:30 +00:00
|
|
|
return node_map[p_node]->inputs.size();
|
|
|
|
}
|
2019-08-08 20:11:48 +00:00
|
|
|
#define GET_NODE(m_type, m_cast) \
|
|
|
|
ERR_FAIL_COND(!node_map.has(p_node)); \
|
|
|
|
ERR_FAIL_COND_MSG(node_map[p_node]->type != m_type, "Invalid parameter for node type."); \
|
2017-03-05 15:44:50 +00:00
|
|
|
m_cast *n = static_cast<m_cast *>(node_map[p_node]);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::animation_node_set_animation(const StringName &p_node, const Ref<Animation> &p_animation) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_ANIMATION, AnimationNode);
|
|
|
|
n->animation = p_animation;
|
|
|
|
dirty_caches = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::animation_node_set_master_animation(const StringName &p_node, const String &p_master_animation) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_ANIMATION, AnimationNode);
|
|
|
|
n->from = p_master_animation;
|
|
|
|
dirty_caches = true;
|
|
|
|
if (master != NodePath())
|
2014-02-10 01:10:30 +00:00
|
|
|
_update_sources();
|
|
|
|
}
|
|
|
|
|
2017-09-01 19:29:00 +00:00
|
|
|
void AnimationTreePlayer::animation_node_set_filter_path(const StringName &p_node, const NodePath &p_track_path, bool p_filter) {
|
2016-04-25 09:41:23 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_ANIMATION, AnimationNode);
|
2016-04-25 09:41:23 +00:00
|
|
|
|
|
|
|
if (p_filter)
|
2017-03-05 15:44:50 +00:00
|
|
|
n->filter[p_track_path] = true;
|
2016-04-25 09:41:23 +00:00
|
|
|
else
|
|
|
|
n->filter.erase(p_track_path);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::animation_node_set_get_filtered_paths(const StringName &p_node, List<NodePath> *r_paths) const {
|
2016-04-25 09:41:23 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_ANIMATION, AnimationNode);
|
2016-04-25 09:41:23 +00:00
|
|
|
|
|
|
|
n->filter.get_key_list(r_paths);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::oneshot_node_set_fadein_time(const StringName &p_node, float p_time) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_ONESHOT, OneShotNode);
|
|
|
|
n->fade_in = p_time;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::oneshot_node_set_fadeout_time(const StringName &p_node, float p_time) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_ONESHOT, OneShotNode);
|
|
|
|
n->fade_out = p_time;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::oneshot_node_set_mix_mode(const StringName &p_node, bool p_mix) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_ONESHOT, OneShotNode);
|
|
|
|
n->mix = p_mix;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::oneshot_node_set_autorestart(const StringName &p_node, bool p_active) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_ONESHOT, OneShotNode);
|
|
|
|
n->autorestart = p_active;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::oneshot_node_set_autorestart_delay(const StringName &p_node, float p_time) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_ONESHOT, OneShotNode);
|
|
|
|
n->autorestart_delay = p_time;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::oneshot_node_set_autorestart_random_delay(const StringName &p_node, float p_time) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_ONESHOT, OneShotNode);
|
|
|
|
n->autorestart_random_delay = p_time;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::oneshot_node_start(const StringName &p_node) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_ONESHOT, OneShotNode);
|
|
|
|
n->active = true;
|
|
|
|
n->start = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::oneshot_node_stop(const StringName &p_node) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_ONESHOT, OneShotNode);
|
|
|
|
n->active = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::oneshot_node_set_filter_path(const StringName &p_node, const NodePath &p_filter, bool p_enable) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_ONESHOT, OneShotNode);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (p_enable)
|
2017-03-05 15:44:50 +00:00
|
|
|
n->filter[p_filter] = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
else
|
|
|
|
n->filter.erase(p_filter);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::oneshot_node_set_get_filtered_paths(const StringName &p_node, List<NodePath> *r_paths) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_ONESHOT, OneShotNode);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
n->filter.get_key_list(r_paths);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::mix_node_set_amount(const StringName &p_node, float p_amount) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_MIX, MixNode);
|
|
|
|
n->amount = p_amount;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::blend2_node_set_amount(const StringName &p_node, float p_amount) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_BLEND2, Blend2Node);
|
|
|
|
n->value = p_amount;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::blend2_node_set_filter_path(const StringName &p_node, const NodePath &p_filter, bool p_enable) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_BLEND2, Blend2Node);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (p_enable)
|
2017-03-05 15:44:50 +00:00
|
|
|
n->filter[p_filter] = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
else
|
|
|
|
n->filter.erase(p_filter);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::blend2_node_set_get_filtered_paths(const StringName &p_node, List<NodePath> *r_paths) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_BLEND2, Blend2Node);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
n->filter.get_key_list(r_paths);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::blend3_node_set_amount(const StringName &p_node, float p_amount) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_BLEND3, Blend3Node);
|
|
|
|
n->value = p_amount;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::blend4_node_set_amount(const StringName &p_node, const Vector2 &p_amount) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_BLEND4, Blend4Node);
|
|
|
|
n->value = p_amount;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::timescale_node_set_scale(const StringName &p_node, float p_scale) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_TIMESCALE, TimeScaleNode);
|
|
|
|
n->scale = p_scale;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::timeseek_node_seek(const StringName &p_node, float p_pos) {
|
2014-07-07 20:54:34 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_TIMESEEK, TimeSeekNode);
|
|
|
|
n->seek_pos = p_pos;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::transition_node_set_input_count(const StringName &p_node, int p_inputs) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_TRANSITION, TransitionNode);
|
|
|
|
ERR_FAIL_COND(p_inputs < 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
n->inputs.resize(p_inputs);
|
|
|
|
n->input_data.resize(p_inputs);
|
2017-12-24 17:21:59 +00:00
|
|
|
|
|
|
|
_clear_cycle_test();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
last_error = _cycle_test(out_name);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::transition_node_set_input_auto_advance(const StringName &p_node, int p_input, bool p_auto_advance) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_TRANSITION, TransitionNode);
|
|
|
|
ERR_FAIL_INDEX(p_input, n->input_data.size());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-07-25 01:11:03 +00:00
|
|
|
n->input_data.write[p_input].auto_advance = p_auto_advance;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::transition_node_set_xfade_time(const StringName &p_node, float p_time) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_TRANSITION, TransitionNode);
|
|
|
|
n->xfade = p_time;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-04-06 19:09:00 +00:00
|
|
|
void AnimationTreePlayer::TransitionNode::set_current(int p_current) {
|
2017-09-12 10:58:18 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_current, inputs.size());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (current == p_current)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
prev = current;
|
|
|
|
prev_xfading = xfade;
|
|
|
|
prev_time = time;
|
|
|
|
time = 0;
|
|
|
|
current = p_current;
|
|
|
|
switched = true;
|
2016-04-06 19:09:00 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::transition_node_set_current(const StringName &p_node, int p_current) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE(NODE_TRANSITION, TransitionNode);
|
2016-04-06 19:09:00 +00:00
|
|
|
n->set_current(p_current);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-09-10 13:37:49 +00:00
|
|
|
void AnimationTreePlayer::node_set_position(const StringName &p_node, const Vector2 &p_pos) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!node_map.has(p_node));
|
2017-03-05 15:44:50 +00:00
|
|
|
node_map[p_node]->pos = p_pos;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AnimationTreePlayer::NodeType AnimationTreePlayer::node_get_type(const StringName &p_node) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!node_map.has(p_node), NODE_OUTPUT);
|
2014-02-10 01:10:30 +00:00
|
|
|
return node_map[p_node]->type;
|
|
|
|
}
|
2017-09-10 13:37:49 +00:00
|
|
|
Point2 AnimationTreePlayer::node_get_position(const StringName &p_node) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!node_map.has(p_node), Point2());
|
2014-02-10 01:10:30 +00:00
|
|
|
return node_map[p_node]->pos;
|
|
|
|
}
|
|
|
|
|
2019-08-08 20:11:48 +00:00
|
|
|
#define GET_NODE_V(m_type, m_cast, m_ret) \
|
|
|
|
ERR_FAIL_COND_V(!node_map.has(p_node), m_ret); \
|
|
|
|
ERR_FAIL_COND_V_MSG(node_map[p_node]->type != m_type, m_ret, "Invalid parameter for node type."); \
|
2017-03-05 15:44:50 +00:00
|
|
|
m_cast *n = static_cast<m_cast *>(node_map[p_node]);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<Animation> AnimationTreePlayer::animation_node_get_animation(const StringName &p_node) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
GET_NODE_V(NODE_ANIMATION, AnimationNode, Ref<Animation>());
|
|
|
|
return n->animation;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String AnimationTreePlayer::animation_node_get_master_animation(const StringName &p_node) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
GET_NODE_V(NODE_ANIMATION, AnimationNode, String());
|
|
|
|
return n->from;
|
|
|
|
}
|
|
|
|
|
2018-05-14 14:06:30 +00:00
|
|
|
float AnimationTreePlayer::animation_node_get_position(const StringName &p_node) const {
|
|
|
|
|
|
|
|
GET_NODE_V(NODE_ANIMATION, AnimationNode, 0);
|
|
|
|
return n->time;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool AnimationTreePlayer::animation_node_is_path_filtered(const StringName &p_node, const NodePath &p_path) const {
|
2016-04-25 09:41:23 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE_V(NODE_ANIMATION, AnimationNode, 0);
|
2016-04-25 09:41:23 +00:00
|
|
|
return n->filter.has(p_path);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float AnimationTreePlayer::oneshot_node_get_fadein_time(const StringName &p_node) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE_V(NODE_ONESHOT, OneShotNode, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
return n->fade_in;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float AnimationTreePlayer::oneshot_node_get_fadeout_time(const StringName &p_node) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE_V(NODE_ONESHOT, OneShotNode, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
return n->fade_out;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool AnimationTreePlayer::oneshot_node_get_mix_mode(const StringName &p_node) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE_V(NODE_ONESHOT, OneShotNode, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
return n->mix;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
bool AnimationTreePlayer::oneshot_node_has_autorestart(const StringName &p_node) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE_V(NODE_ONESHOT, OneShotNode, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
return n->autorestart;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
float AnimationTreePlayer::oneshot_node_get_autorestart_delay(const StringName &p_node) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE_V(NODE_ONESHOT, OneShotNode, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
return n->autorestart_delay;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
float AnimationTreePlayer::oneshot_node_get_autorestart_random_delay(const StringName &p_node) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE_V(NODE_ONESHOT, OneShotNode, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
return n->autorestart_random_delay;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool AnimationTreePlayer::oneshot_node_is_active(const StringName &p_node) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE_V(NODE_ONESHOT, OneShotNode, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
return n->active;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool AnimationTreePlayer::oneshot_node_is_path_filtered(const StringName &p_node, const NodePath &p_path) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE_V(NODE_ONESHOT, OneShotNode, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
return n->filter.has(p_path);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float AnimationTreePlayer::mix_node_get_amount(const StringName &p_node) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE_V(NODE_MIX, MixNode, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
return n->amount;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
float AnimationTreePlayer::blend2_node_get_amount(const StringName &p_node) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE_V(NODE_BLEND2, Blend2Node, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
return n->value;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool AnimationTreePlayer::blend2_node_is_path_filtered(const StringName &p_node, const NodePath &p_path) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE_V(NODE_BLEND2, Blend2Node, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
return n->filter.has(p_path);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float AnimationTreePlayer::blend3_node_get_amount(const StringName &p_node) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE_V(NODE_BLEND3, Blend3Node, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
return n->value;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector2 AnimationTreePlayer::blend4_node_get_amount(const StringName &p_node) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE_V(NODE_BLEND4, Blend4Node, Vector2());
|
2014-02-10 01:10:30 +00:00
|
|
|
return n->value;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float AnimationTreePlayer::timescale_node_get_scale(const StringName &p_node) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE_V(NODE_TIMESCALE, TimeScaleNode, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
return n->scale;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::transition_node_delete_input(const StringName &p_node, int p_input) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
GET_NODE(NODE_TRANSITION, TransitionNode);
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_input, n->inputs.size());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (n->inputs.size() <= 1)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
n->inputs.remove(p_input);
|
|
|
|
n->input_data.remove(p_input);
|
2017-03-05 15:44:50 +00:00
|
|
|
last_error = _cycle_test(out_name);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int AnimationTreePlayer::transition_node_get_input_count(const StringName &p_node) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE_V(NODE_TRANSITION, TransitionNode, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
return n->inputs.size();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool AnimationTreePlayer::transition_node_has_input_auto_advance(const StringName &p_node, int p_input) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE_V(NODE_TRANSITION, TransitionNode, false);
|
|
|
|
ERR_FAIL_INDEX_V(p_input, n->inputs.size(), false);
|
2014-02-10 01:10:30 +00:00
|
|
|
return n->input_data[p_input].auto_advance;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
float AnimationTreePlayer::transition_node_get_xfade_time(const StringName &p_node) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE_V(NODE_TRANSITION, TransitionNode, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
return n->xfade;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int AnimationTreePlayer::transition_node_get_current(const StringName &p_node) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GET_NODE_V(NODE_TRANSITION, TransitionNode, -1);
|
2014-02-10 01:10:30 +00:00
|
|
|
return n->current;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
/*misc */
|
2014-02-10 01:10:30 +00:00
|
|
|
void AnimationTreePlayer::get_node_list(List<StringName> *p_node_list) const {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<StringName, NodeBase *>::Element *E = node_map.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
p_node_list->push_back(E->key());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::remove_node(const StringName &p_node) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(!node_map.has(p_node));
|
2019-08-08 20:11:48 +00:00
|
|
|
ERR_FAIL_COND_MSG(p_node == out_name, "Node 0 (output) can't be removed.");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<StringName, NodeBase *>::Element *E = node_map.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
NodeBase *nb = E->get();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < nb->inputs.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (nb->inputs[i].node == p_node)
|
2018-07-25 01:11:03 +00:00
|
|
|
nb->inputs.write[i].node = StringName();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
node_map.erase(p_node);
|
|
|
|
|
2017-12-24 17:21:59 +00:00
|
|
|
_clear_cycle_test();
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
// compute last error again, just in case
|
2017-03-05 15:44:50 +00:00
|
|
|
last_error = _cycle_test(out_name);
|
|
|
|
dirty_caches = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AnimationTreePlayer::ConnectError AnimationTreePlayer::_cycle_test(const StringName &p_at_node) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!node_map.has(p_at_node), CONNECT_INCOMPLETE);
|
|
|
|
|
|
|
|
NodeBase *nb = node_map[p_at_node];
|
|
|
|
if (nb->cycletest)
|
|
|
|
return CONNECT_CYCLE;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
nb->cycletest = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < nb->inputs.size(); i++) {
|
|
|
|
if (nb->inputs[i].node == StringName())
|
2014-02-10 01:10:30 +00:00
|
|
|
return CONNECT_INCOMPLETE;
|
|
|
|
|
|
|
|
ConnectError _err = _cycle_test(nb->inputs[i].node);
|
|
|
|
if (_err)
|
|
|
|
return _err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CONNECT_OK;
|
|
|
|
}
|
|
|
|
|
2017-12-24 17:21:59 +00:00
|
|
|
// Use this function to not alter next complete _cycle_test().
|
|
|
|
void AnimationTreePlayer::_clear_cycle_test() {
|
|
|
|
for (Map<StringName, NodeBase *>::Element *E = node_map.front(); E; E = E->next()) {
|
|
|
|
NodeBase *nb = E->get();
|
|
|
|
nb->cycletest = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Error AnimationTreePlayer::connect_nodes(const StringName &p_src_node, const StringName &p_dst_node, int p_dst_input) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!node_map.has(p_src_node), ERR_INVALID_PARAMETER);
|
|
|
|
ERR_FAIL_COND_V(!node_map.has(p_dst_node), ERR_INVALID_PARAMETER);
|
|
|
|
ERR_FAIL_COND_V(p_src_node == p_dst_node, ERR_INVALID_PARAMETER);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
//NodeBase *src = node_map[p_src_node];
|
2014-02-10 01:10:30 +00:00
|
|
|
NodeBase *dst = node_map[p_dst_node];
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_dst_input, dst->inputs.size(), ERR_INVALID_PARAMETER);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
//int oldval = dst->inputs[p_dst_input].node;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<StringName, NodeBase *>::Element *E = node_map.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
NodeBase *nb = E->get();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < nb->inputs.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (nb->inputs[i].node == p_src_node)
|
2018-07-25 01:11:03 +00:00
|
|
|
nb->inputs.write[i].node = StringName();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-25 01:11:03 +00:00
|
|
|
dst->inputs.write[p_dst_input].node = p_src_node;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-12-24 17:21:59 +00:00
|
|
|
_clear_cycle_test();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
last_error = _cycle_test(out_name);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (last_error) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (last_error == CONNECT_INCOMPLETE)
|
2014-02-10 01:10:30 +00:00
|
|
|
return ERR_UNCONFIGURED;
|
2017-03-05 15:44:50 +00:00
|
|
|
else if (last_error == CONNECT_CYCLE)
|
2014-02-10 01:10:30 +00:00
|
|
|
return ERR_CYCLIC_LINK;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
dirty_caches = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool AnimationTreePlayer::are_nodes_connected(const StringName &p_src_node, const StringName &p_dst_node, int p_dst_input) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!node_map.has(p_src_node), false);
|
|
|
|
ERR_FAIL_COND_V(!node_map.has(p_dst_node), false);
|
|
|
|
ERR_FAIL_COND_V(p_src_node == p_dst_node, false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
NodeBase *dst = node_map[p_dst_node];
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return dst->inputs[p_dst_input].node == p_src_node;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::disconnect_nodes(const StringName &p_node, int p_input) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(!node_map.has(p_node));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
NodeBase *dst = node_map[p_node];
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_input, dst->inputs.size());
|
2018-07-25 01:11:03 +00:00
|
|
|
dst->inputs.write[p_input].node = StringName();
|
2017-03-05 15:44:50 +00:00
|
|
|
last_error = CONNECT_INCOMPLETE;
|
|
|
|
dirty_caches = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::get_connection_list(List<Connection> *p_connections) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<StringName, NodeBase *>::Element *E = node_map.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
NodeBase *nb = E->get();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < nb->inputs.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (nb->inputs[i].node != StringName()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
Connection c;
|
2017-03-05 15:44:50 +00:00
|
|
|
c.src_node = nb->inputs[i].node;
|
|
|
|
c.dst_node = E->key();
|
|
|
|
c.dst_input = i;
|
2014-02-10 01:10:30 +00:00
|
|
|
p_connections->push_back(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AnimationTreePlayer::Track *AnimationTreePlayer::_find_track(const NodePath &p_path) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Node *parent = get_node(base_path);
|
|
|
|
ERR_FAIL_COND_V(!parent, NULL);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-04-12 00:10:35 +00:00
|
|
|
RES resource;
|
2017-05-30 20:20:15 +00:00
|
|
|
Vector<StringName> leftover_path;
|
|
|
|
Node *child = parent->get_node_and_resource(p_path, resource, leftover_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!child) {
|
2017-03-05 15:44:50 +00:00
|
|
|
String err = "Animation track references unknown Node: '" + String(p_path) + "'.";
|
2014-02-10 01:10:30 +00:00
|
|
|
WARN_PRINT(err.ascii().get_data());
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-08-07 10:17:31 +00:00
|
|
|
ObjectID id = child->get_instance_id();
|
2017-03-05 15:44:50 +00:00
|
|
|
int bone_idx = -1;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-30 20:20:15 +00:00
|
|
|
if (p_path.get_subname_count()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-08-24 20:58:51 +00:00
|
|
|
if (Object::cast_to<Skeleton>(child))
|
2017-05-30 20:20:15 +00:00
|
|
|
bone_idx = Object::cast_to<Skeleton>(child)->find_bone(p_path.get_subname(0));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TrackKey key;
|
2017-03-05 15:44:50 +00:00
|
|
|
key.id = id;
|
|
|
|
key.bone_idx = bone_idx;
|
2017-05-30 20:20:15 +00:00
|
|
|
key.subpath_concatenated = p_path.get_concatenated_subnames();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!track_map.has(key)) {
|
|
|
|
|
|
|
|
Track tr;
|
2017-03-05 15:44:50 +00:00
|
|
|
tr.id = id;
|
|
|
|
tr.object = resource.is_valid() ? (Object *)resource.ptr() : (Object *)child;
|
2017-08-24 20:58:51 +00:00
|
|
|
tr.skeleton = Object::cast_to<Skeleton>(child);
|
|
|
|
tr.spatial = Object::cast_to<Spatial>(child);
|
2017-03-05 15:44:50 +00:00
|
|
|
tr.bone_idx = bone_idx;
|
2021-05-04 12:28:27 +00:00
|
|
|
if (bone_idx == -1)
|
|
|
|
tr.subpath = leftover_path;
|
2017-03-05 15:44:50 +00:00
|
|
|
|
|
|
|
track_map[key] = tr;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &track_map[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreePlayer::_recompute_caches() {
|
|
|
|
|
|
|
|
track_map.clear();
|
|
|
|
_recompute_caches(out_name);
|
2017-03-05 15:44:50 +00:00
|
|
|
dirty_caches = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::_recompute_caches(const StringName &p_node) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(!node_map.has(p_node));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
NodeBase *nb = node_map[p_node];
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (nb->type == NODE_ANIMATION) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AnimationNode *an = static_cast<AnimationNode *>(nb);
|
2017-01-14 17:03:38 +00:00
|
|
|
an->tref.clear();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!an->animation.is_null()) {
|
|
|
|
|
|
|
|
Ref<Animation> a = an->animation;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < an->animation->get_track_count(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Track *tr = _find_track(a->track_get_path(i));
|
|
|
|
if (!tr)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
AnimationNode::TrackRef tref;
|
2017-03-05 15:44:50 +00:00
|
|
|
tref.local_track = i;
|
|
|
|
tref.track = tr;
|
|
|
|
tref.weight = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
an->tref.push_back(tref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < nb->inputs.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
_recompute_caches(nb->inputs[i].node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreePlayer::recompute_caches() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
dirty_caches = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
/* playback */
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
void AnimationTreePlayer::set_active(bool p_active) {
|
|
|
|
|
2015-09-02 12:11:34 +00:00
|
|
|
if (active == p_active)
|
|
|
|
return;
|
|
|
|
|
|
|
|
active = p_active;
|
|
|
|
processing = active;
|
2016-04-06 19:07:58 +00:00
|
|
|
reset_request = p_active;
|
2015-09-02 12:11:34 +00:00
|
|
|
_set_process(processing, true);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AnimationTreePlayer::is_active() const {
|
|
|
|
|
|
|
|
return active;
|
|
|
|
}
|
|
|
|
|
|
|
|
AnimationTreePlayer::ConnectError AnimationTreePlayer::get_last_error() const {
|
|
|
|
|
|
|
|
return last_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreePlayer::reset() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
reset_request = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::set_base_path(const NodePath &p_path) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
base_path = p_path;
|
2014-02-10 01:10:30 +00:00
|
|
|
recompute_caches();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
NodePath AnimationTreePlayer::get_base_path() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return base_path;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreePlayer::set_master_player(const NodePath &p_path) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_path == master)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
master = p_path;
|
2014-02-10 01:10:30 +00:00
|
|
|
_update_sources();
|
|
|
|
recompute_caches();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
NodePath AnimationTreePlayer::get_master_player() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return master;
|
|
|
|
}
|
|
|
|
|
2017-01-07 21:25:37 +00:00
|
|
|
PoolVector<String> AnimationTreePlayer::_get_node_list() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
List<StringName> nl;
|
|
|
|
get_node_list(&nl);
|
2017-01-07 21:25:37 +00:00
|
|
|
PoolVector<String> ret;
|
2014-02-10 01:10:30 +00:00
|
|
|
ret.resize(nl.size());
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = 0;
|
|
|
|
for (List<StringName>::Element *E = nl.front(); E; E = E->next()) {
|
|
|
|
ret.set(idx++, E->get());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreePlayer::_update_sources() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (master == NodePath())
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2014-11-06 00:20:42 +00:00
|
|
|
if (!is_inside_tree())
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
Node *m = get_node(master);
|
|
|
|
if (!m) {
|
2017-03-05 15:44:50 +00:00
|
|
|
master = NodePath();
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_COND(!m);
|
|
|
|
}
|
|
|
|
|
2017-08-24 20:58:51 +00:00
|
|
|
AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(m);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!ap) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
master = NodePath();
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_COND(!ap);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<StringName, NodeBase *>::Element *E = node_map.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (E->get()->type == NODE_ANIMATION) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AnimationNode *an = static_cast<AnimationNode *>(E->get());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (an->from != "") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
an->animation = ap->get_animation(an->from);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool AnimationTreePlayer::node_exists(const StringName &p_name) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return (node_map.has(p_name));
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Error AnimationTreePlayer::node_rename(const StringName &p_node, const StringName &p_new_name) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_new_name == p_node)
|
2014-02-10 01:10:30 +00:00
|
|
|
return OK;
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!node_map.has(p_node), ERR_ALREADY_EXISTS);
|
|
|
|
ERR_FAIL_COND_V(node_map.has(p_new_name), ERR_ALREADY_EXISTS);
|
|
|
|
ERR_FAIL_COND_V(p_new_name == StringName(), ERR_INVALID_DATA);
|
|
|
|
ERR_FAIL_COND_V(p_node == out_name, ERR_INVALID_DATA);
|
|
|
|
ERR_FAIL_COND_V(p_new_name == out_name, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<StringName, NodeBase *>::Element *E = node_map.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
NodeBase *nb = E->get();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < nb->inputs.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (nb->inputs[i].node == p_node) {
|
2018-07-25 01:11:03 +00:00
|
|
|
nb->inputs.write[i].node = p_new_name;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
node_map[p_new_name] = node_map[p_node];
|
2014-02-10 01:10:30 +00:00
|
|
|
node_map.erase(p_node);
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2018-12-07 23:53:07 +00:00
|
|
|
String AnimationTreePlayer::get_configuration_warning() const {
|
|
|
|
|
|
|
|
return TTR("This node has been deprecated. Use AnimationTree instead.");
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void AnimationTreePlayer::_bind_methods() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("add_node", "type", "id"), &AnimationTreePlayer::add_node);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("node_exists", "node"), &AnimationTreePlayer::node_exists);
|
|
|
|
ClassDB::bind_method(D_METHOD("node_rename", "node", "new_name"), &AnimationTreePlayer::node_rename);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("node_get_type", "id"), &AnimationTreePlayer::node_get_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("node_get_input_count", "id"), &AnimationTreePlayer::node_get_input_count);
|
|
|
|
ClassDB::bind_method(D_METHOD("node_get_input_source", "id", "idx"), &AnimationTreePlayer::node_get_input_source);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-08-09 11:19:41 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("animation_node_set_animation", "id", "animation"), &AnimationTreePlayer::animation_node_set_animation);
|
|
|
|
ClassDB::bind_method(D_METHOD("animation_node_get_animation", "id"), &AnimationTreePlayer::animation_node_get_animation);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("animation_node_set_master_animation", "id", "source"), &AnimationTreePlayer::animation_node_set_master_animation);
|
|
|
|
ClassDB::bind_method(D_METHOD("animation_node_get_master_animation", "id"), &AnimationTreePlayer::animation_node_get_master_animation);
|
2018-05-14 14:06:30 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("animation_node_get_position", "id"), &AnimationTreePlayer::animation_node_get_position);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("animation_node_set_filter_path", "id", "path", "enable"), &AnimationTreePlayer::animation_node_set_filter_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("oneshot_node_set_fadein_time", "id", "time_sec"), &AnimationTreePlayer::oneshot_node_set_fadein_time);
|
|
|
|
ClassDB::bind_method(D_METHOD("oneshot_node_get_fadein_time", "id"), &AnimationTreePlayer::oneshot_node_get_fadein_time);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("oneshot_node_set_fadeout_time", "id", "time_sec"), &AnimationTreePlayer::oneshot_node_set_fadeout_time);
|
|
|
|
ClassDB::bind_method(D_METHOD("oneshot_node_get_fadeout_time", "id"), &AnimationTreePlayer::oneshot_node_get_fadeout_time);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("oneshot_node_set_autorestart", "id", "enable"), &AnimationTreePlayer::oneshot_node_set_autorestart);
|
|
|
|
ClassDB::bind_method(D_METHOD("oneshot_node_set_autorestart_delay", "id", "delay_sec"), &AnimationTreePlayer::oneshot_node_set_autorestart_delay);
|
|
|
|
ClassDB::bind_method(D_METHOD("oneshot_node_set_autorestart_random_delay", "id", "rand_sec"), &AnimationTreePlayer::oneshot_node_set_autorestart_random_delay);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("oneshot_node_has_autorestart", "id"), &AnimationTreePlayer::oneshot_node_has_autorestart);
|
|
|
|
ClassDB::bind_method(D_METHOD("oneshot_node_get_autorestart_delay", "id"), &AnimationTreePlayer::oneshot_node_get_autorestart_delay);
|
|
|
|
ClassDB::bind_method(D_METHOD("oneshot_node_get_autorestart_random_delay", "id"), &AnimationTreePlayer::oneshot_node_get_autorestart_random_delay);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("oneshot_node_start", "id"), &AnimationTreePlayer::oneshot_node_start);
|
|
|
|
ClassDB::bind_method(D_METHOD("oneshot_node_stop", "id"), &AnimationTreePlayer::oneshot_node_stop);
|
|
|
|
ClassDB::bind_method(D_METHOD("oneshot_node_is_active", "id"), &AnimationTreePlayer::oneshot_node_is_active);
|
|
|
|
ClassDB::bind_method(D_METHOD("oneshot_node_set_filter_path", "id", "path", "enable"), &AnimationTreePlayer::oneshot_node_set_filter_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("mix_node_set_amount", "id", "ratio"), &AnimationTreePlayer::mix_node_set_amount);
|
|
|
|
ClassDB::bind_method(D_METHOD("mix_node_get_amount", "id"), &AnimationTreePlayer::mix_node_get_amount);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("blend2_node_set_amount", "id", "blend"), &AnimationTreePlayer::blend2_node_set_amount);
|
|
|
|
ClassDB::bind_method(D_METHOD("blend2_node_get_amount", "id"), &AnimationTreePlayer::blend2_node_get_amount);
|
|
|
|
ClassDB::bind_method(D_METHOD("blend2_node_set_filter_path", "id", "path", "enable"), &AnimationTreePlayer::blend2_node_set_filter_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("blend3_node_set_amount", "id", "blend"), &AnimationTreePlayer::blend3_node_set_amount);
|
|
|
|
ClassDB::bind_method(D_METHOD("blend3_node_get_amount", "id"), &AnimationTreePlayer::blend3_node_get_amount);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("blend4_node_set_amount", "id", "blend"), &AnimationTreePlayer::blend4_node_set_amount);
|
|
|
|
ClassDB::bind_method(D_METHOD("blend4_node_get_amount", "id"), &AnimationTreePlayer::blend4_node_get_amount);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("timescale_node_set_scale", "id", "scale"), &AnimationTreePlayer::timescale_node_set_scale);
|
|
|
|
ClassDB::bind_method(D_METHOD("timescale_node_get_scale", "id"), &AnimationTreePlayer::timescale_node_get_scale);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-10 13:37:49 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("timeseek_node_seek", "id", "seconds"), &AnimationTreePlayer::timeseek_node_seek);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("transition_node_set_input_count", "id", "count"), &AnimationTreePlayer::transition_node_set_input_count);
|
|
|
|
ClassDB::bind_method(D_METHOD("transition_node_get_input_count", "id"), &AnimationTreePlayer::transition_node_get_input_count);
|
|
|
|
ClassDB::bind_method(D_METHOD("transition_node_delete_input", "id", "input_idx"), &AnimationTreePlayer::transition_node_delete_input);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("transition_node_set_input_auto_advance", "id", "input_idx", "enable"), &AnimationTreePlayer::transition_node_set_input_auto_advance);
|
|
|
|
ClassDB::bind_method(D_METHOD("transition_node_has_input_auto_advance", "id", "input_idx"), &AnimationTreePlayer::transition_node_has_input_auto_advance);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("transition_node_set_xfade_time", "id", "time_sec"), &AnimationTreePlayer::transition_node_set_xfade_time);
|
|
|
|
ClassDB::bind_method(D_METHOD("transition_node_get_xfade_time", "id"), &AnimationTreePlayer::transition_node_get_xfade_time);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("transition_node_set_current", "id", "input_idx"), &AnimationTreePlayer::transition_node_set_current);
|
|
|
|
ClassDB::bind_method(D_METHOD("transition_node_get_current", "id"), &AnimationTreePlayer::transition_node_get_current);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-10 13:37:49 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("node_set_position", "id", "screen_position"), &AnimationTreePlayer::node_set_position);
|
|
|
|
ClassDB::bind_method(D_METHOD("node_get_position", "id"), &AnimationTreePlayer::node_get_position);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("remove_node", "id"), &AnimationTreePlayer::remove_node);
|
|
|
|
ClassDB::bind_method(D_METHOD("connect_nodes", "id", "dst_id", "dst_input_idx"), &AnimationTreePlayer::connect_nodes);
|
|
|
|
ClassDB::bind_method(D_METHOD("are_nodes_connected", "id", "dst_id", "dst_input_idx"), &AnimationTreePlayer::are_nodes_connected);
|
|
|
|
ClassDB::bind_method(D_METHOD("disconnect_nodes", "id", "dst_input_idx"), &AnimationTreePlayer::disconnect_nodes);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_active", "enabled"), &AnimationTreePlayer::set_active);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_active"), &AnimationTreePlayer::is_active);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_base_path", "path"), &AnimationTreePlayer::set_base_path);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_base_path"), &AnimationTreePlayer::get_base_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_master_player", "nodepath"), &AnimationTreePlayer::set_master_player);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_master_player"), &AnimationTreePlayer::get_master_player);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_node_list"), &AnimationTreePlayer::_get_node_list);
|
2015-04-27 03:23:16 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_animation_process_mode", "mode"), &AnimationTreePlayer::set_animation_process_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_animation_process_mode"), &AnimationTreePlayer::get_animation_process_mode);
|
2015-04-27 03:23:16 +00:00
|
|
|
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("advance", "delta"), &AnimationTreePlayer::advance);
|
2015-04-27 03:23:16 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("reset"), &AnimationTreePlayer::reset);
|
2015-04-27 03:23:16 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("recompute_caches"), &AnimationTreePlayer::recompute_caches);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_GROUP("Playback", "playback_");
|
2017-10-21 14:28:08 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_animation_process_mode", "get_animation_process_mode");
|
2015-09-02 12:11:34 +00:00
|
|
|
|
2018-06-27 23:50:25 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "master_player", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "AnimationPlayer"), "set_master_player", "get_master_player");
|
2017-12-06 03:25:37 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "base_path"), "set_base_path", "get_base_path");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "active"), "set_active", "is_active");
|
|
|
|
|
2017-08-20 15:45:01 +00:00
|
|
|
BIND_ENUM_CONSTANT(NODE_OUTPUT);
|
|
|
|
BIND_ENUM_CONSTANT(NODE_ANIMATION);
|
|
|
|
BIND_ENUM_CONSTANT(NODE_ONESHOT);
|
|
|
|
BIND_ENUM_CONSTANT(NODE_MIX);
|
|
|
|
BIND_ENUM_CONSTANT(NODE_BLEND2);
|
|
|
|
BIND_ENUM_CONSTANT(NODE_BLEND3);
|
|
|
|
BIND_ENUM_CONSTANT(NODE_BLEND4);
|
|
|
|
BIND_ENUM_CONSTANT(NODE_TIMESCALE);
|
|
|
|
BIND_ENUM_CONSTANT(NODE_TIMESEEK);
|
|
|
|
BIND_ENUM_CONSTANT(NODE_TRANSITION);
|
2017-09-12 19:09:06 +00:00
|
|
|
|
2017-09-30 14:19:07 +00:00
|
|
|
BIND_ENUM_CONSTANT(ANIMATION_PROCESS_PHYSICS);
|
2017-09-12 19:09:06 +00:00
|
|
|
BIND_ENUM_CONSTANT(ANIMATION_PROCESS_IDLE);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AnimationTreePlayer::AnimationTreePlayer() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
active_list = NULL;
|
|
|
|
out = memnew(NodeOut);
|
|
|
|
out_name = "out";
|
|
|
|
out->pos = Point2(40, 40);
|
|
|
|
node_map.insert(out_name, out);
|
2015-09-02 12:11:34 +00:00
|
|
|
animation_process_mode = ANIMATION_PROCESS_IDLE;
|
|
|
|
processing = false;
|
2017-03-05 15:44:50 +00:00
|
|
|
active = false;
|
|
|
|
dirty_caches = true;
|
|
|
|
reset_request = true;
|
|
|
|
last_error = CONNECT_INCOMPLETE;
|
|
|
|
base_path = String("..");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AnimationTreePlayer::~AnimationTreePlayer() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (node_map.size()) {
|
|
|
|
memdelete(node_map.front()->get());
|
|
|
|
node_map.erase(node_map.front());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|