@ -9,9 +9,11 @@
# include <API/EditorAssetSystemAPI.h>
# include <API/EditorAssetSystemAPI.h>
# include <AssetBrowser/Thumbnails/ProductThumbnail.h>
# include <AssetBrowser/Thumbnails/ProductThumbnail.h>
# include <AssetBrowser/Thumbnails/SourceThumbnail.h>
# include <AssetBrowser/Thumbnails/SourceThumbnail.h>
# include <Atom/RPI.Reflect/Asset/AssetUtils.h>
# include <Atom/RPI.Reflect/Material/MaterialAsset.h>
# include <Atom/RPI.Reflect/Material/MaterialAsset.h>
# include <Atom/RPI.Reflect/Model/ModelAsset.h>
# include <Atom/RPI.Reflect/Model/ModelAsset.h>
# include <Atom/RPI.Reflect/System/AnyAsset.h>
# include <Atom/RPI.Reflect/System/AnyAsset.h>
# include <AtomToolsFramework/Util/Util.h>
# include <SharedPreview/SharedPreviewUtils.h>
# include <SharedPreview/SharedPreviewUtils.h>
namespace AZ
namespace AZ
@ -20,45 +22,64 @@ namespace AZ
{
{
namespace SharedPreviewUtils
namespace SharedPreviewUtils
{
{
Data : : AssetId GetAssetId (
AZStd : : unordered_set < AZ : : Uuid > GetSupportedAssetTypes ( )
AzToolsFramework : : Thumbnailer : : SharedThumbnailKey key ,
{
const Data : : AssetType & assetType ,
return { RPI : : AnyAsset : : RTTI_Type ( ) , RPI : : MaterialAsset : : RTTI_Type ( ) , RPI : : ModelAsset : : RTTI_Type ( ) } ;
const Data : : AssetId & defaultAssetId )
}
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
// 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 ( ) ) ;
auto sourceKey = azrtti_cast < const AzToolsFramework : : AssetBrowser : : SourceThumbnailKey * > ( key . data ( ) ) ;
if ( sourceKey )
if ( sourceKey )
{
{
bool foundIt = false ;
bool foundIt = false ;
AZStd : : vector < Data : : AssetInfo > productsAssetInfo ;
AZStd : : vector < AZ: : Data: : AssetInfo > productsAssetInfo ;
AzToolsFramework : : AssetSystemRequestBus : : BroadcastResult (
AzToolsFramework : : AssetSystemRequestBus : : BroadcastResult (
foundIt , & AzToolsFramework : : AssetSystemRequestBus : : Events : : GetAssetsProducedBySourceUUID ,
foundIt , & AzToolsFramework : : AssetSystemRequestBus : : Events : : GetAssetsProducedBySourceUUID ,
sourceKey - > GetSourceUuid ( ) , productsAssetInfo ) ;
sourceKey - > GetSourceUuid ( ) , productsAssetInfo ) ;
if ( ! foundIt )
for ( const auto & assetInfo : productsAssetInfo )
{
{
return defaultAssetId ;
if ( supportedTypeIds . find ( assetInfo . m_assetType ) ! = supportedTypeIds . end ( ) )
}
auto assetInfoIt = AZStd : : find_if (
productsAssetInfo . begin ( ) , productsAssetInfo . end ( ) ,
[ & assetType ] ( const Data : : AssetInfo & assetInfo )
{
{
return assetInfo . m_assetType = = assetType ;
return assetInfo ;
} ) ;
}
if ( assetInfoIt = = productsAssetInfo . end ( ) )
{
return defaultAssetId ;
}
}
return AZ : : Data : : AssetInfo ( ) ;
return assetInfoIt - > m_assetId ;
}
}
// if it's a product thumbnail key just return its assetId
// 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 ( ) ) ;
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 )
QString WordWrap ( const QString & string , int maxLength )
@ -85,32 +106,6 @@ namespace AZ
}
}
return result ;
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 SharedPreviewUtils
} // namespace LyIntegration
} // namespace LyIntegration
} // namespace AZ
} // namespace AZ