mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-12 18:27:24 +01:00
Use Legacy Color Tables because our materials do not have DT ones yet.
This commit is contained in:
parent
93dcd317c1
commit
1341c4316c
12 changed files with 55 additions and 54 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) };
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<nint, (DateTime Update, ColorTable Table)> _textures = [];
|
||||
private readonly object _lock = new();
|
||||
private readonly ConcurrentDictionary<nint, (DateTime Update, LegacyColorTable Table)> _textures = [];
|
||||
|
||||
/// <summary> Generate a color table the way the game does inside the original texture, and release the original. </summary>
|
||||
/// <param name="original"> The original texture that will be replaced with a new one. </param>
|
||||
/// <param name="colorTable"> The input color table. </param>
|
||||
/// <returns> Success or failure. </returns>
|
||||
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
|
|||
/// <param name="texture"> A pointer to the internal texture struct containing the GPU handle. </param>
|
||||
/// <param name="table"> The returned color table. </param>
|
||||
/// <returns> Whether the table could be fetched. </returns>
|
||||
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
|
|||
}
|
||||
|
||||
/// <summary> Turn a mapped texture into a color table. </summary>
|
||||
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
|
|||
/// <param name="height"> The height of the texture. (Needs to be 16).</param>
|
||||
/// <param name="pitch"> The stride in the texture data. </param>
|
||||
/// <returns></returns>
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
|||
|
||||
/// <summary> Update and apply the glamourer state of an actor according to the application sources when updated by the game. </summary>
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -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
|
|||
/// <param name="modelSlot"> The model slot. </param>
|
||||
/// <param name="materialSlot"> The material slot in the model. </param>
|
||||
/// <returns> A pointer to the color table or null. </returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
global using DesignMaterialManager = Glamourer.Interop.Material.MaterialValueManager<Glamourer.Interop.Material.MaterialValueDesign>;
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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
|
|||
}
|
||||
|
||||
/// <summary> Assumes the actor is valid. </summary>
|
||||
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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 07cc26f196984a44711b3bc4c412947d863288bd
|
||||
Subproject commit b8282970ee78a2c085e740f60450fecf7ea58b9c
|
||||
Loading…
Add table
Add a link
Reference in a new issue