From 528a451838963498318931ec6a32311db7b576dc Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Fri, 24 Feb 2023 00:09:19 +0100 Subject: [PATCH] try a component transform --- .../SGVirtualHandAnimInstanceProxy.cpp | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/Source/SenseGlove/Private/SenseGlove/Animation/SGVirtualHandAnimInstanceProxy.cpp b/Source/SenseGlove/Private/SenseGlove/Animation/SGVirtualHandAnimInstanceProxy.cpp index 3f24fd28..8eecff17 100644 --- a/Source/SenseGlove/Private/SenseGlove/Animation/SGVirtualHandAnimInstanceProxy.cpp +++ b/Source/SenseGlove/Private/SenseGlove/Animation/SGVirtualHandAnimInstanceProxy.cpp @@ -151,7 +151,7 @@ void FSGVirtualHandAnimInstanceProxy::PreEvaluateAnimation(UAnimInstance* InAnim continue; } - FRotator JointRotation = FingerJointRotations[JointIndex]; + FRotator JointRotation{FingerJointRotations[JointIndex]}; FName BoneName(Hand->IsRight() ? GetRightHandBoneName(FingerIndex, JointIndex) @@ -164,7 +164,7 @@ void FSGVirtualHandAnimInstanceProxy::PreEvaluateAnimation(UAnimInstance* InAnim bool FSGVirtualHandAnimInstanceProxy::Evaluate(FPoseContext& Output) { - const USkeletalMeshComponent* HandMeshComponent = GetSkelMeshComponent(); + USkeletalMeshComponent* HandMeshComponent = GetSkelMeshComponent(); if (!IsValid(HandMeshComponent)) { return FAnimInstanceProxy::Evaluate(Output); @@ -196,15 +196,18 @@ bool FSGVirtualHandAnimInstanceProxy::Evaluate(FPoseContext& Output) FName BoneName(Bone.Key); FRotator BoneRotation(Bone.Value); + const int32 BoneIndex = GetRequiredBones().GetPoseBoneIndexForBoneName(BoneName); + ensureAlwaysMsgf(BoneIndex != INDEX_NONE, TEXT("Invalid BoneIndex!")); + FBoneReference BoneReference; - BoneReference.BoneName = BoneName; - BoneReference.BoneIndex = GetRequiredBones().GetPoseBoneIndexForBoneName(BoneName); + BoneReference.BoneName = MoveTemp(BoneName); + BoneReference.BoneIndex = BoneIndex; BoneReference.bUseSkeletonIndex = true; FAnimNode_ModifyBone BoneController; BoneController.BoneToModify = MoveTemp(BoneReference); BoneController.RotationMode = EBoneModificationMode::BMM_Replace; - BoneController.RotationSpace = EBoneControlSpace::BCS_WorldSpace; + BoneController.RotationSpace = EBoneControlSpace::BCS_ComponentSpace; BoneController.Rotation = MoveTemp(BoneRotation); if (BoneController.IsValidToEvaluate(HandSkeleton, PoseContext.Pose.GetPose().GetBoneContainer())) @@ -212,9 +215,20 @@ bool FSGVirtualHandAnimInstanceProxy::Evaluate(FPoseContext& Output) TArray BoneTransforms; BoneController.EvaluateSkeletalControl_AnyThread(PoseContext, BoneTransforms); - if (BoneTransforms.Num() > 0) + const TArray::SizeType BoneTransformsNum = BoneTransforms.Num(); + if (BoneTransformsNum > 0) { - PoseContext.Pose.LocalBlendCSBoneTransforms(BoneTransforms, 1.0f); + const FCompactPoseBoneIndex PoseBoneIndex{static_cast(BoneIndex)}; + const FTransform BoneTransformBefore{PoseContext.Pose.GetComponentSpaceTransform(PoseBoneIndex)}; + PoseContext.Pose.SetComponentSpaceTransform(PoseBoneIndex, BoneTransforms[0].Transform); + const FTransform BoneTransformAfter{PoseContext.Pose.GetComponentSpaceTransform(PoseBoneIndex)}; + + SGLOG("BoneController.Rotation", BoneController.Rotation); + SGLOG("BoneTransforms[0].Transform.GetRotation()", BoneTransforms[0].Transform.GetRotation().Rotator()); + SGLOG("BoneTransformBefore.Rotation", BoneTransformBefore.Rotator()); + SGLOG("BoneTransformAfter.Rotation", BoneTransformAfter.Rotator()); + + HandMeshComponent->MarkRenderStateDirty(); } } }