diff --git a/Source/VictoryBPLibrary/Private/VictoryBPFunctionLibrary.cpp b/Source/VictoryBPLibrary/Private/VictoryBPFunctionLibrary.cpp index 5ee554f..3e9850f 100644 --- a/Source/VictoryBPLibrary/Private/VictoryBPFunctionLibrary.cpp +++ b/Source/VictoryBPLibrary/Private/VictoryBPFunctionLibrary.cpp @@ -4332,6 +4332,53 @@ UTexture2D* UVictoryBPFunctionLibrary::Victory_LoadTexture2D_FromFile(const FStr IsValid = true; return LoadedT2D; } +UTexture2D* UVictoryBPFunctionLibrary::Victory_LoadNormalTexture2D_FromFile(const FString& FullFilePath, EJoyImageFormats ImageFormat, bool& IsValid, int32& Width, int32& Height) +{ + IsValid = false; + UTexture2D* LoadedT2D = NULL; + + IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked(FName("ImageWrapper")); + TSharedPtr ImageWrapper = ImageWrapperModule.CreateImageWrapper(GetJoyImageFormat(ImageFormat)); + + //Load From File + TArray RawFileData; + if (!FFileHelper::LoadFileToArray(RawFileData, *FullFilePath)) return NULL; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + //Create T2D! + if (ImageWrapper.IsValid() && ImageWrapper->SetCompressed(RawFileData.GetData(), RawFileData.Num())) + { + TArray UncompressedBGRA; + if (ImageWrapper->GetRaw(ERGBFormat::BGRA, 8, UncompressedBGRA)) + { + LoadedT2D = UTexture2D::CreateTransient(ImageWrapper->GetWidth(), ImageWrapper->GetHeight(), PF_B8G8R8A8); + + //Valid? + if (!LoadedT2D) return NULL; + //~~~~~~~~~~~~~~ + + // Change options to use as normal map + LoadedT2D->LODGroup = TextureGroup::TEXTUREGROUP_WorldNormalMap; + LoadedT2D->SRGB = false; + LoadedT2D->CompressionSettings = TextureCompressionSettings::TC_Normalmap; + + //Out! + Width = ImageWrapper->GetWidth(); + Height = ImageWrapper->GetHeight(); + + //Copy! + void* TextureData = LoadedT2D->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE); + FMemory::Memcpy(TextureData, UncompressedBGRA.GetData(), UncompressedBGRA.Num()); + LoadedT2D->PlatformData->Mips[0].BulkData.Unlock(); + + //Update! + LoadedT2D->UpdateResource(); + } + } + // Success! + IsValid = true; + return LoadedT2D; +} UTexture2D* UVictoryBPFunctionLibrary::Victory_LoadTexture2D_FromFile_Pixels(const FString& FullFilePath,EJoyImageFormats ImageFormat,bool& IsValid, int32& Width, int32& Height, TArray& OutPixels) { //Clear any previous data diff --git a/Source/VictoryBPLibrary/Public/VictoryBPFunctionLibrary.h b/Source/VictoryBPLibrary/Public/VictoryBPFunctionLibrary.h index ca703bd..617371a 100644 --- a/Source/VictoryBPLibrary/Public/VictoryBPFunctionLibrary.h +++ b/Source/VictoryBPLibrary/Public/VictoryBPFunctionLibrary.h @@ -1556,7 +1556,11 @@ class VICTORYBPLIBRARY_API UVictoryBPFunctionLibrary : public UBlueprintFunction /** Load a Texture2D from a JPG,PNG,BMP,ICO,EXR,ICNS file! IsValid tells you if file path was valid or not. Enjoy! -Rama */ UFUNCTION(BlueprintPure, Category = "Victory BP Library|Load Texture From File",meta=(Keywords="image png jpg jpeg bmp bitmap ico icon exr icns")) static UTexture2D* Victory_LoadTexture2D_FromFile(const FString& FullFilePath,EJoyImageFormats ImageFormat,bool& IsValid, int32& Width, int32& Height); - + + /** Load a Texture2D as a Normal texture from a JPG,PNG,BMP,ICO,EXR,ICNS file! IsValid tells you if file path was valid or not. */ + UFUNCTION(BlueprintPure, Category = "Victory BP Library|Load Texture From File",meta=(Keywords="image png jpg jpeg bmp bitmap ico icon exr icns")) + static UTexture2D* Victory_LoadNormalTexture2D_FromFile(const FString& FullFilePath,EJoyImageFormats ImageFormat,bool& IsValid, int32& Width, int32& Height); + /** Load a Texture2D from a JPG,PNG,BMP,ICO,EXR,ICNS file! IsValid tells you if file path was valid or not. Enjoy! -Rama */ UFUNCTION(BlueprintPure, Category = "Victory BP Library|Load Texture From File",meta=(Keywords="image png jpg jpeg bmp bitmap ico icon exr icns")) static UTexture2D* Victory_LoadTexture2D_FromFile_Pixels(const FString& FullFilePath,EJoyImageFormats ImageFormat,bool& IsValid, int32& Width, int32& Height, TArray& OutPixels);