Hi friends!! I am working to load jpeg files from origin server. I want use this files to make a Texture2D and put this on static mesh component.
My code is a combination of C++ class and a blueprint child of this:
Blueprint Class
GegCuadros()
void ACOD_cargaObras::GetCuadros(){
TSharedRef < IHttpRequest > Request = FHttpModule::Get().CreateRequest();
//Set Request
Request->SetHeader(TEXT("Content-Type"), TEXT("text/html; charset=UTF-8"));
Request->SetURL(TEXT("http://navesixtina.es/juanga/interior01.jpg"));
Request->SetVerb("GET");
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, Request->GetURL());
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT("Activado"));
Request->OnProcessRequestComplete().BindUObject(this, &ACOD_cargaObras::LoadTexture);
if (!Request->ProcessRequest()){
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Problem processing the request "));
}
}
LoadTexture
void ACOD_cargaObras::LoadTexture(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful){
IImageWrapperModule& imageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
IImageWrapperPtr imageWrapper = imageWrapperModule.CreateImageWrapper(EImageFormat::JPEG);
UTexture2D* imagenTexture = NULL;
if (bWasSuccessful){
if (!Response.IsValid()){
UE_LOG(LogTemp, Warning, TEXT("Texture is not valid"));
}
else{
fileData = Response->GetContent();
if (imageWrapper.IsValid() && imageWrapper->SetCompressed(fileData.GetData(), fileData.Num())){
const TArray<uint8>* uncompressedRGBA = NULL;
if (imageWrapper->GetRaw(ERGBFormat::RGBA, 8, uncompressedRGBA))
{
imagenTexture = UTexture2D::CreateTransient(imageWrapper->GetWidth(), imageWrapper->GetHeight(), PF_B8G8R8A8);
void* dataTexture = imagenTexture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
FMemory::Memcpy(dataTexture, uncompressedRGBA->GetData(), uncompressedRGBA->Num());
imagenTexture->PlatformData->Mips[0].BulkData.Unlock();
imagenTexture->UpdateResource();
this->OnImagenCargada(imagenTexture);
}
}
}
}
}
The code runs perfect in the UE4 Editor!!
In the image you can see the result. The left mesh has got a texture charge with UE4Editor, and the right mesh it’s charged from code:
But, when I package the project on HTML5. I see this:
The web console and debug console don’t show error messages. I think that it’s a adjustment properties problem in UTexture2D but when I try edit this the web browser throws an error.
Thanks for your attention!!