-Fix blend tree rename, closes #20210
-Fixed activity lines in blend tree
This commit is contained in:
parent
adc0188d9f
commit
bffaa835fc
5 changed files with 79 additions and 16 deletions
|
@ -650,8 +650,9 @@ void AnimationNodeBlendTreeEditor::_notification(int p_what) {
|
||||||
blend_tree->get_node_connections(&conns);
|
blend_tree->get_node_connections(&conns);
|
||||||
for (List<AnimationNodeBlendTree::NodeConnection>::Element *E = conns.front(); E; E = E->next()) {
|
for (List<AnimationNodeBlendTree::NodeConnection>::Element *E = conns.front(); E; E = E->next()) {
|
||||||
float activity = 0;
|
float activity = 0;
|
||||||
|
StringName path = AnimationTreeEditor::get_singleton()->get_base_path() + E->get().input_node;
|
||||||
if (AnimationTreeEditor::get_singleton()->get_tree() && !AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) {
|
if (AnimationTreeEditor::get_singleton()->get_tree() && !AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) {
|
||||||
activity = blend_tree->get_connection_activity(E->get().input_node, E->get().input_index);
|
activity = AnimationTreeEditor::get_singleton()->get_tree()->get_connection_activity(path, E->get().input_index);
|
||||||
}
|
}
|
||||||
graph->set_connection_activity(E->get().output_node, 0, E->get().input_node, E->get().input_index, activity);
|
graph->set_connection_activity(E->get().output_node, 0, E->get().input_node, E->get().input_index, activity);
|
||||||
}
|
}
|
||||||
|
@ -777,6 +778,30 @@ void AnimationNodeBlendTreeEditor::_node_renamed(const String &p_text, Ref<Anima
|
||||||
visible_properties[i]->set_object_and_property(visible_properties[i]->get_edited_object(), new_name);
|
visible_properties[i]->set_object_and_property(visible_properties[i]->get_edited_object(), new_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//recreate connections
|
||||||
|
graph->clear_connections();
|
||||||
|
|
||||||
|
List<AnimationNodeBlendTree::NodeConnection> connections;
|
||||||
|
blend_tree->get_node_connections(&connections);
|
||||||
|
|
||||||
|
for (List<AnimationNodeBlendTree::NodeConnection>::Element *E = connections.front(); E; E = E->next()) {
|
||||||
|
|
||||||
|
StringName from = E->get().output_node;
|
||||||
|
StringName to = E->get().input_node;
|
||||||
|
int to_idx = E->get().input_index;
|
||||||
|
|
||||||
|
graph->connect_node(from, 0, to, to_idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
//update animations
|
||||||
|
for (Map<StringName, ProgressBar *>::Element *E = animations.front(); E; E = E->next()) {
|
||||||
|
if (E->key() == prev_name) {
|
||||||
|
animations[new_name] = animations[prev_name];
|
||||||
|
animations.erase(prev_name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnimationNodeBlendTreeEditor::_node_renamed_focus_out(Node *le, Ref<AnimationNode> p_node) {
|
void AnimationNodeBlendTreeEditor::_node_renamed_focus_out(Node *le, Ref<AnimationNode> p_node) {
|
||||||
|
|
|
@ -987,17 +987,6 @@ void AnimationNodeBlendTree::disconnect_node(const StringName &p_node, int p_inp
|
||||||
nodes[p_node].connections.write[p_input_index] = StringName();
|
nodes[p_node].connections.write[p_input_index] = StringName();
|
||||||
}
|
}
|
||||||
|
|
||||||
float AnimationNodeBlendTree::get_connection_activity(const StringName &p_input_node, int p_input_index) const {
|
|
||||||
|
|
||||||
ERR_FAIL_COND_V(!nodes.has(p_input_node), 0);
|
|
||||||
|
|
||||||
Ref<AnimationNode> input = nodes[p_input_node].node;
|
|
||||||
ERR_FAIL_INDEX_V(p_input_index, nodes[p_input_node].connections.size(), 0);
|
|
||||||
|
|
||||||
//return input->get_input_activity(p_input_index);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
AnimationNodeBlendTree::ConnectionError AnimationNodeBlendTree::can_connect_node(const StringName &p_input_node, int p_input_index, const StringName &p_output_node) const {
|
AnimationNodeBlendTree::ConnectionError AnimationNodeBlendTree::can_connect_node(const StringName &p_input_node, int p_input_index, const StringName &p_output_node) const {
|
||||||
|
|
||||||
if (!nodes.has(p_output_node) || p_output_node == SceneStringNames::get_singleton()->output) {
|
if (!nodes.has(p_output_node) || p_output_node == SceneStringNames::get_singleton()->output) {
|
||||||
|
|
|
@ -349,7 +349,6 @@ public:
|
||||||
|
|
||||||
void connect_node(const StringName &p_input_node, int p_input_index, const StringName &p_output_node);
|
void connect_node(const StringName &p_input_node, int p_input_index, const StringName &p_output_node);
|
||||||
void disconnect_node(const StringName &p_node, int p_input_index);
|
void disconnect_node(const StringName &p_node, int p_input_index);
|
||||||
float get_connection_activity(const StringName &p_input_node, int p_input_index) const;
|
|
||||||
|
|
||||||
struct NodeConnection {
|
struct NodeConnection {
|
||||||
StringName input_node;
|
StringName input_node;
|
||||||
|
|
|
@ -109,8 +109,16 @@ float AnimationNode::blend_input(int p_input, float p_time, bool p_seek, float p
|
||||||
Ref<AnimationNode> node = blend_tree->get_node(node_name);
|
Ref<AnimationNode> node = blend_tree->get_node(node_name);
|
||||||
|
|
||||||
//inputs.write[p_input].last_pass = state->last_pass;
|
//inputs.write[p_input].last_pass = state->last_pass;
|
||||||
float activity;
|
float activity=0;
|
||||||
return _blend_node(node_name, blend_tree->get_node_connection_array(node_name), NULL, node, p_time, p_seek, p_blend, p_filter, p_optimize, &activity);
|
float ret = _blend_node(node_name, blend_tree->get_node_connection_array(node_name), NULL, node, p_time, p_seek, p_blend, p_filter, p_optimize, &activity);
|
||||||
|
|
||||||
|
Vector<AnimationTree::Activity> *activity_ptr = state->tree->input_activity_map.getptr(base_path);
|
||||||
|
|
||||||
|
if (activity_ptr && p_input<activity_ptr->size()) {
|
||||||
|
activity_ptr->write[p_input].last_pass = state->last_pass;
|
||||||
|
activity_ptr->write[p_input].activity = activity;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
float AnimationNode::blend_node(const StringName &p_sub_path, Ref<AnimationNode> p_node, float p_time, bool p_seek, float p_blend, FilterAction p_filter, bool p_optimize) {
|
float AnimationNode::blend_node(const StringName &p_sub_path, Ref<AnimationNode> p_node, float p_time, bool p_seek, float p_blend, FilterAction p_filter, bool p_optimize) {
|
||||||
|
@ -1285,6 +1293,18 @@ void AnimationTree::_update_properties_for_node(const String &p_base_path, Ref<A
|
||||||
property_parent_map[p_base_path] = HashMap<StringName, StringName>();
|
property_parent_map[p_base_path] = HashMap<StringName, StringName>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node->get_input_count() && !input_activity_map.has(p_base_path)) {
|
||||||
|
|
||||||
|
Vector<Activity> activity;
|
||||||
|
for(int i=0;i<node->get_input_count();i++) {
|
||||||
|
Activity a;
|
||||||
|
a.last_pass=0;
|
||||||
|
activity.push_back(a);
|
||||||
|
}
|
||||||
|
input_activity_map[p_base_path] = activity;
|
||||||
|
input_activity_map_get[String(p_base_path).substr(0,String(p_base_path).length()-1)]=&input_activity_map[p_base_path];
|
||||||
|
}
|
||||||
|
|
||||||
List<PropertyInfo> plist;
|
List<PropertyInfo> plist;
|
||||||
node->get_parameter_list(&plist);
|
node->get_parameter_list(&plist);
|
||||||
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
|
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
|
||||||
|
@ -1317,6 +1337,8 @@ void AnimationTree::_update_properties() {
|
||||||
|
|
||||||
properties.clear();
|
properties.clear();
|
||||||
property_parent_map.clear();
|
property_parent_map.clear();
|
||||||
|
input_activity_map.clear();
|
||||||
|
input_activity_map_get.clear();
|
||||||
|
|
||||||
if (root.is_valid()) {
|
if (root.is_valid()) {
|
||||||
_update_properties_for_node(SceneStringNames::get_singleton()->parameters_base_path, root);
|
_update_properties_for_node(SceneStringNames::get_singleton()->parameters_base_path, root);
|
||||||
|
@ -1380,6 +1402,25 @@ void AnimationTree::rename_parameter(const String &p_base, const String &p_new_b
|
||||||
_update_properties();
|
_update_properties();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float AnimationTree::get_connection_activity(const StringName& p_path,int p_connection) const {
|
||||||
|
|
||||||
|
if (!input_activity_map_get.has(p_path)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
const Vector<Activity> *activity = input_activity_map_get[p_path];
|
||||||
|
|
||||||
|
if (!activity || p_connection<0 || p_connection>=activity->size()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((*activity)[p_connection].last_pass != process_pass) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (*activity)[p_connection].activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void AnimationTree::_bind_methods() {
|
void AnimationTree::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("set_active", "active"), &AnimationTree::set_active);
|
ClassDB::bind_method(D_METHOD("set_active", "active"), &AnimationTree::set_active);
|
||||||
ClassDB::bind_method(D_METHOD("is_active"), &AnimationTree::is_active);
|
ClassDB::bind_method(D_METHOD("is_active"), &AnimationTree::is_active);
|
||||||
|
|
|
@ -55,7 +55,7 @@ public:
|
||||||
|
|
||||||
Vector<float> blends;
|
Vector<float> blends;
|
||||||
State *state;
|
State *state;
|
||||||
String path;
|
|
||||||
float _pre_process(const StringName &p_base_path, AnimationNode *p_parent, State *p_state, float p_time, bool p_seek, const Vector<StringName> &p_connections);
|
float _pre_process(const StringName &p_base_path, AnimationNode *p_parent, State *p_state, float p_time, bool p_seek, const Vector<StringName> &p_connections);
|
||||||
void _pre_update_animations(HashMap<NodePath, int> *track_map);
|
void _pre_update_animations(HashMap<NodePath, int> *track_map);
|
||||||
|
|
||||||
|
@ -256,6 +256,14 @@ private:
|
||||||
HashMap<StringName, HashMap<StringName, StringName> > property_parent_map;
|
HashMap<StringName, HashMap<StringName, StringName> > property_parent_map;
|
||||||
HashMap<StringName, Variant> property_map;
|
HashMap<StringName, Variant> property_map;
|
||||||
|
|
||||||
|
struct Activity {
|
||||||
|
uint64_t last_pass;
|
||||||
|
float activity;
|
||||||
|
};
|
||||||
|
|
||||||
|
HashMap<StringName, Vector<Activity> > input_activity_map;
|
||||||
|
HashMap<StringName, Vector<Activity> *> input_activity_map_get;
|
||||||
|
|
||||||
void _update_properties_for_node(const String &p_base_path, Ref<AnimationNode> node);
|
void _update_properties_for_node(const String &p_base_path, Ref<AnimationNode> node);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -289,6 +297,7 @@ public:
|
||||||
|
|
||||||
Transform get_root_motion_transform() const;
|
Transform get_root_motion_transform() const;
|
||||||
|
|
||||||
|
float get_connection_activity(const StringName &p_path, int p_connection) const;
|
||||||
void advance(float p_time);
|
void advance(float p_time);
|
||||||
|
|
||||||
void rename_parameter(const String &p_base, const String &p_new_base);
|
void rename_parameter(const String &p_base, const String &p_new_base);
|
||||||
|
|
Loading…
Reference in a new issue