Make limits a bit cleaner.

This commit is contained in:
Ottermandias 2025-01-30 14:06:39 +01:00
parent b0a8b1baa5
commit 64748790cc
2 changed files with 10 additions and 7 deletions

View file

@ -8,6 +8,9 @@ namespace Penumbra.Import.Models.Import;
public partial class ModelImporter(ModelRoot model, IoNotifier notifier) public partial class ModelImporter(ModelRoot model, IoNotifier notifier)
{ {
public const int BoneLimit = 128;
public const int MaterialLimit = 10;
public static MdlFile Import(ModelRoot model, IoNotifier notifier) public static MdlFile Import(ModelRoot model, IoNotifier notifier)
{ {
var importer = new ModelImporter(model, notifier); var importer = new ModelImporter(model, notifier);
@ -208,10 +211,9 @@ public partial class ModelImporter(ModelRoot model, IoNotifier notifier)
if (index >= 0) if (index >= 0)
return (ushort)index; return (ushort)index;
// If there's already 10 materials, we can't add any more.
// TODO: permit, with a warning to reduce, and validation in MdlTab. // TODO: permit, with a warning to reduce, and validation in MdlTab.
var count = _materials.Count; var count = _materials.Count;
if (count >= 10) if (count >= MaterialLimit)
return 0; return 0;
_materials.Add(materialName); _materials.Add(materialName);
@ -234,11 +236,11 @@ public partial class ModelImporter(ModelRoot model, IoNotifier notifier)
boneIndices.Add((ushort)boneIndex); boneIndices.Add((ushort)boneIndex);
} }
if (boneIndices.Count > 128) if (boneIndices.Count > BoneLimit)
throw notifier.Exception("XIV does not support meshes weighted to a total of more than 128 bones."); throw notifier.Exception($"XIV does not support meshes weighted to a total of more than {BoneLimit} bones.");
var boneIndicesArray = new ushort[128]; var boneIndicesArray = new ushort[BoneLimit];
Array.Copy(boneIndices.ToArray(), boneIndicesArray, boneIndices.Count); boneIndices.CopyTo(boneIndicesArray);
var boneTableIndex = _boneTables.Count; var boneTableIndex = _boneTables.Count;
_boneTables.Add(new BoneTableStruct() _boneTables.Add(new BoneTableStruct()

View file

@ -9,6 +9,7 @@ using OtterGui.Widgets;
using Penumbra.GameData; using Penumbra.GameData;
using Penumbra.GameData.Files; using Penumbra.GameData.Files;
using Penumbra.Import.Models; using Penumbra.Import.Models;
using Penumbra.Import.Models.Import;
using Penumbra.String.Classes; using Penumbra.String.Classes;
using Penumbra.UI.Classes; using Penumbra.UI.Classes;
@ -16,7 +17,7 @@ namespace Penumbra.UI.AdvancedWindow;
public partial class ModEditWindow public partial class ModEditWindow
{ {
private const int MdlMaterialMaximum = 10; private const int MdlMaterialMaximum = ModelImporter.MaterialLimit;
private const string MdlImportDocumentation = private const string MdlImportDocumentation =
@"https://github.com/xivdev/Penumbra/wiki/Model-IO#user-content-9b49d296-23ab-410a-845b-a3be769b71ea"; @"https://github.com/xivdev/Penumbra/wiki/Model-IO#user-content-9b49d296-23ab-410a-845b-a3be769b71ea";