Skip to content

Commit

Permalink
UTexture2DArray support
Browse files Browse the repository at this point in the history
  • Loading branch information
LongerWarrior committed Dec 8, 2024
1 parent c07dc02 commit 0882062
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions FModel/ViewModels/CUE4ParseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ public void Extract(CancellationToken cancellationToken, string fullPath, bool a
case "bat":
case "dat":
case "cfg":
case "ddr":
case "ide":
case "ipl":
case "zon":
Expand Down
4 changes: 2 additions & 2 deletions FModel/ViewModels/SearchViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private bool ItemFilter(object item, IEnumerable<string> filters)
return filters.All(x => assetItem.FullPath.Contains(x, HasMatchCaseEnabled ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase));

var o = RegexOptions.None;
if (HasMatchCaseEnabled) o |= RegexOptions.IgnoreCase;
if (!HasMatchCaseEnabled) o |= RegexOptions.IgnoreCase;
return new Regex(FilterText, o).Match(assetItem.FullPath).Success;
}
}
}
16 changes: 13 additions & 3 deletions FModel/Views/Snooper/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using FModel.Views.Snooper.Lights;
using FModel.Views.Snooper.Models;
using FModel.Views.Snooper.Shading;
using SkiaSharp;

namespace FModel.Views.Snooper;

Expand Down Expand Up @@ -185,17 +186,26 @@ public void SelectMorph(int index, SkeletalModel model)
model.UpdateMorph(SelectedMorph);
}

public bool TryGetTexture(UTexture2D o, bool fix, out Texture texture)
public bool TryGetTexture(UTexture o, bool fix, out Texture texture)
{
var guid = o.LightingGuid;
if (!Textures.TryGetValue(guid, out texture) &&
o.Decode(UserSettings.Default.PreviewMaxTextureSize, UserSettings.Default.CurrentDir.TexturePlatform) is { } bitmap)
if (Textures.TryGetValue(guid, out texture)) return texture != null;

SKBitmap bitmap = o switch
{
UTexture2D texture2D => texture2D.Decode(UserSettings.Default.PreviewMaxTextureSize, UserSettings.Default.CurrentDir.TexturePlatform),
UTexture2DArray texture2DArray => texture2DArray.DecodeTextureArray(UserSettings.Default.CurrentDir.TexturePlatform)?.FirstOrDefault(),
_ => o.Decode(UserSettings.Default.CurrentDir.TexturePlatform)
};

if (bitmap is not null)
{
texture = new Texture(bitmap, o);
if (fix) TextureHelper.FixChannels(_game, texture);
Textures[guid] = texture;
bitmap.Dispose();
}

return texture != null;
}

Expand Down
6 changes: 3 additions & 3 deletions FModel/Views/Snooper/Shading/Material.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ public void Setup(Options options, int uvCount)
/// <param name="triggers">list of texture parameter names by uv channel</param>
/// <param name="fallback">fallback texture name to use if no top texture found</param>
/// <param name="first">if no top texture, no fallback texture, then use the first texture found</param>
private Texture[] FillTextures(Options options, int uvCount, bool top, IReadOnlyList<string[]> triggers, string fallback, bool first = false)
private Texture[] FillTextures(Options options, int uvCount, bool top, string[][] triggers, string fallback, bool first = false)
{
UTexture2D original;
UTexture original;
Texture transformed;
var fix = fallback == CMaterialParams2.FallbackSpecularMasks;
var textures = new Texture[uvCount];
Expand Down Expand Up @@ -192,7 +192,7 @@ private Texture[] FillTextures(Options options, int uvCount, bool top, IReadOnly
/// <param name="textures">reference array</param>
/// <param name="triggers">list of color parameter names by uv channel</param>
/// <param name="fallback">fallback color to use if no trigger was found</param>
private Vector4[] FillColors(int uvCount, IReadOnlyList<Texture> textures, IReadOnlyList<string[]> triggers, Vector4 fallback)
private Vector4[] FillColors(int uvCount, Texture[] textures, string[][] triggers, Vector4 fallback)
{
var colors = new Vector4[uvCount];
for (int i = 0; i < colors.Length; i++)
Expand Down
4 changes: 1 addition & 3 deletions FModel/Views/Snooper/Shading/Texture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,13 @@ public Texture(int width, int height) : this(TextureType.Framebuffer)
GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, _target, _handle, 0);
}

public Texture(SKBitmap bitmap, UTexture2D texture2D) : this(TextureType.Normal)
public Texture(SKBitmap bitmap, UTexture texture2D) : this(TextureType.Normal)
{
Type = texture2D.ExportType;
Guid = texture2D.LightingGuid;
Name = texture2D.Name;
Path = texture2D.GetPathName();
Format = texture2D.Format;
ImportedWidth = texture2D.ImportedSize.X;
ImportedHeight = texture2D.ImportedSize.Y;
Width = bitmap.Width;
Height = bitmap.Height;
Bind(TextureUnit.Texture0);
Expand Down

0 comments on commit 0882062

Please sign in to comment.