2019-12-27 07:44:07 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2018-06-07 18:49:50 -04:00
# include "FlipPolygon.h"
# include "EditableMesh.h"
# include "Framework/Commands/UICommandInfo.h"
# include "IMeshEditorModeEditingContract.h"
# include "ScopedTransaction.h"
# define LOCTEXT_NAMESPACE "MeshEditorMode"
void UFlipPolygonCommand : : RegisterUICommand ( FBindingContext * BindingContext )
{
UI_COMMAND_EXT ( BindingContext , /* Out */ UICommandInfo , " FlipPolygon " , " Flip " , " Flip the currently selected polygons. " , EUserInterfaceActionType : : Button , FInputChord ( EKeys : : F , EModifierKey : : Shift ) ) ;
}
void UFlipPolygonCommand : : Execute ( IMeshEditorModeEditingContract & MeshEditorMode )
{
if ( MeshEditorMode . GetActiveAction ( ) ! = NAME_None )
{
return ;
}
static TMap < UEditableMesh * , TArray < FMeshElement > > MeshesAndPolygons ;
MeshEditorMode . GetSelectedMeshesAndPolygons ( MeshesAndPolygons ) ;
if ( MeshesAndPolygons . Num ( ) = = 0 )
{
return ;
}
const FScopedTransaction Transaction ( LOCTEXT ( " UndoFlipPolygon " , " Flip Polygon " ) ) ;
MeshEditorMode . CommitSelectedMeshes ( ) ;
// Refresh selection (committing may have created a new mesh instance)
MeshEditorMode . GetSelectedMeshesAndPolygons ( MeshesAndPolygons ) ;
2019-01-10 17:26:53 -05:00
// Deselect the elements because the selection visual needs to be updated
MeshEditorMode . DeselectMeshElements ( MeshesAndPolygons ) ;
2018-06-07 18:49:50 -04:00
// Flip selected polygons
for ( const auto & MeshAndPolygons : MeshesAndPolygons )
{
UEditableMesh * EditableMesh = MeshAndPolygons . Key ;
EditableMesh - > StartModification ( EMeshModificationType : : Final , EMeshTopologyChange : : TopologyChange ) ;
static TArray < FPolygonID > PolygonsToFlip ;
PolygonsToFlip . Reset ( ) ;
for ( const FMeshElement & PolygonElement : MeshAndPolygons . Value )
{
const FPolygonID PolygonID ( PolygonElement . ElementAddress . ElementID ) ;
PolygonsToFlip . Add ( PolygonID ) ;
}
EditableMesh - > FlipPolygons ( PolygonsToFlip ) ;
EditableMesh - > EndModification ( ) ;
MeshEditorMode . TrackUndo ( EditableMesh , EditableMesh - > MakeUndo ( ) ) ;
}
2019-01-10 17:26:53 -05:00
// Re-select the elements to update the selection visual
for ( const auto & MeshAndPolygons : MeshesAndPolygons )
{
MeshEditorMode . SelectMeshElements ( MeshAndPolygons . Value ) ;
}
2018-06-07 18:49:50 -04:00
}
# undef LOCTEXT_NAMESPACE