From 144123cd3e34df0c4ee53b7878c0d8d838e13c04 Mon Sep 17 00:00:00 2001 From: Sebastian Pape <pape@vr.rwth-aachen.de> Date: Mon, 18 Nov 2024 17:13:07 +0100 Subject: [PATCH] More adjustments for study. Parameters are now changable. --- Source/DasherVR/Private/Dasher3DWidget.cpp | 70 ++++++++++++++++++++-- Source/DasherVR/Private/SDasherWidget.cpp | 34 ++++++++++- Source/DasherVR/Private/UDasherWidget.cpp | 18 ++++++ Source/DasherVR/Public/Dasher3DWidget.h | 14 ++++- Source/DasherVR/Public/SDasherWidget.h | 3 + Source/DasherVR/Public/UDasherWidget.h | 6 ++ 6 files changed, 138 insertions(+), 7 deletions(-) diff --git a/Source/DasherVR/Private/Dasher3DWidget.cpp b/Source/DasherVR/Private/Dasher3DWidget.cpp index f0c6dbb..765f5c4 100644 --- a/Source/DasherVR/Private/Dasher3DWidget.cpp +++ b/Source/DasherVR/Private/Dasher3DWidget.cpp @@ -96,13 +96,13 @@ void ADasher3DWidget::DrawCube(float posX, float posY, float sizeX, float sizeY, if (sizeX == 0 || sizeY == 0) return; - const float currentNodeDepth = ExtrusionLevelToHeight(nodeDepth.extrusionLevel) + nodeDepth.groupRecursionDepth*0.001; - const float parentNodeDepth = ExtrusionLevelToHeight(parentDepth.extrusionLevel) + parentDepth.groupRecursionDepth*0.001; + const float currentNodeDepth = ExtrusionLevelToHeight(nodeDepth.extrusionLevel) + nodeDepth.groupRecursionDepth*GroupDepthScale; + const float parentNodeDepth = ExtrusionLevelToHeight(parentDepth.extrusionLevel) + parentDepth.groupRecursionDepth*GroupDepthScale; const FVector Scale = FVector(FVector2D(sizeX, sizeY) / DrawingSize, FMath::Max(currentNodeDepth - parentNodeDepth, 0.001f)); // Min Depth 1mm const FVector2D Translation = FVector2D(posX, posY) / DrawingSize - FVector2D(0.5f, 0.5f); - const FLinearColor RectColor = FLinearColor(color.Red / 255.0, color.Green / 255.0, color.Blue / 255.0, color.Alpha / 255.0); + const FLinearColor RectColor = FLinearColor(color.Red / 255.0 * Brightness, color.Green / 255.0 * Brightness, color.Blue / 255.0 * Brightness, color.Alpha / 255.0 * Brightness); BackBuffer->first.Add(FTransform(FQuat::Identity, FVector(Translation, parentNodeDepth) * WorldToMeters, Scale)); BackBuffer->second.Add(RectColor.R); @@ -158,7 +158,7 @@ void ADasher3DWidget::Draw3DLabel(Label* label, Dasher::screenint x, Dasher::scr const FVector CharTranslation = FVector( ((x + x_offset) / DrawingSize.X + CharScale.X * 0.5f) * WorldToMeters + CharacterOffset, ((y + y_offset + ((orientation != Dasher::Options::BottomToTop) ? CharacterVerticalOffset : 0.1f)) / DrawingSize.Y) * WorldToMeters, //0.1px offset for not running into Z-fighting - (FMath::Max(ExtrusionLevelToHeight(extrusionLevel), 0.001f) + groupRecursionDepth*0.001) * WorldToMeters + z_offset + (FMath::Max(ExtrusionLevelToHeight(extrusionLevel), 0.001f) + groupRecursionDepth*GroupDepthScale) * WorldToMeters + z_offset ) - FVector(0.5f, 0.5f, 0) * WorldToMeters; // Move to upper left corner of parent @@ -321,6 +321,68 @@ void ADasher3DWidget::SimulateClick(FKey Key, bool pressed) } } +void ADasher3DWidget::SetBoolParamter(FString ParameterName, bool Value) +{ + for (auto param = Dasher::Settings::parameter_defaults.begin(); param != Dasher::Settings::parameter_defaults.end(); ++param) + if (param->second.name == TCHAR_TO_UTF8(*ParameterName)) + { + DasherMainInterface->SetBoolParameter(param->first, Value); + return; + } +} + +void ADasher3DWidget::SetLongParamter(FString ParameterName, int64 Value) +{ + for (auto param = Dasher::Settings::parameter_defaults.begin(); param != Dasher::Settings::parameter_defaults.end(); ++param) + if (param->second.name == TCHAR_TO_UTF8(*ParameterName)) + { + DasherMainInterface->SetLongParameter(param->first, Value); + return; + } +} + +void ADasher3DWidget::SetStringParamter(FString ParameterName, FString Value) +{ + for (auto param = Dasher::Settings::parameter_defaults.begin(); param != Dasher::Settings::parameter_defaults.end(); ++param) + if (param->second.name == TCHAR_TO_UTF8(*ParameterName)) + { + DasherMainInterface->SetStringParameter(param->first, TCHAR_TO_UTF8(*Value)); + return; + } +} + +bool ADasher3DWidget::GetBoolParamter(FString ParameterName) +{ + for (auto param = Dasher::Settings::parameter_defaults.begin(); param != Dasher::Settings::parameter_defaults.end(); ++param) + { + if (param->second.name == TCHAR_TO_UTF8(*ParameterName)) + { + return DasherMainInterface->GetBoolParameter(param->first); + } + } + return false; +} + +int64 ADasher3DWidget::GetLongParamter(FString ParameterName) +{ + for (auto param = Dasher::Settings::parameter_defaults.begin(); param != Dasher::Settings::parameter_defaults.end(); ++param) + if (param->second.name == TCHAR_TO_UTF8(*ParameterName)) + { + return DasherMainInterface->GetLongParameter(param->first); + } + return -1; +} + +FString ADasher3DWidget::GetStringParamter(FString ParameterName) +{ + for (auto param = Dasher::Settings::parameter_defaults.begin(); param != Dasher::Settings::parameter_defaults.end(); ++param) + if (param->second.name == TCHAR_TO_UTF8(*ParameterName)) + { + return UTF8_TO_TCHAR(DasherMainInterface->GetStringParameter(param->first).c_str()); + } + return ""; +} + void ADasher3DWidget::InitializeTextureArray() { TextureArray = NewObject<UTexture2DArray>(); diff --git a/Source/DasherVR/Private/SDasherWidget.cpp b/Source/DasherVR/Private/SDasherWidget.cpp index fd326d1..8316a7c 100644 --- a/Source/DasherVR/Private/SDasherWidget.cpp +++ b/Source/DasherVR/Private/SDasherWidget.cpp @@ -310,6 +310,38 @@ void SDasherWidget::SetParameter(FString ParameterName, FString Value) } } +bool SDasherWidget::GetBoolParamter(FString ParameterName) +{ + for (auto param = Dasher::Settings::parameter_defaults.begin(); param != Dasher::Settings::parameter_defaults.end(); ++param) + { + if (param->second.name == TCHAR_TO_UTF8(*ParameterName)) + { + return DasherMainInterface->GetBoolParameter(param->first); + } + } + return false; +} + +int64 SDasherWidget::GetLongParamter(FString ParameterName) +{ + for (auto param = Dasher::Settings::parameter_defaults.begin(); param != Dasher::Settings::parameter_defaults.end(); ++param) + if (param->second.name == TCHAR_TO_UTF8(*ParameterName)) + { + return DasherMainInterface->GetLongParameter(param->first); + } + return -1; +} + +FString SDasherWidget::GetStringParamter(FString ParameterName) +{ + for (auto param = Dasher::Settings::parameter_defaults.begin(); param != Dasher::Settings::parameter_defaults.end(); ++param) + if (param->second.name == TCHAR_TO_UTF8(*ParameterName)) + { + return UTF8_TO_TCHAR(DasherMainInterface->GetStringParameter(param->first).c_str()); + } + return ""; +} + //paints our stuff, then lets compoundwidget (super::) draw its stuff //This draws from bottom to top rectangles->lines->labels, this is enough for our use, but for more complex scenarios a proper layering system might have to be implemented int32 SDasherWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const @@ -416,7 +448,7 @@ void SDasherWidget::DrawRectangle(Dasher::screenint x1, Dasher::screenint y1, Da if(color != Dasher::ColorPalette::noColor && !color.isFullyTransparent()) { - BackBuffer->Add(MakeUnique<FFilledRect>(FVector2D(x1 + iThickness, y1 + iThickness), FVector2D(x2 - iThickness, y2 - iThickness), FLinearColor(color.Red / 255.0f, color.Green / 255.0f, color.Blue / 255.0f, color.Alpha / 255.0f))); + BackBuffer->Add(MakeUnique<FFilledRect>(FVector2D(x1 + iThickness, y1 + iThickness), FVector2D(x2 - iThickness, y2 - iThickness), FLinearColor(color.Red / 255.0f * brightness, color.Green / 255.0f * brightness, color.Blue / 255.0f * brightness, color.Alpha / 255.0f))); } if (iThickness && outlineColor != Dasher::ColorPalette::noColor && !outlineColor.isFullyTransparent()) diff --git a/Source/DasherVR/Private/UDasherWidget.cpp b/Source/DasherVR/Private/UDasherWidget.cpp index 9b12077..0160bf7 100644 --- a/Source/DasherVR/Private/UDasherWidget.cpp +++ b/Source/DasherVR/Private/UDasherWidget.cpp @@ -85,6 +85,24 @@ void UDasherWidget::SetStringParamter(FString ParameterName, FString Value) DasherScreen->SetParameter(ParameterName, Value); } +bool UDasherWidget::GetBoolParamter(FString ParameterName) +{ + if(!DasherScreen) return false; + return DasherScreen->GetBoolParamter(ParameterName); +} + +int64 UDasherWidget::GetLongParamter(FString ParameterName) +{ + if(!DasherScreen) return -1; + return DasherScreen->GetLongParamter(ParameterName); +} + +FString UDasherWidget::GetStringParamter(FString ParameterName) +{ + if(!DasherScreen) return ""; + return DasherScreen->GetStringParamter(ParameterName); +} + void UDasherWidget::InputButton(bool Pressed) { if(!DasherScreen) return; diff --git a/Source/DasherVR/Public/Dasher3DWidget.h b/Source/DasherVR/Public/Dasher3DWidget.h index f68c8b9..2c0b757 100644 --- a/Source/DasherVR/Public/Dasher3DWidget.h +++ b/Source/DasherVR/Public/Dasher3DWidget.h @@ -67,13 +67,23 @@ public: UPROPERTY(VisibleAnywhere, Category = "Components") UInstancedStaticMeshComponent* CubeInstances = nullptr; UPROPERTY(VisibleAnywhere, Category = "Components") UInstancedStaticMeshComponent* LetterInstances = nullptr; UPROPERTY(EditAnywhere) UFont* DisplayFont; - UPROPERTY(EditAnywhere) float DepthScale = 0.1; + UPROPERTY(EditAnywhere, BlueprintReadWrite) float DepthScale = 0.1; + UPROPERTY(EditAnywhere, BlueprintReadWrite) float GroupDepthScale = 0.001; + UPROPERTY(EditAnywhere, BlueprintReadWrite) float Brightness = 1; UPROPERTY(EditAnywhere, BlueprintReadOnly) FVector Origin = {0,0,0}; UPROPERTY(EditAnywhere, BlueprintReadOnly) FVector MousePos = {0,0,0}; UPROPERTY(EditAnywhere, BlueprintReadWrite) FString settingsFile = "Settings3D.xml"; UFUNCTION(BlueprintCallable) void SetMouseLocation(FVector WorldLocation); UFUNCTION(BlueprintCallable) void SimulateClick(FKey Key, bool pressed); + + UFUNCTION(BlueprintCallable) void SetBoolParamter(FString ParameterName, bool Value); + UFUNCTION(BlueprintCallable) void SetLongParamter(FString ParameterName, int64 Value); + UFUNCTION(BlueprintCallable) void SetStringParamter(FString ParameterName, FString Value); + UFUNCTION(BlueprintPure) bool GetBoolParamter(FString ParameterName); + UFUNCTION(BlueprintPure) int64 GetLongParamter(FString ParameterName); + UFUNCTION(BlueprintPure) FString GetStringParamter(FString ParameterName); + virtual void PostInitializeComponents() override; public: @@ -97,7 +107,7 @@ private: private: FVector2D CursorPosition; float WorldToMeters; // normally 100 - FVector2D DrawingSize = {1000,1000}; // Rendering Resolution + FVector2D DrawingSize = {1920,1080}; // Rendering Resolution TSharedPtr<Dasher::DasherInterface> DasherMainInterface; UPROPERTY() UMaterialInstanceDynamic* CubeMaterialInstanceDynamic; UPROPERTY() UMaterialInstanceDynamic* LetterMaterialInstanceDynamic; diff --git a/Source/DasherVR/Public/SDasherWidget.h b/Source/DasherVR/Public/SDasherWidget.h index 9a17c05..09540b0 100644 --- a/Source/DasherVR/Public/SDasherWidget.h +++ b/Source/DasherVR/Public/SDasherWidget.h @@ -94,6 +94,9 @@ public: void SetParameter(FString ParameterName, bool Value); void SetParameter(FString ParameterName, int64 Value); void SetParameter(FString ParameterName, FString Value); + bool GetBoolParamter(FString ParameterName); + int64 GetLongParamter(FString ParameterName); + FString GetStringParamter(FString ParameterName); virtual int32 OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const override; diff --git a/Source/DasherVR/Public/UDasherWidget.h b/Source/DasherVR/Public/UDasherWidget.h index be1822f..f7f06a6 100644 --- a/Source/DasherVR/Public/UDasherWidget.h +++ b/Source/DasherVR/Public/UDasherWidget.h @@ -38,6 +38,10 @@ public: UFUNCTION(BlueprintCallable) void SetLongParamter(FString ParameterName, int64 Value); UFUNCTION(BlueprintCallable) void SetStringParamter(FString ParameterName, FString Value); + UFUNCTION(BlueprintPure) bool GetBoolParamter(FString ParameterName); + UFUNCTION(BlueprintPure) int64 GetLongParamter(FString ParameterName); + UFUNCTION(BlueprintPure) FString GetStringParamter(FString ParameterName); + UFUNCTION(BlueprintCallable) void InputButton(bool Pressed); UFUNCTION(BlueprintCallable) void InputVector(FVector2D InputVector); @@ -59,8 +63,10 @@ public: //Only for testing UFUNCTION(BlueprintCallable) void SetTransparency(float transparency){DasherScreen->transparency = 255*transparency;} UFUNCTION(BlueprintCallable) void SetBrightness(float brightness){DasherScreen->brightness = brightness;} + UFUNCTION(BlueprintCallable, BlueprintPure) float GetBrightness(){return DasherScreen->brightness;} public: + // UWidget interface virtual void SynchronizeProperties() override; // End of UWidget interface -- GitLab