JackGraphFixture.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 "JackGraphFixture.h"
  9. #include <EMotionFX/Source/Actor.h>
  10. #include <EMotionFX/Source/ActorInstance.h>
  11. #include <EMotionFX/Source/AnimGraph.h>
  12. #include <EMotionFX/Source/AnimGraphInstance.h>
  13. #include <EMotionFX/Source/AnimGraphStateMachine.h>
  14. #include <EMotionFX/Source/MotionSet.h>
  15. #include <EMotionFX/Source/Node.h>
  16. #include <EMotionFX/Source/Importer/Importer.h>
  17. #include <EMotionFX/Source/EMotionFXManager.h>
  18. #include <EMotionFX/Source/Parameter/ParameterFactory.h>
  19. #include <MCore/Source/ReflectionSerializer.h>
  20. #include <AzCore/IO/SystemFile.h>
  21. #include <AzFramework/StringFunc/StringFunc.h>
  22. #include <Tests/TestAssetCode/JackActor.h>
  23. #include <Tests/TestAssetCode/ActorFactory.h>
  24. namespace EMotionFX
  25. {
  26. void JackGraphFixture::SetUp()
  27. {
  28. SystemComponentFixture::SetUp();
  29. m_actor = ActorFactory::CreateAndInit<JackNoMeshesActor>();
  30. OnPostActorCreated();
  31. m_actorInstance = ActorInstance::Create(m_actor.get());
  32. m_motionSet = aznew MotionSet("motionSet");
  33. ConstructGraph();
  34. m_animGraph->InitAfterLoading();
  35. m_animGraphInstance = AnimGraphInstance::Create(m_animGraph.get(), m_actorInstance, m_motionSet);
  36. m_actorInstance->SetAnimGraphInstance(m_animGraphInstance);
  37. m_animGraphInstance->IncreaseReferenceCount(); // Two owners now, the test and the actor instance
  38. m_animGraphInstance->RecursiveInvalidateUniqueDatas();
  39. }
  40. void JackGraphFixture::ConstructGraph()
  41. {
  42. m_animGraph = AnimGraphFactory::Create<EmptyAnimGraph>();
  43. }
  44. void JackGraphFixture::TearDown()
  45. {
  46. if (m_animGraphInstance)
  47. {
  48. m_animGraphInstance->Destroy();
  49. m_animGraphInstance = nullptr;
  50. }
  51. if (m_actorInstance)
  52. {
  53. m_actorInstance->Destroy();
  54. m_actorInstance = nullptr;
  55. }
  56. delete m_motionSet;
  57. m_motionSet = nullptr;
  58. m_animGraph.reset();
  59. m_actor.reset();
  60. SystemComponentFixture::TearDown();
  61. }
  62. void JackGraphFixture::Evaluate(float timeDelta)
  63. {
  64. GetEMotionFX().Update(timeDelta);
  65. }
  66. void JackGraphFixture::AddValueParameter(const AZ::TypeId& typeId, const AZStd::string& name)
  67. {
  68. Parameter* parameter = ParameterFactory::Create(typeId);
  69. parameter->SetName(name);
  70. m_animGraph->AddParameter(parameter);
  71. m_animGraphInstance->AddMissingParameterValues();
  72. }
  73. } // namespace EMotionFX