From aeb43c4012fd23ebf9cbe1a4758250c86d15a8f9 Mon Sep 17 00:00:00 2001 From: santorac <55155825+santorac@users.noreply.github.com> Date: Wed, 26 Jan 2022 13:04:28 -0800 Subject: [PATCH] Fixed up a few small things to get Material Editor working again. Signed-off-by: santorac <55155825+santorac@users.noreply.github.com> --- .../Materials/Special/ShadowCatcher.materialtype | 1 - .../RPI.Edit/Material/MaterialTypeSourceData.h | 11 ++++------- .../Code/Source/Document/MaterialDocument.cpp | 14 +++++++------- .../Material/EditorMaterialComponentUtil.cpp | 6 +++--- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Special/ShadowCatcher.materialtype b/Gems/Atom/Feature/Common/Assets/Materials/Special/ShadowCatcher.materialtype index 937abe656d..973f8b2147 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Special/ShadowCatcher.materialtype +++ b/Gems/Atom/Feature/Common/Assets/Materials/Special/ShadowCatcher.materialtype @@ -2,7 +2,6 @@ "description": "Base material for the reflection probe visualization model.", "version": 1, "propertyLayout": { - "version": 1, "propertySets": [ { "name": "settings", 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 4fae3f710e..b5e7eecd0d 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 @@ -76,6 +76,7 @@ namespace AZ static const float DefaultMax; static const float DefaultStep; + // TODO: Consider making this private and readonly because it is used as the key for lookups and collision validation. AZStd::string m_name; //!< The name of the property within the property group. The full property ID will be groupName.propertyName. MaterialPropertyVisibility m_visibility = MaterialPropertyVisibility::Default; @@ -213,9 +214,9 @@ namespace AZ AZStd::string m_description; //< TODO: Make this private //! Version 1 is the default and should not contain any version update. - uint32_t m_version = 1; + uint32_t m_version = 1; //< TODO: Make this private - VersionUpdates m_versionUpdates; + VersionUpdates m_versionUpdates; //< TODO: Make this private //! A list of shader variants that are always used at runtime; they cannot be turned off AZStd::vector m_shaderCollection; //< TODO: Make this private @@ -283,11 +284,7 @@ namespace AZ MaterialTypeAssetCreator& materialTypeAssetCreator, AZStd::vector& propertyNameContext, const MaterialTypeSourceData::PropertySet* propertySet) const; - - //! Possibly renames @propertyId based on the material version update steps. - //! @return true if the property was renamed - bool ApplyPropertyRenames(MaterialPropertyId& propertyId) const; - + //! Construct a complete list of group definitions, including implicit groups, arranged in the same order as the source data. //! Groups with the same name will be consolidated into a single entry. //! Operates on the old format PropertyLayout::m_groups, used for conversion to the new format. diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocument.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocument.cpp index 8d6eaf0633..c9ae970215 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocument.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocument.cpp @@ -585,11 +585,11 @@ namespace MaterialEditor bool result = true; // populate sourceData with properties that meet the filter - m_materialTypeSourceData.EnumerateProperties([this, &sourceData, &propertyFilter, &result](const AZStd::string& propertyIdContext, const auto& propertyDefinition) { + m_materialTypeSourceData.EnumerateProperties([&](const AZStd::string& propertyIdContext, const auto& propertyDefinition) { - const AZStd::string propertyId = propertyIdContext + propertyDefinition->m_name; + Name propertyId{propertyIdContext + propertyDefinition->m_name}; - const auto it = m_properties.find(Name{propertyId}); + const auto it = m_properties.find(propertyId); if (it != m_properties.end() && propertyFilter(it->second)) { MaterialPropertyValue propertyValue = AtomToolsFramework::ConvertToRuntimeType(it->second.GetValue()); @@ -603,7 +603,7 @@ namespace MaterialEditor } // TODO: Support populating the Material Editor with nested property sets, not just the top level. - const AZStd::string groupName = propertyId.substr(0, propertyId.size() - propertyDefinition->m_name.size() - 1); + const AZStd::string groupName = propertyId.GetStringView().substr(0, propertyId.GetStringView().size() - propertyDefinition->m_name.size() - 1); sourceData.m_properties[groupName][propertyDefinition->m_name].m_value = propertyValue; } } @@ -897,12 +897,12 @@ namespace MaterialEditor return false; } } - + bool enumerateResult = m_materialTypeSourceData.EnumeratePropertySets( - [this, &materialTypeSourceFilePath](const AZStd::string&, const MaterialTypeSourceData::PropertySet* propertySet) + [this](const AZStd::string&, const MaterialTypeSourceData::PropertySet* propertySet) { const MaterialFunctorSourceData::EditorContext editorContext = MaterialFunctorSourceData::EditorContext( - materialTypeSourceFilePath, m_materialAsset->GetMaterialPropertiesLayout()); + m_materialSourceData.m_materialType, m_materialAsset->GetMaterialPropertiesLayout()); for (Ptr functorData : propertySet->GetFunctors()) { diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentUtil.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentUtil.cpp index 96cf02c6f9..d6342a2507 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentUtil.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentUtil.cpp @@ -122,7 +122,7 @@ namespace AZ AZ::RPI::MaterialPropertyValue propertyValue = editData.m_materialAsset->GetPropertyValues()[propertyIndex.GetIndex()]; - AZ::RPI::MaterialPropertyValue propertyValueDefault = propertyDefinition.m_value; + AZ::RPI::MaterialPropertyValue propertyValueDefault = propertyDefinition->m_value; if (editData.m_materialParentAsset.IsReady()) { propertyValueDefault = editData.m_materialParentAsset->GetPropertyValues()[propertyIndex.GetIndex()]; @@ -135,7 +135,7 @@ namespace AZ propertyValue = AZ::RPI::MaterialPropertyValue::FromAny(propertyOverrideItr->second); } - if (!AtomToolsFramework::ConvertToExportFormat(path, propertyId, propertyDefinition, propertyValue)) + if (!AtomToolsFramework::ConvertToExportFormat(path, propertyId, *propertyDefinition, propertyValue)) { AZ_Error("AZ::Render::EditorMaterialComponentUtil", false, "Failed to export: %s", path.c_str()); result = false; @@ -151,7 +151,7 @@ namespace AZ // TODO: Support populating the Material Editor with nested property sets, not just the top level. const AZStd::string groupName = propertyId.GetStringView().substr(0, propertyId.GetStringView().size() - propertyDefinition->m_name.size() - 1); - exportData.m_properties[groupName][propertyDefinition.m_name].m_value = propertyValue; + exportData.m_properties[groupName][propertyDefinition->m_name].m_value = propertyValue; return true; });