mirror of
https://github.com/4sval/FModel.git
synced 2026-12-04 23:02:22 -06:00
Paper2D support + fixes (#718)
This commit is contained in:
Submodule CUE4Parse updated: e76778c10e...56e904b39e
@@ -170,7 +170,7 @@ public class BaseIcon : UCreator
|
||||
{
|
||||
if (uObject is UTexture2D texture2D)
|
||||
{
|
||||
SeriesBackground = texture2D.Decode().ToSkBitmap();
|
||||
SeriesBackground = texture2D.Decode(UserSettings.GetExportOptions()).ToSkBitmap();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ public static class Utils
|
||||
|
||||
public static SKBitmap GetB64Bitmap(string b64) => SKBitmap.Decode(new MemoryStream(Convert.FromBase64String(b64)) { Position = 0 });
|
||||
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).ToSkBitmap();
|
||||
public static SKBitmap GetBitmap(UTexture2D texture) => texture.Decode(UserSettings.GetExportOptions()).ToSkBitmap();
|
||||
public static SKBitmap GetBitmap(byte[] data) => SKBitmap.Decode(data);
|
||||
|
||||
public static SKBitmap ResizeWithRatio(this SKBitmap me, double width, double height)
|
||||
|
||||
@@ -134,6 +134,7 @@ public enum EAssetCategory : uint
|
||||
GeometryCollection = Mesh + 5,
|
||||
ChaosClothAsset = Mesh + 6,
|
||||
Texture = AssetCategoryExtensions.CategoryBase + (3 << 16),
|
||||
AnimatedTexture = Texture + 1,
|
||||
Materials = AssetCategoryExtensions.CategoryBase + (4 << 16),
|
||||
Material = Materials + 1,
|
||||
MaterialEditorData = Materials + 2,
|
||||
|
||||
@@ -6,11 +6,21 @@ using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace FModel.Extensions;
|
||||
|
||||
public static class ClipboardExtensions
|
||||
{
|
||||
public static void SetImage(BitmapSource image, string fileName = null)
|
||||
{
|
||||
var encoder = new PngBitmapEncoder();
|
||||
encoder.Frames.Add(BitmapFrame.Create(image));
|
||||
using var stream = new MemoryStream();
|
||||
encoder.Save(stream);
|
||||
SetImage(stream.ToArray(), fileName);
|
||||
}
|
||||
|
||||
public static void SetImage(byte[] pngBytes, string fileName = null)
|
||||
{
|
||||
Clipboard.Clear();
|
||||
@@ -195,4 +205,4 @@ public static class ClipboardExtensions
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<Solution>
|
||||
<Project Path="../CUE4Parse/CUE4Parse-Conversion/CUE4Parse-Conversion.csproj" />
|
||||
<Project Path="../CUE4Parse/CUE4Parse.Tests/CUE4Parse.Tests.csproj" />
|
||||
<Project Path="../CUE4Parse/CUE4Parse/CUE4Parse.csproj" />
|
||||
<Project Path="../Snooper/Editor/Editor.csproj" />
|
||||
<Project Path="../Snooper/Snooper/Snooper.csproj" />
|
||||
|
||||
@@ -423,6 +423,7 @@
|
||||
<DockPanel>
|
||||
|
||||
<inputs:SearchTextBox DockPanel.Dock="Top" x:Name="AssetsSearchTextBox"
|
||||
Watermark="Filter assets in current folder..."
|
||||
Text="{Binding CUE4Parse.AssetsFolder.SelectedFolder.SearchText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
ClearButtonClick="OnClearFilterClick" />
|
||||
|
||||
@@ -510,6 +511,7 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<inputs:SearchTextBox x:Name="AssetsExplorerSearch" Grid.Column="0"
|
||||
Watermark="Filter assets in current folder..."
|
||||
Text="{Binding CUE4Parse.AssetsFolder.SelectedFolder.SearchText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
ClearButtonClick="OnClearFilterClick" />
|
||||
|
||||
|
||||
@@ -120,7 +120,6 @@ public partial class MainWindow
|
||||
_applicationView.CUE4Parse.VerifyConsoleVariables(),
|
||||
_applicationView.CUE4Parse.VerifyOnDemandArchives(),
|
||||
_applicationView.CUE4Parse.InitMappings(),
|
||||
ApplicationViewModel.InitDetex(),
|
||||
ApplicationViewModel.InitVgmStream(),
|
||||
Task.Run(() =>
|
||||
{
|
||||
|
||||
@@ -73,7 +73,8 @@ public sealed class UserSettings : ViewModel
|
||||
Default.CompressionFormat,
|
||||
Default.PngCompressionLevel,
|
||||
Default.TgaRleCompression,
|
||||
Default.IncludeDisabledMeshSections
|
||||
Default.IncludeDisabledMeshSections,
|
||||
Default.AnimatedTextureExportFormat
|
||||
);
|
||||
}
|
||||
|
||||
@@ -533,6 +534,13 @@ public sealed class UserSettings : ViewModel
|
||||
set => SetProperty(ref _textureExportFormat, value);
|
||||
}
|
||||
|
||||
private EAnimatedTextureFormat _animatedTextureExportFormat = EAnimatedTextureFormat.Png;
|
||||
public EAnimatedTextureFormat AnimatedTextureExportFormat
|
||||
{
|
||||
get => _animatedTextureExportFormat;
|
||||
set => SetProperty(ref _animatedTextureExportFormat, value);
|
||||
}
|
||||
|
||||
private int _textureQuality = 100;
|
||||
public int TextureQuality
|
||||
{
|
||||
|
||||
@@ -314,21 +314,6 @@ public class ApplicationViewModel : ViewModel
|
||||
await ZlibHelper.InitializeAsync(zlibPath);
|
||||
}
|
||||
|
||||
public static async Task 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);
|
||||
}
|
||||
|
||||
public static async Task InitUnluac()
|
||||
{
|
||||
var unluacPath = Path.Combine(UserSettings.Default.OutputDirectory, ".data", UnluacHelper.DllName);
|
||||
|
||||
@@ -60,6 +60,7 @@ public class TreeItem : ViewModel
|
||||
}
|
||||
|
||||
private string _searchText = string.Empty;
|
||||
private string[] _searchTerms = [];
|
||||
public string SearchText
|
||||
{
|
||||
get => _searchText;
|
||||
@@ -67,6 +68,7 @@ public class TreeItem : ViewModel
|
||||
{
|
||||
if (SetProperty(ref _searchText, value))
|
||||
{
|
||||
_searchTerms = value.Trim().Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
RefreshFilters();
|
||||
}
|
||||
}
|
||||
@@ -104,7 +106,7 @@ public class TreeItem : ViewModel
|
||||
// BulkPopulate sorts Folders before this view is created
|
||||
_filteredFoldersView ??= new ListCollectionView(Folders)
|
||||
{
|
||||
Filter = e => ItemFilter(e, SearchText.Trim().Split(' ', StringSplitOptions.RemoveEmptyEntries))
|
||||
Filter = ItemFilter
|
||||
};
|
||||
return _filteredFoldersView;
|
||||
}
|
||||
@@ -132,7 +134,7 @@ public class TreeItem : ViewModel
|
||||
}
|
||||
PathAtThisPoint = pathHere;
|
||||
|
||||
AssetsList.AssetsView.Filter = o => ItemFilter(o, SearchText.Trim().Split(' ', StringSplitOptions.RemoveEmptyEntries));
|
||||
AssetsList.AssetsView.Filter = ItemFilter;
|
||||
}
|
||||
|
||||
private void RefreshFilters()
|
||||
@@ -141,27 +143,22 @@ public class TreeItem : ViewModel
|
||||
FilteredFoldersView?.Refresh();
|
||||
}
|
||||
|
||||
private bool ItemFilter(object item, IEnumerable<string> filters)
|
||||
private bool ItemFilter(object item) => item switch
|
||||
{
|
||||
var f = filters.ToArray();
|
||||
switch (item)
|
||||
GameFileViewModel entry => (SelectedCategory == EAssetCategory.All || entry.AssetCategory.IsOfCategory(SelectedCategory)) && MatchesSearch(entry.Asset.Name),
|
||||
TreeItem folder => SelectedCategory == EAssetCategory.All && MatchesSearch(folder.Header),
|
||||
_ => false
|
||||
};
|
||||
|
||||
private bool MatchesSearch(string name)
|
||||
{
|
||||
foreach (var term in _searchTerms)
|
||||
{
|
||||
case GameFileViewModel entry:
|
||||
{
|
||||
bool matchesSearch = f.Length == 0 || f.All(x => entry.Asset.Name.Contains(x, StringComparison.OrdinalIgnoreCase));
|
||||
bool matchesCategory = SelectedCategory == EAssetCategory.All || entry.AssetCategory.IsOfCategory(SelectedCategory);
|
||||
|
||||
return matchesSearch && matchesCategory;
|
||||
}
|
||||
case TreeItem folder:
|
||||
{
|
||||
bool matchesSearch = f.Length == 0 || f.All(x => folder.Header.Contains(x, StringComparison.OrdinalIgnoreCase));
|
||||
bool matchesCategory = SelectedCategory == EAssetCategory.All;
|
||||
|
||||
return matchesSearch && matchesCategory;
|
||||
}
|
||||
if (!name.Contains(term, StringComparison.OrdinalIgnoreCase))
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task OnSelectedCategoryChanged()
|
||||
@@ -333,7 +330,7 @@ public class AssetsFolderViewModel : ViewModel
|
||||
}
|
||||
}
|
||||
|
||||
private static void SortFolders(RangeObservableCollection<TreeItem> folders)
|
||||
private static void SortEntries(RangeObservableCollection<TreeItem> folders)
|
||||
{
|
||||
if (folders.Count > 1)
|
||||
{
|
||||
@@ -342,7 +339,13 @@ public class AssetsFolderViewModel : ViewModel
|
||||
|
||||
foreach (var folder in folders)
|
||||
{
|
||||
SortFolders(folder.Folders);
|
||||
// Keep the source ordered so filtering does not sort the same assets on every edit
|
||||
if (folder.AssetsList.Assets.Count > 1)
|
||||
{
|
||||
folder.AssetsList.Assets.ReplaceRange([.. folder.AssetsList.Assets.OrderBy(x => x.Asset.Path, StringComparer.CurrentCulture)]);
|
||||
}
|
||||
|
||||
SortEntries(folder.Folders);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -420,7 +423,7 @@ public class AssetsFolderViewModel : ViewModel
|
||||
lastNode?.AssetsList.Add(entry);
|
||||
}
|
||||
|
||||
SortFolders(treeItems);
|
||||
SortEntries(treeItems);
|
||||
|
||||
Folders.AddRange(treeItems);
|
||||
VisibleFolders.AddRange(treeItems);
|
||||
|
||||
@@ -14,10 +14,7 @@ public class AssetsListViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
_assetsView ??= new ListCollectionView(Assets)
|
||||
{
|
||||
SortDescriptions = { new SortDescription("Asset.Path", ListSortDirection.Ascending) }
|
||||
};
|
||||
_assetsView ??= new ListCollectionView(Assets);
|
||||
return _assetsView;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -964,7 +964,7 @@ public class CUE4ParseViewModel : ViewModel
|
||||
canvas.Translate(-bounds.Left, -bounds.Top);
|
||||
canvas.DrawPicture(svg.Picture);
|
||||
|
||||
TabControl.SelectedTab.AddImage(entry.NameWithoutExtension, false, bitmap, saveTextures, updateUi);
|
||||
TabControl.SelectedTab.AddImage(entry.Name, data, bitmap, saveTextures, updateUi);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -1277,6 +1277,34 @@ public class CUE4ParseViewModel : ViewModel
|
||||
TabControl.SelectedTab.SetDocumentText(luaScript.Code, false, false);
|
||||
return true;
|
||||
}
|
||||
case UPaperSprite when (isNone || saveTextures) && pointer.Object.Value is UPaperSprite paperSprite:
|
||||
{
|
||||
if (saveTextures)
|
||||
{
|
||||
SaveExport(paperSprite);
|
||||
}
|
||||
|
||||
if (updateUi)
|
||||
{
|
||||
TabControl.SelectedTab.AddImage(paperSprite, false, true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
case UPaperFlipbook when (isNone || saveTextures) && pointer.Object.Value is UPaperFlipbook paperFlipbook:
|
||||
{
|
||||
if (saveTextures)
|
||||
{
|
||||
SaveExport(paperFlipbook);
|
||||
}
|
||||
|
||||
if (updateUi)
|
||||
{
|
||||
TabControl.SelectedTab.AddImage(paperFlipbook, false, true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
case UTexture when (isNone || saveTextures) && pointer.Object.Value is UTexture texture:
|
||||
{
|
||||
if (saveTextures)
|
||||
@@ -1345,7 +1373,7 @@ public class CUE4ParseViewModel : ViewModel
|
||||
}
|
||||
}
|
||||
|
||||
TabControl.SelectedTab.AddImage(sourceFile.SubstringAfterLast('/'), false, bitmap, false, updateUi);
|
||||
TabControl.SelectedTab.AddImage(Path.GetFileName(sourceFile) ?? svgasset.Name + ".svg", data, bitmap, false, updateUi);
|
||||
return false;
|
||||
}
|
||||
case UBiomesMaskTextureData when (isNone || saveTextures) && pointer.Object.Value is UBiomesMaskTextureData biomes && biomes.MaskData is { } maskData:
|
||||
|
||||
@@ -4,19 +4,18 @@ using FModel.Framework;
|
||||
using FModel.Views.Resources.Controls;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.IO;
|
||||
using FModel.Views.Resources.Converters;
|
||||
|
||||
namespace FModel.ViewModels.Commands;
|
||||
|
||||
public class ImageCommand : ViewModelCommand<TabItem>
|
||||
public class ImageCommand(TabItem contextViewModel) : ViewModelCommand<TabItem>(contextViewModel)
|
||||
{
|
||||
public ImageCommand(TabItem contextViewModel) : base(contextViewModel)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Execute(TabItem tabViewModel, object parameter)
|
||||
{
|
||||
if (parameter == null || !tabViewModel.HasImage) return;
|
||||
if (parameter == null || !tabViewModel.HasImage)
|
||||
return;
|
||||
|
||||
switch (parameter)
|
||||
{
|
||||
@@ -33,12 +32,14 @@ public class ImageCommand : ViewModelCommand<TabItem>
|
||||
ImageCtrl = { Source = tabViewModel.SelectedImage.Image }
|
||||
};
|
||||
RenderOptions.SetBitmapScalingMode(popout.ImageCtrl, BoolToRenderModeConverter.Instance.Convert(tabViewModel.SelectedImage.RenderNearestNeighbor));
|
||||
ImageAnimation.SetFrames(popout.ImageCtrl, tabViewModel.SelectedImage.AnimationFrames);
|
||||
popout.Show();
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "Copy":
|
||||
ClipboardExtensions.SetImage(tabViewModel.SelectedImage.ImageBuffer, $"{tabViewModel.SelectedImage.ExportName}.png");
|
||||
case BitmapSource:
|
||||
ClipboardExtensions.SetImage(parameter as BitmapSource ?? tabViewModel.SelectedImage.Image, Path.ChangeExtension(tabViewModel.SelectedImage.ExportName, "png"));
|
||||
break;
|
||||
case "Save":
|
||||
tabViewModel.SaveImage();
|
||||
|
||||
@@ -151,6 +151,13 @@ public class ExportOptionsViewModel : ViewModel
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<EAnimatedTextureFormat> AnimatedTextureFormats { get; } = Enum.GetValues<EAnimatedTextureFormat>();
|
||||
public EAnimatedTextureFormat SelectedAnimatedTextureFormat
|
||||
{
|
||||
get;
|
||||
set => SetProperty(ref field, value);
|
||||
}
|
||||
|
||||
public bool ShowTextureQuality => SelectedTextureFormat is ETextureFormat.Jpeg or ETextureFormat.Webp;
|
||||
public bool ShowPngCompression => SelectedTextureFormat is ETextureFormat.Png;
|
||||
public bool ShowTgaCompression => SelectedTextureFormat is ETextureFormat.Tga;
|
||||
@@ -213,6 +220,7 @@ public class ExportOptionsViewModel : ViewModel
|
||||
ExportMaterials = UserSettings.Default.SaveEmbeddedMaterials;
|
||||
SelectedTexturePlatform = UserSettings.Default.CurrentDir.TexturePlatform;
|
||||
SelectedTextureFormat = UserSettings.Default.TextureExportFormat;
|
||||
SelectedAnimatedTextureFormat = UserSettings.Default.AnimatedTextureExportFormat;
|
||||
if (SelectedMeshFormat is EMeshFormat.USD)
|
||||
{
|
||||
_preUsdTextureFormat = SelectedTextureFormat;
|
||||
@@ -243,6 +251,7 @@ public class ExportOptionsViewModel : ViewModel
|
||||
UserSettings.Default.SaveEmbeddedMaterials = ExportMaterials;
|
||||
UserSettings.Default.CurrentDir.TexturePlatform = SelectedTexturePlatform;
|
||||
UserSettings.Default.TextureExportFormat = SelectedTextureFormat;
|
||||
UserSettings.Default.AnimatedTextureExportFormat = SelectedAnimatedTextureFormat;
|
||||
UserSettings.Default.SaveHdrTexturesAsHdr = ExportHdrTexturesAsHdr;
|
||||
UserSettings.Default.SaveMorphTargets = ExportMorphTargets;
|
||||
UserSettings.Default.TextureQuality = TextureQuality;
|
||||
@@ -274,6 +283,7 @@ public class ExportOptionsViewModel : ViewModel
|
||||
SelectedCompressionFormat,
|
||||
PngCompressionLevel,
|
||||
TgaRleCompression,
|
||||
IncludeDisabledMeshSections
|
||||
IncludeDisabledMeshSections,
|
||||
SelectedAnimatedTextureFormat
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using CUE4Parse_Conversion.Textures;
|
||||
using CUE4Parse_Conversion.Textures.Paper2D;
|
||||
using CUE4Parse_Conversion.Dto;
|
||||
using CUE4Parse.FileProvider.Objects;
|
||||
using CUE4Parse.GameTypes.Borderlands3.Assets.Exports;
|
||||
@@ -63,6 +64,7 @@ using CUE4Parse.Utils;
|
||||
using FModel.Framework;
|
||||
using FModel.Services;
|
||||
using FModel.Settings;
|
||||
using FModel.Views.Resources.Controls;
|
||||
using Serilog;
|
||||
using SkiaSharp;
|
||||
using Svg.Skia;
|
||||
@@ -194,6 +196,7 @@ public class GameFileViewModel(GameFile asset) : ViewModel
|
||||
Resolved |= EResolveCompute.Preview;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
if (Asset.NameWithoutExtension.EndsWith("_BuiltData"))
|
||||
{
|
||||
AssetCategory = EAssetCategory.BuildData;
|
||||
@@ -234,7 +237,7 @@ public class GameFileViewModel(GameFile asset) : ViewModel
|
||||
|
||||
UHoudiniAsset or UHoudiniStaticMesh => EAssetFamily.Houdini,
|
||||
|
||||
UPaperTileMap or UPaperTileLayer or UPaperTileSet or UPaperSprite => EAssetFamily.Paper2D,
|
||||
UPaperTileMap or UPaperTileLayer or UPaperTileSet or UPaperSprite or UPaperFlipbook => EAssetFamily.Paper2D,
|
||||
|
||||
_ => EAssetFamily.None,
|
||||
};
|
||||
@@ -262,7 +265,8 @@ public class GameFileViewModel(GameFile asset) : ViewModel
|
||||
|
||||
UHoudiniAsset => (EAssetCategory.Data, EBulkType.None),
|
||||
|
||||
UTexture => (EAssetCategory.Texture, EBulkType.Textures),
|
||||
UTexture or UPaperSprite => (EAssetCategory.Texture, EBulkType.Textures),
|
||||
UPaperFlipbook => (EAssetCategory.AnimatedTexture, EBulkType.Textures),
|
||||
|
||||
UMaterialInterface => (EAssetCategory.Material, EBulkType.None),
|
||||
UMaterialInterfaceEditorOnlyData => (EAssetCategory.MaterialEditorData, EBulkType.None),
|
||||
@@ -324,9 +328,10 @@ public class GameFileViewModel(GameFile asset) : ViewModel
|
||||
_ => (EAssetCategory.All, EBulkType.None),
|
||||
};
|
||||
|
||||
var obj = pointer.Object.Value;
|
||||
if (EmbeddedFilesDto.Supports(dummy))
|
||||
{
|
||||
var files = new EmbeddedFilesDto(pointer.Object.Value).Files;
|
||||
var files = new EmbeddedFilesDto(obj).Files;
|
||||
EmbeddedFileExtensions = string.Join(", ", files.Select(file => "." + file.Extension).Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(extension => extension, StringComparer.OrdinalIgnoreCase));
|
||||
if (files.Count > 0)
|
||||
AssetActions |= EBulkType.EmbeddedFiles;
|
||||
@@ -334,28 +339,49 @@ public class GameFileViewModel(GameFile asset) : ViewModel
|
||||
|
||||
switch (AssetCategory)
|
||||
{
|
||||
case EAssetCategory.Texture when pointer.Object.Value is UTexture texture:
|
||||
case EAssetCategory.Texture:
|
||||
{
|
||||
if (!resolve.HasFlag(EResolveCompute.Preview))
|
||||
break;
|
||||
|
||||
if (pointer.Object.Value is UTexture2DArray textureArray && textureArray.GetFirstMip() is { SizeZ: > 1 } firstMip)
|
||||
if (obj is UTexture2DArray textureArray && textureArray.GetFirstMip() is { SizeZ: > 1 } firstMip)
|
||||
NumTextures = firstMip.SizeZ;
|
||||
|
||||
var img = texture.Decode(MaxPreviewSize, UserSettings.Default.CurrentDir.TexturePlatform);
|
||||
var options = UserSettings.GetExportOptions();
|
||||
var img = obj switch
|
||||
{
|
||||
UTexture texture => texture.Decode(MaxPreviewSize, options),
|
||||
UPaperSprite sprite => sprite.Decode(options),
|
||||
_ => null
|
||||
};
|
||||
if (img != null)
|
||||
{
|
||||
using var bitmap = img.ToSkBitmap();
|
||||
using var image = bitmap.Encode(SKEncodedImageFormat.Png, 100);
|
||||
SetPreviewImage(image);
|
||||
}
|
||||
else
|
||||
{
|
||||
Resolved |= EResolveCompute.Preview;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case EAssetCategory.AnimatedTexture when obj is UPaperFlipbook flipbook:
|
||||
{
|
||||
if (!resolve.HasFlag(EResolveCompute.Preview))
|
||||
break;
|
||||
|
||||
var preview = ImageAnimation.CreateThumbnail(flipbook, UserSettings.GetExportOptions(), MaxPreviewSize);
|
||||
Application.Current.Dispatcher.InvokeAsync(() => PreviewImage = preview);
|
||||
if (preview == null) Resolved |= EResolveCompute.Preview;
|
||||
break;
|
||||
}
|
||||
case EAssetCategory.ItemDefinitionBase:
|
||||
if (!resolve.HasFlag(EResolveCompute.Preview))
|
||||
break;
|
||||
|
||||
if (pointer.Object.Value is UItemDefinitionBase itemDef)
|
||||
if (obj is UItemDefinitionBase itemDef)
|
||||
{
|
||||
if (LookupPreview(itemDef.DataList)) break;
|
||||
|
||||
@@ -372,7 +398,7 @@ public class GameFileViewModel(GameFile asset) : ViewModel
|
||||
!icon.TryLoad<UTexture2D>(out var texture))
|
||||
continue;
|
||||
|
||||
var img = texture.Decode(MaxPreviewSize, UserSettings.Default.CurrentDir.TexturePlatform);
|
||||
var img = texture.Decode(MaxPreviewSize, UserSettings.GetExportOptions());
|
||||
if (img == null) return false;
|
||||
|
||||
using var bitmap = img.ToSkBitmap();
|
||||
@@ -515,7 +541,6 @@ public class GameFileViewModel(GameFile asset) : ViewModel
|
||||
|
||||
using var image = bitmap.Encode(lowercaseExtension == "jpg" ? SKEncodedImageFormat.Jpeg : SKEncodedImageFormat.Png, 100);
|
||||
SetPreviewImage(image);
|
||||
|
||||
bitmap.Dispose();
|
||||
});
|
||||
}
|
||||
@@ -550,14 +575,12 @@ public class GameFileViewModel(GameFile asset) : ViewModel
|
||||
{
|
||||
using var ms = new MemoryStream(data.ToArray());
|
||||
ms.Position = 0;
|
||||
|
||||
var bitmap = new BitmapImage();
|
||||
bitmap.BeginInit();
|
||||
bitmap.CacheOption = BitmapCacheOption.OnLoad;
|
||||
bitmap.StreamSource = ms;
|
||||
bitmap.EndInit();
|
||||
bitmap.Freeze();
|
||||
|
||||
Application.Current.Dispatcher.InvokeAsync(() => PreviewImage = bitmap);
|
||||
}
|
||||
|
||||
@@ -570,7 +593,6 @@ public class GameFileViewModel(GameFile asset) : ViewModel
|
||||
_previewCts?.Cancel();
|
||||
_previewCts = new CancellationTokenSource();
|
||||
var token = _previewCts.Token;
|
||||
|
||||
Task.Delay(100, token).ContinueWith(t =>
|
||||
{
|
||||
if (t.IsCanceled) return;
|
||||
|
||||
@@ -7,9 +7,11 @@ using System.Windows;
|
||||
using System.Windows.Media.Imaging;
|
||||
using CUE4Parse_Conversion.Options;
|
||||
using CUE4Parse.FileProvider.Objects;
|
||||
using CUE4Parse.UE4.Assets.Exports.Paper2D;
|
||||
using CUE4Parse.UE4.Assets.Exports.Texture;
|
||||
using CUE4Parse.Utils;
|
||||
using CUE4Parse_Conversion.Textures;
|
||||
using CUE4Parse_Conversion.Textures.Paper2D;
|
||||
using FModel.Extensions;
|
||||
using FModel.Framework;
|
||||
using FModel.Services;
|
||||
@@ -25,31 +27,62 @@ namespace FModel.ViewModels;
|
||||
|
||||
public class TabImage : ViewModel
|
||||
{
|
||||
private readonly string _name;
|
||||
private readonly object _source;
|
||||
|
||||
public string ExportName { get; set; }
|
||||
|
||||
public byte[] ImageBuffer { get; set; }
|
||||
|
||||
public ImageAnimation.Frame[] AnimationFrames { get; }
|
||||
public bool CanDisableAlpha => AnimationFrames == null;
|
||||
|
||||
public TabImage(string name, CFlipbook flipbook)
|
||||
{
|
||||
_name = name;
|
||||
_source = flipbook;
|
||||
RenderNearestNeighbor = true;
|
||||
Encode(UserSettings.GetExportOptions());
|
||||
AnimationFrames = ImageAnimation.CreateFrames(flipbook);
|
||||
Image = ImageAnimation.CreateSource(AnimationFrames);
|
||||
}
|
||||
|
||||
public TabImage(string name, bool rnn, SKBitmap img)
|
||||
{
|
||||
ExportName = name;
|
||||
_name = name;
|
||||
_source = img;
|
||||
RenderNearestNeighbor = rnn;
|
||||
SetImage(img);
|
||||
Encode(UserSettings.GetExportOptions());
|
||||
}
|
||||
|
||||
public TabImage(string name, bool rnn, CTexture img)
|
||||
{
|
||||
ExportName = name;
|
||||
_name = name;
|
||||
_source = img;
|
||||
RenderNearestNeighbor = rnn;
|
||||
SetImage(img);
|
||||
SetImage(img?.ToSkBitmap());
|
||||
Encode(UserSettings.GetExportOptions());
|
||||
}
|
||||
|
||||
private BitmapImage _image;
|
||||
public BitmapImage Image
|
||||
public TabImage(string exportName, byte[] data, SKBitmap preview)
|
||||
{
|
||||
_name = Path.GetFileNameWithoutExtension(exportName);
|
||||
_source = data;
|
||||
ExportName = exportName;
|
||||
ImageBuffer = data;
|
||||
SetImage(preview);
|
||||
}
|
||||
|
||||
private BitmapSource _image;
|
||||
public BitmapSource Image
|
||||
{
|
||||
get => _image;
|
||||
set
|
||||
{
|
||||
if (_image == value) return;
|
||||
if (_image == value)
|
||||
return;
|
||||
|
||||
SetProperty(ref _image, value);
|
||||
}
|
||||
}
|
||||
@@ -67,6 +100,9 @@ public class TabImage : ViewModel
|
||||
get => _noAlpha;
|
||||
set
|
||||
{
|
||||
if (!CanDisableAlpha)
|
||||
return;
|
||||
|
||||
SetProperty(ref _noAlpha, value);
|
||||
ResetImage();
|
||||
}
|
||||
@@ -82,49 +118,54 @@ public class TabImage : ViewModel
|
||||
}
|
||||
|
||||
_bmp = bitmap;
|
||||
ExportName += "." + (NoAlpha ? "jpg" : "png");
|
||||
using var data = _bmp.Encode(NoAlpha ? SKEncodedImageFormat.Jpeg : SKEncodedImageFormat.Png, 100);
|
||||
using var stream = new MemoryStream(ImageBuffer = data.ToArray(), false);
|
||||
var image = new BitmapImage();
|
||||
image.BeginInit();
|
||||
image.CacheOption = BitmapCacheOption.OnLoad;
|
||||
image.StreamSource = stream;
|
||||
image.EndInit();
|
||||
image.Freeze();
|
||||
Image = image;
|
||||
using var opaque = NoAlpha ? _bmp.Copy(SKColorType.Rgb888x) : null;
|
||||
using var data = (opaque ?? _bmp).Encode(SKEncodedImageFormat.Png, 100);
|
||||
using var stream = new MemoryStream(data.ToArray(), false);
|
||||
Image = CreateImage(stream);
|
||||
}
|
||||
|
||||
private void SetImage(CTexture bitmap)
|
||||
public void Encode(ExportOptions options)
|
||||
{
|
||||
if (bitmap is null)
|
||||
string ext;
|
||||
switch (_source)
|
||||
{
|
||||
ImageBuffer = null;
|
||||
Image = null;
|
||||
return;
|
||||
case byte[] data:
|
||||
ImageBuffer = data;
|
||||
return;
|
||||
case CFlipbook flipbook:
|
||||
ImageBuffer = flipbook.Encode(options, out ext);
|
||||
break;
|
||||
case CTexture texture:
|
||||
ImageBuffer = texture.Encode(options, out ext);
|
||||
break;
|
||||
case SKBitmap source:
|
||||
{
|
||||
using var bitmap = new SKBitmap(new SKImageInfo(source.Width, source.Height, SKColorType.Rgba8888, SKAlphaType.Unpremul));
|
||||
using var pixels = source.PeekPixels();
|
||||
if (!pixels.ReadPixels(bitmap.Info, bitmap.GetPixels(), bitmap.RowBytes))
|
||||
throw new InvalidOperationException("Failed to read image pixels for export.");
|
||||
|
||||
var converted = new CTexture(bitmap.Width, bitmap.Height, EPixelFormat.PF_R8G8B8A8, bitmap.Bytes);
|
||||
ImageBuffer = converted.Encode(options, out ext);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
_bmp = bitmap.ToSkBitmap();
|
||||
byte[] imageData = _bmp.Encode(NoAlpha ? SKEncodedImageFormat.Jpeg : SKEncodedImageFormat.Png, 100).ToArray();
|
||||
ExportName = _name + "." + ext;
|
||||
}
|
||||
|
||||
if (PixelFormatUtils.IsHDR(bitmap.PixelFormat) || (UserSettings.Default.TextureExportFormat != ETextureFormat.Jpeg && UserSettings.Default.TextureExportFormat != ETextureFormat.Png))
|
||||
{
|
||||
ImageBuffer = bitmap.Encode(UserSettings.Default.TextureExportFormat, UserSettings.Default.SaveHdrTexturesAsHdr, out var ext);
|
||||
ExportName += "." + ext;
|
||||
}
|
||||
else
|
||||
{
|
||||
ImageBuffer = imageData;
|
||||
ExportName += "." + (NoAlpha || UserSettings.Default.TextureExportFormat == ETextureFormat.Jpeg ? "jpg" : "png");
|
||||
}
|
||||
|
||||
using var stream = new MemoryStream(imageData);
|
||||
private static BitmapImage CreateImage(Stream stream)
|
||||
{
|
||||
stream.Position = 0;
|
||||
var image = new BitmapImage();
|
||||
image.BeginInit();
|
||||
image.CacheOption = BitmapCacheOption.OnLoad;
|
||||
image.StreamSource = stream;
|
||||
image.EndInit();
|
||||
image.Freeze();
|
||||
Image = image;
|
||||
return image;
|
||||
}
|
||||
|
||||
private SKBitmap _bmp;
|
||||
@@ -231,7 +272,9 @@ public class TabItem : ViewModel
|
||||
get => _highlighter;
|
||||
set
|
||||
{
|
||||
if (_highlighter == value) return;
|
||||
if (_highlighter == value)
|
||||
return;
|
||||
|
||||
SetProperty(ref _highlighter, value);
|
||||
}
|
||||
}
|
||||
@@ -242,10 +285,12 @@ public class TabItem : ViewModel
|
||||
get => _selectedImage;
|
||||
set
|
||||
{
|
||||
if (_selectedImage == value) return;
|
||||
if (_selectedImage == value)
|
||||
return;
|
||||
|
||||
SetProperty(ref _selectedImage, value);
|
||||
RaisePropertyChanged("HasImage");
|
||||
RaisePropertyChanged("Page");
|
||||
RaisePropertyChanged(nameof(HasImage));
|
||||
RaisePropertyChanged(nameof(Page));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,7 +314,7 @@ public class TabItem : ViewModel
|
||||
public TabItem(GameFile entry)
|
||||
{
|
||||
Entry = entry;
|
||||
_images = new ObservableCollection<TabImage>();
|
||||
_images = [];
|
||||
}
|
||||
|
||||
public void SoftReset(GameFile entry)
|
||||
@@ -281,25 +326,43 @@ public class TabItem : ViewModel
|
||||
{
|
||||
_images.Clear();
|
||||
SelectedImage = null;
|
||||
RaisePropertyChanged("HasMultipleImages");
|
||||
RaisePropertyChanged(nameof(HasMultipleImages));
|
||||
|
||||
Document ??= new TextDocument();
|
||||
Document.Text = string.Empty;
|
||||
});
|
||||
}
|
||||
|
||||
public void AddImage(UPaperSprite sprite, bool save, bool updateUi)
|
||||
{
|
||||
var decoded = sprite.Decode(UserSettings.GetExportOptions());
|
||||
if (decoded == null)
|
||||
return;
|
||||
|
||||
AddImage(sprite.Name, true, decoded, save, updateUi);
|
||||
}
|
||||
|
||||
public void AddImage(UPaperFlipbook flipbook, bool save, bool updateUi)
|
||||
{
|
||||
var decoded = flipbook.Decode(UserSettings.GetExportOptions());
|
||||
if (decoded == null)
|
||||
return;
|
||||
|
||||
AddImage(new TabImage(flipbook.Name, decoded), save, updateUi);
|
||||
}
|
||||
|
||||
public void AddImage(UTexture texture, bool save, bool updateUi)
|
||||
{
|
||||
var appendLayerNumber = false;
|
||||
var img = new CTexture[1];
|
||||
if (texture is UTexture2DArray textureArray)
|
||||
{
|
||||
img = textureArray.DecodeTextureArray(UserSettings.Default.CurrentDir.TexturePlatform);
|
||||
img = textureArray.DecodeTextureArray(UserSettings.GetExportOptions());
|
||||
appendLayerNumber = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
img[0] = texture.Decode(UserSettings.Default.CurrentDir.TexturePlatform);
|
||||
img[0] = texture.Decode(UserSettings.GetExportOptions());
|
||||
if (texture is UTextureCube)
|
||||
{
|
||||
img[0] = img[0].ToPanorama();
|
||||
@@ -326,32 +389,27 @@ public class TabItem : ViewModel
|
||||
}
|
||||
|
||||
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");
|
||||
});
|
||||
}
|
||||
=> AddImage(new TabImage(name, rnn, img), save, updateUi);
|
||||
|
||||
public void AddImage(string name, bool rnn, SKBitmap img, bool save, bool updateUi)
|
||||
=> AddImage(new TabImage(name, rnn, img), save, updateUi);
|
||||
|
||||
public void AddImage(string exportName, byte[] data, SKBitmap preview, bool save, bool updateUi)
|
||||
=> AddImage(new TabImage(exportName, data, preview), save, updateUi);
|
||||
|
||||
private void AddImage(TabImage image, bool save, bool updateUi)
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
var t = new TabImage(name, rnn, img);
|
||||
if (save) SaveImage(t, updateUi);
|
||||
if (!updateUi) return;
|
||||
if (save)
|
||||
SaveImage(image, updateUi);
|
||||
if (!updateUi)
|
||||
return;
|
||||
|
||||
_images.Add(t);
|
||||
SelectedImage ??= t;
|
||||
RaisePropertyChanged("Page");
|
||||
RaisePropertyChanged("HasMultipleImages");
|
||||
_images.Add(image);
|
||||
SelectedImage ??= image;
|
||||
RaisePropertyChanged(nameof(Page));
|
||||
RaisePropertyChanged(nameof(HasMultipleImages));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -366,15 +424,18 @@ public class TabItem : ViewModel
|
||||
Document.Text = text;
|
||||
Document.UndoStack.ClearAll();
|
||||
|
||||
if (save) SaveProperty(updateUi);
|
||||
if (save)
|
||||
SaveProperty(updateUi);
|
||||
});
|
||||
}
|
||||
|
||||
public void SaveImage() => SaveImage(SelectedImage, true);
|
||||
private void SaveImage(TabImage image, bool updateUi)
|
||||
{
|
||||
if (image is null) return;
|
||||
if (image is null)
|
||||
return;
|
||||
|
||||
image.Encode(UserSettings.GetExportOptions());
|
||||
var path = Path.Combine(UserSettings.Default.TextureDirectory, UserSettings.Default.KeepDirectoryStructure ? Entry.Directory : "", image.ExportName).Replace('\\', '/');
|
||||
|
||||
Directory.CreateDirectory(path.SubstringBeforeLast('/'));
|
||||
@@ -390,7 +451,9 @@ public class TabItem : ViewModel
|
||||
|
||||
private void SaveImage(TabImage image, string path)
|
||||
{
|
||||
if (image.ImageBuffer is null) return;
|
||||
if (image.ImageBuffer is null)
|
||||
return;
|
||||
|
||||
using var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read);
|
||||
fs.Write(image.ImageBuffer, 0, image.ImageBuffer.Length);
|
||||
}
|
||||
@@ -477,7 +540,9 @@ public class TabControlViewModel : ViewModel
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CanAddTabs) return;
|
||||
if (!CanAddTabs)
|
||||
return;
|
||||
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
_tabItems.Add(new TabItem(entry));
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using FModel.Extensions;
|
||||
|
||||
namespace FModel.Views.Resources.Controls.Explorer;
|
||||
|
||||
public class AssetExplorerListBox : ListBox
|
||||
{
|
||||
protected override void OnItemsSourceChanged(IEnumerable oldValue, IEnumerable newValue)
|
||||
public AssetExplorerListBox()
|
||||
{
|
||||
base.OnItemsSourceChanged(oldValue, newValue);
|
||||
AddHandler(ScrollViewer.ScrollChangedEvent, new ScrollChangedEventHandler(OnScrollChanged));
|
||||
}
|
||||
|
||||
// Always start at the top, otherwise inherited offset can cause items not to be visible when we change folder
|
||||
if (this.FindVisualChild<VirtualizingPanel>() is IScrollInfo scroll)
|
||||
// This is important, when we scroll and then change folder, scroll offset won't be adjusted and we will end up with missing items
|
||||
// Same applies to filtering assets as that also changes scroll offset
|
||||
private void OnScrollChanged(object sender, ScrollChangedEventArgs e)
|
||||
{
|
||||
if (e.OriginalSource is ScrollViewer scroll && scroll.VerticalOffset > scroll.ScrollableHeight)
|
||||
{
|
||||
scroll.SetVerticalOffset(0);
|
||||
scroll.ScrollToVerticalOffset(scroll.ScrollableHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:vm="clr-namespace:FModel.ViewModels"
|
||||
xmlns:controls="clr-namespace:FModel.Views.Resources.Controls"
|
||||
xmlns:converters="clr-namespace:FModel.Views.Resources.Converters"
|
||||
xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI"
|
||||
mc:Ignorable="d"
|
||||
@@ -24,6 +25,7 @@
|
||||
Height="20"
|
||||
Margin="0 0 8 0">
|
||||
<Image Stretch="Uniform"
|
||||
controls:ImageAnimation.Frames="{Binding PreviewImage.(controls:ImageAnimation.Frames)}"
|
||||
Source="{Binding PreviewImage}" />
|
||||
<Path x:Name="FallbackIcon"
|
||||
Stretch="Uniform">
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
d:DataContext="{d:DesignInstance Type=vm:GameFileViewModel, IsDesignTimeCreatable=False}"
|
||||
|
||||
xmlns:vm="clr-namespace:FModel.ViewModels"
|
||||
xmlns:controls="clr-namespace:FModel.Views.Resources.Controls"
|
||||
xmlns:converters="clr-namespace:FModel.Views.Resources.Converters"
|
||||
xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI"
|
||||
Width="128" Height="192"
|
||||
@@ -19,7 +20,7 @@
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid Grid.Row="0" Height="128" Background="{DynamicResource {x:Static adonisUi:Brushes.Layer3BorderBrush}}">
|
||||
<Image Stretch="Uniform" Source="{Binding PreviewImage}" />
|
||||
<Image Stretch="Uniform" Source="{Binding PreviewImage}" controls:ImageAnimation.Frames="{Binding PreviewImage.(controls:ImageAnimation.Frames)}" />
|
||||
<Path x:Name="FallbackIcon" Width="64" Stretch="Uniform">
|
||||
<Path.Style>
|
||||
<Style TargetType="{x:Type Path}">
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
@@ -232,8 +233,28 @@
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
|
||||
<TextBlock Grid.Row="13" Grid.Column="0" Text="Texture Platform" VerticalAlignment="Center" Margin="0 0 0 10" />
|
||||
<ComboBox Grid.Row="13" Grid.Column="2" Grid.ColumnSpan="3" Margin="0 0 0 10"
|
||||
<TextBlock Grid.Row="13" Grid.Column="0" Text="Animated Texture Format" VerticalAlignment="Center" Margin="0 0 0 5" />
|
||||
<ComboBox Grid.Row="13" Grid.Column="2" Grid.ColumnSpan="3" Margin="0 0 0 5"
|
||||
ItemsSource="{Binding AnimatedTextureFormats}"
|
||||
SelectedItem="{Binding SelectedAnimatedTextureFormat, Mode=TwoWay}">
|
||||
<ComboBox.Style>
|
||||
<Style TargetType="{x:Type ComboBox}" BasedOn="{StaticResource {x:Type ComboBox}}">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding SelectedAnimatedTextureFormat}" Value="{x:Static c4pMeshes:EAnimatedTextureFormat.Auto}">
|
||||
<Setter Property="ToolTip" Value="Uses the same format you have selected for normal textures (if given format supports animation)." />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ComboBox.Style>
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Converter={x:Static converters:EnumToStringConverter.Instance}}" />
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
|
||||
<TextBlock Grid.Row="14" Grid.Column="0" Text="Texture Platform" VerticalAlignment="Center" Margin="0 0 0 10" />
|
||||
<ComboBox Grid.Row="14" Grid.Column="2" Grid.ColumnSpan="3" Margin="0 0 0 10"
|
||||
ItemsSource="{Binding TexturePlatforms}"
|
||||
SelectedItem="{Binding SelectedTexturePlatform, Mode=TwoWay}">
|
||||
<ComboBox.ItemTemplate>
|
||||
@@ -243,17 +264,17 @@
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
|
||||
<TextBlock Grid.Row="14" Grid.Column="0" Text="Texture Quality" VerticalAlignment="Center" Margin="0 0 0 12"
|
||||
<TextBlock Grid.Row="15" Grid.Column="0" Text="Texture Quality" VerticalAlignment="Center" Margin="0 0 0 12"
|
||||
Visibility="{Binding ShowTextureQuality, Converter={StaticResource BoolToVisibilityConverter}}" />
|
||||
<Slider Grid.Row="14" Grid.Column="2" Grid.ColumnSpan="3" Minimum="1" Maximum="100" TickPlacement="None"
|
||||
<Slider Grid.Row="15" Grid.Column="2" Grid.ColumnSpan="3" Minimum="1" Maximum="100" TickPlacement="None"
|
||||
AutoToolTipPlacement="BottomRight" IsMoveToPointEnabled="True" IsSnapToTickEnabled="True" Margin="0 0 0 12"
|
||||
Value="{Binding TextureQuality, Mode=TwoWay}"
|
||||
Visibility="{Binding ShowTextureQuality, Converter={StaticResource BoolToVisibilityConverter}}" />
|
||||
|
||||
<TextBlock x:Name="PngCompressionText" Grid.Row="14" Grid.Column="0" Text="PNG Compression" VerticalAlignment="Center" Margin="0 0 0 12"
|
||||
<TextBlock x:Name="PngCompressionText" Grid.Row="15" Grid.Column="0" Text="PNG Compression" VerticalAlignment="Center" Margin="0 0 0 12"
|
||||
ToolTip="Lossless compression. Level 3 is recommended for speed."
|
||||
Visibility="{Binding ShowPngCompression, Converter={StaticResource BoolToVisibilityConverter}}" />
|
||||
<Grid Grid.Row="14" Grid.Column="2" Grid.ColumnSpan="3" Margin="0 0 0 12"
|
||||
<Grid Grid.Row="15" Grid.Column="2" Grid.ColumnSpan="3" Margin="0 0 0 12"
|
||||
ToolTip="{Binding ToolTip, ElementName=PngCompressionText}"
|
||||
Visibility="{Binding ShowPngCompression, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
<Grid.ColumnDefinitions>
|
||||
@@ -266,37 +287,37 @@
|
||||
<TextBlock Grid.Column="1" Text="{Binding PngCompressionLevel}" VerticalAlignment="Center" Margin="8 0 0 0" />
|
||||
</Grid>
|
||||
|
||||
<TextBlock Grid.Row="14" Grid.Column="0" Text="TGA RLE Compression" VerticalAlignment="Center" Margin="0 0 0 12"
|
||||
<TextBlock Grid.Row="15" Grid.Column="0" Text="TGA RLE Compression" VerticalAlignment="Center" Margin="0 0 0 12"
|
||||
ToolTip="Lossless compression of repeated pixels. File size depends on the image."
|
||||
Visibility="{Binding ShowTgaCompression, Converter={StaticResource BoolToVisibilityConverter}}" />
|
||||
<CheckBox Grid.Row="14" Grid.Column="2" Grid.ColumnSpan="3" Margin="0 0 0 12"
|
||||
<CheckBox Grid.Row="15" Grid.Column="2" Grid.ColumnSpan="3" Margin="0 0 0 12"
|
||||
IsChecked="{Binding TgaRleCompression, Mode=TwoWay}"
|
||||
Content="{Binding IsChecked, RelativeSource={RelativeSource Self}, Converter={x:Static converters:BoolToToggleConverter.Instance}}"
|
||||
Style="{DynamicResource {x:Static adonisUi:Styles.ToggleSwitch}}"
|
||||
Visibility="{Binding ShowTgaCompression, Converter={StaticResource BoolToVisibilityConverter}}" />
|
||||
|
||||
<TextBlock Grid.Row="15" Grid.Column="0" Text="Save HDR as .hdr" VerticalAlignment="Center" Margin="0 0 0 12" />
|
||||
<CheckBox Grid.Row="15" Grid.Column="2" Grid.ColumnSpan="3"
|
||||
<TextBlock Grid.Row="16" Grid.Column="0" Text="Save HDR as .hdr" VerticalAlignment="Center" Margin="0 0 0 12" />
|
||||
<CheckBox Grid.Row="16" Grid.Column="2" Grid.ColumnSpan="3"
|
||||
IsChecked="{Binding ExportHdrTexturesAsHdr, Mode=TwoWay}"
|
||||
Content="{Binding IsChecked, RelativeSource={RelativeSource Self}, Converter={x:Static converters:BoolToToggleConverter.Instance}}"
|
||||
Style="{DynamicResource {x:Static adonisUi:Styles.ToggleSwitch}}"
|
||||
Margin="0 0 0 12" />
|
||||
|
||||
<TextBlock Grid.Row="16"
|
||||
<TextBlock Grid.Row="17"
|
||||
Grid.Column="0"
|
||||
Text="Export All Mips"
|
||||
VerticalAlignment="Center" />
|
||||
<CheckBox Grid.Row="16"
|
||||
<CheckBox Grid.Row="17"
|
||||
Grid.Column="2"
|
||||
Grid.ColumnSpan="3"
|
||||
IsChecked="{Binding ExportAllTextureMips, Mode=TwoWay}"
|
||||
Content="{Binding IsChecked, RelativeSource={RelativeSource Self}, Converter={x:Static converters:BoolToToggleConverter.Instance}}"
|
||||
Style="{DynamicResource {x:Static adonisUi:Styles.ToggleSwitch}}" />
|
||||
|
||||
<Separator Grid.Row="17" Grid.Column="0" Grid.ColumnSpan="5" Style="{StaticResource CustomSeparator}" Tag="MATERIAL & MORPH" Margin="0 10 0 10" />
|
||||
<Separator Grid.Row="18" Grid.Column="0" Grid.ColumnSpan="5" Style="{StaticResource CustomSeparator}" Tag="MATERIAL & MORPH" Margin="0 10 0 10" />
|
||||
|
||||
<TextBlock Grid.Row="18" Grid.Column="0" Text="Material Depth" VerticalAlignment="Center" Margin="0 0 0 12" />
|
||||
<ComboBox Grid.Row="18" Grid.Column="2" Grid.ColumnSpan="3" Margin="0 0 0 12"
|
||||
<TextBlock Grid.Row="19" Grid.Column="0" Text="Material Depth" VerticalAlignment="Center" Margin="0 0 0 12" />
|
||||
<ComboBox Grid.Row="19" Grid.Column="2" Grid.ColumnSpan="3" Margin="0 0 0 12"
|
||||
ItemsSource="{Binding MaterialDepths}"
|
||||
SelectedItem="{Binding SelectedMaterialDepth, Mode=TwoWay}">
|
||||
<ComboBox.ItemTemplate>
|
||||
@@ -306,9 +327,9 @@
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
|
||||
<TextBlock Grid.Row="19" Grid.Column="0" Text="Auto-Export Attached Materials" VerticalAlignment="Center" Margin="0 0 0 15"
|
||||
<TextBlock Grid.Row="20" Grid.Column="0" Text="Auto-Export Attached Materials" VerticalAlignment="Center" Margin="0 0 0 15"
|
||||
ToolTip="When exporting a mesh, also find and export its attached materials." />
|
||||
<Grid Grid.Row="19" Grid.Column="2" Grid.ColumnSpan="3" Margin="0 0 0 15">
|
||||
<Grid Grid.Row="20" Grid.Column="2" Grid.ColumnSpan="3" Margin="0 0 0 15">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
@@ -323,8 +344,8 @@
|
||||
Text="For geometry-only exports, it can be significantly faster to disable this option." />
|
||||
</Grid>
|
||||
|
||||
<TextBlock Grid.Row="20" Grid.Column="0" Text="Export Morph Targets" VerticalAlignment="Center" Margin="0 0 0 15" />
|
||||
<CheckBox Grid.Row="20" Grid.Column="2" Grid.ColumnSpan="3" Margin="0 0 0 15"
|
||||
<TextBlock Grid.Row="21" Grid.Column="0" Text="Export Morph Targets" VerticalAlignment="Center" Margin="0 0 0 15" />
|
||||
<CheckBox Grid.Row="21" Grid.Column="2" Grid.ColumnSpan="3" Margin="0 0 0 15"
|
||||
IsChecked="{Binding ExportMorphTargets, Mode=TwoWay}"
|
||||
Content="{Binding IsChecked, RelativeSource={RelativeSource Self}, Converter={x:Static converters:BoolToToggleConverter.Instance}}"
|
||||
Style="{DynamicResource {x:Static adonisUi:Styles.ToggleSwitch}}" />
|
||||
|
||||
164
FModel/Views/Resources/Controls/ImageAnimation.cs
Normal file
164
FModel/Views/Resources/Controls/ImageAnimation.cs
Normal file
@@ -0,0 +1,164 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Threading;
|
||||
using CUE4Parse.UE4.Assets.Exports.Paper2D;
|
||||
using CUE4Parse_Conversion.Options;
|
||||
using CUE4Parse_Conversion.Textures;
|
||||
using CUE4Parse_Conversion.Textures.Paper2D;
|
||||
|
||||
namespace FModel.Views.Resources.Controls;
|
||||
|
||||
public static class ImageAnimation
|
||||
{
|
||||
public sealed record Frame(BitmapSource Image, TimeSpan Duration);
|
||||
|
||||
public static readonly DependencyProperty FramesProperty = DependencyProperty.RegisterAttached("Frames", typeof(IReadOnlyList<Frame>), typeof(ImageAnimation), new PropertyMetadata(null, OnFramesChanged));
|
||||
|
||||
private static readonly DependencyProperty _playbackProperty = DependencyProperty.RegisterAttached("Playback", typeof(Playback), typeof(ImageAnimation));
|
||||
|
||||
public static IReadOnlyList<Frame> GetFrames(DependencyObject image) => (IReadOnlyList<Frame>) image.GetValue(FramesProperty);
|
||||
public static void SetFrames(DependencyObject image, IReadOnlyList<Frame> frames) => image.SetValue(FramesProperty, frames);
|
||||
|
||||
public static BitmapSource CreateSource(IReadOnlyList<Frame> frames)
|
||||
{
|
||||
if (frames is not { Count: > 0 })
|
||||
return null;
|
||||
if (frames.Count == 1)
|
||||
return frames[0].Image;
|
||||
|
||||
var source = frames[0].Image.Clone();
|
||||
SetFrames(source, frames);
|
||||
source.Freeze();
|
||||
return source;
|
||||
}
|
||||
|
||||
internal static Frame[] CreateFrames(CFlipbook flipbook, int maxSize = 0, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var animation = flipbook.ToImage(new ExportOptions(), maxSize: maxSize, cancellationToken: cancellationToken);
|
||||
var frames = new Frame[animation.Frames.Count];
|
||||
var minimumDuration = maxSize > 0 ? 1.0 / 15 : 0.001;
|
||||
for (var i = 0; i < frames.Length; i++)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var frame = animation.Frames[i];
|
||||
var pixels = new byte[frame.Width * frame.Height * 4];
|
||||
frame.CopyPixelDataTo(pixels);
|
||||
for (var pixel = 0; pixel < pixels.Length; pixel += 4)
|
||||
{
|
||||
(pixels[pixel], pixels[pixel + 2]) = (pixels[pixel + 2], pixels[pixel]);
|
||||
}
|
||||
|
||||
var image = BitmapSource.Create(frame.Width, frame.Height, 96, 96, PixelFormats.Bgra32, null, pixels, frame.Width * 4);
|
||||
image.Freeze();
|
||||
|
||||
var seconds = flipbook.FramesPerSecond > 0 ? flipbook.Frames[i].FrameRun / (double) flipbook.FramesPerSecond : 0;
|
||||
frames[i] = new Frame(image, TimeSpan.FromSeconds(Math.Max(minimumDuration, seconds)));
|
||||
}
|
||||
|
||||
return frames;
|
||||
}
|
||||
|
||||
// Only light animations, otherwise use the first frame as a thumbnail
|
||||
internal static BitmapSource CreateThumbnail(UPaperFlipbook flipbook, ExportOptions options, int maxSize)
|
||||
{
|
||||
var cache = new Dictionary<string, CTexture>();
|
||||
if (flipbook.FramesPerSecond > 0 && flipbook.KeyFrames.Length is > 1 and <= 64)
|
||||
{
|
||||
var pixels = flipbook.KeyFrames.Where(frame => frame.FrameRun > 0).Select(frame => frame.LoadSprite()).OfType<UPaperSprite>().Distinct()
|
||||
.Sum(sprite => (double) sprite.BakedSourceDimension.X * sprite.BakedSourceDimension.Y);
|
||||
if (pixels <= 16 * 1024 * 1024 && flipbook.Decode(options, cache) is { } decoded)
|
||||
{
|
||||
var minimumRun = Math.Max(1, (int) Math.Ceiling(decoded.FramesPerSecond / 15));
|
||||
var frames = new List<CFlipbookFrame>();
|
||||
foreach (var frame in decoded.Frames)
|
||||
{
|
||||
if (frames.Count > 0 && frames[^1].FrameRun < minimumRun)
|
||||
{
|
||||
var previous = frames[^1];
|
||||
frames[^1] = new CFlipbookFrame(previous.Texture, previous.FrameRun + frame.FrameRun, previous.Offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
frames.Add(frame);
|
||||
}
|
||||
}
|
||||
|
||||
return CreateSource(CreateFrames(new CFlipbook(frames, decoded.FramesPerSecond), maxSize));
|
||||
}
|
||||
}
|
||||
|
||||
var first = flipbook.KeyFrames.Where(frame => frame.FrameRun > 0).Select(frame => frame.LoadSprite()?.Decode(options, cache)).FirstOrDefault(texture => texture != null);
|
||||
return first == null ? null : CreateSource(CreateFrames(new CFlipbook([new CFlipbookFrame(first)], 1), maxSize));
|
||||
}
|
||||
|
||||
private static void OnFramesChanged(DependencyObject element, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
if (element is not Image image)
|
||||
return;
|
||||
|
||||
(image.GetValue(_playbackProperty) as Playback)?.Dispose();
|
||||
image.ClearValue(_playbackProperty);
|
||||
if (args.NewValue is not IReadOnlyList<Frame> { Count: > 0 } frames)
|
||||
return;
|
||||
|
||||
image.SetCurrentValue(Image.SourceProperty, frames[0].Image);
|
||||
if (frames.Count > 1)
|
||||
{
|
||||
image.SetValue(_playbackProperty, new Playback(image, frames));
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class Playback : IDisposable
|
||||
{
|
||||
private readonly Image _image;
|
||||
private readonly IReadOnlyList<Frame> _frames;
|
||||
private readonly DispatcherTimer _timer;
|
||||
private int _index;
|
||||
|
||||
public Playback(Image image, IReadOnlyList<Frame> frames)
|
||||
{
|
||||
_image = image;
|
||||
_frames = frames;
|
||||
_timer = new DispatcherTimer(DispatcherPriority.Render, image.Dispatcher) { Interval = frames[0].Duration };
|
||||
_timer.Tick += (_, _) =>
|
||||
{
|
||||
_index = (_index + 1) % _frames.Count;
|
||||
_image.SetCurrentValue(Image.SourceProperty, _frames[_index].Image);
|
||||
_timer.Interval = _frames[_index].Duration;
|
||||
};
|
||||
image.Loaded += UpdatePlayback;
|
||||
image.Unloaded += OnUnloaded;
|
||||
image.IsVisibleChanged += OnIsVisibleChanged;
|
||||
UpdatePlayback(image, null);
|
||||
}
|
||||
|
||||
private void UpdatePlayback(object sender, RoutedEventArgs args)
|
||||
{
|
||||
if (_image.IsLoaded && _image.IsVisible)
|
||||
{
|
||||
_timer.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
_timer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnUnloaded(object sender, RoutedEventArgs args) => _timer.Stop();
|
||||
private void OnIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs args) => UpdatePlayback(sender, null);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_timer.Stop();
|
||||
_image.Loaded -= UpdatePlayback;
|
||||
_image.Unloaded -= OnUnloaded;
|
||||
_image.IsVisibleChanged -= OnIsVisibleChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ public class FileToGeometryConverter : IMultiValueConverter
|
||||
EAssetCategory.UserDefinedStruct => ("BlueprintIcon", "UserDefinedStructBrush"),
|
||||
EAssetCategory.CookedMetaData => ("BlueprintIcon", "CookedMetaDataBrush"),
|
||||
|
||||
EAssetCategory.Texture => ("TextureIconAlt", "TextureBrush"),
|
||||
EAssetCategory.Texture or EAssetCategory.AnimatedTexture => ("TextureIconAlt", "TextureBrush"),
|
||||
|
||||
EAssetCategory.StaticMesh => ("StaticMeshIconAlt", "NeutralBrush"),
|
||||
EAssetCategory.SkeletalMesh => ("SkeletalMeshIconAlt", "NeutralBrush"),
|
||||
|
||||
@@ -528,6 +528,7 @@
|
||||
<Border Grid.Column="2" BorderBrush="#3b3d4a" BorderThickness="1" HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
Visibility="{Binding SelectedItem.HasImage, ElementName=TabControlName, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
<Image VerticalAlignment="Center" HorizontalAlignment="Center" Stretch="Uniform"
|
||||
controls:ImageAnimation.Frames="{Binding SelectedItem.SelectedImage.AnimationFrames, ElementName=TabControlName}"
|
||||
Visibility="{Binding SelectedItem.HasImage, ElementName=TabControlName, Converter={StaticResource BoolToVisibilityConverter}}"
|
||||
Source="{Binding SelectedItem.SelectedImage.Image, ElementName=TabControlName}" RenderOptions.BitmapScalingMode="{Binding SelectedItem.SelectedImage.RenderNearestNeighbor, ElementName=TabControlName, Converter={x:Static converters:BoolToRenderModeConverter.Instance}}">
|
||||
<Image.InputBindings>
|
||||
@@ -535,8 +536,7 @@
|
||||
</Image.InputBindings>
|
||||
<Image.ContextMenu>
|
||||
<ContextMenu DataContext="{Binding PlacementTarget, RelativeSource={RelativeSource Self}}">
|
||||
<MenuItem Header="Disable Alpha Channel" IsCheckable="True" IsChecked="{Binding DataContext.SelectedImage.NoAlpha}" />
|
||||
<MenuItem Header="Open Image" Command="{Binding DataContext.ImageCommand}" CommandParameter="Open">
|
||||
<MenuItem Header="Open in New Window" Command="{Binding DataContext.ImageCommand}" CommandParameter="Open">
|
||||
<MenuItem.Icon>
|
||||
<Viewbox Width="16" Height="16">
|
||||
<Canvas Width="24" Height="24">
|
||||
@@ -547,7 +547,7 @@
|
||||
</Viewbox>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Copy Image" Command="{Binding DataContext.ImageCommand}" CommandParameter="Copy">
|
||||
<MenuItem Header="Copy Image" Command="{Binding DataContext.ImageCommand}" CommandParameter="{Binding Source}">
|
||||
<MenuItem.Icon>
|
||||
<Viewbox Width="16" Height="16">
|
||||
<Canvas Width="24" Height="24">
|
||||
@@ -556,7 +556,7 @@
|
||||
</Viewbox>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Save Image" Command="{Binding DataContext.ImageCommand}" CommandParameter="Save">
|
||||
<MenuItem Header="Export Image" Command="{Binding DataContext.ImageCommand}" CommandParameter="Save">
|
||||
<MenuItem.Icon>
|
||||
<Viewbox Width="16" Height="16">
|
||||
<Canvas Width="24" Height="24">
|
||||
@@ -565,6 +565,9 @@
|
||||
</Viewbox>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem Header="Ignore Alpha in Preview" IsCheckable="True" IsChecked="{Binding DataContext.SelectedImage.NoAlpha}"
|
||||
IsEnabled="{Binding DataContext.SelectedImage.CanDisableAlpha}" />
|
||||
</ContextMenu>
|
||||
</Image.ContextMenu>
|
||||
</Image>
|
||||
|
||||
2
Snooper
2
Snooper
Submodule Snooper updated: 526a2be78d...e59c8966e3
Reference in New Issue
Block a user