From 357648a42431acfbef39d5402c99c6ab424ba752 Mon Sep 17 00:00:00 2001 From: Guthrie Adams Date: Tue, 23 Nov 2021 20:52:41 -0600 Subject: [PATCH] =?UTF-8?q?Fixed=20a=20bug=20with=20model=20previews=20and?= =?UTF-8?q?=20thumbnails.=20A=20source=20model=20asset=20can=20have=20mult?= =?UTF-8?q?iple=20products=20including=20models=20and=20materials.=20It?= =?UTF-8?q?=E2=80=99s=20not=20guaranteed=20that=20the=20first=20entry=20in?= =?UTF-8?q?=20the=20list=20of=20products=20for=20a=20model=20asset=20will?= =?UTF-8?q?=20be=20a=20model.=20In=20this=20case=20the=20first=20product?= =?UTF-8?q?=20was=20the=20default=20material=20asset.=20This=20caused=20so?= =?UTF-8?q?me=20model=20previews=20to=20render=20a=20gray=20sphere=20depic?= =?UTF-8?q?ting=20the=20default=20material.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guthrie Adams --- .../Source/SharedPreview/SharedPreviewUtils.cpp | 17 +++++++++++------ .../Source/SharedPreview/SharedPreviewUtils.h | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SharedPreview/SharedPreviewUtils.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SharedPreview/SharedPreviewUtils.cpp index d0e288d239..7fbe374286 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SharedPreview/SharedPreviewUtils.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SharedPreview/SharedPreviewUtils.cpp @@ -22,9 +22,9 @@ namespace AZ { namespace SharedPreviewUtils { - AZStd::unordered_set GetSupportedAssetTypes() + AZStd::vector GetSupportedAssetTypes() { - return { RPI::AnyAsset::RTTI_Type(), RPI::MaterialAsset::RTTI_Type(), RPI::ModelAsset::RTTI_Type() }; + return { RPI::ModelAsset::RTTI_Type(), RPI::MaterialAsset::RTTI_Type(), RPI::AnyAsset::RTTI_Type() }; } bool IsSupportedAssetType(AzToolsFramework::Thumbnailer::SharedThumbnailKey key) @@ -46,11 +46,15 @@ namespace AZ foundIt, &AzToolsFramework::AssetSystemRequestBus::Events::GetAssetsProducedBySourceUUID, sourceKey->GetSourceUuid(), productsAssetInfo); - for (const auto& assetInfo : productsAssetInfo) + // Search the product assets for a matching asset type ID in the order of the supported type IDs, which are organized by priority + for (const auto& typeId : supportedTypeIds) { - if (supportedTypeIds.find(assetInfo.m_assetType) != supportedTypeIds.end()) + for (const auto& assetInfo : productsAssetInfo) { - return assetInfo; + if (assetInfo.m_assetType == typeId) + { + return assetInfo; + } } } return AZ::Data::AssetInfo(); @@ -59,7 +63,8 @@ namespace AZ // if it's a product thumbnail key just return its assetId AZ::Data::AssetInfo assetInfo; auto productKey = azrtti_cast(key.data()); - if (productKey && supportedTypeIds.find(productKey->GetAssetType()) != supportedTypeIds.end()) + if (productKey && + AZStd::find(supportedTypeIds.begin(), supportedTypeIds.end(), productKey->GetAssetType()) != supportedTypeIds.end()) { AZ::Data::AssetCatalogRequestBus::BroadcastResult( assetInfo, &AZ::Data::AssetCatalogRequestBus::Events::GetAssetInfoById, productKey->GetAssetId()); diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SharedPreview/SharedPreviewUtils.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SharedPreview/SharedPreviewUtils.h index 28c9809d6d..d215271936 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SharedPreview/SharedPreviewUtils.h +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SharedPreview/SharedPreviewUtils.h @@ -21,7 +21,7 @@ namespace AZ namespace SharedPreviewUtils { //! Get the set of all asset types supported by the shared preview - AZStd::unordered_set GetSupportedAssetTypes(); + AZStd::vector GetSupportedAssetTypes(); //! Determine if a thumbnail key has an asset supported by the shared preview bool IsSupportedAssetType(AzToolsFramework::Thumbnailer::SharedThumbnailKey key);