diff --git a/synced_animation_graph.cpp b/blendalot_animation_graph.cpp similarity index 66% rename from synced_animation_graph.cpp rename to blendalot_animation_graph.cpp index c4fe5df..7ca1a81 100644 --- a/synced_animation_graph.cpp +++ b/blendalot_animation_graph.cpp @@ -1,37 +1,37 @@ -#include "synced_animation_graph.h" +#include "blendalot_animation_graph.h" #include "core/os/time.h" #include "core/profiling/profiling.h" #include "scene/3d/skeleton_3d.h" #include "scene/animation/animation_player.h" -void SyncedAnimationGraph::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_active", "active"), &SyncedAnimationGraph::set_active); - ClassDB::bind_method(D_METHOD("is_active"), &SyncedAnimationGraph::is_active); +void BLTAnimationGraph::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_active", "active"), &BLTAnimationGraph::set_active); + ClassDB::bind_method(D_METHOD("is_active"), &BLTAnimationGraph::is_active); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "active"), "set_active", "is_active"); - ClassDB::bind_method(D_METHOD("set_callback_mode_process", "mode"), &SyncedAnimationGraph::set_callback_mode_process); - ClassDB::bind_method(D_METHOD("get_callback_mode_process"), &SyncedAnimationGraph::get_callback_mode_process); + ClassDB::bind_method(D_METHOD("set_callback_mode_process", "mode"), &BLTAnimationGraph::set_callback_mode_process); + ClassDB::bind_method(D_METHOD("get_callback_mode_process"), &BLTAnimationGraph::get_callback_mode_process); - ClassDB::bind_method(D_METHOD("set_callback_mode_method", "mode"), &SyncedAnimationGraph::set_callback_mode_method); - ClassDB::bind_method(D_METHOD("get_callback_mode_method"), &SyncedAnimationGraph::get_callback_mode_method); + ClassDB::bind_method(D_METHOD("set_callback_mode_method", "mode"), &BLTAnimationGraph::set_callback_mode_method); + ClassDB::bind_method(D_METHOD("get_callback_mode_method"), &BLTAnimationGraph::get_callback_mode_method); - ClassDB::bind_method(D_METHOD("set_animation_player", "animation_player"), &SyncedAnimationGraph::set_animation_player); - ClassDB::bind_method(D_METHOD("get_animation_player"), &SyncedAnimationGraph::get_animation_player); + ClassDB::bind_method(D_METHOD("set_animation_player", "animation_player"), &BLTAnimationGraph::set_animation_player); + ClassDB::bind_method(D_METHOD("get_animation_player"), &BLTAnimationGraph::get_animation_player); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "animation_player", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "AnimationPlayer"), "set_animation_player", "get_animation_player"); ADD_SIGNAL(MethodInfo(SNAME("animation_player_changed"))); - ClassDB::bind_method(D_METHOD("set_tree_root", "animation_node"), &SyncedAnimationGraph::set_root_animation_node); - ClassDB::bind_method(D_METHOD("get_tree_root"), &SyncedAnimationGraph::get_root_animation_node); + ClassDB::bind_method(D_METHOD("set_tree_root", "animation_node"), &BLTAnimationGraph::set_root_animation_node); + ClassDB::bind_method(D_METHOD("get_tree_root"), &BLTAnimationGraph::get_root_animation_node); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "tree_root", PROPERTY_HINT_RESOURCE_TYPE, "SyncedAnimationNode"), "set_tree_root", "get_tree_root"); - ClassDB::bind_method(D_METHOD("set_skeleton", "skeleton"), &SyncedAnimationGraph::set_skeleton); - ClassDB::bind_method(D_METHOD("get_skeleton"), &SyncedAnimationGraph::get_skeleton); + ClassDB::bind_method(D_METHOD("set_skeleton", "skeleton"), &BLTAnimationGraph::set_skeleton); + ClassDB::bind_method(D_METHOD("get_skeleton"), &BLTAnimationGraph::get_skeleton); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "skeleton", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Skeleton3D"), "set_skeleton", "get_skeleton"); ADD_SIGNAL(MethodInfo(SNAME("skeleton_changed"))); } -void SyncedAnimationGraph::_update_properties_for_node(const String &p_base_path, Ref p_node) const { +void BLTAnimationGraph::_update_properties_for_node(const String &p_base_path, Ref p_node) const { ERR_FAIL_COND(p_node.is_null()); List plist; @@ -40,22 +40,22 @@ void SyncedAnimationGraph::_update_properties_for_node(const String &p_base_path StringName key = pinfo.name; if (!parameter_to_node_parameter_map.has(p_base_path + key)) { - parameter_to_node_parameter_map[p_base_path + key] = Pair, StringName>(p_node, key); + parameter_to_node_parameter_map[p_base_path + key] = Pair, StringName>(p_node, key); } pinfo.name = p_base_path + key; properties.push_back(pinfo); } - List> children; + List> children; p_node->get_child_nodes(&children); - for (const Ref &child_node : children) { + for (const Ref &child_node : children) { _update_properties_for_node(p_base_path + child_node->name + "/", child_node); } } -void SyncedAnimationGraph::_update_properties() const { +void BLTAnimationGraph::_update_properties() const { if (!properties_dirty) { return; } @@ -69,10 +69,10 @@ void SyncedAnimationGraph::_update_properties() const { properties_dirty = false; - const_cast(this)->notify_property_list_changed(); + const_cast(this)->notify_property_list_changed(); } -bool SyncedAnimationGraph::_set(const StringName &p_name, const Variant &p_value) { +bool BLTAnimationGraph::_set(const StringName &p_name, const Variant &p_value) { #ifndef DISABLE_DEPRECATED String name = p_name; if (name == "process_callback") { @@ -85,7 +85,7 @@ bool SyncedAnimationGraph::_set(const StringName &p_name, const Variant &p_value } if (parameter_to_node_parameter_map.has(p_name)) { - const Pair, StringName> &property_node = parameter_to_node_parameter_map[p_name]; + const Pair, StringName> &property_node = parameter_to_node_parameter_map[p_name]; if (!property_node.first.is_valid()) { print_error(vformat("Cannot set property '%s' node not found.", p_name)); return false; @@ -98,7 +98,7 @@ bool SyncedAnimationGraph::_set(const StringName &p_name, const Variant &p_value return false; } -bool SyncedAnimationGraph::_get(const StringName &p_name, Variant &r_ret) const { +bool BLTAnimationGraph::_get(const StringName &p_name, Variant &r_ret) const { #ifndef DISABLE_DEPRECATED if (p_name == "process_callback") { r_ret = get_callback_mode_process(); @@ -110,7 +110,7 @@ bool SyncedAnimationGraph::_get(const StringName &p_name, Variant &r_ret) const } if (parameter_to_node_parameter_map.has(p_name)) { - const Pair, StringName> &property_node = parameter_to_node_parameter_map[p_name]; + const Pair, StringName> &property_node = parameter_to_node_parameter_map[p_name]; if (!property_node.first.is_valid()) { print_error(vformat("Cannot get property '%s' node not found.", p_name)); return false; @@ -122,7 +122,7 @@ bool SyncedAnimationGraph::_get(const StringName &p_name, Variant &r_ret) const return false; } -void SyncedAnimationGraph::_get_property_list(List *p_list) const { +void BLTAnimationGraph::_get_property_list(List *p_list) const { if (properties_dirty) { _update_properties(); } @@ -132,16 +132,16 @@ void SyncedAnimationGraph::_get_property_list(List *p_list) const } } -void SyncedAnimationGraph::_tree_changed() { +void BLTAnimationGraph::_tree_changed() { if (properties_dirty) { return; } - callable_mp(this, &SyncedAnimationGraph::_update_properties).call_deferred(); + callable_mp(this, &BLTAnimationGraph::_update_properties).call_deferred(); properties_dirty = true; } -void SyncedAnimationGraph::_notification(int p_what) { +void BLTAnimationGraph::_notification(int p_what) { GodotProfileZone("SyncedAnimationGraph::_notification"); switch (p_what) { @@ -177,7 +177,7 @@ void SyncedAnimationGraph::_notification(int p_what) { } } -void SyncedAnimationGraph::set_active(bool p_active) { +void BLTAnimationGraph::set_active(bool p_active) { if (active == p_active) { return; } @@ -186,11 +186,11 @@ void SyncedAnimationGraph::set_active(bool p_active) { _set_process(processing, true); } -bool SyncedAnimationGraph::is_active() const { +bool BLTAnimationGraph::is_active() const { return active; } -void SyncedAnimationGraph::set_callback_mode_process(AnimationMixer::AnimationCallbackModeProcess p_mode) { +void BLTAnimationGraph::set_callback_mode_process(AnimationMixer::AnimationCallbackModeProcess p_mode) { if (callback_mode_process == p_mode) { return; } @@ -207,29 +207,29 @@ void SyncedAnimationGraph::set_callback_mode_process(AnimationMixer::AnimationCa } } -AnimationMixer::AnimationCallbackModeProcess SyncedAnimationGraph::get_callback_mode_process() const { +AnimationMixer::AnimationCallbackModeProcess BLTAnimationGraph::get_callback_mode_process() const { return callback_mode_process; } -void SyncedAnimationGraph::set_callback_mode_method(AnimationMixer::AnimationCallbackModeMethod p_mode) { +void BLTAnimationGraph::set_callback_mode_method(AnimationMixer::AnimationCallbackModeMethod p_mode) { callback_mode_method = p_mode; emit_signal(SNAME("mixer_updated")); } -AnimationMixer::AnimationCallbackModeMethod SyncedAnimationGraph::get_callback_mode_method() const { +AnimationMixer::AnimationCallbackModeMethod BLTAnimationGraph::get_callback_mode_method() const { return callback_mode_method; } -void SyncedAnimationGraph::set_callback_mode_discrete(AnimationMixer::AnimationCallbackModeDiscrete p_mode) { +void BLTAnimationGraph::set_callback_mode_discrete(AnimationMixer::AnimationCallbackModeDiscrete p_mode) { callback_mode_discrete = p_mode; emit_signal(SNAME("mixer_updated")); } -AnimationMixer::AnimationCallbackModeDiscrete SyncedAnimationGraph::get_callback_mode_discrete() const { +AnimationMixer::AnimationCallbackModeDiscrete BLTAnimationGraph::get_callback_mode_discrete() const { return callback_mode_discrete; } -void SyncedAnimationGraph::set_animation_player(const NodePath &p_path) { +void BLTAnimationGraph::set_animation_player(const NodePath &p_path) { animation_player_path = p_path; if (p_path.is_empty()) { // set_root_node(SceneStringName(path_pp)); @@ -245,20 +245,20 @@ void SyncedAnimationGraph::set_animation_player(const NodePath &p_path) { emit_signal(SNAME("animation_player_changed")); // Needs to unpin AnimationPlayerEditor. } -NodePath SyncedAnimationGraph::get_animation_player() const { +NodePath BLTAnimationGraph::get_animation_player() const { return animation_player_path; } -void SyncedAnimationGraph::set_root_animation_node(const Ref &p_animation_node) { +void BLTAnimationGraph::set_root_animation_node(const Ref &p_animation_node) { if (root_animation_node.is_valid()) { - root_animation_node->disconnect(SNAME("tree_changed"), callable_mp(this, &SyncedAnimationGraph::_tree_changed)); + root_animation_node->disconnect(SNAME("tree_changed"), callable_mp(this, &BLTAnimationGraph::_tree_changed)); } root_animation_node = p_animation_node; if (root_animation_node.is_valid()) { _setup_graph(); - root_animation_node->connect(SNAME("tree_changed"), callable_mp(this, &SyncedAnimationGraph::_tree_changed)); + root_animation_node->connect(SNAME("tree_changed"), callable_mp(this, &BLTAnimationGraph::_tree_changed)); } properties_dirty = true; @@ -266,11 +266,11 @@ void SyncedAnimationGraph::set_root_animation_node(const Ref SyncedAnimationGraph::get_root_animation_node() const { +Ref BLTAnimationGraph::get_root_animation_node() const { return root_animation_node; } -void SyncedAnimationGraph::set_skeleton(const NodePath &p_path) { +void BLTAnimationGraph::set_skeleton(const NodePath &p_path) { skeleton_path = p_path; if (p_path.is_empty()) { // set_root_node(SceneStringName(path_pp)); @@ -286,11 +286,11 @@ void SyncedAnimationGraph::set_skeleton(const NodePath &p_path) { emit_signal(SNAME("skeleton_changed")); // Needs to unpin AnimationPlayerEditor. } -NodePath SyncedAnimationGraph::get_skeleton() const { +NodePath BLTAnimationGraph::get_skeleton() const { return skeleton_path; } -void SyncedAnimationGraph::_process_graph(double p_delta, bool p_update_only) { +void BLTAnimationGraph::_process_graph(double p_delta, bool p_update_only) { if (!root_animation_node.is_valid()) { return; } @@ -300,8 +300,8 @@ void SyncedAnimationGraph::_process_graph(double p_delta, bool p_update_only) { _update_properties(); AnimationData *graph_output = graph_context.animation_data_allocator.allocate(); - root_animation_node->activate_inputs(Vector>()); - root_animation_node->calculate_sync_track(Vector>()); + root_animation_node->activate_inputs(Vector>()); + root_animation_node->calculate_sync_track(Vector>()); root_animation_node->update_time(p_delta); root_animation_node->evaluate(graph_context, LocalVector(), *graph_output); @@ -310,7 +310,7 @@ void SyncedAnimationGraph::_process_graph(double p_delta, bool p_update_only) { graph_context.animation_data_allocator.free(graph_output); } -void SyncedAnimationGraph::_apply_animation_data(const AnimationData &output_data) const { +void BLTAnimationGraph::_apply_animation_data(const AnimationData &output_data) const { GodotProfileZone("SyncedAnimationGraph::_apply_animation_data"); for (const KeyValue &K : output_data.value_buffer_offset) { @@ -342,7 +342,7 @@ void SyncedAnimationGraph::_apply_animation_data(const AnimationData &output_dat } } -void SyncedAnimationGraph::_set_process(bool p_process, bool p_force) { +void BLTAnimationGraph::_set_process(bool p_process, bool p_force) { if (processing == p_process && !p_force) { return; } @@ -353,19 +353,19 @@ void SyncedAnimationGraph::_set_process(bool p_process, bool p_force) { processing = p_process; } -void SyncedAnimationGraph::_setup_evaluation_context() { +void BLTAnimationGraph::_setup_evaluation_context() { _cleanup_evaluation_context(); graph_context.animation_player = Object::cast_to(get_node_or_null(animation_player_path)); graph_context.skeleton_3d = Object::cast_to(get_node_or_null(skeleton_path)); } -void SyncedAnimationGraph::_cleanup_evaluation_context() { +void BLTAnimationGraph::_cleanup_evaluation_context() { graph_context.animation_player = nullptr; graph_context.skeleton_3d = nullptr; } -void SyncedAnimationGraph::_setup_graph() { +void BLTAnimationGraph::_setup_graph() { if (graph_context.animation_player == nullptr || graph_context.skeleton_3d == nullptr || !root_animation_node.is_valid()) { return; } @@ -373,5 +373,5 @@ void SyncedAnimationGraph::_setup_graph() { root_animation_node->initialize(graph_context); } -SyncedAnimationGraph::SyncedAnimationGraph() { +BLTAnimationGraph::BLTAnimationGraph() { } diff --git a/synced_animation_graph.h b/blendalot_animation_graph.h similarity index 82% rename from synced_animation_graph.h rename to blendalot_animation_graph.h index 091f9bd..a532997 100644 --- a/synced_animation_graph.h +++ b/blendalot_animation_graph.h @@ -1,27 +1,27 @@ #pragma once +#include "blendalot_animation_node.h" #include "scene/animation/animation_player.h" -#include "synced_animation_node.h" class Skeleton3D; -class SyncedAnimationGraph : public Node { - GDCLASS(SyncedAnimationGraph, Node); +class BLTAnimationGraph : public Node { + GDCLASS(BLTAnimationGraph, Node); private: NodePath animation_player_path; - Ref root_animation_node; + Ref root_animation_node; NodePath skeleton_path; GraphEvaluationContext graph_context = {}; mutable List properties; - mutable AHashMap, StringName>> parameter_to_node_parameter_map; + mutable AHashMap, StringName>> parameter_to_node_parameter_map; mutable bool properties_dirty = true; void _update_properties() const; - void _update_properties_for_node(const String &p_base_path, Ref p_node) const; + void _update_properties_for_node(const String &p_base_path, Ref p_node) const; void _tree_changed(); @@ -51,8 +51,8 @@ public: void set_animation_player(const NodePath &p_path); NodePath get_animation_player() const; - void set_root_animation_node(const Ref &p_animation_node); - Ref get_root_animation_node() const; + void set_root_animation_node(const Ref &p_animation_node); + Ref get_root_animation_node() const; void set_skeleton(const NodePath &p_path); NodePath get_skeleton() const; @@ -70,7 +70,7 @@ public: return graph_context; } - SyncedAnimationGraph(); + BLTAnimationGraph(); private: void _set_process(bool p_process, bool p_force = false); diff --git a/synced_animation_node.cpp b/blendalot_animation_node.cpp similarity index 75% rename from synced_animation_node.cpp rename to blendalot_animation_node.cpp index b74929c..285ee1c 100644 --- a/synced_animation_node.cpp +++ b/blendalot_animation_node.cpp @@ -2,46 +2,49 @@ // Created by martin on 03.12.25. // -#include "synced_animation_node.h" +#include "blendalot_animation_node.h" -void SyncedAnimationNode::_bind_methods() { +void BLTAnimationNode::_bind_methods() { ADD_SIGNAL(MethodInfo("tree_changed")); ADD_SIGNAL(MethodInfo("animation_node_renamed", PropertyInfo(Variant::INT, "object_id"), PropertyInfo(Variant::STRING, "old_name"), PropertyInfo(Variant::STRING, "new_name"))); ADD_SIGNAL(MethodInfo("animation_node_removed", PropertyInfo(Variant::INT, "object_id"), PropertyInfo(Variant::STRING, "name"))); } -void SyncedAnimationNode::get_parameter_list(List *r_list) const { +void BLTAnimationNode::get_parameter_list(List *r_list) const { } -Variant SyncedAnimationNode::get_parameter_default_value(const StringName &p_parameter) const { +Variant BLTAnimationNode::get_parameter_default_value(const StringName &p_parameter) const { return Variant(); } -bool SyncedAnimationNode::is_parameter_read_only(const StringName &p_parameter) const { +bool BLTAnimationNode::is_parameter_read_only(const StringName &p_parameter) const { return false; } -void SyncedAnimationNode::set_parameter(const StringName &p_name, const Variant &p_value) { +void BLTAnimationNode::set_parameter(const StringName &p_name, const Variant &p_value) { } -Variant SyncedAnimationNode::get_parameter(const StringName &p_name) const { +Variant BLTAnimationNode::get_parameter(const StringName &p_name) const { return Variant(); } -void SyncedAnimationNode::_tree_changed() { +void BLTAnimationNode::_tree_changed() { emit_signal(SNAME("tree_changed")); } -void SyncedAnimationNode::_animation_node_renamed(const ObjectID &p_oid, const String &p_old_name, const String &p_new_name) { +void BLTAnimationNode::_animation_node_renamed(const ObjectID &p_oid, const String &p_old_name, const String &p_new_name) { emit_signal(SNAME("animation_node_renamed"), p_oid, p_old_name, p_new_name); } -void SyncedAnimationNode::_animation_node_removed(const ObjectID &p_oid, const StringName &p_node) { +void BLTAnimationNode::_animation_node_removed(const ObjectID &p_oid, const StringName &p_node) { emit_signal(SNAME("animation_node_removed"), p_oid, p_node); } -void SyncedBlendTree::_get_property_list(List *p_list) const { - for (const Ref &node : tree_graph.nodes) { +void BLTAnimationNodeBlendTree::_bind_methods() { +} + +void BLTAnimationNodeBlendTree::_get_property_list(List *p_list) const { + for (const Ref &node : tree_graph.nodes) { String prop_name = node->name; if (prop_name != "Output") { p_list->push_back(PropertyInfo(Variant::OBJECT, "nodes/" + prop_name + "/node", PROPERTY_HINT_RESOURCE_TYPE, "AnimationNode", PROPERTY_USAGE_NO_EDITOR)); @@ -52,7 +55,7 @@ void SyncedBlendTree::_get_property_list(List *p_list) const { p_list->push_back(PropertyInfo(Variant::ARRAY, "node_connections", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR)); } -bool SyncedBlendTree::_get(const StringName &p_name, Variant &r_value) const { +bool BLTAnimationNodeBlendTree::_get(const StringName &p_name, Variant &r_value) const { String prop_name = p_name; if (prop_name.begins_with("nodes/")) { String node_name = prop_name.get_slicec('/', 1); @@ -77,7 +80,7 @@ bool SyncedBlendTree::_get(const StringName &p_name, Variant &r_value) const { conns.resize(tree_graph.connections.size() * 3); int idx = 0; - for (const BlendTreeConnection &connection : tree_graph.connections) { + for (const BLTBlendTreeConnection &connection : tree_graph.connections) { conns[idx * 3 + 0] = connection.target_node->name; conns[idx * 3 + 1] = connection.target_node->get_input_index(connection.target_port_name); conns[idx * 3 + 2] = connection.source_node->name; @@ -91,14 +94,14 @@ bool SyncedBlendTree::_get(const StringName &p_name, Variant &r_value) const { return false; } -bool SyncedBlendTree::_set(const StringName &p_name, const Variant &p_value) { +bool BLTAnimationNodeBlendTree::_set(const StringName &p_name, const Variant &p_value) { String prop_name = p_name; if (prop_name.begins_with("nodes/")) { String node_name = prop_name.get_slicec('/', 1); String what = prop_name.get_slicec('/', 2); if (what == "node") { - Ref anode = p_value; + Ref anode = p_value; if (anode.is_valid()) { anode->name = node_name; add_node(anode); @@ -122,7 +125,7 @@ bool SyncedBlendTree::_set(const StringName &p_name, const Variant &p_value) { int target_node_port_index = conns[i + 1]; int source_node_index = find_node_index_by_name(conns[i + 2]); - Ref target_node = tree_graph.nodes[target_node_index]; + Ref target_node = tree_graph.nodes[target_node_index]; Vector target_input_names; target_node->get_input_names(target_input_names); @@ -239,8 +242,8 @@ void AnimationDataAllocator::register_track_values(const Ref &animati default_data.allocate_track_values(animation, skeleton_3d); } -bool AnimationSamplerNode::initialize(GraphEvaluationContext &context) { - SyncedAnimationNode::initialize(context); +bool BLTAnimationNodeSampler::initialize(GraphEvaluationContext &context) { + BLTAnimationNode::initialize(context); animation = context.animation_player->get_animation(animation_name); if (!animation.is_valid()) { @@ -271,8 +274,8 @@ bool AnimationSamplerNode::initialize(GraphEvaluationContext &context) { return true; } -void AnimationSamplerNode::update_time(double p_time) { - SyncedAnimationNode::update_time(p_time); +void BLTAnimationNodeSampler::update_time(double p_time) { + BLTAnimationNode::update_time(p_time); if (node_time_info.is_synced) { // Any potential looping has already been performed in the sync-controlling node. @@ -290,7 +293,7 @@ void AnimationSamplerNode::update_time(double p_time) { } } -void AnimationSamplerNode::evaluate(GraphEvaluationContext &context, const LocalVector &inputs, AnimationData &output) { +void BLTAnimationNodeSampler::evaluate(GraphEvaluationContext &context, const LocalVector &inputs, AnimationData &output) { GodotProfileZone("AnimationSamplerNode::evaluate"); assert(inputs.size() == 0); @@ -302,58 +305,58 @@ void AnimationSamplerNode::evaluate(GraphEvaluationContext &context, const Local output.sample_from_animation(animation, context.skeleton_3d, node_time_info.position); } -void AnimationSamplerNode::set_animation(const StringName &p_name) { +void BLTAnimationNodeSampler::set_animation(const StringName &p_name) { animation_name = p_name; } -StringName AnimationSamplerNode::get_animation() const { +StringName BLTAnimationNodeSampler::get_animation() const { return animation_name; } -void AnimationSamplerNode::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_animation", "name"), &AnimationSamplerNode::set_animation); - ClassDB::bind_method(D_METHOD("get_animation"), &AnimationSamplerNode::get_animation); +void BLTAnimationNodeSampler::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_animation", "name"), &BLTAnimationNodeSampler::set_animation); + ClassDB::bind_method(D_METHOD("get_animation"), &BLTAnimationNodeSampler::get_animation); ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "animation"), "set_animation", "get_animation"); } -void AnimationBlend2Node::evaluate(GraphEvaluationContext &context, const LocalVector &inputs, AnimationData &output) { +void BLTAnimationNodeBlend2::evaluate(GraphEvaluationContext &context, const LocalVector &inputs, AnimationData &output) { GodotProfileZone("AnimationBlend2Node::evaluate"); output = std::move(*inputs[0]); output.blend(*inputs[1], blend_weight); } -void AnimationBlend2Node::set_use_sync(bool p_sync) { +void BLTAnimationNodeBlend2::set_use_sync(bool p_sync) { sync = p_sync; } -bool AnimationBlend2Node::is_using_sync() const { +bool BLTAnimationNodeBlend2::is_using_sync() const { return sync; } -void AnimationBlend2Node::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_use_sync", "enable"), &AnimationBlend2Node::set_use_sync); - ClassDB::bind_method(D_METHOD("is_using_sync"), &AnimationBlend2Node::is_using_sync); +void BLTAnimationNodeBlend2::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_use_sync", "enable"), &BLTAnimationNodeBlend2::set_use_sync); + ClassDB::bind_method(D_METHOD("is_using_sync"), &BLTAnimationNodeBlend2::is_using_sync); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sync"), "set_use_sync", "is_using_sync"); } -void AnimationBlend2Node::get_parameter_list(List *p_list) const { +void BLTAnimationNodeBlend2::get_parameter_list(List *p_list) const { p_list->push_back(PropertyInfo(Variant::FLOAT, blend_weight_pname, PROPERTY_HINT_RANGE, "0,1,0.01,or_less,or_greater")); } -void AnimationBlend2Node::set_parameter(const StringName &p_name, const Variant &p_value) { +void BLTAnimationNodeBlend2::set_parameter(const StringName &p_name, const Variant &p_value) { _set(p_name, p_value); } -Variant AnimationBlend2Node::get_parameter(const StringName &p_name) const { +Variant BLTAnimationNodeBlend2::get_parameter(const StringName &p_name) const { Variant result; _get(p_name, result); return result; } -Variant AnimationBlend2Node::get_parameter_default_value(const StringName &p_parameter) const { +Variant BLTAnimationNodeBlend2::get_parameter_default_value(const StringName &p_parameter) const { if (p_parameter == blend_weight_pname) { return blend_weight; } @@ -361,12 +364,12 @@ Variant AnimationBlend2Node::get_parameter_default_value(const StringName &p_par return Variant(); } -void AnimationBlend2Node::_get_property_list(List *p_list) const { +void BLTAnimationNodeBlend2::_get_property_list(List *p_list) const { p_list->push_back(PropertyInfo(Variant::FLOAT, blend_weight_pname, PROPERTY_HINT_RANGE, "0,1,0.01,or_less,or_greater")); p_list->push_back(PropertyInfo(Variant::BOOL, sync_pname)); } -bool AnimationBlend2Node::_get(const StringName &p_name, Variant &r_value) const { +bool BLTAnimationNodeBlend2::_get(const StringName &p_name, Variant &r_value) const { if (p_name == blend_weight_pname) { r_value = blend_weight; return true; @@ -380,7 +383,7 @@ bool AnimationBlend2Node::_get(const StringName &p_name, Variant &r_value) const return false; } -bool AnimationBlend2Node::_set(const StringName &p_name, const Variant &p_value) { +bool BLTAnimationNodeBlend2::_set(const StringName &p_name, const Variant &p_value) { if (p_name == blend_weight_pname) { blend_weight = p_value; return true; diff --git a/synced_animation_node.h b/blendalot_animation_node.h similarity index 86% rename from synced_animation_node.h rename to blendalot_animation_node.h index 02c00bf..3e8af64 100644 --- a/synced_animation_node.h +++ b/blendalot_animation_node.h @@ -227,13 +227,13 @@ struct GraphEvaluationContext { }; /** - * @class SyncedAnimationNode + * @class BLTAnimationNode * Base class for all nodes in an SyncedAnimationGraph including BlendTree nodes and StateMachine states. */ -class SyncedAnimationNode : public Resource { - GDCLASS(SyncedAnimationNode, Resource); +class BLTAnimationNode : public Resource { + GDCLASS(BLTAnimationNode, Resource); - friend class SyncedAnimationGraph; + friend class BLTAnimationGraph; protected: static void _bind_methods(); @@ -265,20 +265,20 @@ public: StringName name; Vector2 position; - virtual ~SyncedAnimationNode() override = default; + virtual ~BLTAnimationNode() override = default; virtual bool initialize(GraphEvaluationContext &context) { node_time_info = {}; return true; } - virtual void activate_inputs(const Vector> &input_nodes) { + virtual void activate_inputs(const Vector> &input_nodes) { // By default, all inputs nodes are activated. - for (const Ref &node : input_nodes) { + for (const Ref &node : input_nodes) { node->active = true; node->node_time_info.is_synced = node_time_info.is_synced; } } - virtual void calculate_sync_track(const Vector> &input_nodes) { + virtual void calculate_sync_track(const Vector> &input_nodes) { // By default, use the SyncTrack of the first input. if (input_nodes.size() > 0) { node_time_info.sync_track = input_nodes[0]->node_time_info.sync_track; @@ -314,11 +314,11 @@ public: } // Creates a list of nodes nested within the current node. E.g. all nodes within a BlendTree node. - virtual void get_child_nodes(List> *r_child_nodes) const {} + virtual void get_child_nodes(List> *r_child_nodes) const {} }; -class AnimationSamplerNode : public SyncedAnimationNode { - GDCLASS(AnimationSamplerNode, SyncedAnimationNode); +class BLTAnimationNodeSampler : public BLTAnimationNode { + GDCLASS(BLTAnimationNodeSampler, BLTAnimationNode); public: StringName animation_name; @@ -337,8 +337,8 @@ protected: static void _bind_methods(); }; -class OutputNode : public SyncedAnimationNode { - GDCLASS(OutputNode, SyncedAnimationNode); +class BLTAnimationNodeOutput : public BLTAnimationNode { + GDCLASS(BLTAnimationNodeOutput, BLTAnimationNode); public: void get_input_names(Vector &inputs) const override { @@ -346,8 +346,8 @@ public: } }; -class AnimationBlend2Node : public SyncedAnimationNode { - GDCLASS(AnimationBlend2Node, SyncedAnimationNode); +class BLTAnimationNodeBlend2 : public BLTAnimationNode { + GDCLASS(BLTAnimationNodeBlend2, BLTAnimationNode); public: float blend_weight = 0.0f; @@ -359,7 +359,7 @@ public: } bool initialize(GraphEvaluationContext &context) override { - bool result = SyncedAnimationNode::initialize(context); + bool result = BLTAnimationNode::initialize(context); if (sync) { // TODO: do we always want looping in this case or do we traverse the graph to check what's reasonable? @@ -368,7 +368,7 @@ public: return result; } - void activate_inputs(const Vector> &input_nodes) override { + void activate_inputs(const Vector> &input_nodes) override { input_nodes[0]->active = true; input_nodes[1]->active = true; @@ -377,7 +377,7 @@ public: input_nodes[1]->node_time_info.is_synced = node_time_info.is_synced || sync; } - void calculate_sync_track(const Vector> &input_nodes) override { + void calculate_sync_track(const Vector> &input_nodes) override { if (node_time_info.is_synced || sync) { assert(input_nodes[0]->node_time_info.loop_mode == input_nodes[1]->node_time_info.loop_mode); node_time_info.sync_track = SyncTrack::blend(blend_weight, input_nodes[0]->node_time_info.sync_track, input_nodes[1]->node_time_info.sync_track); @@ -385,7 +385,7 @@ public: } void update_time(double p_delta) override { - SyncedAnimationNode::update_time(p_delta); + BLTAnimationNode::update_time(p_delta); if (sync && !node_time_info.is_synced) { if (node_time_info.loop_mode != Animation::LOOP_NONE) { @@ -422,17 +422,17 @@ private: StringName sync_pname = PNAME("sync"); }; -struct BlendTreeConnection { - const Ref source_node = nullptr; - const Ref target_node = nullptr; +struct BLTBlendTreeConnection { + const Ref source_node = nullptr; + const Ref target_node = nullptr; const StringName target_port_name = ""; }; /** - * @class BlendTreeGraph + * @class BLTBlendTreeGraph * Helper class that is used to build runtime blend trees and also to validate connections. */ -struct BlendTreeGraph { +struct BLTBlendTreeGraph { struct NodeConnectionInfo { int parent_node_index = -1; HashSet input_subtree_node_indices; // Contains all nodes down to the tree leaves that influence this node. @@ -440,7 +440,7 @@ struct BlendTreeGraph { NodeConnectionInfo() = default; - explicit NodeConnectionInfo(const SyncedAnimationNode *node) { + explicit NodeConnectionInfo(const BLTAnimationNode *node) { parent_node_index = -1; for (int i = 0; i < node->get_input_count(); i++) { connected_child_node_index_at_port.push_back(-1); @@ -477,22 +477,22 @@ struct BlendTreeGraph { } }; - Vector> nodes; // All added nodes + Vector> nodes; // All added nodes LocalVector node_connection_info; - LocalVector connections; + LocalVector connections; - BlendTreeGraph() { - Ref output_node; + BLTBlendTreeGraph() { + Ref output_node; output_node.instantiate(); output_node->name = "Output"; add_node(output_node); } - Ref get_output_node() const { + Ref get_output_node() const { return nodes[0]; } - int find_node_index(const Ref &node) const { + int find_node_index(const Ref &node) const { for (int i = 0; i < nodes.size(); i++) { if (nodes[i] == node) { return i; @@ -512,7 +512,7 @@ struct BlendTreeGraph { return -1; } - void add_node(const Ref &node) { + void add_node(const Ref &node) { StringName node_base_name = node->name; if (node_base_name.is_empty()) { node_base_name = node->get_class_name(); @@ -532,7 +532,7 @@ struct BlendTreeGraph { void sort_nodes_and_references() { LocalVector sorted_node_indices = get_sorted_node_indices(); - Vector> sorted_nodes; + Vector> sorted_nodes; LocalVector old_node_connection_info = node_connection_info; for (unsigned int i = 0; i < sorted_node_indices.size(); i++) { int node_index = sorted_node_indices[i]; @@ -581,7 +581,7 @@ struct BlendTreeGraph { add_index_and_update_subtrees_recursive(node_parent, node_connection_info[node_parent].parent_node_index); } - bool add_connection(const Ref &source_node, const Ref &target_node, const StringName &target_port_name) { + bool add_connection(const Ref &source_node, const Ref &target_node, const StringName &target_port_name) { if (!is_connection_valid(source_node, target_node, target_port_name)) { return false; } @@ -592,14 +592,14 @@ struct BlendTreeGraph { node_connection_info[source_node_index].parent_node_index = target_node_index; node_connection_info[target_node_index].connected_child_node_index_at_port[target_input_port_index] = source_node_index; - connections.push_back(BlendTreeConnection{ source_node, target_node, target_port_name }); + connections.push_back(BLTBlendTreeConnection{ source_node, target_node, target_port_name }); add_index_and_update_subtrees_recursive(source_node_index, target_node_index); return true; } - bool is_connection_valid(const Ref &source_node, const Ref &target_node, StringName target_port_name) { + bool is_connection_valid(const Ref &source_node, const Ref &target_node, StringName target_port_name) { int source_node_index = find_node_index(source_node); if (source_node_index == -1) { print_error("Cannot connect nodes: source node not found."); @@ -640,10 +640,10 @@ struct BlendTreeGraph { } }; -class SyncedBlendTree : public SyncedAnimationNode { - GDCLASS(SyncedBlendTree, SyncedAnimationNode); +class BLTAnimationNodeBlendTree : public BLTAnimationNode { + GDCLASS(BLTAnimationNodeBlendTree, BLTAnimationNode); - BlendTreeGraph tree_graph; + BLTBlendTreeGraph tree_graph; bool tree_initialized = false; void sort_nodes() { @@ -654,7 +654,7 @@ class SyncedBlendTree : public SyncedAnimationNode { void setup_runtime_data() { // Add nodes and allocate runtime data for (int i = 0; i < tree_graph.nodes.size(); i++) { - const Ref node = tree_graph.nodes[i]; + const Ref node = tree_graph.nodes[i]; NodeRuntimeData node_runtime_data; for (int ni = 0; ni < node->get_input_count(); ni++) { @@ -667,7 +667,7 @@ class SyncedBlendTree : public SyncedAnimationNode { // Populate runtime data (only now is this.nodes populated to retrieve the nodes) for (int i = 0; i < tree_graph.nodes.size(); i++) { - Ref node = tree_graph.nodes[i]; + Ref node = tree_graph.nodes[i]; NodeRuntimeData &node_runtime_data = _node_runtime_data[i]; for (int port_index = 0; port_index < node->get_input_count(); port_index++) { @@ -678,23 +678,24 @@ class SyncedBlendTree : public SyncedAnimationNode { } protected: + static void _bind_methods(); void _get_property_list(List *p_list) const; bool _get(const StringName &p_name, Variant &r_value) const; bool _set(const StringName &p_name, const Variant &p_value); public: struct NodeRuntimeData { - Vector> input_nodes; + Vector> input_nodes; LocalVector input_data; AnimationData *output_data = nullptr; }; LocalVector _node_runtime_data; - Ref get_output_node() const { + Ref get_output_node() const { return tree_graph.nodes[0]; } - int find_node_index(const Ref &node) const { + int find_node_index(const Ref &node) const { return tree_graph.find_node_index(node); } @@ -702,7 +703,7 @@ public: return tree_graph.find_node_index_by_name(name); } - Ref get_node(int node_index) { + Ref get_node(int node_index) { if (node_index < 0 || node_index > tree_graph.nodes.size()) { return nullptr; } @@ -710,7 +711,7 @@ public: return tree_graph.nodes[node_index]; } - void add_node(const Ref &node) { + void add_node(const Ref &node) { if (tree_initialized) { print_error("Cannot add node to BlendTree: BlendTree already initialized."); return; @@ -719,7 +720,7 @@ public: tree_graph.add_node(node); } - bool add_connection(const Ref &source_node, const Ref &target_node, const StringName &target_port_name) { + bool add_connection(const Ref &source_node, const Ref &target_node, const StringName &target_port_name) { if (tree_initialized) { print_error("Cannot add connection to BlendTree: BlendTree already initialized."); return false; @@ -733,7 +734,7 @@ public: sort_nodes(); setup_runtime_data(); - for (const Ref &node : tree_graph.nodes) { + for (const Ref &node : tree_graph.nodes) { if (!node->initialize(context)) { return false; } @@ -744,12 +745,12 @@ public: return true; } - void activate_inputs(const Vector> &input_nodes) override { + void activate_inputs(const Vector> &input_nodes) override { GodotProfileZone("SyncedBlendTree::activate_inputs"); tree_graph.nodes[0]->active = true; for (int i = 0; i < tree_graph.nodes.size(); i++) { - const Ref &node = tree_graph.nodes[i]; + const Ref &node = tree_graph.nodes[i]; if (!node->active) { continue; @@ -760,10 +761,10 @@ public: } } - void calculate_sync_track(const Vector> &input_nodes) override { + void calculate_sync_track(const Vector> &input_nodes) override { GodotProfileZone("SyncedBlendTree::calculate_sync_track"); for (int i = tree_graph.nodes.size() - 1; i > 0; i--) { - const Ref &node = tree_graph.nodes[i]; + const Ref &node = tree_graph.nodes[i]; if (!node->active) { continue; @@ -782,13 +783,13 @@ public: tree_graph.nodes[0]->node_time_info.position += p_delta; for (int i = 1; i < tree_graph.nodes.size(); i++) { - const Ref &node = tree_graph.nodes[i]; + const Ref &node = tree_graph.nodes[i]; if (!node->active) { continue; } - const Ref &node_parent = tree_graph.nodes[tree_graph.node_connection_info[i].parent_node_index]; + const Ref &node_parent = tree_graph.nodes[tree_graph.node_connection_info[i].parent_node_index]; if (node->node_time_info.is_synced) { node->update_time(node_parent->node_time_info.sync_position); @@ -802,7 +803,7 @@ public: ZoneScopedN("SyncedBlendTree::evaluate"); for (int i = tree_graph.nodes.size() - 1; i > 0; i--) { - const Ref &node = tree_graph.nodes[i]; + const Ref &node = tree_graph.nodes[i]; if (!node->active) { continue; @@ -832,8 +833,8 @@ public: } } - void get_child_nodes(List> *r_child_nodes) const override { - for (const Ref &node : tree_graph.nodes) { + void get_child_nodes(List> *r_child_nodes) const override { + for (const Ref &node : tree_graph.nodes) { r_child_nodes->push_back(node.ptr()); } } diff --git a/demo/main.gd b/demo/main.gd index cedb685..d4963cc 100644 --- a/demo/main.gd +++ b/demo/main.gd @@ -18,9 +18,9 @@ func _process(delta: float) -> void: func _on_blend_weight_slider_value_changed(value: float) -> void: mixamo_amy_walk_limp.get_node("AnimationTree").set("parameters/Blend2/blend_amount", value) - mixamo_amy_walk_limp_synced.get_node("SyncedAnimationGraph").set("parameters/AnimationBlend2Node/blend_amount", value) + mixamo_amy_walk_limp_synced.get_node("SyncedAnimationGraph").set("parameters/BLTAnimationNodeBlend2/blend_amount", value) mixamo_amy_walk_run.get_node("AnimationTree").set("parameters/Blend2/blend_amount", value) - mixamo_amy_walk_run_synced.get_node("SyncedAnimationGraph").set("parameters/AnimationBlend2Node/blend_amount", value) + mixamo_amy_walk_run_synced.get_node("SyncedAnimationGraph").set("parameters/BLTAnimationNodeBlend2/blend_amount", value) blend_weight_label.text = str(value) diff --git a/demo/main.tscn b/demo/main.tscn index 41901ad..12222c3 100644 --- a/demo/main.tscn +++ b/demo/main.tscn @@ -4,8 +4,8 @@ [ext_resource type="Script" uid="uid://bjvgqujpqumj7" path="res://main.gd" id="1_1bvp3"] [ext_resource type="AnimationLibrary" uid="uid://dwubn740aqx51" path="res://animation_library.res" id="3_1bvp3"] [ext_resource type="AnimationNodeBlendTree" uid="uid://dqy0dgwsm8t46" path="res://animation_tree_walk_limp.tres" id="3_272bh"] -[ext_resource type="SyncedBlendTree" uid="uid://2qfwr1xkiw0s" path="res://synced_blend_tree_walk_limp.tres" id="4_lquwl"] -[ext_resource type="SyncedBlendTree" uid="uid://qsk64ax2o47f" path="res://synced_blend_tree_walk_run.tres" id="5_7mycd"] +[ext_resource type="BLTAnimationNodeBlendTree" uid="uid://2qfwr1xkiw0s" path="res://synced_blend_tree_walk_limp.tres" id="4_lquwl"] +[ext_resource type="BLTAnimationNodeBlendTree" uid="uid://qsk64ax2o47f" path="res://synced_blend_tree_walk_run.tres" id="5_7mycd"] [ext_resource type="AnimationNodeBlendTree" uid="uid://vsf71o82lkld" path="res://animation_tree_walk_run.tres" id="6_5vw27"] [sub_resource type="Theme" id="Theme_272bh"] @@ -32,12 +32,12 @@ sky = SubResource("Sky_1bvp3") tonemap_mode = 2 glow_enabled = true -[node name="Main" type="Node3D"] +[node name="Main" type="Node3D" unique_id=933302313] script = ExtResource("1_1bvp3") -[node name="UI" type="CanvasLayer" parent="."] +[node name="UI" type="CanvasLayer" parent="." unique_id=833570844] -[node name="MarginContainer" type="MarginContainer" parent="UI"] +[node name="MarginContainer" type="MarginContainer" parent="UI" unique_id=2079852348] anchors_preset = 7 anchor_left = 0.5 anchor_top = 1.0 @@ -52,15 +52,15 @@ size_flags_horizontal = 4 size_flags_vertical = 8 theme = SubResource("Theme_272bh") -[node name="HBoxContainer" type="HBoxContainer" parent="UI/MarginContainer"] +[node name="HBoxContainer" type="HBoxContainer" parent="UI/MarginContainer" unique_id=965781454] layout_mode = 2 theme_override_constants/separation = 14 -[node name="Label" type="Label" parent="UI/MarginContainer/HBoxContainer"] +[node name="Label" type="Label" parent="UI/MarginContainer/HBoxContainer" unique_id=634588892] layout_mode = 2 text = "Blend Weight" -[node name="BlendWeightSlider" type="HSlider" parent="UI/MarginContainer/HBoxContainer"] +[node name="BlendWeightSlider" type="HSlider" parent="UI/MarginContainer/HBoxContainer" unique_id=708139207] unique_name_in_owner = true custom_minimum_size = Vector2(200, 0) layout_mode = 2 @@ -68,105 +68,101 @@ size_flags_vertical = 4 max_value = 1.0 step = 0.001 -[node name="BlendWeightLabel" type="Label" parent="UI/MarginContainer/HBoxContainer"] +[node name="BlendWeightLabel" type="Label" parent="UI/MarginContainer/HBoxContainer" unique_id=1745243570] unique_name_in_owner = true custom_minimum_size = Vector2(80, 0) layout_mode = 2 text = "0.0" horizontal_alignment = 2 -[node name="MarginContainer2" type="MarginContainer" parent="UI"] +[node name="MarginContainer2" type="MarginContainer" parent="UI" unique_id=1639984576] anchors_preset = 10 anchor_right = 1.0 offset_bottom = 23.0 grow_horizontal = 2 theme_override_constants/margin_top = 80 -[node name="HBoxContainer2" type="HBoxContainer" parent="UI/MarginContainer2"] +[node name="HBoxContainer2" type="HBoxContainer" parent="UI/MarginContainer2" unique_id=1134641196] layout_mode = 2 size_flags_vertical = 0 theme_override_constants/separation = 400 alignment = 1 -[node name="Label" type="Label" parent="UI/MarginContainer2/HBoxContainer2"] +[node name="Label" type="Label" parent="UI/MarginContainer2/HBoxContainer2" unique_id=1630716301] layout_mode = 2 theme_override_font_sizes/font_size = 32 text = "Unsynced" -[node name="EmptyLabel" type="Label" parent="UI/MarginContainer2/HBoxContainer2"] +[node name="EmptyLabel" type="Label" parent="UI/MarginContainer2/HBoxContainer2" unique_id=991022601] layout_mode = 2 -[node name="Label3" type="Label" parent="UI/MarginContainer2/HBoxContainer2"] +[node name="Label3" type="Label" parent="UI/MarginContainer2/HBoxContainer2" unique_id=736671898] layout_mode = 2 theme_override_font_sizes/font_size = 32 text = "Synced" -[node name="Level" type="Node3D" parent="."] +[node name="Level" type="Node3D" parent="." unique_id=1485026735] -[node name="MeshInstance3D" type="MeshInstance3D" parent="Level"] +[node name="MeshInstance3D" type="MeshInstance3D" parent="Level" unique_id=2025315417] mesh = SubResource("PlaneMesh_h2yge") skeleton = NodePath("../..") -[node name="DirectionalLight3D" type="DirectionalLight3D" parent="Level"] +[node name="DirectionalLight3D" type="DirectionalLight3D" parent="Level" unique_id=468068224] transform = Transform3D(1, 0, 0, 0, 0.14081486, 0.99003595, 0, -0.99003595, 0.14081486, 0, 2.0531263, 4.9494514) shadow_enabled = true -[node name="WorldEnvironment" type="WorldEnvironment" parent="Level"] +[node name="WorldEnvironment" type="WorldEnvironment" parent="Level" unique_id=1787092986] environment = SubResource("Environment_lquwl") -[node name="Camera3D" type="Camera3D" parent="Level"] +[node name="Camera3D" type="Camera3D" parent="Level" unique_id=1534208216] transform = Transform3D(1, 0, 0, 0, 0.95413065, 0.29939055, 0, -0.29939055, 0.95413065, 0, 1.649, 3.197) fov = 36.8 -[node name="Characters" type="Node3D" parent="."] +[node name="Characters" type="Node3D" parent="." unique_id=1282309438] -[node name="MixamoAmyWalkLimp" parent="Characters" instance=ExtResource("1_0xm2m")] +[node name="MixamoAmyWalkLimp" parent="Characters" unique_id=829927137 instance=ExtResource("1_0xm2m")] unique_name_in_owner = true transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.4, 0, 0) -[node name="AnimationTree" type="AnimationTree" parent="Characters/MixamoAmyWalkLimp"] +[node name="AnimationTree" type="AnimationTree" parent="Characters/MixamoAmyWalkLimp" unique_id=1713995200] tree_root = ExtResource("3_272bh") anim_player = NodePath("../AnimationPlayer") parameters/Blend2/blend_amount = 0.0 -[node name="MixamoAmyWalkRun" parent="Characters" instance=ExtResource("1_0xm2m")] +[node name="MixamoAmyWalkRun" parent="Characters" unique_id=1431806836 instance=ExtResource("1_0xm2m")] unique_name_in_owner = true transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.6, 0, 0) -[node name="AnimationTree" type="AnimationTree" parent="Characters/MixamoAmyWalkRun"] +[node name="AnimationTree" type="AnimationTree" parent="Characters/MixamoAmyWalkRun" unique_id=1079690622] tree_root = ExtResource("6_5vw27") anim_player = NodePath("../AnimationPlayer") parameters/Blend2/blend_amount = 0.0 -[node name="MixamoAmyWalkLimpSynced" parent="Characters" instance=ExtResource("1_0xm2m")] +[node name="MixamoAmyWalkLimpSynced" parent="Characters" unique_id=1018815116 instance=ExtResource("1_0xm2m")] unique_name_in_owner = true transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.6, 0, 0) -[node name="AnimationPlayer2" type="AnimationPlayer" parent="Characters/MixamoAmyWalkLimpSynced"] -libraries = { -&"animation_library": ExtResource("3_1bvp3") -} +[node name="AnimationPlayer2" type="AnimationPlayer" parent="Characters/MixamoAmyWalkLimpSynced" unique_id=379737684] +libraries/animation_library = ExtResource("3_1bvp3") -[node name="SyncedAnimationGraph" type="SyncedAnimationGraph" parent="Characters/MixamoAmyWalkLimpSynced"] +[node name="SyncedAnimationGraph" type="BLTAnimationGraph" parent="Characters/MixamoAmyWalkLimpSynced" unique_id=1866796918] animation_player = NodePath("../AnimationPlayer2") tree_root = ExtResource("4_lquwl") skeleton = NodePath("../Armature/Skeleton3D") -parameters/AnimationBlend2Node/blend_amount = 0.0 +parameters/BLTAnimationNodeBlend2/blend_amount = 0.4 -[node name="MixamoAmyWalkRunSynced" parent="Characters" instance=ExtResource("1_0xm2m")] +[node name="MixamoAmyWalkRunSynced" parent="Characters" unique_id=2088190993 instance=ExtResource("1_0xm2m")] unique_name_in_owner = true transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.4, 0, 0) -[node name="AnimationPlayer2" type="AnimationPlayer" parent="Characters/MixamoAmyWalkRunSynced"] -libraries = { -&"animation_library": ExtResource("3_1bvp3") -} +[node name="AnimationPlayer2" type="AnimationPlayer" parent="Characters/MixamoAmyWalkRunSynced" unique_id=1255239074] +libraries/animation_library = ExtResource("3_1bvp3") -[node name="SyncedAnimationGraph" type="SyncedAnimationGraph" parent="Characters/MixamoAmyWalkRunSynced"] +[node name="SyncedAnimationGraph" type="BLTAnimationGraph" parent="Characters/MixamoAmyWalkRunSynced" unique_id=1602406394] animation_player = NodePath("../AnimationPlayer2") tree_root = ExtResource("5_7mycd") skeleton = NodePath("../Armature/Skeleton3D") -parameters/AnimationBlend2Node/blend_amount = 0.0 +parameters/BLTAnimationNodeBlend2/blend_amount = 0.4 [connection signal="value_changed" from="UI/MarginContainer/HBoxContainer/BlendWeightSlider" to="." method="_on_blend_weight_slider_value_changed"] diff --git a/demo/synced_blend_tree_walk_limp.tres b/demo/synced_blend_tree_walk_limp.tres index 674d2a0..fd2c576 100644 --- a/demo/synced_blend_tree_walk_limp.tres +++ b/demo/synced_blend_tree_walk_limp.tres @@ -1,18 +1,19 @@ -[gd_resource type="SyncedBlendTree" load_steps=4 format=3 uid="uid://2qfwr1xkiw0s"] +[gd_resource type="BLTAnimationNodeBlendTree" load_steps=4 format=3 uid="uid://2qfwr1xkiw0s"] -[sub_resource type="AnimationBlend2Node" id="AnimationBlend2Node_bvt3d"] +[sub_resource type="BLTAnimationNodeBlend2" id="BLTAnimationNodeBlend2_bvt3d"] +blend_amount = 0.4 -[sub_resource type="AnimationSamplerNode" id="AnimationSamplerNode_sntl5"] +[sub_resource type="BLTAnimationNodeSampler" id="BLTAnimationNodeSampler_sntl5"] animation = &"animation_library/Limping-InPlace" -[sub_resource type="AnimationSamplerNode" id="AnimationSamplerNode_n4m28"] +[sub_resource type="BLTAnimationNodeSampler" id="BLTAnimationNodeSampler_n4m28"] animation = &"animation_library/Walk-InPlace" [resource] -nodes/AnimationBlend2Node/node = SubResource("AnimationBlend2Node_bvt3d") -nodes/AnimationBlend2Node/position = Vector2(0, 0) -"nodes/AnimationSamplerNode 1/node" = SubResource("AnimationSamplerNode_sntl5") -"nodes/AnimationSamplerNode 1/position" = Vector2(0, 0) -nodes/AnimationSamplerNode/node = SubResource("AnimationSamplerNode_n4m28") -nodes/AnimationSamplerNode/position = Vector2(0, 0) -node_connections = [&"AnimationBlend2Node", 0, &"AnimationSamplerNode", &"AnimationBlend2Node", 1, &"AnimationSamplerNode 1", &"Output", 0, &"AnimationBlend2Node"] +nodes/BLTAnimationNodeBlend2/node = SubResource("BLTAnimationNodeBlend2_bvt3d") +nodes/BLTAnimationNodeBlend2/position = Vector2(0, 0) +"nodes/BLTAnimationNodeSampler 1/node" = SubResource("BLTAnimationNodeSampler_sntl5") +"nodes/BLTAnimationNodeSampler 1/position" = Vector2(0, 0) +nodes/BLTAnimationNodeSampler/node = SubResource("BLTAnimationNodeSampler_n4m28") +nodes/BLTAnimationNodeSampler/position = Vector2(0, 0) +node_connections = [&"BLTAnimationNodeBlend2", 0, &"BLTAnimationNodeSampler", &"BLTAnimationNodeBlend2", 1, &"BLTAnimationNodeSampler 1", &"Output", 0, &"BLTAnimationNodeBlend2"] diff --git a/demo/synced_blend_tree_walk_run.tres b/demo/synced_blend_tree_walk_run.tres index a36bad9..10d6c6e 100644 --- a/demo/synced_blend_tree_walk_run.tres +++ b/demo/synced_blend_tree_walk_run.tres @@ -1,18 +1,19 @@ -[gd_resource type="SyncedBlendTree" load_steps=4 format=3 uid="uid://qsk64ax2o47f"] +[gd_resource type="BLTAnimationNodeBlendTree" load_steps=4 format=3 uid="uid://qsk64ax2o47f"] -[sub_resource type="AnimationBlend2Node" id="AnimationBlend2Node_bvt3d"] +[sub_resource type="BLTAnimationNodeBlend2" id="BLTAnimationNodeBlend2_bvt3d"] +blend_amount = 0.4 -[sub_resource type="AnimationSamplerNode" id="AnimationSamplerNode_sntl5"] +[sub_resource type="BLTAnimationNodeSampler" id="BLTAnimationNodeSampler_sntl5"] animation = &"animation_library/Run-InPlace" -[sub_resource type="AnimationSamplerNode" id="AnimationSamplerNode_n4m28"] +[sub_resource type="BLTAnimationNodeSampler" id="BLTAnimationNodeSampler_n4m28"] animation = &"animation_library/Walk-InPlace" [resource] -nodes/AnimationBlend2Node/node = SubResource("AnimationBlend2Node_bvt3d") -nodes/AnimationBlend2Node/position = Vector2(0, 0) -"nodes/AnimationSamplerNode 1/node" = SubResource("AnimationSamplerNode_sntl5") -"nodes/AnimationSamplerNode 1/position" = Vector2(0, 0) -nodes/AnimationSamplerNode/node = SubResource("AnimationSamplerNode_n4m28") -nodes/AnimationSamplerNode/position = Vector2(0, 0) -node_connections = [&"AnimationBlend2Node", 0, &"AnimationSamplerNode", &"AnimationBlend2Node", 1, &"AnimationSamplerNode 1", &"Output", 0, &"AnimationBlend2Node"] +nodes/BLTAnimationNodeBlend2/node = SubResource("BLTAnimationNodeBlend2_bvt3d") +nodes/BLTAnimationNodeBlend2/position = Vector2(0, 0) +"nodes/BLTAnimationNodeSampler 1/node" = SubResource("BLTAnimationNodeSampler_sntl5") +"nodes/BLTAnimationNodeSampler 1/position" = Vector2(0, 0) +nodes/BLTAnimationNodeSampler/node = SubResource("BLTAnimationNodeSampler_n4m28") +nodes/BLTAnimationNodeSampler/position = Vector2(0, 0) +node_connections = [&"BLTAnimationNodeBlend2", 0, &"BLTAnimationNodeSampler", &"BLTAnimationNodeBlend2", 1, &"BLTAnimationNodeSampler 1", &"Output", 0, &"BLTAnimationNodeBlend2"] diff --git a/register_types.cpp b/register_types.cpp index c70ea4b..a924f42 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -1,17 +1,17 @@ #include "register_types.h" +#include "blendalot_animation_graph.h" #include "core/object/class_db.h" -#include "synced_animation_graph.h" void initialize_blendalot_animgraph_module(ModuleInitializationLevel p_level) { if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) { return; } - ClassDB::register_class(); - ClassDB::register_class(); - ClassDB::register_class(); - ClassDB::register_class(); - ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); } void uninitialize_blendalot_animgraph_module(ModuleInitializationLevel p_level) { diff --git a/tests/test_synced_animation_graph.h b/tests/test_synced_animation_graph.h index 977ae33..8d6e373 100644 --- a/tests/test_synced_animation_graph.h +++ b/tests/test_synced_animation_graph.h @@ -1,6 +1,6 @@ #pragma once -#include "../synced_animation_graph.h" +#include "../blendalot_animation_graph.h" #include "scene/animation/animation_tree.h" #include "scene/main/window.h" @@ -20,9 +20,9 @@ struct SyncedAnimationGraphFixture { Ref animation_library; - SyncedAnimationGraph *synced_animation_graph; + BLTAnimationGraph *synced_animation_graph; SyncedAnimationGraphFixture() { - SyncedAnimationGraph *scene_animation_graph = dynamic_cast(SceneTree::get_singleton()->get_root()->find_child("SyncedAnimationGraphFixtureTestNode", true, false)); + BLTAnimationGraph *scene_animation_graph = dynamic_cast(SceneTree::get_singleton()->get_root()->find_child("SyncedAnimationGraphFixtureTestNode", true, false)); if (scene_animation_graph == nullptr) { setup_test_scene(); @@ -50,7 +50,7 @@ struct SyncedAnimationGraphFixture { SceneTree::get_singleton()->get_root()->add_child(player_node); - synced_animation_graph = memnew(SyncedAnimationGraph); + synced_animation_graph = memnew(BLTAnimationGraph); synced_animation_graph->set_name("SyncedAnimationGraphFixtureTestNode"); SceneTree::get_singleton()->get_root()->add_child(synced_animation_graph); @@ -112,7 +112,7 @@ struct SyncedAnimationGraphFixture { } void assign_scene_variables() { - synced_animation_graph = dynamic_cast(SceneTree::get_singleton()->get_root()->find_child("SyncedAnimationGraphFixtureTestNode", true, false)); + synced_animation_graph = dynamic_cast(SceneTree::get_singleton()->get_root()->find_child("SyncedAnimationGraphFixtureTestNode", true, false)); REQUIRE(synced_animation_graph); character_node = (SceneTree::get_singleton()->get_root()->find_child("CharacterNode", true, false)); REQUIRE(character_node != nullptr); @@ -144,27 +144,27 @@ namespace TestSyncedAnimationGraph { TEST_CASE("[SyncedAnimationGraph] Test BlendTree construction") { BlendTreeGraph tree_constructor; - Ref animation_sampler_node0; + Ref animation_sampler_node0; animation_sampler_node0.instantiate(); animation_sampler_node0->name = "Sampler0"; tree_constructor.add_node(animation_sampler_node0); - Ref animation_sampler_node1; + Ref animation_sampler_node1; animation_sampler_node1.instantiate(); animation_sampler_node1->name = "Sampler1"; tree_constructor.add_node(animation_sampler_node1); - Ref animation_sampler_node2; + Ref animation_sampler_node2; animation_sampler_node2.instantiate(); animation_sampler_node2->name = "Sampler2"; tree_constructor.add_node(animation_sampler_node2); - Ref node_blend0; + Ref node_blend0; node_blend0.instantiate(); node_blend0->name = "Blend0"; tree_constructor.add_node(node_blend0); - Ref node_blend1; + Ref node_blend1; node_blend1.instantiate(); node_blend1->name = "Blend1"; tree_constructor.add_node(node_blend1); @@ -256,7 +256,7 @@ TEST_CASE_FIXTURE(SyncedAnimationGraphFixture, "[SceneTree][SyncedAnimationGraph } TEST_CASE_FIXTURE(SyncedAnimationGraphFixture, "[SceneTree][SyncedAnimationGraph] SyncedAnimationGraph evaluation with an AnimationSampler as root node") { - Ref animation_sampler_node; + Ref animation_sampler_node; animation_sampler_node.instantiate(); animation_sampler_node->animation_name = "animation_library/TestAnimationA"; @@ -278,10 +278,10 @@ TEST_CASE_FIXTURE(SyncedAnimationGraphFixture, "[SceneTree][SyncedAnimationGraph } TEST_CASE_FIXTURE(SyncedAnimationGraphFixture, "[SceneTree][SyncedAnimationGraph][BlendTree] BlendTree evaluation with a AnimationSamplerNode connected to the output") { - Ref synced_blend_tree_node; + Ref synced_blend_tree_node; synced_blend_tree_node.instantiate(); - Ref animation_sampler_node; + Ref animation_sampler_node; animation_sampler_node.instantiate(); animation_sampler_node->animation_name = "animation_library/TestAnimationA"; @@ -308,25 +308,25 @@ TEST_CASE_FIXTURE(SyncedAnimationGraphFixture, "[SceneTree][SyncedAnimationGraph } TEST_CASE_FIXTURE(SyncedAnimationGraphFixture, "[SceneTree][SyncedAnimationGraph][BlendTree][Blend2Node] BlendTree evaluation with a Blend2Node connected to the output") { - Ref synced_blend_tree_node; + Ref synced_blend_tree_node; synced_blend_tree_node.instantiate(); // TestAnimationA - Ref animation_sampler_node_a; + Ref animation_sampler_node_a; animation_sampler_node_a.instantiate(); animation_sampler_node_a->animation_name = "animation_library/TestAnimationA"; synced_blend_tree_node->add_node(animation_sampler_node_a); // TestAnimationB - Ref animation_sampler_node_b; + Ref animation_sampler_node_b; animation_sampler_node_b.instantiate(); animation_sampler_node_b->animation_name = "animation_library/TestAnimationB"; synced_blend_tree_node->add_node(animation_sampler_node_b); // Blend2 - Ref blend2_node; + Ref blend2_node; blend2_node.instantiate(); blend2_node->name = "Blend2"; blend2_node->blend_weight = 0.5; @@ -344,7 +344,7 @@ TEST_CASE_FIXTURE(SyncedAnimationGraphFixture, "[SceneTree][SyncedAnimationGraph synced_blend_tree_node->initialize(synced_animation_graph->get_context()); int blend2_node_index = synced_blend_tree_node->find_node_index(blend2_node); - const SyncedBlendTree::NodeRuntimeData &blend2_runtime_data = synced_blend_tree_node->_node_runtime_data[blend2_node_index]; + const BLTAnimationNodeBlendTree::NodeRuntimeData &blend2_runtime_data = synced_blend_tree_node->_node_runtime_data[blend2_node_index]; CHECK(blend2_runtime_data.input_nodes[0] == animation_sampler_node_a); CHECK(blend2_runtime_data.input_nodes[1] == animation_sampler_node_b); @@ -433,10 +433,10 @@ TEST_CASE_FIXTURE(SyncedAnimationGraphFixture, "[SceneTree][SyncedAnimationGraph REQUIRE(ClassDB::class_exists("AnimationSamplerNode")); // Load blend tree - Ref loaded_synced_blend_tree = ResourceLoader::load("synced_blend_tree_node.tres"); + Ref loaded_synced_blend_tree = ResourceLoader::load("synced_blend_tree_node.tres"); REQUIRE(loaded_synced_blend_tree.is_valid()); - Ref loaded_blend2_node = loaded_synced_blend_tree->get_node(loaded_synced_blend_tree->find_node_index_by_name("Blend2")); + Ref loaded_blend2_node = loaded_synced_blend_tree->get_node(loaded_synced_blend_tree->find_node_index_by_name("Blend2")); REQUIRE(loaded_blend2_node.is_valid()); CHECK(loaded_blend2_node->sync == false); CHECK(loaded_blend2_node->blend_weight == blend2_node->blend_weight);