From 57e690ae16631607106676bcc78df893c6421dcd Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Fri, 27 Jun 2025 14:47:50 +0200 Subject: [PATCH] update VRExpansionPlugin plugin with changes from upstream --- .../Private/HandSocketComponentDetails.cpp | 4 +- .../Private/GripMotionControllerComponent.cpp | 38 +++++++++---- .../Grippables/GrippableStaticMeshActor.cpp | 4 +- .../Grippables/HandSocketComponent.cpp | 11 ++-- .../Private/Interactibles/VRDialComponent.cpp | 28 ++++++--- .../Private/Misc/CollisionIgnoreSubsystem.cpp | 32 ++++------- .../Private/ReplicatedVRCameraComponent.cpp | 8 +-- .../Private/VRBPDatatypes.cpp | 15 +++++ .../Private/VRCharacterMovementComponent.cpp | 6 +- .../Private/VRExpansionFunctionLibrary.cpp | 5 ++ .../Private/VRRootComponent.cpp | 30 +++++++--- .../Private/VRStereoWidgetComponent.cpp | 11 +++- .../Public/Grippables/HandSocketComponent.h | 2 +- .../Public/Misc/VRWheeledVehicle.h | 57 +++++++++++++++++++ .../ParentRelativeAttachmentComponent.h | 3 +- .../VRExpansionPlugin/Public/VRBPDatatypes.h | 2 + .../Public/VRExpansionFunctionLibrary.h | 4 ++ .../Public/VRRootComponent.h | 11 +++- 18 files changed, 204 insertions(+), 67 deletions(-) diff --git a/Plugins/VRExpansionPlugin/Source/VRExpansionEditor/Private/HandSocketComponentDetails.cpp b/Plugins/VRExpansionPlugin/Source/VRExpansionEditor/Private/HandSocketComponentDetails.cpp index 4198f7c..cb853cf 100644 --- a/Plugins/VRExpansionPlugin/Source/VRExpansionEditor/Private/HandSocketComponentDetails.cpp +++ b/Plugins/VRExpansionPlugin/Source/VRExpansionEditor/Private/HandSocketComponentDetails.cpp @@ -107,7 +107,7 @@ TWeakObjectPtr FHandSocketComponentDetails::SaveAnimationAsset(co if (!BaseAnimation) { - LocalPoses = HandSocketComponent->VisualizationMesh->GetSkeleton()->GetRefLocalPoses(); + LocalPoses = HandSocketComponent->VisualizationMesh->GetRefSkeleton().GetRefBonePose(); } // If not, create new one now. @@ -251,7 +251,7 @@ TWeakObjectPtr FHandSocketComponentDetails::SaveAnimationAsset(co int32 BoneIndex = BoneTreeIndex;//AnimSkeleton->GetMeshBoneIndexFromSkeletonBoneIndex(SkeletalMesh, BoneTreeIndex); //int32 ParentIndex = SkeletalMesh->RefSkeleton.GetParentIndex(BoneIndex); FTransform LocalTransform = LocalPoses[BoneIndex]; - + //FTransform LocalTransform = RefSkeleton.GetRefBonePose()[BoneIndex]; FName BoneName = AnimSkeleton->GetReferenceSkeleton().GetBoneName(BoneIndex); diff --git a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/GripMotionControllerComponent.cpp b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/GripMotionControllerComponent.cpp index 5bcf7aa..f4e23d3 100644 --- a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/GripMotionControllerComponent.cpp +++ b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/GripMotionControllerComponent.cpp @@ -4310,7 +4310,7 @@ bool UGripMotionControllerComponent::TeleportMoveGrippedActor(AActor * GrippedAc FBPActorGripInformation * GripInfo = LocallyGrippedObjects.FindByKey(GrippedActorToMove); if (!GripInfo) - GrippedObjects.FindByKey(GrippedActorToMove); + GripInfo = GrippedObjects.FindByKey(GrippedActorToMove); if (GripInfo) { @@ -4327,7 +4327,7 @@ bool UGripMotionControllerComponent::TeleportMoveGrippedComponent(UPrimitiveComp FBPActorGripInformation * GripInfo = LocallyGrippedObjects.FindByKey(ComponentToMove); if (!GripInfo) - GrippedObjects.FindByKey(ComponentToMove); + GripInfo = GrippedObjects.FindByKey(ComponentToMove); if (GripInfo) { @@ -6017,7 +6017,7 @@ void UGripMotionControllerComponent::CleanUpBadPhysicsHandles() { FBPActorGripInformation * GripInfo = LocallyGrippedObjects.FindByKey(PhysicsGrips[g].GripID); if(!GripInfo) - GrippedObjects.FindByKey(PhysicsGrips[g].GripID); + GripInfo = GrippedObjects.FindByKey(PhysicsGrips[g].GripID); if (!GripInfo) { @@ -7214,18 +7214,25 @@ void UGripMotionControllerComponent::ApplyTrackingParameters(FVector& OriginalPo if (GEngine->XRSystem->GetCurrentPose(IXRTrackingSystem::HMDDeviceId, curRot, curLoc)) { - if (IsValid(AttachChar) && AttachChar->VRReplicatedCamera) + /*if (IsValid(AttachChar) && AttachChar->VRReplicatedCamera) { AttachChar->VRReplicatedCamera->ApplyTrackingParameters(curLoc, true); - } + }*/ //curLoc.Z = 0; LastLocationForLateUpdate = curLoc; if (IsValid(AttachChar) && !AttachChar->bRetainRoomscale) { - FRotator StoredCameraRotOffset = UVRExpansionFunctionLibrary::GetHMDPureYaw_I(curRot.Rotator()); - LastLocationForLateUpdate += StoredCameraRotOffset.RotateVector(FVector(AttachChar->VRRootReference->VRCapsuleOffset.X, AttachChar->VRRootReference->VRCapsuleOffset.Y, 0.0f)); + if (AttachChar->VRMovementReference && AttachChar->VRMovementReference->GetReplicatedMovementMode() == EVRConjoinedMovementModes::C_VRMOVE_Seated) + { + + } + else + { + FRotator StoredCameraRotOffset = UVRExpansionFunctionLibrary::GetHMDPureYaw_I(curRot.Rotator()); + LastLocationForLateUpdate += StoredCameraRotOffset.RotateVector(FVector(AttachChar->VRRootReference->VRCapsuleOffset.X, AttachChar->VRRootReference->VRCapsuleOffset.Y, 0.0f)); + } } } } @@ -7234,12 +7241,19 @@ void UGripMotionControllerComponent::ApplyTrackingParameters(FVector& OriginalPo if (IsValid(AttachChar) && AttachChar->VRReplicatedCamera) { // Sample camera location instead - LastLocationForLateUpdate = AttachChar->VRReplicatedCamera->GetRelativeLocation(); + LastLocationForLateUpdate = AttachChar->VRReplicatedCamera->ReplicatedCameraTransform.Position; //GetRelativeLocation(); if (!AttachChar->bRetainRoomscale && IsLocallyControlled()) { - FRotator StoredCameraRotOffset = UVRExpansionFunctionLibrary::GetHMDPureYaw_I(AttachChar->VRReplicatedCamera->GetRelativeRotation()); - LastLocationForLateUpdate += StoredCameraRotOffset.RotateVector(FVector(AttachChar->VRRootReference->VRCapsuleOffset.X, AttachChar->VRRootReference->VRCapsuleOffset.Y, 0.0f)); + if (AttachChar->VRMovementReference && AttachChar->VRMovementReference->GetReplicatedMovementMode() == EVRConjoinedMovementModes::C_VRMOVE_Seated) + { + + } + else + { + FRotator StoredCameraRotOffset = UVRExpansionFunctionLibrary::GetHMDPureYaw_I(AttachChar->VRReplicatedCamera->GetRelativeRotation()); + LastLocationForLateUpdate += StoredCameraRotOffset.RotateVector(FVector(AttachChar->VRRootReference->VRCapsuleOffset.X, AttachChar->VRRootReference->VRCapsuleOffset.Y, 0.0f)); + } } } } @@ -8334,12 +8348,12 @@ void UGripMotionControllerComponent::GetHandType(EControllerHand& Hand) { // Check if the palm motion source extension is being used // I assume eventually epic will handle this case - if (MotionSource.Compare(FName(TEXT("RightPalm"))) == 0) + if (MotionSource.Compare(FName(TEXT("RightPalm"))) == 0 || MotionSource.Compare(FName(TEXT("RightWrist"))) == 0) { Hand = EControllerHand::Right; } // Could skip this and default to left now but would rather check - else if (MotionSource.Compare(FName(TEXT("LeftPalm"))) == 0) + else if (MotionSource.Compare(FName(TEXT("LeftPalm"))) == 0 || MotionSource.Compare(FName(TEXT("LeftWrist"))) == 0) { Hand = EControllerHand::Left; } diff --git a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableStaticMeshActor.cpp b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableStaticMeshActor.cpp index 74dec5c..a2fa1ee 100644 --- a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableStaticMeshActor.cpp +++ b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableStaticMeshActor.cpp @@ -805,11 +805,11 @@ void AGrippableStaticMeshActor::OnRep_ReplicatedMovement() return; } - if (VRGripInterfaceSettings.HoldingControllers.Num() > 0) + /*if (VRGripInterfaceSettings.HoldingControllers.Num() > 0) { ShouldWeSkipAttachmentReplication(); int gg = 0; - } + }*/ Super::OnRep_ReplicatedMovement(); } diff --git a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/HandSocketComponent.cpp b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/HandSocketComponent.cpp index d11ad29..91a775c 100644 --- a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/HandSocketComponent.cpp +++ b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/HandSocketComponent.cpp @@ -397,7 +397,8 @@ bool UHandSocketComponent::GetBlendedPoseSnapShot(FPoseSnapshot& PoseSnapShot, U PoseSnapShot.LocalTransforms.Empty(); TargetMesh->GetBoneNames(PoseSnapShot.BoneNames); - PoseSnapShot.LocalTransforms = TargetMesh->GetSkinnedAsset()->GetSkeleton()->GetRefLocalPoses(); + //PoseSnapShot.LocalTransforms = TargetMesh->GetSkinnedAsset()->GetSkeleton()->GetRefLocalPoses(); + PoseSnapShot.LocalTransforms = TargetMesh->GetSkinnedAsset()->GetRefSkeleton().GetRefBonePose(); FQuat DeltaQuat = FQuat::Identity; FName TargetBoneName = NAME_None; @@ -692,7 +693,7 @@ void UHandSocketComponent::OnRegister() { if (HandPreviewMaterial) { - HandVisualizerComponent->SetMaterial(0, (UMaterialInterface*)HandPreviewMaterial); + HandVisualizerComponent->SetMaterial(0, HandPreviewMaterial); } HandVisualizerComponent->SetSkinnedAssetAndUpdate(VisualizationMesh); } @@ -782,9 +783,11 @@ void UHandSocketComponent::PoseVisualizationToAnimation(bool bForceRefresh) if (!HandTargetAnimation) { // Store local poses for posing - LocalPoses = HandVisualizerComponent->GetSkinnedAsset()->GetSkeleton()->GetRefLocalPoses(); + LocalPoses = HandVisualizerComponent->GetSkinnedAsset()->GetRefSkeleton().GetRefBonePose(); } + + // Check out of the skin cache, the poses don't update otherwise when enabled int32 NumLODs = HandVisualizerComponent->GetNumLODs(); HandVisualizerComponent->SkinCacheUsage.Empty(NumLODs); @@ -841,6 +844,7 @@ void UHandSocketComponent::PoseVisualizationToAnimation(bool bForceRefresh) else { BoneTrans = LocalPoses[i]; + //BoneTrans = HandVisualizerComponent->GetSkinnedAsset()->GetRefSkeleton().GetRefBonePose()[i]; } BoneTrans = BoneTrans * ParentTrans;// *HandVisualizerComponent->GetComponentTransform(); @@ -851,7 +855,6 @@ void UHandSocketComponent::PoseVisualizationToAnimation(bool bForceRefresh) BoneTrans.ConcatenateRotation(DeltaQuat); BoneTrans.NormalizeRotation(); HandVisualizerComponent->SetBoneTransformByName(BonesNames[i], BoneTrans, EBoneSpaces::ComponentSpace); - } if (HandVisualizerComponent && (!bTickedPose || bForceRefresh)) diff --git a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Interactibles/VRDialComponent.cpp b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Interactibles/VRDialComponent.cpp index 7930efc..d6ec172 100644 --- a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Interactibles/VRDialComponent.cpp +++ b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Interactibles/VRDialComponent.cpp @@ -272,24 +272,34 @@ void UVRDialComponent::OnGripRelease_Implementation(UGripMotionControllerCompone float AngleOffsetCheck = FMath::Abs(FRotator::ClampAxis(CurRotBackEnd) - FRotator::ClampAxis(LastSnapAngle)); float TargetSnap = FMath::RoundToFloat(FMath::GridSnap(CurRotBackEnd, SnapAngleIncrement)); - if (FMath::Abs(FRotator::ClampAxis(CurRotBackEnd) - TargetSnap) <= FMath::Min(SnapAngleIncrement, SnapAngleThreshold)) + if (FMath::Abs(/*FRotator::ClampAxis(*/CurRotBackEnd/*)*/ - TargetSnap) <= FMath::Min(SnapAngleIncrement, SnapAngleThreshold)) { if (AngleOffsetCheck >= SnapAngleThreshold)//FMath::Min(SnapAngleIncrement, SnapAngleThreshold)) { this->SetRelativeRotation((FTransform(UVRInteractibleFunctionLibrary::SetAxisValueRot(DialRotationAxis, FMath::GridSnap(CurRotBackEnd, SnapAngleIncrement), FRotator::ZeroRotator)) * InitialRelativeTransform).Rotator()); CurRotBackEnd = FMath::GridSnap(CurRotBackEnd, SnapAngleIncrement); + + if (bUseRollover) + { + CurrentDialAngle = FMath::RoundToFloat(CurRotBackEnd); + } + else + { + CurrentDialAngle = FRotator::ClampAxis(FMath::RoundToFloat(CurRotBackEnd)); + } + } + else + { + // Reset to the snap angle so that it requires full motion to break out of it + CurRotBackEnd = CurrentDialAngle; } - } - - if (bUseRollover) - { - CurrentDialAngle = FMath::RoundToFloat(CurRotBackEnd); } else { - CurrentDialAngle = FRotator::ClampAxis(FMath::RoundToFloat(CurRotBackEnd)); + // Reset to the snap angle so that it requires full motion to break out of it + CurRotBackEnd = CurrentDialAngle; } - + if (!FMath::IsNearlyEqual(LastSnapAngle, CurrentDialAngle)) { ReceiveDialHitSnapAngle(CurrentDialAngle); @@ -582,7 +592,7 @@ void UVRDialComponent::AddDialAngle(float DialAngleDelta, bool bCallEvents, bool float AngleOffsetCheck = FMath::Abs(FRotator::ClampAxis(CurRotBackEnd) - FRotator::ClampAxis(LastSnapAngle)); float TargetSnap = FMath::RoundToFloat(FMath::GridSnap(CurRotBackEnd, SnapAngleIncrement)); - if (FMath::Abs(FRotator::ClampAxis(CurRotBackEnd) - TargetSnap) <= FMath::Min(SnapAngleIncrement, SnapAngleThreshold)) + if (FMath::Abs(/*FRotator::ClampAxis(*/CurRotBackEnd/*)*/ - TargetSnap) <= FMath::Min(SnapAngleIncrement, SnapAngleThreshold)) { if (AngleOffsetCheck >= SnapAngleThreshold)//FMath::Min(SnapAngleIncrement, SnapAngleThreshold)) { diff --git a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Misc/CollisionIgnoreSubsystem.cpp b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Misc/CollisionIgnoreSubsystem.cpp index 0308f80..06cec9f 100644 --- a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Misc/CollisionIgnoreSubsystem.cpp +++ b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Misc/CollisionIgnoreSubsystem.cpp @@ -161,17 +161,14 @@ void UCollisionIgnoreSubsystem::CheckActiveFilters() { bool bMadeChanges = false; - for (TPair& KeyPair : CollisionTrackedPairs) + for (TMap::TIterator ItRemove = CollisionTrackedPairs.CreateIterator(); ItRemove; ++ItRemove) { - // First check for invalid primitives - if (!IsValid(KeyPair.Key.Prim1) || !IsValid(KeyPair.Key.Prim2)) + // First check for invalid primitives and an empty pair array + if (!IsValid(ItRemove->Key.Prim1) || !IsValid(ItRemove->Key.Prim2) || ItRemove->Value.PairArray.Num() < 1) { - // If we don't have a map element for this pair, then add it now - if (!RemovedPairs.Contains(KeyPair.Key)) - { - RemovedPairs.Add(KeyPair.Key, KeyPair.Value); - bMadeChanges = true; - } + ItRemove->Value.PairArray.Empty(); + ItRemove.RemoveCurrent(); + bMadeChanges = true; continue; // skip remaining checks as we have invalid primitives anyway } @@ -267,16 +264,6 @@ void UCollisionIgnoreSubsystem::CheckActiveFilters() }); } #endif - - // If there are no pairs left - if (KeyPair.Value.PairArray.Num() < 1) - { - // Try and remove it, chaos should be cleaning up the ignore setups - if (!RemovedPairs.Contains(KeyPair.Key)) - { - RemovedPairs.Add(KeyPair.Key, KeyPair.Value); - } - } } /*#if WITH_CHAOS @@ -295,13 +282,18 @@ void UCollisionIgnoreSubsystem::CheckActiveFilters() } #endif*/ - for (const TPair& KeyPair : RemovedPairs) + /*for (const TPair& KeyPair : RemovedPairs) { if (CollisionTrackedPairs.Contains(KeyPair.Key)) { CollisionTrackedPairs[KeyPair.Key].PairArray.Empty(); CollisionTrackedPairs.Remove(KeyPair.Key); } + }*/ + + if (bMadeChanges) + { + CollisionTrackedPairs.Compact(); } UpdateTimer(bMadeChanges); diff --git a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/ReplicatedVRCameraComponent.cpp b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/ReplicatedVRCameraComponent.cpp index c592ee2..d0becb0 100644 --- a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/ReplicatedVRCameraComponent.cpp +++ b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/ReplicatedVRCameraComponent.cpp @@ -210,7 +210,7 @@ void UReplicatedVRCameraComponent::UpdateTracking(float DeltaTime) FRotator StoredCameraRotOffset = FRotator::ZeroRotator; if (AttachChar->VRMovementReference && AttachChar->VRMovementReference->GetReplicatedMovementMode() == EVRConjoinedMovementModes::C_VRMOVE_Seated) { - AttachChar->SeatInformation.InitialRelCameraTransform.Rotator(); + //StoredCameraRotOffset = AttachChar->SeatInformation.InitialRelCameraTransform.Rotator(); } else { @@ -250,7 +250,7 @@ void UReplicatedVRCameraComponent::RunNetworkedSmoothing(float DeltaTime) FRotator StoredCameraRotOffset = FRotator::ZeroRotator; if (AttachChar->VRMovementReference && AttachChar->VRMovementReference->GetReplicatedMovementMode() == EVRConjoinedMovementModes::C_VRMOVE_Seated) { - AttachChar->SeatInformation.InitialRelCameraTransform.Rotator(); + //StoredCameraRotOffset = AttachChar->SeatInformation.InitialRelCameraTransform.Rotator(); } else { @@ -485,7 +485,7 @@ void UReplicatedVRCameraComponent::HandleXRCamera() FRotator StoredCameraRotOffset = FRotator::ZeroRotator; if (AttachChar->VRMovementReference->GetReplicatedMovementMode() == EVRConjoinedMovementModes::C_VRMOVE_Seated) { - AttachChar->SeatInformation.InitialRelCameraTransform.Rotator(); + //StoredCameraRotOffset = AttachChar->SeatInformation.InitialRelCameraTransform.Rotator(); } else { @@ -536,7 +536,7 @@ void UReplicatedVRCameraComponent::OnRep_ReplicatedCameraTransform() FRotator StoredCameraRotOffset = FRotator::ZeroRotator; if (AttachChar->VRMovementReference && AttachChar->VRMovementReference->GetReplicatedMovementMode() == EVRConjoinedMovementModes::C_VRMOVE_Seated) { - AttachChar->SeatInformation.InitialRelCameraTransform.Rotator(); + //StoredCameraRotOffset = AttachChar->SeatInformation.InitialRelCameraTransform.Rotator(); } else { diff --git a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRBPDatatypes.cpp b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRBPDatatypes.cpp index 82cbd35..602330c 100644 --- a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRBPDatatypes.cpp +++ b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRBPDatatypes.cpp @@ -283,6 +283,21 @@ UPrimitiveComponent* FBPActorGripInformation::GetGrippedComponent() const return Cast(GrippedObject); } + +UPrimitiveComponent* FBPActorGripInformation::GetGripPrimitiveComponent() const +{ + UPrimitiveComponent* RootComp = nullptr; + + if (GripTargetType == EGripTargetType::ActorGrip) + { + RootComp = Cast(GetGrippedActor()->GetRootComponent()); + } + else + RootComp = GetGrippedComponent(); + + return RootComp; +} + bool FBPActorGripInformation::operator==(const UPrimitiveComponent* Other) const { if (Other && GrippedObject && GrippedObject == (const UObject*)Other) diff --git a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRCharacterMovementComponent.cpp b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRCharacterMovementComponent.cpp index 504ad79..96afe16 100644 --- a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRCharacterMovementComponent.cpp +++ b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRCharacterMovementComponent.cpp @@ -340,7 +340,11 @@ void UVRCharacterMovementComponent::UnCrouch(bool bClientSimulation) if (!bEncroached) { // Commit the change in location. - //UpdatedComponent->MoveComponent(StandingLocation - PawnLocation, UpdatedComponent->GetComponentQuat(), false, nullptr, EMoveComponentFlags::MOVECOMP_NoFlags, ETeleportType::TeleportPhysics); + if (!BaseVRCharacterOwner || !BaseVRCharacterOwner->bRetainRoomscale) + { + // we actually move this when not using retained roomscale + //UpdatedComponent->MoveComponent(StandingLocation - PawnLocation, UpdatedComponent->GetComponentQuat(), false, nullptr, EMoveComponentFlags::MOVECOMP_NoFlags, ETeleportType::TeleportPhysics); + } bForceNextFloorCheck = true; } } diff --git a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRExpansionFunctionLibrary.cpp b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRExpansionFunctionLibrary.cpp index c634b3b..ad0639d 100644 --- a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRExpansionFunctionLibrary.cpp +++ b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRExpansionFunctionLibrary.cpp @@ -586,6 +586,11 @@ bool UVRExpansionFunctionLibrary::IsActiveGrip(const FBPActorGripInformation& Gr return Grip.IsActive(); } +UPrimitiveComponent* UVRExpansionFunctionLibrary::GetGripPrimitiveTarget(const FBPActorGripInformation& Grip) +{ + return Grip.GetGripPrimitiveComponent(); +} + FTransform_NetQuantize UVRExpansionFunctionLibrary::MakeTransform_NetQuantize(FVector Translation, FRotator Rotation, FVector Scale) { return FTransform_NetQuantize(Rotation, Translation, Scale); diff --git a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRRootComponent.cpp b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRRootComponent.cpp index 2da97a2..3dfa40c 100644 --- a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRRootComponent.cpp +++ b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRRootComponent.cpp @@ -468,7 +468,7 @@ void UVRRootComponent::UpdateCharacterCapsuleOffset() { if (owningVRChar && !owningVRChar->bRetainRoomscale && owningVRChar->NetSmoother) { - if (!FMath::IsNearlyEqual(LastCapsuleHalfHeight, CapsuleHalfHeight)) + if (bCenterCapsuleOnHMD || !FMath::IsNearlyEqual(LastCapsuleHalfHeight, CapsuleHalfHeight)) { owningVRChar->NetSmoother->SetRelativeLocation(GetTargetHeightOffset(), false, nullptr, ETeleportType::TeleportPhysics); @@ -506,6 +506,8 @@ void UVRRootComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, if (IsLocallyControlled()) { + bool bHadBadTracking = false; + if (owningVRChar && owningVRChar->bTrackingPaused) { curCameraLoc = owningVRChar->PausedTrackingLoc; @@ -524,6 +526,7 @@ void UVRRootComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, { curCameraLoc = lastCameraLoc; curCameraRot = lastCameraRot; + bHadBadTracking = true; } else { @@ -562,7 +565,7 @@ void UVRRootComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, // Can adjust the relative tolerances to remove jitter and some update processing - if (!bRetainRoomscale || (!curCameraLoc.Equals(lastCameraLoc, 0.01f) || !curCameraRot.Equals(lastCameraRot, 0.01f))) + if (!bHadBadTracking && (!bRetainRoomscale || (!curCameraLoc.Equals(lastCameraLoc, 0.01f) || !curCameraRot.Equals(lastCameraRot, 0.01f)))) { // Also calculate vector of movement for the movement component FVector LastPosition = OffsetComponentToWorld.GetLocation(); @@ -591,9 +594,23 @@ void UVRRootComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, Params.bFindInitialOverlaps = true; bool bBlockingHit = false; - if (bUseWalkingCollisionOverride && bRetainRoomscale) + if (bUseWalkingCollisionOverride /* && bRetainRoomscale*/) { - FVector TargetWorldLocation = OffsetComponentToWorld.GetLocation(); + FVector TargetWorldLocation = FVector::ZeroVector; + + if (bRetainRoomscale) + { + TargetWorldLocation = OffsetComponentToWorld.GetLocation(); + } + else // Not Retained Roomscale + { + FVector NewLocation = StoredCameraRotOffset.RotateVector(FVector(VRCapsuleOffset.X, VRCapsuleOffset.Y, 0.0f)) + curCameraLoc; + FVector PlanerLocation = NewLocation - lastCameraLoc; + PlanerLocation.Z = 0.0f; + DifferenceFromLastFrame = GetComponentTransform().TransformVector(PlanerLocation); + TargetWorldLocation = LastPosition + DifferenceFromLastFrame; + } + bool bAllowWalkingCollision = false; if (CharMove != nullptr) { @@ -638,7 +655,6 @@ void UVRRootComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, } else { - // Run this first so we get full fidelity on the relative space calculation FVector NewLocation = StoredCameraRotOffset.RotateVector(FVector(VRCapsuleOffset.X, VRCapsuleOffset.Y, 0.0f)) + curCameraLoc; FVector PlanerLocation = NewLocation - lastCameraLoc; @@ -1537,7 +1553,7 @@ bool UVRRootComponent::IsLocallyControlled() const // Simulated proxies should already have the new height from the server if (!owningVRChar->bRetainRoomscale && (owningVRChar->GetNetMode() < ENetMode::NM_Client || IsLocallyControlled())) { - MoveComponent(this->GetComponentQuat().GetUpVector() * (Offset * this->GetComponentScale().Z), GetComponentQuat(), true, nullptr, EMoveComponentFlags::MOVECOMP_NoFlags, ETeleportType::TeleportPhysics); + MoveComponent(this->GetComponentQuat().GetUpVector() * (Offset * this->GetComponentScale().Z), GetComponentQuat(), false, nullptr, EMoveComponentFlags::MOVECOMP_NoFlags, ETeleportType::TeleportPhysics); } /*else { @@ -1545,7 +1561,7 @@ bool UVRRootComponent::IsLocallyControlled() const GenerateOffsetToWorld(); }*/ - if (!owningVRChar->bRetainRoomscale && !IsLocallyControlled()) + if (!owningVRChar->bRetainRoomscale && !IsLocallyControlled() && !IsNetMode(NM_DedicatedServer)) { // Don't smooth this change in mesh position FNetworkPredictionData_Client_Character* ClientData = owningVRChar->GetCharacterMovement()->GetPredictionData_Client_Character(); diff --git a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRStereoWidgetComponent.cpp b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRStereoWidgetComponent.cpp index 6f03c91..9eb072c 100644 --- a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRStereoWidgetComponent.cpp +++ b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRStereoWidgetComponent.cpp @@ -415,6 +415,8 @@ UVRStereoWidgetComponent::~UVRStereoWidgetComponent() void UVRStereoWidgetComponent::EndPlay(const EEndPlayReason::Type EndPlayReason) { + Super::EndPlay(EndPlayReason); + if (EndPlayReason == EEndPlayReason::EndPlayInEditor || EndPlayReason == EEndPlayReason::Quit) { //FStereoLayerAdditionalFlagsManager::Destroy(); @@ -601,7 +603,14 @@ void UVRStereoWidgetComponent::TickComponent(float DeltaTime, enum ELevelTick Ti if (AVRCharacter* VRChar = Cast(mpawn)) { - HMDLoc += UVRExpansionFunctionLibrary::GetHMDPureYaw_I(HMDRot.Rotator()).RotateVector(FVector(VRChar->VRRootReference->VRCapsuleOffset.X, VRChar->VRRootReference->VRCapsuleOffset.Y, 0.0f)); + if (VRChar->VRMovementReference && VRChar->VRMovementReference->GetReplicatedMovementMode() == EVRConjoinedMovementModes::C_VRMOVE_Seated) + { + + } + else + { + HMDLoc += UVRExpansionFunctionLibrary::GetHMDPureYaw_I(HMDRot.Rotator()).RotateVector(FVector(VRChar->VRRootReference->VRCapsuleOffset.X, VRChar->VRRootReference->VRCapsuleOffset.Y, 0.0f)); + } } DeltaTrans = FTransform(FQuat::Identity, HMDLoc, FVector(1.0f)); diff --git a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/Grippables/HandSocketComponent.h b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/Grippables/HandSocketComponent.h index 6073e9c..d3e0ac7 100644 --- a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/Grippables/HandSocketComponent.h +++ b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/Grippables/HandSocketComponent.h @@ -465,7 +465,7 @@ public: #if WITH_EDITORONLY_DATA // Material to apply to the hand UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hand Visualization") - TObjectPtr HandPreviewMaterial; + TObjectPtr HandPreviewMaterial; #endif }; diff --git a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/Misc/VRWheeledVehicle.h b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/Misc/VRWheeledVehicle.h index d29d88c..a0ed62a 100644 --- a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/Misc/VRWheeledVehicle.h +++ b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/Misc/VRWheeledVehicle.h @@ -13,6 +13,40 @@ #include "VRWheeledVehicle.generated.h" +// This only exists to expose the blueprint properties of the transmission values +USTRUCT(BlueprintType, Category = "VRWheeledVehicle") +struct VREXPANSIONPLUGIN_API FBPVehicleTransmissionConfig : public FVehicleTransmissionConfig +{ + GENERATED_BODY() +public: + + void SetFrom(FVehicleTransmissionConfig & Config) + { + bUseAutomaticGears = Config.bUseAutomaticGears; + bUseAutoReverse = Config.bUseAutoReverse; + FinalRatio = Config.FinalRatio; + ForwardGearRatios = Config.ForwardGearRatios; + ReverseGearRatios = Config.ReverseGearRatios; + ChangeUpRPM = Config.ChangeUpRPM; + ChangeDownRPM = Config.ChangeDownRPM; + GearChangeTime = Config.GearChangeTime; + TransmissionEfficiency = Config.TransmissionEfficiency; + } + + void SetTo(FVehicleTransmissionConfig& Config) + { + Config.bUseAutomaticGears = bUseAutomaticGears; + Config.bUseAutoReverse = bUseAutoReverse; + Config.FinalRatio = FinalRatio; + Config.ForwardGearRatios = ForwardGearRatios; + Config.ReverseGearRatios = ReverseGearRatios; + Config.ChangeUpRPM = ChangeUpRPM; + Config.ChangeDownRPM = ChangeDownRPM; + Config.GearChangeTime = GearChangeTime; + Config.TransmissionEfficiency = TransmissionEfficiency; + } +}; + /** * This override of the base wheeled vehicle allows for dual pawn usage in engine. */ @@ -24,6 +58,29 @@ class VREXPANSIONPLUGIN_API AVRWheeledVehicle : public AWheeledVehiclePawn public: + + UFUNCTION(BlueprintPure, Category = "Pawn") + float GetFinalGearRatio() + { + float CurrentGearRatio = 0.0f; + if (UChaosWheeledVehicleMovementComponent* MoveComp = Cast(this->GetMovementComponent())) + { + CurrentGearRatio = MoveComp->TransmissionSetup.FinalRatio; + } + + return CurrentGearRatio; + } + + UFUNCTION(BlueprintCallable, Category = "Pawn") + void SetFinalGearRatio(float NewFinalGearRatio) + { + if (UChaosWheeledVehicleMovementComponent* MoveComp = Cast(this->GetMovementComponent())) + { + MoveComp->TransmissionSetup.FinalRatio = NewFinalGearRatio; + } + } + + // Calls the movement components override controller function UFUNCTION(BlueprintCallable, Category = "Pawn") virtual bool SetBindToInput(AController * CController, bool bBindToInput) { diff --git a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/ParentRelativeAttachmentComponent.h b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/ParentRelativeAttachmentComponent.h index e1abb2f..c95f376 100644 --- a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/ParentRelativeAttachmentComponent.h +++ b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/ParentRelativeAttachmentComponent.h @@ -137,8 +137,7 @@ public: FQuat GetCalculatedRotation(FRotator InverseRot, float DeltaTime) { FRotator FinalRot = FRotator::ZeroRotator; - - if (FPlatformMath::Abs(FRotator::ClampAxis(InverseRot.Yaw) - LastRot) < YawTolerance) // This is never true with the default value of 0.0f + if (FPlatformMath::Abs(FMath::FindDeltaAngleDegrees(InverseRot.Yaw, LastRot)) < YawTolerance) // This is never true with the default value of 0.0f { if (!bWasSetOnce) { diff --git a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/VRBPDatatypes.h b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/VRBPDatatypes.h index 5196519..f04ed78 100644 --- a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/VRBPDatatypes.h +++ b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/VRBPDatatypes.h @@ -1562,6 +1562,8 @@ public: UPrimitiveComponent* GetGrippedComponent() const; + UPrimitiveComponent* GetGripPrimitiveComponent() const; + //Check if a grip is the same as another, the only things I check for are the actor / component //This is here for the Find() function from TArray FORCEINLINE bool operator==(const FBPActorGripInformation &Other) const diff --git a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/VRExpansionFunctionLibrary.h b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/VRExpansionFunctionLibrary.h index a7e12a4..918dd74 100644 --- a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/VRExpansionFunctionLibrary.h +++ b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/VRExpansionFunctionLibrary.h @@ -200,6 +200,10 @@ public: UFUNCTION(BlueprintPure, Category = "VRExpansionFunctions") static bool IsActiveGrip(const FBPActorGripInformation& Grip); + /* Returns the target primitive component if the grip has one (it should always), otherwise it will return invalid */ + UFUNCTION(BlueprintPure, Category = "VRExpansionFunctions") + static UPrimitiveComponent* GetGripPrimitiveTarget(const FBPActorGripInformation& Grip); + /** Make a transform net quantize from location, rotation and scale */ UFUNCTION(BlueprintPure, meta = (Scale = "1,1,1", Keywords = "construct build", NativeMakeFunc), Category = "VRExpansionLibrary|TransformNetQuantize") static FTransform_NetQuantize MakeTransform_NetQuantize(FVector Location, FRotator Rotation, FVector Scale); diff --git a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/VRRootComponent.h b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/VRRootComponent.h index 08ac90f..9bb42ef 100644 --- a/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/VRRootComponent.h +++ b/Plugins/VRExpansionPlugin/Source/VRExpansionPlugin/Public/VRRootComponent.h @@ -57,7 +57,14 @@ public: inline FVector GetTargetHeightOffset() { //return FVector::ZeroVector; - return FVector(0.f, 0.f, (-this->GetUnscaledCapsuleHalfHeight()) - VRCapsuleOffset.Z); + if (bCenterCapsuleOnHMD) + { + return FVector(0.f, 0.f, (-VRCapsuleOffset.Z) - curCameraLoc.Z); + } + else + { + return FVector(0.f, 0.f, (-this->GetUnscaledCapsuleHalfHeight()) - VRCapsuleOffset.Z); + } } /** @@ -266,7 +273,7 @@ void inline UVRRootComponent::GenerateOffsetToWorld(bool bUpdateBounds, bool bGe if(owningVRChar && !owningVRChar->bRetainRoomscale) { - OffsetComponentToWorld = FTransform(CamRotOffset.Quaternion(), FVector(0.0f, 0.0f, bCenterCapsuleOnHMD ? curCameraLoc.Z : 0.0f), FVector(1.0f)) * GetComponentTransform(); + OffsetComponentToWorld = FTransform(CamRotOffset.Quaternion(), FVector(0.0f, 0.0f, 0.0f), FVector(1.0f)) * GetComponentTransform(); } else {