2021-02-23 18:03:26 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
#include "MultiSelectionTool.h"
|
2021-05-10 01:17:30 -04:00
|
|
|
#include "ToolTargets/PrimitiveComponentToolTarget.h"
|
|
|
|
|
#include "Components/PrimitiveComponent.h"
|
2021-02-23 18:03:26 -04:00
|
|
|
|
2022-09-24 13:57:58 -04:00
|
|
|
#include UE_INLINE_GENERATED_CPP_BY_NAME(MultiSelectionTool)
|
|
|
|
|
|
2021-05-10 01:17:30 -04:00
|
|
|
|
|
|
|
|
bool UMultiSelectionTool::SupportsWorldSpaceFocusBox()
|
|
|
|
|
{
|
|
|
|
|
int32 PrimitiveCount = 0;
|
|
|
|
|
for (const TObjectPtr<UToolTarget>& Target : Targets)
|
|
|
|
|
{
|
|
|
|
|
if (Cast<UPrimitiveComponentToolTarget>(Target) != nullptr)
|
|
|
|
|
{
|
|
|
|
|
PrimitiveCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return PrimitiveCount > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FBox UMultiSelectionTool::GetWorldSpaceFocusBox()
|
|
|
|
|
{
|
|
|
|
|
FBox AccumBox(EForceInit::ForceInit);
|
|
|
|
|
for (const TObjectPtr<UToolTarget>& Target : Targets)
|
|
|
|
|
{
|
|
|
|
|
UPrimitiveComponentToolTarget* PrimTarget = Cast<UPrimitiveComponentToolTarget>(Target);
|
|
|
|
|
if (PrimTarget)
|
|
|
|
|
{
|
|
|
|
|
UPrimitiveComponent* Component = PrimTarget->GetOwnerComponent();
|
|
|
|
|
if (Component)
|
|
|
|
|
{
|
|
|
|
|
FBox ComponentBounds = Component->Bounds.GetBox();
|
|
|
|
|
AccumBox += ComponentBounds;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return AccumBox;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool UMultiSelectionTool::SupportsWorldSpaceFocusPoint()
|
|
|
|
|
{
|
|
|
|
|
int32 PrimitiveCount = 0;
|
|
|
|
|
for (const TObjectPtr<UToolTarget>& Target : Targets)
|
|
|
|
|
{
|
|
|
|
|
if (Cast<UPrimitiveComponentToolTarget>(Target) != nullptr)
|
|
|
|
|
{
|
|
|
|
|
PrimitiveCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return PrimitiveCount > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool UMultiSelectionTool::GetWorldSpaceFocusPoint(const FRay& WorldRay, FVector& PointOut)
|
|
|
|
|
{
|
|
|
|
|
double NearestRayParam = (double)HALF_WORLD_MAX;
|
|
|
|
|
PointOut = FVector::ZeroVector;
|
|
|
|
|
|
|
|
|
|
for (const TObjectPtr<UToolTarget>& Target : Targets)
|
|
|
|
|
{
|
|
|
|
|
UPrimitiveComponentToolTarget* PrimTarget = Cast<UPrimitiveComponentToolTarget>(Target);
|
|
|
|
|
if (PrimTarget)
|
|
|
|
|
{
|
|
|
|
|
FHitResult HitResult;
|
|
|
|
|
if (PrimTarget->HitTestComponent(WorldRay, HitResult))
|
|
|
|
|
{
|
|
|
|
|
double HitRayParam = (double)WorldRay.GetParameter(HitResult.ImpactPoint);
|
|
|
|
|
if (HitRayParam < NearestRayParam)
|
|
|
|
|
{
|
|
|
|
|
NearestRayParam = HitRayParam;
|
|
|
|
|
PointOut = HitResult.ImpactPoint;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (NearestRayParam < (double)HALF_WORLD_MAX);
|
|
|
|
|
}
|
2022-09-24 13:57:58 -04:00
|
|
|
|