/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #include #include #include #include #include #include #include #include #include namespace AZ { namespace LyIntegration { namespace SharedPreviewUtils { AZStd::unordered_set 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(key.data()); if (sourceKey) { bool foundIt = false; AZStd::vector productsAssetInfo; AzToolsFramework::AssetSystemRequestBus::BroadcastResult( foundIt, &AzToolsFramework::AssetSystemRequestBus::Events::GetAssetsProducedBySourceUUID, sourceKey->GetSourceUuid(), productsAssetInfo); 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(key.data()); if (productKey && supportedTypeIds.find(productKey->GetAssetType()) != supportedTypeIds.end()) { AZ::Data::AssetCatalogRequestBus::BroadcastResult( assetInfo, &AZ::Data::AssetCatalogRequestBus::Events::GetAssetInfoById, productKey->GetAssetId()); } 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 result; int length = 0; for (const QChar& c : string) { if (c == '\n') { length = 0; } else if (length > maxLength) { result.append('\n'); length = 0; } else { length++; } result.append(c); } return result; } } // namespace SharedPreviewUtils } // namespace LyIntegration } // namespace AZ