Skip to content
Snippets Groups Projects
Commit 1ad51beb authored by Simon Oehrl's avatar Simon Oehrl
Browse files

Merge branch 'release/4.22.1'

parents 2ffc739d 74a8ec8e
No related branches found
No related tags found
No related merge requests found
File added
File added
// Fill out your copyright notice in the Description page of Project Settings. // Fill out your copyright notice in the Description page of Project Settings.
#include "RwthComponent.h" #include "VRWidgetInteractionComponent.h"
#include "Runtime/InputCore/Classes/InputCoreTypes.h" #include "Runtime/InputCore/Classes/InputCoreTypes.h"
#include "Runtime/Engine/Classes/Components/InputComponent.h" #include "Runtime/Engine/Classes/Components/InputComponent.h"
#include "ConstructorHelpers.h"
#include "Modules/ModuleManager.h"
#include "Interfaces/IPluginManager.h"
#include "VirtualRealityPawn.h" #include "VirtualRealityPawn.h"
URwthComponent::URwthComponent()
UVRWidgetInteractionComponent::UVRWidgetInteractionComponent() {
InteractionRay = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Interaction Ray"));
//this ray model as a inlayed cross with flipped normals so it can be seen as a cross in desktop mode where the right hand is attached to the head
ConstructorHelpers::FObjectFinder<UStaticMesh> MeshAsset(TEXT("/WidgetInteraction/Ray_Mesh"));
if (MeshAsset.Object != nullptr)
{ {
InteractionRay->SetStaticMesh(MeshAsset.Object);
}
bShowDebug = false;
} }
void URwthComponent::Init() void UVRWidgetInteractionComponent::Init(USceneComponent* parent)
{ {
SetVisibility(true); SetVisibility(true);
InteractionDistance = 1000000.0f; InteractionDistance = 1000000.0f;
auto input_cmp = dynamic_cast<UInputComponent*>(GetOwner()->GetComponentByClass(UInputComponent::StaticClass())); auto input_cmp = dynamic_cast<UInputComponent*>(GetOwner()->GetComponentByClass(UInputComponent::StaticClass()));
input_cmp->BindAction<FFireDelegate>("Fire", IE_Pressed, this, &URwthComponent::OnFire, true); input_cmp->BindAction<FFireDelegate>("Fire", IE_Pressed, this, &UVRWidgetInteractionComponent::OnFire, true);
input_cmp->BindAction<FFireDelegate>("Fire", IE_Released, this, &URwthComponent::OnFire, false); input_cmp->BindAction<FFireDelegate>("Fire", IE_Released, this, &UVRWidgetInteractionComponent::OnFire, false);
RegisterComponent(); RegisterComponent();
InteractionRay->RegisterComponent();
if (parent != nullptr) {
InteractionRay->AttachToComponent(parent, FAttachmentTransformRules::KeepRelativeTransform);
this->AttachToComponent(parent, FAttachmentTransformRules::KeepRelativeTransform);
}
} }
void URwthComponent::SetVisibility(bool visible) { void UVRWidgetInteractionComponent::SetVisibility(bool visible) {
bShowDebug = visible; InteractionRay->SetVisibility(visible);
} }
void URwthComponent::OnFire(bool val) void UVRWidgetInteractionComponent::OnFire(bool val)
{ {
if (val == true) if (val == true)
PressPointerKey(EKeys::LeftMouseButton); PressPointerKey(EKeys::LeftMouseButton);
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#define LOCTEXT_NAMESPACE "FWidgetInteractionModule" #define LOCTEXT_NAMESPACE "FWidgetInteractionModule"
DEFINE_LOG_CATEGORY(WidgetIntLog);
void FWidgetInteractionModule::StartupModule() void FWidgetInteractionModule::StartupModule()
{ {
on_world_tick_start_delegate_.BindRaw(this, &FWidgetInteractionModule::OnWorldTickStart); on_world_tick_start_delegate_.BindRaw(this, &FWidgetInteractionModule::OnWorldTickStart);
...@@ -21,8 +23,8 @@ void FWidgetInteractionModule::ShutdownModule() ...@@ -21,8 +23,8 @@ void FWidgetInteractionModule::ShutdownModule()
void FWidgetInteractionModule::OnWorldTickStart(ELevelTick level_tick, float val) void FWidgetInteractionModule::OnWorldTickStart(ELevelTick level_tick, float val)
{ {
//called every Tick() //since OnWorldTickStart is called independent of the world/level we are in,
//we need to check whether the level changed and, if so, reattach the interaction component
auto worlds = GEngine->GetWorldContexts(); auto worlds = GEngine->GetWorldContexts();
for (auto world_context : worlds) { for (auto world_context : worlds) {
...@@ -49,55 +51,21 @@ void FWidgetInteractionModule::OnWorldTickStart(ELevelTick level_tick, float val ...@@ -49,55 +51,21 @@ void FWidgetInteractionModule::OnWorldTickStart(ELevelTick level_tick, float val
if (vr_pawn == nullptr) if (vr_pawn == nullptr)
continue; continue;
UE_LOG(LogTemp, Warning, TEXT("OnWorldTickStart called and interaction component will be updated")); CreateWidgetInteraction(vr_pawn->GetRightHandComponent(), vr_pawn);
FString name = "";
UClass* component_class = UMotionControllerComponent::StaticClass();
if (IDisplayCluster::Get().GetClusterMgr()->IsStandalone()) {
//if this is a standalone setup ...
if (UHeadMountedDisplayFunctionLibrary::IsHeadMountedDisplayEnabled()) {
//.. with an HMD, we attach the intercation component to the right hand
name = FString("RightMotionController");
component_class = UMotionControllerComponent::StaticClass();
}
else {
//... without an HMD, we also attach it to the virtual right hand, since it exists in this case
name = TEXT("RightMotionController");
component_class = UMotionControllerComponent::StaticClass();
}
}
else {
//if this is a cluster setup we attach it to the flystick
name = TEXT("flystick");
component_class = UDisplayClusterSceneComponent::StaticClass();
}
auto parent_vec = vr_pawn->GetComponentsByClass(component_class);
bool success;
for (auto parent : parent_vec) {
if (parent->GetName() == FString(name)) {
CreateWidgetInteraction(dynamic_cast<USceneComponent*>(parent), vr_pawn);
success = true;
last_world = world; last_world = world;
}
}
if (!success) UE_LOG(WidgetIntLog, Verbose, TEXT("VRInteractionComponent attached to right hand"));
UE_LOG(LogTemp, Error, TEXT("Failed to load widget asset \"%s\", cannot attach widget interaction component"), *name);
} }
} }
URwthComponent* FWidgetInteractionModule::GetWidgetInteractionComponent() { UVRWidgetInteractionComponent* FWidgetInteractionModule::GetWidgetInteractionComponent() {
return widget_interaction_cmp_; return widget_interaction_cmp_;
} }
void FWidgetInteractionModule::CreateWidgetInteraction(USceneComponent* parent, AVirtualRealityPawn* outer) void FWidgetInteractionModule::CreateWidgetInteraction(USceneComponent* parent, AVirtualRealityPawn* outer)
{ {
widget_interaction_cmp_ = NewObject<URwthComponent>(outer, URwthComponent::StaticClass()); widget_interaction_cmp_ = NewObject<UVRWidgetInteractionComponent>(outer, UVRWidgetInteractionComponent::StaticClass());
widget_interaction_cmp_->AttachToComponent(parent, FAttachmentTransformRules(EAttachmentRule::KeepRelative, false)); widget_interaction_cmp_->Init(parent);
widget_interaction_cmp_->Init();
} }
#undef LOCTEXT_NAMESPACE #undef LOCTEXT_NAMESPACE
......
...@@ -4,24 +4,28 @@ ...@@ -4,24 +4,28 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "Components/WidgetInteractionComponent.h" #include "Components/WidgetInteractionComponent.h"
#include "RwthComponent.generated.h" #include "Components/StaticMeshComponent.h"
#include "VRWidgetInteractionComponent.generated.h"
/** /**
* *
*/ */
UCLASS() UCLASS()
class WIDGETINTERACTION_API URwthComponent : public UWidgetInteractionComponent class WIDGETINTERACTION_API UVRWidgetInteractionComponent : public UWidgetInteractionComponent
{ {
GENERATED_BODY() GENERATED_BODY()
public: public:
URwthComponent(); UVRWidgetInteractionComponent();
void Init(); void Init(USceneComponent* parent);
void SetVisibility(bool visible); void SetVisibility(bool visible);
protected: protected:
void OnFire(bool val); void OnFire(bool val);
UPROPERTY(VisibleAnywhere) UStaticMeshComponent* InteractionRay;
DECLARE_DELEGATE_OneParam(FFireDelegate, bool); DECLARE_DELEGATE_OneParam(FFireDelegate, bool);
}; };
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "VirtualRealityPawn.h" #include "VirtualRealityPawn.h"
#include "RwthComponent.h" #include "VRWidgetInteractionComponent.h"
#include "Modules/ModuleManager.h" #include "Modules/ModuleManager.h"
DECLARE_LOG_CATEGORY_EXTERN(WidgetIntLog, Log, All);
class WIDGETINTERACTION_API FWidgetInteractionModule : public IModuleInterface class WIDGETINTERACTION_API FWidgetInteractionModule : public IModuleInterface
{ {
public: public:
...@@ -15,10 +17,9 @@ public: ...@@ -15,10 +17,9 @@ public:
virtual void StartupModule() override; virtual void StartupModule() override;
virtual void ShutdownModule() override; virtual void ShutdownModule() override;
UFUNCTION() UFUNCTION() void OnWorldTickStart(ELevelTick, float);
void OnWorldTickStart(ELevelTick, float);
URwthComponent* GetWidgetInteractionComponent(); UVRWidgetInteractionComponent* GetWidgetInteractionComponent();
private: private:
void CreateWidgetInteraction(USceneComponent* parent, AVirtualRealityPawn* outer); void CreateWidgetInteraction(USceneComponent* parent, AVirtualRealityPawn* outer);
...@@ -26,6 +27,6 @@ private: ...@@ -26,6 +27,6 @@ private:
private: private:
TBaseDelegate<void, ELevelTick, float> on_world_tick_start_delegate_; TBaseDelegate<void, ELevelTick, float> on_world_tick_start_delegate_;
URwthComponent * widget_interaction_cmp_; UVRWidgetInteractionComponent* widget_interaction_cmp_;
UWorld* last_world; UWorld* last_world;
}; };
...@@ -25,7 +25,7 @@ public class WidgetInteraction : ModuleRules ...@@ -25,7 +25,7 @@ public class WidgetInteraction : ModuleRules
PublicDependencyModuleNames.AddRange( PublicDependencyModuleNames.AddRange(
new string[] new string[]
{ {
"Core", "Core"
// ... add other public dependencies that you statically link with here ... // ... add other public dependencies that you statically link with here ...
} }
); );
...@@ -35,15 +35,16 @@ public class WidgetInteraction : ModuleRules ...@@ -35,15 +35,16 @@ public class WidgetInteraction : ModuleRules
new string[] new string[]
{ {
"CoreUObject", "CoreUObject",
"Engine",
"Projects",
"DisplayCluster", "DisplayCluster",
"DisplayClusterInput", "DisplayClusterInput",
"Engine",
"HeadMountedDisplay", "HeadMountedDisplay",
"DisplayClusterExtensions", "DisplayClusterExtensions",
"InputCore", "InputCore",
"UMG", "UMG",
"Slate", "Slate",
"SlateCore", "SlateCore"
// ... add private dependencies that you statically link with here ... // ... add private dependencies that you statically link with here ...
} }
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment