Skip to content

Commit e8c9ff9

Browse files
committed
Add BlendSpace BlendPoint weight velocity limiting
1 parent ce94b26 commit e8c9ff9

10 files changed

+586
-24
lines changed

doc/classes/AnimationNodeBlendSpace1D.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@
7575
<member name="min_space" type="float" setter="set_min_space" getter="get_min_space" default="-1.0">
7676
The blend space's axis's lower limit for the points' position. See [method add_blend_point].
7777
</member>
78+
<member name="smooth" type="bool" setter="set_use_smooth" getter="is_using_smooth" default="false">
79+
If [code]true[/code], while [member sync] is [code]true[/code] a blend point's weight is applied over time using [member smooth_speed].
80+
</member>
81+
<member name="smooth_speed" type="float" setter="set_smooth_speed" getter="get_smooth_speed" default="1.0">
82+
Controls the blend point smoothing speed.
83+
</member>
7884
<member name="snap" type="float" setter="set_snap" getter="get_snap" default="0.1">
7985
Position increment to snap to when moving a point on the axis.
8086
</member>

doc/classes/AnimationNodeBlendSpace2D.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@
110110
<member name="min_space" type="Vector2" setter="set_min_space" getter="get_min_space" default="Vector2(-1, -1)">
111111
The blend space's X and Y axes' lower limit for the points' position. See [method add_blend_point].
112112
</member>
113+
<member name="smooth" type="bool" setter="set_use_smooth" getter="is_using_smooth" default="false">
114+
If [code]true[/code], while [member sync] is [code]true[/code] a blend point's weight is applied over time using [member smooth_speed].
115+
</member>
116+
<member name="smooth_speed" type="float" setter="set_smooth_speed" getter="get_smooth_speed" default="1.0">
117+
Controls the blend point smoothing speed.
118+
</member>
113119
<member name="snap" type="Vector2" setter="set_snap" getter="get_snap" default="Vector2(0.1, 0.1)">
114120
Position increment to snap to when moving a point.
115121
</member>

editor/plugins/animation_blend_space_1d_editor.cpp

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "editor/editor_string_names.h"
3737
#include "editor/editor_undo_redo_manager.h"
3838
#include "editor/gui/editor_file_dialog.h"
39+
#include "editor/inspector_dock.h"
3940
#include "editor/themes/editor_scale.h"
4041
#include "scene/animation/animation_blend_tree.h"
4142
#include "scene/gui/button.h"
@@ -133,9 +134,9 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEven
133134
for (int i = 0; i < points.size(); i++) {
134135
if (Math::abs(float(points[i] - mb->get_position().x)) < 10 * EDSCALE) {
135136
selected_point = i;
136-
137137
Ref<AnimationNode> node = blend_space->get_blend_point_node(i);
138-
EditorNode::get_singleton()->push_item(node.ptr(), "", true);
138+
current_blend_point_editor->setup(blend_space, selected_point, node);
139+
InspectorDock::get_inspector_singleton()->edit(current_blend_point_editor.ptr());
139140
dragging_selected_attempt = true;
140141
drag_from = mb->get_position();
141142
_update_tool_erase();
@@ -336,6 +337,8 @@ void AnimationNodeBlendSpace1DEditor::_update_space() {
336337

337338
sync->set_pressed(blend_space->is_using_sync());
338339
interpolation->select(blend_space->get_blend_mode());
340+
use_velocity_limit->set_pressed(blend_space->get_use_velocity_limit());
341+
default_velocity_limit->set_value(blend_space->get_velocity_limit());
339342

340343
label_value->set_text(blend_space->get_value_label());
341344

@@ -364,6 +367,11 @@ void AnimationNodeBlendSpace1DEditor::_config_changed(double) {
364367
undo_redo->add_undo_method(blend_space.ptr(), "set_use_sync", blend_space->is_using_sync());
365368
undo_redo->add_do_method(blend_space.ptr(), "set_blend_mode", interpolation->get_selected());
366369
undo_redo->add_undo_method(blend_space.ptr(), "set_blend_mode", blend_space->get_blend_mode());
370+
blending_hb->set_visible(sync->is_pressed());
371+
undo_redo->add_do_method(blend_space.ptr(), "set_use_velocity_limit", use_velocity_limit->is_pressed());
372+
undo_redo->add_undo_method(blend_space.ptr(), "set_use_velocity_limit", blend_space->get_use_velocity_limit());
373+
undo_redo->add_do_method(blend_space.ptr(), "set_velocity_limit", default_velocity_limit->get_value());
374+
undo_redo->add_undo_method(blend_space.ptr(), "set_velocity_limit", blend_space->get_velocity_limit());
367375
undo_redo->add_do_method(this, "_update_space");
368376
undo_redo->add_undo_method(this, "_update_space");
369377
undo_redo->commit_action();
@@ -617,6 +625,82 @@ void AnimationNodeBlendSpace1DEditor::_notification(int p_what) {
617625
} break;
618626
}
619627
}
628+
void BlendPointEditor1D::setup(Ref<AnimationNodeBlendSpace1D> p_blend_space, int p_idx, Ref<AnimationNode> p_anim_node) {
629+
blend_space = p_blend_space;
630+
selected_point = p_idx;
631+
anim_node = p_anim_node;
632+
}
633+
634+
void BlendPointEditor1D::set_velocity_limit(float p_value) {
635+
if (blend_space.is_valid()) {
636+
if (updating) {
637+
return;
638+
}
639+
updating = true;
640+
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
641+
undo_redo->create_action(TTR("Change Node Velocity Limit"));
642+
undo_redo->add_do_method(blend_space.ptr(), "set_blend_point_vl", selected_point, p_value);
643+
undo_redo->add_undo_method(blend_space.ptr(), "set_blend_point_vl", selected_point, blend_space->get_blend_point_vl(selected_point));
644+
undo_redo->commit_action();
645+
updating = false;
646+
}
647+
}
648+
double BlendPointEditor1D::get_velocity_limit() const {
649+
return (blend_space.is_valid()) ? blend_space->get_blend_point_vl(selected_point) : 0.0;
650+
}
651+
652+
Ref<AnimationNode> BlendPointEditor1D::get_anim_node() const {
653+
return anim_node;
654+
}
655+
void BlendPointEditor1D::set_velocity_limit_ease(float const p_ease) {
656+
if (blend_space.is_valid()) {
657+
updating = true;
658+
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
659+
undo_redo->create_action(TTR("Change Blendspace Velocity Limit Ease"));
660+
undo_redo->add_do_method(blend_space.ptr(), "set_velocity_limit_ease", p_ease);
661+
undo_redo->add_undo_method(blend_space.ptr(), "set_velocity_limit_ease", blend_space->get_velocity_limit_ease());
662+
undo_redo->commit_action();
663+
updating = false;
664+
}
665+
}
666+
float BlendPointEditor1D::get_velocity_limit_ease() const {
667+
return (blend_space.is_valid()) ? blend_space->get_velocity_limit_ease() : 1.0;
668+
}
669+
670+
void BlendPointEditor1D::set_override_velocity_limit(bool const p_ovl) {
671+
if (blend_space.is_valid()) {
672+
updating = true;
673+
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
674+
undo_redo->create_action(TTR("Change Node Override Velocity Limit"));
675+
undo_redo->add_do_method(blend_space.ptr(), "set_blend_point_ovl", selected_point, p_ovl);
676+
undo_redo->add_undo_method(blend_space.ptr(), "set_blend_point_ovl", selected_point, blend_space->get_blend_point_ovl(selected_point));
677+
undo_redo->commit_action();
678+
updating = false;
679+
}
680+
}
681+
bool BlendPointEditor1D::get_override_velocity_limit() const {
682+
return (blend_space.is_valid()) ? blend_space->get_blend_point_ovl(selected_point) : false;
683+
}
684+
685+
void BlendPointEditor1D::_bind_methods() {
686+
ClassDB::bind_method(D_METHOD("set_velocity_limit", "value"), &BlendPointEditor1D::set_velocity_limit);
687+
ClassDB::bind_method(D_METHOD("get_velocity_limit"), &BlendPointEditor1D::get_velocity_limit);
688+
ClassDB::bind_method(D_METHOD("_dont_undo_redo"), &BlendPointEditor1D::_dont_undo_redo);
689+
ClassDB::bind_method(D_METHOD("_hide_script_from_inspector"), &BlendPointEditor1D::_hide_script_from_inspector);
690+
ClassDB::bind_method(D_METHOD("_hide_metadata_from_inspector"), &BlendPointEditor1D::_hide_metadata_from_inspector);
691+
692+
ClassDB::bind_method(D_METHOD("get_velocity_limit_ease"), &BlendPointEditor1D::get_velocity_limit_ease);
693+
ClassDB::bind_method(D_METHOD("set_velocity_limit_ease"), &BlendPointEditor1D::set_velocity_limit_ease);
694+
695+
ClassDB::bind_method(D_METHOD("set_override_velocity_limit"), &BlendPointEditor1D::set_override_velocity_limit);
696+
ClassDB::bind_method(D_METHOD("get_override_velocity_limit"), &BlendPointEditor1D::get_override_velocity_limit);
697+
698+
ClassDB::bind_method(D_METHOD("get_anim_node"), &BlendPointEditor1D::get_anim_node);
699+
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "velocity_limit_ease", PROPERTY_HINT_EXP_EASING), "set_velocity_limit_ease", "get_velocity_limit_ease");
700+
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "override_velocity_limit", PROPERTY_HINT_NONE), "set_override_velocity_limit", "get_override_velocity_limit");
701+
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "velocity_limit", PROPERTY_HINT_NONE, "0,60,0.01,or_greater,suffix:/s"), "set_velocity_limit", "get_velocity_limit");
702+
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "animation_node", PROPERTY_HINT_RESOURCE_TYPE, "AnimationNode"), "", "get_anim_node");
703+
}
620704

621705
void AnimationNodeBlendSpace1DEditor::_bind_methods() {
622706
ClassDB::bind_method("_update_space", &AnimationNodeBlendSpace1DEditor::_update_space);
@@ -646,6 +730,8 @@ void AnimationNodeBlendSpace1DEditor::edit(const Ref<AnimationNode> &p_node) {
646730
min_value->set_editable(!read_only);
647731
max_value->set_editable(!read_only);
648732
sync->set_disabled(read_only);
733+
default_velocity_limit->set_editable(!read_only);
734+
use_velocity_limit->set_disabled(read_only);
649735
interpolation->set_disabled(read_only);
650736
}
651737

@@ -728,6 +814,26 @@ AnimationNodeBlendSpace1DEditor::AnimationNodeBlendSpace1DEditor() {
728814
top_hb->add_child(interpolation);
729815
interpolation->connect(SceneStringName(item_selected), callable_mp(this, &AnimationNodeBlendSpace1DEditor::_config_changed));
730816

817+
blending_hb = memnew(HBoxContainer);
818+
top_hb->add_child(blending_hb);
819+
blending_hb->add_child(memnew(VSeparator));
820+
821+
blending_hb->add_child(memnew(Label(TTR("Use Velocity Limit:"))));
822+
use_velocity_limit = memnew(CheckBox);
823+
blending_hb->add_child(use_velocity_limit);
824+
use_velocity_limit->connect(SceneStringName(toggled), callable_mp(this, &AnimationNodeBlendSpace1DEditor::_config_changed));
825+
826+
blending_hb->add_child(memnew(Label(TTR("Default Velocity limit:"))));
827+
default_velocity_limit = memnew(SpinBox);
828+
blending_hb->add_child(default_velocity_limit);
829+
default_velocity_limit->set_min(0.0);
830+
default_velocity_limit->set_step(0.01);
831+
default_velocity_limit->set_max(60.0);
832+
default_velocity_limit->set_suffix("/s");
833+
default_velocity_limit->connect(SceneStringName(value_changed), callable_mp(this, &AnimationNodeBlendSpace1DEditor::_config_changed));
834+
835+
current_blend_point_editor.instantiate();
836+
731837
edit_hb = memnew(HBoxContainer);
732838
top_hb->add_child(edit_hb);
733839
edit_hb->add_child(memnew(VSeparator));

editor/plugins/animation_blend_space_1d_editor.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class PanelContainer;
4343
class SpinBox;
4444
class VSeparator;
4545

46+
class BlendPointEditor1D;
4647
class AnimationNodeBlendSpace1DEditor : public AnimationTreeNodeEditorPlugin {
4748
GDCLASS(AnimationNodeBlendSpace1DEditor, AnimationTreeNodeEditorPlugin);
4849

@@ -68,6 +69,11 @@ class AnimationNodeBlendSpace1DEditor : public AnimationTreeNodeEditorPlugin {
6869
CheckBox *sync = nullptr;
6970
OptionButton *interpolation = nullptr;
7071

72+
HBoxContainer *blending_hb = nullptr;
73+
CheckBox *use_velocity_limit = nullptr;
74+
SpinBox *default_velocity_limit = nullptr;
75+
Ref<BlendPointEditor1D> current_blend_point_editor;
76+
7177
HBoxContainer *edit_hb = nullptr;
7278
SpinBox *edit_value = nullptr;
7379
Button *open_editor = nullptr;
@@ -135,3 +141,33 @@ class AnimationNodeBlendSpace1DEditor : public AnimationTreeNodeEditorPlugin {
135141
virtual void edit(const Ref<AnimationNode> &p_node) override;
136142
AnimationNodeBlendSpace1DEditor();
137143
};
144+
145+
class BlendPointEditor1D : public RefCounted {
146+
GDCLASS(BlendPointEditor1D, RefCounted);
147+
148+
private:
149+
Ref<AnimationNodeBlendSpace1D> blend_space;
150+
Ref<AnimationNode> anim_node;
151+
float velocity_limit_ease;
152+
int selected_point = -1;
153+
float velocity_limit = 0.0;
154+
bool override_velocity_limit = false;
155+
bool updating = false;
156+
157+
public:
158+
void setup(Ref<AnimationNodeBlendSpace1D> p_blend_space, int idx, Ref<AnimationNode> p_anim_node);
159+
160+
void set_velocity_limit(float p_value);
161+
double get_velocity_limit() const;
162+
void set_override_velocity_limit(bool const p_ovl);
163+
bool get_override_velocity_limit() const;
164+
165+
Ref<AnimationNode> get_anim_node() const;
166+
void set_velocity_limit_ease(float const p_ease);
167+
float get_velocity_limit_ease() const;
168+
bool _hide_script_from_inspector() { return true; }
169+
bool _hide_metadata_from_inspector() { return true; }
170+
bool _dont_undo_redo() { return true; }
171+
172+
static void _bind_methods();
173+
};

0 commit comments

Comments
 (0)