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 Dec 6, 2019
1 parent a87a871 commit b5fb7ce
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 @@ -890,7 +890,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 @@ -949,25 +948,17 @@ 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.linear_interpolate(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.linear_interpolate(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 @@ -198,7 +198,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 b5fb7ce

Please sign in to comment.