203 lines
6.3 KiB
C++
203 lines
6.3 KiB
C++
/**
|
|
* @file
|
|
*
|
|
* @author Mamadou Babaei <mamadou@senseglove.com>
|
|
*
|
|
* @section LICENSE
|
|
*
|
|
* (The MIT License)
|
|
*
|
|
* Copyright (c) 2020 - 2026 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 "HeadMountedDisplayTypes.h"
|
|
#include "Math/Rotator.h"
|
|
#include "Math/Transform.h"
|
|
#include "Misc/AssertionMacros.h"
|
|
#include "ReferenceSkeleton.h"
|
|
#include "Runtime/Launch/Resources/Version.h"
|
|
#include "Templates/UniquePtr.h"
|
|
#include "UObject/NameTypes.h"
|
|
|
|
#include "SGSettings/SGVirtualHandSettings.h"
|
|
#include "SGSettings/SGVirtualHandSettingsOverrides.h"
|
|
|
|
#include "SGVirtualHandComponent.generated.h"
|
|
|
|
class USphereComponent;
|
|
class USkeletalMesh;
|
|
|
|
class USGHapticGlove;
|
|
class USGWristTrackerComponent;
|
|
|
|
UCLASS(Config=Engine, Blueprintable, ClassGroup=(SenseGlove), hidecategories=(Object, "Mesh|SkeletalAsset"),
|
|
editinlinenew, meta=(BlueprintSpawnableComponent))
|
|
class SENSEGLOVE_API USGVirtualHandComponent : public USkeletalMeshComponent
|
|
{
|
|
GENERATED_UCLASS_BODY()
|
|
|
|
public:
|
|
DECLARE_EVENT_OneParam(USGVirtualHandComponent, FHandVisibilityChangedEvent, bool bNewVisibiliy);
|
|
|
|
FHandVisibilityChangedEvent& OnHandVisibilityChanged()
|
|
{
|
|
return HandVisibilityChangedEvent;
|
|
};
|
|
|
|
private:
|
|
FHandVisibilityChangedEvent HandVisibilityChangedEvent;
|
|
|
|
public:
|
|
static const TArray<FName>& GetLeftHandBoneNames();
|
|
static const TArray<FName>& GetRightHandBoneNames();
|
|
|
|
static const FName& GetLeftHandBoneName(int32 Joint);
|
|
static const FName& GetRightHandBoneName(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"))
|
|
bool bRight;
|
|
|
|
/**
|
|
* Overrides the plugin's virtual hand settings.
|
|
*/
|
|
UPROPERTY(EditAnywhere, Category = "SenseGlove", meta=(AllowPrivateAccess="false"))
|
|
FSGVirtualHandSettingsOverrides VirtualHandSettingsOverrides;
|
|
|
|
private:
|
|
UPROPERTY(Transient)
|
|
USGWristTrackerComponent* WristTracker;
|
|
|
|
protected:
|
|
UFUNCTION(BlueprintNativeEvent, Category="SenseGlove | Components | Virtual Hand Component")
|
|
void OnHandVisibilityChanged(bool bNewVisibility);
|
|
|
|
public:
|
|
FORCEINLINE bool IsLeft() const
|
|
{
|
|
return !IsRight();
|
|
}
|
|
|
|
FORCEINLINE bool IsRight() const
|
|
{
|
|
return bRight;
|
|
}
|
|
|
|
void SetRight(const bool bInRight);
|
|
|
|
FORCEINLINE bool OverridesPluginVirtualHandSettings() const
|
|
{
|
|
return VirtualHandSettingsOverrides.bOverridePluginSettings;
|
|
}
|
|
|
|
FORCEINLINE const FSGVirtualHandSettingsOverrides& GetVirtualHandSettingsOverrides() const
|
|
{
|
|
return VirtualHandSettingsOverrides;
|
|
}
|
|
|
|
void SetVirtualHandSettingsOverrides(const FSGVirtualHandSettingsOverrides& InVirtualHandSettingsOverrides);
|
|
|
|
FSGVirtualHandSettings GetVirtualHandSettings() const;
|
|
|
|
public:
|
|
FORCEINLINE void SetWristTracker(USGWristTrackerComponent* InWristTracker)
|
|
{
|
|
WristTracker = InWristTracker;
|
|
}
|
|
|
|
public:
|
|
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
|
|
virtual void SetAnimInstanceClass(class UClass* NewClass) override;
|
|
#else /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
|
virtual void SetAnimClass(class UClass* NewClass) override;
|
|
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
|
|
|
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;
|
|
USGHapticGlove* GetConnectedGlove() const;
|
|
|
|
UE_DEPRECATED(5.5, "Deprecated by UE 5.5 in favor of GetMotionControllerState and GetHandTrackingState")
|
|
const FXRMotionControllerData& GetMotionControllerData() const;
|
|
|
|
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
|
|
const FXRHandTrackingState& GetHandTrackingState() const;
|
|
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
|
|
|
public:
|
|
const TArray<FName>& GetHandBoneNames() const;
|
|
const FName& GetHandBoneName(int32 Joint) const;
|
|
|
|
const FTransform& GetHandBoneRefTransform(const FName& BoneName) const;
|
|
const FTransform& GetHandBoneRefTransform(int32 Joint) const;
|
|
|
|
const FTransform& GetHandRootBoneRefTransform() const;
|
|
|
|
FRotator GetHandBoneRefRotation(const FName& BoneName) const;
|
|
FRotator GetHandBoneRefRotation(int32 Joint) const;
|
|
};
|