ActorAsset.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #pragma once
  9. #include <AzCore/std/smart_ptr/unique_ptr.h>
  10. #include <AzFramework/Asset/SimpleAsset.h>
  11. #include <Integration/Assets/AssetCommon.h>
  12. #include <Integration/Rendering/RenderActor.h>
  13. namespace EMotionFX
  14. {
  15. class Actor;
  16. class ActorInstance;
  17. namespace Integration
  18. {
  19. /**
  20. * Represents an EMotionFX actor asset.
  21. * Each asset maintains storage of the original EMotionFX binary asset (via EMotionFXAsset base class).
  22. * Initialization of the asset constructs Open 3D Engine rendering objects, such as the render mesh and material,
  23. * directly from the instantiated EMotionFX actor.
  24. * An easy future memory optimization is to wipe the EMotionFXAsset buffer after the actor, render meshes,
  25. * and materials are created, since it's technically no longer necessary. At this stage it's worth keeping
  26. * around for testing.
  27. */
  28. class ActorAsset
  29. : public EMotionFXAsset
  30. {
  31. public:
  32. friend class ActorAssetHandler;
  33. AZ_RTTI(ActorAsset, "{F67CC648-EA51-464C-9F5D-4A9CE41A7F86}", EMotionFXAsset)
  34. AZ_CLASS_ALLOCATOR_DECL
  35. ActorAsset(AZ::Data::AssetId id = AZ::Data::AssetId());
  36. using ActorInstancePtr = EMotionFXPtr<EMotionFX::ActorInstance>;
  37. ActorInstancePtr CreateInstance(AZ::Entity* entity);
  38. Actor* GetActor() const { return m_emfxActor.get(); }
  39. RenderActor* GetRenderActor() const { return m_renderActor.get(); }
  40. void SetData(AZStd::shared_ptr<Actor> actor);
  41. void InitRenderActor();
  42. private:
  43. AZStd::shared_ptr<Actor> m_emfxActor;
  44. AZStd::unique_ptr<RenderActor> m_renderActor;
  45. };
  46. /**
  47. * Asset handler for loading and initializing actor assets.
  48. * The OnInitAsset stage constructs Open 3D Engine render meshes and materials by extracting
  49. * said data from the EMotionFX actor.
  50. */
  51. class ActorAssetHandler
  52. : public EMotionFXAssetHandler<ActorAsset>
  53. {
  54. public:
  55. AZ_CLASS_ALLOCATOR_DECL
  56. bool OnInitAsset(const AZ::Data::Asset<AZ::Data::AssetData>& asset) override;
  57. AZ::Data::AssetType GetAssetType() const override;
  58. void GetAssetTypeExtensions(AZStd::vector<AZStd::string>& extensions) override;
  59. AZ::Uuid GetComponentTypeId() const override;
  60. const char* GetAssetTypeDisplayName() const override;
  61. const char* GetBrowserIcon() const override;
  62. int GetAssetTypeDragAndDropCreationPriority() const override;
  63. };
  64. } // namespace Integration
  65. using ActorAssetData = AZ::Data::Asset<Integration::ActorAsset>;
  66. } // namespace EMotionFX
  67. namespace AZ
  68. {
  69. AZ_TYPE_INFO_SPECIALIZE(EMotionFX::Integration::EMotionFXPtr<EMotionFX::Integration::ActorAsset>, "{3F60D391-F1C8-4A40-9946-A2637D088C48}");
  70. AZ_TYPE_INFO_SPECIALIZE(EMotionFX::Integration::EMotionFXPtr<EMotionFX::ActorInstance>, "{169ACF47-3DEF-482A-AB7D-4CC11934D932}");
  71. }