Skip to content

Commit d92355f

Browse files
authored
Merge pull request #17 from Lunaretic/master
Calculate Bounding Box data for imported models.
2 parents 75e3868 + c8ee182 commit d92355f

File tree

1 file changed

+31
-3
lines changed
  • xivModdingFramework/Models/FileTypes

1 file changed

+31
-3
lines changed

xivModdingFramework/Models/FileTypes/Mdl.cs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,10 @@ public async Task<Dictionary<string, string>> ImportModel(IItemModel item, XivMd
13971397
// A dictionary containing error messages if there are any so that a single exception can be thrown with all available context
13981398
var errorDictionary = new Dictionary<int, string>();
13991399

1400+
// Calculations for bounding boxes.
1401+
var maxPos = Vector3.Zero;
1402+
var minPos = Vector3.Zero;
1403+
14001404
// Check for missing data and add dummy data if possible or throw exception
14011405
for (var i = 0; i < meshPartDataDictionary.Count; i++)
14021406
{
@@ -1462,6 +1466,7 @@ public async Task<Dictionary<string, string>> ImportModel(IItemModel item, XivMd
14621466
throw new Exception(errorString);
14631467
}
14641468

1469+
14651470
var indexListList = new List<List<int[]>>();
14661471
var partStartingIndexDicList = new List<Dictionary<(int Start,int End),Dictionary<string,int>>>();
14671472
for (var i = 0; i < meshPartDataDictionary.Count; i++)
@@ -1491,6 +1496,7 @@ public async Task<Dictionary<string, string>> ImportModel(IItemModel item, XivMd
14911496
var biNormalMax = 0;
14921497
var vColorAlphaMax = 0;
14931498

1499+
14941500
if (partDataDict.Count > 0)
14951501
{
14961502
var startingIndex = 0;
@@ -1523,8 +1529,10 @@ public async Task<Dictionary<string, string>> ImportModel(IItemModel item, XivMd
15231529
}
15241530

15251531
// Consolidate all index data into one Collada Data per mesh
1532+
15261533
for (var k = 0; k < partDataDict[partNum].PositionIndices.Count; k++)
15271534
{
1535+
15281536
meshDataDictionary[i].Indices.Add(partDataDict[partNum].PositionIndices[k] + positionMax);
15291537
meshDataDictionary[i].Indices.Add(partDataDict[partNum].NormalIndices[k] + normalMax);
15301538
meshDataDictionary[i].Indices.Add(partDataDict[partNum].TextureCoordinate0Indices[k] + texCoord0Max);
@@ -1745,9 +1753,18 @@ Dictionary<string,int> GetIndexLocDictionary(int meshIndex,int index,string key)
17451753

17461754
for (var i = 0; i < colladaData.Positions.Count; i += 3)
17471755
{
1748-
positionCollection.Add(new Vector3((colladaData.Positions[i] / ModelMultiplier),
1756+
1757+
var pos = new Vector3((colladaData.Positions[i] / ModelMultiplier),
17491758
(colladaData.Positions[i + 1] / ModelMultiplier),
1750-
(colladaData.Positions[i + 2] / ModelMultiplier)));
1759+
(colladaData.Positions[i + 2] / ModelMultiplier));
1760+
1761+
maxPos.X = maxPos.X > pos.X ? maxPos.X : pos.X;
1762+
maxPos.Y = maxPos.Y > pos.Y ? maxPos.Y : pos.Y;
1763+
maxPos.Z = maxPos.Z > pos.Z ? maxPos.Z : pos.Z;
1764+
minPos.X = minPos.X < pos.X ? minPos.X : pos.X;
1765+
minPos.Y = minPos.Y < pos.Y ? minPos.Y : pos.Y;
1766+
minPos.Z = minPos.Z < pos.Z ? minPos.Z : pos.Z;
1767+
positionCollection.Add(pos);
17511768
}
17521769

17531770
for (var i = 0; i < colladaData.Normals.Count; i += 3)
@@ -2377,6 +2394,17 @@ Dictionary<string,int> GetIndexLocDictionary(int meshIndex,int index,string key)
23772394
warningsDictionary.Add($"Weight Corrections", weightErrorString);
23782395
}
23792396

2397+
xivMdl.BoundBox.PointList[0] = new Vector4(minPos, 1);
2398+
xivMdl.BoundBox.PointList[1] = new Vector4(maxPos, 1);
2399+
xivMdl.BoundBox.PointList[2] = new Vector4(minPos, 1);
2400+
xivMdl.BoundBox.PointList[3] = new Vector4(maxPos, 1);
2401+
xivMdl.BoundBox.PointList[4] = new Vector4(0,0,0,0);
2402+
xivMdl.BoundBox.PointList[5] = new Vector4(0, 0, 0, 0);
2403+
xivMdl.BoundBox.PointList[6] = new Vector4(0, 0, 0, 0);
2404+
xivMdl.BoundBox.PointList[7] = new Vector4(0, 0, 0, 0);
2405+
//xivMdl.BoundBox.PointList[1] = Vector(;
2406+
//xivMdl.BoundBox.PointList[2] = minPos;
2407+
23802408
await MakeNewMdlFile(colladaMeshDataList, item, xivMdl, advImportSettings, source, rawDataOnly);
23812409

23822410
return warningsDictionary;
@@ -3934,7 +3962,7 @@ private async Task MakeNewMdlFile(List<ColladaMeshData> colladaMeshDataList, IIt
39343962
#region Bounding Box Data Block
39353963

39363964
var boundingBoxDataBlock = new List<byte>();
3937-
3965+
39383966
var boundingBox = xivMdl.BoundBox;
39393967

39403968
foreach (var point in boundingBox.PointList)

0 commit comments

Comments
 (0)