diff --git a/Table/Content/Camera/BP_Projector.uasset b/Table/Content/Camera/BP_Projector.uasset index eb3b585..429e485 100644 Binary files a/Table/Content/Camera/BP_Projector.uasset and b/Table/Content/Camera/BP_Projector.uasset differ diff --git a/Table/Content/WorldObjects/GestureActions/BP_GestureAction_Ruler.uasset b/Table/Content/WorldObjects/GestureActions/BP_GestureAction_Ruler.uasset index 8604fda..99572b2 100644 Binary files a/Table/Content/WorldObjects/GestureActions/BP_GestureAction_Ruler.uasset and b/Table/Content/WorldObjects/GestureActions/BP_GestureAction_Ruler.uasset differ diff --git a/Table/Content/WorldObjects/TableIcons/BP_LabelIcon.uasset b/Table/Content/WorldObjects/TableIcons/BP_LabelIcon.uasset new file mode 100644 index 0000000..4a17dc2 Binary files /dev/null and b/Table/Content/WorldObjects/TableIcons/BP_LabelIcon.uasset differ diff --git a/Table/Content/WorldObjects/TableIcons/BP_TableIconLineActor.uasset b/Table/Content/WorldObjects/TableIcons/BP_LineIcon.uasset similarity index 57% rename from Table/Content/WorldObjects/TableIcons/BP_TableIconLineActor.uasset rename to Table/Content/WorldObjects/TableIcons/BP_LineIcon.uasset index caa1280..192de31 100644 Binary files a/Table/Content/WorldObjects/TableIcons/BP_TableIconLineActor.uasset and b/Table/Content/WorldObjects/TableIcons/BP_LineIcon.uasset differ diff --git a/Table/Content/WorldObjects/TableIcons/Widgets/W_IconLabel.uasset b/Table/Content/WorldObjects/TableIcons/Widgets/W_IconLabel.uasset new file mode 100644 index 0000000..02eb4da Binary files /dev/null and b/Table/Content/WorldObjects/TableIcons/Widgets/W_IconLabel.uasset differ diff --git a/Table/Source/Table/Private/MyGestureActions.cpp b/Table/Source/Table/Private/MyGestureActions.cpp index 75eb032..9e2dd23 100644 --- a/Table/Source/Table/Private/MyGestureActions.cpp +++ b/Table/Source/Table/Private/MyGestureActions.cpp @@ -33,17 +33,35 @@ void AGestureAction_Ruler::InitAction_Implementation(AHandActor* Hand, const FGe } RulerPoints.Add(FVector::ZeroVector); RulerPoints.Add(FVector::ZeroVector); + + if (LabelIconClass) + { + LabelIcon = GetWorld()->SpawnActor(LabelIconClass, StartPoint, FRotator::ZeroRotator, SpawnParams); + + if (LabelIcon) + { + LabelIcon->OwningAction = this; + LabelIcon->bPersistOnActionEnd = true; + LabelIcon->UpdateLabel(StartPoint, 0.f); + Icons.Add(LabelIcon); + } + } } void AGestureAction_Ruler::UpdateAction_Implementation() { - if (!HandA || !IsValid(LineIcon)) return; + if (!HandA || !IsValid(LineIcon) || !IsValid(LabelIcon)) return; const FVector Current = HandA->Points[8]; //if (FVector::DistSquared(Current, RulerPoints[RulerPoints.Num() - 1]) < FMath::Square(UEUnitsPerUnit)) return; - RulerPoints[RulerPoints.Num() - 1] = Current - StartPoint; - RulerPoints[RulerPoints.Num() - 1].Z = 0; + RulerPoints.Last() = Current - StartPoint; + RulerPoints.Last().Z = 0; LineIcon->SetPoints(RulerPoints); + + // RulerPoints are local to the line actor, so convert back to world + FVector LabelPosition = StartPoint + (RulerPoints.Last() * 0.5f); + LabelPosition.Z = 10; + LabelIcon->UpdateLabel(LabelPosition, GetSnappedUnits(GetTotalLength())); } float AGestureAction_Ruler::GetSnappedUnits(float RawDistance) const diff --git a/Table/Source/Table/Private/MyTableIconActors.cpp b/Table/Source/Table/Private/MyTableIconActors.cpp index 5abebc6..7c068b8 100644 --- a/Table/Source/Table/Private/MyTableIconActors.cpp +++ b/Table/Source/Table/Private/MyTableIconActors.cpp @@ -98,17 +98,14 @@ void ATableIconLineActor::BuildLineMesh() MeshComponent->CreateMeshSection(0, Vertices, Triangles, Normals, UVs, Colors, Tangents, false); } - - - - +//-------------------------------------------------------------------------------------------- ATableIconWidgetActor::ATableIconWidgetActor() { USceneComponent* Root = CreateDefaultSubobject(TEXT("Root")); SetRootComponent(Root); - PrimaryActorTick.bCanEverTick = true; + PrimaryActorTick.bCanEverTick = false; WidgetComponent = CreateDefaultSubobject(TEXT("WidgetComponent")); WidgetComponent->SetupAttachment(RootComponent); @@ -120,22 +117,8 @@ ATableIconWidgetActor::ATableIconWidgetActor() WidgetInteraction->SetupAttachment(RootComponent); WidgetInteraction->InteractionSource = EWidgetInteractionSource::Custom; WidgetInteraction->InteractionDistance = 10.f; -} -void ATableIconWidgetActor::Tick(float DeltaTime) -{ - Super::Tick(DeltaTime); - - APlayerCameraManager* CamManager = UGameplayStatics::GetPlayerCameraManager(this, 0); - if (!CamManager) return; - - FVector CamLocation = CamManager->GetCameraLocation(); - FVector ToCamera = (CamLocation - GetActorLocation()).GetSafeNormal(); - - // Only rotate on yaw � keeps widget flat relative to table - ToCamera.Z = 0.f; - if (!ToCamera.IsNearlyZero()) - SetActorRotation(ToCamera.ToOrientationRotator()); + SetWidgetClass(LabelWidgetClass); } void ATableIconWidgetActor::SetWidgetClass(TSubclassOf InWidgetClass) @@ -150,10 +133,10 @@ UUserWidget* ATableIconWidgetActor::GetWidget() const return WidgetComponent->GetUserWidgetObject(); } +//-------------------------------------------------------------------------------------------- - -void ATableIconLabelActor::SetDistance(float RealWorldUnits, const FString& UnitSuffix) +void ATableIconLabelActor::UpdateLabel(const FVector& WorldLocation, float Value) { - int32 Snapped = FMath::RoundToInt(RealWorldUnits); - SetLabelText(FString::Printf(TEXT("%d%s"), Snapped, *UnitSuffix)); -} \ No newline at end of file + SetActorLocation(WorldLocation); + SetLabelText(FString::Printf(TEXT("%.1f%s"), Value, *UnitSuffix)); +} diff --git a/Table/Source/Table/Public/MyGestureActions.h b/Table/Source/Table/Public/MyGestureActions.h index ff35c01..69e40a3 100644 --- a/Table/Source/Table/Public/MyGestureActions.h +++ b/Table/Source/Table/Public/MyGestureActions.h @@ -35,7 +35,7 @@ public: UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Ruler") TSubclassOf LabelIconClass; UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Ruler") FString UnitSuffix = TEXT("\""); UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Ruler") TArray RulerPoints; - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Line") float DesiredHeight = -650.f; + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Ruler") float DesiredHeight = -650.f; UFUNCTION(BlueprintCallable, BlueprintPure) float GetTotalLength() const; UFUNCTION(BlueprintCallable) void AddRulerPoint(); diff --git a/Table/Source/Table/Public/MyTableIconActors.h b/Table/Source/Table/Public/MyTableIconActors.h index fc78e23..b8a46d7 100644 --- a/Table/Source/Table/Public/MyTableIconActors.h +++ b/Table/Source/Table/Public/MyTableIconActors.h @@ -11,15 +11,6 @@ class UWidgetComponent; class UWidgetInteractionComponent; -/** - * - */ -UCLASS() -class TABLE_API AMyTableIconActors : public ATableIconActor -{ - GENERATED_BODY() - -}; UCLASS(Blueprintable) @@ -46,6 +37,7 @@ private: void BuildLineMesh(); }; +//-------------------------------------------------------------------------------------------- UCLASS(Blueprintable) @@ -56,22 +48,26 @@ class TABLE_API ATableIconWidgetActor : public ATableIconActor public: ATableIconWidgetActor(); - UPROPERTY(VisibleAnywhere, BlueprintReadOnly) UWidgetComponent* WidgetComponent; - UPROPERTY(VisibleAnywhere, BlueprintReadOnly) UWidgetInteractionComponent* WidgetInteraction; - UFUNCTION(BlueprintCallable) void SetWidgetClass(TSubclassOf InWidgetClass); - UFUNCTION(BlueprintCallable, BlueprintPure) UUserWidget* GetWidget() const; + UPROPERTY(VisibleAnywhere, BlueprintReadOnly) UWidgetComponent* WidgetComponent; + UPROPERTY(VisibleAnywhere, BlueprintReadOnly) UWidgetInteractionComponent* WidgetInteraction; + UPROPERTY(VisibleAnywhere, BlueprintReadOnly) TSubclassOf LabelWidgetClass; + + UFUNCTION(BlueprintCallable) void SetWidgetClass(TSubclassOf InWidgetClass); + UFUNCTION(BlueprintCallable, BlueprintPure) UUserWidget* GetWidget() const; -protected: - virtual void Tick(float DeltaTime) override; }; +//-------------------------------------------------------------------------------------------- + UCLASS(Blueprintable) class TABLE_API ATableIconLabelActor : public ATableIconWidgetActor { GENERATED_BODY() public: - - UFUNCTION(BlueprintImplementableEvent, BlueprintCallable) void SetLabelText(const FString& Text); - UFUNCTION(BlueprintCallable) void SetDistance(float RealWorldUnits, const FString& UnitSuffix = TEXT("\"")); + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Label") FString UnitSuffix = TEXT("\""); + + UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "Label") void SetLabelText(const FString& Text); + UFUNCTION(BlueprintCallable, Category = "Label") void UpdateLabel(const FVector& WorldLocation, float Value); + }; \ No newline at end of file diff --git a/Table/enc_temp_folder/818ed75f49bf8f964599b398d81a43/MyGestureActions.cpp b/Table/enc_temp_folder/818ed75f49bf8f964599b398d81a43/MyGestureActions.cpp deleted file mode 100644 index a7e4280..0000000 --- a/Table/enc_temp_folder/818ed75f49bf8f964599b398d81a43/MyGestureActions.cpp +++ /dev/null @@ -1,69 +0,0 @@ -// Fill out your copyright notice in the Description page of Project Settings. - - -#include "MyGestureActions.h" -#include "HandActor.h" -#include "TableIconActor.h" -#include "MyTableIconActors.h" - - -void AGestureAction_Ruler::InitAction_Implementation(AHandActor* Hand, const FGestureBinding& NewBinding, float NewUEUnitsPerUnit, float TableHeight) -{ - Super::InitAction_Implementation(Hand, NewBinding, NewUEUnitsPerUnit, TableHeight); - DesiredHeight = -500; - StartPoint = HandA->Points[8]; - StartPoint.Z = DesiredHeight; - - FActorSpawnParameters SpawnParams; - SpawnParams.Owner = this; - SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; - - if (LineIconClass) - { - - LineIcon = GetWorld()->SpawnActor(LineIconClass, StartPoint, FRotator::ZeroRotator, SpawnParams); - - if (LineIcon) - { - LineIcon->OwningAction = this; - LineIcon->bPersistOnActionEnd = true; - LineIcon->LineThickness = 50; - Icons.Add(LineIcon); - } - } - RulerPoints.Add(FVector(0, 0, 0)); - RulerPoints.Add(FVector(0, 0, DesiredHeight)); -} - -void AGestureAction_Ruler::UpdateAction_Implementation() -{ - if (!HandA || !IsValid(LineIcon)) return; - const FVector Current = HandA->Points[8]; - - //if (FVector::DistSquared(Current, RulerPoints[RulerPoints.Num() - 1]) < FMath::Square(UEUnitsPerUnit)) return; - //RulerPoints[RulerPoints.Num() - 1] = Current; - RulerPoints[RulerPoints.Num() - 1] = Current - StartPoint; - RulerPoints[RulerPoints.Num() - 1].Z = 0; - LineIcon->SetPoints(RulerPoints); -} - -float AGestureAction_Ruler::GetSnappedUnits(float RawDistance) const -{ - if (UEUnitsPerUnit <= 0.f) return 0.f; - return FMath::RoundToFloat(RawDistance / UEUnitsPerUnit); -} - -float AGestureAction_Ruler::GetTotalLength() const -{ - float Total = 0.f; - for (int32 i = 0; i < RulerPoints.Num() - 1; i++) - Total += FVector::Dist(RulerPoints[i], RulerPoints[i + 1]); - return Total; -} - -void AGestureAction_Ruler::AddRulerPoint() -{ - FVector Current = HandA->Points[8]; - //Current.Z = DesiredHeight; - RulerPoints.Add(Current - StartPoint); -} diff --git a/Table/enc_temp_folder/d06d726b1f8919e2123e6effd51e7/MyTableIconActors.cpp b/Table/enc_temp_folder/d06d726b1f8919e2123e6effd51e7/MyTableIconActors.cpp deleted file mode 100644 index bc53753..0000000 --- a/Table/enc_temp_folder/d06d726b1f8919e2123e6effd51e7/MyTableIconActors.cpp +++ /dev/null @@ -1,161 +0,0 @@ -// Fill out your copyright notice in the Description page of Project Settings. - - -#include "MyTableIconActors.h" -#include "KismetProceduralMeshLibrary.h" -#include "TableIconActor.h" - -#include "Kismet/GameplayStatics.h" -#include "Camera/CameraActor.h" - -ATableIconLineActor::ATableIconLineActor() -{ - PrimaryActorTick.bCanEverTick = false; // purely driven by SetPoints - - USceneComponent* Root = CreateDefaultSubobject(TEXT("Root")); - SetRootComponent(Root); - - MeshComponent = CreateDefaultSubobject(TEXT("LineMesh")); - MeshComponent->SetupAttachment(RootComponent); - MeshComponent->SetCastShadow(false); - MeshComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision); -} - -void ATableIconLineActor::SetPoints(const TArray& NewPoints) -{ - const FTransform& ActorTransform = GetActorTransform(); - - Points.Reset(NewPoints.Num()); - - Points = NewPoints; - - MeshComponent->ClearMeshSection(0); - - BuildLineMesh(); - - if (LineMaterial) MeshComponent->SetMaterial(0, LineMaterial); -} - - - -void ATableIconLineActor::BuildLineMesh() -{ - TArray Vertices; - TArray Triangles; - TArray Normals; - TArray UVs; - TArray Colors; - TArray Tangents; - - FVector Direction = FVector::ZeroVector; - const float HalfLineThickness = LineThickness * 0.5f; - - for (int32 i = 0; i < Points.Num() - 1; i++) { - const FVector& PointA = Points[i]; - const FVector& PointB = Points[i + 1]; - - Direction = (PointB - PointA).GetSafeNormal(); - - const FVector Right = FVector::CrossProduct(FVector::UpVector, Direction).GetSafeNormal(); - - const FVector Offset = Right * (LineThickness * 0.5f); - - int32 Base = Vertices.Num(); - - Vertices.Add(PointA - Offset); - Vertices.Add(PointA + Offset); - Vertices.Add(PointB + Offset); - Vertices.Add(PointB - Offset); - - Triangles.Add(Base + 0); - Triangles.Add(Base + 1); - Triangles.Add(Base + 2); - - Triangles.Add(Base + 0); - Triangles.Add(Base + 2); - Triangles.Add(Base + 3); - } - - - for (int i = 0; i < Vertices.Num(); i++) - { - Normals.Add(FVector::UpVector); - } - - for (int i = 0; i < Vertices.Num(); i++) - { - UVs.Add(FVector2D::ZeroVector); - } - - for (int i = 0; i < Vertices.Num(); i++) - { - Colors.Add(FColor::Red); - } - - for (int i = 0; i < Vertices.Num(); i++) - { - Tangents.Add(FProcMeshTangent(Direction, false)); - } - - MeshComponent->CreateMeshSection(0, Vertices, Triangles, Normals, UVs, Colors, Tangents, false); -} - - - - - - -ATableIconWidgetActor::ATableIconWidgetActor() -{ - USceneComponent* Root = CreateDefaultSubobject(TEXT("Root")); - SetRootComponent(Root); - - PrimaryActorTick.bCanEverTick = true; - - WidgetComponent = CreateDefaultSubobject(TEXT("WidgetComponent")); - WidgetComponent->SetupAttachment(RootComponent); - WidgetComponent->SetDrawAtDesiredSize(true); - WidgetComponent->SetWidgetSpace(EWidgetSpace::World); - WidgetComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision); - - WidgetInteraction = CreateDefaultSubobject(TEXT("WidgetInteraction")); - WidgetInteraction->SetupAttachment(RootComponent); - WidgetInteraction->InteractionSource = EWidgetInteractionSource::Custom; - WidgetInteraction->InteractionDistance = 10.f; -} - -void ATableIconWidgetActor::Tick(float DeltaTime) -{ - Super::Tick(DeltaTime); - - APlayerCameraManager* CamManager = UGameplayStatics::GetPlayerCameraManager(this, 0); - if (!CamManager) return; - - FVector CamLocation = CamManager->GetCameraLocation(); - FVector ToCamera = (CamLocation - GetActorLocation()).GetSafeNormal(); - - // Only rotate on yaw � keeps widget flat relative to table - ToCamera.Z = 0.f; - if (!ToCamera.IsNearlyZero()) - SetActorRotation(ToCamera.ToOrientationRotator()); -} - -void ATableIconWidgetActor::SetWidgetClass(TSubclassOf InWidgetClass) -{ - if (!InWidgetClass) return; - WidgetComponent->SetWidgetClass(InWidgetClass); - WidgetComponent->InitWidget(); -} - -UUserWidget* ATableIconWidgetActor::GetWidget() const -{ - return WidgetComponent->GetUserWidgetObject(); -} - - - -void ATableIconLabelActor::SetDistance(float RealWorldUnits, const FString& UnitSuffix) -{ - int32 Snapped = FMath::RoundToInt(RealWorldUnits); - SetLabelText(FString::Printf(TEXT("%d%s"), Snapped, *UnitSuffix)); -} \ No newline at end of file