mirror of
https://github.com/4sval/FModel.git
synced 2026-03-21 17:24:26 -05:00
Texture Changes & HDR Preview/Export (#559)
Some checks failed
FModel QA Builder / build (push) Has been cancelled
Some checks failed
FModel QA Builder / build (push) Has been cancelled
* texture refactor * fix bgra in opengl Co-authored-by: Asval <asval.contactme@gmail.com>
This commit is contained in:
parent
edebff0925
commit
556ae6e036
|
|
@ -1 +1 @@
|
|||
Subproject commit d512c176b722af7345fd4240ffaeed05a5f49013
|
||||
Subproject commit 72eaf4101268bd971281f3cd8769a57be90caedb
|
||||
|
|
@ -159,7 +159,7 @@ public class BaseIcon : UCreator
|
|||
{
|
||||
if (uObject is UTexture2D texture2D)
|
||||
{
|
||||
SeriesBackground = texture2D.Decode();
|
||||
SeriesBackground = texture2D.Decode().ToSkBitmap();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ public static class Utils
|
|||
public static SKBitmap GetB64Bitmap(string b64) => SKBitmap.Decode(new MemoryStream(Convert.FromBase64String(b64)) { Position = 0 });
|
||||
public static SKBitmap GetBitmap(FSoftObjectPath softObjectPath) => GetBitmap(softObjectPath.Load<UTexture2D>());
|
||||
public static SKBitmap GetBitmap(string fullPath) => TryLoadObject(fullPath, out UTexture2D texture) ? GetBitmap(texture) : null;
|
||||
public static SKBitmap GetBitmap(UTexture2D texture) => texture.Decode(UserSettings.Default.CurrentDir.TexturePlatform);
|
||||
public static SKBitmap GetBitmap(UTexture2D texture) => texture.Decode(UserSettings.Default.CurrentDir.TexturePlatform).ToSkBitmap();
|
||||
public static SKBitmap GetBitmap(byte[] data) => SKBitmap.Decode(data);
|
||||
|
||||
public static SKBitmap ResizeWithRatio(this SKBitmap me, double width, double height)
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ public partial class MainWindow
|
|||
|
||||
await ApplicationViewModel.InitOodle();
|
||||
await ApplicationViewModel.InitZlib();
|
||||
await ApplicationViewModel.InitDetex();
|
||||
await _applicationView.CUE4Parse.Initialize();
|
||||
await _applicationView.AesManager.InitAes();
|
||||
await _applicationView.UpdateProvider(true);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.IO.Compression;
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using CUE4Parse_Conversion.Textures.BC;
|
||||
using CUE4Parse.Compression;
|
||||
using CUE4Parse.Encryption.Aes;
|
||||
using CUE4Parse.UE4.Objects.Core.Misc;
|
||||
|
|
@ -258,4 +259,19 @@ public class ApplicationViewModel : ViewModel
|
|||
|
||||
ZlibHelper.Initialize(zlibPath);
|
||||
}
|
||||
|
||||
public static async ValueTask InitDetex()
|
||||
{
|
||||
var detexPath = Path.Combine(UserSettings.Default.OutputDirectory, ".data", DetexHelper.DLL_NAME);
|
||||
if (File.Exists(DetexHelper.DLL_NAME))
|
||||
{
|
||||
File.Move(DetexHelper.DLL_NAME, detexPath, true);
|
||||
}
|
||||
else if (!File.Exists(detexPath))
|
||||
{
|
||||
await DetexHelper.LoadDllAsync(detexPath);
|
||||
}
|
||||
|
||||
DetexHelper.Initialize(detexPath);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ namespace FModel.ViewModels;
|
|||
|
||||
public class TabImage : ViewModel
|
||||
{
|
||||
public string ExportName { get; }
|
||||
public string ExportName { get; set; }
|
||||
|
||||
public byte[] ImageBuffer { get; set; }
|
||||
|
||||
public TabImage(string name, bool rnn, SKBitmap img)
|
||||
|
|
@ -32,6 +33,13 @@ public class TabImage : ViewModel
|
|||
SetImage(img);
|
||||
}
|
||||
|
||||
public TabImage(string name, bool rnn, CTexture img)
|
||||
{
|
||||
ExportName = name;
|
||||
RenderNearestNeighbor = rnn;
|
||||
SetImage(img);
|
||||
}
|
||||
|
||||
private BitmapImage _image;
|
||||
public BitmapImage Image
|
||||
{
|
||||
|
|
@ -71,11 +79,42 @@ public class TabImage : ViewModel
|
|||
}
|
||||
|
||||
_bmp = bitmap;
|
||||
using var data = _bmp.Encode(NoAlpha ? ETextureFormat.Jpeg : UserSettings.Default.TextureExportFormat, 100);
|
||||
ExportName += "." + (NoAlpha ? "jpg" : "png");
|
||||
using var data = _bmp.Encode(NoAlpha ? SKEncodedImageFormat.Jpeg : SKEncodedImageFormat.Png, 100);
|
||||
using var stream = new MemoryStream(ImageBuffer = data.ToArray(), false);
|
||||
if (UserSettings.Default.TextureExportFormat == ETextureFormat.Tga)
|
||||
return;
|
||||
var image = new BitmapImage();
|
||||
image.BeginInit();
|
||||
image.CacheOption = BitmapCacheOption.OnLoad;
|
||||
image.StreamSource = stream;
|
||||
image.EndInit();
|
||||
image.Freeze();
|
||||
Image = image;
|
||||
}
|
||||
|
||||
private void SetImage(CTexture bitmap)
|
||||
{
|
||||
if (bitmap is null)
|
||||
{
|
||||
ImageBuffer = null;
|
||||
Image = null;
|
||||
return;
|
||||
}
|
||||
|
||||
_bmp = bitmap.ToSkBitmap();
|
||||
byte[] imageData = _bmp.Encode(NoAlpha ? SKEncodedImageFormat.Jpeg : SKEncodedImageFormat.Png, 100).ToArray();
|
||||
|
||||
if (PixelFormatUtils.IsHDR(bitmap.PixelFormat) || (UserSettings.Default.TextureExportFormat != ETextureFormat.Jpeg && UserSettings.Default.TextureExportFormat != ETextureFormat.Png))
|
||||
{
|
||||
ImageBuffer = bitmap.Encode(UserSettings.Default.TextureExportFormat, out var ext);
|
||||
ExportName += "." + ext;
|
||||
}
|
||||
else
|
||||
{
|
||||
ImageBuffer = imageData;
|
||||
ExportName += "." + (NoAlpha ? "jpg" : "png");
|
||||
}
|
||||
|
||||
using var stream = new MemoryStream(imageData);
|
||||
var image = new BitmapImage();
|
||||
image.BeginInit();
|
||||
image.CacheOption = BitmapCacheOption.OnLoad;
|
||||
|
|
@ -253,7 +292,7 @@ public class TabItem : ViewModel
|
|||
public void AddImage(UTexture texture, bool save, bool updateUi)
|
||||
{
|
||||
var appendLayerNumber = false;
|
||||
var img = new SKBitmap[1];
|
||||
var img = new CTexture[1];
|
||||
if (texture is UTexture2DArray textureArray)
|
||||
{
|
||||
img = textureArray.DecodeTextureArray(UserSettings.Default.CurrentDir.TexturePlatform);
|
||||
|
|
@ -264,7 +303,7 @@ public class TabItem : ViewModel
|
|||
img[0] = texture.Decode(UserSettings.Default.CurrentDir.TexturePlatform);
|
||||
if (texture is UTextureCube)
|
||||
{
|
||||
img[0] = img[0]?.ToPanorama();
|
||||
img[0] = img[0].ToPanorama();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -279,6 +318,29 @@ public class TabItem : ViewModel
|
|||
}
|
||||
}
|
||||
|
||||
public void AddImage(string name, bool rnn, CTexture[] img, bool save, bool updateUi, bool appendLayerNumber = false)
|
||||
{
|
||||
for (var i = 0; i < img.Length; i++)
|
||||
{
|
||||
AddImage($"{name}{(appendLayerNumber ? $"_{i}" : "")}", rnn, img[i], save, updateUi);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddImage(string name, bool rnn, CTexture img, bool save, bool updateUi)
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
var t = new TabImage(name, rnn, img);
|
||||
if (save) SaveImage(t, updateUi);
|
||||
if (!updateUi) return;
|
||||
|
||||
_images.Add(t);
|
||||
SelectedImage ??= t;
|
||||
RaisePropertyChanged("Page");
|
||||
RaisePropertyChanged("HasMultipleImages");
|
||||
});
|
||||
}
|
||||
|
||||
public void AddImage(string name, bool rnn, SKBitmap img, bool save, bool updateUi)
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
|
|
@ -312,23 +374,14 @@ public class TabItem : ViewModel
|
|||
public void SaveImage() => SaveImage(SelectedImage, true);
|
||||
private void SaveImage(TabImage image, bool updateUi)
|
||||
{
|
||||
if (image == null) return;
|
||||
if (image == null)
|
||||
return;
|
||||
|
||||
var ext = UserSettings.Default.TextureExportFormat switch
|
||||
{
|
||||
ETextureFormat.Png => ".png",
|
||||
ETextureFormat.Jpeg => ".jpg",
|
||||
ETextureFormat.Tga => ".tga",
|
||||
_ => ".png"
|
||||
};
|
||||
|
||||
var fileName = image.ExportName + ext;
|
||||
var path = Path.Combine(UserSettings.Default.TextureDirectory,
|
||||
UserSettings.Default.KeepDirectoryStructure ? Entry.Directory : "", fileName!).Replace('\\', '/');
|
||||
var path = Path.Combine(UserSettings.Default.TextureDirectory, UserSettings.Default.KeepDirectoryStructure ? Entry.Directory : "", image.ExportName).Replace('\\', '/');
|
||||
|
||||
Directory.CreateDirectory(path.SubstringBeforeLast('/'));
|
||||
|
||||
SaveImage(image, path, fileName, updateUi);
|
||||
SaveImage(image, path, image.ExportName, updateUi);
|
||||
}
|
||||
|
||||
private void SaveImage(TabImage image, string path, string fileName, bool updateUi)
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ public class Options
|
|||
if (Textures.TryGetValue(guid, out texture)) return texture != null;
|
||||
if (o.Format == EPixelFormat.PF_BC6H) return false; // BC6H is not supported by Decode thus randomly crashes the app
|
||||
|
||||
SKBitmap bitmap = o switch
|
||||
var bitmap = o switch
|
||||
{
|
||||
UTexture2D texture2D => texture2D.Decode(UserSettings.Default.PreviewMaxTextureSize, UserSettings.Default.CurrentDir.TexturePlatform),
|
||||
UTexture2DArray texture2DArray => texture2DArray.DecodeTextureArray(UserSettings.Default.CurrentDir.TexturePlatform)?.FirstOrDefault(),
|
||||
|
|
@ -202,10 +202,9 @@ public class Options
|
|||
|
||||
if (bitmap is not null)
|
||||
{
|
||||
texture = new Texture(bitmap, o);
|
||||
texture = new Texture(bitmap.ToSkBitmap(), o);
|
||||
if (fix) TextureHelper.FixChannels(_game, texture);
|
||||
Textures[guid] = texture;
|
||||
bitmap.Dispose();
|
||||
}
|
||||
|
||||
return texture != null;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Numerics;
|
||||
using System.Windows;
|
||||
using CUE4Parse_Conversion.Textures;
|
||||
using CUE4Parse.UE4.Assets.Exports.Texture;
|
||||
using CUE4Parse.UE4.Objects.Core.Math;
|
||||
using CUE4Parse.UE4.Objects.Core.Misc;
|
||||
|
|
@ -90,15 +91,16 @@ public class Texture : IDisposable
|
|||
Height = bitmap.Height;
|
||||
Bind(TextureUnit.Texture0);
|
||||
|
||||
var internalFormat = Format switch
|
||||
var internalFormat = bitmap.ColorType switch
|
||||
{
|
||||
EPixelFormat.PF_G8 => PixelInternalFormat.R8,
|
||||
SKColorType.Gray8 => PixelInternalFormat.R8,
|
||||
_ => texture2D.SRGB ? PixelInternalFormat.Srgb : PixelInternalFormat.Rgb
|
||||
};
|
||||
|
||||
var pixelFormat = Format switch
|
||||
var pixelFormat = bitmap.ColorType switch
|
||||
{
|
||||
EPixelFormat.PF_G8 => PixelFormat.Red,
|
||||
SKColorType.Gray8 => PixelFormat.Red,
|
||||
SKColorType.Bgra8888 => PixelFormat.Bgra,
|
||||
_ => PixelFormat.Rgba
|
||||
};
|
||||
|
||||
|
|
@ -109,6 +111,7 @@ public class Texture : IDisposable
|
|||
GL.TexParameter(_target, TextureParameterName.TextureMaxLevel, 8);
|
||||
|
||||
GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
|
||||
bitmap.Dispose();
|
||||
}
|
||||
|
||||
public Texture(FLinearColor color) : this(TextureType.Normal)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ FModel - An Unreal Engine Archives Explorer in C#
|
|||
[](https://github.com/4sval/FModel/actions)
|
||||
[](https://fmodel.app/download)
|
||||
[](https://fmodel.app/donate)
|
||||
[](https://fmodel.app/discord)
|
||||
[](https://fmodel.app/discord)
|
||||
***
|
||||
|
||||
### Description:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user