ActorFixture.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 "ActorFixture.h"
  9. #include <MCore/Source/ReflectionSerializer.h>
  10. #include <EMotionFX/Source/Actor.h>
  11. #include <EMotionFX/Source/ActorInstance.h>
  12. #include <EMotionFX/Source/ActorManager.h>
  13. #include <EMotionFX/Source/Importer/Importer.h>
  14. #include <EMotionFX/Source/EMotionFXManager.h>
  15. #include <EMotionFX/Source/SimulatedObjectSetup.h>
  16. #include <Tests/TestAssetCode/JackActor.h>
  17. #include <Tests/TestAssetCode/ActorFactory.h>
  18. #include <Tests/TestAssetCode/TestActorAssets.h>
  19. namespace EMotionFX
  20. {
  21. void ActorFixture::SetUp()
  22. {
  23. SystemComponentFixture::SetUp();
  24. AZ::Data::AssetId actorAssetId("{5060227D-B6F4-422E-BF82-41AAC5F228A5}");
  25. m_actorAsset = TestActorAssets::CreateActorAssetAndRegister<JackNoMeshesActor>(actorAssetId);
  26. m_actorInstance = ActorInstance::Create(GetActor());
  27. }
  28. void ActorFixture::TearDown()
  29. {
  30. if (m_actorInstance)
  31. {
  32. m_actorInstance->Destroy();
  33. m_actorInstance = nullptr;
  34. }
  35. m_actorAsset.Reset();
  36. GetEMotionFX().GetActorManager()->UnregisterAllActors();
  37. SystemComponentFixture::TearDown();
  38. }
  39. AZStd::string ActorFixture::SerializePhysicsSetup(const Actor* actor) const
  40. {
  41. if (!actor)
  42. {
  43. return AZStd::string();
  44. }
  45. return MCore::ReflectionSerializer::Serialize(actor->GetPhysicsSetup().get()).GetValue();
  46. }
  47. AZStd::string ActorFixture::SerializeSimulatedObjectSetup(const Actor* actor) const
  48. {
  49. if (!actor)
  50. {
  51. return AZStd::string();
  52. }
  53. return MCore::ReflectionSerializer::Serialize(actor->GetSimulatedObjectSetup().get()).GetValue();
  54. }
  55. SimulatedObjectSetup* ActorFixture::DeserializeSimulatedObjectSetup(const AZStd::string& data) const
  56. {
  57. AZ::SerializeContext* serializeContext = nullptr;
  58. AZ::ComponentApplicationBus::BroadcastResult(serializeContext, &AZ::ComponentApplicationBus::Events::GetSerializeContext);
  59. if (!serializeContext)
  60. {
  61. AZ_Error("EMotionFX", false, "Can't get serialize context from component application.");
  62. return nullptr;
  63. }
  64. AZ::ObjectStream::FilterDescriptor loadFilter(nullptr, AZ::ObjectStream::FILTERFLAG_IGNORE_UNKNOWN_CLASSES);
  65. SimulatedObjectSetup* setup = AZ::Utils::LoadObjectFromBuffer<EMotionFX::SimulatedObjectSetup>(data.data(), data.size(), serializeContext, loadFilter);
  66. setup->InitAfterLoad(GetActor());
  67. return setup;
  68. }
  69. AZStd::vector<AZStd::string> ActorFixture::GetTestJointNames() const
  70. {
  71. return { "Bip01__pelvis", "l_upLeg", "l_loLeg", "l_ankle" };
  72. }
  73. Actor* ActorFixture::GetActor() const
  74. {
  75. return m_actorAsset->GetActor();
  76. }
  77. } // namespace EMotionFX