calculate the bone ref transforms using the current mesh rather than the reference mesh

This commit is contained in:
Mamadou Babaei
2024-11-25 08:44:51 +01:00
parent a90fd774b8
commit 9b2bdfc80c
2 changed files with 32 additions and 38 deletions
+10
View File
@@ -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.
@@ -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<USkeletalMesh>& 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<FTransform> 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<FTransform> 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(