dump some animation errors to the logs inside the editor instead of crashing

This commit is contained in:
Mamadou Babaei
2023-03-28 10:37:51 +02:00
parent 685a200577
commit 5f95972a05
2 changed files with 20 additions and 9 deletions
@@ -43,6 +43,7 @@
#include "Containers/UnrealString.h"
#include "Engine/SkeletalMesh.h"
#include "Math/Rotator.h"
#include "SGLog/SGLog.h"
#include "SenseGlove/Components/SGVirtualHandComponent.h"
@@ -71,24 +72,25 @@ void FSGVirtualHandAnimInstanceProxy::PreEvaluateAnimation(UAnimInstance* InAnim
return;
}
BonesRotations.Empty();
if (!VirtualHand->IsGloveConnected())
{
return;
}
BonesRotations.Empty();
BonesRotations = VirtualHand->GetFingersBonesRotations();
}
bool FSGVirtualHandAnimInstanceProxy::Evaluate(FPoseContext& Output)
{
USkeletalMeshComponent* HandMeshComponent{GetSkelMeshComponent()};
if (!IsValid(HandMeshComponent))
USGVirtualHandComponent* VirtualHand{Cast<USGVirtualHandComponent>(GetSkelMeshComponent())};
if (!IsValid(VirtualHand) && !VirtualHand->IsGloveConnected())
{
return FAnimInstanceProxy::Evaluate(Output);
}
const USkeletalMesh* HandMesh{HandMeshComponent->
const USkeletalMesh* HandMesh{VirtualHand->
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1
GetSkeletalMeshAsset()
#else
@@ -115,7 +117,12 @@ bool FSGVirtualHandAnimInstanceProxy::Evaluate(FPoseContext& Output)
FRotator BoneRotation(Bone.Value);
const int32 BoneIndex = GetRequiredBones().GetPoseBoneIndexForBoneName(BoneName);
ensureAlwaysMsgf(BoneIndex != INDEX_NONE, TEXT("Invalid finger bone index!"));
if (BoneIndex == INDEX_NONE)
{
SGLOG_WARNING(FString::Printf(TEXT("Could not find a bone index for '%s' finger bone!"),
*BoneName.ToString()));
continue;
}
FBoneReference BoneReference;
BoneReference.BoneName = MoveTemp(BoneName);
@@ -141,7 +148,7 @@ bool FSGVirtualHandAnimInstanceProxy::Evaluate(FPoseContext& Output)
PoseContext.Pose.LocalBlendCSBoneTransforms(BoneTransforms, 1.0f);
PoseContext.Pose.ConvertComponentPosesToLocalPoses(PoseContext.Pose, Output.Pose);
HandMeshComponent->MarkRenderStateDirty();
VirtualHand->MarkRenderStateDirty();
}
}
}
@@ -318,8 +318,12 @@ const FTransform& USGVirtualHandComponent::GetFingerBoneRefTransform(const int32
const FReferenceSkeleton& ReferenceSkeleton{Pimpl->GetRefSkeleton()};
const int32 BoneIndex = ReferenceSkeleton.FindBoneIndex(BoneName);
ensureAlwaysMsgf(BoneIndex != INDEX_NONE, TEXT("Invalid virtual hand bone name '%s' or index!"),
*BoneName.ToString());
if (BoneIndex == INDEX_NONE)
{
SGLOG_WARNING(FString::Printf(TEXT("Could not find a bone index for '%s' finger bone!"),
*BoneName.ToString()));
return FTransform::Identity;
}
const FTransform& BoneTransform{ReferenceSkeleton.GetRefBonePose()[BoneIndex]};
return BoneTransform;
@@ -491,7 +495,7 @@ bool USGVirtualHandComponent::FImpl::CheckGlove() const
if (!bFoundGlove && bGloveWasPresent)
{
SGLOG_ERROR(FString::Printf(TEXT("Could not find a %s glove"),
SGLOG_ERROR(FString::Printf(TEXT("Could not find a %s glove!"),
(Owner->bRight ? TEXT("right-handed") : TEXT("left-handed"))));
}