2022-07-15 13:49:13 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "Commands/DeleteGeometrySelectionCommand.h"
|
|
|
|
|
#include "ToolContextInterfaces.h"
|
|
|
|
|
#include "UDynamicMesh.h"
|
|
|
|
|
#include "DynamicMesh/DynamicMesh3.h"
|
|
|
|
|
#include "DynamicMesh/DynamicMeshChangeTracker.h"
|
|
|
|
|
#include "DynamicMeshEditor.h"
|
|
|
|
|
#include "Changes/MeshChange.h"
|
2022-07-15 17:53:52 -04:00
|
|
|
#include "Selections/GeometrySelectionUtil.h"
|
2022-07-15 13:49:13 -04:00
|
|
|
|
2022-11-22 20:17:33 -05:00
|
|
|
#include UE_INLINE_GENERATED_CPP_BY_NAME(DeleteGeometrySelectionCommand)
|
|
|
|
|
|
2022-07-15 13:49:13 -04:00
|
|
|
using namespace UE::Geometry;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define LOCTEXT_NAMESPACE "UDeleteGeometrySelectionCommand"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FText UDeleteGeometrySelectionCommand::GetCommandShortString() const
|
|
|
|
|
{
|
|
|
|
|
return LOCTEXT("ShortString", "Delete Selection");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool UDeleteGeometrySelectionCommand::CanExecuteCommandForSelection(UGeometrySelectionEditCommandArguments* SelectionArgs)
|
|
|
|
|
{
|
|
|
|
|
return SelectionArgs->IsMatchingType(FGeometryIdentifier::ETargetType::MeshContainer, FGeometryIdentifier::EObjectType::DynamicMesh);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
ModelingMode: Selection system improvements. Add Disconnect command and various new Selection-Edit Commands
Add UInteractiveCommandResult, UInteractiveCommand::ExecuteCommand() now optionally can return a result subclass
Add UGeometrySelectionEditCommandResult, UGeometrySelectionEditCommand now can optionally return an "output" selection via this type
UGeometrySelectionManager::ExecuteSelectionCommand optionally can restore a selection after a command, via UGeometrySelectionEditCommandResult
Add UDisconnectGeometrySelectionCommand, implements disconnection of selected triangles (ie separates but not into a new mesh)
Add UModifyGeometrySelectionCommand, implements various selection edits (select all, expand to connected, invert, invert connected, expand, contract)
Add IGeometrySelector::InitializeSelectionFromPredicate() and ::UpdateSelectionFromSelection(), implement in UDynamicMeshSelector, used to implement selection edit commands
Add UI to enable new commands in Modeling Mode
#rb none
#preflight 63c047f4305002c64170f6a2
[CL 23667880 by ryan schmidt in ue5-main branch]
2023-01-12 14:52:52 -05:00
|
|
|
void UDeleteGeometrySelectionCommand::ExecuteCommandForSelection(UGeometrySelectionEditCommandArguments* SelectionArgs, UInteractiveCommandResult** Result)
|
2022-07-15 13:49:13 -04:00
|
|
|
{
|
ModelingMode: Selection system improvements. Add Disconnect command and various new Selection-Edit Commands
Add UInteractiveCommandResult, UInteractiveCommand::ExecuteCommand() now optionally can return a result subclass
Add UGeometrySelectionEditCommandResult, UGeometrySelectionEditCommand now can optionally return an "output" selection via this type
UGeometrySelectionManager::ExecuteSelectionCommand optionally can restore a selection after a command, via UGeometrySelectionEditCommandResult
Add UDisconnectGeometrySelectionCommand, implements disconnection of selected triangles (ie separates but not into a new mesh)
Add UModifyGeometrySelectionCommand, implements various selection edits (select all, expand to connected, invert, invert connected, expand, contract)
Add IGeometrySelector::InitializeSelectionFromPredicate() and ::UpdateSelectionFromSelection(), implement in UDynamicMeshSelector, used to implement selection edit commands
Add UI to enable new commands in Modeling Mode
#rb none
#preflight 63c047f4305002c64170f6a2
[CL 23667880 by ryan schmidt in ue5-main branch]
2023-01-12 14:52:52 -05:00
|
|
|
// delete never returns a new selection
|
|
|
|
|
if (Result != nullptr)
|
|
|
|
|
{
|
|
|
|
|
*Result = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-15 13:49:13 -04:00
|
|
|
// should have been verified by CanExecute
|
|
|
|
|
check(SelectionArgs->IsMatchingType(FGeometryIdentifier::ETargetType::MeshContainer, FGeometryIdentifier::EObjectType::DynamicMesh));
|
|
|
|
|
|
|
|
|
|
// collect up all our inputs
|
|
|
|
|
UDynamicMesh* MeshObject = SelectionArgs->SelectionHandle.Identifier.GetAsObjectType<UDynamicMesh>();
|
|
|
|
|
check(MeshObject != nullptr);
|
|
|
|
|
const FGeometrySelection* Selection = SelectionArgs->SelectionHandle.Selection;
|
|
|
|
|
if (Selection->Selection.Num() == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool bTrackChanges = SelectionArgs->HasTransactionsAPI();
|
|
|
|
|
TUniquePtr<FDynamicMeshChange> DynamicMeshChange; // only initialized if bTrackChanges == true
|
|
|
|
|
|
|
|
|
|
// apply the delete operation
|
|
|
|
|
MeshObject->EditMesh([&](FDynamicMesh3& EditMesh)
|
|
|
|
|
{
|
|
|
|
|
// build list of triangles from whatever the selection contains
|
|
|
|
|
TSet<int32> TriangleList;
|
|
|
|
|
//UE::Geometry::FPolygroupSet UsePolygroupSet = ...; // need to support this eventually
|
|
|
|
|
UE::Geometry::EnumerateSelectionTriangles(*Selection, EditMesh,
|
|
|
|
|
[&](int32 TriangleID) { TriangleList.Add(TriangleID); });
|
|
|
|
|
|
|
|
|
|
// mark triangles for change
|
|
|
|
|
FDynamicMeshChangeTracker ChangeTracker(&EditMesh);
|
|
|
|
|
if (bTrackChanges)
|
|
|
|
|
{
|
|
|
|
|
ChangeTracker.BeginChange();
|
|
|
|
|
ChangeTracker.SaveTriangles(TriangleList, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// actually delete them
|
|
|
|
|
FDynamicMeshEditor Editor(&EditMesh);
|
|
|
|
|
Editor.RemoveTriangles(TriangleList.Array(), true);
|
|
|
|
|
|
|
|
|
|
// extract the change record
|
|
|
|
|
if (bTrackChanges)
|
|
|
|
|
{
|
|
|
|
|
DynamicMeshChange = ChangeTracker.EndChange();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, EDynamicMeshChangeType::GeneralEdit, EDynamicMeshAttributeChangeFlags::Unknown, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// emit change
|
|
|
|
|
if ( bTrackChanges && DynamicMeshChange.IsValid() )
|
|
|
|
|
{
|
|
|
|
|
SelectionArgs->GetTransactionsAPI()->BeginUndoTransaction(GetCommandShortString());
|
|
|
|
|
SelectionArgs->GetTransactionsAPI()->AppendChange(MeshObject,
|
|
|
|
|
MakeUnique<FMeshChange>(MoveTemp(DynamicMeshChange)), GetCommandShortString());
|
|
|
|
|
SelectionArgs->GetTransactionsAPI()->EndUndoTransaction();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#undef LOCTEXT_NAMESPACE
|