Pullsar
(Pullsar)
May 27, 2023, 6:52am
1
I 'm trying to get the thumbnails of some existing assets and assign them to the UImage as a texture in the editor utility widget that I created. However, when I do with as follows, the returned textures look different and corrupted from their original versions in the content browser. Am I missing something , or Is there better way to obtain this ?
void UMBMaterialAssignmentSlot::SetSlotParams(const FAssetData& AssetData)
{
FString PackageFilename;
const FName ObjectFullName = FName(*AssetData.GetFullName());
TSet<FName> ObjectFullNames;
ObjectFullNames.Add(ObjectFullName);
if(FPackageName::DoesPackageExist(AssetData.PackageName.ToString(), &PackageFilename))
{
FThumbnailMap ThumbnailMap;
ThumbnailTools::LoadThumbnailsFromPackage(PackageFilename,ObjectFullNames,
ThumbnailMap);
ThumbnailMap.Find(ObjectFullName)->AccessImageData();
const auto CreatedTexture = FImageUtils::ImportBufferAsTexture2D
(ThumbnailMap.Find(ObjectFullName)->AccessCompressedImageData());
MaterialImage->SetBrushFromTexture(CreatedTexture);
}
}
3dRaven
(3dRaven)
May 27, 2023, 3:43pm
2
Basing off the staff’s post
Exporting Thumbnails to PNGs
Article written by Cody A.
For some projects, it can be useful to automatically export out generated asset thumbnails as PNG files. This can be accomplished by accessing the thumbnail via the ThumbnailTools namespace, and using the ImageWrapper module to convert the pixels into a PNG for export.
The following code regenerates the thumbnail to ensure it’s up to date, generates the compressed PNG, and saves it to a location on disk.
void UMyThumbnailSaver::SaveThum…
I repurposed it for your thumbnail gen.
.build file needs "ImageWrapper"
in dependencies
Includes
#include "IImageWrapper.h"
#include "IImageWrapperModule.h"
void UMBMaterialAssignmentSlot::SetSlotParams(const FAssetData& AssetData) {
UTexture2D* CreatedTexture = nullptr;
FString PackageFilename;
const FName ObjectFullName = FName(*AssetData.GetFullName());
TSet<FName> ObjectFullNames;
ObjectFullNames.Add(ObjectFullName);
if (FPackageName::DoesPackageExist(AssetData.PackageName.ToString(), &PackageFilename))
{
FThumbnailMap ThumbnailMap;
ThumbnailTools::LoadThumbnailsFromPackage(PackageFilename, ObjectFullNames,
ThumbnailMap);
FObjectThumbnail* objTN = ThumbnailMap.Find(ObjectFullName);
IImageWrapperModule& ImageWrapperModule = FModuleManager::Get().LoadModuleChecked<IImageWrapperModule>(TEXT("ImageWrapper"));
TSharedPtr<IImageWrapper> ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG);
ImageWrapper->SetRaw(objTN->GetUncompressedImageData().GetData(), objTN->GetUncompressedImageData().Num(), objTN->GetImageWidth(), objTN->GetImageHeight(), ERGBFormat::BGRA, 8);
const TArray64<uint8>& CompressedByteArray = ImageWrapper->GetCompressed();
CreatedTexture = FImageUtils::ImportBufferAsTexture2D(CompressedByteArray);
MeshImage->SetBrushFromTexture(CreatedTexture);
}
}
2 Likes
Pullsar
(Pullsar)
May 27, 2023, 7:56pm
3
It works perfectly. Thank you.
1 Like
system
(system)
Closed
June 26, 2023, 7:57pm
4
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.