Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed broken root motion calculation in internal process of AnimationBlendTree such as NodeOneShot #60774

Merged
merged 1 commit into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions doc/classes/AnimationNode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<return type="float" />
<argument index="0" name="time" type="float" />
<argument index="1" name="seek" type="bool" />
<argument index="2" name="seek_root" type="bool" />
<description>
User-defined callback called when a custom node is processed. The [code]time[/code] parameter is a relative delta, unless [code]seek[/code] is [code]true[/code], in which case it is absolute.
Here, call the [method blend_input], [method blend_node] or [method blend_animation] functions. You can also use [method get_parameter] and [method set_parameter] to modify local memory.
Expand All @@ -72,8 +73,9 @@
<argument index="1" name="time" type="float" />
<argument index="2" name="delta" type="float" />
<argument index="3" name="seeked" type="bool" />
<argument index="4" name="blend" type="float" />
<argument index="5" name="pingponged" type="int" default="0" />
<argument index="4" name="seek_root" type="bool" />
<argument index="5" name="blend" type="float" />
<argument index="6" name="pingponged" type="int" default="0" />
<description>
Blend an animation by [code]blend[/code] amount (name must be valid in the linked [AnimationPlayer]). A [code]time[/code] and [code]delta[/code] may be passed, as well as whether [code]seek[/code] happened.
</description>
Expand All @@ -83,9 +85,10 @@
<argument index="0" name="input_index" type="int" />
<argument index="1" name="time" type="float" />
<argument index="2" name="seek" type="bool" />
<argument index="3" name="blend" type="float" />
<argument index="4" name="filter" type="int" enum="AnimationNode.FilterAction" default="0" />
<argument index="5" name="optimize" type="bool" default="true" />
<argument index="3" name="seek_root" type="bool" />
<argument index="4" name="blend" type="float" />
<argument index="5" name="filter" type="int" enum="AnimationNode.FilterAction" default="0" />
<argument index="6" name="optimize" type="bool" default="true" />
<description>
Blend an input. This is only useful for nodes created for an [AnimationNodeBlendTree]. The [code]time[/code] parameter is a relative delta, unless [code]seek[/code] is [code]true[/code], in which case it is absolute. A filter mode may be optionally passed (see [enum FilterAction] for options).
</description>
Expand All @@ -96,9 +99,10 @@
<argument index="1" name="node" type="AnimationNode" />
<argument index="2" name="time" type="float" />
<argument index="3" name="seek" type="bool" />
<argument index="4" name="blend" type="float" />
<argument index="5" name="filter" type="int" enum="AnimationNode.FilterAction" default="0" />
<argument index="6" name="optimize" type="bool" default="true" />
<argument index="4" name="seek_root" type="bool" />
<argument index="5" name="blend" type="float" />
<argument index="6" name="filter" type="int" enum="AnimationNode.FilterAction" default="0" />
<argument index="7" name="optimize" type="bool" default="true" />
<description>
Blend another animation node (in case this node contains children animation nodes). This function is only useful if you inherit from [AnimationRootNode] instead, else editors will not display your node for addition.
</description>
Expand Down
4 changes: 2 additions & 2 deletions doc/classes/AnimationNodeOneShot.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
<member name="autorestart_random_delay" type="float" setter="set_autorestart_random_delay" getter="get_autorestart_random_delay" default="0.0">
If [member autorestart] is [code]true[/code], a random additional delay (in seconds) between 0 and this value will be added to [member autorestart_delay].
</member>
<member name="fadein_time" type="float" setter="set_fadein_time" getter="get_fadein_time" default="0.1">
<member name="fadein_time" type="float" setter="set_fadein_time" getter="get_fadein_time" default="0.0">
</member>
<member name="fadeout_time" type="float" setter="set_fadeout_time" getter="get_fadeout_time" default="0.1">
<member name="fadeout_time" type="float" setter="set_fadeout_time" getter="get_fadeout_time" default="0.0">
</member>
<member name="mix_mode" type="int" setter="set_mix_mode" getter="get_mix_mode" enum="AnimationNodeOneShot.MixMode" default="0">
</member>
Expand Down
18 changes: 9 additions & 9 deletions editor/animation_track_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1417,14 +1417,14 @@ void AnimationTimelineEdit::_anim_length_changed(double p_new_len) {
void AnimationTimelineEdit::_anim_loop_pressed() {
undo_redo->create_action(TTR("Change Animation Loop"));
switch (animation->get_loop_mode()) {
case Animation::LoopMode::LOOP_NONE: {
undo_redo->add_do_method(animation.ptr(), "set_loop_mode", Animation::LoopMode::LOOP_LINEAR);
case Animation::LOOP_NONE: {
undo_redo->add_do_method(animation.ptr(), "set_loop_mode", Animation::LOOP_LINEAR);
} break;
case Animation::LoopMode::LOOP_LINEAR: {
undo_redo->add_do_method(animation.ptr(), "set_loop_mode", Animation::LoopMode::LOOP_PINGPONG);
case Animation::LOOP_LINEAR: {
undo_redo->add_do_method(animation.ptr(), "set_loop_mode", Animation::LOOP_PINGPONG);
} break;
case Animation::LoopMode::LOOP_PINGPONG: {
undo_redo->add_do_method(animation.ptr(), "set_loop_mode", Animation::LoopMode::LOOP_NONE);
case Animation::LOOP_PINGPONG: {
undo_redo->add_do_method(animation.ptr(), "set_loop_mode", Animation::LOOP_NONE);
} break;
default:
break;
Expand Down Expand Up @@ -1724,15 +1724,15 @@ void AnimationTimelineEdit::update_values() {
}

switch (animation->get_loop_mode()) {
case Animation::LoopMode::LOOP_NONE: {
case Animation::LOOP_NONE: {
loop->set_icon(get_theme_icon(SNAME("Loop"), SNAME("EditorIcons")));
loop->set_pressed(false);
} break;
case Animation::LoopMode::LOOP_LINEAR: {
case Animation::LOOP_LINEAR: {
loop->set_icon(get_theme_icon(SNAME("Loop"), SNAME("EditorIcons")));
loop->set_pressed(true);
} break;
case Animation::LoopMode::LOOP_PINGPONG: {
case Animation::LOOP_PINGPONG: {
loop->set_icon(get_theme_icon(SNAME("PingPongLoop"), SNAME("EditorIcons")));
loop->set_pressed(true);
} break;
Expand Down
8 changes: 4 additions & 4 deletions editor/animation_track_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,10 @@ class AnimationTrackEditor : public VBoxContainer {
struct TrackClipboard {
NodePath full_path;
NodePath base_path;
Animation::TrackType track_type = Animation::TrackType::TYPE_ANIMATION;
Animation::InterpolationType interp_type = Animation::InterpolationType::INTERPOLATION_CUBIC;
Animation::UpdateMode update_mode = Animation::UpdateMode::UPDATE_CAPTURE;
Animation::LoopMode loop_mode = Animation::LoopMode::LOOP_LINEAR;
Animation::TrackType track_type = Animation::TYPE_ANIMATION;
Animation::InterpolationType interp_type = Animation::INTERPOLATION_CUBIC;
Animation::UpdateMode update_mode = Animation::UPDATE_CAPTURE;
Animation::LoopMode loop_mode = Animation::LOOP_LINEAR;
bool loop_wrap = false;
bool enabled = false;

Expand Down
2 changes: 1 addition & 1 deletion editor/import/resource_importer_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<I
static const char *loop_strings[loop_string_count] = { "loop_mode", "loop", "cycle" };
for (int i = 0; i < loop_string_count; i++) {
if (_teststr(animname, loop_strings[i])) {
anim->set_loop_mode(Animation::LoopMode::LOOP_LINEAR);
anim->set_loop_mode(Animation::LOOP_LINEAR);
animname = _fixstr(animname, loop_strings[i]);

Ref<AnimationLibrary> library = ap->get_animation_library(ap->find_animation_library(anim));
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/animation_player_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ void AnimationPlayerEditor::_prepare_onion_layers_2() {

float pos = cpos + step_off * anim->get_step();

bool valid = anim->get_loop_mode() != Animation::LoopMode::LOOP_NONE || (pos >= 0 && pos <= anim->get_length());
bool valid = anim->get_loop_mode() != Animation::LOOP_NONE || (pos >= 0 && pos <= anim->get_length());
onion.captures_valid.write[cidx] = valid;
if (valid) {
player->seek(pos, true);
Expand Down
6 changes: 3 additions & 3 deletions scene/animation/animation_blend_space_1d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,14 @@ void AnimationNodeBlendSpace1D::_add_blend_point(int p_index, const Ref<Animatio
}
}

double AnimationNodeBlendSpace1D::process(double p_time, bool p_seek) {
double AnimationNodeBlendSpace1D::process(double p_time, bool p_seek, bool p_seek_root) {
if (blend_points_used == 0) {
return 0.0;
}

if (blend_points_used == 1) {
// only one point available, just play that animation
return blend_node(blend_points[0].name, blend_points[0].node, p_time, p_seek, 1.0, FILTER_IGNORE, false);
return blend_node(blend_points[0].name, blend_points[0].node, p_time, p_seek, p_seek_root, 1.0, FILTER_IGNORE, false);
}

double blend_pos = get_parameter(blend_position);
Expand Down Expand Up @@ -295,7 +295,7 @@ double AnimationNodeBlendSpace1D::process(double p_time, bool p_seek) {
double max_time_remaining = 0.0;

for (int i = 0; i < blend_points_used; i++) {
double remaining = blend_node(blend_points[i].name, blend_points[i].node, p_time, p_seek, weights[i], FILTER_IGNORE, false);
double remaining = blend_node(blend_points[i].name, blend_points[i].node, p_time, p_seek, p_seek_root, weights[i], FILTER_IGNORE, false);

max_time_remaining = MAX(max_time_remaining, remaining);
}
Expand Down
2 changes: 1 addition & 1 deletion scene/animation/animation_blend_space_1d.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class AnimationNodeBlendSpace1D : public AnimationRootNode {
void set_value_label(const String &p_label);
String get_value_label() const;

double process(double p_time, bool p_seek) override;
double process(double p_time, bool p_seek, bool p_seek_root) override;
String get_caption() const override;

Ref<AnimationNode> get_child_by_name(const StringName &p_name) override;
Expand Down
12 changes: 6 additions & 6 deletions scene/animation/animation_blend_space_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ void AnimationNodeBlendSpace2D::_blend_triangle(const Vector2 &p_pos, const Vect
r_weights[2] = w;
}

double AnimationNodeBlendSpace2D::process(double p_time, bool p_seek) {
double AnimationNodeBlendSpace2D::process(double p_time, bool p_seek, bool p_seek_root) {
_update_triangles();

Vector2 blend_pos = get_parameter(blend_position);
Expand Down Expand Up @@ -502,7 +502,7 @@ double AnimationNodeBlendSpace2D::process(double p_time, bool p_seek) {
for (int j = 0; j < 3; j++) {
if (i == triangle_points[j]) {
//blend with the given weight
double t = blend_node(blend_points[i].name, blend_points[i].node, p_time, p_seek, blend_weights[j], FILTER_IGNORE, false);
double t = blend_node(blend_points[i].name, blend_points[i].node, p_time, p_seek, p_seek_root, blend_weights[j], FILTER_IGNORE, false);
if (first || t < mind) {
mind = t;
first = false;
Expand All @@ -514,7 +514,7 @@ double AnimationNodeBlendSpace2D::process(double p_time, bool p_seek) {

if (!found) {
//ignore
blend_node(blend_points[i].name, blend_points[i].node, p_time, p_seek, 0, FILTER_IGNORE, false);
blend_node(blend_points[i].name, blend_points[i].node, p_time, p_seek, p_seek_root, 0, FILTER_IGNORE, false);
}
}
} else {
Expand All @@ -539,16 +539,16 @@ double AnimationNodeBlendSpace2D::process(double p_time, bool p_seek) {
na_n->set_backward(na_c->is_backward());
}
//see how much animation remains
from = length_internal - blend_node(blend_points[closest].name, blend_points[closest].node, p_time, false, 0.0, FILTER_IGNORE, false);
from = length_internal - blend_node(blend_points[closest].name, blend_points[closest].node, p_time, false, p_seek_root, 0.0, FILTER_IGNORE, false);
}

mind = blend_node(blend_points[new_closest].name, blend_points[new_closest].node, from, true, 1.0, FILTER_IGNORE, false);
mind = blend_node(blend_points[new_closest].name, blend_points[new_closest].node, from, true, p_seek_root, 1.0, FILTER_IGNORE, false);
length_internal = from + mind;

closest = new_closest;

} else {
mind = blend_node(blend_points[closest].name, blend_points[closest].node, p_time, p_seek, 1.0, FILTER_IGNORE, false);
mind = blend_node(blend_points[closest].name, blend_points[closest].node, p_time, p_seek, p_seek_root, 1.0, FILTER_IGNORE, false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion scene/animation/animation_blend_space_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class AnimationNodeBlendSpace2D : public AnimationRootNode {
void set_y_label(const String &p_label);
String get_y_label() const;

virtual double process(double p_time, bool p_seek) override;
virtual double process(double p_time, bool p_seek, bool p_seek_root) override;
virtual String get_caption() const override;

Vector2 get_closest_point(const Vector2 &p_point);
Expand Down
Loading