Skip to content

Commit ba2b0e5

Browse files
committed
- Ensure shape data is properly updated after model modifiers are applied.
- Ensure shape data is properly updated after switching model between import and export ready modes. - Throw an error if the model has too many total vertices due to shape data inclusions.
1 parent d00a7f5 commit ba2b0e5

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

xivModdingFramework/Models/FileTypes/Mdl.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3071,6 +3071,10 @@ internal async Task<byte[]> MakeNewMdlFile(TTModel ttModel, XivMdl ogMdl, Action
30713071
var meshNum = p.MeshId;
30723072
foreach (var r in p.IndexReplacements)
30733073
{
3074+
if(r.Value > ushort.MaxValue)
3075+
{
3076+
throw new InvalidDataException("Mesh Group " + meshNum + " has too many total vertices/triangle indices.\nRemove some vertices/faces/shapes or split them across multiple mesh groups.");
3077+
}
30743078
meshShapeDataBlock.AddRange(BitConverter.GetBytes((ushort)r.Key));
30753079
meshShapeDataBlock.AddRange(BitConverter.GetBytes((ushort)r.Value));
30763080
}

xivModdingFramework/Models/Helpers/ModelModifiers.cs

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,9 @@ public void Apply(TTModel ttModel, XivMdl currentMdl = null, XivMdl originalMdl
134134
}
135135
ModelModifiers.ClearShapeData(ttModel, loggingFunction);
136136
ModelModifiers.MergeShapeData(ttModel, originalMdl, loggingFunction);
137-
138-
// Let's at least update the base shape data to match our base model.
139-
ttModel.UpdateShapeData();
140137
}
141138

142-
if(AutoScale)
139+
if (AutoScale)
143140
{
144141
if (originalMdl == null)
145142
{
@@ -149,6 +146,9 @@ public void Apply(TTModel ttModel, XivMdl currentMdl = null, XivMdl originalMdl
149146
var oldModel = TTModel.FromRaw(originalMdl);
150147
ModelModifiers.AutoScaleModel(ttModel, oldModel, 0.3, loggingFunction);
151148
}
149+
150+
// Ensure shape data is updated with our various changes.
151+
ttModel.UpdateShapeData();
152152
}
153153
}
154154

@@ -1325,22 +1325,14 @@ public static void MakeImportReady(TTModel model, Action<bool, string> loggingFu
13251325
{
13261326
loggingFunction(true, "Group: " + mIdx + " Part: " + pIdx + " :: " + perPartMajorCorrections.ToString() + " Vertices had major corrections made to their weight data.");
13271327
}
1328-
1329-
foreach(var shpKv in p.ShapeParts)
1330-
{
1331-
foreach(var v in shpKv.Value.Vertices)
1332-
{
1333-
v.UV1[1] *= -1;
1334-
v.UV2[1] *= -1;
1335-
}
1336-
}
1337-
13381328
pIdx++;
13391329
}
13401330
mIdx++;
13411331
}
13421332

13431333

1334+
// Update the base shape data to match our base model.
1335+
model.UpdateShapeData();
13441336
}
13451337

13461338
/// <summary>
@@ -1365,16 +1357,11 @@ public static void MakeExportReady(TTModel model, Action<bool, string> loggingFu
13651357
v.UV1[1] *= -1;
13661358
v.UV2[1] *= -1;
13671359
}
1368-
foreach (var shpKv in p.ShapeParts)
1369-
{
1370-
foreach (var v in shpKv.Value.Vertices)
1371-
{
1372-
v.UV1[1] *= -1;
1373-
v.UV2[1] *= -1;
1374-
}
1375-
}
13761360
}
13771361
}
1362+
1363+
// Update the base shape data to match our base model.
1364+
model.UpdateShapeData();
13781365
}
13791366

13801367
/// <summary>

0 commit comments

Comments
 (0)