@@ -711,7 +711,7 @@ public static void CloneUV2(TTModel model, Action<bool, string> loggingFunction
711
711
/// <param name="model"></param>
712
712
/// <param name="targetRace"></param>
713
713
/// <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 )
715
715
{
716
716
try
717
717
{
@@ -727,10 +727,36 @@ public static void ApplyRacialDeform(TTModel model, XivRace targetRace, Action<b
727
727
}
728
728
loggingFunction ( false , "Attempting to deform model..." ) ;
729
729
730
-
731
730
Dictionary < string , Matrix > deformations , decomposed , recalculated ;
732
731
Mdl . GetDeformationMatrices ( targetRace , out deformations , out decomposed , out recalculated ) ;
733
732
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
+
734
760
// Now we're ready to animate...
735
761
736
762
// For each mesh
@@ -755,10 +781,17 @@ public static void ApplyRacialDeform(TTModel model, XivRace targetRace, Action<b
755
781
var boneWeight = ( v . Weights [ b ] ) / 255f ;
756
782
757
783
var matrix = Matrix . Identity ;
758
- if ( deformations . ContainsKey ( boneName ) ) {
784
+ if ( deformations . ContainsKey ( boneName ) )
785
+ {
759
786
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 } )") ;
762
795
}
763
796
764
797
0 commit comments