EditorMaterialComponentInspector.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. #if !defined(Q_MOC_RUN)
  10. #include <AtomLyIntegration/CommonFeatures/Material/EditorMaterialSystemComponentNotificationBus.h>
  11. #include <AtomLyIntegration/CommonFeatures/Material/MaterialComponentBus.h>
  12. #include <AtomToolsFramework/DynamicProperty/DynamicPropertyGroup.h>
  13. #include <AtomToolsFramework/Inspector/InspectorWidget.h>
  14. #include <AzCore/Asset/AssetCommon.h>
  15. #include <AzCore/Component/EntityBus.h>
  16. #include <AzCore/Component/TickBus.h>
  17. #include <AzCore/std/containers/unordered_map.h>
  18. #include <AzCore/std/containers/vector.h>
  19. #include <AzCore/std/function/function_base.h>
  20. #include <AzCore/std/string/string.h>
  21. #include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI_Internals.h>
  22. #include <Material/EditorMaterialComponentUtil.h>
  23. #endif
  24. class QLabel;
  25. namespace AZ
  26. {
  27. namespace Render
  28. {
  29. namespace EditorMaterialComponentInspector
  30. {
  31. //! Inspector window for displaying and editing entity material instance properties
  32. //! If multiple entities are selected and pinned to this inspector then their corresponding properties will also be updated
  33. class MaterialPropertyInspector
  34. : public AtomToolsFramework::InspectorWidget
  35. , public AzToolsFramework::IPropertyEditorNotify
  36. , public AZ::EntitySystemBus::Handler
  37. , public AZ::SystemTickBus::Handler
  38. , public MaterialComponentNotificationBus::MultiHandler
  39. , public EditorMaterialSystemComponentNotificationBus::Handler
  40. {
  41. Q_OBJECT
  42. public:
  43. AZ_CLASS_ALLOCATOR(MaterialPropertyInspector, AZ::SystemAllocator);
  44. MaterialPropertyInspector(QWidget* parent = nullptr);
  45. ~MaterialPropertyInspector() override;
  46. //! Loads the material edit data for the active material on the primary entity ID.
  47. //! The function will fail and return false if the data cannot be loaded or the rest of the entities are not compatible with
  48. //! the primary entity materials.
  49. bool LoadMaterial(
  50. const AZ::EntityId& primaryEntityId,
  51. const AzToolsFramework::EntityIdSet& entityIdsToEdit,
  52. const AZ::Render::MaterialAssignmentId& materialAssignmentId);
  53. //! Releases all of the edit data and assets, clearing the inspector of all content
  54. void UnloadMaterial();
  55. //! Returns true if all of the edit data has been loaded, the instance has been created, the primary entity and material
  56. //! slot has not changed the assigned material, and all of the entities share the same material type
  57. bool IsLoaded() const;
  58. // AtomToolsFramework::InspectorRequestBus::Handler overrides...
  59. void Reset() override;
  60. //! Builds all of the properties and generates the user interface for the inspector
  61. void Populate();
  62. AZStd::string GetRelativePath(const AZStd::string& path) const;
  63. AZStd::string GetFileName(const AZStd::string& path) const;
  64. bool IsSourceMaterial(const AZStd::string& path) const;
  65. bool SaveMaterial(const AZStd::string& path) const;
  66. void OpenMenu();
  67. const EditorMaterialComponentUtil::MaterialEditData& GetEditData() const;
  68. private:
  69. AZ::Data::AssetId GetActiveMaterialAssetIdFromEntity() const;
  70. // AzToolsFramework::IPropertyEditorNotify overrides...
  71. void BeforePropertyModified([[maybe_unused]] AzToolsFramework::InstanceDataNode* pNode) override{};
  72. void AfterPropertyModified(AzToolsFramework::InstanceDataNode* pNode) override;
  73. void SetPropertyEditingActive([[maybe_unused]] AzToolsFramework::InstanceDataNode* pNode) override{};
  74. void SetPropertyEditingComplete(AzToolsFramework::InstanceDataNode* pNode) override;
  75. void SealUndoStack() override{};
  76. void RequestPropertyContextMenu([[maybe_unused]] AzToolsFramework::InstanceDataNode*, const QPoint&) override{};
  77. void PropertySelectionChanged([[maybe_unused]] AzToolsFramework::InstanceDataNode*, bool) override{};
  78. // AZ::EntitySystemBus::Handler overrides...
  79. void OnEntityInitialized(const AZ::EntityId& entityId) override;
  80. void OnEntityDestroyed(const AZ::EntityId& entityId) override;
  81. void OnEntityActivated(const AZ::EntityId& entityId) override;
  82. void OnEntityDeactivated(const AZ::EntityId& entityId) override;
  83. void OnEntityNameChanged(const AZ::EntityId& entityId, const AZStd::string& name) override;
  84. //! AZ::SystemTickBus::Handler overrides...
  85. void OnSystemTick() override;
  86. //! MaterialComponentNotificationBus::MultiHandler overrides...
  87. void OnMaterialsEdited() override;
  88. //! EditorMaterialSystemComponentNotificationBus::Handler overrides...
  89. void OnRenderMaterialPreviewReady(
  90. const AZ::EntityId& entityId,
  91. const AZ::Render::MaterialAssignmentId& materialAssignmentId,
  92. const QPixmap& pixmap) override;
  93. void UpdateUI();
  94. void CreateHeading();
  95. void UpdateHeading();
  96. void AddUvNamesGroup();
  97. void AddPropertiesGroup();
  98. void LoadOverridesFromEntity();
  99. void SaveOverrideToEntities(const AtomToolsFramework::DynamicProperty& property, bool commitChanges);
  100. void RunEditorMaterialFunctors();
  101. void UpdateMaterialInstanceProperty(const AtomToolsFramework::DynamicProperty& property);
  102. bool AddEditorMaterialFunctors(
  103. const AZStd::vector<AZ::RPI::Ptr<AZ::RPI::MaterialFunctorSourceDataHolder>>& functorSourceDataHolders,
  104. const AZ::RPI::MaterialNameContext& nameContext);
  105. AZ::Crc32 GetGroupSaveStateKey(const AZStd::string& groupName) const;
  106. bool IsInstanceNodePropertyModifed(const AzToolsFramework::InstanceDataNode* node) const;
  107. const char* GetInstanceNodePropertyIndicator(const AzToolsFramework::InstanceDataNode* node) const;
  108. AZ::EntityId m_primaryEntityId;
  109. AzToolsFramework::EntityIdSet m_entityIdsToEdit;
  110. AZ::Render::MaterialAssignmentId m_materialAssignmentId;
  111. EditorMaterialComponentUtil::MaterialEditData m_editData;
  112. AZ::Data::Instance<AZ::RPI::Material> m_materialInstance = {};
  113. AZStd::vector<AZ::RPI::Ptr<AZ::RPI::MaterialFunctor>> m_editorFunctors = {};
  114. AZ::RPI::MaterialPropertyFlags m_dirtyPropertyFlags = {};
  115. AZStd::unordered_map<AZStd::string, AtomToolsFramework::DynamicPropertyGroup> m_groups = {};
  116. bool m_internalEditNotification = {};
  117. bool m_updateUI = {};
  118. bool m_updatePreview = {};
  119. QLabel* m_overviewText = {};
  120. QLabel* m_overviewImage = {};
  121. };
  122. } // namespace EditorMaterialComponentInspector
  123. } // namespace Render
  124. } // namespace AZ