mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
Merge element ids and flags
This commit is contained in:
parent
4b81b065aa
commit
b089bbca37
1 changed files with 31 additions and 0 deletions
|
|
@ -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 {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue