Merge remote-tracking branch 'upstream/stabilization/2110' into Atom/santorac/MaterialEditorHandlesMissingTextures
This commit is contained in:
@@ -231,18 +231,13 @@ namespace MaterialEditor
|
||||
|
||||
// create source data from properties
|
||||
MaterialSourceData sourceData;
|
||||
sourceData.m_materialType = m_materialSourceData.m_materialType;
|
||||
sourceData.m_parentMaterial = m_materialSourceData.m_parentMaterial;
|
||||
|
||||
AZ_Assert(m_materialAsset && m_materialAsset->GetMaterialTypeAsset(), "When IsOpen() is true, these assets should not be null.");
|
||||
sourceData.m_materialTypeVersion = m_materialAsset->GetMaterialTypeAsset()->GetVersion();
|
||||
|
||||
// Force save data to store forward slashes
|
||||
AzFramework::StringFunc::Replace(sourceData.m_materialType, "\\", "/");
|
||||
AzFramework::StringFunc::Replace(sourceData.m_parentMaterial, "\\", "/");
|
||||
sourceData.m_materialType = AtomToolsFramework::GetExteralReferencePath(m_absolutePath, m_materialSourceData.m_materialType);
|
||||
sourceData.m_parentMaterial = AtomToolsFramework::GetExteralReferencePath(m_absolutePath, m_materialSourceData.m_parentMaterial);
|
||||
|
||||
// populate sourceData with modified or overwritten properties
|
||||
const bool savedProperties = SavePropertiesToSourceData(sourceData, [](const AtomToolsFramework::DynamicProperty& property) {
|
||||
const bool savedProperties = SavePropertiesToSourceData(m_absolutePath, sourceData, [](const AtomToolsFramework::DynamicProperty& property)
|
||||
{
|
||||
return !AtomToolsFramework::ArePropertyValuesEqual(property.GetValue(), property.GetConfig().m_parentValue);
|
||||
});
|
||||
|
||||
@@ -305,18 +300,13 @@ namespace MaterialEditor
|
||||
|
||||
// create source data from properties
|
||||
MaterialSourceData sourceData;
|
||||
sourceData.m_materialType = m_materialSourceData.m_materialType;
|
||||
sourceData.m_parentMaterial = m_materialSourceData.m_parentMaterial;
|
||||
|
||||
AZ_Assert(m_materialAsset && m_materialAsset->GetMaterialTypeAsset(), "When IsOpen() is true, these assets should not be null.");
|
||||
sourceData.m_materialTypeVersion = m_materialAsset->GetMaterialTypeAsset()->GetVersion();
|
||||
|
||||
// Force save data to store forward slashes
|
||||
AzFramework::StringFunc::Replace(sourceData.m_materialType, "\\", "/");
|
||||
AzFramework::StringFunc::Replace(sourceData.m_parentMaterial, "\\", "/");
|
||||
sourceData.m_materialType = AtomToolsFramework::GetExteralReferencePath(normalizedSavePath, m_materialSourceData.m_materialType);
|
||||
sourceData.m_parentMaterial = AtomToolsFramework::GetExteralReferencePath(normalizedSavePath, m_materialSourceData.m_parentMaterial);
|
||||
|
||||
// populate sourceData with modified or overwritten properties
|
||||
const bool savedProperties = SavePropertiesToSourceData(sourceData, [](const AtomToolsFramework::DynamicProperty& property) {
|
||||
const bool savedProperties = SavePropertiesToSourceData(normalizedSavePath, sourceData, [](const AtomToolsFramework::DynamicProperty& property)
|
||||
{
|
||||
return !AtomToolsFramework::ArePropertyValuesEqual(property.GetValue(), property.GetConfig().m_parentValue);
|
||||
});
|
||||
|
||||
@@ -378,23 +368,18 @@ namespace MaterialEditor
|
||||
|
||||
// create source data from properties
|
||||
MaterialSourceData sourceData;
|
||||
sourceData.m_materialType = m_materialSourceData.m_materialType;
|
||||
|
||||
AZ_Assert(m_materialAsset && m_materialAsset->GetMaterialTypeAsset(), "When IsOpen() is true, these assets should not be null.");
|
||||
sourceData.m_materialTypeVersion = m_materialAsset->GetMaterialTypeAsset()->GetVersion();
|
||||
sourceData.m_materialType = AtomToolsFramework::GetExteralReferencePath(normalizedSavePath, m_materialSourceData.m_materialType);
|
||||
|
||||
// Only assign a parent path if the source was a .material
|
||||
if (AzFramework::StringFunc::Path::IsExtension(m_relativePath.c_str(), MaterialSourceData::Extension))
|
||||
{
|
||||
sourceData.m_parentMaterial = m_relativePath;
|
||||
sourceData.m_parentMaterial = AtomToolsFramework::GetExteralReferencePath(normalizedSavePath, m_absolutePath);
|
||||
}
|
||||
|
||||
// Force save data to store forward slashes
|
||||
AzFramework::StringFunc::Replace(sourceData.m_materialType, "\\", "/");
|
||||
AzFramework::StringFunc::Replace(sourceData.m_parentMaterial, "\\", "/");
|
||||
|
||||
// populate sourceData with modified properties
|
||||
const bool savedProperties = SavePropertiesToSourceData(sourceData, [](const AtomToolsFramework::DynamicProperty& property) {
|
||||
const bool savedProperties = SavePropertiesToSourceData(normalizedSavePath, sourceData, [](const AtomToolsFramework::DynamicProperty& property)
|
||||
{
|
||||
return !AtomToolsFramework::ArePropertyValuesEqual(property.GetValue(), property.GetConfig().m_originalValue);
|
||||
});
|
||||
|
||||
@@ -591,7 +576,8 @@ namespace MaterialEditor
|
||||
}
|
||||
}
|
||||
|
||||
bool MaterialDocument::SavePropertiesToSourceData(AZ::RPI::MaterialSourceData& sourceData, PropertyFilterFunction propertyFilter) const
|
||||
bool MaterialDocument::SavePropertiesToSourceData(
|
||||
const AZStd::string& exportPath, AZ::RPI::MaterialSourceData& sourceData, PropertyFilterFunction propertyFilter) const
|
||||
{
|
||||
using namespace AZ;
|
||||
using namespace RPI;
|
||||
@@ -599,7 +585,7 @@ namespace MaterialEditor
|
||||
bool result = true;
|
||||
|
||||
// populate sourceData with properties that meet the filter
|
||||
m_materialTypeSourceData.EnumerateProperties([this, &sourceData, &propertyFilter, &result](const AZStd::string& groupName, const AZStd::string& propertyName, const auto& propertyDefinition) {
|
||||
m_materialTypeSourceData.EnumerateProperties([&](const AZStd::string& groupName, const AZStd::string& propertyName, const auto& propertyDefinition) {
|
||||
|
||||
const MaterialPropertyId propertyId(groupName, propertyName);
|
||||
|
||||
@@ -609,7 +595,7 @@ namespace MaterialEditor
|
||||
MaterialPropertyValue propertyValue = AtomToolsFramework::ConvertToRuntimeType(it->second.GetValue());
|
||||
if (propertyValue.IsValid())
|
||||
{
|
||||
if (!m_materialTypeSourceData.ConvertPropertyValueToSourceDataFormat(propertyId.GetFullName(), propertyDefinition, propertyValue))
|
||||
if (!AtomToolsFramework::ConvertToExportFormat(exportPath, propertyId.GetFullName(), propertyDefinition, propertyValue))
|
||||
{
|
||||
AZ_Error("MaterialDocument", false, "Material document property could not be converted: '%s' in '%s'.", propertyId.GetFullName().GetCStr(), m_absolutePath.c_str());
|
||||
result = false;
|
||||
@@ -663,8 +649,6 @@ namespace MaterialEditor
|
||||
return false;
|
||||
}
|
||||
|
||||
AZStd::string materialTypeSourceFilePath;
|
||||
|
||||
// The material document and inspector are constructed from source data
|
||||
if (AzFramework::StringFunc::Path::IsExtension(m_absolutePath.c_str(), MaterialSourceData::Extension))
|
||||
{
|
||||
@@ -675,13 +659,24 @@ namespace MaterialEditor
|
||||
return false;
|
||||
}
|
||||
|
||||
// We must also always load the material type data for a complete, ordered set of the
|
||||
// groups and properties that will be needed for comparison and building the inspector
|
||||
materialTypeSourceFilePath = AssetUtils::ResolvePathReference(m_absolutePath, m_materialSourceData.m_materialType);
|
||||
auto materialTypeOutcome = MaterialUtils::LoadMaterialTypeSourceData(materialTypeSourceFilePath);
|
||||
// We always need the absolute path for the material type and parent material to load source data and resolving
|
||||
// relative paths when saving. This will convert and store them as absolute paths for use within the document.
|
||||
if (!m_materialSourceData.m_parentMaterial.empty())
|
||||
{
|
||||
m_materialSourceData.m_parentMaterial =
|
||||
AssetUtils::ResolvePathReference(m_absolutePath, m_materialSourceData.m_parentMaterial);
|
||||
}
|
||||
|
||||
if (!m_materialSourceData.m_materialType.empty())
|
||||
{
|
||||
m_materialSourceData.m_materialType = AssetUtils::ResolvePathReference(m_absolutePath, m_materialSourceData.m_materialType);
|
||||
}
|
||||
|
||||
// Load the material type source data which provides the layout and default values of all of the properties
|
||||
auto materialTypeOutcome = MaterialUtils::LoadMaterialTypeSourceData(m_materialSourceData.m_materialType);
|
||||
if (!materialTypeOutcome.IsSuccess())
|
||||
{
|
||||
AZ_Error("MaterialDocument", false, "Material type source data could not be loaded: '%s'.", materialTypeSourceFilePath.c_str());
|
||||
AZ_Error("MaterialDocument", false, "Material type source data could not be loaded: '%s'.", m_materialSourceData.m_materialType.c_str());
|
||||
return false;
|
||||
}
|
||||
m_materialTypeSourceData = materialTypeOutcome.GetValue();
|
||||
@@ -694,10 +689,10 @@ namespace MaterialEditor
|
||||
}
|
||||
else if (AzFramework::StringFunc::Path::IsExtension(m_absolutePath.c_str(), MaterialTypeSourceData::Extension))
|
||||
{
|
||||
materialTypeSourceFilePath = m_absolutePath;
|
||||
|
||||
// Load the material type source data, which will be used for enumerating properties and building material source data
|
||||
auto materialTypeOutcome = MaterialUtils::LoadMaterialTypeSourceData(materialTypeSourceFilePath);
|
||||
// A material document can be created or loaded from material or material type source data. If we are attempting to load
|
||||
// material type source data then the material source data object can be created just by referencing the document path as the
|
||||
// material type path.
|
||||
auto materialTypeOutcome = MaterialUtils::LoadMaterialTypeSourceData(m_absolutePath);
|
||||
if (!materialTypeOutcome.IsSuccess())
|
||||
{
|
||||
AZ_Error("MaterialDocument", false, "Material type source data could not be loaded: '%s'.", m_absolutePath.c_str());
|
||||
@@ -705,9 +700,8 @@ namespace MaterialEditor
|
||||
}
|
||||
m_materialTypeSourceData = materialTypeOutcome.GetValue();
|
||||
|
||||
// The document represents a material, not a material type.
|
||||
// If the input data is a material type file we have to generate the material source data by referencing it.
|
||||
m_materialSourceData.m_materialType = m_relativePath;
|
||||
// We are storing absolute paths in the loaded version of the source data so that the files can be resolved at all times.
|
||||
m_materialSourceData.m_materialType = m_absolutePath;
|
||||
m_materialSourceData.m_parentMaterial.clear();
|
||||
}
|
||||
else
|
||||
@@ -751,25 +745,24 @@ namespace MaterialEditor
|
||||
if (!m_materialSourceData.m_parentMaterial.empty())
|
||||
{
|
||||
AZ::RPI::MaterialSourceData parentMaterialSourceData;
|
||||
const auto parentMaterialFilePath = AssetUtils::ResolvePathReference(m_absolutePath, m_materialSourceData.m_parentMaterial);
|
||||
if (!AZ::RPI::JsonUtils::LoadObjectFromFile(parentMaterialFilePath, parentMaterialSourceData))
|
||||
if (!AZ::RPI::JsonUtils::LoadObjectFromFile(m_materialSourceData.m_parentMaterial, parentMaterialSourceData))
|
||||
{
|
||||
AZ_Error("MaterialDocument", false, "Material parent source data could not be loaded for: '%s'.", parentMaterialFilePath.c_str());
|
||||
AZ_Error("MaterialDocument", false, "Material parent source data could not be loaded for: '%s'.", m_materialSourceData.m_parentMaterial.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto parentMaterialAssetIdResult = AssetUtils::MakeAssetId(parentMaterialFilePath, 0);
|
||||
const auto parentMaterialAssetIdResult = AssetUtils::MakeAssetId(m_materialSourceData.m_parentMaterial, 0);
|
||||
if (!parentMaterialAssetIdResult)
|
||||
{
|
||||
AZ_Error("MaterialDocument", false, "Material parent asset ID could not be created: '%s'.", parentMaterialFilePath.c_str());
|
||||
AZ_Error("MaterialDocument", false, "Material parent asset ID could not be created: '%s'.", m_materialSourceData.m_parentMaterial.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto parentMaterialAssetResult = parentMaterialSourceData.CreateMaterialAssetFromSourceData(
|
||||
parentMaterialAssetIdResult.GetValue(), parentMaterialFilePath, elevateWarnings, true);
|
||||
parentMaterialAssetIdResult.GetValue(), parentMaterialFilePath, true, true);
|
||||
if (!parentMaterialAssetResult)
|
||||
{
|
||||
AZ_Error("MaterialDocument", false, "Material parent asset could not be created from source data: '%s'.", parentMaterialFilePath.c_str());
|
||||
AZ_Error("MaterialDocument", false, "Material parent asset could not be created from source data: '%s'.", m_materialSourceData.m_parentMaterial.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -880,7 +873,8 @@ namespace MaterialEditor
|
||||
m_properties[propertyConfig.m_id] = AtomToolsFramework::DynamicProperty(propertyConfig);
|
||||
}
|
||||
|
||||
const MaterialFunctorSourceData::EditorContext editorContext = MaterialFunctorSourceData::EditorContext(materialTypeSourceFilePath, m_materialAsset->GetMaterialPropertiesLayout());
|
||||
const MaterialFunctorSourceData::EditorContext editorContext =
|
||||
MaterialFunctorSourceData::EditorContext(m_materialSourceData.m_materialType, m_materialAsset->GetMaterialPropertiesLayout());
|
||||
for (Ptr<MaterialFunctorSourceDataHolder> functorData : m_materialTypeSourceData.m_materialFunctorSourceData)
|
||||
{
|
||||
MaterialFunctorSourceData::FunctorResult result2 = functorData->CreateFunctor(editorContext);
|
||||
|
||||
Reference in New Issue
Block a user