EditorMaterialComponent.h 3.7 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. #pragma once
  9. #include <Atom/Feature/Utils/EditorRenderComponentAdapter.h>
  10. #include <AtomLyIntegration/CommonFeatures/Material/MaterialComponentBus.h>
  11. #include <AtomLyIntegration/CommonFeatures/Material/MaterialComponentConstants.h>
  12. #include <Material/EditorMaterialComponentSlot.h>
  13. #include <Material/MaterialComponent.h>
  14. namespace AZ
  15. {
  16. namespace Render
  17. {
  18. //! In-editor material component for displaying and editing material assignments.
  19. class EditorMaterialComponent final
  20. : public EditorRenderComponentAdapter<MaterialComponentController, MaterialComponent, MaterialComponentConfig>
  21. , public MaterialComponentNotificationBus::Handler
  22. {
  23. public:
  24. friend class JsonEditorMaterialComponentSerializer;
  25. using BaseClass = EditorRenderComponentAdapter<MaterialComponentController, MaterialComponent, MaterialComponentConfig>;
  26. AZ_EDITOR_COMPONENT(EditorMaterialComponent, EditorMaterialComponentTypeId, BaseClass);
  27. static void Reflect(AZ::ReflectContext* context);
  28. static bool ConvertVersion(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement);
  29. EditorMaterialComponent() = default;
  30. EditorMaterialComponent(const MaterialComponentConfig& config);
  31. private:
  32. // BaseClass overrides ...
  33. void Activate() override;
  34. void Deactivate() override;
  35. void AddContextMenuActions(QMenu* menu) override;
  36. //! Called when you want to change the game asset through code (like when creating components based on assets).
  37. void SetPrimaryAsset(const AZ::Data::AssetId& assetId) override;
  38. AZ::u32 OnConfigurationChanged() override;
  39. //! MaterialComponentNotificationBus::Handler overrides...
  40. void OnMaterialSlotLayoutChanged() override;
  41. void OnMaterialsCreated(const MaterialAssignmentMap& materials) override;
  42. // AzToolsFramework::EditorEntityVisibilityNotificationBus::Handler overrides
  43. void OnEntityVisibilityChanged(bool visibility) override;
  44. // Regenerates the editor component material slots based on the material and
  45. // LOD mapping from the model or other consumer of materials.
  46. // If any corresponding material assignments are found in the component
  47. // controller configuration then those values will be assigned to the editor component slots.
  48. void UpdateMaterialSlots();
  49. // Opens the source material export dialog and updates editor material slots based on
  50. // selected actions
  51. AZ::u32 OpenMaterialExporterFromRPE();
  52. AZ::u32 OpenMaterialExporter(const AzToolsFramework::EntityIdSet& entityIdsToEdit);
  53. AZ::u32 OnLodsToggled();
  54. // Get the visibility of the LOD material slots based on the enable flag
  55. AZ::Crc32 GetLodVisibility() const;
  56. AZStd::string GetLabelForLod(int lodIndex) const;
  57. EditorMaterialComponentSlot m_defaultMaterialSlot;
  58. EditorMaterialComponentSlotContainer m_materialSlots;
  59. EditorMaterialComponentSlotsByLodContainer m_materialSlotsByLod;
  60. bool m_materialSlotsByLodEnabled = false;
  61. static const char* GenerateMaterialsButtonText;
  62. static const char* GenerateMaterialsToolTipText;
  63. static const char* ResetMaterialsButtonText;
  64. static const char* ResetMaterialsToolTipText;
  65. };
  66. } // namespace Render
  67. } // namespace AZ