diff --git a/Content/Input/InputMappingContext.uasset b/Content/Input/InputMappingContext.uasset new file mode 100644 index 0000000000000000000000000000000000000000..c288799bfb707b229c0f7a37b00a5312a958cced --- /dev/null +++ b/Content/Input/InputMappingContext.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cd5ee3e188c0ecf6037ba855e15c20420dbdd7487d3aba12c48a71c55a944c0b +size 11924 diff --git a/Content/Input/NextSentence.uasset b/Content/Input/NextSentence.uasset new file mode 100644 index 0000000000000000000000000000000000000000..ee71f0162b1e37c815cfaf658a84235a51a023f7 --- /dev/null +++ b/Content/Input/NextSentence.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6ac35d22d798b6c67eefb568f16d3d08b01f183b39c7848fdae7b042d958a189 +size 1349 diff --git a/Content/Input/SaveAnimation.uasset b/Content/Input/SaveAnimation.uasset new file mode 100644 index 0000000000000000000000000000000000000000..d74c8620ab433fdeb3e163bef117b97b54db21e1 --- /dev/null +++ b/Content/Input/SaveAnimation.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1409a3ef562ddcdce0ea891bbc41b78978d5bf3c8a82142afe40b5b12a5f3484 +size 1354 diff --git a/Content/Input/SetMarker.uasset b/Content/Input/SetMarker.uasset new file mode 100644 index 0000000000000000000000000000000000000000..e55958695e75bb4f81a4e435f88d2128eb87759a --- /dev/null +++ b/Content/Input/SetMarker.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a03a160c795ebe01c641f91af9b8c6311c4f15e36156931228ae9c4f5e0f6324 +size 1334 diff --git a/Content/Input/StartRecording.uasset b/Content/Input/StartRecording.uasset new file mode 100644 index 0000000000000000000000000000000000000000..174ebd3ae614df18074b670aa3542ece332d0b43 --- /dev/null +++ b/Content/Input/StartRecording.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:52d97862a6b745a1e27360eddf365e3343f23f1144397c56021ccce2b1a9d713 +size 1359 diff --git a/Content/Input/ToggleRecording.uasset b/Content/Input/ToggleRecording.uasset new file mode 100644 index 0000000000000000000000000000000000000000..76b856fe0ca455fc6fe4a398cf002dc0d8febbd7 --- /dev/null +++ b/Content/Input/ToggleRecording.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bb821e7b7e4a444e8e0cac4429630e9776fdb2dca937af0030922083dc2a9b9a +size 1364 diff --git a/Content/MoCapMap.umap b/Content/MoCapMap.umap index 14a7dbb360357d4db9cfa0446809f68e5432f3d5..b73e7d46d01bc066d818fdb7250544878bf02e66 100644 --- a/Content/MoCapMap.umap +++ b/Content/MoCapMap.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e411c0cd1771015cf525991322daa708792baa510251ad631d8241e420363934 -size 88754 +oid sha256:447434a35a182e65441c7059ea90d3ad5fa1d6de4df788832979e768fbaeb2d1 +size 91652 diff --git a/Source/MoCapPlugin/MoCapPlugin.Build.cs b/Source/MoCapPlugin/MoCapPlugin.Build.cs index 848ecc82372293c1916a80b910c8a2c8a7672033..617f2fa11e737c6a5e1fa3f5e4959ffbf2511be8 100644 --- a/Source/MoCapPlugin/MoCapPlugin.Build.cs +++ b/Source/MoCapPlugin/MoCapPlugin.Build.cs @@ -27,7 +27,8 @@ public class MoCapPlugin : ModuleRules "AnimGraphRuntime", "CharacterPlugin", "ControlRig", - "RigVM" + "RigVM", + "EnhancedInput" } ); diff --git a/Source/MoCapPlugin/Private/MCController.cpp b/Source/MoCapPlugin/Private/MCController.cpp index f6e318e22ca82a2de4047e35be8529ecc2802797..6401f82ed22e4655f538d10bb3986c731dfdf724 100644 --- a/Source/MoCapPlugin/Private/MCController.cpp +++ b/Source/MoCapPlugin/Private/MCController.cpp @@ -12,7 +12,8 @@ #include "Engine/Engine.h" #include "Kismet/GameplayStatics.h" #include "AssetRegistryModule.h" -#include "SteamVRInputDeviceFunctionLibrary.h" +#include "SteamVRInputDeviceFunctionLibrary.h" +#include "Animation/AnimData/IAnimationDataController.h" AMCController::AMCController() { @@ -38,12 +39,18 @@ void AMCController::BeginPlay() { APlayerController* Controller = UGameplayStatics::GetPlayerController(GetWorld(), 0); EnableInput(Controller); - if (SetControls && InputComponent != nullptr) { - InputComponent->BindAction("ToggleRecording", EInputEvent::IE_Pressed, this, &AMCController::ToggleRecording); - InputComponent->BindAction("SetMarker", EInputEvent::IE_Pressed, this, &AMCController::SetMarker); - InputComponent->BindAction("StartRecording", EInputEvent::IE_Pressed, this, &AMCController::ToggleRecording); - InputComponent->BindAction("NextSentence", EInputEvent::IE_Pressed, this, &AMCController::SetMarker); - InputComponent->BindAction("SaveAnimation", EInputEvent::IE_Pressed, this, &AMCController::SaveAnimationEditor); + UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(Controller->GetLocalPlayer()); + Subsystem->ClearAllMappings(); + Subsystem->AddMappingContext(InputMapping, 0); + + UEnhancedInputComponent* Input = Cast<UEnhancedInputComponent>(InputComponent); + + if (SetControls && Input != nullptr) { + Input->BindAction(InputToggleRecording, ETriggerEvent::Triggered, this, &AMCController::ToggleRecording); + Input->BindAction(InputSetMarker, ETriggerEvent::Triggered, this, &AMCController::SetMarker); + Input->BindAction(InputStartRecording, ETriggerEvent::Triggered, this, &AMCController::ToggleRecording); + Input->BindAction(InputNextSentence, ETriggerEvent::Triggered, this, &AMCController::SetMarker); + Input->BindAction(InputSaveAnimation, ETriggerEvent::Triggered, this, &AMCController::SaveAnimationEditor); } if (!Pawn || !Pawn->GetActorLocation().Equals(FVector(0, 0, 0)) || !Pawn->GetActorRotation().Equals(FRotator(0, 0, 0))) { @@ -659,16 +666,16 @@ bool AMCController::PreprocessRecording(float StartHaltingPoint, float EndHaltin SaveContent += FString::SanitizeFloat(Entry->Pos.X) + "," + FString::SanitizeFloat(Entry->Pos.Y) + "," + FString::SanitizeFloat(Entry->Pos.Z) + "," + FString::SanitizeFloat(Entry->Rot.X) + "," + FString::SanitizeFloat(Entry->Rot.Y) + "," + FString::SanitizeFloat(Entry->Rot.Z) + "," + FString::SanitizeFloat(Entry->Rot.W) + "\n"; } - FString SavePath = FPaths::ProjectContentDir() + "/LastDefaultPose.txt"; + FString SavePath = FPaths::ProjectContentDir() + "LastDefaultPose.txt"; FFileHelper::SaveStringToFile(SaveContent, *SavePath); break; } } } } - else if(FPaths::FileExists(FPaths::ProjectContentDir() + "/" + TakeDefaultPoseFromFile)) { + else if(FPaths::FileExists(FPaths::ProjectContentDir() + TakeDefaultPoseFromFile)) { TArray<FString> SaveContent; - FString SavePath = FPaths::ProjectContentDir() + "/" + TakeDefaultPoseFromFile; + FString SavePath = FPaths::ProjectContentDir() + TakeDefaultPoseFromFile; FFileHelper::LoadFileToStringArray(SaveContent, *SavePath); for (int i = 0; i < SaveContent.Num(); i++) { EBodyPart Type = EBodyPart(i); @@ -1067,10 +1074,10 @@ void AMCController::SaveAnimSnapshots() { FolderName = Dest + "_" + FString::FromInt(j); } j++; - } while (FPaths::DirectoryExists(FPaths::ProjectContentDir() + "/" + FolderName)); + } while (FPaths::DirectoryExists(FPaths::ProjectContentDir() + FolderName)); IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile(); - PlatformFile.CreateDirectory(*(FPaths::ProjectContentDir() + "/" + FolderName)); + PlatformFile.CreateDirectory(*(FPaths::ProjectContentDir() + FolderName)); for (int i = 0; i < Anims.Num(); i++) { FString AnimName; @@ -1121,7 +1128,7 @@ UAnimSequence* AMCController::SaveAsAnimSequence(const FSnapshotAnimations& Reco int32 PelvisIndex = AnimationSequence->GetSkeleton()->GetSkeletonBoneIndexFromMeshBoneIndex(AnimSaveState.Pawn->SkeletalMesh->SkeletalMesh, RefPelvisIndex); AnimationSequence->GetSkeleton()->SetBoneTranslationRetargetingMode(PelvisIndex, EBoneTranslationRetargetingMode::Animation, false); - AnimationSequence->SetSequenceLength((Recording.EndTime - Recording.StartTime).GetTotalSeconds()); + //AnimationSequence->SetSequenceLength((Recording.EndTime - Recording.StartTime).GetTotalSeconds()); Controller.SetPlayLength((Recording.EndTime - Recording.StartTime).GetTotalSeconds()); Controller.SetFrameRate(FFrameRate((Recording.EndTime - Recording.StartTime).GetTotalSeconds(), Recording.Snapshots.Num())); @@ -1155,32 +1162,43 @@ void AMCController::SetBonesAnimationInAnimSeq(const FSnapshotAnimations& Record IAnimationDataController& Controller = AnimSequence->GetController(); - for (const FName& BoneName : BoneNames) { + for (int i = 0; i < BoneNames.Num(); i++) { + int32 in = AnimSequence->GetController().AddBoneTrack(BoneNames[i]); + } - FRawAnimSequenceTrack Track; + for (int i = 0; i < BoneNames.Num(); i++) { + + TArray<FQuat4f> RotKeys; + TArray<FVector3f> PosKeys; + TArray<FVector3f> ScaleKeys; for (int Frame = 0; Frame < Recording.Snapshots.Num(); Frame++) { const FPoseSnapshot& Snapshot = Recording.Snapshots[Frame]; - int32 Index = Snapshot.BoneNames.IndexOfByKey(BoneName); + int32 Index = Snapshot.BoneNames.IndexOfByKey(BoneNames[i]); if (Index != INDEX_NONE) { - Track.RotKeys.Add(FQuat4f(Snapshot.LocalTransforms[Index].GetRotation())); - Track.PosKeys.Add(FVector3f(Snapshot.LocalTransforms[Index].GetLocation())); + RotKeys.Add(FQuat4f(Snapshot.LocalTransforms[Index].GetRotation())); + PosKeys.Add(FVector3f(Snapshot.LocalTransforms[Index].GetLocation())); + ScaleKeys.Add(FVector3f::OneVector); } else if (Frame == 0) { - Track.RotKeys.Add(FQuat4f(FRotator::ZeroRotator.Quaternion())); - Track.PosKeys.Add(FVector3f(FVector::ZeroVector)); + RotKeys.Add(FQuat4f(FRotator::ZeroRotator.Quaternion())); + PosKeys.Add(FVector3f(FVector::ZeroVector)); + ScaleKeys.Add(FVector3f::OneVector); } else { - Track.RotKeys.Add(Track.RotKeys[Frame - 1]); - Track.PosKeys.Add(Track.PosKeys[Frame - 1]); + RotKeys.Add(RotKeys[Frame - 1]); + PosKeys.Add(PosKeys[Frame - 1]); + ScaleKeys.Add(FVector3f::OneVector); } } - Controller.AddBoneTrack(BoneName); - Controller.SetBoneTrackKeys(BoneName, Track.PosKeys, Track.RotKeys, {}); + bool juh = AnimSequence->GetController().SetBoneTrackKeys(BoneNames[i], PosKeys, RotKeys, ScaleKeys); + if (juh) { + RotKeys.Add(FQuat4f::Identity); + } } #endif diff --git a/Source/MoCapPlugin/Private/MCLogHandler.cpp b/Source/MoCapPlugin/Private/MCLogHandler.cpp index e347d8db2ba44b8440406ec8a0c2e58d0ebb9b73..7a4d9ac3ec26d0561714313a564470f8def6a704 100644 --- a/Source/MoCapPlugin/Private/MCLogHandler.cpp +++ b/Source/MoCapPlugin/Private/MCLogHandler.cpp @@ -47,9 +47,9 @@ struct DirectoryVisitor : public IPlatformFile::FDirectoryVisitor { void UMCLogHandler::CopyLogToRecordings(FString& Name) { - if (!FPaths::DirectoryExists(FPaths::ProjectSavedDir() + "/Recordings")) { + if (!FPaths::DirectoryExists(FPaths::ProjectSavedDir() + "Recordings")) { IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile(); - PlatformFile.CreateDirectory(*(FPaths::ProjectSavedDir() + "/Recordings")); + PlatformFile.CreateDirectory(*(FPaths::ProjectSavedDir() + "Recordings")); } int LastSubIndex = Name.Find("_", ESearchCase::CaseSensitive, ESearchDir::FromEnd); @@ -70,7 +70,7 @@ void UMCLogHandler::CopyLogToRecordings(FString& Name) { FolderName = Name + "_" + FString::FromInt(j + 1); } j++; - } while (FPaths::DirectoryExists(FPaths::ProjectSavedDir() + "/Recordings/" + FolderName)); + } while (FPaths::DirectoryExists(FPaths::ProjectSavedDir() + "Recordings/" + FolderName)); Name = FolderName; diff --git a/Source/MoCapPlugin/Public/MCController.h b/Source/MoCapPlugin/Public/MCController.h index 2dfdd3ec79802a03fa8e397bf7d53dcc6889cc87..473eb4c723e6c2891be8d95ae627b125ef842ed8 100644 --- a/Source/MoCapPlugin/Public/MCController.h +++ b/Source/MoCapPlugin/Public/MCController.h @@ -13,6 +13,9 @@ #include "MCFeedbackWidget.h" #include "Components/WidgetComponent.h" #include "Engine/SceneCapture2D.h" +#include "EnhancedInput/Public/EnhancedInputComponent.h" +#include "EnhancedInput/Public/InputMappingContext.h" +#include "EnhancedInput/Public/EnhancedInputSubsystems.h" #include "MCController.generated.h" @@ -168,6 +171,24 @@ public: UPROPERTY(EditAnywhere, meta = (DisplayName = "Right Foot Plane", Category = "MotionCapture Map")) AActor* RightFootPlane; + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "MotionCapture Map") + UInputMappingContext* InputMapping; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "MotionCapture Map") + UInputAction* InputToggleRecording; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "MotionCapture Map") + UInputAction* InputSetMarker; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "MotionCapture Map") + UInputAction* InputStartRecording; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "MotionCapture Map") + UInputAction* InputNextSentence; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "MotionCapture Map") + UInputAction* InputSaveAnimation; + /*------------ANIM PROPERTIES-------------*/ UPROPERTY(EditAnywhere, meta = (DisplayName = "Frames per Second", Category = "MotionCapture Anim"))