Skip to content

Commit 74e5d01

Browse files
committed
Add bounding box updates to fast v6 upgrades.
1 parent 5ab1e34 commit 74e5d01

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

xivModdingFramework/Models/DataContainers/TTModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2400,7 +2400,7 @@ public static void SaveFullToFile(string filePath, XivRace race, List<TTModel> m
24002400
private static void WriteVertex(TTVertex v, SQLiteConnection db, int meshIdx, int partIdx, int vIdx)
24012401
{
24022402
var query = @"insert into vertices ( mesh, part, vertex_id, position_x, position_y, position_z, normal_x, normal_y, normal_z, binormal_x, binormal_y, binormal_z, tangent_x, tangent_y, tangent_z, color_r, color_g, color_b, color_a, color2_r, color2_g, color2_b, color2_a, uv_1_u, uv_1_v, uv_2_u, uv_2_v, bone_1_id, bone_1_weight, bone_2_id, bone_2_weight, bone_3_id, bone_3_weight, bone_4_id, bone_4_weight, bone_5_id, bone_5_weight, bone_6_id, bone_6_weight, bone_7_id, bone_7_weight, bone_8_id, bone_8_weight, uv_3_u, uv_3_v)
2403-
values ($mesh, $part, $vertex_id, $position_x, $position_y, $position_z, $normal_x, $normal_y, $normal_z, $binormal_x, $binormal_y, $binormal_z, $tangent_x, $tangent_y, $tangent_z, $color_r, $color_g, $color_b, $color1_a, $color2_r, $color2_g, $color2_b, $color2_a, $uv_1_u, $uv_1_v, $uv_2_u, $uv_2_v, $bone_1_id, $bone_1_weight, $bone_2_id, $bone_2_weight, $bone_3_id, $bone_3_weight, $bone_4_id, $bone_4_weight, $bone_5_id, $bone_5_weight, $bone_6_id, $bone_6_weight, $bone_7_id, $bone_7_weight, $bone_8_id, $bone_8_weight, $uv_3_u, $uv_3_v);";
2403+
values ($mesh, $part, $vertex_id, $position_x, $position_y, $position_z, $normal_x, $normal_y, $normal_z, $binormal_x, $binormal_y, $binormal_z, $tangent_x, $tangent_y, $tangent_z, $color_r, $color_g, $color_b, $color_a, $color2_r, $color2_g, $color2_b, $color2_a, $uv_1_u, $uv_1_v, $uv_2_u, $uv_2_v, $bone_1_id, $bone_1_weight, $bone_2_id, $bone_2_weight, $bone_3_id, $bone_3_weight, $bone_4_id, $bone_4_weight, $bone_5_id, $bone_5_weight, $bone_6_id, $bone_6_weight, $bone_7_id, $bone_7_weight, $bone_8_id, $bone_8_weight, $uv_3_u, $uv_3_v);";
24042404
using (var cmd = new SQLiteCommand(query, db))
24052405
{
24062406
cmd.Parameters.AddWithValue("part", partIdx);

xivModdingFramework/Models/FileTypes/Mdl.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,40 @@ public static XivMdl GetXivMdl(byte[] mdlData, string mdlPath = "")
11301130
}
11311131

11321132

1133+
internal static List<Vector4> ReadBoundingBox(BinaryReader br)
1134+
{
1135+
var ret = new List<Vector4>();
1136+
1137+
ret.Add(new Vector4(
1138+
br.ReadSingle(),
1139+
br.ReadSingle(),
1140+
br.ReadSingle(),
1141+
br.ReadSingle()
1142+
));
1143+
1144+
ret.Add(new Vector4(
1145+
br.ReadSingle(),
1146+
br.ReadSingle(),
1147+
br.ReadSingle(),
1148+
br.ReadSingle()
1149+
));
1150+
1151+
return ret;
1152+
}
1153+
internal static void WriteBoundingBox(BinaryWriter bw, List<Vector4> bb)
1154+
{
1155+
bw.Write(BitConverter.GetBytes(bb[0][0]));
1156+
bw.Write(BitConverter.GetBytes(bb[0][1]));
1157+
bw.Write(BitConverter.GetBytes(bb[0][2]));
1158+
bw.Write(BitConverter.GetBytes(bb[0][3]));
1159+
1160+
bw.Write(BitConverter.GetBytes(bb[1][0]));
1161+
bw.Write(BitConverter.GetBytes(bb[1][1]));
1162+
bw.Write(BitConverter.GetBytes(bb[1][2]));
1163+
bw.Write(BitConverter.GetBytes(bb[1][3]));
1164+
}
1165+
1166+
11331167
/// <summary>
11341168
/// Extracts and calculates the full MTRL paths from a given MDL file.
11351169
/// A material variant of -1 gets the materials for ALL variants,

xivModdingFramework/Mods/EndwalkerUpgrade.cs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,13 +421,57 @@ private static bool FastMdlv6Upgrade(BinaryReader br, BinaryWriter bw, long offs
421421
idx++;
422422
}
423423

424-
var end = bonesetStart + boneSetSize;
424+
// Net size of old bone sets
425+
var end = bonesetStart + (((64 * 2) + 4) * mdlData.BoneSetCount);
425426
while(bw.BaseStream.Position < end)
426427
{
427428
// Fill out the remainder of the block with 0s.
428429
bw.Write((byte)0);
429430
}
430431

432+
var endOfBoneSet = bw.BaseStream.Position;
433+
434+
// Shape Data is next.
435+
var shpCount = mdlData.ShapeCount;
436+
var shpParts = mdlData.ShapePartCount;
437+
var shpIndices = mdlData.ShapeDataCount;
438+
439+
var endOfShapeHeaders = endOfBoneSet + (shpCount * 16);
440+
var endOfShapePartHeaders = endOfShapeHeaders + (shpParts * 12);
441+
var endOfShapeIndices = endOfShapePartHeaders + (shpIndices * 4);
442+
443+
// Part Bone Sets
444+
br.BaseStream.Seek(endOfShapeIndices, SeekOrigin.Begin);
445+
var partBoneSets = br.ReadInt32();
446+
var endOfPartBones = br.BaseStream.Position + (partBoneSets);
447+
448+
// Padding
449+
br.BaseStream.Seek(endOfPartBones, SeekOrigin.Begin);
450+
var padding = br.ReadByte();
451+
br.BaseStream.Seek(br.BaseStream.Position + padding, SeekOrigin.Begin);
452+
453+
// Bounding Boxes
454+
var baseBox = Mdl.ReadBoundingBox(br);
455+
var mdlBox = Mdl.ReadBoundingBox(br);
456+
var waterBox = Mdl.ReadBoundingBox(br);
457+
var shadowBox = Mdl.ReadBoundingBox(br);
458+
459+
const float _Divisor = 20.0f;
460+
var min = -1 * (mdlData.Radius / _Divisor);
461+
var max = (mdlData.Radius / _Divisor);
462+
var bb = new List<Vector4>()
463+
{
464+
new Vector4(min, min, min, 1.0f),
465+
new Vector4(max, max, max, 1.0f),
466+
};
467+
468+
// Write new bone bounding boxes.
469+
bw.BaseStream.Seek(br.BaseStream.Position, SeekOrigin.Begin);
470+
for(int i = 0; i < mdlData.BoneCount; i++)
471+
{
472+
Mdl.WriteBoundingBox(bw, bb);
473+
}
474+
431475
return true;
432476
}
433477

0 commit comments

Comments
 (0)