328 lines
9.8 KiB
C++
328 lines
9.8 KiB
C++
/**
|
|
* @file
|
|
*
|
|
* @author Mamadou Babaei <mamadou@senseglove.com>
|
|
*
|
|
* @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 "Components/SkeletalMeshComponent.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 "SGSettings/SGDebugVirtualHandSettings.h"
|
|
|
|
#include "SGVirtualHandComponent.generated.h"
|
|
|
|
class USphereComponent;
|
|
class USkeletalMesh;
|
|
|
|
class USGHandPose;
|
|
class USGHapticGlove;
|
|
class USGWristTrackerComponent;
|
|
|
|
UCLASS(Config=Engine, Blueprintable, ClassGroup=(Rendering, Common), hidecategories=(Object, "Mesh|SkeletalAsset"),
|
|
editinlinenew, meta=(BlueprintSpawnableComponent))
|
|
class SENSEGLOVE_API USGVirtualHandComponent : public USkeletalMeshComponent
|
|
{
|
|
GENERATED_UCLASS_BODY()
|
|
|
|
public:
|
|
static const TArray<TArray<FName>>& GetLeftHandFingerBoneNames();
|
|
static const TArray<TArray<FName>>& 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<FImpl, FImplDeleter> Pimpl;
|
|
FImplDeleter PimplDeleter;
|
|
|
|
private:
|
|
UPROPERTY(EditAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false"))
|
|
uint8 bRight : 1;
|
|
|
|
UPROPERTY(EditAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false"))
|
|
uint8 bHiddenInGameIfNoGloveDetected : 1;
|
|
|
|
UPROPERTY(EditAnywhere, Category="SenseGlove | Haptics", meta=(AllowPrivateAccess="false"))
|
|
uint8 bAutoStopAllHapticsOnEndPlay : 1;
|
|
|
|
UPROPERTY(EditAnywhere, Category="SenseGlove | Grab", meta=(AllowPrivateAccess="false"))
|
|
FName GrabSocketName;
|
|
|
|
UPROPERTY(EditAnywhere, Category="SenseGlove | Grab", meta=(AllowPrivateAccess="false"))
|
|
FVector DefaultFingertipsGrabColliderSize;
|
|
|
|
UPROPERTY(EditAnywhere, Category="SenseGlove | Grab", meta=(AllowPrivateAccess="false"))
|
|
FName ThumbFingertipGrabSocketName;
|
|
|
|
UPROPERTY(EditAnywhere, Category="SenseGlove | Grab", meta=(AllowPrivateAccess="false"))
|
|
FName IndexFingertipGrabSocketName;
|
|
|
|
UPROPERTY(EditAnywhere, Category="SenseGlove | Grab", meta=(AllowPrivateAccess="false"))
|
|
FName MiddleFingertipGrabSocketName;
|
|
|
|
UPROPERTY(EditAnywhere, Category="SenseGlove | Touch", meta=(AllowPrivateAccess="false"))
|
|
FVector DefaultFingertipsTouchColliderSize;
|
|
|
|
UPROPERTY(EditAnywhere, Category="SenseGlove | Touch", meta=(AllowPrivateAccess="false"))
|
|
FName ThumbFingertipTouchSocketName;
|
|
|
|
UPROPERTY(EditAnywhere, Category="SenseGlove | Touch", meta=(AllowPrivateAccess="false"))
|
|
FName IndexFingertipTouchSocketName;
|
|
|
|
UPROPERTY(EditAnywhere, Category="SenseGlove | Touch", meta=(AllowPrivateAccess="false"))
|
|
FName MiddleFingertipTouchSocketName;
|
|
|
|
UPROPERTY(EditAnywhere, Category="SenseGlove | Touch", meta=(AllowPrivateAccess="false"))
|
|
FName RingFingertipTouchSocketName;
|
|
|
|
UPROPERTY(EditAnywhere, Category="SenseGlove | Touch", meta=(AllowPrivateAccess="false"))
|
|
FName PinkyFingertipTouchSocketName;
|
|
|
|
UPROPERTY(EditAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false"))
|
|
FSGDebugVirtualHandSettings DebugVirtualHandSettings;
|
|
|
|
private:
|
|
UPROPERTY(Transient)
|
|
USGHapticGlove* Glove;
|
|
|
|
UPROPERTY(Transient)
|
|
USGWristTrackerComponent* WristTracker;
|
|
|
|
public:
|
|
FORCEINLINE bool IsLeft() const
|
|
{
|
|
return !IsRight();
|
|
}
|
|
|
|
FORCEINLINE bool IsRight() const
|
|
{
|
|
return !!bRight;
|
|
}
|
|
|
|
void SetRight(const bool bInRight);
|
|
|
|
FORCEINLINE const FName& GetMiddleFingertipTouchSocketName() const
|
|
{
|
|
return MiddleFingertipTouchSocketName;
|
|
}
|
|
|
|
FORCEINLINE void SetMiddleFingertipTouchSocketName(const FName& SocketName)
|
|
{
|
|
MiddleFingertipTouchSocketName = SocketName;
|
|
}
|
|
|
|
FORCEINLINE bool AutoStopsAllHapticsOnEndPlay() const
|
|
{
|
|
return !!bAutoStopAllHapticsOnEndPlay;
|
|
}
|
|
|
|
FORCEINLINE void SetAutoStopAllHapticsOnEndPlay(const bool bInAutoStopAllHapticsOnEndPlay)
|
|
{
|
|
bAutoStopAllHapticsOnEndPlay = bInAutoStopAllHapticsOnEndPlay;
|
|
}
|
|
|
|
FORCEINLINE const FName& GetGrabSocketName() const
|
|
{
|
|
return GrabSocketName;
|
|
}
|
|
|
|
FORCEINLINE const FVector& GetDefaultFingertipsGrabColliderSize() const
|
|
{
|
|
return DefaultFingertipsGrabColliderSize;
|
|
}
|
|
|
|
FORCEINLINE const FName& GetThumbFingertipGrabSocketName() const
|
|
{
|
|
return ThumbFingertipGrabSocketName;
|
|
}
|
|
|
|
FORCEINLINE void SetThumbFingertipGrabSocketName(const FName& SocketName)
|
|
{
|
|
ThumbFingertipGrabSocketName = SocketName;
|
|
}
|
|
|
|
FORCEINLINE const FName& GetIndexFingertipGrabSocketName() const
|
|
{
|
|
return IndexFingertipGrabSocketName;
|
|
}
|
|
|
|
FORCEINLINE void SetIndexFingertipGrabSocketName(const FName& SocketName)
|
|
{
|
|
IndexFingertipGrabSocketName = SocketName;
|
|
}
|
|
|
|
FORCEINLINE const FName& GetMiddleFingertipGrabSocketName() const
|
|
{
|
|
return MiddleFingertipGrabSocketName;
|
|
}
|
|
|
|
FORCEINLINE void SetMiddleFingertipGrabSocketName(const FName& SocketName)
|
|
{
|
|
MiddleFingertipGrabSocketName = SocketName;
|
|
}
|
|
|
|
FORCEINLINE const FVector& GetDefaultFingertipsTouchColliderSize() const
|
|
{
|
|
return DefaultFingertipsTouchColliderSize;
|
|
}
|
|
|
|
FORCEINLINE const FName& GetThumbFingertipTouchSocketName() const
|
|
{
|
|
return ThumbFingertipTouchSocketName;
|
|
}
|
|
|
|
FORCEINLINE void SetThumbFingertipTouchSocketName(const FName& SocketName)
|
|
{
|
|
ThumbFingertipTouchSocketName = SocketName;
|
|
}
|
|
|
|
FORCEINLINE const FName& GetIndexFingertipTouchSocketName() const
|
|
{
|
|
return IndexFingertipTouchSocketName;
|
|
}
|
|
|
|
FORCEINLINE void SetIndexFingertipTouchSocketName(const FName& SocketName)
|
|
{
|
|
IndexFingertipTouchSocketName = SocketName;
|
|
}
|
|
|
|
FORCEINLINE const FName& GetRingFingertipTouchSocketName() const
|
|
{
|
|
return RingFingertipTouchSocketName;
|
|
}
|
|
|
|
FORCEINLINE void SetRingFingertipTouchSocketName(const FName& SocketName)
|
|
{
|
|
RingFingertipTouchSocketName = SocketName;
|
|
}
|
|
|
|
FORCEINLINE const FName& GetPinkyFingertipTouchSocketName() const
|
|
{
|
|
return PinkyFingertipTouchSocketName;
|
|
}
|
|
|
|
FORCEINLINE void SetPinkyFingertipTouchSocketName(const FName& SocketName)
|
|
{
|
|
PinkyFingertipTouchSocketName = SocketName;
|
|
}
|
|
|
|
FORCEINLINE const FSGDebugVirtualHandSettings& GetDebugVirtualHandSettings() const
|
|
{
|
|
return DebugVirtualHandSettings;
|
|
}
|
|
|
|
FORCEINLINE FSGDebugVirtualHandSettings& GetDebugVirtualHandSettings()
|
|
{
|
|
return DebugVirtualHandSettings;
|
|
}
|
|
|
|
FORCEINLINE void SetDebugVirtualHandSettings(const FSGDebugVirtualHandSettings& InDebugVirtualHandSettings)
|
|
{
|
|
DebugVirtualHandSettings = InDebugVirtualHandSettings;
|
|
}
|
|
|
|
FORCEINLINE bool IsHiddenInGameIfNoGloveDetected() const
|
|
{
|
|
return !!bHiddenInGameIfNoGloveDetected;
|
|
}
|
|
|
|
FORCEINLINE void SetHiddenIfNoGloveDetected(const bool bInHiddenIfNoGloveDetected)
|
|
{
|
|
bHiddenInGameIfNoGloveDetected = bInHiddenIfNoGloveDetected;
|
|
}
|
|
|
|
FORCEINLINE void SetWristTracker(USGWristTrackerComponent* InWristTracker)
|
|
{
|
|
WristTracker = InWristTracker;
|
|
}
|
|
|
|
public:
|
|
virtual void SetAnimClass(class UClass* NewClass) override;
|
|
|
|
virtual void PostInitProperties() override;
|
|
|
|
#if WITH_EDITOR
|
|
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
|
|
#endif /* WITH_EDITOR */
|
|
|
|
virtual void InitializeComponent() override;
|
|
|
|
virtual void UninitializeComponent() override;
|
|
|
|
virtual void BeginPlay() override;
|
|
|
|
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
|
|
|
|
virtual void TickComponent(float DeltaTime,
|
|
enum ELevelTick TickType,
|
|
FActorComponentTickFunction* ThisTickFunction) override;
|
|
|
|
virtual void SetSkeletalMesh(USkeletalMesh* NewMesh, bool bReinitPose = true) override;
|
|
|
|
protected:
|
|
virtual void EditorTick(float DeltaTime,
|
|
enum ELevelTick TickType,
|
|
FActorComponentTickFunction* ThisTickFunction);
|
|
|
|
public:
|
|
bool IsGloveConnected() const;
|
|
|
|
FORCEINLINE USGHapticGlove* GetConnectedGlove() const
|
|
{
|
|
return Glove;
|
|
}
|
|
|
|
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<FName, FRotator> GetFingersBonesRotations();
|
|
}; |