diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index 42e32b97883..9530fae8e41 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -650,8 +650,9 @@ void AnimationNodeBlendTreeEditor::_notification(int p_what) { blend_tree->get_node_connections(&conns); for (List::Element *E = conns.front(); E; E = E->next()) { 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()) { - 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); } @@ -777,6 +778,30 @@ void AnimationNodeBlendTreeEditor::_node_renamed(const String &p_text, Refset_object_and_property(visible_properties[i]->get_edited_object(), new_name); } } + + //recreate connections + graph->clear_connections(); + + List connections; + blend_tree->get_node_connections(&connections); + + for (List::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::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 p_node) { diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp index 66a9c5babda..10bab3ce38d 100644 --- a/scene/animation/animation_blend_tree.cpp +++ b/scene/animation/animation_blend_tree.cpp @@ -987,17 +987,6 @@ void AnimationNodeBlendTree::disconnect_node(const StringName &p_node, int p_inp 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 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 { if (!nodes.has(p_output_node) || p_output_node == SceneStringNames::get_singleton()->output) { diff --git a/scene/animation/animation_blend_tree.h b/scene/animation/animation_blend_tree.h index 37bd45c74a5..7bf2917c1ef 100644 --- a/scene/animation/animation_blend_tree.h +++ b/scene/animation/animation_blend_tree.h @@ -349,7 +349,6 @@ public: 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); - float get_connection_activity(const StringName &p_input_node, int p_input_index) const; struct NodeConnection { StringName input_node; diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index 1513010a8a5..76f0ee9359c 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -109,8 +109,16 @@ float AnimationNode::blend_input(int p_input, float p_time, bool p_seek, float p Ref node = blend_tree->get_node(node_name); //inputs.write[p_input].last_pass = state->last_pass; - float activity; - 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 activity=0; + 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 *activity_ptr = state->tree->input_activity_map.getptr(base_path); + + if (activity_ptr && p_inputsize()) { + 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 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(); } + if (node->get_input_count() && !input_activity_map.has(p_base_path)) { + + Vector activity; + for(int i=0;iget_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 plist; node->get_parameter_list(&plist); for (List::Element *E = plist.front(); E; E = E->next()) { @@ -1317,6 +1337,8 @@ void AnimationTree::_update_properties() { properties.clear(); property_parent_map.clear(); + input_activity_map.clear(); + input_activity_map_get.clear(); if (root.is_valid()) { _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(); } +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 = 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() { ClassDB::bind_method(D_METHOD("set_active", "active"), &AnimationTree::set_active); ClassDB::bind_method(D_METHOD("is_active"), &AnimationTree::is_active); diff --git a/scene/animation/animation_tree.h b/scene/animation/animation_tree.h index 3c615b2f92d..70f3932f21b 100644 --- a/scene/animation/animation_tree.h +++ b/scene/animation/animation_tree.h @@ -55,7 +55,7 @@ public: Vector blends; 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 &p_connections); void _pre_update_animations(HashMap *track_map); @@ -256,6 +256,14 @@ private: HashMap > property_parent_map; HashMap property_map; + struct Activity { + uint64_t last_pass; + float activity; + }; + + HashMap > input_activity_map; + HashMap *> input_activity_map_get; + void _update_properties_for_node(const String &p_base_path, Ref node); protected: @@ -289,6 +297,7 @@ public: Transform get_root_motion_transform() const; + float get_connection_activity(const StringName &p_path, int p_connection) const; void advance(float p_time); void rename_parameter(const String &p_base, const String &p_new_base);