Skip to content

Commit b9f429e

Browse files
committed
Improved handling of Furniture Materials.
1 parent 3bb0f56 commit b9f429e

File tree

2 files changed

+61
-15
lines changed

2 files changed

+61
-15
lines changed

xivModdingFramework/Materials/DataContainers/XivMtrl.cs

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ public ShaderInfo GetShaderInfo()
309309
case "bg.shpk":
310310
info.Shader = MtrlShader.Furniture;
311311
break;
312+
case "bgcolorchange.shpk":
313+
info.Shader = MtrlShader.DyeableFurniture;
314+
break;
312315
default:
313316
info.Shader = MtrlShader.Other;
314317
break;
@@ -356,6 +359,9 @@ public void SetShaderInfo(ShaderInfo info)
356359
case MtrlShader.Furniture:
357360
Shader = "bg.shpk";
358361
break;
362+
case MtrlShader.DyeableFurniture:
363+
Shader = "bgcolorchange.shpk";
364+
break;
359365
default:
360366
// No change to the Shader for 'Other' type entries.
361367
break;
@@ -419,6 +425,11 @@ public MapInfo GetMapInfo(XivTexType MapType)
419425
mapIndex = (int) paramSet.TextureIndex;
420426
info.Format = GetFormat(paramSet.FileFormat);
421427
}
428+
else if (paramSet.TextureType == Mtrl.FurnitureTextureDescriptorValues[MapType])
429+
{
430+
mapIndex = (int)paramSet.TextureIndex;
431+
info.Format = GetFormat(paramSet.FileFormat);
432+
}
422433
}
423434

424435
if(mapIndex < 0)
@@ -472,7 +483,12 @@ public MapInfo GetMapInfo(string path)
472483
if(Mtrl.TextureDescriptorValues.ContainsValue(descriptor.TextureType))
473484
{
474485
info.Usage = Mtrl.TextureDescriptorValues.First(x => x.Value == descriptor.TextureType).Key;
475-
} else
486+
}
487+
else if (Mtrl.FurnitureTextureDescriptorValues.ContainsValue(descriptor.TextureType))
488+
{
489+
info.Usage = Mtrl.FurnitureTextureDescriptorValues.First(x => x.Value == descriptor.TextureType).Key;
490+
}
491+
else
476492
{
477493
info.Usage = XivTexType.Other;
478494
}
@@ -607,6 +623,15 @@ public void SetMapInfo(XivTexType MapType, MapInfo info)
607623
/// </summary>
608624
private void RegenerateTextureUsageList()
609625
{
626+
var shaderInfo = GetShaderInfo();
627+
628+
// Furniture shaders do not use the texture usage list at all.
629+
if(shaderInfo.Shader == MtrlShader.Furniture || shaderInfo.Shader == MtrlShader.DyeableFurniture)
630+
{
631+
TextureUsageList.Clear();
632+
return;
633+
}
634+
610635
// Everything (should) have a normal, so this is redundant.
611636
// bool hasNormal = GetMapInfo(XivTexType.Normal) != null;
612637
bool hasSpec = GetMapInfo(XivTexType.Specular) != null;
@@ -694,6 +719,7 @@ private void SetTextureUsage(XivTexType usage, uint? unknownValue = null)
694719
public List<MapInfo> GetAllMapInfos(bool tokenize = true)
695720
{
696721
var ret = new List<MapInfo>();
722+
var shaderInfo = GetShaderInfo();
697723
for(var i = 0; i < TexturePathList.Count; i++)
698724
{
699725
var info = new MapInfo();
@@ -714,7 +740,16 @@ public List<MapInfo> GetAllMapInfos(bool tokenize = true)
714740
return (x.Value == p.TextureType);
715741
}).Key;
716742
info.Usage = usage;
717-
} else
743+
} else if(Mtrl.FurnitureTextureDescriptorValues.ContainsValue(p.TextureType))
744+
{
745+
// Known parameter for the furniture shaders.
746+
var usage = Mtrl.FurnitureTextureDescriptorValues.First(x =>
747+
{
748+
return (x.Value == p.TextureType);
749+
}).Key;
750+
info.Usage = usage;
751+
752+
} else
718753
{
719754
info.Usage = XivTexType.Other;
720755
}
@@ -748,12 +783,13 @@ public List<TexTypePath> GetTextureTypePathList()
748783
TexTypePath ttp;
749784
foreach (var map in maps)
750785
{
751-
752-
753786
if (shaderInfo.Shader == MtrlShader.Skin && map.Usage == XivTexType.Multi)
754787
{
755788
ttp = new TexTypePath() { DataFile = GetDataFile(), Path = map.path, Type = XivTexType.Skin };
756789

790+
} else if (shaderInfo.Shader == MtrlShader.Furniture && map.path.Contains("dummy")) {
791+
// Dummy textures are skipped.
792+
continue;
757793
}
758794
else
759795
{
@@ -1049,13 +1085,14 @@ public enum MtrlTextureDescriptorFormat
10491085
// Enum representation of the shader names used in mtrl files.
10501086
public enum MtrlShader
10511087
{
1052-
Standard, // character.shpk
1053-
Glass, // characterglass.shpk
1054-
Skin, // skin.shpk
1055-
Hair, // hair.shpk
1056-
Iris, // iris.shpk
1057-
Furniture, // bg.shpk
1058-
Other // Unknown Shader
1088+
Standard, // character.shpk
1089+
Glass, // characterglass.shpk
1090+
Skin, // skin.shpk
1091+
Hair, // hair.shpk
1092+
Iris, // iris.shpk
1093+
Furniture, // bg.shpk
1094+
DyeableFurniture, //bgcolorchange.shpk
1095+
Other // Unknown Shader
10591096
}
10601097

10611098
/// <summary>

xivModdingFramework/Materials/FileTypes/Mtrl.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,20 @@ public XivDataFile DataFile
7474
{ XivTexType.Reflection, 4271961042 } // Used for the Catchlight texture in Iris Materials.
7575
};
7676

77+
public static Dictionary<XivTexType, uint> FurnitureTextureDescriptorValues = new Dictionary<XivTexType, uint>()
78+
{
79+
{ XivTexType.Normal, 2863978985 },
80+
{ XivTexType.Diffuse, 510652316 },
81+
{ XivTexType.Specular, 465317650 },
82+
{ XivTexType.Multi, 0 },
83+
{ XivTexType.Reflection, 0 }
84+
};
85+
7786
// MtrlParam constants for file compressions/formats.
7887
public static Dictionary<MtrlTextureDescriptorFormat, short> TextureDescriptorFormatValues = new Dictionary<MtrlTextureDescriptorFormat, short>()
7988
{
80-
{ MtrlTextureDescriptorFormat.UsesColorset, -32768 }, // There is some variation on these values, but it always occures in the last 6 bits, and doesn't seem
81-
{ MtrlTextureDescriptorFormat.NoColorset, -31936 } // To have an appreciable change (Either [000000] or [010101])
89+
{ MtrlTextureDescriptorFormat.UsesColorset, -32768 }, // There is some variation on these values, but it always occures in the last 6 bits, and doesn't seem
90+
{ MtrlTextureDescriptorFormat.NoColorset, -31936 }, // To have an appreciable change (Either [000000] or [010101])
8291
// Non-normal maps are always [WithoutAlpha]. Normal maps are always [WithAlpha],
8392
// with the exception that 8.8.8.8 ARGB normal maps use the WithoutAlpha flag (And do not pull a colorset).
8493

@@ -607,7 +616,7 @@ public async Task<int> ImportMtrl(XivMtrl xivMtrl, IItem item, string source)
607616
var path = mapInfo.path;
608617
var fileHash = HashGenerator.GetHash(Path.GetFileName(path));
609618
var pathHash = HashGenerator.GetHash(path.Substring(0, path.LastIndexOf("/", StringComparison.Ordinal)));
610-
var exists = await _index.FileExists(fileHash, pathHash, XivDataFile._04_Chara);
619+
var exists = await _index.FileExists(fileHash, pathHash, IOUtil.GetDataFileFromPath(path));
611620

612621
if(exists)
613622
{
@@ -619,7 +628,7 @@ public async Task<int> ImportMtrl(XivMtrl xivMtrl, IItem item, string source)
619628
var xivTex = new XivTex();
620629
xivTex.TextureTypeAndPath = new TexTypePath()
621630
{
622-
DataFile = XivDataFile._04_Chara, Path = path, Type = mapInfo.Usage
631+
DataFile = IOUtil.GetDataFileFromPath(path), Path = path, Type = mapInfo.Usage
623632
};
624633
xivTex.TextureFormat = format;
625634

0 commit comments

Comments
 (0)