AnimGraphTransitionTests.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 "AnimGraphTransitionFixture.h"
  9. #include <EMotionFX/Source/EMotionFXManager.h>
  10. #include <EMotionFX/Source/AnimGraphStateMachine.h>
  11. #include <EMotionFX/Source/AnimGraphMotionNode.h>
  12. namespace EMotionFX
  13. {
  14. class AnimGraphTransitionFixtureParams
  15. : public AnimGraphTransitionFixture
  16. , public ::testing::WithParamInterface<decltype(&AnimGraphNodeData::GetLocalWeight)>
  17. {
  18. };
  19. TEST_P(AnimGraphTransitionFixtureParams, TestAnimGraphTransitionWeight)
  20. {
  21. static constexpr float fps = 60.0f;
  22. static constexpr float updateInterval = 1.0f / fps;
  23. static constexpr int numIterations = static_cast<int>(3.0f * fps);
  24. // Run the EMotionFX update loop for 3 seconds at 60 fps
  25. for (int i = 0; i < numIterations; ++i)
  26. {
  27. GetEMotionFX().Update(updateInterval);
  28. const AZStd::vector<AnimGraphNode*>& activeStates = m_stateMachine->GetActiveStates(m_animGraphInstance);
  29. float weight = 0.0f;
  30. for (const AnimGraphNode* activeState : activeStates)
  31. {
  32. for (int j = 0; j < 2; ++j)
  33. {
  34. AnimGraphMotionNode* motionNode = (j == 0) ? m_motionNodeA : m_motionNodeB;
  35. // Check if the node is active
  36. if (motionNode == activeState)
  37. {
  38. AnimGraphNodeData* uniqueData = motionNode->FindOrCreateUniqueNodeData(m_animGraphInstance);
  39. weight += (uniqueData->*(GetParam()))();
  40. }
  41. }
  42. }
  43. // The combined weights for the active nodes should be close to 1
  44. EXPECT_FLOAT_EQ(weight, 1.0f) << "frame " << i;
  45. }
  46. }
  47. INSTANTIATE_TEST_CASE_P(TestAnimGraphTransitionWeights, AnimGraphTransitionFixtureParams,
  48. ::testing::Values(
  49. &AnimGraphNodeData::GetLocalWeight,
  50. &AnimGraphNodeData::GetGlobalWeight
  51. )
  52. );
  53. } // end namespace EMotionFX