From e0a09e8a3134f719b886554ce1c8ba9d9ec2dc80 Mon Sep 17 00:00:00 2001 From: Passive <20432486+PassiveModding@users.noreply.github.com> Date: Sun, 29 Sep 2024 23:35:25 +1000 Subject: [PATCH] raw texture mode init --- .../Models/Composer/CharacterComposer.cs | 10 ++--- .../Models/Composer/MaterialSet.cs | 37 ++++++++++++++---- .../Composer/Materials/BgMaterialBuilder.cs | 6 +-- .../Materials/CharacterMaterialBuilder.cs | 28 ++++++++++--- .../CharacterTattooMaterialBuilder.cs | 4 +- .../Materials/GenericMaterialBuilder.cs | 1 - .../Composer/Materials/HairMaterialBuilder.cs | 26 ++++++++++--- .../Composer/Materials/IrisMaterialBuilder.cs | 27 +++++++++---- .../Materials/LightshaftMaterialBuilder.cs | 1 - .../Materials/MeddleMaterialBuilder.cs | 29 +++++++++++++- .../Composer/Materials/SkinMaterialBuilder.cs | 39 +++++++++++++------ Meddle/Meddle.Plugin/Models/Enums.cs | 6 +++ Meddle/Meddle.Plugin/Plugin.cs | 2 +- Meddle/Meddle.Plugin/UI/Layout/Instance.cs | 9 ++++- Meddle/Meddle.Plugin/UI/OptionsTab.cs | 31 ++++++++++++--- 15 files changed, 194 insertions(+), 62 deletions(-) diff --git a/Meddle/Meddle.Plugin/Models/Composer/CharacterComposer.cs b/Meddle/Meddle.Plugin/Models/Composer/CharacterComposer.cs index d72f0a4..5b1eef8 100644 --- a/Meddle/Meddle.Plugin/Models/Composer/CharacterComposer.cs +++ b/Meddle/Meddle.Plugin/Models/Composer/CharacterComposer.cs @@ -22,7 +22,7 @@ public class CharacterComposer private static readonly object StaticFileLock = new(); private readonly SkeletonUtils.PoseMode poseMode; private readonly bool includePose; - private readonly bool computeCharacterTextures; + private readonly TextureMode textureMode; public CharacterComposer(DataProvider dataProvider, Configuration config, Action? progress = null) { @@ -30,7 +30,7 @@ public CharacterComposer(DataProvider dataProvider, Configuration config, Action this.progress = progress; includePose = config.IncludePose; poseMode = config.PoseMode; - computeCharacterTextures = config.ComputeCharacterTextures; + textureMode = config.TextureMode; lock (StaticFileLock) { @@ -76,11 +76,6 @@ private void HandleModel(GenderRace genderRace, CustomizeParameter customizePara try { var materialInfo = modelInfo.Materials[i]; - if (!computeCharacterTextures) - { - materialBuilders[i] = new MaterialBuilder(materialInfo.Path.FullPath); - continue; - } progress?.Invoke(new ProgressEvent(modelInfo.GetHashCode(), $"{materialInfo.Path.GamePath}", i + 1, modelInfo.Materials.Length)); var mtrlData = dataProvider.LookupData(materialInfo.Path.FullPath); @@ -117,6 +112,7 @@ private void HandleModel(GenderRace genderRace, CustomizeParameter customizePara material.SetCustomizeParameters(customizeParameter); material.SetCustomizeData(customizeData); + material.SetTextureMode(textureMode); materialBuilders[i] = material.Compose(dataProvider); } diff --git a/Meddle/Meddle.Plugin/Models/Composer/MaterialSet.cs b/Meddle/Meddle.Plugin/Models/Composer/MaterialSet.cs index cb6a798..354c5ec 100644 --- a/Meddle/Meddle.Plugin/Models/Composer/MaterialSet.cs +++ b/Meddle/Meddle.Plugin/Models/Composer/MaterialSet.cs @@ -420,17 +420,17 @@ private MeddleMaterialBuilder GetMaterialBuilder(DataProvider dataProvider) return new LightshaftMaterialBuilder(mtrlName, this, dataProvider); case "character.shpk": case "characterlegacy.shpk": - return new CharacterMaterialBuilder(mtrlName, this, dataProvider, colorTable); + return new CharacterMaterialBuilder(mtrlName, this, dataProvider, colorTable, textureMode); case "charactertattoo.shpk": - return new CharacterTattooMaterialBuilder(mtrlName, this, dataProvider, customizeParameters ?? new CustomizeParameter()); + return new CharacterTattooMaterialBuilder(mtrlName, this, dataProvider, customizeParameters ?? new CustomizeParameter(), textureMode); case "characterocclusion.shpk": return new CharacterOcclusionMaterialBuilder(mtrlName, this, dataProvider); case "skin.shpk": - return new SkinMaterialBuilder(mtrlName, this, dataProvider, customizeParameters ?? new CustomizeParameter(), customizeData ?? new CustomizeData()); + return new SkinMaterialBuilder(mtrlName, this, dataProvider, customizeParameters ?? new CustomizeParameter(), customizeData ?? new CustomizeData(), textureMode); case "hair.shpk": - return new HairMaterialBuilder(mtrlName, this, dataProvider, customizeParameters ?? new CustomizeParameter()); + return new HairMaterialBuilder(mtrlName, this, dataProvider, customizeParameters ?? new CustomizeParameter(), textureMode); case "iris.shpk": - return new IrisMaterialBuilder(mtrlName, this, dataProvider, customizeParameters ?? new CustomizeParameter()); + return new IrisMaterialBuilder(mtrlName, this, dataProvider, customizeParameters ?? new CustomizeParameter(), textureMode); default: return new GenericMaterialBuilder(mtrlName, this, dataProvider); } @@ -461,7 +461,11 @@ public Dictionary ComposeExtras() var extrasDict = new Dictionary { {"ShaderPackage", ShpkName}, - {"Material", MtrlPath} + {"Material", MtrlPath}, + {"HashStr", HashStr()}, + {"RenderBackfaces", RenderBackfaces}, + {"IsTransparent", IsTransparent}, + {"CharacterTextureMode", textureMode} }; AddConstants(); AddSamplers(); @@ -476,6 +480,17 @@ public Dictionary ComposeExtras() void AddCustomizeParameters() { if (customizeParameters == null) return; + extrasDict["LeftIrisColor"] = customizeParameters.LeftColor.AsFloatArray(); + extrasDict["RightIrisColor"] = customizeParameters.RightColor.AsFloatArray(); + extrasDict["MainColor"] = customizeParameters.MainColor.AsFloatArray(); + extrasDict["SkinColor"] = customizeParameters.SkinColor.AsFloatArray(); + extrasDict["MeshColor"] = customizeParameters.MeshColor.AsFloatArray(); + extrasDict["LipColor"] = customizeParameters.LipColor.AsFloatArray(); + extrasDict["SkinColor"] = customizeParameters.SkinColor.AsFloatArray(); + extrasDict["FacePaintUVOffset"] = customizeParameters.FacePaintUVOffset; + extrasDict["FacePaintUVMultiplier"] = customizeParameters.FacePaintUVMultiplier; + extrasDict["MuscleTone"] = customizeParameters.MuscleTone; + extrasDict["OptionColor"] = customizeParameters.OptionColor; extrasDict["CustomizeParameters"] = JsonNode.Parse(JsonSerializer.Serialize(customizeParameters, JsonOptions))!; } @@ -494,6 +509,8 @@ void AddStainColor() void AddCustomizeData() { if (customizeData == null) return; + extrasDict["Highlights"] = customizeData.Highlights; + extrasDict["LipStick"] = customizeData.LipStick; extrasDict["CustomizeData"] = JsonNode.Parse(JsonSerializer.Serialize(customizeData, JsonOptions))!; } @@ -517,7 +534,7 @@ void AddShaderKeys() ShaderCategory.CategorySkinType => IsDefinedOrHex((SkinType)value), ShaderCategory.CategoryDiffuseAlpha => IsDefinedOrHex((DiffuseAlpha)value), ShaderCategory.CategorySpecularType => IsDefinedOrHex((SpecularMode)value), - ShaderCategory.GetValuesTextureType => IsDefinedOrHex((TextureMode)value), + ShaderCategory.GetValuesTextureType => IsDefinedOrHex((Meddle.Utils.Export.TextureMode)value), ShaderCategory.CategoryFlowMapType => IsDefinedOrHex((FlowType)value), ShaderCategory.CategoryBgVertexPaint => IsDefinedOrHex((BgVertexPaint)value), _ => $"0x{value:X8}" @@ -562,4 +579,10 @@ void AddConstants() } } } + + private TextureMode textureMode = TextureMode.Bake; + public void SetTextureMode(TextureMode computeTextures) + { + this.textureMode = computeTextures; + } } diff --git a/Meddle/Meddle.Plugin/Models/Composer/Materials/BgMaterialBuilder.cs b/Meddle/Meddle.Plugin/Models/Composer/Materials/BgMaterialBuilder.cs index b318da2..3fe93e9 100644 --- a/Meddle/Meddle.Plugin/Models/Composer/Materials/BgMaterialBuilder.cs +++ b/Meddle/Meddle.Plugin/Models/Composer/Materials/BgMaterialBuilder.cs @@ -23,7 +23,7 @@ public BgColorChangeParams(Vector4? stainColor) public record BgParams : IBgMaterialBuilderParams; -public class BgMaterialBuilder : MeddleMaterialBuilder, IVertexPaintMaterialBuilder +public class BgMaterialBuilder : MeddleMaterialBuilder { private readonly IBgMaterialBuilderParams bgParams; private readonly MaterialSet set; @@ -105,8 +105,6 @@ private DetailSet GetDetail(int detailId, Vector2 size) } } - public bool VertexPaint { get; private set; } - private bool GetDiffuseColor(out Vector4 diffuseColor) { @@ -163,8 +161,6 @@ public override MeddleMaterialBuilder Apply() // only the green/y channel is used here for roughness WithMetallicRoughness(specularMap0Texture, 0.0f, 1.0f); - IndexOfRefraction = 1.0f; - Extras = set.ComposeExtrasNode(extras.ToArray()); return this; } diff --git a/Meddle/Meddle.Plugin/Models/Composer/Materials/CharacterMaterialBuilder.cs b/Meddle/Meddle.Plugin/Models/Composer/Materials/CharacterMaterialBuilder.cs index eeece28..60d270e 100644 --- a/Meddle/Meddle.Plugin/Models/Composer/Materials/CharacterMaterialBuilder.cs +++ b/Meddle/Meddle.Plugin/Models/Composer/Materials/CharacterMaterialBuilder.cs @@ -12,17 +12,19 @@ public class CharacterMaterialBuilder : MeddleMaterialBuilder private readonly MaterialSet set; private readonly DataProvider dataProvider; private readonly IColorTableSet? colorTableSet; + private readonly TextureMode textureMode; - public CharacterMaterialBuilder(string name, MaterialSet set, DataProvider dataProvider, IColorTableSet? colorTableSet) : base(name) + public CharacterMaterialBuilder(string name, MaterialSet set, DataProvider dataProvider, IColorTableSet? colorTableSet, TextureMode textureMode) : base(name) { this.set = set; this.dataProvider = dataProvider; this.colorTableSet = colorTableSet; + this.textureMode = textureMode; } - public override MeddleMaterialBuilder Apply() + private void ApplyComputed() { - var textureMode = set.GetShaderKeyOrDefault(ShaderCategory.GetValuesTextureType, TextureMode.Default); + var textureMode = set.GetShaderKeyOrDefault(ShaderCategory.GetValuesTextureType, Meddle.Utils.Export.TextureMode.Default); var specularMode = set.GetShaderKeyOrDefault(ShaderCategory.CategorySpecularType, SpecularMode.Default); // TODO: is default actually default var flowType = set.GetShaderKeyOrDefault(ShaderCategory.CategoryFlowMapType, FlowType.Standard); @@ -35,7 +37,7 @@ public override MeddleMaterialBuilder Apply() var diffuseTexture = textureMode switch { - TextureMode.Compatibility => set.TryGetTexture(dataProvider, TextureUsage.g_SamplerDiffuse, out var tex) ? tex.ToTexture(normalRes.Size) : throw new InvalidOperationException("Missing diffuse texture"), + Meddle.Utils.Export.TextureMode.Compatibility => set.TryGetTexture(dataProvider, TextureUsage.g_SamplerDiffuse, out var tex) ? tex.ToTexture(normalRes.Size) : throw new InvalidOperationException("Missing diffuse texture"), _ => new SKTexture(normalRes.Width, normalRes.Height) }; @@ -58,13 +60,13 @@ public override MeddleMaterialBuilder Apply() var blended = ((ColorTableSet?)colorTableSet)!.Value.ColorTable .GetBlendedPair(indexColor.Red, indexColor.Green); - if (textureMode == TextureMode.Compatibility) + if (textureMode == Meddle.Utils.Export.TextureMode.Compatibility) { var diffuse = diffuseTexture![x, y].ToVector4(); diffuse *= new Vector4(blended.Diffuse, normal.Z); diffuseTexture[x, y] = (diffuse with {W = normal.Z}).ToSkColor(); } - else if (textureMode == TextureMode.Default) + else if (textureMode == Meddle.Utils.Export.TextureMode.Default) { var diffuse = new Vector4(blended.Diffuse, normal.Z); diffuseTexture[x, y] = diffuse.ToSkColor(); @@ -89,6 +91,20 @@ public override MeddleMaterialBuilder Apply() WithBaseColor(dataProvider.CacheTexture(diffuseTexture, $"Computed/{set.ComputedTextureName("diffuse")}")); WithNormal(dataProvider.CacheTexture(normalTexture, $"Computed/{set.ComputedTextureName("normal")}")); + + } + + public override MeddleMaterialBuilder Apply() + { + if (textureMode == TextureMode.Bake) + { + ApplyComputed(); + } + else + { + ApplyRaw(set, dataProvider); + } + IndexOfRefraction = set.GetConstantOrThrow(MaterialConstant.g_GlassIOR); var alphaThreshold = set.GetConstantOrDefault(MaterialConstant.g_AlphaThreshold, 0.0f); diff --git a/Meddle/Meddle.Plugin/Models/Composer/Materials/CharacterTattooMaterialBuilder.cs b/Meddle/Meddle.Plugin/Models/Composer/Materials/CharacterTattooMaterialBuilder.cs index 19fc1c4..81aac4f 100644 --- a/Meddle/Meddle.Plugin/Models/Composer/Materials/CharacterTattooMaterialBuilder.cs +++ b/Meddle/Meddle.Plugin/Models/Composer/Materials/CharacterTattooMaterialBuilder.cs @@ -12,7 +12,9 @@ public class CharacterTattooMaterialBuilder : MeddleMaterialBuilder private readonly DataProvider dataProvider; private readonly CustomizeParameter customizeParameter; - public CharacterTattooMaterialBuilder(string name, MaterialSet set, DataProvider dataProvider, CustomizeParameter customizeParameter) : base(name) + public CharacterTattooMaterialBuilder( + string name, MaterialSet set, DataProvider dataProvider, CustomizeParameter customizeParameter, + TextureMode textureMode) : base(name) { this.set = set; this.dataProvider = dataProvider; diff --git a/Meddle/Meddle.Plugin/Models/Composer/Materials/GenericMaterialBuilder.cs b/Meddle/Meddle.Plugin/Models/Composer/Materials/GenericMaterialBuilder.cs index 1211956..0213959 100644 --- a/Meddle/Meddle.Plugin/Models/Composer/Materials/GenericMaterialBuilder.cs +++ b/Meddle/Meddle.Plugin/Models/Composer/Materials/GenericMaterialBuilder.cs @@ -23,7 +23,6 @@ public override MeddleMaterialBuilder Apply() WithAlpha(AlphaMode.MASK, alphaThreshold); var setTypes = new HashSet(); - // TODO: foreach (var textureUsage in set.TextureUsageDict) { var texData = dataProvider.LookupData(textureUsage.Value.FullPath); diff --git a/Meddle/Meddle.Plugin/Models/Composer/Materials/HairMaterialBuilder.cs b/Meddle/Meddle.Plugin/Models/Composer/Materials/HairMaterialBuilder.cs index d000014..635bec3 100644 --- a/Meddle/Meddle.Plugin/Models/Composer/Materials/HairMaterialBuilder.cs +++ b/Meddle/Meddle.Plugin/Models/Composer/Materials/HairMaterialBuilder.cs @@ -11,15 +11,19 @@ public class HairMaterialBuilder : MeddleMaterialBuilder private readonly MaterialSet set; private readonly DataProvider dataProvider; private readonly CustomizeParameter parameters; + private readonly TextureMode textureMode; - public HairMaterialBuilder(string name, MaterialSet set, DataProvider dataProvider, CustomizeParameter parameters) : base(name) + public HairMaterialBuilder( + string name, MaterialSet set, DataProvider dataProvider, CustomizeParameter parameters, + TextureMode textureMode) : base(name) { this.set = set; this.dataProvider = dataProvider; this.parameters = parameters; + this.textureMode = textureMode; } - public override MeddleMaterialBuilder Apply() + private void ApplyComputed() { var hairType = set.GetShaderKeyOrDefault(ShaderCategory.CategoryHairType, HairType.Hair); @@ -65,13 +69,23 @@ public override MeddleMaterialBuilder Apply() WithBaseColor(dataProvider.CacheTexture(diffuseTexture, $"Computed/{set.ComputedTextureName("diffuse")}")); WithNormal(dataProvider.CacheTexture(normalTexture, $"Computed/{set.ComputedTextureName("normal")}")); WithMetallicRoughness(dataProvider.CacheTexture(metallicRoughnessTexture, $"Computed/{set.ComputedTextureName("metallicRoughness")}")); + } + + public override MeddleMaterialBuilder Apply() + { + if (textureMode == TextureMode.Bake) + { + ApplyComputed(); + } + else + { + ApplyRaw(set, dataProvider); + } + WithAlpha(AlphaMode.MASK, set.GetConstantOrThrow(MaterialConstant.g_AlphaThreshold)); IndexOfRefraction = set.GetConstantOrThrow(MaterialConstant.g_GlassIOR); - Extras = set.ComposeExtrasNode( - ("hairColor", hairColor.AsFloatArray()), - ("bonusColor", bonusColor.AsFloatArray()) - ); + Extras = set.ComposeExtrasNode(); return this; } } diff --git a/Meddle/Meddle.Plugin/Models/Composer/Materials/IrisMaterialBuilder.cs b/Meddle/Meddle.Plugin/Models/Composer/Materials/IrisMaterialBuilder.cs index 3bed344..2b630d0 100644 --- a/Meddle/Meddle.Plugin/Models/Composer/Materials/IrisMaterialBuilder.cs +++ b/Meddle/Meddle.Plugin/Models/Composer/Materials/IrisMaterialBuilder.cs @@ -12,12 +12,16 @@ public class IrisMaterialBuilder : MeddleMaterialBuilder private readonly MaterialSet set; private readonly DataProvider dataProvider; private readonly CustomizeParameter parameters; + private readonly TextureMode textureMode; - public IrisMaterialBuilder(string name, MaterialSet set, DataProvider dataProvider, CustomizeParameter parameters) : base(name) + public IrisMaterialBuilder( + string name, MaterialSet set, DataProvider dataProvider, CustomizeParameter parameters, + TextureMode textureMode) : base(name) { this.set = set; this.dataProvider = dataProvider; this.parameters = parameters; + this.textureMode = textureMode; } private SKTexture GetCubeMap(int index) @@ -29,7 +33,7 @@ private SKTexture GetCubeMap(int index) return ImageUtils.GetTexData(cubeMap, index, 0, 0).ToTexture(); } - public override MeddleMaterialBuilder Apply() + private void ApplyComputed() { if (!set.TryGetTextureStrict(dataProvider, TextureUsage.g_SamplerNormal, out var normalRes)) throw new InvalidOperationException("Missing normal texture"); @@ -79,16 +83,25 @@ public override MeddleMaterialBuilder Apply() WithSpecularFactor(dataProvider.CacheTexture(specularTexture, $"Computed/{set.ComputedTextureName("specular")}"), 0.2f); WithSpecularColor(dataProvider.CacheTexture(specularTexture, $"Computed/{set.ComputedTextureName("specular")}")); WithEmissive(dataProvider.CacheTexture(emissiveTexture, $"Computed/{set.ComputedTextureName("emissive")}")); + } + + public override MeddleMaterialBuilder Apply() + { + if (textureMode == TextureMode.Bake) + { + ApplyComputed(); + } + else + { + ApplyRaw(set, dataProvider); + } IndexOfRefraction = set.GetConstantOrThrow(MaterialConstant.g_GlassIOR); var alphaThreshold = set.GetConstantOrThrow(MaterialConstant.g_AlphaThreshold); if (alphaThreshold > 0) WithAlpha(AlphaMode.MASK, alphaThreshold); - - Extras = set.ComposeExtrasNode( - ("leftIrisColor", leftIrisColor.AsFloatArray()), - ("rightIrisColor", parameters.RightColor.AsFloatArray()) - ); + + Extras = set.ComposeExtrasNode(); return this; } } diff --git a/Meddle/Meddle.Plugin/Models/Composer/Materials/LightshaftMaterialBuilder.cs b/Meddle/Meddle.Plugin/Models/Composer/Materials/LightshaftMaterialBuilder.cs index 5cfbeaa..b2f43b1 100644 --- a/Meddle/Meddle.Plugin/Models/Composer/Materials/LightshaftMaterialBuilder.cs +++ b/Meddle/Meddle.Plugin/Models/Composer/Materials/LightshaftMaterialBuilder.cs @@ -20,7 +20,6 @@ public override MeddleMaterialBuilder Apply() this.WithBaseColor(new Vector4(1, 1, 1, 0)); WithAlpha(AlphaMode.BLEND, 0.5f); - IndexOfRefraction = 1.0f; Extras = set.ComposeExtrasNode(); return this; } diff --git a/Meddle/Meddle.Plugin/Models/Composer/Materials/MeddleMaterialBuilder.cs b/Meddle/Meddle.Plugin/Models/Composer/Materials/MeddleMaterialBuilder.cs index 5e32635..489d40a 100644 --- a/Meddle/Meddle.Plugin/Models/Composer/Materials/MeddleMaterialBuilder.cs +++ b/Meddle/Meddle.Plugin/Models/Composer/Materials/MeddleMaterialBuilder.cs @@ -1,12 +1,37 @@ -using SharpGLTF.Materials; +using Meddle.Utils; +using Meddle.Utils.Materials; +using SharpGLTF.Materials; namespace Meddle.Plugin.Models.Composer.Materials; -public abstract class MeddleMaterialBuilder : MaterialBuilder +public abstract class MeddleMaterialBuilder : MaterialBuilder, IVertexPaintMaterialBuilder { public MeddleMaterialBuilder(string name) : base(name) { + IndexOfRefraction = 1.0f; } public abstract MeddleMaterialBuilder Apply(); + + internal void ApplyRaw(MaterialSet set, DataProvider dataProvider) + { + VertexPaint = true; + + var hashStr = set.HashStr(); + foreach (var texture in set.TextureUsageDict) + { + if (set.TryGetTexture(dataProvider, texture.Key, out var tex)) + { + var texName = $"{hashStr}/{set.ComputedTextureName(texture.Value.GamePath)}"; + var builder = dataProvider.CacheTexture(tex.ToTexture(), texName); + var mapped = GenericMaterialBuilder.MapTextureUsageToChannel(texture.Key); + if (mapped != null) + { + WithChannelImage(mapped.Value, builder); + } + } + } + } + + public bool VertexPaint { get; internal set; } } diff --git a/Meddle/Meddle.Plugin/Models/Composer/Materials/SkinMaterialBuilder.cs b/Meddle/Meddle.Plugin/Models/Composer/Materials/SkinMaterialBuilder.cs index 7950bb2..cdd8d7a 100644 --- a/Meddle/Meddle.Plugin/Models/Composer/Materials/SkinMaterialBuilder.cs +++ b/Meddle/Meddle.Plugin/Models/Composer/Materials/SkinMaterialBuilder.cs @@ -12,18 +12,22 @@ public class SkinMaterialBuilder : MeddleMaterialBuilder private readonly DataProvider dataProvider; private readonly CustomizeParameter parameters; private readonly CustomizeData data; + private readonly TextureMode textureMode; - public SkinMaterialBuilder(string name, MaterialSet set, DataProvider dataProvider, CustomizeParameter parameters, CustomizeData data) : base(name) + public SkinMaterialBuilder( + string name, MaterialSet set, DataProvider dataProvider, CustomizeParameter parameters, CustomizeData data, + TextureMode textureMode) : base(name) { this.set = set; this.dataProvider = dataProvider; this.parameters = parameters; this.data = data; + this.textureMode = textureMode; } - public override MeddleMaterialBuilder Apply() + private void ApplyComputed() { - var skinType = set.GetShaderKeyOrDefault(ShaderCategory.CategorySkinType, SkinType.Face); + var skinType = set.GetShaderKeyOrDefault(ShaderCategory.CategorySkinType, SkinType.Face); // var normalTexture = set.GetTexture(dataProvider, TextureUsage.g_SamplerNormal).ToResource().ToTexture(); // var maskTexture = set.GetTexture(dataProvider, TextureUsage.g_SamplerMask).ToResource().ToTexture(normalTexture.Size); @@ -113,13 +117,26 @@ public override MeddleMaterialBuilder Apply() WithNormal(dataProvider.CacheTexture(normalTexture, $"Computed/{set.ComputedTextureName("normal")}")); WithMetallicRoughness(dataProvider.CacheTexture(metallicRoughnessTexture, $"Computed/{set.ComputedTextureName("metallicRoughness")}")); WithVolumeThickness(dataProvider.CacheTexture(sssTexture, $"Computed/{set.ComputedTextureName("sss")}"), 1.0f); - - IndexOfRefraction = set.GetConstantOrThrow(MaterialConstant.g_GlassIOR); - WithMetallicRoughnessShader(); - WithAlpha(AlphaMode.MASK, alphaThreshold); - WithDoubleSide(set.RenderBackfaces); - - Extras = set.ComposeExtrasNode(); - return this; + } + + public override MeddleMaterialBuilder Apply() + { + if (textureMode == TextureMode.Bake) + { + ApplyComputed(); + } + else + { + ApplyRaw(set, dataProvider); + } + + IndexOfRefraction = set.GetConstantOrDefault(MaterialConstant.g_GlassIOR, 1.0f); + var alphaThreshold = set.GetConstantOrDefault(MaterialConstant.g_AlphaThreshold, 0.0f); + WithAlpha(AlphaMode.MASK, alphaThreshold); + WithMetallicRoughnessShader(); + WithDoubleSide(set.RenderBackfaces); + Extras = set.ComposeExtrasNode(); + + return this; } } diff --git a/Meddle/Meddle.Plugin/Models/Enums.cs b/Meddle/Meddle.Plugin/Models/Enums.cs index b3c323b..274a7b8 100644 --- a/Meddle/Meddle.Plugin/Models/Enums.cs +++ b/Meddle/Meddle.Plugin/Models/Enums.cs @@ -16,3 +16,9 @@ public enum ExportType OBJ = 4 // ReSharper restore InconsistentNaming } + +public enum TextureMode +{ + Bake, + Raw +} diff --git a/Meddle/Meddle.Plugin/Plugin.cs b/Meddle/Meddle.Plugin/Plugin.cs index 2afab84..62a2d43 100644 --- a/Meddle/Meddle.Plugin/Plugin.cs +++ b/Meddle/Meddle.Plugin/Plugin.cs @@ -133,7 +133,7 @@ public class Configuration : IPluginConfiguration /// public SkeletonUtils.PoseMode PoseMode { get; set; } = DefaultPoseMode; - public bool ComputeCharacterTextures { get; set; } = true; + public TextureMode TextureMode { get; set; } = TextureMode.Bake; /// /// GLTF = GLTF JSON diff --git a/Meddle/Meddle.Plugin/UI/Layout/Instance.cs b/Meddle/Meddle.Plugin/UI/Layout/Instance.cs index c27fc3f..5efb45e 100644 --- a/Meddle/Meddle.Plugin/UI/Layout/Instance.cs +++ b/Meddle/Meddle.Plugin/UI/Layout/Instance.cs @@ -1,12 +1,19 @@ using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using Dalamud.Interface.Textures; using Dalamud.Interface.Utility.Raii; using FFXIVClientStructs.FFXIV.Client.Game.Object; +using FFXIVClientStructs.FFXIV.Client.Graphics; +using FFXIVClientStructs.FFXIV.Client.LayoutEngine.Layer; +using FFXIVClientStructs.Interop; using ImGuiNET; using Meddle.Plugin.Models.Layout; +using Meddle.Plugin.Models.Structs; using Meddle.Plugin.Utils; using Meddle.Utils; using Meddle.Utils.Export; +using Transform = FFXIVClientStructs.FFXIV.Client.LayoutEngine.Transform; namespace Meddle.Plugin.UI.Layout; @@ -26,7 +33,7 @@ private void DrawInstanceTable(IEnumerable instances, Action stack, Action, ParsedInstance>? additionalOptions = null) { if (stack.Count > 10) diff --git a/Meddle/Meddle.Plugin/UI/OptionsTab.cs b/Meddle/Meddle.Plugin/UI/OptionsTab.cs index bdf020e..3bc68c8 100644 --- a/Meddle/Meddle.Plugin/UI/OptionsTab.cs +++ b/Meddle/Meddle.Plugin/UI/OptionsTab.cs @@ -77,12 +77,7 @@ public void Draw() DrawPoseMode(); - var computeCharacterTextures = config.ComputeCharacterTextures; - if (ImGui.Checkbox("Compute Character Textures", ref computeCharacterTextures)) - { - config.ComputeCharacterTextures = computeCharacterTextures; - config.Save(); - } + DrawCharacterTextureMode(); ImGui.Separator(); @@ -163,6 +158,30 @@ private void DrawPoseMode() } } + private void DrawCharacterTextureMode() + { + var characterTexture = config.TextureMode; + if (ImGui.BeginCombo("Character Texture Mode", characterTexture.ToString())) + { + foreach (var mode in Enum.GetValues()) + { + if (ImGui.Selectable(mode.ToString(), mode == characterTexture)) + { + config.TextureMode = mode; + config.Save(); + } + } + + ImGui.EndCombo(); + } + + if (!Enum.IsDefined(typeof(TextureMode), config.TextureMode)) + { + config.TextureMode = TextureMode.Bake; + config.Save(); + } + } + private void DrawExportType() { var exportType = config.ExportType;