re-implement the wrist tracking settings overrides

This commit is contained in:
Mamadou Babaei
2024-08-16 16:37:28 +02:00
parent ac1af0512c
commit 740660fac4
7 changed files with 332 additions and 18 deletions
@@ -47,6 +47,14 @@ struct USGWristTrackerComponent::FImpl
* Static methods
************************/
static FName ParseWristTrackingSettingsOverridesPropertyName(const FName& PropertyName);
/************************
* Member variables
************************/
bool bMotionSourcePropertyModified;
/************************
* Owner object
************************/
@@ -73,6 +81,9 @@ struct USGWristTrackerComponent::FImpl
bool IsEditor() const;
void OverridePluginSettingsPropertyChanged();
void MotionSourcePropertyChanged();
void UpdateMotionSource() const;
void UpdateWristTrackingData() const;
void DrawDebugGizmo() const;
@@ -102,22 +113,72 @@ USGWristTrackerComponent::USGWristTrackerComponent(const FObjectInitializer& Obj
WristRotation = FRotator::ZeroRotator;
}
FName USGWristTrackerComponent::FImpl::ParseWristTrackingSettingsOverridesPropertyName(const FName& PropertyName)
{
static const UStruct* Struct{FSGWristTrackingSettingsOverrides::StaticStruct()};
if (!ensureAlwaysMsgf(Struct, TEXT("Invalid Struct!")))
{
return NAME_None;
}
// +3 because of ::
static const int32 StructNameLength = Struct->GetFName().ToString().Len() + 3;
const FString PropertyString{PropertyName.ToString()};
const int32 PropertyStringLength = PropertyString.Len();
const int32 PropertyNameLength = PropertyStringLength - StructNameLength;
const FName ParsedName{*PropertyString.Right(PropertyNameLength)};
return ParsedName;
}
void USGWristTrackerComponent::SetRight(const bool bInRight)
{
bRight = bInRight;
Pimpl->UpdateMotionSource();
}
const FSGWristTrackingSettings& USGWristTrackerComponent::GetWristTrackingSettings() const
void USGWristTrackerComponent::SetWristTrackingSettingsOverrides(
const FSGWristTrackingSettingsOverrides& InWristTrackingSettingsOverrides)
{
const USGSettings* Settings{USGSettings::GetInstance()};
if (!ensureAlwaysMsgf(Settings, TEXT("The settings subsystem has not been initialized!")))
{
static const FSGWristTrackingSettings DummySettings;
return DummySettings;
WristTrackingSettingsOverrides = InWristTrackingSettingsOverrides;
}
return Settings->GetTrackingSettings().WristTrackingSettings;
FSGWristTrackingSettings USGWristTrackerComponent::GetWristTrackingSettings() const
{
const USGSettings* Settings{USGSettings::GetInstance()};
if (!ensureAlwaysMsgf(IsValid(Settings), TEXT("The settings subsystem has not been initialized!")))
{
return FSGWristTrackingSettings{};
}
const FSGWristTrackingSettings& PluginWristTrackingSettings{Settings->GetTrackingSettings().WristTrackingSettings};
if (!OverridesPluginWristTrackingSettings())
{
return PluginWristTrackingSettings;
}
const EControllerHand LeftMotionSource =
IsLeft()
? WristTrackingSettingsOverrides.MotionSource
: PluginWristTrackingSettings.LeftHandMotionSource;
const EControllerHand RightMotionSource =
IsRight()
? WristTrackingSettingsOverrides.MotionSource
: PluginWristTrackingSettings.RightHandMotionSource;
const FSGWristTrackingSettings WristTrackingSettings{
PluginWristTrackingSettings.TrackingHardware,
PluginWristTrackingSettings.TrackingHardwareLocationOffsetLeftHand,
PluginWristTrackingSettings.TrackingHardwareLocationOffsetRightHand,
PluginWristTrackingSettings.TrackingHardwareRotationOffsetLeftHand,
PluginWristTrackingSettings.TrackingHardwareRotationOffsetRightHand,
LeftMotionSource,
RightMotionSource,
!!WristTrackingSettingsOverrides.bDrawDebugGizmo,
WristTrackingSettingsOverrides.DebugGizmoSettings,
};
return WristTrackingSettings;
}
#if WITH_EDITOR
@@ -131,7 +192,28 @@ void USGWristTrackerComponent::PostEditChangeProperty(FPropertyChangedEvent& Pro
: NAME_None
};
(void) PropertyName;
static const FName OverridePluginSettingsName{
FImpl::ParseWristTrackingSettingsOverridesPropertyName(
GET_MEMBER_NAME_CHECKED(FSGWristTrackingSettingsOverrides,
FSGWristTrackingSettingsOverrides::bOverridePluginSettings))
};
static const FName MotionSourceUPropertyName{
FImpl::ParseWristTrackingSettingsOverridesPropertyName(
GET_MEMBER_NAME_CHECKED(FSGWristTrackingSettingsOverrides,
FSGWristTrackingSettingsOverrides::MotionSource))
};
if (PropertyName == OverridePluginSettingsName)
{
Pimpl->OverridePluginSettingsPropertyChanged();
return;
}
if (PropertyName == MotionSourceUPropertyName)
{
Pimpl->MotionSourcePropertyChanged();
return;
}
}
#endif /* WITH_EDITOR */
@@ -197,7 +279,8 @@ bool USGWristTrackerComponent::GetMotionControllerData(FXRMotionControllerData&
}
USGWristTrackerComponent::FImpl::FImpl(USGWristTrackerComponent* InOwner)
: Owner(InOwner)
: bMotionSourcePropertyModified(false),
Owner(InOwner)
{
}
@@ -214,6 +297,40 @@ bool USGWristTrackerComponent::FImpl::IsEditor() const
return false;
}
void USGWristTrackerComponent::FImpl::OverridePluginSettingsPropertyChanged()
{
if (bMotionSourcePropertyModified)
{
return;
}
const USGSettings* Settings{USGSettings::GetInstance()};
if (IsValid(Settings))
{
const FSGWristTrackingSettings& PluginWristTrackingSettings{
Settings->GetTrackingSettings().WristTrackingSettings
};
Owner->WristTrackingSettingsOverrides.MotionSource =
Owner->IsRight()
? PluginWristTrackingSettings.RightHandMotionSource
: PluginWristTrackingSettings.LeftHandMotionSource;
}
else
{
Owner->WristTrackingSettingsOverrides.MotionSource =
Owner->IsRight() ? EControllerHand::Right : EControllerHand::Left;
}
}
void USGWristTrackerComponent::FImpl::MotionSourcePropertyChanged()
{
if (bMotionSourcePropertyModified)
{
return;
}
bMotionSourcePropertyModified = true;
}
void USGWristTrackerComponent::FImpl::UpdateMotionSource() const
{
if (GEngine)
@@ -43,6 +43,7 @@
#include "Templates/UniquePtr.h"
#include "SGSettings/SGWristTrackingSettings.h"
#include "SGSettings/SGWristTrackingSettingsOverrides.h"
#include "SGWristTrackerComponent.generated.h"
@@ -94,6 +95,12 @@ private:
UPROPERTY(EditAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false"))
uint8 bRight : 1;
/**
* Overrides the plugin's wrist tracking settings.
*/
UPROPERTY(EditAnywhere, Category = "SenseGlove", meta=(AllowPrivateAccess="false"))
FSGWristTrackingSettingsOverrides WristTrackingSettingsOverrides;
private:
UPROPERTY(Transient)
FVector WristLocation;
@@ -114,7 +121,19 @@ public:
void SetRight(const bool bInRight);
const FSGWristTrackingSettings& GetWristTrackingSettings() const;
FORCEINLINE bool OverridesPluginWristTrackingSettings() const
{
return !!WristTrackingSettingsOverrides.bOverridePluginSettings;
}
FORCEINLINE const FSGWristTrackingSettingsOverrides& GetWristTrackingSettingsOverrides() const
{
return WristTrackingSettingsOverrides;
}
void SetWristTrackingSettingsOverrides(const FSGWristTrackingSettingsOverrides& InWristTrackingSettingsOverrides);
FSGWristTrackingSettings GetWristTrackingSettings() const;
FORCEINLINE const FVector& GetWristLocation() const
{
@@ -37,12 +37,6 @@
#include "SenseGlove/Components/SGWristTrackerComponent.h"
const FSGWristTrackingSettings& UWristTrackerComponentKismetLibrary::GetWristTrackingSettings(
const USGWristTrackerComponent* WristTrackerComponent)
{
return WristTrackerComponent->GetWristTrackingSettings();
}
bool UWristTrackerComponentKismetLibrary::IsLeft(const USGWristTrackerComponent* WristTrackerComponent)
{
return WristTrackerComponent->IsLeft();
@@ -59,6 +53,31 @@ void UWristTrackerComponentKismetLibrary::SetRight(
WristTrackerComponent->SetRight(bInRight);
}
bool UWristTrackerComponentKismetLibrary::OverridesPluginWristTrackingSettings(
const USGWristTrackerComponent* WristTrackerComponent)
{
return WristTrackerComponent->OverridesPluginWristTrackingSettings();
}
const FSGWristTrackingSettingsOverrides& UWristTrackerComponentKismetLibrary::GetWristTrackingSettingsOverrides(
const USGWristTrackerComponent* WristTrackerComponent)
{
return WristTrackerComponent->GetWristTrackingSettingsOverrides();
}
void UWristTrackerComponentKismetLibrary::SetWristTrackingSettingsOverrides(
USGWristTrackerComponent* WristTrackerComponent,
const FSGWristTrackingSettingsOverrides& InWristTrackingSettingsOverrides)
{
WristTrackerComponent->SetWristTrackingSettingsOverrides(InWristTrackingSettingsOverrides);
}
FSGWristTrackingSettings UWristTrackerComponentKismetLibrary::GetWristTrackingSettings(
const USGWristTrackerComponent* WristTrackerComponent)
{
return WristTrackerComponent->GetWristTrackingSettings();
}
const FVector& UWristTrackerComponentKismetLibrary::GetWristLocation(
const USGWristTrackerComponent* WristTrackerComponent)
{
@@ -39,6 +39,7 @@
#include "SGKismet/SGBlueprintFunctionLibrary.h"
#include "SGSettings/SGWristTrackingSettings.h"
#include "SGSettings/SGWristTrackingSettingsOverrides.h"
#include "SGWristTrackerComponentKismetLibrary.generated.h"
@@ -52,10 +53,6 @@ class SENSEGLOVEKISMET_API UWristTrackerComponentKismetLibrary final : public US
GENERATED_BODY()
public:
UFUNCTION(BlueprintPure, Category="SenseGlove | Components | Wrist Tracker Component")
static const FSGWristTrackingSettings& GetWristTrackingSettings(
const USGWristTrackerComponent* WristTrackerComponent);
UFUNCTION(BlueprintPure, Category="SenseGlove | Components | Wrist Tracker Component")
static bool IsLeft(const USGWristTrackerComponent* WristTrackerComponent);
@@ -65,6 +62,21 @@ public:
UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Wrist Tracker Component")
static void SetRight(UPARAM(ref) USGWristTrackerComponent* WristTrackerComponent, bool bInRight);
UFUNCTION(BlueprintPure, Category="SenseGlove | Components | Wrist Tracker Component")
static bool OverridesPluginWristTrackingSettings(const USGWristTrackerComponent* WristTrackerComponent);
UFUNCTION(BlueprintPure, Category="SenseGlove | Components | Wrist Tracker Component")
static const FSGWristTrackingSettingsOverrides& GetWristTrackingSettingsOverrides(
const USGWristTrackerComponent* WristTrackerComponent);
UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Wrist Tracker Component")
static void SetWristTrackingSettingsOverrides(
UPARAM(ref) USGWristTrackerComponent* WristTrackerComponent,
const FSGWristTrackingSettingsOverrides& InWristTrackingSettingsOverrides);
UFUNCTION(BlueprintPure, Category="SenseGlove | Components | Wrist Tracker Component")
static FSGWristTrackingSettings GetWristTrackingSettings(const USGWristTrackerComponent* WristTrackerComponent);
UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Wrist Tracker Component")
static const FVector& GetWristLocation(const USGWristTrackerComponent* WristTrackerComponent);
@@ -0,0 +1,58 @@
/**
* @file
*
* @author Mamadou Babaei <mamadou@senseglove.com>
*
* @section LICENSE
*
* (The MIT License)
*
* Copyright (c) 2020 - 2024 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
*
*
*/
#include "SGSettings/SGWristTrackingSettingsOverrides.h"
FSGWristTrackingSettingsOverrides::FSGWristTrackingSettingsOverrides()
: FSGWristTrackingSettingsOverrides{
false,
EControllerHand::AnyHand,
false,
FSGDebugGizmoSettings{}
}
{
}
FSGWristTrackingSettingsOverrides::FSGWristTrackingSettingsOverrides(
const bool bInOverridePluginSettings,
const EControllerHand InMotionSource,
const bool bInDrawDebugGizmo,
const FSGDebugGizmoSettings& InDebugGizmoSettings)
: bOverridePluginSettings(bInOverridePluginSettings),
MotionSource(InMotionSource),
bDrawDebugGizmo(bInDrawDebugGizmo),
DebugGizmoSettings{InDebugGizmoSettings}
{
}
@@ -35,6 +35,7 @@
#pragma once
#include "HAL/Platform.h"
#include "InputCoreTypes.h"
#include "Math/Rotator.h"
#include "Math/Vector.h"
@@ -0,0 +1,88 @@
/**
* @file
*
* @author Mamadou Babaei <mamadou@senseglove.com>
*
* @section LICENSE
*
* (The MIT License)
*
* Copyright (c) 2020 - 2024 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 "HAL/Platform.h"
#include "InputCoreTypes.h"
#include "UObject/ObjectMacros.h"
#include "SGSettings/SGDebugGizmoSettings.h"
#include "SGWristTrackingSettingsOverrides.generated.h"
USTRUCT(BlueprintType)
struct SENSEGLOVESETTINGS_API FSGWristTrackingSettingsOverrides
{
GENERATED_USTRUCT_BODY()
public:
/**
* Determines whether to override the plugin's wrist tracking settings or not.
*/
UPROPERTY(EditAnywhere, Category = "SenseGlove")
uint8 bOverridePluginSettings : 1;
/**
* Determines which motion source to use.
* For Oculus this is usually Left/Right, and for VIVE usually LeftFoot/RightFoot.
*/
UPROPERTY(EditAnywhere, Category = "SenseGlove",
meta=(EditCondition="bOverridePluginSettings", EditConditionHides))
EControllerHand MotionSource;
/**
* If enabled, draws debug Wrist trackers where possible.
*/
UPROPERTY(EditAnywhere, Category = "SenseGlove",
meta=(EditCondition="bOverridePluginSettings", EditConditionHides))
uint8 bDrawDebugGizmo : 1;
/**
* Valid only if bDrawDebugGizmo is enabled.
*/
UPROPERTY(EditAnywhere, Category = "SenseGlove",
meta=(EditCondition="bOverridePluginSettings && bDrawDebugGizmo", EditConditionHides))
FSGDebugGizmoSettings DebugGizmoSettings;
public:
FSGWristTrackingSettingsOverrides();
FSGWristTrackingSettingsOverrides(
bool bInOverridePluginSettings,
EControllerHand InMotionSource,
bool bInDrawDebugGizmo,
const FSGDebugGizmoSettings& InDebugGizmoSettings);
};