diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Edit/Material/MaterialTypeSourceData.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Edit/Material/MaterialTypeSourceData.h index 9aa31af97a..ef14555061 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Edit/Material/MaterialTypeSourceData.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Edit/Material/MaterialTypeSourceData.h @@ -285,7 +285,8 @@ namespace AZ //! Return false to terminate the traversal. using EnumeratePropertyGroupsCallback = AZStd::function; //! Recursively traverses all of the property groups contained in the material type, executing a callback function for each. @@ -296,7 +297,7 @@ namespace AZ //! Return false to terminate the traversal. using EnumeratePropertiesCallback = AZStd::function; //! Recursively traverses all of the properties contained in the material type, executing a callback function for each. @@ -318,8 +319,8 @@ namespace AZ PropertyDefinition* FindProperty(AZStd::span parsedPropertyId, AZStd::span> inPropertyGroupList); // Function overloads for recursion, returns false to indicate that recursion should end. - bool EnumeratePropertyGroups(const EnumeratePropertyGroupsCallback& callback, MaterialNameContext materialNameContext, const AZStd::vector>& inPropertyGroupList) const; - bool EnumerateProperties(const EnumeratePropertiesCallback& callback, MaterialNameContext materialNameContext, const AZStd::vector>& inPropertyGroupList) const; + bool EnumeratePropertyGroups(const EnumeratePropertyGroupsCallback& callback, MaterialNameContext nameContext, const AZStd::vector>& inPropertyGroupList) const; + bool EnumerateProperties(const EnumeratePropertiesCallback& callback, MaterialNameContext nameContext, const AZStd::vector>& inPropertyGroupList) const; static MaterialNameContext ExtendNameContext(MaterialNameContext nameContext, const MaterialTypeSourceData::PropertyGroup& propertyGroup); diff --git a/Gems/Atom/RPI/Code/Source/RPI.Edit/Material/MaterialTypeSourceData.cpp b/Gems/Atom/RPI/Code/Source/RPI.Edit/Material/MaterialTypeSourceData.cpp index 725041eab4..874039d605 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Edit/Material/MaterialTypeSourceData.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Edit/Material/MaterialTypeSourceData.cpp @@ -377,18 +377,18 @@ namespace AZ return parts; } - bool MaterialTypeSourceData::EnumeratePropertyGroups(const EnumeratePropertyGroupsCallback& callback, MaterialNameContext materialNameContext, const AZStd::vector>& inPropertyGroupList) const + bool MaterialTypeSourceData::EnumeratePropertyGroups(const EnumeratePropertyGroupsCallback& callback, MaterialNameContext nameContext, const AZStd::vector>& inPropertyGroupList) const { for (auto& propertyGroup : inPropertyGroupList) { - MaterialNameContext materialNameContext2 = ExtendNameContext(materialNameContext, *propertyGroup); + MaterialNameContext groupNameContext = ExtendNameContext(nameContext, *propertyGroup); - if (!callback(propertyGroup.get(), materialNameContext2)) + if (!callback(propertyGroup.get(), groupNameContext, nameContext)) { - return false; // Stop processing + return false; // Stop processing } - if (!EnumeratePropertyGroups(callback, materialNameContext2, propertyGroup->m_propertyGroups)) + if (!EnumeratePropertyGroups(callback, groupNameContext, propertyGroup->m_propertyGroups)) { return false; // Stop processing } @@ -407,21 +407,21 @@ namespace AZ return EnumeratePropertyGroups(callback, {}, m_propertyLayout.m_propertyGroups); } - bool MaterialTypeSourceData::EnumerateProperties(const EnumeratePropertiesCallback& callback, MaterialNameContext materialNameContext, const AZStd::vector>& inPropertyGroupList) const + bool MaterialTypeSourceData::EnumerateProperties(const EnumeratePropertiesCallback& callback, MaterialNameContext nameContext, const AZStd::vector>& inPropertyGroupList) const { for (auto& propertyGroup : inPropertyGroupList) { - MaterialNameContext materialNameContext2 = ExtendNameContext(materialNameContext, *propertyGroup); + MaterialNameContext groupNameContext = ExtendNameContext(nameContext, *propertyGroup); for (auto& property : propertyGroup->m_properties) { - if (!callback(property.get(), materialNameContext2)) + if (!callback(property.get(), groupNameContext)) { return false; // Stop processing } } - if (!EnumerateProperties(callback, materialNameContext2, propertyGroup->m_propertyGroups)) + if (!EnumerateProperties(callback, groupNameContext, propertyGroup->m_propertyGroups)) { return false; // Stop processing } diff --git a/Gems/Atom/RPI/Code/Tests/Material/MaterialTypeSourceDataTests.cpp b/Gems/Atom/RPI/Code/Tests/Material/MaterialTypeSourceDataTests.cpp index 04b55b3aaf..46cbb1ac46 100644 --- a/Gems/Atom/RPI/Code/Tests/Material/MaterialTypeSourceDataTests.cpp +++ b/Gems/Atom/RPI/Code/Tests/Material/MaterialTypeSourceDataTests.cpp @@ -487,24 +487,30 @@ namespace UnitTest struct EnumeratePropertyGroupsResult { const MaterialTypeSourceData::PropertyGroup* m_propertyGroup; - MaterialNameContext m_materialNameContext; + MaterialNameContext m_groupNameContext; + MaterialNameContext m_parentNameContext; void Check(AZStd::string expectedIdContext, const MaterialTypeSourceData::PropertyGroup* expectedPropertyGroup) { Name groupFullId{m_propertyGroup->GetName()}; - m_materialNameContext.ContextualizeProperty(groupFullId); + m_parentNameContext.ContextualizeProperty(groupFullId); AZStd::string expectedPropertyId = expectedIdContext + expectedPropertyGroup->GetName(); EXPECT_EQ(expectedPropertyId, groupFullId.GetStringView()); EXPECT_EQ(expectedPropertyGroup, m_propertyGroup); + + Name imaginaryPropertyName{"someChildProperty"}; + m_groupNameContext.ContextualizeProperty(imaginaryPropertyName); + EXPECT_EQ(AZStd::string(groupFullId.GetStringView()) + ".someChildProperty", imaginaryPropertyName.GetStringView()); } }; AZStd::vector enumeratePropertyGroupsResults; - sourceData.EnumeratePropertyGroups([&enumeratePropertyGroupsResults](const MaterialTypeSourceData::PropertyGroup* propertyGroup, const MaterialNameContext& nameContext) + sourceData.EnumeratePropertyGroups([&enumeratePropertyGroupsResults]( + const MaterialTypeSourceData::PropertyGroup* propertyGroup, const MaterialNameContext& groupNameContext, const MaterialNameContext& parentNameContext) { - enumeratePropertyGroupsResults.push_back(EnumeratePropertyGroupsResult{propertyGroup, nameContext}); + enumeratePropertyGroupsResults.push_back(EnumeratePropertyGroupsResult{propertyGroup, groupNameContext, parentNameContext}); return true; }); diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocument.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocument.cpp index 9349ad4dc9..e4a99b73ed 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocument.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocument.cpp @@ -783,7 +783,8 @@ namespace MaterialEditor // Populate the property map from a combination of source data and assets // Assets must still be used for now because they contain the final accumulated value after all other materials // in the hierarchy are applied - m_materialTypeSourceData.EnumeratePropertyGroups([this, &parentPropertyValues](const MaterialTypeSourceData::PropertyGroup* propertyGroup, const MaterialNameContext& nameContext) + m_materialTypeSourceData.EnumeratePropertyGroups([this, &parentPropertyValues]( + const MaterialTypeSourceData::PropertyGroup* propertyGroup, const MaterialNameContext& groupNameContext, const MaterialNameContext& /*parentNameContext*/) { AtomToolsFramework::DynamicPropertyConfig propertyConfig; @@ -791,7 +792,7 @@ namespace MaterialEditor { // Assign id before conversion so it can be used in dynamic description propertyConfig.m_id = propertyDefinition->GetName(); - nameContext.ContextualizeProperty(propertyConfig.m_id); + groupNameContext.ContextualizeProperty(propertyConfig.m_id); const auto& propertyIndex = m_materialAsset->GetMaterialPropertiesLayout()->FindPropertyIndex(propertyConfig.m_id); const bool propertyIndexInBounds = propertyIndex.IsValid() && propertyIndex.GetIndex() < m_materialAsset->GetPropertyValues().size(); @@ -905,10 +906,10 @@ namespace MaterialEditor // Add any material functors that are located inside each property group. bool enumerateResult = m_materialTypeSourceData.EnumeratePropertyGroups( - [this](const MaterialTypeSourceData::PropertyGroup* propertyGroup, const MaterialNameContext& nameContext) + [this](const MaterialTypeSourceData::PropertyGroup* propertyGroup, const MaterialNameContext& groupNameContext, const MaterialNameContext& /*parentNameContext*/) { const MaterialFunctorSourceData::EditorContext editorContext = MaterialFunctorSourceData::EditorContext( - m_materialSourceData.m_materialType, m_materialAsset->GetMaterialPropertiesLayout(), &nameContext); + m_materialSourceData.m_materialType, m_materialAsset->GetMaterialPropertiesLayout(), &groupNameContext); for (Ptr functorData : propertyGroup->GetFunctors()) {