2020-08-11 01:36:57 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "MeshBoundaryToolBase.h"
|
|
|
|
|
|
|
|
|
|
#include "BaseBehaviors/SingleClickBehavior.h"
|
|
|
|
|
#include "BaseBehaviors/MouseHoverBehavior.h"
|
2021-06-13 00:36:02 -04:00
|
|
|
#include "DynamicMesh/DynamicMesh3.h"
|
2020-08-11 01:36:57 -04:00
|
|
|
#include "InteractiveToolManager.h"
|
|
|
|
|
#include "MeshDescriptionToDynamicMesh.h"
|
|
|
|
|
#include "Selection/PolygonSelectionMechanic.h"
|
|
|
|
|
|
2021-03-24 11:11:02 -04:00
|
|
|
#include "TargetInterfaces/PrimitiveComponentBackedTarget.h"
|
2021-12-06 12:42:19 -05:00
|
|
|
#include "ModelingToolTargetUtil.h"
|
2021-03-24 11:11:02 -04:00
|
|
|
|
2021-03-09 19:33:56 -04:00
|
|
|
using namespace UE::Geometry;
|
|
|
|
|
|
2020-08-11 01:36:57 -04:00
|
|
|
#define LOCTEXT_NAMESPACE "UMeshBoundaryToolBase"
|
|
|
|
|
|
|
|
|
|
void UMeshBoundaryToolBase::Setup()
|
|
|
|
|
{
|
|
|
|
|
USingleSelectionTool::Setup();
|
|
|
|
|
|
2021-03-24 11:11:02 -04:00
|
|
|
if (!Target)
|
2020-08-11 01:36:57 -04:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// create mesh to operate on
|
2021-02-17 11:50:23 -04:00
|
|
|
OriginalMesh = MakeShared<FDynamicMesh3, ESPMode::ThreadSafe>();
|
2020-08-11 01:36:57 -04:00
|
|
|
FMeshDescriptionToDynamicMesh Converter;
|
2021-12-06 12:42:19 -05:00
|
|
|
Converter.Convert( UE::ToolTarget::GetMeshDescription(Target), *OriginalMesh);
|
2020-08-11 01:36:57 -04:00
|
|
|
|
|
|
|
|
// initialize hit query
|
|
|
|
|
MeshSpatial.SetMesh(OriginalMesh.Get());
|
|
|
|
|
|
|
|
|
|
// initialize topology
|
|
|
|
|
Topology = MakeUnique<FBasicTopology>(OriginalMesh.Get(), false);
|
|
|
|
|
bool bTopologyOK = Topology->RebuildTopology();
|
|
|
|
|
|
|
|
|
|
// Set up selection mechanic to find and select edges
|
|
|
|
|
SelectionMechanic = NewObject<UPolygonSelectionMechanic>(this);
|
|
|
|
|
SelectionMechanic->bAddSelectionFilterPropertiesToParentTool = false;
|
|
|
|
|
SelectionMechanic->Setup(this);
|
|
|
|
|
SelectionMechanic->Properties->bSelectEdges = true;
|
|
|
|
|
SelectionMechanic->Properties->bSelectFaces = false;
|
|
|
|
|
SelectionMechanic->Properties->bSelectVertices = false;
|
|
|
|
|
SelectionMechanic->Initialize(OriginalMesh.Get(),
|
2022-02-24 15:01:41 -05:00
|
|
|
(FTransform3d)Cast<IPrimitiveComponentBackedTarget>(Target)->GetWorldTransform(),
|
2022-01-28 10:18:10 -05:00
|
|
|
GetTargetWorld(),
|
2020-08-11 01:36:57 -04:00
|
|
|
Topology.Get(),
|
2020-11-13 12:09:55 -04:00
|
|
|
[this]() { return &MeshSpatial; }
|
2020-08-11 01:36:57 -04:00
|
|
|
);
|
2020-11-13 12:09:55 -04:00
|
|
|
SelectionMechanic->OnSelectionChanged.AddUObject(this, &UMeshBoundaryToolBase::OnSelectionChanged);
|
2020-08-11 01:36:57 -04:00
|
|
|
}
|
|
|
|
|
|
2022-01-28 18:40:54 -05:00
|
|
|
void UMeshBoundaryToolBase::OnShutdown(EToolShutdownType ShutdownType)
|
2020-08-11 01:36:57 -04:00
|
|
|
{
|
|
|
|
|
if (SelectionMechanic)
|
|
|
|
|
{
|
|
|
|
|
SelectionMechanic->Shutdown();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UMeshBoundaryToolBase::Render(IToolsContextRenderAPI* RenderAPI)
|
|
|
|
|
{
|
|
|
|
|
if (SelectionMechanic)
|
|
|
|
|
{
|
|
|
|
|
SelectionMechanic->Render(RenderAPI);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#undef LOCTEXT_NAMESPACE
|