From e5c11adec353ed79f526ebe60f29f287ebdc7dd9 Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Mon, 25 Nov 2024 08:44:08 +0100 Subject: [PATCH] calculate the bone ref transforms using the current mesh rather than the reference mesh --- Handbook/src/appendix/changelog.md | 10 ++++ .../Private/SGEditor/SGAssetUtils.cpp | 60 +++++++------------ 2 files changed, 32 insertions(+), 38 deletions(-) diff --git a/Handbook/src/appendix/changelog.md b/Handbook/src/appendix/changelog.md index c9a5d51a..22452c5f 100644 --- a/Handbook/src/appendix/changelog.md +++ b/Handbook/src/appendix/changelog.md @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Fixed + +- Additional minor fixes and improvements that may not be listed here. + +### Changed + +- The SenseGlove Sockets Editor now calculates hand bone reference transforms using the current virtual hand mesh being edited, rather than the reference mesh, when adding SenseGlove sockets. + ## [2.3.0] - 2024-11-13 This minor release includes some improvements and adds official Unreal Engine `5.5` Fab support. diff --git a/Source/SenseGloveEditor/Private/SGEditor/SGAssetUtils.cpp b/Source/SenseGloveEditor/Private/SGEditor/SGAssetUtils.cpp index 5fb5989f..11a3aa3e 100644 --- a/Source/SenseGloveEditor/Private/SGEditor/SGAssetUtils.cpp +++ b/Source/SenseGloveEditor/Private/SGEditor/SGAssetUtils.cpp @@ -99,7 +99,7 @@ struct FSGAssetUtils::FImpl static bool IsLeftHandMesh(const ISkeletalMeshEditor* SkeletalMeshEditor, const USkeletalMesh* SkeletalMesh); static bool IsRightHandMesh(const ISkeletalMeshEditor* SkeletalMeshEditor, const USkeletalMesh* SkeletalMesh); - static FTransform GetHandBoneBoneRefTransform(bool bRight, const FName& BoneName); + static FTransform GetHandBoneRefTransform(const USkeletalMesh* SkeletalMesh, const FName& BoneName); static bool AddSocket( const ISkeletalMeshEditor* SkeletalMeshEditor, USkeletalMesh* SkeletalMesh, @@ -310,48 +310,32 @@ bool FSGAssetUtils::FImpl::IsRightHandMesh( return true; } -FTransform FSGAssetUtils::FImpl::GetHandBoneBoneRefTransform(const bool bRight, const FName& BoneName) +FTransform FSGAssetUtils::FImpl::GetHandBoneRefTransform( + const USkeletalMesh* SkeletalMesh, const FName& BoneName) { - const FSGVirtualHandMeshSettings& MeshSettings{GetVirtualHandSettings().MeshSettings}; - - const TSoftObjectPtr& HandMesh{ - bRight - ? MeshSettings.LeftHandReferenceMesh - : MeshSettings.RightHandReferenceMesh - }; - - if (HandMesh.IsValid()) + if (!ensureAlwaysMsgf(IsValid(SkeletalMesh), TEXT("Invalid SkeletalMesh"))) { - const FReferenceSkeleton& ReferenceSkeleton{HandMesh->GetRefSkeleton()}; - const int32 BoneIndex = ReferenceSkeleton.FindBoneIndex(BoneName); - - if (BoneIndex == INDEX_NONE) - { - SGLOG_WARNING(FString::Printf(TEXT("Could not find a bone index for the '%s' joint!"), - *BoneName.ToString())); - } - - const TArray Transforms{ReferenceSkeleton.GetRefBonePose()}; - ensureAlwaysMsgf(Transforms.Num() > 0 && Transforms.Num() > BoneIndex, - TEXT("Invalid bone index '%d' or no transforms found!"), BoneIndex); - - const FTransform& Transform{Transforms[BoneIndex]}; - return Transform; + return FTransform::Identity; } - ensureAlwaysMsgf( - bRight - ? MeshSettings.RightHandDefaultReferenceBoneTransforms.Contains(BoneName) - : MeshSettings.LeftHandDefaultReferenceBoneTransforms.Contains(BoneName), - TEXT("Invalid bone name '%s'!"), *BoneName.ToString()); + const FReferenceSkeleton& ReferenceSkeleton{SkeletalMesh->GetRefSkeleton()}; + const int32 BoneIndex = ReferenceSkeleton.FindBoneIndex(BoneName); - const FTransform& Transform{ - bRight - ? MeshSettings.RightHandDefaultReferenceBoneTransforms[BoneName] - : MeshSettings.LeftHandDefaultReferenceBoneTransforms[BoneName] - }; + if (BoneIndex == INDEX_NONE) + { + SGLOG_WARNING(FString::Printf(TEXT("Could not find a bone index for the '%s' joint!"), + *BoneName.ToString())); + } + + const TArray Transforms{ReferenceSkeleton.GetRefBonePose()}; + if (!ensureAlwaysMsgf(Transforms.Num() > 0 && Transforms.Num() > BoneIndex, + TEXT("Invalid bone index '%d' or no transforms found!"), BoneIndex)) + { + return FTransform::Identity; + } + + const FTransform& Transform{Transforms[BoneIndex]}; return Transform; - } bool FSGAssetUtils::FImpl::AddSocket( @@ -468,7 +452,7 @@ bool FSGAssetUtils::FImpl::AddFingertipColliderSocket( }; FTransform SocketTransform{ - GetHandBoneBoneRefTransform(bRight, BoneName) + GetHandBoneRefTransform(SkeletalMesh, BoneName) }; const bool bAddedSocket = AddSocket(