Skip to content

Commit

Permalink
Merge branch '5.4-Preview' of https://github.com/mordentral/VRExpansi…
Browse files Browse the repository at this point in the history
…onPlugin into 5.4-Preview
  • Loading branch information
Joshua committed Apr 12, 2024
2 parents aba26a2 + 7bda72c commit 62632bb
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 31 deletions.
4 changes: 2 additions & 2 deletions OpenXRExpansionPlugin/OpenXRExpansionPlugin.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 5.3,
"VersionName": "5.3",
"Version": 5.4,
"VersionName": "5.4",
"FriendlyName": "OpenXRExpansionPlugin",
"Description": "An set of utility functions for OpenXR",
"Category": "Virtual Reality",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "VRBPDatatypes.h"
#include UE_INLINE_GENERATED_CPP_BY_NAME(VRBPDatatypes)

#include "VRGlobalSettings.h"
#include "HAL/IConsoleManager.h"
#include "Chaos/ChaosEngineInterface.h"

Expand Down Expand Up @@ -219,3 +220,53 @@ FTransform FBPEuroLowPassFilterTrans::RunFilterSmoothing(const FTransform& InRaw
// Filter passed value
return NewTrans;
}

bool FBPAdvancedPhysicsHandleSettings::FillTo(FBPActorPhysicsHandleInformation* HandleInfo, bool bModifyWithScalers) const
{
if (!HandleInfo)
return false;

float DampingMod = 0.0f;
float StiffnessMod = 0.0f;
float ADampingMod = 0.0f;
float AStiffnessMod = 0.0f;
const UVRGlobalSettings& VRSettings = *GetDefault<UVRGlobalSettings>();

if (VRSettings.bUseChaosTranslationScalers)
{
StiffnessMod = VRSettings.LinearDriveStiffnessScale;
DampingMod = VRSettings.LinearDriveDampingScale;
AStiffnessMod = VRSettings.AngularDriveStiffnessScale;
ADampingMod = VRSettings.AngularDriveDampingScale;
}
else
{
auto CVarLinearDriveStiffnessScale = IConsoleManager::Get().FindConsoleVariable(TEXT("p.Chaos.JointConstraint.LinearDriveStiffnessScale"));
auto CVarLinearDriveDampingScale = IConsoleManager::Get().FindConsoleVariable(TEXT("p.Chaos.JointConstraint.LinaearDriveDampingScale"));
auto CVarAngularDriveStiffnessScale = IConsoleManager::Get().FindConsoleVariable(TEXT("p.Chaos.JointConstraint.AngularDriveStiffnessScale"));
auto CVarAngularDriveDampingScale = IConsoleManager::Get().FindConsoleVariable(TEXT("p.Chaos.JointConstraint.AngularDriveDampingScale"));

StiffnessMod = CVarLinearDriveStiffnessScale->GetFloat();
DampingMod = CVarLinearDriveDampingScale->GetFloat();
AStiffnessMod = CVarAngularDriveStiffnessScale->GetFloat();
ADampingMod = CVarAngularDriveDampingScale->GetFloat();
}

XAxisSettings.FillTo(HandleInfo->LinConstraint.XDrive, DampingMod, StiffnessMod);
YAxisSettings.FillTo(HandleInfo->LinConstraint.YDrive, DampingMod, StiffnessMod);
ZAxisSettings.FillTo(HandleInfo->LinConstraint.ZDrive, DampingMod, StiffnessMod);

if ((SlerpSettings.bEnablePositionDrive || SlerpSettings.bEnableVelocityDrive))
{
HandleInfo->AngConstraint.AngularDriveMode = EAngularDriveMode::SLERP;
SlerpSettings.FillTo(HandleInfo->AngConstraint.SlerpDrive, ADampingMod, AStiffnessMod);
}
else
{
HandleInfo->AngConstraint.AngularDriveMode = EAngularDriveMode::TwistAndSwing;
TwistSettings.FillTo(HandleInfo->AngConstraint.TwistDrive, ADampingMod, AStiffnessMod);
SwingSettings.FillTo(HandleInfo->AngConstraint.SwingDrive, ADampingMod, AStiffnessMod);
}

return true;
}
32 changes: 5 additions & 27 deletions VRExpansionPlugin/Source/VRExpansionPlugin/Public/VRBPDatatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1868,11 +1868,11 @@ struct VREXPANSIONPLUGIN_API FBPAdvancedPhysicsHandleAxisSettings
bEnableVelocityDrive = ConstraintDrive.bEnableVelocityDrive;
}

void FillTo(FConstraintDrive& ConstraintDrive) const
void FillTo(FConstraintDrive& ConstraintDrive, float DampingScaler = 1.0f, float StiffnessScaler = 1.0f) const
{
ConstraintDrive.Damping = Damping;
ConstraintDrive.Stiffness = Stiffness;
ConstraintDrive.MaxForce = MaxForceCoefficient * Stiffness;
ConstraintDrive.Damping = Damping * DampingScaler;
ConstraintDrive.Stiffness = Stiffness * StiffnessScaler;
ConstraintDrive.MaxForce = (float)FMath::Clamp<double>((double)ConstraintDrive.Stiffness * (double)MaxForceCoefficient, 0, (double)MAX_FLT);
ConstraintDrive.bEnablePositionDrive = bEnablePositionDrive;
ConstraintDrive.bEnableVelocityDrive = bEnableVelocityDrive;
}
Expand Down Expand Up @@ -1929,27 +1929,5 @@ struct VREXPANSIONPLUGIN_API FBPAdvancedPhysicsHandleSettings
return true;
}

bool FillTo(FBPActorPhysicsHandleInformation* HandleInfo) const
{
if (!HandleInfo)
return false;

XAxisSettings.FillTo(HandleInfo->LinConstraint.XDrive);
YAxisSettings.FillTo(HandleInfo->LinConstraint.YDrive);
ZAxisSettings.FillTo(HandleInfo->LinConstraint.ZDrive);

if ((SlerpSettings.bEnablePositionDrive || SlerpSettings.bEnableVelocityDrive))
{
HandleInfo->AngConstraint.AngularDriveMode = EAngularDriveMode::SLERP;
SlerpSettings.FillTo(HandleInfo->AngConstraint.SlerpDrive);
}
else
{
HandleInfo->AngConstraint.AngularDriveMode = EAngularDriveMode::TwistAndSwing;
TwistSettings.FillTo(HandleInfo->AngConstraint.TwistDrive);
SwingSettings.FillTo(HandleInfo->AngConstraint.SwingDrive);
}

return true;
}
bool FillTo(FBPActorPhysicsHandleInformation* HandleInfo, bool bModifyWithScalers = true) const;
};
4 changes: 2 additions & 2 deletions VRExpansionPlugin/VRExpansionPlugin.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 5.3,
"VersionName": "5.3",
"Version": 5.4,
"VersionName": "5.4",
"FriendlyName": "VRExpansionPlugin",
"Description": "Adds several new VR features & components to UE4",
"Category": "VRExpansion",
Expand Down

0 comments on commit 62632bb

Please sign in to comment.