From e9285410e2c15bf8ae88d88f83bdcaa11e810d69 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 7 Dec 2023 20:27:24 -0600 Subject: [PATCH 1/4] Fix blending additive animations. --- .../Engine/Animations/Graph/AnimGroup.Animation.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp index 6f0d7661b..37e605916 100644 --- a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp +++ b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp @@ -1075,11 +1075,16 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu { tA = nodesA->Nodes[i]; tB = nodesB->Nodes[i]; - t.Translation = tA.Translation + tB.Translation; - t.Orientation = tA.Orientation * tB.Orientation; - t.Scale = tA.Scale * tB.Scale; + t.Translation = tA.Translation * (1 - alpha) + tB.Translation * alpha; + auto originalOrientation = (1 - alpha) * tA.Orientation; + auto additiveOrientation = alpha * tB.Orientation; + if (Quaternion::Dot(originalOrientation, additiveOrientation) < 0) + additiveOrientation *= -1; + t.Orientation = originalOrientation + additiveOrientation; + t.Scale = tA.Scale * (1 - alpha) + tB.Scale * alpha; t.Orientation.Normalize(); - Transform::Lerp(tA, t, alpha, nodes->Nodes[i]); + nodes->Nodes[i] = t; + //Transform::Lerp(tA, t, alpha, nodes->Nodes[i]); } Transform::Lerp(nodesA->RootMotion, nodesA->RootMotion + nodesB->RootMotion, alpha, nodes->RootMotion); value = nodes; From 73074b6e44a69dabb0ec1c7c09290294ccb6f175 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 7 Dec 2023 20:31:18 -0600 Subject: [PATCH 2/4] Enable Transform Lerp --- Source/Engine/Animations/Graph/AnimGroup.Animation.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp index 37e605916..ea4575860 100644 --- a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp +++ b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp @@ -1083,8 +1083,8 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu t.Orientation = originalOrientation + additiveOrientation; t.Scale = tA.Scale * (1 - alpha) + tB.Scale * alpha; t.Orientation.Normalize(); - nodes->Nodes[i] = t; - //Transform::Lerp(tA, t, alpha, nodes->Nodes[i]); + //nodes->Nodes[i] = t; + Transform::Lerp(tA, t, alpha, nodes->Nodes[i]); } Transform::Lerp(nodesA->RootMotion, nodesA->RootMotion + nodesB->RootMotion, alpha, nodes->RootMotion); value = nodes; From 91033a6468eb11f1e707a480ee44e42f61225c27 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 7 Dec 2023 20:51:24 -0600 Subject: [PATCH 3/4] Simplify --- .../Engine/Animations/Graph/AnimGroup.Animation.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp index ea4575860..4d4c7835c 100644 --- a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp +++ b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp @@ -1075,15 +1075,12 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu { tA = nodesA->Nodes[i]; tB = nodesB->Nodes[i]; - t.Translation = tA.Translation * (1 - alpha) + tB.Translation * alpha; + + auto t = tB; auto originalOrientation = (1 - alpha) * tA.Orientation; - auto additiveOrientation = alpha * tB.Orientation; + auto additiveOrientation = alpha * t.Orientation; if (Quaternion::Dot(originalOrientation, additiveOrientation) < 0) - additiveOrientation *= -1; - t.Orientation = originalOrientation + additiveOrientation; - t.Scale = tA.Scale * (1 - alpha) + tB.Scale * alpha; - t.Orientation.Normalize(); - //nodes->Nodes[i] = t; + t.Orientation *= -1; Transform::Lerp(tA, t, alpha, nodes->Nodes[i]); } Transform::Lerp(nodesA->RootMotion, nodesA->RootMotion + nodesB->RootMotion, alpha, nodes->RootMotion); From a6a94d5f77d8cf5edc25984dc4832c9410589632 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 8 Dec 2023 00:59:41 -0600 Subject: [PATCH 4/4] 2nd pass on additive blend math. --- .../Animations/Graph/AnimGroup.Animation.cpp | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp index 4d4c7835c..e8a203a83 100644 --- a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp +++ b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp @@ -1076,11 +1076,28 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu tA = nodesA->Nodes[i]; tB = nodesB->Nodes[i]; - auto t = tB; - auto originalOrientation = (1 - alpha) * tA.Orientation; - auto additiveOrientation = alpha * t.Orientation; - if (Quaternion::Dot(originalOrientation, additiveOrientation) < 0) - t.Orientation *= -1; + // Get Base pose nodes + auto baseNode = _graph.BaseModel.Get()->GetNodes()[i]; + + t.Translation = tA.Translation + (tB.Translation - baseNode.LocalTransform.Translation) * alpha; + + //auto baseOrientation = tA.Orientation; + //Quaternion additiveOrientation = alpha * (tB.Orientation - baseNode.LocalTransform.Orientation); + //t.Orientation = baseOrientation + additiveOrientation; + auto m1 = Matrix::RotationQuaternion(tA.Orientation); + auto m2 = Matrix::RotationQuaternion(alpha * tB.Orientation); + auto m3 = Matrix::RotationQuaternion(alpha * baseNode.LocalTransform.Orientation); + Matrix m4; + Matrix::Subtract(m2, m3, m4); + Matrix m5; + Matrix::Add(m1, m4, m5); + + t.SetRotation(m5); + t.Orientation.Normalize(); + + t.Scale = tA.Scale * tB.Scale; + + //nodes->Nodes[i] = t; Transform::Lerp(tA, t, alpha, nodes->Nodes[i]); } Transform::Lerp(nodesA->RootMotion, nodesA->RootMotion + nodesB->RootMotion, alpha, nodes->RootMotion);