From 1341c4316c3dcf358740022d5a1ee5683b99563b Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Mon, 27 May 2024 17:42:49 +0200 Subject: [PATCH] Use Legacy Color Tables because our materials do not have DT ones yet. --- Glamourer/Designs/DesignConverter.cs | 4 ++-- Glamourer/Gui/Materials/AdvancedDyePopup.cs | 12 +++++----- Glamourer/Gui/Materials/ColorRowClipboard.cs | 8 +++---- Glamourer/Gui/Materials/MaterialDrawer.cs | 6 ++--- Glamourer/Interop/Material/DirectXService.cs | 22 +++++++++---------- .../Material/LiveColorTablePreviewer.cs | 18 +++++++-------- Glamourer/Interop/Material/MaterialManager.cs | 4 ++-- Glamourer/Interop/Material/MaterialService.cs | 12 +++++----- .../Interop/Material/MaterialValueIndex.cs | 4 ++-- .../Interop/Material/MaterialValueManager.cs | 6 ++--- Glamourer/Interop/Material/PrepareColorSet.cs | 11 +++++----- Penumbra.GameData | 2 +- 12 files changed, 55 insertions(+), 54 deletions(-) diff --git a/Glamourer/Designs/DesignConverter.cs b/Glamourer/Designs/DesignConverter.cs index a7358b8..f3955c5 100644 --- a/Glamourer/Designs/DesignConverter.cs +++ b/Glamourer/Designs/DesignConverter.cs @@ -7,7 +7,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Penumbra.GameData.DataContainers; using Penumbra.GameData.Enums; -using Penumbra.GameData.Files; +using Penumbra.GameData.Files.MaterialStructs; using Penumbra.GameData.Structs; namespace Glamourer.Designs; @@ -224,7 +224,7 @@ public class DesignConverter( foreach (var (key, value) in materials.Values) { var idx = MaterialValueIndex.FromKey(key); - if (idx.RowIndex >= MtrlFile.ColorTable.NumRows) + if (idx.RowIndex >= LegacyColorTable.NumUsedRows) continue; if (idx.MaterialIndex >= MaterialService.MaterialsPerModel) continue; diff --git a/Glamourer/Gui/Materials/AdvancedDyePopup.cs b/Glamourer/Gui/Materials/AdvancedDyePopup.cs index c2dbdbe..232541e 100644 --- a/Glamourer/Gui/Materials/AdvancedDyePopup.cs +++ b/Glamourer/Gui/Materials/AdvancedDyePopup.cs @@ -11,7 +11,7 @@ using OtterGui; using OtterGui.Raii; using OtterGui.Services; using Penumbra.GameData.Enums; -using Penumbra.GameData.Files; +using Penumbra.GameData.Files.MaterialStructs; using Penumbra.GameData.Interop; using Penumbra.String; @@ -190,11 +190,11 @@ public sealed unsafe class AdvancedDyePopup( DrawWindow(textures); } - private void DrawTable(MaterialValueIndex materialIndex, in MtrlFile.ColorTable table) + private void DrawTable(MaterialValueIndex materialIndex, in LegacyColorTable table) { using var disabled = ImRaii.Disabled(_state.IsLocked); _anyChanged = false; - for (byte i = 0; i < MtrlFile.ColorTable.NumRows; ++i) + for (byte i = 0; i < LegacyColorTable.NumUsedRows; ++i) { var index = materialIndex with { RowIndex = i }; ref var row = ref table[i]; @@ -205,7 +205,7 @@ public sealed unsafe class AdvancedDyePopup( DrawAllRow(materialIndex, table); } - private void DrawAllRow(MaterialValueIndex materialIndex, in MtrlFile.ColorTable table) + private void DrawAllRow(MaterialValueIndex materialIndex, in LegacyColorTable table) { using var id = ImRaii.PushId(100); var buttonSize = new Vector2(ImGui.GetFrameHeight()); @@ -242,11 +242,11 @@ public sealed unsafe class AdvancedDyePopup( ImGui.SameLine(0, spacing); if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.UndoAlt.ToIconString(), buttonSize, "Reset this table to game state.", !_anyChanged, true)) - for (byte i = 0; i < MtrlFile.ColorTable.NumRows; ++i) + for (byte i = 0; i < LegacyColorTable.NumUsedRows; ++i) stateManager.ResetMaterialValue(_state, materialIndex with { RowIndex = i }, ApplySettings.Game); } - private void DrawRow(ref MtrlFile.ColorTable.Row row, MaterialValueIndex index, in MtrlFile.ColorTable table) + private void DrawRow(ref LegacyColorTable.Row row, MaterialValueIndex index, in LegacyColorTable table) { using var id = ImRaii.PushId(index.RowIndex); var changed = _state.Materials.TryGetValue(index, out var value); diff --git a/Glamourer/Gui/Materials/ColorRowClipboard.cs b/Glamourer/Gui/Materials/ColorRowClipboard.cs index f8310c3..4d99018 100644 --- a/Glamourer/Gui/Materials/ColorRowClipboard.cs +++ b/Glamourer/Gui/Materials/ColorRowClipboard.cs @@ -1,18 +1,18 @@ using Glamourer.Interop.Material; -using Penumbra.GameData.Files; +using Penumbra.GameData.Files.MaterialStructs; namespace Glamourer.Gui.Materials; public static class ColorRowClipboard { - private static ColorRow _row; - private static MtrlFile.ColorTable _table; + private static ColorRow _row; + private static LegacyColorTable _table; public static bool IsSet { get; private set; } public static bool IsTableSet { get; private set; } - public static MtrlFile.ColorTable Table + public static LegacyColorTable Table { get => _table; set diff --git a/Glamourer/Gui/Materials/MaterialDrawer.cs b/Glamourer/Gui/Materials/MaterialDrawer.cs index aeb4a9b..26432e9 100644 --- a/Glamourer/Gui/Materials/MaterialDrawer.cs +++ b/Glamourer/Gui/Materials/MaterialDrawer.cs @@ -7,7 +7,7 @@ using ImGuiNET; using OtterGui; using OtterGui.Services; using Penumbra.GameData.Enums; -using Penumbra.GameData.Files; +using Penumbra.GameData.Files.MaterialStructs; using Penumbra.GameData.Gui; namespace Glamourer.Gui.Materials; @@ -175,9 +175,9 @@ public class MaterialDrawer(DesignManager _designManager, Configuration _config) { _newRowIdx += 1; ImGui.SetNextItemWidth(ImGui.CalcTextSize("Row #0000").X); - if (ImGui.DragInt("##Row", ref _newRowIdx, 0.01f, 1, MtrlFile.ColorTable.NumRows, "Row #%i")) + if (ImGui.DragInt("##Row", ref _newRowIdx, 0.01f, 1, LegacyColorTable.NumUsedRows, "Row #%i")) { - _newRowIdx = Math.Clamp(_newRowIdx, 1, MtrlFile.ColorTable.NumRows); + _newRowIdx = Math.Clamp(_newRowIdx, 1, LegacyColorTable.NumUsedRows); _newKey = _newKey with { RowIndex = (byte)(_newRowIdx - 1) }; } diff --git a/Glamourer/Interop/Material/DirectXService.cs b/Glamourer/Interop/Material/DirectXService.cs index d3fa3db..6d9c71b 100644 --- a/Glamourer/Interop/Material/DirectXService.cs +++ b/Glamourer/Interop/Material/DirectXService.cs @@ -2,11 +2,11 @@ using FFXIVClientStructs.FFXIV.Client.Graphics.Kernel; using Lumina.Data.Files; using OtterGui.Services; +using Penumbra.GameData.Files.MaterialStructs; using Penumbra.String.Functions; using SharpGen.Runtime; using Vortice.Direct3D11; using Vortice.DXGI; -using static Penumbra.GameData.Files.MtrlFile; using MapFlags = Vortice.Direct3D11.MapFlags; using Texture = FFXIVClientStructs.FFXIV.Client.Graphics.Kernel.Texture; @@ -14,14 +14,14 @@ namespace Glamourer.Interop.Material; public unsafe class DirectXService(IFramework framework) : IService { - private readonly object _lock = new(); - private readonly ConcurrentDictionary _textures = []; + private readonly object _lock = new(); + private readonly ConcurrentDictionary _textures = []; /// Generate a color table the way the game does inside the original texture, and release the original. /// The original texture that will be replaced with a new one. /// The input color table. /// Success or failure. - public bool ReplaceColorTable(Texture** original, in ColorTable colorTable) + public bool ReplaceColorTable(Texture** original, in LegacyColorTable colorTable) { if (original == null) return false; @@ -38,7 +38,7 @@ public unsafe class DirectXService(IFramework framework) : IService if (texture.IsInvalid) return false; - fixed (ColorTable* ptr = &colorTable) + fixed (LegacyColorTable* ptr = &colorTable) { if (!texture.Texture->InitializeContents(ptr)) return false; @@ -51,7 +51,7 @@ public unsafe class DirectXService(IFramework framework) : IService return true; } - public bool TryGetColorTable(Texture* texture, out ColorTable table) + public bool TryGetColorTable(Texture* texture, out LegacyColorTable table) { if (_textures.TryGetValue((nint)texture, out var p) && framework.LastUpdateUTC == p.Update) { @@ -73,7 +73,7 @@ public unsafe class DirectXService(IFramework framework) : IService /// A pointer to the internal texture struct containing the GPU handle. /// The returned color table. /// Whether the table could be fetched. - private static bool TextureColorTable(Texture* texture, out ColorTable table) + private static bool TextureColorTable(Texture* texture, out LegacyColorTable table) { if (texture == null) { @@ -114,7 +114,7 @@ public unsafe class DirectXService(IFramework framework) : IService } /// Turn a mapped texture into a color table. - private static ColorTable GetTextureData(ID3D11Texture2D1 resource, MappedSubresource map) + private static LegacyColorTable GetTextureData(ID3D11Texture2D1 resource, MappedSubresource map) { var desc = resource.Description1; @@ -133,14 +133,14 @@ public unsafe class DirectXService(IFramework framework) : IService /// The height of the texture. (Needs to be 16). /// The stride in the texture data. /// - private static ColorTable ReadTexture(nint data, int length, int height, int pitch) + private static LegacyColorTable ReadTexture(nint data, int length, int height, int pitch) { // Check that the data has sufficient dimension and size. var expectedSize = sizeof(Half) * MaterialService.TextureWidth * height * 4; - if (length < expectedSize || sizeof(ColorTable) != expectedSize || height != MaterialService.TextureHeight) + if (length < expectedSize || sizeof(LegacyColorTable) != expectedSize || height != MaterialService.TextureHeight) return default; - var ret = new ColorTable(); + var ret = new LegacyColorTable(); var target = (byte*)&ret; // If the stride is the same as in the table, just copy. if (pitch == MaterialService.TextureWidth) diff --git a/Glamourer/Interop/Material/LiveColorTablePreviewer.cs b/Glamourer/Interop/Material/LiveColorTablePreviewer.cs index e732472..aa4c358 100644 --- a/Glamourer/Interop/Material/LiveColorTablePreviewer.cs +++ b/Glamourer/Interop/Material/LiveColorTablePreviewer.cs @@ -1,7 +1,7 @@ using Dalamud.Plugin.Services; using ImGuiNET; using OtterGui.Services; -using Penumbra.GameData.Files; +using Penumbra.GameData.Files.MaterialStructs; using Penumbra.GameData.Structs; namespace Glamourer.Interop.Material; @@ -12,12 +12,12 @@ public sealed unsafe class LiveColorTablePreviewer : IService, IDisposable private readonly IFramework _framework; private readonly DirectXService _directXService; - public MaterialValueIndex LastValueIndex { get; private set; } = MaterialValueIndex.Invalid; - public MtrlFile.ColorTable LastOriginalColorTable { get; private set; } - private MaterialValueIndex _valueIndex = MaterialValueIndex.Invalid; - private ObjectIndex _lastObjectIndex = ObjectIndex.AnyIndex; - private ObjectIndex _objectIndex = ObjectIndex.AnyIndex; - private MtrlFile.ColorTable _originalColorTable; + public MaterialValueIndex LastValueIndex { get; private set; } = MaterialValueIndex.Invalid; + public LegacyColorTable LastOriginalColorTable { get; private set; } + private MaterialValueIndex _valueIndex = MaterialValueIndex.Invalid; + private ObjectIndex _lastObjectIndex = ObjectIndex.AnyIndex; + private ObjectIndex _objectIndex = ObjectIndex.AnyIndex; + private LegacyColorTable _originalColorTable; public LiveColorTablePreviewer(global::Penumbra.GameData.Interop.ObjectManager objects, IFramework framework, DirectXService directXService) { @@ -78,7 +78,7 @@ public sealed unsafe class LiveColorTablePreviewer : IService, IDisposable } else { - for (var i = 0; i < MtrlFile.ColorTable.NumRows; ++i) + for (var i = 0; i < LegacyColorTable.NumUsedRows; ++i) { table[i].Diffuse = diffuse; table[i].Emissive = emissive; @@ -92,7 +92,7 @@ public sealed unsafe class LiveColorTablePreviewer : IService, IDisposable _objectIndex = ObjectIndex.AnyIndex; } - public void OnHover(MaterialValueIndex index, ObjectIndex objectIndex, MtrlFile.ColorTable table) + public void OnHover(MaterialValueIndex index, ObjectIndex objectIndex, LegacyColorTable table) { if (_valueIndex.DrawObject is not MaterialValueIndex.DrawObjectType.Invalid) return; diff --git a/Glamourer/Interop/Material/MaterialManager.cs b/Glamourer/Interop/Material/MaterialManager.cs index 1fb758b..8e3936e 100644 --- a/Glamourer/Interop/Material/MaterialManager.cs +++ b/Glamourer/Interop/Material/MaterialManager.cs @@ -6,7 +6,7 @@ using Glamourer.State; using OtterGui.Services; using Penumbra.GameData.Actors; using Penumbra.GameData.Enums; -using Penumbra.GameData.Files; +using Penumbra.GameData.Files.MaterialStructs; using Penumbra.GameData.Interop; using Penumbra.GameData.Structs; @@ -76,7 +76,7 @@ public sealed unsafe class MaterialManager : IRequiredService, IDisposable /// Update and apply the glamourer state of an actor according to the application sources when updated by the game. private void UpdateMaterialValues(ActorState state, ReadOnlySpan<(uint Key, MaterialValueState Value)> values, CharacterWeapon drawData, - ref MtrlFile.ColorTable colorTable) + ref LegacyColorTable colorTable) { var deleteList = _deleteList.Value!; deleteList.Clear(); diff --git a/Glamourer/Interop/Material/MaterialService.cs b/Glamourer/Interop/Material/MaterialService.cs index 03165a3..4c8706c 100644 --- a/Glamourer/Interop/Material/MaterialService.cs +++ b/Glamourer/Interop/Material/MaterialService.cs @@ -1,8 +1,8 @@ using FFXIVClientStructs.FFXIV.Client.Graphics.Kernel; using FFXIVClientStructs.FFXIV.Client.System.Resource.Handle; using Lumina.Data.Files; +using Penumbra.GameData.Files.MaterialStructs; using Penumbra.GameData.Interop; -using static Penumbra.GameData.Files.MtrlFile; using Texture = FFXIVClientStructs.FFXIV.Client.Graphics.Kernel.Texture; namespace Glamourer.Interop.Material; @@ -10,10 +10,10 @@ namespace Glamourer.Interop.Material; public static unsafe class MaterialService { public const int TextureWidth = 4; - public const int TextureHeight = ColorTable.NumRows; + public const int TextureHeight = LegacyColorTable.NumUsedRows; public const int MaterialsPerModel = 4; - public static bool GenerateNewColorTable(in ColorTable colorTable, out Texture* texture) + public static bool GenerateNewColorTable(in LegacyColorTable colorTable, out Texture* texture) { var textureSize = stackalloc int[2]; textureSize[0] = TextureWidth; @@ -24,7 +24,7 @@ public static unsafe class MaterialService if (texture == null) return false; - fixed (ColorTable* ptr = &colorTable) + fixed (LegacyColorTable* ptr = &colorTable) { return texture->InitializeContents(ptr); } @@ -53,7 +53,7 @@ public static unsafe class MaterialService /// The model slot. /// The material slot in the model. /// A pointer to the color table or null. - public static ColorTable* GetMaterialColorTable(Model model, int modelSlot, byte materialSlot) + public static LegacyColorTable* GetMaterialColorTable(Model model, int modelSlot, byte materialSlot) { if (!model.IsCharacterBase) return null; @@ -66,6 +66,6 @@ public static unsafe class MaterialService if (material == null || material->ColorTable == null) return null; - return (ColorTable*)material->ColorTable; + return (LegacyColorTable*)material->ColorTable; } } diff --git a/Glamourer/Interop/Material/MaterialValueIndex.cs b/Glamourer/Interop/Material/MaterialValueIndex.cs index ec9996b..9bfcc4c 100644 --- a/Glamourer/Interop/Material/MaterialValueIndex.cs +++ b/Glamourer/Interop/Material/MaterialValueIndex.cs @@ -2,7 +2,7 @@ using FFXIVClientStructs.Interop; using Newtonsoft.Json; using Penumbra.GameData.Enums; -using Penumbra.GameData.Files; +using Penumbra.GameData.Files.MaterialStructs; using Penumbra.GameData.Interop; namespace Glamourer.Interop.Material; @@ -143,7 +143,7 @@ public readonly record struct MaterialValueIndex( => materialIndex < MaterialService.MaterialsPerModel; public static bool ValidateRow(byte rowIndex) - => rowIndex < MtrlFile.ColorTable.NumRows; + => rowIndex < LegacyColorTable.NumUsedRows; private static uint ToKey(DrawObjectType type, byte slotIndex, byte materialIndex, byte rowIndex) { diff --git a/Glamourer/Interop/Material/MaterialValueManager.cs b/Glamourer/Interop/Material/MaterialValueManager.cs index 599d264..483e6af 100644 --- a/Glamourer/Interop/Material/MaterialValueManager.cs +++ b/Glamourer/Interop/Material/MaterialValueManager.cs @@ -2,9 +2,9 @@ global using DesignMaterialManager = Glamourer.Interop.Material.MaterialValueManager; using Glamourer.GameData; using Glamourer.State; -using Penumbra.GameData.Files; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Penumbra.GameData.Files.MaterialStructs; using Penumbra.GameData.Structs; @@ -21,7 +21,7 @@ public struct ColorRow(Vector3 diffuse, Vector3 specular, Vector3 emissive, floa public float SpecularStrength = specularStrength; public float GlossStrength = glossStrength; - public ColorRow(in MtrlFile.ColorTable.Row row) + public ColorRow(in LegacyColorTable.Row row) : this(Root(row.Diffuse), Root(row.Specular), Root(row.Emissive), row.SpecularStrength, row.GlossStrength) { } @@ -44,7 +44,7 @@ public struct ColorRow(Vector3 diffuse, Vector3 specular, Vector3 emissive, floa private static float Root(float value) => value < 0 ? MathF.Sqrt(-value) : MathF.Sqrt(value); - public readonly bool Apply(ref MtrlFile.ColorTable.Row row) + public readonly bool Apply(ref LegacyColorTable.Row row) { var ret = false; var d = Square(Diffuse); diff --git a/Glamourer/Interop/Material/PrepareColorSet.cs b/Glamourer/Interop/Material/PrepareColorSet.cs index 5257c4e..1661037 100644 --- a/Glamourer/Interop/Material/PrepareColorSet.cs +++ b/Glamourer/Interop/Material/PrepareColorSet.cs @@ -5,7 +5,7 @@ using FFXIVClientStructs.FFXIV.Client.System.Resource.Handle; using OtterGui.Classes; using OtterGui.Services; using Penumbra.GameData.Enums; -using Penumbra.GameData.Files; +using Penumbra.GameData.Files.MaterialStructs; using Penumbra.GameData.Interop; using Penumbra.GameData.Structs; @@ -55,7 +55,7 @@ public sealed unsafe class PrepareColorSet } public static bool TryGetColorTable(CharacterBase* characterBase, MaterialResourceHandle* material, StainId stainId, - out MtrlFile.ColorTable table) + out LegacyColorTable table) { if (material->ColorTable == null) { @@ -63,7 +63,7 @@ public sealed unsafe class PrepareColorSet return false; } - var newTable = *(MtrlFile.ColorTable*)material->ColorTable; + var newTable = *(LegacyColorTable*)material->ColorTable; if (stainId.Id != 0) characterBase->ReadStainingTemplate(material, stainId.Id, (Half*)(&newTable)); table = newTable; @@ -71,11 +71,12 @@ public sealed unsafe class PrepareColorSet } /// Assumes the actor is valid. - public static bool TryGetColorTable(Actor actor, MaterialValueIndex index, out MtrlFile.ColorTable table) + public static bool TryGetColorTable(Actor actor, MaterialValueIndex index, out LegacyColorTable table) { - var idx = index.SlotIndex * MaterialService.MaterialsPerModel + index.MaterialIndex; + var idx = index.SlotIndex * MaterialService.MaterialsPerModel + index.MaterialIndex; if (!index.TryGetModel(actor, out var model)) return false; + var handle = (MaterialResourceHandle*)model.AsCharacterBase->Materials[idx]; if (handle == null) { diff --git a/Penumbra.GameData b/Penumbra.GameData index 07cc26f..b828297 160000 --- a/Penumbra.GameData +++ b/Penumbra.GameData @@ -1 +1 @@ -Subproject commit 07cc26f196984a44711b3bc4c412947d863288bd +Subproject commit b8282970ee78a2c085e740f60450fecf7ea58b9c