mirror of
https://github.com/sinbad/StevesUEHelpers.git
synced 2025-02-23 17:45:23 +00:00
Add support for cylinders and capsules in editor vis
This commit is contained in:
parent
5eb2f2b786
commit
3a42320158
@ -33,6 +33,33 @@ void FStevesDebugRenderSceneProxy::GetDynamicMeshElements(const TArray<const FSc
|
|||||||
C.Radius, C.NumSegments,
|
C.Radius, C.NumSegments,
|
||||||
C.Color, SDPG_Foreground);
|
C.Color, SDPG_Foreground);
|
||||||
}
|
}
|
||||||
|
// Draw Cylinders (properly! superclass ignores transforms)
|
||||||
|
for (const auto& C : CylindersImproved)
|
||||||
|
{
|
||||||
|
::DrawWireCylinder(PDI,
|
||||||
|
C.Centre,
|
||||||
|
C.X,
|
||||||
|
C.Y,
|
||||||
|
C.Z,
|
||||||
|
C.Color,
|
||||||
|
C.Radius,
|
||||||
|
C.HalfHeight,
|
||||||
|
C.NumSegments,
|
||||||
|
SDPG_Foreground);
|
||||||
|
}
|
||||||
|
for (const auto& C : CapsulesImproved)
|
||||||
|
{
|
||||||
|
::DrawWireCapsule(PDI,
|
||||||
|
C.Location,
|
||||||
|
C.X,
|
||||||
|
C.Y,
|
||||||
|
C.Z,
|
||||||
|
C.Color,
|
||||||
|
C.Radius,
|
||||||
|
C.HalfHeight,
|
||||||
|
16,
|
||||||
|
SDPG_Foreground);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,6 +76,34 @@ FPrimitiveSceneProxy* UStevesEditorVisComponent::CreateSceneProxy()
|
|||||||
Ret->Boxes.Add(FStevesDebugRenderSceneProxy::FDebugBox(
|
Ret->Boxes.Add(FStevesDebugRenderSceneProxy::FDebugBox(
|
||||||
DBox, Box.Colour, CombinedXForm));
|
DBox, Box.Colour, CombinedXForm));
|
||||||
}
|
}
|
||||||
|
for (auto& Cylinder : Cylinders)
|
||||||
|
{
|
||||||
|
// Apply local rotation first then parent transform
|
||||||
|
const FTransform CombinedXForm = FTransform(Cylinder.Rotation, Cylinder.Location) * XForm;
|
||||||
|
const float HalfH = Cylinder.Height * 0.5f * CombinedXForm.GetScale3D().Z;
|
||||||
|
const float R = Cylinder.Radius * CombinedXForm.GetScale3D().Z;
|
||||||
|
const FVector Centre = CombinedXForm.TransformPosition(FVector::ZeroVector);
|
||||||
|
const FVector LocalX = CombinedXForm.TransformVectorNoScale(FVector::ForwardVector);
|
||||||
|
const FVector LocalY = CombinedXForm.TransformVectorNoScale(FVector::RightVector);
|
||||||
|
const FVector LocalZ = CombinedXForm.TransformVectorNoScale(FVector::UpVector);
|
||||||
|
Ret->CylindersImproved.Add(FStevesDebugRenderSceneProxy::FDebugCylinder(
|
||||||
|
Centre, LocalX, LocalY, LocalZ, R, HalfH, 16, Cylinder.Colour));
|
||||||
|
}
|
||||||
|
for (auto& Capsule : Capsules)
|
||||||
|
{
|
||||||
|
// Apply local rotation first then parent transform
|
||||||
|
const FTransform CombinedXForm = FTransform(Capsule.Rotation, Capsule.Location) * XForm;
|
||||||
|
const float HalfH = Capsule.Height * 0.5f * CombinedXForm.GetScale3D().Z;
|
||||||
|
const float R = Capsule.Radius * CombinedXForm.GetScale3D().Z;
|
||||||
|
const FVector Position = CombinedXForm.TransformPosition(FVector::ZeroVector);
|
||||||
|
const FVector LocalX = CombinedXForm.TransformVectorNoScale(FVector::ForwardVector);
|
||||||
|
const FVector LocalY = CombinedXForm.TransformVectorNoScale(FVector::RightVector);
|
||||||
|
const FVector LocalZ = CombinedXForm.TransformVectorNoScale(FVector::UpVector);
|
||||||
|
Ret->CapsulesImproved.Add(FStevesDebugRenderSceneProxy::FCapsule(
|
||||||
|
Position, R,
|
||||||
|
LocalX, LocalY, LocalZ,
|
||||||
|
HalfH, Capsule.Colour));
|
||||||
|
}
|
||||||
|
|
||||||
return Ret;
|
return Ret;
|
||||||
|
|
||||||
@ -120,6 +148,24 @@ FBoxSphereBounds UStevesEditorVisComponent::CalcBounds(const FTransform& LocalTo
|
|||||||
DBox = DBox.TransformBy(BoxXForm);
|
DBox = DBox.TransformBy(BoxXForm);
|
||||||
B = B + FBoxSphereBounds(DBox);
|
B = B + FBoxSphereBounds(DBox);
|
||||||
}
|
}
|
||||||
|
for (auto& Cylinder : Cylinders)
|
||||||
|
{
|
||||||
|
FVector HalfSize = FVector(Cylinder.Radius, Cylinder.Radius, Cylinder.Height * 0.5f);
|
||||||
|
FBox DBox(-HalfSize, HalfSize);
|
||||||
|
// Apply local rotation only, world is done later
|
||||||
|
FTransform XForm = FTransform(Cylinder.Rotation, Cylinder.Location);
|
||||||
|
DBox = DBox.TransformBy(XForm);
|
||||||
|
B = B + FBoxSphereBounds(DBox);
|
||||||
|
}
|
||||||
|
for (auto& Capsule : Capsules)
|
||||||
|
{
|
||||||
|
FVector HalfSize = FVector(Capsule.Radius, Capsule.Radius, Capsule.Height * 0.5f + Capsule.Radius * 2.f);
|
||||||
|
FBox DBox(-HalfSize, HalfSize);
|
||||||
|
// Apply local rotation only, world is done later
|
||||||
|
FTransform XForm = FTransform(Capsule.Rotation, Capsule.Location);
|
||||||
|
DBox = DBox.TransformBy(XForm);
|
||||||
|
B = B + FBoxSphereBounds(DBox);
|
||||||
|
}
|
||||||
return B.TransformBy(LocalToWorld);
|
return B.TransformBy(LocalToWorld);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +70,33 @@ public:
|
|||||||
FColor Color;
|
FColor Color;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Replacement for FWireCylinder because that's garbage and doesn't reflect the component transform
|
||||||
|
struct FDebugCylinder
|
||||||
|
{
|
||||||
|
FDebugCylinder(const FVector &InCentre, const FVector& InX, const FVector& InY, const FVector& InZ, const float InRadius, const float InHalfHeight, int InNumSegments, const FColor &InColor) :
|
||||||
|
Centre(InCentre),
|
||||||
|
X(InX), Y(InY), Z(InZ),
|
||||||
|
Radius(InRadius),
|
||||||
|
HalfHeight(InHalfHeight),
|
||||||
|
NumSegments(InNumSegments),
|
||||||
|
Color(InColor)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
FVector Centre;
|
||||||
|
FVector X;
|
||||||
|
FVector Y;
|
||||||
|
FVector Z;
|
||||||
|
float Radius;
|
||||||
|
float HalfHeight;
|
||||||
|
int NumSegments;
|
||||||
|
FColor Color;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
TArray<FDebugCircle> Circles;
|
TArray<FDebugCircle> Circles;
|
||||||
TArray<FDebugArc> Arcs;
|
TArray<FDebugArc> Arcs;
|
||||||
|
TArray<FDebugCylinder> CylindersImproved; // Because we need our own
|
||||||
|
TArray<FCapsule> CapsulesImproved; // Because we need our own
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -195,7 +195,53 @@ struct STEVESUEHELPERS_API FStevesEditorVisBox
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
USTRUCT(BlueprintType)
|
||||||
|
struct STEVESUEHELPERS_API FStevesEditorVisCylinder
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
/// Location relative to component
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
FVector Location;
|
||||||
|
/// Height of cylinder
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
float Height;
|
||||||
|
/// Radius of cylinder
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
float Radius;
|
||||||
|
/// Rotation relative to component
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
FRotator Rotation;
|
||||||
|
/// The colour of the line render
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
FColor Colour;
|
||||||
|
|
||||||
|
FStevesEditorVisCylinder(const FVector& InLocation, float InHeight, float InRadius, const FRotator& InRot,
|
||||||
|
const FColor& InColour) :
|
||||||
|
Location(InLocation),
|
||||||
|
Height(InHeight),
|
||||||
|
Radius(InRadius),
|
||||||
|
Rotation(InRot),
|
||||||
|
Colour(InColour)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
FStevesEditorVisCylinder():
|
||||||
|
Location(FVector::ZeroVector),
|
||||||
|
Height(50),
|
||||||
|
Radius(10),
|
||||||
|
Rotation(FRotator::ZeroRotator),
|
||||||
|
Colour(FColor::White)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
USTRUCT(BlueprintType)
|
||||||
|
struct STEVESUEHELPERS_API FStevesEditorVisCapsule : public FStevesEditorVisCylinder
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* A component that solely exists to provide arbitrary editor visualisation when not selected.
|
* A component that solely exists to provide arbitrary editor visualisation when not selected.
|
||||||
@ -227,6 +273,10 @@ public:
|
|||||||
TArray<FStevesEditorVisSphere> Spheres;
|
TArray<FStevesEditorVisSphere> Spheres;
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
TArray<FStevesEditorVisBox> Boxes;
|
TArray<FStevesEditorVisBox> Boxes;
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
TArray<FStevesEditorVisCylinder> Cylinders;
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
TArray<FStevesEditorVisCapsule> Capsules;
|
||||||
|
|
||||||
UStevesEditorVisComponent(const FObjectInitializer& ObjectInitializer);
|
UStevesEditorVisComponent(const FObjectInitializer& ObjectInitializer);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user