diff --git a/Source/SenseGlove/Private/SenseGlove/Animation/SGVirtualHandAnimInstanceProxy.cpp b/Source/SenseGlove/Private/SenseGlove/Animation/SGVirtualHandAnimInstanceProxy.cpp index 4324bf10..f64ce44d 100644 --- a/Source/SenseGlove/Private/SenseGlove/Animation/SGVirtualHandAnimInstanceProxy.cpp +++ b/Source/SenseGlove/Private/SenseGlove/Animation/SGVirtualHandAnimInstanceProxy.cpp @@ -44,7 +44,7 @@ #include "Engine/SkeletalMesh.h" #include "Math/Rotator.h" -#include "SenseGlove/GameFramework/SGVirtualHand.h" +#include "SenseGlove/Components/SGVirtualHandComponent.h" FSGVirtualHandAnimInstanceProxy::FSGVirtualHandAnimInstanceProxy() : FAnimInstanceProxy() @@ -65,14 +65,14 @@ void FSGVirtualHandAnimInstanceProxy::PreEvaluateAnimation(UAnimInstance* InAnim return; } - ASGVirtualHand* Hand(Cast(InAnimInstance->GetOwningActor())); - if (!IsValid(Hand)) + USGVirtualHandComponent* VirtualHand{Cast(GetSkelMeshComponent())}; + if (!IsValid(VirtualHand)) { return; } BonesRotations.Empty(); - BonesRotations = Hand->GetFingersBonesRotations(); + BonesRotations = VirtualHand->GetFingersBonesRotations(); } bool FSGVirtualHandAnimInstanceProxy::Evaluate(FPoseContext& Output) diff --git a/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandMeshComponent.cpp b/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandComponent.cpp similarity index 81% rename from Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandMeshComponent.cpp rename to Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandComponent.cpp index ebb4ee56..4be48b43 100644 --- a/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandMeshComponent.cpp +++ b/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandComponent.cpp @@ -33,7 +33,7 @@ */ -#include "SenseGlove/Components/SGVirtualHandMeshComponent.h" +#include "SenseGlove/Components/SGVirtualHandComponent.h" #include "Animation/Skeleton.h" #include "Components/SkeletalMeshComponent.h" @@ -45,7 +45,7 @@ #include "SGCore/SGHapticGlove.h" #include "SGLog/SGLog.h" -struct USGVirtualHandMeshComponent::FImpl +struct USGVirtualHandComponent::FImpl { /************************ * Static methods @@ -83,13 +83,13 @@ struct USGVirtualHandMeshComponent::FImpl * Owner object ************************/ - USGVirtualHandMeshComponent* Owner; + USGVirtualHandComponent* Owner; /************************ * Constructor / Destructor ************************/ - explicit FImpl(USGVirtualHandMeshComponent* InOwner); + explicit FImpl(USGVirtualHandComponent* InOwner); ~FImpl(); /************************ @@ -117,7 +117,7 @@ struct USGVirtualHandMeshComponent::FImpl bool CheckGlove() const; }; -const TArray>& USGVirtualHandMeshComponent::GetLeftHandFingerBoneNames() +const TArray>& USGVirtualHandComponent::GetLeftHandFingerBoneNames() { static const TArray> BoneNames{ {FName(TEXT("thumb_01_l")), FName(TEXT("thumb_02_l")), FName(TEXT("thumb_03_l"))}, @@ -129,7 +129,7 @@ const TArray>& USGVirtualHandMeshComponent::GetLeftHandFingerBoneN return BoneNames; } -const TArray>& USGVirtualHandMeshComponent::GetRightHandFingerBoneNames() +const TArray>& USGVirtualHandComponent::GetRightHandFingerBoneNames() { static const TArray> BoneNames{ {FName(TEXT("thumb_01_r")), FName(TEXT("thumb_02_r")), FName(TEXT("thumb_03_r"))}, @@ -141,7 +141,7 @@ const TArray>& USGVirtualHandMeshComponent::GetRightHandFingerBone return BoneNames; } -const FName& USGVirtualHandMeshComponent::GetLeftHandFingerBoneName(const int32 Finger, const int32 Joint) +const FName& USGVirtualHandComponent::GetLeftHandFingerBoneName(const int32 Finger, const int32 Joint) { const TArray>& BoneNames{GetLeftHandFingerBoneNames()}; @@ -152,7 +152,7 @@ const FName& USGVirtualHandMeshComponent::GetLeftHandFingerBoneName(const int32 return BoneName; } -const FName& USGVirtualHandMeshComponent::GetRightHandFingerBoneName(const int32 Finger, const int32 Joint) +const FName& USGVirtualHandComponent::GetRightHandFingerBoneName(const int32 Finger, const int32 Joint) { const TArray>& BoneNames{GetRightHandFingerBoneNames()}; @@ -163,7 +163,7 @@ const FName& USGVirtualHandMeshComponent::GetRightHandFingerBoneName(const int32 return BoneName; } -USGVirtualHandMeshComponent::USGVirtualHandMeshComponent(const FObjectInitializer& ObjectInitializer) +USGVirtualHandComponent::USGVirtualHandComponent(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer), Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) { @@ -205,7 +205,17 @@ USGVirtualHandMeshComponent::USGVirtualHandMeshComponent(const FObjectInitialize Glove = nullptr; } -void USGVirtualHandMeshComponent::SetAnimClass(UClass* NewClass) +void USGVirtualHandComponent::SetRight(const bool bInRight) +{ + bRight = bInRight; + + if (!Pimpl->IsUsingUserMesh()) + { + Pimpl->SetDefaultMesh(); + } +} + +void USGVirtualHandComponent::SetAnimClass(UClass* NewClass) { ensureAlwaysMsgf(Cast(NewClass), TEXT("The AnimInstance class must be a subclass of USGVirtualHandAnimInstance!")); @@ -213,7 +223,25 @@ void USGVirtualHandMeshComponent::SetAnimClass(UClass* NewClass) Super::SetAnimClass(NewClass); } -void USGVirtualHandMeshComponent::InitializeComponent() +#if WITH_EDITOR +void USGVirtualHandComponent::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) +{ + Super::PostEditChangeProperty(PropertyChangedEvent); + + const FName PropertyName{PropertyChangedEvent.Property + ? PropertyChangedEvent.Property->GetFName() + : NAME_None}; + if (PropertyName == GET_MEMBER_NAME_CHECKED(USGVirtualHandComponent, bRight)) + { + if (!Pimpl->IsUsingUserMesh()) + { + Pimpl->SetDefaultMesh(); + } + } +} +#endif /* WITH_EDITOR */ + +void USGVirtualHandComponent::InitializeComponent() { Super::InitializeComponent(); @@ -223,7 +251,7 @@ void USGVirtualHandMeshComponent::InitializeComponent() } } -void USGVirtualHandMeshComponent::TickComponent( +void USGVirtualHandComponent::TickComponent( const float DeltaTime, const ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { #if WITH_EDITOR @@ -239,7 +267,7 @@ void USGVirtualHandMeshComponent::TickComponent( (void) Pimpl->CheckGlove(); } -void USGVirtualHandMeshComponent::SetSkeletalMesh(USkeletalMesh* NewMesh, const bool bReinitPose) +void USGVirtualHandComponent::SetSkeletalMesh(USkeletalMesh* NewMesh, const bool bReinitPose) { if (IsValid(NewMesh)) { @@ -251,19 +279,19 @@ void USGVirtualHandMeshComponent::SetSkeletalMesh(USkeletalMesh* NewMesh, const } } -void USGVirtualHandMeshComponent::EditorTick( +void USGVirtualHandComponent::EditorTick( const float DeltaTime, const ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { (void) Pimpl->CheckGlove(); } -bool USGVirtualHandMeshComponent::IsGloveConnected() const +bool USGVirtualHandComponent::IsGloveConnected() const { return Pimpl->CheckGlove(); } -USGHandPose* USGVirtualHandMeshComponent::GetHandPose() +USGHandPose* USGVirtualHandComponent::GetHandPose() { USGHandPose* HandPose = nullptr; @@ -275,7 +303,7 @@ USGHandPose* USGVirtualHandMeshComponent::GetHandPose() return HandPose; } -const FName& USGVirtualHandMeshComponent::GetFingerBoneName(const int32 Finger, const int32 Joint) const +const FName& USGVirtualHandComponent::GetFingerBoneName(const int32 Finger, const int32 Joint) const { const FName& Name{IsRight() ? GetRightHandFingerBoneName(Finger, Joint) @@ -283,7 +311,7 @@ const FName& USGVirtualHandMeshComponent::GetFingerBoneName(const int32 Finger, return Name; } -const FTransform& USGVirtualHandMeshComponent::GetFingerBoneRefTransform(const int32 Finger, const int32 Joint) const +const FTransform& USGVirtualHandComponent::GetFingerBoneRefTransform(const int32 Finger, const int32 Joint) const { const FName& BoneName{GetFingerBoneName(Finger, Joint)}; const FReferenceSkeleton& ReferenceSkeleton{Pimpl->GetRefSkeleton()}; @@ -296,14 +324,14 @@ const FTransform& USGVirtualHandMeshComponent::GetFingerBoneRefTransform(const i return BoneTransform; } -FRotator USGVirtualHandMeshComponent::GetFingerBoneRefRotation(const int32 Finger, const int32 Joint) const +FRotator USGVirtualHandComponent::GetFingerBoneRefRotation(const int32 Finger, const int32 Joint) const { const FTransform BoneTransform{GetFingerBoneRefTransform(Finger, Joint)}; FRotator BoneRotation{BoneTransform.GetRotation().Rotator()}; return MoveTemp(BoneRotation); } -TMap USGVirtualHandMeshComponent::GetFingersBonesRotations() +TMap USGVirtualHandComponent::GetFingersBonesRotations() { TMap Rotations; @@ -337,14 +365,14 @@ TMap USGVirtualHandMeshComponent::GetFingersBonesRotations() return MoveTemp(Rotations); } -USGVirtualHandMeshComponent::FImpl::FImpl(USGVirtualHandMeshComponent* InOwner) +USGVirtualHandComponent::FImpl::FImpl(USGVirtualHandComponent* InOwner) : Owner(InOwner) { } -USGVirtualHandMeshComponent::FImpl::~FImpl() = default; +USGVirtualHandComponent::FImpl::~FImpl() = default; -bool USGVirtualHandMeshComponent::FImpl::IsEditor() const +bool USGVirtualHandComponent::FImpl::IsEditor() const { const UWorld* World = Owner->GetWorld(); if (World && World->WorldType == EWorldType::Editor) @@ -355,7 +383,7 @@ bool USGVirtualHandMeshComponent::FImpl::IsEditor() const return false; } -FString USGVirtualHandMeshComponent::FImpl::GetDefaultMeshPath() const +FString USGVirtualHandComponent::FImpl::GetDefaultMeshPath() const { FString SkeletalMeshPath; @@ -371,7 +399,7 @@ FString USGVirtualHandMeshComponent::FImpl::GetDefaultMeshPath() const return MoveTemp(SkeletalMeshPath); } -bool USGVirtualHandMeshComponent::FImpl::IsUsingUserMesh() const +bool USGVirtualHandComponent::FImpl::IsUsingUserMesh() const { const USkeletalMesh* SkeletalMesh{GetMesh()}; if (!IsValid(SkeletalMesh)) @@ -395,7 +423,7 @@ bool USGVirtualHandMeshComponent::FImpl::IsUsingUserMesh() const return true; } -USkeletalMesh* USGVirtualHandMeshComponent::FImpl::LoadDefaultMesh() const +USkeletalMesh* USGVirtualHandComponent::FImpl::LoadDefaultMesh() const { const FString SkeletalMeshPath(GetDefaultMeshPath()); USkeletalMesh* SkeletalMesh = Cast( @@ -406,12 +434,12 @@ USkeletalMesh* USGVirtualHandMeshComponent::FImpl::LoadDefaultMesh() const return SkeletalMesh; } -void USGVirtualHandMeshComponent::FImpl::SetDefaultMesh() const +void USGVirtualHandComponent::FImpl::SetDefaultMesh() const { Owner->SetSkeletalMesh(LoadDefaultMesh(), true); } -USkeletalMesh* USGVirtualHandMeshComponent::FImpl::GetMesh() const +USkeletalMesh* USGVirtualHandComponent::FImpl::GetMesh() const { return Owner-> #if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1 @@ -422,7 +450,7 @@ USkeletalMesh* USGVirtualHandMeshComponent::FImpl::GetMesh() const ; } -USkeleton* USGVirtualHandMeshComponent::FImpl::GetSkeleton() const +USkeleton* USGVirtualHandComponent::FImpl::GetSkeleton() const { USkeletalMesh* SkeletalMesh{GetMesh()}; ensureAlwaysMsgf(IsValid(SkeletalMesh), TEXT("Invalid SkeletalMesh object!")); @@ -436,7 +464,7 @@ USkeleton* USGVirtualHandMeshComponent::FImpl::GetSkeleton() const ; } -const FReferenceSkeleton& USGVirtualHandMeshComponent::FImpl::GetRefSkeleton() const +const FReferenceSkeleton& USGVirtualHandComponent::FImpl::GetRefSkeleton() const { USkeletalMesh* SkeletalMesh{GetMesh()}; ensureAlwaysMsgf(IsValid(SkeletalMesh), TEXT("Invalid SkeletalMesh object!")); @@ -450,7 +478,7 @@ const FReferenceSkeleton& USGVirtualHandMeshComponent::FImpl::GetRefSkeleton() c ; } -bool USGVirtualHandMeshComponent::FImpl::CheckGlove() const +bool USGVirtualHandComponent::FImpl::CheckGlove() const { const bool bGloveWasPresent = IsValid(Owner->Glove); const bool bFoundGlove = USGHapticGlove::GetGlove(Owner, Owner->IsRight(), Owner->Glove); @@ -464,7 +492,7 @@ bool USGVirtualHandMeshComponent::FImpl::CheckGlove() const return bFoundGlove; } -void USGVirtualHandMeshComponent::FImplDeleter::operator()(const FImpl* P) const +void USGVirtualHandComponent::FImplDeleter::operator()(const FImpl* P) const { delete P; } \ No newline at end of file diff --git a/Source/SenseGlove/Private/SenseGlove/GameFramework/SGVirtualHand.cpp b/Source/SenseGlove/Private/SenseGlove/GameFramework/SGVirtualHand.cpp deleted file mode 100644 index c8bba5f6..00000000 --- a/Source/SenseGlove/Private/SenseGlove/GameFramework/SGVirtualHand.cpp +++ /dev/null @@ -1,478 +0,0 @@ -/** - * @file - * - * @author Mamadou Babaei - * - * @section LICENSE - * - * (The MIT License) - * - * Copyright (c) 2020 - 2023 SenseGlove - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * @section DESCRIPTION - * - * - */ - - -#include "SenseGlove/GameFramework/SGVirtualHand.h" - -#include "Animation/Skeleton.h" -#include "Components/SkeletalMeshComponent.h" -#include "Engine/SkeletalMesh.h" -#include "UObject/ConstructorHelpers.h" - -#include "SenseGlove/Animation/SGVirtualHandAnimInstance.h" -#include "SGCore/SGHandPose.h" -#include "SGCore/SGHapticGlove.h" -#include "SGLog/SGLog.h" - -struct ASGVirtualHand::FImpl -{ - /************************ - * Static methods - ************************/ - - FORCEINLINE static const FString& GetDefaultLeftHandMeshPath() - { - static const FString Path{TEXT("SkeletalMesh'/SenseGlove/Meshes/" - "SK_SenseGlove_VirtualHand_Left.SK_SenseGlove_VirtualHand_Left'")}; - return Path; - } - - FORCEINLINE static const FString& GetDefaultLeftHandMeshPathOnly() - { - static const FString Path{TEXT("/SenseGlove/Meshes/" - "SK_SenseGlove_VirtualHand_Left.SK_SenseGlove_VirtualHand_Left")}; - return Path; - } - - FORCEINLINE static const FString& GetDefaultRightHandMeshPath() - { - static const FString Path{TEXT("SkeletalMesh'/SenseGlove/Meshes/" - "SK_SenseGlove_VirtualHand_Right.SK_SenseGlove_VirtualHand_Right'")}; - return Path; - } - - FORCEINLINE static const FString& GetDefaultRightHandMeshPathOnly() - { - static const FString Path{TEXT("/SenseGlove/Meshes/" - "SK_SenseGlove_VirtualHand_Right.SK_SenseGlove_VirtualHand_Right")}; - return Path; - } - - /************************ - * Owner object - ************************/ - - ASGVirtualHand* Owner; - - /************************ - * Constructor / Destructor - ************************/ - - explicit FImpl(ASGVirtualHand* InOwner); - ~FImpl(); - - /************************ - * Default copy constructor & copy assignment operator - ************************/ - - FImpl(const FImpl& Rhs) = default; - FImpl& operator=(const FImpl& Rhs) = default; - - /************************ - * Methods - ************************/ - - bool IsEditor() const; - - void SetHandMesh(USkeletalMesh* VirtualHandMesh, bool bReinitPos) const; - - FString GetDefaultMeshPath() const; - bool IsUsingUserMesh() const; - USkeletalMesh* LoadDefaultMesh() const; - void SetDefaultMesh() const; - - bool CheckGlove() const; -}; - -const TArray>& ASGVirtualHand::GetLeftHandFingerBoneNames() -{ - static const TArray> BoneNames{ - {FName(TEXT("thumb_01_l")), FName(TEXT("thumb_02_l")), FName(TEXT("thumb_03_l"))}, - {FName(TEXT("index_01_l")), FName(TEXT("index_02_l")), FName(TEXT("index_03_l"))}, - {FName(TEXT("middle_01_l")), FName(TEXT("middle_02_l")), FName(TEXT("middle_03_l"))}, - {FName(TEXT("ring_01_l")), FName(TEXT("ring_02_l")), FName(TEXT("ring_03_l"))}, - {FName(TEXT("pinky_01_l")), FName(TEXT("pinky_02_l")), FName(TEXT("pinky_03_l"))}, - }; - return BoneNames; -} - -const TArray>& ASGVirtualHand::GetRightHandFingerBoneNames() -{ - static const TArray> BoneNames{ - {FName(TEXT("thumb_01_r")), FName(TEXT("thumb_02_r")), FName(TEXT("thumb_03_r"))}, - {FName(TEXT("index_01_r")), FName(TEXT("index_02_r")), FName(TEXT("index_03_r"))}, - {FName(TEXT("middle_01_r")), FName(TEXT("middle_02_r")), FName(TEXT("middle_03_r"))}, - {FName(TEXT("ring_01_r")), FName(TEXT("ring_02_r")), FName(TEXT("ring_03_r"))}, - {FName(TEXT("pinky_01_r")), FName(TEXT("pinky_02_r")), FName(TEXT("pinky_03_r"))}, - }; - return BoneNames; -} - -const FName& ASGVirtualHand::GetLeftHandFingerBoneName(const int32 Finger, const int32 Joint) -{ - const TArray>& BoneNames{GetLeftHandFingerBoneNames()}; - - ensureAlwaysMsgf(Finger < BoneNames.Num(), TEXT("Finger index is out of bound!")); - ensureAlwaysMsgf(Joint < BoneNames[Finger].Num(), TEXT("Joint index is out of bound!")); - - const FName& BoneName{BoneNames[Finger][Joint]}; - return BoneName; -} - -const FName& ASGVirtualHand::GetRightHandFingerBoneName(const int32 Finger, const int32 Joint) -{ - const TArray>& BoneNames{GetRightHandFingerBoneNames()}; - - ensureAlwaysMsgf(Finger < BoneNames.Num(), TEXT("Finger index is out of bound!")); - ensureAlwaysMsgf(Joint < BoneNames[Finger].Num(), TEXT("Joint index is out of bound!")); - - const FName& BoneName{BoneNames[Finger][Joint]}; - return BoneName; -} - -ASGVirtualHand::ASGVirtualHand(const FObjectInitializer& ObjectInitializer) - : Super(ObjectInitializer), - Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) -{ - PrimaryActorTick.bCanEverTick = true; - - SceneRoot = CreateDefaultSubobject(TEXT("SceneRoot")); - SetRootComponent(SceneRoot); - - Mesh = CreateDefaultSubobject(TEXT("Mesh")); - Mesh->SetupAttachment(RootComponent); - Mesh->SetCastShadow(true); - Mesh->SetCastHiddenShadow(false); - Mesh->bCastDynamicShadow = true; - Mesh->SetOnlyOwnerSee(false); - Mesh->SetReceivesDecals(true); - Mesh->SetCanEverAffectNavigation(false); - Mesh->SetCollisionObjectType(ECC_WorldDynamic); - Mesh->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics); - Mesh->SetCollisionResponseToAllChannels(ECR_Overlap); - Mesh->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Block); - Mesh->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Block); - Mesh->SetCollisionResponseToChannel(ECC_Pawn, ECR_Block); - Mesh->SetCollisionResponseToChannel(ECC_Visibility, ECR_Block); - Mesh->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Block); - Mesh->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Block); - Mesh->SetCollisionResponseToChannel(ECC_Destructible, ECR_Block); - - AnimInstanceClass = USGVirtualHandAnimInstance::StaticClass(); - - bRight = true; - bHiddenInGameIfNoGloveDetected = true; - bAnimateInEditor = true; - - const FString SkeletalMeshPath(Pimpl->GetDefaultMeshPath()); - const ConstructorHelpers::FObjectFinder SkeletalMesh(*SkeletalMeshPath); - ensureAlwaysMsgf(SkeletalMesh.Succeeded() && SkeletalMesh.Object, - TEXT("Failed to load the skeletal mesh: '%s'"), *SkeletalMeshPath); - Pimpl->SetHandMesh(SkeletalMesh.Object, true); - - Glove = nullptr; -} - -void ASGVirtualHand::Tick(const float DeltaSeconds) -{ -#if WITH_EDITOR - if (Pimpl->IsEditor()) - { - EditorTick(DeltaSeconds); - return; - } -#endif - - Super::Tick(DeltaSeconds); - - (void) Pimpl->CheckGlove(); -} - -bool ASGVirtualHand::ShouldTickIfViewportsOnly() const -{ - if (!bAnimateInEditor) - { - return false; - } - - if (Pimpl->IsEditor()) - { - return true; - } - - return false; -} - -void ASGVirtualHand::OnConstruction(const FTransform& Transform) -{ - Super::OnConstruction(Transform); - - if (!Pimpl->IsUsingUserMesh()) - { - Pimpl->SetDefaultMesh(); - } -} - -void ASGVirtualHand::EditorTick(float DeltaSeconds) -{ - (void) Pimpl->CheckGlove(); -} - -USkeletalMesh* ASGVirtualHand::GetHandMesh() const -{ - ensureAlwaysMsgf(IsValid(Mesh), TEXT("Invalid Mesh object!")); - - return Mesh-> -#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1 - GetSkeletalMeshAsset() -#else - SkeletalMesh -#endif /* ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 1 */ - ; -} - -void ASGVirtualHand::SetHandMesh(USkeletalMesh* VirtualHandMesh, const bool bReinitPos) const -{ - Pimpl->SetHandMesh(VirtualHandMesh, bReinitPos); -} - -USkeleton* ASGVirtualHand::GetHandSkeleton() const -{ - USkeletalMesh* SkeletalMesh{GetHandMesh()}; - ensureAlwaysMsgf(IsValid(SkeletalMesh), TEXT("Invalid SkeletalMesh object!")); - - return SkeletalMesh-> -#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1 - GetSkeleton() -#else - Skeleton -#endif /* ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 1 */ - ; -} - -const FReferenceSkeleton& ASGVirtualHand::GetHandRefSkeleton() const -{ - USkeletalMesh* SkeletalMesh{GetHandMesh()}; - ensureAlwaysMsgf(IsValid(SkeletalMesh), TEXT("Invalid SkeletalMesh object!")); - - return SkeletalMesh-> -#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1 - GetRefSkeleton() -#else - RefSkeleton -#endif /* ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 1 */ - ; -} - -bool ASGVirtualHand::IsGloveConnected() const -{ - return Pimpl->CheckGlove(); -} - -USGHandPose* ASGVirtualHand::GetHandPose() -{ - USGHandPose* HandPose = nullptr; - - if (IsValid(Glove)) - { - Glove->GetHandPose(this, HandPose); - } - - return HandPose; -} - -const FName& ASGVirtualHand::GetFingerBoneName(const int32 Finger, const int32 Joint) const -{ - const FName& Name{IsRight() - ? GetRightHandFingerBoneName(Finger, Joint) - : GetLeftHandFingerBoneName(Finger, Joint)}; - return Name; -} - -const FTransform& ASGVirtualHand::GetFingerBoneRefTransform(const int32 Finger, const int32 Joint) const -{ - const FName& BoneName{GetFingerBoneName(Finger, Joint)}; - const FReferenceSkeleton& ReferenceSkeleton{GetHandRefSkeleton()}; - const int32 BoneIndex = ReferenceSkeleton.FindBoneIndex(BoneName); - - ensureAlwaysMsgf(BoneIndex != INDEX_NONE, TEXT("Invalid virtual hand bone name '%s' or index!"), - *BoneName.ToString()); - - const FTransform& BoneTransform{ReferenceSkeleton.GetRefBonePose()[BoneIndex]}; - return BoneTransform; -} - -FRotator ASGVirtualHand::GetFingerBoneRefRotation(const int32 Finger, const int32 Joint) const -{ - const FTransform BoneTransform{GetFingerBoneRefTransform(Finger, Joint)}; - FRotator BoneRotation{BoneTransform.GetRotation().Rotator()}; - return MoveTemp(BoneRotation); -} - -TMap ASGVirtualHand::GetFingersBonesRotations() -{ - TMap Rotations; - - const USGHandPose* HandPose = GetHandPose(); - if (!IsValid(HandPose)) - { - return MoveTemp(Rotations); - } - - const TArray> HandAngles{HandPose->GetHandAngles()}; - - for (int32 FingerIndex = 0; FingerIndex < HandAngles.Num(); ++FingerIndex) - { - const TArray& FingerJointAngles{HandAngles[FingerIndex]}; - - for (int32 JointIndex = 0; JointIndex < FingerJointAngles.Num(); ++JointIndex) - { - const FVector& JointAngle{FingerJointAngles[JointIndex]}; - const FQuat JointRotation{FQuat::MakeFromEuler(JointAngle)}; - - const FTransform& BoneRefTransform{GetFingerBoneRefTransform(FingerIndex, JointIndex)}; - - FQuat NewBoneRotation{BoneRefTransform.GetRotation() * JointRotation}; - - FName BoneName{GetFingerBoneName(FingerIndex, JointIndex)}; - - Rotations.Emplace(MoveTemp(BoneName), MoveTemp(NewBoneRotation)); - } - } - - return MoveTemp(Rotations); -} - -ASGVirtualHand::FImpl::FImpl(ASGVirtualHand* InOwner) - : Owner(InOwner) -{ -} - -ASGVirtualHand::FImpl::~FImpl() = default; - -void ASGVirtualHand::FImpl::SetHandMesh(USkeletalMesh* VirtualHandMesh, const bool bReinitPos) const -{ - ensureAlwaysMsgf(IsValid(VirtualHandMesh), TEXT("Invalid VirtualHandMesh object!")); - ensureAlwaysMsgf(IsValid(Owner->Mesh), TEXT("Invalid Mesh object!")); - ensureAlwaysMsgf(IsValid(Owner->AnimInstanceClass), TEXT("Invalid AnimInstanceClass object!")); - - Owner->Mesh->SetSkeletalMesh(VirtualHandMesh, bReinitPos); - Owner->Mesh->SetAnimInstanceClass(Owner->AnimInstanceClass); -} - -bool ASGVirtualHand::FImpl::IsEditor() const -{ - const UWorld* World = Owner->GetWorld(); - if (World && World->WorldType == EWorldType::Editor) - { - return true; - } - - return false; -} - -FString ASGVirtualHand::FImpl::GetDefaultMeshPath() const -{ - FString SkeletalMeshPath; - - if (Owner->bRight) - { - SkeletalMeshPath = GetDefaultRightHandMeshPath(); - } - else - { - SkeletalMeshPath = GetDefaultLeftHandMeshPath(); - } - - return MoveTemp(SkeletalMeshPath); -} - -bool ASGVirtualHand::FImpl::IsUsingUserMesh() const -{ - const USkeletalMesh* SkeletalMesh{Owner->GetHandMesh()}; - if (!IsValid(SkeletalMesh)) - { - return false; - } - - const FString CurrentMeshPath(SkeletalMesh->GetPathName()); - const FString LeftHandDefaultMeshPath(GetDefaultLeftHandMeshPath()); - const FString LeftHandDefaultMeshPathOnly(GetDefaultLeftHandMeshPathOnly()); - const FString RightHandDefaultMeshPath(GetDefaultRightHandMeshPath()); - const FString RightHandDefaultMeshPathOnly(GetDefaultRightHandMeshPathOnly()); - if (CurrentMeshPath == LeftHandDefaultMeshPath - || CurrentMeshPath == LeftHandDefaultMeshPathOnly - || CurrentMeshPath == RightHandDefaultMeshPath - || CurrentMeshPath == RightHandDefaultMeshPathOnly) - { - return false; - } - - return true; -} - -USkeletalMesh* ASGVirtualHand::FImpl::LoadDefaultMesh() const -{ - const FString SkeletalMeshPath(GetDefaultMeshPath()); - USkeletalMesh* SkeletalMesh = Cast( - StaticLoadObject(USkeletalMesh::StaticClass(), nullptr, *SkeletalMeshPath)); - - ensureAlwaysMsgf(SkeletalMesh, TEXT("Failed to load the skeletal mesh: '%s'"), *SkeletalMeshPath); - - return SkeletalMesh; -} - -void ASGVirtualHand::FImpl::SetDefaultMesh() const -{ - SetHandMesh(LoadDefaultMesh(), true); -} - -bool ASGVirtualHand::FImpl::CheckGlove() const -{ - const bool bGloveWasPresent = IsValid(Owner->Glove); - const bool bFoundGlove = USGHapticGlove::GetGlove(Owner, Owner->IsRight(), Owner->Glove); - - if (!bFoundGlove && bGloveWasPresent) - { - SGLOG_ERROR(FString::Printf(TEXT("Could not find a %s glove"), - (Owner->bRight ? TEXT("right-handed") : TEXT("left-handed")))); - } - - return bFoundGlove; -} - -void ASGVirtualHand::FImplDeleter::operator()(const FImpl* P) const -{ - delete P; -} \ No newline at end of file diff --git a/Source/SenseGlove/Private/SenseGlove/GameFramework/SGVirtualHandActor.cpp b/Source/SenseGlove/Private/SenseGlove/GameFramework/SGVirtualHandActor.cpp new file mode 100644 index 00000000..c467f5bc --- /dev/null +++ b/Source/SenseGlove/Private/SenseGlove/GameFramework/SGVirtualHandActor.cpp @@ -0,0 +1,156 @@ +/** + * @file + * + * @author Mamadou Babaei + * + * @section LICENSE + * + * (The MIT License) + * + * Copyright (c) 2020 - 2023 SenseGlove + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @section DESCRIPTION + * + * + */ + + +#include "SenseGlove/GameFramework/SGVirtualHandActor.h" + +#include "SenseGlove/Components/SGVirtualHandComponent.h" + +struct ASGVirtualHandActor::FImpl +{ + /************************ + * Owner object + ************************/ + + ASGVirtualHandActor* Owner; + + /************************ + * Constructor / Destructor + ************************/ + + explicit FImpl(ASGVirtualHandActor* InOwner); + ~FImpl(); + + /************************ + * Default copy constructor & copy assignment operator + ************************/ + + FImpl(const FImpl& Rhs) = default; + FImpl& operator=(const FImpl& Rhs) = default; + + /************************ + * Methods + ************************/ + + bool IsEditor() const; + + FORCEINLINE USGVirtualHandComponent* GetVirtualHand() const + { + ensureAlwaysMsgf(IsValid(Owner->VirtualHand), TEXT("Invalid VirtualHand object!")); + return Owner->VirtualHand; + } +}; + +ASGVirtualHandActor::ASGVirtualHandActor(const FObjectInitializer& ObjectInitializer) + : Super(ObjectInitializer), + Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) +{ + PrimaryActorTick.bCanEverTick = true; + + SceneRoot = CreateDefaultSubobject(TEXT("SceneRoot")); + SetRootComponent(SceneRoot); + + VirtualHand = CreateDefaultSubobject(TEXT("VirtualHand")); + VirtualHand->SetupAttachment(RootComponent); +} + +void ASGVirtualHandActor::Tick(const float DeltaSeconds) +{ +#if WITH_EDITOR + if (Pimpl->IsEditor()) + { + EditorTick(DeltaSeconds); + return; + } +#endif + + Super::Tick(DeltaSeconds); +} + +bool ASGVirtualHandActor::ShouldTickIfViewportsOnly() const +{ + if (VirtualHand->bTickInEditor && Pimpl->IsEditor()) + { + return true; + } + + return false; +} + +void ASGVirtualHandActor::OnConstruction(const FTransform& Transform) +{ + Super::OnConstruction(Transform); +} + +void ASGVirtualHandActor::EditorTick(float DeltaSeconds) +{ +} + +bool ASGVirtualHandActor::IsLeft() const +{ + return GetVirtualHand()->IsLeft(); +} + +bool ASGVirtualHandActor::IsRight() const +{ + return GetVirtualHand()->IsRight(); +} + +bool ASGVirtualHandActor::IsGloveConnected() const +{ + return GetVirtualHand()->IsGloveConnected(); +} + +ASGVirtualHandActor::FImpl::FImpl(ASGVirtualHandActor* InOwner) + : Owner(InOwner) +{ +} + +ASGVirtualHandActor::FImpl::~FImpl() = default; + +bool ASGVirtualHandActor::FImpl::IsEditor() const +{ + const UWorld* World = Owner->GetWorld(); + if (World && World->WorldType == EWorldType::Editor) + { + return true; + } + + return false; +} + +void ASGVirtualHandActor::FImplDeleter::operator()(const FImpl* P) const +{ + delete P; +} \ No newline at end of file diff --git a/Source/SenseGlove/Public/SenseGlove/Components/SGVirtualHandMeshComponent.h b/Source/SenseGlove/Public/SenseGlove/Components/SGVirtualHandComponent.h similarity index 93% rename from Source/SenseGlove/Public/SenseGlove/Components/SGVirtualHandMeshComponent.h rename to Source/SenseGlove/Public/SenseGlove/Components/SGVirtualHandComponent.h index be0f285f..5faddf32 100644 --- a/Source/SenseGlove/Public/SenseGlove/Components/SGVirtualHandMeshComponent.h +++ b/Source/SenseGlove/Public/SenseGlove/Components/SGVirtualHandComponent.h @@ -45,7 +45,7 @@ #include "Templates/UniquePtr.h" #include "UObject/NameTypes.h" -#include "SGVirtualHandMeshComponent.generated.h" +#include "SGVirtualHandComponent.generated.h" class USkeletalMesh; class USkeleton; @@ -56,7 +56,7 @@ class USGHapticGlove; UCLASS(Config=Engine, Blueprintable, ClassGroup=(Rendering, Common), hidecategories=(Object, "Mesh|SkeletalAsset"), editinlinenew, meta=(BlueprintSpawnableComponent)) -class SENSEGLOVE_API USGVirtualHandMeshComponent : public USkeletalMeshComponent +class SENSEGLOVE_API USGVirtualHandComponent : public USkeletalMeshComponent { GENERATED_UCLASS_BODY() @@ -100,10 +100,7 @@ public: return !!bRight; } - FORCEINLINE void SetRight(const bool bInRight) - { - bRight = bInRight; - } + void SetRight(const bool bInRight); FORCEINLINE bool IsHiddenInGameIfNoGloveDetected() const { @@ -118,6 +115,10 @@ public: public: virtual void SetAnimClass(class UClass* NewClass) override; +#if WITH_EDITOR + virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override; +#endif /* WITH_EDITOR */ + virtual void InitializeComponent() override; virtual void TickComponent(float DeltaTime, diff --git a/Source/SenseGlove/Public/SenseGlove/GameFramework/SGVirtualHand.h b/Source/SenseGlove/Public/SenseGlove/GameFramework/SGVirtualHand.h deleted file mode 100644 index bf3764b9..00000000 --- a/Source/SenseGlove/Public/SenseGlove/GameFramework/SGVirtualHand.h +++ /dev/null @@ -1,187 +0,0 @@ -/** - * @file - * - * @author Mamadou Babaei - * - * @section LICENSE - * - * (The MIT License) - * - * Copyright (c) 2020 - 2023 SenseGlove - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * @section DESCRIPTION - * - * - */ - - -#pragma once - -#include "Containers/Array.h" -#include "Containers/Map.h" -#include "GameFramework/Actor.h" -#include "Math/Rotator.h" -#include "Math/Transform.h" -#include "ReferenceSkeleton.h" -#include "Templates/UniquePtr.h" -#include "UObject/NameTypes.h" - -#include "SGVirtualHand.generated.h" - -class USkeletalMesh; -class USkeleton; -class USkeletalMeshComponent; -class USceneComponent; - -class USGHandPose; -class USGHapticGlove; - -UCLASS(Config=Game, BlueprintType) -class SENSEGLOVE_API ASGVirtualHand : public AActor -{ - GENERATED_UCLASS_BODY() - -public: - static const TArray>& GetLeftHandFingerBoneNames(); - static const TArray>& GetRightHandFingerBoneNames(); - - static const FName& GetLeftHandFingerBoneName(int32 Finger, int32 Joint); - static const FName& GetRightHandFingerBoneName(int32 Finger, int32 Joint); - -private: - struct FImpl; - - struct FImplDeleter - { - void operator()(const FImpl* P) const; - }; - - TUniquePtr Pimpl; - FImplDeleter PimplDeleter; - -private: - UPROPERTY(VisibleAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false")) - USceneComponent* SceneRoot; - - UPROPERTY(VisibleAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false")) - USkeletalMeshComponent* Mesh; - - UPROPERTY(EditAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false")) - UClass* AnimInstanceClass; - - UPROPERTY(EditAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false")) - uint8 bRight : 1; - - UPROPERTY(EditAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false")) - uint8 bHiddenInGameIfNoGloveDetected : 1; - - UPROPERTY(EditAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false")) - uint8 bAnimateInEditor : 1; - -private: - UPROPERTY(Transient) - USGHapticGlove* Glove; - -public: - FORCEINLINE USkeletalMeshComponent* GetMesh() const - { - return Mesh; - } - -public: - FORCEINLINE bool IsLeft() const - { - return !IsRight(); - } - - FORCEINLINE bool IsRight() const - { - return !!bRight; - } - - FORCEINLINE void SetRight(const bool bInRight) - { - bRight = bInRight; - } - - FORCEINLINE bool IsHiddenInGameIfNoGloveDetected() const - { - return !!bHiddenInGameIfNoGloveDetected; - } - - FORCEINLINE void SetHiddenIfNoGloveDetected(const bool bInHiddenIfNoGloveDetected) - { - bHiddenInGameIfNoGloveDetected = bInHiddenIfNoGloveDetected; - } - - FORCEINLINE bool IsAnimateInEditor() const - { - return bAnimateInEditor; - } - - FORCEINLINE void SetAnimateInEditor(const bool bInAnimateInEditor) - { - bAnimateInEditor = bInAnimateInEditor; - } - -protected: - FORCEINLINE void SetMesh(USkeletalMeshComponent* InMesh) - { - Mesh = InMesh; - } - - FORCEINLINE UClass* GetAnimInstanceClass() const - { - return AnimInstanceClass; - } - - FORCEINLINE void SetAnimInstanceClass(UClass* InAnimInstanceClass) - { - AnimInstanceClass = InAnimInstanceClass; - } - -public: - virtual void Tick(float DeltaSeconds) override; - - virtual bool ShouldTickIfViewportsOnly() const override; - - virtual void OnConstruction(const FTransform& Transform) override; - -protected: - virtual void EditorTick(float DeltaSeconds); - -public: - USkeletalMesh* GetHandMesh() const; - void SetHandMesh(USkeletalMesh* VirtualHandMesh, bool bReinitPos) const; - - USkeleton* GetHandSkeleton() const; - const FReferenceSkeleton& GetHandRefSkeleton() const; - - bool IsGloveConnected() const; - USGHandPose* GetHandPose(); - -public: - const FName& GetFingerBoneName(int32 Finger, int32 Joint) const; - const FTransform& GetFingerBoneRefTransform(int32 Finger, int32 Joint) const; - - FRotator GetFingerBoneRefRotation(int32 Finger, int32 Joint) const; - TMap GetFingersBonesRotations(); -}; \ No newline at end of file diff --git a/Source/SenseGlove/Public/SenseGlove/GameFramework/SGVirtualHandActor.h b/Source/SenseGlove/Public/SenseGlove/GameFramework/SGVirtualHandActor.h new file mode 100644 index 00000000..3d7a49e0 --- /dev/null +++ b/Source/SenseGlove/Public/SenseGlove/GameFramework/SGVirtualHandActor.h @@ -0,0 +1,103 @@ +/** + * @file + * + * @author Mamadou Babaei + * + * @section LICENSE + * + * (The MIT License) + * + * Copyright (c) 2020 - 2023 SenseGlove + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @section DESCRIPTION + * + * + */ + + +#pragma once + +#include "Containers/Array.h" +#include "Containers/Map.h" +#include "GameFramework/Actor.h" +#include "Templates/UniquePtr.h" +#include "UObject/NameTypes.h" + +#include "SGVirtualHandActor.generated.h" + +class USkeletalMesh; +class USkeleton; +class USceneComponent; + +class USGHandPose; +class USGVirtualHandComponent; + +UCLASS(Config=Game, BlueprintType) +class SENSEGLOVE_API ASGVirtualHandActor : public AActor +{ + GENERATED_UCLASS_BODY() + +private: + struct FImpl; + + struct FImplDeleter + { + void operator()(const FImpl* P) const; + }; + + TUniquePtr Pimpl; + FImplDeleter PimplDeleter; + +private: + UPROPERTY(VisibleAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false")) + USceneComponent* SceneRoot; + + UPROPERTY(VisibleAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false")) + USGVirtualHandComponent* VirtualHand; + +public: + FORCEINLINE USGVirtualHandComponent* GetVirtualHand() const + { + return VirtualHand; + } + +protected: + FORCEINLINE void SetMesh(USGVirtualHandComponent* InVirtualHand) + { + VirtualHand = InVirtualHand; + } + +public: + virtual void Tick(float DeltaSeconds) override; + + virtual bool ShouldTickIfViewportsOnly() const override; + + virtual void OnConstruction(const FTransform& Transform) override; + +protected: + virtual void EditorTick(float DeltaSeconds); + +public: + bool IsLeft() const; + bool IsRight() const; + + bool IsGloveConnected() const; +}; \ No newline at end of file diff --git a/Source/SenseGloveKismet/Private/SGKismet/SGVirtualHandActorKismetLibrary.cpp b/Source/SenseGloveKismet/Private/SGKismet/SGVirtualHandActorKismetLibrary.cpp new file mode 100644 index 00000000..63b02886 --- /dev/null +++ b/Source/SenseGloveKismet/Private/SGKismet/SGVirtualHandActorKismetLibrary.cpp @@ -0,0 +1,58 @@ +/** + * @file + * + * @author Mamadou Babaei + * + * @section LICENSE + * + * (The MIT License) + * + * Copyright (c) 2020 - 2023 SenseGlove + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @section DESCRIPTION + * + * + */ + + +#include "SGKismet/SGVirtualHandActorKismetLibrary.h" + +#include "SenseGlove/GameFramework/SGVirtualHandActor.h" + +USGVirtualHandComponent* UVirtualHandActorKismetLibrary::GetVirtualHand(const ASGVirtualHandActor* VirtualHandActor) +{ + return VirtualHandActor->GetVirtualHand(); +} + +bool UVirtualHandActorKismetLibrary::IsLeft(const ASGVirtualHandActor* VirtualHandActor) +{ + return VirtualHandActor->IsLeft(); +} + +bool UVirtualHandActorKismetLibrary::IsRight(const ASGVirtualHandActor* VirtualHandActor) +{ + return VirtualHandActor->IsRight(); +} + +bool UVirtualHandActorKismetLibrary::IsGloveConnected(const ASGVirtualHandActor* VirtualHandActor) const +{ + return VirtualHandActor->IsGloveConnected(); +} \ No newline at end of file diff --git a/Source/SenseGloveKismet/Private/SGKismet/SGVirtualHandComponentKismetLibrary.cpp b/Source/SenseGloveKismet/Private/SGKismet/SGVirtualHandComponentKismetLibrary.cpp new file mode 100644 index 00000000..1d2f81d2 --- /dev/null +++ b/Source/SenseGloveKismet/Private/SGKismet/SGVirtualHandComponentKismetLibrary.cpp @@ -0,0 +1,124 @@ +/** + * @file + * + * @author Mamadou Babaei + * + * @section LICENSE + * + * (The MIT License) + * + * Copyright (c) 2020 - 2023 SenseGlove + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @section DESCRIPTION + * + * + */ + + +#include "SGKismet/SGVirtualHandComponentKismetLibrary.h" + +#include "SenseGlove/Components/SGVirtualHandComponent.h" +#include "SGCore/SGHandPose.h" +#include "SGUtils/SGArrayUtils.h" + +TArray UVirtualHandComponentKismetLibrary::GetLeftHandFingerBoneNames() +{ + return FSGArrayUtils::ToNestedBPArray( + USGVirtualHandComponent::GetLeftHandFingerBoneNames()); +} + +TArray UVirtualHandComponentKismetLibrary::GetRightHandFingerBoneNames() +{ + return FSGArrayUtils::ToNestedBPArray( + USGVirtualHandComponent::GetRightHandFingerBoneNames()); +} + +const FName& UVirtualHandComponentKismetLibrary::GetLeftHandFingerBoneName(const int32 Finger, const int32 Joint) +{ + return USGVirtualHandComponent::GetLeftHandFingerBoneName(Finger, Joint); +} + +const FName& UVirtualHandComponentKismetLibrary::GetRightHandFingerBoneName(const int32 Finger, const int32 Joint) +{ + return USGVirtualHandComponent::GetRightHandFingerBoneName(Finger, Joint); +} + +bool UVirtualHandComponentKismetLibrary::IsLeft(const USGVirtualHandComponent* VirtualHandComponent) +{ + return VirtualHandComponent->IsLeft(); +} + +bool UVirtualHandComponentKismetLibrary::IsRight(const USGVirtualHandComponent* VirtualHandComponent) +{ + return VirtualHandComponent->IsRight(); +} + +void UVirtualHandComponentKismetLibrary::SetRight(USGVirtualHandComponent* VirtualHandComponent, + const bool bInRight) +{ + VirtualHandComponent->SetRight(bInRight); +} + +bool UVirtualHandComponentKismetLibrary::IsHiddenInGameIfNoGloveDetected( + const USGVirtualHandComponent* VirtualHandComponent) +{ + return VirtualHandComponent->IsHiddenInGameIfNoGloveDetected(); +} + +void UVirtualHandComponentKismetLibrary::SetHiddenIfNoGloveDetected( + USGVirtualHandComponent* VirtualHandComponent, const bool bInHiddenIfNoGloveDetected) +{ + VirtualHandComponent->SetHiddenIfNoGloveDetected(bInHiddenIfNoGloveDetected); +} + +bool UVirtualHandComponentKismetLibrary::IsGloveConnected(const USGVirtualHandComponent* VirtualHandComponent) const +{ + return VirtualHandComponent->IsGloveConnected(); +} + +USGHandPose* UVirtualHandComponentKismetLibrary::GetHandPose(USGVirtualHandComponent* VirtualHandComponent) +{ + return VirtualHandComponent->GetHandPose(); +} + +const FName& UVirtualHandComponentKismetLibrary::GetFingerBoneName( + const USGVirtualHandComponent* VirtualHandComponent, const int32 Finger, const int32 Joint) const +{ + return VirtualHandComponent->GetFingerBoneName(Finger, Joint); +} + +const FTransform& UVirtualHandComponentKismetLibrary::GetFingerBoneRefTransform( + const USGVirtualHandComponent* VirtualHandComponent, const int32 Finger, const int32 Joint) const +{ + return VirtualHandComponent->GetFingerBoneRefTransform(Finger, Joint); +} + +FRotator UVirtualHandComponentKismetLibrary::GetFingerBoneRefRotation( + const USGVirtualHandComponent* VirtualHandComponent, const int32 Finger, const int32 Joint) const +{ + return VirtualHandComponent->GetFingerBoneRefRotation(Finger, Joint); +} + +TMap UVirtualHandComponentKismetLibrary::GetFingersBonesRotations( + USGVirtualHandComponent* VirtualHandComponent) +{ + return VirtualHandComponent->GetFingersBonesRotations(); +} \ No newline at end of file diff --git a/Source/SenseGloveKismet/Private/SGKismet/SGVirtualHandKismetLibrary.cpp b/Source/SenseGloveKismet/Private/SGKismet/SGVirtualHandKismetLibrary.cpp deleted file mode 100644 index 4364d562..00000000 --- a/Source/SenseGloveKismet/Private/SGKismet/SGVirtualHandKismetLibrary.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/** - * @file - * - * @author Mamadou Babaei - * - * @section LICENSE - * - * (The MIT License) - * - * Copyright (c) 2020 - 2023 SenseGlove - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * @section DESCRIPTION - * - * - */ - - -#include "SGKismet/SGVirtualHandKismetLibrary.h" - -#include "SenseGlove/GameFramework/SGVirtualHand.h" -#include "SGCore/SGHandPose.h" -#include "SGUtils/SGArrayUtils.h" - -TArray UVirtualHandKismetLibrary::GetLeftHandFingerBoneNames() -{ - return FSGArrayUtils::ToNestedBPArray(ASGVirtualHand::GetLeftHandFingerBoneNames()); -} - -TArray UVirtualHandKismetLibrary::GetRightHandFingerBoneNames() -{ - return FSGArrayUtils::ToNestedBPArray(ASGVirtualHand::GetRightHandFingerBoneNames()); -} - -const FName& UVirtualHandKismetLibrary::GetLeftHandFingerBoneName(const int32 Finger, const int32 Joint) -{ - return ASGVirtualHand::GetLeftHandFingerBoneName(Finger, Joint); -} - -const FName& UVirtualHandKismetLibrary::GetRightHandFingerBoneName(const int32 Finger, const int32 Joint) -{ - return ASGVirtualHand::GetRightHandFingerBoneName(Finger, Joint); -} - -USkeletalMeshComponent* UVirtualHandKismetLibrary::GetMesh(const ASGVirtualHand* VirtualHand) -{ - return VirtualHand->GetMesh(); -} - -bool UVirtualHandKismetLibrary::IsLeft(const ASGVirtualHand* VirtualHand) -{ - return VirtualHand->IsLeft(); -} - -bool UVirtualHandKismetLibrary::IsRight(const ASGVirtualHand* VirtualHand) -{ - return VirtualHand->IsRight(); -} - -void UVirtualHandKismetLibrary::SetRight(ASGVirtualHand* VirtualHand, const bool bInRight) -{ - VirtualHand->SetRight(bInRight); -} - -bool UVirtualHandKismetLibrary::IsHiddenInGameIfNoGloveDetected(const ASGVirtualHand* VirtualHand) -{ - return VirtualHand->IsHiddenInGameIfNoGloveDetected(); -} - -void UVirtualHandKismetLibrary::SetHiddenIfNoGloveDetected(ASGVirtualHand* VirtualHand, - const bool bInHiddenIfNoGloveDetected) -{ - VirtualHand->SetHiddenIfNoGloveDetected(bInHiddenIfNoGloveDetected); -} - -bool UVirtualHandKismetLibrary::IsAnimateInEditor(const ASGVirtualHand* VirtualHand) -{ - return VirtualHand->IsAnimateInEditor(); -} - -void UVirtualHandKismetLibrary::SetAnimateInEditor(ASGVirtualHand* VirtualHand, const bool bInAnimateInEditor) -{ - VirtualHand->SetAnimateInEditor(bInAnimateInEditor); -} - -USkeletalMesh* UVirtualHandKismetLibrary::GetHandMesh(const ASGVirtualHand* VirtualHand) const -{ - return VirtualHand->GetHandMesh(); -} - -void UVirtualHandKismetLibrary::SetHandMesh(UPARAM(ref) ASGVirtualHand* VirtualHand, - USkeletalMesh* VirtualHandMesh, const bool bReinitPos) const -{ - VirtualHand->SetHandMesh(VirtualHandMesh, bReinitPos); -} - -USkeleton* UVirtualHandKismetLibrary::GetHandSkeleton(const ASGVirtualHand* VirtualHand) const -{ - return VirtualHand->GetHandSkeleton(); -} - -bool UVirtualHandKismetLibrary::IsGloveConnected(const ASGVirtualHand* VirtualHand) const -{ - return VirtualHand->IsGloveConnected(); -} - -USGHandPose* UVirtualHandKismetLibrary::GetHandPose(ASGVirtualHand* VirtualHand) -{ - return VirtualHand->GetHandPose(); -} - -const FName& UVirtualHandKismetLibrary::GetFingerBoneName(const ASGVirtualHand* VirtualHand, - const int32 Finger, const int32 Joint) const -{ - return VirtualHand->GetFingerBoneName(Finger, Joint); -} - -const FTransform& UVirtualHandKismetLibrary::GetFingerBoneRefTransform(const ASGVirtualHand* VirtualHand, - const int32 Finger, const int32 Joint) const -{ - return VirtualHand->GetFingerBoneRefTransform(Finger, Joint); -} - -FRotator UVirtualHandKismetLibrary::GetFingerBoneRefRotation(const ASGVirtualHand* VirtualHand, - const int32 Finger, const int32 Joint) const -{ - return VirtualHand->GetFingerBoneRefRotation(Finger, Joint); -} - -TMap UVirtualHandKismetLibrary::GetFingersBonesRotations(ASGVirtualHand* VirtualHand) -{ - return VirtualHand->GetFingersBonesRotations(); -} \ No newline at end of file diff --git a/Source/SenseGloveKismet/Private/SGKismet/SGVirtualHandMeshComponentKismetLibrary.cpp b/Source/SenseGloveKismet/Private/SGKismet/SGVirtualHandMeshComponentKismetLibrary.cpp deleted file mode 100644 index ce326fed..00000000 --- a/Source/SenseGloveKismet/Private/SGKismet/SGVirtualHandMeshComponentKismetLibrary.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/** - * @file - * - * @author Mamadou Babaei - * - * @section LICENSE - * - * (The MIT License) - * - * Copyright (c) 2020 - 2023 SenseGlove - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * @section DESCRIPTION - * - * - */ - - -#include "SGKismet/SGVirtualHandMeshComponentKismetLibrary.h" - -#include "SenseGlove/Components/SGVirtualHandMeshComponent.h" -#include "SGCore/SGHandPose.h" -#include "SGUtils/SGArrayUtils.h" - -TArray UVirtualHandMeshComponentKismetLibrary::GetLeftHandFingerBoneNames() -{ - return FSGArrayUtils::ToNestedBPArray( - USGVirtualHandMeshComponent::GetLeftHandFingerBoneNames()); -} - -TArray UVirtualHandMeshComponentKismetLibrary::GetRightHandFingerBoneNames() -{ - return FSGArrayUtils::ToNestedBPArray( - USGVirtualHandMeshComponent::GetRightHandFingerBoneNames()); -} - -const FName& UVirtualHandMeshComponentKismetLibrary::GetLeftHandFingerBoneName(const int32 Finger, const int32 Joint) -{ - return USGVirtualHandMeshComponent::GetLeftHandFingerBoneName(Finger, Joint); -} - -const FName& UVirtualHandMeshComponentKismetLibrary::GetRightHandFingerBoneName(const int32 Finger, const int32 Joint) -{ - return USGVirtualHandMeshComponent::GetRightHandFingerBoneName(Finger, Joint); -} - -bool UVirtualHandMeshComponentKismetLibrary::IsLeft(const USGVirtualHandMeshComponent* VirtualHandMeshComponent) -{ - return VirtualHandMeshComponent->IsLeft(); -} - -bool UVirtualHandMeshComponentKismetLibrary::IsRight(const USGVirtualHandMeshComponent* VirtualHandMeshComponent) -{ - return VirtualHandMeshComponent->IsRight(); -} - -void UVirtualHandMeshComponentKismetLibrary::SetRight(USGVirtualHandMeshComponent* VirtualHandMeshComponent, - const bool bInRight) -{ - VirtualHandMeshComponent->SetRight(bInRight); -} - -bool UVirtualHandMeshComponentKismetLibrary::IsHiddenInGameIfNoGloveDetected( - const USGVirtualHandMeshComponent* VirtualHandMeshComponent) -{ - return VirtualHandMeshComponent->IsHiddenInGameIfNoGloveDetected(); -} - -void UVirtualHandMeshComponentKismetLibrary::SetHiddenIfNoGloveDetected( - USGVirtualHandMeshComponent* VirtualHandMeshComponent, - const bool bInHiddenIfNoGloveDetected) -{ - VirtualHandMeshComponent->SetHiddenIfNoGloveDetected(bInHiddenIfNoGloveDetected); -} - -bool UVirtualHandMeshComponentKismetLibrary::IsGloveConnected( - const USGVirtualHandMeshComponent* VirtualHandMeshComponent) const -{ - return VirtualHandMeshComponent->IsGloveConnected(); -} - -USGHandPose* UVirtualHandMeshComponentKismetLibrary::GetHandPose(USGVirtualHandMeshComponent* VirtualHandMeshComponent) -{ - return VirtualHandMeshComponent->GetHandPose(); -} - -const FName& UVirtualHandMeshComponentKismetLibrary::GetFingerBoneName( - const USGVirtualHandMeshComponent* VirtualHandMeshComponent, - const int32 Finger, const int32 Joint) const -{ - return VirtualHandMeshComponent->GetFingerBoneName(Finger, Joint); -} - -const FTransform& UVirtualHandMeshComponentKismetLibrary::GetFingerBoneRefTransform( - const USGVirtualHandMeshComponent* VirtualHandMeshComponent, - const int32 Finger, const int32 Joint) const -{ - return VirtualHandMeshComponent->GetFingerBoneRefTransform(Finger, Joint); -} - -FRotator UVirtualHandMeshComponentKismetLibrary::GetFingerBoneRefRotation( - const USGVirtualHandMeshComponent* VirtualHandMeshComponent, - const int32 Finger, const int32 Joint) const -{ - return VirtualHandMeshComponent->GetFingerBoneRefRotation(Finger, Joint); -} - -TMap UVirtualHandMeshComponentKismetLibrary::GetFingersBonesRotations( - USGVirtualHandMeshComponent* VirtualHandMeshComponent) -{ - return VirtualHandMeshComponent->GetFingersBonesRotations(); -} \ No newline at end of file diff --git a/Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandActorKismetLibrary.h b/Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandActorKismetLibrary.h new file mode 100644 index 00000000..e87184f0 --- /dev/null +++ b/Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandActorKismetLibrary.h @@ -0,0 +1,67 @@ +/** + * @file + * + * @author Mamadou Babaei + * + * @section LICENSE + * + * (The MIT License) + * + * Copyright (c) 2020 - 2023 SenseGlove + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @section DESCRIPTION + * + * A data class containing the minimum required data for a hand's forward + * kinematics. + * Used in both kinematics and calibration. + */ + + +#pragma once + +#include "SGKismet/SGBlueprintFunctionLibrary.h" + +#include "SGVirtualHandActorKismetLibrary.generated.h" + +class ASGVirtualHandActor; +class USGVirtualHandComponent; + +/** + * Represents data of a user's hand required for forward kinematics. + */ +UCLASS(meta=(ScriptName = "SesneGloveVirtualHandActorKismetLibrary")) +class SENSEGLOVEKISMET_API UVirtualHandActorKismetLibrary final : public USGBlueprintFunctionLibrary +{ + GENERATED_BODY() + +public: + UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Virtual Hand") + static USGVirtualHandComponent* GetVirtualHand(const ASGVirtualHandActor* VirtualHandActor); + + UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Virtual Hand") + static bool IsLeft(const ASGVirtualHandActor* VirtualHandActor); + + UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Virtual Hand") + static bool IsRight(const ASGVirtualHandActor* VirtualHandActor); + + UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Virtual Hand") + bool IsGloveConnected(const ASGVirtualHandActor* VirtualHandActor) const; +}; \ No newline at end of file diff --git a/Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandMeshComponentKismetLibrary.h b/Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandComponentKismetLibrary.h similarity index 77% rename from Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandMeshComponentKismetLibrary.h rename to Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandComponentKismetLibrary.h index 24266738..98f77d0f 100644 --- a/Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandMeshComponentKismetLibrary.h +++ b/Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandComponentKismetLibrary.h @@ -39,7 +39,6 @@ #include "Containers/Array.h" #include "Containers/Map.h" -#include "GameFramework/Actor.h" #include "Math/Rotator.h" #include "Math/Transform.h" #include "UObject/NameTypes.h" @@ -47,18 +46,18 @@ #include "SGKismet/SGBlueprintFunctionLibrary.h" #include "SGTypes/SGNameArray.h" -#include "SGVirtualHandMeshComponentKismetLibrary.generated.h" +#include "SGVirtualHandComponentKismetLibrary.generated.h" class USkeletalMeshComponent; -class USGVirtualHandMeshComponent; +class USGVirtualHandComponent; class USGHandPose; /** * Represents data of a user's hand required for forward kinematics. */ -UCLASS(meta=(ScriptName = "SesneGloveVirtualHandMeshComponentKismetLibrary")) -class SENSEGLOVEKISMET_API UVirtualHandMeshComponentKismetLibrary final : public USGBlueprintFunctionLibrary +UCLASS(meta=(ScriptName = "SesneGloveVirtualHandComponentKismetLibrary")) +class SENSEGLOVEKISMET_API UVirtualHandComponentKismetLibrary final : public USGBlueprintFunctionLibrary { GENERATED_BODY() @@ -76,39 +75,39 @@ public: static const FName& GetRightHandFingerBoneName(int32 Finger, int32 Joint); UFUNCTION(BlueprintPure, Category="SenseGlove | Components | Virtual Hand Mesh Component") - static bool IsLeft(const USGVirtualHandMeshComponent* VirtualHandMeshComponent); + static bool IsLeft(const USGVirtualHandComponent* VirtualHandComponent); UFUNCTION(BlueprintPure, Category="SenseGlove | Components | Virtual Hand Mesh Component") - static bool IsRight(const USGVirtualHandMeshComponent* VirtualHandMeshComponent); + static bool IsRight(const USGVirtualHandComponent* VirtualHandComponent); UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Virtual Hand Mesh Component") - static void SetRight(UPARAM(ref) USGVirtualHandMeshComponent* VirtualHandMeshComponent, bool bInRight); + static void SetRight(UPARAM(ref) USGVirtualHandComponent* VirtualHandComponent, bool bInRight); UFUNCTION(BlueprintPure, Category="SenseGlove | Components | Virtual Hand Mesh Component") - static bool IsHiddenInGameIfNoGloveDetected(const USGVirtualHandMeshComponent* VirtualHandMeshComponent); + static bool IsHiddenInGameIfNoGloveDetected(const USGVirtualHandComponent* VirtualHandComponent); UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Virtual Hand Mesh Component") - static void SetHiddenIfNoGloveDetected(UPARAM(ref) USGVirtualHandMeshComponent* VirtualHandMeshComponent, + static void SetHiddenIfNoGloveDetected(UPARAM(ref) USGVirtualHandComponent* VirtualHandComponent, bool bInHiddenIfNoGloveDetected); UFUNCTION(BlueprintPure, Category="SenseGlove | Components | Virtual Hand Mesh Component") - bool IsGloveConnected(const USGVirtualHandMeshComponent* VirtualHandMeshComponent) const; + bool IsGloveConnected(const USGVirtualHandComponent* VirtualHandComponent) const; UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Virtual Hand Mesh Component") - USGHandPose* GetHandPose(UPARAM(ref) USGVirtualHandMeshComponent* VirtualHandMeshComponent); + USGHandPose* GetHandPose(UPARAM(ref) USGVirtualHandComponent* VirtualHandComponent); UFUNCTION(BlueprintPure, Category="SenseGlove | Components | Virtual Hand Mesh Component") - const FName& GetFingerBoneName(const USGVirtualHandMeshComponent* VirtualHandMeshComponent, + const FName& GetFingerBoneName(const USGVirtualHandComponent* VirtualHandComponent, int32 Finger, int32 Joint) const; UFUNCTION(BlueprintPure, Category="SenseGlove | Components | Virtual Hand Mesh Component") - const FTransform& GetFingerBoneRefTransform(const USGVirtualHandMeshComponent* VirtualHandMeshComponent, + const FTransform& GetFingerBoneRefTransform(const USGVirtualHandComponent* VirtualHandComponent, int32 Finger, int32 Joint) const; UFUNCTION(BlueprintPure, Category="SenseGlove | Components | Virtual Hand Mesh Component") - FRotator GetFingerBoneRefRotation(const USGVirtualHandMeshComponent* VirtualHandMeshComponent, + FRotator GetFingerBoneRefRotation(const USGVirtualHandComponent* VirtualHandComponent, int32 Finger, int32 Joint) const; UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Virtual Hand Mesh Component") - TMap GetFingersBonesRotations(UPARAM(ref) USGVirtualHandMeshComponent* VirtualHandMeshComponent); + TMap GetFingersBonesRotations(UPARAM(ref) USGVirtualHandComponent* VirtualHandComponent); }; \ No newline at end of file diff --git a/Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandKismetLibrary.h b/Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandKismetLibrary.h deleted file mode 100644 index a089250c..00000000 --- a/Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandKismetLibrary.h +++ /dev/null @@ -1,129 +0,0 @@ -/** - * @file - * - * @author Mamadou Babaei - * - * @section LICENSE - * - * (The MIT License) - * - * Copyright (c) 2020 - 2023 SenseGlove - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * @section DESCRIPTION - * - * A data class containing the minimum required data for a hand's forward - * kinematics. - * Used in both kinematics and calibration. - */ - - -#pragma once - -#include "Containers/Array.h" -#include "Containers/Map.h" -#include "GameFramework/Actor.h" -#include "Math/Rotator.h" -#include "Math/Transform.h" -#include "UObject/NameTypes.h" - -#include "SGKismet/SGBlueprintFunctionLibrary.h" -#include "SGTypes/SGNameArray.h" - -#include "SGVirtualHandKismetLibrary.generated.h" - -class USkeletalMeshComponent; - -class ASGVirtualHand; -class USGHandPose; - -/** - * Represents data of a user's hand required for forward kinematics. - */ -UCLASS(meta=(ScriptName = "SesneGloveVirtualHandKismetLibrary")) -class SENSEGLOVEKISMET_API UVirtualHandKismetLibrary final : public USGBlueprintFunctionLibrary -{ - GENERATED_BODY() - -public: - UFUNCTION(BlueprintCallable, Category="SenseGlove | Game Framework | Virtual Hand") - static TArray GetLeftHandFingerBoneNames(); - - UFUNCTION(BlueprintCallable, Category="SenseGlove | Game Framework | Virtual Hand") - static TArray GetRightHandFingerBoneNames(); - - UFUNCTION(BlueprintCallable, Category="SenseGlove | Game Framework | Virtual Hand") - static const FName& GetLeftHandFingerBoneName(int32 Finger, int32 Joint); - - UFUNCTION(BlueprintCallable, Category="SenseGlove | Game Framework | Virtual Hand") - static const FName& GetRightHandFingerBoneName(int32 Finger, int32 Joint); - - UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Virtual Hand") - static USkeletalMeshComponent* GetMesh(const ASGVirtualHand* VirtualHand); - - UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Virtual Hand") - static bool IsLeft(const ASGVirtualHand* VirtualHand); - - UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Virtual Hand") - static bool IsRight(const ASGVirtualHand* VirtualHand); - - UFUNCTION(BlueprintCallable, Category="SenseGlove | Game Framework | Virtual Hand") - static void SetRight(UPARAM(ref) ASGVirtualHand* VirtualHand, bool bInRight); - - UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Virtual Hand") - static bool IsHiddenInGameIfNoGloveDetected(const ASGVirtualHand* VirtualHand); - - UFUNCTION(BlueprintCallable, Category="SenseGlove | Game Framework | Virtual Hand") - static void SetHiddenIfNoGloveDetected(UPARAM(ref) ASGVirtualHand* VirtualHand, bool bInHiddenIfNoGloveDetected); - - UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Virtual Hand") - static bool IsAnimateInEditor(const ASGVirtualHand* VirtualHand); - - UFUNCTION(BlueprintCallable, Category="SenseGlove | Game Framework | Virtual Hand") - static void SetAnimateInEditor(UPARAM(ref) ASGVirtualHand* VirtualHand, bool bInAnimateInEditor); - - UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Virtual Hand") - USkeletalMesh* GetHandMesh(const ASGVirtualHand* VirtualHand) const; - - UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Virtual Hand") - void SetHandMesh(UPARAM(ref) ASGVirtualHand* VirtualHand, - USkeletalMesh* VirtualHandMesh, bool bReinitPos) const; - - UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Virtual Hand") - USkeleton* GetHandSkeleton(const ASGVirtualHand* VirtualHand) const; - - UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Virtual Hand") - bool IsGloveConnected(const ASGVirtualHand* VirtualHand) const; - - UFUNCTION(BlueprintCallable, Category="SenseGlove | Game Framework | Virtual Hand") - USGHandPose* GetHandPose(UPARAM(ref) ASGVirtualHand* VirtualHand); - - UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Virtual Hand") - const FName& GetFingerBoneName(const ASGVirtualHand* VirtualHand, int32 Finger, int32 Joint) const; - - UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Virtual Hand") - const FTransform& GetFingerBoneRefTransform(const ASGVirtualHand* VirtualHand, int32 Finger, int32 Joint) const; - - UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Virtual Hand") - FRotator GetFingerBoneRefRotation(const ASGVirtualHand* VirtualHand, int32 Finger, int32 Joint) const; - - UFUNCTION(BlueprintCallable, Category="SenseGlove | Game Framework | Virtual Hand") - TMap GetFingersBonesRotations(UPARAM(ref) ASGVirtualHand* VirtualHand); -}; \ No newline at end of file