Merge element ids and flags

This commit is contained in:
ackwell 2024-01-17 23:13:53 +11:00 committed by Ottermandias
parent 4b81b065aa
commit b089bbca37

View file

@ -1,3 +1,4 @@
using Lumina.Data.Parsing;
using OtterGui; using OtterGui;
using Penumbra.GameData; using Penumbra.GameData;
using Penumbra.GameData.Files; using Penumbra.GameData.Files;
@ -161,6 +162,13 @@ public partial class ModEditWindow
if (ImportKeepAttributes) if (ImportKeepAttributes)
MergeAttributes(newMdl, Mdl); MergeAttributes(newMdl, Mdl);
// Until someone works out how to actually author these, unconditionally merge element ids.
MergeElementIds(newMdl, Mdl);
// TODO: Add flag editing.
newMdl.Flags1 = Mdl.Flags1;
newMdl.Flags2 = Mdl.Flags2;
Initialize(newMdl); Initialize(newMdl);
_dirty = true; _dirty = true;
} }
@ -210,6 +218,29 @@ public partial class ModEditWindow
} }
} }
/// <summary> Merge element ids from the source onto the target. </summary>
/// <param name="target"> Model that will be updated. ></param>
/// <param name="source"> Model to copy element ids from. </param>
private static void MergeElementIds(MdlFile target, MdlFile source)
{
var elementIds = new List<MdlStructs.ElementIdStruct>();
foreach (var sourceElement in source.ElementIds)
{
var sourceBone = source.Bones[sourceElement.ParentBoneName];
var targetIndex = target.Bones.IndexOf(sourceBone);
// Given that there's no means of authoring these at the moment, this should probably remain a hard error.
if (targetIndex == -1)
throw new Exception($"Failed to merge element IDs. Original model contains element IDs targeting bone {sourceBone}, which is not present on the imported model.");
elementIds.Add(sourceElement with
{
ParentBoneName = (uint)targetIndex,
});
}
target.ElementIds = [.. elementIds];
}
private void RecordIoExceptions(Exception? exception) private void RecordIoExceptions(Exception? exception)
{ {
IoExceptions = exception switch { IoExceptions = exception switch {