Add line support to vis component

This commit is contained in:
Steve Streeting 2021-09-14 11:53:23 +01:00
parent 94a783e0d4
commit 056bae4719
2 changed files with 53 additions and 8 deletions

View File

@ -27,6 +27,11 @@ FPrimitiveSceneProxy* UStevesEditorVisComponent::CreateSceneProxy()
auto Ret = new FStevesDebugRenderSceneProxy(this);
const FTransform& XForm = GetComponentTransform();
for (auto& L : Lines)
{
Ret->Lines.Add(FDebugRenderSceneProxy::FDebugLine(XForm.TransformPosition(L.Start),
XForm.TransformPosition(L.End), L.Colour));
}
for (auto& C : Circles)
{
FQuat WorldRot = XForm.TransformRotation(C.Rotation.Quaternion());
@ -47,6 +52,12 @@ FBoxSphereBounds UStevesEditorVisComponent::CalcBounds(const FTransform& LocalTo
FBoxSphereBounds B = Super::CalcBounds(LocalToWorld);
// Now we need to merge in all components
for (auto& L : Lines)
{
// Re-centre the origin of the line to make box extents
FVector Extents = L.Start.GetAbs().ComponentMax(L.End.GetAbs());
B = B + FBoxSphereBounds(FVector::ZeroVector, Extents, Extents.GetMax());
}
for (auto& C : Circles)
{
B = B + FBoxSphereBounds(C.Location, FVector(C.Radius), C.Radius);

View File

@ -7,6 +7,37 @@
#include "StevesEditorVisComponent.generated.h"
USTRUCT(BlueprintType)
struct FStevesEditorVisLine
{
GENERATED_BODY()
/// Start location relative to component
UPROPERTY(EditAnywhere)
FVector Start;
/// End location relative to component
UPROPERTY(EditAnywhere)
FVector End;
/// The colour of the line render
UPROPERTY(EditAnywhere)
FColor Colour;
FStevesEditorVisLine(const FVector& InStart, const FVector& InEnd,
const FColor& InColour)
: Start(InStart),
End(InEnd),
Colour(Colour)
{
}
FStevesEditorVisLine():
Start(FVector::ZeroVector),
End(FVector(100,0,0)),
Colour(FColor::White)
{
}
};
USTRUCT(BlueprintType)
struct FStevesEditorVisCircle
{
@ -28,13 +59,13 @@ struct FStevesEditorVisCircle
UPROPERTY(EditAnywhere)
FColor Colour;
FStevesEditorVisCircle(const FVector& Location, const FRotator& Rotation, float Radius, int NumSegments,
const FColor& Colour)
: Location(Location),
Rotation(Rotation),
Radius(Radius),
NumSegments(NumSegments),
Colour(Colour)
FStevesEditorVisCircle(const FVector& InLocation, const FRotator& InRotation, float InRadius, int InNumSegments,
const FColor& InColour)
: Location(InLocation),
Rotation(InRotation),
Radius(InRadius),
NumSegments(InNumSegments),
Colour(InColour)
{
}
@ -58,13 +89,16 @@ 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(ClassGroup="Debug", 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<FStevesEditorVisLine> Lines;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<FStevesEditorVisCircle> Circles;
UStevesEditorVisComponent(const FObjectInitializer& ObjectInitializer);