5#include "CoreMinimal.h"
10#include "GameplayTagContainer.h"
11#include "GameplayTagAssetInterface.h"
12#include "Components/SceneComponent.h"
13#include "Components/SkeletalMeshComponent.h"
14#include "Components/PoseableMeshComponent.h"
15#include "Animation/AnimSequence.h"
16#include "Animation/AnimInstance.h"
17#include "Animation/AnimInstanceProxy.h"
18#include "Animation/PoseSnapshot.h"
20#include "HandSocketComponent.generated.h"
30 BeforeCustomVersionWasAdded = 0,
33 HandSocketStoringSetState = 1,
37 LatestVersion = VersionPlusOne - 1
64USTRUCT(BlueprintType, Category =
"VRExpansionLibrary")
71 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category =
"Settings")
75 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Settings")
78 FBoneReference ReferenceToConstruct;
83 DeltaPose = FQuat::Identity;
86 FORCEINLINE
bool operator==(
const FName&
Other)
const
88 return (BoneName ==
Other);
92UCLASS(Blueprintable, ClassGroup = (
VRExpansionPlugin), hideCategories = (
"Component Tick", Events, Physics, Lod,
"Asset User Data", Collision))
105 UPROPERTY(EditDefaultsOnly, Category =
"Hand Socket Data|Mirroring|Advanced")
106 TEnumAsByte<
EVRAxis::Type> MirrorAxis;
109 UPROPERTY(VisibleDefaultsOnly, Category = "Hand Socket Data|Mirroring|Advanced")
110 TEnumAsByte<
EVRAxis::Type> FlipAxis;
113 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Socket Data")
114 FTransform HandRelativePlacement;
117 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Socket Data")
121 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Hand Socket Data")
122 bool bDecoupleMeshPlacement;
126 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Socket Data")
131 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Socket Data")
132 bool bIgnoreAttachBone;
135 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Hand Socket Data")
136 bool bLeftHandDominant;
139 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Socket Data|Mirroring", meta = (
DisplayName = "Flip For Off Hand"))
140 bool bFlipForLeftHand;
143 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Socket Data|Mirroring", meta = (editcondition = "bFlipForLeftHand"))
144 bool bOnlyFlipRotation;
147 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Socket Data")
152 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Socket Data")
156 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Socket Data")
161 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Socket Data")
162 float OverrideDistance;
165 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Animation")
166 bool bUseCustomPoseDeltas;
169 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Animation")
174 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Animation")
175 UAnimSequence* HandTargetAnimation;
178 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Hand Visualization")
179 FVector MirroredScale;
181 FTransform GetBoneTransformAtTime(UAnimSequence* MyAnimSequence,
int BoneIdx,
bool bUseRawDataOnly);
184 UFUNCTION(BlueprintCallable, Category = "Hand Socket Data")
185 UAnimSequence* GetTargetAnimation();
194 UFUNCTION(BlueprintCallable, Category = "Hand Socket Data")
195 bool GetBlendedPoseSnapShot(FPoseSnapshot& PoseSnapShot,
USkeletalMeshComponent* TargetMesh =
nullptr,
bool bSkipRootBone = false,
bool bFlipHand = false);
205 UFUNCTION(BlueprintCallable, Category = "Hand Socket Data", meta = (bIgnoreSelf = "true"))
206 static
bool GetAnimationSequenceAsPoseSnapShot(UAnimSequence * InAnimationSequence, FPoseSnapshot& OutPoseSnapShot,
USkeletalMeshComponent* TargetMesh =
nullptr,
bool bSkipRootBone = false,
bool bFlipHand = false);
210 FTransform GetHandRelativePlacement();
212 inline
void MirrorHandTransform(FTransform& ReturnTrans, FTransform& relTrans)
214 if (bOnlyFlipRotation)
216 ReturnTrans.SetTranslation(ReturnTrans.GetTranslation() - relTrans.GetTranslation());
217 ReturnTrans.Mirror(GetAsEAxis(MirrorAxis), GetCrossAxis());
218 ReturnTrans.SetTranslation(ReturnTrans.GetTranslation() + relTrans.GetTranslation());
222 ReturnTrans.Mirror(GetAsEAxis(MirrorAxis), GetCrossAxis());
226 inline TEnumAsByte<EAxis::Type> GetAsEAxis(TEnumAsByte<EVRAxis::Type> InAxis)
248 inline FVector GetMirrorVector()
254 return FVector::RightVector;
258 return FVector::UpVector;
263 return FVector::ForwardVector;
268 inline FVector GetFlipVector()
274 return FVector::RightVector;
278 return FVector::UpVector;
283 return FVector::ForwardVector;
288 inline TEnumAsByte<EAxis::Type> GetCrossAxis()
291 FVector SignVec = MirroredScale.GetSignVector();
297 else if (SignVec.Z < 0)
301 else if (SignVec.Y < 0)
306 return GetAsEAxis(FlipAxis);
328 UFUNCTION(BlueprintCallable, Category =
"Hand Socket Data")
329 FTransform GetMeshRelativeTransform(
bool bIsRightHand,
bool bUseParentScale = false,
bool bUseMirrorScale = false);
333 UFUNCTION(BlueprintCallable, Category = "Hand Socket Data")
336 if (
AActor* OwningActor = Cast<AActor>(ObjectToCheck))
338 if (
USceneComponent* OwningRoot = Cast<USceneComponent>(OwningActor->GetRootComponent()))
340 TArray<USceneComponent*> AttachChildren = OwningRoot->GetAttachChildren();
345 return Cast<UHandSocketComponent>(AttachChild);
350 else if (
USceneComponent* OwningRoot = Cast<USceneComponent>(ObjectToCheck))
352 TArray<USceneComponent*> AttachChildren = OwningRoot->GetAttachChildren();
355 if (AttachChild && AttachChild->IsA<
UHandSocketComponent>() && AttachChild->GetFName() == SocketName)
357 return Cast<UHandSocketComponent>(AttachChild);
368 virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
override;
370#if WITH_EDITORONLY_DATA
371 static void AddReferencedObjects(
UObject* InThis, FReferenceCollector& Collector);
372 virtual void OnComponentDestroyed(
bool bDestroyingHierarchy)
override;
373 void PoseVisualizationToAnimation(
bool bForceRefresh =
false);
379 virtual void Serialize(FArchive& Ar)
override;
380 virtual void OnRegister()
override;
381 virtual void PreReplication(IRepChangedPropertyTracker& ChangedPropertyTracker)
override;
388 virtual void GetOwnedGameplayTags(FGameplayTagContainer& TagContainer)
const override
390 TagContainer = GameplayTags;
394 UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category =
"GameplayTags")
395 FGameplayTagContainer GameplayTags;
400 UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface|Replication")
401 bool bRepGameplayTags;
404 UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface|Replication")
405 bool bReplicateMovement;
408#if WITH_EDITORONLY_DATA
411 class UPoseableMeshComponent* HandVisualizerComponent;
413 UPROPERTY(EditAnywhere, BlueprintReadOnly, Transient, Category =
"Hand Visualization")
414 class USkeletalMesh* VisualizationMesh;
417 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Hand Visualization")
418 bool bShowVisualizationMesh;
421 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Hand Visualization")
422 bool bMirrorVisualizationMesh;
426 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Hand Visualization")
427 bool bShowRangeVisualization;
429 void PositionVisualizationMesh();
430 void HideVisualizationMesh();
434#if WITH_EDITORONLY_DATA
436 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
"Hand Visualization")
442UCLASS(transient, Blueprintable, hideCategories = AnimInstance, BlueprintType)
449 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, transient, Category =
"Socket Data")
452 virtual void NativeInitializeAnimation()
override
454 Super::NativeInitializeAnimation();
456 OwningSocket = Cast<UHandSocketComponent>(GetOwningComponent()->GetAttachParent());
DECLARE_LOG_CATEGORY_EXTERN(LogVRHandSocketComponent, Log, All)
UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = MotionController)
UCLASS(transient, Blueprintable, hideCategories = AnimInstance, BlueprintType)
virtual void NativeInitializeAnimation() override
UHandSocketComponent * OwningSocket
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, transient, Category = "Socket Data")
UCLASS(Blueprintable, ClassGroup = (VRExpansionPlugin), hideCategories = ("Component Tick",...
TArray< FBPVRHandPoseBonePair > CustomPoseDeltas
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Animation")
bool bUseCustomPoseDeltas
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Animation")
FGameplayTagContainer GameplayTags
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "GameplayTags")
bool bOnlyFlipRotation
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Socket Data|Mirroring",...
bool bOnlySnapMesh
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Socket Data")
TEnumAsByte< EVRAxis::Type > FlipAxis
UPROPERTY(VisibleDefaultsOnly, Category = "Hand Socket Data|Mirroring|Advanced")
bool bDisabled
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Socket Data")
TEnumAsByte< EAxis::Type > GetCrossAxis()
void MirrorHandTransform(FTransform &ReturnTrans, FTransform &relTrans)
bool bIgnoreAttachBone
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Socket Data")
UAnimSequence * HandTargetAnimation
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Animation")
TEnumAsByte< EAxis::Type > GetAsEAxis(TEnumAsByte< EVRAxis::Type > InAxis)
bool bMatchRotation
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Socket Data")
float OverrideDistance
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Socket Data")
bool bFlipForLeftHand
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Socket Data|Mirroring",...
bool bRepGameplayTags
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface|Replication")
bool bLeftHandDominant
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Hand Socket Data")
FName SlotPrefix
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Socket Data")
bool bDecoupleMeshPlacement
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Hand Socket Data")
static UHandSocketComponent * GetHandSocketComponentFromObject(UObject *ObjectToCheck, FName SocketName)
UFUNCTION(BlueprintCallable, Category = "Hand Socket Data")
TEnumAsByte< EVRAxis::Type > MirrorAxis
UPROPERTY(EditDefaultsOnly, Category = "Hand Socket Data|Mirroring|Advanced")
virtual void GetOwnedGameplayTags(FGameplayTagContainer &TagContainer) const override
FVector GetMirrorVector()
bool bAlwaysInRange
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Socket Data")
FTransform HandRelativePlacement
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Socket Data")
FVector MirroredScale
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Hand Visualization")
bool bReplicateMovement
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface|Replication")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
FName BoneName
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Settings")
FBoneReference ReferenceToConstruct
FQuat DeltaPose
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Settings")
FORCEINLINE bool operator==(const FName &Other) const
FVRHandSocketCustomVersion()