@@ -3519,6 +3519,7 @@ public static byte[] MakeUncompressedMdlFile(TTModel ttModel, XivMdl ogMdl, Acti
3519
3519
if ( i < 2 )
3520
3520
{
3521
3521
// First bounding box is bounds from the origin.
3522
+
3522
3523
boundingBoxDataBlock . AddRange ( BitConverter . GetBytes ( i == 0 && minVect . X > 0 ? 0.0f : minVect . X ) ) ;
3523
3524
boundingBoxDataBlock . AddRange ( BitConverter . GetBytes ( i == 0 && minVect . Y > 0 ? 0.0f : minVect . Y ) ) ;
3524
3525
boundingBoxDataBlock . AddRange ( BitConverter . GetBytes ( i == 0 && minVect . Z > 0 ? 0.0f : minVect . Z ) ) ;
@@ -3536,21 +3537,47 @@ public static byte[] MakeUncompressedMdlFile(TTModel ttModel, XivMdl ogMdl, Acti
3536
3537
}
3537
3538
}
3538
3539
3539
- // Afterwards there are is a bounding box for every bone.
3540
- // Again, we'll be lazy and just use the full model bounding box for each.
3541
- // Unsure what these are actually used for since there seems no difference
3542
- // in model function whether these have real data or no data.
3540
+ var ogBbDict = new Dictionary < string , List < Vector4 > > ( ) ;
3541
+
3542
+ var boneId = 0 ;
3543
+ foreach ( var bbList in ogMdl . BoneBoundingBoxes )
3544
+ {
3545
+ if ( boneId >= ogMdl . PathData . BoneList . Count ) continue ;
3546
+ var bone = ogMdl . PathData . BoneList [ boneId ] ;
3547
+
3548
+ var list = bbList ;
3549
+ // Ignore old bad data.
3550
+ if ( new Vector3 ( bbList [ 0 ] [ 0 ] , bbList [ 0 ] [ 1 ] , bbList [ 0 ] [ 2 ] ) == minVect
3551
+ && new Vector3 ( bbList [ 1 ] [ 0 ] , bbList [ 1 ] [ 1 ] , bbList [ 1 ] [ 2 ] ) == maxVect )
3552
+ {
3553
+ list = new List < Vector4 > ( )
3554
+ {
3555
+ new Vector4 ( 0 , 0 , 0 , 0 ) ,
3556
+ new Vector4 ( 0 , 0 , 0 , 0 ) ,
3557
+ } ;
3558
+ }
3559
+
3560
+ ogBbDict . Add ( bone , list ) ;
3561
+ boneId ++ ;
3562
+ }
3563
+
3564
+
3565
+ // Bone bounding boxes. We use a 1/10th model size cube for every bone.
3566
+ // This gives us something functional, without having to do a bunch of wild and crazy
3567
+ // parsing/math or demanding the user import models with a functional skeleton.
3568
+ const float _Divisor = 20.0f ;
3543
3569
var boneBoundingBoxDataBlock = new List < byte > ( ) ;
3544
3570
for ( var i = 0 ; i < ttModel . Bones . Count ; i ++ )
3545
3571
{
3546
- boundingBoxDataBlock . AddRange ( BitConverter . GetBytes ( minVect . X ) ) ;
3547
- boundingBoxDataBlock . AddRange ( BitConverter . GetBytes ( minVect . Y ) ) ;
3548
- boundingBoxDataBlock . AddRange ( BitConverter . GetBytes ( minVect . Z ) ) ;
3572
+ var bone = ttModel . Bones [ i ] ;
3573
+ boundingBoxDataBlock . AddRange ( BitConverter . GetBytes ( - 1 * modelRadius / _Divisor ) ) ;
3574
+ boundingBoxDataBlock . AddRange ( BitConverter . GetBytes ( - 1 * modelRadius / _Divisor ) ) ;
3575
+ boundingBoxDataBlock . AddRange ( BitConverter . GetBytes ( - 1 * modelRadius / _Divisor ) ) ;
3549
3576
boundingBoxDataBlock . AddRange ( BitConverter . GetBytes ( 1.0f ) ) ;
3550
3577
3551
- boundingBoxDataBlock . AddRange ( BitConverter . GetBytes ( maxVect . X ) ) ;
3552
- boundingBoxDataBlock . AddRange ( BitConverter . GetBytes ( maxVect . Y ) ) ;
3553
- boundingBoxDataBlock . AddRange ( BitConverter . GetBytes ( maxVect . Z ) ) ;
3578
+ boundingBoxDataBlock . AddRange ( BitConverter . GetBytes ( modelRadius / _Divisor ) ) ;
3579
+ boundingBoxDataBlock . AddRange ( BitConverter . GetBytes ( modelRadius / _Divisor ) ) ;
3580
+ boundingBoxDataBlock . AddRange ( BitConverter . GetBytes ( modelRadius / _Divisor ) ) ;
3554
3581
boundingBoxDataBlock . AddRange ( BitConverter . GetBytes ( 1.0f ) ) ;
3555
3582
}
3556
3583
0 commit comments