Skip to content

Commit 7488ac0

Browse files
committed
Bone bounding box changes.
1 parent 767a2d1 commit 7488ac0

File tree

1 file changed

+37
-10
lines changed
  • xivModdingFramework/Models/FileTypes

1 file changed

+37
-10
lines changed

xivModdingFramework/Models/FileTypes/Mdl.cs

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3519,6 +3519,7 @@ public static byte[] MakeUncompressedMdlFile(TTModel ttModel, XivMdl ogMdl, Acti
35193519
if (i < 2)
35203520
{
35213521
// First bounding box is bounds from the origin.
3522+
35223523
boundingBoxDataBlock.AddRange(BitConverter.GetBytes(i == 0 && minVect.X > 0 ? 0.0f : minVect.X));
35233524
boundingBoxDataBlock.AddRange(BitConverter.GetBytes(i == 0 && minVect.Y > 0 ? 0.0f : minVect.Y));
35243525
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
35363537
}
35373538
}
35383539

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;
35433569
var boneBoundingBoxDataBlock = new List<byte>();
35443570
for (var i = 0; i < ttModel.Bones.Count; i++)
35453571
{
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));
35493576
boundingBoxDataBlock.AddRange(BitConverter.GetBytes(1.0f));
35503577

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));
35543581
boundingBoxDataBlock.AddRange(BitConverter.GetBytes(1.0f));
35553582
}
35563583

0 commit comments

Comments
 (0)