Skip to content
Snippets Groups Projects
Commit 8b2b697a authored by Timon Römer's avatar Timon Römer
Browse files

Fixes Undo Redo for Magic Wand and Baseline

parent 067a2e94
Branches
No related tags found
No related merge requests found
Showing with 111 additions and 53 deletions
No preview for this file type
File added
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -63,10 +63,11 @@ public:
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
void UpdateSelection();
virtual void Tick(float DeltaTime) override;
public:
void UpdateSelection();
void DrawVoxel(const int Index, float Time) const;
void SelectAllPointsInVoxels(const TArray<int32> VoxelIndices);
void AddToSelection(const TArray<bool>& NewSelection);
......@@ -119,9 +120,12 @@ public:
}
void SaveStateAndUpdate()
{
AsyncTask(ENamedThreads::Type::GameThread, [this]()
{
MyUndoRedoManager.AddState(SelectionFlags);
UpdateSelection();
});
}
int32 GetNumberOfPoints() const
......
......@@ -296,10 +296,8 @@ void UMagicWand::GenerateCylinderBetweenPoints(const FVector& Start, const FVect
// INPUT HANDLING
void UMagicWand::HandleMetaSelectPressed(const FInputActionInstance& Instance)
void UMagicWand::SelectionStartAction()
{
Super::HandleMetaSelectPressed(Instance);
if(NumberThreads.GetValue() > 0) return;
ProceduralMesh->ClearAllMeshSections();
......@@ -318,10 +316,8 @@ void UMagicWand::HandleMetaSelectPressed(const FInputActionInstance& Instance)
IsMagicWandInitialized = true;
}
void UMagicWand::HandleMetaSelectReleased(const FInputActionInstance& Instance)
void UMagicWand::SelectionEndAction()
{
Super::HandleMetaSelectReleased(Instance);
IsMagicWandInitialized = false;
ProceduralMesh->ClearAllMeshSections();
MarchingCubeMesh->SetVisibility(false);
......@@ -343,21 +339,17 @@ void UMagicWand::HandleMetaSelectReleased(const FInputActionInstance& Instance)
}
MyPointCloud->SaveStateAndUpdate();
//CurrentSelection.Reset();
}
void UMagicWand::HandleMetaEraseReleased(const FInputActionInstance& Instance)
{
Super::HandleMetaEraseReleased(Instance);
if(NumberThreads.GetValue() > 0)
{
return;
}
//AbortMagicWand.Store(true);
if(EraseSound) UGameplayStatics::PlaySound2D(World, EraseSound);
Super::HandleMetaEraseReleased(Instance);
CurrentSelection = MakeShared<FSelectionManager>(MyPointCloud->GetNumberOfPoints(), MyDensityField->GetVoxelNumber());
for(int i = 0; i < MyPointCloud->GetNumberOfPoints(); i++)
......@@ -370,20 +362,16 @@ void UMagicWand::HandleMetaEraseReleased(const FInputActionInstance& Instance)
void UMagicWand::HandleUndoAction(const FInputActionInstance& Instance)
{
Super::HandleUndoAction(Instance);
if(NumberThreads.GetValue() > 0) return;
if(UndoSound) UGameplayStatics::PlaySound2D(World, UndoSound);
MyPointCloud->Undo();
Super::HandleUndoAction(Instance);
}
void UMagicWand::HandleRedoAction(const FInputActionInstance& Instance)
{
Super::HandleRedoAction(Instance);
if(NumberThreads.GetValue() > 0) return;
if(RedoSound) UGameplayStatics::PlaySound2D(World, RedoSound);
MyPointCloud->Redo();
Super::HandleRedoAction(Instance);
}
// MAGIC WAND SELECTION
......
......@@ -74,21 +74,6 @@ class UMagicWand : public UMetaCastBaseline
UPROPERTY(EditAnywhere)
bool UpdateMagicWandDuringDrag = false;
UPROPERTY(EditAnywhere)
USoundWave* SelectionEndSound;
UPROPERTY(EditAnywhere)
USoundWave* SelectionStartSound;
UPROPERTY(EditAnywhere)
USoundWave* UndoSound;
UPROPERTY(EditAnywhere)
USoundWave* RedoSound;
UPROPERTY(EditAnywhere)
USoundWave* EraseSound;
public:
int32 SeedPointIndex;
......@@ -101,8 +86,8 @@ public:
// INPUT HANDLING
virtual void HandleMetaSelectReleased(const FInputActionInstance& Instance) override;
virtual void HandleMetaSelectPressed(const FInputActionInstance& Instance) override;
virtual void SelectionEndAction() override;
virtual void SelectionStartAction() override;
virtual void HandleMetaEraseReleased(const FInputActionInstance& Instance) override;
virtual void HandleUndoAction(const FInputActionInstance& Instance) override;
virtual void HandleRedoAction(const FInputActionInstance& Instance) override;
......
......@@ -2,8 +2,12 @@
#include "EngineUtils.h"
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
#include "Kismet/GameplayStatics.h"
UMetaCastBaseline::UMetaCastBaseline() : SelectionObject(nullptr), EnhancedInputComponent(nullptr), MetaSelectAction(nullptr), MetaEraseAction(nullptr), UndoAction(nullptr), RedoAction(nullptr), InputMappingContext(nullptr), LeftHandComponent(nullptr), MyPointCloud(nullptr)
UMetaCastBaseline::UMetaCastBaseline() :
SelectionObject(nullptr), EnhancedInputComponent(nullptr), MetaSelectAction(nullptr), MetaEraseAction(nullptr), UndoAction(nullptr),
RedoAction(nullptr), InputMappingContext(nullptr), LeftHandComponent(nullptr), MyPointCloud(nullptr), SelectionEndSound(nullptr),
SelectionStartSound(nullptr), UndoSound(nullptr), RedoSound(nullptr), EraseSound(nullptr)
{
PrimaryComponentTick.bCanEverTick = true;
}
......@@ -124,29 +128,74 @@ void UMetaCastBaseline::InitInputBindings()
void UMetaCastBaseline::HandleMetaSelectPressed(const FInputActionInstance& Instance)
{
this->Select = Instance.GetValue().Get<bool>();
SelectionStartAction();
}
void UMetaCastBaseline::HandleMetaErasePressed(const FInputActionInstance& Instance)
{
this->Erase = Instance.GetValue().Get<bool>();
SelectionEraseAction();
}
void UMetaCastBaseline::HandleMetaSelectReleased(const FInputActionInstance& Instance)
{
this->Select = Instance.GetValue().Get<bool>();
SelectionEndAction();
}
void UMetaCastBaseline::SelectionStartAction()
{
}
void UMetaCastBaseline::SelectionEndAction()
{
if(GetWorld())
{
if(SelectionEndSound) UGameplayStatics::PlaySound2D(GetWorld(), SelectionEndSound);
}
MyPointCloud->SaveStateAndUpdate();
}
void UMetaCastBaseline::SelectionEraseAction()
{
for(int i = 0; i < MyPointCloud->GetNumberOfPoints(); i++)
{
MyPointCloud->SetSelectionFlag(i, false);
}
MyPointCloud->SaveStateAndUpdate();
}
void UMetaCastBaseline::HandleMetaEraseReleased(const FInputActionInstance& Instance)
{
this->Erase = Instance.GetValue().Get<bool>();
if(GetWorld())
{
if(EraseSound) UGameplayStatics::PlaySound2D(GetWorld(), EraseSound);
}
}
void UMetaCastBaseline::HandleUndoAction(const FInputActionInstance& Instance)
{
if(GetWorld())
{
if(UndoSound) UGameplayStatics::PlaySound2D(GetWorld(), UndoSound);
MyPointCloud->Undo();
}
}
void UMetaCastBaseline::HandleRedoAction(const FInputActionInstance& Instance)
{
if(GetWorld())
{
if(RedoSound) UGameplayStatics::PlaySound2D(GetWorld(), RedoSound);
MyPointCloud->Redo();
}
}
void UMetaCastBaseline::AttachToHand(const float DeltaTime) const
......@@ -199,6 +248,8 @@ void UMetaCastBaseline::SelectParticles(const FVector& InputPosition)
MyPointCloud->SetSelectionFlag(i, true); // Set the flag to true as it's now selected
}
}
MyPointCloud->UpdateSelection();
}
void UMetaCastBaseline::EraseParticles(const FVector& InputPosition)
......@@ -221,3 +272,5 @@ void UMetaCastBaseline::EraseParticles(const FVector& InputPosition)
}
}
......@@ -63,16 +63,35 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
APointCloud* MyPointCloud;
UPROPERTY(EditAnywhere, Category = "Sound")
USoundWave* SelectionEndSound;
UPROPERTY(EditAnywhere, Category = "Sound")
USoundWave* SelectionStartSound;
UPROPERTY(EditAnywhere, Category = "Sound")
USoundWave* UndoSound;
UPROPERTY(EditAnywhere, Category = "Sound")
USoundWave* RedoSound;
UPROPERTY(EditAnywhere, Category = "Sound")
USoundWave* EraseSound;
// Sets default values for this component's properties
UMetaCastBaseline();
void InitLeftHand();
void InitInputBindings();
virtual void HandleMetaSelectPressed(const FInputActionInstance& Instance);
virtual void HandleMetaErasePressed(const FInputActionInstance& Instance);
void HandleMetaSelectPressed(const FInputActionInstance& Instance);
virtual void SelectionStartAction();
void HandleMetaErasePressed(const FInputActionInstance& Instance);
virtual void SelectionEraseAction();
virtual void HandleMetaSelectReleased(const FInputActionInstance& Instance);
void HandleMetaSelectReleased(const FInputActionInstance& Instance);
virtual void SelectionEndAction();
virtual void HandleMetaEraseReleased(const FInputActionInstance& Instance);
virtual void HandleUndoAction(const FInputActionInstance& Instance);
......
#include "MetaPoint.h"
#include "Generators/MarchingCubes.h"
#include "Kismet/GameplayStatics.h"
#include "MetaCastBachelor/General/Utilities.h"
#include "MetaCastBachelor/PointStorage/PointCloud.h"
......@@ -49,22 +50,30 @@ void UMetaPoint::EraseParticles(const FVector& InputPosition)
}
void UMetaPoint::HandleMetaSelectReleased(const FInputActionInstance& Instance)
void UMetaPoint::SelectionEndAction()
{
Super::HandleMetaSelectReleased(Instance);
ProceduralMesh->ClearAllMeshSections();
ProceduralMesh->SetVisibility(false);
if(SelectionEndSound)
{
UGameplayStatics::PlaySound2D(World, SelectionEndSound);
}
AsyncTask(ENamedThreads::Type::AnyBackgroundHiPriTask, [this]()
{
MyPointCloud->SelectAllPointsInVoxels(FloodedIndices);
});
MyPointCloud->SaveStateAndUpdate();
}
void UMetaPoint::HandleMetaSelectPressed(const FInputActionInstance& Instance)
void UMetaPoint::SelectionStartAction()
{
Super::HandleMetaSelectPressed(Instance);
if(SelectionStartSound)
{
UGameplayStatics::PlaySound2D(World, SelectionStartSound);
}
InitMetaPointSelection();
}
......@@ -159,8 +168,8 @@ void UMetaPoint::SelectParticles(const FVector& InputPosition)
LocalMaximumIndex = MyDensityField->WorldPositionToIndex(LocalMaximum);
const float Dist = FVector::Distance(SelectStartPosition, SelectionLocalPosition);
UE_LOG(LogTemp, Warning, TEXT("Dist: %f"), Dist);
float InitThreshold = FUtilities::InterpolateDensityAtPosition(MyDensityField, SelectStartPosition);
//UE_LOG(LogTemp, Warning, TEXT("Dist: %f"), Dist);
const float InitThreshold = FUtilities::InterpolateDensityAtPosition(MyDensityField, SelectStartPosition);
float Thr = MyDensityField->MaxDensity - (Dist / 100.0f) * (MyDensityField->MaxDensity - MyDensityField->MinDensity) - InitThreshold;
MetaPointThreshold = FUtilities::InterpolateDensityAtPosition(MyDensityField, SelectionLocalPosition);
......
......@@ -56,8 +56,8 @@ public:
virtual void SelectParticles(const FVector& InputPosition) override;
virtual void EraseParticles(const FVector& InputPosition) override;
virtual void HandleMetaSelectReleased(const FInputActionInstance& Instance) override;
virtual void HandleMetaSelectPressed(const FInputActionInstance& Instance) override;
virtual void SelectionEndAction() override;
virtual void SelectionStartAction() override;
virtual void HandleMetaEraseReleased(const FInputActionInstance& Instance) override;
virtual void HandleUndoAction(const FInputActionInstance& Instance) override;
virtual void HandleRedoAction(const FInputActionInstance& Instance) override;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment