Prevent import of models with too many shape values

This commit is contained in:
ackwell 2024-01-10 00:03:32 +11:00
parent c3ba8a2231
commit ec114b3f6a
2 changed files with 11 additions and 3 deletions

View file

@ -4,7 +4,7 @@ using SharpGLTF.Schema2;
namespace Penumbra.Import.Models.Import;
public partial class ModelImporter(ModelRoot _model)
public partial class ModelImporter(ModelRoot model)
{
public static MdlFile Import(ModelRoot model)
{
@ -99,7 +99,7 @@ public partial class ModelImporter(ModelRoot _model)
/// <summary> Returns an iterator over sorted, grouped mesh nodes. </summary>
private IEnumerable<IEnumerable<Node>> GroupedMeshNodes()
=> _model.LogicalNodes
=> model.LogicalNodes
.Where(node => node.Mesh != null)
.Select(node =>
{
@ -171,6 +171,14 @@ public partial class ModelImporter(ModelRoot _model)
_shapeValues.AddRange(meshShapeKey.ShapeValues);
}
// The number of shape values in a model is bounded by the count
// value, which is stored as a u16.
// While technically there are similar bounds on other shape struct
// arrays, values is practically guaranteed to be the highest of the
// group, so a failure on any of them will be a failure on it.
if (_shapeValues.Count > ushort.MaxValue)
throw new Exception($"Importing this file would require more than the maximum of {ushort.MaxValue} shape values.\nTry removing or applying shape keys that do not need to be changed at runtime in-game.");
}
private ushort BuildBoneTable(List<string> boneNames)

View file

@ -138,7 +138,7 @@ public partial class ModEditWindow
var spaceAvail = ImGui.GetContentRegionAvail().X - ImGui.GetStyle().ItemSpacing.X - 100;
foreach (var exception in tab.IoExceptions)
{
var message = $"{exception.GetType().Name}: {exception.Message} {exception.Message}";
var message = $"{exception.GetType().Name}: {exception.Message}";
var textSize = ImGui.CalcTextSize(message).X;
if (textSize > spaceAvail)
message = message.Substring(0, (int)Math.Floor(message.Length * (spaceAvail / textSize))) + "...";