Skip to content

Commit

Permalink
Fix charactertattoo not exporting correctly in raw mode
Browse files Browse the repository at this point in the history
  • Loading branch information
PassiveModding committed Jan 13, 2025
1 parent 2cf03a0 commit c6bc174
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
10 changes: 5 additions & 5 deletions Meddle/Meddle.Plugin/Models/Composer/MaterialSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,12 @@ public Vector4 GetConstantOrDefault(MaterialConstant id, Vector4 @default)
: @default;
}

public uint GetShaderKeyOrDefault(uint category)
public uint GetShaderKeyOrThrow(uint category)
{
return GetShaderKeyOrDefault((ShaderCategory)category);
return GetShaderKeyOrThrow((ShaderCategory)category);
}

public uint GetShaderKeyOrDefault(ShaderCategory category)
public uint GetShaderKeyOrThrow(ShaderCategory category)
{
if (ShaderKeyDict.TryGetValue(category, out var value))
{
Expand All @@ -347,7 +347,7 @@ public uint GetShaderKeyOrDefault(ShaderCategory category)
throw new InvalidOperationException($"Shader key {category} not found");
}

public TValue GetShaderKeyOrDefault<TValue>(ShaderCategory category) where TValue : Enum
public TValue GetShaderKeyOrThrow<TValue>(ShaderCategory category) where TValue : Enum
{
if (ShaderKeyDict.TryGetValue(category, out var value))
{
Expand Down Expand Up @@ -518,7 +518,7 @@ void AddCustomizeParameters()
extrasDict["FacePaintUVOffset"] = customizeParameters.FacePaintUVOffset;
extrasDict["FacePaintUVMultiplier"] = customizeParameters.FacePaintUVMultiplier;
extrasDict["MuscleTone"] = customizeParameters.MuscleTone;
extrasDict["OptionColor"] = customizeParameters.OptionColor;
extrasDict["OptionColor"] = customizeParameters.OptionColor.AsFloatArray();
extrasDict["CustomizeParameters"] = JsonNode.Parse(JsonSerializer.Serialize(customizeParameters, JsonOptions))!;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public CharacterMaterialBuilder(string name, MaterialSet set, DataProvider dataP

private void ApplyComputed()
{
var textureMode = set.GetShaderKeyOrDefault<Meddle.Utils.Constants.TextureMode>(ShaderCategory.GetValuesTextureType);
var textureMode = set.GetShaderKeyOrThrow<Meddle.Utils.Constants.TextureMode>(ShaderCategory.GetValuesTextureType);

if (!set.TryGetTextureStrict(dataProvider, TextureUsage.g_SamplerNormal, out var normalRes))
throw new InvalidOperationException("Missing normal texture");
Expand Down Expand Up @@ -108,7 +108,6 @@ public override MeddleMaterialBuilder Apply()

WithDoubleSide(set.RenderBackfaces);


Extras = set.ComposeExtrasNode();
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class CharacterTattooMaterialBuilder : MeddleMaterialBuilder
private readonly MaterialSet set;
private readonly DataProvider dataProvider;
private readonly CustomizeParameter customizeParameter;
private readonly TextureMode textureMode;

public CharacterTattooMaterialBuilder(
string name, MaterialSet set, DataProvider dataProvider, CustomizeParameter customizeParameter,
Expand All @@ -22,9 +23,10 @@ public CharacterTattooMaterialBuilder(
this.set = set;
this.dataProvider = dataProvider;
this.customizeParameter = customizeParameter;
this.textureMode = textureMode;
}

public override MeddleMaterialBuilder Apply()
private void ApplyComputed()
{
var influenceColor = customizeParameter.OptionColor;
if (!set.TryGetTextureStrict(dataProvider, TextureUsage.g_SamplerNormal, out var normalRes))
Expand All @@ -51,14 +53,25 @@ 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);
}

WithDoubleSide(set.RenderBackfaces);

WithAlpha(AlphaMode.BLEND, set.GetConstantOrThrow<float>(MaterialConstant.g_AlphaThreshold));
IndexOfRefraction = set.GetConstantOrThrow<float>(MaterialConstant.g_GlassIOR);
var alphaThreshold = set.GetConstantOrThrow<float>(MaterialConstant.g_AlphaThreshold);
WithAlpha(AlphaMode.BLEND, alphaThreshold);

WithDoubleSide(set.RenderBackfaces);
Extras = set.ComposeExtrasNode();

return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public HairMaterialBuilder(

private void ApplyComputed()
{
var hairType = set.GetShaderKeyOrDefault<HairType>(ShaderCategory.CategoryHairType);
var hairType = set.GetShaderKeyOrThrow<HairType>(ShaderCategory.CategoryHairType);

if (!set.TryGetTextureStrict(dataProvider, TextureUsage.g_SamplerNormal, out var normalRes))
throw new InvalidOperationException("Missing normal texture");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public SkinMaterialBuilder(

private void ApplyComputed()
{
var skinType = set.GetShaderKeyOrDefault<SkinType>(ShaderCategory.CategorySkinType);
var skinType = set.GetShaderKeyOrThrow<SkinType>(ShaderCategory.CategorySkinType);

// var normalTexture = set.GetTexture(dataProvider, TextureUsage.g_SamplerNormal).ToResource().ToTexture();
// var maskTexture = set.GetTexture(dataProvider, TextureUsage.g_SamplerMask).ToResource().ToTexture(normalTexture.Size);
Expand Down Expand Up @@ -136,7 +136,6 @@ public override MeddleMaterialBuilder Apply()
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();

Expand Down

0 comments on commit c6bc174

Please sign in to comment.