From 64748790cc877f613833a3de9f366e2e21168d9d Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Thu, 30 Jan 2025 14:06:39 +0100 Subject: [PATCH] Make limits a bit cleaner. --- Penumbra/Import/Models/Import/ModelImporter.cs | 14 ++++++++------ Penumbra/UI/AdvancedWindow/ModEditWindow.Models.cs | 3 ++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Penumbra/Import/Models/Import/ModelImporter.cs b/Penumbra/Import/Models/Import/ModelImporter.cs index 5367e892..502d060a 100644 --- a/Penumbra/Import/Models/Import/ModelImporter.cs +++ b/Penumbra/Import/Models/Import/ModelImporter.cs @@ -8,6 +8,9 @@ namespace Penumbra.Import.Models.Import; 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) { var importer = new ModelImporter(model, notifier); @@ -208,10 +211,9 @@ public partial class ModelImporter(ModelRoot model, IoNotifier notifier) if (index >= 0) 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. var count = _materials.Count; - if (count >= 10) + if (count >= MaterialLimit) return 0; _materials.Add(materialName); @@ -234,11 +236,11 @@ public partial class ModelImporter(ModelRoot model, IoNotifier notifier) boneIndices.Add((ushort)boneIndex); } - if (boneIndices.Count > 128) - throw notifier.Exception("XIV does not support meshes weighted to a total of more than 128 bones."); + if (boneIndices.Count > BoneLimit) + throw notifier.Exception($"XIV does not support meshes weighted to a total of more than {BoneLimit} bones."); - var boneIndicesArray = new ushort[128]; - Array.Copy(boneIndices.ToArray(), boneIndicesArray, boneIndices.Count); + var boneIndicesArray = new ushort[BoneLimit]; + boneIndices.CopyTo(boneIndicesArray); var boneTableIndex = _boneTables.Count; _boneTables.Add(new BoneTableStruct() diff --git a/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.cs b/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.cs index bbf3dd00..8fbe5a68 100644 --- a/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.cs +++ b/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.cs @@ -9,6 +9,7 @@ using OtterGui.Widgets; using Penumbra.GameData; using Penumbra.GameData.Files; using Penumbra.Import.Models; +using Penumbra.Import.Models.Import; using Penumbra.String.Classes; using Penumbra.UI.Classes; @@ -16,7 +17,7 @@ namespace Penumbra.UI.AdvancedWindow; public partial class ModEditWindow { - private const int MdlMaterialMaximum = 10; + private const int MdlMaterialMaximum = ModelImporter.MaterialLimit; private const string MdlImportDocumentation = @"https://github.com/xivdev/Penumbra/wiki/Model-IO#user-content-9b49d296-23ab-410a-845b-a3be769b71ea";