2019-12-27 07:44:07 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2017-03-30 16:00:43 -04:00
# include "SplitEdge.h"
# include "IMeshEditorModeEditingContract.h"
# include "IMeshEditorModeUIContract.h"
2018-02-14 14:13:42 -05:00
# include "Framework/Commands/UICommandInfo.h"
2017-03-30 16:00:43 -04:00
# include "EditableMesh.h"
# include "MeshElement.h"
2018-02-14 14:13:42 -05:00
# include "Framework/MultiBox/MultiBoxBuilder.h"
# include "Framework/Commands/UICommandList.h"
2017-03-30 16:00:43 -04:00
# include "ViewportInteractor.h"
# define LOCTEXT_NAMESPACE "MeshEditorMode"
void USplitEdgeCommand : : RegisterUICommand ( FBindingContext * BindingContext )
{
2017-06-26 14:00:48 -04:00
UI_COMMAND_EXT ( BindingContext , /* Out */ UICommandInfo , " InsertVertex " , " Insert Vertex " , " Inserts a vertex at a specific position along an edge as you click and drag, splitting the edge into two. " , EUserInterfaceActionType : : RadioButton , FInputChord ( ) ) ;
2017-03-30 16:00:43 -04:00
}
void USplitEdgeCommand : : ApplyDuringDrag ( IMeshEditorModeEditingContract & MeshEditorMode , UViewportInteractor * ViewportInteractor )
{
2018-03-09 14:34:55 -05:00
// Figure out what to split
static TMap < class UEditableMesh * , TArray < FMeshElement > > SplitEdgeMeshesAndEdgesToSplit ;
MeshEditorMode . GetSelectedMeshesAndEdges ( /* Out */ SplitEdgeMeshesAndEdgesToSplit ) ;
if ( SplitEdgeMeshesAndEdgesToSplit . Num ( ) > 0 )
2017-03-30 16:00:43 -04:00
{
MeshEditorMode . DeselectAllMeshElements ( ) ;
static TArray < FMeshElement > MeshElementsToSelect ;
MeshElementsToSelect . Reset ( ) ;
for ( auto & MeshAndEdges : SplitEdgeMeshesAndEdgesToSplit )
{
UEditableMesh * EditableMesh = MeshAndEdges . Key ;
verify ( ! EditableMesh - > AnyChangesToUndo ( ) ) ;
const TArray < FMeshElement > & EdgeElements = MeshAndEdges . Value ;
2018-03-09 14:34:55 -05:00
// Figure out where to split
FEdgeID ClosestEdgeID = FEdgeID : : Invalid ;
float Split = 0.0f ;
const bool bFoundSplit = MeshEditorMode . FindEdgeSplitUnderInteractor ( ViewportInteractor , EditableMesh , EdgeElements , /* Out */ ClosestEdgeID , /* Out */ Split ) ;
if ( bFoundSplit )
2017-03-30 16:00:43 -04:00
{
2018-03-09 14:34:55 -05:00
for ( const FMeshElement & EdgeElement : EdgeElements )
2017-03-30 16:00:43 -04:00
{
2018-03-09 14:34:55 -05:00
const FEdgeID EdgeID ( EdgeElement . ElementAddress . ElementID ) ;
2017-03-30 16:00:43 -04:00
2018-03-09 14:34:55 -05:00
static TArray < FVertexID > NewVertexIDs ;
NewVertexIDs . Reset ( ) ;
static TArray < float > Splits ; // @todo mesheditor edgeloop: Add support for inserting multiple splits at once!
Splits . Reset ( ) ;
Splits . Add ( Split ) ;
EditableMesh - > SplitEdge ( EdgeID , Splits , /* Out */ NewVertexIDs ) ;
// Select all of the new vertices that were created by splitting the edge
{
for ( const FVertexID NewVertexID : NewVertexIDs )
{
FMeshElement MeshElementToSelect ;
{
MeshElementToSelect . Component = EdgeElement . Component ;
MeshElementToSelect . ElementAddress . SubMeshAddress = EdgeElement . ElementAddress . SubMeshAddress ;
MeshElementToSelect . ElementAddress . ElementType = EEditableMeshElementType : : Vertex ;
MeshElementToSelect . ElementAddress . ElementID = NewVertexID ;
}
// Queue selection of this new element. We don't want it to be part of the current action.
MeshElementsToSelect . Add ( MeshElementToSelect ) ;
}
2017-03-30 16:00:43 -04:00
}
}
}
MeshEditorMode . TrackUndo ( EditableMesh , EditableMesh - > MakeUndo ( ) ) ;
}
MeshEditorMode . SelectMeshElements ( MeshElementsToSelect ) ;
}
}
# undef LOCTEXT_NAMESPACE