Files
UnrealEngineUWP/Engine/Source/Runtime/InteractiveToolsFramework/Private/MultiSelectionTool.cpp
michael balzer 5a20a5e3d0 Move InteractiveToolsFramework and GeometryFramework out of Experimental
#jira UETOOL-3823
#rb brooke.hubert
#preflight 6109d1e9b4288d0001acb7ef

#ROBOMERGE-SOURCE: CL 17055606 in //UE5/Main/...
#ROBOMERGE-BOT: STARSHIP (Main -> Release-Engine-Test) (v850-17047176)

[CL 17055619 by michael balzer in ue5-release-engine-test branch]
2021-08-04 13:59:17 -04:00

116 lines
2.9 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "MultiSelectionTool.h"
#include "TargetInterfaces/AssetBackedTarget.h"
#include "ToolTargets/PrimitiveComponentToolTarget.h"
#include "Components/PrimitiveComponent.h"
bool UMultiSelectionTool::GetMapToSharedSourceData(TArray<int32>& MapToFirstOccurrences)
{
bool bSharesSources = false;
MapToFirstOccurrences.SetNumUninitialized(Targets.Num());
for (int32 ComponentIdx = 0; ComponentIdx < Targets.Num(); ComponentIdx++)
{
MapToFirstOccurrences[ComponentIdx] = -1;
}
for (int32 ComponentIdx = 0; ComponentIdx < Targets.Num(); ComponentIdx++)
{
if (MapToFirstOccurrences[ComponentIdx] >= 0) // already mapped
{
continue;
}
MapToFirstOccurrences[ComponentIdx] = ComponentIdx;
IAssetBackedTarget* Target = Cast<IAssetBackedTarget>(Targets[ComponentIdx]);
if (!Target)
{
continue;
}
for (int32 VsIdx = ComponentIdx + 1; VsIdx < Targets.Num(); VsIdx++)
{
IAssetBackedTarget* OtherTarget = Cast<IAssetBackedTarget>(Targets[VsIdx]);
if (OtherTarget && OtherTarget->GetSourceData() == Target->GetSourceData())
{
bSharesSources = true;
MapToFirstOccurrences[VsIdx] = ComponentIdx;
}
}
}
return bSharesSources;
}
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);
}