SceneProcessingModule.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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/Module/Module.h>
  9. #include <AzCore/Module/DynamicModuleHandle.h>
  10. #include <AzFramework/Metrics/MetricsPlainTextNameRegistration.h>
  11. #include <SceneBuilder/SceneBuilderComponent.h>
  12. #include <SceneBuilder/SceneSerializationHandler.h>
  13. #include <Config/Components/SceneProcessingConfigSystemComponent.h>
  14. #include <Config/Components/SoftNameBehavior.h>
  15. #include <Config/Widgets/GraphTypeSelector.h>
  16. #include <Generation/Components/TangentGenerator/TangentGenerateComponent.h>
  17. #include <Generation/Components/TangentGenerator/TangentPreExportComponent.h>
  18. #include <Generation/Components/UVsGenerator/UVsGenerateComponent.h>
  19. #include <Generation/Components/UVsGenerator/UVsPreExportComponent.h>
  20. #include <Generation/Components/MeshOptimizer/MeshOptimizerComponent.h>
  21. #include <Source/SceneProcessingModule.h>
  22. namespace AZ
  23. {
  24. namespace SceneProcessing
  25. {
  26. class SceneProcessingModule
  27. : public Module
  28. {
  29. public:
  30. AZ_RTTI(SceneProcessingModule, "{13DCFEF2-BB25-4DBB-A69B-22958CAD6885}", Module);
  31. SceneProcessingModule()
  32. : Module()
  33. {
  34. LoadSceneModule(s_sceneCoreModule, "SceneCore");
  35. LoadSceneModule(s_sceneDataModule, "SceneData");
  36. LoadSceneModule(s_sceneBuilderModule, "SceneBuilder");
  37. m_descriptors.insert(m_descriptors.end(),
  38. {
  39. SceneProcessingConfig::SceneProcessingConfigSystemComponent::CreateDescriptor(),
  40. SceneProcessingConfig::SoftNameBehavior::CreateDescriptor(),
  41. SceneBuilder::BuilderPluginComponent::CreateDescriptor(),
  42. SceneBuilder::SceneSerializationHandler::CreateDescriptor(),
  43. AZ::SceneGenerationComponents::TangentPreExportComponent::CreateDescriptor(),
  44. AZ::SceneGenerationComponents::TangentGenerateComponent::CreateDescriptor(),
  45. AZ::SceneGenerationComponents::CreateUVsGenerateComponentDescriptor(),
  46. AZ::SceneGenerationComponents::CreateUVsPreExportComponentDescriptor(),
  47. AZ::SceneGenerationComponents::MeshOptimizerComponent::CreateDescriptor(),
  48. });
  49. // This is an internal Amazon gem, so register it's components for metrics tracking, otherwise the name of the component won't get sent back.
  50. // IF YOU ARE A THIRDPARTY WRITING A GEM, DO NOT REGISTER YOUR COMPONENTS WITH EditorMetricsComponentRegistrationBus
  51. AZStd::vector<AZ::Uuid> typeIds;
  52. typeIds.reserve(m_descriptors.size());
  53. for (AZ::ComponentDescriptor* descriptor : m_descriptors)
  54. {
  55. typeIds.emplace_back(descriptor->GetUuid());
  56. }
  57. AzFramework::MetricsPlainTextNameRegistrationBus::Broadcast(&AzFramework::MetricsPlainTextNameRegistrationBus::Events::RegisterForNameSending, typeIds);
  58. }
  59. ~SceneProcessingModule()
  60. {
  61. UnloadModule(s_sceneBuilderModule);
  62. UnloadModule(s_sceneDataModule);
  63. UnloadModule(s_sceneCoreModule);
  64. }
  65. AZ::ComponentTypeList GetRequiredSystemComponents() const override
  66. {
  67. return AZ::ComponentTypeList
  68. {
  69. azrtti_typeid<SceneProcessingConfig::SceneProcessingConfigSystemComponent>(),
  70. };
  71. }
  72. void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  73. {
  74. provided.push_back(AZ_CRC("SceneConfiguration", 0x2a3785fb));
  75. }
  76. void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  77. {
  78. incompatible.push_back(AZ_CRC("SceneConfiguration", 0x2a3785fb));
  79. }
  80. protected:
  81. void LoadSceneModule(AZStd::unique_ptr<DynamicModuleHandle>& module, const char* name)
  82. {
  83. if (!module)
  84. {
  85. module = DynamicModuleHandle::Create(name);
  86. if (module)
  87. {
  88. module->Load();
  89. auto init = module->GetFunction<InitializeDynamicModuleFunction>(InitializeDynamicModuleFunctionName);
  90. if (init)
  91. {
  92. (*init)();
  93. }
  94. }
  95. }
  96. }
  97. void UnloadModule(AZStd::unique_ptr<DynamicModuleHandle>& module)
  98. {
  99. if (module)
  100. {
  101. auto uninit = module->GetFunction<UninitializeDynamicModuleFunction>(UninitializeDynamicModuleFunctionName);
  102. if (uninit)
  103. {
  104. (*uninit)();
  105. }
  106. module.reset();
  107. }
  108. }
  109. };
  110. } // namespace SceneProcessing
  111. } // namespace AZ
  112. #if defined(O3DE_GEM_NAME)
  113. AZ_DECLARE_MODULE_CLASS(AZ_JOIN(Gem_, O3DE_GEM_NAME, _Editor), AZ::SceneProcessing::SceneProcessingModule)
  114. #else
  115. AZ_DECLARE_MODULE_CLASS(Gem_SceneProcessing_Editor, AZ::SceneProcessing::SceneProcessingModule)
  116. #endif