Add a default fallback image when a StreamingImageAsset fails to load

Signed-off-by: Tommy Walton <waltont@amazon.com>
This commit is contained in:
Tommy Walton
2021-11-02 16:40:56 -07:00
parent 47b7ad1ec4
commit 672c82f69d
2 changed files with 32 additions and 0 deletions
@@ -25,6 +25,8 @@ namespace AZ
const Data::Asset<Data::AssetData>& asset,
AZStd::shared_ptr<Data::AssetDataStream> stream,
const Data::AssetFilterCB& assetLoadFilterCB) override;
Data::AssetId AssetMissingInCatalog(const Data::Asset<Data::AssetData>& /*asset*/) override;
};
}
}
@@ -7,6 +7,7 @@
*/
#include <Atom/RPI.Reflect/Image/StreamingImageAssetHandler.h>
#include <AzFramework/Asset/AssetSystemBus.h>
namespace AZ
{
@@ -40,5 +41,34 @@ namespace AZ
return loadResult;
}
Data::AssetId StreamingImageAssetHandler::AssetMissingInCatalog(const Data::Asset<Data::AssetData>& asset)
{
// Escalate the asset to the top of the list
AzFramework::AssetSystemRequestBus::Broadcast(
&AzFramework::AssetSystem::AssetSystemRequests::EscalateAssetByUuid, asset.GetId().m_guid);
// Make sure the default fallback image has been processed so that it is part of the asset catalog
AzFramework::AssetSystem::AssetStatus status = AzFramework::AssetSystem::AssetStatus_Unknown;
AzFramework::AssetSystemRequestBus::BroadcastResult(
status, &AzFramework::AssetSystemRequestBus::Events::CompileAssetSync, "textures/defaults/defaultnouvs.tif.streamingimage");
// Get the id of the fallback image
Data::AssetInfo assetInfo;
assetInfo.m_relativePath = "textures/defaults/defaultnouvs.tif.streamingimage";
Data::AssetId assetId;
Data::AssetCatalogRequestBus::BroadcastResult(
assetId, &Data::AssetCatalogRequestBus::Events::GenerateAssetIdTEMP,
assetInfo.m_relativePath.c_str());
assetInfo.m_assetId = Data::AssetId(assetId.m_guid, StreamingImageAsset::GetImageAssetSubId());
// Register the fallback image with the asset catalog
Data::AssetCatalogRequestBus::Broadcast(
&Data::AssetCatalogRequestBus::Events::RegisterAsset, assetInfo.m_assetId, assetInfo);
// Use a default Image as a fallback
return assetInfo.m_assetId;
}
}
}