diff --git a/Content/MoCapMap.umap b/Content/MoCapMap.umap index bf7f3307f137ebdf9b97b3f3c0a621d434ccabcf..05a0d22754cf75c4e2919b960225c47f57119074 100644 --- a/Content/MoCapMap.umap +++ b/Content/MoCapMap.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:29c1462b3554bd2fdd0d05bce798be8315c48c75c1e345c85752c6e46e2d9dd2 -size 87731 +oid sha256:e07552ee89cef0a03047b2d47453b6098a23742328a02d75e0aee83ad8828907 +size 87589 diff --git a/Source/MoCapPlugin/Private/MCAnimInstance.cpp b/Source/MoCapPlugin/Private/MCAnimInstance.cpp index 6e7759466f89f7a0aca648c2e90b068d612b766e..5cab788e4bcd63ac7b00d3f768e3c08ed2542936 100644 --- a/Source/MoCapPlugin/Private/MCAnimInstance.cpp +++ b/Source/MoCapPlugin/Private/MCAnimInstance.cpp @@ -14,6 +14,8 @@ void UMCAnimInstance::NativeInitializeAnimation() { AppliedPose = true; DoRig = false; + Scale = FVector(1., 1., 1.); + } void UMCAnimInstance::NativeUpdateAnimation(float DeltaSeconds) { diff --git a/Source/MoCapPlugin/Private/MCController.cpp b/Source/MoCapPlugin/Private/MCController.cpp index b26ecd3be0b85149efd3bafb9ca940815fdf3bbd..6924685eae8c7a1cf2860a1575ae24373002106c 100644 --- a/Source/MoCapPlugin/Private/MCController.cpp +++ b/Source/MoCapPlugin/Private/MCController.cpp @@ -368,6 +368,13 @@ bool AMCController::PreprocessRecording(const TArray<float>& HaltingPoints) { return false; } + //found no end -> add one + /*if (!AnimSaveState.AnimData.Last().IsEnd) { + AnimSaveState.AnimData.Push(FProcessedAnimData()); + AnimSaveState.AnimData.Last().Timestamp = LastStamp + FTimespan::FromMilliseconds(10); + AnimSaveState.AnimData.Last().IsEnd = true; + }*/ + //----process the anim data---- //---Sensor turned off -> interpolate @@ -524,161 +531,61 @@ bool AMCController::PreprocessRecording(const TArray<float>& HaltingPoints) { } //---find last slow part of the gesture and scale it up--- - - TArray<float> GestureSpeed; - bool newMethod = true; - - if (!newMethod) { - if (GestureHoldExcessTime > 0.f) { - - for (int i = 1; i < AnimSaveState.AnimData.Num(); i++) { - - FProcessedAnimData& AnimData = AnimSaveState.AnimData[i]; - - if (AnimData.IsMarker || AnimData.IsEnd) { - continue; - } - - //process sensor data - - float Speed = 0.f; - int SpeedCount = 0; - int window = 1; - - FSensorData& SensorData = AnimData.SensorData; - for (int j = 0; j < EBodyPart::LAST; j++) { - - EBodyPart Type = EBodyPart(j); - FSensorDataEntry* Entry = SensorData.GetEntry(Type); - - if (Type == EBodyPart::HandL || Type == EBodyPart::HandR) { - - for (int w = 0; w < window; w++) { - int index = i + w; - if (index - 1 >= 0 && index < AnimSaveState.AnimData.Num()) { - FProcessedAnimData& Data0 = AnimSaveState.AnimData[index - 1]; - FProcessedAnimData& Data1 = AnimSaveState.AnimData[index]; - float Time = (Data1.Timestamp - Data0.Timestamp).GetTotalSeconds(); - Speed += Time * (Data1.SensorData.GetEntry(Type)->Pos - Data0.SensorData.GetEntry(Type)->Pos).Size(); - - } - } - - SpeedCount++; - - } + + if (HaltingPoints.Num() > 0) { - } + FTimespan Start; + bool StartTimeInitialized = false; + bool hold = false; + int holdStartingIndex = -1; - GestureSpeed.Push(Speed / (float)SpeedCount); + for (int i = 1; i < AnimSaveState.AnimData.Num(); i++) { - } + FProcessedAnimData& AnimData = AnimSaveState.AnimData[i]; - //smooth - TArray<float> SmoothedGestureSpeed; - int window = 5; - int Num = GestureSpeed.Num(); - for (int i = 0; i < Num; i++) { - float avg = 0.f; - for (int wInd = -window; wInd <= window; wInd++) { - int w = i + wInd; - if (w < 0) { - avg += (GestureSpeed[0] + GestureSpeed[1] + GestureSpeed[2] + GestureSpeed[3] + GestureSpeed[4]) / 5.f; - } - else if (w >= Num) { - avg += (GestureSpeed[Num - 1] + GestureSpeed[Num - 2] + GestureSpeed[Num - 3] + GestureSpeed[Num - 4] + GestureSpeed[Num - 5]) / 5.f; - } - else { - avg += GestureSpeed[w]; - } - } - avg /= (float)(window * 2 + 1); - SmoothedGestureSpeed.Push(avg); + if (AnimData.IsMarker || AnimData.IsEnd) { + continue; } - GestureSpeed = SmoothedGestureSpeed; - - int MaxNumToScale = 30; - - //maximum - int maxWindow = 8; - int ScaleStart; - for (ScaleStart = GestureSpeed.Num() - 1; ScaleStart >= 0 && ScaleStart >= GestureSpeed.Num() - MaxNumToScale; ScaleStart--) { - bool isMax = true; - for (int w = -maxWindow; w <= maxWindow; w++) { - int index = ScaleStart + w; - if (index >= 0 && index < GestureSpeed.Num() && index != ScaleStart) { - if (GestureSpeed[index] >= GestureSpeed[ScaleStart]) { - isMax = false; - break; - } - } - } - if (isMax) { - break; - } + if (!StartTimeInitialized) { + StartTimeInitialized = true; + Start = AnimData.Timestamp; } - ScaleAnimDataInterval(ScaleStart, AnimSaveState.AnimData.Num() - 2, GestureHoldExcessTime); - - } - } - else { - if (HaltingPoints.Num() > 0) { - - FTimespan Start; - bool StartTimeInitialized = false; - bool hold = false; - int holdStartingIndex = -1; - - for (int i = 1; i < AnimSaveState.AnimData.Num(); i++) { - - FProcessedAnimData& AnimData = AnimSaveState.AnimData[i]; - - if (AnimData.IsMarker || AnimData.IsEnd) { - continue; - } - - if (!StartTimeInitialized) { - StartTimeInitialized = true; - Start = AnimData.Timestamp; - } - - //process sensor data + //process sensor data - FSensorData& SensorData = AnimData.SensorData; - for (int j = 0; j < EBodyPart::LAST; j++) { + FSensorData& SensorData = AnimData.SensorData; + for (int j = 0; j < EBodyPart::LAST; j++) { - EBodyPart Type = EBodyPart(j); - FSensorDataEntry* Entry = SensorData.GetEntry(Type); + EBodyPart Type = EBodyPart(j); + FSensorDataEntry* Entry = SensorData.GetEntry(Type); - if (Type == EBodyPart::HandL || Type == EBodyPart::HandR - || Type == EBodyPart::LowerArmL || Type == EBodyPart::LowerArmR) { + if (Type == EBodyPart::HandL || Type == EBodyPart::HandR + || Type == EBodyPart::LowerArmL || Type == EBodyPart::LowerArmR) { - if (DoHolding && hold) { - if (Type == EBodyPart::HandL || Type == EBodyPart::HandR) { - Entry->Pos = AnimSaveState.AnimData[i - 1].SensorData.GetEntry(Type)->Pos; - } - Entry->Rot = AnimSaveState.AnimData[i - 1].SensorData.GetEntry(Type)->Rot; + if (DoHolding && hold) { + if (Type == EBodyPart::HandL || Type == EBodyPart::HandR) { + Entry->Pos = AnimSaveState.AnimData[i - 1].SensorData.GetEntry(Type)->Pos; } - + Entry->Rot = AnimSaveState.AnimData[i - 1].SensorData.GetEntry(Type)->Rot; } } - //or time unit? - if (!hold && HaltingPoints[0] <= (AnimData.Timestamp - Start).GetTotalSeconds()) { - hold = true; - holdStartingIndex = i; - } - } - if (hold && GestureHoldExcessTime > 0.f) { - ScaleAnimDataInterval(holdStartingIndex, AnimSaveState.AnimData.Num() - 2, GestureHoldExcessTime); + //or time unit? + if (!hold && HaltingPoints[0] <= (AnimData.Timestamp - Start).GetTotalSeconds()) { + hold = true; + holdStartingIndex = i; } } + + if (hold && GestureHoldExcessTime > 0.f) { + ScaleAnimDataInterval(holdStartingIndex, AnimSaveState.AnimData.Num() - 2, GestureHoldExcessTime); + } + } //---adjust feet position so that they are located at the green foot indicators--- @@ -743,15 +650,6 @@ bool AMCController::PreprocessRecording(const TArray<float>& HaltingPoints) { } AnimSaveState.NextFrame = FTimespan(); - - - //debugging things - - std::string speed = ""; - - for (int i = 0; i < GestureSpeed.Num(); i++) { - speed += "\n" + std::to_string(GestureSpeed[i]); - } return true; @@ -1206,7 +1104,7 @@ void AMCController::ToggleRecording() { CurRecordingInSession++; } - if (DebugMode) { + if (DebugMode || KeepDoingRig) { Pawn->GetAnimInstance()->DoRig = true; } else { @@ -1256,18 +1154,33 @@ void AMCController::SaveAnimation(const TArray<float>& HaltingPoints, bool skipT return; } - FString LogSourcePath; - FFileHelper::LoadFileToString(LogSourcePath, *(PathSaved + "/LogSourcePath.txt")); - LogSourcePath = FPaths::ProjectSavedDir() + "OwnLogs/" + LogSourcePath; + TArray<FString> LogSourcePath; + FFileHelper::LoadFileToStringArray(LogSourcePath, *(PathSaved + "/LogSourcePath.txt")); + LogSourcePath[0] = FPaths::ProjectSavedDir() + "OwnLogs/" + LogSourcePath[0]; - if (!FPaths::FileExists(LogSourcePath)) { + if (!FPaths::FileExists(LogSourcePath[0])) { GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, FString::Printf(TEXT("The corresponding Log to this recording name in OwnLogs is not existent!"))); return; } IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile(); - PlatformFile.CopyFile(*(PathSaved + "/DataLog.log"), *LogSourcePath); - PathSaved = LogSourcePath; + PlatformFile.CopyFile(*(PathSaved + "/DataLog.log"), *LogSourcePath[0]); + PathSaved = LogSourcePath[0]; + + //restore stopped file + if (LogSourcePath.Num() > 1) { + LogSourcePath[1] = FPaths::ProjectSavedDir() + "OwnLogs/" + LogSourcePath[1]; + if (FPaths::FileExists(LogSourcePath[1])) { + FString StoppedFile; + FFileHelper::LoadFileToString(StoppedFile, *LogSourcePath[1]); + FString ToAddOn; + FFileHelper::LoadFileToString(ToAddOn, *PathSaved); + if (!ToAddOn.Contains("\"End\"}")) { + ToAddOn += StoppedFile; + FFileHelper::SaveStringToFile(ToAddOn, *PathSaved); + } + } + } } else { PathSaved = PathSaved + "/DataLog.log"; diff --git a/Source/MoCapPlugin/Private/MCLogHandler.cpp b/Source/MoCapPlugin/Private/MCLogHandler.cpp index 6494527d70416cd253abb50384dc1ed2bdcfb038..e347d8db2ba44b8440406ec8a0c2e58d0ebb9b73 100644 --- a/Source/MoCapPlugin/Private/MCLogHandler.cpp +++ b/Source/MoCapPlugin/Private/MCLogHandler.cpp @@ -80,20 +80,33 @@ void UMCLogHandler::CopyLogToRecordings(FString& Name) { DirectoryVisitor Visitor; IFileManager::Get().IterateDirectory(*PathLog, Visitor); FFileManagerGeneric Fm; + FDateTime MaxNonStoppedDateTime; FDateTime MaxDateTime; + int MaxNonStoppedIndex = -1; int MaxIndex = -1; for (int i = 0; i < Visitor.Files.Num(); i++) { FDateTime DateTime = Fm.GetTimeStamp(*Visitor.Files[i]); + if ((DateTime > MaxNonStoppedDateTime || MaxNonStoppedIndex == -1) && !Visitor.Files[i].Contains("Stopped")) { + MaxNonStoppedDateTime = DateTime; + MaxNonStoppedIndex = i; + } if (DateTime > MaxDateTime || MaxIndex == -1) { MaxDateTime = DateTime; MaxIndex = i; } } - FString PathMostRecent = Visitor.Files[MaxIndex]; + FString PathMostRecent = Visitor.Files[MaxNonStoppedIndex]; LastSubIndex = PathMostRecent.Find("/", ESearchCase::CaseSensitive, ESearchDir::FromEnd); PathMostRecent = PathMostRecent.RightChop(LastSubIndex + 1); PathMostRecent = PathMostRecent + "/" + CurLog + ".log"; + if (MaxIndex != MaxNonStoppedIndex) { + FString PathStopped = Visitor.Files[MaxIndex]; + LastSubIndex = PathStopped.Find("/", ESearchCase::CaseSensitive, ESearchDir::FromEnd); + PathStopped = PathStopped.RightChop(LastSubIndex + 1); + PathStopped = PathStopped + "/" + CurLog + ".log"; //TODO CurLog oder 0? + PathMostRecent += "\n" + PathStopped; + } FFileHelper::SaveStringToFile(PathMostRecent, *(Path + "LogSourcePath.txt")); } diff --git a/Source/MoCapPlugin/Public/MCAnimInstance.h b/Source/MoCapPlugin/Public/MCAnimInstance.h index 73a63e683b663e11c2859bebfc293f521dfeeefe..bb16e0e6ee534befbf4d870b66787e51735a5ba3 100644 --- a/Source/MoCapPlugin/Public/MCAnimInstance.h +++ b/Source/MoCapPlugin/Public/MCAnimInstance.h @@ -62,6 +62,9 @@ public: UPROPERTY(BlueprintReadWrite) bool SkipCalibration; + UPROPERTY(BlueprintReadWrite) + FVector Scale; + virtual void NativeInitializeAnimation() override; virtual void NativeUpdateAnimation(float DeltaSeconds) override; diff --git a/Source/MoCapPlugin/Public/MCController.h b/Source/MoCapPlugin/Public/MCController.h index c9aa65a06e4e63e00366c4213811654d45cd761d..32d2a25a003e2603f31b5a2a3fc0c9757f9cd59c 100644 --- a/Source/MoCapPlugin/Public/MCController.h +++ b/Source/MoCapPlugin/Public/MCController.h @@ -59,6 +59,7 @@ public: bool SetControls = true; bool KeepPawnInvisible = false; bool KeepPawnVisible = false; + bool KeepDoingRig = false; bool OutputMsgOnScreen = true; AMCController();