Skip to content

Commit bc39f89

Browse files
committed
Add BlendSpace BlendPoint weight velocity limiting
1 parent 0dd9178 commit bc39f89

10 files changed

+737
-48
lines changed

doc/classes/AnimationNodeBlendSpace1D.xml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,27 @@
3434
Returns the [AnimationNode] referenced by the point at index [param point].
3535
</description>
3636
</method>
37+
<method name="get_blend_point_ovl" qualifiers="const">
38+
<return type="bool" />
39+
<param index="0" name="point" type="int" />
40+
<description>
41+
Returns the velocity limit override of the point at index [param point].
42+
</description>
43+
</method>
3744
<method name="get_blend_point_position" qualifiers="const">
3845
<return type="float" />
3946
<param index="0" name="point" type="int" />
4047
<description>
4148
Returns the position of the point at index [param point].
4249
</description>
4350
</method>
51+
<method name="get_blend_point_vl" qualifiers="const">
52+
<return type="float" />
53+
<param index="0" name="point" type="int" />
54+
<description>
55+
Returns the velocity limit of the point at index [param point].
56+
</description>
57+
</method>
4458
<method name="remove_blend_point">
4559
<return type="void" />
4660
<param index="0" name="point" type="int" />
@@ -56,6 +70,14 @@
5670
Changes the [AnimationNode] referenced by the point at index [param point].
5771
</description>
5872
</method>
73+
<method name="set_blend_point_ovl">
74+
<return type="void" />
75+
<param index="0" name="point" type="int" />
76+
<param index="1" name="override_velocity_limit" type="bool" />
77+
<description>
78+
Updates the velocity limit override of the point at index [param point] in the blend space.
79+
</description>
80+
</method>
5981
<method name="set_blend_point_position">
6082
<return type="void" />
6183
<param index="0" name="point" type="int" />
@@ -64,6 +86,14 @@
6486
Updates the position of the point at index [param point] on the blend axis.
6587
</description>
6688
</method>
89+
<method name="set_blend_point_vl">
90+
<return type="void" />
91+
<param index="0" name="point" type="int" />
92+
<param index="1" name="velocity_limit" type="float" />
93+
<description>
94+
Updates the velocity limit of the point at index [param point] in the blend space.
95+
</description>
96+
</method>
6797
</methods>
6898
<members>
6999
<member name="blend_mode" type="int" setter="set_blend_mode" getter="get_blend_mode" enum="AnimationNodeBlendSpace1D.BlendMode" default="0">
@@ -82,9 +112,18 @@
82112
If [code]false[/code], the blended animations' frame are stopped when the blend value is [code]0[/code].
83113
If [code]true[/code], forcing the blended animations to advance frame.
84114
</member>
115+
<member name="use_velocity_limit" type="bool" setter="set_use_velocity_limit" getter="get_use_velocity_limit" default="false">
116+
If [code]true[/code], while [member sync] is [code]true[/code] a blend point's weight is applied over time using [member velocity_limit] with [member velocity_limit_ease].
117+
</member>
85118
<member name="value_label" type="String" setter="set_value_label" getter="get_value_label" default="&quot;value&quot;">
86119
Label of the virtual axis of the blend space.
87120
</member>
121+
<member name="velocity_limit" type="float" setter="set_velocity_limit" getter="get_velocity_limit" default="0.0">
122+
Controls the blend point velocity limit speed.
123+
</member>
124+
<member name="velocity_limit_ease" type="float" setter="set_velocity_limit_ease" getter="get_velocity_limit_ease" default="1.0">
125+
Controls the easing of the velocity limit speed.
126+
</member>
88127
</members>
89128
<constants>
90129
<constant name="BLEND_MODE_INTERPOLATED" value="0" enum="BlendMode">

doc/classes/AnimationNodeBlendSpace2D.xml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,27 @@
4545
Returns the [AnimationRootNode] referenced by the point at index [param point].
4646
</description>
4747
</method>
48+
<method name="get_blend_point_ovl" qualifiers="const">
49+
<return type="bool" />
50+
<param index="0" name="point" type="int" />
51+
<description>
52+
Returns the velocity limit override of the point at index [param point].
53+
</description>
54+
</method>
4855
<method name="get_blend_point_position" qualifiers="const">
4956
<return type="Vector2" />
5057
<param index="0" name="point" type="int" />
5158
<description>
5259
Returns the position of the point at index [param point].
5360
</description>
5461
</method>
62+
<method name="get_blend_point_vl" qualifiers="const">
63+
<return type="float" />
64+
<param index="0" name="point" type="int" />
65+
<description>
66+
Returns the velocity limit of the point at index [param point].
67+
</description>
68+
</method>
5569
<method name="get_triangle_count" qualifiers="const">
5670
<return type="int" />
5771
<description>
@@ -88,6 +102,14 @@
88102
Changes the [AnimationNode] referenced by the point at index [param point].
89103
</description>
90104
</method>
105+
<method name="set_blend_point_ovl">
106+
<return type="void" />
107+
<param index="0" name="point" type="int" />
108+
<param index="1" name="override_velocity_limit" type="bool" />
109+
<description>
110+
Updates the velocity limit override of the point at index [param point] in the blend space.
111+
</description>
112+
</method>
91113
<method name="set_blend_point_position">
92114
<return type="void" />
93115
<param index="0" name="point" type="int" />
@@ -96,6 +118,14 @@
96118
Updates the position of the point at index [param point] in the blend space.
97119
</description>
98120
</method>
121+
<method name="set_blend_point_vl">
122+
<return type="void" />
123+
<param index="0" name="point" type="int" />
124+
<param index="1" name="velocity_limit" type="float" />
125+
<description>
126+
Updates the velocity limit of the point at index [param point] in the blend space.
127+
</description>
128+
</method>
99129
</methods>
100130
<members>
101131
<member name="auto_triangles" type="bool" setter="set_auto_triangles" getter="get_auto_triangles" default="true">
@@ -117,6 +147,15 @@
117147
If [code]false[/code], the blended animations' frame are stopped when the blend value is [code]0[/code].
118148
If [code]true[/code], forcing the blended animations to advance frame.
119149
</member>
150+
<member name="use_velocity_limit" type="bool" setter="set_use_velocity_limit" getter="get_use_velocity_limit" default="false">
151+
If [code]true[/code], while [member sync] is [code]true[/code] a blend point's weight is applied over time using [member velocity_limit] with [member velocity_limit_ease].
152+
</member>
153+
<member name="velocity_limit" type="float" setter="set_velocity_limit" getter="get_velocity_limit" default="0.0">
154+
Controls the blend point velocity limit speed.
155+
</member>
156+
<member name="velocity_limit_ease" type="float" setter="set_velocity_limit_ease" getter="get_velocity_limit_ease" default="1.0">
157+
Controls the easing of the velocity limit speed.
158+
</member>
120159
<member name="x_label" type="String" setter="set_x_label" getter="get_x_label" default="&quot;x&quot;">
121160
Name of the blend space's X axis.
122161
</member>

editor/animation/animation_blend_space_1d_editor.cpp

Lines changed: 114 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "animation_blend_space_1d_editor.h"
3232

3333
#include "core/os/keyboard.h"
34+
#include "editor/docks/inspector_dock.h"
3435
#include "editor/editor_node.h"
3536
#include "editor/editor_string_names.h"
3637
#include "editor/editor_undo_redo_manager.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();
@@ -571,6 +579,7 @@ void AnimationNodeBlendSpace1DEditor::_open_editor() {
571579

572580
void AnimationNodeBlendSpace1DEditor::_notification(int p_what) {
573581
switch (p_what) {
582+
case NOTIFICATION_ENTER_TREE:
574583
case NOTIFICATION_THEME_CHANGED: {
575584
error_panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Tree")));
576585
error_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
@@ -616,6 +625,82 @@ void AnimationNodeBlendSpace1DEditor::_notification(int p_what) {
616625
} break;
617626
}
618627
}
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+
}
619704

620705
void AnimationNodeBlendSpace1DEditor::_bind_methods() {
621706
ClassDB::bind_method("_update_space", &AnimationNodeBlendSpace1DEditor::_update_space);
@@ -645,6 +730,8 @@ void AnimationNodeBlendSpace1DEditor::edit(const Ref<AnimationNode> &p_node) {
645730
min_value->set_editable(!read_only);
646731
max_value->set_editable(!read_only);
647732
sync->set_disabled(read_only);
733+
default_velocity_limit->set_editable(!read_only);
734+
use_velocity_limit->set_disabled(read_only);
648735
interpolation->set_disabled(read_only);
649736
}
650737

@@ -666,6 +753,7 @@ AnimationNodeBlendSpace1DEditor::AnimationNodeBlendSpace1DEditor() {
666753
top_hb->add_child(tool_blend);
667754
tool_blend->set_pressed(true);
668755
tool_blend->set_tooltip_text(TTR("Set the blending position within the space"));
756+
tool_blend->set_accessibility_name(TTRC("Set Blending Position"));
669757
tool_blend->connect(SceneStringName(pressed), callable_mp(this, &AnimationNodeBlendSpace1DEditor::_tool_switch).bind(3));
670758

671759
tool_select = memnew(Button);
@@ -674,6 +762,7 @@ AnimationNodeBlendSpace1DEditor::AnimationNodeBlendSpace1DEditor() {
674762
tool_select->set_button_group(bg);
675763
top_hb->add_child(tool_select);
676764
tool_select->set_tooltip_text(TTR("Select and move points, create points with RMB."));
765+
tool_select->set_accessibility_name(TTRC("Edit Points"));
677766
tool_select->connect(SceneStringName(pressed), callable_mp(this, &AnimationNodeBlendSpace1DEditor::_tool_switch).bind(0));
678767

679768
tool_create = memnew(Button);
@@ -682,6 +771,7 @@ AnimationNodeBlendSpace1DEditor::AnimationNodeBlendSpace1DEditor() {
682771
tool_create->set_button_group(bg);
683772
top_hb->add_child(tool_create);
684773
tool_create->set_tooltip_text(TTR("Create points."));
774+
tool_create->set_accessibility_name(TTRC("Create Points"));
685775
tool_create->connect(SceneStringName(pressed), callable_mp(this, &AnimationNodeBlendSpace1DEditor::_tool_switch).bind(1));
686776

687777
tool_erase_sep = memnew(VSeparator);
@@ -690,6 +780,7 @@ AnimationNodeBlendSpace1DEditor::AnimationNodeBlendSpace1DEditor() {
690780
tool_erase->set_theme_type_variation(SceneStringName(FlatButton));
691781
top_hb->add_child(tool_erase);
692782
tool_erase->set_tooltip_text(TTR("Erase points."));
783+
tool_erase->set_accessibility_name(TTRC("Erase Points"));
693784
tool_erase->connect(SceneStringName(pressed), callable_mp(this, &AnimationNodeBlendSpace1DEditor::_erase_selected));
694785

695786
top_hb->add_child(memnew(VSeparator));
@@ -700,6 +791,7 @@ AnimationNodeBlendSpace1DEditor::AnimationNodeBlendSpace1DEditor() {
700791
top_hb->add_child(snap);
701792
snap->set_pressed(true);
702793
snap->set_tooltip_text(TTR("Enable snap and show grid."));
794+
snap->set_accessibility_name(TTRC("Snap to Grid"));
703795
snap->connect(SceneStringName(pressed), callable_mp(this, &AnimationNodeBlendSpace1DEditor::_snap_toggled));
704796

705797
snap_value = memnew(SpinBox);
@@ -722,6 +814,26 @@ AnimationNodeBlendSpace1DEditor::AnimationNodeBlendSpace1DEditor() {
722814
top_hb->add_child(interpolation);
723815
interpolation->connect(SceneStringName(item_selected), callable_mp(this, &AnimationNodeBlendSpace1DEditor::_config_changed));
724816

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+
725837
edit_hb = memnew(HBoxContainer);
726838
top_hb->add_child(edit_hb);
727839
edit_hb->add_child(memnew(VSeparator));

0 commit comments

Comments
 (0)