diff --git a/Source/DasherVR/Private/Dasher3DWidget.cpp b/Source/DasherVR/Private/Dasher3DWidget.cpp index d52de31a7a7e9b89ca5e548c6e052c34480117e7..131080ea1456346ac2dbabd1d20113a5a6f97c56 100644 --- a/Source/DasherVR/Private/Dasher3DWidget.cpp +++ b/Source/DasherVR/Private/Dasher3DWidget.cpp @@ -13,20 +13,21 @@ ADasher3DWidget::ADasher3DWidget() : DasherParents() PrimaryActorTick.bCanEverTick = true; ActorRootComponent = CreateDefaultSubobject<UStaticMeshComponent>("Root"); + ActorRootComponent->SetCollisionResponseToChannel(ECC_Visibility, ECR_Block); SetRootComponent(ActorRootComponent); CubeInstances = CreateDefaultSubobject<UInstancedStaticMeshComponent>("Cubes"); CubeInstances->SetupAttachment(GetRootComponent()); CubeInstances->SetFlags(RF_Transactional); CubeInstances->NumCustomDataFloats = 7; //Color(3), Scale(3), LineWidth(1) - CubeInstances->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore); + CubeInstances->SetCollisionResponseToChannel(ECC_Visibility, ECR_Block); this->AddInstanceComponent(CubeInstances); LetterInstances = CreateDefaultSubobject<UInstancedStaticMeshComponent>("Letters"); LetterInstances->SetupAttachment(GetRootComponent()); LetterInstances->SetFlags(RF_Transactional); LetterInstances->NumCustomDataFloats = 5; //UV(2), Size(2), TexturePage(1) - LetterInstances->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore); + LetterInstances->SetCollisionResponseToAllChannels(ECR_Ignore); this->AddInstanceComponent(LetterInstances); } @@ -37,6 +38,9 @@ void ADasher3DWidget::PostInitializeComponents() CubeMaterialInstanceDynamic = UMaterialInstanceDynamic::Create(CubeInstances->GetMaterial(0), CubeInstances); CubeInstances->SetMaterial(0, CubeMaterialInstanceDynamic); + + LetterMaterialInstanceDynamic = UMaterialInstanceDynamic::Create(LetterInstances->GetMaterial(0), LetterInstances); + LetterInstances->SetMaterial(0, LetterMaterialInstanceDynamic); } // Called when the game starts or when spawned @@ -63,8 +67,10 @@ void ADasher3DWidget::Tick(float DeltaTime) std::pair<Dasher::screenint, Dasher::screenint> ADasher3DWidget::TextSize(Label* label, unsigned iFontSize) { - char CurrentChar = label->m_strText[0]; + FString labelText = UTF8_TO_TCHAR(label->m_strText.c_str()); + TCHAR CurrentChar = labelText[0]; if (CurrentChar < 32) CurrentChar = 32; // replace non-printable characters with spaces. + CurrentChar = DisplayFont->RemapChar(CurrentChar); const float FontScale = iFontSize / DisplayFont->ImportOptions.Height; const float CharacterSizeU = DisplayFont->Characters[CurrentChar].USize; // Pixel Sizes for actual character without blank space @@ -80,7 +86,7 @@ std::pair<Dasher::screenint, Dasher::screenint> ADasher3DWidget::TextSize(Label* void ADasher3DWidget::DrawString(Label* label, Dasher::screenint x, Dasher::screenint y, unsigned iFontSize, const Dasher::ColorPalette::Color& color){} -void ADasher3DWidget::DrawCube(Dasher::screenint posX, Dasher::screenint posY, Dasher::screenint sizeX, Dasher::screenint sizeY, Dasher::myint extrusionLevel, Dasher::myint groupRecursionDepth, Dasher::myint levelUnderCrosshair, const Dasher::ColorPalette::Color& color, const Dasher::ColorPalette::Color& outlineColor, int iThickness) { +void ADasher3DWidget::DrawCube(Dasher::screenint posX, Dasher::screenint posY, Dasher::screenint sizeX, Dasher::screenint sizeY, Dasher::myint extrusionLevel, Dasher::myint groupRecursionDepth, const Dasher::ColorPalette::Color& color, const Dasher::ColorPalette::Color& outlineColor, int iThickness) { if (sizeX == 0 || sizeY == 0) return; const FVector Scale = FVector(FVector2D(sizeX, sizeY) / DrawingSize, @@ -90,7 +96,7 @@ void ADasher3DWidget::DrawCube(Dasher::screenint posX, Dasher::screenint posY, D const FLinearColor RectColor = FLinearColor(color.Red / 255.0, color.Green / 255.0, color.Blue / 255.0, color.Alpha / 255.0); - BackBuffer->first.Add(FTransform(FQuat::Identity, FVector(Translation, -ExtrusionLevelToHeight(levelUnderCrosshair)) * WorldToMeters, Scale)); + BackBuffer->first.Add(FTransform(FQuat::Identity, FVector(Translation, 0) * WorldToMeters, Scale)); BackBuffer->second.Add(RectColor.R); BackBuffer->second.Add(RectColor.G); BackBuffer->second.Add(RectColor.B); @@ -101,23 +107,25 @@ void ADasher3DWidget::DrawCube(Dasher::screenint posX, Dasher::screenint posY, D } // x & y are given as upper left corner of the character -void ADasher3DWidget::Draw3DLabel(Label* label, Dasher::screenint x, Dasher::screenint y, Dasher::myint extrusionLevel, Dasher::myint groupRecursionDepth, Dasher::myint levelUnderCrosshair, unsigned int iFontSize, const Dasher::ColorPalette::Color& color) { +void ADasher3DWidget::Draw3DLabel(Label* label, Dasher::screenint x, Dasher::screenint y, Dasher::myint extrusionLevel, Dasher::myint groupRecursionDepth, unsigned int iFontSize, const Dasher::ColorPalette::Color& color) { float CharacterOffset = 0; // in Meters - - for (int i = 0; i < label->m_strText.size(); i++) + + FString labelText = UTF8_TO_TCHAR(label->m_strText.c_str()); + for (int i = 0; i < labelText.Len(); i++) { - char CurrentChar = label->m_strText[i]; + TCHAR CurrentChar = labelText[i]; if (CurrentChar < 32) CurrentChar = 32; // replace non-printable characters with spaces. + const TCHAR RemappedChar = DisplayFont->RemapChar(CurrentChar); - const int TextureIndex = DisplayFont->Characters[CurrentChar].TextureIndex; + const int TextureIndex = DisplayFont->Characters[RemappedChar].TextureIndex; const float FontScale = iFontSize / DisplayFont->ImportOptions.Height; - const float TextureSizeU = TextureArray->SourceTextures[TextureIndex]->GetSizeX(); // Pixel Sizes - const float TextureSizeV = TextureArray->SourceTextures[TextureIndex]->GetSizeY(); // Pixel Sizes - const float CharacterOffsetU = DisplayFont->Characters[CurrentChar].StartU; //Upper left corner - const float CharacterOffsetV = DisplayFont->Characters[CurrentChar].StartV; //Upper left corner - const float CharacterSizeU = DisplayFont->Characters[CurrentChar].USize; // Pixel Sizes for actual character without blank space - const float CharacterSizeV = DisplayFont->Characters[CurrentChar].VSize; // Pixel Sizes for actual character without blank space - const float CharacterVerticalOffset = DisplayFont->Characters[CurrentChar].VerticalOffset * FontScale; //vertical offset in pixels + const float TextureSizeU = DisplayFont->Textures[TextureIndex]->GetSizeX(); // Pixel Sizes + const float TextureSizeV = DisplayFont->Textures[TextureIndex]->GetSizeY(); // Pixel Sizes + const float CharacterOffsetU = DisplayFont->Characters[RemappedChar].StartU; //Upper left corner + const float CharacterOffsetV = DisplayFont->Characters[RemappedChar].StartV; //Upper left corner + const float CharacterSizeU = DisplayFont->Characters[RemappedChar].USize; // Pixel Sizes for actual character without blank space + const float CharacterSizeV = DisplayFont->Characters[RemappedChar].VSize; // Pixel Sizes for actual character without blank space + const float CharacterVerticalOffset = DisplayFont->Characters[RemappedChar].VerticalOffset * FontScale; //vertical offset in pixels TArray<float> FontData = { CharacterOffsetU / TextureSizeU, // Upper Left Corner given in UV @@ -136,7 +144,7 @@ void ADasher3DWidget::Draw3DLabel(Label* label, Dasher::screenint x, Dasher::scr const FVector CharTranslation = FVector( (x / DrawingSize.X + CharScale.X * 0.5f) * WorldToMeters + CharacterOffset, ((y + CharacterVerticalOffset) / DrawingSize.Y) * WorldToMeters, - (FMath::Max(ExtrusionLevelToHeight(extrusionLevel), 0.001) - ExtrusionLevelToHeight(levelUnderCrosshair) + groupRecursionDepth*FLT_EPSILON) * WorldToMeters + 0.01f + (FMath::Max(ExtrusionLevelToHeight(extrusionLevel), 0.001) + groupRecursionDepth*0.001) * WorldToMeters + 0.01f ) - FVector(0.5f, 0.5f, 0) * WorldToMeters; // Move to upper left corner of parent @@ -147,9 +155,17 @@ void ADasher3DWidget::Draw3DLabel(Label* label, Dasher::screenint x, Dasher::scr } } +void ADasher3DWidget::FinishRender3D(Dasher::myint originX, Dasher::myint originY, Dasher::myint originExtrusionLevel) +{ + Origin = FVector(originX / DrawingSize.X, originY / DrawingSize.Y, 0) * WorldToMeters; + + CubeInstances->SetRelativeLocation({0,0,-ExtrusionLevelToHeight(originExtrusionLevel) * WorldToMeters}); + LetterInstances->SetRelativeLocation({0,0,-ExtrusionLevelToHeight(originExtrusionLevel) * WorldToMeters}); +} + void ADasher3DWidget::DrawRectangle(Dasher::screenint x1, Dasher::screenint y1, Dasher::screenint x2, Dasher::screenint y2, const Dasher::ColorPalette::Color& color, const Dasher::ColorPalette::Color& outlineColor, int iThickness) { - DrawCube((x2 - x1)/2 + x1, (y2-y1)/2 + y1, x2-x1, y2-y1, 1, 0, 0, color, outlineColor, iThickness); + DrawCube((x2 - x1)/2 + x1, (y2-y1)/2 + y1, x2-x1, y2-y1, 1, 0, color, outlineColor, iThickness); } void ADasher3DWidget::DrawCircle(Dasher::screenint iCX, Dasher::screenint iCY, Dasher::screenint iR, const Dasher::ColorPalette::Color& fillColor, const Dasher::ColorPalette::Color& lineColor, int iLineWidth) @@ -241,8 +257,8 @@ bool ADasher3DWidget::GetScreenCoords(Dasher::screenint& iX, Dasher::screenint& void ADasher3DWidget::SetMouseLocation(FVector WorldLocation) { - FVector2D inp = FVector2D(ActorRootComponent->GetComponentToWorld().InverseTransformPosition(WorldLocation)) / WorldToMeters + FVector2D(0.5f,0.5f); - CursorPosition = inp * DrawingSize; //convert to pixels + MousePos = ActorRootComponent->GetComponentToWorld().InverseTransformPosition(WorldLocation) + FVector(0.5f,0.5f,0) * WorldToMeters; + CursorPosition = FVector2D(MousePos) / WorldToMeters * DrawingSize; //convert to pixels } void ADasher3DWidget::SimulateClick(FKey Key, bool pressed) @@ -265,6 +281,7 @@ void ADasher3DWidget::InitializeTextureArray() TextureArray->SourceTextures.Add(DisplayFont->Textures[i]); } TextureArray->UpdateSourceFromSourceTextures(true); + LetterMaterialInstanceDynamic->SetTextureParameterValue("TextureArray", TextureArray); } float ADasher3DWidget::ExtrusionLevelToHeight(float level) diff --git a/Source/DasherVR/Private/SDasherWidget.cpp b/Source/DasherVR/Private/SDasherWidget.cpp index 3f715fe8c70df4aa2e1f3fcdd9a1e664509c3673..c533fc775f94695ca56599a8ed250d1cad2519f6 100644 --- a/Source/DasherVR/Private/SDasherWidget.cpp +++ b/Source/DasherVR/Private/SDasherWidget.cpp @@ -138,14 +138,15 @@ void SDasherWidget::Construct(const FArguments& InArgs) //Setting up Dasher static Dasher::XMLErrorDisplay display; - Dasher::XmlSettingsStore* Settings = new Dasher::XmlSettingsStore("Settings.xml", &display); //Gets deleted somewhere else - Settings->Load(); + Dasher::XmlSettingsStore* Settings = new Dasher::XmlSettingsStore("Settings.xml", &display); //Gets deleted somewhere else + Settings->Load(); Settings->Save(); - DasherMainInterface = MakeShared<Dasher::DasherInterface>(Settings); + DasherMainInterface = MakeShared<Dasher::DasherInterface>(Settings); DasherMainInterface->SetDefaultInputDevice(this); DasherMainInterface->SetScreen(this); DasherMainInterface->SetBuffer(0); + DasherMainInterface->SetLongParameter(Dasher::LP_SHAPE_TYPE, Dasher::Options::OVERLAPPING_RECTANGLE); DasherMainInterface->SetCharEnteredCallback([this](FString Char, FString Buffer) {CharacterEnteredFlag = true; AlteredChar = Char; }); DasherMainInterface->SetCharDeletedCallback([this](FString Char, FString Buffer) {CharacterDeletedFlag = true; AlteredChar = Char; }); diff --git a/Source/DasherVR/Public/Dasher3DWidget.h b/Source/DasherVR/Public/Dasher3DWidget.h index df3167aaed7aa77281e5979dd9ec413f2ac120ca..936e4074bafe6e262f14b83de16af027b0a0937f 100644 --- a/Source/DasherVR/Public/Dasher3DWidget.h +++ b/Source/DasherVR/Public/Dasher3DWidget.h @@ -43,8 +43,9 @@ public: virtual std::pair<Dasher::screenint, Dasher::screenint> TextSize(Label* label, unsigned iFontSize) override; virtual void DrawString(Label* label, Dasher::screenint x, Dasher::screenint y, unsigned iFontSize, const Dasher::ColorPalette::Color& color) override; virtual void DrawRectangle(Dasher::screenint x1, Dasher::screenint y1, Dasher::screenint x2, Dasher::screenint y2, const Dasher::ColorPalette::Color& color, const Dasher::ColorPalette::Color& outlineColor, int iThickness) override; - virtual void DrawCube(Dasher::screenint posX, Dasher::screenint posY, Dasher::screenint sizeX, Dasher::screenint sizeY, Dasher::myint extrusionLevel, Dasher::myint groupRecursionDepth, Dasher::myint levelUnderCrosshair, const Dasher::ColorPalette::Color& color, const Dasher::ColorPalette::Color& outlineColor, int iThickness) override; - virtual void Draw3DLabel(Label* label, Dasher::screenint x, Dasher::screenint y, Dasher::myint extrusionLevel, Dasher::myint groupRecursionDepth, Dasher::myint levelUnderCrosshair, unsigned int iFontSize, const Dasher::ColorPalette::Color& color) override; + virtual void DrawCube(Dasher::screenint posX, Dasher::screenint posY, Dasher::screenint sizeX, Dasher::screenint sizeY, Dasher::myint extrusionLevel, Dasher::myint groupRecursionDepth, const Dasher::ColorPalette::Color& color, const Dasher::ColorPalette::Color& outlineColor, int iThickness) override; + virtual void Draw3DLabel(Label* label, Dasher::screenint x, Dasher::screenint y, Dasher::myint extrusionLevel, Dasher::myint groupRecursionDepth, unsigned int iFontSize, const Dasher::ColorPalette::Color& color) override; + virtual void FinishRender3D(Dasher::myint originX, Dasher::myint originY, Dasher::myint originExtrusionLevel) override; virtual void DrawCircle(Dasher::screenint iCX, Dasher::screenint iCY, Dasher::screenint iR, const Dasher::ColorPalette::Color& fillColor, const Dasher::ColorPalette::Color& lineColor, int iLineWidth) override; virtual void Polyline(point* Points, int Number, int iWidth, const Dasher::ColorPalette::Color& color) override; virtual void Polygon(point* Points, int Number, const Dasher::ColorPalette::Color& fillColor, const Dasher::ColorPalette::Color& outlineColor, int lineWidth) override; @@ -62,10 +63,13 @@ public: UPROPERTY(EditAnywhere) UFont* DisplayFont; UPROPERTY(EditAnywhere) UMaterial* FontMaterial; UPROPERTY(EditAnywhere) float DepthScale = 0.1; + UPROPERTY(EditAnywhere, BlueprintReadOnly) FVector Origin = {0,0,0}; + UPROPERTY(EditAnywhere, BlueprintReadOnly) FVector MousePos = {0,0,0}; UFUNCTION(BlueprintCallable) void SetMouseLocation(FVector WorldLocation); UFUNCTION(BlueprintCallable) void SimulateClick(FKey Key, bool pressed); virtual void PostInitializeComponents() override; + private: FVector2D CursorPosition; @@ -73,6 +77,7 @@ private: FVector2D DrawingSize = {1000,1000}; // Rendering Resolution TSharedPtr<Dasher::DasherInterface> DasherMainInterface; UPROPERTY() UMaterialInstanceDynamic* CubeMaterialInstanceDynamic; + UPROPERTY() UMaterialInstanceDynamic* LetterMaterialInstanceDynamic; UPROPERTY() UTexture2DArray* TextureArray; FVector DefaultTranslation; diff --git a/Source/Thirdparty/Dasher/DasherCore b/Source/Thirdparty/Dasher/DasherCore index a061849126815c95bda625aee511b63030904236..841a75e6a3410f40a44696a5ba4b224fac32566c 160000 --- a/Source/Thirdparty/Dasher/DasherCore +++ b/Source/Thirdparty/Dasher/DasherCore @@ -1 +1 @@ -Subproject commit a061849126815c95bda625aee511b63030904236 +Subproject commit 841a75e6a3410f40a44696a5ba4b224fac32566c diff --git a/Source/Thirdparty/Dasher/Lib/DasherCore.lib b/Source/Thirdparty/Dasher/Lib/DasherCore.lib index 0541fb69966d448865c63120098149237f45ba4a..211eee4b20608207d8122a1c2a774eabf90dbc57 100644 --- a/Source/Thirdparty/Dasher/Lib/DasherCore.lib +++ b/Source/Thirdparty/Dasher/Lib/DasherCore.lib @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:461b5d6f6fec5470088444f0467fd5a7ed51f135bef940b1fc1142d950a950dd -size 19978948 +oid sha256:6b5181c3f79660521838bb8c41ba794ef0520053e866f40be22e12913b5de066 +size 20109586 diff --git a/Source/Thirdparty/Dasher/Lib/DasherCore.pdb b/Source/Thirdparty/Dasher/Lib/DasherCore.pdb index 130b41dcca7bc1dfc61498ffa647656a8c135793..c5fff29c9228c3de21efa84677b30bac89437b21 100644 Binary files a/Source/Thirdparty/Dasher/Lib/DasherCore.pdb and b/Source/Thirdparty/Dasher/Lib/DasherCore.pdb differ