Always rebuild armatures on skeleton updates instead of trying to augment them
This commit is contained in:
@@ -162,26 +162,21 @@ public unsafe class Armature
|
||||
: $"Armature (#{_localId}) on {ActorIdentifier.IncognitoDebug()} ({Profile}) with no skeleton reference";
|
||||
}
|
||||
|
||||
public bool NewBonesAvailable(CharacterBase* cBase)
|
||||
public bool IsSkeletonUpdated(CharacterBase* cBase)
|
||||
{
|
||||
if (cBase == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (cBase->Skeleton->PartialSkeletonCount > _partialSkeletons.Length)
|
||||
{
|
||||
else if (cBase->Skeleton->PartialSkeletonCount != _partialSkeletons.Length)
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (var i = 0; i < cBase->Skeleton->PartialSkeletonCount; ++i)
|
||||
{
|
||||
var newPose = cBase->Skeleton->PartialSkeletons[i].GetHavokPose(Constants.TruePoseIndex);
|
||||
|
||||
if (newPose != null
|
||||
&& newPose->Skeleton->Bones.Length > _partialSkeletons[i].Length)
|
||||
{
|
||||
&& newPose->Skeleton->Bones.Length != _partialSkeletons[i].Length)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,43 +200,6 @@ public unsafe class Armature
|
||||
Plugin.Logger.Debug($"Rebuilt {this}");
|
||||
}
|
||||
|
||||
public void AugmentSkeleton(CharacterBase* cBase)
|
||||
{
|
||||
if (cBase == null)
|
||||
return;
|
||||
|
||||
var oldPartials = _partialSkeletons.Select(x => x.ToList()).ToList();
|
||||
var newPartials = ParseBonesFromObject(this, cBase);
|
||||
|
||||
//for each of the new partial skeletons discovered...
|
||||
for (var i = 0; i < newPartials.Count; ++i)
|
||||
{
|
||||
//if the old skeleton doesn't contain the new partial at all, add the whole thing
|
||||
if (i > oldPartials.Count)
|
||||
{
|
||||
oldPartials.Add(newPartials[i]);
|
||||
}
|
||||
//otherwise, add every model bone the new partial has that the old one doesn't
|
||||
else
|
||||
{
|
||||
//Case: get carbuncle, enable profile for it, turn carbuncle into human via glamourer
|
||||
if (oldPartials.Count <= i)
|
||||
oldPartials.Add(new List<ModelBone>());
|
||||
|
||||
for (var j = oldPartials[i].Count; j < newPartials[i].Count; ++j)
|
||||
{
|
||||
oldPartials[i].Add(newPartials[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_partialSkeletons = oldPartials.Select(x => x.ToArray()).ToArray();
|
||||
|
||||
RebuildBoneTemplateBinding(); //todo: intentionally not calling ArmatureChanged.Type.Updated because this is pending rewrite
|
||||
|
||||
Plugin.Logger.Debug($"Augmented {this} with new bones");
|
||||
}
|
||||
|
||||
public BoneTransform? GetAppliedBoneTransform(string boneName)
|
||||
{
|
||||
if (BoneTemplateBinding.TryGetValue(boneName, out var template)
|
||||
|
||||
@@ -184,7 +184,7 @@ public unsafe sealed class ArmatureManager : IDisposable
|
||||
}
|
||||
|
||||
//Needed because skeleton sometimes appears to be not ready when armature is created
|
||||
//and also because we want to augment armature with new bones if they are available
|
||||
//and also because we want to keep armature up to date with any character skeleton changes
|
||||
TryLinkSkeleton(armature);
|
||||
}
|
||||
}
|
||||
@@ -207,38 +207,22 @@ public unsafe sealed class ArmatureManager : IDisposable
|
||||
/// Returns whether or not a link can be established between the armature and an in-game object.
|
||||
/// If unbuilt, the armature will be rebuilded.
|
||||
/// </summary>
|
||||
private bool TryLinkSkeleton(Armature armature, bool forceRebuild = false)
|
||||
private bool TryLinkSkeleton(Armature armature)
|
||||
{
|
||||
_objectManager.Update();
|
||||
|
||||
try
|
||||
if (!_objectManager.Identifiers.ContainsKey(armature.ActorIdentifier))
|
||||
return false;
|
||||
|
||||
var actor = _objectManager[armature.ActorIdentifier].Objects[0];
|
||||
|
||||
if (!armature.IsBuilt || armature.IsSkeletonUpdated(actor.Model.AsCharacterBase))
|
||||
{
|
||||
if (!_objectManager.Identifiers.ContainsKey(armature.ActorIdentifier))
|
||||
return false;
|
||||
|
||||
var actor = _objectManager[armature.ActorIdentifier].Objects[0];
|
||||
|
||||
if (!armature.IsBuilt || forceRebuild)
|
||||
{
|
||||
armature.RebuildSkeleton(actor.Model.AsCharacterBase);
|
||||
}
|
||||
else if (armature.NewBonesAvailable(actor.Model.AsCharacterBase))
|
||||
{
|
||||
armature.AugmentSkeleton(actor.Model.AsCharacterBase);
|
||||
}
|
||||
|
||||
return true;
|
||||
_logger.Debug($"Skeleton for actor #{actor.AsObject->ObjectIndex} tied to \"{armature}\" has changed");
|
||||
armature.RebuildSkeleton(actor.Model.AsCharacterBase);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// This is on wait until isse #191 on Github responds. Keeping it in code, delete it if I forget and this is longer then a month ago.
|
||||
|
||||
// Disabling this if its any Default Profile due to Log spam. A bit crazy but hey, if its for me id Remove Default profiles all together so this is as much as ill do for now! :)
|
||||
//if(!(Profile.CharacterName.Equals(Constants.DefaultProfileCharacterName) || Profile.CharacterName.Equals("DefaultCutscene"))) {
|
||||
_logger.Error($"Error occured while attempting to link skeleton: {armature}");
|
||||
throw;
|
||||
//}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -213,10 +213,27 @@ public class StateMonitoringTab
|
||||
//ImGui.Text("Profile:");
|
||||
//DrawSingleProfile($"armature-{armature.GetHashCode()}", armature.Profile);
|
||||
|
||||
ImGui.Text($"Bone template bindings:");
|
||||
foreach (var kvPair in armature.BoneTemplateBinding)
|
||||
var bindingsShow = ImGui.CollapsingHeader($"Bone template bindings ({armature.BoneTemplateBinding.Count})###{prefix}-armature-{armature.GetHashCode()}-bindings");
|
||||
|
||||
if (bindingsShow)
|
||||
{
|
||||
ImGui.Text($"{BoneData.GetBoneDisplayName(kvPair.Key)} ({kvPair.Key}) -> {kvPair.Value.Name.Text.Incognify()} ({kvPair.Value.UniqueId})");
|
||||
foreach (var kvPair in armature.BoneTemplateBinding)
|
||||
{
|
||||
ImGui.Text($"{BoneData.GetBoneDisplayName(kvPair.Key)} ({kvPair.Key}) -> {kvPair.Value.Name.Text.Incognify()} ({kvPair.Value.UniqueId})");
|
||||
}
|
||||
}
|
||||
|
||||
var bonesShow = ImGui.CollapsingHeader($"Armature bones###{prefix}-armature-{armature.GetHashCode()}-bones");
|
||||
|
||||
if (!bonesShow)
|
||||
return;
|
||||
|
||||
var bones = armature.GetAllBones().ToList();
|
||||
ImGui.Text($"{bones.Count} bones");
|
||||
|
||||
foreach (var bone in bones)
|
||||
{
|
||||
ImGui.Text($"{(bone.IsActive ? "[A] " : "")}{BoneData.GetBoneDisplayName(bone.BoneName)} [{bone.BoneName}] ({bone.PartialSkeletonIndex}-{bone.BoneIndex})");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user