diff --git a/Content/BaselineMap.umap b/Content/BaselineMap.umap index 8e8f8b96b3de4c867b20d140777bdc9df555abe3..790123205ae6a3dd19e1f1ae1031234fc2eb1e24 100644 Binary files a/Content/BaselineMap.umap and b/Content/BaselineMap.umap differ diff --git a/Content/BaselinePawn.uasset b/Content/BaselinePawn.uasset new file mode 100644 index 0000000000000000000000000000000000000000..91601efa69de6e1b1668a248c5d34e4ab21ad9e6 Binary files /dev/null and b/Content/BaselinePawn.uasset differ diff --git a/Content/MagicWandMap.umap b/Content/MagicWandMap.umap index d02fcaa70c32895380315ccb53e21ebb4aded783..539b1a7ba764672b385820a2c7921335dd1e2d81 100644 Binary files a/Content/MagicWandMap.umap and b/Content/MagicWandMap.umap differ diff --git a/Content/MetaPointMap.umap b/Content/MetaPointMap.umap index e65a8b10eadfdfb9712a93fbbe490b559b6eb5ed..a72bbe726246e20a572a9592fe5f670744ae9b98 100644 Binary files a/Content/MetaPointMap.umap and b/Content/MetaPointMap.umap differ diff --git a/Content/Redo.uasset b/Content/Redo.uasset index 9ce8c21f68e3a2e291a0231af6b929a769e1c23b..08b3ee74087a8e32a8a405f3a2af265230ed4ede 100644 Binary files a/Content/Redo.uasset and b/Content/Redo.uasset differ diff --git a/Content/Undo.uasset b/Content/Undo.uasset index 8e85ab4f54ebddfc3ae615f8283e75792a377b0f..7ad45bdaa35db1108919281246596e81b584fc9b 100644 Binary files a/Content/Undo.uasset and b/Content/Undo.uasset differ diff --git a/Source/MetaCastBachelor/PointStorage/PointCloud.h b/Source/MetaCastBachelor/PointStorage/PointCloud.h index 60181109a646440b91af7e9bad490addfe7b706b..6cf8f9fd13a988b4d748d5b073e9a0af061c5160 100644 --- a/Source/MetaCastBachelor/PointStorage/PointCloud.h +++ b/Source/MetaCastBachelor/PointStorage/PointCloud.h @@ -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); @@ -120,8 +121,11 @@ public: void SaveStateAndUpdate() { - MyUndoRedoManager.AddState(SelectionFlags); - UpdateSelection(); + AsyncTask(ENamedThreads::Type::GameThread, [this]() + { + MyUndoRedoManager.AddState(SelectionFlags); + UpdateSelection(); + }); } int32 GetNumberOfPoints() const diff --git a/Source/MetaCastBachelor/SelectionMethods/MagicWand.cpp b/Source/MetaCastBachelor/SelectionMethods/MagicWand.cpp index 654f419355c699935bd2ef801ef5c1d429943c92..875b70da8391ccbbb1b7c947f1203d65a819c9bb 100644 --- a/Source/MetaCastBachelor/SelectionMethods/MagicWand.cpp +++ b/Source/MetaCastBachelor/SelectionMethods/MagicWand.cpp @@ -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; } + + Super::HandleMetaEraseReleased(Instance); - //AbortMagicWand.Store(true); - if(EraseSound) UGameplayStatics::PlaySound2D(World, EraseSound); 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 diff --git a/Source/MetaCastBachelor/SelectionMethods/MagicWand.h b/Source/MetaCastBachelor/SelectionMethods/MagicWand.h index f12fc010a718bea58aa7a810fb7e5b97535926a3..d71c659f195a6f86a458f7158458ae5b2ad485f9 100644 --- a/Source/MetaCastBachelor/SelectionMethods/MagicWand.h +++ b/Source/MetaCastBachelor/SelectionMethods/MagicWand.h @@ -73,21 +73,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; diff --git a/Source/MetaCastBachelor/SelectionMethods/MetaCastBaseline.cpp b/Source/MetaCastBachelor/SelectionMethods/MetaCastBaseline.cpp index 50b47ae33075d40d82a7851f2963fed28b8d781d..af11024d1e391c3895f547482fccddb9336388a5 100644 --- a/Source/MetaCastBachelor/SelectionMethods/MetaCastBaseline.cpp +++ b/Source/MetaCastBachelor/SelectionMethods/MetaCastBaseline.cpp @@ -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) } } + + diff --git a/Source/MetaCastBachelor/SelectionMethods/MetaCastBaseline.h b/Source/MetaCastBachelor/SelectionMethods/MetaCastBaseline.h index 5bc02362fc0f8c413b053c6b8952b6e34ebef923..48fc2ba92ab5b3319992e300d246537f617ff9f5 100644 --- a/Source/MetaCastBachelor/SelectionMethods/MetaCastBaseline.h +++ b/Source/MetaCastBachelor/SelectionMethods/MetaCastBaseline.h @@ -62,6 +62,21 @@ 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 @@ -69,10 +84,14 @@ public: 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); diff --git a/Source/MetaCastBachelor/SelectionMethods/MetaPoint.cpp b/Source/MetaCastBachelor/SelectionMethods/MetaPoint.cpp index f6d7040d5c6fcb7486f822c0ce1f165952eed939..33827c5472ca1555da47f80e94702bc6d2b9557f 100644 --- a/Source/MetaCastBachelor/SelectionMethods/MetaPoint.cpp +++ b/Source/MetaCastBachelor/SelectionMethods/MetaPoint.cpp @@ -1,5 +1,6 @@ #include "MetaPoint.h" #include "Generators/MarchingCubes.h" +#include "Kismet/GameplayStatics.h" #include "MetaCastBachelor/General/Utilities.h" #include "MetaCastBachelor/PointStorage/PointCloud.h" @@ -49,23 +50,31 @@ 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); diff --git a/Source/MetaCastBachelor/SelectionMethods/MetaPoint.h b/Source/MetaCastBachelor/SelectionMethods/MetaPoint.h index dfb9ba54b8463cf11a415246cac20f994dc4b506..e3c47009fb3af9f0ef56d1f24b6543a760407b01 100644 --- a/Source/MetaCastBachelor/SelectionMethods/MetaPoint.h +++ b/Source/MetaCastBachelor/SelectionMethods/MetaPoint.h @@ -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;