Skip to content

Commit 57a7de1

Browse files
Fix debugging tools and APIs (#89)
1 parent acaa11f commit 57a7de1

8 files changed

+47
-20
lines changed

src/editor/mm_editor.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void MMEditor::_bake_all_animation_libraries(const AnimationMixer* p_mixer, cons
7171
}
7272
}
7373

74-
void MMEditor::_refresh() {
74+
void MMEditor::_refresh(bool character_changed) {
7575
if (!_current_controller) {
7676
return;
7777
}
@@ -93,10 +93,19 @@ void MMEditor::_refresh() {
9393

9494
_library_selector->add_item(animation_library_list[i]);
9595
}
96-
_library_selector->select(-1);
96+
if (animation_library_list.is_empty()) {
97+
_library_selector->select(-1);
98+
} else if (character_changed) {
99+
_library_selector->select(0);
100+
}
97101

98102
_visualization_tab->clear();
99103
_data_tab->clear();
104+
105+
const int32_t selected_index = _library_selector->get_selected();
106+
if (selected_index != -1) {
107+
_anim_lib_selected(selected_index);
108+
}
100109
}
101110

102111
void MMEditor::_bake_button_pressed() {
@@ -130,7 +139,8 @@ void MMEditor::_bake_button_pressed() {
130139
mm_lib->bake_data(animation_mixer, skeleton);
131140
ResourceSaver::get_singleton()->save(mm_lib);
132141

133-
_refresh();
142+
_visualization_tab->refresh();
143+
_data_tab->set_animation_library(mm_lib);
134144
}
135145

136146
void MMEditor::_anim_lib_selected(int p_index) {

src/editor/mm_editor.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ class MMEditor : public Control {
2323
const bool changed = p_controller != _current_controller;
2424

2525
_current_controller = p_controller;
26-
if (changed) {
27-
_refresh();
28-
}
26+
_refresh(changed);
2927
}
3028

3129
protected:
@@ -34,7 +32,7 @@ class MMEditor : public Control {
3432

3533
private:
3634
static void _bake_all_animation_libraries(const AnimationMixer* p_mixer, const Skeleton3D* p_skeleton);
37-
void _refresh();
35+
void _refresh(bool character_changed);
3836
void _bake_button_pressed();
3937
void _anim_lib_selected(int p_index);
4038

src/editor/mm_visualization_tab.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ void MMVisualizationTab::_viz_time_changed(float p_value) {
5858
StringName animation_name = animation_list[_selected_animation_index];
5959
String anim_lib_name = _current_animation_library->get_path().get_file().get_basename();
6060

61-
UtilityFunctions::print(anim_lib_name);
6261
_emit_animation_viz_request(anim_lib_name, animation_name, p_value);
6362
}
6463

@@ -93,7 +92,9 @@ void MMVisualizationTab::refresh() {
9392
_viz_animation_option_button->add_item(animation_name, i);
9493
}
9594

96-
if (_current_animation_library->needs_baking()) {
95+
if (!animations.is_empty()) {
96+
_viz_animation_option_button->select(0);
97+
_viz_anim_selected(0);
9798
}
9899

99100
set_enabled(!_current_animation_library->needs_baking());

src/mm_animation_node.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ PackedFloat32Array MMAnimationNode::_process_animation_node(const PackedFloat64A
6868
_start_transition(animation_match, time_match);
6969
}
7070
_last_query_output = query_output;
71-
emit_signal("on_query_result", _output_to_dict(query_output));
71+
query_input->on_query_result(query_output);
7272
}
7373

7474
return _update_current_animation(p_test_only);
@@ -247,7 +247,6 @@ void MMAnimationNode::_bind_methods() {
247247
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "blending_enabled"), "set_blending_enabled", "get_blending_enabled");
248248

249249
BINDER_PROPERTY_PARAMS(MMAnimationNode, Variant::FLOAT, transition_halflife);
250-
ADD_SIGNAL(MethodInfo("on_query_result", PropertyInfo(Variant::DICTIONARY, "query_output")));
251250
}
252251

253252
Dictionary MMAnimationNode::_output_to_dict(const MMQueryOutput& output) {

src/mm_character.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "mm_animation_library.h"
55
#include "mm_animation_node.h"
66

7+
#include <godot_cpp/classes/animation_root_node.hpp>
78
#include <godot_cpp/classes/engine.hpp>
89
#include <godot_cpp/classes/input.hpp>
910
#include <godot_cpp/classes/input_event_mouse_motion.hpp>
@@ -256,6 +257,7 @@ void MMCharacter::_fill_query_input(MMQueryInput& input) {
256257
input.controller_transform = get_global_transform();
257258
input.character_transform = skeleton->get_global_transform();
258259
input.skeleton_state = _skeleton_state;
260+
input.on_query_result = std::bind(&MMCharacter::_on_query_result, this, std::placeholders::_1);
259261
}
260262

261263
void MMCharacter::_update_query() {
@@ -326,6 +328,12 @@ void MMCharacter::_update_skeleton_state(double delta_t) {
326328
}
327329
}
328330

331+
void MMCharacter::_on_query_result(const MMQueryOutput& output) {
332+
if (emit_result_signal) {
333+
emit_signal("on_query_result", _output_to_dict(output));
334+
}
335+
}
336+
329337
Dictionary MMCharacter::_output_to_dict(const MMQueryOutput& output) {
330338
Dictionary result;
331339

@@ -366,6 +374,9 @@ void MMCharacter::_bind_methods() {
366374
BINDER_PROPERTY_PARAMS(MMCharacter, Variant::FLOAT, trajectory_delta_time);
367375
BINDER_PROPERTY_PARAMS(MMCharacter, Variant::INT, history_point_count);
368376
BINDER_PROPERTY_PARAMS(MMCharacter, Variant::FLOAT, history_delta_time);
377+
378+
ADD_GROUP("Debug", "");
379+
BINDER_PROPERTY_PARAMS(MMCharacter, Variant::BOOL, emit_result_signal);
369380
}
370381

371382
void MMCharacter::_notification(int p_what) {

src/mm_character.h

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class MMCharacter : public CharacterBody3D {
8585
GETSET(AnimationTree*, animation_tree);
8686
GETSET(Ref<MMSynchronizer>, synchronizer);
8787

88+
// Debug
89+
GETSET(bool, emit_result_signal, false);
90+
8891
protected:
8992
static constexpr size_t HISTORY_BUFFER_SIZE{100}; // Around 1.6s
9093
static void _bind_methods();
@@ -115,6 +118,8 @@ class MMCharacter : public CharacterBody3D {
115118
void _reset_skeleton_state();
116119
void _update_skeleton_state(double delta_t);
117120

121+
void _on_query_result(const MMQueryOutput& output);
122+
118123
static Dictionary _output_to_dict(const MMQueryOutput& output);
119124

120125
private:

src/mm_query.h

+11-8
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,25 @@
22
#define MM_QUERY_H
33

44
#include "mm_bone_state.h"
5+
#include "mm_query.h"
56
#include "mm_trajectory_point.h"
67

8+
#include <functional>
79
#include <godot_cpp/classes/skeleton3d.hpp>
810
#include <godot_cpp/variant/string.hpp>
911
#include <godot_cpp/variant/transform3d.hpp>
1012
#include <godot_cpp/variant/vector3.hpp>
1113

1214
using namespace godot;
1315

16+
struct MMQueryOutput {
17+
String animation_match;
18+
float time_match;
19+
float cost;
20+
PackedFloat32Array matched_frame_data;
21+
Dictionary feature_costs;
22+
};
23+
1424
class MMQueryInput : public RefCounted {
1525
GDCLASS(MMQueryInput, RefCounted);
1626

@@ -22,6 +32,7 @@ class MMQueryInput : public RefCounted {
2232
std::vector<MMTrajectoryPoint> trajectory;
2333
std::vector<MMTrajectoryPoint> trajectory_history;
2434
SkeletonState skeleton_state;
35+
std::function<void(const MMQueryOutput&)> on_query_result;
2536

2637
bool is_valid() const {
2738
// Add validation logic here
@@ -33,12 +44,4 @@ class MMQueryInput : public RefCounted {
3344
}
3445
};
3546

36-
struct MMQueryOutput {
37-
String animation_match;
38-
float time_match;
39-
float cost;
40-
PackedFloat32Array matched_frame_data;
41-
Dictionary feature_costs;
42-
};
43-
4447
#endif // MM_QUERY_H

0 commit comments

Comments
 (0)