TestActorAssets.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 <AzCore/IO/SystemFile.h>
  9. #include <AzCore/std/containers/vector.h>
  10. #include <AzFramework/StringFunc/StringFunc.h>
  11. #include <EMotionFX/Source/Actor.h>
  12. #include <EMotionFX/Source/Importer/Importer.h>
  13. #include <Tests/TestAssetCode/TestActorAssets.h>
  14. #include <Tests/TestAssetCode/ActorFactory.h>
  15. #include <Tests/TestAssetCode/JackActor.h>
  16. namespace EMotionFX
  17. {
  18. AZStd::string TestActorAssets::FileToBase64(const char* filePath)
  19. {
  20. AZ::IO::SystemFile systemFile;
  21. if (systemFile.Open(filePath, AZ::IO::SystemFile::SF_OPEN_READ_ONLY))
  22. {
  23. const size_t sizeInBytes = systemFile.Length();
  24. AZStd::vector<AZ::u8> dataToEncode;
  25. dataToEncode.resize(sizeInBytes);
  26. systemFile.Read(sizeInBytes, dataToEncode.begin());
  27. return AzFramework::StringFunc::Base64::Encode(dataToEncode.begin(), sizeInBytes);
  28. }
  29. return AZStd::string();
  30. }
  31. AZ::Data::Asset<Integration::ActorAsset> TestActorAssets::GetAssetFromActor(const AZ::Data::AssetId& assetId, AZStd::unique_ptr<Actor>&& actor)
  32. {
  33. AZ::Data::Asset<Integration::ActorAsset> actorAsset = AZ::Data::AssetManager::Instance().CreateAsset<Integration::ActorAsset>(assetId);
  34. actorAsset.GetAs<Integration::ActorAsset>()->SetData(AZStd::move(actor));
  35. return actorAsset;
  36. }
  37. } // namespace EMotionFX