From 618fc84c3272e19a9e985ca68bd63c4ca6a87a7a Mon Sep 17 00:00:00 2001 From: Steve Streeting Date: Tue, 14 Sep 2021 13:10:32 +0100 Subject: [PATCH] Add Arc support --- .../Private/StevesEditorVisComponent.cpp | 16 +++++ .../Public/StevesEditorVisComponent.h | 58 ++++++++++++++++++- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/Source/StevesUEHelpers/Private/StevesEditorVisComponent.cpp b/Source/StevesUEHelpers/Private/StevesEditorVisComponent.cpp index 6c533ef..013b0f5 100644 --- a/Source/StevesUEHelpers/Private/StevesEditorVisComponent.cpp +++ b/Source/StevesUEHelpers/Private/StevesEditorVisComponent.cpp @@ -43,6 +43,17 @@ FPrimitiveSceneProxy* UStevesEditorVisComponent::CreateSceneProxy() C.NumSegments, C.Colour )); } + for (auto& Arc : Arcs) + { + FQuat WorldRot = XForm.TransformRotation(Arc.Rotation.Quaternion()); + Ret->Arcs.Add(FStevesDebugRenderSceneProxy::FDebugArc( + XForm.TransformPosition(Arc.Location), + WorldRot.GetForwardVector(), WorldRot.GetRightVector(), + Arc.MinAngle, Arc.MaxAngle, + XForm.GetMaximumAxisScale() * Arc.Radius, + Arc.NumSegments, Arc.Colour + )); + } return Ret; @@ -63,6 +74,11 @@ FBoxSphereBounds UStevesEditorVisComponent::CalcBounds(const FTransform& LocalTo { B = B + FBoxSphereBounds(C.Location, FVector(C.Radius), C.Radius); } + for (auto& Arc : Arcs) + { + // Just use the entire circle for simplicity + B = B + FBoxSphereBounds(Arc.Location, FVector(Arc.Radius), Arc.Radius); + } return B.TransformBy(LocalToWorld); } diff --git a/Source/StevesUEHelpers/Public/StevesEditorVisComponent.h b/Source/StevesUEHelpers/Public/StevesEditorVisComponent.h index c3a923b..74a805b 100644 --- a/Source/StevesUEHelpers/Public/StevesEditorVisComponent.h +++ b/Source/StevesUEHelpers/Public/StevesEditorVisComponent.h @@ -78,7 +78,59 @@ struct FStevesEditorVisCircle } }; +USTRUCT(BlueprintType) +struct FStevesEditorVisArc +{ + GENERATED_BODY() + + /// Location relative to component + UPROPERTY(EditAnywhere) + FVector Location; + /// Rotation relative to component; arcs will be rendered in the X/Y plane + UPROPERTY(EditAnywhere) + FRotator Rotation; + /// Minimum angle to render arc from + UPROPERTY(EditAnywhere) + float MinAngle; + /// Maximum angle to render arc to + UPROPERTY(EditAnywhere) + float MaxAngle; + /// Circle radius + UPROPERTY(EditAnywhere) + float Radius; + /// The number of line segments to render the circle with + UPROPERTY(EditAnywhere) + int NumSegments; + /// The colour of the line render + UPROPERTY(EditAnywhere) + FColor Colour; + + FStevesEditorVisArc(const FVector& InLocation, const FRotator& InRotation, float InMinAngle, float InMaxAngle, + float InRadius, int InNumSegments, + const FColor& InColour, float InThickness) + : Location(InLocation), + Rotation(InRotation), + MinAngle(InMinAngle), + MaxAngle(InMaxAngle), + Radius(InRadius), + NumSegments(InNumSegments), + Colour(InColour) + { + } + + FStevesEditorVisArc(): + Location(FVector::ZeroVector), + Rotation(FRotator::ZeroRotator), + MinAngle(0), + MaxAngle(180), + Radius(50), NumSegments(12), + Colour(FColor::White) + { + } +}; + /** + * * A component that solely exists to provide arbitrary editor visualisation when not selected. * FComponentVisualizer can only display visualisation when selected. * To display vis on an unselected object, you need a UPrimitiveComponent, and sometimes you don't want/need one of those @@ -89,17 +141,19 @@ struct FStevesEditorVisCircle * If you want to, you can add this to your Blueprints too. This component automatically marks itself as "visualisation * only" so shouldn't have a runtime impact. */ -UCLASS(Blueprintable, ClassGroup="Utility", hidecategories=(Collision,Physics,Object,LOD,Lighting,TextureStreaming), meta=(DisplayName="Steves Editor Visualisation", BlueprintSpawnableComponent)) +UCLASS(Blueprintable, ClassGroup="Utility", hidecategories=(Collision,Physics,Object,LOD,Lighting,TextureStreaming), + meta=(DisplayName="Steves Editor Visualisation", BlueprintSpawnableComponent)) class STEVESUEHELPERS_API UStevesEditorVisComponent : public UPrimitiveComponent { GENERATED_BODY() public: - /// Circles to render UPROPERTY(EditAnywhere, BlueprintReadWrite) TArray Lines; UPROPERTY(EditAnywhere, BlueprintReadWrite) TArray Circles; + UPROPERTY(EditAnywhere, BlueprintReadWrite) + TArray Arcs; UStevesEditorVisComponent(const FObjectInitializer& ObjectInitializer);