BlendTreeTransformNodeTests.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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/AnimGraph.h>
  10. #include <EMotionFX/Source/AnimGraphStateMachine.h>
  11. #include <EMotionFX/Source/BlendTree.h>
  12. #include <EMotionFX/Source/BlendTreeFinalNode.h>
  13. #include <EMotionFX/Source/BlendTreeTransformNode.h>
  14. #include <EMotionFX/Source/BlendTreeParameterNode.h>
  15. #include <EMotionFX/Source/EMotionFXManager.h>
  16. #include <EMotionFX/Source/Parameter/FloatSliderParameter.h>
  17. #include <EMotionFX/Source/Parameter/ParameterFactory.h>
  18. #include <Tests/Printers.h>
  19. namespace EMotionFX
  20. {
  21. class BlendTreeTransformNodeTests : public AnimGraphFixture
  22. {
  23. public:
  24. void ConstructGraph() override
  25. {
  26. AnimGraphFixture::ConstructGraph();
  27. m_blendTreeAnimGraph = AnimGraphFactory::Create<OneBlendTreeNodeAnimGraph>();
  28. m_rootStateMachine = m_blendTreeAnimGraph->GetRootStateMachine();
  29. m_blendTree = m_blendTreeAnimGraph->GetBlendTreeNode();
  30. m_transformNode = aznew BlendTreeTransformNode();
  31. BlendTreeFinalNode* finalNode = aznew BlendTreeFinalNode();
  32. BlendTreeParameterNode* parameterNode = aznew BlendTreeParameterNode();
  33. m_blendTree->AddChildNode(m_transformNode);
  34. m_blendTree->AddChildNode(finalNode);
  35. m_blendTree->AddChildNode(parameterNode);
  36. m_transformNode->SetTargetNodeName("rootJoint");
  37. m_transformNode->SetMinTranslation(AZ::Vector3::CreateZero());
  38. m_transformNode->SetMaxTranslation(AZ::Vector3(10.0f, 0.0f, 0.0f));
  39. {
  40. Parameter* parameter = ParameterFactory::Create(azrtti_typeid<FloatSliderParameter>());
  41. parameter->SetName("translate_amount");
  42. m_blendTreeAnimGraph->AddParameter(parameter);
  43. }
  44. finalNode->AddUnitializedConnection(m_transformNode, BlendTreeTransformNode::PORTID_OUTPUT_POSE, BlendTreeFinalNode::PORTID_INPUT_POSE);
  45. m_transformNode->AddUnitializedConnection(parameterNode, 0, BlendTreeTransformNode::PORTID_INPUT_TRANSLATE_AMOUNT);
  46. m_blendTreeAnimGraph->InitAfterLoading();
  47. }
  48. void SetUp() override
  49. {
  50. AnimGraphFixture::SetUp();
  51. m_animGraphInstance->Destroy();
  52. m_animGraphInstance = m_blendTreeAnimGraph->GetAnimGraphInstance(m_actorInstance, m_motionSet);
  53. }
  54. BlendTree* m_blendTree;
  55. BlendTreeTransformNode* m_transformNode;
  56. };
  57. // Basic test that just evaluates the node. Since the node is not doing anything,
  58. // The pose should not be affected.
  59. TEST_F(BlendTreeTransformNodeTests, Evaluate)
  60. {
  61. Evaluate();
  62. ASSERT_EQ(Transform::CreateIdentity(), GetOutputTransform());
  63. }
  64. // Set some values to validate that the node is transforming the root
  65. TEST_F(BlendTreeTransformNodeTests, EvalauteTranslationBlending)
  66. {
  67. MCore::AttributeFloat* translate_amount = m_animGraphInstance->GetParameterValueChecked<MCore::AttributeFloat>(0);
  68. translate_amount->SetValue(0.0f);
  69. Evaluate();
  70. Transform outputRoot = GetOutputTransform();
  71. Transform expected = Transform::CreateIdentity();
  72. ASSERT_EQ(expected, outputRoot);
  73. translate_amount->SetValue(0.5f);
  74. Evaluate();
  75. expected.m_position = AZ::Vector3(5.0f, 0.0f, 0.0f);
  76. outputRoot = GetOutputTransform();
  77. ASSERT_EQ(expected, outputRoot);
  78. translate_amount->SetValue(1.0f);
  79. Evaluate();
  80. expected.m_position = AZ::Vector3(10.0f, 0.0f, 0.0f);
  81. outputRoot = GetOutputTransform();
  82. ASSERT_EQ(expected, outputRoot);
  83. }
  84. } // end namespace EMotionFX