3
0

BlendTreeRotationMath2NodeTests.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "AnimGraphFixture.h"
  9. #include <EMotionFX/Source/Actor.h>
  10. #include <EMotionFX/Source/AnimGraph.h>
  11. #include <EMotionFX/Source/AnimGraphStateMachine.h>
  12. #include <EMotionFX/Source/BlendTree.h>
  13. #include <EMotionFX/Source/BlendTreeFinalNode.h>
  14. #include <EMotionFX/Source/BlendTreeParameterNode.h>
  15. #include <EMotionFX/Source/EMotionFXManager.h>
  16. #include <EMotionFX/Source/BlendTreeGetTransformNode.h>
  17. #include <EMotionFX/Source/BlendTreeSetTransformNode.h>
  18. #include <EMotionFX/Source/AnimGraphBindPoseNode.h>
  19. #include <EMotionFX/Source/BlendTreeRotationMath2Node.h>
  20. #include <EMotionFX/Source/Node.h>
  21. #include <EMotionFX/Source/Skeleton.h>
  22. namespace EMotionFX
  23. {
  24. class BlendTreeRotationMath2NodeTests : public AnimGraphFixture
  25. {
  26. public:
  27. void ConstructGraph() override
  28. {
  29. AnimGraphFixture::ConstructGraph();
  30. m_blendTreeAnimGraph = AnimGraphFactory::Create<OneBlendTreeNodeAnimGraph>();
  31. m_rootStateMachine = m_blendTreeAnimGraph->GetRootStateMachine();
  32. m_blendTree = m_blendTreeAnimGraph->GetBlendTreeNode();
  33. AnimGraphBindPoseNode* bindPoseNode = aznew AnimGraphBindPoseNode();
  34. m_getTransformNode = aznew BlendTreeGetTransformNode();
  35. m_rotationMathNode = aznew BlendTreeRotationMath2Node();
  36. m_setTransformNode = aznew BlendTreeSetTransformNode();
  37. BlendTreeFinalNode* finalNode = aznew BlendTreeFinalNode();
  38. m_blendTree->AddChildNode(bindPoseNode);
  39. m_blendTree->AddChildNode(m_getTransformNode);
  40. m_blendTree->AddChildNode(m_rotationMathNode);
  41. m_blendTree->AddChildNode(m_setTransformNode);
  42. m_blendTree->AddChildNode(finalNode);
  43. m_getTransformNode->AddUnitializedConnection(bindPoseNode, AnimGraphBindPoseNode::PORTID_OUTPUT_POSE, BlendTreeFinalNode::PORTID_INPUT_POSE);
  44. m_setTransformNode->AddUnitializedConnection(bindPoseNode, AnimGraphBindPoseNode::PORTID_OUTPUT_POSE, BlendTreeFinalNode::PORTID_INPUT_POSE);
  45. m_rotationMathNode->AddUnitializedConnection(m_getTransformNode, BlendTreeGetTransformNode::OUTPUTPORT_ROTATION, BlendTreeRotationMath2Node::INPUTPORT_X);
  46. m_setTransformNode->AddUnitializedConnection(m_rotationMathNode, BlendTreeRotationMath2Node::OUTPUTPORT_RESULT_QUATERNION, BlendTreeSetTransformNode::INPUTPORT_ROTATION);
  47. finalNode->AddUnitializedConnection(m_setTransformNode, BlendTreeSetTransformNode::PORTID_OUTPUT_POSE, BlendTreeFinalNode::PORTID_INPUT_POSE);
  48. m_blendTreeAnimGraph->InitAfterLoading();
  49. }
  50. void SetUp() override
  51. {
  52. AnimGraphFixture::SetUp();
  53. m_animGraphInstance->Destroy();
  54. m_animGraphInstance = m_blendTreeAnimGraph->GetAnimGraphInstance(m_actorInstance, m_motionSet);
  55. }
  56. BlendTree* m_blendTree = nullptr;
  57. BlendTreeGetTransformNode* m_getTransformNode = nullptr;
  58. BlendTreeRotationMath2Node* m_rotationMathNode = nullptr;
  59. BlendTreeSetTransformNode* m_setTransformNode = nullptr;
  60. };
  61. TEST_F(BlendTreeRotationMath2NodeTests, EvalauteTranslationBlending)
  62. {
  63. const char* firstNodeName = m_actor->GetSkeleton()->GetNode(0)->GetName();
  64. m_getTransformNode->SetJointName(firstNodeName);
  65. m_getTransformNode->InvalidateUniqueData(m_animGraphInstance);
  66. m_setTransformNode->SetJointName(firstNodeName);
  67. m_setTransformNode->InvalidateUniqueData(m_animGraphInstance);
  68. AZ::Quaternion expectedRotation = AZ::Quaternion::CreateRotationY(MCore::Math::pi * 0.25f);
  69. m_rotationMathNode->SetDefaultValue(expectedRotation);
  70. Evaluate();
  71. Transform outputRoot = GetOutputTransform();
  72. Transform expected = Transform::CreateIdentity();
  73. expected.Set(AZ::Vector3::CreateZero(), expectedRotation);
  74. bool success = AZ::IsClose(expected.m_rotation.GetW(), outputRoot.m_rotation.GetW(), 0.0001f);
  75. success = success && AZ::IsClose(expected.m_rotation.GetX(), outputRoot.m_rotation.GetX(), 0.0001f);
  76. success = success && AZ::IsClose(expected.m_rotation.GetY(), outputRoot.m_rotation.GetY(), 0.0001f);
  77. success = success && AZ::IsClose(expected.m_rotation.GetZ(), outputRoot.m_rotation.GetZ(), 0.0001f);
  78. m_rotationMathNode->SetMathFunction(EMotionFX::BlendTreeRotationMath2Node::MATHFUNCTION_INVERSE_MULTIPLY);
  79. expectedRotation = expectedRotation.GetInverseFull();
  80. Evaluate();
  81. outputRoot = GetOutputTransform();
  82. expected.Identity();
  83. expected.Set(AZ::Vector3::CreateZero(), expectedRotation);
  84. success = success && AZ::IsClose(expected.m_rotation.GetW(), outputRoot.m_rotation.GetW(), 0.0001f);
  85. success = success && AZ::IsClose(expected.m_rotation.GetX(), outputRoot.m_rotation.GetX(), 0.0001f);
  86. success = success && AZ::IsClose(expected.m_rotation.GetY(), outputRoot.m_rotation.GetY(), 0.0001f);
  87. success = success && AZ::IsClose(expected.m_rotation.GetZ(), outputRoot.m_rotation.GetZ(), 0.0001f);
  88. ASSERT_TRUE(success);
  89. }
  90. } // end namespace EMotionFX