VR Tunnelling Pro UE4
Plug-and-Play VR Comfort
VRTPMobile.h
1 #pragma once
2 
3 #include "CoreMinimal.h"
4 #include "Components/ActorComponent.h"
5 #include "Components/PrimitiveComponent.h"
6 #include "Components/SceneCaptureComponentCube.h"
7 #include "Engine/TextureRenderTargetCube.h"
8 #include "Engine/DataAsset.h"
9 #include "Engine/TextureCube.h"
10 #include "VRTPMobile.generated.h"
11 
13 UENUM(BlueprintType)
14 enum class EVRTPMBackgroundMode : uint8
15 {
16  MM_COLOR UMETA(DisplayName = "Color"),
17  MM_SKYBOX UMETA(DisplayName = "Skybox")
18 };
19 
21 UENUM(BlueprintType)
22 enum class EVRTPMMaskMode : uint8
23 {
24  MM_OFF UMETA(DisplayName = "Off"),
25  MM_MASK UMETA(DisplayName = "Mask"),
26  MM_WINDOW UMETA(DisplayName = "Window"),
27  MM_PORTAL UMETA(DisplayName = "Portal"),
28 };
29 
31 USTRUCT(BlueprintType)
33 {
34  GENERATED_USTRUCT_BODY()
35 
36 
37  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Capture")
38  TSubclassOf<class AActor> SkyboxBlueprint;
39 
41  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Capture")
42  UTextureCube* CubeMapOverride;
43 
45  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Post Process")
46  UMaterial* PostProcessMaterial;
47 
49  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Iris")
50  UStaticMesh* IrisMesh;
51 
53  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Effect Settings")
54  FLinearColor EffectColor;
55 
57  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Effect Settings", meta = (ClampMin = "0.0", ClampMax = "1.0"))
58  float EffectCoverage;
59 
61  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Effect Settings", meta = (ClampMin = "0.0", ClampMax = "10.0"))
62  float EffectFeather;
63 
65  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Effect Settings")
66  EVRTPMBackgroundMode BackgroundMode;
67 
69  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Effect Settings")
70  bool ApplyEffectColor;
71 
73  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Effect Settings")
74  bool ForceEffect;
75 
77  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Effect Settings|Mask Settings")
78  EVRTPMMaskMode MaskMode;
79 
81  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Effect Settings|Mask Settings", meta = (ClampMin = "0", ClampMax = "255"))
82  int32 StencilIndex;
83 
85  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Motion Settings|Angular Velocity")
86  bool bUseAngularVelocity;
87 
89  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Motion Settings|Angular Velocity", meta = (ClampMin = "0.0", ClampMax = "10.0"))
90  float AngularStrength;
91 
93  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Motion Settings|Angular Velocity", meta = (ClampMin = "0.0", ClampMax = "180.0"))
94  float AngularMin;
95 
97  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Motion Settings|Angular Velocity", meta = (ClampMin = "0.0", ClampMax = "180.0"))
98  float AngularMax;
99 
101  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Motion Settings|Angular Velocity", meta = (ClampMin = "0.0", ClampMax = "1.0"))
102  float AngularSmoothing;
103 
105  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Motion Settings|Velocity")
106  bool bUseVelocity;
107 
109  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Motion Settings|Velocity", meta = (ClampMin = "0.0", ClampMax = "10.0"))
110  float VelocityStrength;
111 
113  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Motion Settings|Velocity", meta = (ClampMin = "0.0", ClampMax = "1000.0"))
114  float VelocityMin;
115 
117  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Motion Settings|Velocity", meta = (ClampMin = "0.0", ClampMax = "1000.0"))
118  float VelocityMax;
119 
121  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Motion Settings|Velocity", meta = (ClampMin = "0.0", ClampMax = "1.0"))
122  float VelocitySmoothing;
123 
125  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Motion Settings|Acceleration")
126  bool bUseAcceleration;
127 
129  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Motion Settings|Acceleration", meta = (ClampMin = "0.0", ClampMax = "10.0"))
130  float AccelerationStrength;
131 
133  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Motion Settings|Acceleration", meta = (ClampMin = "0.0", ClampMax = "1000.0"))
134  float AccelerationMin;
135 
137  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Motion Settings|Acceleration", meta = (ClampMin = "0.0", ClampMax = "1000.0"))
138  float AccelerationMax;
139 
141  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Motion Settings|Acceleration", meta = (ClampMin = "0.0", ClampMax = "1.0"))
142  float AccelerationSmoothing;
143 
144  FVRTPMPreset()
145  {
146  SkyboxBlueprint = NULL;
147  CubeMapOverride = NULL;
148  PostProcessMaterial = NULL;
149  IrisMesh = NULL;
150  EffectColor = FLinearColor::Black;
151  EffectCoverage = 0;
152  EffectFeather = 0;
153  BackgroundMode = EVRTPMBackgroundMode::MM_COLOR;
154  ApplyEffectColor = false;
155  ForceEffect = false;
156  MaskMode = EVRTPMMaskMode::MM_OFF;
157  StencilIndex = 200;
158  bUseAngularVelocity = false;
159  AngularStrength = 0;
160  AngularMin = 0;
161  AngularMax = 0;
162  AngularSmoothing = 0;
163  bUseVelocity = false;
164  VelocityStrength = 0;
165  VelocityMin = 0;
166  VelocityMax = 0;
167  VelocitySmoothing = 0;
168  bUseAcceleration = false;
169  AccelerationStrength = 0;
170  AccelerationMin = 0;
171  AccelerationMax = 0;
172  AccelerationSmoothing = 0;
173  }
174 };
175 
177 UCLASS()
178 class UVRTPMPresetData : public UDataAsset
179 {
180  GENERATED_BODY()
181 
182 public:
184  UPROPERTY(EditAnywhere)
186 };
187 
189 UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = MotionController, HideCategories = ("VRTunnellingProMobile"))
190 class UVRTunnellingProMobile : public UActorComponent
191 {
192  GENERATED_BODY()
193 
194 public:
195 
197 
198 #if WITH_EDITOR
199  virtual void PreEditChange(UProperty* PropertyAboutToChange) override;
200  virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
201 #endif
202  virtual void OnComponentDestroyed(bool bDestroyingHierarchy) override;
203 
205  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Tunnelling|Effect Preset")
207 
209  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Tunnelling|Effect Preset")
210  bool bEnablePreset;
211 
213  UPROPERTY(EditAnywhere, BlueprintReadWrite, AdvancedDisplay, Category = "VR Tunnelling")
214  TSubclassOf<class AActor> SkyboxBlueprint;
215  UPROPERTY(EditAnywhere)
216  TSubclassOf<class AActor> SkyboxBlueprintSwap;
217 
219  UPROPERTY(EditAnywhere, BlueprintReadWrite, AdvancedDisplay, Category = "VR Tunnelling")
220  UTextureCube* CubeMapOverride;
221  UPROPERTY(EditAnywhere)
222  UTextureCube* CubeMapOverrideSwap;
223 
225  UPROPERTY(EditAnywhere, BlueprintReadWrite, AdvancedDisplay, Category = "VR Tunnelling")
226  UMaterial* PostProcessMaterial;
227  UPROPERTY(EditAnywhere)
228  UMaterial* PostProcessMaterialSwap;
229 
231  UPROPERTY(EditAnywhere, BlueprintReadWrite, AdvancedDisplay, Category = "VR Tunnelling")
232  UStaticMesh* IrisMesh;
233  UPROPERTY(EditAnywhere)
234  UStaticMesh* IrisMeshSwap;
235 
237  UPROPERTY(EditAnywhere, BlueprintReadWrite, SimpleDisplay, Category = "VR Tunnelling|Effect Settings")
238  FLinearColor EffectColor;
239  UPROPERTY(EditAnywhere)
240  FLinearColor EffectColorSwap;
241 
243  UPROPERTY(EditAnywhere, BlueprintReadWrite, SimpleDisplay, Category = "VR Tunnelling|Effect Settings", meta = (ClampMin = "0.0", ClampMax = "1.0"))
244  float EffectCoverage;
245  UPROPERTY(EditAnywhere)
246  float EffectCoverageSwap;
247 
249  UPROPERTY(EditAnywhere, BlueprintReadWrite, SimpleDisplay, Category = "VR Tunnelling|Effect Settings", meta = (ClampMin = "0.0", ClampMax = "10.0"))
250  float EffectFeather;
251  UPROPERTY(EditAnywhere)
252  float EffectFeatherSwap;
253 
255  UPROPERTY(EditAnywhere, BlueprintReadWrite, SimpleDisplay, Category = "VR Tunnelling|Effect Settings")
256  EVRTPMBackgroundMode BackgroundMode;
257  UPROPERTY(EditAnywhere)
258  EVRTPMBackgroundMode BackgroundModeSwap;
259 
261  UPROPERTY(EditAnywhere, BlueprintReadWrite, SimpleDisplay, Category = "VR Tunnelling|Effect Settings")
262  bool ApplyEffectColor;
263  UPROPERTY(EditAnywhere)
264  bool ApplyEffectColorSwap;
265 
267  UPROPERTY(EditAnywhere, BlueprintReadWrite, SimpleDisplay, Category = "VR Tunnelling|Effect Settings")
268  bool ForceEffect;
269  UPROPERTY(EditAnywhere)
270  bool ForceEffectSwap;
271 
273  UPROPERTY(EditAnywhere, BlueprintReadWrite, SimpleDisplay, Category = "VR Tunnelling|Effect Settings|Mask Settings")
274  EVRTPMMaskMode MaskMode;
275  UPROPERTY(EditAnywhere)
276  EVRTPMMaskMode MaskModeSwap;
277 
279  UPROPERTY(EditAnywhere, BlueprintReadWrite, SimpleDisplay, Category = "VR Tunnelling|Effect Settings|Mask Settings", meta = (ClampMin = "0", ClampMax = "255"))
280  int32 StencilIndex;
281  UPROPERTY(EditAnywhere)
282  int32 StencilIndexSwap;
283 
285  UPROPERTY(EditAnywhere, BlueprintReadWrite, SimpleDisplay, Category = "VR Tunnelling|Motion Settings|Angular Velocity")
286  bool bUseAngularVelocity;
287  UPROPERTY(EditAnywhere)
288  bool bUseAngularVelocitySwap;
289 
291  UPROPERTY(EditAnywhere, BlueprintReadWrite, SimpleDisplay, Category = "VR Tunnelling|Motion Settings|Angular Velocity", meta = (ClampMin = "0.0", ClampMax = "10.0"))
292  float AngularStrength;
293  UPROPERTY(EditAnywhere)
294  float AngularStrengthSwap;
295 
297  UPROPERTY(EditAnywhere, BlueprintReadWrite, SimpleDisplay, Category = "VR Tunnelling|Motion Settings|Angular Velocity", meta = (ClampMin = "0.0", ClampMax = "180.0"))
298  float AngularMin;
299  UPROPERTY(EditAnywhere)
300  float AngularMinSwap;
301 
303  UPROPERTY(EditAnywhere, BlueprintReadWrite, SimpleDisplay, Category = "VR Tunnelling|Motion Settings|Angular Velocity", meta = (ClampMin = "0.0", ClampMax = "180.0"))
304  float AngularMax;
305  UPROPERTY(EditAnywhere)
306  float AngularMaxSwap;
307 
309  UPROPERTY(EditAnywhere, BlueprintReadWrite, SimpleDisplay, Category = "VR Tunnelling|Motion Settings|Angular Velocity", meta = (ClampMin = "0.0", ClampMax = "1.0"))
310  float AngularSmoothing;
311  UPROPERTY(EditAnywhere)
312  float AngularSmoothingSwap;
313 
315  UPROPERTY(EditAnywhere, BlueprintReadWrite, SimpleDisplay, Category = "VR Tunnelling|Motion Settings|Velocity")
316  bool bUseVelocity;
317  UPROPERTY(EditAnywhere)
318  bool bUseVelocitySwap;
319 
321  UPROPERTY(EditAnywhere, BlueprintReadWrite, SimpleDisplay, Category = "VR Tunnelling|Motion Settings|Velocity", meta = (ClampMin = "0.0", ClampMax = "10.0"))
322  float VelocityStrength;
323  UPROPERTY(EditAnywhere)
324  float VelocityStrengthSwap;
325 
327  UPROPERTY(EditAnywhere, BlueprintReadWrite, SimpleDisplay, Category = "VR Tunnelling|Motion Settings|Velocity", meta = (ClampMin = "0.0", ClampMax = "1000.0"))
328  float VelocityMin;
329  UPROPERTY(EditAnywhere)
330  float VelocityMinSwap;
331 
333  UPROPERTY(EditAnywhere, BlueprintReadWrite, SimpleDisplay, Category = "VR Tunnelling|Motion Settings|Velocity", meta = (ClampMin = "0.0", ClampMax = "1000.0"))
334  float VelocityMax;
335  UPROPERTY(EditAnywhere)
336  float VelocityMaxSwap;
337 
339  UPROPERTY(EditAnywhere, BlueprintReadWrite, SimpleDisplay, Category = "VR Tunnelling|Motion Settings|Velocity", meta = (ClampMin = "0.0", ClampMax = "1.0"))
340  float VelocitySmoothing;
341  UPROPERTY(EditAnywhere)
342  float VelocitySmoothingSwap;
343 
345  UPROPERTY(EditAnywhere, BlueprintReadWrite, SimpleDisplay, Category = "VR Tunnelling|Motion Settings|Acceleration")
346  bool bUseAcceleration;
347  UPROPERTY(EditAnywhere)
348  bool bUseAccelerationSwap;
349 
351  UPROPERTY(EditAnywhere, BlueprintReadWrite, SimpleDisplay, Category = "VR Tunnelling|Motion Settings|Acceleration", meta = (ClampMin = "0.0", ClampMax = "10.0"))
352  float AccelerationStrength;
353  UPROPERTY(EditAnywhere)
354  float AccelerationStrengthSwap;
355 
357  UPROPERTY(EditAnywhere, BlueprintReadWrite, SimpleDisplay, Category = "VR Tunnelling|Motion Settings|Acceleration", meta = (ClampMin = "0.0", ClampMax = "1000.0"))
358  float AccelerationMin;
359  UPROPERTY(EditAnywhere)
360  float AccelerationMinSwap;
361 
363  UPROPERTY(EditAnywhere, BlueprintReadWrite, SimpleDisplay, Category = "VR Tunnelling|Motion Settings|Acceleration", meta = (ClampMin = "0.0", ClampMax = "1000.0"))
364  float AccelerationMax;
365  UPROPERTY(EditAnywhere)
366  float AccelerationMaxSwap;
367 
369  UPROPERTY(EditAnywhere, BlueprintReadWrite, SimpleDisplay, Category = "VR Tunnelling|Motion Settings|Acceleration", meta = (ClampMin = "0.0", ClampMax = "1.0"))
370  float AccelerationSmoothing;
371  UPROPERTY(EditAnywhere)
372  float AccelerationSmoothingSwap;
373 
374  USceneCaptureComponentCube* SceneCaptureCube;
375  UTextureRenderTargetCube* TC;
376  float HFov;
377  float VFov;
378  UMaterialInstanceDynamic* PostProcessMID;
379  AActor* Skybox;
380  UStaticMeshComponent* Iris;
381  UMaterialInstanceDynamic* IrisOuterMID;
382  UMaterialInstanceDynamic* IrisInnerMID;
383  bool CaptureInit;
384 
386  UFUNCTION(BlueprintCallable, Category = "VR Tunnelling")
387  void ApplyPreset(UVRTPMPresetData* NewPreset);
388 
390  UFUNCTION(BlueprintCallable, Category = "VR Tunnelling")
391  void SetBackgroundMode(EVRTPMBackgroundMode NewBackgroundMode);
392 
394  UFUNCTION(BlueprintCallable, Category = "VR Tunnelling")
395  void SetMaskMode(EVRTPMMaskMode NewMaskMode);
396 
398  UFUNCTION(BlueprintCallable, Category = "VR Tunnelling")
399  void SetEffectColor(FLinearColor NewColor);
400 
402  UFUNCTION(BlueprintCallable, Category = "VR Tunnelling")
403  void ApplyColor(bool Enabled);
404 
406  UFUNCTION(BlueprintCallable, Category = "VR Tunnelling")
407  void SetStencilMask(int32 NewStencilIndex, bool UpdateMaskedObjects = true);
408 
410  UFUNCTION(BlueprintCallable, Category = "VR Tunnelling")
411  void UpdateMaskedObjects();
412 
414  UFUNCTION(BlueprintCallable, Category = "VR Tunnelling")
415  void SetFeather(float NewFeather);
416 
417 protected:
418  virtual void BeginPlay() override;
419 
420 public:
421  virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
422 
423 private:
424  FVector LastForward;
425  FVector LastPosition;
426  float LastSpeed;
427 
428  float AngleSmoothed;
429  float VelocitySmoothed;
430  float AccelerationSmoothed;
431 
432  void CacheSettings();
433  void InitCapture();
434  void InitSkybox();
435  void InitIris();
436  void InitFromPreset();
437  void SetPresetData(UVRTPMPresetData* NewPreset);
438  void UpdateEffectSettings();
439 
440  void CalculateMotion(float DeltaTime);
441  void ApplyBackgroundMode();
442  void ApplyMaskMode();
443  void ApplyStencilMasks();
444 };
Mobile preset data asset definition.
Definition: VRTPMobile.h:178
Tunnelling actor component, for mobile applications.
Definition: VRTPMobile.h:190
VRTP Mobile Preset Definition (Applied to mobile version only)
Definition: VRTPMobile.h:32