1
0
mirror of synced 2025-02-25 22:38:07 +01:00

BFRES : Some fixes to skeleton searching for external files

This commit is contained in:
KillzXGaming 2023-06-29 20:50:17 -04:00
parent 765c09c8f1
commit d7a161200d

View File

@ -211,36 +211,13 @@ namespace Bfres.Structs
private STSkeleton GetActiveSkeleton() private STSkeleton GetActiveSkeleton()
{ {
var viewport = LibraryGUI.GetActiveViewport();
if (viewport != null)
{
foreach (var drawable in viewport.scene.objects)
{
if (drawable is STSkeleton)
{
bool areAllBonesPresent = ((STSkeleton)drawable).bones.Count > 0;
foreach (var bone in Bones)
{
var animBone = ((STSkeleton)drawable).GetBone(bone.Text);
if (animBone == null)
areAllBonesPresent = false;
}
if (areAllBonesPresent)
return ((STSkeleton)drawable);
}
}
}
if (Parent == null) if (Parent == null)
return null; return null;
//Check parent renderer and find skeleton //Check parent renderer and find skeleton
var render = ((BFRES)Parent.Parent.Parent).BFRESRender; var render = ((BFRES)Parent.Parent.Parent).BFRESRender;
if (render == null) if (render != null)
return null; {
//Return individual skeleton for single model files //Return individual skeleton for single model files
if (render.models.Count == 1) if (render.models.Count == 1)
return render.models[0].Skeleton; return render.models[0].Skeleton;
@ -248,13 +225,33 @@ namespace Bfres.Structs
//Search multiple FMDL to find matching bones //Search multiple FMDL to find matching bones
foreach (var model in render.models) foreach (var model in render.models)
{ {
//Check if all the bones in the animation are present in the skeleton
bool areAllBonesPresent = model.Skeleton.bones.Count > 0;
foreach (var bone in Bones) foreach (var bone in Bones)
{ {
var animBone = model.Skeleton.GetBone(bone.Text); var animBone = model.Skeleton.GetBone(bone.Text);
if (animBone != null) if (animBone == null)
areAllBonesPresent = false;
}
if (areAllBonesPresent)
return model.Skeleton; return model.Skeleton;
} }
//If not all bones were present but models are present, use first model
if (render.models.Count > 0)
return render.models[0].Skeleton;
}
//Search by viewport active model in the event the animation is externally loaded
var viewport = LibraryGUI.GetActiveViewport();
if (viewport != null)
{
foreach (var drawable in viewport.scene.objects)
{
if (drawable is STSkeleton)
return ((STSkeleton)drawable);
}
} }
return null; return null;