Updated MaterialPropertyId class in preparation for nested material property sets.

Here the class has been generalized for a list of group names and a final property name, rather than assuming a single group containing the property. This included removing the unused GetPropertyName and GetGroupName functions. All that's really need from this class is conversion to a full property ID string.

Testing:
New unit test.
Reprocessed all core material types and StandardPBR test materials used in Atom Sample Viewer's material screenshot test.
Atom Sample Viewer material screenshot test script.

Signed-off-by: santorac <55155825+santorac@users.noreply.github.com>
This commit is contained in:
santorac
2021-09-18 23:57:52 -07:00
parent 71c7fc0217
commit 55eb85d546
11 changed files with 216 additions and 63 deletions
@@ -27,63 +27,84 @@ namespace AZ
bool MaterialPropertyId::IsValid() const
{
const bool groupNameIsValid = m_groupName.IsEmpty() || IsValidName(m_groupName);
const bool propertyNameIsValid = IsValidName(m_propertyName);
return groupNameIsValid && propertyNameIsValid;
return !m_fullName.IsEmpty();
}
MaterialPropertyId MaterialPropertyId::Parse(AZStd::string_view fullPropertyId)
{
AZStd::vector<AZStd::string> tokens;
AzFramework::StringFunc::Tokenize(fullPropertyId.data(), tokens, '.', true, true);
AzFramework::StringFunc::Tokenize(fullPropertyId, tokens, '.', true, true);
if (tokens.size() == 1)
if (tokens.empty())
{
return MaterialPropertyId{"", tokens[0]};
AZ_Error("MaterialPropertyId", false, "Property ID is empty.", fullPropertyId.data());
return MaterialPropertyId{};
}
else if (tokens.size() == 2)
for (const auto& token : tokens)
{
return MaterialPropertyId{tokens[0], tokens[1]};
if (!IsValidName(token))
{
AZ_Error("MaterialPropertyId", false, "Property ID '%.*s' is not a valid identifier.", AZ_STRING_ARG(fullPropertyId));
return MaterialPropertyId{};
}
}
MaterialPropertyId id;
id.m_fullName = fullPropertyId;
return id;
}
MaterialPropertyId::MaterialPropertyId(AZStd::string_view propertyName)
{
if (!IsValidName(propertyName))
{
AZ_Error("MaterialPropertyId", false, "Property name '%.*s' is not a valid identifier.", AZ_STRING_ARG(propertyName));
}
else
{
AZ_Error("MaterialPropertyId", false, "Property ID '%s' is not a valid identifier.", fullPropertyId.data());
return MaterialPropertyId{};
m_fullName = propertyName;
}
}
MaterialPropertyId::MaterialPropertyId(AZStd::string_view groupName, AZStd::string_view propertyName)
: MaterialPropertyId(Name{groupName}, Name{propertyName})
{
}
MaterialPropertyId::MaterialPropertyId(const Name& groupName, const Name& propertyName)
{
AZ_Error("MaterialPropertyId", groupName.IsEmpty() || IsValidName(groupName), "Group name '%s' is not a valid identifier.", groupName.GetCStr());
AZ_Error("MaterialPropertyId", IsValidName(propertyName), "Property name '%s' is not a valid identifier.", propertyName.GetCStr());
m_groupName = groupName;
m_propertyName = propertyName;
if (groupName.IsEmpty())
if (!IsValidName(groupName))
{
m_fullName = m_propertyName.GetStringView();
AZ_Error("MaterialPropertyId", false, "Group name '%.*s' is not a valid identifier.", AZ_STRING_ARG(groupName));
}
else if (!IsValidName(propertyName))
{
AZ_Error("MaterialPropertyId", false, "Property name '%.*s' is not a valid identifier.", AZ_STRING_ARG(propertyName));
}
else
{
m_fullName = AZStd::string::format("%s.%s", m_groupName.GetCStr(), m_propertyName.GetCStr());
m_fullName = AZStd::string::format("%.*s.%.*s", AZ_STRING_ARG(groupName), AZ_STRING_ARG(propertyName));
}
}
const Name& MaterialPropertyId::GetGroupName() const
MaterialPropertyId::MaterialPropertyId(const Name& groupName, const Name& propertyName)
: MaterialPropertyId(groupName.GetStringView(), propertyName.GetStringView())
{
return m_groupName;
}
MaterialPropertyId::MaterialPropertyId(const AZStd::array_view<AZStd::string> names)
{
for (const auto& name : names)
{
if (!IsValidName(name))
{
AZ_Error("MaterialPropertyId", false, "'%s' is not a valid identifier.", name.c_str());
return;
}
}
AZStd::string fullName;
AzFramework::StringFunc::Join(fullName, names.begin(), names.end(), ".");
m_fullName = fullName;
}
const Name& MaterialPropertyId::GetPropertyName() const
{
return m_propertyName;
}
const Name& MaterialPropertyId::GetFullName() const
MaterialPropertyId::operator const Name&() const
{
return m_fullName;
}
@@ -130,7 +130,7 @@ namespace AZ
}
else
{
MaterialPropertyIndex propertyIndex = materialAssetCreator.m_materialPropertiesLayout->FindPropertyIndex(propertyId.GetFullName());
MaterialPropertyIndex propertyIndex = materialAssetCreator.m_materialPropertiesLayout->FindPropertyIndex(propertyId);
if (propertyIndex.IsValid())
{
const MaterialPropertyDescriptor* propertyDescriptor = materialAssetCreator.m_materialPropertiesLayout->GetPropertyDescriptor(propertyIndex);
@@ -145,11 +145,11 @@ namespace AZ
auto& imageAsset = imageAssetResult.GetValue();
// Load referenced images when load material
imageAsset.SetAutoLoadBehavior(Data::AssetLoadBehavior::PreLoad);
materialAssetCreator.SetPropertyValue(propertyId.GetFullName(), imageAsset);
materialAssetCreator.SetPropertyValue(propertyId, imageAsset);
}
else
{
materialAssetCreator.ReportError("Material property '%s': Could not find the image '%s'", propertyId.GetFullName().GetCStr(), property.second.m_value.GetValue<AZStd::string>().data());
materialAssetCreator.ReportError("Material property '%s': Could not find the image '%s'", propertyId.GetCStr(), property.second.m_value.GetValue<AZStd::string>().data());
}
}
break;
@@ -163,18 +163,18 @@ namespace AZ
}
else
{
materialAssetCreator.SetPropertyValue(propertyId.GetFullName(), enumValue);
materialAssetCreator.SetPropertyValue(propertyId, enumValue);
}
}
break;
default:
materialAssetCreator.SetPropertyValue(propertyId.GetFullName(), property.second.m_value);
materialAssetCreator.SetPropertyValue(propertyId, property.second.m_value);
break;
}
}
else
{
materialAssetCreator.ReportWarning("Can not find property id '%s' in MaterialPropertyLayout", propertyId.GetFullName().GetStringView().data());
materialAssetCreator.ReportWarning("Can not find property id '%s' in MaterialPropertyLayout", propertyId.GetCStr());
}
}
}
@@ -354,7 +354,7 @@ namespace AZ
continue;
}
materialTypeAssetCreator.BeginMaterialProperty(propertyId.GetFullName(), property.m_dataType);
materialTypeAssetCreator.BeginMaterialProperty(propertyId, property.m_dataType);
if (property.m_dataType == MaterialPropertyDataType::Enum)
{
@@ -404,17 +404,17 @@ namespace AZ
if (imageAssetResult.IsSuccess())
{
materialTypeAssetCreator.SetPropertyValue(propertyId.GetFullName(), imageAssetResult.GetValue());
materialTypeAssetCreator.SetPropertyValue(propertyId, imageAssetResult.GetValue());
}
else
{
materialTypeAssetCreator.ReportError("Material property '%s': Could not find the image '%s'", propertyId.GetFullName().GetCStr(), property.m_value.GetValue<AZStd::string>().data());
materialTypeAssetCreator.ReportError("Material property '%s': Could not find the image '%s'", propertyId.GetCStr(), property.m_value.GetValue<AZStd::string>().data());
}
}
break;
case MaterialPropertyDataType::Enum:
{
MaterialPropertyIndex propertyIndex = materialTypeAssetCreator.GetMaterialPropertiesLayout()->FindPropertyIndex(propertyId.GetFullName());
MaterialPropertyIndex propertyIndex = materialTypeAssetCreator.GetMaterialPropertiesLayout()->FindPropertyIndex(propertyId);
const MaterialPropertyDescriptor* propertyDescriptor = materialTypeAssetCreator.GetMaterialPropertiesLayout()->GetPropertyDescriptor(propertyIndex);
AZ::Name enumName = AZ::Name(property.m_value.GetValue<AZStd::string>());
@@ -425,12 +425,12 @@ namespace AZ
}
else
{
materialTypeAssetCreator.SetPropertyValue(propertyId.GetFullName(), enumValue);
materialTypeAssetCreator.SetPropertyValue(propertyId, enumValue);
}
}
break;
default:
materialTypeAssetCreator.SetPropertyValue(propertyId.GetFullName(), property.m_value);
materialTypeAssetCreator.SetPropertyValue(propertyId, property.m_value);
break;
}
}