EditorMaterialComponentUtil.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/RPI.Edit/Material/MaterialSourceData.h>
  10. #include <Atom/RPI.Edit/Material/MaterialTypeSourceData.h>
  11. #include <Atom/RPI.Reflect/Material/MaterialAsset.h>
  12. #include <Atom/RPI.Reflect/Material/MaterialTypeAsset.h>
  13. #include <AtomLyIntegration/CommonFeatures/Material/MaterialAssignment.h>
  14. #include <AzCore/Asset/AssetCommon.h>
  15. #include <AzCore/std/string/string.h>
  16. #include <AzToolsFramework/Entity/EntityTypes.h>
  17. namespace AZ
  18. {
  19. namespace Render
  20. {
  21. namespace EditorMaterialComponentUtil
  22. {
  23. static constexpr AZStd::string_view MaterialExtension("material");
  24. static constexpr AZStd::string_view MaterialTypeExtension("materialtype");
  25. static constexpr AZStd::string_view MaterialGraphExtension("materialgraph");
  26. static constexpr AZStd::string_view MaterialGraphNodeExtension("materialgraphnode");
  27. static constexpr AZStd::string_view MaterialGraphTemplateExtension("materialgraphtemplate");
  28. static constexpr AZStd::string_view ShaderExtension("shader");
  29. static constexpr AZStd::string_view MaterialExtensionWithDot(".material");
  30. static constexpr AZStd::string_view MaterialTypeExtensionWithDot(".materialtype");
  31. static constexpr AZStd::string_view MaterialGraphExtensionWithDot(".materialgraph");
  32. static constexpr AZStd::string_view MaterialGraphNodeExtensionWithDot(".materialgraphnode");
  33. static constexpr AZStd::string_view MaterialGraphTemplateExtensionWithDot(".materialgraphtemplate");
  34. static constexpr AZStd::string_view ShaderExtensionWithDot(".shader");
  35. struct MaterialEditData
  36. {
  37. AZ::Data::AssetId m_materialAssetId = {};
  38. AZ::Data::Asset<AZ::RPI::MaterialAsset> m_materialAsset = {};
  39. AZ::Data::Asset<AZ::RPI::MaterialTypeAsset> m_materialTypeAsset = {};
  40. AZ::Data::Asset<AZ::RPI::MaterialAsset> m_materialParentAsset = {};
  41. AZ::RPI::MaterialSourceData m_materialSourceData;
  42. AZ::RPI::MaterialTypeSourceData m_materialTypeSourceData;
  43. AZStd::string m_materialSourcePath;
  44. AZStd::string m_materialTypeSourcePath;
  45. AZStd::string m_originalMaterialTypeSourcePath;
  46. AZStd::string m_materialParentSourcePath;
  47. MaterialPropertyOverrideMap m_materialPropertyOverrideMap = {};
  48. };
  49. bool LoadMaterialEditDataFromAssetId(const AZ::Data::AssetId& assetId, MaterialEditData& editData);
  50. bool SaveSourceMaterialFromEditData(const AZStd::string& path, const MaterialEditData& editData);
  51. //! Retrieves the material type asset ID for a given material asset ID
  52. AZ::Data::AssetId GetMaterialTypeAssetIdFromMaterialAssetId(const AZ::Data::AssetId& materialAssetId);
  53. //! Determines if a set of entities have the same active material type on a given material slot
  54. //! @param primaryEntityId The entity whose material types will be compared against all others in the set
  55. //! @param secondaryEntityIds Set of entities that will be compared against material types on the primaryEntityId
  56. //! @param materialAssignmentId ID of the material type slot that will be tested for quality
  57. //! @returns True if all of the entities share the same active material type asset on the specified slot
  58. bool DoEntitiesHaveMatchingMaterialTypes(
  59. const AZ::EntityId& primaryEntityId,
  60. const AzToolsFramework::EntityIdSet& secondaryEntityIds,
  61. const MaterialAssignmentId& materialAssignmentId);
  62. //! Determines if a set of entities have the same active material on a given material slot
  63. //! @param primaryEntityId The entity whose materials will be compared against all others in the set
  64. //! @param secondaryEntityIds Set of entities that will be compared against materials on the primaryEntityId
  65. //! @param materialAssignmentId ID of the material slot that will be tested for quality
  66. //! @returns True if all of the entities share the same active material asset on the specified slot
  67. bool DoEntitiesHaveMatchingMaterials(
  68. const AZ::EntityId& primaryEntityId,
  69. const AzToolsFramework::EntityIdSet& secondaryEntityIds,
  70. const MaterialAssignmentId& materialAssignmentId);
  71. //! Determines if a set of entities have the same material slot configuration, LODs, etc
  72. //! @param primaryEntityId The entity whose material slots will be compared against all others in the set
  73. //! @param secondaryEntityIds Set of entities that will be compared against material slots on the primaryEntityId
  74. //! @returns True if all of the entities share the same material slot configuration
  75. bool DoEntitiesHaveMatchingMaterialSlots(const AZ::EntityId& primaryEntityId, const AzToolsFramework::EntityIdSet& entityIds);
  76. //! Returns the set of entities selected or pinned in the active entity inspector
  77. //! This function is only reliable when called from context menu or edit context attribute handlers guaranteed to be called from
  78. //! within the inspector
  79. AzToolsFramework::EntityIdSet GetSelectedEntitiesFromActiveInspector();
  80. //! Removes all entries from a set of entity IDs that do not have the same material slot configuration as the primary entity
  81. //! @param primaryEntityId The entity whose material slots will be compared against all others in the set
  82. //! @param secondaryEntityIds Set of entities that will be compared against material slots on the primaryEntityId
  83. //! @returns All of the entity IDs contained within secondaryEntityIds except for the ones whose materials did not match
  84. //! primaryEntityId
  85. AzToolsFramework::EntityIdSet GetEntitiesMatchingMaterialSlots(
  86. const AZ::EntityId& primaryEntityId, const AzToolsFramework::EntityIdSet& secondaryEntityIds);
  87. } // namespace EditorMaterialComponentUtil
  88. } // namespace Render
  89. } // namespace AZ