mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
Fix ColorTable preview with legacy color tables.
This commit is contained in:
parent
f11cefcec1
commit
b30de460e7
5 changed files with 23 additions and 19 deletions
|
|
@ -1 +1 @@
|
|||
Subproject commit b8282970ee78a2c085e740f60450fecf7ea58b9c
|
||||
Subproject commit b83ce830919ca56e8b066d48d588c889df3af39b
|
||||
|
|
@ -49,7 +49,7 @@ public class MaterialExporter
|
|||
private static MaterialBuilder BuildCharacter(Material material, string name)
|
||||
{
|
||||
// Build the textures from the color table.
|
||||
var table = material.Mtrl.Table;
|
||||
var table = new LegacyColorTable(material.Mtrl.Table);
|
||||
|
||||
var normal = material.Textures[TextureUsage.SamplerNormal];
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ public class MaterialExporter
|
|||
|
||||
// TODO: It feels a little silly to request the entire normal here when extracting the normal only needs some of the components.
|
||||
// As a future refactor, it would be neat to accept a single-channel field here, and then do composition of other stuff later.
|
||||
private readonly struct ProcessCharacterNormalOperation(Image<Rgba32> normal, ColorTable table) : IRowOperation
|
||||
private readonly struct ProcessCharacterNormalOperation(Image<Rgba32> normal, LegacyColorTable table) : IRowOperation
|
||||
{
|
||||
public Image<Rgba32> Normal { get; } = normal.Clone();
|
||||
public Image<Rgba32> BaseColor { get; } = new(normal.Width, normal.Height);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace Penumbra.Interop.MaterialPreview;
|
|||
public sealed unsafe class LiveColorTablePreviewer : LiveMaterialPreviewerBase
|
||||
{
|
||||
public const int TextureWidth = 4;
|
||||
public const int TextureHeight = GameData.Files.MaterialStructs.ColorTable.NumUsedRows;
|
||||
public const int TextureHeight = GameData.Files.MaterialStructs.LegacyColorTable.NumUsedRows;
|
||||
public const int TextureLength = TextureWidth * TextureHeight * 4;
|
||||
|
||||
private readonly IFramework _framework;
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ public partial class ModEditWindow
|
|||
{
|
||||
var ret = false;
|
||||
if (tab.Mtrl.HasDyeTable)
|
||||
for (var i = 0; i < ColorTable.NumUsedRows; ++i)
|
||||
for (var i = 0; i < LegacyColorTable.NumUsedRows; ++i)
|
||||
ret |= tab.Mtrl.ApplyDyeTemplate(_stainService.StmFile, i, dyeId, 0);
|
||||
|
||||
tab.UpdateColorTablePreview();
|
||||
|
|
@ -170,6 +170,7 @@ public partial class ModEditWindow
|
|||
}
|
||||
}
|
||||
|
||||
[SkipLocalsInit]
|
||||
private static unsafe void ColorTableCopyClipboardButton(ColorTable.Row row, ColorDyeTable.Row dye)
|
||||
{
|
||||
if (!ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Clipboard.ToIconString(), ImGui.GetFrameHeight() * Vector2.One,
|
||||
|
|
@ -178,11 +179,11 @@ public partial class ModEditWindow
|
|||
|
||||
try
|
||||
{
|
||||
var data = new byte[ColorTable.Row.Size + 2];
|
||||
Span<byte> data = stackalloc byte[ColorTable.Row.Size + ColorDyeTable.Row.Size];
|
||||
fixed (byte* ptr = data)
|
||||
{
|
||||
MemoryUtility.MemCpyUnchecked(ptr, &row, ColorTable.Row.Size);
|
||||
MemoryUtility.MemCpyUnchecked(ptr + ColorTable.Row.Size, &dye, 2);
|
||||
MemoryUtility.MemCpyUnchecked(ptr, &row, ColorTable.Row.Size);
|
||||
MemoryUtility.MemCpyUnchecked(ptr + ColorTable.Row.Size, &dye, ColorDyeTable.Row.Size);
|
||||
}
|
||||
|
||||
var text = Convert.ToBase64String(data);
|
||||
|
|
@ -218,7 +219,7 @@ public partial class ModEditWindow
|
|||
{
|
||||
var text = ImGui.GetClipboardText();
|
||||
var data = Convert.FromBase64String(text);
|
||||
if (data.Length != ColorTable.Row.Size + 2
|
||||
if (data.Length != ColorTable.Row.Size + ColorDyeTable.Row.Size
|
||||
|| !tab.Mtrl.HasTable)
|
||||
return false;
|
||||
|
||||
|
|
@ -349,7 +350,7 @@ public partial class ModEditWindow
|
|||
ImGui.TableNextColumn();
|
||||
tmpFloat = row.GlossStrength;
|
||||
ImGui.SetNextItemWidth(floatSize);
|
||||
float glossStrengthMin = ImGui.GetIO().KeyCtrl ? 0.0f : HalfEpsilon;
|
||||
var glossStrengthMin = ImGui.GetIO().KeyCtrl ? 0.0f : HalfEpsilon;
|
||||
if (ImGui.DragFloat("##GlossStrength", ref tmpFloat, Math.Max(0.1f, tmpFloat * 0.025f), glossStrengthMin, HalfMaxValue, "%.1f")
|
||||
&& FixFloat(ref tmpFloat, row.GlossStrength))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -455,7 +455,8 @@ public partial class ModEditWindow
|
|||
{
|
||||
UnbindFromMaterialInstances();
|
||||
|
||||
var instances = MaterialInfo.FindMaterials(_edit._resourceTreeFactory.GetLocalPlayerRelatedCharacters().Select(ch => ch.Address), FilePath);
|
||||
var instances = MaterialInfo.FindMaterials(_edit._resourceTreeFactory.GetLocalPlayerRelatedCharacters().Select(ch => ch.Address),
|
||||
FilePath);
|
||||
|
||||
var foundMaterials = new HashSet<nint>();
|
||||
foreach (var materialInfo in instances)
|
||||
|
|
@ -596,13 +597,13 @@ public partial class ModEditWindow
|
|||
if (!Mtrl.HasTable)
|
||||
return;
|
||||
|
||||
var row = Mtrl.Table[rowIdx];
|
||||
var row = new LegacyColorTable.Row(Mtrl.Table[rowIdx]);
|
||||
if (Mtrl.HasDyeTable)
|
||||
{
|
||||
var stm = _edit._stainService.StmFile;
|
||||
var dye = Mtrl.DyeTable[rowIdx];
|
||||
var dye = new LegacyColorDyeTable.Row(Mtrl.DyeTable[rowIdx]);
|
||||
if (stm.TryGetValue(dye.Template, _edit._stainService.StainCombo.CurrentSelection.Key, out var dyes))
|
||||
row.ApplyDyeTemplate(dye, dyes, default);
|
||||
row.ApplyDyeTemplate(dye, dyes);
|
||||
}
|
||||
|
||||
if (HighlightedColorTableRow == rowIdx)
|
||||
|
|
@ -624,17 +625,18 @@ public partial class ModEditWindow
|
|||
if (!Mtrl.HasTable)
|
||||
return;
|
||||
|
||||
var rows = Mtrl.Table;
|
||||
var rows = new LegacyColorTable(Mtrl.Table);
|
||||
var dyeRows = new LegacyColorDyeTable(Mtrl.DyeTable);
|
||||
if (Mtrl.HasDyeTable)
|
||||
{
|
||||
var stm = _edit._stainService.StmFile;
|
||||
var stainId = (StainId)_edit._stainService.StainCombo.CurrentSelection.Key;
|
||||
for (var i = 0; i < ColorTable.NumUsedRows; ++i)
|
||||
for (var i = 0; i < LegacyColorTable.NumUsedRows; ++i)
|
||||
{
|
||||
ref var row = ref rows[i];
|
||||
var dye = Mtrl.DyeTable[i];
|
||||
var dye = dyeRows[i];
|
||||
if (stm.TryGetValue(dye.Template, stainId, out var dyes))
|
||||
row.ApplyDyeTemplate(dye, dyes, default);
|
||||
row.ApplyDyeTemplate(dye, dyes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -643,12 +645,13 @@ public partial class ModEditWindow
|
|||
|
||||
foreach (var previewer in ColorTablePreviewers)
|
||||
{
|
||||
// TODO: Dawntrail
|
||||
rows.AsHalves().CopyTo(previewer.ColorTable);
|
||||
previewer.ScheduleUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
private static void ApplyHighlight(ref ColorTable.Row row, float time)
|
||||
private static void ApplyHighlight(ref LegacyColorTable.Row row, float time)
|
||||
{
|
||||
var level = (MathF.Sin(time * 2.0f * MathF.PI) + 2.0f) / 3.0f / 255.0f;
|
||||
var baseColor = ColorId.InGameHighlight.Value();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue