Created function to get relative paths to referenced files that will fall back to asset folder relative paths under certain conditions
Signed-off-by: Guthrie Adams <guthadam@amazon.com>
This commit is contained in:
+13
-1
@@ -45,10 +45,22 @@ namespace AtomToolsFramework
|
||||
//! Convert the property value into the format that will be stored in the source data
|
||||
//! This is primarily needed to support conversions of special types like enums and images
|
||||
bool ConvertToExportFormat(
|
||||
const AZ::IO::BasicPath<AZStd::string>& exportFolder,
|
||||
const AZStd::string& exportPath,
|
||||
const AZ::RPI::MaterialTypeSourceData::PropertyDefinition& propertyDefinition,
|
||||
AZ::RPI::MaterialPropertyValue& propertyValue);
|
||||
|
||||
//! Generate a file path from the exported file to the external reference.
|
||||
//! This function is to support copying or moving a folder containing materials, models, and textures without modifying the files. The
|
||||
//! general case returns a relative path from the export file to the reference file. If the reference path is too different or distant
|
||||
//! from the export path then it might be more difficult to work with than an asset folder relative path. For example, material types
|
||||
//! that Atom provides live in a folder that should be accessible from anywhere. When materials are created in arbitrary gems and
|
||||
//! project folders, a relative path to the material type would need to be updated whenever the materials are copied or moved. The same
|
||||
//! thing will happen with parent materials or textures if their paths can’t be resolved. To alleviate some of this, we use the asset
|
||||
//! folder relative path if the export folder relative path is too complex. An alternate solution would be to only use export folder
|
||||
//! relative paths if the referenced path is in the same folder or a sub folder the assets are not generally packaged like that.
|
||||
AZStd::string GetExteralReferencePath(
|
||||
const AZStd::string& exportPath, const AZStd::string& referencePath, const uint32_t maxPathDepth = 2);
|
||||
|
||||
//! Traverse up the instance data node hierarchy to find the containing dynamic property object
|
||||
const AtomToolsFramework::DynamicProperty* FindDynamicPropertyForInstanceDataNode(const AzToolsFramework::InstanceDataNode* pNode);
|
||||
} // namespace AtomToolsFramework
|
||||
|
||||
@@ -166,10 +166,13 @@ namespace AtomToolsFramework
|
||||
}
|
||||
|
||||
bool ConvertToExportFormat(
|
||||
const AZ::IO::BasicPath<AZStd::string>& exportFolder,
|
||||
const AZStd::string& exportPath,
|
||||
const AZ::RPI::MaterialTypeSourceData::PropertyDefinition& propertyDefinition,
|
||||
AZ::RPI::MaterialPropertyValue& propertyValue)
|
||||
{
|
||||
AZ::IO::BasicPath<AZStd::string> exportFolder(exportPath);
|
||||
exportFolder.RemoveFilename();
|
||||
|
||||
if (propertyDefinition.m_dataType == AZ::RPI::MaterialPropertyDataType::Enum && propertyValue.Is<uint32_t>())
|
||||
{
|
||||
const uint32_t index = propertyValue.GetValue<uint32_t>();
|
||||
@@ -206,6 +209,47 @@ namespace AtomToolsFramework
|
||||
return true;
|
||||
}
|
||||
|
||||
AZStd::string GetExteralReferencePath(const AZStd::string& exportPath, const AZStd::string& referencePath, const uint32_t maxPathDepth)
|
||||
{
|
||||
if (referencePath.empty())
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
AZ::IO::BasicPath<AZStd::string> exportFolder(exportPath);
|
||||
exportFolder.RemoveFilename();
|
||||
|
||||
const AZStd::string relativePath = AZ::IO::PathView(referencePath).LexicallyRelative(exportFolder).StringAsPosix();
|
||||
|
||||
// Count the difference in depth between the export file path and the referenced file path.
|
||||
uint32_t parentFolderCount = 0;
|
||||
AZStd::string::size_type pos = 0;
|
||||
const AZStd::string parentFolderToken = "..";
|
||||
while ((pos = relativePath.find(parentFolderToken, pos)) != AZStd::string::npos)
|
||||
{
|
||||
parentFolderCount++;
|
||||
pos += parentFolderToken.length();
|
||||
}
|
||||
|
||||
// If the difference in depth is too great then revert to using the asset folder relative path.
|
||||
// We could change this to only use relative paths for references in subfolders.
|
||||
if (parentFolderCount > maxPathDepth)
|
||||
{
|
||||
AZStd::string watchFolder;
|
||||
AZ::Data::AssetInfo assetInfo;
|
||||
bool sourceInfoFound = false;
|
||||
AzToolsFramework::AssetSystemRequestBus::BroadcastResult(
|
||||
sourceInfoFound, &AzToolsFramework::AssetSystemRequestBus::Events::GetSourceInfoBySourcePath, referencePath.c_str(),
|
||||
assetInfo, watchFolder);
|
||||
if (sourceInfoFound)
|
||||
{
|
||||
return assetInfo.m_relativePath;
|
||||
}
|
||||
}
|
||||
|
||||
return relativePath;
|
||||
}
|
||||
|
||||
const AtomToolsFramework::DynamicProperty* FindDynamicPropertyForInstanceDataNode(const AzToolsFramework::InstanceDataNode* pNode)
|
||||
{
|
||||
// Traverse up the hierarchy from the input node to search for an instance corresponding to material inspector property
|
||||
|
||||
Reference in New Issue
Block a user