Skip to content

Commit 6945c66

Browse files
committed
Merge branch 'develop' into full_model
2 parents 2d924c8 + 8340d93 commit 6945c66

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

xivModdingFramework/Materials/FileTypes/Mtrl.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ private async Task<List<TexTypePath>> GetTexNames(IEnumerable<string> texPathLis
996996
private static readonly Regex _weaponMatch = new Regex("(w[0-9]{4})");
997997
private static readonly Regex _tailMatch = new Regex("(t[0-9]{4})");
998998
private static readonly Regex _raceMatch = new Regex("(c[0-9]{4})");
999+
private static readonly Regex _bodyRegex = new Regex("(b[0-9]{4})");
9991000
private static readonly Regex _skinRegex = new Regex("^/mt_c([0-9]{4})b([0-9]{4})_.+\\.mtrl$");
10001001
/// <summary>
10011002
/// Resolves the MTRL path for a given MDL path.
@@ -1020,11 +1021,27 @@ public string GetMtrlPath(string mdlPath, string mtrlName, int mtrlVariant = 1)
10201021
var mdlMatch = _raceMatch.Match(mdlPath);
10211022
var mtrlMatch = _raceMatch.Match(mtrlName);
10221023

1024+
10231025
// Both Items have racial model information in their path, and the races DON'T match.
10241026
if (mdlMatch.Success && mtrlMatch.Success && mdlMatch.Groups[1].Value != mtrlMatch.Groups[1].Value)
10251027
{
1026-
// In this case, we actually replace the race in the Material the race from the MODEL, which has priority.
1027-
mtrlName = mtrlName.Replace(mtrlMatch.Groups[1].Value, mdlMatch.Groups[1].Value);
1028+
1029+
// Need to find the racial skin for this race.
1030+
var baseRace = XivRaces.GetXivRace(mdlMatch.Groups[1].Value.Substring(1));
1031+
var skinRace = XivRaceTree.GetSkinRace(baseRace);
1032+
var skinRaceString = "c" + XivRaces.GetRaceCode(skinRace);
1033+
1034+
// In this case, we actually replace both with the racial skin material based on the Model, which has priority.
1035+
mtrlName = mtrlName.Replace(mtrlMatch.Groups[1].Value, skinRaceString);
1036+
mdlPath = mdlPath.Replace(mdlMatch.Groups[1].Value, skinRaceString);
1037+
1038+
// If we actually shifted races, reset the body identifier.
1039+
// This shouldn't really ever happen, but safety check.
1040+
if(baseRace != skinRace)
1041+
{
1042+
mtrlName = _bodyRegex.Replace(mtrlName, "b0001");
1043+
mdlPath = _bodyRegex.Replace(mdlPath, "b0001");
1044+
}
10281045
}
10291046

10301047

xivModdingFramework/Models/FileTypes/Mdl.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ public async Task ExportModel(TTModel model, string outputFilePath, int mtrlVari
217217
// Pop the textures out so the exporters can reference them.
218218
if (includeTextures)
219219
{
220+
// Fix up our skin references in the model before exporting, to ensure
221+
// we supply the right material names to the exporters down-chain.
222+
if (model.IsInternal)
223+
{
224+
ModelModifiers.FixUpSkinReferences(model, model.Source, null);
225+
}
220226
await ExportMaterialsForModel(model, outputFilePath, _gameDirectory, mtrlVariant);
221227
}
222228

xivModdingFramework/Models/Helpers/ModelModifiers.cs

Lines changed: 26 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.
@@ -1143,28 +1144,50 @@ public static void CalculateTangentsFromBinormals(TTModel model, Action<bool, st
11431144
/// <param name="newInternalPath"></param>
11441145
public static void FixUpSkinReferences(TTModel model, string newInternalPath, Action<bool, string> loggingFunction = null)
11451146
{
1147+
if (loggingFunction == null)
1148+
{
1149+
loggingFunction = NoOp;
1150+
}
11461151

11471152
// Here we should to go in and correct any Skin Material references to point to the skin material for this race.
11481153
// 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.
11491154

11501155
var raceRegex = new Regex("(c[0-9]{4})");
1156+
var bodyRegex = new Regex("(b[0-9]{4})");
1157+
11511158
// So we have to do this step first.
11521159
var newRaceMatch = raceRegex.Match(newInternalPath);
11531160

1161+
// Now model doesn't exist in a racial folder. Nothing to fix up/impossible to.
11541162
if(!newRaceMatch.Success)
11551163
{
11561164
return;
11571165
}
11581166

11591167
loggingFunction(false, "Fixing up racial skin references...");
11601168

1169+
// Need to find the racial skin for this race.
1170+
var baseRace = XivRaces.GetXivRace(newRaceMatch.Groups[1].Value.Substring(1));
1171+
var skinRace = XivRaceTree.GetSkinRace(baseRace);
1172+
var skinRaceString = "c" + XivRaces.GetRaceCode(skinRace);
1173+
1174+
1175+
11611176
foreach (var m in model.MeshGroups)
11621177
{
11631178
if (m.Material == null) continue;
1164-
var mtrlMatch = raceRegex.Match(m.Material);
1165-
if(mtrlMatch.Success)
1179+
1180+
// Only fix up -skin- materials.
1181+
if (_skinMaterialRegex.IsMatch(m.Material))
11661182
{
1167-
m.Material.Replace(mtrlMatch.Groups[1].Value, newRaceMatch.Groups[1].Value);
1183+
var mtrlMatch = raceRegex.Match(m.Material);
1184+
if (mtrlMatch.Success && mtrlMatch.Groups[1].Value != skinRaceString)
1185+
{
1186+
m.Material = m.Material.Replace(mtrlMatch.Groups[1].Value, skinRaceString);
1187+
1188+
// Reset the body ID if we actually changed races.
1189+
m.Material = bodyRegex.Replace(m.Material, "b0001");
1190+
}
11681191
}
11691192
}
11701193

0 commit comments

Comments
 (0)