Skip to content

Commit e160bfd

Browse files
committed
Added basic model sanity check function to catch common errors.
1 parent b0638b0 commit e160bfd

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

xivModdingFramework/Models/DataContainers/TTModel.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,39 @@ private Dictionary<string, SkeletonData> ResolveBoneHeirarchy()
11601160
return skelDict;
11611161
}
11621162

1163+
1164+
/// <summary>
1165+
/// Performs a basic sanity check on an incoming TTModel
1166+
/// Returns true if there were no errors or errors that were resolvable.
1167+
/// Returns false if the model was deemed insane.
1168+
/// </summary>
1169+
/// <param name="model"></param>
1170+
/// <param name="loggingFunction"></param>
1171+
/// <returns></returns>
1172+
public static bool SanityCheck(TTModel model, Action<bool, string> loggingFunction = null)
1173+
{
1174+
if (loggingFunction == null)
1175+
{
1176+
loggingFunction = ModelModifiers.NoOp;
1177+
}
1178+
1179+
if(model.MeshGroups.Count == 0)
1180+
{
1181+
loggingFunction(true, "Model has no data. - Model must have at least one valid Mesh Group.");
1182+
return false;
1183+
}
1184+
1185+
1186+
var Group0Valid = model.MeshGroups[0].Parts.Any(x => x.Vertices.Count > 0);
1187+
if(!Group0Valid)
1188+
{
1189+
loggingFunction(true, "Mesh Group 0 has no valid parts - Model must have at least one vertex in Mesh Group 0.");
1190+
return false;
1191+
}
1192+
1193+
return true;
1194+
}
1195+
11631196
#endregion
11641197
}
11651198
}

xivModdingFramework/Models/FileTypes/Mdl.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,10 +1910,12 @@ await Task.Run(async () =>
19101910
}
19111911
#endregion
19121912

1913-
if (ttModel.MeshGroups.Count == 0)
1913+
var sane = TTModel.SanityCheck(ttModel, loggingFunction);
1914+
if(!sane)
19141915
{
1915-
throw new InvalidDataException("The imported model has no data.");
1916+
throw new InvalidDataException("Model was deemed invalid.");
19161917
}
1918+
19171919
// At this point we now have a fully populated TTModel entry.
19181920
// Time to pull in the Model Modifier for any extra steps before we pass
19191921
// it to the raw MDL creation function.

0 commit comments

Comments
 (0)