2019-12-27 07:44:07 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2018-12-12 11:25:29 -05:00
# include "CollapseSelectedHierarchyCommand.h"
# include "IMeshEditorModeEditingContract.h"
# include "ScopedTransaction.h"
# include "Editor.h"
# include "Engine/Selection.h"
2019-10-01 20:41:42 -04:00
# include "StaticMeshAttributes.h"
2018-12-12 11:25:29 -05:00
# include "PackageTools.h"
# include "MeshFractureSettings.h"
# include "EditableMeshFactory.h"
# include "GeometryCollection/GeometryCollection.h"
# include "GeometryCollection/GeometryCollectionActor.h"
# include "GeometryCollection/GeometryCollectionComponent.h"
# include "GeometryCollection/GeometryCollectionObject.h"
# include "EditorSupportDelegates.h"
# include "GeometryCollection/GeometryCollectionConversion.h"
# include "GeometryCollection/GeometryCollectionClusteringUtility.h"
# define LOCTEXT_NAMESPACE "CollapseSelectedHierarchyCommand"
DEFINE_LOG_CATEGORY ( LogCollapseSelectedHierarchyCommand ) ;
void UCollapseSelectedHierarchyCommand : : RegisterUICommand ( FBindingContext * BindingContext )
{
UI_COMMAND_EXT ( BindingContext , /* Out */ UICommandInfo , " CollapseSelectedHierarchy " , " Uncluster " , " Performs collpase of hierarchy at selected nodes. " , EUserInterfaceActionType : : Button , FInputChord ( ) ) ;
}
void UCollapseSelectedHierarchyCommand : : Execute ( IMeshEditorModeEditingContract & MeshEditorMode )
{
if ( MeshEditorMode . GetActiveAction ( ) ! = NAME_None )
{
return ;
}
if ( MeshEditorMode . GetSelectedEditableMeshes ( ) . Num ( ) = = 0 )
{
return ;
}
FScopedTransaction Transaction ( LOCTEXT ( " CollapseSelectedHierarchy " , " Uncluster " ) ) ;
MeshEditorMode . CommitSelectedMeshes ( ) ;
TArray < UEditableMesh * > SelectedActors = MeshEditorMode . GetSelectedEditableMeshes ( ) ;
CollapseHierarchies ( MeshEditorMode , SelectedActors ) ;
2019-06-08 17:15:34 -04:00
UpdateExplodedView ( MeshEditorMode , EViewResetType : : RESET_ALL ) ;
2018-12-12 11:25:29 -05:00
}
void UCollapseSelectedHierarchyCommand : : CollapseHierarchies ( IMeshEditorModeEditingContract & MeshEditorMode , TArray < UEditableMesh * > & SelectedMeshes )
{
for ( UEditableMesh * EditableMesh : SelectedMeshes )
{
UGeometryCollectionComponent * GeometryCollectionComponent = GetGeometryCollectionComponent ( EditableMesh ) ;
if ( GeometryCollectionComponent ! = nullptr )
{
// scoped edit of collection
FGeometryCollectionEdit GeometryCollectionEdit = GeometryCollectionComponent - > EditRestCollection ( ) ;
if ( UGeometryCollection * GeometryCollectionObject = GeometryCollectionEdit . GetRestCollection ( ) )
{
2019-06-08 17:15:34 -04:00
TSharedPtr < FGeometryCollection , ESPMode : : ThreadSafe > GeometryCollectionPtr = GeometryCollectionObject - > GetGeometryCollection ( ) ;
2018-12-12 11:25:29 -05:00
if ( FGeometryCollection * GeometryCollection = GeometryCollectionPtr . Get ( ) )
{
AddAdditionalAttributesIfRequired ( GeometryCollectionObject ) ;
UE_LOG ( LogCollapseSelectedHierarchyCommand , Log , TEXT ( " Hierarchy Before Collapsing ... " ) ) ;
LogHierarchy ( GeometryCollectionObject ) ;
const UMeshFractureSettings * FratureSettings = MeshEditorMode . GetFractureSettings ( ) ;
int8 FractureLevel = FratureSettings - > CommonSettings - > GetFractureLevelNumber ( ) ;
FGeometryCollectionClusteringUtility : : CollapseSelectedHierarchy ( FractureLevel , GeometryCollectionComponent - > GetSelectedBones ( ) , GeometryCollection ) ;
FScopedColorEdit EditBoneColor = GeometryCollectionComponent - > EditBoneSelection ( ) ;
EditBoneColor . ResetBoneSelection ( ) ;
UE_LOG ( LogCollapseSelectedHierarchyCommand , Log , TEXT ( " Hierarchy After Collapsing ... " ) ) ;
LogHierarchy ( GeometryCollectionObject ) ;
GeometryCollectionComponent - > MarkRenderDynamicDataDirty ( ) ;
GeometryCollectionComponent - > MarkRenderStateDirty ( ) ;
}
}
}
}
}
# undef LOCTEXT_NAMESPACE