From 9bab5134cfd4f0095545ae58fcf6a10dc07dc7d1 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Wed, 27 Jun 2018 16:30:48 -0300 Subject: [PATCH] The way multiple quaternions being slerped was not good, changed approach to one that seems to work better. --- editor/plugins/root_motion_editor_plugin.cpp | 3 ++- scene/animation/animation_tree.cpp | 10 +++++++++- scene/animation/animation_tree.h | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/editor/plugins/root_motion_editor_plugin.cpp b/editor/plugins/root_motion_editor_plugin.cpp index e316116b43b..89c1b3a9784 100644 --- a/editor/plugins/root_motion_editor_plugin.cpp +++ b/editor/plugins/root_motion_editor_plugin.cpp @@ -124,9 +124,10 @@ void EditorPropertyRootMotion::_node_assign() { ti = filters->create_item(ti); parenthood[accum] = ti; ti->set_text(0, F->get()); - ti->set_selectable(0, false); + ti->set_selectable(0, true); ti->set_editable(0, false); ti->set_icon(0, get_icon("BoneAttachment", "EditorIcons")); + ti->set_metadata(0, accum); } else { ti = parenthood[accum]; } diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index 62f2726f754..1e583db6763 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -813,6 +813,7 @@ 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(); } @@ -876,7 +877,14 @@ void AnimationTree::_process_graph(float p_delta) { continue; t->loc = t->loc.linear_interpolate(loc, blend); - t->rot = t->rot.slerp(rot, 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); } diff --git a/scene/animation/animation_tree.h b/scene/animation/animation_tree.h index 41d67118c19..540c36437a4 100644 --- a/scene/animation/animation_tree.h +++ b/scene/animation/animation_tree.h @@ -161,6 +161,7 @@ private: int bone_idx; Vector3 loc; Quat rot; + float rot_blend_accum; Vector3 scale; TrackCacheTransform() {