BuilderComponent.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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/Component/Entity.h>
  9. #include <AzCore/Serialization/EditContext.h>
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. #include <AzCore/Script/ScriptAsset.h>
  12. #include <Atom/RPI.Edit/Material/MaterialTypeSourceData.h>
  13. #include <Atom/RPI.Edit/Material/MaterialSourceData.h>
  14. #include <Atom/RPI.Edit/Material/MaterialPipelineSourceData.h>
  15. #include <Atom/RPI.Edit/Material/MaterialPropertyValueSourceData.h>
  16. #include <Atom/RPI.Edit/Material/MaterialPropertySourceData.h>
  17. #include <Atom/RPI.Edit/Material/MaterialFunctorSourceDataHolder.h>
  18. #include <Atom/RPI.Edit/Material/LuaMaterialFunctorSourceData.h>
  19. #include <Atom/RPI.Edit/Shader/ShaderSourceData.h>
  20. #include <Atom/RPI.Edit/Shader/ShaderVariantListSourceData.h>
  21. #include <Atom/RPI.Edit/Common/AssetAliasesSourceData.h>
  22. #include <Atom/RPI.Reflect/Asset/AssetHandler.h>
  23. #include <Atom/RPI.Reflect/Material/MaterialAsset.h>
  24. #include <Atom/RPI.Reflect/Shader/ShaderAsset.h>
  25. #include <Atom/RPI.Reflect/Image/StreamingImagePoolAsset.h>
  26. #include <Atom/RPI.Reflect/Buffer/BufferAsset.h>
  27. #include <Atom/RPI.Reflect/Model/ModelLodAsset.h>
  28. #include <Atom/RPI.Reflect/Model/ModelAsset.h>
  29. #include <Atom/RPI.Reflect/Model/MorphTargetMetaAsset.h>
  30. #include <Atom/RPI.Reflect/Model/SkinMetaAsset.h>
  31. #include <Atom/RPI.Reflect/Pass/PassAsset.h>
  32. #include <Atom/RPI.Reflect/Shader/ShaderVariantAsset.h>
  33. #include <Atom/RPI.Reflect/Shader/ShaderVariantTreeAsset.h>
  34. #include <BuilderComponent.h>
  35. #include <Common/AnyAssetBuilder.h>
  36. #include <Material/MaterialBuilder.h>
  37. #include <Material/MaterialPipelineScriptRunner.h>
  38. #include <Material/MaterialTypeBuilder.h>
  39. #include <ResourcePool/ResourcePoolBuilder.h>
  40. #include <Pass/PassBuilder.h>
  41. namespace AZ
  42. {
  43. namespace RPI
  44. {
  45. void BuilderComponent::Reflect(AZ::ReflectContext* context)
  46. {
  47. if (auto* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  48. {
  49. serialize->Class<BuilderComponent, AZ::Component>()
  50. ->Version(0)
  51. ->Attribute(AZ::Edit::Attributes::SystemComponentTags, AZStd::vector<AZ::Crc32>({ AssetBuilderSDK::ComponentTags::AssetBuilder }))
  52. ;
  53. }
  54. MaterialPropertySourceData::Reflect(context);
  55. MaterialTypeSourceData::Reflect(context);
  56. MaterialSourceData::Reflect(context);
  57. MaterialPipelineSourceData::Reflect(context);
  58. MaterialPropertyValueSourceData::Reflect(context);
  59. MaterialFunctorSourceData::Reflect(context);
  60. MaterialFunctorSourceDataHolder::Reflect(context);
  61. LuaMaterialFunctorSourceData::Reflect(context);
  62. ResourcePoolSourceData::Reflect(context);
  63. ConvertibleSource::Reflect(context);
  64. AssetAliasesSourceData::Reflect(context);
  65. ShaderSourceData::Reflect(context);
  66. ShaderVariantListSourceData::Reflect(context);
  67. MaterialPipelineScriptRunner::Reflect(context);
  68. }
  69. BuilderComponent::BuilderComponent()
  70. {
  71. m_materialFunctorRegistration.Init();
  72. }
  73. BuilderComponent::~BuilderComponent()
  74. {
  75. m_materialFunctorRegistration.Shutdown();
  76. }
  77. void BuilderComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  78. {
  79. provided.push_back(AZ_CRC_CE("RPIBuilderService"));
  80. }
  81. void BuilderComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  82. {
  83. required.push_back(AZ_CRC_CE("ScriptService"));
  84. }
  85. void BuilderComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  86. {
  87. incompatible.push_back(AZ_CRC_CE("RPIBuilderService"));
  88. }
  89. void BuilderComponent::Activate()
  90. {
  91. // Register asset workers
  92. m_assetWorkers.emplace_back(MakeAssetBuilder<MaterialBuilder>());
  93. m_assetWorkers.emplace_back(MakeAssetBuilder<MaterialTypeBuilder>());
  94. m_assetWorkers.emplace_back(MakeAssetBuilder<ResourcePoolBuilder>());
  95. m_assetWorkers.emplace_back(MakeAssetBuilder<AnyAssetBuilder>());
  96. m_assetWorkers.emplace_back(MakeAssetBuilder<PassBuilder>());
  97. m_assetHandlers.emplace_back(MakeAssetHandler<ShaderAssetHandler>());
  98. m_assetHandlers.emplace_back(MakeAssetHandler<MaterialTypeAssetHandler>());
  99. m_assetHandlers.emplace_back(MakeAssetHandler<MaterialAssetHandler>());
  100. m_assetHandlers.emplace_back(MakeAssetHandler<ResourcePoolAssetHandler>());
  101. m_assetHandlers.emplace_back(MakeAssetHandler<StreamingImagePoolAssetHandler>());
  102. m_assetHandlers.emplace_back(MakeAssetHandler<BufferAssetHandler>());
  103. m_assetHandlers.emplace_back(MakeAssetHandler<ModelLodAssetHandler>());
  104. m_assetHandlers.emplace_back(MakeAssetHandler<ModelAssetHandler>());
  105. m_assetHandlers.emplace_back(MakeAssetHandler<PassAssetHandler>());
  106. m_assetHandlers.emplace_back(MakeAssetHandler<ShaderVariantAssetHandler>());
  107. m_assetHandlers.emplace_back(MakeAssetHandler<ShaderVariantTreeAssetHandler>());
  108. m_assetHandlers.emplace_back(MakeAssetHandler<SkinMetaAssetHandler>());
  109. m_assetHandlers.emplace_back(MakeAssetHandler<MorphTargetMetaAssetHandler>());
  110. }
  111. void BuilderComponent::Deactivate()
  112. {
  113. m_assetHandlers.clear();
  114. m_assetWorkers.clear();
  115. }
  116. } // namespace RPI
  117. } // namespace AZ