I’m using Assimp to export FBX with embedded textures.
Reading an image from a png file (into the built-in aiTexture*) works fine.
But when I try to convert UTextureRenderTarget2D to aiTexel* pcData I always get wrong data.
static FName ImageWrapperName("ImageWrapper");
IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(ImageWrapperName);
FTextureRenderTargetResource* RTResource = RenderTarget->GameThread_GetRenderTargetResource();
FIntPoint DestSize(RenderTarget->GetSurfaceWidth(), RenderTarget->GetSurfaceHeight());
TUniquePtr<TImagePixelData<FColor>> PixelData;
PixelData = MakeUnique<TImagePixelData<FColor>>(FIntPoint((int32)DestSize.X, (int32)DestSize.Y));
PixelData->Pixels.SetNumUninitialized(DestSize.X * DestSize.Y);
RTResource->ReadPixelsPtr(PixelData->Pixels.GetData());
FImagePixelData* Data = PixelData.Get();
FImageView Image = Data->GetImageView();
TArray64<uint8> CompressedFile;
ImageWrapperModule.CompressImage(CompressedFile, EImageFormat::PNG, Image, (int32)EImageCompressionQuality::Max);
aiTexture* texture = new aiTexture;
texture->mHeight = 0;
texture->mWidth = CompressedFile.Num();
texture->pcData = new aiTexel[1ul + static_cast<unsigned long>(CompressedFile.Num()) / sizeof(aiTexel)];
for (int i = 0; i < CompressedFile.Num(); i += 4)
{
int32 index = i / 4;
texture->pcData[index].b = CompressedFile[i + 0];
texture->pcData[index].g = CompressedFile[i + 1];
texture->pcData[index].r = CompressedFile[i + 2];
texture->pcData[index].a = CompressedFile[i + 3];
}
texture->achFormatHint[0] = 'p';
texture->achFormatHint[1] = 'n';
texture->achFormatHint[2] = 'g';
texture->achFormatHint[3] = '';
scene.mTextures[0] = texture;
New contributor
DigitalBug is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.