Module.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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/Memory/SystemAllocator.h>
  9. #include <AzCore/Module/Module.h>
  10. #include <System/SystemComponent.h>
  11. #include <System/FabricCooker.h>
  12. #include <System/TangentSpaceHelper.h>
  13. #include <Components/ClothComponent.h>
  14. #ifdef NVCLOTH_EDITOR
  15. #include <Editor/EditorSystemComponent.h>
  16. #include <Components/EditorClothComponent.h>
  17. #include <Pipeline/SceneAPIExt/ClothRuleBehavior.h>
  18. #endif //NVCLOTH_EDITOR
  19. namespace NvCloth
  20. {
  21. class Module
  22. : public AZ::Module
  23. {
  24. public:
  25. AZ_RTTI(Module, "{34C529D4-688F-4B51-BF60-75425754A7E6}", AZ::Module);
  26. AZ_CLASS_ALLOCATOR(Module, AZ::SystemAllocator);
  27. Module()
  28. : AZ::Module()
  29. {
  30. SystemComponent::InitializeNvClothLibrary();
  31. // IFabricCooker and ITangentSpaceHelper interfaces will be available
  32. // at both runtime and asset build time.
  33. m_fabricCooker = AZStd::make_unique<FabricCooker>();
  34. m_tangentSpaceHelper = AZStd::make_unique<TangentSpaceHelper>();
  35. // Push results of [MyComponent]::CreateDescriptor() into m_descriptors here.
  36. m_descriptors.insert(m_descriptors.end(), {
  37. SystemComponent::CreateDescriptor(),
  38. ClothComponent::CreateDescriptor(),
  39. #ifdef NVCLOTH_EDITOR
  40. EditorSystemComponent::CreateDescriptor(),
  41. EditorClothComponent::CreateDescriptor(),
  42. Pipeline::ClothRuleBehavior::CreateDescriptor(),
  43. #endif //NVCLOTH_EDITOR
  44. });
  45. }
  46. ~Module()
  47. {
  48. m_tangentSpaceHelper.reset();
  49. m_fabricCooker.reset();
  50. SystemComponent::TearDownNvClothLibrary();
  51. }
  52. /**
  53. * Add required SystemComponents to the SystemEntity.
  54. */
  55. AZ::ComponentTypeList GetRequiredSystemComponents() const override
  56. {
  57. return AZ::ComponentTypeList{
  58. azrtti_typeid<SystemComponent>()
  59. #ifdef NVCLOTH_EDITOR
  60. , azrtti_typeid<EditorSystemComponent>()
  61. #endif //NVCLOTH_EDITOR
  62. };
  63. }
  64. private:
  65. AZStd::unique_ptr<FabricCooker> m_fabricCooker;
  66. AZStd::unique_ptr<TangentSpaceHelper> m_tangentSpaceHelper;
  67. };
  68. } // namespace NvCloth
  69. #if defined(O3DE_GEM_NAME)
  70. AZ_DECLARE_MODULE_CLASS(AZ_JOIN(Gem_, O3DE_GEM_NAME), NvCloth::Module)
  71. #else
  72. AZ_DECLARE_MODULE_CLASS(Gem_NvCloth, NvCloth::Module)
  73. #endif