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

made improvements, added some features

parent 3b85f348
No related branches found
No related tags found
No related merge requests found
File added
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -37,12 +37,18 @@ void AMCController::BeginPlay() {
APlayerController* Controller = UGameplayStatics::GetPlayerController(GetWorld(), 0);
EnableInput(Controller);
if (InputComponent != nullptr) {
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::SaveAnimation);
}
if (!Pawn || !Pawn->GetActorLocation().Equals(FVector(0, 0, 0)) || !Pawn->GetActorRotation().Equals(FRotator(0, 0, 0))) {
GEngine->AddOnScreenDebugMessage(-1, 30.0f, FColor::Red, FString::Printf(TEXT("Pawn for Recording in MCController is not positioned at 0, 0, 0 with rotation 0, 0, 0. This can lead to unwanted offsets."), *NameOfRecording));
}
Pawn->LoadMeasurementFile(MeasurementPath);
Pawn->GetAnimInstance()->PawnOwner = Pawn;
if (bFingerTrackingEnabled) {
......@@ -54,6 +60,8 @@ void AMCController::BeginPlay() {
Pawn->VRCamera->SetWorldRotation(SpectatorCam->GetActorRotation());
}
LastAddOffsets = AdditionalOffsets;
}
void AMCController::Tick(float DeltaTime) {
......@@ -94,7 +102,7 @@ void AMCController::Tick(float DeltaTime) {
}
}
if (IsSavingToAnim) {
if (!EditOffsetMode && IsSavingToAnim) {
SaveToAnimMode();
}
......@@ -155,6 +163,23 @@ void AMCController::SaveToAnimMode() {
}
void AMCController::NextEditFrame() {
InputNextFrame();
}
void AMCController::PrevEditFrame() {
AnimSaveState.CurrentEntryIndex -= 2;
if (AnimSaveState.CurrentEntryIndex < 0) {
AnimSaveState.CurrentEntryIndex = 0;
}
InputNextFrame();
}
void AMCController::FinishEditAnim() {
IsSavingToAnim = false;
AnimSaveState = FAnimSaveState();
}
void AMCController::ScaleAnimDataInterval(int start, int end, float DeltaTime) {
FTimespan StartTime = AnimSaveState.AnimData[start].Timestamp;
......@@ -591,6 +616,67 @@ void AMCController::PreprocessRecording() {
}
//---adjust feet position so that they are located at the green foot indicators---
int amount = 0;
int start = 0;
for (int i = 0; i < AnimSaveState.AnimData.Num() && LockFeet; i++) {
FProcessedAnimData& AnimData = AnimSaveState.AnimData[i];
if (AnimData.IsMarker || AnimData.IsEnd) {
FVector cog(0, 0, 0);
for (int j = start; j < i; j++) {
FSensorData& SensorData = AnimSaveState.AnimData[j].SensorData;
FVector LPos = SensorData.GetEntry(EBodyPart::LowerLegL)->Pos;
FQuat LRot = SensorData.GetEntry(EBodyPart::LowerLegL)->Rot;
Pawn->OffsetSensorData(EBodyPart::LowerLegL, LPos, LRot);
FVector RPos = SensorData.GetEntry(EBodyPart::LowerLegR)->Pos;
FQuat RRot = SensorData.GetEntry(EBodyPart::LowerLegR)->Rot;
Pawn->OffsetSensorData(EBodyPart::LowerLegR, RPos, RRot);
cog += 0.5f * (LPos + RPos) * (1.f / amount);
}
FVector shiftAmount = 0.5f * (LeftFootPlane->GetActorLocation() + RightFootPlane->GetActorLocation()) - cog - FVector(0, 10, 0);
shiftAmount.Z = 0;
for (int j = start; j < i; j++) {
FSensorData& SensorData = AnimSaveState.AnimData[j].SensorData;
for (int k = 0; k < EBodyPart::LAST; k++) {
EBodyPart Type = EBodyPart(k);
FSensorDataEntry* Entry = SensorData.GetEntry(Type);
Entry->Pos += shiftAmount;
}
}
for (int j = start; j < i; j++) {
FSensorData& SensorData = AnimSaveState.AnimData[j].SensorData;
FVector LPos = SensorData.GetEntry(EBodyPart::LowerLegL)->Pos;
FQuat LRot = SensorData.GetEntry(EBodyPart::LowerLegL)->Rot;
Pawn->OffsetSensorData(EBodyPart::LowerLegL, LPos, LRot);
FVector RPos = SensorData.GetEntry(EBodyPart::LowerLegR)->Pos;
FQuat RRot = SensorData.GetEntry(EBodyPart::LowerLegR)->Rot;
Pawn->OffsetSensorData(EBodyPart::LowerLegR, RPos, RRot);
shiftAmount = LeftFootPlane->GetActorLocation() - LPos - FVector(-4, 10, 0);
SensorData.GetEntry(EBodyPart::LowerLegL)->Pos.X += shiftAmount.X;
SensorData.GetEntry(EBodyPart::LowerLegL)->Pos.Y += shiftAmount.Y;
shiftAmount = RightFootPlane->GetActorLocation() - RPos - FVector(4, 10, 0);
SensorData.GetEntry(EBodyPart::LowerLegR)->Pos.X += shiftAmount.X;
SensorData.GetEntry(EBodyPart::LowerLegR)->Pos.Y += shiftAmount.Y;
}
amount = 0;
start = i + 1;
continue;
}
amount++;
}
AnimSaveState.NextFrame = FTimespan();
......@@ -647,7 +733,9 @@ void AMCController::InputNextFrame() {
AnimSaveState.Pawn->AICalcFrame();
stop = true;
if (!EditOffsetMode) {
AnimSaveState.WaitForAnimInstance = true;
}
FeedbackWidget->ProgBar->SetPercent((float)AnimSaveState.CurrentEntryIndex / (float)AnimSaveState.AnimData.Num());
......@@ -790,6 +878,199 @@ void AMCController::SetBonesAnimationInAnimSeq(const FSnapshotAnimations& Record
}
#if WITH_EDITOR
void AMCController::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) {
Super::PostEditChangeProperty(PropertyChangedEvent);
FProperty* prop = PropertyChangedEvent.Property;
FFloatProperty* fprop = CastField<FFloatProperty>(prop);
if (fprop != nullptr) {
float* val = nullptr;
{
if (LastAddOffsets.HeadRotOffset.Roll != AdditionalOffsets.HeadRotOffset.Roll) {
val = &AdditionalOffsets.HeadRotOffset.Roll;
}
if (LastAddOffsets.HeadRotOffset.Yaw != AdditionalOffsets.HeadRotOffset.Yaw) {
val = &AdditionalOffsets.HeadRotOffset.Yaw;
}
if (LastAddOffsets.HeadRotOffset.Pitch != AdditionalOffsets.HeadRotOffset.Pitch) {
val = &AdditionalOffsets.HeadRotOffset.Pitch;
}
if (LastAddOffsets.HeadPosOffset.X != AdditionalOffsets.HeadPosOffset.X) {
val = &AdditionalOffsets.HeadPosOffset.X;
}
if (LastAddOffsets.HeadPosOffset.Y != AdditionalOffsets.HeadPosOffset.Y) {
val = &AdditionalOffsets.HeadPosOffset.Y;
}
if (LastAddOffsets.HeadPosOffset.Z != AdditionalOffsets.HeadPosOffset.Z) {
val = &AdditionalOffsets.HeadPosOffset.Z;
}
if (LastAddOffsets.HandLRotOffset.Roll != AdditionalOffsets.HandLRotOffset.Roll) {
val = &AdditionalOffsets.HandLRotOffset.Roll;
}
if (LastAddOffsets.HandLRotOffset.Yaw != AdditionalOffsets.HandLRotOffset.Yaw) {
val = &AdditionalOffsets.HandLRotOffset.Yaw;
}
if (LastAddOffsets.HandLRotOffset.Pitch != AdditionalOffsets.HandLRotOffset.Pitch) {
val = &AdditionalOffsets.HandLRotOffset.Pitch;
}
if (LastAddOffsets.HandLPosOffset.X != AdditionalOffsets.HandLPosOffset.X) {
val = &AdditionalOffsets.HandLPosOffset.X;
}
if (LastAddOffsets.HandLPosOffset.Y != AdditionalOffsets.HandLPosOffset.Y) {
val = &AdditionalOffsets.HandLPosOffset.Y;
}
if (LastAddOffsets.HandLPosOffset.Z != AdditionalOffsets.HandLPosOffset.Z) {
val = &AdditionalOffsets.HandLPosOffset.Z;
}
if (LastAddOffsets.HandRRotOffset.Roll != AdditionalOffsets.HandRRotOffset.Roll) {
val = &AdditionalOffsets.HandRRotOffset.Roll;
}
if (LastAddOffsets.HandRRotOffset.Yaw != AdditionalOffsets.HandRRotOffset.Yaw) {
val = &AdditionalOffsets.HandRRotOffset.Yaw;
}
if (LastAddOffsets.HandRRotOffset.Pitch != AdditionalOffsets.HandRRotOffset.Pitch) {
val = &AdditionalOffsets.HandRRotOffset.Pitch;
}
if (LastAddOffsets.HandRPosOffset.X != AdditionalOffsets.HandRPosOffset.X) {
val = &AdditionalOffsets.HandRPosOffset.X;
}
if (LastAddOffsets.HandRPosOffset.Y != AdditionalOffsets.HandRPosOffset.Y) {
val = &AdditionalOffsets.HandRPosOffset.Y;
}
if (LastAddOffsets.HandRPosOffset.Z != AdditionalOffsets.HandRPosOffset.Z) {
val = &AdditionalOffsets.HandRPosOffset.Z;
}
if (LastAddOffsets.LowerLegRRotOffset.Roll != AdditionalOffsets.LowerLegRRotOffset.Roll) {
val = &AdditionalOffsets.LowerLegRRotOffset.Roll;
}
if (LastAddOffsets.LowerLegRRotOffset.Yaw != AdditionalOffsets.LowerLegRRotOffset.Yaw) {
val = &AdditionalOffsets.LowerLegRRotOffset.Yaw;
}
if (LastAddOffsets.LowerLegRRotOffset.Pitch != AdditionalOffsets.LowerLegRRotOffset.Pitch) {
val = &AdditionalOffsets.LowerLegRRotOffset.Pitch;
}
if (LastAddOffsets.LowerLegRPosOffset.X != AdditionalOffsets.LowerLegRPosOffset.X) {
val = &AdditionalOffsets.LowerLegRPosOffset.X;
}
if (LastAddOffsets.LowerLegRPosOffset.Y != AdditionalOffsets.LowerLegRPosOffset.Y) {
val = &AdditionalOffsets.LowerLegRPosOffset.Y;
}
if (LastAddOffsets.LowerLegRPosOffset.Z != AdditionalOffsets.LowerLegRPosOffset.Z) {
val = &AdditionalOffsets.LowerLegRPosOffset.Z;
}
if (LastAddOffsets.LowerLegLRotOffset.Roll != AdditionalOffsets.LowerLegLRotOffset.Roll) {
val = &AdditionalOffsets.LowerLegLRotOffset.Roll;
}
if (LastAddOffsets.LowerLegLRotOffset.Yaw != AdditionalOffsets.LowerLegLRotOffset.Yaw) {
val = &AdditionalOffsets.LowerLegLRotOffset.Yaw;
}
if (LastAddOffsets.LowerLegLRotOffset.Pitch != AdditionalOffsets.LowerLegLRotOffset.Pitch) {
val = &AdditionalOffsets.LowerLegLRotOffset.Pitch;
}
if (LastAddOffsets.LowerLegLPosOffset.X != AdditionalOffsets.LowerLegLPosOffset.X) {
val = &AdditionalOffsets.LowerLegLPosOffset.X;
}
if (LastAddOffsets.LowerLegLPosOffset.Y != AdditionalOffsets.LowerLegLPosOffset.Y) {
val = &AdditionalOffsets.LowerLegLPosOffset.Y;
}
if (LastAddOffsets.LowerLegLPosOffset.Z != AdditionalOffsets.LowerLegLPosOffset.Z) {
val = &AdditionalOffsets.LowerLegLPosOffset.Z;
}
if (LastAddOffsets.LowerArmLRotOffset.Roll != AdditionalOffsets.LowerArmLRotOffset.Roll) {
val = &AdditionalOffsets.LowerArmLRotOffset.Roll;
}
if (LastAddOffsets.LowerArmLRotOffset.Yaw != AdditionalOffsets.LowerArmLRotOffset.Yaw) {
val = &AdditionalOffsets.LowerArmLRotOffset.Yaw;
}
if (LastAddOffsets.LowerArmLRotOffset.Pitch != AdditionalOffsets.LowerArmLRotOffset.Pitch) {
val = &AdditionalOffsets.LowerArmLRotOffset.Pitch;
}
if (LastAddOffsets.LowerArmLPosOffset.X != AdditionalOffsets.LowerArmLPosOffset.X) {
val = &AdditionalOffsets.LowerArmLPosOffset.X;
}
if (LastAddOffsets.LowerArmLPosOffset.Y != AdditionalOffsets.LowerArmLPosOffset.Y) {
val = &AdditionalOffsets.LowerArmLPosOffset.Y;
}
if (LastAddOffsets.LowerArmLPosOffset.Z != AdditionalOffsets.LowerArmLPosOffset.Z) {
val = &AdditionalOffsets.LowerArmLPosOffset.Z;
}
if (LastAddOffsets.LowerArmRRotOffset.Roll != AdditionalOffsets.LowerArmRRotOffset.Roll) {
val = &AdditionalOffsets.LowerArmRRotOffset.Roll;
}
if (LastAddOffsets.LowerArmRRotOffset.Yaw != AdditionalOffsets.LowerArmRRotOffset.Yaw) {
val = &AdditionalOffsets.LowerArmRRotOffset.Yaw;
}
if (LastAddOffsets.LowerArmRRotOffset.Pitch != AdditionalOffsets.LowerArmRRotOffset.Pitch) {
val = &AdditionalOffsets.LowerArmRRotOffset.Pitch;
}
if (LastAddOffsets.LowerArmRPosOffset.X != AdditionalOffsets.LowerArmRPosOffset.X) {
val = &AdditionalOffsets.LowerArmRPosOffset.X;
}
if (LastAddOffsets.LowerArmRPosOffset.Y != AdditionalOffsets.LowerArmRPosOffset.Y) {
val = &AdditionalOffsets.LowerArmRPosOffset.Y;
}
if (LastAddOffsets.LowerArmRPosOffset.Z != AdditionalOffsets.LowerArmRPosOffset.Z) {
val = &AdditionalOffsets.LowerArmRPosOffset.Z;
}
if (LastAddOffsets.LowerBodyRotOffset.Roll != AdditionalOffsets.LowerBodyRotOffset.Roll) {
val = &AdditionalOffsets.LowerBodyRotOffset.Roll;
}
if (LastAddOffsets.LowerBodyRotOffset.Yaw != AdditionalOffsets.LowerBodyRotOffset.Yaw) {
val = &AdditionalOffsets.LowerBodyRotOffset.Yaw;
}
if (LastAddOffsets.LowerBodyRotOffset.Pitch != AdditionalOffsets.LowerBodyRotOffset.Pitch) {
val = &AdditionalOffsets.LowerBodyRotOffset.Pitch;
}
if (LastAddOffsets.LowerBodyPosOffset.X != AdditionalOffsets.LowerBodyPosOffset.X) {
val = &AdditionalOffsets.LowerBodyPosOffset.X;
}
if (LastAddOffsets.LowerBodyPosOffset.Y != AdditionalOffsets.LowerBodyPosOffset.Y) {
val = &AdditionalOffsets.LowerBodyPosOffset.Y;
}
if (LastAddOffsets.LowerBodyPosOffset.Z != AdditionalOffsets.LowerBodyPosOffset.Z) {
val = &AdditionalOffsets.LowerBodyPosOffset.Z;
}
if (LastAddOffsets.UpperBodyRotOffset.Roll != AdditionalOffsets.UpperBodyRotOffset.Roll) {
val = &AdditionalOffsets.UpperBodyRotOffset.Roll;
}
if (LastAddOffsets.UpperBodyRotOffset.Yaw != AdditionalOffsets.UpperBodyRotOffset.Yaw) {
val = &AdditionalOffsets.UpperBodyRotOffset.Yaw;
}
if (LastAddOffsets.UpperBodyRotOffset.Pitch != AdditionalOffsets.UpperBodyRotOffset.Pitch) {
val = &AdditionalOffsets.UpperBodyRotOffset.Pitch;
}
if (LastAddOffsets.UpperBodyPosOffset.X != AdditionalOffsets.UpperBodyPosOffset.X) {
val = &AdditionalOffsets.UpperBodyPosOffset.X;
}
if (LastAddOffsets.UpperBodyPosOffset.Y != AdditionalOffsets.UpperBodyPosOffset.Y) {
val = &AdditionalOffsets.UpperBodyPosOffset.Y;
}
if (LastAddOffsets.UpperBodyPosOffset.Z != AdditionalOffsets.UpperBodyPosOffset.Z) {
val = &AdditionalOffsets.UpperBodyPosOffset.Z;
}
}
if (val != nullptr) {
UObject* DefaultObject = GetClass()->GetDefaultObject();
//fprop->SetPropertyValue_InContainer(DefaultObject, *val);
LastAddOffsets = AdditionalOffsets;
}
}
}
#endif
void AMCController::ToggleRecording() {
if (IsSavingToAnim) {
return;
......@@ -816,7 +1097,9 @@ void AMCController::ToggleRecording() {
FeedbackWidget->ProgBar->SetVisibility(ESlateVisibility::Hidden);
}
else {
if (!KeepPawnInvisible) {
Pawn->SetMeshVisibility(true);
}
LogHandler.StopRecording();
LogHandler.WriteToLogFile();
FString OldName = NameOfRecording;
......@@ -824,8 +1107,10 @@ void AMCController::ToggleRecording() {
if (OldName != NameOfRecording) {
InstructionWidget->FeedbackText->SetText(FText::FromString("Recording Done!\nNameOfRecording changed to " + NameOfRecording));
if (OutputMsgOnScreen) {
GEngine->AddOnScreenDebugMessage(-1, 30.0f, FColor::Yellow, FString::Printf(TEXT("NameOfRecording changed to %s. If you want to use this recording in future play sessions, please update the property on MCController."), *NameOfRecording));
}
}
InstructionWidget->FeedbackText->SetText(FText::FromString("Recording Done!"));
InstructionWidget->WidgetSwitcher->SetActiveWidgetIndex(InstructionWidget->StartIndex);
......@@ -915,13 +1200,16 @@ void AMCController::SaveAnimation() {
AnimSaveState.Pawn = Pawn;
AnimSaveState.Pawn->GetAnimInstance()->DoFingers = bFingerTrackingEnabled;
AnimSaveState.Pawn->GetAnimInstance()->LockFeet = LockFeet;
AnimSaveState.Pawn->GetAnimInstance()->SnapshotAnimations.Empty();
AnimSaveState.FPS = FramesPerSecond;
AnimSaveState.SPF = 1.f / ((float)AnimSaveState.FPS);
IsSavingToAnim = true;
if (!EditOffsetMode) {
AnimSaveState.WaitForAnimInstance = true;
}
AnimSaveState.Pawn->GetAnimInstance()->AdditionalOffsets = AdditionalOffsets;
......
......@@ -50,6 +50,9 @@ public:
UPROPERTY(BlueprintReadWrite)
bool DoRig;
UPROPERTY(BlueprintReadWrite)
bool LockFeet;
virtual void NativeInitializeAnimation() override;
virtual void NativeUpdateAnimation(float DeltaSeconds) override;
......
......@@ -56,6 +56,9 @@ protected:
bool DebugMode = false;
bool UseLastOffsets = false;
bool SetControls = true;
bool KeepPawnInvisible = false;
bool OutputMsgOnScreen = true;
public:
......@@ -82,6 +85,15 @@ protected:
UFUNCTION(BlueprintCallable)
void SaveAnimation();
UFUNCTION(BlueprintCallable)
void NextEditFrame();
UFUNCTION(BlueprintCallable)
void PrevEditFrame();
UFUNCTION(BlueprintCallable)
void FinishEditAnim();
void RecordMode();
void SaveToAnimMode();
......@@ -93,6 +105,10 @@ protected:
UAnimSequence* SaveAsAnimSequence(const FSnapshotAnimations& Recording, const FString& AnimName, const FString& FolderName);
void SetBonesAnimationInAnimSeq(const FSnapshotAnimations& Recording, UAnimSequence* AnimSequence);
#if WITH_EDITOR
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
#endif
TSubclassOf<AActor> InstructionWidgetObjClass;
AActor* InstructionWidgetObj;
UMCInstructionWidget* InstructionWidget;
......@@ -145,7 +161,21 @@ public:
UPROPERTY(EditAnywhere, meta = (DisplayName = "Leg Smoothing Neighbor Window", Category = "MotionCapture"))
int LegSmoothWindow = 3;
UPROPERTY(EditAnywhere, meta = (DisplayName = "Left Foot Plane", Category = "MotionCapture"))
AActor* LeftFootPlane;
UPROPERTY(EditAnywhere, meta = (DisplayName = "Right Foot Plane", Category = "MotionCapture"))
AActor* RightFootPlane;
UPROPERTY(EditAnywhere, meta = (DisplayName = "Edit Offsets Mode", Category = "MotionCapture"))
bool EditOffsetMode = false;
UPROPERTY(EditAnywhere, meta = (DisplayName = "Lock Feet To Green Foot Indicators", Category = "MotionCapture"))
bool LockFeet = true;
UPROPERTY(EditAnywhere, meta = (DisplayName = "Additional Post Processing Offsets", Category = "MotionCapture"))
FAdditionalOffsets AdditionalOffsets;
FAdditionalOffsets LastAddOffsets;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment