Files
tyson brochu 9efcc70606 ModelingComponents/Selection:
- create a new MeshTopologySelector base class. The existing GroupTopologySelector class now inherits from it, as does a new BoundarySelector class
- likewise, create a new MeshTopologySelectionMehchanic base class and have (existing) PolygonSelectionMechanic and (new) BoundarySelectionMechanic inherit from it
- the new Boundary classes use FMeshBoundary loops to define selectable loops rather than FGroupTopology

HoleFillTool:
- change to using BoundarySelectionMechanic instead of GroupTopologySelector

Misc:
- allow FMeshBoundaryLoops to fail untangling a loop with bowties but still continue processing other loops


#jira UE-144821
#rb jimmy.andrews
#preflight 63222176e93a80888cb7d3df

[CL 22013854 by tyson brochu in ue5-main branch]
2022-09-14 15:25:19 -04:00

95 lines
2.9 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "Selection/BoundarySelectionMechanic.h"
#include "MeshBoundaryLoops.h"
#include "Selection/BoundarySelector.h"
#include "ToolSceneQueriesUtil.h"
using namespace UE::Geometry;
#define LOCTEXT_NAMESPACE "UBoundarySelectionMechanic"
void UBoundarySelectionMechanic::Initialize(
const FDynamicMesh3* MeshIn,
FTransform3d TargetTransformIn,
UWorld* WorldIn,
const UE::Geometry::FMeshBoundaryLoops* BoundaryLoopsIn,
TFunction<FDynamicMeshAABBTree3* ()> GetSpatialSourceFuncIn)
{
TopoSelector = MakeShared<FBoundarySelector>(MeshIn, BoundaryLoopsIn);;
UMeshTopologySelectionMechanic::Initialize(MeshIn, TargetTransformIn, WorldIn, GetSpatialSourceFuncIn);
}
bool UBoundarySelectionMechanic::UpdateHighlight(const FRay& WorldRay)
{
checkf(DrawnTriangleSetComponent != nullptr, TEXT("Initialize() not called on UMeshTopologySelectionMechanic."));
FRay3d LocalRay(TargetTransform.InverseTransformPosition((FVector3d)WorldRay.Origin),
TargetTransform.InverseTransformVector((FVector3d)WorldRay.Direction));
UE::Geometry::Normalize(LocalRay.Direction);
HilightSelection.Clear();
FVector3d LocalPosition, LocalNormal;
FGroupTopologySelector::FSelectionSettings TopoSelectorSettings = GetTopoSelectorSettings(CameraState.bIsOrthographic);
bool bHit = TopoSelector->FindSelectedElement(TopoSelectorSettings, LocalRay, HilightSelection, LocalPosition, LocalNormal);
// Don't hover highlight a selection that we already selected, because people didn't like that
if (PersistentSelection.Contains(HilightSelection))
{
HilightSelection.Clear();
}
return bHit;
}
bool UBoundarySelectionMechanic::UpdateSelection(const FRay& WorldRay, FVector3d& LocalHitPositionOut, FVector3d& LocalHitNormalOut)
{
FRay3d LocalRay(TargetTransform.InverseTransformPosition((FVector3d)WorldRay.Origin),
TargetTransform.InverseTransformVector((FVector3d)WorldRay.Direction));
UE::Geometry::Normalize(LocalRay.Direction);
const FGroupTopologySelection PreviousSelection = PersistentSelection;
FVector3d LocalPosition, LocalNormal;
FGroupTopologySelection Selection;
FGroupTopologySelector::FSelectionSettings TopoSelectorSettings = GetTopoSelectorSettings(CameraState.bIsOrthographic);
if (TopoSelector->FindSelectedElement(TopoSelectorSettings, LocalRay, Selection, LocalPosition, LocalNormal))
{
LocalHitPositionOut = LocalPosition;
LocalHitNormalOut = LocalNormal;
}
if (ShouldAddToSelectionFunc())
{
if (ShouldRemoveFromSelectionFunc())
{
PersistentSelection.Toggle(Selection);
}
else
{
PersistentSelection.Append(Selection);
}
}
else if (ShouldRemoveFromSelectionFunc())
{
PersistentSelection.Remove(Selection);
}
else
{
PersistentSelection = Selection;
}
if (PersistentSelection != PreviousSelection)
{
SelectionTimestamp++;
OnSelectionChanged.Broadcast();
return true;
}
return false;
}
#undef LOCTEXT_NAMESPACE