MotionAsset.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 <Integration/Assets/MotionAsset.h>
  9. #include <EMotionFX/Source/EMotionFXManager.h>
  10. #include <EMotionFX/Source/Importer/Importer.h>
  11. #include <EMotionFX/Source/Motion.h>
  12. namespace EMotionFX
  13. {
  14. namespace Integration
  15. {
  16. AZ_CLASS_ALLOCATOR_IMPL(MotionAsset, EMotionFXAllocator);
  17. AZ_CLASS_ALLOCATOR_IMPL(MotionAssetHandler, EMotionFXAllocator);
  18. MotionAsset::MotionAsset(AZ::Data::AssetId id)
  19. : EMotionFXAsset(id)
  20. {}
  21. //////////////////////////////////////////////////////////////////////////
  22. void MotionAsset::SetData(EMotionFX::Motion* motion)
  23. {
  24. m_emfxMotion.reset(motion);
  25. m_status = AZ::Data::AssetData::AssetStatus::Ready;
  26. }
  27. //////////////////////////////////////////////////////////////////////////
  28. bool MotionAssetHandler::OnInitAsset(const AZ::Data::Asset<AZ::Data::AssetData>& asset)
  29. {
  30. MotionAsset* assetData = asset.GetAs<MotionAsset>();
  31. assetData->m_emfxMotion = EMotionFXPtr<EMotionFX::Motion>::MakeFromNew(EMotionFX::GetImporter().LoadMotion(
  32. assetData->m_emfxNativeData.data(),
  33. assetData->m_emfxNativeData.size(),
  34. nullptr));
  35. if (assetData->m_emfxMotion)
  36. {
  37. assetData->m_emfxMotion->SetIsOwnedByRuntime(true);
  38. }
  39. assetData->ReleaseEMotionFXData();
  40. AZ_Error("EMotionFX", assetData->m_emfxMotion, "Failed to initialize motion asset %s", asset.GetHint().c_str());
  41. return (assetData->m_emfxMotion);
  42. }
  43. //////////////////////////////////////////////////////////////////////////
  44. AZ::Data::AssetType MotionAssetHandler::GetAssetType() const
  45. {
  46. return azrtti_typeid<MotionAsset>();
  47. }
  48. //////////////////////////////////////////////////////////////////////////
  49. void MotionAssetHandler::GetAssetTypeExtensions(AZStd::vector<AZStd::string>& extensions)
  50. {
  51. extensions.push_back("motion");
  52. }
  53. //////////////////////////////////////////////////////////////////////////
  54. const char* MotionAssetHandler::GetAssetTypeDisplayName() const
  55. {
  56. return "EMotion FX Motion";
  57. }
  58. //////////////////////////////////////////////////////////////////////////
  59. const char* MotionAssetHandler::GetBrowserIcon() const
  60. {
  61. return "Editor/Images/AssetBrowser/Motion_16.svg";
  62. }
  63. } // namespace Integration
  64. } // namespace EMotionFX