SceneProcessingConfigSystemComponent.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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/Component/Component.h>
  10. #include <AzCore/std/smart_ptr/unique_ptr.h>
  11. #include <AzCore/Serialization/SerializeContext.h>
  12. #include <SceneAPI/SceneCore/Components/SceneSystemComponent.h>
  13. #include <Config/SceneProcessingConfigBus.h>
  14. #include <Config/SettingsObjects/SoftNameSetting.h>
  15. #include <SceneAPI/SceneCore/Events/AssetImportRequest.h>
  16. #include <SceneAPI/SceneCore/Events/ScriptConfigEventBus.h>
  17. namespace AZ
  18. {
  19. class DynamicModuleHandle;
  20. namespace SceneProcessingConfig
  21. {
  22. inline constexpr const char* AssetProcessorDefaultScriptsKey{ "/O3DE/AssetProcessor/SceneBuilder/defaultScripts" };
  23. class SceneProcessingConfigSystemComponentSerializationEvents
  24. : public SerializeContext::IEventHandler
  25. {
  26. public:
  27. AZ_CLASS_ALLOCATOR(SceneProcessingConfigSystemComponentSerializationEvents, SystemAllocator);
  28. void OnWriteBegin(void* classPtr) override;
  29. };
  30. class SceneProcessingConfigSystemComponent
  31. : public AZ::SceneAPI::SceneCore::SceneSystemComponent
  32. , protected SceneProcessingConfigRequestBus::Handler
  33. , public AZ::SceneAPI::Events::AssetImportRequestBus::Handler
  34. , public AZ::SceneAPI::Events::ScriptConfigEventBus::Handler
  35. {
  36. public:
  37. AZ_COMPONENT(SceneProcessingConfigSystemComponent, "{80FE1130-91B4-44D4-869F-859BB996161A}", AZ::SceneAPI::SceneCore::SceneSystemComponent);
  38. static constexpr const char AssetProcessorDefaultNodeSoftNameSettingsKey[] = "/O3DE/AssetProcessor/SceneBuilder/NodeSoftNameSettings";
  39. static constexpr const char AssetProcessorDefaultFileSoftNameSettingsKey[] = "/O3DE/AssetProcessor/SceneBuilder/FileSoftNameSettings";
  40. SceneProcessingConfigSystemComponent();
  41. ~SceneProcessingConfigSystemComponent();
  42. void Activate() override;
  43. void Deactivate() override;
  44. void Clear();
  45. // SceneProcessingConfigRequestBus START
  46. const AZStd::vector<AZStd::unique_ptr<SoftNameSetting>>* GetSoftNames() override;
  47. bool AddNodeSoftName(const char* pattern,
  48. SceneAPI::SceneCore::PatternMatcher::MatchApproach approach,
  49. const char* virtualType, bool includeChildren) override;
  50. bool AddFileSoftName(const char* pattern, SceneAPI::SceneCore::PatternMatcher::MatchApproach approach,
  51. const char* virtualType, bool inclusive, const AZStd::string& graphObjectTypeName) override;
  52. // SceneProcessingConfigRequestBus END
  53. // AssetImportRequestBus START
  54. void AreCustomNormalsUsed(bool &value) override;
  55. void GetPolicyName(AZStd::string& result) const override
  56. {
  57. result = "SceneProcessingConfigSystemComponent";
  58. }
  59. // AssetImportRequestBus END
  60. // AZ::SceneAPI::Events::ScriptConfigEventBus START
  61. void GetScriptConfigList(AZStd::vector<SceneAPI::Events::ScriptConfig>& scriptConfigList) const override;
  62. AZStd::optional<SceneAPI::Events::ScriptConfig> MatchesScriptConfig(const AZStd::string& sourceFile) const override;
  63. // AZ::SceneAPI::Events::ScriptConfigEventBus END
  64. static void Reflect(AZ::ReflectContext* context);
  65. static void GetProvidedServices(ComponentDescriptor::DependencyArrayType& provided);
  66. static void GetIncompatibleServices(ComponentDescriptor::DependencyArrayType& incompatible);
  67. static void GetRequiredServices(ComponentDescriptor::DependencyArrayType& required);
  68. static void GetDependentServices(ComponentDescriptor::DependencyArrayType& dependent);
  69. private:
  70. //unique_ptr cannot be copied -> vector of unique_ptrs cannot be copied -> class cannot be copied
  71. SceneProcessingConfigSystemComponent(const SceneProcessingConfigSystemComponent&) = delete;
  72. bool AddSoftName(AZStd::unique_ptr<SoftNameSetting> newSoftname);
  73. void PopulateSoftNameSettings();
  74. template<class SoftNameSettingsType>
  75. bool AddSoftNameSettingsFromSettingsRegistry(
  76. AZ::SettingsRegistryInterface* settingsRegistry, AZStd::string_view settingRegistryKey);
  77. void LoadScriptSettings();
  78. static void ReflectSceneModule(ReflectContext* context, const AZStd::unique_ptr<DynamicModuleHandle>& module);
  79. static void ActivateSceneModule(const AZStd::unique_ptr<DynamicModuleHandle>& module);
  80. static void DeactivateSceneModule(const AZStd::unique_ptr<DynamicModuleHandle>& module);
  81. AZStd::vector<AZ::SceneAPI::Events::ScriptConfig> m_scriptConfigList;
  82. AZStd::vector<AZStd::unique_ptr<SoftNameSetting>> m_softNames;
  83. bool m_UseCustomNormals;
  84. };
  85. } // namespace SceneProcessingConfig
  86. } // namespace AZ