CogEngine: Improve collision tester and viewer

Replace usage of engine asset by debug config for the colors of collision channels
This commit is contained in:
Arnaud Jamin
2024-01-03 03:56:47 -05:00
parent 7dd4922b01
commit 11022f7311
15 changed files with 1205 additions and 1281 deletions
@@ -1,6 +1,7 @@
#include "CogDebug.h"
#include "CogCommonDebugFilteredActorInterface.h"
#include "CogDebugDrawHelper.h"
#include "CogDebugReplicator.h"
#include "Engine/World.h"
#include "Engine/Engine.h"
@@ -232,3 +233,79 @@ bool FCogDebug::IsSecondarySkeletonBone(FName BoneName)
return false;
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebug::GetDebugChannelColors(FColor ChannelColors[ECC_MAX])
{
ChannelColors[ECC_WorldStatic] = Settings.ChannelColorWorldStatic;
ChannelColors[ECC_WorldDynamic] = Settings.ChannelColorWorldDynamic;
ChannelColors[ECC_Pawn] = Settings.ChannelColorPawn;
ChannelColors[ECC_Visibility] = Settings.ChannelColorVisibility;
ChannelColors[ECC_Camera] = Settings.ChannelColorCamera;
ChannelColors[ECC_PhysicsBody] = Settings.ChannelColorPhysicsBody;
ChannelColors[ECC_Vehicle] = Settings.ChannelColorVehicle;
ChannelColors[ECC_Destructible] = Settings.ChannelColorDestructible;
ChannelColors[ECC_EngineTraceChannel1] = Settings.ChannelColorEngineTraceChannel1;
ChannelColors[ECC_EngineTraceChannel2] = Settings.ChannelColorEngineTraceChannel2;
ChannelColors[ECC_EngineTraceChannel3] = Settings.ChannelColorEngineTraceChannel3;
ChannelColors[ECC_EngineTraceChannel4] = Settings.ChannelColorEngineTraceChannel4;
ChannelColors[ECC_EngineTraceChannel5] = Settings.ChannelColorEngineTraceChannel5;
ChannelColors[ECC_EngineTraceChannel6] = Settings.ChannelColorEngineTraceChannel6;
ChannelColors[ECC_GameTraceChannel1] = Settings.ChannelColorGameTraceChannel1;
ChannelColors[ECC_GameTraceChannel2] = Settings.ChannelColorGameTraceChannel2;
ChannelColors[ECC_GameTraceChannel3] = Settings.ChannelColorGameTraceChannel3;
ChannelColors[ECC_GameTraceChannel4] = Settings.ChannelColorGameTraceChannel4;
ChannelColors[ECC_GameTraceChannel5] = Settings.ChannelColorGameTraceChannel5;
ChannelColors[ECC_GameTraceChannel6] = Settings.ChannelColorGameTraceChannel6;
ChannelColors[ECC_GameTraceChannel7] = Settings.ChannelColorGameTraceChannel7;
ChannelColors[ECC_GameTraceChannel8] = Settings.ChannelColorGameTraceChannel8;
ChannelColors[ECC_GameTraceChannel9] = Settings.ChannelColorGameTraceChannel9;
ChannelColors[ECC_GameTraceChannel10] = Settings.ChannelColorGameTraceChannel10;
ChannelColors[ECC_GameTraceChannel11] = Settings.ChannelColorGameTraceChannel11;
ChannelColors[ECC_GameTraceChannel12] = Settings.ChannelColorGameTraceChannel12;
ChannelColors[ECC_GameTraceChannel13] = Settings.ChannelColorGameTraceChannel13;
ChannelColors[ECC_GameTraceChannel14] = Settings.ChannelColorGameTraceChannel14;
ChannelColors[ECC_GameTraceChannel15] = Settings.ChannelColorGameTraceChannel15;
ChannelColors[ECC_GameTraceChannel16] = Settings.ChannelColorGameTraceChannel16;
ChannelColors[ECC_GameTraceChannel17] = Settings.ChannelColorGameTraceChannel17;
ChannelColors[ECC_GameTraceChannel18] = Settings.ChannelColorGameTraceChannel18;
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebug::GetDebugDrawOverlapSettings(FCogDebugDrawOverlapParams& Params)
{
Params.HitColor = Settings.CollisionQueryHitColor;
Params.NoHitColor = Settings.CollisionQueryNoHitColor;
Params.DrawHitPrimitives = Settings.CollisionQueryDrawHitPrimitives;
Params.DrawHitPrimitiveActorsName = Settings.CollisionQueryDrawHitPrimitiveActorsName;
Params.HitPrimitiveActorsNameShadow = Settings.CollisionQueryHitPrimitiveActorsNameShadow;
Params.HitPrimitiveActorsNameSize = Settings.CollisionQueryHitPrimitiveActorsNameSize;
Params.Persistent = false;
Params.LifeTime = 0.0f;
Params.DepthPriority = Settings.DepthPriority;
Params.Thickness = Settings.Thickness;
GetDebugChannelColors(Params.ChannelColors);
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebug::GetDebugDrawLineTraceSettings(FCogDebugDrawLineTraceParams& Params)
{
GetDebugDrawOverlapSettings(Params);
Params.DrawHitLocation = Settings.CollisionQueryDrawHitLocation;
Params.DrawHitImpactPoints = Settings.CollisionQueryDrawHitImpactPoints;
Params.DrawHitNormals = Settings.CollisionQueryDrawHitNormals;
Params.DrawHitImpactNormals = Settings.CollisionQueryDrawHitImpactNormals;
Params.HitPointSize = Settings.CollisionQueryHitPointSize;
Params.NormalColor = Settings.CollisionQueryNormalColor;
Params.ImpactNormalColor = Settings.CollisionQueryImpactNormalColor;
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebug::GetDebugDrawSweepSettings(FCogDebugDrawSweepParams& Params)
{
GetDebugDrawLineTraceSettings(Params);
Params.DrawHitShapes = Settings.CollisionQueryDrawHitShapes;
}
@@ -1,9 +1,11 @@
#include "CogDebugDrawHelper.h"
#include "CogDebug.h"
#include "Components/LineBatchComponent.h"
#include "Kismet/KismetSystemLibrary.h"
#include "Engine/Engine.h"
#include "DrawDebugHelpers.h"
#include "Components/BoxComponent.h"
namespace
{
@@ -161,237 +163,6 @@ void FCogDebugDrawHelper::DrawFlatCapsule(
::DrawDebugCircle(InWorld, FRotationTranslationMatrix(FRotator(90, 0, 0), FVector(End, Z)), Radius, Segments, Color, bPersistentLines, LifeTime, DepthPriority, Thickness, false);
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebugDrawHelper::DrawRaycastSingle(
const UWorld* World,
const FVector& Start,
const FVector& End,
const EDrawDebugTrace::Type DrawType,
const bool bHit,
const FHitResult& Hit,
const float HitSize,
const FLinearColor DrawColor,
const FLinearColor DrawHitColor,
const float DrawDuration,
const uint8 DepthPriority /*= 0*/
)
{
if (DrawType != EDrawDebugTrace::None)
{
bool DrawPersistent = DrawType == EDrawDebugTrace::Persistent;
float DrawTime = (DrawType == EDrawDebugTrace::ForDuration) ? DrawDuration : 0.f;
if (bHit && Hit.bBlockingHit)
{
::DrawDebugLine(World, Start, Hit.ImpactPoint, DrawColor.ToFColor(true), DrawPersistent, DrawTime);
::DrawDebugLine(World, Hit.ImpactPoint, End, DrawHitColor.ToFColor(true), DrawPersistent, DrawTime);
DrawHitResult(World, Hit, 0, DrawType, false, HitSize, DrawHitColor, DrawTime, DepthPriority);
}
else
{
::DrawDebugLine(World, Start, End, DrawColor.ToFColor(true), DrawPersistent, DrawTime);
}
}
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebugDrawHelper::DrawSphereOverlapMulti(
const UWorld* World,
const FVector& Position,
const float Radius,
const EDrawDebugTrace::Type DrawType,
const bool bOverlap,
const TArray<AActor*>& OutActors,
const FLinearColor DrawColor,
const FLinearColor DrawHitColor,
const float DrawDuration /*= 0*/
)
{
if (DrawType == EDrawDebugTrace::None)
return;
const bool DrawPersistent = DrawType == EDrawDebugTrace::Persistent;
const float DrawTime = (DrawType == EDrawDebugTrace::ForDuration) ? DrawDuration : 0.f;
DrawSphereOverlapSingle(World, Position, Radius, DrawColor.ToFColor(true), DrawPersistent, DrawTime);
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebugDrawHelper::DrawSphereOverlapSingle(
const UWorld* World,
const FVector& Position,
const float Radius,
const FColor& DrawColor,
const bool DrawPersistent,
const float DrawTime /*= -1.f*/,
const uint8 DepthPriority /*= 0*/
)
{
::DrawDebugSphere(World, Position, Radius, 16, DrawColor, DrawPersistent, DrawTime, DepthPriority);
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebugDrawHelper::DrawCapsuleCastMulti(const UWorld* World, const FVector& Start, const FVector& End, const FQuat& Rotation, const float HalfHeight, const float Radius, const EDrawDebugTrace::Type DrawType, const bool bHit, const TArray<FHitResult>& OutHits, const FLinearColor DrawColor, const FLinearColor DrawHitColor, const float DrawDuration /*= 0*/)
{
if (DrawType == EDrawDebugTrace::None)
return;
const bool DrawPersistent = DrawType == EDrawDebugTrace::Persistent;
const float DrawTime = (DrawType == EDrawDebugTrace::ForDuration) ? DrawDuration : 0.f;
if (bHit && OutHits.Last().bBlockingHit)
{
FVector const BlockingHitPoint = OutHits.Last().Location;
DrawCapsuleCastSingle(World, Start, BlockingHitPoint, Rotation, HalfHeight, Radius, DrawHitColor.ToFColor(true), DrawPersistent, DrawTime);
DrawCapsuleCastSingle(World, Start, End, Rotation, HalfHeight, Radius, DrawColor.ToFColor(true), DrawPersistent, DrawTime);
}
else
{
DrawCapsuleCastSingle(World, Start, End, Rotation, HalfHeight, Radius, DrawColor.ToFColor(true), DrawPersistent, DrawTime);
}
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebugDrawHelper::DrawCapsuleCastSingle(const UWorld* World, const FVector& Start, const FVector& End, const FQuat& Rotation, const float HalfHeight, const float Radius, const FColor& DrawColor, const bool DrawPersistent, const float DrawDuration /*= -1.f*/, const uint8 DepthPriority /*= 0*/)
{
::DrawDebugCapsule(World, Start, HalfHeight, Radius, Rotation, DrawColor, DrawPersistent, DrawDuration, DepthPriority);
::DrawDebugLine(World, Start, End, DrawColor, DrawPersistent, DrawDuration, DepthPriority, 0.5f);
::DrawDebugCapsule(World, End, HalfHeight, Radius, Rotation, DrawColor, DrawPersistent, DrawDuration, DepthPriority);
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebugDrawHelper::DrawSphereCastMulti(
const UWorld* World,
const FVector& Start,
const FVector& End,
const float Radius,
const EDrawDebugTrace::Type DrawType,
const bool bHit,
const TArray<FHitResult>& OutHits,
const FLinearColor DrawColor,
const FLinearColor DrawHitColor,
const float DrawDuration /*= 0*/
)
{
if (DrawType == EDrawDebugTrace::None)
return;
const bool DrawPersistent = DrawType == EDrawDebugTrace::Persistent;
const float DrawTime = (DrawType == EDrawDebugTrace::ForDuration) ? DrawDuration : 0.f;
if (bHit && OutHits.Last().bBlockingHit)
{
FVector const BlockingHitPoint = OutHits.Last().Location;
DrawSphereCastSingle(World, Start, BlockingHitPoint, Radius, DrawColor.ToFColor(true), DrawPersistent, DrawTime);
DrawSphereCastSingle(World, BlockingHitPoint, End, Radius, DrawHitColor.ToFColor(true), DrawPersistent, DrawTime);
}
else
{
DrawSphereCastSingle(World, Start, End, Radius, DrawColor.ToFColor(true), DrawPersistent, DrawTime);
}
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebugDrawHelper::DrawSphereCastSingle(
const UWorld* World,
const FVector& Start,
const FVector& End,
const float Radius,
const FColor& DrawColor,
const bool DrawPersistent,
const float DrawDuration /*= -1.f*/,
const uint8 DepthPriority /*= 0*/
)
{
FVector const TraceVec = End - Start;
float const Dist = TraceVec.Size();
FVector const Center = Start + TraceVec * 0.5f;
float const HalfHeight = (Dist * 0.5f) + Radius;
FQuat const CapsuleRot = FRotationMatrix::MakeFromZ(TraceVec).ToQuat();
::DrawDebugCapsule(World, Center, HalfHeight, Radius, CapsuleRot, DrawColor, DrawPersistent, DrawDuration, DepthPriority);
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebugDrawHelper::DrawHitResults(
const UWorld* World,
const TArray<FHitResult>& OutHits,
const EDrawDebugTrace::Type DrawType,
const bool ShowHitIndex,
const float HitSize,
const FLinearColor HitColor,
const float DrawDuration,
const uint8 DepthPriority /*= 0*/
)
{
if (DrawType == EDrawDebugTrace::None)
return;
for (int32 i = 0; i < OutHits.Num(); ++i)
{
DrawHitResult(World, OutHits[i], i, DrawType, ShowHitIndex, HitSize, HitColor, DrawDuration, DepthPriority);
}
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebugDrawHelper::DrawHitResultsDiscarded(
const UWorld* World,
const TArray<FHitResult>& AllHits,
const TArray<FHitResult>& KeptHits,
const EDrawDebugTrace::Type DrawType,
const float HitSize,
const FLinearColor DrawColor,
const float DrawDuration,
const uint8 DepthPriority /*= 0*/
)
{
if (DrawType == EDrawDebugTrace::None)
return;
for (int32 i = 0; i < AllHits.Num(); ++i)
{
const FHitResult& PhysicHit = AllHits[i];
if (!KeptHits.ContainsByPredicate([&](const FHitResult& Hit)
{
return Hit.GetActor() == PhysicHit.GetActor() && Hit.Component == PhysicHit.Component && Hit.Distance == PhysicHit.Distance;
}))
{
DrawHitResult(World, PhysicHit, i, DrawType, false, HitSize, DrawColor, DrawDuration, DepthPriority);
}
}
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebugDrawHelper::DrawHitResult(
const UWorld* World,
const FHitResult& Hit,
const int HitIndex,
const EDrawDebugTrace::Type DrawType,
const bool ShowHitIndex,
const float HitSize,
const FLinearColor HitColor,
const float DrawDuration,
const uint8 DepthPriority /*= 0*/
)
{
if (DrawType == EDrawDebugTrace::None)
return;
const bool DrawPersistent = DrawType == EDrawDebugTrace::Persistent;
const float DrawTime = (DrawType == EDrawDebugTrace::ForDuration) ? DrawDuration : 0.f;
::DrawDebugSphere(World, Hit.ImpactPoint, HitSize, 12, HitColor.ToFColor(true), DrawPersistent, DrawTime, DepthPriority);
if (ShowHitIndex)
{
::DrawDebugString(World, Hit.ImpactPoint, FString::Printf(TEXT("%d"), HitIndex), nullptr, HitColor.ToFColor(true), DrawTime, true, 1.0f);
}
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebugDrawHelper::DrawFrustum(
const UWorld* World,
@@ -406,9 +177,9 @@ void FCogDebugDrawHelper::DrawFrustum(
const uint8 DepthPriority,
const float Thickness)
{
FVector Direction(1, 0, 0);
FVector LeftVector(0, 1, 0);
FVector UpVector(0, 0, 1);
const FVector Direction(1, 0, 0);
const FVector LeftVector(0, 1, 0);
const FVector UpVector(0, 0, 1);
FVector Verts[8];
@@ -519,4 +290,347 @@ void FCogDebugDrawHelper::DrawSolidQuad(const UWorld* World, const FVector& Posi
Indices[5] = 3;
DrawDebugMesh(World, Verts, Indices, Color, bPersistent, LifeTime, DepthPriority);
}
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebugDrawHelper::DrawHitResult(
const UWorld* World,
const FHitResult& HitResult,
const FCogDebugDrawLineTraceParams& Settings)
{
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebugDrawHelper::DrawHitResults(
const UWorld* World,
const TArray<FHitResult>& HitResults,
const FCogDebugDrawLineTraceParams& Settings)
{
TSet<const UPrimitiveComponent*> AlreadyDrawnPrimitives;
TSet<const AActor*> AlreadyDrawnActors;
for (const FHitResult& HitResult : HitResults)
{
const FColor& HitColor = Settings.HitColor;
if (Settings.DrawHitLocation)
{
DrawDebugPoint(
World,
HitResult.Location,
Settings.HitPointSize,
HitColor,
Settings.Persistent,
Settings.LifeTime,
Settings.DepthPriority);
}
if (Settings.DrawHitImpactPoints)
{
DrawDebugPoint(
World,
HitResult.ImpactPoint,
Settings.HitPointSize,
HitColor,
Settings.Persistent,
Settings.LifeTime,
Settings.DepthPriority);
}
if (Settings.DrawHitNormals)
{
DrawDebugDirectionalArrow(
World,
HitResult.Location,
HitResult.Location + HitResult.Normal * 20.0f,
FCogDebug::Settings.ArrowSize,
Settings.NormalColor,
Settings.Persistent,
Settings.LifeTime,
Settings.DepthPriority,
Settings.Thickness);
}
if (Settings.DrawHitImpactNormals)
{
DrawDebugDirectionalArrow(
World,
HitResult.ImpactPoint,
HitResult.ImpactPoint + HitResult.ImpactNormal * 20.0f,
FCogDebug::Settings.ArrowSize,
Settings.ImpactNormalColor,
Settings.Persistent,
Settings.LifeTime,
Settings.DepthPriority,
Settings.Thickness);
}
if (Settings.DrawHitPrimitives)
{
const UPrimitiveComponent* PrimitiveComponent = HitResult.GetComponent();
if (PrimitiveComponent == nullptr)
{
continue;
}
if (AlreadyDrawnPrimitives.Contains(PrimitiveComponent))
{
continue;
}
AlreadyDrawnPrimitives.Add(PrimitiveComponent);
const ECollisionChannel CollisionObjectType = PrimitiveComponent->GetCollisionObjectType();
const FColor PrimitiveColor = Settings.ChannelColors[CollisionObjectType];
DrawPrimitiveComponent(*PrimitiveComponent, PrimitiveColor, Settings.Persistent, Settings.LifeTime, Settings.DepthPriority, Settings.Thickness);
if (Settings.DrawHitPrimitiveActorsName)
{
const AActor* Actor = PrimitiveComponent->GetOwner();
if (Actor == nullptr)
{
continue;
}
if (AlreadyDrawnActors.Contains(Actor))
{
continue;
}
AlreadyDrawnActors.Add(Actor);
const FColor TextColor = PrimitiveColor.WithAlpha(255);
DrawDebugString(World, Actor->GetActorLocation(), GetNameSafe(Actor->GetClass()), nullptr, TextColor, 0.0f, Settings.HitPrimitiveActorsNameShadow, Settings.HitPrimitiveActorsNameSize);
}
}
}
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebugDrawHelper::DrawLineTrace(
const UWorld* World,
const FVector& Start,
const FVector& End,
const bool HasHits,
TArray<FHitResult>& HitResults,
const FCogDebugDrawLineTraceParams& Settings
)
{
DrawDebugDirectionalArrow(
World,
Start,
End,
FCogDebug::Settings.ArrowSize,
HasHits ? Settings.HitColor : Settings.NoHitColor,
false,
0.0f,
FCogDebug::GetDebugDepthPriority(0),
FCogDebug::GetDebugThickness(0.0f));
DrawHitResults(World, HitResults, Settings);
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebugDrawHelper::DrawSweep(
const UWorld* World,
const FCollisionShape& Shape,
const FVector& Start,
const FVector& End,
const FQuat& Rotation,
const bool HasHits,
TArray<FHitResult>& HitResults,
const FCogDebugDrawSweepParams& Settings
)
{
const FColor Color = HasHits ? Settings.HitColor : Settings.NoHitColor;
DrawDebugDirectionalArrow(
World,
Start,
End,
FCogDebug::Settings.ArrowSize,
Color,
false,
0.0f,
FCogDebug::GetDebugDepthPriority(0),
FCogDebug::GetDebugThickness(0.0f));
DrawShape(World, Shape, Start, Rotation, FVector::OneVector, Color, Settings.Persistent, Settings.LifeTime, Settings.DepthPriority, Settings.Thickness);
DrawHitResults(World, HitResults, Settings);
for (const FHitResult& Hit : HitResults)
{
if (Settings.DrawHitShapes)
{
DrawShape(World, Shape, Hit.Location, Rotation, FVector::OneVector, Color, Settings.Persistent, Settings.LifeTime, Settings.DepthPriority, Settings.Thickness);
}
}
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebugDrawHelper::DrawOverlap(
const UWorld* World,
const FCollisionShape& Shape,
const FVector& Location,
const FQuat& Rotation,
TArray<FOverlapResult>& OverlapResults,
const FCogDebugDrawOverlapParams& Settings
)
{
const FColor Color = OverlapResults.Num() > 0 ? Settings.HitColor : Settings.NoHitColor;
DrawShape(World, Shape, Location, Rotation, FVector::OneVector, Color, Settings.Persistent, Settings.LifeTime, Settings.DepthPriority, Settings.Thickness);
if (Settings.DrawHitPrimitives)
{
for (const FOverlapResult& OverlapResult : OverlapResults)
{
if (const UPrimitiveComponent* PrimitiveComponent = OverlapResult.GetComponent())
{
const ECollisionChannel CollisionObjectType = PrimitiveComponent->GetCollisionObjectType();
const FColor PrimitiveColor = Settings.ChannelColors[CollisionObjectType];
DrawPrimitiveComponent(*PrimitiveComponent, PrimitiveColor, Settings.Persistent, Settings.LifeTime, Settings.DepthPriority, Settings.Thickness);
}
}
}
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebugDrawHelper::DrawPrimitiveComponent(
const UPrimitiveComponent& PrimitiveComponent,
const FColor& Color,
const bool Persistent,
const float LifeTime,
const uint8 DepthPriority,
const float Thickness)
{
const UWorld* World = PrimitiveComponent.GetWorld();
if (World == nullptr)
{
return;
}
const UBoxComponent* BoxComponent = Cast<UBoxComponent>(&PrimitiveComponent);;
const FCollisionShape Shape = PrimitiveComponent.GetCollisionShape();
if (Shape.ShapeType == ECollisionShape::Box && BoxComponent == nullptr)
{
FVector Location;
FVector Extent;
PrimitiveComponent.Bounds.GetBox().GetCenterAndExtents(Location, Extent);
// TODO: this adds padding to prevent Z fight. Maybe add this as a parameter.
Extent += FVector::OneVector;
DrawDebugSolidBox(
World,
Location,
Extent,
FQuat::Identity,
Color,
Persistent,
LifeTime,
DepthPriority);
DrawDebugBox(
World,
Location,
Extent,
FQuat::Identity,
Color,
Persistent,
LifeTime,
DepthPriority,
Thickness);
}
else
{
const FVector Location = PrimitiveComponent.GetComponentLocation();
const FQuat Rotation = PrimitiveComponent.GetComponentQuat();
const FVector Scale = PrimitiveComponent.GetComponentScale();
DrawShape(World, Shape, Location, Rotation, Scale, Color, Persistent, LifeTime, DepthPriority, Thickness);
}
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebugDrawHelper::DrawShape(
const UWorld* World,
const FCollisionShape& InShape,
const FVector& Location,
const FQuat& Rotation,
const FVector& Scale,
const FColor& Color,
const bool Persistent,
const float LifeTime,
const uint8 DepthPriority,
const float Thickness)
{
switch (InShape.ShapeType)
{
case ECollisionShape::Box:
{
//--------------------------------------------------
// see UBoxComponent::GetScaledBoxExtent()
//--------------------------------------------------
const FVector HalfExtent(InShape.Box.HalfExtentX * Scale.X, InShape.Box.HalfExtentY * Scale.Y, InShape.Box.HalfExtentZ * Scale.Z);
DrawDebugBox(
World,
Location,
HalfExtent,
Rotation,
Color,
Persistent,
LifeTime,
DepthPriority,
Thickness);
break;
}
case ECollisionShape::Sphere:
{
//--------------------------------------------------
// see USphereComponent::GetScaledSphereRadius()
//--------------------------------------------------
const float RadiusScale = FMath::Min(Scale.X, FMath::Min(Scale.Y, Scale.Z));
const float Radius = InShape.Sphere.Radius * RadiusScale;
DrawSphere(
World,
Location,
Radius,
FCogDebug::GetCircleSegments(),
Color,
Persistent,
LifeTime,
DepthPriority,
Thickness);
break;
}
case ECollisionShape::Capsule:
{
//--------------------------------------------------
// see UCapsuleComponent::GetScaledCapsuleRadius()
//--------------------------------------------------
const float Radius = InShape.Capsule.Radius * FMath::Min(Scale.X, Scale.Y);
const float HalfHeight = InShape.Capsule.HalfHeight * UE_REAL_TO_FLOAT(Scale.Z);
DrawDebugCapsule(
World,
Location,
HalfHeight,
Radius,
Rotation,
Color,
Persistent,
LifeTime,
DepthPriority,
Thickness);
break;
}
default:
break;
}
}
+158 -9
View File
@@ -4,6 +4,9 @@
#include "UObject/WeakObjectPtrTemplates.h"
#include "CogDebug.generated.h"
struct FCogDebugDrawSweepParams;
struct FCogDebugDrawLineTraceParams;
struct FCogDebugDrawOverlapParams;
class UObject;
class AActor;
class UWorld;
@@ -86,34 +89,34 @@ struct FCogDebugSettings
float GizmoTranslationAxisLength = 50.0f;
UPROPERTY(Config)
bool GizmoTranslationSnapEnable = true;
bool GizmoTranslationSnapEnable = false;
UPROPERTY(Config)
float GizmoTranslationSnapValue = 10.0f;
UPROPERTY(Config)
float GizmoTranslationPlaneOffset = 25.0f;
float GizmoTranslationPlaneOffset = 18.0f;
UPROPERTY(Config)
float GizmoTranslationPlaneExtent = 5.0f;
UPROPERTY(Config)
bool GizmoRotationSnapEnable = true;
bool GizmoRotationSnapEnable = false;
UPROPERTY(Config)
float GizmoRotationSnapValue = 10.0f;
UPROPERTY(Config)
float GizmoRotationSpeed = 0.01f;
float GizmoRotationSpeed = 1.0f;
UPROPERTY(Config)
float GizmoRotationRadius = 15.0f;
float GizmoRotationRadius = 40.0f;
UPROPERTY(Config)
int GizmoRotationSegments = 12;
int GizmoRotationSegments = 8;
UPROPERTY(Config)
bool GizmoScaleSnapEnable = true;
bool GizmoScaleSnapEnable = false;
UPROPERTY(Config)
float GizmoScaleSnapValue = 1.0f;
@@ -125,7 +128,7 @@ struct FCogDebugSettings
float GizmoScaleBoxExtent = 2.0f;
UPROPERTY(Config)
float GizmoScaleSpeed = 0.5f;
float GizmoScaleSpeed = 0.01f;
UPROPERTY(Config)
float GizmoScaleMin = 0.001f;
@@ -136,7 +139,7 @@ struct FCogDebugSettings
UPROPERTY(Config)
TEnumAsByte<ECollisionChannel> GizmoGroundRaycastChannel = ECollisionChannel::ECC_WorldStatic;
UPROPERTY(Config)
UPROPERTY(Config)
float GizmoGroundRaycastCircleRadius = 5.0f;
UPROPERTY(Config)
@@ -184,6 +187,144 @@ struct FCogDebugSettings
UPROPERTY(Config)
FColor GizmoTextColor = FColor(255, 255, 255, 255);
UPROPERTY(Config)
FColor CollisionQueryHitColor = FColor::Green;
UPROPERTY(Config)
FColor CollisionQueryNoHitColor = FColor::Red;
UPROPERTY(Config)
bool CollisionQueryDrawHitPrimitives = true;
UPROPERTY(Config)
bool CollisionQueryDrawHitPrimitiveActorsName = false;
UPROPERTY(Config)
bool CollisionQueryHitPrimitiveActorsNameShadow = true;
UPROPERTY(Config)
float CollisionQueryHitPrimitiveActorsNameSize = 1.0f;
UPROPERTY(Config)
bool CollisionQueryDrawHitLocation = true;
UPROPERTY(Config)
bool CollisionQueryDrawHitImpactPoints = true;
UPROPERTY(Config)
bool CollisionQueryDrawHitNormals = true;
UPROPERTY(Config)
bool CollisionQueryDrawHitImpactNormals = true;
UPROPERTY(Config)
float CollisionQueryHitPointSize = 5.0f;
UPROPERTY(Config)
FColor CollisionQueryNormalColor = FColor::Yellow;
UPROPERTY(Config)
FColor CollisionQueryImpactNormalColor = FColor::Cyan;
UPROPERTY(Config)
bool CollisionQueryDrawHitShapes = true;
UPROPERTY(Config)
FColor ChannelColorWorldStatic = FColor(255, 0, 0, 5);
UPROPERTY(Config)
FColor ChannelColorWorldDynamic = FColor(255, 0, 188, 5);
UPROPERTY(Config)
FColor ChannelColorPawn = FColor(105, 0, 255, 5);
UPROPERTY(Config)
FColor ChannelColorVisibility = FColor(0, 15, 255, 5);
UPROPERTY(Config)
FColor ChannelColorCamera = FColor(0, 105, 255, 5);
UPROPERTY(Config)
FColor ChannelColorPhysicsBody = FColor(0, 255, 208, 5);
UPROPERTY(Config)
FColor ChannelColorVehicle = FColor(52, 255, 0, 5);
UPROPERTY(Config)
FColor ChannelColorDestructible = FColor(255, 255, 0, 0);
UPROPERTY(Config)
FColor ChannelColorEngineTraceChannel1 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorEngineTraceChannel2 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorEngineTraceChannel3 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorEngineTraceChannel4 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorEngineTraceChannel5 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorEngineTraceChannel6 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel1 = FColor(255, 105, 0, 5);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel2 = FColor(255, 30, 0, 5);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel3 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel4 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel5 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel6 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel7 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel8 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel9 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel10 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel11 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel12 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel13 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel14 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel15 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel16 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel17 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel18 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
TArray<FString> SecondaryBoneWildcards = {
"interaction",
@@ -252,6 +393,14 @@ public:
static void Reset();
static void GetDebugChannelColors(FColor ChannelColors[ECC_MAX]);
static void GetDebugDrawOverlapSettings(FCogDebugDrawOverlapParams& Params);
static void GetDebugDrawLineTraceSettings(FCogDebugDrawLineTraceParams& Params);
static void GetDebugDrawSweepSettings(FCogDebugDrawSweepParams& Params);
static FCogDebugSettings Settings;
private:
@@ -8,42 +8,67 @@ class UWorld;
struct FHitResult;
class AActor;
struct FCogDebugDrawOverlapParams
{
FColor HitColor = FColor::Green;
FColor NoHitColor = FColor::Red;
bool DrawHitPrimitives = true;
bool DrawHitPrimitiveActorsName = false;
bool HitPrimitiveActorsNameShadow = true;
float HitPrimitiveActorsNameSize = 1.0f;
bool Persistent = false;
float LifeTime = 0.0f;
uint8 DepthPriority = 0;
float Thickness = 0.0f;
FColor ChannelColors[ECC_MAX];
};
struct FCogDebugDrawLineTraceParams : public FCogDebugDrawOverlapParams
{
bool DrawHitLocation = true;
bool DrawHitImpactPoints = true;
bool DrawHitNormals = true;
bool DrawHitImpactNormals = true;
float HitPointSize = 5.0f;
FColor NormalColor = FColor::Yellow;
FColor ImpactNormalColor = FColor::Cyan;
};
struct FCogDebugDrawSweepParams : public FCogDebugDrawLineTraceParams
{
bool DrawHitShapes = true;
};
class COGDEBUG_API FCogDebugDrawHelper
{
public:
static void DrawArc(const UWorld* InWorld, const FMatrix& Matrix, const float InnterRadius, const float OuterRadius, const float AngleStart, const float AngleEnd, const int32 Segments, const FColor& Color, const bool bPersistentLines = false, const float LifeTime = -1.f, const uint8 DepthPriority = 0U, const float Thickness = 0.0f);
static void DrawArc(const UWorld* World, const FMatrix& Matrix, const float InnterRadius, const float OuterRadius, const float AngleStart, const float AngleEnd, const int32 Segments, const FColor& Color, const bool bPersistentLines = false, const float LifeTime = -1.f, const uint8 DepthPriority = 0U, const float Thickness = 0.0f);
static void DrawArc(const UWorld* InWorld, const FMatrix& Matrix, const float InnterRadius, const float OuterRadius, const float ArcAngle, const int32 Segments, const FColor& Color, const bool bPersistentLines = false, const float LifeTime = -1.f, const uint8 DepthPriority = 0U, const float Thickness = 0.0f);
static void DrawArc(const UWorld* World, const FMatrix& Matrix, const float InnterRadius, const float OuterRadius, const float ArcAngle, const int32 Segments, const FColor& Color, const bool bPersistentLines = false, const float LifeTime = -1.f, const uint8 DepthPriority = 0U, const float Thickness = 0.0f);
static void DrawSphere(const UWorld* InWorld, const FVector& Center, const float Radius, const int32 Segments, const FColor& Color, const bool bPersistentLines = false, const float LifeTime = -1.f, const uint8 DepthPriority = 0U, const float Thickness = 0.0f);
static void DrawSphere(const UWorld* World, const FVector& Center, const float Radius, const int32 Segments, const FColor& Color, const bool bPersistentLines = false, const float LifeTime = -1.f, const uint8 DepthPriority = 0U, const float Thickness = 0.0f);
static void DrawFrustum(const UWorld* World, const FMatrix& Matrix, const float Angle, const float AspectRatio, const float NearPlane, const float FarPlane, const FColor& Color, const bool bPersistentLines = false, const float LifeTime = -1.f, const uint8 DepthPriority = 0U, const float Thickness = 0.0f);
static void DrawFlatCapsule(const UWorld* InWorld, const FVector2D& Start, const FVector2D& End, const float Radius, const float Z, const float Segments, const FColor& Color, const bool bPersistentLines = false, const float LifeTime = -1.0f, const uint8 DepthPriority = 0, const float Thickness = 0.0f);
static void DrawFlatCapsule(const UWorld* World, const FVector2D& Start, const FVector2D& End, const float Radius, const float Z, const float Segments, const FColor& Color, const bool bPersistentLines = false, const float LifeTime = -1.0f, const uint8 DepthPriority = 0, const float Thickness = 0.0f);
static void DrawRaycastSingle(const UWorld* World, const FVector& Start, const FVector& End, const EDrawDebugTrace::Type DrawType, const bool bHit, const FHitResult& Hit, const float HitSize, const FLinearColor DrawColor, const FLinearColor DrawHitColor, const float DrawDuration, const uint8 DepthPriority = 0);
static void DrawSphereOverlapMulti(const UWorld* World, const FVector& Position, const float Radius, const EDrawDebugTrace::Type DrawType, const bool bOverlap, const TArray<AActor*>& OutActors, const FLinearColor DrawColor, const FLinearColor DrawHitColor, const float DrawDuration = 0);
static void DrawSphereOverlapSingle(const UWorld* World, const FVector& Position, const float Radius, const FColor& DrawColor, const bool DrawPersistent, const float DrawDuration = -1.f, const uint8 DepthPriority = 0);
static void DrawCapsuleCastMulti(const UWorld* World, const FVector& Start, const FVector& End, const FQuat& Rotation, const float HalfHeight, const float Radius, const EDrawDebugTrace::Type DrawType, const bool bHit, const TArray<FHitResult>& OutHits, const FLinearColor DrawColor, const FLinearColor DrawHitColor, const float DrawDuration = 0);
static void DrawCapsuleCastSingle(const UWorld* World, const FVector& Start, const FVector& End, const FQuat& Rotation, const float HalfHeight, const float Radius, const FColor& DrawColor, const bool DrawPersistent, const float DrawDuration = -1.f, const uint8 DepthPriority = 0);
static void DrawSphereCastMulti(const UWorld* World, const FVector& Start, const FVector& End, const float Radius, const EDrawDebugTrace::Type DrawType, const bool bHit, const TArray<FHitResult>& OutHits, const FLinearColor DrawColor, const FLinearColor DrawHitColor, const float DrawDuration = 0);
static void DrawSphereCastSingle(const UWorld* World, const FVector& Start, const FVector& End, const float Radius, const FColor& DrawColor, const bool DrawPersistent, const float LifeTime = -1.f, const uint8 DepthPriority = 0);
static void DrawHitResults(const UWorld* World, const TArray<FHitResult>& OutHits, const EDrawDebugTrace::Type DrawType, const bool ShowHitIndex, const float HitSize, const FLinearColor HitColor, const float DrawDuration, const uint8 DepthPriority = 0);
static void DrawHitResultsDiscarded(const UWorld* World, const TArray<FHitResult>& AllHits, const TArray<FHitResult>& KeptHits, const EDrawDebugTrace::Type DrawType, const float HitSize, const FLinearColor DrawColor, const float DrawDuration, const uint8 DepthPriority = 0);
static void DrawHitResult(const UWorld* World, const FHitResult& Hit, const int HitIndex, const EDrawDebugTrace::Type DrawType, const bool ShowHitIndex, const float HitSize, const FLinearColor HitColor, const float DrawDuration, const uint8 DepthPriority = 0);
static void DrawQuad(const UWorld* World, const FVector& Position, const FQuat& Rotation, const FVector2D& Extents, const FColor& Color, bool bPersistent = false, float LifeTime = -1, uint8 DepthPriority = 0, const float Thickness = 0.0f);
static void DrawSolidQuad(const UWorld* World, const FVector& Position, const FQuat& Rotation, const FVector2D& Extents, const FColor& Color, bool bPersistent = false, float LifeTime = -1, uint8 DepthPriority = 0);
static void DrawShape(const UWorld* World, const FCollisionShape& InShape, const FVector& Location, const FQuat& Rotation, const FVector& Scale, const FColor& Color, const bool Persistent, const float LifeTime, const uint8 DepthPriority, const float Thickness);
static void DrawPrimitiveComponent(const UPrimitiveComponent& PrimitiveComponent, const FColor& Color, const bool Persistent, const float LifeTime, const uint8 DepthPriority, const float Thickness);
static void DrawOverlap(const UWorld* World, const FCollisionShape& Shape, const FVector& Location, const FQuat& Rotation, TArray<FOverlapResult>& OverlapResults, const FCogDebugDrawOverlapParams& Settings);
static void DrawHitResult(const UWorld* World, const FHitResult& HitResult, const FCogDebugDrawLineTraceParams& Settings);
static void DrawHitResults(const UWorld* World, const TArray<FHitResult>& HitResults, const FCogDebugDrawLineTraceParams& Settings);
static void DrawLineTrace(const UWorld* World, const FVector& Start, const FVector& End, const bool HasHits, TArray<FHitResult>& HitResults, const FCogDebugDrawLineTraceParams& Settings);
static void DrawSweep(const UWorld* World, const FCollisionShape& Shape, const FVector& Start, const FVector& End, const FQuat& Rotation, const bool HasHits, TArray<FHitResult>& HitResults, const FCogDebugDrawSweepParams& Settings);
};
@@ -38,16 +38,11 @@ void ACogEngineCollisionTester::Tick(float DeltaSeconds)
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogEngineCollisionTester::Query()
void ACogEngineCollisionTester::Query() const
{
AlreadyDrawnActors.Empty();
AlreadyDrawnComponents.Empty();
FVector QueryStart = StartComponent->GetComponentLocation();
FVector QueryEnd = EndComponent->GetComponentLocation();
FQuat QueryRotation = StartComponent->GetComponentQuat();
TArray<FHitResult> Hits;
TArray<FOverlapResult> Overlaps;
bool HasHits = false;
static const FName TraceTag(TEXT("FCogWindow_Collision"));
@@ -57,9 +52,7 @@ void ACogEngineCollisionTester::Query()
const FName ProfileName = Profile != nullptr ? Profile->Name : FName();
FCollisionShape QueryShape;
const bool bIsUsingShape = Type == ECogEngine_CollisionQueryType::Overlap || Type == ECogEngine_CollisionQueryType::Sweep;
if (bIsUsingShape)
if (Type == ECogEngine_CollisionQueryType::Overlap || Type == ECogEngine_CollisionQueryType::Sweep)
{
switch (Shape)
{
@@ -71,439 +64,235 @@ void ACogEngineCollisionTester::Query()
switch (Type)
{
case ECogEngine_CollisionQueryType::Overlap:
{
switch (By)
{
case ECogEngine_CollisionQueryBy::Channel:
{
HasHits = GetWorld()->OverlapMultiByChannel(Overlaps, QueryStart, QueryRotation, Channel, QueryShape, QueryParams);
break;
}
case ECogEngine_CollisionQueryType::Overlap:
{
TArray<FOverlapResult> Overlaps;
switch (By)
{
case ECogEngine_CollisionQueryBy::Channel:
{
HasHits = GetWorld()->OverlapMultiByChannel(Overlaps, QueryStart, QueryRotation, Channel, QueryShape, QueryParams);
break;
}
case ECogEngine_CollisionQueryBy::ObjectType:
{
FCollisionObjectQueryParams QueryObjectParams;
QueryObjectParams.ObjectTypesToQuery = ObjectTypesToQuery;
HasHits = GetWorld()->OverlapMultiByObjectType(Overlaps, QueryStart, QueryRotation, QueryObjectParams, QueryShape, QueryParams);
break;
}
case ECogEngine_CollisionQueryBy::ObjectType:
{
FCollisionObjectQueryParams QueryObjectParams;
QueryObjectParams.ObjectTypesToQuery = ObjectTypesToQuery;
HasHits = GetWorld()->OverlapMultiByObjectType(Overlaps, QueryStart, QueryRotation, QueryObjectParams, QueryShape, QueryParams);
break;
}
case ECogEngine_CollisionQueryBy::Profile:
{
HasHits = GetWorld()->OverlapMultiByProfile(Overlaps, QueryStart, QueryRotation, ProfileName, QueryShape, QueryParams);
break;
}
}
case ECogEngine_CollisionQueryBy::Profile:
{
HasHits = GetWorld()->OverlapMultiByProfile(Overlaps, QueryStart, QueryRotation, ProfileName, QueryShape, QueryParams);
break;
}
}
break;
}
FCogDebugDrawOverlapParams DrawParams;
FCogDebug::GetDebugDrawOverlapSettings(DrawParams);
FCogDebugDrawHelper::DrawOverlap(GetWorld(), QueryShape, QueryStart, QueryRotation, Overlaps, DrawParams);
break;
}
case ECogEngine_CollisionQueryType::LineTrace:
{
switch (By)
{
case ECogEngine_CollisionQueryBy::Channel:
{
switch (Mode)
{
case ECogEngine_CollisionQueryMode::Single:
{
FHitResult Hit;
HasHits = GetWorld()->LineTraceSingleByChannel(Hit, QueryStart, QueryEnd, Channel, QueryParams);
if (HasHits)
{
Hits.Add(Hit);
}
break;
}
case ECogEngine_CollisionQueryMode::Multi:
{
HasHits = GetWorld()->LineTraceMultiByChannel(Hits, QueryStart, QueryEnd, Channel, QueryParams);
break;
}
case ECogEngine_CollisionQueryMode::Test:
{
HasHits = GetWorld()->LineTraceTestByChannel(QueryStart, QueryEnd, Channel, QueryParams);
break;
}
}
case ECogEngine_CollisionQueryType::LineTrace:
{
TArray<FHitResult> Hits;
switch (By)
{
case ECogEngine_CollisionQueryBy::Channel:
{
switch (Mode)
{
case ECogEngine_CollisionQueryMode::Single:
{
FHitResult Hit;
HasHits = GetWorld()->LineTraceSingleByChannel(Hit, QueryStart, QueryEnd, Channel, QueryParams);
if (HasHits)
{
Hits.Add(Hit);
}
break;
}
case ECogEngine_CollisionQueryMode::Multi:
{
HasHits = GetWorld()->LineTraceMultiByChannel(Hits, QueryStart, QueryEnd, Channel, QueryParams);
break;
}
case ECogEngine_CollisionQueryMode::Test:
{
HasHits = GetWorld()->LineTraceTestByChannel(QueryStart, QueryEnd, Channel, QueryParams);
break;
}
}
break;
}
break;
}
case ECogEngine_CollisionQueryBy::ObjectType:
{
FCollisionObjectQueryParams QueryObjectParams;
QueryObjectParams.ObjectTypesToQuery = ObjectTypesToQuery;
case ECogEngine_CollisionQueryBy::ObjectType:
{
FCollisionObjectQueryParams QueryObjectParams;
QueryObjectParams.ObjectTypesToQuery = ObjectTypesToQuery;
switch (Mode)
{
case ECogEngine_CollisionQueryMode::Single:
{
FHitResult Hit;
HasHits = GetWorld()->LineTraceSingleByObjectType(Hit, QueryStart, QueryEnd, QueryObjectParams, QueryParams);
if (HasHits)
{
Hits.Add(Hit);
}
break;
}
case ECogEngine_CollisionQueryMode::Multi:
{
HasHits = GetWorld()->LineTraceMultiByObjectType(Hits, QueryStart, QueryEnd, QueryObjectParams, QueryParams);
break;
}
case ECogEngine_CollisionQueryMode::Test:
{
HasHits = GetWorld()->LineTraceTestByObjectType(QueryStart, QueryEnd, QueryObjectParams, QueryParams);
break;
}
}
break;
}
switch (Mode)
{
case ECogEngine_CollisionQueryMode::Single:
{
FHitResult Hit;
HasHits = GetWorld()->LineTraceSingleByObjectType(Hit, QueryStart, QueryEnd, QueryObjectParams, QueryParams);
if (HasHits)
{
Hits.Add(Hit);
}
break;
}
case ECogEngine_CollisionQueryMode::Multi:
{
HasHits = GetWorld()->LineTraceMultiByObjectType(Hits, QueryStart, QueryEnd, QueryObjectParams, QueryParams);
break;
}
case ECogEngine_CollisionQueryMode::Test:
{
HasHits = GetWorld()->LineTraceTestByObjectType(QueryStart, QueryEnd, QueryObjectParams, QueryParams);
break;
}
}
break;
}
case ECogEngine_CollisionQueryBy::Profile:
{
switch (Mode)
{
case ECogEngine_CollisionQueryMode::Single:
{
FHitResult Hit;
HasHits = GetWorld()->LineTraceSingleByProfile(Hit, QueryStart, QueryEnd, ProfileName, QueryParams);
if (HasHits)
{
Hits.Add(Hit);
}
break;
}
case ECogEngine_CollisionQueryMode::Multi:
{
HasHits = GetWorld()->LineTraceMultiByProfile(Hits, QueryStart, QueryEnd, ProfileName, QueryParams);
break;
}
case ECogEngine_CollisionQueryMode::Test:
{
HasHits = GetWorld()->LineTraceTestByProfile(QueryStart, QueryEnd, ProfileName, QueryParams);
break;
}
}
break;
}
}
break;
}
case ECogEngine_CollisionQueryBy::Profile:
{
switch (Mode)
{
case ECogEngine_CollisionQueryMode::Single:
{
FHitResult Hit;
HasHits = GetWorld()->LineTraceSingleByProfile(Hit, QueryStart, QueryEnd, ProfileName, QueryParams);
if (HasHits)
{
Hits.Add(Hit);
}
break;
}
case ECogEngine_CollisionQueryMode::Multi:
{
HasHits = GetWorld()->LineTraceMultiByProfile(Hits, QueryStart, QueryEnd, ProfileName, QueryParams);
break;
}
case ECogEngine_CollisionQueryMode::Test:
{
HasHits = GetWorld()->LineTraceTestByProfile(QueryStart, QueryEnd, ProfileName, QueryParams);
break;
}
}
break;
}
}
case ECogEngine_CollisionQueryType::Sweep:
{
switch (By)
{
case ECogEngine_CollisionQueryBy::Channel:
{
switch (Mode)
{
case ECogEngine_CollisionQueryMode::Single:
{
FHitResult Hit;
HasHits = GetWorld()->SweepSingleByChannel(Hit, QueryStart, QueryEnd, QueryRotation, Channel, QueryShape, QueryParams);
if (HasHits)
{
Hits.Add(Hit);
}
break;
}
case ECogEngine_CollisionQueryMode::Multi:
{
HasHits = GetWorld()->SweepMultiByChannel(Hits, QueryStart, QueryEnd, QueryRotation, Channel, QueryShape, QueryParams);
break;
}
case ECogEngine_CollisionQueryMode::Test:
{
HasHits = GetWorld()->SweepTestByChannel(QueryStart, QueryEnd, QueryRotation, Channel, QueryShape, QueryParams);
break;
}
}
break;
}
FCogDebugDrawLineTraceParams DrawParams;
FCogDebug::GetDebugDrawLineTraceSettings(DrawParams);
FCogDebugDrawHelper::DrawLineTrace(GetWorld(), QueryStart, QueryEnd, HasHits, Hits, DrawParams);
break;
}
case ECogEngine_CollisionQueryBy::ObjectType:
{
FCollisionObjectQueryParams QueryObjectParams;
QueryObjectParams.ObjectTypesToQuery = ObjectTypesToQuery;
case ECogEngine_CollisionQueryType::Sweep:
{
TArray<FHitResult> Hits;
switch (By)
{
case ECogEngine_CollisionQueryBy::Channel:
{
switch (Mode)
{
case ECogEngine_CollisionQueryMode::Single:
{
FHitResult Hit;
HasHits = GetWorld()->SweepSingleByChannel(Hit, QueryStart, QueryEnd, QueryRotation, Channel, QueryShape, QueryParams);
if (HasHits)
{
Hits.Add(Hit);
}
break;
}
case ECogEngine_CollisionQueryMode::Multi:
{
HasHits = GetWorld()->SweepMultiByChannel(Hits, QueryStart, QueryEnd, QueryRotation, Channel, QueryShape, QueryParams);
break;
}
case ECogEngine_CollisionQueryMode::Test:
{
HasHits = GetWorld()->SweepTestByChannel(QueryStart, QueryEnd, QueryRotation, Channel, QueryShape, QueryParams);
break;
}
}
break;
}
switch (Mode)
{
case ECogEngine_CollisionQueryMode::Single:
{
FHitResult Hit;
HasHits = GetWorld()->SweepSingleByObjectType(Hit, QueryStart, QueryEnd, QueryRotation, QueryObjectParams, QueryShape, QueryParams);
if (HasHits)
{
Hits.Add(Hit);
}
break;
}
case ECogEngine_CollisionQueryMode::Multi:
{
HasHits = GetWorld()->SweepMultiByObjectType(Hits, QueryStart, QueryEnd, QueryRotation, QueryObjectParams, QueryShape, QueryParams);
break;
}
case ECogEngine_CollisionQueryMode::Test:
{
HasHits = GetWorld()->SweepTestByObjectType(QueryStart, QueryEnd, QueryRotation, QueryObjectParams, QueryShape, QueryParams);
break;
}
}
break;
}
case ECogEngine_CollisionQueryBy::ObjectType:
{
FCollisionObjectQueryParams QueryObjectParams;
QueryObjectParams.ObjectTypesToQuery = ObjectTypesToQuery;
case ECogEngine_CollisionQueryBy::Profile:
{
switch (Mode)
{
case ECogEngine_CollisionQueryMode::Single:
{
FHitResult Hit;
HasHits = GetWorld()->SweepSingleByProfile(Hit, QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams);
if (HasHits)
{
Hits.Add(Hit);
}
break;
}
case ECogEngine_CollisionQueryMode::Multi:
{
HasHits = GetWorld()->SweepMultiByProfile(Hits, QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams);
break;
}
case ECogEngine_CollisionQueryMode::Test:
{
HasHits = GetWorld()->SweepTestByProfile(QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams);
break;
}
}
break;
}
}
break;
}
}
switch (Mode)
{
case ECogEngine_CollisionQueryMode::Single:
{
FHitResult Hit;
HasHits = GetWorld()->SweepSingleByObjectType(Hit, QueryStart, QueryEnd, QueryRotation, QueryObjectParams, QueryShape, QueryParams);
if (HasHits)
{
Hits.Add(Hit);
}
break;
}
case ECogEngine_CollisionQueryMode::Multi:
{
HasHits = GetWorld()->SweepMultiByObjectType(Hits, QueryStart, QueryEnd, QueryRotation, QueryObjectParams, QueryShape, QueryParams);
break;
}
case ECogEngine_CollisionQueryMode::Test:
{
HasHits = GetWorld()->SweepTestByObjectType(QueryStart, QueryEnd, QueryRotation, QueryObjectParams, QueryShape, QueryParams);
break;
}
}
break;
}
const FColor Color = HasHits ? FLinearColor(HitColor).ToFColor(true) : FLinearColor(NoHitColor).ToFColor(true);
const bool bUseTrace = Type == ECogEngine_CollisionQueryType::LineTrace || Type == ECogEngine_CollisionQueryType::Sweep;
if (bUseTrace)
{
DrawDebugDirectionalArrow(
GetWorld(),
QueryStart,
QueryEnd,
FCogDebug::Settings.ArrowSize,
Color,
false,
0.0f,
FCogDebug::GetDebugDepthPriority(0),
FCogDebug::GetDebugThickness(0.0f));
}
case ECogEngine_CollisionQueryBy::Profile:
{
switch (Mode)
{
case ECogEngine_CollisionQueryMode::Single:
{
FHitResult Hit;
HasHits = GetWorld()->SweepSingleByProfile(Hit, QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams);
if (HasHits)
{
Hits.Add(Hit);
}
break;
}
case ECogEngine_CollisionQueryMode::Multi:
{
HasHits = GetWorld()->SweepMultiByProfile(Hits, QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams);
break;
}
case ECogEngine_CollisionQueryMode::Test:
{
HasHits = GetWorld()->SweepTestByProfile(QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams);
break;
}
}
break;
}
}
if (bIsUsingShape)
{
DrawShape(QueryShape, QueryStart, QueryRotation, FVector::OneVector, Color, false);
}
for (const FOverlapResult& Overlap : Overlaps)
{
if (DrawHitPrimitives)
{
DrawPrimitive(Overlap.GetComponent());
}
}
for (const FHitResult& Hit : Hits)
{
if (DrawHitLocations)
{
DrawDebugPoint(
GetWorld(),
Hit.Location,
HitPointSize,
Color,
false,
0.0f,
FCogDebug::GetDebugDepthPriority(0));
}
if (DrawHitImpactPoints)
{
DrawDebugPoint(
GetWorld(),
Hit.ImpactPoint,
HitPointSize,
Color,
false,
0.0f,
FCogDebug::GetDebugDepthPriority(0));
}
if (bIsUsingShape && DrawHitShapes)
{
DrawShape(QueryShape, Hit.Location, QueryRotation, FVector::OneVector, Color, false);
}
if (DrawHitNormals)
{
DrawDebugDirectionalArrow(
GetWorld(),
Hit.Location,
Hit.Location + Hit.Normal * 20.0f,
FCogDebug::Settings.ArrowSize,
FLinearColor(NormalColor).ToFColor(true),
false,
0.0f,
FCogDebug::GetDebugDepthPriority(0),
FCogDebug::GetDebugThickness(0.0f));
}
if (DrawHitImpactNormals)
{
DrawDebugDirectionalArrow(
GetWorld(),
Hit.ImpactPoint,
Hit.ImpactPoint + Hit.ImpactNormal * 20.0f,
FCogDebug::Settings.ArrowSize,
FLinearColor(ImpactNormalColor).ToFColor(true),
false,
0.0f,
FCogDebug::GetDebugDepthPriority(0),
FCogDebug::GetDebugThickness(0.0f));
}
if (DrawHitPrimitives)
{
DrawPrimitive(Hit.GetComponent());
}
}
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogEngineCollisionTester::DrawPrimitive(const UPrimitiveComponent* PrimitiveComponent)
{
//-------------------------------------------------------
// Don't draw same primitives multiple times (for bones)
//-------------------------------------------------------
if (AlreadyDrawnComponents.Contains(PrimitiveComponent))
{
return;
}
AlreadyDrawnComponents.Add(PrimitiveComponent);
ECollisionChannel CollisionObjectType = PrimitiveComponent->GetCollisionObjectType();
FColor Color = FColor::Green; // Channels[CollisionObjectType].Color;
//-------------------------------------------------------
// Draw Name
//-------------------------------------------------------
if (DrawHitActorsNames)
{
const AActor* Actor = PrimitiveComponent->GetOwner();
if (Actor != nullptr)
{
if (AlreadyDrawnActors.Contains(Actor) == false)
{
FColor TextColor = Color.WithAlpha(255);
DrawDebugString(GetWorld(), Actor->GetActorLocation(), GetNameSafe(Actor->GetClass()), nullptr, FColor::White, 0.0f, FCogDebug::Settings.TextShadow, FCogDebug::Settings.TextSize);
AlreadyDrawnActors.Add(Actor);
}
}
}
const FVector Location = PrimitiveComponent->GetComponentLocation();
const FQuat Rotation = PrimitiveComponent->GetComponentQuat();
const FVector Scale = PrimitiveComponent->GetComponentScale();
const FCollisionShape PrimitiveShape = PrimitiveComponent->GetCollisionShape();
DrawShape(PrimitiveShape, Location, Rotation, Scale, Color, true);
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogEngineCollisionTester::DrawShape(const FCollisionShape& InShape, const FVector& InLocation, const FQuat& InRotation, const FVector& InScale, const FColor& InColor, bool InDrawSolid) const
{
switch (InShape.ShapeType)
{
case ECollisionShape::Box:
{
//--------------------------------------------------
// see UBoxComponent::GetScaledBoxExtent()
//--------------------------------------------------
const FVector HalfExtent(InShape.Box.HalfExtentX * InScale.X, InShape.Box.HalfExtentY * InScale.Y, InShape.Box.HalfExtentZ * InScale.Z);
if (InDrawSolid)
{
DrawDebugSolidBox(
GetWorld(),
InLocation,
HalfExtent,
InRotation,
InColor,
false,
0.0f,
FCogDebug::GetDebugDepthPriority(0));
}
DrawDebugBox(
GetWorld(),
InLocation,
HalfExtent,
InRotation,
InColor,
false,
0.0f,
FCogDebug::GetDebugDepthPriority(0),
FCogDebug::GetDebugThickness(0.0f));
break;
}
case ECollisionShape::Sphere:
{
//--------------------------------------------------
// see USphereComponent::GetScaledSphereRadius()
//--------------------------------------------------
const float RadiusScale = FMath::Min(InScale.X, FMath::Min(InScale.Y, InScale.Z));
const float Radius = InShape.Sphere.Radius * RadiusScale;
FCogDebugDrawHelper::DrawSphere(
GetWorld(),
InLocation,
Radius,
FCogDebug::GetCircleSegments(),
InColor,
false,
0.0f,
FCogDebug::GetDebugDepthPriority(0),
FCogDebug::GetDebugThickness(0.0f));
break;
}
case ECollisionShape::Capsule:
{
//--------------------------------------------------
// see UCapsuleComponent::GetScaledCapsuleRadius()
//--------------------------------------------------
const float Radius = InShape.Capsule.Radius * FMath::Min(InScale.X, InScale.Y);
const float HalfHeight = InShape.Capsule.HalfHeight * UE_REAL_TO_FLOAT(InScale.Z);
DrawDebugCapsule(
GetWorld(),
InLocation,
HalfHeight,
Radius,
InRotation,
InColor,
false,
0.0f,
FCogDebug::GetDebugDepthPriority(0),
FCogDebug::GetDebugThickness(0.0f));
break;
}
FCogDebugDrawSweepParams DrawParams;
FCogDebug::GetDebugDrawSweepSettings(DrawParams);
FCogDebugDrawHelper::DrawSweep(GetWorld(), QueryShape, QueryStart, QueryEnd, QueryRotation, HasHits, Hits, DrawParams);
break;
}
}
}
@@ -1,7 +1,6 @@
#include "CogEngineWindow_CollisionTester.h"
#include "CogDebug.h"
#include "CogEngineDataAsset.h"
#include "CogImGuiHelper.h"
#include "CogWindowWidgets.h"
#include "Components/PrimitiveComponent.h"
@@ -15,8 +14,6 @@ void FCogEngineWindow_CollisionTester::Initialize()
bHasMenu = true;
SetAsset(GetAsset<UCogEngineDataAsset>());
Config = GetConfig<UCogEngineConfig_CollisionTester>();
}
@@ -34,117 +31,80 @@ void FCogEngineWindow_CollisionTester::ResetConfig()
Config->Reset();
}
//--------------------------------------------------------------------------------------------------------------------------
bool RenderCollisionProfileChannels(const UCollisionProfile& CollisionProfileChannels, int32& Channels, const TArray<FCogCollisionChannel>& ChannelsConfig)
{
bool Result = false;
for (const FCogCollisionChannel& ChannelConfig : ChannelsConfig)
{
const ECollisionChannel Channel = ChannelConfig.Channel.GetValue();
ImGui::PushID(Channel);
ImColor Color = FCogImguiHelper::ToImColor(ChannelConfig.Color);
ImGui::ColorEdit4("Color", (float*)&Color.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel);
ImGui::SameLine();
bool IsCollisionActive = (Channels & ECC_TO_BITFIELD(Channel)) > 0;
const FName ChannelName = CollisionProfileChannels.ReturnChannelNameFromContainerIndex(Channel);
if (ImGui::Checkbox(TCHAR_TO_ANSI(*ChannelName.ToString()), &IsCollisionActive))
{
Result = true;
if (IsCollisionActive)
{
Channels |= ECC_TO_BITFIELD(Channel);
}
else
{
Channels &= ~ECC_TO_BITFIELD(Channel);
}
}
ImGui::PopID();
}
return Result;
}
//--------------------------------------------------------------------------------------------------------------------------
bool RenderComboCollisionChannel(const char* Label, const UCollisionProfile& CollisionProfile, ECollisionChannel& SelectedChannel, const TArray<FCogCollisionChannel>& ChannelsConfig)
{
const FName SelectedChannelName = CollisionProfile.ReturnChannelNameFromContainerIndex(SelectedChannel);
bool Result = false;
if (ImGui::BeginCombo(Label, TCHAR_TO_ANSI(*SelectedChannelName.ToString()), ImGuiComboFlags_HeightLarge))
{
for (const FCogCollisionChannel& ChannelConfig : ChannelsConfig)
{
const ECollisionChannel Channel = ChannelConfig.Channel.GetValue();
ImGui::PushID(Channel);
const FName ChannelName = CollisionProfile.ReturnChannelNameFromContainerIndex(Channel);
ImColor Color = FCogImguiHelper::ToImColor(ChannelConfig.Color);
ImGui::ColorEdit4("Color", (float*)&Color.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel);
ImGui::SameLine();
if (ImGui::Selectable(TCHAR_TO_ANSI(*ChannelName.ToString())))
{
SelectedChannel = Channel;
Result = true;
}
ImGui::PopID();
}
ImGui::EndCombo();
}
return Result;
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogEngineWindow_CollisionTester::RenderContent()
{
Super::RenderContent();
ACogEngineCollisionTester* CollisionTester = Cast<ACogEngineCollisionTester>(GetSelection());
//-------------------------------------------------
// Menu
//-------------------------------------------------
if (ImGui::BeginMenuBar())
{
if (ImGui::BeginMenu("Options"))
ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(0, 0, 0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f));
if (ImGui::ArrowButton("SelectPrev", ImGuiDir_Left))
{
ImGui::Checkbox("Draw Hit Locations", &Config->DrawHitLocations);
ImGui::Checkbox("Draw Hit Impact Points", &Config->DrawHitImpactPoints);
ImGui::Checkbox("Draw Hit Shapes", &Config->DrawHitShapes);
ImGui::Checkbox("Draw Hit Normal", &Config->DrawHitNormals);
ImGui::Checkbox("Draw Hit Impact Normal", &Config->DrawHitImpactNormals);
ImGui::Checkbox("Draw Hit Primitives", &Config->DrawHitPrimitives);
ImGui::Checkbox("Draw Hit Actors Names", &Config->DrawHitActorsNames);
}
if (ImGui::BeginItemTooltip())
{
ImGui::SetTooltip("Select previous collision tester");
ImGui::EndTooltip();
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::SliderFloat("Hit Point Size", &Config->HitPointSize, 0.0f, 20.0f, "%0.f");
ImGui::SameLine();
if (ImGui::ArrowButton("SelectNext", ImGuiDir_Right))
{
}
if (ImGui::BeginItemTooltip())
{
ImGui::SetTooltip("Select next collision tester");
ImGui::EndTooltip();
}
ImGui::ColorEdit4("No Hit Color", (float*)&Config->NoHitColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
ImGui::ColorEdit4("Hit Color", (float*)&Config->HitColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
ImGui::ColorEdit4("Normal Color", (float*)&Config->NormalColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
ImGui::ColorEdit4("Impact Normal Color", (float*)&Config->ImpactNormalColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
ImGui::PopStyleColor(1);
ImGui::PopStyleVar(1);
ImGui::EndMenu();
if (ImGui::MenuItem("Spawn"))
{
const FActorSpawnParameters SpawnInfo;
const FTransform Transform = GetSelection() ? GetSelection()->GetActorTransform() : FTransform::Identity;
ACogEngineCollisionTester* Actor = GetWorld()->SpawnActor<ACogEngineCollisionTester>(ACogEngineCollisionTester::StaticClass(), Transform, SpawnInfo);
FCogDebug::SetSelection(GetWorld(), Actor);
}
if (ImGui::BeginItemTooltip())
{
ImGui::SetTooltip("Spawn a new collision tester");
ImGui::EndTooltip();
}
const bool Disable = CollisionTester == nullptr;
if (Disable)
{
ImGui::BeginDisabled();
}
if (ImGui::MenuItem("Delete"))
{
GetWorld()->DestroyActor(CollisionTester);
CollisionTester = nullptr;
}
if (ImGui::BeginItemTooltip())
{
ImGui::SetTooltip("Delete selected collision tester");
ImGui::EndTooltip();
}
if (Disable)
{
ImGui::EndDisabled();
}
ImGui::EndMenuBar();
}
if (ImGui::Button("Spawn Collision Tester", ImVec2(-1, 0)))
{
const FActorSpawnParameters SpawnInfo;
ACogEngineCollisionTester* Actor = GetWorld()->SpawnActor<ACogEngineCollisionTester>(SpawnInfo);
FCogDebug::SetSelection(GetWorld(), Actor);
}
ACogEngineCollisionTester* CollisionTester = Cast<ACogEngineCollisionTester>(GetSelection());
if (CollisionTester == nullptr)
{
ImGui::TextDisabled("Spawn or select a Collision Tester actor");
@@ -183,7 +143,7 @@ void FCogEngineWindow_CollisionTester::RenderContent()
{
FCogWindowWidgets::SetNextItemToShortWidth();
ECollisionChannel Channel = CollisionTester->Channel.GetValue();
if (RenderComboCollisionChannel("Channel", *CollisionProfile, Channel, Asset->Channels))
if (FCogWindowWidgets::ComboCollisionChannel("Channel", Channel))
{
CollisionTester->Channel = Channel;
}
@@ -241,24 +201,24 @@ void FCogEngineWindow_CollisionTester::RenderContent()
case ECogEngine_CollisionQueryShape::Sphere:
{
FCogWindowWidgets::SetNextItemToShortWidth();
FCogImguiHelper::DragDouble("Sphere Radius", &CollisionTester->ShapeExtent.X, 0.1f, 0, FLT_MAX, "%.1f");
FCogImguiHelper::DragDouble("Sphere Radius", &CollisionTester->ShapeExtent.X, 1.0f, 0, FLT_MAX, "%.1f");
break;
}
case ECogEngine_CollisionQueryShape::Box:
{
FCogWindowWidgets::SetNextItemToShortWidth();
FCogImguiHelper::DragFVector("Box Extent", CollisionTester->ShapeExtent, 0.1f, 0, FLT_MAX, "%.1f");
FCogImguiHelper::DragFVector("Box Extent", CollisionTester->ShapeExtent, 1.0f, 0, FLT_MAX, "%.1f");
break;
}
case ECogEngine_CollisionQueryShape::Capsule:
{
FCogWindowWidgets::SetNextItemToShortWidth();
FCogImguiHelper::DragDouble("Capsule Radius", &CollisionTester->ShapeExtent.X, 0.1f, 0, FLT_MAX, "%.1f");
FCogImguiHelper::DragDouble("Capsule Radius", &CollisionTester->ShapeExtent.X, 1.0f, 0, FLT_MAX, "%.1f");
FCogWindowWidgets::SetNextItemToShortWidth();
FCogImguiHelper::DragDouble("Capsule Half Height", &CollisionTester->ShapeExtent.Z, 0.1f, 0, FLT_MAX, "%.1f");
FCogImguiHelper::DragDouble("Capsule Half Height", &CollisionTester->ShapeExtent.Z, 1.0f, 0, FLT_MAX, "%.1f");
break;
}
}
@@ -272,34 +232,11 @@ void FCogEngineWindow_CollisionTester::RenderContent()
if (CollisionTester->By == ECogEngine_CollisionQueryBy::Profile)
{
ImGui::BeginDisabled();
RenderCollisionProfileChannels(*CollisionProfile, CollisionTester->ObjectTypesToQuery, Asset->Channels);
FCogWindowWidgets::CollisionProfileChannels(CollisionTester->ObjectTypesToQuery);
ImGui::EndDisabled();
}
else if (CollisionTester->By == ECogEngine_CollisionQueryBy::ObjectType)
{
RenderCollisionProfileChannels(*CollisionProfile, CollisionTester->ObjectTypesToQuery, Asset->Channels);
}
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogEngineWindow_CollisionTester::SetAsset(const UCogEngineDataAsset* Value)
{
Asset = Value;
if (Asset == nullptr)
{
return;
}
for (FChannel& Channel : Channels)
{
Channel.IsValid = false;
}
for (const FCogCollisionChannel& AssetChannel : Asset->Channels)
{
FChannel& Channel = Channels[(uint8)AssetChannel.Channel];
Channel.IsValid = true;
Channel.Color = AssetChannel.Color.ToFColor(true);
FCogWindowWidgets::CollisionProfileChannels(CollisionTester->ObjectTypesToQuery);
}
}
@@ -2,14 +2,11 @@
#include "CogDebugDrawHelper.h"
#include "CogDebug.h"
#include "CogEngineDataAsset.h"
#include "CogEngineCollisionTester.h"
#include "CogImguiHelper.h"
#include "CogWindowHelper.h"
#include "Components/BoxComponent.h"
#include "Components/CapsuleComponent.h"
#include "CogWindowWidgets.h"
#include "Components/PrimitiveComponent.h"
#include "Components/SceneComponent.h"
#include "Components/SphereComponent.h"
#include "DrawDebugHelpers.h"
#include "Engine/World.h"
#include "GameFramework/Pawn.h"
@@ -24,8 +21,6 @@ void FCogEngineWindow_CollisionViewer::Initialize()
bHasMenu = true;
SetAsset(GetAsset<UCogEngineDataAsset>());
Config = GetConfig<UCogEngineConfig_CollisionViewer>();
}
@@ -34,8 +29,6 @@ void FCogEngineWindow_CollisionViewer::RenderHelp()
{
ImGui::Text("This window is used to inspect collisions by performing a collision query with the selected channels. "
"The query can be configured in the options. "
"The displayed collision channels can be configured in the '%s' data asset. "
, TCHAR_TO_ANSI(*GetNameSafe(Asset.Get()))
);
}
@@ -108,11 +101,6 @@ void FCogEngineWindow_CollisionViewer::RenderContent()
//-------------------------------------------------
ImGui::Checkbox("Show Actors Names", &Config->ShowActorsNames);
//-------------------------------------------------
// Show Query
//-------------------------------------------------
ImGui::Checkbox("Show Query", &Config->ShowQuery);
ImGui::EndMenu();
}
@@ -153,41 +141,7 @@ void FCogEngineWindow_CollisionViewer::RenderContent()
}
ImGui::Separator();
//-------------------------------------------------
// Query Filtering
//-------------------------------------------------
for (int ChannelIndex = 0; ChannelIndex < (int32)ECC_MAX; ++ChannelIndex)
{
const FChannel& Channel = Channels[ChannelIndex];
if (Channel.IsValid == false)
{
continue;
}
ImGui::PushID(ChannelIndex);
ImColor Color = FCogImguiHelper::ToImColor(Channel.Color);
ImGui::ColorEdit4("Color", (float*)&Color.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel);
ImGui::SameLine();
bool IsCollisionActive = (Config->ObjectTypesToQuery & ECC_TO_BITFIELD(ChannelIndex)) > 0;
const FName ChannelName = CollisionProfile->ReturnChannelNameFromContainerIndex(ChannelIndex);
if (ImGui::Checkbox(TCHAR_TO_ANSI(*ChannelName.ToString()), &IsCollisionActive))
{
if (IsCollisionActive)
{
Config->ObjectTypesToQuery |= ECC_TO_BITFIELD(ChannelIndex);
Config->ProfileIndex = INDEX_NONE;
}
else
{
Config->ObjectTypesToQuery &= ~ECC_TO_BITFIELD(ChannelIndex);
Config->ProfileIndex = INDEX_NONE;
}
}
ImGui::PopID();
}
FCogWindowWidgets::CollisionProfileChannels(Config->ObjectTypesToQuery);
//-------------------------------------------------
// Perform Query
@@ -247,10 +201,10 @@ void FCogEngineWindow_CollisionViewer::RenderContent()
FCollisionShape QueryShape;
QueryShape.SetSphere(QueryRadius);
TArray<FHitResult> QueryHits;
TArray<FHitResult> HitResults;
UWorld* World = GetWorld();
World->SweepMultiByObjectType(
QueryHits,
HitResults,
QueryStart,
QueryEnd,
FQuat::Identity,
@@ -258,153 +212,13 @@ void FCogEngineWindow_CollisionViewer::RenderContent()
QueryShape,
QueryParams);
if (Config->ShowQuery)
{
FCogDebugDrawHelper::DrawCapsuleCastMulti(World, QueryStart, QueryEnd, FQuat::Identity, 0.0f, QueryRadius, EDrawDebugTrace::ForOneFrame, false, QueryHits, FLinearColor::White, FLinearColor::Red, FCogDebug::GetDebugDuration(true));
}
TSet<const AActor*> AlreadyDrawnActors;
TSet<const UPrimitiveComponent*> AlreadyDrawnComponents;
for (const FHitResult& HitResult : QueryHits)
{
//-------------------------------------------------------
// Don't draw same primitives multiple times (for bones)
//-------------------------------------------------------
const UPrimitiveComponent* PrimitiveComponent = HitResult.GetComponent();
if (AlreadyDrawnComponents.Contains(PrimitiveComponent))
{
continue;
}
AlreadyDrawnComponents.Add(PrimitiveComponent);
ECollisionChannel CollisionObjectType = PrimitiveComponent->GetCollisionObjectType();
FColor Color = Channels[CollisionObjectType].Color;
//-------------------------------------------------------
// Draw Name
//-------------------------------------------------------
if (Config->ShowActorsNames)
{
const AActor* Actor = HitResult.GetActor();
if (Actor != nullptr)
{
if (AlreadyDrawnActors.Contains(Actor) == false)
{
FColor TextColor = Color.WithAlpha(255);
DrawDebugString(World, Actor->GetActorLocation(), GetNameSafe(Actor->GetClass()), nullptr, FColor::White, 0.0f, FCogDebug::Settings.TextShadow, FCogDebug::Settings.TextSize);
AlreadyDrawnActors.Add(Actor);
}
}
}
//-------------------------------------------------------
// Draw Shape
//-------------------------------------------------------
FCollisionShape Shape = PrimitiveComponent->GetCollisionShape();
switch (Shape.ShapeType)
{
case ECollisionShape::Box:
{
FVector Location;
FVector Extent;
FQuat Rotation;
if (const UBoxComponent* BoxComponent = Cast<UBoxComponent>(PrimitiveComponent))
{
Location = BoxComponent->GetComponentLocation();
Extent = BoxComponent->GetScaledBoxExtent();
Rotation = BoxComponent->GetComponentQuat();
}
else
{
PrimitiveComponent->Bounds.GetBox().GetCenterAndExtents(Location, Extent);
Extent += FVector::OneVector;
Rotation = FQuat::Identity;
}
DrawDebugSolidBox(
World,
Location,
Extent,
Rotation,
Color,
false,
0.0f,
FCogDebug::GetDebugDepthPriority(0));
DrawDebugBox(
World,
Location,
Extent,
Rotation,
Color,
false,
0.0f,
FCogDebug::GetDebugDepthPriority(0),
FCogDebug::GetDebugThickness(0.0f));
break;
}
case ECollisionShape::Sphere:
{
if (const USphereComponent* SphereComponent = Cast<USphereComponent>(PrimitiveComponent))
{
FCogDebugDrawHelper::DrawSphere(
World,
SphereComponent->GetComponentLocation(),
SphereComponent->GetScaledSphereRadius(),
FCogDebug::GetCircleSegments(),
Color,
false,
0.0f,
FCogDebug::GetDebugDepthPriority(0),
FCogDebug::GetDebugThickness(0.0f));
}
break;
}
case ECollisionShape::Capsule:
{
if (const UCapsuleComponent* CapsuleComponent = Cast<UCapsuleComponent>(PrimitiveComponent))
{
DrawDebugCapsule(World,
CapsuleComponent->GetComponentLocation(),
CapsuleComponent->GetScaledCapsuleHalfHeight(),
CapsuleComponent->GetScaledCapsuleRadius(),
CapsuleComponent->GetComponentQuat(),
Color,
false,
0.0f,
FCogDebug::GetDebugDepthPriority(0),
FCogDebug::GetDebugThickness(0.0f));
}
break;
}
}
}
FCogDebugDrawSweepParams DrawParams;
FCogDebug::GetDebugDrawSweepSettings(DrawParams);
DrawParams.DrawHitNormals = false;
DrawParams.DrawHitImpactNormals = false;
DrawParams.DrawHitImpactPoints = false;
DrawParams.DrawHitLocation = false;
DrawParams.DrawHitPrimitives = true;
DrawParams.DrawHitPrimitiveActorsName = Config->ShowActorsNames;
FCogDebugDrawHelper::DrawSweep(GetWorld(), QueryShape, QueryStart, QueryEnd, FQuat::Identity, false, HitResults, DrawParams);
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogEngineWindow_CollisionViewer::SetAsset(const UCogEngineDataAsset* Value)
{
Asset = Value;
if (Asset == nullptr)
{
return;
}
for (FChannel& Channel : Channels)
{
Channel.IsValid = false;
}
for (const FCogCollisionChannel& AssetChannel : Asset->Channels)
{
FChannel& Channel = Channels[(uint8)AssetChannel.Channel];
Channel.IsValid = true;
Channel.Color = AssetChannel.Color.ToFColor(true);
}
}
@@ -43,6 +43,13 @@ void FCogEngineWindow_DebugSettings::PreSaveConfig()
Config->Data = FCogDebug::Settings;
}
//--------------------------------------------------------------------------------------------------------------------------
void RenderCollisionChannelColor(const UCollisionProfile& CollisionProfile, FColor& Color, ECollisionChannel Channel, ImGuiColorEditFlags ColorEditFlags)
{
const FString ChannelName = CollisionProfile.ReturnChannelNameFromContainerIndex(Channel).ToString();
FCogImguiHelper::ColorEdit4(StringCast<ANSICHAR>(*ChannelName).Get(), Color, ColorEditFlags);
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogEngineWindow_DebugSettings::RenderContent()
{
@@ -57,200 +64,210 @@ void FCogEngineWindow_DebugSettings::RenderContent()
FCogDebug::Reset();
}
ImGui::Checkbox("Show Advanced Settings", &Config->bShowAdvancedSettings);
ImGui::EndMenu();
}
ImGui::EndMenuBar();
}
Config->Data.bIsFilteringBySelection = FCogDebug::GetIsFilteringBySelection();
if (ImGui::Checkbox("Filter by selection", &Config->Data.bIsFilteringBySelection))
{
FCogDebug::SetIsFilteringBySelection(GetWorld(), Config->Data.bIsFilteringBySelection);
}
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("If checked, only show the debug of the currently selected actor. Otherwise show the debug of all actors.");
}
constexpr ImGuiColorEditFlags ColorEditFlags = ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf;
FCogDebugSettings& Settings = FCogDebug::Settings;
ImGui::Checkbox("Persistent", &Settings.Persistent);
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
if (ImGui::CollapsingHeader("General", ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::SetTooltip("Make debug draw always persist");
Config->Data.bIsFilteringBySelection = FCogDebug::GetIsFilteringBySelection();
if (ImGui::Checkbox("Filter by selection", &Config->Data.bIsFilteringBySelection))
{
FCogDebug::SetIsFilteringBySelection(GetWorld(), Config->Data.bIsFilteringBySelection);
}
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("If checked, only show the debug of the currently selected actor. Otherwise show the debug of all actors.");
}
ImGui::Checkbox("Persistent", &Settings.Persistent);
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("Make debug draw always persist");
}
ImGui::Checkbox("Text Shadow", &Settings.TextShadow);
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("Show a shadow below debug text.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::Checkbox("Fade 2D", &Settings.Fade2D);
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("Does the 2D debug is fading out.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Duration", &Settings.Duration, 0.01f, 0.0f, 100.0f, "%.1f");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("The duration of debug elements.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Thickness", &Settings.Thickness, 0.05f, 0.0f, 5.0f, "%.1f");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("The thickness of debug lines.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Server Thickness", &Settings.ServerThickness, 0.05f, 0.0f, 5.0f, "%.1f");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("The thickness the server debug lines.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Server Color Mult", &Settings.ServerColorMultiplier, 0.01f, 0.0f, 1.0f, "%.1f");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("The color multiplier applied to the server debug lines.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragInt("Depth Priority", &Settings.DepthPriority, 0.1f, 0, 100);
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("The depth priority of debug elements.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragInt("Segments", &Settings.Segments, 0.1f, 4, 20.0f);
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("The number of segments used for circular shapes.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Axes Scale", &Settings.AxesScale, 0.1f, 0, 10.0f, "%.1f");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("The scaling debug axis.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Arrow Size", &Settings.ArrowSize, 1.0f, 0.0f, 200.0f, "%.0f");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("The size of debug arrows.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Gradient Intensity", &Settings.GradientColorIntensity, 0.01f, 0.0f, 1.0f, "%.2f");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("How much the debug elements color should be changed by a gradient color over time.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Gradient Speed", &Settings.GradientColorSpeed, 0.1f, 0.0f, 10.0f, "%.1f");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("The speed of the gradient color change.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Text Size", &Settings.TextSize, 0.1f, 0.1f, 5.0f, "%.1f");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("The size of the debug texts.");
}
}
ImGui::Checkbox("Text Shadow", &Settings.TextShadow);
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
if (ImGui::CollapsingHeader("Gizmo"))
{
ImGui::SetTooltip("Show a shadow below debug text.");
}
ImGui::SeparatorText("General");
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::Checkbox("Fade 2D", &Settings.Fade2D);
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("Does the 2D debug is fading out.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Duration", &Settings.Duration, 0.01f, 0.0f, 100.0f, "%.1f");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("The duration of debug elements.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Thickness", &Settings.Thickness, 0.05f, 0.0f, 5.0f, "%.1f");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("The thickness of debug lines.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Server Thickness", &Settings.ServerThickness, 0.05f, 0.0f, 5.0f, "%.1f");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("The thickness the server debug lines.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Server Color Mult", &Settings.ServerColorMultiplier, 0.01f, 0.0f, 1.0f, "%.1f");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("The color multiplier applied to the server debug lines.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragInt("Depth Priority", &Settings.DepthPriority, 0.1f, 0, 100);
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("The depth priority of debug elements.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragInt("Segments", &Settings.Segments, 0.1f, 4, 20.0f);
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("The number of segments used for circular shapes.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Axes Scale", &Settings.AxesScale, 0.1f, 0, 10.0f, "%.1f");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("The scaling debug axis.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Arrow Size", &Settings.ArrowSize, 1.0f, 0.0f, 200.0f, "%.0f");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("The size of debug arrows.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Gradient Intensity", &Settings.GradientColorIntensity, 0.01f, 0.0f, 1.0f, "%.2f");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("How much the debug elements color should be changed by a gradient color over time.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Gradient Speed", &Settings.GradientColorSpeed, 0.1f, 0.0f, 10.0f, "%.1f");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("The speed of the gradient color change.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Text Size", &Settings.TextSize, 0.1f, 0.1f, 5.0f, "%.1f");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("The size of the debug texts.");
}
ImGui::SeparatorText("Gizmo");
ImGui::Checkbox("Gizmo Use Local Space", &Settings.GizmoUseLocalSpace);
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Gizmo Scale", &Settings.GizmoScale, 0.1f, 0.1f, 10.0f, "%.1f");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("The scale of the gizmo.");
}
if (Config->bShowAdvancedSettings)
{
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragInt("Gizmo Z Low", &Settings.GizmoZLow, 0.5f, 0, 1000);
ImGui::Checkbox("Use Local Space", &Settings.GizmoUseLocalSpace);
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragInt("Gizmo Z High", &Settings.GizmoZHigh, 0.5f, 0, 1000);
ImGui::DragFloat("Gizmo Scale", &Settings.GizmoScale, 0.1f, 0.1f, 10.0f, "%.1f");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
ImGui::SetTooltip("The scale of the gizmo.");
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Gizmo Thickness Z Low", &Settings.GizmoThicknessZLow, 0.1f, 0.0f, 10.0f, "%.1f");
ImGui::DragInt("Z Low", &Settings.GizmoZLow, 0.5f, 0, 1000);
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Gizmo Thickness Z High", &Settings.GizmoThicknessZHigh, 0.1f, 0.0f, 10.0f, "%.1f");
ImGui::DragInt("Z High", &Settings.GizmoZHigh, 0.5f, 0, 1000);
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Gizmo Mouse Max Distance", &Settings.GizmoCursorSelectionThreshold, 0.1f, 0.0f, 50.0f, "%.1f");
ImGui::DragFloat("Thickness Z Low", &Settings.GizmoThicknessZLow, 0.1f, 0.0f, 10.0f, "%.1f");
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::Checkbox("Gizmo Translation Snap Enable", &Settings.GizmoTranslationSnapEnable);
ImGui::DragFloat("Thickness Z High", &Settings.GizmoThicknessZHigh, 0.1f, 0.0f, 10.0f, "%.1f");
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Gizmo Translation Snap", &Settings.GizmoTranslationSnapValue, 0.1f, 0.0f, 1000.0f, "%.1f");
ImGui::DragFloat("Mouse Max Distance", &Settings.GizmoCursorSelectionThreshold, 0.1f, 0.0f, 50.0f, "%.1f");
ImGui::SeparatorText("Translation");
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Gizmo Translation Axis Length", &Settings.GizmoTranslationAxisLength, 0.1f, 0.1f, 500.0f, "%.1f");
ImGui::Checkbox("Translation Snap Enable", &Settings.GizmoTranslationSnapEnable);
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Gizmo Translation Plane Offset", &Settings.GizmoTranslationPlaneOffset, 0.1f, 0.0f, 500.0f, "%.1f");
ImGui::DragFloat("Translation Snap", &Settings.GizmoTranslationSnapValue, 0.1f, 0.0f, 1000.0f, "%.1f");
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Gizmo Translation Plane Extent", &Settings.GizmoTranslationPlaneExtent, 0.1f, 0.0f, 100.0f, "%.1f");
ImGui::DragFloat("Translation Axis Length", &Settings.GizmoTranslationAxisLength, 0.1f, 0.1f, 500.0f, "%.1f");
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::Checkbox("Gizmo Rotation Snap Enable", &Settings.GizmoRotationSnapEnable);
ImGui::DragFloat("Translation Plane Offset", &Settings.GizmoTranslationPlaneOffset, 0.1f, 0.0f, 500.0f, "%.1f");
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Gizmo Rotation Snap", &Settings.GizmoRotationSnapValue, 0.1f, 0.0f, 360.0f, "%.1f");
ImGui::DragFloat("Translation Plane Extent", &Settings.GizmoTranslationPlaneExtent, 0.1f, 0.0f, 100.0f, "%.1f");
ImGui::SeparatorText("Rotation");
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Gizmo Rotation Speed", &Settings.GizmoRotationSpeed, 0.01f, 0.01f, 100.0f, "%.2f");
ImGui::Checkbox("Rotation Snap Enable", &Settings.GizmoRotationSnapEnable);
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Gizmo Rotation Radius", &Settings.GizmoRotationRadius, 0.1f, 0.1f, 500.0f, "%.1f");
ImGui::DragFloat("Rotation Snap", &Settings.GizmoRotationSnapValue, 0.1f, 0.0f, 360.0f, "%.1f");
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragInt("Gizmo Rotation Segments", &Settings.GizmoRotationSegments, 0.5f, 2, 12);
ImGui::DragFloat("Rotation Speed", &Settings.GizmoRotationSpeed, 0.01f, 0.01f, 100.0f, "%.2f");
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::Checkbox("Gizmo Scale Snap Enable", &Settings.GizmoScaleSnapEnable);
ImGui::DragFloat("Rotation Radius", &Settings.GizmoRotationRadius, 0.1f, 0.1f, 500.0f, "%.1f");
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Gizmo Scale Snap", &Settings.GizmoScaleSnapValue, 0.1f, 0.0f, 10.0f, "%.1f");
ImGui::DragInt("Rotation Segments", &Settings.GizmoRotationSegments, 0.5f, 2, 12);
ImGui::SeparatorText("Scale");
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Gizmo Scale Box Offset", &Settings.GizmoScaleBoxOffset, 0.0f, 0.0f, 500.0f, "%.1f");
ImGui::Checkbox("Scale Snap Enable", &Settings.GizmoScaleSnapEnable);
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Gizmo Scale Box Extent", &Settings.GizmoScaleBoxExtent, 0.1f, 0.0f, 100.0f, "%.1f");
ImGui::DragFloat("Scale Snap", &Settings.GizmoScaleSnapValue, 0.1f, 0.0f, 10.0f, "%.1f");
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Gizmo Scale Speed", &Settings.GizmoScaleSpeed, 0.01f, 0.01f, 100.0f, "%.2f");
ImGui::DragFloat("Scale Box Offset", &Settings.GizmoScaleBoxOffset, 0.0f, 0.0f, 500.0f, "%.1f");
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Gizmo Scale Min", &Settings.GizmoScaleMin, 0.001f, 0.001f, 1.0f, "%.3f");
ImGui::DragFloat("Scale Box Extent", &Settings.GizmoScaleBoxExtent, 0.1f, 0.0f, 100.0f, "%.1f");
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Gizmo Ground Raycast Length", &Settings.GizmoGroundRaycastLength, 10.0f, 0.0f, 1000000.0f, "%.0f");
ImGui::DragFloat("Scale Speed", &Settings.GizmoScaleSpeed, 0.01f, 0.01f, 100.0f, "%.2f");
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Scale Min", &Settings.GizmoScaleMin, 0.001f, 0.001f, 1.0f, "%.3f");
ImGui::SeparatorText("Ground Raycast");
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Ground Raycast Length", &Settings.GizmoGroundRaycastLength, 10.0f, 0.0f, 1000000.0f, "%.0f");
FCogWindowWidgets::SetNextItemToShortWidth();
ECollisionChannel Channel = Settings.GizmoGroundRaycastChannel.GetValue();
@@ -260,26 +277,90 @@ void FCogEngineWindow_DebugSettings::RenderContent()
}
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Gizmo Ground Raycast Circle Radius", &Settings.GizmoGroundRaycastCircleRadius, 0.1f, 0.1f, 1000.0f, "%.1f");
ImGui::DragFloat("Ground Raycast Circle Radius", &Settings.GizmoGroundRaycastCircleRadius, 0.1f, 0.1f, 1000.0f, "%.1f");
FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZLow X", Settings.GizmoAxisColorsZLowX, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZLow Y", Settings.GizmoAxisColorsZLowY, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZLow Z", Settings.GizmoAxisColorsZLowZ, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZLow W", Settings.GizmoAxisColorsZLowW, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
FCogImguiHelper::ColorEdit4("Ground Raycast Color", Settings.GizmoGroundRaycastColor, ColorEditFlags);
FCogImguiHelper::ColorEdit4("Ground Raycast Circle Color", Settings.GizmoGroundRaycastCircleColor, ColorEditFlags);
FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZHigh X", Settings.GizmoAxisColorsZHighX, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZHigh Y", Settings.GizmoAxisColorsZHighY, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZHigh Z", Settings.GizmoAxisColorsZHighZ, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZHigh W", Settings.GizmoAxisColorsZHighW, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
ImGui::SeparatorText("Axis Colors");
FCogImguiHelper::ColorEdit4("Gizmo Axis Colors Selection X", Settings.GizmoAxisColorsSelectionX, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
FCogImguiHelper::ColorEdit4("Gizmo Axis Colors Selection Y", Settings.GizmoAxisColorsSelectionY, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
FCogImguiHelper::ColorEdit4("Gizmo Axis Colors Selection Z", Settings.GizmoAxisColorsSelectionZ, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
FCogImguiHelper::ColorEdit4("Gizmo Axis Colors Selection W", Settings.GizmoAxisColorsSelectionW, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
FCogImguiHelper::ColorEdit4("Axis Colors ZLow X", Settings.GizmoAxisColorsZLowX, ColorEditFlags);
FCogImguiHelper::ColorEdit4("Axis Colors ZLow Y", Settings.GizmoAxisColorsZLowY, ColorEditFlags);
FCogImguiHelper::ColorEdit4("Axis Colors ZLow Z", Settings.GizmoAxisColorsZLowZ, ColorEditFlags);
FCogImguiHelper::ColorEdit4("Axis Colors ZLow W", Settings.GizmoAxisColorsZLowW, ColorEditFlags);
FCogImguiHelper::ColorEdit4("Gizmo Text Color", Settings.GizmoTextColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
FCogImguiHelper::ColorEdit4("Axis Colors ZHigh X", Settings.GizmoAxisColorsZHighX, ColorEditFlags);
FCogImguiHelper::ColorEdit4("Axis Colors ZHigh Y", Settings.GizmoAxisColorsZHighY, ColorEditFlags);
FCogImguiHelper::ColorEdit4("Axis Colors ZHigh Z", Settings.GizmoAxisColorsZHighZ, ColorEditFlags);
FCogImguiHelper::ColorEdit4("Axis Colors ZHigh W", Settings.GizmoAxisColorsZHighW, ColorEditFlags);
FCogImguiHelper::ColorEdit4("Gizmo Ground Raycast Color", Settings.GizmoGroundRaycastColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
FCogImguiHelper::ColorEdit4("Gizmo Ground Raycast Circle Color", Settings.GizmoGroundRaycastCircleColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf);
FCogImguiHelper::ColorEdit4("Axis Colors Selection X", Settings.GizmoAxisColorsSelectionX, ColorEditFlags);
FCogImguiHelper::ColorEdit4("Axis Colors Selection Y", Settings.GizmoAxisColorsSelectionY, ColorEditFlags);
FCogImguiHelper::ColorEdit4("Axis Colors Selection Z", Settings.GizmoAxisColorsSelectionZ, ColorEditFlags);
FCogImguiHelper::ColorEdit4("Axis Colors Selection W", Settings.GizmoAxisColorsSelectionW, ColorEditFlags);
FCogImguiHelper::ColorEdit4("Text Color", Settings.GizmoTextColor, ColorEditFlags);
}
if (ImGui::CollapsingHeader("Collision Channels"))
{
if (const UCollisionProfile* CollisionProfile = UCollisionProfile::Get())
{
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorWorldStatic, ECC_WorldStatic, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorWorldDynamic, ECC_WorldDynamic, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorPawn, ECC_Pawn, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorVisibility, ECC_Visibility, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorCamera, ECC_Camera, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorPhysicsBody, ECC_PhysicsBody, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorVehicle, ECC_Vehicle, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorDestructible, ECC_Destructible, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorEngineTraceChannel1, ECC_EngineTraceChannel1, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorEngineTraceChannel2, ECC_EngineTraceChannel2, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorEngineTraceChannel3, ECC_EngineTraceChannel3, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorEngineTraceChannel4, ECC_EngineTraceChannel4, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorEngineTraceChannel5, ECC_EngineTraceChannel5, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorEngineTraceChannel6, ECC_EngineTraceChannel6, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel1, ECC_GameTraceChannel1, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel2, ECC_GameTraceChannel2, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel3, ECC_GameTraceChannel3, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel4, ECC_GameTraceChannel4, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel5, ECC_GameTraceChannel5, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel6, ECC_GameTraceChannel6, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel7, ECC_GameTraceChannel7, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel8, ECC_GameTraceChannel8, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel9, ECC_GameTraceChannel9, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel10, ECC_GameTraceChannel10, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel11, ECC_GameTraceChannel11, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel12, ECC_GameTraceChannel12, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel13, ECC_GameTraceChannel13, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel14, ECC_GameTraceChannel14, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel15, ECC_GameTraceChannel15, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel16, ECC_GameTraceChannel16, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel17, ECC_GameTraceChannel17, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel18, ECC_GameTraceChannel18, ColorEditFlags);
}
}
if (ImGui::CollapsingHeader("Collision Query"))
{
ImGui::Checkbox("Draw Hit Primitives", &Settings.CollisionQueryDrawHitPrimitives);
ImGui::Checkbox("Draw Hit Primitive Actors Name", &Settings.CollisionQueryDrawHitPrimitiveActorsName);
ImGui::Checkbox("Prim Hit Primitive Actors Name Shadow", &Settings.CollisionQueryHitPrimitiveActorsNameShadow);
ImGui::Checkbox("Draw Hit Shapes", &Settings.CollisionQueryDrawHitShapes);
ImGui::Checkbox("Draw Hit Location", &Settings.CollisionQueryDrawHitLocation);
ImGui::Checkbox("Draw Hit Impact Points", &Settings.CollisionQueryDrawHitImpactPoints);
ImGui::Checkbox("Draw Hit Normals", &Settings.CollisionQueryDrawHitNormals);
ImGui::Checkbox("Draw Hit Impact Normals", &Settings.CollisionQueryDrawHitImpactNormals);
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Primitive Actors Name Size", &Settings.CollisionQueryHitPrimitiveActorsNameSize);
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Hit Point Size", &Settings.CollisionQueryHitPointSize);
FCogImguiHelper::ColorEdit4("Hit Color", Settings.CollisionQueryHitColor, ColorEditFlags);
FCogImguiHelper::ColorEdit4("No Hit Color", Settings.CollisionQueryNoHitColor, ColorEditFlags);
FCogImguiHelper::ColorEdit4("Normal Color", Settings.CollisionQueryNormalColor, ColorEditFlags);
FCogImguiHelper::ColorEdit4("Impact Normal Color", Settings.CollisionQueryImpactNormalColor, ColorEditFlags);
}
}
@@ -4,11 +4,6 @@
#include "Engine/HitResult.h"
#include "CogEngineCollisionTester.generated.h"
class UCogEngineEditAnywhere_CollisionViewer;
class UCogEngineDataAsset;
class UPrimitiveComponent;
struct FCollisionShape;
//--------------------------------------------------------------------------------------------------------------------------
UENUM()
enum class ECogEngine_CollisionQueryType : uint8
@@ -52,15 +47,14 @@ class COGENGINE_API ACogEngineCollisionTester : public AActor
GENERATED_BODY()
public:
ACogEngineCollisionTester(const FObjectInitializer& ObjectInitializer);
virtual void Tick(float DeltaSeconds) override;
virtual bool ShouldTickIfViewportsOnly() const override;
void Query();
void DrawPrimitive(const UPrimitiveComponent* PrimitiveComponent);
void DrawShape(const FCollisionShape& Shape, const FVector& InLocation, const FQuat& InRotation, const FVector& InScale,
const FColor& InColor, bool InDrawSolid) const;
void Query() const;
UPROPERTY(EditAnywhere)
bool TickInEditor = false;
@@ -90,7 +84,7 @@ public:
int32 ProfileIndex = 0;
UPROPERTY(EditAnywhere)
FVector ShapeExtent = FVector::One();
FVector ShapeExtent = FVector(100, 100, 100);
UPROPERTY(EditAnywhere)
bool DrawHitLocations = true;
@@ -128,10 +122,6 @@ public:
UPROPERTY(EditAnywhere)
FColor ImpactNormalColor = FColor::Cyan;
TSet<const AActor*> AlreadyDrawnActors;
TSet<const UPrimitiveComponent*> AlreadyDrawnComponents;
UPROPERTY(EditAnywhere)
USceneComponent* StartComponent = nullptr;
@@ -5,19 +5,6 @@
#include "Engine/EngineTypes.h"
#include "CogEngineDataAsset.generated.h"
//--------------------------------------------------------------------------------------------------------------------------
USTRUCT()
struct COGENGINE_API FCogCollisionChannel
{
GENERATED_BODY()
UPROPERTY(EditAnywhere)
TEnumAsByte<ECollisionChannel> Channel = ECC_WorldStatic;
UPROPERTY(EditAnywhere)
FLinearColor Color = FLinearColor(0.5f, 0.5f, 0.5f, 1.0f);
};
//--------------------------------------------------------------------------------------------------------------------------
USTRUCT()
struct COGENGINE_API FCogEngineSpawnEntry
@@ -59,7 +46,4 @@ public:
UPROPERTY(Category = "Spawns", EditAnywhere, meta = (TitleProperty = "Name"))
TArray<FCogEngineSpawnGroup> SpawnGroups;
UPROPERTY(Category = "Collisions", EditAnywhere, meta = (TitleProperty = "Channel"))
TArray<FCogCollisionChannel> Channels;
};
@@ -9,7 +9,6 @@
#include "CogEngineWindow_CollisionTester.generated.h"
class UCogEngineConfig_CollisionViewer;
class UCogEngineDataAsset;
class UPrimitiveComponent;
struct FCollisionShape;
@@ -32,8 +31,6 @@ protected:
virtual void RenderContent() override;
virtual void SetAsset(const UCogEngineDataAsset* Value);
struct FChannel
{
bool IsValid = false;
@@ -42,8 +39,6 @@ protected:
FChannel Channels[ECC_MAX];
TObjectPtr<const UCogEngineDataAsset> Asset = nullptr;
TObjectPtr<UCogEngineConfig_CollisionTester> Config = nullptr;
FCogDebug_Gizmo EndGizmo;
@@ -96,42 +91,6 @@ public:
UPROPERTY(Config)
FVector ShapeExtent;
UPROPERTY(Config)
bool DrawHitLocations;
UPROPERTY(Config)
bool DrawHitImpactPoints;
UPROPERTY(Config)
bool DrawHitShapes;
UPROPERTY(Config)
bool DrawHitNormals;
UPROPERTY(Config)
bool DrawHitImpactNormals;
UPROPERTY(Config)
bool DrawHitPrimitives;
UPROPERTY(Config)
bool DrawHitActorsNames;
UPROPERTY(Config)
float HitPointSize;
UPROPERTY(Config)
FVector4f NoHitColor;
UPROPERTY(Config)
FVector4f HitColor;
UPROPERTY(Config)
FVector4f NormalColor;
UPROPERTY(Config)
FVector4f ImpactNormalColor;
UCogEngineConfig_CollisionTester()
{
Reset();
@@ -151,17 +110,5 @@ public:
ObjectTypesToQuery = 0;
ProfileIndex = 0;
DrawHitLocations = true;
DrawHitImpactPoints = true;
DrawHitShapes = true;
DrawHitNormals = true;
DrawHitImpactNormals = true;
DrawHitPrimitives = true;
DrawHitActorsNames = false;
HitPointSize = 10.0f;
NoHitColor = FVector4f(1.0f, 0.0f, 0.0f, 1.0f);
HitColor = FVector4f(0.0f, 1.0f, 0.0f, 1.0f);
NormalColor = FVector4f(0.0f, 1.0f, 0.0f, 1.0f);
ImpactNormalColor = FVector4f(0.0f, 1.0f, 0.0f, 1.0f);
}
};
@@ -26,18 +26,12 @@ protected:
virtual void RenderContent() override;
virtual void SetAsset(const UCogEngineDataAsset* Value);
struct FChannel
{
bool IsValid = false;
FColor Color;
};
FChannel Channels[ECC_MAX];
TObjectPtr<const UCogEngineDataAsset> Asset = nullptr;
TObjectPtr<UCogEngineConfig_CollisionViewer> Config = nullptr;
};
@@ -70,9 +64,6 @@ public:
UPROPERTY(Config)
bool ShowActorsNames = false;
UPROPERTY(Config)
bool ShowQuery = false;
virtual void Reset() override
{
Super::Reset();
@@ -84,6 +75,5 @@ public:
QueryThickness = 0.0f;
UseComplexCollisions = false;
ShowActorsNames = false;
ShowQuery = false;
}
};
@@ -41,13 +41,9 @@ public:
UPROPERTY(Config)
FCogDebugSettings Data;
UPROPERTY(Config)
bool bShowAdvancedSettings = false;
virtual void Reset() override
{
Super::Reset();
Data = FCogDebugSettings();
bShowAdvancedSettings = false;
}
};
@@ -1,5 +1,6 @@
#include "CogWindowWidgets.h"
#include "CogDebug.h"
#include "CogImguiHelper.h"
#include "CogImguiKeyInfo.h"
#include "CogImguiInputHelper.h"
@@ -616,6 +617,9 @@ bool FCogWindowWidgets::MultiChoiceButtonsFloat(TArray<float>& Values, float& Va
//--------------------------------------------------------------------------------------------------------------------------
bool FCogWindowWidgets::ComboCollisionChannel(const char* Label, ECollisionChannel& Channel)
{
FColor ChannelColors[ECC_MAX];
FCogDebug::GetDebugChannelColors(ChannelColors);
FName SelectedChannelName;
const UCollisionProfile* CollisionProfile = UCollisionProfile::Get();
if (CollisionProfile != nullptr)
@@ -626,12 +630,21 @@ bool FCogWindowWidgets::ComboCollisionChannel(const char* Label, ECollisionChann
bool Result = false;
if (ImGui::BeginCombo(Label, TCHAR_TO_ANSI(*SelectedChannelName.ToString()), ImGuiComboFlags_HeightLarge))
{
for (int32 ChannelIndex = 0; ChannelIndex < (int32)ECC_MAX; ++ChannelIndex)
for (int32 ChannelIndex = 0; ChannelIndex < (int32)ECC_OverlapAll_Deprecated; ++ChannelIndex)
{
FColor Color = ChannelColors[ChannelIndex];
if (Color == FColor::Transparent)
{
continue;
}
ImGui::PushID(ChannelIndex);
const FName ChannelName = CollisionProfile->ReturnChannelNameFromContainerIndex(ChannelIndex);
FCogImguiHelper::ColorEdit4("Color", Color, ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel);
ImGui::SameLine();
if (ChannelName.IsValid())
{
if (ImGui::Selectable(TCHAR_TO_ANSI(*ChannelName.ToString())))
@@ -650,10 +663,13 @@ bool FCogWindowWidgets::ComboCollisionChannel(const char* Label, ECollisionChann
}
//--------------------------------------------------------------------------------------------------------------------------
bool FCogWindowWidgets::CollisionProfileChannel(const UCollisionProfile& CollisionProfile, const int32 ChannelIndex, int32& Channels)
bool FCogWindowWidgets::CollisionProfileChannel(const UCollisionProfile& CollisionProfile, const int32 ChannelIndex, FColor& ChannelColor, int32& Channels)
{
bool Result = false;
FCogImguiHelper::ColorEdit4("Color", ChannelColor, ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel);
ImGui::SameLine();
bool IsCollisionActive = (Channels & ECC_TO_BITFIELD(ChannelIndex)) > 0;
const FName ChannelName = CollisionProfile.ReturnChannelNameFromContainerIndex(ChannelIndex);
if (ImGui::Checkbox(TCHAR_TO_ANSI(*ChannelName.ToString()), &IsCollisionActive))
@@ -674,14 +690,29 @@ bool FCogWindowWidgets::CollisionProfileChannel(const UCollisionProfile& Collisi
}
//--------------------------------------------------------------------------------------------------------------------------
bool FCogWindowWidgets::CollisionProfileChannels(const UCollisionProfile& CollisionProfile, int32& Channels)
bool FCogWindowWidgets::CollisionProfileChannels(int32& Channels)
{
const UCollisionProfile* CollisionProfile = UCollisionProfile::Get();
if (CollisionProfile == nullptr)
{
return false;
}
FColor ChannelColors[ECC_MAX];
FCogDebug::GetDebugChannelColors(ChannelColors);
bool Result = false;
for (int32 ChannelIndex = 0; ChannelIndex < (int32)ECC_MAX; ++ChannelIndex)
for (int32 ChannelIndex = 0; ChannelIndex < (int32)ECC_OverlapAll_Deprecated; ++ChannelIndex)
{
FColor Color = ChannelColors[ChannelIndex];
if (Color == FColor::Transparent)
{
continue;
}
ImGui::PushID(ChannelIndex);
Result |= CollisionProfileChannel(CollisionProfile, ChannelIndex, Channels);
Result |= CollisionProfileChannel(*CollisionProfile, ChannelIndex, Color, Channels);
ImGui::PopID();
}
@@ -82,9 +82,9 @@ public:
static bool ComboCollisionChannel(const char* Label, ECollisionChannel& Channel);
static bool CollisionProfileChannel(const UCollisionProfile& CollisionProfile, int32 ChannelIndex, int32& Channels);
static bool CollisionProfileChannel(const UCollisionProfile& CollisionProfile, int32 ChannelIndex, FColor& ChannelColor, int32& Channels);
static bool CollisionProfileChannels(const UCollisionProfile& CollisionProfile, int32& Channels);
static bool CollisionProfileChannels(int32& Channels);
};