Updated VRE

This commit is contained in:
Simeon "Waldo" Wallrath 2024-04-04 15:13:02 +02:00
parent 9657f9135f
commit 6db822feb1
25 changed files with 351 additions and 98 deletions

Binary file not shown.

View file

@ -369,7 +369,7 @@ bool FVRCharacterNetworkMoveData::Serialize(UCharacterMovementComponent& Charact
if (AVRBaseCharacter* BaseChar = Cast<AVRBaseCharacter>(CharacterOwner))
{
if (!BaseChar->VRMovementReference->bUseClientControlRotation)
if (BaseChar->VRMovementReference && !BaseChar->VRMovementReference->bUseClientControlRotation)
{
bRepRollAndPitch = (Roll != 0 || Pitch != 0);
}

View file

@ -6709,15 +6709,6 @@ bool UGripMotionControllerComponent::SetGripConstraintStiffnessAndDamping(const
}
}
if (VRSettings.bUseChaosTranslationScalers)
{
Stiffness *= VRSettings.LinearDriveStiffnessScale;
Damping *= VRSettings.LinearDriveDampingScale;
AngularStiffness *= VRSettings.AngularDriveStiffnessScale;
AngularDamping *= VRSettings.AngularDriveDampingScale;
}
else
{
if (VRSettings.bUseChaosTranslationScalers)
{
Stiffness *= VRSettings.LinearDriveStiffnessScale;
@ -6737,7 +6728,6 @@ bool UGripMotionControllerComponent::SetGripConstraintStiffnessAndDamping(const
AngularStiffness *= CVarAngularDriveStiffnessScale->GetFloat();
AngularDamping *= CVarAngularDriveDampingScale->GetFloat();
}
}
AngularMaxForce = (float)FMath::Clamp<double>((double)AngularStiffness * (double)Grip->AdvancedGripSettings.PhysicsSettings.AngularMaxForceCoefficient, 0, (double)MAX_FLT);
MaxForce = (float)FMath::Clamp<double>((double)Stiffness * (double)Grip->AdvancedGripSettings.PhysicsSettings.LinearMaxForceCoefficient, 0, (double)MAX_FLT);

View file

@ -512,10 +512,13 @@ void UGS_GunTools::GetVirtualStockTarget(UGripMotionControllerComponent * Grippi
if (GrippingController && (GrippingController->HasAuthority() || bUseHighQualityRemoteSimulation))
{
if (AVRBaseCharacter * vrOwner = Cast<AVRBaseCharacter>(GrippingController->GetOwner()))
{
if (vrOwner->VRReplicatedCamera)
{
CameraComponent = vrOwner->VRReplicatedCamera;
return;
}
}
else
{
TArray<USceneComponent*> children = GrippingController->GetOwner()->GetRootComponent()->GetAttachChildren();

View file

@ -9,8 +9,13 @@
#include "Components/PrimitiveComponent.h"
#include "GameFramework/Actor.h"
#include "Net/UnrealNetwork.h"
#include "Net/Core/PushModel/PushModel.h"
#include "Engine/NetDriver.h"
#if UE_WITH_IRIS
#include "Iris/ReplicationSystem/ReplicationFragmentUtil.h"
#endif // UE_WITH_IRIS
UVRGripScriptBase::UVRGripScriptBase(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
@ -69,6 +74,18 @@ UVRGripScriptBase* UVRGripScriptBase::GetGripScriptByClass(UObject* WorldContext
return nullptr;
}
#if UE_WITH_IRIS
void UVRGripScriptBase::RegisterReplicationFragments(UE::Net::FFragmentRegistrationContext& Context, UE::Net::EFragmentRegistrationFlags RegistrationFlags)
{
using namespace UE::Net;
Super::RegisterReplicationFragments(Context, RegistrationFlags);
// Build descriptors and allocate PropertyReplicationFragments for this object
FReplicationFragmentUtil::CreateAndRegisterFragmentsForObject(this, Context, RegistrationFlags);
}
#endif // UE_WITH_IRIS
void UVRGripScriptBase::GetLifetimeReplicatedProps(TArray< class FLifetimeProperty > & OutLifetimeProps) const
{
// Uobject has no replicated props
@ -80,6 +97,56 @@ void UVRGripScriptBase::GetLifetimeReplicatedProps(TArray< class FLifetimeProper
{
BPClass->GetLifetimeBlueprintReplicationList(OutLifetimeProps);
}
FDoRepLifetimeParams SharedParams;
SharedParams.bIsPushBased = true;
DOREPLIFETIME_WITH_PARAMS(UVRGripScriptBase, bReplicates, SharedParams);
}
void UVRGripScriptBase::SetIsReplicated(bool bShouldReplicate)
{
if (GetIsReplicated() != bShouldReplicate)
{
bReplicates = bShouldReplicate;
FBoolProperty* BoolProperty = CastField<FBoolProperty>(this->GetClass()->FindPropertyByName("bReplicates"));
MARK_PROPERTY_DIRTY(this, BoolProperty);
//MARK_PROPERTY_DIRTY_FROM_NAME(UVRGripScriptBase, bReplicates, this);
// Remove us from the subobject replication list if we need to be
if (AActor* OwningActor = Cast<AActor>(GetParent()))
{
if (OwningActor->IsUsingRegisteredSubObjectList())
{
if (bReplicates)
{
if (!OwningActor->IsReplicatedSubObjectRegistered(this))
{
OwningActor->AddReplicatedSubObject(this);
}
}
else if(OwningActor->IsReplicatedSubObjectRegistered(this))
{
OwningActor->RemoveReplicatedSubObject(this);
}
}
}
else if (UActorComponent* OwningComp = Cast<UActorComponent>(GetParent()))
{
if (bReplicates)
{
if (!OwningComp->IsReplicatedSubObjectRegistered(this))
{
OwningComp->AddReplicatedSubObject(this);
}
}
else if (OwningComp->IsReplicatedSubObjectRegistered(this))
{
OwningComp->RemoveReplicatedSubObject(this);
}
}
}
}
void UVRGripScriptBase::Tick(float DeltaTime)
@ -320,14 +387,73 @@ UWorld* UVRGripScriptBase::GetWorld() const
void UVRGripScriptBase::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
// Remove us from the subobject replication list if we need to be
if (AActor* OwningActor = Cast<AActor>(GetParent()))
{
if (OwningActor->IsUsingRegisteredSubObjectList())
{
OwningActor->RemoveReplicatedSubObject(this);
}
}
else if (UActorComponent* OwningComp = Cast<UActorComponent>(GetParent()))
{
if (OwningComp->IsUsingRegisteredSubObjectList())
{
OwningComp->RemoveReplicatedSubObject(this);
}
}
OnEndPlay(EndPlayReason);
}
void UVRGripScriptBase::BeginDestroy()
{
Super::BeginDestroy();
if (bReplicates)
{
// Remove us from the subobject replication list if we need to be
if (AActor* OwningActor = Cast<AActor>(GetParent()))
{
if (OwningActor->IsUsingRegisteredSubObjectList())
{
OwningActor->RemoveReplicatedSubObject(this);
}
}
else if (UActorComponent* OwningComp = Cast<UActorComponent>(GetParent()))
{
if (OwningComp->IsUsingRegisteredSubObjectList())
{
OwningComp->RemoveReplicatedSubObject(this);
}
}
}
}
void UVRGripScriptBase::BeginPlay(UObject * CallingOwner)
{
if (bAlreadyNotifiedPlay)
return;
if (bReplicates)
{
// Register us to the subobject replication list if we need to be
if (AActor* OwningActor = Cast<AActor>(CallingOwner))
{
if (OwningActor->IsUsingRegisteredSubObjectList())
{
OwningActor->AddReplicatedSubObject(this, ReplicationCondition);
}
}
else if (UActorComponent* OwningComp = Cast<UActorComponent>(CallingOwner))
{
if (OwningComp->IsUsingRegisteredSubObjectList())
{
OwningComp->AddReplicatedSubObject(this, ReplicationCondition);
}
}
}
bAlreadyNotifiedPlay = true;
// Notify the subscripts about begin play
@ -338,6 +464,8 @@ void UVRGripScriptBase::PostInitProperties()
{
Super::PostInitProperties();
if (bReplicates)
{
//Called in game, when World exist . BeginPlay will not be called in editor
if (GetWorld())
{
@ -345,7 +473,8 @@ void UVRGripScriptBase::PostInitProperties()
{
if (Owner->IsActorInitialized())
{
BeginPlay(GetOwner());
BeginPlay(GetParent());
}
}
}
}

View file

@ -311,7 +311,7 @@ bool AGrippableActor::ReplicateSubobjects(UActorChannel* Channel, class FOutBunc
{
bool WroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags);
if (bReplicateGripScripts)
if (bReplicateGripScripts && !IsUsingRegisteredSubObjectList())
{
for (UVRGripScriptBase* Script : GripLogicScripts)
{

View file

@ -73,7 +73,7 @@ bool UGrippableBoxComponent::ReplicateSubobjects(UActorChannel* Channel, class F
{
bool WroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags);
if (bReplicateGripScripts)
if (bReplicateGripScripts && !IsUsingRegisteredSubObjectList())
{
for (UVRGripScriptBase* Script : GripLogicScripts)
{

View file

@ -69,7 +69,7 @@ bool UGrippableCapsuleComponent::ReplicateSubobjects(UActorChannel* Channel, cla
{
bool WroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags);
if (bReplicateGripScripts)
if (bReplicateGripScripts && !IsUsingRegisteredSubObjectList())
{
for (UVRGripScriptBase* Script : GripLogicScripts)
{

View file

@ -70,7 +70,7 @@ bool UGrippableSkeletalMeshComponent::ReplicateSubobjects(UActorChannel* Channel
{
bool WroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags);
if (bReplicateGripScripts)
if (bReplicateGripScripts && !IsUsingRegisteredSubObjectList())
{
for (UVRGripScriptBase* Script : GripLogicScripts)
{

View file

@ -68,7 +68,7 @@ bool UGrippableSphereComponent::ReplicateSubobjects(UActorChannel* Channel, clas
{
bool WroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags);
if (bReplicateGripScripts)
if (bReplicateGripScripts && !IsUsingRegisteredSubObjectList())
{
for (UVRGripScriptBase* Script : GripLogicScripts)
{

View file

@ -306,7 +306,7 @@ bool AGrippableStaticMeshActor::ReplicateSubobjects(UActorChannel* Channel, clas
{
bool WroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags);
if (bReplicateGripScripts)
if (bReplicateGripScripts && !IsUsingRegisteredSubObjectList())
{
for (UVRGripScriptBase* Script : GripLogicScripts)
{

View file

@ -69,7 +69,7 @@ bool UGrippableStaticMeshComponent::ReplicateSubobjects(UActorChannel* Channel,
{
bool WroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags);
if (bReplicateGripScripts)
if (bReplicateGripScripts && !IsUsingRegisteredSubObjectList())
{
for (UVRGripScriptBase* Script : GripLogicScripts)
{

View file

@ -90,6 +90,69 @@ UAnimSequence* UHandSocketComponent::GetTargetAnimation()
return HandTargetAnimation;
}
void UHandSocketComponent::GetAllHandSocketComponents(TArray<UHandSocketComponent*>& OutHandSockets)
{
for (TObjectIterator<UHandSocketComponent> It; It; ++It)
{
UHandSocketComponent* HandSocket = *It;
if (IsValid(HandSocket) && !HandSocket->IsTemplate())
{
OutHandSockets.Add(HandSocket);
}
}
}
bool UHandSocketComponent::GetAllHandSocketComponentsInRange(FVector SearchFromWorldLocation, float SearchRange, TArray<UHandSocketComponent*>& OutHandSockets)
{
float SearchDistSq = FMath::Square(SearchRange);
UHandSocketComponent* HandSocket = nullptr;
FTransform HandSocketTrans;
for (TObjectIterator<UHandSocketComponent> It; It; ++It)
{
HandSocket = *It;
if (IsValid(HandSocket) && !HandSocket->IsTemplate())
{
HandSocketTrans = HandSocket->GetRelativeTransform() * HandSocket->GetOwner()->GetActorTransform();
if (FVector::DistSquared(HandSocketTrans.GetLocation(), SearchFromWorldLocation) <= SearchDistSq)
{
OutHandSockets.Add(HandSocket);
}
}
}
return OutHandSockets.Num() > 0;
}
UHandSocketComponent* UHandSocketComponent::GetClosestHandSocketComponentInRange(FVector SearchFromWorldLocation, float SearchRange)
{
float SearchDistSq = FMath::Square(SearchRange);
UHandSocketComponent* ClosestHandSocket = nullptr;
float LastDist = 0.0f;
float DistSq = 0.0f;
bool bFoundOne = false;
UHandSocketComponent* HandSocket = nullptr;
FTransform HandSocketTrans;
for (TObjectIterator<UHandSocketComponent> It; It; ++It)
{
HandSocket = *It;
if (IsValid(HandSocket) && !HandSocket->IsTemplate())
{
HandSocketTrans = HandSocket->GetRelativeTransform() * HandSocket->GetOwner()->GetActorTransform();
DistSq = FVector::DistSquared(HandSocketTrans.GetLocation(), SearchFromWorldLocation);
if (DistSq <= SearchDistSq && (!bFoundOne || DistSq < LastDist))
{
bFoundOne = true;
ClosestHandSocket = HandSocket;
LastDist = DistSq;
}
}
}
return ClosestHandSocket;
}
bool UHandSocketComponent::GetAnimationSequenceAsPoseSnapShot(UAnimSequence* InAnimationSequence, FPoseSnapshot& OutPoseSnapShot, USkeletalMeshComponent* TargetMesh, bool bSkipRootBone, bool bFlipHand)
{
if (InAnimationSequence)

View file

@ -677,8 +677,8 @@ void UVRLeverComponent::CalculateCurrentAngle(FTransform & CurrentTransform)
FullCurrentAngle = FMath::RadiansToDegrees(FMath::Acos(FVector::DotProduct(UpVec, FVector::UpVector)));
CurrentLeverAngle = FMath::RoundToFloat(FullCurrentAngle);
AllCurrentLeverAngles.Roll = FMath::Sign(UpVec.Y) * FMath::RadiansToDegrees(FMath::Acos(FVector::DotProduct(FVector(0.0f, UpVec.Y, UpVec.Z), FVector::UpVector)));
AllCurrentLeverAngles.Pitch = FMath::Sign(UpVec.X) * FMath::RadiansToDegrees(FMath::Acos(FVector::DotProduct(FVector(UpVec.X, 0.0f, UpVec.Z), FVector::UpVector)));
AllCurrentLeverAngles.Roll = FMath::Sign(UpVec.Y) * FMath::RadiansToDegrees(FMath::Acos(FVector::DotProduct(FVector(0.0f, UpVec.Y, UpVec.Z).GetSafeNormal(), FVector::UpVector)));
AllCurrentLeverAngles.Pitch = FMath::Sign(UpVec.X) * FMath::RadiansToDegrees(FMath::Acos(FVector::DotProduct(FVector(UpVec.X, 0.0f, UpVec.Z).GetSafeNormal(), FVector::UpVector)));
if (bBlendAxisValuesByAngleThreshold)
{

View file

@ -50,7 +50,7 @@ void UParentRelativeAttachmentComponent::InitializeComponent()
Super::InitializeComponent();
// Update our tracking
if (!bUseFeetLocation && IsValid(AttachChar)) // New case to early out and with less calculations
if (!bUseFeetLocation && IsValid(AttachChar) && IsValid(AttachChar->VRReplicatedCamera)) // New case to early out and with less calculations
{
SetRelativeTransform(AttachChar->VRReplicatedCamera->GetRelativeTransform());
}

View file

@ -204,7 +204,7 @@ void UReplicatedVRCameraComponent::UpdateTracking(float DeltaTime)
Position.Y = 0.0f;
FRotator StoredCameraRotOffset = FRotator::ZeroRotator;
if (AttachChar->VRMovementReference->GetReplicatedMovementMode() == EVRConjoinedMovementModes::C_VRMOVE_Seated)
if (AttachChar->VRMovementReference && AttachChar->VRMovementReference->GetReplicatedMovementMode() == EVRConjoinedMovementModes::C_VRMOVE_Seated)
{
AttachChar->SeatInformation.InitialRelCameraTransform.Rotator();
}
@ -244,7 +244,7 @@ void UReplicatedVRCameraComponent::RunNetworkedSmoothing(float DeltaTime)
if (AttachChar && !AttachChar->bRetainRoomscale)
{
FRotator StoredCameraRotOffset = FRotator::ZeroRotator;
if (AttachChar->VRMovementReference->GetReplicatedMovementMode() == EVRConjoinedMovementModes::C_VRMOVE_Seated)
if (AttachChar->VRMovementReference && AttachChar->VRMovementReference->GetReplicatedMovementMode() == EVRConjoinedMovementModes::C_VRMOVE_Seated)
{
AttachChar->SeatInformation.InitialRelCameraTransform.Rotator();
}
@ -470,7 +470,7 @@ void UReplicatedVRCameraComponent::HandleXRCamera()
Position.X = 0.0f;
Position.Y = 0.0f;
//FRotator OffsetRotator =
if (AttachChar->VRMovementReference->GetReplicatedMovementMode() != EVRConjoinedMovementModes::C_VRMOVE_Seated)
if (AttachChar->VRMovementReference && AttachChar->VRMovementReference->GetReplicatedMovementMode() != EVRConjoinedMovementModes::C_VRMOVE_Seated)
{
AttachChar->SeatInformation.InitialRelCameraTransform.Rotator();
@ -521,7 +521,7 @@ void UReplicatedVRCameraComponent::OnRep_ReplicatedCameraTransform()
CameraPosition.Y = 0;
FRotator StoredCameraRotOffset = FRotator::ZeroRotator;
if (AttachChar->VRMovementReference->GetReplicatedMovementMode() == EVRConjoinedMovementModes::C_VRMOVE_Seated)
if (AttachChar->VRMovementReference && AttachChar->VRMovementReference->GetReplicatedMovementMode() == EVRConjoinedMovementModes::C_VRMOVE_Seated)
{
AttachChar->SeatInformation.InitialRelCameraTransform.Rotator();
}

View file

@ -54,7 +54,7 @@ AVRBaseCharacter::AVRBaseCharacter(const FObjectInitializer& ObjectInitializer)
cap->SetCollisionResponseToChannel(ECollisionChannel::ECC_WorldStatic, ECollisionResponse::ECR_Block);
}
NetSmoother = CreateDefaultSubobject<USceneComponent>(AVRBaseCharacter::SmoothingSceneParentComponentName);
NetSmoother = CreateOptionalDefaultSubobject<USceneComponent>(AVRBaseCharacter::SmoothingSceneParentComponentName);
if (NetSmoother)
{
NetSmoother->SetupAttachment(RootComponent);
@ -69,17 +69,17 @@ AVRBaseCharacter::AVRBaseCharacter(const FObjectInitializer& ObjectInitializer)
}
}
VRProxyComponent = CreateDefaultSubobject<USceneComponent>(AVRBaseCharacter::VRProxyComponentName);
VRProxyComponent = CreateOptionalDefaultSubobject<USceneComponent>(AVRBaseCharacter::VRProxyComponentName);
if (NetSmoother && VRProxyComponent)
{
VRProxyComponent->SetupAttachment(NetSmoother);
}
VRReplicatedCamera = CreateDefaultSubobject<UReplicatedVRCameraComponent>(AVRBaseCharacter::ReplicatedCameraComponentName);
VRReplicatedCamera = CreateOptionalDefaultSubobject<UReplicatedVRCameraComponent>(AVRBaseCharacter::ReplicatedCameraComponentName);
if (VRReplicatedCamera)
{
//VRReplicatedCamera->bOffsetByHMD = false;
VRReplicatedCamera->SetupAttachment(VRProxyComponent);
VRReplicatedCamera->SetupAttachment(VRProxyComponent ? VRProxyComponent : NetSmoother ? NetSmoother : RootComponent);
VRReplicatedCamera->OverrideSendTransform = &AVRBaseCharacter::Server_SendTransformCamera;
}
@ -90,11 +90,11 @@ AVRBaseCharacter::AVRBaseCharacter(const FObjectInitializer& ObjectInitializer)
//AddTickPrerequisiteComponent(this->GetCharacterMovement());
}
ParentRelativeAttachment = CreateDefaultSubobject<UParentRelativeAttachmentComponent>(AVRBaseCharacter::ParentRelativeAttachmentComponentName);
ParentRelativeAttachment = CreateOptionalDefaultSubobject<UParentRelativeAttachmentComponent>(AVRBaseCharacter::ParentRelativeAttachmentComponentName);
if (ParentRelativeAttachment && VRReplicatedCamera)
{
// Moved this to be root relative as the camera late updates were killing how it worked
ParentRelativeAttachment->SetupAttachment(VRProxyComponent);
ParentRelativeAttachment->SetupAttachment(VRProxyComponent ? VRProxyComponent : NetSmoother ? NetSmoother : RootComponent);
//ParentRelativeAttachment->bOffsetByHMD = false;
ParentRelativeAttachment->AddTickPrerequisiteComponent(VRReplicatedCamera);
@ -104,10 +104,10 @@ AVRBaseCharacter::AVRBaseCharacter(const FObjectInitializer& ObjectInitializer)
}
}
LeftMotionController = CreateDefaultSubobject<UGripMotionControllerComponent>(AVRBaseCharacter::LeftMotionControllerComponentName);
LeftMotionController = CreateOptionalDefaultSubobject<UGripMotionControllerComponent>(AVRBaseCharacter::LeftMotionControllerComponentName);
if (IsValid(LeftMotionController))
{
LeftMotionController->SetupAttachment(VRProxyComponent);
LeftMotionController->SetupAttachment(VRProxyComponent ? VRProxyComponent : NetSmoother ? NetSmoother : RootComponent);
//LeftMotionController->MotionSource = FXRMotionControllerBase::LeftHandSourceId;
LeftMotionController->SetTrackingMotionSource(IMotionController::LeftHandSourceId);
//LeftMotionController->Hand = EControllerHand::Left;
@ -118,10 +118,10 @@ AVRBaseCharacter::AVRBaseCharacter(const FObjectInitializer& ObjectInitializer)
LeftMotionController->OverrideSendTransform = &AVRBaseCharacter::Server_SendTransformLeftController;
}
RightMotionController = CreateDefaultSubobject<UGripMotionControllerComponent>(AVRBaseCharacter::RightMotionControllerComponentName);
RightMotionController = CreateOptionalDefaultSubobject<UGripMotionControllerComponent>(AVRBaseCharacter::RightMotionControllerComponentName);
if (IsValid(RightMotionController))
{
RightMotionController->SetupAttachment(VRProxyComponent);
RightMotionController->SetupAttachment(VRProxyComponent ? VRProxyComponent : NetSmoother ? NetSmoother : RootComponent);
//RightMotionController->MotionSource = FXRMotionControllerBase::RightHandSourceId;
RightMotionController->SetTrackingMotionSource(IMotionController::RightHandSourceId);
//RightMotionController->Hand = EControllerHand::Right;
@ -680,6 +680,9 @@ void AVRBaseCharacter::InitSeatedModeTransition()
void AVRBaseCharacter::TickSeatInformation(float DeltaTime)
{
if (!VRReplicatedCamera)
return;
float LastThresholdScaler = SeatInformation.CurrentThresholdScaler;
bool bLastOverThreshold = SeatInformation.bIsOverThreshold;
@ -779,7 +782,7 @@ bool AVRBaseCharacter::SetSeatedMode(USceneComponent * SeatParent, bool bSetSeat
// Automate the intial relative camera transform for this mode
// I think we can remove the initial value alltogether eventually right?
if (!bRetainRoomscale)
if (!bRetainRoomscale && VRReplicatedCamera)
{
InitialRelCameraTransform = FTransform(VRReplicatedCamera->ReplicatedCameraTransform.Rotation, VRReplicatedCamera->ReplicatedCameraTransform.Position, VRReplicatedCamera->GetComponentScale());
}
@ -909,7 +912,7 @@ FVector AVRBaseCharacter::SetActorRotationVR(FRotator NewRot, bool bUseYawOnly,
NewRot.Roll = 0.0f;
}
if (bAccountForHMDRotation)
if (bAccountForHMDRotation && VRReplicatedCamera)
{
NewRotation = UVRExpansionFunctionLibrary::GetHMDPureYaw_I(VRReplicatedCamera->GetRelativeRotation());
NewRotation = (NewRot.Quaternion() * NewRotation.Quaternion().Inverse()).Rotator();
@ -944,7 +947,7 @@ FVector AVRBaseCharacter::SetActorLocationAndRotationVR(FVector NewLoc, FRotator
NewRot.Roll = 0.0f;
}
if (bAccountForHMDRotation)
if (bAccountForHMDRotation && VRReplicatedCamera)
{
NewRotation = UVRExpansionFunctionLibrary::GetHMDPureYaw_I(VRReplicatedCamera->GetRelativeRotation());//bUseControllerRotationYaw && OwningController ? OwningController->GetControlRotation() : GetActorRotation();
NewRotation = (NewRot.Quaternion() * NewRotation.Quaternion().Inverse()).Rotator();

View file

@ -2016,9 +2016,12 @@ void UVRBaseCharacterMovementComponent::SmoothCorrection(const FVector& OldLocat
// #TODO: Get this working in the future?
// I am currently skipping smoothing on rotation operations
if ((!OldRotation.Equals(NewRotation, 1e-5f)))// || Velocity.IsNearlyZero()))
{
if (BaseVRCharacterOwner->NetSmoother)
{
BaseVRCharacterOwner->NetSmoother->SetRelativeLocation(BaseVRCharacterOwner->bRetainRoomscale ? FVector::ZeroVector : BaseVRCharacterOwner->VRRootReference->GetTargetHeightOffset());
//BaseVRCharacterOwner->NetSmoother->SetRelativeLocation(FVector::ZeroVector);
}
UpdatedComponent->SetWorldLocationAndRotation(NewLocation, NewRotation, false, nullptr, GetTeleportType());
ClientData->MeshTranslationOffset = FVector::ZeroVector;
ClientData->MeshRotationOffset = ClientData->MeshRotationTarget;
@ -2152,7 +2155,7 @@ void UVRBaseCharacterMovementComponent::SmoothClientPosition_UpdateVRVisuals()
if (ClientData)
{
if (NetworkSmoothingMode == ENetworkSmoothingMode::Linear)
if (NetworkSmoothingMode == ENetworkSmoothingMode::Linear && BaseVRCharacterOwner->NetSmoother)
{
// Erased most of the code here, check back in later
const USceneComponent* MeshParent = BaseVRCharacterOwner->NetSmoother->GetAttachParent();
@ -2167,7 +2170,7 @@ void UVRBaseCharacterMovementComponent::SmoothClientPosition_UpdateVRVisuals()
FVector HeightOffset = (BaseVRCharacterOwner->bRetainRoomscale ? FVector::ZeroVector : BaseVRCharacterOwner->VRRootReference->GetTargetHeightOffset());
BaseVRCharacterOwner->NetSmoother->SetRelativeLocation(NewRelLocation + HeightOffset);
}
else if (NetworkSmoothingMode == ENetworkSmoothingMode::Exponential)
else if (NetworkSmoothingMode == ENetworkSmoothingMode::Exponential && BaseVRCharacterOwner->NetSmoother)
{
const USceneComponent* MeshParent = BaseVRCharacterOwner->NetSmoother->GetAttachParent();
FVector MeshParentScale = MeshParent != nullptr ? MeshParent->GetComponentScale() : FVector(1.0f, 1.0f, 1.0f);

View file

@ -423,12 +423,15 @@ void UVRRootComponent::BeginPlay()
Super::BeginPlay();
if(AVRBaseCharacter * vrOwner = Cast<AVRBaseCharacter>(this->GetOwner()))
{
if (vrOwner->VRReplicatedCamera)
{
TargetPrimitiveComponent = vrOwner->VRReplicatedCamera;
owningVRChar = vrOwner;
//VRCameraCollider = vrOwner->VRCameraCollider;
return;
}
}
else
{
TArray<USceneComponent*> children = this->GetAttachChildren();
@ -456,7 +459,7 @@ void UVRRootComponent::SetTrackingPaused(bool bPaused)
void UVRRootComponent::UpdateCharacterCapsuleOffset()
{
if (owningVRChar && !owningVRChar->bRetainRoomscale)
if (owningVRChar && !owningVRChar->bRetainRoomscale && owningVRChar->NetSmoother)
{
if (!FMath::IsNearlyEqual(LastCapsuleHalfHeight, CapsuleHalfHeight))
{
@ -485,11 +488,13 @@ void UVRRootComponent::TickComponent(float DeltaTime, enum ELevelTick TickType,
}
UVRBaseCharacterMovementComponent * CharMove = nullptr;
bool bRetainRoomscale = true;
// Need these for passing physics updates to character movement
if (IsValid(owningVRChar))
{
CharMove = Cast<UVRBaseCharacterMovementComponent>(owningVRChar->GetCharacterMovement());
bRetainRoomscale = owningVRChar->bRetainRoomscale;
}
if (IsLocallyControlled())
@ -539,7 +544,7 @@ void UVRRootComponent::TickComponent(float DeltaTime, enum ELevelTick TickType,
// Skip this if not retaining roomscale as we use higher initial fidelity
// And we can rep the values at full precision if we want too
if (owningVRChar->bRetainRoomscale)
if (bRetainRoomscale)
{
// Pre-Process this for network sends
curCameraLoc.X = FMath::RoundToFloat(curCameraLoc.X * 100.f) / 100.f;
@ -549,14 +554,14 @@ void UVRRootComponent::TickComponent(float DeltaTime, enum ELevelTick TickType,
// Can adjust the relative tolerances to remove jitter and some update processing
if (!owningVRChar->bRetainRoomscale || (!curCameraLoc.Equals(lastCameraLoc, 0.01f) || !curCameraRot.Equals(lastCameraRot, 0.01f)))
if (!bRetainRoomscale || (!curCameraLoc.Equals(lastCameraLoc, 0.01f) || !curCameraRot.Equals(lastCameraRot, 0.01f)))
{
// Also calculate vector of movement for the movement component
FVector LastPosition = OffsetComponentToWorld.GetLocation();
bCalledUpdateTransform = false;
if (owningVRChar->bRetainRoomscale)
if (bRetainRoomscale)
{
// If the character movement doesn't exist or is not active/ticking
if (!CharMove || !CharMove->IsComponentTickEnabled() || !CharMove->IsActive())
@ -578,7 +583,7 @@ void UVRRootComponent::TickComponent(float DeltaTime, enum ELevelTick TickType,
Params.bFindInitialOverlaps = true;
bool bBlockingHit = false;
if (bUseWalkingCollisionOverride && owningVRChar->bRetainRoomscale)
if (bUseWalkingCollisionOverride && bRetainRoomscale)
{
FVector TargetWorldLocation = OffsetComponentToWorld.GetLocation();
bool bAllowWalkingCollision = false;
@ -608,9 +613,9 @@ void UVRRootComponent::TickComponent(float DeltaTime, enum ELevelTick TickType,
bHadRelativeMovement = true;
// Not supporting walking collision override currently with new pawn setup
if (bHadRelativeMovement || !owningVRChar->bRetainRoomscale)
if (bHadRelativeMovement || (owningVRChar && !owningVRChar->bRetainRoomscale))
{
if (owningVRChar->bRetainRoomscale)
if (bRetainRoomscale)
{
DifferenceFromLastFrame = OffsetComponentToWorld.GetLocation() - LastPosition;
lastCameraLoc = curCameraLoc;
@ -755,17 +760,23 @@ void UVRRootComponent::SetSimulatePhysics(bool bSimulate)
if (bSimulate)
{
if (AVRCharacter* OwningCharacter = Cast<AVRCharacter>(GetOwner()))
{
if (OwningCharacter->NetSmoother)
{
OwningCharacter->NetSmoother->SetRelativeLocation(FVector(0.f,0.f, -this->GetUnscaledCapsuleHalfHeight()));
}
}
this->AddWorldOffset(this->GetComponentRotation().RotateVector(FVector(0.f, 0.f, this->GetScaledCapsuleHalfHeight())), false, nullptr, ETeleportType::TeleportPhysics);
}
else
{
if (AVRCharacter* OwningCharacter = Cast<AVRCharacter>(GetOwner()))
{
if (OwningCharacter->NetSmoother)
{
OwningCharacter->NetSmoother->SetRelativeLocation(FVector(0.f, 0.f, 0));
}
}
this->AddWorldOffset(this->GetComponentRotation().RotateVector(FVector(0.f, 0.f, -this->GetScaledCapsuleHalfHeight())), false, nullptr, ETeleportType::TeleportPhysics);
}
}

View file

@ -575,6 +575,8 @@ void UVRStereoWidgetComponent::TickComponent(float DeltaTime, enum ELevelTick Ti
bool bHandledTransform = false;
if (AVRBaseCharacter* BaseVRChar = Cast<AVRBaseCharacter>(mpawn))
{
if (BaseVRChar->VRReplicatedCamera)
{
if (USceneComponent* CameraParent = BaseVRChar->VRReplicatedCamera->GetAttachParent())
{
@ -600,6 +602,7 @@ void UVRStereoWidgetComponent::TickComponent(float DeltaTime, enum ELevelTick Ti
bHandledTransform = true;
}
}
}
else if (UCameraComponent* Camera = mpawn->FindComponentByClass<UCameraComponent>())
{
// Look for generic camera comp and use its attach parent

View file

@ -55,6 +55,27 @@ public:
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings")
bool bIsActive;
private:
// If we should replicate, if false we will never be added to our parents list.
UPROPERTY(Replicated, EditDefaultsOnly, BlueprintReadOnly, Category = "GSSettings|Replication", meta = (AllowPrivateAccess = "true"))
bool bReplicates = false;
public:
/** Enable or disable replication. This is the equivalent of RemoteRole for actors (only a bool is required for components) */
UFUNCTION(BlueprintCallable, Category = "Components")
void SetIsReplicated(bool ShouldReplicate);
/** Returns whether replication is enabled or not. */
UFUNCTION(BlueprintCallable, Category = "Components")
bool GetIsReplicated() const
{
return bReplicates;
}
// Replication Condition (If using subobject replication list)
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings|Replication")
TEnumAsByte<ELifetimeCondition> ReplicationCondition = ELifetimeCondition::COND_None;
// Returns if the script is going to modify the world transform of the grip
EGSTransformOverrideType GetWorldTransformOverrideType();
@ -128,6 +149,11 @@ public:
bool Wants_DenyTeleport(UGripMotionControllerComponent * Controller);
virtual bool Wants_DenyTeleport_Implementation(UGripMotionControllerComponent* Controller);
#if UE_WITH_IRIS
/** Register all replication fragments */
virtual void RegisterReplicationFragments(UE::Net::FFragmentRegistrationContext& Context, UE::Net::EFragmentRegistrationFlags RegistrationFlags) override;
#endif // UE_WITH_IRIS
virtual void GetLifetimeReplicatedProps(TArray< class FLifetimeProperty > & OutLifetimeProps) const override;
// doesn't currently compile in editor builds, not sure why the linker is screwing up there but works elsewhere
@ -200,6 +226,7 @@ public:
UFUNCTION(BlueprintPure, Category = "VRGripScript")
bool IsServer();
virtual void BeginDestroy();
void EndPlay(const EEndPlayReason::Type EndPlayReason);
// Not all scripts will require this function, specific ones that use things like Lever logic however will. Best to call it.

View file

@ -161,10 +161,10 @@ public:
bool bDisabled;
/***
/* If true then the hand socket will be locked in place during gameplay and not moved with the actor (saving performance)
/* Generally you want this unless you are moving a hand socket manually during play for custom grip offsetting logic
/* If you need the relative location of the hand socket for game logic, get the LockedRelativeTransform variable if bLockInPlace is enabled.
/* Defaulted off currently for bug testing
// If true then the hand socket will be locked in place during gameplay and not moved with the actor (saving performance)
// Generally you want this unless you are moving a hand socket manually during play for custom grip offsetting logic
// If you need the relative location of the hand socket for game logic, get the LockedRelativeTransform variable if bLockInPlace is enabled.
// Defaulted off currently for bug testing
***/
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Hand Socket Data|Control")
bool bLockInPlace;
@ -232,6 +232,26 @@ public:
UFUNCTION(BlueprintCallable, Category = "Hand Socket Data", meta = (bIgnoreSelf = "true"))
static bool GetAnimationSequenceAsPoseSnapShot(UAnimSequence * InAnimationSequence, FPoseSnapshot& OutPoseSnapShot, USkeletalMeshComponent* TargetMesh = nullptr, bool bSkipRootBone = false, bool bFlipHand = false);
/**
* Gets all hand socket components in the entire level (this is a slow operation, DO NOT run this on tick)
*/
UFUNCTION(BlueprintCallable, Category = "Hand Socket Data")
static void GetAllHandSocketComponents(TArray<UHandSocketComponent*>& OutHandSockets);
/**
* Gets all hand socket components within a set range of a world location (this is a slow operation, DO NOT run this on tick)
*/
UFUNCTION(BlueprintCallable, Category = "Hand Socket Data")
static bool GetAllHandSocketComponentsInRange(FVector SearchFromWorldLocation, float SearchRange, TArray<UHandSocketComponent*>& OutHandSockets);
/**
* Gets the closest hand socket component within a set range of a world location (this is a slow operation, DO NOT run this on tick)
* Must check the output for validity
*/
UFUNCTION(BlueprintCallable, Category = "Hand Socket Data")
static UHandSocketComponent* GetClosestHandSocketComponentInRange(FVector SearchFromWorldLocation, float SearchRange);
// Returns the target relative transform of the hand
//UFUNCTION(BlueprintCallable, Category = "Hand Socket Data")
FTransform GetHandRelativePlacement();

View file

@ -108,7 +108,7 @@ protected:
public:
void BeginPlay() override;
virtual void BeginPlay() override;
virtual void InitializeComponent() override;
bool IsLocallyControlled() const;
@ -200,7 +200,7 @@ public:
bool bHadRelativeMovement;
FPrimitiveSceneProxy* CreateSceneProxy() override;
void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
virtual void UpdatePhysicsVolume(bool bTriggerNotifiers) override;

View file

@ -15,6 +15,7 @@ public class VRExpansionPlugin : ModuleRules
//bEnforceIWYU = true;
PublicDefinitions.Add("WITH_VR_EXPANSION=1");
SetupIrisSupport(Target);
// To detect VR Preview, not built out in packaged builds
if (Target.bBuildEditor == true)