Skip to content

Commit e470731

Browse files
committed
Corrections to skin reference calculations during model import.
1 parent 57ed263 commit e470731

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

xivModdingFramework/Models/Helpers/ModelModifiers.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@ public static void CalculateTangentsFromBinormals(TTModel model, Action<bool, st
11341134
}
11351135

11361136

1137+
private static readonly Regex _skinMaterialRegex = new Regex("^/mt_c([0-9]{4})b([0-9]{4})_.+\\.mtrl$");
11371138

11381139
/// <summary>
11391140
/// Fixes up the racial skin references in the model's materials.
@@ -1148,23 +1149,41 @@ public static void FixUpSkinReferences(TTModel model, string newInternalPath, Ac
11481149
// It's not actually -NEEDED-, as the game will dynamically resolve them anyways to the player's skin material, but it's good for user expectation and sanity.
11491150

11501151
var raceRegex = new Regex("(c[0-9]{4})");
1152+
var bodyRegex = new Regex("(b[0-9]{4})");
1153+
11511154
// So we have to do this step first.
11521155
var newRaceMatch = raceRegex.Match(newInternalPath);
11531156

1157+
// Now model doesn't exist in a racial folder. Nothing to fix up/impossible to.
11541158
if(!newRaceMatch.Success)
11551159
{
11561160
return;
11571161
}
11581162

11591163
loggingFunction(false, "Fixing up racial skin references...");
11601164

1165+
// Need to find the racial skin for this race.
1166+
var baseRace = XivRaces.GetXivRace(newRaceMatch.Groups[1].Value.Substring(1));
1167+
var skinRace = XivRaceTree.GetSkinRace(baseRace);
1168+
var skinRaceString = "c" + XivRaces.GetRaceCode(skinRace);
1169+
1170+
1171+
11611172
foreach (var m in model.MeshGroups)
11621173
{
11631174
if (m.Material == null) continue;
1164-
var mtrlMatch = raceRegex.Match(m.Material);
1165-
if(mtrlMatch.Success)
1175+
1176+
// Only fix up -skin- materials.
1177+
if (_skinMaterialRegex.IsMatch(m.Material))
11661178
{
1167-
m.Material.Replace(mtrlMatch.Groups[1].Value, newRaceMatch.Groups[1].Value);
1179+
var mtrlMatch = raceRegex.Match(m.Material);
1180+
if (mtrlMatch.Success && mtrlMatch.Groups[1].Value != skinRaceString)
1181+
{
1182+
m.Material = m.Material.Replace(mtrlMatch.Groups[1].Value, skinRaceString);
1183+
1184+
// Reset the body ID if we actually changed races.
1185+
m.Material = bodyRegex.Replace(m.Material, "b0001");
1186+
}
11681187
}
11691188
}
11701189

0 commit comments

Comments
 (0)