cleanup and setting asset preload flags

Signed-off-by: Guthrie Adams <guthadam@amazon.com>
This commit is contained in:
Guthrie Adams
2021-10-22 01:30:12 -05:00
parent b038faf9ca
commit b72970201b
3 changed files with 38 additions and 35 deletions
@@ -102,10 +102,8 @@ namespace AZ
bool includeMaterialPropertyNames = true) const;
private:
static void ApplyMaterialSourceDataPropertiesToAssetCreator(
AZ::RPI::MaterialAssetCreator& materialAssetCreator,
const AZStd::string_view& materialSourceFilePath,
const MaterialSourceData& materialSourceData);
void ApplyPropertiesToAssetCreator(
AZ::RPI::MaterialAssetCreator& materialAssetCreator, const AZStd::string_view& materialSourceFilePath) const;
};
} // namespace RPI
} // namespace AZ
@@ -174,7 +174,7 @@ namespace AZ
materialAssetCreator.Begin(assetId, *parentMaterialAsset.GetValue().Get(), includeMaterialPropertyNames);
}
ApplyMaterialSourceDataPropertiesToAssetCreator(materialAssetCreator, materialSourceFilePath, *this);
ApplyPropertiesToAssetCreator(materialAssetCreator, materialSourceFilePath);
Data::Asset<MaterialAsset> material;
if (materialAssetCreator.End(material))
@@ -211,21 +211,21 @@ namespace AZ
materialAssetCreator.Begin(assetId, *materialTypeAsset.GetValue().Get(), includeMaterialPropertyNames);
AZStd::vector<MaterialSourceData> parentMaterialSourceDataVec;
AZStd::vector<MaterialSourceData> parentSourceDataStack;
AZStd::string parentMaterialPath = m_parentMaterial;
AZStd::string parentMaterialSourcePath = AssetUtils::ResolvePathReference(materialSourceFilePath, parentMaterialPath);
while (!parentMaterialPath.empty())
AZStd::string parentSourceRelPath = m_parentMaterial;
AZStd::string parentSourceAbsPath = AssetUtils::ResolvePathReference(materialSourceFilePath, parentSourceRelPath);
while (!parentSourceRelPath.empty())
{
MaterialSourceData parentMaterialSourceData;
if (!AZ::RPI::JsonUtils::LoadObjectFromFile(parentMaterialSourcePath, parentMaterialSourceData))
MaterialSourceData parentSourceData;
if (!AZ::RPI::JsonUtils::LoadObjectFromFile(parentSourceAbsPath, parentSourceData))
{
return Failure();
}
// Make sure the parent material has the same material type
auto materialTypeIdOutcome1 = AssetUtils::MakeAssetId(materialSourceFilePath, m_materialType, 0);
auto materialTypeIdOutcome2 = AssetUtils::MakeAssetId(parentMaterialSourcePath, parentMaterialSourceData.m_materialType, 0);
auto materialTypeIdOutcome2 = AssetUtils::MakeAssetId(parentSourceAbsPath, parentSourceData.m_materialType, 0);
if (!materialTypeIdOutcome1.IsSuccess() || !materialTypeIdOutcome2.IsSuccess() ||
materialTypeIdOutcome1.GetValue() != materialTypeIdOutcome2.GetValue())
{
@@ -233,18 +233,18 @@ namespace AZ
return Failure();
}
parentMaterialPath = parentMaterialSourceData.m_parentMaterial;
parentMaterialSourcePath = AssetUtils::ResolvePathReference(parentMaterialSourcePath, parentMaterialPath);
parentMaterialSourceDataVec.push_back(parentMaterialSourceData);
parentSourceDataStack.push_back(parentSourceData);
parentSourceRelPath = parentSourceData.m_parentMaterial;
parentSourceAbsPath = AssetUtils::ResolvePathReference(parentSourceAbsPath, parentSourceRelPath);
}
AZStd::reverse(parentMaterialSourceDataVec.begin(), parentMaterialSourceDataVec.end());
for (const auto& parentMaterialSourceData : parentMaterialSourceDataVec)
while (!parentSourceDataStack.empty())
{
ApplyMaterialSourceDataPropertiesToAssetCreator(materialAssetCreator, materialSourceFilePath, parentMaterialSourceData);
parentSourceDataStack.back().ApplyPropertiesToAssetCreator(materialAssetCreator, materialSourceFilePath);
parentSourceDataStack.pop_back();
}
ApplyMaterialSourceDataPropertiesToAssetCreator(materialAssetCreator, materialSourceFilePath, *this);
ApplyPropertiesToAssetCreator(materialAssetCreator, materialSourceFilePath);
Data::Asset<MaterialAsset> material;
if (materialAssetCreator.End(material))
@@ -257,12 +257,10 @@ namespace AZ
}
}
void MaterialSourceData::ApplyMaterialSourceDataPropertiesToAssetCreator(
AZ::RPI::MaterialAssetCreator& materialAssetCreator,
const AZStd::string_view& materialSourceFilePath,
const MaterialSourceData& materialSourceData)
void MaterialSourceData::ApplyPropertiesToAssetCreator(
AZ::RPI::MaterialAssetCreator& materialAssetCreator, const AZStd::string_view& materialSourceFilePath) const
{
for (auto& group : materialSourceData.m_properties)
for (auto& group : m_properties)
{
for (auto& property : group.second)
{
@@ -351,11 +351,14 @@ namespace AZ
for (const ShaderVariantReferenceData& shaderRef : m_shaderCollection)
{
const auto& shaderFile = shaderRef.m_shaderFilePath;
const auto& shaderAsset = AssetUtils::LoadAsset<ShaderAsset>(materialTypeSourceFilePath, shaderFile, 0);
auto shaderAssetResult = AssetUtils::LoadAsset<ShaderAsset>(materialTypeSourceFilePath, shaderFile, 0);
if (shaderAsset)
if (shaderAssetResult)
{
auto optionsLayout = shaderAsset.GetValue()->GetShaderOptionGroupLayout();
auto shaderAsset = shaderAssetResult.GetValue();
shaderAsset.SetAutoLoadBehavior(Data::AssetLoadBehavior::PreLoad);
auto optionsLayout = shaderAsset->GetShaderOptionGroupLayout();
ShaderOptionGroup options{ optionsLayout };
for (auto& iter : shaderRef.m_shaderOptionValues)
{
@@ -366,12 +369,11 @@ namespace AZ
}
materialTypeAssetCreator.AddShader(
shaderAsset.GetValue(), options.GetShaderVariantId(),
shaderRef.m_shaderTag.IsEmpty() ? Uuid::CreateRandom().ToString<AZ::Name>() : shaderRef.m_shaderTag
);
shaderAsset, options.GetShaderVariantId(),
shaderRef.m_shaderTag.IsEmpty() ? Uuid::CreateRandom().ToString<AZ::Name>() : shaderRef.m_shaderTag);
// Gather UV names
const ShaderInputContract& shaderInputContract = shaderAsset.GetValue()->GetInputContract();
const ShaderInputContract& shaderInputContract = shaderAsset->GetInputContract();
for (const ShaderInputContract::StreamChannelInfo& channel : shaderInputContract.m_streamChannels)
{
const RHI::ShaderSemantic& semantic = channel.m_semantic;
@@ -451,15 +453,20 @@ namespace AZ
{
case MaterialPropertyDataType::Image:
{
Outcome<Data::Asset<ImageAsset>> imageAssetResult = MaterialUtils::GetImageAssetReference(materialTypeSourceFilePath, property.m_value.GetValue<AZStd::string>());
auto imageAssetResult = MaterialUtils::GetImageAssetReference(
materialTypeSourceFilePath, property.m_value.GetValue<AZStd::string>());
if (imageAssetResult.IsSuccess())
if (imageAssetResult)
{
materialTypeAssetCreator.SetPropertyValue(propertyId.GetFullName(), imageAssetResult.GetValue());
auto imageAsset = imageAssetResult.GetValue();
imageAsset.SetAutoLoadBehavior(Data::AssetLoadBehavior::PreLoad);
materialTypeAssetCreator.SetPropertyValue(propertyId.GetFullName(), imageAsset);
}
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.GetFullName().GetCStr(),
property.m_value.GetValue<AZStd::string>().data());
}
}
break;