Skip to content
Snippets Groups Projects
Commit ebd8fe95 authored by Patrick Nossol's avatar Patrick Nossol
Browse files

Fixed some StopPlay issues

parent 7413bf66
Branches
No related tags found
No related merge requests found
No preview for this file type
......@@ -14,6 +14,8 @@ void UMCAnimInstance::NativeInitializeAnimation() {
AppliedPose = true;
DoRig = false;
Scale = FVector(1., 1., 1.);
}
void UMCAnimInstance::NativeUpdateAnimation(float DeltaSeconds) {
......
......@@ -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
......@@ -525,105 +532,6 @@ 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++;
}
}
GestureSpeed.Push(Speed / (float)SpeedCount);
}
//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);
}
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;
}
}
ScaleAnimDataInterval(ScaleStart, AnimSaveState.AnimData.Num() - 2, GestureHoldExcessTime);
}
}
else {
if (HaltingPoints.Num() > 0) {
FTimespan Start;
......@@ -679,7 +587,6 @@ bool AMCController::PreprocessRecording(const TArray<float>& HaltingPoints) {
}
}
}
//---adjust feet position so that they are located at the green foot indicators---
......@@ -744,15 +651,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";
......
......@@ -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"));
}
......
......@@ -62,6 +62,9 @@ public:
UPROPERTY(BlueprintReadWrite)
bool SkipCalibration;
UPROPERTY(BlueprintReadWrite)
FVector Scale;
virtual void NativeInitializeAnimation() override;
virtual void NativeUpdateAnimation(float DeltaSeconds) override;
......
......@@ -59,6 +59,7 @@ public:
bool SetControls = true;
bool KeepPawnInvisible = false;
bool KeepPawnVisible = false;
bool KeepDoingRig = false;
bool OutputMsgOnScreen = true;
AMCController();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment