Skip to content

Commit bd0274f

Browse files
committed
Addition of check if deformation is possible
Addition of deform inversion
1 parent 9d76cca commit bd0274f

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

xivModdingFramework/Models/Helpers/ModelModifiers.cs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ public static void CloneUV2(TTModel model, Action<bool, string> loggingFunction
711711
/// <param name="model"></param>
712712
/// <param name="targetRace"></param>
713713
/// <param name="loggingFunction"></param>
714-
public static void ApplyRacialDeform(TTModel model, XivRace targetRace, Action<bool, string> loggingFunction = null)
714+
public static void ApplyRacialDeform(TTModel model, XivRace targetRace, bool invert = false, Action<bool, string> loggingFunction = null)
715715
{
716716
try
717717
{
@@ -727,10 +727,36 @@ public static void ApplyRacialDeform(TTModel model, XivRace targetRace, Action<b
727727
}
728728
loggingFunction(false, "Attempting to deform model...");
729729

730-
731730
Dictionary<string, Matrix> deformations, decomposed, recalculated;
732731
Mdl.GetDeformationMatrices(targetRace, out deformations, out decomposed, out recalculated);
733732

733+
// Check if deformation is possible
734+
var missingDeforms = new HashSet<string>();
735+
736+
foreach (var m in model.MeshGroups)
737+
{
738+
foreach (var mBone in m.Bones)
739+
{
740+
if (!deformations.ContainsKey(mBone))
741+
{
742+
missingDeforms.Add(mBone);
743+
}
744+
}
745+
}
746+
747+
// Throw an exception if there is any missing deform bones
748+
if (missingDeforms.Any())
749+
{
750+
var sb = new StringBuilder();
751+
sb.AppendLine();
752+
foreach (var missingDeform in missingDeforms)
753+
{
754+
sb.AppendLine($"{missingDeform}");
755+
}
756+
757+
throw new Exception(sb.ToString());
758+
}
759+
734760
// Now we're ready to animate...
735761

736762
// For each mesh
@@ -755,10 +781,17 @@ public static void ApplyRacialDeform(TTModel model, XivRace targetRace, Action<b
755781
var boneWeight = (v.Weights[b]) / 255f;
756782

757783
var matrix = Matrix.Identity;
758-
if (deformations.ContainsKey(boneName)) {
784+
if (deformations.ContainsKey(boneName))
785+
{
759786
matrix = deformations[boneName];
760-
} else {
761-
throw new Exception("Invalid bone");
787+
if (invert)
788+
{
789+
matrix.Invert();
790+
}
791+
}
792+
else
793+
{
794+
throw new Exception($"Invalid bone ({boneName})");
762795
}
763796

764797

0 commit comments

Comments
 (0)