Moved asynchronous image loading function to atom tools framework

Moved settings registry wrapper function to atom tools framework
Created registry settings with default values for preview configurations based on asset type
Changed lighting preset previews and thumbnails to use reflective material
Created registry settings for preset selection dialog borders, padding, sizes
Updated shared preview utility functions to compare against registered asset types instead of passing them in individually

Signed-off-by: Guthrie Adams <guthadam@amazon.com>
This commit is contained in:
Guthrie Adams
2021-11-16 23:23:25 -06:00
parent 6dcbc64cd6
commit cb552256f8
15 changed files with 225 additions and 147 deletions
@@ -9,9 +9,11 @@
#include <API/EditorAssetSystemAPI.h>
#include <AssetBrowser/Thumbnails/ProductThumbnail.h>
#include <AssetBrowser/Thumbnails/SourceThumbnail.h>
#include <Atom/RPI.Reflect/Asset/AssetUtils.h>
#include <Atom/RPI.Reflect/Material/MaterialAsset.h>
#include <Atom/RPI.Reflect/Model/ModelAsset.h>
#include <Atom/RPI.Reflect/System/AnyAsset.h>
#include <AtomToolsFramework/Util/Util.h>
#include <SharedPreview/SharedPreviewUtils.h>
namespace AZ
@@ -20,45 +22,64 @@ namespace AZ
{
namespace SharedPreviewUtils
{
Data::AssetId GetAssetId(
AzToolsFramework::Thumbnailer::SharedThumbnailKey key,
const Data::AssetType& assetType,
const Data::AssetId& defaultAssetId)
AZStd::unordered_set<AZ::Uuid> GetSupportedAssetTypes()
{
return { RPI::AnyAsset::RTTI_Type(), RPI::MaterialAsset::RTTI_Type(), RPI::ModelAsset::RTTI_Type() };
}
bool IsSupportedAssetType(AzToolsFramework::Thumbnailer::SharedThumbnailKey key)
{
return GetSupportedAssetInfo(key).m_assetId.IsValid();
}
AZ::Data::AssetInfo GetSupportedAssetInfo(AzToolsFramework::Thumbnailer::SharedThumbnailKey key)
{
const auto& supportedTypeIds = GetSupportedAssetTypes();
// if it's a source thumbnail key, find first product with a matching asset type
auto sourceKey = azrtti_cast<const AzToolsFramework::AssetBrowser::SourceThumbnailKey*>(key.data());
if (sourceKey)
{
bool foundIt = false;
AZStd::vector<Data::AssetInfo> productsAssetInfo;
AZStd::vector<AZ::Data::AssetInfo> productsAssetInfo;
AzToolsFramework::AssetSystemRequestBus::BroadcastResult(
foundIt, &AzToolsFramework::AssetSystemRequestBus::Events::GetAssetsProducedBySourceUUID,
sourceKey->GetSourceUuid(), productsAssetInfo);
if (!foundIt)
{
return defaultAssetId;
}
auto assetInfoIt = AZStd::find_if(
productsAssetInfo.begin(), productsAssetInfo.end(),
[&assetType](const Data::AssetInfo& assetInfo)
{
return assetInfo.m_assetType == assetType;
});
if (assetInfoIt == productsAssetInfo.end())
{
return defaultAssetId;
}
return assetInfoIt->m_assetId;
for (const auto& assetInfo : productsAssetInfo)
{
if (supportedTypeIds.find(assetInfo.m_assetType) != supportedTypeIds.end())
{
return assetInfo;
}
}
return AZ::Data::AssetInfo();
}
// if it's a product thumbnail key just return its assetId
AZ::Data::AssetInfo assetInfo;
auto productKey = azrtti_cast<const AzToolsFramework::AssetBrowser::ProductThumbnailKey*>(key.data());
if (productKey && productKey->GetAssetType() == assetType)
if (productKey && supportedTypeIds.find(productKey->GetAssetType()) != supportedTypeIds.end())
{
return productKey->GetAssetId();
AZ::Data::AssetCatalogRequestBus::BroadcastResult(
assetInfo, &AZ::Data::AssetCatalogRequestBus::Events::GetAssetInfoById, productKey->GetAssetId());
}
return defaultAssetId;
return assetInfo;
}
AZ::Data::AssetId GetSupportedAssetId(AzToolsFramework::Thumbnailer::SharedThumbnailKey key, const AZ::Data::AssetId& defaultAssetId)
{
const AZ::Data::AssetInfo assetInfo = GetSupportedAssetInfo(key);
return assetInfo.m_assetId.IsValid() ? assetInfo.m_assetId : defaultAssetId;
}
AZ::Data::AssetId GetAssetIdForProductPath(const AZStd::string_view productPath)
{
if (!productPath.empty())
{
return AZ::RPI::AssetUtils::GetAssetIdForProductPath(productPath.data());
}
return AZ::Data::AssetId();
}
QString WordWrap(const QString& string, int maxLength)
@@ -85,32 +106,6 @@ namespace AZ
}
return result;
}
AZStd::unordered_set<AZ::Uuid> GetSupportedAssetTypes()
{
return { RPI::AnyAsset::RTTI_Type(), RPI::MaterialAsset::RTTI_Type(), RPI::ModelAsset::RTTI_Type() };
}
bool IsSupportedAssetType(AzToolsFramework::Thumbnailer::SharedThumbnailKey key)
{
for (const AZ::Uuid& typeId : SharedPreviewUtils::GetSupportedAssetTypes())
{
const AZ::Data::AssetId& assetId = SharedPreviewUtils::GetAssetId(key, typeId);
if (assetId.IsValid())
{
if (typeId == RPI::AnyAsset::RTTI_Type())
{
AZ::Data::AssetInfo assetInfo;
AZ::Data::AssetCatalogRequestBus::BroadcastResult(
assetInfo, &AZ::Data::AssetCatalogRequestBus::Events::GetAssetInfoById, assetId);
return AzFramework::StringFunc::EndsWith(assetInfo.m_relativePath.c_str(), "lightingpreset.azasset");
}
return true;
}
}
return false;
}
} // namespace SharedPreviewUtils
} // namespace LyIntegration
} // namespace AZ