diff --git a/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandComponent.cpp b/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandComponent.cpp index 8493d685..eb1edc82 100644 --- a/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandComponent.cpp +++ b/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandComponent.cpp @@ -61,6 +61,8 @@ struct USGVirtualHandComponent::FImpl * Static methods ************************/ + static FName ParseVirtualHandSettingsOverridesPropertyName(const FName& PropertyName); + FORCEINLINE static const FSGVirtualHandSettings& GetPluginVirtualHandSettings() { const USGSettings* Settings{USGSettings::GetInstance()}; @@ -92,6 +94,8 @@ struct USGVirtualHandComponent::FImpl * Member variables ************************/ + bool bOverridePluginSettingsPropertyAlreadyModified; + bool bCachedGenerateOverlapEvents; ECollisionEnabled::Type CachedCollisionEnabled; FCollisionResponseContainer CachedCollisionResponse; @@ -122,6 +126,9 @@ struct USGVirtualHandComponent::FImpl bool IsEditor() const; + void RightPropertyChanged(); + void OverridePluginSettingsPropertyChanged(); + FString GetDefaultMeshPath() const; bool IsUsingDefaultMesh() const; bool IsUsingUserMesh() const; @@ -151,6 +158,25 @@ struct USGVirtualHandComponent::FImpl void TriggerHandVisibilityChangedEvent(bool bNewVisibility) const; }; +FName USGVirtualHandComponent::FImpl::ParseVirtualHandSettingsOverridesPropertyName(const FName& PropertyName) +{ + static const UStruct* Struct{FSGVirtualHandSettingsOverrides::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; +} + const TArray& USGVirtualHandComponent::GetLeftHandBoneNames() { return FImpl::GetPluginVirtualHandSettings().MeshSettings.LeftHandBoneNames; @@ -293,12 +319,27 @@ void USGVirtualHandComponent::PostEditChangeProperty(FPropertyChangedEvent& Prop ? PropertyChangedEvent.Property->GetFName() : NAME_None }; - if (PropertyName == GET_MEMBER_NAME_CHECKED(USGVirtualHandComponent, bRight)) + + static const FName RightName{ + GET_MEMBER_NAME_CHECKED(USGVirtualHandComponent, bRight) + }; + + static const FName OverridePluginSettingsName{ + FImpl::ParseVirtualHandSettingsOverridesPropertyName( + GET_MEMBER_NAME_CHECKED(FSGWristTrackingSettingsOverrides, + FSGWristTrackingSettingsOverrides::bOverridePluginSettings)) + }; + + if (PropertyName == RightName) { - if (!Pimpl->IsUsingUserMesh()) - { - Pimpl->SetDefaultMesh(); - } + Pimpl->RightPropertyChanged(); + return; + } + + if (PropertyName == OverridePluginSettingsName) + { + Pimpl->OverridePluginSettingsPropertyChanged(); + return; } } #endif /* WITH_EDITOR */ @@ -485,7 +526,8 @@ FRotator USGVirtualHandComponent::GetHandBoneRefRotation(const int32 Joint) cons } USGVirtualHandComponent::FImpl::FImpl(USGVirtualHandComponent* InOwner) - : bCachedGenerateOverlapEvents(InOwner->GetGenerateOverlapEvents()), + : bOverridePluginSettingsPropertyAlreadyModified(false), + bCachedGenerateOverlapEvents(InOwner->GetGenerateOverlapEvents()), CachedCollisionEnabled(InOwner->GetCollisionEnabled()), Owner(InOwner) @@ -505,6 +547,44 @@ bool USGVirtualHandComponent::FImpl::IsEditor() const return false; } +void USGVirtualHandComponent::FImpl::RightPropertyChanged() +{ + if (!IsUsingUserMesh()) + { + SetDefaultMesh(); + } +} + +void USGVirtualHandComponent::FImpl::OverridePluginSettingsPropertyChanged() +{ + if (bOverridePluginSettingsPropertyAlreadyModified) + { + return; + } + + bOverridePluginSettingsPropertyAlreadyModified = true; + + if (!Owner->VirtualHandSettingsOverrides.bOverridePluginSettings) + { + return; + } + + const USGSettings* Settings{USGSettings::GetInstance()}; + if (!ensureAlwaysMsgf(IsValid(Settings), TEXT("The settings subsystem has not been initialized!"))) + { + return; + } + + const FSGVirtualHandSettings& PluginVirtualHandSettings{Settings->GetVirtualHandSettings()}; + Owner->VirtualHandSettingsOverrides.bVisibleWhenHandDataUnavailable = + !!PluginVirtualHandSettings.bVisibleWhenHandDataUnavailable; + Owner->VirtualHandSettingsOverrides.AnimationSettings = PluginVirtualHandSettings.AnimationSettings; + Owner->VirtualHandSettingsOverrides.DebuggingSettings = PluginVirtualHandSettings.DebuggingSettings; + Owner->VirtualHandSettingsOverrides.GrabSettings = PluginVirtualHandSettings.GrabSettings; + Owner->VirtualHandSettingsOverrides.HapticsSettings = PluginVirtualHandSettings.HapticsSettings; + Owner->VirtualHandSettingsOverrides.TouchSettings = PluginVirtualHandSettings.TouchSettings; +} + FString USGVirtualHandComponent::FImpl::GetDefaultMeshPath() const { FString SkeletalMeshPath; @@ -595,6 +675,10 @@ void USGVirtualHandComponent::FImpl::SetDefaultMesh() const // One workaround would be disabling the async loading or as an alternative simply disabling this portion of the // code should be a good-enough fix until we address this issue in its own time. //Owner->SetSkeletalMesh(LoadDefaultMesh(), true); + // Temporary hack to make it work inside the Blueprint Editor. +#if WITH_EDITOR + Owner->SetSkeletalMesh(LoadDefaultMesh(), true); +#endif /* WITH_EDITOR */ } USkeletalMesh* USGVirtualHandComponent::FImpl::GetMesh() const diff --git a/Source/SenseGlove/Private/SenseGlove/Components/SGWristTrackerComponent.cpp b/Source/SenseGlove/Private/SenseGlove/Components/SGWristTrackerComponent.cpp index e15a329c..4d0a1501 100644 --- a/Source/SenseGlove/Private/SenseGlove/Components/SGWristTrackerComponent.cpp +++ b/Source/SenseGlove/Private/SenseGlove/Components/SGWristTrackerComponent.cpp @@ -47,10 +47,14 @@ struct USGWristTrackerComponent::FImpl * Static methods ************************/ + static FName ParseWristTrackingSettingsOverridesPropertyName(const FName& PropertyName); + /************************ * Member variables ************************/ + bool bOverridePluginSettingsPropertyAlreadyModified; + /************************ * Owner object ************************/ @@ -77,6 +81,8 @@ struct USGWristTrackerComponent::FImpl bool IsEditor() const; + void OverridePluginSettingsPropertyChanged(); + void UpdateMotionSource() const; void UpdateWristTrackingData() const; void DrawDebugWristTracker() const; @@ -106,6 +112,25 @@ 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; @@ -156,7 +181,17 @@ void USGWristTrackerComponent::PostEditChangeProperty(FPropertyChangedEvent& Pro : NAME_None }; - (void) PropertyName; + static const FName OverridePluginSettingsName{ + FImpl::ParseWristTrackingSettingsOverridesPropertyName( + GET_MEMBER_NAME_CHECKED(FSGWristTrackingSettingsOverrides, + FSGWristTrackingSettingsOverrides::bOverridePluginSettings)) + }; + + if (PropertyName == OverridePluginSettingsName) + { + Pimpl->OverridePluginSettingsPropertyChanged(); + return; + } } #endif /* WITH_EDITOR */ @@ -222,7 +257,8 @@ bool USGWristTrackerComponent::GetMotionControllerData(FXRMotionControllerData& } USGWristTrackerComponent::FImpl::FImpl(USGWristTrackerComponent* InOwner) - : Owner(InOwner) + : bOverridePluginSettingsPropertyAlreadyModified(false), + Owner(InOwner) { } @@ -239,6 +275,30 @@ bool USGWristTrackerComponent::FImpl::IsEditor() const return false; } +void USGWristTrackerComponent::FImpl::OverridePluginSettingsPropertyChanged() +{ + if (bOverridePluginSettingsPropertyAlreadyModified) + { + return; + } + + bOverridePluginSettingsPropertyAlreadyModified = true; + + if (!Owner->WristTrackingSettingsOverrides.bOverridePluginSettings) + { + return; + } + + const USGSettings* Settings{USGSettings::GetInstance()}; + if (!ensureAlwaysMsgf(IsValid(Settings), TEXT("The settings subsystem has not been initialized!"))) + { + return; + } + + const FSGWristTrackingSettings& PluginWristTrackingSettings{Settings->GetTrackingSettings().WristTrackingSettings}; + Owner->WristTrackingSettingsOverrides.DebuggingSettings = PluginWristTrackingSettings.DebuggingSettings; +} + void USGWristTrackerComponent::FImpl::UpdateMotionSource() const { if (GEngine)