Skip to content

Commit

Permalink
Fix Incorrect/Non-linear blending in AnimationTree
Browse files Browse the repository at this point in the history
  • Loading branch information
marstaik committed Jan 20, 2021
1 parent 8a6d4dd commit 2b5fb6e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
21 changes: 6 additions & 15 deletions scene/animation/animation_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,6 @@ void AnimationTree::_process_graph(float p_delta) {
t->process_pass = process_pass;
t->loc = Vector3();
t->rot = Quat();
t->rot_blend_accum = 0;
t->scale = Vector3(1, 1, 1);
}

Expand Down Expand Up @@ -911,26 +910,18 @@ void AnimationTree::_process_graph(float p_delta) {

if (t->process_pass != process_pass) {
t->process_pass = process_pass;
t->loc = loc;
t->rot = rot;
t->rot_blend_accum = 0;
t->scale = scale;
t->loc = Vector3();
t->rot = Quat();
t->scale = Vector3();
}

if (err != OK) {
continue;
}

t->loc = t->loc.lerp(loc, blend);
if (t->rot_blend_accum == 0) {
t->rot = rot;
t->rot_blend_accum = blend;
} else {
float rot_total = t->rot_blend_accum + blend;
t->rot = rot.slerp(t->rot, t->rot_blend_accum / rot_total).normalized();
t->rot_blend_accum = rot_total;
}
t->scale = t->scale.lerp(scale, blend);
t->loc += loc * blend;
t->rot = (t->rot * Quat().slerp(rot, blend)).normalized();
t->scale += scale * blend;
}

} break;
Expand Down
1 change: 0 additions & 1 deletion scene/animation/animation_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ class AnimationTree : public Node {
int bone_idx;
Vector3 loc;
Quat rot;
float rot_blend_accum;
Vector3 scale;

TrackCacheTransform() {
Expand Down

0 comments on commit 2b5fb6e

Please sign in to comment.