5#include "CoreMinimal.h"
6#include "Engine/Engine.h"
8#include "Algo/Reverse.h"
9#include "Components/SplineMeshComponent.h"
10#include "Components/SplineComponent.h"
12#include "Engine/DataAsset.h"
13#include "DrawDebugHelpers.h"
14#include "Components/LineBatchComponent.h"
15#include "Engine/EngineTypes.h"
16#include "Engine/EngineBaseTypes.h"
17#include "TimerManager.h"
18#include "VRGestureComponent.generated.h"
41USTRUCT(BlueprintType, Category =
"VRGestures")
48 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category =
"VRGesture|Advanced")
49 int Minimum_Gesture_Length;
52 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category =
"VRGesture|Advanced")
56 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGesture|Advanced")
61 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGesture|Advanced")
65 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGesture|Advanced")
69 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGesture|Advanced")
74 Minimum_Gesture_Length = 1;
75 firstThreshold = 20.0f;
76 FullThreshold = 20.0f;
79 bEnableScaling =
true;
83USTRUCT(BlueprintType, Category =
"VRGestures")
90 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGesture")
94 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGesture")
98 UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "VRGesture")
99 TArray<FVector> Samples;
101 UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "VRGesture")
104 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGesture")
110 GestureSize = FBox();
113 void CalculateSizeOfGesture(
bool bAllowResizing =
false,
float TargetExtentSize = 1.f)
116 for (
int i = 0; i < Samples.Num(); ++i)
118 NewSample = Samples[i];
119 GestureSize.Max.X = FMath::Max(NewSample.X, GestureSize.Max.X);
120 GestureSize.Max.Y = FMath::Max(NewSample.Y, GestureSize.Max.Y);
121 GestureSize.Max.Z = FMath::Max(NewSample.Z, GestureSize.Max.Z);
123 GestureSize.Min.X = FMath::Min(NewSample.X, GestureSize.Min.X);
124 GestureSize.Min.Y = FMath::Min(NewSample.Y, GestureSize.Min.Y);
125 GestureSize.Min.Z = FMath::Min(NewSample.Z, GestureSize.Min.Z);
130 FVector BoxSize = GestureSize.GetSize();
131 float Scaler = TargetExtentSize / BoxSize.GetMax();
133 for (
int i = 0; i < Samples.Num(); ++i)
135 Samples[i] *= Scaler;
138 GestureSize.Min *= Scaler;
139 GestureSize.Max *= Scaler;
147UCLASS(BlueprintType, Category =
"VRGestures")
154 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category =
"VRGestures")
157 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGestures")
158 float TargetGestureScale;
162 TargetGestureScale = 100.0f;
166 UFUNCTION(BlueprintCallable, Category =
"VRGestures")
167 void RecalculateGestures(
bool bScaleToDatabase = true);
170 UFUNCTION(BlueprintCallable, Category = "VRGestures")
171 void FillSplineWithGesture(UPARAM(ref)
FVRGesture &Gesture, USplineComponent * SplineComponent,
bool bCenterPointsOnSpline = true,
bool bScaleToBounds = false,
float OptionalBounds = 0.0f,
bool bUseCurvedPoints = true,
bool bFillInSplineMeshComponents = true, UStaticMesh * Mesh =
nullptr,
UMaterial * MeshMat =
nullptr);
174 UFUNCTION(BlueprintCallable, Category = "VRGestures")
175 bool ImportSplineAsGesture(USplineComponent * HostSplineComponent, FString GestureName,
bool bKeepSplineCurves = true,
float SegmentLen = 10.0f,
bool bScaleToDatabase = true);
180USTRUCT(BlueprintType, Category = "VRGestures")
187 USplineComponent* SplineComponent;
190 TArray<USplineMeshComponent*> SplineMeshes;
193 int NextIndexCleared;
196 void ClearLastPoint();
232 UFUNCTION(BlueprintImplementableEvent, Category =
"BaseVRCharacter")
233 void OnGestureDetected(uint8 GestureType, FString &DetectedGestureName,
int & DetectedGestureIndex,
UGesturesDatabase * GestureDatabase);
236 UPROPERTY(BlueprintAssignable, Category = "VRGestures")
237 FVRGestureDetectedSignature OnGestureDetected_Bind;
240 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGestures")
244 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGestures")
245 float SameSampleTolerance;
248 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGestures")
252 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGestures")
258 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGestures")
259 bool bDrawSplinesCurved;
262 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGestures")
263 bool bGetGestureInWorldSpace;
266 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGestures")
267 UStaticMesh* SplineMesh;
270 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGestures")
271 FVector2D SplineMeshScaler;
274 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGestures")
275 UMaterialInterface* SplineMaterial;
278 float RecordingDelta;
281 int RecordingBufferSize;
283 float RecordingClampingTolerance;
284 bool bRecordingFlattenGesture;
285 bool bDrawRecordingGesture;
286 bool bDrawRecordingGestureAsSpline;
287 bool bGestureChanged;
290 FTimerHandle TickGestureTimer_Handle;
293 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGestures")
296 UPROPERTY(BlueprintReadOnly, Category = "VRGestures")
300 UPROPERTY(BlueprintReadOnly, Category = "VRGestures")
303 inline
float GetGestureDistance(FVector Seq1, FVector Seq2,
bool bMirrorGesture = false)
307 return FVector::DistSquared(Seq1, FVector(Seq2.X, -Seq2.Y, Seq2.Z));
310 return FVector::DistSquared(Seq1, Seq2);
313 void BeginDestroy()
override;
316 UFUNCTION(BlueprintCallable, Category =
"VRGestures")
320 UFUNCTION(BlueprintCallable, Category = "VRGestures", meta = (WorldContext = "WorldContextObject"))
321 void DrawDebugGesture(
UObject* WorldContextObject, UPARAM(ref)FTransform& StartTransform,
FVRGesture GestureToDraw, FColor const& Color,
bool bPersistentLines = false, uint8 DepthPriority = 0,
float LifeTime = -1.f,
float Thickness = 0.f);
324 FTransform OriginatingTransform;
337 UFUNCTION(BlueprintCallable, Category = "VRGestures")
338 void BeginRecording(
bool bRunDetection,
bool bFlattenGesture = true,
bool bDrawGesture = true,
bool bDrawAsSpline = false,
int SamplingHTZ = 30,
int SampleBufferSize = 60,
float ClampingTolerance = 0.01f);
341 UFUNCTION(BlueprintCallable, Category = "VRGestures")
345 UFUNCTION(BlueprintCallable, Category = "VRGestures")
346 void ClearRecording();
349 UFUNCTION(BlueprintCallable, Category = "VRGestures")
350 void SaveRecording(UPARAM(ref)
FVRGesture &Recording, FString RecordingName,
bool bScaleRecordingToDatabase = true);
352 void CaptureGestureFrame();
EVRGestureState
UENUM(Blueprintable)
EVRGestureMirrorMode
UENUM(Blueprintable)
DECLARE_STATS_GROUP(TEXT("TICKGesture"), STATGROUP_TickGesture, STATCAT_Advanced)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_FourParams(FVRGestureDetectedSignature, uint8, GestureType, FString, DetectedGestureName, int, DetectedGestureIndex, UGesturesDatabase *, GestureDataBase)
UCLASS(BlueprintType, Category = "VRGestures")
TArray< FVRGesture > Gestures
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGestures")
float TargetGestureScale
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGestures")
UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = (VRExpansionPlugin))
UMaterialInterface * SplineMaterial
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGestures")
FVRGesture GestureLog
UPROPERTY(BlueprintReadOnly, Category = "VRGestures")
bool bRecordingFlattenGesture
UStaticMesh * SplineMesh
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGestures")
bool bDrawRecordingGestureAsSpline
AVRBaseCharacter * TargetCharacter
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGestures")
FTransform OriginatingTransform
EVRGestureState CurrentState
UPROPERTY(BlueprintReadOnly, Category = "VRGestures")
float SameSampleTolerance
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGestures")
bool bDrawRecordingGesture
FVRGestureSplineDraw RecordingGestureDraw
int maxSlope
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGestures")
FTimerHandle TickGestureTimer_Handle
FVRGestureDetectedSignature OnGestureDetected_Bind
UPROPERTY(BlueprintAssignable, Category = "VRGestures")
UGesturesDatabase * GesturesDB
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGestures")
FVector2D SplineMeshScaler
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGestures")
float GetGestureDistance(FVector Seq1, FVector Seq2, bool bMirrorGesture=false)
float RecordingClampingTolerance
bool bGetGestureInWorldSpace
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGestures")
EVRGestureMirrorMode MirroringHand
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGestures")
void OnGestureDetected(uint8 GestureType, FString &DetectedGestureName, int &DetectedGestureIndex, UGesturesDatabase *GestureDatabase)
UFUNCTION(BlueprintImplementableEvent, Category = "BaseVRCharacter")
bool bDrawSplinesCurved
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGestures")
USTRUCT(BlueprintType, Category = "VRGestures")
FVRGestureSettings GestureSettings
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGesture")
FBox GestureSize
UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "VRGesture")
TArray< FVector > Samples
UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "VRGesture")
uint8 GestureType
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGesture")
void CalculateSizeOfGesture(bool bAllowResizing=false, float TargetExtentSize=1.f)
FString Name
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGesture")
USTRUCT(BlueprintType, Category = "VRGestures")
EVRGestureMirrorMode MirrorMode
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGesture|Advanced")
float firstThreshold
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGesture|Advanced")
bool bEnableScaling
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGesture|Advanced")
float FullThreshold
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGesture|Advanced")
int Minimum_Gesture_Length
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGesture|Advanced")
bool bEnabled
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "VRGesture|Advanced")
USTRUCT(BlueprintType, Category = "VRGestures")
USplineComponent * SplineComponent
UPROPERTY()
TArray< USplineMeshComponent * > SplineMeshes
UPROPERTY()