Got the unit tests working again.
I made MaterialAsset::Finalize private so I could add some parameters specifically for MaterialAssetCreator to use. Now MaterialAssetCreator::Begin has an option to finalize the material or not. Moved MaterialAssetCreatorCommon::ValidateDataType to MaterialPropertyDescriptor as "ValidateMaterialPropertyDataType" so that MaterialAsset::Finalize could use it too Signed-off-by: santorac <55155825+santorac@users.noreply.github.com>
This commit is contained in:
@@ -114,13 +114,29 @@ namespace AZ
|
||||
return m_isFinalized;
|
||||
}
|
||||
|
||||
void MaterialAsset::Finalize()
|
||||
void MaterialAsset::Finalize(AZStd::function<void(const char*)> reportWarning, AZStd::function<void(const char*)> reportError)
|
||||
{
|
||||
if (IsFinalized())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!reportWarning)
|
||||
{
|
||||
reportWarning = [](const char* message)
|
||||
{
|
||||
AZ_Warning(s_debugTraceName, false, "%s", message);
|
||||
};
|
||||
}
|
||||
|
||||
if (!reportError)
|
||||
{
|
||||
reportError = [](const char* message)
|
||||
{
|
||||
AZ_Error(s_debugTraceName, false, "%s", message);
|
||||
};
|
||||
}
|
||||
|
||||
const uint32_t materialTypeVersion = m_materialTypeAsset->GetVersion();
|
||||
if (m_materialTypeVersion < materialTypeVersion)
|
||||
{
|
||||
@@ -147,7 +163,7 @@ namespace AZ
|
||||
uint32_t enumValue = propertyDescriptor->GetEnumValue(enumName);
|
||||
if (enumValue == MaterialPropertyDescriptor::InvalidEnumValue)
|
||||
{
|
||||
AZ_Error(s_debugTraceName, false, "Material property name \"%s\" has invalid enum value \"%s\".", name.GetCStr(), enumName.GetCStr());
|
||||
reportWarning(AZStd::string::format("Material property name \"%s\" has invalid enum value \"%s\".", name.GetCStr(), enumName.GetCStr()).c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -164,12 +180,15 @@ namespace AZ
|
||||
}
|
||||
else
|
||||
{
|
||||
finalizedPropertyValues[propertyIndex.GetIndex()] = value;
|
||||
if (ValidateMaterialPropertyDataType(value.GetTypeId(), name, propertyDescriptor, reportError))
|
||||
{
|
||||
finalizedPropertyValues[propertyIndex.GetIndex()] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Warning(s_debugTraceName, false, "Material property name \"%s\" is not found in the material properties layout and will not be used.", name.GetCStr());
|
||||
reportWarning(AZStd::string::format("Material property name \"%s\" is not found in the material properties layout and will not be used.", name.GetCStr()).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,16 +16,21 @@ namespace AZ
|
||||
{
|
||||
namespace RPI
|
||||
{
|
||||
void MaterialAssetCreator::Begin(const Data::AssetId& assetId, const Data::Asset<MaterialTypeAsset>& materialType)
|
||||
void MaterialAssetCreator::Begin(const Data::AssetId& assetId, const Data::Asset<MaterialTypeAsset>& materialType, bool shouldFinalize)
|
||||
{
|
||||
BeginCommon(assetId);
|
||||
|
||||
if (ValidateIsReady())
|
||||
{
|
||||
m_shouldFinalize = shouldFinalize;
|
||||
|
||||
m_asset->m_materialTypeAsset = materialType;
|
||||
|
||||
m_asset->m_materialTypeAsset.SetAutoLoadBehavior(AZ::Data::AssetLoadBehavior::PreLoad);
|
||||
|
||||
|
||||
if (shouldFinalize && !m_asset->m_materialTypeAsset)
|
||||
{
|
||||
ReportError("MaterialTypeAsset is null, the MaterialAsset cannot be finalized");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +42,14 @@ namespace AZ
|
||||
}
|
||||
|
||||
m_asset->SetReady();
|
||||
|
||||
if (m_shouldFinalize)
|
||||
{
|
||||
m_asset->Finalize(
|
||||
[this](const char* message) { ReportWarning("%s", message); },
|
||||
[this](const char* message) { ReportError("%s", message); });
|
||||
}
|
||||
|
||||
return EndCommon(result);
|
||||
}
|
||||
|
||||
@@ -71,6 +84,21 @@ namespace AZ
|
||||
m_asset->m_rawPropertyValues.emplace_back(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialAssetCreator::SetPropertyValue(const Name& name, const Data::Asset<ImageAsset>& imageAsset)
|
||||
{
|
||||
SetPropertyValue(name, MaterialPropertyValue{imageAsset});
|
||||
}
|
||||
|
||||
void MaterialAssetCreator::SetPropertyValue(const Name& name, const Data::Asset<StreamingImageAsset>& imageAsset)
|
||||
{
|
||||
SetPropertyValue(name, Data::Asset<ImageAsset>(imageAsset));
|
||||
}
|
||||
|
||||
void MaterialAssetCreator::SetPropertyValue(const Name& name, const Data::Asset<AttachmentImageAsset>& imageAsset)
|
||||
{
|
||||
SetPropertyValue(name, Data::Asset<ImageAsset>(imageAsset));
|
||||
}
|
||||
|
||||
} // namespace RPI
|
||||
} // namespace AZ
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
#include <Atom/RPI.Reflect/Material/MaterialAssetCreatorCommon.h>
|
||||
#include <Atom/RPI.Reflect/Material/MaterialAssetCreatorCommon.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
@@ -32,57 +33,6 @@ namespace AZ
|
||||
m_reportError = nullptr;
|
||||
}
|
||||
|
||||
MaterialPropertyDataType MaterialAssetCreatorCommon::GetMaterialPropertyDataType(TypeId typeId) const
|
||||
{
|
||||
if (typeId == azrtti_typeid<bool>()) { return MaterialPropertyDataType::Bool; }
|
||||
if (typeId == azrtti_typeid<int32_t>()) { return MaterialPropertyDataType::Int; }
|
||||
if (typeId == azrtti_typeid<uint32_t>()) { return MaterialPropertyDataType::UInt; }
|
||||
if (typeId == azrtti_typeid<float>()) { return MaterialPropertyDataType::Float; }
|
||||
if (typeId == azrtti_typeid<Vector2>()) { return MaterialPropertyDataType::Vector2; }
|
||||
if (typeId == azrtti_typeid<Vector3>()) { return MaterialPropertyDataType::Vector3; }
|
||||
if (typeId == azrtti_typeid<Vector4>()) { return MaterialPropertyDataType::Vector4; }
|
||||
if (typeId == azrtti_typeid<Color>()) { return MaterialPropertyDataType::Color; }
|
||||
if (typeId == azrtti_typeid<Data::Asset<ImageAsset>>()) { return MaterialPropertyDataType::Image; }
|
||||
else
|
||||
{
|
||||
return MaterialPropertyDataType::Invalid;
|
||||
}
|
||||
}
|
||||
|
||||
bool MaterialAssetCreatorCommon::ValidateDataType(TypeId typeId, const Name& propertyName, const MaterialPropertyDescriptor* materialPropertyDescriptor)
|
||||
{
|
||||
auto expectedDataType = materialPropertyDescriptor->GetDataType();
|
||||
auto actualDataType = GetMaterialPropertyDataType(typeId);
|
||||
|
||||
if (expectedDataType == MaterialPropertyDataType::Enum)
|
||||
{
|
||||
if (actualDataType != MaterialPropertyDataType::UInt)
|
||||
{
|
||||
m_reportError(
|
||||
AZStd::string::format("Material property '%s' is a Enum type, can only accept UInt value, input value is %s",
|
||||
propertyName.GetCStr(),
|
||||
ToString(actualDataType)
|
||||
).data());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (expectedDataType != actualDataType)
|
||||
{
|
||||
m_reportError(
|
||||
AZStd::string::format("Material property '%s': Type mismatch. Expected %s but was %s",
|
||||
propertyName.GetCStr(),
|
||||
ToString(expectedDataType),
|
||||
ToString(actualDataType)
|
||||
).data());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MaterialAssetCreatorCommon::PropertyCheck(TypeId typeId, const Name& name)
|
||||
{
|
||||
if (!m_reportWarning || !m_reportError)
|
||||
@@ -108,7 +58,7 @@ namespace AZ
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ValidateDataType(typeId, name, materialPropertyDescriptor))
|
||||
if (!ValidateMaterialPropertyDataType(typeId, name, materialPropertyDescriptor, m_reportError))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -97,6 +97,57 @@ namespace AZ
|
||||
return AZStd::string::format("<Unkonwn type %s>", typeId.ToString<AZStd::string>().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
bool ValidateMaterialPropertyDataType(TypeId typeId, const Name& propertyName, const MaterialPropertyDescriptor* materialPropertyDescriptor, AZStd::function<void(const char*)> onError)
|
||||
{
|
||||
auto toMaterialPropertyDataType = [](TypeId typeId)
|
||||
{
|
||||
if (typeId == azrtti_typeid<bool>()) { return MaterialPropertyDataType::Bool; }
|
||||
if (typeId == azrtti_typeid<int32_t>()) { return MaterialPropertyDataType::Int; }
|
||||
if (typeId == azrtti_typeid<uint32_t>()) { return MaterialPropertyDataType::UInt; }
|
||||
if (typeId == azrtti_typeid<float>()) { return MaterialPropertyDataType::Float; }
|
||||
if (typeId == azrtti_typeid<Vector2>()) { return MaterialPropertyDataType::Vector2; }
|
||||
if (typeId == azrtti_typeid<Vector3>()) { return MaterialPropertyDataType::Vector3; }
|
||||
if (typeId == azrtti_typeid<Vector4>()) { return MaterialPropertyDataType::Vector4; }
|
||||
if (typeId == azrtti_typeid<Color>()) { return MaterialPropertyDataType::Color; }
|
||||
if (typeId == azrtti_typeid<Data::Asset<ImageAsset>>()) { return MaterialPropertyDataType::Image; }
|
||||
else
|
||||
{
|
||||
return MaterialPropertyDataType::Invalid;
|
||||
}
|
||||
};
|
||||
|
||||
auto expectedDataType = materialPropertyDescriptor->GetDataType();
|
||||
auto actualDataType = toMaterialPropertyDataType(typeId);
|
||||
|
||||
if (expectedDataType == MaterialPropertyDataType::Enum)
|
||||
{
|
||||
if (actualDataType != MaterialPropertyDataType::UInt)
|
||||
{
|
||||
onError(
|
||||
AZStd::string::format("Material property '%s' is a Enum type, can only accept UInt value, input value is %s",
|
||||
propertyName.GetCStr(),
|
||||
ToString(actualDataType)
|
||||
).data());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (expectedDataType != actualDataType)
|
||||
{
|
||||
onError(
|
||||
AZStd::string::format("Material property '%s': Type mismatch. Expected %s but was %s",
|
||||
propertyName.GetCStr(),
|
||||
ToString(expectedDataType),
|
||||
ToString(actualDataType)
|
||||
).data());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MaterialPropertyOutputId::Reflect(ReflectContext* context)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user