I use FinalizeBlob to retrieve the image data and then export it as a PNG file. These are part of my code,
I think I used the wrong method to retrieve the texture data. So, how can I safely and reliably retrieve the data from the UTG_Texture node and save it as a PNG file?
If needed, I can provide the complete Gaea node code.
`void UTG_Expression_Gaea::Evaluate(FTG_EvaluationContext* InContext)
{
Super::Evaluate(InContext);
TArray<FName> Keys;
InContext->Inputs.VarArguments.GetKeys(Keys);
InputVars.Empty();
for (FName Key : Keys)
{
FTG_Var* Var = InContext->Inputs.GetVar(Key);
const FTG_Argument* VarArgument = InContext->Inputs.GetVarArgument(Key);
if (VarArgument->IsTexture())
{
FString FilePath;
if (Var && !Var->IsEmpty())
{
FTG_Texture& ParamValue = Var->EditAs<FTG_Texture>();
FilePath = TEXT("\"") + GetNodeInputTexture(Key.ToString(), ParamValue) + TEXT("\""); // Export the input texture as a PNG file and return the file path.
}
else
{
//...
}
InputVars.Add(Key.ToString(), FilePath);
}
}
//...
}
AsyncBool UTG_Expression_Gaea::FinalizeBlob(BlobPtr TargetBlob)
{
auto TiledOutput = std::static_pointer_cast(TargetBlob);
return TiledOutput->OnFinalise().then([=]
{
return true;
});
}
FString UTG_Expression_Gaea::GetNodeInputTexture(FString MaskName,FTG_Texture InputTexture)
{
if (!InputTexture.RasterBlob)
{
UE_LOG(LogTemp, Warning, TEXT("Invalid RasterBlob! "));
return FString();
}
FString LevelName = FPaths::GetBaseFilename(GWorld->GetCurrentLevel()->GetFullName());
FString TexturePath = FPaths::ConvertRelativePathToFull(FPaths::Combine(FPaths::AutomationTransientDir(), LevelName));
FinalizeBlob(InputTexture.RasterBlob)
.then([this,InputTexture]() {
if (InputTexture->GetTiles()[0][0] == NULL)
return cti::make_ready_continuable(0);
InputTexture->CombineTiles(false, false);
return cti::make_ready_continuable(1);
})
.then([this,InputTexture]() {
DeviceBufferRef Buffer = InputTexture->GetBufferRef();
if (Buffer->IsNull())
return this->GetNullBufferPtr();// cti::make_ready_continuable(0);
return Buffer->Raw();
})
.then([this, TexturePath, MaskName](RawBufferPtr RawObj) {
if (!RawObj || RawObj->GetData() == nullptr)
{
UE_LOG(LogTexture, Warning, TEXT("Can't export with invalid RawBuffer: %s"), *(RawObj->GetName()));
return;
}
//ExportTexture2D...
});
return FPaths::Combine(TexturePath, MaskName + TEXT(".png"));
}`